[PATCH v2 00/21] 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
Changes in v2: - Add new patch to enable more bootm OS methods in sandbox - Split addition of struct bootm_info to its own patch - Split changing of boot_os_fn parameters to a separate patch - Split out adding the rest of struct bootm_info fields to separate patch - Split out patch to move do_bootm_states() comment to header - Split out booti removal of #ifdef - Split out bootz removal of #ifdef - Adjust patch to focus just on dropping the do_bootm_states() arguments - Split do_bootm_states() rename to a separate patch - Rework series to allow OS access to cmdline arguments for bootm
Simon Glass (21): 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 sandbox: bootm: Enable more bootm OS methods bootm: Create a struct for argument information bootm: Adjust arguments of boot_os_fn bootm: Add more fields to bootm_info bootm: Move do_bootm_states() comment to header file booti: Avoid use of #ifdef bootz: Avoid use of #ifdef bootm: Drop arguments from do_bootm_states() bootm: Rename do_bootm_states() to bootm_run_states() bootm: Tidy up boot_selected_os() 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 | 5 +- arch/arm/lib/bootm.c | 6 +- .../cmd_stm32prog/cmd_stm32prog.c | 33 +++-- arch/m68k/lib/bootm.c | 5 +- arch/m68k/lib/traps.c | 7 + arch/microblaze/lib/bootm.c | 6 +- arch/mips/cpu/cpu.c | 8 +- arch/mips/lib/bootm.c | 8 +- arch/nios2/cpu/cpu.c | 8 +- arch/nios2/lib/bootm.c | 10 +- arch/powerpc/lib/bootm.c | 5 +- arch/powerpc/lib/traps.c | 10 ++ arch/riscv/cpu/cpu.c | 13 ++ arch/riscv/lib/bootm.c | 11 +- arch/riscv/lib/reset.c | 7 +- arch/sandbox/cpu/cpu.c | 8 ++ arch/sandbox/lib/bootm.c | 5 +- arch/sh/lib/bootm.c | 6 +- arch/x86/lib/bootm.c | 6 +- arch/xtensa/lib/bootm.c | 4 +- boot/bootm.c | 133 ++++++++++-------- boot/bootm_os.c | 78 +++++----- cmd/booti.c | 55 +++++--- cmd/bootm.c | 43 ++++-- cmd/bootz.c | 35 +++-- configs/sandbox_defconfig | 3 +- include/bootm.h | 124 ++++++++++++++-- 27 files changed, 440 insertions(+), 202 deletions(-)

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 ---
(no changes since v1)
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; }

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 Acked-by: Angelo Dureghello angelo@kernel-spcece.org ---
(no changes since v1)
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 ---
(no changes since v1)
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 ---
(no changes since v1)
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 ---
(no changes since v1)
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; }

-----Original Message----- From: Simon Glass sjg@chromium.org Sent: Friday, December 15, 2023 1:50 AM To: U-Boot Mailing List u-boot@lists.denx.de Cc: Tom Rini trini@konsulko.com; Simon Glass sjg@chromium.org; Chanho Park chanho61.park@samsung.com; Heinrich Schuchardt
Leo ycliang@andestech.com; Nikita Shubin n.shubin@yadro.com; Rick Chen rick@andestech.com Subject: [PATCH v2 05/21] riscv: Add a reset_cpu() function
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
Reviewed-by: Chanho Park chanho61.park@samsung.com Tested-by: Chanho Park chanho61.park@samsung.com
(no changes since v1)
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;
}
2.43.0.472.g3155946c3a-goog

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 ---
(no changes since v1)
boot/bootm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 301cfded05cb..8a0dba5074e8 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1140,10 +1140,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; }

Hi Simon,
Thank you for your patch.
On jeu., déc. 14, 2023 at 09:50, Simon Glass sjg@chromium.org 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
Reviewed-by: Mattijs Korpershoek mkorpershoek@baylibre.com
(no changes since v1)
boot/bootm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 301cfded05cb..8a0dba5074e8 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1140,10 +1140,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;
}
2.43.0.472.g3155946c3a-goog

