summaryrefslogtreecommitdiffstats
path: root/common/firmware.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/firmware.c')
-rw-r--r--common/firmware.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/common/firmware.c b/common/firmware.c
index b87d7da38f..3c7960581f 100644
--- a/common/firmware.c
+++ b/common/firmware.c
@@ -272,17 +272,18 @@ int firmwaremgr_load_file(struct firmware_mgr *mgr, const char *firmware)
firmwarefd = open(firmware, O_RDONLY);
if (firmwarefd < 0) {
- printf("could not open %s: %s\n", firmware,
- errno_str());
+ printf("could not open %s: %m\n", firmware);
ret = firmwarefd;
goto out;
}
- type = file_name_detect_type(firmware);
+ ret = file_name_detect_type(firmware, &type);
+ if (ret)
+ goto out;
devicefd = open(dst, O_WRONLY);
if (devicefd < 0) {
- printf("could not open %s: %s\n", dst, errno_str());
+ printf("could not open %s: %m\n", dst);
ret = devicefd;
goto out;
}
@@ -305,6 +306,38 @@ out:
return ret;
}
+/*
+ * request_firmware - load a firmware to a device
+ */
+int request_firmware(const struct firmware **out, const char *fw_name, struct device *dev)
+{
+ char fw_path[PATH_MAX + 1];
+ struct firmware *fw;
+ int ret;
+
+ fw = kzalloc(sizeof(struct firmware), GFP_KERNEL);
+ if (!fw)
+ return -ENOMEM;
+
+ snprintf(fw_path, sizeof(fw_path), "%s/%s", firmware_path, fw_name);
+
+ ret = read_file_2(fw_path, &fw->size, (void *)&fw->data, FILESIZE_MAX);
+ if (ret) {
+ kfree(fw);
+ return ret;
+ }
+
+ *out = fw;
+
+ return 0;
+}
+
+void release_firmware(const struct firmware *fw)
+{
+ kfree_const(fw->data);
+ kfree_const(fw);
+}
+
static int firmware_init(void)
{
firmware_path = strdup("/env/firmware");