Skip to contentSkip to conversation

arm: add call to cleanup_before_linux for go command

PATCH In review Anshul Dalal 4 participants 12 messages Apr 30, 2025 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: add call to cleanup_before_linux for go command

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

NOTE: This might cause regressions with users expecting a configured MMU but I'm unsure if it's a supported use case for the go command anyway.

[1]: https://lore.kernel.org/u-boot/[email protected]/

---
 arch/arm/lib/Makefile |  1 +
 arch/arm/lib/boot.c   | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 arch/arm/lib/boot.c
arch/arm/lib/Makefile +1 -0
index 74cd5051552..e4cb50a7f71 100644
@@ -24,6 +24,7 @@ endif
 ifndef CONFIG_XPL_BUILD
 ifdef CONFIG_ARM64
 obj-y	+= relocate_64.o
+obj-y	+= boot.o
 else
 obj-y	+= relocate.o
 endif
arch/arm/lib/boot.c new file +16 -0
new file mode 100644
index 00000000000..eafdb0f9e5a
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2025 Texas Instruments Incorporated - https://www.ti.com/
+ * Anshul Dalal, <[email protected]>
+ */
+
+#include <command.h>
+#include <asm/u-boot-arm.h>
+
+unsigned long do_go_exec(ulong (*entry)(int, char *const[]), int argc,
+			 char *const argv[])
+{
+	cleanup_before_linux();
+
+	return entry(argc, argv);
+}
Signature · 1 line
2.49.0
#1 lore raw
Quoted 8 lines · Anshul Dalal

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

Quoted 6 lines

NOTE: This might cause regressions with users expecting a configured MMU but I'm unsure if it's a supported use case for the go command anyway.

[1]: https://lore.kernel.org/u-boot/[email protected]/

This is the inverse of what needs to be done, sorry. RISC-V shouldn't be doing this type of cleanup. I know it sounds reductive but "go means go". We have all of the other bootX commands for "prepare the system and boot the thing at $address".

Signature · 1 line
Tom
#2 lore raw
Quoted 13 lines · Tom Rini
Quoted 11 lines · Anshul Dalal

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

NOTE: This might cause regressions with users expecting a configured MMU but I'm unsure if it's a supported use case for the go command anyway.

Quoted 8 lines
Quoted 3 lines

[1]: https://lore.kernel.org/u-boot/[email protected]/

This is the inverse of what needs to be done, sorry. RISC-V shouldn't be doing this type of cleanup. I know it sounds reductive but "go means go". We have all of the other bootX commands for "prepare the system and boot the thing at $address".

Well, "go means go" implies we jump to the necessary DDR address and start executing. But with caches enabled, it fails in cases where we have that specific address in the icache already. In that case the execution starts from whatever's stored in the icache and not really DDR.

#3 lore raw
Quoted 23 lines · Anshul Dalal
Quoted 13 lines · Tom Rini
Quoted 11 lines · Anshul Dalal

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

NOTE: This might cause regressions with users expecting a configured MMU but I'm unsure if it's a supported use case for the go command anyway.

Quoted 8 lines
Quoted 3 lines

[1]: https://lore.kernel.org/u-boot/[email protected]/

This is the inverse of what needs to be done, sorry. RISC-V shouldn't be doing this type of cleanup. I know it sounds reductive but "go means go". We have all of the other bootX commands for "prepare the system and boot the thing at $address".

Quoted 5 lines

Well, "go means go" implies we jump to the necessary DDR address and start executing. But with caches enabled, it fails in cases where we have that specific address in the icache already. In that case the execution starts from whatever's stored in the icache and not really DDR.

Yes, and if you're using go you're supposed to disable the cache and force a flush. Or you're doing something Interesting and nothing else should be getting in the way.

Signature · 1 line
Tom
#4 lore raw
In reply to Anshul Dalal

On April 30, 2025 thus sayeth Anshul Dalal:

Quoted 8 lines

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

I know quite a few other OSes are beginning to use U-Boot (QNX, GreenHills or all the other RTOSes) each with their own requirements from the bootloader. I'm curious if we should make boot* a little more generic rather than abuse the 'go' command.

