Complete decoupling of bootm logic from commands
Subsystems (13)
v2 cover 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(-)
Signature · 1 line
2.43.0.472.g3155946c3a-goog
PATCH v2 1/21 mips: 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.
---
(no changes since v1)
arch/mips/cpu/cpu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/mips/cpu/cpu.c +7 -1
@@ -4,6 +4,7 @@* Wolfgang Denk, DENX Software Engineering, <[email protected]> */ +#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 ; }
Signature · 1 line
2.43.0.472.g3155946c3a-goog
PATCH v2 2/21 m68k: Add a reset_cpu() function
In reply to Simon GlassThe 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.
---
(no changes since v1)
arch/m68k/lib/traps.c | 7 +++++++ 1 file changed, 7 insertions(+)
arch/m68k/lib/traps.c +7 -0
@@ -7,6 +7,7 @@* Wolfgang Denk, DENX Software Engineering, [email protected]. */ +#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 ); +}
Signature · 1 line
2.43.0.472.g3155946c3a-goog
PATCH v2 3/21 ppc: Add a reset_cpu() function
In reply to Simon GlassThe 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.
---
(no changes since v1)
arch/powerpc/lib/traps.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/powerpc/lib/traps.c +10 -0
@@ -4,6 +4,8 @@* Wolfgang Denk, DENX Software Engineering, [email protected]. */ +#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
Signature · 1 line
2.43.0.472.g3155946c3a-goog
PATCH v2 4/21 nios2: Add a reset_cpu() function
In reply to Simon GlassThe current do_reset() is called from a command context. Add a function which can be used from anywhere, as is done on ARM.
---
(no changes since v1)
arch/nios2/cpu/cpu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/nios2/cpu/cpu.c +7 -1
@@ -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 ; }
Signature · 1 line
2.43.0.472.g3155946c3a-goog
PATCH v2 5/21 riscv: Add a reset_cpu() function
In reply to Simon GlassThe 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.
---
(no changes since v1)
arch/riscv/cpu/cpu.c | 13 +++++++++++++ arch/riscv/lib/reset.c | 7 ++----- 2 files changed, 15 insertions(+), 5 deletions(-)
arch/riscv/cpu/cpu.c +13 -0
@@ -3,10 +3,13 @@* Copyright (C) 2018, Bin Meng <[email protected]> */ +#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
arch/riscv/lib/reset.c +2 -5
@@ -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 ; }
Signature · 1 line
2.43.0.472.g3155946c3a-goog
RE: [PATCH v2 05/21] riscv: Add a reset_cpu() function
Quoted 6 lines
-----Original Message-----
From: Simon Glass <[email protected]>
Sent: Friday, December 15, 2023 1:50 AM
To: U-Boot Mailing List <[email protected]>
Cc: Tom Rini <[email protected]>; Simon Glass <[email protected]>; Chanho Park <[email protected]>; Heinrich Schuchardt
Quoted 4 lines
Leo <[email protected]>; Nikita Shubin <[email protected]>; Rick Chen <[email protected]>
Subject: [PATCH v2 05/21] riscv: Add areset_cpu()function
Quoted 8 lines
The current
do_reset()is called from a command context. Add a function which can be used from anywhere, as is done on ARM. Adjustdo_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 <[email protected]>
Quoted 64 lines
---
(no changes since v1)
arch/riscv/cpu/cpu.c | 13 +++++++++++++ arch/riscv/lib/reset.c | 7 ++----- 2 files changed, 15 insertions(+), 5 deletions(-)arch/riscv/cpu/cpu.c +13
-0@@ -3,10 +3,13 @@* Copyright (C) 2018, Bin Meng <[email protected]> */ +#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 arch/riscv/lib/reset.c +2
-5@@ -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
PATCH v2 6/21 bootm: Adjust how the board is reset
In reply to Simon GlassUse 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.
---
(no changes since v1)
boot/bootm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
boot/bootm.c +5 -3
@@ -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; }
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 06/21] bootm: Adjust how the board is reset
Hi Simon,
Thank you for your patch.
Quoted 6 lines · Simon Glass
Use
reset_cpu()to reset the board, copying the logic from the 'reset' command. This makes more sense than directly calling thedo_reset()function with the arguments passsed to the bootm command.Signed-off-by Simon Glass <[email protected]>Reviewed-by Tom Rini <[email protected]>
Quoted 29 lines
---
(no changes since v1)
boot/bootm.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)boot/bootm.c +5
-3@@ -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; }Signature · 1 line
2.43.0.472.g3155946c3a-goog
PATCH v2 7/21 sandbox: bootm: Enable more bootm OS methods
In reply to Simon GlassIt 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.
---
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(-)
arch/sandbox/cpu/cpu.c +8 -0
@@ -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 ;
configs/sandbox_defconfig +2 -1
@@ -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
Signature · 1 line
2.43.0.472.g3155946c3a-goog
PATCH v2 8/21 bootm: Create a struct for argument information
In reply to Simon GlassSome 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.
---
Changes in v2:
- Split addition of struct bootm_info to its own patch
include/bootm.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
include/bootm.h +15 -1
@@ -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);
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 08/21] bootm: Create a struct for argument information
Quoted 16 lines · Simon Glass
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 <[email protected]>
[snip]
include/bootm.h typedef int boot_os_fn(int flag, int argc, char *const argv[], · line 56
Quoted 6 lines
include/bootm.h +1
-1@@ -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.
Signature · 1 line
Tom
PATCH v2 9/21 bootm: Adjust arguments of boot_os_fn
In reply to Simon GlassAdjust 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.
---
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(-)
arch/arc/lib/bootm.c +4 -1
@@ -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 ;
arch/arm/lib/bootm.c +4 -2
@@ -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 ;
arch/m68k/lib/bootm.c +3 -2
@@ -4,6 +4,7 @@* Wolfgang Denk, DENX Software Engineering, [email protected]. */ +#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 );
arch/microblaze/lib/bootm.c +4 -2
@@ -7,6 +7,7 @@* Yasushi SHOJI <[email protected]> */ +#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' */
arch/mips/lib/bootm.c +4 -2
@@ -4,6 +4,7 @@* Wolfgang Denk, DENX Software Engineering, [email protected]. */ +#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 ;
arch/nios2/lib/bootm.c +6 -4
@@ -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;
arch/powerpc/lib/bootm.c +3 -2
@@ -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 ) {
arch/riscv/lib/bootm.c +6 -5
@@ -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 )
arch/sandbox/lib/bootm.c +4 -1
@@ -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);
arch/sh/lib/bootm.c +4 -2
@@ -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 */
arch/x86/lib/bootm.c +4 -2
@@ -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 ;
arch/xtensa/lib/bootm.c +3 -1
@@ -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" );
boot/bootm.c +8 -3
@@ -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
boot/bootm_os.c +41 -36
208 lines not on this page · raw message
include/bootm.h +2 -7
@@ -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;
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 09/21] bootm: Adjust arguments of boot_os_fn
Quoted 6 lines · Simon Glass
Adjust
boot_os_fnto use structbootm_infoinstead 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 <[email protected]>
Signature · 1 line
Tom
PATCH v2 10/21 bootm: Add more fields to bootm_info
In reply to Simon GlassAdd fields for the three bootm parameters and other things needed for booting. Also add a helper to set up the struct correctly.
---
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(+)
boot/bootm.c +8 -0
@@ -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 *
include/bootm.h +35 -0
@@ -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'
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 10/21] bootm: Add more fields to bootm_info
Quoted 4 lines · Simon Glass
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 <[email protected]>
[snip]
include/bootm.h struct cmd_tbl; · line 25
Quoted 12 lines
include/bootm.h +4
-0@@ -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.
Signature · 1 line
Tom
PATCH v2 11/21 bootm: Move do_bootm_states() comment to header file
In reply to Simon GlassThis is an exported function, so move the function comment to the bootm.h header file.
---
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(-)
boot/bootm.c +0 -25
@@ -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)
include/bootm.h +25 -0
@@ -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);
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 11/21] bootm: Move do_bootm_states() comment to header file
Quoted 4 lines · Simon Glass
This is an exported function, so move the function comment to the
bootm.hheader file.Signed-off-by Simon Glass <[email protected]>
Signature · 1 line
Tom
Re: [PATCH v2 11/21] bootm: Move do_bootm_states() comment to header file
In reply to Simon GlassHi Simon,
Thank you for the patch.
Quoted 4 lines · Simon Glass
This is an exported function, so move the function comment to the
bootm.hheader file.Signed-off-by Simon Glass <[email protected]>
Quoted 83 lines
---
Changes in v2:
- Split out patch to movedo_bootm_states()comment to headerboot/bootm.c | 25 ------------------------- include/bootm.h | 25 +++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 25 deletions(-)boot/bootm.c +0
-25@@ -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)include/bootm.h +25
-0@@ -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);Signature · 1 line
2.43.0.472.g3155946c3a-goog
PATCH v2 12/21 booti: Avoid use of #ifdef
In reply to Simon GlassUse the compiler to get the set of states, instead of the preprocessor.
---
Changes in v2:
- Split out booti removal of #ifdef
cmd/booti.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-)
cmd/booti.c +11 -13
@@ -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; }
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 12/21] booti: Avoid use of #ifdef
Quoted 3 lines · Simon Glass
Use the compiler to get the set of states, instead of the preprocessor.
Signed-off-by Simon Glass <[email protected]>
Signature · 1 line
Tom
PATCH v2 13/21 bootz: Avoid use of #ifdef
In reply to Simon GlassUse the compiler to get the set of states, instead of the preprocessor.
---
Changes in v2:
- Split out bootz removal of #ifdef
cmd/bootz.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
cmd/bootz.c +8 -9
@@ -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; }
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 13/21] bootz: Avoid use of #ifdef
Quoted 3 lines · Simon Glass
Use the compiler to get the set of states, instead of the preprocessor.
Signed-off-by Simon Glass <[email protected]>
Signature · 1 line
Tom
PATCH v2 14/21 bootm: Drop arguments from do_bootm_states()
In reply to Simon GlassUse 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.
---
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(-)
boot/bootm.c +21 -31
@@ -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([email protected]): 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; }
cmd/booti.c +22 -11
@@ -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; }
cmd/bootm.c +31 -2
@@ -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 ; }
cmd/bootz.c +23 -4
@@ -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; }
include/bootm.h +8 -17
@@ -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 );
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 14/21] bootm: Drop arguments from do_bootm_states()
Quoted 7 lines · Simon Glass
Use the
bootm_infostruct 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 ofdo_bootm_states()as well. Take care to use the same value forboot_progresseven though it is a little inconsistent.
Quoted 7 lines
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_infostruct, for bootm only.Signed-off-by Simon Glass <[email protected]>
Signature · 1 line
Tom
PATCH v2 15/21 bootm: Rename do_bootm_states() to bootm_run_states()
In reply to Simon GlassRename 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.
---
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(-)
arch/mips/lib/bootm.c +1 -1
@@ -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" );
boot/bootm.c +2 -2
@@ -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; }
cmd/booti.c +2 -2
@@ -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; }
cmd/bootm.c +2 -2
@@ -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 ; }
cmd/bootz.c +2 -2
@@ -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; }
include/bootm.h +2 -2
@@ -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 );
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 15/21] bootm: Rename do_bootm_states() to bootm_run_states()
Quoted 5 lines · Simon Glass
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 <[email protected]>
Signature · 1 line
Tom
PATCH v2 16/21 bootm: Tidy up boot_selected_os()
In reply to Simon GlassUse struct bootm_info with this function, to avoiding needing to create a new one.
---
(no changes since v1)
boot/bootm.c | 6 ++---- boot/bootm_os.c | 11 +++-------- include/bootm.h | 3 +-- 3 files changed, 6 insertions(+), 14 deletions(-)
boot/bootm.c +2 -4
@@ -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:
boot/bootm_os.c +3 -8
@@ -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 ;
include/bootm.h +1 -2
@@ -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 );
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 16/21] bootm: Tidy up boot_selected_os()
Quoted 4 lines · Simon Glass
Use struct
bootm_infowith this function, to avoiding needing to create a new one.Signed-off-by Simon Glass <[email protected]>
Signature · 1 line
Tom
PATCH v2 17/21 bootm: Create a function to run through the bootm states
In reply to Simon GlassIn 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.
---
(no changes since v1)
boot/bootm.c | 19 +++++++++++++++++++ cmd/bootm.c | 14 +------------- include/bootm.h | 13 +++++++++++++ 3 files changed, 33 insertions(+), 13 deletions(-)
boot/bootm.c +19 -0
@@ -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 ];
cmd/bootm.c +1 -13
@@ -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 ; }
include/bootm.h +13 -0
@@ -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 );/*
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 17/21] bootm: Create a function to run through the bootm states
Quoted 5 lines · Simon Glass
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 newbootm_run()function to handle this.Signed-off-by Simon Glass <[email protected]>
[snip]
Quoted 8 lines
boot/bootm.c +8
-0+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 |
boot/bootm.c err: · line 1143
Quoted 10 lines
boot/bootm.c +10
-0+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.
Signature · 1 line
Tom
PATCH v2 18/21 stm32: Use local vars in stm32prog for initrd and fdt
In reply to Simon GlassRather 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.
---
(no changes since v1)
.../cmd_stm32prog/cmd_stm32prog.c | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-)
arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c +14 -9
@@ -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);
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 18/21] stm32: Use local vars in stm32prog for initrd and fdt
Hi,
Quoted 55 lines · Simon Glass
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 <[email protected]>---
(no changes since v1)
.../cmd_stm32prog/cmd_stm32prog.c | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-)arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c +9
-7@@ -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; }
arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc, · line 158
Quoted 10 lines
arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c +5
-2-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);
Thanks
Patrick
PATCH v2 19/21 bootm: Create a function to run through the bootz states
In reply to Simon GlassIn 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.
---
(no changes since v1)
boot/bootm.c | 13 +++++++++++++ cmd/bootz.c | 9 ++------- include/bootm.h | 13 +++++++++++++ 3 files changed, 28 insertions(+), 7 deletions(-)
boot/bootm.c +13 -0
@@ -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 ];
cmd/bootz.c +2 -7
@@ -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; }
include/bootm.h +13 -0
@@ -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 );/*
Signature · 1 line
2.43.0.472.g3155946c3a-goog
PATCH v2 20/21 stm32: Use bootm_run() and bootz_run()
In reply to Simon GlassUse the new bootm/z_run() functions to avoid having to create an argument list for the stm32prog code.
---
(no changes since v1)
.../cmd_stm32prog/cmd_stm32prog.c | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c +11 -9
@@ -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 );
Signature · 1 line
2.43.0.472.g3155946c3a-goog
Re: [PATCH v2 20/21] stm32: Use bootm_run() and bootz_run()
Hi,
Quoted 60 lines · Simon Glass
Use the new bootm/z_run() functions to avoid having to create an argument list for the stm32prog code.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v1)
.../cmd_stm32prog/cmd_stm32prog.c | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c +9
-7@@ -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;
arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc, · line 165
Quoted 10 lines
arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c +2
-2/* 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 );
Thanks
Patrick
PATCH v2 21/21 bootm: Create a function to run through the booti states
In reply to Simon GlassIn 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.
---
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(+)
boot/bootm.c +13 -0
@@ -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 ];
include/bootm.h +13 -0
@@ -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 );/*
Signature · 1 line
2.43.0.472.g3155946c3a-goog