]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
bootm: Create bootm_final() for pre-boot cleanup
authorSimon Glass <simon.glass@canonical.com>
Fri, 6 Mar 2026 02:36:13 +0000 (19:36 -0700)
committerTom Rini <trini@konsulko.com>
Wed, 18 Mar 2026 19:17:34 +0000 (13:17 -0600)
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 <simon.glass@canonical.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
boot/bootm.c
include/bootm.h

index 4bdca22ea8cfc2a89753d924e29352b3dbd1646f..cba10b5dce705f6b0114d6927b22ace842ca7b48 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef USE_HOSTCC
 #include <bootm.h>
 #include <bootstage.h>
+#include <dm/root.h>
 #include <cli.h>
 #include <command.h>
 #include <cpu_func.h>
@@ -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)
index 4060cec7fc06b5010caba724d7729402f27424fc..f6958be751adfefc761a0842744fe148f46db17d 100644 (file)
@@ -321,4 +321,14 @@ void zimage_dump(struct boot_params *base_ptr, bool show_cmdline);
  */
 int bootm_boot_start(ulong addr, const char *cmdline);
 
+/**
+ * bootm_final() - Announce and do cleanup before boot
+ *
+ * This performs the common pre-boot steps: printing the "Starting kernel"
+ * message, recording bootstage data, and removing active devices.
+ *
+ * @flag: Boot state flags (BOOTM_STATE_OS_FAKE_GO prints a fake-run message)
+ */
+void bootm_final(int flag);
+
 #endif