public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up
@ 2026-03-06  2:36 Simon Glass
  2026-03-06  2:36 ` [PATCH v4 01/17] dm: Move flags_remove() check before child removal Simon Glass
                   ` (17 more replies)
  0 siblings, 18 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Simon Glass, Albert Aribaud, Alexey Brodkin,
	Alison Wang, Andy Fleming, Angelo Dureghello, Angelo Dureghello,
	Aristo Chen, Benjamin ROBIN, Bin Meng, Daniel Schwierzeck,
	Eugeniy Paltsev, Guillaume Ranquet, Ilias Apalodimas,
	Kuan-Wei Chiu, Leo, Marek Vasut, Marek Vasut, Mario Six,
	Mattijs Korpershoek, Michal Simek, Michal Simek,
	Nobuhiro Iwamatsu, Patrice Chotard, Pavel Herrmann, Peng Fan,
	Priyanka Jain, Quentin Schulz, Rick Chen, Scott McNutt,
	Stefan Roese, Sughosh Ganu, Thomas Chou, Vishnu Singh,
	Wolfgang Denk, Wolfgang Wallner, Yao Zi, uboot-snps-arc

Each arch does something slightly different before booting the OS. Some
archs even do different things depending on the CPU type.

It is quite hard to know what actually happens in the final milliseconds
before the OS boot.

This series attempts to start cleaning up U-Boot in this area.

The basic intent is to create a new bootm_final() function which can be
called by all archs. It provides some flags for a couple of necessary
variations but otherwise it is generic.

All architectures are converted over to use this new function.

board_quiesce_devices() is moved into bootm_final() so that all archs
benefit from it.

This series fixes a bug in device_remove() is fixed where removing a
parent with specialised flags (e.g. DM_REMOVE_ACTIVE_ALL) could leave
children activated, since they do not match the flags. This fixes is
needed to avoid bootm_final() causing test failures on sandbox.

Future work could take this a little further:
- Convert EFI loader to use the same function
- Improve comments for cleanup_before_linux() across architectures
- Support fake-run tracing on all archs

Changes in v4:
- Drop announce_and_cleanup() in arm and riscv
- Drop announce_and_cleanup(), inline the two calls
- Pass flag directly instead of using BOOTM_FINAL_FAKE
- Print '(fake run for tracing)' when flag is set
- Use BOOTM_STATE_OS_FAKE_GO instead of new enum bootm_final_t

Changes in v3:
- Add dm: device_remove() fix for child removal with specialised flags
- Add new patch for ARC conversion
- Add new patch for ARM conversion (requested by Tom)
- Add new patch for MIPS conversion
- Add new patch for MicroBlaze conversion
- Add new patch for Nios2 conversion
- Add new patch for PowerPC conversion
- Add new patch for SH conversion
- Add new patch for Xtensa conversion
- Add new patch for bootstage stashing, needed for ARM conversion
- Add new patch for m68k conversion
- Add new patch for sandbox conversion
- Convert all remaining architectures
- Drop cleanup_before_linux() patch
- Drop the DMA comment move (now in the introductory patch)
- Drop udc_disconnect()
- Fix "the a" typo
- Introduce with all common functionality (not empty)
- Move board_quiesce_devices() into bootm_final() instead of dropping it
- Move bootstage dummies earlier in the series
- Move earlier in the series so bootm_final() can use bootstage from the start
- Put bootm_final() in bootm.c instead of a separate file
- Put in bootm.c instead of a separate file
- Squash in patches 2, 3 and 5 from v2
- Squash introductory patches so bootm_final() is introduced non-empty
- Squash with the previous riscv patches
- Update cover letter to match current series

Changes in v2:
- Drop patch 'efi: Drop EFI_GRUB_ARM32_WORKAROUND'
- Update cover message to reflect dropping the EFI patches, etc.

Simon Glass (17):
  dm: Move flags_remove() check before child removal
  dm: Remove children when parent is removed by flags
  bootstage: Add some missing dummy functions
  bootm: Create bootm_final() for pre-boot cleanup
  x86: Call bootm_final()
  riscv: Call bootm_final()
  bootm: Stash bootstage data in bootm_final()
  arm: Call bootm_final()
  arc: Call bootm_final()
  microblaze: Call bootm_final()
  mips: Call bootm_final()
  powerpc: Call bootm_final()
  m68k: Call bootm_final()
  nios2: Call bootm_final()
  sh: Call bootm_final()
  xtensa: Call bootm_final()
  sandbox: Call bootm_final()

 arch/arc/lib/bootm.c                  |  8 ++---
 arch/arm/lib/bootm.c                  | 50 ++++-----------------------
 arch/m68k/lib/bootm.c                 |  2 ++
 arch/microblaze/lib/bootm.c           |  8 ++---
 arch/mips/lib/bootm.c                 |  7 +---
 arch/nios2/lib/bootm.c                |  2 ++
 arch/powerpc/lib/bootm.c              |  7 +---
 arch/riscv/include/asm/u-boot-riscv.h |  1 -
 arch/riscv/lib/bootm.c                | 39 ++-------------------
 arch/sandbox/lib/bootm.c              |  1 +
 arch/sh/lib/bootm.c                   |  2 ++
 arch/x86/lib/bootm.c                  | 14 +-------
 arch/xtensa/lib/bootm.c               |  2 ++
 boot/bootm.c                          | 25 ++++++++++++++
 drivers/core/device-remove.c          | 34 +++++++++++-------
 include/bootm.h                       | 10 ++++++
 include/bootstage.h                   |  8 +++++
 17 files changed, 90 insertions(+), 130 deletions(-)

