diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-10-10 08:11:22 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-10-11 16:46:25 +0200 |
commit | 8513703c6c46428908264923260504ce81e3e3a7 (patch) | |
tree | c0960258fa50fe8c8933b1214fd52cf5dd3bd3c1 /common | |
parent | 47cacd4d9818e02f203f83d5cc4a205f6185cb07 (diff) | |
download | barebox-8513703c6c46428908264923260504ce81e3e3a7.tar.gz barebox-8513703c6c46428908264923260504ce81e3e3a7.tar.xz |
common: bootm: use switch-case
The switch statement is more readable and lends itself to be easily
extended for future file types, e.g. PE/COFF for EFI loading.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20221010061122.2084009-11-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r-- | common/bootm.c | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/common/bootm.c b/common/bootm.c index f507aece8c..fb1ed36a26 100644 --- a/common/bootm.c +++ b/common/bootm.c @@ -577,16 +577,19 @@ static int bootm_open_fit(struct image_data *data) static int bootm_open_elf(struct image_data *data) { + struct elf_image *elf; + if (!IS_ENABLED(CONFIG_ELF)) return -ENOSYS; - data->elf = elf_open(data->os_file); - if (IS_ERR(data->elf)) - return PTR_ERR(data->elf); + elf = elf_open(data->os_file); + if (IS_ERR(elf)) + return PTR_ERR(elf); - pr_info("Entry Point: %08llx\n", data->elf->entry); + pr_info("Entry Point: %08llx\n", elf->entry); - data->os_address = data->elf->entry; + data->os_address = elf->entry; + data->elf = elf; return 0; } @@ -689,29 +692,25 @@ int bootm_boot(struct bootm_data *bootm_data) } } - if (os_type == filetype_oftree) { + switch (os_type) { + case filetype_oftree: ret = bootm_open_fit(data); - if (ret) - return ret; - } - - if (os_type == filetype_uimage) { + break; + case filetype_uimage: ret = bootm_open_os_uimage(data); - if (ret) { - pr_err("Loading OS image failed with: %s\n", - strerror(-ret)); - goto err_out; - } + break; + case filetype_elf: + ret = bootm_open_elf(data); + break; + default: + ret = 0; + break; } - if (os_type == filetype_elf) { - ret = bootm_open_elf(data); - if (ret) { - pr_err("Loading ELF image failed with: %s\n", - strerror(-ret)); - data->elf = NULL; - goto err_out; - } + if (ret) { + pr_err("Loading %s image failed with: %pe\n", + file_type_to_short_string(os_type), ERR_PTR(ret)); + goto err_out; } if (bootm_data->appendroot) { |