~Bryan

#5 lore raw
Quoted 10 lines · Bryan Brattlof

On April 30, 2025 thus sayeth Anshul Dalal:

Quoted 8 lines

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

Quoted 4 lines

I know quite a few other OSes are beginning to use U-Boot (QNX, GreenHills or all the other RTOSes) each with their own requirements from the bootloader. I'm curious if we should make boot* a little more generic rather than abuse the 'go' command.

Well, that's what bootelf is for :)

Signature · 1 line
Tom
#6 lore raw
Quoted 11 lines · Tom Rini
Quoted 10 lines · Bryan Brattlof

On April 30, 2025 thus sayeth Anshul Dalal:

Quoted 8 lines

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

Quoted 4 lines
Quoted 4 lines

I know quite a few other OSes are beginning to use U-Boot (QNX, GreenHills or all the other RTOSes) each with their own requirements from the bootloader. I'm curious if we should make boot* a little more generic rather than abuse the 'go' command.

VXworks has its own:
https://docs.u-boot.org/en/stable/usage/os/vxworks.html

I suppose QNX and others should ideally have their own cmds as needed.

Quoted 3 lines

Well, that's what bootelf is for :)

And if its not an elf but some .bin file "go" cmd should be used in conjunction with "cache" cmd here to flush/disable cache, I guess?

If so, we should probably update the docs for this cmd appropriately so as to avoid end users overloading like what RISC-V did?

Regards
Vignesh

#7 lore raw
Quoted 19 lines · Vignesh
Quoted 11 lines · Tom Rini
Quoted 10 lines · Bryan Brattlof

On April 30, 2025 thus sayeth Anshul Dalal:

Quoted 8 lines

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

Quoted 4 lines
Quoted 4 lines

I know quite a few other OSes are beginning to use U-Boot (QNX, GreenHills or all the other RTOSes) each with their own requirements from the bootloader. I'm curious if we should make boot* a little more generic rather than abuse the 'go' command.

Quoted 4 lines

VXworks has its own:
https://docs.u-boot.org/en/stable/usage/os/vxworks.html

I suppose QNX and others should ideally have their own cmds as needed.

Well, what's the QNX output file format (options?) again?

Quoted 5 lines
Quoted 2 lines

Well, that's what bootelf is for :)

And if its not an elf but some .bin file "go" cmd should be used in conjunction with "cache" cmd here to flush/disable cache, I guess?

Well, what exactly are we talking about? Is this an "in theory" or some project(s) which exist today?

There's a whole lot of reasons for either a legacy header and bootm or a not-legacy FIT image. The "go" command is for the "U-Boot is a debugger" side of the world, not how you should kick off some OS/application in production. It is all of the "this is dangerous" idioms.

Quoted 2 lines

If so, we should probably update the docs for this cmd appropriately so as to avoid end users overloading like what RISC-V did?

Yes, we should clarify things as needed and unwind, most likely, what RISC-V is doing. But not blindly so as perhaps there's now, sigh, a production / in-the-wild case here and we're now in a sticky spot.

Signature · 1 line
Tom
#8 lore raw

On April 30, 2025 thus sayeth Tom Rini:

Quoted 20 lines · Vignesh
Quoted 19 lines · Tom Rini
Quoted 15 lines · Bryan Brattlof
Quoted 14 lines

On April 30, 2025 thus sayeth Anshul Dalal:

Quoted 8 lines

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

I know quite a few other OSes are beginning to use U-Boot (QNX, GreenHills or all the other RTOSes) each with their own requirements from the bootloader. I'm curious if we should make boot* a little more generic rather than abuse the 'go' command.

Quoted 6 lines
Quoted 4 lines

VXworks has its own:
https://docs.u-boot.org/en/stable/usage/os/vxworks.html

I suppose QNX and others should ideally have their own cmds as needed.

Well, what's the QNX output file format (options?) again?

I've only ever seen outputs in compressed binary formats but I've been told there are tools to produce an ELF for the simulators

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

Well, that's what bootelf is for :)

And if its not an elf but some .bin file "go" cmd should be used in conjunction with "cache" cmd here to flush/disable cache, I guess?