-- 
2.43.0

base-commit: c0ca147ac6228949a6d6497531c9f2f4a0dc6c67
branch: bootma-us4

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v4 01/17] dm: Move flags_remove() check before child removal
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06  2:36 ` [PATCH v4 02/17] dm: Remove children when parent is removed by flags Simon Glass
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Simon Glass, Marek Vasut, Pavel Herrmann, Simon Glass

From: Simon Glass <simon.glass@canonical.com>

Move the flags_remove() call before device_chld_remove() and save the
result in a separate variable. This is just a refactoring with no
behaviour change, preparing for the next commit which needs to know
whether the parent will be removed before deciding how to remove its
children.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

(no changes since v1)

 drivers/core/device-remove.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
index 437080ed778..03ef49c4db0 100644
--- a/drivers/core/device-remove.c
+++ b/drivers/core/device-remove.c
@@ -198,7 +198,7 @@ static int flags_remove(uint flags, uint drv_flags)
 int device_remove(struct udevice *dev, uint flags)
 {
 	const struct driver *drv;
-	int ret;
+	int ret, cret;
 
 	if (!dev)
 		return -EINVAL;
@@ -210,6 +210,14 @@ int device_remove(struct udevice *dev, uint flags)
 	if (ret)
 		return ret;
 
+	/*
+	 * Remove the device if called with the "normal" remove flag set,
+	 * or if the remove flag matches any of the drivers remove flags
+	 */
+	drv = dev->driver;
+	assert(drv);
+	cret = flags_remove(flags, drv->flags);
+
 	/*
 	 * If the child returns EKEYREJECTED, continue. It just means that it
 	 * didn't match the flags.
@@ -218,17 +226,10 @@ int device_remove(struct udevice *dev, uint flags)
 	if (ret && ret != -EKEYREJECTED)
 		return ret;
 
-	/*
-	 * Remove the device if called with the "normal" remove flag set,
-	 * or if the remove flag matches any of the drivers remove flags
-	 */
-	drv = dev->driver;
-	assert(drv);
-	ret = flags_remove(flags, drv->flags);
-	if (ret) {
+	if (cret) {
 		log_debug("%s: When removing: flags=%x, drv->flags=%x, err=%d\n",
-			  dev->name, flags, drv->flags, ret);
-		return ret;
+			  dev->name, flags, drv->flags, cret);
+		return cret;
 	}
 
 	ret = uclass_pre_remove_device(dev);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 02/17] dm: Remove children when parent is removed by flags
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
  2026-03-06  2:36 ` [PATCH v4 01/17] dm: Move flags_remove() check before child removal Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06  2:36 ` [PATCH v4 03/17] bootstage: Add some missing dummy functions Simon Glass
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Simon Glass, Marek Vasut, Pavel Herrmann, Simon Glass

From: Simon Glass <simon.glass@canonical.com>

When dm_remove_devices_active() removes devices using specialised flags
like DM_REMOVE_ACTIVE_ALL, a parent device may match (e.g. MMC has
DM_FLAG_OS_PREPARE) while its children do not. This deactivates the
parent but leaves children activated, an inconsistent state.

Later, when uclass_destroy() calls device_remove() with DM_REMOVE_NORMAL
on the already-deactivated parent, it returns early without touching the
children. The subsequent device_unbind() then fails because the children
are still activated.

Fix this by dropping only the DM_REMOVE_ACTIVE_ALL requirement for child
removal when the parent is being removed. This ensures children are
removed along with their parent, while still preserving other flags like
DM_REMOVE_NON_VITAL so that vital devices remain protected.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

(no changes since v1)

 drivers/core/device-remove.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c
index 03ef49c4db0..557afb8d817 100644
--- a/drivers/core/device-remove.c
+++ b/drivers/core/device-remove.c
@@ -219,10 +219,19 @@ int device_remove(struct udevice *dev, uint flags)
 	cret = flags_remove(flags, drv->flags);
 
 	/*
+	 * Remove all children. If this device is being removed due to
+	 * active-DMA or OS-prepare flags, drop the active-flag requirement
+	 * for children so they are removed even without matching active
+	 * flags, since a deactivated device must not have activated
+	 * children. Preserve other flags (e.g. DM_REMOVE_NON_VITAL) so
+	 * that vital children are still protected.
+	 *
 	 * If the child returns EKEYREJECTED, continue. It just means that it
 	 * didn't match the flags.
 	 */
-	ret = device_chld_remove(dev, NULL, flags);
+	ret = device_chld_remove(dev, NULL,
+				 cret ? flags :
+				 (flags & ~DM_REMOVE_ACTIVE_ALL));
 	if (ret && ret != -EKEYREJECTED)
 		return ret;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 03/17] bootstage: Add some missing dummy functions
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
  2026-03-06  2:36 ` [PATCH v4 01/17] dm: Move flags_remove() check before child removal Simon Glass
  2026-03-06  2:36 ` [PATCH v4 02/17] dm: Remove children when parent is removed by flags Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06  2:36 ` [PATCH v4 04/17] bootm: Create bootm_final() for pre-boot cleanup Simon Glass
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Simon Glass, Aristo Chen

From: Simon Glass <simon.glass@canonical.com>

Neither bootstage_fdt_add_report() nor bootstage_report() has a dummy
double for when bootstage is disabled. Add them.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
---

(no changes since v3)

Changes in v3:
- Move earlier in the series so bootm_final() can use bootstage from the start

 include/bootstage.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/include/bootstage.h b/include/bootstage.h
