[PATCH 00/19] bootm: Clean up arch-specific, pre-OS clean-up

From: Simon Glass <sjg@chromium.org> Each arch does something slightly different before booting the OS. Some archs even do different things depending on the CPU type. EFT_LOADER has its own special code, regardless of which arch is being booted. It is quite hard to know what actually happens in the final milliseconds before the OS boot. This series attempts to clean up U-Boot in this area. The basic approach is to create a new bootm_final() function which is called by all archs. It provides some flags for a couple of necessary variations but otherwise it is generic. RISC-V, x86 and ARM are converted over to use this new function. For consistency, EFI loader is converted as well. A noteable change is that EFI_LOADER now does bootstage processing before boot, if enabled, thus producing a report. Future work could take this a little further: - Drop board_quiesce_devices() and rely on driver model for that - Similarly with udc_disconnect() - cleanup_before_linux() could use more details as to what it is supposed to do, to reduce the number of arch-specific variations Simon Glass (19): test: Only show the timing summary if test actually run boot: Create a function for final pre-boot steps efi: Make use of bootm_final() bootm: Add a message when booting bootstage: Add some missing dummy functions bootm: Do bootstage processing in bootm_final() x86: Call bootm_final() riscv: Drop board_quiesce_devices() riscv: Call bootm_final() efi: Drop EFI_GRUB_ARM32_WORKAROUND x86: Add cleanup_before_linux() bootm: Move cleanup_before_linux() to bootm.h bootm: Call cleanup_before_linux() from bootm_final() bootm: Move board_quiesce_devices(void) to bootm_final() bootm: Drop re-enabling of interrupts on error bootm: Move bootm_disable_interrupts() to bootm_final() arm: Drop announce_and_cleanup() riscv: Drop announce_and_cleanup() x86: Drop bootm_announce_and_cleanup() MAINTAINERS | 1 + arch/arc/lib/bootm.c | 2 +- arch/arm/cpu/arm11/cpu.c | 3 +- arch/arm/cpu/arm720t/cpu.c | 2 + arch/arm/cpu/arm920t/cpu.c | 3 +- arch/arm/cpu/arm926ejs/cpu.c | 3 +- arch/arm/cpu/arm946es/cpu.c | 3 +- arch/arm/cpu/armv7/cpu.c | 1 + arch/arm/cpu/armv7m/cpu.c | 1 + arch/arm/cpu/armv8/cpu.c | 1 + arch/arm/include/asm/u-boot-arm.h | 3 -- arch/arm/lib/bootm.c | 39 +------------------ arch/arm/lib/spl.c | 1 + arch/arm/mach-rockchip/spl.c | 1 + arch/riscv/cpu/andes/cpu.c | 1 + arch/riscv/cpu/ast2700/cpu.c | 1 + arch/riscv/cpu/cv1800b/cpu.c | 2 + arch/riscv/cpu/fu540/cpu.c | 1 + arch/riscv/cpu/fu740/cpu.c | 1 + arch/riscv/cpu/generic/cpu.c | 1 + arch/riscv/cpu/jh7110/cpu.c | 1 + arch/riscv/include/asm/u-boot-riscv.h | 4 -- arch/riscv/lib/boot.c | 1 + arch/riscv/lib/bootm.c | 39 +------------------ arch/sandbox/cpu/cpu.c | 1 + arch/sandbox/include/asm/u-boot-sandbox.h | 2 - arch/sh/cpu/sh4/cpu.c | 1 + arch/x86/cpu/cpu.c | 7 +++- arch/x86/include/asm/bootm.h | 2 - arch/x86/include/asm/u-boot-x86.h | 2 - arch/x86/lib/bootm.c | 25 ++---------- boot/Makefile | 2 +- boot/bootm.c | 11 ------ boot/bootm_final.c | 47 +++++++++++++++++++++++ cmd/booti.c | 6 --- configs/mt7623n_bpir2_defconfig | 1 - drivers/net/fsl-mc/mc.c | 2 +- include/bootm.h | 21 ++++++++++ include/bootstage.h | 8 ++++ lib/efi_loader/Kconfig | 10 ----- lib/efi_loader/efi_boottime.c | 35 +---------------- test/boot/bootflow.c | 6 ++- test/py/conftest.py | 3 +- 43 files changed, 128 insertions(+), 180 deletions(-) create mode 100644 boot/bootm_final.c -- 2.43.0 base-commit: 62c19a204ff8b95e63e2f9afdec0283571f9b864 branch: qemj

From: Simon Glass <sjg@chromium.org> If there is a failure before any test manages to run, the timing summary will not be present. Handle this case to avoid a strange exception. Signed-off-by: Simon Glass <sjg@chromium.org> --- test/py/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/py/conftest.py b/test/py/conftest.py index 5074444731c..4460e5a3af2 100644 --- a/test/py/conftest.py +++ b/test/py/conftest.py @@ -31,6 +31,7 @@ import time # Globals: The HTML log file, and the top-level fixture log = None ubman_fix = None +ubconfig = None TEST_PY_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -613,7 +614,7 @@ def show_timings(): if too_long: show_bar(f'>{get_time_delta(max_dur)}', too_long_msecs, too_long) log.info(buf.getvalue()) - if ubconfig.timing: + if ubconfig and hasattr(ubconfig, 'timing'): print(buf.getvalue(), end='') -- 2.43.0

