[PATCH 00/18] Complete decoupling of bootm logic from commands

This series continues refactoring the bootm code to allow it to be used with CONFIG_COMMAND disabled. The OS-handling code is refactored and a new bootm_run() function is created to run through the bootm stages. This completes the work.
A booti_go() function is created also, in case it proves useful, but at last for now standard boot does not use this.
This is cmdd (part d of CMDLINE refactoring) It depends on dm/bootstda-working which depends on dm/cmdc-working
Simon Glass (18): bootm: netbds: Drop passing of arguments bootm: plan: Drop passing of arguments bootm: qnxelf: Drop passing of arguments nios2: Drop separate parsing of bootm args treewide: bootm: Drop command-line args to boot_os_fn bootm: Drop arguments from boot_selected_os() mips: Add a reset_cpu() function m68k: Add a reset_cpu() function ppc: Add a reset_cpu() function nios2: Add a reset_cpu() function riscv: Add a reset_cpu() function bootm: Adjust how the board is reset bootm: Drop arguments from do_bootm_states() and rename bootm: Create a function to run through the bootm states stm32: Use local vars in stm32prog for initrd and fdt bootm: Create a function to run through the bootz states stm32: Use bootm_run() and bootz_run() bootm: Create a function to run through the booti states
arch/arc/lib/bootm.c | 2 +- arch/arm/lib/bootm.c | 3 +- .../cmd_stm32prog/cmd_stm32prog.c | 35 +++-- arch/m68k/lib/bootm.c | 3 +- arch/m68k/lib/traps.c | 7 + arch/microblaze/lib/bootm.c | 3 +- arch/mips/cpu/cpu.c | 8 +- arch/mips/lib/bootm.c | 5 +- arch/nios2/cpu/cpu.c | 8 +- arch/nios2/lib/bootm.c | 5 +- arch/powerpc/lib/bootm.c | 3 +- arch/powerpc/lib/traps.c | 10 ++ arch/riscv/cpu/cpu.c | 13 ++ arch/riscv/lib/bootm.c | 5 +- arch/riscv/lib/reset.c | 7 +- arch/sandbox/lib/bootm.c | 2 +- arch/sh/lib/bootm.c | 3 +- arch/x86/lib/bootm.c | 3 +- arch/xtensa/lib/bootm.c | 2 +- boot/bootm.c | 125 ++++++++++-------- boot/bootm_os.c | 101 +++++--------- cmd/booti.c | 55 ++++---- cmd/bootm.c | 36 +++-- cmd/bootz.c | 38 ++++-- include/bootm.h | 107 +++++++++++++-- 25 files changed, 362 insertions(+), 227 deletions(-)

It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the three arguments at the end are passed to the OS. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.
Rely instead on the "bootargs" mechanism, which is the standard approach.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootm_os.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/boot/bootm_os.c b/boot/bootm_os.c index b92422171a84..b5055d78706c 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -102,19 +102,9 @@ static int do_bootm_netbsd(int flag, int argc, char *const argv[], os_hdr = hdr; }
- if (argc > 0) { - ulong len; - int i; - - for (i = 0, len = 0; i < argc; i += 1) - len += strlen(argv[i]) + 1; - cmdline = malloc(len); - copy_args(cmdline, argc, argv, ' '); - } else { - cmdline = env_get("bootargs"); - if (cmdline == NULL) - cmdline = ""; - } + cmdline = env_get("bootargs"); + if (!cmdline) + cmdline = "";
loader = (void (*)(struct bd_info *, struct legacy_img_hdr *, char *, char *))images->ep;

From: Simon Glass sjg@chromium.org Date: Sun, 3 Dec 2023 17:26:17 -0700
Hi Simon,
There is a typo in first line of the commit message: s/netbds/netbsd/.
It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the three arguments at the end are passed to the OS. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.
Rely instead on the "bootargs" mechanism, which is the standard approach.
It is a very Linuxy approach though.
I suspect this feature was added to pass kernel arguments for "one-off" boots. For example
bootm -s
could be used to boot NetBSD in single-user mode and is quite a bit more convenient than:
setenv bootargs -s bootm
That said, I'm not sure to what extent the bootm command is used to boot NetBSD these days. So this may not really matter.
Cheers,
Mark
Signed-off-by: Simon Glass sjg@chromium.org
boot/bootm_os.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/boot/bootm_os.c b/boot/bootm_os.c index b92422171a84..b5055d78706c 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -102,19 +102,9 @@ static int do_bootm_netbsd(int flag, int argc, char *const argv[], os_hdr = hdr; }
- if (argc > 0) {
ulong len;
int i;
for (i = 0, len = 0; i < argc; i += 1)
len += strlen(argv[i]) + 1;
cmdline = malloc(len);
copy_args(cmdline, argc, argv, ' ');
- } else {
cmdline = env_get("bootargs");
if (cmdline == NULL)
cmdline = "";
- }
cmdline = env_get("bootargs");
if (!cmdline)
cmdline = "";
loader = (void (*)(struct bd_info *, struct legacy_img_hdr *, char *, char *))images->ep;
-- 2.43.0.rc2.451.g8631bc7472-goog

On Mon, Dec 04, 2023 at 11:48:17AM +0100, Mark Kettenis wrote:
That said, I'm not sure to what extent the bootm command is used to boot NetBSD these days. So this may not really matter.
It is used on most 32bit ARM platforms.
Martin

Hi,
I am replying to this email since it still has the context below.
On Mon, 4 Dec 2023 at 03:48, Mark Kettenis mark.kettenis@xs4all.nl wrote:
From: Simon Glass sjg@chromium.org Date: Sun, 3 Dec 2023 17:26:17 -0700
Hi Simon,
There is a typo in first line of the commit message: s/netbds/netbsd/.
It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the three arguments at the end are passed to the OS. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.
Rely instead on the "bootargs" mechanism, which is the standard approach.
It is a very Linuxy approach though.
I suspect this feature was added to pass kernel arguments for "one-off" boots. For example
bootm -s
Martin says that this is used with NetBSD. So do we rely on U-Boot parsing the '-s' as 0 and then using loadaddr as the default?
I wonder if we could come up with another mechanism? Perhaps 'bootm -- args go here' ? Or define that if the first arg starts with '-' then the args are not parsed?
Martin, would it be possible to send a patch to doc/ describing how to boot NetBSD?
could be used to boot NetBSD in single-user mode and is quite a bit more convenient than:
setenv bootargs -s bootm
That said, I'm not sure to what extent the bootm command is used to boot NetBSD these days. So this may not really matter.
Cheers,
Mark
Signed-off-by: Simon Glass sjg@chromium.org
boot/bootm_os.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/boot/bootm_os.c b/boot/bootm_os.c index b92422171a84..b5055d78706c 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -102,19 +102,9 @@ static int do_bootm_netbsd(int flag, int argc, char *const argv[], os_hdr = hdr; }
if (argc > 0) {
ulong len;
int i;
for (i = 0, len = 0; i < argc; i += 1)
len += strlen(argv[i]) + 1;
cmdline = malloc(len);
copy_args(cmdline, argc, argv, ' ');
} else {
cmdline = env_get("bootargs");
if (cmdline == NULL)
cmdline = "";
}
cmdline = env_get("bootargs");
if (!cmdline)
cmdline = ""; loader = (void (*)(struct bd_info *, struct legacy_img_hdr *, char *, char *))images->ep;
-- 2.43.0.rc2.451.g8631bc7472-goog

On Tue, Dec 05, 2023 at 08:53:58PM -0700, Simon Glass wrote:
Hi,
I am replying to this email since it still has the context below.
On Mon, 4 Dec 2023 at 03:48, Mark Kettenis mark.kettenis@xs4all.nl wrote:
From: Simon Glass sjg@chromium.org Date: Sun, 3 Dec 2023 17:26:17 -0700
Hi Simon,
There is a typo in first line of the commit message: s/netbds/netbsd/.
It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the three arguments at the end are passed to the OS. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.
Rely instead on the "bootargs" mechanism, which is the standard approach.
It is a very Linuxy approach though.
I suspect this feature was added to pass kernel arguments for "one-off" boots. For example
bootm -s
Martin says that this is used with NetBSD. So do we rely on U-Boot parsing the '-s' as 0 and then using loadaddr as the default?
I wonder if we could come up with another mechanism? Perhaps 'bootm -- args go here' ? Or define that if the first arg starts with '-' then the args are not parsed?
Martin, would it be possible to send a patch to doc/ describing how to boot NetBSD?
A patch describing how booting is done today, especially including some of the potentially less common but still valid usages would be much appreciated. We can go from there to decide what changes if any to make to what's exposed to the user in this case as I am loathe to change things like this which amount of an ABI.

It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the three arguments at the end are passed to the OS. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.
Rely instead on the "bootargs" mechanism, which is the standard approach.
Drop the helper function as well.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootm_os.c | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-)
diff --git a/boot/bootm_os.c b/boot/bootm_os.c index b5055d78706c..4aa1db848d6c 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -41,20 +41,6 @@ static int do_bootm_standalone(int flag, int argc, char *const argv[], /* OS booting routines */ /*******************************************************************/
-#if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9) -static void copy_args(char *dest, int argc, char *const argv[], char delim) -{ - int i; - - for (i = 0; i < argc; i++) { - if (i > 0) - *dest++ = delim; - strcpy(dest, argv[i]); - dest += strlen(argv[i]); - } -} -#endif - static void __maybe_unused fit_unsupported_reset(const char *msg) { if (CONFIG_IS_ENABLED(FIT_VERBOSE)) { @@ -211,16 +197,12 @@ static int do_bootm_plan9(int flag, int argc, char *const argv[],
/* See README.plan9 */ s = env_get("confaddr"); - if (s != NULL) { + if (s) { char *confaddr = (char *)hextoul(s, NULL);
- if (argc > 0) { - copy_args(confaddr, argc, argv, '\n'); - } else { - s = env_get("bootargs"); - if (s != NULL) - strcpy(confaddr, s); - } + s = env_get("bootargs"); + if (!s) + strcpy(confaddr, s); }
entry_point = (void (*)(void))images->ep;

It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the '1000' argument is passed to QNX. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.
Rely instead on the "bootargs" mechanism, which is the standard approach.
Also make sure that the argument list is NULL-terminated.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootm_os.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/boot/bootm_os.c b/boot/bootm_os.c index 4aa1db848d6c..598671e576c6 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -333,7 +333,7 @@ int do_bootm_vxworks(int flag, int argc, char *const argv[], static int do_bootm_qnxelf(int flag, int argc, char *const argv[], struct bootm_headers *images) { - char *local_args[2]; + char *local_args[3]; char str[16]; int dcache;
@@ -348,8 +348,9 @@ static int do_bootm_qnxelf(int flag, int argc, char *const argv[], #endif
sprintf(str, "%lx", images->ep); /* write entry-point into string */ - local_args[0] = argv[0]; - local_args[1] = str; /* and provide it via the arguments */ + local_args[0] = "qnxelf"; + local_args[1] = env_get("bootargs"); + local_args[2] = NULL;
/* * QNX images require the data cache is disabled. @@ -358,7 +359,7 @@ static int do_bootm_qnxelf(int flag, int argc, char *const argv[], if (dcache) dcache_disable();
- do_bootelf(NULL, 0, 2, local_args); + do_bootelf(NULL, 0, local_args[1] ? 2 : 1, local_args);
if (dcache) dcache_enable();

This function is supposed to boot the OS. Parsing of the arguments is done in easier phases.
The code to handle this is already here, behind an #ifdef on CONFIG_OF_LIBFDT so rely on that.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/nios2/lib/bootm.c | 2 -- 1 file changed, 2 deletions(-)
diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c index 06c094d0f1c7..823d524c9a2d 100644 --- a/arch/nios2/lib/bootm.c +++ b/arch/nios2/lib/bootm.c @@ -29,8 +29,6 @@ int do_bootm_linux(int flag, int argc, char *const argv[], if (images->ft_len) of_flat_tree = images->ft_addr; #endif - if (!of_flat_tree && argc > 1) - of_flat_tree = (char *)hextoul(argv[1], NULL); if (of_flat_tree) initrd_end = (ulong)of_flat_tree;

These arguments are not used now. They cannot be provided when there is no bootm command invoked to provide arguments. Drop the argc and argv parameters.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/arc/lib/bootm.c | 2 +- arch/arm/lib/bootm.c | 3 +-- arch/m68k/lib/bootm.c | 3 +-- arch/microblaze/lib/bootm.c | 3 +-- arch/mips/lib/bootm.c | 3 +-- arch/nios2/lib/bootm.c | 3 +-- arch/powerpc/lib/bootm.c | 3 +-- arch/riscv/lib/bootm.c | 5 ++-- arch/sandbox/lib/bootm.c | 2 +- arch/sh/lib/bootm.c | 3 +-- arch/x86/lib/bootm.c | 3 +-- arch/xtensa/lib/bootm.c | 2 +- boot/bootm.c | 6 ++--- boot/bootm_os.c | 46 ++++++++++++++----------------------- include/bootm.h | 7 +----- 15 files changed, 34 insertions(+), 60 deletions(-)
diff --git a/arch/arc/lib/bootm.c b/arch/arc/lib/bootm.c index 44ec5864a1c6..0ae7a21b24b6 100644 --- a/arch/arc/lib/bootm.c +++ b/arch/arc/lib/bootm.c @@ -78,7 +78,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag) board_jump_and_run(kernel_entry, r0, 0, r2); }
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on ARC */ if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE)) diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c index c56285738a26..ebaac029e094 100644 --- a/arch/arm/lib/bootm.c +++ b/arch/arm/lib/bootm.c @@ -378,8 +378,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag) * DIFFERENCE: Instead of calling prep and go at the end * they are called if subcommand is equal 0. */ -int do_bootm_linux(int flag, int argc, char *const argv[], - struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on ARM */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) diff --git a/arch/m68k/lib/bootm.c b/arch/m68k/lib/bootm.c index 79d8b34c0d56..0720861ae9cc 100644 --- a/arch/m68k/lib/bootm.c +++ b/arch/m68k/lib/bootm.c @@ -34,8 +34,7 @@ void arch_lmb_reserve(struct lmb *lmb) arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 1024); }
-int do_bootm_linux(int flag, int argc, char *const argv[], - struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { int ret; struct bd_info *kbd; diff --git a/arch/microblaze/lib/bootm.c b/arch/microblaze/lib/bootm.c index f3ec4b741b88..93cdf62e18cf 100644 --- a/arch/microblaze/lib/bootm.c +++ b/arch/microblaze/lib/bootm.c @@ -81,8 +81,7 @@ static void boot_prep_linux(struct bootm_headers *images) } }
-int do_bootm_linux(int flag, int argc, char *const argv[], - struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { images->cmdline_start = (ulong)env_get("bootargs");
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index d6d2f7d9d031..05dbe6131728 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -300,8 +300,7 @@ static void boot_jump_linux(struct bootm_headers *images) linux_extra); }
-int do_bootm_linux(int flag, int argc, char *const argv[], - struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on MIPS */ if (flag & BOOTM_STATE_OS_BD_T) diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c index 823d524c9a2d..040a806bc75e 100644 --- a/arch/nios2/lib/bootm.c +++ b/arch/nios2/lib/bootm.c @@ -16,8 +16,7 @@ DECLARE_GLOBAL_DATA_PTR;
#define NIOS_MAGIC 0x534f494e /* enable command line and initrd passing */
-int do_bootm_linux(int flag, int argc, char *const argv[], - struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { void (*kernel)(int, int, int, char *) = (void *)images->ep; char *commandline = env_get("bootargs"); diff --git a/arch/powerpc/lib/bootm.c b/arch/powerpc/lib/bootm.c index 910121ec9c85..4d248cb13b5f 100644 --- a/arch/powerpc/lib/bootm.c +++ b/arch/powerpc/lib/bootm.c @@ -223,8 +223,7 @@ static int boot_body_linux(struct bootm_headers *images) return 0; }
-noinline int do_bootm_linux(int flag, int argc, char *const argv[], - struct bootm_headers *images) +noinline int do_bootm_linux(int flag, struct bootm_headers *images) { int ret;
diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index f9e1e18ae026..d90f26091530 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -105,8 +105,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag) } }
-int do_bootm_linux(int flag, int argc, char *const argv[], - struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on RISC-V */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) @@ -130,7 +129,7 @@ int do_bootm_linux(int flag, int argc, char *const argv[], int do_bootm_vxworks(int flag, int argc, char *const argv[], struct bootm_headers *images) { - return do_bootm_linux(flag, argc, argv, images); + return do_bootm_linux(flag, images); }
static ulong get_sp(void) diff --git a/arch/sandbox/lib/bootm.c b/arch/sandbox/lib/bootm.c index dc8b8e46cb41..d2b514d3f0ca 100644 --- a/arch/sandbox/lib/bootm.c +++ b/arch/sandbox/lib/bootm.c @@ -64,7 +64,7 @@ static int boot_prep_linux(struct bootm_headers *images) return 0; }
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { if (flag & BOOTM_STATE_OS_PREP) return boot_prep_linux(images); diff --git a/arch/sh/lib/bootm.c b/arch/sh/lib/bootm.c index b205e5e3db1b..d0284582ae0e 100644 --- a/arch/sh/lib/bootm.c +++ b/arch/sh/lib/bootm.c @@ -39,8 +39,7 @@ static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base) return val; }
-int do_bootm_linux(int flag, int argc, char *const argv[], - struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { /* Linux kernel load address */ void (*kernel) (void) = (void (*)(void))images->ep; diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c index 3196f9ddc2c8..34d5c585a55a 100644 --- a/arch/x86/lib/bootm.c +++ b/arch/x86/lib/bootm.c @@ -237,8 +237,7 @@ static int boot_jump_linux(struct bootm_headers *images) images->os.arch == IH_ARCH_X86_64); }
-int do_bootm_linux(int flag, int argc, char *const argv[], - struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on x86 */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) diff --git a/arch/xtensa/lib/bootm.c b/arch/xtensa/lib/bootm.c index fee339281502..5e8e14021ab3 100644 --- a/arch/xtensa/lib/bootm.c +++ b/arch/xtensa/lib/bootm.c @@ -134,7 +134,7 @@ static struct bp_tag *setup_fdt_tag(struct bp_tag *params, void *fdt_start) * Boot Linux. */
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { struct bp_tag *params, *params_start; ulong initrd_start, initrd_end; diff --git a/boot/bootm.c b/boot/bootm.c index 301cfded05cb..c343f313e80a 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1099,9 +1099,9 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
/* Call various other states that are not generally used */ if (!ret && (states & BOOTM_STATE_OS_CMDLINE)) - ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images); + ret = boot_fn(BOOTM_STATE_OS_CMDLINE, images); if (!ret && (states & BOOTM_STATE_OS_BD_T)) - ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images); + ret = boot_fn(BOOTM_STATE_OS_BD_T, images); if (!ret && (states & BOOTM_STATE_OS_PREP)) { ret = bootm_process_cmdline_env(images->os.os == IH_OS_LINUX); if (ret) { @@ -1109,7 +1109,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, ret = CMD_RET_FAILURE; goto err; } - ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images); + ret = boot_fn(BOOTM_STATE_OS_PREP, images); }
#ifdef CONFIG_TRACE diff --git a/boot/bootm_os.c b/boot/bootm_os.c index 598671e576c6..df1aab4b3e4d 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -23,8 +23,7 @@
DECLARE_GLOBAL_DATA_PTR;
-static int do_bootm_standalone(int flag, int argc, char *const argv[], - struct bootm_headers *images) +static int do_bootm_standalone(int flag, struct bootm_headers *images) { int (*appl)(int, char *const[]);
@@ -33,7 +32,7 @@ static int do_bootm_standalone(int flag, int argc, char *const argv[], return 0; } appl = (int (*)(int, char * const []))images->ep; - appl(argc, argv); + appl(0, NULL); return 0; }
@@ -50,8 +49,7 @@ static void __maybe_unused fit_unsupported_reset(const char *msg) }
#ifdef CONFIG_BOOTM_NETBSD -static int do_bootm_netbsd(int flag, int argc, char *const argv[], - struct bootm_headers *images) +static int do_bootm_netbsd(int flag, struct bootm_headers *images) { void (*loader)(struct bd_info *bd, struct legacy_img_hdr *hdr, char *console, char *cmdline); @@ -113,8 +111,7 @@ static int do_bootm_netbsd(int flag, int argc, char *const argv[], #endif /* CONFIG_BOOTM_NETBSD*/
#ifdef CONFIG_BOOTM_RTEMS -static int do_bootm_rtems(int flag, int argc, char *const argv[], - struct bootm_headers *images) +static int do_bootm_rtems(int flag, struct bootm_headers *images) { void (*entry_point)(struct bd_info *);
@@ -146,8 +143,7 @@ static int do_bootm_rtems(int flag, int argc, char *const argv[], #endif /* CONFIG_BOOTM_RTEMS */
#if defined(CONFIG_BOOTM_OSE) -static int do_bootm_ose(int flag, int argc, char *const argv[], - struct bootm_headers *images) +static int do_bootm_ose(int flag, struct bootm_headers *images) { void (*entry_point)(void);
@@ -179,8 +175,7 @@ static int do_bootm_ose(int flag, int argc, char *const argv[], #endif /* CONFIG_BOOTM_OSE */
#if defined(CONFIG_BOOTM_PLAN9) -static int do_bootm_plan9(int flag, int argc, char *const argv[], - struct bootm_headers *images) +static int do_bootm_plan9(int flag, struct bootm_headers *images) { void (*entry_point)(void); char *s; @@ -283,8 +278,7 @@ static void do_bootvx_fdt(struct bootm_headers *images) puts("## vxWorks terminated\n"); }
-static int do_bootm_vxworks_legacy(int flag, int argc, char *const argv[], - struct bootm_headers *images) +static int do_bootm_vxworks_legacy(int flag, struct bootm_headers *images) { if (flag != BOOTM_STATE_OS_GO) return 0; @@ -294,8 +288,7 @@ static int do_bootm_vxworks_legacy(int flag, int argc, char *const argv[], return 1; }
-int do_bootm_vxworks(int flag, int argc, char *const argv[], - struct bootm_headers *images) +int do_bootm_vxworks(int flag, struct bootm_headers *images) { char *bootargs; int pos; @@ -320,18 +313,17 @@ int do_bootm_vxworks(int flag, int argc, char *const argv[], if (std_dtb) { if (flag & BOOTM_STATE_OS_PREP) printf(" Using standard DTB\n"); - return do_bootm_linux(flag, argc, argv, images); + return do_bootm_linux(flag, images); } else { if (flag & BOOTM_STATE_OS_PREP) printf(" !!! WARNING !!! Using legacy DTB\n"); - return do_bootm_vxworks_legacy(flag, argc, argv, images); + return do_bootm_vxworks_legacy(flag, images); } } #endif
#if defined(CONFIG_CMD_ELF) -static int do_bootm_qnxelf(int flag, int argc, char *const argv[], - struct bootm_headers *images) +static int do_bootm_qnxelf(int flag, struct bootm_headers *images) { char *local_args[3]; char str[16]; @@ -369,8 +361,7 @@ static int do_bootm_qnxelf(int flag, int argc, char *const argv[], #endif
#ifdef CONFIG_INTEGRITY -static int do_bootm_integrity(int flag, int argc, char *const argv[], - struct bootm_headers *images) +static int do_bootm_integrity(int flag, struct bootm_headers *images) { void (*entry_point)(void);
@@ -402,8 +393,7 @@ static int do_bootm_integrity(int flag, int argc, char *const argv[], #endif
#ifdef CONFIG_BOOTM_OPENRTOS -static int do_bootm_openrtos(int flag, int argc, char *const argv[], - struct bootm_headers *images) +static int do_bootm_openrtos(int flag, struct bootm_headers *images) { void (*entry_point)(void);
@@ -428,8 +418,7 @@ static int do_bootm_openrtos(int flag, int argc, char *const argv[], #endif
#ifdef CONFIG_BOOTM_OPTEE -static int do_bootm_tee(int flag, int argc, char *const argv[], - struct bootm_headers *images) +static int do_bootm_tee(int flag, struct bootm_headers *images) { int ret;
@@ -441,13 +430,12 @@ static int do_bootm_tee(int flag, int argc, char *const argv[], return ret;
/* From here we can run the regular linux boot path */ - return do_bootm_linux(flag, argc, argv, images); + return do_bootm_linux(flag, images); } #endif
#ifdef CONFIG_BOOTM_EFI -static int do_bootm_efi(int flag, int argc, char *const argv[], - struct bootm_headers *images) +static int do_bootm_efi(int flag, struct bootm_headers *images) { efi_status_t efi_ret; void *image_buf; @@ -544,7 +532,7 @@ int boot_selected_os(int argc, char *const argv[], int state, { arch_preboot_os(); board_preboot_os(); - boot_fn(state, argc, argv, images); + boot_fn(state, images);
/* Stand-alone may return when 'autostart' is 'no' */ if (images->os.type == IH_TYPE_STANDALONE || diff --git a/include/bootm.h b/include/bootm.h index f5229ea90b33..0e4662485006 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -25,16 +25,11 @@ struct cmd_tbl; * - disabled interrupts. * * @flag: Flags indicating what to do (BOOTM_STATE_...) - * @argc: Number of arguments. Note that the arguments are shifted down - * so that 0 is the first argument not processed by U-Boot, and - * argc is adjusted accordingly. This avoids confusion as to how - * many arguments are available for the OS. * @images: Pointers to os/initrd/fdt * Return: 1 on error. On success the OS boots so this function does * not return. */ -typedef int boot_os_fn(int flag, int argc, char *const argv[], - struct bootm_headers *images); +typedef int boot_os_fn(int flag, struct bootm_headers *images);
extern boot_os_fn do_bootm_linux; extern boot_os_fn do_bootm_vxworks;

Hi Simon,
looks like i cannot apply this patch:
~/dev-k/u-boot-coldfire on master *2 git am Complete-decoupling-of-bootm-logic-from-commands.patch Applying: bootm: netbds: Drop passing of arguments Applying: bootm: plan: Drop passing of arguments Applying: bootm: qnxelf: Drop passing of arguments Applying: nios2: Drop separate parsing of bootm args Applying: treewide: bootm: Drop command-line args to boot_os_fn error: patch failed: boot/bootm_os.c:441 error: boot/bootm_os.c: patch does not apply Patch failed at 0005 treewide: bootm: Drop command-line args to boot_os_fn hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
And getting similar issues for the "pxe: Allow extlinux booting without CMDLINE enabled"
Am i doing something wrong ?
Thanks,
Regards angelo
On 04/12/23 1:26 AM, Simon Glass wrote:
These arguments are not used now. They cannot be provided when there is no bootm command invoked to provide arguments. Drop the argc and argv parameters.
Signed-off-by: Simon Glass sjg@chromium.org
arch/arc/lib/bootm.c | 2 +- arch/arm/lib/bootm.c | 3 +-- arch/m68k/lib/bootm.c | 3 +-- arch/microblaze/lib/bootm.c | 3 +-- arch/mips/lib/bootm.c | 3 +-- arch/nios2/lib/bootm.c | 3 +-- arch/powerpc/lib/bootm.c | 3 +-- arch/riscv/lib/bootm.c | 5 ++-- arch/sandbox/lib/bootm.c | 2 +- arch/sh/lib/bootm.c | 3 +-- arch/x86/lib/bootm.c | 3 +-- arch/xtensa/lib/bootm.c | 2 +- boot/bootm.c | 6 ++--- boot/bootm_os.c | 46 ++++++++++++++----------------------- include/bootm.h | 7 +----- 15 files changed, 34 insertions(+), 60 deletions(-)
diff --git a/arch/arc/lib/bootm.c b/arch/arc/lib/bootm.c index 44ec5864a1c6..0ae7a21b24b6 100644 --- a/arch/arc/lib/bootm.c +++ b/arch/arc/lib/bootm.c @@ -78,7 +78,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag) board_jump_and_run(kernel_entry, r0, 0, r2); }
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on ARC */ if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE)) diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c index c56285738a26..ebaac029e094 100644 --- a/arch/arm/lib/bootm.c +++ b/arch/arm/lib/bootm.c @@ -378,8 +378,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
- DIFFERENCE: Instead of calling prep and go at the end
- they are called if subcommand is equal 0.
*/ -int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on ARM */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) diff --git a/arch/m68k/lib/bootm.c b/arch/m68k/lib/bootm.c index 79d8b34c0d56..0720861ae9cc 100644 --- a/arch/m68k/lib/bootm.c +++ b/arch/m68k/lib/bootm.c @@ -34,8 +34,7 @@ void arch_lmb_reserve(struct lmb *lmb) arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 1024); }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { int ret; struct bd_info *kbd; diff --git a/arch/microblaze/lib/bootm.c b/arch/microblaze/lib/bootm.c index f3ec4b741b88..93cdf62e18cf 100644 --- a/arch/microblaze/lib/bootm.c +++ b/arch/microblaze/lib/bootm.c @@ -81,8 +81,7 @@ static void boot_prep_linux(struct bootm_headers *images) } }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { images->cmdline_start = (ulong)env_get("bootargs");
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index d6d2f7d9d031..05dbe6131728 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -300,8 +300,7 @@ static void boot_jump_linux(struct bootm_headers *images) linux_extra); }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on MIPS */ if (flag & BOOTM_STATE_OS_BD_T) diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c index 823d524c9a2d..040a806bc75e 100644 --- a/arch/nios2/lib/bootm.c +++ b/arch/nios2/lib/bootm.c @@ -16,8 +16,7 @@ DECLARE_GLOBAL_DATA_PTR;
#define NIOS_MAGIC 0x534f494e /* enable command line and initrd passing */
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { void (*kernel)(int, int, int, char *) = (void *)images->ep; char *commandline = env_get("bootargs"); diff --git a/arch/powerpc/lib/bootm.c b/arch/powerpc/lib/bootm.c index 910121ec9c85..4d248cb13b5f 100644 --- a/arch/powerpc/lib/bootm.c +++ b/arch/powerpc/lib/bootm.c @@ -223,8 +223,7 @@ static int boot_body_linux(struct bootm_headers *images) return 0; }
-noinline int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+noinline int do_bootm_linux(int flag, struct bootm_headers *images) { int ret;
diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index f9e1e18ae026..d90f26091530 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -105,8 +105,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag) } }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on RISC-V */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) @@ -130,7 +129,7 @@ int do_bootm_linux(int flag, int argc, char *const argv[], int do_bootm_vxworks(int flag, int argc, char *const argv[], struct bootm_headers *images) {
- return do_bootm_linux(flag, argc, argv, images);
return do_bootm_linux(flag, images); }
static ulong get_sp(void)
diff --git a/arch/sandbox/lib/bootm.c b/arch/sandbox/lib/bootm.c index dc8b8e46cb41..d2b514d3f0ca 100644 --- a/arch/sandbox/lib/bootm.c +++ b/arch/sandbox/lib/bootm.c @@ -64,7 +64,7 @@ static int boot_prep_linux(struct bootm_headers *images) return 0; }
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { if (flag & BOOTM_STATE_OS_PREP) return boot_prep_linux(images); diff --git a/arch/sh/lib/bootm.c b/arch/sh/lib/bootm.c index b205e5e3db1b..d0284582ae0e 100644 --- a/arch/sh/lib/bootm.c +++ b/arch/sh/lib/bootm.c @@ -39,8 +39,7 @@ static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base) return val; }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { /* Linux kernel load address */ void (*kernel) (void) = (void (*)(void))images->ep; diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c index 3196f9ddc2c8..34d5c585a55a 100644 --- a/arch/x86/lib/bootm.c +++ b/arch/x86/lib/bootm.c @@ -237,8 +237,7 @@ static int boot_jump_linux(struct bootm_headers *images) images->os.arch == IH_ARCH_X86_64); }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on x86 */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) diff --git a/arch/xtensa/lib/bootm.c b/arch/xtensa/lib/bootm.c index fee339281502..5e8e14021ab3 100644 --- a/arch/xtensa/lib/bootm.c +++ b/arch/xtensa/lib/bootm.c @@ -134,7 +134,7 @@ static struct bp_tag *setup_fdt_tag(struct bp_tag *params, void *fdt_start)
- Boot Linux.
*/
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { struct bp_tag *params, *params_start; ulong initrd_start, initrd_end; diff --git a/boot/bootm.c b/boot/bootm.c index 301cfded05cb..c343f313e80a 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1099,9 +1099,9 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
/* Call various other states that are not generally used */ if (!ret && (states & BOOTM_STATE_OS_CMDLINE))
ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images);
if (!ret && (states & BOOTM_STATE_OS_BD_T))ret = boot_fn(BOOTM_STATE_OS_CMDLINE, images);
ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
if (!ret && (states & BOOTM_STATE_OS_PREP)) { ret = bootm_process_cmdline_env(images->os.os == IH_OS_LINUX); if (ret) {ret = boot_fn(BOOTM_STATE_OS_BD_T, images);
@@ -1109,7 +1109,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, ret = CMD_RET_FAILURE; goto err; }
ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
ret = boot_fn(BOOTM_STATE_OS_PREP, images);
}
#ifdef CONFIG_TRACE
diff --git a/boot/bootm_os.c b/boot/bootm_os.c index 598671e576c6..df1aab4b3e4d 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -23,8 +23,7 @@
DECLARE_GLOBAL_DATA_PTR;
-static int do_bootm_standalone(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_standalone(int flag, struct bootm_headers *images) { int (*appl)(int, char *const[]);
@@ -33,7 +32,7 @@ static int do_bootm_standalone(int flag, int argc, char *const argv[], return 0; } appl = (int (*)(int, char * const []))images->ep;
- appl(argc, argv);
- appl(0, NULL); return 0; }
@@ -50,8 +49,7 @@ static void __maybe_unused fit_unsupported_reset(const char *msg) }
#ifdef CONFIG_BOOTM_NETBSD -static int do_bootm_netbsd(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_netbsd(int flag, struct bootm_headers *images) { void (*loader)(struct bd_info *bd, struct legacy_img_hdr *hdr, char *console, char *cmdline); @@ -113,8 +111,7 @@ static int do_bootm_netbsd(int flag, int argc, char *const argv[], #endif /* CONFIG_BOOTM_NETBSD*/
#ifdef CONFIG_BOOTM_RTEMS -static int do_bootm_rtems(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_rtems(int flag, struct bootm_headers *images) { void (*entry_point)(struct bd_info *);
@@ -146,8 +143,7 @@ static int do_bootm_rtems(int flag, int argc, char *const argv[], #endif /* CONFIG_BOOTM_RTEMS */
#if defined(CONFIG_BOOTM_OSE) -static int do_bootm_ose(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_ose(int flag, struct bootm_headers *images) { void (*entry_point)(void);
@@ -179,8 +175,7 @@ static int do_bootm_ose(int flag, int argc, char *const argv[], #endif /* CONFIG_BOOTM_OSE */
#if defined(CONFIG_BOOTM_PLAN9) -static int do_bootm_plan9(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_plan9(int flag, struct bootm_headers *images) { void (*entry_point)(void); char *s; @@ -283,8 +278,7 @@ static void do_bootvx_fdt(struct bootm_headers *images) puts("## vxWorks terminated\n"); }
-static int do_bootm_vxworks_legacy(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_vxworks_legacy(int flag, struct bootm_headers *images) { if (flag != BOOTM_STATE_OS_GO) return 0; @@ -294,8 +288,7 @@ static int do_bootm_vxworks_legacy(int flag, int argc, char *const argv[], return 1; }
-int do_bootm_vxworks(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_vxworks(int flag, struct bootm_headers *images) { char *bootargs; int pos; @@ -320,18 +313,17 @@ int do_bootm_vxworks(int flag, int argc, char *const argv[], if (std_dtb) { if (flag & BOOTM_STATE_OS_PREP) printf(" Using standard DTB\n");
return do_bootm_linux(flag, argc, argv, images);
} else { if (flag & BOOTM_STATE_OS_PREP) printf(" !!! WARNING !!! Using legacy DTB\n");return do_bootm_linux(flag, images);
return do_bootm_vxworks_legacy(flag, argc, argv, images);
return do_bootm_vxworks_legacy(flag, images);
} } #endif
#if defined(CONFIG_CMD_ELF)
-static int do_bootm_qnxelf(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_qnxelf(int flag, struct bootm_headers *images) { char *local_args[3]; char str[16]; @@ -369,8 +361,7 @@ static int do_bootm_qnxelf(int flag, int argc, char *const argv[], #endif
#ifdef CONFIG_INTEGRITY -static int do_bootm_integrity(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_integrity(int flag, struct bootm_headers *images) { void (*entry_point)(void);
@@ -402,8 +393,7 @@ static int do_bootm_integrity(int flag, int argc, char *const argv[], #endif
#ifdef CONFIG_BOOTM_OPENRTOS -static int do_bootm_openrtos(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_openrtos(int flag, struct bootm_headers *images) { void (*entry_point)(void);
@@ -428,8 +418,7 @@ static int do_bootm_openrtos(int flag, int argc, char *const argv[], #endif
#ifdef CONFIG_BOOTM_OPTEE -static int do_bootm_tee(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_tee(int flag, struct bootm_headers *images) { int ret;
@@ -441,13 +430,12 @@ static int do_bootm_tee(int flag, int argc, char *const argv[], return ret;
/* From here we can run the regular linux boot path */
- return do_bootm_linux(flag, argc, argv, images);
return do_bootm_linux(flag, images); } #endif
#ifdef CONFIG_BOOTM_EFI
-static int do_bootm_efi(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_efi(int flag, struct bootm_headers *images) { efi_status_t efi_ret; void *image_buf; @@ -544,7 +532,7 @@ int boot_selected_os(int argc, char *const argv[], int state, { arch_preboot_os(); board_preboot_os();
- boot_fn(state, argc, argv, images);
boot_fn(state, images);
/* Stand-alone may return when 'autostart' is 'no' */ if (images->os.type == IH_TYPE_STANDALONE ||
diff --git a/include/bootm.h b/include/bootm.h index f5229ea90b33..0e4662485006 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -25,16 +25,11 @@ struct cmd_tbl;
- disabled interrupts.
- @flag: Flags indicating what to do (BOOTM_STATE_...)
- @argc: Number of arguments. Note that the arguments are shifted down
so that 0 is the first argument not processed by U-Boot, and
argc is adjusted accordingly. This avoids confusion as to how
*/
many arguments are available for the OS.
- @images: Pointers to os/initrd/fdt
- Return: 1 on error. On success the OS boots so this function does
- not return.
-typedef int boot_os_fn(int flag, int argc, char *const argv[],
struct bootm_headers *images);
+typedef int boot_os_fn(int flag, struct bootm_headers *images);
extern boot_os_fn do_bootm_linux; extern boot_os_fn do_bootm_vxworks;

Hi Angelo,
On Tue, 5 Dec 2023 at 08:01, Angelo Dureghello angelo@kernel-space.org wrote:
Hi Simon,
looks like i cannot apply this patch:
~/dev-k/u-boot-coldfire on master *2 git am Complete-decoupling-of-bootm-logic-from-commands.patch Applying: bootm: netbds: Drop passing of arguments Applying: bootm: plan: Drop passing of arguments Applying: bootm: qnxelf: Drop passing of arguments Applying: nios2: Drop separate parsing of bootm args Applying: treewide: bootm: Drop command-line args to boot_os_fn error: patch failed: boot/bootm_os.c:441 error: boot/bootm_os.c: patch does not apply Patch failed at 0005 treewide: bootm: Drop command-line args to boot_os_fn hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".
And getting similar issues for the "pxe: Allow extlinux booting without CMDLINE enabled"
Am i doing something wrong ?
Could you please check the cover letter? There are several series here and I put the -dm tree links in as well.
I was keeping these to send in sequence, but it would likely take several releases that way, so I elected to send everything at once and get feedback.
Regards, SmIon

Hi Simon,
Acked-by: Angelo Dureghello angelo@kernel-space.org
On 04/12/23 1:26 AM, Simon Glass wrote:
These arguments are not used now. They cannot be provided when there is no bootm command invoked to provide arguments. Drop the argc and argv parameters.
Signed-off-by: Simon Glass sjg@chromium.org
arch/arc/lib/bootm.c | 2 +- arch/arm/lib/bootm.c | 3 +-- arch/m68k/lib/bootm.c | 3 +-- arch/microblaze/lib/bootm.c | 3 +-- arch/mips/lib/bootm.c | 3 +-- arch/nios2/lib/bootm.c | 3 +-- arch/powerpc/lib/bootm.c | 3 +-- arch/riscv/lib/bootm.c | 5 ++-- arch/sandbox/lib/bootm.c | 2 +- arch/sh/lib/bootm.c | 3 +-- arch/x86/lib/bootm.c | 3 +-- arch/xtensa/lib/bootm.c | 2 +- boot/bootm.c | 6 ++--- boot/bootm_os.c | 46 ++++++++++++++----------------------- include/bootm.h | 7 +----- 15 files changed, 34 insertions(+), 60 deletions(-)
diff --git a/arch/arc/lib/bootm.c b/arch/arc/lib/bootm.c index 44ec5864a1c6..0ae7a21b24b6 100644 --- a/arch/arc/lib/bootm.c +++ b/arch/arc/lib/bootm.c @@ -78,7 +78,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag) board_jump_and_run(kernel_entry, r0, 0, r2); }
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on ARC */ if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE)) diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c index c56285738a26..ebaac029e094 100644 --- a/arch/arm/lib/bootm.c +++ b/arch/arm/lib/bootm.c @@ -378,8 +378,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
- DIFFERENCE: Instead of calling prep and go at the end
- they are called if subcommand is equal 0.
*/ -int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on ARM */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) diff --git a/arch/m68k/lib/bootm.c b/arch/m68k/lib/bootm.c index 79d8b34c0d56..0720861ae9cc 100644 --- a/arch/m68k/lib/bootm.c +++ b/arch/m68k/lib/bootm.c @@ -34,8 +34,7 @@ void arch_lmb_reserve(struct lmb *lmb) arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 1024); }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { int ret; struct bd_info *kbd; diff --git a/arch/microblaze/lib/bootm.c b/arch/microblaze/lib/bootm.c index f3ec4b741b88..93cdf62e18cf 100644 --- a/arch/microblaze/lib/bootm.c +++ b/arch/microblaze/lib/bootm.c @@ -81,8 +81,7 @@ static void boot_prep_linux(struct bootm_headers *images) } }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { images->cmdline_start = (ulong)env_get("bootargs");
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index d6d2f7d9d031..05dbe6131728 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -300,8 +300,7 @@ static void boot_jump_linux(struct bootm_headers *images) linux_extra); }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on MIPS */ if (flag & BOOTM_STATE_OS_BD_T) diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c index 823d524c9a2d..040a806bc75e 100644 --- a/arch/nios2/lib/bootm.c +++ b/arch/nios2/lib/bootm.c @@ -16,8 +16,7 @@ DECLARE_GLOBAL_DATA_PTR;
#define NIOS_MAGIC 0x534f494e /* enable command line and initrd passing */
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { void (*kernel)(int, int, int, char *) = (void *)images->ep; char *commandline = env_get("bootargs"); diff --git a/arch/powerpc/lib/bootm.c b/arch/powerpc/lib/bootm.c index 910121ec9c85..4d248cb13b5f 100644 --- a/arch/powerpc/lib/bootm.c +++ b/arch/powerpc/lib/bootm.c @@ -223,8 +223,7 @@ static int boot_body_linux(struct bootm_headers *images) return 0; }
-noinline int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+noinline int do_bootm_linux(int flag, struct bootm_headers *images) { int ret;
diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index f9e1e18ae026..d90f26091530 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -105,8 +105,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag) } }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on RISC-V */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) @@ -130,7 +129,7 @@ int do_bootm_linux(int flag, int argc, char *const argv[], int do_bootm_vxworks(int flag, int argc, char *const argv[], struct bootm_headers *images) {
- return do_bootm_linux(flag, argc, argv, images);
return do_bootm_linux(flag, images); }
static ulong get_sp(void)
diff --git a/arch/sandbox/lib/bootm.c b/arch/sandbox/lib/bootm.c index dc8b8e46cb41..d2b514d3f0ca 100644 --- a/arch/sandbox/lib/bootm.c +++ b/arch/sandbox/lib/bootm.c @@ -64,7 +64,7 @@ static int boot_prep_linux(struct bootm_headers *images) return 0; }
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { if (flag & BOOTM_STATE_OS_PREP) return boot_prep_linux(images); diff --git a/arch/sh/lib/bootm.c b/arch/sh/lib/bootm.c index b205e5e3db1b..d0284582ae0e 100644 --- a/arch/sh/lib/bootm.c +++ b/arch/sh/lib/bootm.c @@ -39,8 +39,7 @@ static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base) return val; }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { /* Linux kernel load address */ void (*kernel) (void) = (void (*)(void))images->ep; diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c index 3196f9ddc2c8..34d5c585a55a 100644 --- a/arch/x86/lib/bootm.c +++ b/arch/x86/lib/bootm.c @@ -237,8 +237,7 @@ static int boot_jump_linux(struct bootm_headers *images) images->os.arch == IH_ARCH_X86_64); }
-int do_bootm_linux(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images) { /* No need for those on x86 */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) diff --git a/arch/xtensa/lib/bootm.c b/arch/xtensa/lib/bootm.c index fee339281502..5e8e14021ab3 100644 --- a/arch/xtensa/lib/bootm.c +++ b/arch/xtensa/lib/bootm.c @@ -134,7 +134,7 @@ static struct bp_tag *setup_fdt_tag(struct bp_tag *params, void *fdt_start)
- Boot Linux.
*/
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images) +int do_bootm_linux(int flag, struct bootm_headers *images) { struct bp_tag *params, *params_start; ulong initrd_start, initrd_end; diff --git a/boot/bootm.c b/boot/bootm.c index 301cfded05cb..c343f313e80a 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1099,9 +1099,9 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
/* Call various other states that are not generally used */ if (!ret && (states & BOOTM_STATE_OS_CMDLINE))
ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images);
if (!ret && (states & BOOTM_STATE_OS_BD_T))ret = boot_fn(BOOTM_STATE_OS_CMDLINE, images);
ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
if (!ret && (states & BOOTM_STATE_OS_PREP)) { ret = bootm_process_cmdline_env(images->os.os == IH_OS_LINUX); if (ret) {ret = boot_fn(BOOTM_STATE_OS_BD_T, images);
@@ -1109,7 +1109,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, ret = CMD_RET_FAILURE; goto err; }
ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
ret = boot_fn(BOOTM_STATE_OS_PREP, images);
}
#ifdef CONFIG_TRACE
diff --git a/boot/bootm_os.c b/boot/bootm_os.c index 598671e576c6..df1aab4b3e4d 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -23,8 +23,7 @@
DECLARE_GLOBAL_DATA_PTR;
-static int do_bootm_standalone(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_standalone(int flag, struct bootm_headers *images) { int (*appl)(int, char *const[]);
@@ -33,7 +32,7 @@ static int do_bootm_standalone(int flag, int argc, char *const argv[], return 0; } appl = (int (*)(int, char * const []))images->ep;
- appl(argc, argv);
- appl(0, NULL); return 0; }
@@ -50,8 +49,7 @@ static void __maybe_unused fit_unsupported_reset(const char *msg) }
#ifdef CONFIG_BOOTM_NETBSD -static int do_bootm_netbsd(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_netbsd(int flag, struct bootm_headers *images) { void (*loader)(struct bd_info *bd, struct legacy_img_hdr *hdr, char *console, char *cmdline); @@ -113,8 +111,7 @@ static int do_bootm_netbsd(int flag, int argc, char *const argv[], #endif /* CONFIG_BOOTM_NETBSD*/
#ifdef CONFIG_BOOTM_RTEMS -static int do_bootm_rtems(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_rtems(int flag, struct bootm_headers *images) { void (*entry_point)(struct bd_info *);
@@ -146,8 +143,7 @@ static int do_bootm_rtems(int flag, int argc, char *const argv[], #endif /* CONFIG_BOOTM_RTEMS */
#if defined(CONFIG_BOOTM_OSE) -static int do_bootm_ose(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_ose(int flag, struct bootm_headers *images) { void (*entry_point)(void);
@@ -179,8 +175,7 @@ static int do_bootm_ose(int flag, int argc, char *const argv[], #endif /* CONFIG_BOOTM_OSE */
#if defined(CONFIG_BOOTM_PLAN9) -static int do_bootm_plan9(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_plan9(int flag, struct bootm_headers *images) { void (*entry_point)(void); char *s; @@ -283,8 +278,7 @@ static void do_bootvx_fdt(struct bootm_headers *images) puts("## vxWorks terminated\n"); }
-static int do_bootm_vxworks_legacy(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_vxworks_legacy(int flag, struct bootm_headers *images) { if (flag != BOOTM_STATE_OS_GO) return 0; @@ -294,8 +288,7 @@ static int do_bootm_vxworks_legacy(int flag, int argc, char *const argv[], return 1; }
-int do_bootm_vxworks(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+int do_bootm_vxworks(int flag, struct bootm_headers *images) { char *bootargs; int pos; @@ -320,18 +313,17 @@ int do_bootm_vxworks(int flag, int argc, char *const argv[], if (std_dtb) { if (flag & BOOTM_STATE_OS_PREP) printf(" Using standard DTB\n");
return do_bootm_linux(flag, argc, argv, images);
} else { if (flag & BOOTM_STATE_OS_PREP) printf(" !!! WARNING !!! Using legacy DTB\n");return do_bootm_linux(flag, images);
return do_bootm_vxworks_legacy(flag, argc, argv, images);
return do_bootm_vxworks_legacy(flag, images);
} } #endif
#if defined(CONFIG_CMD_ELF)
-static int do_bootm_qnxelf(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_qnxelf(int flag, struct bootm_headers *images) { char *local_args[3]; char str[16]; @@ -369,8 +361,7 @@ static int do_bootm_qnxelf(int flag, int argc, char *const argv[], #endif
#ifdef CONFIG_INTEGRITY -static int do_bootm_integrity(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_integrity(int flag, struct bootm_headers *images) { void (*entry_point)(void);
@@ -402,8 +393,7 @@ static int do_bootm_integrity(int flag, int argc, char *const argv[], #endif
#ifdef CONFIG_BOOTM_OPENRTOS -static int do_bootm_openrtos(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_openrtos(int flag, struct bootm_headers *images) { void (*entry_point)(void);
@@ -428,8 +418,7 @@ static int do_bootm_openrtos(int flag, int argc, char *const argv[], #endif
#ifdef CONFIG_BOOTM_OPTEE -static int do_bootm_tee(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_tee(int flag, struct bootm_headers *images) { int ret;
@@ -441,13 +430,12 @@ static int do_bootm_tee(int flag, int argc, char *const argv[], return ret;
/* From here we can run the regular linux boot path */
- return do_bootm_linux(flag, argc, argv, images);
return do_bootm_linux(flag, images); } #endif
#ifdef CONFIG_BOOTM_EFI
-static int do_bootm_efi(int flag, int argc, char *const argv[],
struct bootm_headers *images)
+static int do_bootm_efi(int flag, struct bootm_headers *images) { efi_status_t efi_ret; void *image_buf; @@ -544,7 +532,7 @@ int boot_selected_os(int argc, char *const argv[], int state, { arch_preboot_os(); board_preboot_os();
- boot_fn(state, argc, argv, images);
boot_fn(state, images);
/* Stand-alone may return when 'autostart' is 'no' */ if (images->os.type == IH_TYPE_STANDALONE ||
diff --git a/include/bootm.h b/include/bootm.h index f5229ea90b33..0e4662485006 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -25,16 +25,11 @@ struct cmd_tbl;
- disabled interrupts.
- @flag: Flags indicating what to do (BOOTM_STATE_...)
- @argc: Number of arguments. Note that the arguments are shifted down
so that 0 is the first argument not processed by U-Boot, and
argc is adjusted accordingly. This avoids confusion as to how
*/
many arguments are available for the OS.
- @images: Pointers to os/initrd/fdt
- Return: 1 on error. On success the OS boots so this function does
- not return.
-typedef int boot_os_fn(int flag, int argc, char *const argv[],
struct bootm_headers *images);
+typedef int boot_os_fn(int flag, struct bootm_headers *images);
extern boot_os_fn do_bootm_linux; extern boot_os_fn do_bootm_vxworks;

The argc and argv parameters are not used now, so drop them.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootm.c | 6 ++---- boot/bootm_os.c | 4 ++-- include/bootm.h | 4 ++-- 3 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index c343f313e80a..d2448f6306dc 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1117,8 +1117,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) { char *cmd_list = env_get("fakegocmd");
- ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO, - images, boot_fn); + ret = boot_selected_os(BOOTM_STATE_OS_FAKE_GO, images, boot_fn); if (!ret && cmd_list) ret = run_command_list(cmd_list, -1, flag); } @@ -1132,8 +1131,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
/* Now run the OS! We hope this doesn't return */ if (!ret && (states & BOOTM_STATE_OS_GO)) - ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_GO, - images, boot_fn); + ret = boot_selected_os(BOOTM_STATE_OS_GO, images, boot_fn);
/* Deal with any fallout */ err: diff --git a/boot/bootm_os.c b/boot/bootm_os.c index df1aab4b3e4d..22ff62e5fb65 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -527,8 +527,8 @@ __weak void board_preboot_os(void) /* please define board specific board_preboot_os() */ }
-int boot_selected_os(int argc, char *const argv[], int state, - struct bootm_headers *images, boot_os_fn *boot_fn) +int boot_selected_os(int state, struct bootm_headers *images, + boot_os_fn *boot_fn) { arch_preboot_os(); board_preboot_os(); diff --git a/include/bootm.h b/include/bootm.h index 0e4662485006..b8d74d03a8c4 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -42,8 +42,8 @@ boot_os_fn *bootm_os_get_boot_func(int os); int bootm_host_load_images(const void *fit, int cfg_noffset); #endif
-int boot_selected_os(int argc, char *const argv[], int state, - struct bootm_headers *images, boot_os_fn *boot_fn); +int boot_selected_os(int argc, struct bootm_headers *images, + boot_os_fn *boot_fn);
ulong bootm_disable_interrupts(void);

On Sun, Dec 03, 2023 at 05:26:22PM -0700, Simon Glass wrote:
The argc and argv parameters are not used now, so drop them.
Signed-off-by: Simon Glass sjg@chromium.org
This along with patches 1-5 depend on what the answer is about how NetBSD certainly already expects to use things.

The current do_reset() is called from a command context. Add a function which can be used from anywhere, as is done on ARM.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/mips/cpu/cpu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/arch/mips/cpu/cpu.c b/arch/mips/cpu/cpu.c index acfc9dc43f17..443465047715 100644 --- a/arch/mips/cpu/cpu.c +++ b/arch/mips/cpu/cpu.c @@ -4,6 +4,7 @@ * Wolfgang Denk, DENX Software Engineering, wd@denx.de */
+#include <cpu_func.h> #include <command.h> #include <init.h> #include <linux/compiler.h> @@ -20,9 +21,14 @@ void __weak _machine_restart(void) /* NOP */; }
-int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +void reset_cpu(void) { _machine_restart(); +} + +int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + reset_cpu();
return 0; }

On Sun, Dec 03, 2023 at 05:26:23PM -0700, Simon Glass wrote:
The current do_reset() is called from a command context. Add a function which can be used from anywhere, as is done on ARM.
Signed-off-by: Simon Glass sjg@chromium.org
A consistent API here for all architectures is good, thanks for doing this cleanup.

The current do_reset() is called from a command context. Add a function which can be used from anywhere, as is done on ARM.
Since there are lots of reset functions, this one actually just calls do_reset(). Future refactoring could correct this.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/m68k/lib/traps.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/arch/m68k/lib/traps.c b/arch/m68k/lib/traps.c index c283351181d8..ae8ae6ccf592 100644 --- a/arch/m68k/lib/traps.c +++ b/arch/m68k/lib/traps.c @@ -7,6 +7,7 @@ * Wolfgang Denk, DENX Software Engineering, wd@denx.de. */
+#include <cpu_func.h> #include <init.h> #include <watchdog.h> #include <command.h> @@ -65,3 +66,9 @@ int arch_initr_trap(void)
return 0; } + +void reset_cpu(void) +{ + /* TODO: Refactor all the do_reset calls to be reset_cpu() instead */ + do_reset(NULL, 0, 0, NULL); +}

Hi Simon,
Acked-by: Angelo Dureghello angelo@kernel-spcece.org
On 04/12/23 1:26 AM, Simon Glass wrote:
The current do_reset() is called from a command context. Add a function which can be used from anywhere, as is done on ARM.
Since there are lots of reset functions, this one actually just calls do_reset(). Future refactoring could correct this.
Signed-off-by: Simon Glass sjg@chromium.org
arch/m68k/lib/traps.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/arch/m68k/lib/traps.c b/arch/m68k/lib/traps.c index c283351181d8..ae8ae6ccf592 100644 --- a/arch/m68k/lib/traps.c +++ b/arch/m68k/lib/traps.c @@ -7,6 +7,7 @@
- Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*/
+#include <cpu_func.h> #include <init.h> #include <watchdog.h> #include <command.h> @@ -65,3 +66,9 @@ int arch_initr_trap(void)
return 0; }
+void reset_cpu(void) +{
- /* TODO: Refactor all the do_reset calls to be reset_cpu() instead */
- do_reset(NULL, 0, 0, NULL);
+}

The current do_reset() is called from a command context. Add a function which can be used from anywhere, as is done on ARM.
This is only needed if CONFIG_SYSRESET is disabled.
Since there are lots of reset functions, this one actually just calls do_reset(). Future refactoring could correct this.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/powerpc/lib/traps.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/arch/powerpc/lib/traps.c b/arch/powerpc/lib/traps.c index c7bce82a44b3..cf8da2e5df0d 100644 --- a/arch/powerpc/lib/traps.c +++ b/arch/powerpc/lib/traps.c @@ -4,6 +4,8 @@ * Wolfgang Denk, DENX Software Engineering, wd@denx.de. */
+#include <command.h> +#include <cpu_func.h> #include <init.h> #include <asm/global_data.h>
@@ -17,3 +19,11 @@ int arch_initr_trap(void)
return 0; } + +#ifndef CONFIG_SYSRESET +void reset_cpu(void) +{ + /* TODO: Refactor all the do_reset calls to be reset_cpu() instead */ + do_reset(NULL, 0, 0, NULL); +} +#endif

The current do_reset() is called from a command context. Add a function which can be used from anywhere, as is done on ARM.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/nios2/cpu/cpu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/arch/nios2/cpu/cpu.c b/arch/nios2/cpu/cpu.c index 79a54d1bc259..de7bfa947f11 100644 --- a/arch/nios2/cpu/cpu.c +++ b/arch/nios2/cpu/cpu.c @@ -35,11 +35,17 @@ int checkboard(void) } #endif
-int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +void reset_cpu(void) { disable_interrupts(); /* indirect call to go beyond 256MB limitation of toolchain */ nios2_callr(gd->arch.reset_addr); +} + +int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) +{ + reset_cpu(); + return 0; }

The current do_reset() is called from a command context. Add a function which can be used from anywhere, as is done on ARM. Adjust do_reset() to call it.
Note that reset_cpu() is normally provided by SYSRESET so make this declaration conditional on that being disabled.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/riscv/cpu/cpu.c | 13 +++++++++++++ arch/riscv/lib/reset.c | 7 ++----- 2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/arch/riscv/cpu/cpu.c b/arch/riscv/cpu/cpu.c index ebd39cb41a60..8445c5823e17 100644 --- a/arch/riscv/cpu/cpu.c +++ b/arch/riscv/cpu/cpu.c @@ -3,10 +3,13 @@ * Copyright (C) 2018, Bin Meng bmeng.cn@gmail.com */
+#include <command.h> #include <cpu.h> +#include <cpu_func.h> #include <dm.h> #include <dm/lists.h> #include <event.h> +#include <hang.h> #include <init.h> #include <log.h> #include <asm/encoding.h> @@ -162,3 +165,13 @@ int arch_early_init_r(void) __weak void harts_early_init(void) { } + +#if !CONFIG_IS_ENABLED(SYSRESET) +void reset_cpu(void) +{ + printf("resetting ...\n"); + + printf("reset not supported yet\n"); + hang(); +} +#endif diff --git a/arch/riscv/lib/reset.c b/arch/riscv/lib/reset.c index 712e1bdb8e1d..c4153c9e6e02 100644 --- a/arch/riscv/lib/reset.c +++ b/arch/riscv/lib/reset.c @@ -4,14 +4,11 @@ */
#include <command.h> -#include <hang.h> +#include <cpu_func.h>
int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - printf("resetting ...\n"); - - printf("reset not supported yet\n"); - hang(); + reset_cpu();
return 0; }

Use reset_cpu() to reset the board, copying the logic from the 'reset' command. This makes more sense than directly calling the do_reset() function with the arguments passsed to the bootm command.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index d2448f6306dc..de5c32099ceb 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1138,10 +1138,12 @@ err: if (iflag) enable_interrupts();
- if (ret == BOOTM_ERR_UNIMPLEMENTED) + if (ret == BOOTM_ERR_UNIMPLEMENTED) { bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL); - else if (ret == BOOTM_ERR_RESET) - do_reset(cmdtp, flag, argc, argv); + } else if (ret == BOOTM_ERR_RESET) { + printf("Resetting the board...\n"); + reset_cpu(); + }
return ret; }

On Sun, Dec 03, 2023 at 05:26:28PM -0700, Simon Glass wrote:
Use reset_cpu() to reset the board, copying the logic from the 'reset' command. This makes more sense than directly calling the do_reset() function with the arguments passsed to the bootm command.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

Create a new struct which holds the information required by bootm. Set this up for each existing caller.
Now that none of the functions called from do_bootm_states() need an argv[] list, change the arguments of do_bootm_states() as well.
For booti make sure it only uses argv[] and argc at the top of the function, so we can eventually refactor to remove these parameters.
Finally, rename the function to bootm_run_states() to better indicate its purpose. The 'do_' prefix is used to indicate a command processor, which this is now not.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/mips/lib/bootm.c | 2 +- boot/bootm.c | 60 ++++++++++++------------------------------- cmd/booti.c | 55 ++++++++++++++++++++++----------------- cmd/bootm.c | 26 +++++++++++++++++-- cmd/bootz.c | 45 +++++++++++++++++++++++--------- include/bootm.h | 57 +++++++++++++++++++++++++++++++++++++--- 6 files changed, 160 insertions(+), 85 deletions(-)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 05dbe6131728..339a875bdf20 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -216,7 +216,7 @@ static int boot_reloc_fdt(struct bootm_headers *images) { /* * In case of legacy uImage's, relocation of FDT is already done - * by do_bootm_states() and should not repeated in 'bootm prep'. + * by bootm_run_states() and should not repeated in 'bootm prep'. */ if (images->state & BOOTM_STATE_FDT) { debug("## FDT already relocated\n"); diff --git a/boot/bootm.c b/boot/bootm.c index de5c32099ceb..1f46bb88b38e 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -989,35 +989,9 @@ unmap_image: return ret; }
-/** - * Execute selected states of the bootm command. - * - * Note the arguments to this state must be the first argument, Any 'bootm' - * or sub-command arguments must have already been taken. - * - * Note that if states contains more than one flag it MUST contain - * BOOTM_STATE_START, since this handles and consumes the command line args. - * - * Also note that aside from boot_os_fn functions and bootm_load_os no other - * functions we store the return value of in 'ret' may use a negative return - * value, without special handling. - * - * @param cmdtp Pointer to bootm command table entry - * @param flag Command flags (CMD_FLAG_...) - * @param argc Number of subcommand arguments (0 = no arguments) - * @param argv Arguments - * @param states Mask containing states to run (BOOTM_STATE_...) - * @param images Image header information - * @param boot_progress 1 to show boot progress, 0 to not do this - * Return: 0 if ok, something else on error. Some errors will cause this - * function to perform a reboot! If states contains BOOTM_STATE_OS_GO - * then the intent is to boot an OS, so this function will not return - * unless the image type is standalone. - */ -int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[], int states, struct bootm_headers *images, - int boot_progress) +int bootm_run_states(struct bootm_info *bmi, int states) { + struct bootm_headers *images = bmi->images; boot_os_fn *boot_fn; ulong iflag = 0; int ret = 0, need_boot_fn; @@ -1032,17 +1006,18 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, ret = bootm_start();
if (!ret && (states & BOOTM_STATE_PRE_LOAD)) - ret = bootm_pre_load(argv[0]); + ret = bootm_pre_load(bmi->addr_fit);
if (!ret && (states & BOOTM_STATE_FINDOS)) - ret = bootm_find_os(cmdtp->name, argv[0]); + ret = bootm_find_os(bmi->cmd_name, bmi->addr_fit);
if (!ret && (states & BOOTM_STATE_FINDOTHER)) { ulong img_addr;
- img_addr = argc ? hextoul(argv[0], NULL) : image_load_addr; - ret = bootm_find_other(img_addr, cmd_arg1(argc, argv), - cmd_arg2(argc, argv)); + img_addr = bmi->addr_fit ? hextoul(bmi->addr_fit, NULL) + : image_load_addr; + ret = bootm_find_other(img_addr, bmi->conf_ramdisk, + bmi->conf_fdt); }
if (IS_ENABLED(CONFIG_MEASURED_BOOT) && !ret && @@ -1119,7 +1094,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
ret = boot_selected_os(BOOTM_STATE_OS_FAKE_GO, images, boot_fn); if (!ret && cmd_list) - ret = run_command_list(cmd_list, -1, flag); + ret = run_command_list(cmd_list, -1, 0); } #endif
@@ -1150,19 +1125,11 @@ err:
int bootm_boot_start(ulong addr, const char *cmdline) { - static struct cmd_tbl cmd = {"bootm"}; char addr_str[30]; - char *argv[] = {addr_str, NULL}; + struct bootm_info bmi; int states; int ret;
- /* - * TODO(sjg@chromium.org): This uses the command-line interface, but - * should not. To clean this up, the various bootm states need to be - * passed an info structure instead of cmdline flags. Then this can - * set up the required info and move through the states without needing - * the command line. - */ states = BOOTM_STATE_START | BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER | BOOTM_STATE_LOADOS | BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | @@ -1180,7 +1147,12 @@ int bootm_boot_start(ulong addr, const char *cmdline) printf("Failed to set cmdline\n"); return ret; } - ret = do_bootm_states(&cmd, 0, 1, argv, states, &images, 1); + memset(&bmi, '\0', sizeof(bmi)); + bmi.addr_fit = addr_str; + bmi.boot_progress = true; + bmi.images = &images; + bmi.cmd_name = "bootm"; + ret = bootm_run_states(&bmi, states);
return ret; } diff --git a/cmd/booti.c b/cmd/booti.c index 2db8f4a16ff2..57850a02edc9 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -20,9 +20,9 @@ DECLARE_GLOBAL_DATA_PTR; /* * Image booting support */ -static int booti_start(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[], struct bootm_headers *images) +static int booti_start(struct bootm_info *bmi) { + struct bootm_headers *images = bmi->images; int ret; ulong ld; ulong relocated_addr; @@ -34,16 +34,15 @@ static int booti_start(struct cmd_tbl *cmdtp, int flag, int argc, unsigned long decomp_len; int ctype;
- ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, - images, 1); + ret = bootm_run_states(bmi, BOOTM_STATE_START);
/* Setup Linux kernel Image entry point */ - if (!argc) { + if (!bmi->addr_fit) { ld = image_load_addr; debug("* kernel: default image load address = 0x%08lx\n", image_load_addr); } else { - ld = hextoul(argv[0], NULL); + ld = hextoul(bmi->addr_fit, NULL); debug("* kernel: cmdline image address = 0x%08lx\n", ld); }
@@ -95,9 +94,8 @@ static int booti_start(struct cmd_tbl *cmdtp, int flag, int argc, * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not * have a header that provide this informaiton. */ - if (bootm_find_images(image_load_addr, cmd_arg1(argc, argv), - cmd_arg2(argc, argv), relocated_addr, - image_size)) + if (bootm_find_images(image_load_addr, bmi->conf_ramdisk, bmi->conf_fdt, + relocated_addr, image_size)) return 1;
return 0; @@ -105,12 +103,25 @@ static int booti_start(struct cmd_tbl *cmdtp, int flag, int argc,
int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { + struct bootm_info bmi; + int states; int ret;
/* Consume 'booti' */ argc--; argv++;
- if (booti_start(cmdtp, flag, argc, argv, &images)) + memset(&bmi, '\0', sizeof(struct bootm_info)); + if (argc) + bmi.addr_fit = argv[0]; + if (argc > 1) + bmi.conf_ramdisk = argv[1]; + if (argc > 2) + bmi.conf_fdt = argv[2]; + bmi.boot_progress = true; + bmi.images = &images; + bmi.cmd_name = "booti"; + + if (booti_start(&bmi)) return 1;
/* @@ -120,19 +131,17 @@ int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) bootm_disable_interrupts();
images.os.os = IH_OS_LINUX; -#ifdef CONFIG_RISCV_SMODE - images.os.arch = IH_ARCH_RISCV; -#elif CONFIG_ARM64 - images.os.arch = IH_ARCH_ARM64; -#endif - ret = do_bootm_states(cmdtp, flag, argc, argv, -#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH - BOOTM_STATE_RAMDISK | -#endif - BOOTM_STATE_MEASURE | - BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | - BOOTM_STATE_OS_GO, - &images, 1); + if (IS_ENABLED(CONFIG_RISCV_SMODE)) + images.os.arch = IH_ARCH_RISCV; + else if (IS_ENABLED(CONFIG_ARM64)) + images.os.arch = IH_ARCH_ARM64; + + states = BOOTM_STATE_MEASURE | BOOTM_STATE_OS_PREP | + BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO; + if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) + states |= BOOTM_STATE_RAMDISK; + + ret = bootm_run_states(&bmi, states);
return ret; } diff --git a/cmd/bootm.c b/cmd/bootm.c index 6ded091dd559..68fb48f77a90 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -76,6 +76,7 @@ static ulong bootm_get_addr(int argc, char *const argv[]) static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { + struct bootm_info bmi; int ret = 0; long state; struct cmd_tbl *c; @@ -103,7 +104,17 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_USAGE; }
- ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0); + memset(&bmi, '\0', sizeof(struct bootm_info)); + if (argc) + bmi.addr_fit = argv[0]; + if (argc > 1) + bmi.conf_ramdisk = argv[1]; + if (argc > 2) + bmi.conf_fdt = argv[2]; + bmi.images = &images; + bmi.cmd_name = "bootm"; + + ret = bootm_run_states(&bmi, state);
#if defined(CONFIG_CMD_BOOTM_PRE_LOAD) if (!ret && (state & BOOTM_STATE_PRE_LOAD)) @@ -120,6 +131,7 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc,
int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { + struct bootm_info bmi; int states; int ret;
@@ -151,7 +163,17 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) states |= BOOTM_STATE_MEASURE; if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS)) states |= BOOTM_STATE_OS_CMDLINE; - ret = do_bootm_states(cmdtp, flag, argc, argv, states, &images, 1); + + memset(&bmi, '\0', sizeof(struct bootm_info)); + if (argc) + bmi.addr_fit = argv[0]; + if (argc > 1) + bmi.conf_ramdisk = argv[1]; + if (argc > 2) + bmi.conf_fdt = argv[2]; + bmi.boot_progress = true; + bmi.images = &images; + ret = bootm_run_states(&bmi, states);
return ret ? CMD_RET_FAILURE : 0; } diff --git a/cmd/bootz.c b/cmd/bootz.c index a652879ea5ec..fa6743a71170 100644 --- a/cmd/bootz.c +++ b/cmd/bootz.c @@ -27,11 +27,21 @@ int __weak bootz_setup(ulong image, ulong *start, ulong *end) static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], struct bootm_headers *images) { - int ret; ulong zi_start, zi_end; + struct bootm_info bmi; + int ret; + + memset(&bmi, '\0', sizeof(struct bootm_info)); + if (argc) + bmi.addr_fit = argv[0]; + if (argc > 1) + bmi.conf_ramdisk = argv[1]; + if (argc > 2) + bmi.conf_fdt = argv[2]; + bmi.boot_progress = true; + bmi.images = images;
- ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, - images, 1); + ret = bootm_run_states(&bmi, BOOTM_STATE_START);
/* Setup Linux kernel zImage entry point */ if (!argc) { @@ -64,7 +74,8 @@ static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc,
int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - int ret; + struct bootm_info bmi; + int states, ret;
/* Consume 'bootz' */ argc--; argv++; @@ -79,14 +90,24 @@ int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) bootm_disable_interrupts();
images.os.os = IH_OS_LINUX; - ret = do_bootm_states(cmdtp, flag, argc, argv, -#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH - BOOTM_STATE_RAMDISK | -#endif - BOOTM_STATE_MEASURE | - BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | - BOOTM_STATE_OS_GO, - &images, 1); + + memset(&bmi, '\0', sizeof(struct bootm_info)); + if (argc) + bmi.addr_fit = argv[0]; + if (argc > 1) + bmi.conf_ramdisk = argv[1]; + if (argc > 2) + bmi.conf_fdt = argv[2]; + bmi.boot_progress = 1; + bmi.images = &images; + bmi.cmd_name = "bootz"; + + states = BOOTM_STATE_MEASURE | BOOTM_STATE_OS_PREP | + BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO; + if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) + states |= BOOTM_STATE_RAMDISK; + + ret = bootm_run_states(&bmi, states);
return ret; } diff --git a/include/bootm.h b/include/bootm.h index b8d74d03a8c4..a3bef1ab88f2 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -16,6 +16,41 @@ struct cmd_tbl; #define BOOTM_ERR_OVERLAP (-2) #define BOOTM_ERR_UNIMPLEMENTED (-3)
+/** + * struct bootm_info() - information used when processing images to boot + * + * These mirror the first three arguments of the bootm command. They are + * designed to handle any type of image, but typically it is a FIT. + * + * @addr_fit: Address of image to bootm, as passed to + * genimg_get_kernel_addr_fit() for processing: + * + * NULL: Usees default load address, i.e. image_load_addr + * <addr>: Uses hex address + * + * For FIT: + * "[<addr>]#<conf>": Uses address (or image_load_addr) and also specifies + * the FIT configuration to use + * "[<addr>]:<subimage>": Uses address (or image_load_addr) and also + * specifies the subimage name containing the OS + * + * @conf_ramdisk: Address (or with FIT, the name) of the ramdisk image, as + * passed to boot_get_ramdisk() for processing, or NULL for none + * @conf_fdt: Address (or with FIT, the name) of the FDT image, as passed to + * boot_get_fdt() for processing, or NULL for none + * @boot_progress: true to show boot progress + * @images: images information + * @cmd_name: command which invoked this operation, e.g. "bootm" + */ +struct bootm_info { + const char *addr_fit; + const char *conf_ramdisk; + const char *conf_fdt; + bool boot_progress; + struct bootm_headers *images; + const char *cmd_name; +}; + /* * Continue booting an OS image; caller already has: * - copied image header to global variable `header' @@ -82,9 +117,25 @@ int bootm_find_images(ulong img_addr, const char *conf_ramdisk, */ int bootm_measure(struct bootm_headers *images);
-int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[], int states, struct bootm_headers *images, - int boot_progress); +/** + * bootm_run_states() - Execute selected states of the bootm command. + * + * Note that if states contains more than one flag it MUST contain + * BOOTM_STATE_START, since this handles the addr_fit, conf_ramdisk and conf_fit + * members of @bmi + * + * Also note that aside from boot_os_fn functions and bootm_load_os, no other + * functions store the return value of in 'ret' may use a negative return + * value, without special handling. + * + * @bmi: bootm information + * @states Mask containing states to run (BOOTM_STATE_...) + * Return: 0 if ok, something else on error. Some errors will cause this + * function to perform a reboot! If states contains BOOTM_STATE_OS_GO + * then the intent is to boot an OS, so this function will not return + * unless the image type is standalone. + */ +int bootm_run_states(struct bootm_info *bmi, int states);
void arch_preboot_os(void);

In quite a few places, the bootm command is used to handle a boot. We want these to be done without needing CONFIG_CMDLINE, so add a new bootm_run() function to handle this.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootm.c | 19 +++++++++++++++++++ cmd/bootm.c | 14 +------------- include/bootm.h | 13 +++++++++++++ 3 files changed, 33 insertions(+), 13 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 1f46bb88b38e..301ba480677d 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1123,6 +1123,25 @@ err: return ret; }
+int bootm_run(struct bootm_info *bmi) +{ + int states; + + bmi->cmd_name = "bootm"; + states = BOOTM_STATE_START | BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD | + BOOTM_STATE_FINDOTHER | BOOTM_STATE_LOADOS | + BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | + BOOTM_STATE_OS_GO; + if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) + states |= BOOTM_STATE_RAMDISK; + if (IS_ENABLED(CONFIG_MEASURED_BOOT)) + states |= BOOTM_STATE_MEASURE; + if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS)) + states |= BOOTM_STATE_OS_CMDLINE; + + return bootm_run_states(bmi, states); +} + int bootm_boot_start(ulong addr, const char *cmdline) { char addr_str[30]; diff --git a/cmd/bootm.c b/cmd/bootm.c index 68fb48f77a90..744a84d6c394 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -132,7 +132,6 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc, int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct bootm_info bmi; - int states; int ret;
/* determine if we have a sub command */ @@ -153,17 +152,6 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) return do_bootm_subcommand(cmdtp, flag, argc, argv); }
- states = BOOTM_STATE_START | BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD | - BOOTM_STATE_FINDOTHER | BOOTM_STATE_LOADOS | - BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | - BOOTM_STATE_OS_GO; - if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) - states |= BOOTM_STATE_RAMDISK; - if (IS_ENABLED(CONFIG_MEASURED_BOOT)) - states |= BOOTM_STATE_MEASURE; - if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS)) - states |= BOOTM_STATE_OS_CMDLINE; - memset(&bmi, '\0', sizeof(struct bootm_info)); if (argc) bmi.addr_fit = argv[0]; @@ -173,7 +161,7 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) bmi.conf_fdt = argv[2]; bmi.boot_progress = true; bmi.images = &images; - ret = bootm_run_states(&bmi, states); + ret = bootm_run(&bmi);
return ret ? CMD_RET_FAILURE : 0; } diff --git a/include/bootm.h b/include/bootm.h index a3bef1ab88f2..ef46c085b594 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -137,6 +137,19 @@ int bootm_measure(struct bootm_headers *images); */ int bootm_run_states(struct bootm_info *bmi, int states);
+/** + * bootm_run() - Run the entire bootm process + * + * This runs through the bootm process from start to finish, using the default + * set of states. + * + * This uses bootm_run_states(). + * + * @bmi: bootm information + * Return: 0 if ok, something else on error + */ +int bootm_run(struct bootm_info *bmi); + void arch_preboot_os(void);
/*

Rather than assigning to the bootm_argv[] array multiple times, use local variables for the two things that can change and assign them at the end.
This makes it easier to drop the array eventually.
Tidu up an overly short line while we are here.
Signed-off-by: Simon Glass sjg@chromium.org ---
.../cmd_stm32prog/cmd_stm32prog.c | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-)
diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c index 2411bcf06d8f..8670535844d3 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c @@ -124,30 +124,35 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc, char boot_addr_start[20]; char dtb_addr[20]; char initrd_addr[40]; + char *fdt_arg, *initrd_arg; char *bootm_argv[5] = { - "bootm", boot_addr_start, "-", dtb_addr, NULL + "bootm", boot_addr_start, }; const void *uimage = (void *)data->uimage; const void *dtb = (void *)data->dtb; const void *initrd = (void *)data->initrd;
+ fdt_arg = dtb_addr; if (!dtb) - bootm_argv[3] = env_get("fdtcontroladdr"); + fdt_arg = env_get("fdtcontroladdr"); else - snprintf(dtb_addr, sizeof(dtb_addr) - 1, - "0x%p", dtb); + snprintf(dtb_addr, sizeof(dtb_addr) - 1, "0x%p", dtb);
snprintf(boot_addr_start, sizeof(boot_addr_start) - 1, "0x%p", uimage);
+ initrd_arg = "-"; if (initrd) { - snprintf(initrd_addr, sizeof(initrd_addr) - 1, "0x%p:0x%zx", - initrd, data->initrd_size); - bootm_argv[2] = initrd_addr; + snprintf(initrd_addr, sizeof(initrd_addr) - 1, + "0x%p:0x%zx", initrd, data->initrd_size); + initrd_arg = initrd_addr; }
- printf("Booting kernel at %s %s %s...\n\n\n", - boot_addr_start, bootm_argv[2], bootm_argv[3]); + printf("Booting kernel at %s %s %s...\n\n\n", boot_addr_start, + initrd_arg, fdt_arg); + bootm_argv[2] = initrd_arg; + bootm_argv[3] = fdt_arg; + /* Try bootm for legacy and FIT format image */ if (genimg_get_format(uimage) != IMAGE_FORMAT_INVALID) do_bootm(cmdtp, 0, 4, bootm_argv);

In a few places, the bootz command is used to handle a boot. We want these to be done without needing CONFIG_CMDLINE, so add a new bootz_run() function to handle this.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootm.c | 13 +++++++++++++ cmd/bootz.c | 9 ++------- include/bootm.h | 13 +++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 301ba480677d..22c6d1604176 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1142,6 +1142,19 @@ int bootm_run(struct bootm_info *bmi) return bootm_run_states(bmi, states); }
+int bootz_run(struct bootm_info *bmi) +{ + int states; + + bmi->cmd_name = "bootz"; + states = BOOTM_STATE_MEASURE | BOOTM_STATE_OS_PREP | + BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO; + if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) + states |= BOOTM_STATE_RAMDISK; + + return bootm_run_states(bmi, states); +} + int bootm_boot_start(ulong addr, const char *cmdline) { char addr_str[30]; diff --git a/cmd/bootz.c b/cmd/bootz.c index fa6743a71170..f03062f1cf75 100644 --- a/cmd/bootz.c +++ b/cmd/bootz.c @@ -75,7 +75,7 @@ static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc, int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { struct bootm_info bmi; - int states, ret; + int ret;
/* Consume 'bootz' */ argc--; argv++; @@ -102,12 +102,7 @@ int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) bmi.images = &images; bmi.cmd_name = "bootz";
- states = BOOTM_STATE_MEASURE | BOOTM_STATE_OS_PREP | - BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO; - if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) - states |= BOOTM_STATE_RAMDISK; - - ret = bootm_run_states(&bmi, states); + ret = bootz_run(&bmi);
return ret; } diff --git a/include/bootm.h b/include/bootm.h index ef46c085b594..d7c9486553e4 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -150,6 +150,19 @@ int bootm_run_states(struct bootm_info *bmi, int states); */ int bootm_run(struct bootm_info *bmi);
+/** + * bootz_run() - Run the entire bootz process + * + * This runs through the bootz process from start to finish, using the default + * set of states. + * + * This uses bootm_run_states(). + * + * @bmi: bootm information + * Return: 0 if ok, something else on error + */ +int bootz_run(struct bootm_info *bmi); + void arch_preboot_os(void);
/*

Use the new bootm/z_run() functions to avoid having to create an argument list for the stm32prog code.
Signed-off-by: Simon Glass sjg@chromium.org ---
.../cmd_stm32prog/cmd_stm32prog.c | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c index 8670535844d3..5e1dc7a03810 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c @@ -4,6 +4,7 @@ */
#include <common.h> +#include <bootm.h> #include <command.h> #include <dfu.h> #include <image.h> @@ -125,12 +126,10 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc, char dtb_addr[20]; char initrd_addr[40]; char *fdt_arg, *initrd_arg; - char *bootm_argv[5] = { - "bootm", boot_addr_start, - }; const void *uimage = (void *)data->uimage; const void *dtb = (void *)data->dtb; const void *initrd = (void *)data->initrd; + struct bootm_info bmi;
fdt_arg = dtb_addr; if (!dtb) @@ -141,7 +140,7 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc, snprintf(boot_addr_start, sizeof(boot_addr_start) - 1, "0x%p", uimage);
- initrd_arg = "-"; + initrd_arg = NULL; if (initrd) { snprintf(initrd_addr, sizeof(initrd_addr) - 1, "0x%p:0x%zx", initrd, data->initrd_size); @@ -149,15 +148,20 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc, }
printf("Booting kernel at %s %s %s...\n\n\n", boot_addr_start, - initrd_arg, fdt_arg); - bootm_argv[2] = initrd_arg; - bootm_argv[3] = fdt_arg; + initrd_arg ?: "-", fdt_arg); + + memset(&bmi, '\0', sizeof(bmi)); + bmi.addr_fit = boot_addr_start; + bmi.conf_ramdisk = initrd_arg; + bmi.conf_fdt = fdt_arg; + bmi.boot_progress = true; + bmi.images = &images;
/* Try bootm for legacy and FIT format image */ if (genimg_get_format(uimage) != IMAGE_FORMAT_INVALID) - do_bootm(cmdtp, 0, 4, bootm_argv); + bootm_run(&bmi); else if (IS_ENABLED(CONFIG_CMD_BOOTZ)) - do_bootz(cmdtp, 0, 4, bootm_argv); + bootz_run(&bmi); } if (data->script) cmd_source_script(data->script, NULL, NULL);

In a few places, the booti command is used to handle a boot. We want these to be done without needing CONFIG_CMDLINE, so add a new booti_run() function to handle this.
So far this is not used.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootm.c | 13 +++++++++++++ include/bootm.h | 13 +++++++++++++ 2 files changed, 26 insertions(+)
diff --git a/boot/bootm.c b/boot/bootm.c index 22c6d1604176..f630b8c1a9c3 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1155,6 +1155,19 @@ int bootz_run(struct bootm_info *bmi) return bootm_run_states(bmi, states); }
+int booti_run(struct bootm_info *bmi) +{ + int states; + + bmi->cmd_name = "booti"; + states = BOOTM_STATE_MEASURE | BOOTM_STATE_OS_PREP | + BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO; + if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) + states |= BOOTM_STATE_RAMDISK; + + return bootm_run_states(bmi, states); +} + int bootm_boot_start(ulong addr, const char *cmdline) { char addr_str[30]; diff --git a/include/bootm.h b/include/bootm.h index d7c9486553e4..ce5298e4ed97 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -163,6 +163,19 @@ int bootm_run(struct bootm_info *bmi); */ int bootz_run(struct bootm_info *bmi);
+/** + * booti_run() - Run the entire booti process + * + * This runs through the booti process from start to finish, using the default + * set of states. + * + * This uses bootm_run_states(). + * + * @bmi: bootm information + * Return: 0 if ok, something else on error + */ +int booti_run(struct bootm_info *bmi); + void arch_preboot_os(void);
/*

On Sun, Dec 03, 2023 at 05:26:16PM -0700, Simon Glass wrote:
This series continues refactoring the bootm code to allow it to be used with CONFIG_COMMAND disabled. The OS-handling code is refactored and a new bootm_run() function is created to run through the bootm stages. This completes the work.
A booti_go() function is created also, in case it proves useful, but at last for now standard boot does not use this.
This is cmdd (part d of CMDLINE refactoring) It depends on dm/bootstda-working which depends on dm/cmdc-working
Since I would ask "what's the size impact of all of this?", I went and checked. I rebased your current cmdd-working branch on top of current next, and compared. While I'm sure this will change a little given feedback so far, generally platforms shrink a little (probably due to the bootm args stuff you dropped, but may need to keep). The only big growth I saw was branch specific and your "rpi" patch, oh yes, that grows rpi_4 given that you change a bunch of stuff there. So that doesn't count.
So generally speaking, I'm OK with this series up to cmdd-working, and will continue catching up and providing specific feedback.

Hi Tom,
On Sat, 9 Dec 2023 at 12:09, Tom Rini trini@konsulko.com wrote:
On Sun, Dec 03, 2023 at 05:26:16PM -0700, Simon Glass wrote:
This series continues refactoring the bootm code to allow it to be used with CONFIG_COMMAND disabled. The OS-handling code is refactored and a new bootm_run() function is created to run through the bootm stages. This completes the work.
A booti_go() function is created also, in case it proves useful, but at last for now standard boot does not use this.
This is cmdd (part d of CMDLINE refactoring) It depends on dm/bootstda-working which depends on dm/cmdc-working
Since I would ask "what's the size impact of all of this?", I went and checked. I rebased your current cmdd-working branch on top of current next, and compared. While I'm sure this will change a little given feedback so far, generally platforms shrink a little (probably due to the bootm args stuff you dropped, but may need to keep). The only big growth I saw was branch specific and your "rpi" patch, oh yes, that grows rpi_4 given that you change a bunch of stuff there. So that doesn't count.
So generally speaking, I'm OK with this series up to cmdd-working, and will continue catching up and providing specific feedback.
OK, great. I have had a busy week but may be able to catch up a bit on the plane.
Regards, Simon
participants (5)
-
Angelo Dureghello
-
Mark Kettenis
-
Martin Husemann
-
Simon Glass
-
Tom Rini