index 528d0ca0614..62fb99110f0 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


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 04/17] bootm: Create bootm_final() for pre-boot cleanup
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (2 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 03/17] bootstage: Add some missing dummy functions Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06 15:12   ` Tom Rini
  2026-03-06  2:36 ` [PATCH v4 05/17] x86: Call bootm_final() Simon Glass
                   ` (13 subsequent siblings)
  17 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Simon Glass, Aristo Chen, Benjamin ROBIN,
	Ilias Apalodimas, Quentin Schulz, Sughosh Ganu, Wolfgang Wallner,
	牛 志宏

From: Simon Glass <simon.glass@canonical.com>

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>

---

Changes in v4:
- Print '(fake run for tracing)' when flag is set
- Use BOOTM_STATE_OS_FAKE_GO instead of new enum bootm_final_t

Changes in v3:
- Fix "the a" typo
- Introduce with all common functionality (not empty)
- Put in bootm.c instead of a separate file
- Squash in patches 2, 3 and 5 from v2

 boot/bootm.c    | 22 ++++++++++++++++++++++
 include/bootm.h | 10 ++++++++++
 2 files changed, 32 insertions(+)

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 <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)
diff --git a/include/bootm.h b/include/bootm.h
index 4060cec7fc0..f6958be751a 100644
--- a/include/bootm.h
+++ b/include/bootm.h
@@ -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
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 05/17] x86: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (3 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 04/17] bootm: Create bootm_final() for pre-boot cleanup Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06  2:36 ` [PATCH v4 06/17] riscv: " Simon Glass
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Simon Glass, Bin Meng, Guillaume Ranquet, Simon Glass

From: Simon Glass <simon.glass@canonical.com>

The x86 code in bootm_announce_and_cleanup() is very similar to the new
bootm_final() function, so just use the latter.

Signed-off-by: Simon Glass <simon.glass@canonical.com>

---

(no changes since v3)

Changes in v3:
- Drop the DMA comment move (now in the introductory patch)

 arch/x86/lib/bootm.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c
index 7a94dc877e3..cde4fbf3557 100644
--- a/arch/x86/lib/bootm.c
+++ b/arch/x86/lib/bootm.c
@@ -34,22 +34,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)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 06/17] riscv: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (4 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 05/17] x86: Call bootm_final() Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06 15:12   ` Tom Rini
  2026-03-06  2:36 ` [PATCH v4 07/17] bootm: Stash bootstage data in bootm_final() Simon Glass
                   ` (11 subsequent siblings)
  17 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Simon Glass, Aristo Chen, Benjamin ROBIN,
	Heinrich Schuchardt, Ilias Apalodimas, Leo, Mattijs Korpershoek,
	Mayuresh Chitale, Rick Chen, Sughosh Ganu,
	牛 志宏

From: Simon Glass <simon.glass@canonical.com>

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 <simon.glass@canonical.com>

---

Changes in v4:
- Drop announce_and_cleanup(), inline the two calls

Changes in v3:
- Drop udc_disconnect()
- Move board_quiesce_devices() into bootm_final() instead of dropping it
- Squash with the previous riscv patches

 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(-)

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
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 07/17] bootm: Stash bootstage data in bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (5 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 06/17] riscv: " Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06  2:36 ` [PATCH v4 08/17] arm: Call bootm_final() Simon Glass
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Simon Glass, Benjamin ROBIN, Ilias Apalodimas,
	Quentin Schulz, Sughosh Ganu, 牛 志宏

From: Simon Glass <simon.glass@canonical.com>

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 <simon.glass@canonical.com>
Reviewed-by: Tom Rini <trini@konsulko.com>

---

(no changes since v3)

Changes in v3:
- Add new patch for bootstage stashing, needed for ARM conversion

 boot/bootm.c | 1 +
 1 file changed, 1 insertion(+)

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();
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 08/17] arm: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (6 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 07/17] bootm: Stash bootstage data in bootm_final() Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06 15:12   ` Tom Rini
  2026-03-06  2:36 ` [PATCH v4 09/17] arc: " Simon Glass
                   ` (9 subsequent siblings)
  17 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Simon Glass, Albert Aribaud, Heinrich Schuchardt,
	Marek Vasut, Mattijs Korpershoek, Quentin Schulz, Vishnu Singh

From: Simon Glass <simon.glass@canonical.com>

The ARM announce_and_cleanup() duplicates the common pre-boot steps.
Replace it with a call to bootm_final().

Drop the ARM weak board_quiesce_devices() definition since it is now
called from bootm_final() and the generic weak definition in bootm.h
is used instead.

Note that the printf() ordering changes slightly: it now prints before
bootstage processing rather than after, matching x86 and RISC-V.

Signed-off-by: Simon Glass <simon.glass@canonical.com>

---

Changes in v4:
- Drop announce_and_cleanup(), inline the two calls

Changes in v3:
- Add new patch for ARM conversion (requested by Tom)

 arch/arm/lib/bootm.c | 50 ++++++--------------------------------------
 1 file changed, 6 insertions(+), 44 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index 019eca95780..727b9c5ca5b 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -42,42 +42,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static struct tag *params;
 
-__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
-	bootstage_stash_default();
-#ifdef CONFIG_BOOTSTAGE_REPORT
-	bootstage_report();
-#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;
@@ -294,8 +258,6 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
 {
 	void (*kernel_entry)(void *fdt_addr, void *res0, void *res1,
 			void *res2);
-	int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
-
 	kernel_entry = (void (*)(void *fdt_addr, void *res0, void *res1,
 				void *res2))images->ep;
 
@@ -303,9 +265,10 @@ 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(flag);
+	cleanup_before_linux();
 
-	if (!fake) {
+	if (!(flag & BOOTM_STATE_OS_FAKE_GO)) {
 #ifdef CONFIG_ARMV8_PSCI
 		armv8_setup_psci();
 #endif
@@ -340,8 +303,6 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
 	char *s;
 	void (*kernel_entry)(int zero, int arch, uint params);
 	unsigned long r2;
-	int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
-
 	kernel_entry = (void (*)(int, int, uint))images->ep;
 #ifdef CONFIG_CPU_V7M
 	ulong addr = (ulong)kernel_entry | 1;
@@ -366,14 +327,15 @@ 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(flag);
+	cleanup_before_linux();
 
 	if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len)
 		r2 = (unsigned long)images->ft_addr;
 	else
 		r2 = gd->bd->bi_boot_params;
 
-	if (fake)
+	if (flag & BOOTM_STATE_OS_FAKE_GO)
 		return;
 
 #ifdef CONFIG_ARMV7_NONSEC
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 09/17] arc: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (7 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 08/17] arm: Call bootm_final() Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06  2:36 ` [PATCH v4 10/17] microblaze: " Simon Glass
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Simon Glass, Alexey Brodkin, Eugeniy Paltsev,
	Patrice Chotard, Peng Fan, Yao Zi, uboot-snps-arc

