[PATCH v3 00/22] 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 v3: - Rename addr_fit to addr_img in struct bootm_info - Rename addr_fit to addr_img in struct bootm_info - Enable CONFIG_MEASURED_BOOT always and rely on CONFIG_MEASURED_BOOT - Rename addr_fit to addr_img in struct bootm_info - Add new boot_run() function
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 (22): 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 bootm: Create a new boot_run() function to handle booting
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 | 119 ++++++++------- boot/bootm_os.c | 78 +++++----- cmd/booti.c | 55 ++++--- cmd/bootm.c | 43 ++++-- cmd/bootz.c | 35 +++-- configs/sandbox_defconfig | 3 +- include/bootm.h | 142 ++++++++++++++++-- 27 files changed, 444 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 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; }

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; }

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 ---
(no changes since v2)
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 Reviewed-by: Tom Rini trini@konsulko.com ---
(no changes since v2)
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);

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

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 v3: - Rename addr_fit to addr_img in struct bootm_info
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..7cfaa0a7d053 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_img: 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_img; + 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 Fri, Dec 15, 2023 at 08:14:14PM -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
Reviewed-by: Tom Rini trini@konsulko.com

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 Reviewed-by: Tom Rini trini@konsulko.com ---
(no changes since v2)
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 7cfaa0a7d053..81f2514f1b7b 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);

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

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

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 ---
Changes in v3: - Rename addr_fit to addr_img in struct bootm_info
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..be1124f75b54 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_img);
if (!ret && (states & BOOTM_STATE_FINDOS)) - ret = bootm_find_os(cmdtp->name, argv[0]); + ret = bootm_find_os(bmi->cmd_name, bmi->addr_img);
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_img ? hextoul(bmi->addr_img, 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_img = 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..0ab293bb880a 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_img) { 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_img, 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_img = 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..76986c61e7b6 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_img = 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_img = 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..12da9422741d 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_img = 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_img = 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 81f2514f1b7b..8010d2f98113 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);

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 ---
(no changes since v2)
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 be1124f75b54..f009e9ace652 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_img = 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 0ab293bb880a..898df0f8896b 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_img) { @@ -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 76986c61e7b6..26d20b9118d2 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 12da9422741d..05b15eb4d761 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 8010d2f98113..dbf883bb08ad 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);

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 ---
(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 f009e9ace652..66b7e350aa86 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 dbf883bb08ad..628d3d3e83ff 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);

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 ---
Changes in v3: - Enable CONFIG_MEASURED_BOOT always and rely on CONFIG_MEASURED_BOOT
boot/bootm.c | 17 +++++++++++++++++ cmd/bootm.c | 14 +------------- include/bootm.h | 13 +++++++++++++ 3 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 66b7e350aa86..cce8485f2d47 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1123,6 +1123,23 @@ 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 | BOOTM_STATE_MEASURE; + if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) + states |= BOOTM_STATE_RAMDISK; + 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 26d20b9118d2..9737a2d28c03 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_img = 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 628d3d3e83ff..6e6b2ad8f7ef 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 Fri, Dec 15, 2023 at 08:14:21PM -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
Reviewed-by: Tom Rini trini@konsulko.com

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 Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
(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);

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 cce8485f2d47..40751a4c6e6f 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1140,6 +1140,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 05b15eb4d761..b6bb4aae72d4 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 6e6b2ad8f7ef..f7d6d27ecb0a 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);
/*

On Fri, Dec 15, 2023 at 08:14:23PM -0700, Simon Glass wrote:
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
Reviewed-by: Tom Rini trini@konsulko.com

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 Reviewed-by: Patrick Delaunay patrick.delaunay@foss.st.com ---
Changes in v3: - Rename addr_fit to addr_img in struct bootm_info
.../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..adee6e05b636 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_img = 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);

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 ---
(no changes since v2)
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 40751a4c6e6f..53236136f489 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1153,6 +1153,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 f7d6d27ecb0a..eba35b33b4e5 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);
/*

On Fri, Dec 15, 2023 at 08:14:25PM -0700, Simon Glass wrote:
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
Reviewed-by: Tom Rini trini@konsulko.com

Create a common function used by the three existing bootz/i/m_run() functions, to reduce duplicated code.
Signed-off-by: Simon Glass sjg@chromium.org Suggested-by: Tom Rini trini@konsulko.com ---
Changes in v3: - Add new boot_run() function
boot/bootm.c | 40 ++++++++++++++-------------------------- include/bootm.h | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 53236136f489..6a4cebcf7a08 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1123,47 +1123,35 @@ err: return ret; }
-int bootm_run(struct bootm_info *bmi) +int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states) { 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 | BOOTM_STATE_MEASURE; + bmi->cmd_name = cmd; + 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; - if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS)) - states |= BOOTM_STATE_OS_CMDLINE; + states |= extra_states;
return bootm_run_states(bmi, states); }
-int bootz_run(struct bootm_info *bmi) +int bootm_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 boot_run(bmi, "bootm", BOOTM_STATE_START | BOOTM_STATE_FINDOS | + BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER | + BOOTM_STATE_LOADOS); +}
- return bootm_run_states(bmi, states); +int bootz_run(struct bootm_info *bmi) +{ + return boot_run(bmi, "bootz", 0); }
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); + return boot_run(bmi, "booti", 0); }
int bootm_boot_start(ulong addr, const char *cmdline) diff --git a/include/bootm.h b/include/bootm.h index eba35b33b4e5..9e0f8d60de0a 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -150,6 +150,24 @@ int bootm_measure(struct bootm_headers *images); */ int bootm_run_states(struct bootm_info *bmi, int states);
+/** + * boot_run() - Run the entire bootm/booti/bootz process + * + * This runs through the boot process from start to finish, with a base set of + * states, along with the extra ones supplied. + * + * This uses bootm_run_states(). + * + * Note that it is normally easier to use bootm_run(), etc. since they handle + * the extra states correctly. + * + * @bmi: bootm information + * @cmd: command being run, NULL if none + * @extra_states: Mask of extra states to use for the boot + * Return: 0 if ok, something else on error + */ +int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states); + /** * bootm_run() - Run the entire bootm process *

On Fri, Dec 15, 2023 at 08:14:26PM -0700, Simon Glass wrote:
Create a common function used by the three existing bootz/i/m_run() functions, to reduce duplicated code.
Signed-off-by: Simon Glass sjg@chromium.org Suggested-by: Tom Rini trini@konsulko.com
Changes in v3:
- Add new boot_run() function
boot/bootm.c | 40 ++++++++++++++-------------------------- include/bootm.h | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 53236136f489..6a4cebcf7a08 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1123,47 +1123,35 @@ err: return ret; }
-int bootm_run(struct bootm_info *bmi) +int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states) { 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 | BOOTM_STATE_MEASURE;
- bmi->cmd_name = cmd;
- states = BOOTM_STATE_MEASURE | BOOTM_STATE_OS_PREP |
if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) states |= BOOTM_STATE_RAMDISK;BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO;
- if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS))
states |= BOOTM_STATE_OS_CMDLINE;
states |= extra_states;
return bootm_run_states(bmi, states);
}
-int bootz_run(struct bootm_info *bmi) +int bootm_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 boot_run(bmi, "bootm", BOOTM_STATE_START | BOOTM_STATE_FINDOS |
BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER |
BOOTM_STATE_LOADOS);
+}
- return bootm_run_states(bmi, states);
+int bootz_run(struct bootm_info *bmi) +{
- return boot_run(bmi, "bootz", 0);
}
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);
- return boot_run(bmi, "booti", 0);
}
int bootm_boot_start(ulong addr, const char *cmdline) diff --git a/include/bootm.h b/include/bootm.h index eba35b33b4e5..9e0f8d60de0a 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -150,6 +150,24 @@ int bootm_measure(struct bootm_headers *images); */ int bootm_run_states(struct bootm_info *bmi, int states);
+/**
- boot_run() - Run the entire bootm/booti/bootz process
- This runs through the boot process from start to finish, with a base set of
- states, along with the extra ones supplied.
- This uses bootm_run_states().
- Note that it is normally easier to use bootm_run(), etc. since they handle
- the extra states correctly.
- @bmi: bootm information
- @cmd: command being run, NULL if none
- @extra_states: Mask of extra states to use for the boot
- Return: 0 if ok, something else on error
- */
+int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states);
/**
- bootm_run() - Run the entire bootm process
Overall good, thanks. My question is, should we mark the others as static, or is this new helper static and not to be called externally?

Hi Tom,
On Sat, 16 Dec 2023 at 10:12, Tom Rini trini@konsulko.com wrote:
On Fri, Dec 15, 2023 at 08:14:26PM -0700, Simon Glass wrote:
Create a common function used by the three existing bootz/i/m_run() functions, to reduce duplicated code.
Signed-off-by: Simon Glass sjg@chromium.org Suggested-by: Tom Rini trini@konsulko.com
Changes in v3:
- Add new boot_run() function
boot/bootm.c | 40 ++++++++++++++-------------------------- include/bootm.h | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 53236136f489..6a4cebcf7a08 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1123,47 +1123,35 @@ err: return ret; }
-int bootm_run(struct bootm_info *bmi) +int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states) { 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 | BOOTM_STATE_MEASURE;
bmi->cmd_name = cmd;
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;
if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS))
states |= BOOTM_STATE_OS_CMDLINE;
states |= extra_states; return bootm_run_states(bmi, states);
}
-int bootz_run(struct bootm_info *bmi) +int bootm_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 boot_run(bmi, "bootm", BOOTM_STATE_START | BOOTM_STATE_FINDOS |
BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER |
BOOTM_STATE_LOADOS);
+}
return bootm_run_states(bmi, states);
+int bootz_run(struct bootm_info *bmi) +{
return boot_run(bmi, "bootz", 0);
}
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);
return boot_run(bmi, "booti", 0);
}
int bootm_boot_start(ulong addr, const char *cmdline) diff --git a/include/bootm.h b/include/bootm.h index eba35b33b4e5..9e0f8d60de0a 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -150,6 +150,24 @@ int bootm_measure(struct bootm_headers *images); */ int bootm_run_states(struct bootm_info *bmi, int states);
+/**
- boot_run() - Run the entire bootm/booti/bootz process
- This runs through the boot process from start to finish, with a base set of
- states, along with the extra ones supplied.
- This uses bootm_run_states().
- Note that it is normally easier to use bootm_run(), etc. since they handle
- the extra states correctly.
- @bmi: bootm information
- @cmd: command being run, NULL if none
- @extra_states: Mask of extra states to use for the boot
- Return: 0 if ok, something else on error
- */
+int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states);
/**
- bootm_run() - Run the entire bootm process
Overall good, thanks. My question is, should we mark the others as static, or is this new helper static and not to be called externally?
The others are used externally.
For bootm_run() I toyed with the idea of it being static, but then wondered if we might use that programmatically instead of the bootz/i/m(_run) versions. It is quite nice that the differences are now pretty minor between them.
I don't mind either way, though.
Regards, Simon

On Sat, Dec 16, 2023 at 11:45:36AM -0700, Simon Glass wrote:
Hi Tom,
On Sat, 16 Dec 2023 at 10:12, Tom Rini trini@konsulko.com wrote:
On Fri, Dec 15, 2023 at 08:14:26PM -0700, Simon Glass wrote:
Create a common function used by the three existing bootz/i/m_run() functions, to reduce duplicated code.
Signed-off-by: Simon Glass sjg@chromium.org Suggested-by: Tom Rini trini@konsulko.com
Changes in v3:
- Add new boot_run() function
boot/bootm.c | 40 ++++++++++++++-------------------------- include/bootm.h | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+), 26 deletions(-)
diff --git a/boot/bootm.c b/boot/bootm.c index 53236136f489..6a4cebcf7a08 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -1123,47 +1123,35 @@ err: return ret; }
-int bootm_run(struct bootm_info *bmi) +int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states) { 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 | BOOTM_STATE_MEASURE;
bmi->cmd_name = cmd;
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;
if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS))
states |= BOOTM_STATE_OS_CMDLINE;
states |= extra_states; return bootm_run_states(bmi, states);
}
-int bootz_run(struct bootm_info *bmi) +int bootm_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 boot_run(bmi, "bootm", BOOTM_STATE_START | BOOTM_STATE_FINDOS |
BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER |
BOOTM_STATE_LOADOS);
+}
return bootm_run_states(bmi, states);
+int bootz_run(struct bootm_info *bmi) +{
return boot_run(bmi, "bootz", 0);
}
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);
return boot_run(bmi, "booti", 0);
}
int bootm_boot_start(ulong addr, const char *cmdline) diff --git a/include/bootm.h b/include/bootm.h index eba35b33b4e5..9e0f8d60de0a 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -150,6 +150,24 @@ int bootm_measure(struct bootm_headers *images); */ int bootm_run_states(struct bootm_info *bmi, int states);
+/**
- boot_run() - Run the entire bootm/booti/bootz process
- This runs through the boot process from start to finish, with a base set of
- states, along with the extra ones supplied.
- This uses bootm_run_states().
- Note that it is normally easier to use bootm_run(), etc. since they handle
- the extra states correctly.
- @bmi: bootm information
- @cmd: command being run, NULL if none
- @extra_states: Mask of extra states to use for the boot
- Return: 0 if ok, something else on error
- */
+int boot_run(struct bootm_info *bmi, const char *cmd, int extra_states);
/**
- bootm_run() - Run the entire bootm process
Overall good, thanks. My question is, should we mark the others as static, or is this new helper static and not to be called externally?
The others are used externally.
For bootm_run() I toyed with the idea of it being static, but then wondered if we might use that programmatically instead of the bootz/i/m(_run) versions. It is quite nice that the differences are now pretty minor between them.
I don't mind either way, though.
OK, lets put it on the TODO list for once the CMDLINE=n case is fully flushed out and code otherwise cleaned up and organized, it'll perhaps be clearer then if the answer is old functions, new function or neither function.
Reviewed-by: Tom Rini trini@konsulko.com

On Fri, 15 Dec 2023 20:14:04 -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.
[...]
Applied to u-boot/next, thanks!
participants (2)
-
Simon Glass
-
Tom Rini