From 1ec3ee670de6b2f8f96cd7c15f7e22e89a06bb2d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Mar 2026 19:36:13 -0700 Subject: bootm: Create bootm_final() for pre-boot cleanup There are various functions which announce that booting is imminent and do related preparation. Most of these are arch-specific. In practice, most archs do a similar thing. It would be better to have a common function, with perhaps some events for things that are really arch- and board-specific. Create a new bootm_final() function with the common pre-boot steps: printing the "Starting kernel" message, recording bootstage data, optionally writing bootstage to the FDT and printing a report, and removing active devices. Be careful to avoid using BIT() macros which are not available with host tools. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- boot/bootm.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'boot') diff --git a/boot/bootm.c b/boot/bootm.c index 4bdca22ea8c..cba10b5dce7 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -7,6 +7,7 @@ #ifndef USE_HOSTCC #include #include +#include #include #include #include @@ -1194,6 +1195,27 @@ void __weak switch_to_non_secure_mode(void) { } +void bootm_final(int flag) +{ + printf("\nStarting kernel ...%s\n\n", + (flag & BOOTM_STATE_OS_FAKE_GO) ? + " (fake run for tracing)" : ""); + + bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); + + if (IS_ENABLED(CONFIG_BOOTSTAGE_FDT) && IS_ENABLED(CONFIG_CMD_FDT)) + bootstage_fdt_add_report(); + if (IS_ENABLED(CONFIG_BOOTSTAGE_REPORT)) + bootstage_report(); + + /* + * Call remove function of all devices with a removal flag set. + * This may be useful for last-stage operations, like cancelling + * of DMA operation or releasing device internal buffers. + */ + dm_remove_devices_active(); +} + #else /* USE_HOSTCC */ #if defined(CONFIG_FIT_SIGNATURE) -- cgit v1.3.1 From aa5ada5447369849c82310073270ed64df1efd9b Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Mar 2026 19:36:15 -0700 Subject: riscv: Call bootm_final() The RISC-V announce_and_cleanup() duplicates the common pre-boot steps. Replace it with a call to bootm_final(). Move board_quiesce_devices() into bootm_final() so it is available to all architectures. Drop the RISC-V weak definition and header declaration since the generic one in bootm.h is used instead. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- arch/riscv/include/asm/u-boot-riscv.h | 1 - arch/riscv/lib/bootm.c | 39 +++-------------------------------- boot/bootm.c | 2 ++ 3 files changed, 5 insertions(+), 37 deletions(-) (limited to 'boot') diff --git a/arch/riscv/include/asm/u-boot-riscv.h b/arch/riscv/include/asm/u-boot-riscv.h index 543a1688db8..3a8fdb57136 100644 --- a/arch/riscv/include/asm/u-boot-riscv.h +++ b/arch/riscv/include/asm/u-boot-riscv.h @@ -16,7 +16,6 @@ int cleanup_before_linux(void); /* board/.../... */ int board_init(void); -void board_quiesce_devices(void); int riscv_board_reserved_mem_fixup(void *fdt); int riscv_fdt_copy_resv_mem_node(const void *src_fdt, void *dest_fdt); diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index 9544907ab1e..69c9ca5c487 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -25,39 +25,6 @@ DECLARE_GLOBAL_DATA_PTR; -__weak void board_quiesce_devices(void) -{ -} - -/** - * announce_and_cleanup() - Print message and prepare for kernel boot - * - * @fake: non-zero to do everything except actually boot - */ -static void announce_and_cleanup(int fake) -{ - printf("\nStarting kernel ...%s\n\n", fake ? - "(fake run for tracing)" : ""); - bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); -#ifdef CONFIG_BOOTSTAGE_FDT - bootstage_fdt_add_report(); -#endif -#if CONFIG_IS_ENABLED(BOOTSTAGE_REPORT) - bootstage_report(); -#endif - - board_quiesce_devices(); - - /* - * Call remove function of all devices with a removal flag set. - * This may be useful for last-stage operations, like cancelling - * of DMA operation or releasing device internal buffers. - */ - dm_remove_devices_active(); - - cleanup_before_linux(); -} - static void boot_prep_linux(struct bootm_headers *images) { if (CONFIG_IS_ENABLED(OF_LIBFDT) && IS_ENABLED(CONFIG_LMB) && images->ft_len) { @@ -75,7 +42,6 @@ static void boot_prep_linux(struct bootm_headers *images) static void boot_jump_linux(struct bootm_headers *images, int flag) { void (*kernel)(ulong hart, void *dtb); - int fake = (flag & BOOTM_STATE_OS_FAKE_GO); #ifdef CONFIG_SMP int ret; #endif @@ -87,9 +53,10 @@ static void boot_jump_linux(struct bootm_headers *images, int flag) debug("## Transferring control to kernel (at address %08lx) ...\n", (ulong)kernel); - announce_and_cleanup(fake); + bootm_final(flag); + cleanup_before_linux(); - if (!fake) { + if (!(flag & BOOTM_STATE_OS_FAKE_GO)) { if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) { #ifdef CONFIG_SMP ret = smp_call_function(images->ep, diff --git a/boot/bootm.c b/boot/bootm.c index cba10b5dce7..e553497192c 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1208,6 +1208,8 @@ void bootm_final(int flag) if (IS_ENABLED(CONFIG_BOOTSTAGE_REPORT)) bootstage_report(); + board_quiesce_devices(); + /* * Call remove function of all devices with a removal flag set. * This may be useful for last-stage operations, like cancelling -- cgit v1.3.1 From 5759155b023e93c24268911a8a40110ec4b13dd9 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Thu, 5 Mar 2026 19:36:16 -0700 Subject: bootm: Stash bootstage data in bootm_final() ARM stashes bootstage data to a known memory location before booting, so the kernel can pick it up. Add this to bootm_final() so all architectures benefit from it. The bootstage_stash_default() function is a no-op when bootstage or stashing is disabled. Signed-off-by: Simon Glass Reviewed-by: Tom Rini --- boot/bootm.c | 1 + 1 file changed, 1 insertion(+) (limited to 'boot') diff --git a/boot/bootm.c b/boot/bootm.c index e553497192c..c42f3b925bc 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1205,6 +1205,7 @@ void bootm_final(int flag) if (IS_ENABLED(CONFIG_BOOTSTAGE_FDT) && IS_ENABLED(CONFIG_CMD_FDT)) bootstage_fdt_add_report(); + bootstage_stash_default(); if (IS_ENABLED(CONFIG_BOOTSTAGE_REPORT)) bootstage_report(); -- cgit v1.3.1