From: Simon Glass <simon.glass@canonical.com>

Replace the open-coded printf and bootstage_mark_name with a call to
bootm_final(). This also adds board_quiesce_devices() and
dm_remove_devices_active() which were not previously called on ARC.

Signed-off-by: Simon Glass <simon.glass@canonical.com>

---

Changes in v4:
- Pass flag directly instead of using BOOTM_FINAL_FAKE

Changes in v3:
- Add new patch for ARC conversion

 arch/arc/lib/bootm.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/arc/lib/bootm.c b/arch/arc/lib/bootm.c
index 91bce5235a5..91165a06a46 100644
--- a/arch/arc/lib/bootm.c
+++ b/arch/arc/lib/bootm.c
@@ -50,17 +50,13 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
 {
 	ulong kernel_entry;
 	unsigned int r0, r2;
-	int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
-
 	kernel_entry = images->ep;
 
 	debug("## Transferring control to Linux (at address %08lx)...\n",
 	      kernel_entry);
 	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
 
-	printf("\nStarting kernel ...%s\n\n", fake ?
-	       "(fake run for tracing)" : "");
-	bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
+	bootm_final(flag);
 
 	if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
 		r0 = 2;
@@ -72,7 +68,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
 
 	cleanup_before_linux();
 
-	if (!fake)
+	if (!(flag & BOOTM_STATE_OS_FAKE_GO))
 		board_jump_and_run(kernel_entry, r0, 0, r2);
 }
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 10/17] microblaze: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (8 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 09/17] arc: " Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06  2:36 ` [PATCH v4 11/17] mips: " Simon Glass
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Simon Glass, Michal Simek, Michal Simek,
	Patrice Chotard, Peng Fan, Yao Zi

From: Simon Glass <simon.glass@canonical.com>

Replace the open-coded printf and bootstage_mark_name with a call to
bootm_final(). This also adds board_quiesce_devices() and
dm_remove_devices_active() which were not previously called on
MicroBlaze.

Signed-off-by: Simon Glass <simon.glass@canonical.com>

---

Changes in v4:
- Pass flag directly instead of using BOOTM_FINAL_FAKE

Changes in v3:
- Add new patch for MicroBlaze conversion

 arch/microblaze/lib/bootm.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/arch/microblaze/lib/bootm.c b/arch/microblaze/lib/bootm.c
index 2410515f4ac..b54c902602f 100644
--- a/arch/microblaze/lib/bootm.c
+++ b/arch/microblaze/lib/bootm.c
@@ -26,8 +26,6 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
 	ulong dt = (ulong)images->ft_addr;
 	ulong rd_start = images->initrd_start;
 	ulong cmdline = images->cmdline_start;
-	int fake = (flag & BOOTM_STATE_OS_FAKE_GO);
-
 	thekernel = (void (*)(char *, ulong, ulong))images->ep;
 
 	debug("## Transferring control to Linux (at address 0x%08lx) ",
@@ -36,13 +34,11 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
 	      cmdline, rd_start, dt);
 	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
 
-	printf("\nStarting kernel ...%s\n\n", fake ?
-	       "(fake run for tracing)" : "");
-	bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
+	bootm_final(flag);
 
 	flush_cache_all();
 
