From a60d9686f21fdf2549858ca0e728bcef545d73d2 Mon Sep 17 00:00:00 2001 From: Chanho Park Date: Fri, 8 Sep 2023 17:08:56 +0900 Subject: spl: add __noreturn attribute to spl_invoke_atf function spl_invoke_atf function will not be returned to SPL. Thus, we need to set __noreturn function attribute to the function. Signed-off-by: Chanho Park --- common/spl/spl_atf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/spl/spl_atf.c b/common/spl/spl_atf.c index 2c10252834f..3bdd013a35f 100644 --- a/common/spl/spl_atf.c +++ b/common/spl/spl_atf.c @@ -187,10 +187,10 @@ static inline void raw_write_daif(unsigned int daif) __asm__ __volatile__("msr DAIF, %x0\n\t" : : "r" (daif) : "memory"); } -typedef void (*atf_entry_t)(struct bl31_params *params, void *plat_params); +typedef void __noreturn (*atf_entry_t)(struct bl31_params *params, void *plat_params); -static void bl31_entry(uintptr_t bl31_entry, uintptr_t bl32_entry, - uintptr_t bl33_entry, uintptr_t fdt_addr) +static void __noreturn bl31_entry(uintptr_t bl31_entry, uintptr_t bl32_entry, + uintptr_t bl33_entry, uintptr_t fdt_addr) { atf_entry_t atf_entry = (atf_entry_t)bl31_entry; void *bl31_params; @@ -251,7 +251,7 @@ uintptr_t spl_fit_images_get_entry(void *blob, int node) return val; } -void spl_invoke_atf(struct spl_image_info *spl_image) +void __noreturn spl_invoke_atf(struct spl_image_info *spl_image) { uintptr_t bl32_entry = 0; uintptr_t bl33_entry = CONFIG_TEXT_BASE; -- cgit v1.3.1 From 6826c432e35115bbdafc17062733f5030b7f8366 Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Wed, 27 Sep 2023 21:44:13 +0000 Subject: spl: Jump to image at end of board_init_r spl_board_prepare_for_boot() is not called before jumping/invoking atf, optee, opensbi or linux images. Jump to image at the end of board_init_r() to fix this. Signed-off-by: Jonas Karlman Reviewed-by: Simon Glass --- common/spl/spl.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'common') diff --git a/common/spl/spl.c b/common/spl/spl.c index 0cf887fd626..66eeea41a34 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -643,6 +643,8 @@ void board_init_r(gd_t *dummy1, ulong dummy2) BOOT_DEVICE_NONE, BOOT_DEVICE_NONE, }; + typedef void __noreturn (*jump_to_image_t)(struct spl_image_info *); + jump_to_image_t jump_to_image = &jump_to_image_no_args; struct spl_image_info spl_image; int ret, os; @@ -731,20 +733,20 @@ void board_init_r(gd_t *dummy1, ulong dummy2) } 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_image)); - spl_invoke_atf(&spl_image); + jump_to_image = &spl_invoke_atf; } 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_image)); - jump_to_image_optee(&spl_image); + jump_to_image = &jump_to_image_optee; } 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); + jump_to_image = &spl_invoke_opensbi; } 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); + jump_to_image = &jump_to_image_linux; } else { debug("Unsupported OS image.. Jumping nevertheless..\n"); } @@ -784,7 +786,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2) } spl_board_prepare_for_boot(); - jump_to_image_no_args(&spl_image); + jump_to_image(&spl_image); } /* -- cgit v1.3.1 From 6da11cc81ea773d9a1e3059da311c6f2e2aeb6ef Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Fri, 29 Sep 2023 02:47:17 +0200 Subject: stdio: fix stdio_deregister_dev() When copying the name of a stdio device we must ensure that it is NUL terminated before passing it to strcmp() to avoid a buffer overrun. Truncating the name field leads to failure to deregister a stdio device. When copying we must ensure that the name field sizes match. Addresses-Coverity-ID: 350462 String not null terminated Fixes: 5294e97832a6 ("stdio: extend "name" to 32 symbols") Signed-off-by: Heinrich Schuchardt Reviewed-by: Simon Glass --- common/stdio.c | 6 +++--- include/stdio_dev.h | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/stdio.c b/common/stdio.c index 010bf576af0..e3354f092dc 100644 --- a/common/stdio.c +++ b/common/stdio.c @@ -259,7 +259,7 @@ int stdio_register(struct stdio_dev *dev) int stdio_deregister_dev(struct stdio_dev *dev, int force) { struct list_head *pos; - char temp_names[3][16]; + char temp_names[3][STDIO_NAME_LEN]; int i; /* get stdio devices (ListRemoveItem changes the dev list) */ @@ -272,8 +272,8 @@ int stdio_deregister_dev(struct stdio_dev *dev, int force) /* Device is assigned -> report error */ return -EBUSY; } - memcpy(&temp_names[i][0], stdio_devices[i]->name, - sizeof(temp_names[i])); + strlcpy(&temp_names[i][0], stdio_devices[i]->name, + sizeof(temp_names[i])); } list_del(&dev->list); diff --git a/include/stdio_dev.h b/include/stdio_dev.h index 7f181020524..4e3c4708f80 100644 --- a/include/stdio_dev.h +++ b/include/stdio_dev.h @@ -17,6 +17,7 @@ #define DEV_FLAGS_INPUT 0x00000001 /* Device can be used as input console */ #define DEV_FLAGS_OUTPUT 0x00000002 /* Device can be used as output console */ #define DEV_FLAGS_DM 0x00000004 /* Device priv is a struct udevice * */ +#define STDIO_NAME_LEN 32 int stdio_file_to_flags(const int file); @@ -24,7 +25,7 @@ int stdio_file_to_flags(const int file); struct stdio_dev { int flags; /* Device flags: input/output/system */ int ext; /* Supported extensions */ - char name[32]; /* Device name */ + char name[STDIO_NAME_LEN]; /* Device name */ /* GENERAL functions */ -- cgit v1.3.1