From: Simon Glass <sjg@chromium.org> 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 the 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 function for this. For now, nothing uses it. Signed-off-by: Simon Glass <sjg@chromium.org> --- MAINTAINERS | 1 + boot/Makefile | 2 +- boot/bootm_final.c | 12 ++++++++++++ include/bootm.h | 17 +++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 boot/bootm_final.c diff --git a/MAINTAINERS b/MAINTAINERS index 70b06c71d2e..3d19c6cc8be 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -941,6 +941,7 @@ M: Simon Glass <sjg@chromium.org> S: Maintained F: boot/bootdev*.c F: boot/bootflow.c +F: boot/bootm_final.c F: boot/bootmeth*.c F: boot/bootstd.c F: cmd/bootdev.c diff --git a/boot/Makefile b/boot/Makefile index 2b41b92230d..f4968cdcf7e 100644 --- a/boot/Makefile +++ b/boot/Makefile @@ -12,7 +12,7 @@ obj-$(CONFIG_PXE_UTILS) += pxe_utils.o endif -obj-y += image.o image-board.o +obj-y += image.o image-board.o bootm_final.o obj-$(CONFIG_ANDROID_AB) += android_ab.o obj-$(CONFIG_ANDROID_BOOT_IMAGE) += image-android.o image-android-dt.o diff --git a/boot/bootm_final.c b/boot/bootm_final.c new file mode 100644 index 00000000000..15ddbbe5e74 --- /dev/null +++ b/boot/bootm_final.c @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Cleanup before handing off to the OS + * + * Copyright 2025 Simon Glass <sjg@chromium.org> + */ + +#include <bootm.h> + +void bootm_final(enum bootm_final_t flags) +{ +} diff --git a/include/bootm.h b/include/bootm.h index f010a3ecfa2..05d55b2d948 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -16,6 +16,16 @@ struct cmd_tbl; #define BOOTM_ERR_OVERLAP (-2) #define BOOTM_ERR_UNIMPLEMENTED (-3) +/** + * enum bootm_final_t - flags to control bootm_final() + * + * @BOOTM_FINAL_FAKE: true to do everything except actually boot; it then + * returns to the caller + */ +enum bootm_final_t { + BOOTM_FINAL_FAKE = BIT(0), +}; + /** * struct bootm_info() - information used when processing images to boot * @@ -375,4 +385,11 @@ void zimage_dump(struct bootm_info *bmi, bool show_cmdline); */ int bootm_boot_start(ulong addr, const char *cmdline); +/** + * bootm_final() - Announce and do cleanup before boot + * + * @flags: Flags to control what this function does + */ +void bootm_final(enum bootm_final_t flags); + #endif -- 2.43.0

From: Simon Glass <sjg@chromium.org> Call this function from the EFI code. Add the required call to dm_remove_devices_active() there. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/bootm_final.c | 2 ++ lib/efi_loader/efi_boottime.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/boot/bootm_final.c b/boot/bootm_final.c index 15ddbbe5e74..263cd95dcb3 100644 --- a/boot/bootm_final.c +++ b/boot/bootm_final.c @@ -6,7 +6,9 @@ */ #include <bootm.h> +#include <dm/root.h> void bootm_final(enum bootm_final_t flags) { + dm_remove_devices_active(); } diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index c51694399e7..36012c177a6 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2256,7 +2256,7 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle, if (IS_ENABLED(CONFIG_USB_DEVICE)) udc_disconnect(); board_quiesce_devices(); - dm_remove_devices_active(); + bootm_final(0); } /* Patch out unsupported runtime function */ -- 2.43.0

From: Simon Glass <sjg@chromium.org> Add a message about starting the kernel. For EFI this will be printed when boot-services are exited. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/bootm_final.c | 2 ++ test/boot/bootflow.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/boot/bootm_final.c b/boot/bootm_final.c index 263cd95dcb3..71661334e11 100644 --- a/boot/bootm_final.c +++ b/boot/bootm_final.c @@ -10,5 +10,7 @@ void bootm_final(enum bootm_final_t flags) { + printf("\nStarting kernel ...\n\n"); + dm_remove_devices_active(); } diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index cac5e0b1a35..7034bef1f05 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -1335,6 +1335,9 @@ static int bootflow_efi(struct unit_test_state *uts) /* TODO: Why the \r ? */ ut_assert_nextline("U-Boot test app for EFI_LOADER\r"); ut_assert_nextline("Exiting boot services"); + ut_assert_nextline_empty(); + ut_assert_nextline("Starting kernel ..."); + ut_assert_nextline_empty(); ut_assert_nextline("Exiting test app"); ut_assert_nextline("Boot failed (err=-14)"); -- 2.43.0