-	if (!fake) {
+	if (!(flag & BOOTM_STATE_OS_FAKE_GO)) {
 		/*
 		 * Linux Kernel Parameters (passing device tree):
 		 * r5: pointer to command line
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 11/17] mips: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (9 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 10/17] microblaze: " Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06 12:20   ` Daniel Schwierzeck
  2026-03-06  2:36 ` [PATCH v4 12/17] powerpc: " Simon Glass
                   ` (6 subsequent siblings)
  17 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Simon Glass, Daniel Schwierzeck

From: Simon Glass <simon.glass@canonical.com>

Replace the open-coded bootstage_fdt_add_report() and
bootstage_report() with a call to bootm_final(). This also adds the
"Starting kernel" message, board_quiesce_devices() and
dm_remove_devices_active() which were not previously called on MIPS.

Signed-off-by: Simon Glass <simon.glass@canonical.com>

---

(no changes since v3)

Changes in v3:
- Add new patch for MIPS conversion

 arch/mips/lib/bootm.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c
index 87195100023..066c830f3fa 100644
--- a/arch/mips/lib/bootm.c
+++ b/arch/mips/lib/bootm.c
@@ -268,12 +268,7 @@ static void boot_jump_linux(struct bootm_headers *images)
 	if (CONFIG_IS_ENABLED(MALTA))
 		linux_extra = gd->ram_size;
 
-#if IS_ENABLED(CONFIG_BOOTSTAGE_FDT)
-	bootstage_fdt_add_report();
-#endif
-#if IS_ENABLED(CONFIG_BOOTSTAGE_REPORT)
-	bootstage_report();
-#endif
+	bootm_final(0);
 
 	if (CONFIG_IS_ENABLED(RESTORE_EXCEPTION_VECTOR_BASE))
 		trap_restore();
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 12/17] powerpc: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (10 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 11/17] mips: " Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06  2:36 ` [PATCH v4 13/17] m68k: " Simon Glass
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Simon Glass, Andy Fleming, Mario Six, Priyanka Jain,
	Stefan Roese, Wolfgang Denk

From: Simon Glass <simon.glass@canonical.com>

Replace the open-coded bootstage_fdt_add_report() and
bootstage_report() with a call to bootm_final(). This also adds the
"Starting kernel" message, board_quiesce_devices() and
dm_remove_devices_active() which were not previously called on
PowerPC.

Signed-off-by: Simon Glass <simon.glass@canonical.com>

---

(no changes since v3)

Changes in v3:
- Add new patch for PowerPC conversion

 arch/powerpc/lib/bootm.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/arch/powerpc/lib/bootm.c b/arch/powerpc/lib/bootm.c
index dc44bf3ab3a..f9351a17a48 100644
--- a/arch/powerpc/lib/bootm.c
+++ b/arch/powerpc/lib/bootm.c
@@ -54,12 +54,7 @@ static void boot_jump_linux(struct bootm_headers *images)
 
 	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
 
-#ifdef CONFIG_BOOTSTAGE_FDT
-	bootstage_fdt_add_report();
-#endif
-#ifdef CONFIG_BOOTSTAGE_REPORT
-	bootstage_report();
-#endif
+	bootm_final(0);
 
 #if defined(CONFIG_SYS_INIT_RAM_LOCK) && !defined(CONFIG_E500)
 	unlock_ram_in_cache();
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 13/17] m68k: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (11 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 12/17] powerpc: " Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-07 16:36   ` Kuan-Wei Chiu
  2026-03-06  2:36 ` [PATCH v4 14/17] nios2: " Simon Glass
                   ` (4 subsequent siblings)
  17 siblings, 1 reply; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Simon Glass, Angelo Dureghello, Alison Wang,
	Angelo Dureghello, Kuan-Wei Chiu

From: Simon Glass <simon.glass@canonical.com>

Add a call to bootm_final() before jumping to the kernel. This adds
the "Starting kernel" message, bootstage tracking,
board_quiesce_devices() and dm_remove_devices_active() which were not
previously called on m68k.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
Acked-by: Angelo Dureghello <angelo@kernel-space.org>
Tested-by: Angelo Dureghello <angelo@kernel-space.org>

---

(no changes since v3)

Changes in v3:
- Add new patch for m68k conversion

 arch/m68k/lib/bootm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/m68k/lib/bootm.c b/arch/m68k/lib/bootm.c
index 3dcff8076e3..7e36ac73169 100644
--- a/arch/m68k/lib/bootm.c
+++ b/arch/m68k/lib/bootm.c
@@ -65,6 +65,8 @@ int do_bootm_linux(int flag, struct bootm_info *bmi)
 
 	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
 
+	bootm_final(0);
+
 	/*
 	 * Linux Kernel Parameters (passing board info data):
 	 *   sp+00: Ignore, side effect of using jsr to jump to kernel
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 14/17] nios2: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (12 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 13/17] m68k: " Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06  2:36 ` [PATCH v4 15/17] sh: " Simon Glass
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Simon Glass, Patrice Chotard, Peng Fan, Scott McNutt,
	Thomas Chou, Yao Zi

From: Simon Glass <simon.glass@canonical.com>

Add a call to bootm_final() before jumping to the kernel. This adds
the "Starting kernel" message, bootstage tracking,
board_quiesce_devices() and dm_remove_devices_active() which were not
previously called on Nios2.

Signed-off-by: Simon Glass <simon.glass@canonical.com>

---

(no changes since v3)

Changes in v3:
- Add new patch for Nios2 conversion

 arch/nios2/lib/bootm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c
index 294ebfb508b..6004e83bf0c 100644
--- a/arch/nios2/lib/bootm.c
+++ b/arch/nios2/lib/bootm.c
@@ -41,6 +41,8 @@ int do_bootm_linux(int flag, struct bootm_info *bmi)
 	if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
 		return 1;
 
+	bootm_final(0);
+
 	/* flushes data and instruction caches before calling the kernel */
 	disable_interrupts();
 	flush_dcache_all();
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 15/17] sh: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (13 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 14/17] nios2: " Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06  2:36 ` [PATCH v4 16/17] xtensa: " Simon Glass
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot
  Cc: Tom Rini, Simon Glass, Marek Vasut, Nobuhiro Iwamatsu,
	Patrice Chotard, Peng Fan, Yao Zi

From: Simon Glass <simon.glass@canonical.com>

Add a call to bootm_final() before jumping to the kernel. This adds
the "Starting kernel" message, bootstage tracking,
board_quiesce_devices() and dm_remove_devices_active() which were not
previously called on SH.

Signed-off-by: Simon Glass <simon.glass@canonical.com>

---

(no changes since v3)

Changes in v3:
- Add new patch for SH conversion

 arch/sh/lib/bootm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/sh/lib/bootm.c b/arch/sh/lib/bootm.c
index 1c118870dad..81d5957edaa 100644
--- a/arch/sh/lib/bootm.c
+++ b/arch/sh/lib/bootm.c
@@ -92,6 +92,8 @@ int do_bootm_linux(int flag, struct bootm_info *bmi)
 			images->rd_end - images->rd_start);
 	}
 
