aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2023-09-26 08:14:22 -0600
committerTom Rini <trini@konsulko.com>2023-09-26 11:25:24 -0400
commitedba69045dfdc3710964ff4cbeb31ea245bff53e (patch)
tree2e8adfc08f06f3131fac5bc5dbf629bb3845bd1c
parent41604bb5beadd3d152a8b0618453d8c522ae1a60 (diff)
downloadu-boot-edba69045dfdc3710964ff4cbeb31ea245bff53e.zip
u-boot-edba69045dfdc3710964ff4cbeb31ea245bff53e.tar.gz
u-boot-edba69045dfdc3710964ff4cbeb31ea245bff53e.tar.bz2
spl: Drop the switch() statement for OS selection
This code is pretty ugly, with many #ifdefs There are quite a lot of IH_OS_U_BOOT values so the compiler struggles to create a jump table here. Also, most of the options are normally disabled. Change it to an else...if construct instead. Add an accessor for the spl_image field behind an #ifdef to avoid needing #ifdef in the C code. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--common/spl/spl.c32
-rw-r--r--include/spl.h9
2 files changed, 19 insertions, 22 deletions
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 117a6c7..e270edb 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -748,7 +748,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
BOOT_DEVICE_NONE,
};
struct spl_image_info spl_image;
- int ret;
+ int ret, os;
debug(">>" SPL_TPL_PROMPT "board_init_r()\n");
@@ -841,39 +841,27 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
ret);
}
- switch (spl_image.os) {
- case IH_OS_U_BOOT:
+ os = spl_image.os;
+ if (os == IH_OS_U_BOOT) {
debug("Jumping to %s...\n", spl_phase_name(spl_next_phase()));
- break;
-#if CONFIG_IS_ENABLED(ATF)
- case IH_OS_ARM_TRUSTED_FIRMWARE:
+ } else if (CONFIG_IS_ENABLED(ATF) && os == IH_OS_ARM_TRUSTED_FIRMWARE) {
debug("Jumping to U-Boot via ARM Trusted Firmware\n");
- spl_fixup_fdt(spl_image.fdt_addr);
+ spl_fixup_fdt(spl_image_fdt_addr(&spl_image));
spl_invoke_atf(&spl_image);
- break;
-#endif
-#if CONFIG_IS_ENABLED(OPTEE_IMAGE)
- case IH_OS_TEE:
+ } else if (CONFIG_IS_ENABLED(OPTEE_IMAGE) && os == IH_OS_TEE) {
debug("Jumping to U-Boot via OP-TEE\n");
- spl_board_prepare_for_optee(spl_image.fdt_addr);
+ spl_board_prepare_for_optee(spl_image_fdt_addr(&spl_image));
jump_to_image_optee(&spl_image);
- break;
-#endif
-#if CONFIG_IS_ENABLED(OPENSBI)
- case IH_OS_OPENSBI:
+ } else if (CONFIG_IS_ENABLED(OPENSBI) && os == IH_OS_OPENSBI) {
debug("Jumping to U-Boot via RISC-V OpenSBI\n");
spl_invoke_opensbi(&spl_image);
- break;
-#endif
-#if CONFIG_IS_ENABLED(OS_BOOT)
- case IH_OS_LINUX:
+ } else if (CONFIG_IS_ENABLED(OS_BOOT) && os == IH_OS_LINUX) {
debug("Jumping to Linux\n");
if (IS_ENABLED(CONFIG_SPL_OS_BOOT))
spl_fixup_fdt((void *)SPL_PAYLOAD_ARGS_ADDR);
spl_board_prepare_for_linux();
jump_to_image_linux(&spl_image);
-#endif
- default:
+ } else {
debug("Unsupported OS image.. Jumping nevertheless..\n");
}
#if CONFIG_VAL(SYS_MALLOC_F_LEN) && !defined(CONFIG_SPL_SYS_MALLOC_SIZE)
diff --git a/include/spl.h b/include/spl.h
index d16cea3..60b55b7 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -263,6 +263,15 @@ struct spl_image_info {
#endif
};
+static inline void *spl_image_fdt_addr(struct spl_image_info *info)
+{
+#if CONFIG_IS_ENABLED(LOAD_FIT) || CONFIG_IS_ENABLED(LOAD_FIT_FULL)
+ return info->fdt_addr;
+#else
+ return 0;
+#endif
+}
+
/**
* Information required to load data from a device
*