From: Simon Glass <sjg@chromium.org> Neither bootstage_fdt_add_report() nor bootstage_report() has a dummy double for when bootstate is disabled. Add them. Signed-off-by: Simon Glass <sjg@chromium.org> --- include/bootstage.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/bootstage.h b/include/bootstage.h index 3300ca0248a..9471c5d770f 100644 --- a/include/bootstage.h +++ b/include/bootstage.h @@ -435,6 +435,14 @@ static inline uint32_t bootstage_accum(enum bootstage_id id) return 0; } +static inline void bootstage_report(void) +{ +} + +static inline void bootstage_fdt_add_report(void) +{ +} + static inline int bootstage_stash(void *base, int size) { return 0; /* Pretend to succeed */ -- 2.43.0

From: Simon Glass <sjg@chromium.org> Mark kernel start before booting. If enabled, show a bootstage report. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/bootm_final.c | 6 ++++++ test/boot/bootflow.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/boot/bootm_final.c b/boot/bootm_final.c index 71661334e11..dd7cac55f1e 100644 --- a/boot/bootm_final.c +++ b/boot/bootm_final.c @@ -6,11 +6,17 @@ */ #include <bootm.h> +#include <bootstage.h> #include <dm/root.h> void bootm_final(enum bootm_final_t flags) { printf("\nStarting kernel ...\n\n"); + bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); + + if (IS_ENABLED(CONFIG_BOOTSTAGE_REPORT)) + bootstage_report(); + dm_remove_devices_active(); } diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 7034bef1f05..671636e5e21 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -1338,7 +1338,8 @@ static int bootflow_efi(struct unit_test_state *uts) ut_assert_nextline_empty(); ut_assert_nextline("Starting kernel ..."); ut_assert_nextline_empty(); - ut_assert_nextline("Exiting test app"); + ut_assert_nextlinen("Timer summary in microseconds"); + ut_assert_skip_to_line("Exiting test app"); ut_assert_nextline("Boot failed (err=-14)"); ut_assert_console_end(); -- 2.43.0

From: Simon Glass <sjg@chromium.org> The x86 code in bootm_announce_and_cleanup() is very similar to the new bootm_final() function, so just use the latter. Move over a useful comment. Signed-off-by: Simon Glass <sjg@chromium.org> --- arch/x86/lib/bootm.c | 14 +------------- boot/bootm_final.c | 5 +++++ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c index ce4dae871ec..fc408d9685c 100644 --- a/arch/x86/lib/bootm.c +++ b/arch/x86/lib/bootm.c @@ -36,22 +36,10 @@ DECLARE_GLOBAL_DATA_PTR; void bootm_announce_and_cleanup(void) { - printf("\nStarting kernel ...\n\n"); - #ifdef CONFIG_SYS_COREBOOT timestamp_add_now(TS_START_KERNEL); #endif - bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); -#if IS_ENABLED(CONFIG_BOOTSTAGE_REPORT) - bootstage_report(); -#endif - - /* - * 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(); + bootm_final(0); } #if defined(CONFIG_OF_LIBFDT) && !defined(CONFIG_OF_NO_KERNEL) diff --git a/boot/bootm_final.c b/boot/bootm_final.c index dd7cac55f1e..7077702d8c7 100644 --- a/boot/bootm_final.c +++ b/boot/bootm_final.c @@ -18,5 +18,10 @@ void bootm_final(enum bootm_final_t flags) 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(); } -- 2.43.0

From: Simon Glass <sjg@chromium.org> This is not used on RISC-V so drop it. Signed-off-by: Simon Glass <sjg@chromium.org> --- arch/riscv/include/asm/u-boot-riscv.h | 1 - arch/riscv/lib/bootm.c | 6 ------ 2 files changed, 7 deletions(-) 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 76c610bcee0..35403e03ab0 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -25,10 +25,6 @@ DECLARE_GLOBAL_DATA_PTR; -__weak void board_quiesce_devices(void) -{ -} - /** * announce_and_cleanup() - Print message and prepare for kernel boot * @@ -50,8 +46,6 @@ static void announce_and_cleanup(int fake) udc_disconnect(); #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 -- 2.43.0

From: Simon Glass <sjg@chromium.org> Make use of this function, adding some pieces needed by RISC-V Drop the udc_disconnect() from EFI_LOADER since it is now done in bootm_final() Signed-off-by: Simon Glass <sjg@chromium.org> --- arch/riscv/lib/bootm.c | 22 +--------------------- boot/bootm_final.c | 9 ++++++++- lib/efi_loader/efi_boottime.c | 2 -- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index 35403e03ab0..bd47275b52e 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -32,27 +32,7 @@ DECLARE_GLOBAL_DATA_PTR; */ 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 - -#ifdef CONFIG_USB_DEVICE - udc_disconnect(); -#endif - - /* - * 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(); - + bootm_final(fake); cleanup_before_linux(); } diff --git a/boot/bootm_final.c b/boot/bootm_final.c index 7077702d8c7..7f069877d06 100644 --- a/boot/bootm_final.c +++ b/boot/bootm_final.c @@ -7,17 +7,24 @@ #include <bootm.h> #include <bootstage.h> +#include <usb.h> #include <dm/root.h> void bootm_final(enum bootm_final_t flags) { - printf("\nStarting kernel ...\n\n"); + printf("\nStarting kernel ...%s\n\n", flags & BOOTM_FINAL_FAKE ? + "(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(); + if (IS_ENABLED(CONFIG_USB_DEVICE)) + udc_disconnect(); + /* * Call remove function of all devices with a removal flag set. * This may be useful for last-stage operations, like cancelling diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 36012c177a6..c1634cb0203 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2253,8 +2253,6 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle, if (!efi_st_keep_devices) { bootm_disable_interrupts(); - if (IS_ENABLED(CONFIG_USB_DEVICE)) - udc_disconnect(); board_quiesce_devices(); bootm_final(0); } -- 2.43.0

From: Simon Glass <sjg@chromium.org> This work-around dates from 2019 and grub 2.04 which is quite old. New builds of grub don't have the problem and old boards presumably use an older U-Boot, so don't need this. Drop it. Signed-off-by: Simon Glass <sjg@chromium.org> --- configs/mt7623n_bpir2_defconfig | 1 - lib/efi_loader/Kconfig | 10 ---------- lib/efi_loader/efi_boottime.c | 26 -------------------------- 3 files changed, 37 deletions(-) diff --git a/configs/mt7623n_bpir2_defconfig b/configs/mt7623n_bpir2_defconfig index 42da25ee4ca..44ebbc8e56e 100644 --- a/configs/mt7623n_bpir2_defconfig +++ b/configs/mt7623n_bpir2_defconfig @@ -13,7 +13,6 @@ CONFIG_DEFAULT_DEVICE_TREE="mt7623n-bananapi-bpi-r2" CONFIG_TARGET_MT7623=y CONFIG_SYS_BOOTM_LEN=0x4000000 CONFIG_SYS_LOAD_ADDR=0x84000000 -# CONFIG_EFI_GRUB_ARM32_WORKAROUND is not set CONFIG_FIT=y CONFIG_FIT_VERBOSE=y CONFIG_DISTRO_DEFAULTS=y diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index a10c0a819f5..80549382694 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -498,16 +498,6 @@ config EFI_LOADER_BOUNCE_BUFFER hardware we can create a bounce buffer so that payloads don't have to worry about platform details. -config EFI_GRUB_ARM32_WORKAROUND - bool "Workaround for GRUB on 32bit ARM" - default n if ARCH_BCM283X || ARCH_SUNXI || ARCH_QEMU_ARM - default y - depends on ARM && !ARM64 - help - GRUB prior to version 2.04 requires U-Boot to disable caches. This - workaround currently is also needed on systems with caches that - cannot be managed via CP15. - config EFI_ESRT bool "Enable the UEFI ESRT generation" depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index c1634cb0203..d90f9020ccb 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2154,29 +2154,6 @@ error: return EFI_EXIT(ret); } -/** - * efi_exit_caches() - fix up caches for EFI payloads if necessary - */ -static void efi_exit_caches(void) -{ -#if defined(CONFIG_EFI_GRUB_ARM32_WORKAROUND) - /* - * Boooting Linux via GRUB prior to version 2.04 fails on 32bit ARM if - * caches are enabled. - * - * TODO: - * According to the UEFI spec caches that can be managed via CP15 - * operations should be enabled. Caches requiring platform information - * to manage should be disabled. This should not happen in - * ExitBootServices() but before invoking any UEFI binary is invoked. - * - * We want to keep the current workaround while GRUB prior to version - * 2.04 is still in use. - */ - cleanup_before_linux(); -#endif -} - /** * efi_exit_boot_services() - stop all boot services * @image_handle: handle of the loaded image @@ -2260,9 +2237,6 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle, /* Patch out unsupported runtime function */ efi_runtime_detach(); - /* Fix up caches for EFI payloads if necessary */ - efi_exit_caches(); - /* Disable boot time services */ systab.con_in_handle = NULL; systab.con_in = NULL; -- 2.43.0

From: Simon Glass <sjg@chromium.org> This function is not present on x86, but there is an x86-specific version which is never called. Add the former, making it call the latter. Signed-off-by: Simon Glass <sjg@chromium.org> --- arch/x86/cpu/cpu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c index c373b14df30..f756a9ebf09 100644 --- a/arch/x86/cpu/cpu.c +++ b/arch/x86/cpu/cpu.c @@ -80,6 +80,11 @@ int __weak x86_cleanup_before_linux(void) return 0; } +int cleanup_before_linux(void) +{ + return x86_cleanup_before_linux(); +} + int x86_init_cache(void) { enable_caches(); -- 2.43.0

From: Simon Glass <sjg@chromium.org> Move the declaration of this function to a common header. Make sure it is included by files which define it. Fix up a few whitespace problems while here. Signed-off-by: Simon Glass <sjg@chromium.org> --- arch/arc/lib/bootm.c | 2 +- arch/arm/cpu/arm11/cpu.c | 3 ++- arch/arm/cpu/arm720t/cpu.c | 2 ++ arch/arm/cpu/arm920t/cpu.c | 3 ++- arch/arm/cpu/arm926ejs/cpu.c | 3 ++- arch/arm/cpu/arm946es/cpu.c | 3 ++- arch/arm/cpu/armv7/cpu.c | 1 + arch/arm/cpu/armv7m/cpu.c | 1 + arch/arm/cpu/armv8/cpu.c | 1 + arch/arm/include/asm/u-boot-arm.h | 3 --- arch/arm/lib/spl.c | 1 + arch/arm/mach-rockchip/spl.c | 1 + arch/riscv/cpu/andes/cpu.c | 1 + arch/riscv/cpu/ast2700/cpu.c | 1 + arch/riscv/cpu/cv1800b/cpu.c | 2 ++ arch/riscv/cpu/fu540/cpu.c | 1 + arch/riscv/cpu/fu740/cpu.c | 1 + arch/riscv/cpu/generic/cpu.c | 1 + arch/riscv/cpu/jh7110/cpu.c | 1 + arch/riscv/include/asm/u-boot-riscv.h | 3 --- arch/riscv/lib/boot.c | 1 + arch/sandbox/cpu/cpu.c | 1 + arch/sandbox/include/asm/u-boot-sandbox.h | 2 -- arch/sh/cpu/sh4/cpu.c | 1 + arch/x86/include/asm/u-boot-x86.h | 2 -- include/bootm.h | 2 ++ 26 files changed, 29 insertions(+), 15 deletions(-) diff --git a/arch/arc/lib/bootm.c b/arch/arc/lib/bootm.c index b143392ee6c..0be0d40002d 100644 --- a/arch/arc/lib/bootm.c +++ b/arch/arc/lib/bootm.c @@ -14,7 +14,7 @@ DECLARE_GLOBAL_DATA_PTR; -static int cleanup_before_linux(void) +int cleanup_before_linux(void) { disable_interrupts(); sync_n_cleanup_cache_all(); diff --git a/arch/arm/cpu/arm11/cpu.c b/arch/arm/cpu/arm11/cpu.c index 4bf0446b543..0ad6bce60f2 100644 --- a/arch/arm/cpu/arm11/cpu.c +++ b/arch/arm/cpu/arm11/cpu.c @@ -14,6 +14,7 @@ * CPU specific code */ +#include <bootm.h> #include <command.h> #include <cpu_func.h> #include <irq_func.h> @@ -23,7 +24,7 @@ static void cache_flush(void); -int cleanup_before_linux (void) +int cleanup_before_linux(void) { /* * this function is called just before we call linux diff --git a/arch/arm/cpu/arm720t/cpu.c b/arch/arm/cpu/arm720t/cpu.c index ece09c83a4a..2ec4a9cbb89 100644 --- a/arch/arm/cpu/arm720t/cpu.c +++ b/arch/arm/cpu/arm720t/cpu.c @@ -9,6 +9,8 @@ * Alex Zuepke <azu@sysgo.de> */ +#include <bootm.h> + /* * cleanup_before_linux() - Prepare the CPU to jump to Linux * diff --git a/arch/arm/cpu/arm920t/cpu.c b/arch/arm/cpu/arm920t/cpu.c index 61e18230573..73cd65b706a 100644 --- a/arch/arm/cpu/arm920t/cpu.c +++ b/arch/arm/cpu/arm920t/cpu.c @@ -12,6 +12,7 @@ * CPU specific code */ +#include <bootm.h> #include <command.h> #include <cpu_func.h> #include <irq_func.h> @@ -19,7 +20,7 @@ static void cache_flush(void); -int cleanup_before_linux (void) +int cleanup_before_linux(void) { /* * this function is called just before we call linux diff --git a/arch/arm/cpu/arm926ejs/cpu.c b/arch/arm/cpu/arm926ejs/cpu.c index 0e100e6f13d..10e18a41e14 100644 --- a/arch/arm/cpu/arm926ejs/cpu.c +++ b/arch/arm/cpu/arm926ejs/cpu.c @@ -12,6 +12,7 @@ * CPU specific code */ +#include <bootm.h> #include <command.h> #include <cpu_func.h> #include <irq_func.h> @@ -33,7 +34,7 @@ void sdelay(unsigned long loops) "bne 1b":"=r" (loops):"0"(loops)); } -int cleanup_before_linux (void) +int cleanup_before_linux(void) { /* * this function is called just before we call linux diff --git a/arch/arm/cpu/arm946es/cpu.c b/arch/arm/cpu/arm946es/cpu.c index efd232d3423..45a857b7522 100644 --- a/arch/arm/cpu/arm946es/cpu.c +++ b/arch/arm/cpu/arm946es/cpu.c @@ -12,6 +12,7 @@ * CPU specific code */ +#include <bootm.h> #include <command.h> #include <cpu_func.h> #include <irq_func.h> @@ -20,7 +21,7 @@ static void cache_flush(void); -int cleanup_before_linux (void) +int cleanup_before_linux(void) { /* * this function is called just before we call linux diff --git a/arch/arm/cpu/armv7/cpu.c b/arch/arm/cpu/armv7/cpu.c index f1b07c414de..b9f58e69464 100644 --- a/arch/arm/cpu/armv7/cpu.c +++ b/arch/arm/cpu/armv7/cpu.c @@ -14,6 +14,7 @@ * CPU specific code */ +#include <bootm.h> #include <command.h> #include <cpu_func.h> #include <irq_func.h> diff --git a/arch/arm/cpu/armv7m/cpu.c b/arch/arm/cpu/armv7m/cpu.c index b4440d3f3f8..02f3b63fbfb 100644 --- a/arch/arm/cpu/armv7m/cpu.c +++ b/arch/arm/cpu/armv7m/cpu.c @@ -7,6 +7,7 @@ * Kamil Lulko, <kamil.lulko@gmail.com> */ +#include <bootm.h> #include <cpu_func.h> #include <irq_func.h> #include <asm/io.h> diff --git a/arch/arm/cpu/armv8/cpu.c b/arch/arm/cpu/armv8/cpu.c index 275aa2501f1..c22bc02d2bd 100644 --- a/arch/arm/cpu/armv8/cpu.c +++ b/arch/arm/cpu/armv8/cpu.c @@ -10,6 +10,7 @@ * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de> */ +#include <bootm.h> #include <command.h> #include <cpu_func.h> #include <irq_func.h> diff --git a/arch/arm/include/asm/u-boot-arm.h b/arch/arm/include/asm/u-boot-arm.h index aef048708da..895e7a00838 100644 --- a/arch/arm/include/asm/u-boot-arm.h +++ b/arch/arm/include/asm/u-boot-arm.h @@ -25,9 +25,6 @@ extern ulong IRQ_STACK_START_IN; /* 8 bytes in IRQ stack */ void s_init(void); -/* cpu/.../cpu.c */ -int cleanup_before_linux(void); - /* Set up ARMv7 MMU, caches and TLBs */ void cpu_init_cp15(void); diff --git a/arch/arm/lib/spl.c b/arch/arm/lib/spl.c index c43a63f1819..1b66b5b5d19 100644 --- a/arch/arm/lib/spl.c +++ b/arch/arm/lib/spl.c @@ -7,6 +7,7 @@ * Tom Rini <trini@ti.com> */ +#include <bootm.h> #include <config.h> #include <init.h> #include <log.h> diff --git a/arch/arm/mach-rockchip/spl.c b/arch/arm/mach-rockchip/spl.c index 503e55dfc3a..f23e4291482 100644 --- a/arch/arm/mach-rockchip/spl.c +++ b/arch/arm/mach-rockchip/spl.c @@ -4,6 +4,7 @@ */ #include <bloblist.h> +#include <bootm.h> #include <cpu_func.h> #include <debug_uart.h> #include <dm.h> diff --git a/arch/riscv/cpu/andes/cpu.c b/arch/riscv/cpu/andes/cpu.c index d25ecba0e88..b59c0c723de 100644 --- a/arch/riscv/cpu/andes/cpu.c +++ b/arch/riscv/cpu/andes/cpu.c @@ -5,6 +5,7 @@ */ /* CPU specific code */ +#include <bootm.h> #include <cpu_func.h> #include <irq_func.h> #include <asm/cache.h> diff --git a/arch/riscv/cpu/ast2700/cpu.c b/arch/riscv/cpu/ast2700/cpu.c index c1540546a9a..7386f6f6740 100644 --- a/arch/riscv/cpu/ast2700/cpu.c +++ b/arch/riscv/cpu/ast2700/cpu.c @@ -4,6 +4,7 @@ * Copyright (C) 2024, Aspeed Technology Inc. */ +#include <bootm.h> #include <irq_func.h> #include <asm/cache.h> diff --git a/arch/riscv/cpu/cv1800b/cpu.c b/arch/riscv/cpu/cv1800b/cpu.c index 233a6a3d64e..05dd85cfd49 100644 --- a/arch/riscv/cpu/cv1800b/cpu.c +++ b/arch/riscv/cpu/cv1800b/cpu.c @@ -3,6 +3,8 @@ * Copyright (c) 2024, Kongyang Liu <seashell11234455@gmail.com> */ +#include <bootm.h> + int cleanup_before_linux(void) { return 0; diff --git a/arch/riscv/cpu/fu540/cpu.c b/arch/riscv/cpu/fu540/cpu.c index f13c18942f3..f66f43351e5 100644 --- a/arch/riscv/cpu/fu540/cpu.c +++ b/arch/riscv/cpu/fu540/cpu.c @@ -3,6 +3,7 @@ * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com> */ +#include <bootm.h> #include <irq_func.h> #include <asm/cache.h> diff --git a/arch/riscv/cpu/fu740/cpu.c b/arch/riscv/cpu/fu740/cpu.c index f13c18942f3..f66f43351e5 100644 --- a/arch/riscv/cpu/fu740/cpu.c +++ b/arch/riscv/cpu/fu740/cpu.c @@ -3,6 +3,7 @@ * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com> */ +#include <bootm.h> #include <irq_func.h> #include <asm/cache.h> diff --git a/arch/riscv/cpu/generic/cpu.c b/arch/riscv/cpu/generic/cpu.c index f13c18942f3..f66f43351e5 100644 --- a/arch/riscv/cpu/generic/cpu.c +++ b/arch/riscv/cpu/generic/cpu.c @@ -3,6 +3,7 @@ * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com> */ +#include <bootm.h> #include <irq_func.h> #include <asm/cache.h> diff --git a/arch/riscv/cpu/jh7110/cpu.c b/arch/riscv/cpu/jh7110/cpu.c index 1d7c026584a..65a881952e3 100644 --- a/arch/riscv/cpu/jh7110/cpu.c +++ b/arch/riscv/cpu/jh7110/cpu.c @@ -4,6 +4,7 @@ * Author: Yanhong Wang <yanhong.wang@starfivetech.com> */ +#include <bootm.h> #include <asm/cache.h> #include <irq_func.h> diff --git a/arch/riscv/include/asm/u-boot-riscv.h b/arch/riscv/include/asm/u-boot-riscv.h index 3a8fdb57136..f6ec024cd73 100644 --- a/arch/riscv/include/asm/u-boot-riscv.h +++ b/arch/riscv/include/asm/u-boot-riscv.h @@ -11,9 +11,6 @@ #ifndef _U_BOOT_RISCV_H_ #define _U_BOOT_RISCV_H_ 1 -/* cpu/.../cpu.c */ -int cleanup_before_linux(void); - /* board/.../... */ int board_init(void); int riscv_board_reserved_mem_fixup(void *fdt); diff --git a/arch/riscv/lib/boot.c b/arch/riscv/lib/boot.c index 161335abee1..81dc94bb963 100644 --- a/arch/riscv/lib/boot.c +++ b/arch/riscv/lib/boot.c @@ -4,6 +4,7 @@ * Rick Chen, Andes Technology Corporation <rick@andestech.com> */ +#include <bootm.h> #include <linux/types.h> #include <asm/u-boot-riscv.h> diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index 218057b94ad..d6177fbbd14 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -5,6 +5,7 @@ #define LOG_CATEGORY LOGC_SANDBOX +#include <bootm.h> #include <bootstage.h> #include <cpu_func.h> #include <errno.h> diff --git a/arch/sandbox/include/asm/u-boot-sandbox.h b/arch/sandbox/include/asm/u-boot-sandbox.h index e7027747b37..23eaa3a45e6 100644 --- a/arch/sandbox/include/asm/u-boot-sandbox.h +++ b/arch/sandbox/include/asm/u-boot-sandbox.h @@ -21,8 +21,6 @@ int board_init(void); int sandbox_early_getopt_check(void); int sandbox_main_loop_init(void); -int cleanup_before_linux(void); - /* drivers/video/sandbox_sdl.c */ int sandbox_lcd_sdl_early_init(void); diff --git a/arch/sh/cpu/sh4/cpu.c b/arch/sh/cpu/sh4/cpu.c index 47a8549beba..6bf3052c4e8 100644 --- a/arch/sh/cpu/sh4/cpu.c +++ b/arch/sh/cpu/sh4/cpu.c @@ -4,6 +4,7 @@ * Nobuhiro Iwamatsu <iwamatsu@nigauri.org> */ +#include <bootm.h> #include <command.h> #include <irq_func.h> #include <cpu_func.h> diff --git a/arch/x86/include/asm/u-boot-x86.h b/arch/x86/include/asm/u-boot-x86.h index ed2f6aa3893..70b818115bd 100644 --- a/arch/x86/include/asm/u-boot-x86.h +++ b/arch/x86/include/asm/u-boot-x86.h @@ -76,7 +76,6 @@ void setup_gdt(struct global_data *id, u64 *gdt_addr); */ void setup_fsp_gdt(void); int init_cache(void); -int cleanup_before_linux(void); /* cpu/.../timer.c */ void timer_isr(void *); @@ -89,7 +88,6 @@ int i8254_init(void); /* cpu/.../interrupts.c */ int cpu_init_interrupts(void); -int cleanup_before_linux(void); int x86_cleanup_before_linux(void); void x86_enable_caches(void); void x86_disable_caches(void); diff --git a/include/bootm.h b/include/bootm.h index 05d55b2d948..6d37d299342 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -392,4 +392,6 @@ int bootm_boot_start(ulong addr, const char *cmdline); */ void bootm_final(enum bootm_final_t flags); +int cleanup_before_linux(void); + #endif -- 2.43.0

From: Simon Glass <sjg@chromium.org> Add this call to the bootm_final() function, dropping it from RISC-V Add a flag to ensure that cleanup_before_linux() is not called when booting an EFI app. Signed-off-by: Simon Glass <sjg@chromium.org> --- arch/riscv/lib/bootm.c | 1 - boot/bootm_final.c | 3 +++ include/bootm.h | 2 ++ lib/efi_loader/efi_boottime.c | 2 +- 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index bd47275b52e..16ded96383f 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -33,7 +33,6 @@ DECLARE_GLOBAL_DATA_PTR; static void announce_and_cleanup(int fake) { bootm_final(fake); - cleanup_before_linux(); } static void boot_prep_linux(struct bootm_headers *images) diff --git a/boot/bootm_final.c b/boot/bootm_final.c index 7f069877d06..bf53c112c19 100644 --- a/boot/bootm_final.c +++ b/boot/bootm_final.c @@ -31,4 +31,7 @@ void bootm_final(enum bootm_final_t flags) * of DMA operation or releasing device internal buffers. */ dm_remove_devices_active(); + + if (!(flags & BOOTM_FINAL_NO_CLEANUP)) + cleanup_before_linux(); } diff --git a/include/bootm.h b/include/bootm.h index 6d37d299342..7c74b6c406d 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -21,9 +21,11 @@ struct cmd_tbl; * * @BOOTM_FINAL_FAKE: true to do everything except actually boot; it then * returns to the caller + * @BOOTM_FINAL_NO_CLEANUP: true to skip calling cleanup_before_linux() */ enum bootm_final_t { BOOTM_FINAL_FAKE = BIT(0), + BOOTM_FINAL_NO_CLEANUP = BIT(1), }; /** diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index d90f9020ccb..2a02029f243 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2231,7 +2231,7 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle, if (!efi_st_keep_devices) { bootm_disable_interrupts(); board_quiesce_devices(); - bootm_final(0); + bootm_final(BOOTM_FINAL_NO_CLEANUP); } /* Patch out unsupported runtime function */ -- 2.43.0

From: Simon Glass <sjg@chromium.org> This function is called just before boot, so move it from EFI into the common bootm_final() function. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/bootm.c | 4 ---- boot/bootm_final.c | 6 ++++++ lib/efi_loader/efi_boottime.c | 1 - 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index bd45ae42fe9..7d7c971207c 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -46,10 +46,6 @@ DECLARE_GLOBAL_DATA_PTR; struct bootm_headers images; /* pointers to os/initrd/fdt images */ -__weak void board_quiesce_devices(void) -{ -} - #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) /** * image_get_kernel - verify legacy format kernel image diff --git a/boot/bootm_final.c b/boot/bootm_final.c index bf53c112c19..466bb55debe 100644 --- a/boot/bootm_final.c +++ b/boot/bootm_final.c @@ -10,6 +10,10 @@ #include <usb.h> #include <dm/root.h> +__weak void board_quiesce_devices(void) +{ +} + void bootm_final(enum bootm_final_t flags) { printf("\nStarting kernel ...%s\n\n", flags & BOOTM_FINAL_FAKE ? @@ -22,6 +26,8 @@ void bootm_final(enum bootm_final_t flags) if (IS_ENABLED(CONFIG_BOOTSTAGE_REPORT)) bootstage_report(); + board_quiesce_devices(); + if (IS_ENABLED(CONFIG_USB_DEVICE)) udc_disconnect(); diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 2a02029f243..6cf430da766 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2230,7 +2230,6 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle, if (!efi_st_keep_devices) { bootm_disable_interrupts(); - board_quiesce_devices(); bootm_final(BOOTM_FINAL_NO_CLEANUP); } -- 2.43.0

From: Simon Glass <sjg@chromium.org> The logic in bootm to re-enable interrupts if the OS fails to boot does not seem very useful, since the board resets immediately afterwards. Drop it. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/bootm.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index 7d7c971207c..3fef6506e91 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1035,7 +1035,6 @@ int bootm_run_states(struct bootm_info *bmi, int states) { struct bootm_headers *images = bmi->images; boot_os_fn *boot_fn; - ulong iflag = 0; int ret = 0, need_boot_fn; images->state |= states; @@ -1068,7 +1067,7 @@ int bootm_run_states(struct bootm_info *bmi, int states) /* Load the OS */ if (!ret && (states & BOOTM_STATE_LOADOS)) { - iflag = bootm_disable_interrupts(); + bootm_disable_interrupts(); if (IS_ENABLED(CONFIG_EVENT)) { struct event_os_load data; @@ -1114,8 +1113,6 @@ int bootm_run_states(struct bootm_info *bmi, int states) BOOTM_STATE_OS_BD_T | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO); if (boot_fn == NULL && need_boot_fn) { - if (iflag) - enable_interrupts(); printf("ERROR: booting os '%s' (%d) is not supported\n", genimg_get_os_name(images->os.os), images->os.os); bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS); @@ -1164,9 +1161,6 @@ int bootm_run_states(struct bootm_info *bmi, int states) /* Deal with any fallout */ err: - if (iflag) - enable_interrupts(); - if (ret == BOOTM_ERR_UNIMPLEMENTED) { bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL); } else if (ret == BOOTM_ERR_RESET) { -- 2.43.0

From: Simon Glass <sjg@chromium.org> Move disabling of interrupts to bootm_final() so it is done for bootm and EFI boot paths. Drop the now-duplicate calls. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/bootm.c | 1 - boot/bootm_final.c | 2 ++ cmd/booti.c | 6 ------ lib/efi_loader/efi_boottime.c | 4 +--- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/boot/bootm.c b/boot/bootm.c index 3fef6506e91..0e15cdd0015 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1067,7 +1067,6 @@ int bootm_run_states(struct bootm_info *bmi, int states) /* Load the OS */ if (!ret && (states & BOOTM_STATE_LOADOS)) { - bootm_disable_interrupts(); if (IS_ENABLED(CONFIG_EVENT)) { struct event_os_load data; diff --git a/boot/bootm_final.c b/boot/bootm_final.c index 466bb55debe..5a3be11841e 100644 --- a/boot/bootm_final.c +++ b/boot/bootm_final.c @@ -38,6 +38,8 @@ void bootm_final(enum bootm_final_t flags) */ dm_remove_devices_active(); + bootm_disable_interrupts(); + if (!(flags & BOOTM_FINAL_NO_CLEANUP)) cleanup_before_linux(); } diff --git a/cmd/booti.c b/cmd/booti.c index f4f782da056..c1a61e4752d 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -124,12 +124,6 @@ int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (booti_start(&bmi)) return 1; - /* - * We are doing the BOOTM_STATE_LOADOS state ourselves, so must - * disable interrupts ourselves - */ - bootm_disable_interrupts(); - images.os.os = IH_OS_LINUX; if (IS_ENABLED(CONFIG_RISCV_SMODE)) images.os.arch = IH_ARCH_RISCV; diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 6cf430da766..cc711a5c52f 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -2228,10 +2228,8 @@ static efi_status_t EFIAPI efi_exit_boot_services(efi_handle_t image_handle, list_del(&evt->link); } - if (!efi_st_keep_devices) { - bootm_disable_interrupts(); + if (!efi_st_keep_devices) bootm_final(BOOTM_FINAL_NO_CLEANUP); - } /* Patch out unsupported runtime function */ efi_runtime_detach(); -- 2.43.0

From: Simon Glass <sjg@chromium.org> Now that ARM's announce_and_cleanup() function includes the same steps as bootm_final(), just use the latter. Move over part of a comment which seems useful. Signed-off-by: Simon Glass <sjg@chromium.org> --- arch/arm/lib/bootm.c | 39 ++------------------------------------- boot/bootm_final.c | 2 ++ drivers/net/fsl-mc/mc.c | 2 +- 3 files changed, 5 insertions(+), 38 deletions(-) diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c index 688c2f3f29b..cb365d95c7b 100644 --- a/arch/arm/lib/bootm.c +++ b/arch/arm/lib/bootm.c @@ -47,41 +47,6 @@ __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) -{ - bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); -#ifdef CONFIG_BOOTSTAGE_FDT - bootstage_fdt_add_report(); -#endif -#ifdef CONFIG_BOOTSTAGE_REPORT - bootstage_report(); -#endif - -#ifdef CONFIG_USB_DEVICE - udc_disconnect(); -#endif - - board_quiesce_devices(); - - printf("\nStarting kernel ...%s\n\n", fake ? - "(fake run for tracing)" : ""); - /* - * 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() ensures that vital devices are removed in - * a second round. - */ - dm_remove_devices_active(); - - cleanup_before_linux(); -} - static void setup_start_tag (struct bd_info *bd) { params = (struct tag *)bd->bi_boot_params; @@ -304,7 +269,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag) (ulong) kernel_entry); bootstage_mark(BOOTSTAGE_ID_RUN_OS); - announce_and_cleanup(fake); + bootm_final(fake ? BOOTM_FINAL_FAKE : 0); if (!fake) { #ifdef CONFIG_ARMV8_PSCI @@ -354,7 +319,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag) debug("## Transferring control to Linux (at address %08lx)" \ "...\n", (ulong) kernel_entry); bootstage_mark(BOOTSTAGE_ID_RUN_OS); - announce_and_cleanup(fake); + bootm_final(fake ? BOOTM_FINAL_FAKE : 0); if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) r2 = (unsigned long)images->ft_addr; diff --git a/boot/bootm_final.c b/boot/bootm_final.c index 5a3be11841e..79ec35e23b0 100644 --- a/boot/bootm_final.c +++ b/boot/bootm_final.c @@ -35,6 +35,8 @@ void bootm_final(enum bootm_final_t flags) * 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() ensures that vital devices are removed in + * a second round. */ dm_remove_devices_active(); diff --git a/drivers/net/fsl-mc/mc.c b/drivers/net/fsl-mc/mc.c index c2869ce4010..36f8590e46c 100644 --- a/drivers/net/fsl-mc/mc.c +++ b/drivers/net/fsl-mc/mc.c @@ -1980,7 +1980,7 @@ static int do_fsl_mc(struct cmd_tbl *cmdtp, int flag, int argc, /* * We will do the actual dpaa exit and dpl apply - * later from announce_and_cleanup(). + * later from bootm_final(). */ mc_lazy_dpl_addr = mc_dpl_addr; break; -- 2.43.0

From: Simon Glass <sjg@chromium.org> Now that RISC-V's announce_and_cleanup() function matches bootm_final(), just use the latter. Signed-off-by: Simon Glass <sjg@chromium.org> --- arch/riscv/lib/bootm.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index 16ded96383f..f2ecbbdef06 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -25,16 +25,6 @@ DECLARE_GLOBAL_DATA_PTR; -/** - * 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) -{ - bootm_final(fake); -} - static void boot_prep_linux(struct bootm_headers *images) { if (CONFIG_IS_ENABLED(OF_LIBFDT) && IS_ENABLED(CONFIG_LMB) && images->ft_len) { @@ -64,7 +54,7 @@ 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(fake ? BOOTM_FINAL_FAKE : 0); if (!fake) { if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) { -- 2.43.0

From: Simon Glass <sjg@chromium.org> Now that bootm_final() does most of what we want, drop this separate function. Signed-off-by: Simon Glass <sjg@chromium.org> --- arch/x86/cpu/cpu.c | 2 +- arch/x86/include/asm/bootm.h | 2 -- arch/x86/lib/bootm.c | 13 ++++--------- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c index f756a9ebf09..d7aaf496c51 100644 --- a/arch/x86/cpu/cpu.c +++ b/arch/x86/cpu/cpu.c @@ -246,7 +246,7 @@ static int last_stage_init(void) } /* - * TODO(sjg@chromium.org): Move this to bootm_announce_and_cleanup() + * TODO(sjg@chromium.org): Move this to boot_linux_kernel() * once APL FSP-S at 0x200000 does not overlap with the bzimage at * 0x100000. */ diff --git a/arch/x86/include/asm/bootm.h b/arch/x86/include/asm/bootm.h index 3b641783b9c..835aa5592df 100644 --- a/arch/x86/include/asm/bootm.h +++ b/arch/x86/include/asm/bootm.h @@ -6,8 +6,6 @@ #ifndef ARM_BOOTM_H #define ARM_BOOTM_H -void bootm_announce_and_cleanup(void); - /** * boot_linux_kernel() - boot a linux kernel * diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c index fc408d9685c..2dace1b0c45 100644 --- a/arch/x86/lib/bootm.c +++ b/arch/x86/lib/bootm.c @@ -34,14 +34,6 @@ DECLARE_GLOBAL_DATA_PTR; #define COMMAND_LINE_OFFSET 0x9000 -void bootm_announce_and_cleanup(void) -{ -#ifdef CONFIG_SYS_COREBOOT - timestamp_add_now(TS_START_KERNEL); -#endif - bootm_final(0); -} - #if defined(CONFIG_OF_LIBFDT) && !defined(CONFIG_OF_NO_KERNEL) int arch_fixup_memory_node(void *blob) { @@ -181,7 +173,10 @@ int efi_boot(ulong setup_base, ulong entry, bool image_64bit) int boot_linux_kernel(ulong setup_base, ulong entry, bool image_64bit) { - bootm_announce_and_cleanup(); +#ifdef CONFIG_SYS_COREBOOT + timestamp_add_now(TS_START_KERNEL); +#endif + bootm_final(0); #ifdef CONFIG_SYS_COREBOOT timestamp_add_now(TS_U_BOOT_START_KERNEL); -- 2.43.0
participants (1)
-
Simon Glass