+	bootm_final(0);
+
 	/* Boot kernel */
 	kernel();
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 16/17] xtensa: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (14 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 15/17] sh: " Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-06  2:36 ` [PATCH v4 17/17] sandbox: " Simon Glass
  2026-03-19 13:52 ` [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Tom Rini
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Simon Glass, Max Filippov

From: Simon Glass <simon.glass@canonical.com>

Add a call to bootm_final() before jumping to the kernel. This adds
the "Starting kernel" message, bootstage tracking,
board_quiesce_devices() and dm_remove_devices_active() which were not
previously called on Xtensa.

Signed-off-by: Simon Glass <simon.glass@canonical.com>

---

Changes in v4:
- Pass flag directly instead of using BOOTM_FINAL_FAKE

Changes in v3:
- Add new patch for Xtensa conversion

 arch/xtensa/lib/bootm.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/xtensa/lib/bootm.c b/arch/xtensa/lib/bootm.c
index 2958f207397..c19ac9d1f9a 100644
--- a/arch/xtensa/lib/bootm.c
+++ b/arch/xtensa/lib/bootm.c
@@ -178,6 +178,8 @@ int do_bootm_linux(int flag, struct bootm_info *bmi)
 	printf("Transferring Control to Linux @0x%08lx ...\n\n",
 	       (ulong)images->ep);
 
+	bootm_final(flag);
+
 	flush_dcache_range((unsigned long)params_start, (unsigned long)params);
 
 	if (flag & BOOTM_STATE_OS_FAKE_GO)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v4 17/17] sandbox: Call bootm_final()
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (15 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 16/17] xtensa: " Simon Glass
@ 2026-03-06  2:36 ` Simon Glass
  2026-03-19 13:52 ` [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Tom Rini
  17 siblings, 0 replies; 24+ messages in thread
From: Simon Glass @ 2026-03-06  2:36 UTC (permalink / raw)
  To: u-boot; +Cc: Tom Rini, Simon Glass, Simon Glass

From: Simon Glass <simon.glass@canonical.com>

Add a call to bootm_final() before the simulated kernel jump. This
adds the "Starting kernel" message, bootstage tracking,
board_quiesce_devices() and dm_remove_devices_active() which were not
previously called on sandbox.

Signed-off-by: Simon Glass <simon.glass@canonical.com>

---

Changes in v4:
- Pass flag directly instead of using BOOTM_FINAL_FAKE

Changes in v3:
- Add new patch for sandbox conversion

 arch/sandbox/lib/bootm.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/sandbox/lib/bootm.c b/arch/sandbox/lib/bootm.c
index 44ba8b52e13..7a5f6f7d36e 100644
--- a/arch/sandbox/lib/bootm.c
+++ b/arch/sandbox/lib/bootm.c
@@ -73,6 +73,7 @@ int do_bootm_linux(int flag, struct bootm_info *bmi)
 
 	if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) {
 		bootstage_mark(BOOTSTAGE_ID_RUN_OS);
+		bootm_final(flag);
 		printf("## Transferring control to Linux (at address %08lx)...\n",
 		       images->ep);
 		printf("sandbox: continuing, as we cannot run Linux\n");
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 11/17] mips: Call bootm_final()
  2026-03-06  2:36 ` [PATCH v4 11/17] mips: " Simon Glass
@ 2026-03-06 12:20   ` Daniel Schwierzeck
  0 siblings, 0 replies; 24+ messages in thread
From: Daniel Schwierzeck @ 2026-03-06 12:20 UTC (permalink / raw)
  To: Simon Glass, u-boot; +Cc: Tom Rini, Simon Glass



On 3/6/26 03:36, Simon Glass wrote:
> From: Simon Glass <simon.glass@canonical.com>
> 
> Replace the open-coded bootstage_fdt_add_report() and
> bootstage_report() with a call to bootm_final(). This also adds the
> "Starting kernel" message, board_quiesce_devices() and
> dm_remove_devices_active() which were not previously called on MIPS.
> 
> Signed-off-by: Simon Glass <simon.glass@canonical.com>
> 
> ---
> 
> (no changes since v3)
> 
> Changes in v3:
> - Add new patch for MIPS conversion
> 
>   arch/mips/lib/bootm.c | 7 +------
>   1 file changed, 1 insertion(+), 6 deletions(-)
> 

Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>

-- 
- Daniel


^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 04/17] bootm: Create bootm_final() for pre-boot cleanup
  2026-03-06  2:36 ` [PATCH v4 04/17] bootm: Create bootm_final() for pre-boot cleanup Simon Glass