It is useful for sandbox to build as much code as possible. Enable support for booting various other operating systems. Add the missing cache functions.
These operating systems do not actually boot on sandbox, of course.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Add new patch to enable more bootm OS methods in sandbox
arch/sandbox/cpu/cpu.c | 8 ++++++++ configs/sandbox_defconfig | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index a1c5c7c4311a..d134905e3f5f 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -286,6 +286,14 @@ void sandbox_set_enable_pci_map(int enable) enable_pci_map = enable; }
+void dcache_enable(void) +{ +} + +void dcache_disable(void) +{ +} + int dcache_status(void) { return 1; diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index af3e7d85be39..fd9ca24f8dbe 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -44,10 +44,11 @@ CONFIG_CMD_CPU=y CONFIG_CMD_LICENSE=y CONFIG_CMD_BOOTM_PRE_LOAD=y CONFIG_CMD_BOOTZ=y +CONFIG_BOOTM_OPENRTOS=y +CONFIG_BOOTM_OSE=y CONFIG_CMD_BOOTEFI_HELLO=y CONFIG_CMD_BOOTMENU=y CONFIG_CMD_ABOOTIMG=y -# CONFIG_CMD_ELF is not set CONFIG_CMD_ASKENV=y CONFIG_CMD_GREPENV=y CONFIG_CMD_ERASEENV=y

Some OS functions require the arguments to the 'bootm' command. This is inconvenient for two reasons.
Firstly, there may not be any actual command, if CMDLINE is not enabled and programmatic boot is being used.
Secondly, most functions don't require the arguments, so it is inefficient to pass them when not needed. For example it increases code size.
Create a new struct which holds the arguments, which can be used if needed.
Add the images pointer as well, since this is commonly needed.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Split addition of struct bootm_info to its own patch
include/bootm.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/bootm.h b/include/bootm.h index f5229ea90b33..a6d5d5ceee8f 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -16,6 +16,20 @@ struct cmd_tbl; #define BOOTM_ERR_OVERLAP (-2) #define BOOTM_ERR_UNIMPLEMENTED (-3)
+/** + * struct bootm_info() - information used when processing images to boot + * + * @images: images information + * @argc: Number of arguments to the command (excluding the actual command). + * This is 0 if there are no arguments + * @argv: NULL-terminated list of arguments, or NULL if there are no arguments + */ +struct bootm_info { + struct bootm_headers *images; + int argc; + char *const *argv; +}; + /* * Continue booting an OS image; caller already has: * - copied image header to global variable `header' @@ -39,7 +53,7 @@ typedef int boot_os_fn(int flag, int argc, char *const argv[], extern boot_os_fn do_bootm_linux; extern boot_os_fn do_bootm_vxworks;
-int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_bootelf(struct cmd_tbl *cmdtp, int fglag, int argc, char *const argv[]);
boot_os_fn *bootm_os_get_boot_func(int os);

On Thu, Dec 14, 2023 at 09:50:17AM -0700, Simon Glass wrote:
Some OS functions require the arguments to the 'bootm' command. This is inconvenient for two reasons.
Firstly, there may not be any actual command, if CMDLINE is not enabled and programmatic boot is being used.
Secondly, most functions don't require the arguments, so it is inefficient to pass them when not needed. For example it increases code size.
Create a new struct which holds the arguments, which can be used if needed.
Add the images pointer as well, since this is commonly needed.
Signed-off-by: Simon Glass sjg@chromium.org
[snip]
@@ -39,7 +53,7 @@ typedef int boot_os_fn(int flag, int argc, char *const argv[], extern boot_os_fn do_bootm_linux; extern boot_os_fn do_bootm_vxworks;
-int do_bootelf(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); +int do_bootelf(struct cmd_tbl *cmdtp, int fglag, int argc, char *const argv[]);
Typo, can just drop when applying if there's no v3.
Reviewed-by: Tom Rini trini@konsulko.com

Adjust boot_os_fn to use struct bootm_info instead of the separate argc, argv and image parameters. Update the handlers accordingly. Few of the functions make use of the arguments, so this improves code size slightly.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Split changing of boot_os_fn parameters to a separate patch
arch/arc/lib/bootm.c | 5 ++- arch/arm/lib/bootm.c | 6 ++- arch/m68k/lib/bootm.c | 5 ++- arch/microblaze/lib/bootm.c | 6 ++- arch/mips/lib/bootm.c | 6 ++- arch/nios2/lib/bootm.c | 10 +++-- arch/powerpc/lib/bootm.c | 5 ++- arch/riscv/lib/bootm.c | 11 +++--- arch/sandbox/lib/bootm.c | 5 ++- arch/sh/lib/bootm.c | 6 ++- arch/x86/lib/bootm.c | 6 ++- arch/xtensa/lib/bootm.c | 4 +- boot/bootm.c | 11 ++++-- boot/bootm_os.c | 77 ++++++++++++++++++++----------------- include/bootm.h | 9 +---- 15 files changed, 100 insertions(+), 72 deletions(-)
diff --git a/arch/arc/lib/bootm.c b/arch/arc/lib/bootm.c index 44ec5864a1c6..b143392ee6c2 100644 --- a/arch/arc/lib/bootm.c +++ b/arch/arc/lib/bootm.c @@ -3,6 +3,7 @@ * Copyright (C) 2013-2014 Synopsys, Inc. All rights reserved. */
+#include <bootm.h> #include <bootstage.h> #include <env.h> #include <image.h> @@ -78,8 +79,10 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; + /* No need for those on ARC */ if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE)) return -1; diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c index c56285738a26..f30a483ed8b4 100644 --- a/arch/arm/lib/bootm.c +++ b/arch/arm/lib/bootm.c @@ -12,6 +12,7 @@ */
#include <common.h> +#include <bootm.h> #include <bootstage.h> #include <command.h> #include <cpu_func.h> @@ -378,9 +379,10 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; + /* No need for those on ARM */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) return -1; diff --git a/arch/m68k/lib/bootm.c b/arch/m68k/lib/bootm.c index 79d8b34c0d56..f2d02e437658 100644 --- a/arch/m68k/lib/bootm.c +++ b/arch/m68k/lib/bootm.c @@ -4,6 +4,7 @@ * Wolfgang Denk, DENX Software Engineering, wd@denx.de. */
+#include <bootm.h> #include <bootstage.h> #include <command.h> #include <env.h> @@ -34,9 +35,9 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; int ret; struct bd_info *kbd; void (*kernel) (struct bd_info *, ulong, ulong, ulong, ulong); diff --git a/arch/microblaze/lib/bootm.c b/arch/microblaze/lib/bootm.c index f3ec4b741b88..cbe9d85aa911 100644 --- a/arch/microblaze/lib/bootm.c +++ b/arch/microblaze/lib/bootm.c @@ -7,6 +7,7 @@ * Yasushi SHOJI yashi@atmark-techno.com */
+#include <bootm.h> #include <bootstage.h> #include <command.h> #include <cpu_func.h> @@ -81,9 +82,10 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; + images->cmdline_start = (ulong)env_get("bootargs");
/* cmdline init is the part of 'prep' and nothing to do for 'bdt' */ diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index f1cff691f4fe..286dbd5c4581 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -4,6 +4,7 @@ * Wolfgang Denk, DENX Software Engineering, wd@denx.de. */
+#include <bootm.h> #include <bootstage.h> #include <env.h> #include <image.h> @@ -300,9 +301,10 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; + /* No need for those on MIPS */ if (flag & BOOTM_STATE_OS_BD_T) return -1; diff --git a/arch/nios2/lib/bootm.c b/arch/nios2/lib/bootm.c index 06c094d0f1c7..657a17c7204f 100644 --- a/arch/nios2/lib/bootm.c +++ b/arch/nios2/lib/bootm.c @@ -5,6 +5,7 @@ */
#include <common.h> +#include <bootm.h> #include <cpu_func.h> #include <env.h> #include <image.h> @@ -16,9 +17,9 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; void (*kernel)(int, int, int, char *) = (void *)images->ep; char *commandline = env_get("bootargs"); ulong initrd_start = images->rd_start; @@ -29,8 +30,9 @@ 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); + /* TODO: Clean this up - the DT should already be set up */ + if (!of_flat_tree && bmi->argc > 1) + of_flat_tree = (char *)hextoul(bmi->argv[1], NULL); if (of_flat_tree) initrd_end = (ulong)of_flat_tree;
diff --git a/arch/powerpc/lib/bootm.c b/arch/powerpc/lib/bootm.c index 910121ec9c85..75c6bfd2bf81 100644 --- a/arch/powerpc/lib/bootm.c +++ b/arch/powerpc/lib/bootm.c @@ -8,6 +8,7 @@
#include <common.h> +#include <bootm.h> #include <bootstage.h> #include <cpu_func.h> #include <env.h> @@ -223,9 +224,9 @@ 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) +int do_bootm_linux(int flag, struct bootm_info *bmi) { + struct bootm_headers *images = bmi->images; int ret;
if (flag & BOOTM_STATE_OS_CMDLINE) { diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c index f9e1e18ae026..13cbaaba6820 100644 --- a/arch/riscv/lib/bootm.c +++ b/arch/riscv/lib/bootm.c @@ -7,6 +7,7 @@ */
#include <bootstage.h> +#include <bootm.h> #include <command.h> #include <dm.h> #include <fdt_support.h> @@ -105,9 +106,10 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; + /* No need for those on RISC-V */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) return -1; @@ -127,10 +129,9 @@ int do_bootm_linux(int flag, int argc, char *const argv[], return 0; }
-int do_bootm_vxworks(int flag, int argc, char *const argv[], - struct bootm_headers *images) +int do_bootm_vxworks(int flag, struct bootm_info *bmi) { - return do_bootm_linux(flag, argc, argv, images); + return do_bootm_linux(flag, bmi); }
static ulong get_sp(void) diff --git a/arch/sandbox/lib/bootm.c b/arch/sandbox/lib/bootm.c index a748ba650b12..e56de90e75b8 100644 --- a/arch/sandbox/lib/bootm.c +++ b/arch/sandbox/lib/bootm.c @@ -5,6 +5,7 @@ */
#include <common.h> +#include <bootm.h> #include <bootstage.h> #include <image.h> #include <asm/io.h> @@ -64,8 +65,10 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->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..05d586b1b6ce 100644 --- a/arch/sh/lib/bootm.c +++ b/arch/sh/lib/bootm.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <bootm.h> #include <command.h> #include <env.h> #include <image.h> @@ -39,9 +40,10 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; + /* Linux kernel load address */ void (*kernel) (void) = (void (*)(void))images->ep; /* empty_zero_page */ diff --git a/arch/x86/lib/bootm.c b/arch/x86/lib/bootm.c index 3196f9ddc2c8..050c420e86b6 100644 --- a/arch/x86/lib/bootm.c +++ b/arch/x86/lib/bootm.c @@ -8,6 +8,7 @@ */
#include <common.h> +#include <bootm.h> #include <bootstage.h> #include <command.h> #include <efi.h> @@ -237,9 +238,10 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; + /* No need for those on x86 */ if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE) return -1; diff --git a/arch/xtensa/lib/bootm.c b/arch/xtensa/lib/bootm.c index fee339281502..9780d46e9b89 100644 --- a/arch/xtensa/lib/bootm.c +++ b/arch/xtensa/lib/bootm.c @@ -5,6 +5,7 @@ */
#include <common.h> +#include <bootm.h> #include <bootstage.h> #include <command.h> #include <cpu_func.h> @@ -134,8 +135,9 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; struct bp_tag *params, *params_start; ulong initrd_start, initrd_end; char *commandline = env_get("bootargs"); diff --git a/boot/bootm.c b/boot/bootm.c index 8a0dba5074e8..f1c45c380659 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -6,6 +6,7 @@
#ifndef USE_HOSTCC #include <common.h> +#include <bootm.h> #include <bootstage.h> #include <cli.h> #include <command.h> @@ -1018,6 +1019,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[], int states, struct bootm_headers *images, int boot_progress) { + struct bootm_info bmi; boot_os_fn *boot_fn; ulong iflag = 0; int ret = 0, need_boot_fn; @@ -1096,12 +1098,15 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, return 1; }
+ bmi.images = images; + bmi.argc = argc; + bmi.argv = argv;
/* 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, &bmi); 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, &bmi); if (!ret && (states & BOOTM_STATE_OS_PREP)) { ret = bootm_process_cmdline_env(images->os.os == IH_OS_LINUX); if (ret) { @@ -1109,7 +1114,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, &bmi); }
#ifdef CONFIG_TRACE diff --git a/boot/bootm_os.c b/boot/bootm_os.c index b92422171a84..4f547b1b1148 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -23,9 +23,9 @@
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_info *bmi) { + struct bootm_headers *images = bmi->images; int (*appl)(int, char *const[]);
if (!env_get_autostart()) { @@ -33,7 +33,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(bmi->argc, bmi->argv); return 0; }
@@ -64,9 +64,9 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; void (*loader)(struct bd_info *bd, struct legacy_img_hdr *hdr, char *console, char *cmdline); struct legacy_img_hdr *os_hdr, *hdr; @@ -102,14 +102,14 @@ static int do_bootm_netbsd(int flag, int argc, char *const argv[], os_hdr = hdr; }
- if (argc > 0) { + if (bmi->argc > 0) { ulong len; int i;
- for (i = 0, len = 0; i < argc; i += 1) - len += strlen(argv[i]) + 1; + for (i = 0, len = 0; i < bmi->argc; i += 1) + len += strlen(bmi->argv[i]) + 1; cmdline = malloc(len); - copy_args(cmdline, argc, argv, ' '); + copy_args(cmdline, bmi->argc, bmi->argv, ' '); } else { cmdline = env_get("bootargs"); if (cmdline == NULL) @@ -137,9 +137,9 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; void (*entry_point)(struct bd_info *);
if (flag != BOOTM_STATE_OS_GO) @@ -170,9 +170,9 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; void (*entry_point)(void);
if (flag != BOOTM_STATE_OS_GO) @@ -203,9 +203,9 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; void (*entry_point)(void); char *s;
@@ -224,8 +224,8 @@ static int do_bootm_plan9(int flag, int argc, char *const argv[], if (s != NULL) { char *confaddr = (char *)hextoul(s, NULL);
- if (argc > 0) { - copy_args(confaddr, argc, argv, '\n'); + if (bmi->argc) { + copy_args(confaddr, bmi->argc, bmi->argv, '\n'); } else { s = env_get("bootargs"); if (s != NULL) @@ -311,9 +311,10 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; + if (flag != BOOTM_STATE_OS_GO) return 0;
@@ -322,8 +323,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_info *bmi) { char *bootargs; int pos; @@ -348,19 +348,19 @@ 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, bmi); } 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, bmi); } } #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_info *bmi) { + struct bootm_headers *images = bmi->images; char *local_args[2]; char str[16]; int dcache; @@ -376,7 +376,7 @@ 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[0] = bmi->argv[0]; local_args[1] = str; /* and provide it via the arguments */
/* @@ -396,9 +396,9 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; void (*entry_point)(void);
if (flag != BOOTM_STATE_OS_GO) @@ -429,9 +429,9 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; void (*entry_point)(void);
if (flag != BOOTM_STATE_OS_GO) @@ -455,9 +455,9 @@ 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_info *bmi) { + struct bootm_headers *images = bmi->images; int ret;
/* Validate OPTEE header */ @@ -468,14 +468,14 @@ 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, bmi); } #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_info *bmi) { + struct bootm_headers *images = bmi->images; efi_status_t efi_ret; void *image_buf;
@@ -569,9 +569,14 @@ __weak void board_preboot_os(void) int boot_selected_os(int argc, char *const argv[], int state, struct bootm_headers *images, boot_os_fn *boot_fn) { + struct bootm_info bmi; arch_preboot_os(); board_preboot_os(); - boot_fn(state, argc, argv, images); + + bmi.argc = argc; + bmi.argv = argv; + bmi.images = images; + boot_fn(state, &bmi);
/* 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 a6d5d5ceee8f..85c560d5a0ae 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -39,16 +39,11 @@ struct bootm_info { * - 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 + * bmi: Bootm information * 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_info *bmi);
extern boot_os_fn do_bootm_linux; extern boot_os_fn do_bootm_vxworks;

On Thu, Dec 14, 2023 at 09:50:18AM -0700, Simon Glass wrote:
Adjust boot_os_fn to use struct bootm_info instead of the separate argc, argv and image parameters. Update the handlers accordingly. Few of the functions make use of the arguments, so this improves code size slightly.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

Add fields for the three bootm parameters and other things needed for booting. Also add a helper to set up the struct correctly.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Split out adding the rest of struct bootm_info fields to separate patch
boot/bootm.c | 8 ++++++++ include/bootm.h | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+)
diff --git a/boot/bootm.c b/boot/bootm.c index f1c45c380659..9e42fa5117d0 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1192,6 +1192,14 @@ int bootm_boot_start(ulong addr, const char *cmdline) return ret; }
+void bootm_init(struct bootm_info *bmi) +{ + memset(bmi, '\0', sizeof(struct bootm_info)); + bmi->boot_progress = true; + if (IS_ENABLED(CONFIG_CMD_BOOTM)) + bmi->images = &images; +} + /** * switch_to_non_secure_mode() - switch to non-secure mode * diff --git a/include/bootm.h b/include/bootm.h index 85c560d5a0ae..c9ab55f18d39 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -19,17 +19,52 @@ struct cmd_tbl; /** * 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" * @argc: Number of arguments to the command (excluding the actual command). * This is 0 if there are no arguments * @argv: NULL-terminated list of arguments, or NULL if there are no arguments */ 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; int argc; char *const *argv; };
+/** + * bootm_init() - Set up a bootm_info struct with useful defaults + * + * Set up the struct with default values for all members: + * @boot_progress is set to true and @images is set to the global images + * variable. Everything else is set to NULL except @argc which is 0 + */ +void bootm_init(struct bootm_info *bmi); + /* * Continue booting an OS image; caller already has: * - copied image header to global variable `header'

On Thu, Dec 14, 2023 at 09:50:19AM -0700, Simon Glass wrote:
Add fields for the three bootm parameters and other things needed for booting. Also add a helper to set up the struct correctly.
Signed-off-by: Simon Glass sjg@chromium.org
[snip]
diff --git a/include/bootm.h b/include/bootm.h index 85c560d5a0ae..c9ab55f18d39 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -19,17 +19,52 @@ struct cmd_tbl; /**
- 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
Maybe we should just call this addr_img ? I was fine with this at first, and then started reviewing 14+ and it just reads oddly at that point. Since we use this for starting everything in memory I think we should name this a bit more generically, and avoid the editorializing about being typically FIT as well.

This is an exported function, so move the function comment to the bootm.h header file.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Split out patch to move do_bootm_states() comment to header
boot/bootm.c | 25 ------------------------- include/bootm.h | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 9e42fa5117d0..875f8a1c2a56 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -990,31 +990,6 @@ 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) diff --git a/include/bootm.h b/include/bootm.h index c9ab55f18d39..950ce5181f1d 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -131,6 +131,31 @@ int bootm_find_images(ulong img_addr, const char *conf_ramdisk, */ int bootm_measure(struct bootm_headers *images);
+/** + * 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);

On Thu, Dec 14, 2023 at 09:50:20AM -0700, Simon Glass wrote:
This is an exported function, so move the function comment to the bootm.h header file.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

Hi Simon,
Thank you for the patch.
On jeu., déc. 14, 2023 at 09:50, Simon Glass sjg@chromium.org wrote:
This is an exported function, so move the function comment to the bootm.h header file.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Mattijs Korpershoek mkorpershoek@baylibre.com
Changes in v2:
- Split out patch to move do_bootm_states() comment to header
boot/bootm.c | 25 ------------------------- include/bootm.h | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 9e42fa5117d0..875f8a1c2a56 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -990,31 +990,6 @@ 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) diff --git a/include/bootm.h b/include/bootm.h index c9ab55f18d39..950ce5181f1d 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -131,6 +131,31 @@ int bootm_find_images(ulong img_addr, const char *conf_ramdisk, */ int bootm_measure(struct bootm_headers *images);
+/**
- 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); -- 2.43.0.472.g3155946c3a-goog

Use the compiler to get the set of states, instead of the preprocessor.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Split out booti removal of #ifdef
cmd/booti.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/cmd/booti.c b/cmd/booti.c index 41d40c962ec2..d3cceb7e0a39 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -105,6 +105,7 @@ 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[]) { + int states; int ret;
/* Consume 'booti' */ @@ -120,19 +121,16 @@ 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 = do_bootm_states(cmdtp, flag, argc, argv, states, &images, 1);
return ret; }