Well, what exactly are we talking about? Is this an "in theory" or some project(s) which exist today?

I noticed this thread mainly because of the number of RTOS people asking me about low level stuff U-Boot and TF-A is doing. I haven't seen any 'In-Production' type bugs but I wouldn't be surprised if U-Boot is being used in their CI environments today.

~Bryan

Quoted 5 lines

There's a whole lot of reasons for either a legacy header and bootm or a not-legacy FIT image. The "go" command is for the "U-Boot is a debugger" side of the world, not how you should kick off some OS/application in production. It is all of the "this is dangerous" idioms.

Quoted 7 lines
Quoted 2 lines

If so, we should probably update the docs for this cmd appropriately so as to avoid end users overloading like what RISC-V did?

Yes, we should clarify things as needed and unwind, most likely, what RISC-V is doing. But not blindly so as perhaps there's now, sigh, a production / in-the-wild case here and we're now in a sticky spot.

I like the idea of boot${OS} flags if only to standardize the interface of how each OS should boot. I worry about situation where custom scripting is being used to boot in production rather than stdboot

~Bryan

#9 lore raw

On April 30, 2025 thus sayeth Bryan Brattlof:

Quoted 24 lines

On April 30, 2025 thus sayeth Tom Rini:

Quoted 23 lines · Vignesh
Quoted 22 lines · Tom Rini
Quoted 11 lines · Bryan Brattlof
Quoted 10 lines

On April 30, 2025 thus sayeth Anshul Dalal:

Quoted 8 lines

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

Quoted 4 lines
Quoted 4 lines

I know quite a few other OSes are beginning to use U-Boot (QNX, GreenHills or all the other RTOSes) each with their own requirements from the bootloader. I'm curious if we should make boot* a little more generic rather than abuse the 'go' command.

VXworks has its own:
https://docs.u-boot.org/en/stable/usage/os/vxworks.html

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

I suppose QNX and others should ideally have their own cmds as needed.

Well, what's the QNX output file format (options?) again?

I've only ever seen outputs in compressed binary formats but I've been told there are tools to produce an ELF for the simulators

Ah as soon as I hit send I find it in the QNX docs[0] it's their own IFS format :)

[0] https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.building/topic/intro/intro_ifs.html

Quoted 36 lines
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

Well, that's what bootelf is for :)

And if its not an elf but some .bin file "go" cmd should be used in conjunction with "cache" cmd here to flush/disable cache, I guess?

Well, what exactly are we talking about? Is this an "in theory" or some project(s) which exist today?

I noticed this thread mainly because of the number of RTOS people asking me about low level stuff U-Boot and TF-A is doing. I haven't seen any 'In-Production' type bugs but I wouldn't be surprised if U-Boot is being used in their CI environments today.

~Bryan

Quoted 5 lines

There's a whole lot of reasons for either a legacy header and bootm or a not-legacy FIT image. The "go" command is for the "U-Boot is a debugger" side of the world, not how you should kick off some OS/application in production. It is all of the "this is dangerous" idioms.

Quoted 7 lines
Quoted 2 lines

If so, we should probably update the docs for this cmd appropriately so as to avoid end users overloading like what RISC-V did?

Yes, we should clarify things as needed and unwind, most likely, what RISC-V is doing. But not blindly so as perhaps there's now, sigh, a production / in-the-wild case here and we're now in a sticky spot.

I like the idea of boot${OS} flags if only to standardize the interface of how each OS should boot. I worry about situation where custom scripting is being used to boot in production rather than stdboot

~Bryan

#10 lore raw
Quoted 29 lines · Bryan Brattlof

On April 30, 2025 thus sayeth Bryan Brattlof:

Quoted 28 lines

On April 30, 2025 thus sayeth Tom Rini:

Quoted 26 lines · Vignesh
Quoted 19 lines · Tom Rini
Quoted 11 lines · Bryan Brattlof
Quoted 10 lines

On April 30, 2025 thus sayeth Anshul Dalal:

Quoted 8 lines

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

Quoted 4 lines
Quoted 4 lines