@ 2026-03-06 15:12   ` Tom Rini
  0 siblings, 0 replies; 24+ messages in thread
From: Tom Rini @ 2026-03-06 15:12 UTC (permalink / raw)
  To: Simon Glass
  Cc: u-boot, Simon Glass, Aristo Chen, Benjamin ROBIN,
	Ilias Apalodimas, Quentin Schulz, Sughosh Ganu, Wolfgang Wallner,
	牛 志宏

[-- Attachment #1: Type: text/plain, Size: 889 bytes --]

On Thu, Mar 05, 2026 at 07:36:13PM -0700, Simon Glass wrote:

> From: Simon Glass <simon.glass@canonical.com>
> 
> 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>

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 06/17] riscv: Call bootm_final()
  2026-03-06  2:36 ` [PATCH v4 06/17] riscv: " Simon Glass
@ 2026-03-06 15:12   ` Tom Rini
  0 siblings, 0 replies; 24+ messages in thread
From: Tom Rini @ 2026-03-06 15:12 UTC (permalink / raw)
  To: Simon Glass
  Cc: u-boot, Simon Glass, Aristo Chen, Benjamin ROBIN,
	Heinrich Schuchardt, Ilias Apalodimas, Leo, Mattijs Korpershoek,
	Mayuresh Chitale, Rick Chen, Sughosh Ganu,
	牛 志宏

[-- Attachment #1: Type: text/plain, Size: 567 bytes --]

On Thu, Mar 05, 2026 at 07:36:15PM -0700, Simon Glass wrote:

> From: Simon Glass <simon.glass@canonical.com>
> 
> 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 <simon.glass@canonical.com>
> 

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 08/17] arm: Call bootm_final()
  2026-03-06  2:36 ` [PATCH v4 08/17] arm: Call bootm_final() Simon Glass
@ 2026-03-06 15:12   ` Tom Rini
  0 siblings, 0 replies; 24+ messages in thread
From: Tom Rini @ 2026-03-06 15:12 UTC (permalink / raw)
  To: Simon Glass
  Cc: u-boot, Simon Glass, Albert Aribaud, Heinrich Schuchardt,
	Marek Vasut, Mattijs Korpershoek, Quentin Schulz, Vishnu Singh

[-- Attachment #1: Type: text/plain, Size: 671 bytes --]

On Thu, Mar 05, 2026 at 07:36:17PM -0700, Simon Glass wrote:

> From: Simon Glass <simon.glass@canonical.com>
> 
> The ARM announce_and_cleanup() duplicates the common pre-boot steps.
> Replace it with a call to bootm_final().
> 
> Drop the ARM weak board_quiesce_devices() definition since it is now
> called from bootm_final() and the generic weak definition in bootm.h
> is used instead.
> 
> Note that the printf() ordering changes slightly: it now prints before
> bootstage processing rather than after, matching x86 and RISC-V.
> 
> Signed-off-by: Simon Glass <simon.glass@canonical.com>
> 

Reviewed-by: Tom Rini <trini@konsulko.com>

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 13/17] m68k: Call bootm_final()
  2026-03-06  2:36 ` [PATCH v4 13/17] m68k: " Simon Glass
@ 2026-03-07 16:36   ` Kuan-Wei Chiu
  0 siblings, 0 replies; 24+ messages in thread
From: Kuan-Wei Chiu @ 2026-03-07 16:36 UTC (permalink / raw)
  To: Simon Glass
  Cc: u-boot, Tom Rini, Simon Glass, Angelo Dureghello, Alison Wang,
	Angelo Dureghello

On Thu, Mar 05, 2026 at 07:36:22PM -0700, Simon Glass wrote:
> From: Simon Glass <simon.glass@canonical.com>
> 
> Add a call to bootm_final() before jumping to the kernel. This adds
> the "Starting kernel" message, bootstage tracking,
> board_quiesce_devices() and dm_remove_devices_active() which were not
> previously called on m68k.
> 
> Signed-off-by: Simon Glass <simon.glass@canonical.com>
> Acked-by: Angelo Dureghello <angelo@kernel-space.org>
> Tested-by: Angelo Dureghello <angelo@kernel-space.org>

FWIW:

Acked-by: Kuan-Wei Chiu <visitorckw@gmail.com>

Regards,
Kuan-Wei

> 
> ---
> 
> (no changes since v3)
> 
> Changes in v3:
> - Add new patch for m68k conversion
> 
>  arch/m68k/lib/bootm.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/arch/m68k/lib/bootm.c b/arch/m68k/lib/bootm.c
> index 3dcff8076e3..7e36ac73169 100644
> --- a/arch/m68k/lib/bootm.c
> +++ b/arch/m68k/lib/bootm.c
> @@ -65,6 +65,8 @@ int do_bootm_linux(int flag, struct bootm_info *bmi)
>  
>  	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
>  
> +	bootm_final(0);
> +
>  	/*
>  	 * Linux Kernel Parameters (passing board info data):
>  	 *   sp+00: Ignore, side effect of using jsr to jump to kernel
> -- 
> 2.43.0
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up
  2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
                   ` (16 preceding siblings ...)
  2026-03-06  2:36 ` [PATCH v4 17/17] sandbox: " Simon Glass
@ 2026-03-19 13:52 ` Tom Rini
  17 siblings, 0 replies; 24+ messages in thread
From: Tom Rini @ 2026-03-19 13:52 UTC (permalink / raw)
  To: u-boot, Simon Glass
  Cc: Albert Aribaud, Alexey Brodkin, Alison Wang, Andy Fleming,
	Angelo Dureghello, Angelo Dureghello, Aristo Chen, Benjamin ROBIN,
	Bin Meng, Daniel Schwierzeck, Eugeniy Paltsev, Guillaume Ranquet,
	Ilias Apalodimas, Kuan-Wei Chiu, Leo, Marek Vasut, Marek Vasut,
	Mario Six, Mattijs Korpershoek, Michal Simek, Nobuhiro Iwamatsu,
	Patrice Chotard, Pavel Herrmann, Peng Fan, Priyanka Jain,
	Quentin Schulz, Rick Chen, Scott McNutt, Stefan Roese,
	Sughosh Ganu, Thomas Chou, Vishnu Singh, Wolfgang Denk,
	Wolfgang Wallner, Yao Zi, uboot-snps-arc, Michal Simek

On Thu, 05 Mar 2026 19:36:09 -0700, Simon Glass wrote:

> Each arch does something slightly different before booting the OS. Some
> archs even do different things depending on the CPU type.
> 
> It is quite hard to know what actually happens in the final milliseconds
> before the OS boot.
> 
> This series attempts to start cleaning up U-Boot in this area.
> 
> [...]

Applied to u-boot/next, thanks!

[01/17] dm: Move flags_remove() check before child removal
        commit: 714dd2252dacfaabf0a72b31b9b7e22a8d816460
[02/17] dm: Remove children when parent is removed by flags
        commit: 3632b5d63c8099c59c936c3653ece5bd04d8f6c7
[03/17] bootstage: Add some missing dummy functions
        commit: 5cc969caf0ba247d8464af1fd87110e73309e37d
[04/17] bootm: Create bootm_final() for pre-boot cleanup
        commit: 1ec3ee670de6b2f8f96cd7c15f7e22e89a06bb2d
[05/17] x86: Call bootm_final()
        commit: 8240a482290960e49a7c2a537b7100120ef4ec20
[06/17] riscv: Call bootm_final()
        commit: aa5ada5447369849c82310073270ed64df1efd9b
[07/17] bootm: Stash bootstage data in bootm_final()
        commit: 5759155b023e93c24268911a8a40110ec4b13dd9
[08/17] arm: Call bootm_final()
        commit: ba992d3eacd0a3ac72ff83a022a5c545bb609e76
[09/17] arc: Call bootm_final()
        commit: 47545a6411da58eb865561a4d026da55781d60ef
[10/17] microblaze: Call bootm_final()
        commit: b8806785c15fa0c5541f9fded66644fbcbcddfc8
[11/17] mips: Call bootm_final()
        commit: 96216ef50701f8219610d0b0cfdb26624ef13baa
[12/17] powerpc: Call bootm_final()
        commit: 15e58f975aa42ffbc9170ac226cc480962c6df59
[13/17] m68k: Call bootm_final()
        commit: 3b4bd773e093e777d35f2d951d1868de1a3cc2f3
[14/17] nios2: Call bootm_final()
        commit: 81334489c0f3e3982c46e9ff5986097d43adaec9
[15/17] sh: Call bootm_final()
        commit: 7fec6d005bdb55e27f1de3d6784dfe8815691bd4
[16/17] xtensa: Call bootm_final()
        commit: 9c4edbddce767fae54a4ba1519cc15e55dd198ec
[17/17] sandbox: Call bootm_final()
        commit: dc88ac7681084b2aff8c3c4e1bb3e861451489a3
-- 
Tom



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2026-03-19 14:18 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06  2:36 [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Simon Glass
2026-03-06  2:36 ` [PATCH v4 01/17] dm: Move flags_remove() check before child removal Simon Glass
2026-03-06  2:36 ` [PATCH v4 02/17] dm: Remove children when parent is removed by flags Simon Glass
2026-03-06  2:36 ` [PATCH v4 03/17] bootstage: Add some missing dummy functions Simon Glass
2026-03-06  2:36 ` [PATCH v4 04/17] bootm: Create bootm_final() for pre-boot cleanup Simon Glass
2026-03-06 15:12   ` Tom Rini
2026-03-06  2:36 ` [PATCH v4 05/17] x86: Call bootm_final() Simon Glass
2026-03-06  2:36 ` [PATCH v4 06/17] riscv: " Simon Glass
2026-03-06 15:12   ` Tom Rini
2026-03-06  2:36 ` [PATCH v4 07/17] bootm: Stash bootstage data in bootm_final() Simon Glass
2026-03-06  2:36 ` [PATCH v4 08/17] arm: Call bootm_final() Simon Glass
2026-03-06 15:12   ` Tom Rini
2026-03-06  2:36 ` [PATCH v4 09/17] arc: " Simon Glass
2026-03-06  2:36 ` [PATCH v4 10/17] microblaze: " Simon Glass
2026-03-06  2:36 ` [PATCH v4 11/17] mips: " Simon Glass
2026-03-06 12:20   ` Daniel Schwierzeck
2026-03-06  2:36 ` [PATCH v4 12/17] powerpc: " Simon Glass
2026-03-06  2:36 ` [PATCH v4 13/17] m68k: " Simon Glass
2026-03-07 16:36   ` Kuan-Wei Chiu
2026-03-06  2:36 ` [PATCH v4 14/17] nios2: " Simon Glass
2026-03-06  2:36 ` [PATCH v4 15/17] sh: " Simon Glass
2026-03-06  2:36 ` [PATCH v4 16/17] xtensa: " Simon Glass
2026-03-06  2:36 ` [PATCH v4 17/17] sandbox: " Simon Glass
2026-03-19 13:52 ` [PATCH v4 00/17] bootm: Clean up arch-specific, pre-OS clean-up Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox