* commit '6498ed382eb4b70688bffac734dd99259904b96d': init: refactor firmware loading locations into table
This commit is contained in:
commit
0d2360532d
1 changed files with 32 additions and 44 deletions
|
|
@ -49,9 +49,9 @@
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
#define SYSFS_PREFIX "/sys"
|
#define SYSFS_PREFIX "/sys"
|
||||||
#define FIRMWARE_DIR1 "/etc/firmware"
|
static const char *firmware_dirs[] = { "/etc/firmware",
|
||||||
#define FIRMWARE_DIR2 "/vendor/firmware"
|
"/vendor/firmware",
|
||||||
#define FIRMWARE_DIR3 "/firmware/image"
|
"/firmware/image" };
|
||||||
|
|
||||||
extern struct selabel_handle *sehandle;
|
extern struct selabel_handle *sehandle;
|
||||||
|
|
||||||
|
|
@ -818,8 +818,9 @@ static int is_booting(void)
|
||||||
|
|
||||||
static void process_firmware_event(struct uevent *uevent)
|
static void process_firmware_event(struct uevent *uevent)
|
||||||
{
|
{
|
||||||
char *root, *loading, *data, *file1 = NULL, *file2 = NULL, *file3 = NULL;
|
char *root, *loading, *data;
|
||||||
int l, loading_fd, data_fd, fw_fd;
|
int l, loading_fd, data_fd, fw_fd;
|
||||||
|
size_t i;
|
||||||
int booting = is_booting();
|
int booting = is_booting();
|
||||||
|
|
||||||
INFO("firmware: loading '%s' for '%s'\n",
|
INFO("firmware: loading '%s' for '%s'\n",
|
||||||
|
|
@ -837,62 +838,49 @@ static void process_firmware_event(struct uevent *uevent)
|
||||||
if (l == -1)
|
if (l == -1)
|
||||||
goto loading_free_out;
|
goto loading_free_out;
|
||||||
|
|
||||||
l = asprintf(&file1, FIRMWARE_DIR1"/%s", uevent->firmware);
|
|
||||||
if (l == -1)
|
|
||||||
goto data_free_out;
|
|
||||||
|
|
||||||
l = asprintf(&file2, FIRMWARE_DIR2"/%s", uevent->firmware);
|
|
||||||
if (l == -1)
|
|
||||||
goto data_free_out;
|
|
||||||
|
|
||||||
l = asprintf(&file3, FIRMWARE_DIR3"/%s", uevent->firmware);
|
|
||||||
if (l == -1)
|
|
||||||
goto data_free_out;
|
|
||||||
|
|
||||||
loading_fd = open(loading, O_WRONLY|O_CLOEXEC);
|
loading_fd = open(loading, O_WRONLY|O_CLOEXEC);
|
||||||
if(loading_fd < 0)
|
if(loading_fd < 0)
|
||||||
goto file_free_out;
|
goto data_free_out;
|
||||||
|
|
||||||
data_fd = open(data, O_WRONLY|O_CLOEXEC);
|
data_fd = open(data, O_WRONLY|O_CLOEXEC);
|
||||||
if(data_fd < 0)
|
if(data_fd < 0)
|
||||||
goto loading_close_out;
|
goto loading_close_out;
|
||||||
|
|
||||||
try_loading_again:
|
try_loading_again:
|
||||||
fw_fd = open(file1, O_RDONLY|O_CLOEXEC);
|
for (i = 0; i < ARRAY_SIZE(firmware_dirs); i++) {
|
||||||
if(fw_fd < 0) {
|
char *file = NULL;
|
||||||
fw_fd = open(file2, O_RDONLY|O_CLOEXEC);
|
l = asprintf(&file, "%s/%s", firmware_dirs[i], uevent->firmware);
|
||||||
if (fw_fd < 0) {
|
if (l == -1)
|
||||||
fw_fd = open(file3, O_RDONLY|O_CLOEXEC);
|
goto data_free_out;
|
||||||
if (fw_fd < 0) {
|
fw_fd = open(file, O_RDONLY|O_CLOEXEC);
|
||||||
if (booting) {
|
free(file);
|
||||||
/* If we're not fully booted, we may be missing
|
if (fw_fd >= 0) {
|
||||||
* filesystems needed for firmware, wait and retry.
|
if(!load_firmware(fw_fd, loading_fd, data_fd))
|
||||||
*/
|
INFO("firmware: copy success { '%s', '%s' }\n", root, uevent->firmware);
|
||||||
usleep(100000);
|
else
|
||||||
booting = is_booting();
|
INFO("firmware: copy failure { '%s', '%s' }\n", root, uevent->firmware);
|
||||||
goto try_loading_again;
|
break;
|
||||||
}
|
|
||||||
INFO("firmware: could not open '%s' %d\n", uevent->firmware, errno);
|
|
||||||
write(loading_fd, "-1", 2);
|
|
||||||
goto data_close_out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (fw_fd < 0) {
|
||||||
if(!load_firmware(fw_fd, loading_fd, data_fd))
|
if (booting) {
|
||||||
INFO("firmware: copy success { '%s', '%s' }\n", root, uevent->firmware);
|
/* If we're not fully booted, we may be missing
|
||||||
else
|
* filesystems needed for firmware, wait and retry.
|
||||||
INFO("firmware: copy failure { '%s', '%s' }\n", root, uevent->firmware);
|
*/
|
||||||
|
usleep(100000);
|
||||||
|
booting = is_booting();
|
||||||
|
goto try_loading_again;
|
||||||
|
}
|
||||||
|
INFO("firmware: could not open '%s' %d\n", uevent->firmware, errno);
|
||||||
|
write(loading_fd, "-1", 2);
|
||||||
|
goto data_close_out;
|
||||||
|
}
|
||||||
|
|
||||||
close(fw_fd);
|
close(fw_fd);
|
||||||
data_close_out:
|
data_close_out:
|
||||||
close(data_fd);
|
close(data_fd);
|
||||||
loading_close_out:
|
loading_close_out:
|
||||||
close(loading_fd);
|
close(loading_fd);
|
||||||
file_free_out:
|
|
||||||
free(file1);
|
|
||||||
free(file2);
|
|
||||||
free(file3);
|
|
||||||
data_free_out:
|
data_free_out:
|
||||||
free(data);
|
free(data);
|
||||||
loading_free_out:
|
loading_free_out:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue