Skip to contentSkip to conversation

bootm: Clean up arch-specific, pre-OS clean-up

PATCH Superseded Simon Glass 3 participants 20 messages Feb 24 – Feb 27

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover bootm: Clean up arch-specific, pre-OS clean-up

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.

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.

There is also a patch to drop EFI_GRUB_ARM32_WORKAROUND, as discussed recently on the mailing list.

Future work could take this a little further:
- Drop board_quiesce_devices() and rely on driver model for that
- Similarly with udc_disconnect()
- Look at converting EFI to use the same function

Also, the comment for cleanup_before_linux() could use more details as to what it is supposed to do, to reduce the number of arch-specific variations. It currently does different things on differents archs and is mostly uncommented (apart from an ARM-specific note in a README). Ideally it would be commented with exactly what it should do, ideally at a high level so it is not just arch-specific.

While some of these arch-specific differences are necessary, some are just due to the changes to code over time.

Changes in v2:
- Replace 'efi: Make use of bootm_final()' with a non-EFI patch
- Drop comment about EFI
- Drop the EFI change
- Drop the call to udc_disconnect()
- Drop the EFI_LOADER change
- Drop patch 'efi: Drop EFI_GRUB_ARM32_WORKAROUND'
- Update cover message to reflect dropping the EFI patches, etc.

Simon Glass (9):
boot: Create a function for final pre-boot steps
bootm: Remove active devices in 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()
x86: Add cleanup_before_linux()

 MAINTAINERS                           |  1 +
 arch/riscv/include/asm/u-boot-riscv.h |  1 -
 arch/riscv/lib/bootm.c                | 24 +------------------
 arch/x86/cpu/cpu.c                    |  5 ++++
 arch/x86/lib/bootm.c                  | 14 +----------
 boot/Makefile                         |  2 +-
 boot/bootm_final.c                    | 34 +++++++++++++++++++++++++++
 include/bootm.h                       | 17 ++++++++++++++
 include/bootstage.h                   |  8 +++++++
 9 files changed, 68 insertions(+), 38 deletions(-)
 create mode 100644 boot/bootm_final.c
Signature · 4 lines
2.43.0

base-commit: 8fd76675efbe7af785ccc1ba1ac8b9f7e10f6715
branch: bootma-us2
#1 lore raw

PATCH v2 1/9 boot: Create a function for final pre-boot steps

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. Be careful to avoid using BIT() macros which are not available with host tools.

---

(no changes since v1)

 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
MAINTAINERS +1 -0
index f8d4f6ee8b2..beebb491f28 100644
@@ -983,6 +983,7 @@ M:	Simon Glass <[email protected]>
 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
boot/Makefile +1 -1
index 7fb56e7ef37..12477fabe28 100644
@@ -15,7 +15,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
boot/bootm_final.c new file +12 -0
new file mode 100644
index 00000000000..15ddbbe5e74
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Cleanup before handing off to the OS
+ *
+ * Copyright 2025 Simon Glass <[email protected]>
+ */
+
+#include <bootm.h>
+
+void bootm_final(enum bootm_final_t flags)
+{
+}
include/bootm.h +17 -0
index 4060cec7fc0..32711eabb2e 100644
@@ -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	= 1 << 0,
+};
+
 /**
  * struct bootm_info() - information used when processing images to boot
  *
@@ -321,4 +331,11 @@ 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
+ *
+ * @flags: Flags to control what this function does
+ */
+void bootm_final(enum bootm_final_t flags);
+
 #endif
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v2 1/9] boot: Create a function for final pre-boot steps

Quoted 13 lines · Simon Glass

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. Be careful to avoid using BIT() macros which are not available with host tools.

---

Quoted 8 lines

(no changes since v1)

 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

I don't think a new file for a function is worthwhile given the linker optimization related fun that then happens (even with LTO). This should just go in one of the existing bootm files.

Signature · 1 line
Tom
#3 lore raw

Re: [PATCH v2 1/9] boot: Create a function for final pre-boot steps

In reply to Simon Glass

Am 24.02.26 um 15:25 schrieb Simon Glass:

Quoted 4 lines

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

change "the a" to "a"

Quoted 94 lines

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. Be careful to avoid using BIT() macros which are not available with host tools.

---

(no changes since v1)

  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

MAINTAINERS +1 -0
index f8d4f6ee8b2..beebb491f28 100644
@@ -983,6 +983,7 @@ M:	Simon Glass <[email protected]>
  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
boot/Makefile +1 -1
index 7fb56e7ef37..12477fabe28 100644
@@ -15,7 +15,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
boot/bootm_final.c new file +12 -0
new file mode 100644
index 00000000000..15ddbbe5e74
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Cleanup before handing off to the OS
+ *
+ * Copyright 2025 Simon Glass <[email protected]>
+ */
+
+#include <bootm.h>
+
+void bootm_final(enum bootm_final_t flags)
+{
+}
include/bootm.h +17 -0
index 4060cec7fc0..32711eabb2e 100644
@@ -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	= 1 << 0,
+};
+
  /**
   * struct bootm_info() - information used when processing images to boot
   *
@@ -321,4 +331,11 @@ 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
+ *
+ * @flags: Flags to control what this function does
+ */
+void bootm_final(enum bootm_final_t flags);
+
  #endif
Signature · 7 lines
Best regards,
Max

TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/
#4 lore raw

PATCH v2 2/9 bootm: Remove active devices in bootm_final()

In reply to Simon Glass

Add a call to dm_remove_devices_active() there to ensure that active devices are removed.

---

Changes in v2:
- Replace 'efi: Make use of bootm_final()' with a non-EFI patch

 boot/bootm_final.c | 2 ++
 1 file changed, 2 insertions(+)
boot/bootm_final.c +2 -0
index 15ddbbe5e74..263cd95dcb3 100644
@@ -6,7 +6,9 @@
  */
 
 #include <bootm.h>
+#include <dm/root.h>
 
 void bootm_final(enum bootm_final_t flags)
 {
+	dm_remove_devices_active();
 }
Signature · 1 line
2.43.0
#5 lore raw

Re: [PATCH v2 2/9] bootm: Remove active devices in bootm_final()

Quoted 17 lines · Simon Glass

Add a call to dm_remove_devices_active() there to ensure that active devices are removed.

---

Changes in v2:
- Replace 'efi: Make use of bootm_final()' with a non-EFI patch

 boot/bootm_final.c | 2 ++
 1 file changed, 2 insertions(+)
boot/bootm_final.c +0 -0
index 15ddbbe5e74..263cd95dcb3 100644

boot/bootm_final.c line 14

Quoted 9 lines
boot/bootm_final.c +2 -0
@@ -6,7 +6,9 @@
  */
 
 #include <bootm.h>
+#include <dm/root.h>
 
 void bootm_final(enum bootm_final_t flags)
 {
+	dm_remove_devices_active();
 }

And lets just make the function be introduced non-empty, and document what it's doing in the header too. In fact, this comment applies to the first few parts of this series. Just introduce the function with the basic and common to all functionality.

Signature · 1 line
Tom
#6 lore raw

PATCH v2 3/9 bootm: Add a message when booting

In reply to Simon Glass

Add a message about starting the kernel.

---

Changes in v2:
- Drop comment about EFI

 boot/bootm_final.c | 2 ++
 1 file changed, 2 insertions(+)
boot/bootm_final.c +2 -0
index 263cd95dcb3..71661334e11 100644
@@ -10,5 +10,7 @@
 
 void bootm_final(enum bootm_final_t flags)
 {
+	printf("\nStarting kernel ...\n\n");
+
 	dm_remove_devices_active();
 }
Signature · 1 line
2.43.0
#7 lore raw