I know quite a few other OSes are beginning to use U-Boot (QNX, GreenHills or all the other RTOSes) each with their own requirements from the bootloader. I'm curious if we should make boot* a little more generic rather than abuse the 'go' command.

Quoted 4 lines

VXworks has its own:
https://docs.u-boot.org/en/stable/usage/os/vxworks.html

I suppose QNX and others should ideally have their own cmds as needed.

Well, what's the QNX output file format (options?) again?

Quoted 8 lines
Quoted 3 lines

I've only ever seen outputs in compressed binary formats but I've been told there are tools to produce an ELF for the simulators

Ah as soon as I hit send I find it in the QNX docs[0] it's their own IFS format :)

[0] https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.building/topic/intro/intro_ifs.html

I see other mentions of U-Boot in the QNX documentation and even some forum posts that aren't 15+ years old. It would be great for someone from QNX to chime in and explain what they recommend people do today, and from there we can see how to improve the situation if needed.

Signature · 1 line
Tom
#11 lore raw
In reply to Bryan Brattlof
Quoted 38 lines · Bryan Brattlof

On April 30, 2025 thus sayeth Tom Rini:

Quoted 20 lines · Vignesh
Quoted 19 lines · Tom Rini
Quoted 15 lines · Bryan Brattlof
Quoted 14 lines

On April 30, 2025 thus sayeth Anshul Dalal:

Quoted 8 lines

As discussed here[1], the go command causes undefined behavior when used for running custom OSes since the icache might hold outdated data. OSes usually also expect the MMU to be disabled upon execution.

Therefore this patch adds a call to cleanup_before_linux before we jump to the loaded program/os which disables both the caches and the MMU. This makes the go command's behavior consistent with riscv platforms.

I know quite a few other OSes are beginning to use U-Boot (QNX, GreenHills or all the other RTOSes) each with their own requirements from the bootloader. I'm curious if we should make boot* a little more generic rather than abuse the 'go' command.

Quoted 6 lines
Quoted 4 lines

VXworks has its own:
https://docs.u-boot.org/en/stable/usage/os/vxworks.html

I suppose QNX and others should ideally have their own cmds as needed.

Well, what's the QNX output file format (options?) again?

I've only ever seen outputs in compressed binary formats but I've been told there are tools to produce an ELF for the simulators

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

Well, that's what bootelf is for :)

And if its not an elf but some .bin file "go" cmd should be used in conjunction with "cache" cmd here to flush/disable cache, I guess?

Quoted 8 lines
Quoted 3 lines

Well, what exactly are we talking about? Is this an "in theory" or some project(s) which exist today?

I noticed this thread mainly because of the number of RTOS people asking me about low level stuff U-Boot and TF-A is doing. I haven't seen any 'In-Production' type bugs but I wouldn't be surprised if U-Boot is being used in their CI environments today.

A number of RTOSes are already supported via "bootm". If they've stopped working (as we don't have tests in CI for them) I'd love patches to fix and at least instructions on how to make it fail somewhere, ideally QEMU.

Quoted 8 lines
Quoted 8 lines

There's a whole lot of reasons for either a legacy header and bootm or a not-legacy FIT image. The "go" command is for the "U-Boot is a debugger" side of the world, not how you should kick off some OS/application in production. It is all of the "this is dangerous" idioms.

Quoted 2 lines

If so, we should probably update the docs for this cmd appropriately so as to avoid end users overloading like what RISC-V did?

Quoted 7 lines
Quoted 3 lines

Yes, we should clarify things as needed and unwind, most likely, what RISC-V is doing. But not blindly so as perhaps there's now, sigh, a production / in-the-wild case here and we're now in a sticky spot.

I like the idea of boot${OS} flags if only to standardize the interface of how each OS should boot. I worry about situation where custom scripting is being used to boot in production rather than stdboot

Right. And that's part of why in this day and age, regular uses should not be using "go". We've had and supported RTOSes via "bootm" for what amounts to forever. We've had "bootelf" for arbitrary things for ages too (and in turn, your custom app/RTOS/whatever using the normal bare metal ELF linker script, target, etc makes it easier on that side too). In more recent times, having a whatever project spit out an EFI binary instead is also possible and done sometimes.

Signature · 1 line
Tom