On Thu, Dec 14, 2023 at 09:50:21AM -0700, Simon Glass wrote:
Use the compiler to get the set of states, instead of the preprocessor.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

Use the compiler to get the set of states, instead of the preprocessor.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Split out bootz removal of #ifdef
cmd/bootz.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/cmd/bootz.c b/cmd/bootz.c index a652879ea5ec..8c25905598a8 100644 --- a/cmd/bootz.c +++ b/cmd/bootz.c @@ -64,7 +64,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[]) { - int ret; + int states, ret;
/* Consume 'bootz' */ argc--; argv++; @@ -79,14 +79,13 @@ 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); + + 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 = do_bootm_states(cmdtp, flag, argc, argv, states, &images, 1);
return ret; }

On Thu, Dec 14, 2023 at 09:50:22AM -0700, Simon Glass wrote:
Use the compiler to get the set of states, instead of the preprocessor.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

Use the bootm_info struct to hold the information required by bootm.
Now that none of the functions called from do_bootm_states() needs an argv[] list, change the arguments of do_bootm_states() as well. Take care to use the same value for boot_progress even though it is a little inconsistent.
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.
With bootm, some OSes need access to the arguments provided to the command, so set these up in the bootm_info struct, for bootm only.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Adjust patch to focus just on dropping the do_bootm_states() arguments
boot/bootm.c | 52 ++++++++++++++++++++----------------------------- cmd/booti.c | 33 ++++++++++++++++++++----------- cmd/bootm.c | 33 +++++++++++++++++++++++++++++-- cmd/bootz.c | 27 +++++++++++++++++++++---- include/bootm.h | 25 ++++++++---------------- 5 files changed, 105 insertions(+), 65 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 875f8a1c2a56..7156149dfae9 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -990,11 +990,9 @@ unmap_image: return ret; }
-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 do_bootm_states(struct bootm_info *bmi, int states) { - struct bootm_info bmi; + struct bootm_headers *images = bmi->images; boot_os_fn *boot_fn; ulong iflag = 0; int ret = 0, need_boot_fn; @@ -1009,17 +1007,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 && @@ -1073,15 +1072,11 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, return 1; }
- bmi.images = images; - bmi.argc = argc; - bmi.argv = argv; - /* Call various other states that are not generally used */ if (!ret && (states & BOOTM_STATE_OS_CMDLINE)) - ret = boot_fn(BOOTM_STATE_OS_CMDLINE, &bmi); + ret = boot_fn(BOOTM_STATE_OS_CMDLINE, bmi); if (!ret && (states & BOOTM_STATE_OS_BD_T)) - ret = boot_fn(BOOTM_STATE_OS_BD_T, &bmi); + ret = boot_fn(BOOTM_STATE_OS_BD_T, bmi); if (!ret && (states & BOOTM_STATE_OS_PREP)) { ret = bootm_process_cmdline_env(images->os.os == IH_OS_LINUX); if (ret) { @@ -1089,7 +1084,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, &bmi); + ret = boot_fn(BOOTM_STATE_OS_PREP, bmi); }
#ifdef CONFIG_TRACE @@ -1097,10 +1092,10 @@ 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(bmi->argc, bmi->argv, + 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
@@ -1112,8 +1107,8 @@ 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(bmi->argc, bmi->argv, BOOTM_STATE_OS_GO, + images, boot_fn);
/* Deal with any fallout */ err: @@ -1132,19 +1127,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 | @@ -1162,7 +1149,10 @@ 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); + bootm_init(&bmi); + bmi.addr_fit = addr_str; + bmi.cmd_name = "bootm"; + ret = do_bootm_states(&bmi, states);
return ret; } diff --git a/cmd/booti.c b/cmd/booti.c index d3cceb7e0a39..3fa153eb5e54 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 = do_bootm_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,13 +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)) + bootm_init(&bmi); + 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.cmd_name = "booti"; + /* do not set up argc and argv[] since nothing uses them */ + + if (booti_start(&bmi)) return 1;
/* @@ -130,7 +140,8 @@ int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO; if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) states |= BOOTM_STATE_RAMDISK; - ret = do_bootm_states(cmdtp, flag, argc, argv, states, &images, 1); + + ret = do_bootm_states(&bmi, states);
return ret; } diff --git a/cmd/bootm.c b/cmd/bootm.c index 6ded091dd559..42a5cf2fa987 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,21 @@ 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); + bootm_init(&bmi); + if (argc) + bmi.addr_fit = argv[0]; + if (argc > 1) + bmi.conf_ramdisk = argv[1]; + if (argc > 2) + bmi.conf_fdt = argv[2]; + bmi.cmd_name = "bootm"; + bmi.boot_progress = false; + + /* set up argc and argv[] since some OSes use them */ + bmi.argc = argc; + bmi.argv = argv; + + ret = do_bootm_states(&bmi, state);
#if defined(CONFIG_CMD_BOOTM_PRE_LOAD) if (!ret && (state & BOOTM_STATE_PRE_LOAD)) @@ -120,6 +135,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 +167,20 @@ 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); + + bootm_init(&bmi); + if (argc) + bmi.addr_fit = argv[0]; + if (argc > 1) + bmi.conf_ramdisk = argv[1]; + if (argc > 2) + bmi.conf_fdt = argv[2]; + + /* set up argc and argv[] since some OSes use them */ + bmi.argc = argc; + bmi.argv = argv; + + ret = do_bootm_states(&bmi, states);
return ret ? CMD_RET_FAILURE : 0; } diff --git a/cmd/bootz.c b/cmd/bootz.c index 8c25905598a8..9aa07b682d1c 100644 --- a/cmd/bootz.c +++ b/cmd/bootz.c @@ -27,11 +27,20 @@ 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;
- ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START, - images, 1); + bootm_init(&bmi); + if (argc) + bmi.addr_fit = argv[0]; + if (argc > 1) + bmi.conf_ramdisk = argv[1]; + if (argc > 2) + bmi.conf_fdt = argv[2]; + /* do not set up argc and argv[] since nothing uses them */ + + ret = do_bootm_states(&bmi, BOOTM_STATE_START);
/* Setup Linux kernel zImage entry point */ if (!argc) { @@ -64,6 +73,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;
/* Consume 'bootz' */ @@ -80,12 +90,21 @@ int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
images.os.os = IH_OS_LINUX;
+ bootm_init(&bmi); + if (argc) + bmi.addr_fit = argv[0]; + if (argc > 1) + bmi.conf_ramdisk = argv[1]; + if (argc > 2) + bmi.conf_fdt = argv[2]; + 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 = do_bootm_states(cmdtp, flag, argc, argv, states, &images, 1); + ret = do_bootm_states(&bmi, states);
return ret; } diff --git a/include/bootm.h b/include/bootm.h index 950ce5181f1d..1f83c160767f 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -132,33 +132,24 @@ int bootm_find_images(ulong img_addr, const char *conf_ramdisk, int bootm_measure(struct bootm_headers *images);
/** - * 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. + * do_bootm_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 and consumes the command line args. + * 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 we store the return value of in 'ret' may use a negative return + * 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. * - * @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 + * @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 do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, - char *const argv[], int states, struct bootm_headers *images, - int boot_progress); +int do_bootm_states(struct bootm_info *bmi, int states);
void arch_preboot_os(void);

On Thu, Dec 14, 2023 at 09:50:23AM -0700, Simon Glass wrote:
Use the bootm_info struct to hold the information required by bootm.
Now that none of the functions called from do_bootm_states() needs an argv[] list, change the arguments of do_bootm_states() as well. Take care to use the same value for boot_progress even though it is a little inconsistent.
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.
With bootm, some OSes need access to the arguments provided to the command, so set these up in the bootm_info struct, for bootm only.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

Rename the function to bootm_run_states() to better indicate ts purpose. The 'do_' prefix is used to indicate a command processor, which this is now not.
Signed-off-by: Simon Glass sjg@chromium.org ---
Changes in v2: - Split do_bootm_states() rename to a separate patch
arch/mips/lib/bootm.c | 2 +- boot/bootm.c | 4 ++-- cmd/booti.c | 4 ++-- cmd/bootm.c | 4 ++-- cmd/bootz.c | 4 ++-- include/bootm.h | 4 ++-- 6 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/arch/mips/lib/bootm.c b/arch/mips/lib/bootm.c index 286dbd5c4581..adb6b6cc229e 100644 --- a/arch/mips/lib/bootm.c +++ b/arch/mips/lib/bootm.c @@ -217,7 +217,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 7156149dfae9..bd208c0493ca 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -990,7 +990,7 @@ unmap_image: return ret; }
-int do_bootm_states(struct bootm_info *bmi, int states) +int bootm_run_states(struct bootm_info *bmi, int states) { struct bootm_headers *images = bmi->images; boot_os_fn *boot_fn; @@ -1152,7 +1152,7 @@ int bootm_boot_start(ulong addr, const char *cmdline) bootm_init(&bmi); bmi.addr_fit = addr_str; bmi.cmd_name = "bootm"; - ret = do_bootm_states(&bmi, states); + ret = bootm_run_states(&bmi, states);
return ret; } diff --git a/cmd/booti.c b/cmd/booti.c index 3fa153eb5e54..55f7ba67611f 100644 --- a/cmd/booti.c +++ b/cmd/booti.c @@ -34,7 +34,7 @@ static int booti_start(struct bootm_info *bmi) unsigned long decomp_len; int ctype;
- ret = do_bootm_states(bmi, BOOTM_STATE_START); + ret = bootm_run_states(bmi, BOOTM_STATE_START);
/* Setup Linux kernel Image entry point */ if (!bmi->addr_fit) { @@ -141,7 +141,7 @@ int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) states |= BOOTM_STATE_RAMDISK;
- ret = do_bootm_states(&bmi, states); + ret = bootm_run_states(&bmi, states);
return ret; } diff --git a/cmd/bootm.c b/cmd/bootm.c index 42a5cf2fa987..4060800cb3b3 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -118,7 +118,7 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc, bmi.argc = argc; bmi.argv = argv;
- ret = do_bootm_states(&bmi, state); + ret = bootm_run_states(&bmi, state);
#if defined(CONFIG_CMD_BOOTM_PRE_LOAD) if (!ret && (state & BOOTM_STATE_PRE_LOAD)) @@ -180,7 +180,7 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) bmi.argc = argc; bmi.argv = argv;
- ret = do_bootm_states(&bmi, states); + ret = bootm_run_states(&bmi, states);
return ret ? CMD_RET_FAILURE : 0; } diff --git a/cmd/bootz.c b/cmd/bootz.c index 9aa07b682d1c..aa8339318413 100644 --- a/cmd/bootz.c +++ b/cmd/bootz.c @@ -40,7 +40,7 @@ static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc, bmi.conf_fdt = argv[2]; /* do not set up argc and argv[] since nothing uses them */
- ret = do_bootm_states(&bmi, BOOTM_STATE_START); + ret = bootm_run_states(&bmi, BOOTM_STATE_START);
/* Setup Linux kernel zImage entry point */ if (!argc) { @@ -104,7 +104,7 @@ int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) states |= BOOTM_STATE_RAMDISK;
- ret = do_bootm_states(&bmi, states); + ret = bootm_run_states(&bmi, states);
return ret; } diff --git a/include/bootm.h b/include/bootm.h index 1f83c160767f..45109f96695d 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -132,7 +132,7 @@ int bootm_find_images(ulong img_addr, const char *conf_ramdisk, int bootm_measure(struct bootm_headers *images);
/** - * do_bootm_states() - Execute selected states of the bootm command. + * 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 @@ -149,7 +149,7 @@ int bootm_measure(struct bootm_headers *images); * 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 bootm_info *bmi, int states); +int bootm_run_states(struct bootm_info *bmi, int states);
void arch_preboot_os(void);

On Thu, Dec 14, 2023 at 09:50:24AM -0700, Simon Glass wrote:
Rename the function to bootm_run_states() to better indicate ts purpose. The 'do_' prefix is used to indicate a command processor, which this is now not.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

Use struct bootm_info with this function, to avoiding needing to create a new one.
Signed-off-by: Simon Glass sjg@chromium.org ---
(no changes since v1)
boot/bootm.c | 6 ++---- boot/bootm_os.c | 11 +++-------- include/bootm.h | 3 +-- 3 files changed, 6 insertions(+), 14 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index bd208c0493ca..f9f0c9782e42 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1092,8 +1092,7 @@ int bootm_run_states(struct bootm_info *bmi, int states) if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) { char *cmd_list = env_get("fakegocmd");
- ret = boot_selected_os(bmi->argc, bmi->argv, - BOOTM_STATE_OS_FAKE_GO, images, boot_fn); + ret = boot_selected_os(BOOTM_STATE_OS_FAKE_GO, bmi, boot_fn); if (!ret && cmd_list) ret = run_command_list(cmd_list, -1, 0); } @@ -1107,8 +1106,7 @@ int bootm_run_states(struct bootm_info *bmi, int states)
/* Now run the OS! We hope this doesn't return */ if (!ret && (states & BOOTM_STATE_OS_GO)) - ret = boot_selected_os(bmi->argc, bmi->argv, BOOTM_STATE_OS_GO, - images, boot_fn); + ret = boot_selected_os(BOOTM_STATE_OS_GO, bmi, boot_fn);
/* Deal with any fallout */ err: diff --git a/boot/bootm_os.c b/boot/bootm_os.c index 4f547b1b1148..47a5fd78fb6a 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -566,20 +566,15 @@ __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_info *bmi, boot_os_fn *boot_fn) { - struct bootm_info bmi; arch_preboot_os(); board_preboot_os();
- bmi.argc = argc; - bmi.argv = argv; - bmi.images = images; - boot_fn(state, &bmi); + boot_fn(state, bmi);
/* Stand-alone may return when 'autostart' is 'no' */ - if (images->os.type == IH_TYPE_STANDALONE || + if (bmi->images->os.type == IH_TYPE_STANDALONE || IS_ENABLED(CONFIG_SANDBOX) || state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */ return 0; diff --git a/include/bootm.h b/include/bootm.h index 45109f96695d..d0749dc5257a 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -91,8 +91,7 @@ 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 state, struct bootm_info *bmi, boot_os_fn *boot_fn);
ulong bootm_disable_interrupts(void);

On Thu, Dec 14, 2023 at 09:50:25AM -0700, Simon Glass wrote:
Use struct bootm_info with this function, to avoiding needing to create a new one.
Signed-off-by: Simon Glass sjg@chromium.org
Reviewed-by: Tom Rini trini@konsulko.com

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 ---
(no changes since v1)
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 f9f0c9782e42..bd1022ada590 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 4060800cb3b3..a193eb8913e7 100644 --- a/cmd/bootm.c +++ b/cmd/bootm.c @@ -136,7 +136,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 */ @@ -157,17 +156,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; - bootm_init(&bmi); if (argc) bmi.addr_fit = argv[0]; @@ -180,7 +168,7 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) bmi.argc = argc; bmi.argv = argv;
- 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 d0749dc5257a..871a44ab05c2 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -150,6 +150,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);
/*

On Thu, Dec 14, 2023 at 09:50:26AM -0700, Simon Glass wrote:
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
[snip]
+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);
+}
Looking at this, and then boot[zi]_run, I think we should either always set BOOTM_STATE_MEASURE (it's a nop without CONFIG_MEASURED_BOOT) or always IS_ENABLED check it before setting. I think we both would prefer the former? And I really do wonder how much it would hurt or not to just have boot_run() or something which takes the name as a param and handles the few "bootm"-only flags.

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 ---
(no changes since v1)
.../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);

Hi,
On 12/14/23 17:50, Simon Glass wrote:
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
(no changes since v1)
.../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 *bootm_argv[5] = {char *fdt_arg, *initrd_arg;
"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");
elsefdt_arg = env_get("fdtcontroladdr");
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);
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks Patrick

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 ---
(no changes since v1)
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 bd1022ada590..1c5a99817a82 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 aa8339318413..0d771a786a71 100644 --- a/cmd/bootz.c +++ b/cmd/bootz.c @@ -74,7 +74,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++; @@ -99,12 +99,7 @@ int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) bmi.conf_fdt = argv[2]; 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 871a44ab05c2..4665c7a24fa5 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -163,6 +163,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 ---
(no changes since v1)
.../cmd_stm32prog/cmd_stm32prog.c | 20 ++++++++++--------- 1 file changed, 11 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..3ed393b7199f 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,18 @@ 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); + + bootm_init(&bmi); + bmi.addr_fit = boot_addr_start; + bmi.conf_ramdisk = initrd_arg; + bmi.conf_fdt = 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); + 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);

Hi,
On 12/14/23 17:50, Simon Glass wrote:
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
(no changes since v1)
.../cmd_stm32prog/cmd_stm32prog.c | 20 ++++++++++--------- 1 file changed, 11 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..3ed393b7199f 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 = "-";
if (initrd) { snprintf(initrd_addr, sizeof(initrd_addr) - 1, "0x%p:0x%zx", initrd, data->initrd_size);initrd_arg = NULL;
@@ -149,15 +148,18 @@ 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);
bootm_init(&bmi);
bmi.addr_fit = boot_addr_start;
bmi.conf_ramdisk = initrd_arg;
bmi.conf_fdt = 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);
else if (IS_ENABLED(CONFIG_CMD_BOOTZ))bootm_run(&bmi);
do_bootz(cmdtp, 0, 4, bootm_argv);
} if (data->script) cmd_source_script(data->script, NULL, NULL);bootz_run(&bmi);
Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com
Thanks Patrick

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 ---
Changes in v2: - Rework series to allow OS access to cmdline arguments for bootm
boot/bootm.c | 13 +++++++++++++ include/bootm.h | 13 +++++++++++++ 2 files changed, 26 insertions(+)
diff --git a/boot/bootm.c b/boot/bootm.c index 1c5a99817a82..248341c927d9 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 4665c7a24fa5..2245503eb0ea 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -176,6 +176,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);
/*
participants (5)
-
Chanho Park
-
Mattijs Korpershoek
-
Patrick DELAUNAY
-
Simon Glass
-
Tom Rini