PATCH v2 4/9 bootstage: Add some missing dummy functions

In reply to Simon Glass

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

---

(no changes since v1)

 include/bootstage.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/bootstage.h +8 -0
index 528d0ca0614..62fb99110f0 100644
@@ -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 */
Signature · 1 line
2.43.0
Reviewed-by on v2 4/9
#8 lore raw

Re: [PATCH v2 4/9] bootstage: Add some missing dummy functions

Quoted 4 lines · Simon Glass

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

While I am ambivalent about which is more readable, this at least matches much of the other usage of bootstage functions. It should however be one of the first patches in the series, so that bootm_final can be introduced with this too.

Signature · 1 line
Tom
#9 lore raw

PATCH v2 5/9 bootm: Do bootstage processing in bootm_final()

In reply to Simon Glass

Mark kernel start before booting. If enabled, show a bootstage report.

---

Changes in v2:
- Drop the EFI change

 boot/bootm_final.c | 6 ++++++
 1 file changed, 6 insertions(+)
boot/bootm_final.c +6 -0
index 71661334e11..dd7cac55f1e 100644
@@ -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();
 }
Signature · 1 line
2.43.0
#10 lore raw

PATCH v2 6/9 x86: Call bootm_final()

In reply to Simon Glass

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.

---

(no changes since v1)

 arch/x86/lib/bootm.c | 14 +-------------
 boot/bootm_final.c   |  5 +++++
 2 files changed, 6 insertions(+), 13 deletions(-)
arch/x86/lib/bootm.c +1 -13
index 7a94dc877e3..cde4fbf3557 100644
@@ -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)
boot/bootm_final.c +5 -0
index dd7cac55f1e..7077702d8c7 100644
@@ -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();
 }
Signature · 1 line
2.43.0
#11 lore raw

Re: [PATCH v2 6/9] x86: Call bootm_final()

Am 24.02.26 um 15:25 schrieb Simon Glass:

Quoted 46 lines

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.

---

(no changes since v1)

  arch/x86/lib/bootm.c | 14 +-------------
  boot/bootm_final.c   |  5 +++++
  2 files changed, 6 insertions(+), 13 deletions(-)
arch/x86/lib/bootm.c +1 -13
index 7a94dc877e3..cde4fbf3557 100644
@@ -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)
boot/bootm_final.c +0 -0
index dd7cac55f1e..7077702d8c7 100644

boot/bootm_final.c void bootm_final(enum bootm_final_t flags) · line 27

Quoted 10 lines
boot/bootm_final.c +5 -0
@@ -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();
  }

I think it would be better if the comment were inserted together with the function. In Patch [PATCH v2 2/9] bootm: Remove active devices in bootm_final()

Signature · 7 lines
Best regards,
Max

TQ-Systems GmbH | Mühlstraße 2, Gut Delling | 82229 Seefeld, Germany
Amtsgericht München, HRB 105018
Geschäftsführer: Detlef Schneider, Rüdiger Stahl, Stefan Schneider
http://www.tq-group.com/
#12 lore raw

PATCH v2 7/9 riscv: Drop board_quiesce_devices()

In reply to Simon Glass

This is not used on RISC-V so drop it.

---

Changes in v2:
- Drop the call to udc_disconnect()

 arch/riscv/include/asm/u-boot-riscv.h | 1 -
 arch/riscv/lib/bootm.c                | 6 ------
 2 files changed, 7 deletions(-)
arch/riscv/include/asm/u-boot-riscv.h +0 -1
index 543a1688db8..3a8fdb57136 100644
@@ -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);
 
arch/riscv/lib/bootm.c +0 -6
index 9544907ab1e..c6a008a4559 100644
@@ -25,10 +25,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-__weak void board_quiesce_devices(void)
-{
-}
-
 /**
  * announce_and_cleanup() - Print message and prepare for kernel boot
  *
@@ -46,8 +42,6 @@ static void announce_and_cleanup(int fake)
 	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
Signature · 1 line
2.43.0
#13 lore raw

Re: [PATCH v2 7/9] riscv: Drop board_quiesce_devices()

Quoted 40 lines · Simon Glass

This is not used on RISC-V so drop it.

---

Changes in v2:
- Drop the call to udc_disconnect()

 arch/riscv/include/asm/u-boot-riscv.h | 1 -
 arch/riscv/lib/bootm.c                | 6 ------
 2 files changed, 7 deletions(-)
arch/riscv/include/asm/u-boot-riscv.h +0 -1
index 543a1688db8..3a8fdb57136 100644
@@ -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);
 
arch/riscv/lib/bootm.c +0 -4
index 9544907ab1e..c6a008a4559 100644
@@ -25,10 +25,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-__weak void board_quiesce_devices(void)
-{
-}
-
 /**
  * announce_and_cleanup() - Print message and prepare for kernel boot
  *

arch/riscv/lib/bootm.c static void announce_and_cleanup(int fake) · line 47

Quoted 8 lines
arch/riscv/lib/bootm.c +0 -2
@@ -46,8 +42,6 @@ static void announce_and_cleanup(int fake)
 	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

This should end up in bootm_final, as the generic hook for things which don't fit in to the DM model.

Signature · 1 line
Tom
#14 lore raw

PATCH v2 8/9 riscv: Call bootm_final()

In reply to Simon Glass

Make use of this function, adding some pieces needed by RISC-V

---

Changes in v2:
- Drop the EFI_LOADER change

 arch/riscv/lib/bootm.c | 18 +-----------------
 boot/bootm_final.c     |  9 ++++++++-
 2 files changed, 9 insertions(+), 18 deletions(-)
arch/riscv/lib/bootm.c +1 -17
index c6a008a4559..bd47275b52e 100644
@@ -32,23 +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
-
-	/*
-	 * 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();
 }
 
boot/bootm_final.c +8 -1
index 7077702d8c7..7f069877d06 100644
@@ -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
Signature · 1 line
2.43.0
#15 lore raw

Re: [PATCH v2 8/9] riscv: Call bootm_final()

Quoted 3 lines · Simon Glass

Make use of this function, adding some pieces needed by RISC-V

[snip]

boot/bootm_final.c line 26

Quoted 2 lines
boot/bootm_final.c +2 -0
+	if (IS_ENABLED(CONFIG_USB_DEVICE))
+		udc_disconnect();

This is still a NAK because nothing does this today.

Signature · 1 line
Tom
#16 lore raw

PATCH v2 9/9 x86: Add cleanup_before_linux()

In reply to Simon Glass

This function is not present on x86, but there is an x86-specific version which is never called. This is a bug, meaning that APs are not parked before booting.

The original weak function was added in 2012 by:
commit f30fc4de4160 ("x86: Add a default implementation for cleanup_before_linux()")

At later change made use of the weak function but was actually dead code. The Fixes tag reflects that.

Add cleanup_before_linux(), making it call x86_cleanup_before_linux()

Fixes 99a573fb326f ("x86: mp: Park CPUs before running the OS")

---

(no changes since v1)

 arch/x86/cpu/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)
arch/x86/cpu/cpu.c +5 -0
index c373b14df30..f756a9ebf09 100644
@@ -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();
Signature · 1 line
2.43.0
#17 lore raw

Re: [PATCH v2 9/9] x86: Add cleanup_before_linux()

Quoted 7 lines · Simon Glass

This function is not present on x86, but there is an x86-specific version which is never called. This is a bug, meaning that APs are not parked before booting.

The original weak function was added in 2012 by:
commit f30fc4de4160 ("x86: Add a default implementation for cleanup_before_linux()")

Quoted 7 lines

At later change made use of the weak function but was actually dead code. The Fixes tag reflects that.

Add cleanup_before_linux(), making it call x86_cleanup_before_linux()

Fixes 99a573fb326f ("x86: mp: Park CPUs before running the OS")

We're at over 5 years since 99a573fb326f and over a decade since f30fc4de4160 and I don't think it was ever actually called. We should just be dropping this, not suddenly calling it.

Signature · 1 line
Tom
#18 lore raw
In reply to Simon Glass
Quoted 6 lines · Simon Glass

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.

Quoted 8 lines

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.

RISC-V, x86 and ARM are converted over to use this new function. For consistency, EFI loader is converted as well.

Please include all architectures in v3, ARM is still not shown in this series.

Quoted 8 lines

A noteable change is that EFI_LOADER now does bootstage processing before boot, if enabled, thus producing a report.

There is also a patch to drop EFI_GRUB_ARM32_WORKAROUND, as discussed recently on the mailing list.

Future work could take this a little further:
- Drop board_quiesce_devices() and rely on driver model for that

Potentially, but there's non-trivial uses that don't fit in driver model today either.

Quoted 1 line

- Similarly with udc_disconnect()

Please look at mainline code again.

Quoted 1 line

- Look at converting EFI to use the same function

You said a few lines above EFI was converted? Please make sure your cover letter is consistent and correct in v3.

Quoted 9 lines

Also, the comment for cleanup_before_linux() could use more details as to what it is supposed to do, to reduce the number of arch-specific variations. It currently does different things on differents archs and is mostly uncommented (apart from an ARM-specific note in a README). Ideally it would be commented with exactly what it should do, ideally at a high level so it is not just arch-specific.

While some of these arch-specific differences are necessary, some are just due to the changes to code over time.

This is due to the entry requirements for Linux being architecture specific. This is more consistent than it was 15 years ago (especially since RISC-V looked at arm64 and copy/pasted as much as they could, which is a good thing!) but still an inherently architecture-specific thing, so yes, we may only end up with limited overlap.

Signature · 1 line
Tom
#19 lore raw

Hi Tom,

Quoted 49 lines · Tom Rini
Quoted 6 lines · Simon Glass

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.

Quoted 8 lines

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.

RISC-V, x86 and ARM are converted over to use this new function. For consistency, EFI loader is converted as well.

Please include all architectures in v3, ARM is still not shown in this series.

Quoted 8 lines

A noteable change is that EFI_LOADER now does bootstage processing before boot, if enabled, thus producing a report.

There is also a patch to drop EFI_GRUB_ARM32_WORKAROUND, as discussed recently on the mailing list.

Future work could take this a little further:
- Drop board_quiesce_devices() and rely on driver model for that

Potentially, but there's non-trivial uses that don't fit in driver model today either.

Quoted 1 line

- Similarly with udc_disconnect()

Please look at mainline code again.

Quoted 1 line

- Look at converting EFI to use the same function

You said a few lines above EFI was converted? Please make sure your cover letter is consistent and correct in v3.

Quoted 7 lines

Also, the comment for cleanup_before_linux() could use more details as to what it is supposed to do, to reduce the number of arch-specific variations. It currently does different things on differents archs and is mostly uncommented (apart from an ARM-specific note in a README). Ideally it would be commented with exactly what it should do, ideally at a high level so it is not just arch-specific.

Quoted 8 lines
Quoted 2 lines

While some of these arch-specific differences are necessary, some are just due to the changes to code over time.

This is due to the entry requirements for Linux being architecture specific. This is more consistent than it was 15 years ago (especially since RISC-V looked at arm64 and copy/pasted as much as they could, which is a good thing!) but still an inherently architecture-specific thing, so yes, we may only end up with limited overlap.

Just to pick up on this point, yes different Linux interfaces are needed, but that is not the target of this series. I am more talking about the differences which are either unintended, or just a rusult of there being more development on some archs than others.

Regards,
Simon