Skip to contentSkip to conversation

Complete decoupling of bootm logic from commands

PATCH Superseded Simon Glass 5 participants 32 messages Dec 4, 2023 – Dec 11, 2023

Subsystems (13)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

Simon Glass (18):
bootm: netbds: Drop passing of arguments
bootm: plan: Drop passing of arguments
bootm: qnxelf: Drop passing of arguments
nios2: Drop separate parsing of bootm args
treewide: bootm: Drop command-line args to boot_os_fn
bootm: Drop arguments from boot_selected_os()
mips: Add a reset_cpu() function
m68k: Add a reset_cpu() function
ppc: Add a reset_cpu() function
nios2: Add a reset_cpu() function
riscv: Add a reset_cpu() function
bootm: Adjust how the board is reset
bootm: Drop arguments from do_bootm_states() and rename
bootm: Create a function to run through the bootm states
stm32: Use local vars in stm32prog for initrd and fdt
bootm: Create a function to run through the bootz states
stm32: Use bootm_run() and bootz_run()
bootm: Create a function to run through the booti states

 arch/arc/lib/bootm.c                          |   2 +-
 arch/arm/lib/bootm.c                          |   3 +-
 .../cmd_stm32prog/cmd_stm32prog.c             |  35 +++--
 arch/m68k/lib/bootm.c                         |   3 +-
 arch/m68k/lib/traps.c                         |   7 +
 arch/microblaze/lib/bootm.c                   |   3 +-
 arch/mips/cpu/cpu.c                           |   8 +-
 arch/mips/lib/bootm.c                         |   5 +-
 arch/nios2/cpu/cpu.c                          |   8 +-
 arch/nios2/lib/bootm.c                        |   5 +-
 arch/powerpc/lib/bootm.c                      |   3 +-
 arch/powerpc/lib/traps.c                      |  10 ++
 arch/riscv/cpu/cpu.c                          |  13 ++
 arch/riscv/lib/bootm.c                        |   5 +-
 arch/riscv/lib/reset.c                        |   7 +-
 arch/sandbox/lib/bootm.c                      |   2 +-
 arch/sh/lib/bootm.c                           |   3 +-
 arch/x86/lib/bootm.c                          |   3 +-
 arch/xtensa/lib/bootm.c                       |   2 +-
 boot/bootm.c                                  | 125 ++++++++++--------
 boot/bootm_os.c                               | 101 +++++---------
 cmd/booti.c                                   |  55 ++++----
 cmd/bootm.c                                   |  36 +++--
 cmd/bootz.c                                   |  38 ++++--
 include/bootm.h                               | 107 +++++++++++++--
 25 files changed, 362 insertions(+), 227 deletions(-)
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#1 lore raw

PATCH 1/18 bootm: netbds: Drop passing of arguments

It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the three arguments at the end are passed to the OS. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.

Rely instead on the "bootargs" mechanism, which is the standard approach.

---

 boot/bootm_os.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
boot/bootm_os.c +3 -13
index b92422171a84..b5055d78706c 100644
@@ -102,19 +102,9 @@ static int do_bootm_netbsd(int flag, int argc, char *const argv[],
 			os_hdr = hdr;
 	}
 
-	if (argc > 0) {
-		ulong len;
-		int   i;
-
-		for (i = 0, len = 0; i < argc; i += 1)
-			len += strlen(argv[i]) + 1;
-		cmdline = malloc(len);
-		copy_args(cmdline, argc, argv, ' ');
-	} else {
-		cmdline = env_get("bootargs");
-		if (cmdline == NULL)
-			cmdline = "";
-	}
+	cmdline = env_get("bootargs");
+	if (!cmdline)
+		cmdline = "";
 
 	loader = (void (*)(struct bd_info *, struct legacy_img_hdr *, char *, char *))images->ep;
 
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#2 lore raw

Re: [PATCH 01/18] bootm: netbds: Drop passing of arguments

Quoted 2 lines

From: Simon Glass <[email protected]>
Date: Sun, 3 Dec 2023 17:26:17 -0700

Hi Simon,

There is a typo in first line of the commit message: s/netbds/netbsd/.

Quoted 7 lines

It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the three arguments at the end are passed to the OS. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.

Rely instead on the "bootargs" mechanism, which is the standard approach.

It is a very Linuxy approach though.

I suspect this feature was added to pass kernel arguments for "one-off" boots. For example

bootm -s

could be used to boot NetBSD in single-user mode and is quite a bit more convenient than:

setenv bootargs -s
bootm

That said, I'm not sure to what extent the bootm command is used to boot NetBSD these days. So this may not really matter.

Cheers,

Mark

Quoted 37 lines

---

 boot/bootm_os.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
boot/bootm_os.c +3 -13
index b92422171a84..b5055d78706c 100644
@@ -102,19 +102,9 @@ static int do_bootm_netbsd(int flag, int argc, char *const argv[],
 			os_hdr = hdr;
 	}
 
-	if (argc > 0) {
-		ulong len;
-		int   i;
-
-		for (i = 0, len = 0; i < argc; i += 1)
-			len += strlen(argv[i]) + 1;
-		cmdline = malloc(len);
-		copy_args(cmdline, argc, argv, ' ');
-	} else {
-		cmdline = env_get("bootargs");
-		if (cmdline == NULL)
-			cmdline = "";
-	}
+	cmdline = env_get("bootargs");
+	if (!cmdline)
+		cmdline = "";
 
 	loader = (void (*)(struct bd_info *, struct legacy_img_hdr *, char *, char *))images->ep;
 
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#3 lore raw

Re: [PATCH 01/18] bootm: netbds: Drop passing of arguments

Quoted 2 lines · Mark Kettenis

That said, I'm not sure to what extent the bootm command is used to boot NetBSD these days. So this may not really matter.

It is used on most 32bit ARM platforms.

Martin

#4 lore raw

Re: [PATCH 01/18] bootm: netbds: Drop passing of arguments

In reply to Mark Kettenis

Hi,

I am replying to this email since it still has the context below.

Quoted 16 lines · Mark Kettenis
Quoted 3 lines

From: Simon Glass <[email protected]>
Date: Sun, 3 Dec 2023 17:26:17 -0700

Hi Simon,

There is a typo in first line of the commit message: s/netbds/netbsd/.

Quoted 7 lines

It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the three arguments at the end are passed to the OS. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.

Rely instead on the "bootargs" mechanism, which is the standard approach.

Quoted 6 lines

It is a very Linuxy approach though.

I suspect this feature was added to pass kernel arguments for "one-off" boots. For example

bootm -s

Martin says that this is used with NetBSD. So do we rely on U-Boot parsing the '-s' as 0 and then using loadaddr as the default?

I wonder if we could come up with another mechanism? Perhaps 'bootm -- args go here' ? Or define that if the first arg starts with '-' then the args are not parsed?

Martin, would it be possible to send a patch to doc/ describing how to boot NetBSD?

Quoted 51 lines

could be used to boot NetBSD in single-user mode and is quite a bit more convenient than:

setenv bootargs -s
bootm

That said, I'm not sure to what extent the bootm command is used to boot NetBSD these days. So this may not really matter.

Cheers,

Mark

Quoted 37 lines

---

 boot/bootm_os.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
boot/bootm_os.c +3 -14
index b92422171a84..b5055d78706c 100644
@@ -102,19 +102,9 @@ static int do_bootm_netbsd(int flag, int argc, char *const argv[],
                      os_hdr = hdr;
      }
 
-     if (argc > 0) {
-             ulong len;
-             int   i;
-
-             for (i = 0, len = 0; i < argc; i += 1)
-                     len += strlen(argv[i]) + 1;
-             cmdline = malloc(len);
-             copy_args(cmdline, argc, argv, ' ');
-     } else {
-             cmdline = env_get("bootargs");
-             if (cmdline == NULL)
-                     cmdline = "";
-     }
+     cmdline = env_get("bootargs");
+     if (!cmdline)
+             cmdline = "";
 
      loader = (void (*)(struct bd_info *, struct legacy_img_hdr *, char *, char *))images->ep;
 
--

2.43.0.rc2.451.g8631bc7472-goog

#5 lore raw

Re: [PATCH 01/18] bootm: netbds: Drop passing of arguments

Quoted 31 lines · Simon Glass

Hi,

I am replying to this email since it still has the context below.

Quoted 16 lines · Mark Kettenis
Quoted 3 lines

From: Simon Glass <[email protected]>
Date: Sun, 3 Dec 2023 17:26:17 -0700

Hi Simon,

There is a typo in first line of the commit message: s/netbds/netbsd/.

Quoted 7 lines

It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the three arguments at the end are passed to the OS. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.

Rely instead on the "bootargs" mechanism, which is the standard approach.

Quoted 6 lines

It is a very Linuxy approach though.

I suspect this feature was added to pass kernel arguments for "one-off" boots. For example

bootm -s

Martin says that this is used with NetBSD. So do we rely on U-Boot parsing the '-s' as 0 and then using loadaddr as the default?

Quoted 6 lines

I wonder if we could come up with another mechanism? Perhaps 'bootm -- args go here' ? Or define that if the first arg starts with '-' then the args are not parsed?

Martin, would it be possible to send a patch to doc/ describing how to boot NetBSD?

A patch describing how booting is done today, especially including some of the potentially less common but still valid usages would be much appreciated. We can go from there to decide what changes if any to make to what's exposed to the user in this case as I am loathe to change things like this which amount of an ABI.

Signature · 1 line
Tom
#6 lore raw

PATCH 2/18 bootm: plan: Drop passing of arguments

In reply to Simon Glass

It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the three arguments at the end are passed to the OS. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.

Rely instead on the "bootargs" mechanism, which is the standard approach.

Drop the helper function as well.

---

 boot/bootm_os.c | 26 ++++----------------------
 1 file changed, 4 insertions(+), 22 deletions(-)
boot/bootm_os.c +4 -22
index b5055d78706c..4aa1db848d6c 100644
@@ -41,20 +41,6 @@ static int do_bootm_standalone(int flag, int argc, char *const argv[],
 /* OS booting routines */
 /*******************************************************************/
 
-#if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9)
-static void copy_args(char *dest, int argc, char *const argv[], char delim)
-{
-	int i;
-
-	for (i = 0; i < argc; i++) {
-		if (i > 0)
-			*dest++ = delim;
-		strcpy(dest, argv[i]);
-		dest += strlen(argv[i]);
-	}
-}
-#endif
-
 static void __maybe_unused fit_unsupported_reset(const char *msg)
 {
 	if (CONFIG_IS_ENABLED(FIT_VERBOSE)) {
@@ -211,16 +197,12 @@ static int do_bootm_plan9(int flag, int argc, char *const argv[],
 
 	/* See README.plan9 */
 	s = env_get("confaddr");
-	if (s != NULL) {
+	if (s) {
 		char *confaddr = (char *)hextoul(s, NULL);
 
-		if (argc > 0) {
-			copy_args(confaddr, argc, argv, '\n');
-		} else {
-			s = env_get("bootargs");
-			if (s != NULL)
-				strcpy(confaddr, s);
-		}
+		s = env_get("bootargs");
+		if (!s)
+			strcpy(confaddr, s);
 	}
 
 	entry_point = (void (*)(void))images->ep;
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#7 lore raw

PATCH 3/18 bootm: qnxelf: Drop passing of arguments

In reply to Simon Glass

It isn't clear how useful it is to pass the arguments of bootm to the OS. For example, if "bootm 1000 2000 3000" is used, the '1000' argument is passed to QNX. This seems like a strange approach, since the argument have already been parsed by U-Boot and processed.

Rely instead on the "bootargs" mechanism, which is the standard approach.

Also make sure that the argument list is NULL-terminated.

---

 boot/bootm_os.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
boot/bootm_os.c +5 -4
index 4aa1db848d6c..598671e576c6 100644
@@ -333,7 +333,7 @@ int do_bootm_vxworks(int flag, int argc, char *const argv[],
 static int do_bootm_qnxelf(int flag, int argc, char *const argv[],
 			   struct bootm_headers *images)
 {
-	char *local_args[2];
+	char *local_args[3];
 	char str[16];
 	int dcache;
 
@@ -348,8 +348,9 @@ static int do_bootm_qnxelf(int flag, int argc, char *const argv[],
 #endif
 
 	sprintf(str, "%lx", images->ep); /* write entry-point into string */
-	local_args[0] = argv[0];
-	local_args[1] = str;	/* and provide it via the arguments */
+	local_args[0] = "qnxelf";
+	local_args[1] = env_get("bootargs");
+	local_args[2] = NULL;
 
 	/*
 	 * QNX images require the data cache is disabled.
@@ -358,7 +359,7 @@ static int do_bootm_qnxelf(int flag, int argc, char *const argv[],
 	if (dcache)
 		dcache_disable();
 
-	do_bootelf(NULL, 0, 2, local_args);
+	do_bootelf(NULL, 0, local_args[1] ? 2 : 1, local_args);
 
 	if (dcache)
 		dcache_enable();
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#8 lore raw

PATCH 4/18 nios2: Drop separate parsing of bootm args

In reply to Simon Glass

This function is supposed to boot the OS. Parsing of the arguments is done in easier phases.

The code to handle this is already here, behind an #ifdef on CONFIG_OF_LIBFDT so rely on that.

---

 arch/nios2/lib/bootm.c | 2 --
 1 file changed, 2 deletions(-)
arch/nios2/lib/bootm.c +0 -2
index 06c094d0f1c7..823d524c9a2d 100644
@@ -29,8 +29,6 @@ int do_bootm_linux(int flag, int argc, char *const argv[],
 	if (images->ft_len)
 		of_flat_tree = images->ft_addr;
 #endif
-	if (!of_flat_tree && argc > 1)
-		of_flat_tree = (char *)hextoul(argv[1], NULL);
 	if (of_flat_tree)
 		initrd_end = (ulong)of_flat_tree;
 
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#9 lore raw

PATCH 5/18 treewide: bootm: Drop command-line args to boot_os_fn

In reply to Simon Glass

These arguments are not used now. They cannot be provided when there is no bootm command invoked to provide arguments. Drop the argc and argv parameters.

---

 arch/arc/lib/bootm.c        |  2 +-
 arch/arm/lib/bootm.c        |  3 +--
 arch/m68k/lib/bootm.c       |  3 +--
 arch/microblaze/lib/bootm.c |  3 +--
 arch/mips/lib/bootm.c       |  3 +--
 arch/nios2/lib/bootm.c      |  3 +--
 arch/powerpc/lib/bootm.c    |  3 +--
 arch/riscv/lib/bootm.c      |  5 ++--
 arch/sandbox/lib/bootm.c    |  2 +-
 arch/sh/lib/bootm.c         |  3 +--
 arch/x86/lib/bootm.c        |  3 +--
 arch/xtensa/lib/bootm.c     |  2 +-
 boot/bootm.c                |  6 ++---
 boot/bootm_os.c             | 46 ++++++++++++++-----------------------
 include/bootm.h             |  7 +-----
 15 files changed, 34 insertions(+), 60 deletions(-)
arch/arc/lib/bootm.c +1 -1
index 44ec5864a1c6..0ae7a21b24b6 100644
@@ -78,7 +78,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
 		board_jump_and_run(kernel_entry, r0, 0, r2);
 }
 
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	/* No need for those on ARC */
 	if ((flag & BOOTM_STATE_OS_BD_T) || (flag & BOOTM_STATE_OS_CMDLINE))
arch/arm/lib/bootm.c +1 -2
index c56285738a26..ebaac029e094 100644
@@ -378,8 +378,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
  * DIFFERENCE: Instead of calling prep and go at the end
  * they are called if subcommand is equal 0.
  */
-int do_bootm_linux(int flag, int argc, char *const argv[],
-		   struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	/* No need for those on ARM */
 	if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
arch/m68k/lib/bootm.c +1 -2
index 79d8b34c0d56..0720861ae9cc 100644
@@ -34,8 +34,7 @@ void arch_lmb_reserve(struct lmb *lmb)
 	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 1024);
 }
 
-int do_bootm_linux(int flag, int argc, char *const argv[],
-		   struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	int ret;
 	struct bd_info  *kbd;
arch/microblaze/lib/bootm.c +1 -2
index f3ec4b741b88..93cdf62e18cf 100644
@@ -81,8 +81,7 @@ static void boot_prep_linux(struct bootm_headers *images)
 	}
 }
 
-int do_bootm_linux(int flag, int argc, char *const argv[],
-		   struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	images->cmdline_start = (ulong)env_get("bootargs");
 
arch/mips/lib/bootm.c +1 -2
index d6d2f7d9d031..05dbe6131728 100644
@@ -300,8 +300,7 @@ static void boot_jump_linux(struct bootm_headers *images)
 			linux_extra);
 }
 
-int do_bootm_linux(int flag, int argc, char *const argv[],
-		   struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	/* No need for those on MIPS */
 	if (flag & BOOTM_STATE_OS_BD_T)
arch/nios2/lib/bootm.c +1 -2
index 823d524c9a2d..040a806bc75e 100644
@@ -16,8 +16,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #define NIOS_MAGIC 0x534f494e /* enable command line and initrd passing */
 
-int do_bootm_linux(int flag, int argc, char *const argv[],
-		   struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	void (*kernel)(int, int, int, char *) = (void *)images->ep;
 	char *commandline = env_get("bootargs");
arch/powerpc/lib/bootm.c +1 -2
index 910121ec9c85..4d248cb13b5f 100644
@@ -223,8 +223,7 @@ static int boot_body_linux(struct bootm_headers *images)
 	return 0;
 }
 
-noinline int do_bootm_linux(int flag, int argc, char *const argv[],
-			    struct bootm_headers *images)
+noinline int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	int	ret;
 
arch/riscv/lib/bootm.c +2 -3
index f9e1e18ae026..d90f26091530 100644
@@ -105,8 +105,7 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
 	}
 }
 
-int do_bootm_linux(int flag, int argc, char *const argv[],
-		   struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	/* No need for those on RISC-V */
 	if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
@@ -130,7 +129,7 @@ int do_bootm_linux(int flag, int argc, char *const argv[],
 int do_bootm_vxworks(int flag, int argc, char *const argv[],
 		     struct bootm_headers *images)
 {
-	return do_bootm_linux(flag, argc, argv, images);
+	return do_bootm_linux(flag, images);
 }
 
 static ulong get_sp(void)
arch/sandbox/lib/bootm.c +1 -1
index dc8b8e46cb41..d2b514d3f0ca 100644
@@ -64,7 +64,7 @@ static int boot_prep_linux(struct bootm_headers *images)
 	return 0;
 }
 
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	if (flag & BOOTM_STATE_OS_PREP)
 		return boot_prep_linux(images);
arch/sh/lib/bootm.c +1 -2
index b205e5e3db1b..d0284582ae0e 100644
@@ -39,8 +39,7 @@ static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base)
 	return val;
 }
 
-int do_bootm_linux(int flag, int argc, char *const argv[],
-		   struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	/* Linux kernel load address */
 	void (*kernel) (void) = (void (*)(void))images->ep;
arch/x86/lib/bootm.c +1 -2
index 3196f9ddc2c8..34d5c585a55a 100644
@@ -237,8 +237,7 @@ static int boot_jump_linux(struct bootm_headers *images)
 				 images->os.arch == IH_ARCH_X86_64);
 }
 
-int do_bootm_linux(int flag, int argc, char *const argv[],
-		   struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	/* No need for those on x86 */
 	if (flag & BOOTM_STATE_OS_BD_T || flag & BOOTM_STATE_OS_CMDLINE)
arch/xtensa/lib/bootm.c +1 -1
index fee339281502..5e8e14021ab3 100644
@@ -134,7 +134,7 @@ static struct bp_tag *setup_fdt_tag(struct bp_tag *params, void *fdt_start)
  * Boot Linux.
  */
 
-int do_bootm_linux(int flag, int argc, char *argv[], struct bootm_headers *images)
+int do_bootm_linux(int flag, struct bootm_headers *images)
 {
 	struct bp_tag *params, *params_start;
 	ulong initrd_start, initrd_end;
boot/bootm.c +3 -3
index 301cfded05cb..c343f313e80a 100644
@@ -1099,9 +1099,9 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	/* Call various other states that are not generally used */
 	if (!ret && (states & BOOTM_STATE_OS_CMDLINE))
-		ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images);
+		ret = boot_fn(BOOTM_STATE_OS_CMDLINE, images);
 	if (!ret && (states & BOOTM_STATE_OS_BD_T))
-		ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
+		ret = boot_fn(BOOTM_STATE_OS_BD_T, images);
 	if (!ret && (states & BOOTM_STATE_OS_PREP)) {
 		ret = bootm_process_cmdline_env(images->os.os == IH_OS_LINUX);
 		if (ret) {
@@ -1109,7 +1109,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
 			ret = CMD_RET_FAILURE;
 			goto err;
 		}
-		ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
+		ret = boot_fn(BOOTM_STATE_OS_PREP, images);
 	}
 
 #ifdef CONFIG_TRACE
boot/bootm_os.c +17 -29

142 lines not on this page · raw message

include/bootm.h +1 -6
index f5229ea90b33..0e4662485006 100644
@@ -25,16 +25,11 @@ struct cmd_tbl;
  *  - disabled interrupts.
  *
  * @flag: Flags indicating what to do (BOOTM_STATE_...)
- * @argc: Number of arguments. Note that the arguments are shifted down
- *	 so that 0 is the first argument not processed by U-Boot, and
- *	 argc is adjusted accordingly. This avoids confusion as to how
- *	 many arguments are available for the OS.
  * @images: Pointers to os/initrd/fdt
  * Return: 1 on error. On success the OS boots so this function does
  * not return.
  */
-typedef int boot_os_fn(int flag, int argc, char *const argv[],
-			struct bootm_headers *images);
+typedef int boot_os_fn(int flag, struct bootm_headers *images);
 
 extern boot_os_fn do_bootm_linux;
 extern boot_os_fn do_bootm_vxworks;
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#10 lore raw

Re: [PATCH 05/18] treewide: bootm: Drop command-line args to boot_os_fn

Hi Simon,

looks like i cannot apply this patch:

   ~/dev-k/u-boot-coldfire  on   master *2  git am
Complete-decoupling-of-bootm-logic-from-commands.patch
Applying: bootm: netbds: Drop passing of arguments
Applying: bootm: plan: Drop passing of arguments
Applying: bootm: qnxelf: Drop passing of arguments
Applying: nios2: Drop separate parsing of bootm args
Applying: treewide: bootm: Drop command-line args to boot_os_fn
error: patch failed: boot/bootm_os.c:441
error: boot/bootm_os.c: patch does not apply
Patch failed at 0005 treewide: bootm: Drop command-line args to boot_os_fn
hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".

And getting similar issues for the "pxe: Allow extlinux booting without CMDLINE enabled"

Am i doing something wrong ?

Thanks,

Regards
angelo

Quoted 405 lines · Simon Glass

These arguments are not used now. They cannot be provided when there is no bootm command invoked to provide arguments. Drop the argc and argv parameters.

---

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

Re: [PATCH 05/18] treewide: bootm: Drop command-line args to boot_os_fn

Hi Angelo,

Quoted 21 lines · Angelo Dureghello

Hi Simon,

looks like i cannot apply this patch:

   ~/dev-k/u-boot-coldfire  on   master *2  git am
Complete-decoupling-of-bootm-logic-from-commands.patch
Applying: bootm: netbds: Drop passing of arguments
Applying: bootm: plan: Drop passing of arguments
Applying: bootm: qnxelf: Drop passing of arguments
Applying: nios2: Drop separate parsing of bootm args
Applying: treewide: bootm: Drop command-line args to boot_os_fn
error: patch failed: boot/bootm_os.c:441
error: boot/bootm_os.c: patch does not apply
Patch failed at 0005 treewide: bootm: Drop command-line args to boot_os_fn
hint: Use 'git am --show-current-patch=diff' to see the failed patch When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort".

Quoted 4 lines

And getting similar issues for the "pxe: Allow extlinux booting without CMDLINE enabled"

Am i doing something wrong ?

Could you please check the cover letter? There are several series here and I put the -dm tree links in as well.

I was keeping these to send in sequence, but it would likely take several releases that way, so I elected to send everything at once and get feedback.

Regards,
SmIon

Acked-by on v1 5/18
#12 lore raw

Re: [PATCH 05/18] treewide: bootm: Drop command-line args to boot_os_fn

In reply to Simon Glass

Hi Simon,

Quoted 405 lines · Simon Glass

These arguments are not used now. They cannot be provided when there is no bootm command invoked to provide arguments. Drop the argc and argv parameters.

---

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

PATCH 6/18 bootm: Drop arguments from boot_selected_os()

In reply to Simon Glass

The argc and argv parameters are not used now, so drop them.

---

 boot/bootm.c    | 6 ++----
 boot/bootm_os.c | 4 ++--
 include/bootm.h | 4 ++--
 3 files changed, 6 insertions(+), 8 deletions(-)
boot/bootm.c +2 -4
index c343f313e80a..d2448f6306dc 100644
@@ -1117,8 +1117,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
 	if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) {
 		char *cmd_list = env_get("fakegocmd");
 
-		ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO,
-				images, boot_fn);
+		ret = boot_selected_os(BOOTM_STATE_OS_FAKE_GO, images, boot_fn);
 		if (!ret && cmd_list)
 			ret = run_command_list(cmd_list, -1, flag);
 	}
@@ -1132,8 +1131,7 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	/* Now run the OS! We hope this doesn't return */
 	if (!ret && (states & BOOTM_STATE_OS_GO))
-		ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_GO,
-				images, boot_fn);
+		ret = boot_selected_os(BOOTM_STATE_OS_GO, images, boot_fn);
 
 	/* Deal with any fallout */
 err:
boot/bootm_os.c +2 -2
index df1aab4b3e4d..22ff62e5fb65 100644
@@ -527,8 +527,8 @@ __weak void board_preboot_os(void)
 	/* please define board specific board_preboot_os() */
 }
 
-int boot_selected_os(int argc, char *const argv[], int state,
-		     struct bootm_headers *images, boot_os_fn *boot_fn)
+int boot_selected_os(int state, struct bootm_headers *images,
+		     boot_os_fn *boot_fn)
 {
 	arch_preboot_os();
 	board_preboot_os();
include/bootm.h +2 -2
index 0e4662485006..b8d74d03a8c4 100644
@@ -42,8 +42,8 @@ boot_os_fn *bootm_os_get_boot_func(int os);
 int bootm_host_load_images(const void *fit, int cfg_noffset);
 #endif
 
-int boot_selected_os(int argc, char *const argv[], int state,
-		     struct bootm_headers *images, boot_os_fn *boot_fn);
+int boot_selected_os(int argc, struct bootm_headers *images,
+		     boot_os_fn *boot_fn);
 
 ulong bootm_disable_interrupts(void);
 
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#14 lore raw

Re: [PATCH 06/18] bootm: Drop arguments from boot_selected_os()

Quoted 3 lines · Simon Glass

The argc and argv parameters are not used now, so drop them.

This along with patches 1-5 depend on what the answer is about how NetBSD certainly already expects to use things.

Signature · 1 line
Tom
#15 lore raw

PATCH 7/18 mips: Add a reset_cpu() function

In reply to Simon Glass

The current do_reset() is called from a command context. Add a function which can be used from anywhere, as is done on ARM.

---

 arch/mips/cpu/cpu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/mips/cpu/cpu.c +7 -1
index acfc9dc43f17..443465047715 100644
@@ -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.rc2.451.g8631bc7472-goog
#16 lore raw

Re: [PATCH 07/18] mips: Add a reset_cpu() function

Quoted 5 lines · Simon Glass

The current do_reset() is called from a command context. Add a function which can be used from anywhere, as is done on ARM.

---

A consistent API here for all architectures is good, thanks for doing this cleanup.

Signature · 1 line
Tom
#17 lore raw

PATCH 8/18 m68k: Add a reset_cpu() function

In reply to Simon Glass

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.

---

 arch/m68k/lib/traps.c | 7 +++++++
 1 file changed, 7 insertions(+)
arch/m68k/lib/traps.c +7 -0
index c283351181d8..ae8ae6ccf592 100644
@@ -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.rc2.451.g8631bc7472-goog
Acked-by on v1 8/18
#18 lore raw

Re: [PATCH 08/18] m68k: Add a reset_cpu() function

Hi Simon,

Quoted 34 lines · Simon Glass

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.

---

  arch/m68k/lib/traps.c | 7 +++++++
  1 file changed, 7 insertions(+)
arch/m68k/lib/traps.c +7 -0
index c283351181d8..ae8ae6ccf592 100644
@@ -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);
+}
#19 lore raw

PATCH 9/18 ppc: Add a reset_cpu() function

In reply to Simon Glass

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.

---

 arch/powerpc/lib/traps.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/powerpc/lib/traps.c +10 -0
index c7bce82a44b3..cf8da2e5df0d 100644
@@ -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.rc2.451.g8631bc7472-goog
#20 lore raw

PATCH 10/18 nios2: Add a reset_cpu() function

In reply to Simon Glass

The current do_reset() is called from a command context. Add a function which can be used from anywhere, as is done on ARM.

---

 arch/nios2/cpu/cpu.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
arch/nios2/cpu/cpu.c +7 -1
index 79a54d1bc259..de7bfa947f11 100644
@@ -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.rc2.451.g8631bc7472-goog
#21 lore raw

PATCH 11/18 riscv: Add a reset_cpu() function

In reply to Simon Glass

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.

---

 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
index ebd39cb41a60..8445c5823e17 100644
@@ -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
index 712e1bdb8e1d..c4153c9e6e02 100644
@@ -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.rc2.451.g8631bc7472-goog
#22 lore raw

PATCH 12/18 bootm: Adjust how the board is reset

In reply to Simon Glass

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.

---

 boot/bootm.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
boot/bootm.c +5 -3
index d2448f6306dc..de5c32099ceb 100644
@@ -1138,10 +1138,12 @@ err:
 	if (iflag)
 		enable_interrupts();
 
-	if (ret == BOOTM_ERR_UNIMPLEMENTED)
+	if (ret == BOOTM_ERR_UNIMPLEMENTED) {
 		bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
-	else if (ret == BOOTM_ERR_RESET)
-		do_reset(cmdtp, flag, argc, argv);
+	} else if (ret == BOOTM_ERR_RESET) {
+		printf("Resetting the board...\n");
+		reset_cpu();
+	}
 
 	return ret;
 }
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
Reviewed-by on v1 12/18
#23 lore raw

Re: [PATCH 12/18] bootm: Adjust how the board is reset

Quoted 5 lines · Simon Glass

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.

Signature · 1 line
Tom
#24 lore raw

PATCH 13/18 bootm: Drop arguments from do_bootm_states() and rename

In reply to Simon Glass

Create a new struct which holds the information required by bootm. Set this up for each existing caller.

Now that none of the functions called from do_bootm_states() need an argv[] list, change the arguments of do_bootm_states() as well.

For booti make sure it only uses argv[] and argc at the top of the function, so we can eventually refactor to remove these parameters.

Finally, rename the function to bootm_run_states() to better indicate its purpose. The 'do_' prefix is used to indicate a command processor, which this is now not.

---

 arch/mips/lib/bootm.c |  2 +-
 boot/bootm.c          | 60 ++++++++++++-------------------------------
 cmd/booti.c           | 55 ++++++++++++++++++++++-----------------
 cmd/bootm.c           | 26 +++++++++++++++++--
 cmd/bootz.c           | 45 +++++++++++++++++++++++---------
 include/bootm.h       | 57 +++++++++++++++++++++++++++++++++++++---
 6 files changed, 160 insertions(+), 85 deletions(-)
arch/mips/lib/bootm.c +1 -1
index 05dbe6131728..339a875bdf20 100644
@@ -216,7 +216,7 @@ static int boot_reloc_fdt(struct bootm_headers *images)
 {
 	/*
 	 * In case of legacy uImage's, relocation of FDT is already done
-	 * by do_bootm_states() and should not repeated in 'bootm prep'.
+	 * by bootm_run_states() and should not repeated in 'bootm prep'.
 	 */
 	if (images->state & BOOTM_STATE_FDT) {
 		debug("## FDT already relocated\n");
boot/bootm.c +16 -44

101 lines not on this page · raw message

cmd/booti.c +32 -23

97 lines not on this page · raw message

cmd/bootm.c +24 -2
index 6ded091dd559..68fb48f77a90 100644
@@ -76,6 +76,7 @@ static ulong bootm_get_addr(int argc, char *const argv[])
 static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc,
 			       char *const argv[])
 {
+	struct bootm_info bmi;
 	int ret = 0;
 	long state;
 	struct cmd_tbl *c;
@@ -103,7 +104,17 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc,
 		return CMD_RET_USAGE;
 	}
 
-	ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0);
+	memset(&bmi, '\0', sizeof(struct bootm_info));
+	if (argc)
+		bmi.addr_fit = argv[0];
+	if (argc > 1)
+		bmi.conf_ramdisk = argv[1];
+	if (argc > 2)
+		bmi.conf_fdt = argv[2];
+	bmi.images = &images;
+	bmi.cmd_name = "bootm";
+
+	ret = bootm_run_states(&bmi, state);
 
 #if defined(CONFIG_CMD_BOOTM_PRE_LOAD)
 	if (!ret && (state & BOOTM_STATE_PRE_LOAD))
@@ -120,6 +131,7 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc,
 
 int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
+	struct bootm_info bmi;
 	int states;
 	int ret;
 
@@ -151,7 +163,17 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		states |= BOOTM_STATE_MEASURE;
 	if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS))
 		states |= BOOTM_STATE_OS_CMDLINE;
-	ret = do_bootm_states(cmdtp, flag, argc, argv, states, &images, 1);
+
+	memset(&bmi, '\0', sizeof(struct bootm_info));
+	if (argc)
+		bmi.addr_fit = argv[0];
+	if (argc > 1)
+		bmi.conf_ramdisk = argv[1];
+	if (argc > 2)
+		bmi.conf_fdt = argv[2];
+	bmi.boot_progress = true;
+	bmi.images = &images;
+	ret = bootm_run_states(&bmi, states);
 
 	return ret ? CMD_RET_FAILURE : 0;
 }
cmd/bootz.c +33 -12

65 lines not on this page · raw message

include/bootm.h +54 -3

69 lines not on this page · raw message

Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#25 lore raw

PATCH 14/18 bootm: Create a function to run through the bootm states

In reply to 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 new bootm_run() function to handle this.

---

 boot/bootm.c    | 19 +++++++++++++++++++
 cmd/bootm.c     | 14 +-------------
 include/bootm.h | 13 +++++++++++++
 3 files changed, 33 insertions(+), 13 deletions(-)
boot/bootm.c +19 -0
index 1f46bb88b38e..301ba480677d 100644
@@ -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
index 68fb48f77a90..744a84d6c394 100644
@@ -132,7 +132,6 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc,
 int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	struct bootm_info bmi;
-	int states;
 	int ret;
 
 	/* determine if we have a sub command */
@@ -153,17 +152,6 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 			return do_bootm_subcommand(cmdtp, flag, argc, argv);
 	}
 
-	states = BOOTM_STATE_START | BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD |
-		BOOTM_STATE_FINDOTHER | BOOTM_STATE_LOADOS |
-		BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
-		BOOTM_STATE_OS_GO;
-	if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH))
-		states |= BOOTM_STATE_RAMDISK;
-	if (IS_ENABLED(CONFIG_MEASURED_BOOT))
-		states |= BOOTM_STATE_MEASURE;
-	if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS))
-		states |= BOOTM_STATE_OS_CMDLINE;
-
 	memset(&bmi, '\0', sizeof(struct bootm_info));
 	if (argc)
 		bmi.addr_fit = argv[0];
@@ -173,7 +161,7 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		bmi.conf_fdt = argv[2];
 	bmi.boot_progress = true;
 	bmi.images = &images;
-	ret = bootm_run_states(&bmi, states);
+	ret = bootm_run(&bmi);
 
 	return ret ? CMD_RET_FAILURE : 0;
 }
include/bootm.h +13 -0
index a3bef1ab88f2..ef46c085b594 100644
@@ -137,6 +137,19 @@ int bootm_measure(struct bootm_headers *images);
  */
 int bootm_run_states(struct bootm_info *bmi, int states);
 
+/**
+ * bootm_run() - Run the entire bootm process
+ *
+ * This runs through the bootm process from start to finish, using the default
+ * set of states.
+ *
+ * This uses bootm_run_states().
+ *
+ * @bmi: bootm information
+ * Return: 0 if ok, something else on error
+ */
+int bootm_run(struct bootm_info *bmi);
+
 void arch_preboot_os(void);
 
 /*
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#26 lore raw

PATCH 15/18 stm32: Use local vars in stm32prog for initrd and fdt

In reply to 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.

---

 .../cmd_stm32prog/cmd_stm32prog.c             | 23 +++++++++++--------
 1 file changed, 14 insertions(+), 9 deletions(-)
arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c +14 -9
index 2411bcf06d8f..8670535844d3 100644
@@ -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.rc2.451.g8631bc7472-goog
#27 lore raw

PATCH 16/18 bootm: Create a function to run through the bootz states

In reply to Simon Glass

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.

---

 boot/bootm.c    | 13 +++++++++++++
 cmd/bootz.c     |  9 ++-------
 include/bootm.h | 13 +++++++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)
boot/bootm.c +13 -0
index 301ba480677d..22c6d1604176 100644
@@ -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
index fa6743a71170..f03062f1cf75 100644
@@ -75,7 +75,7 @@ static int bootz_start(struct cmd_tbl *cmdtp, int flag, int argc,
 int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	struct bootm_info bmi;
-	int states, ret;
+	int ret;
 
 	/* Consume 'bootz' */
 	argc--; argv++;
@@ -102,12 +102,7 @@ int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	bmi.images = &images;
 	bmi.cmd_name = "bootz";
 
-	states = BOOTM_STATE_MEASURE | BOOTM_STATE_OS_PREP |
-		BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO;
-	if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH))
-		states |= BOOTM_STATE_RAMDISK;
-
-	ret = bootm_run_states(&bmi, states);
+	ret = bootz_run(&bmi);
 
 	return ret;
 }
include/bootm.h +13 -0
index ef46c085b594..d7c9486553e4 100644
@@ -150,6 +150,19 @@ int bootm_run_states(struct bootm_info *bmi, int states);
  */
 int bootm_run(struct bootm_info *bmi);
 
+/**
+ * bootz_run() - Run the entire bootz process
+ *
+ * This runs through the bootz process from start to finish, using the default
+ * set of states.
+ *
+ * This uses bootm_run_states().
+ *
+ * @bmi: bootm information
+ * Return: 0 if ok, something else on error
+ */
+int bootz_run(struct bootm_info *bmi);
+
 void arch_preboot_os(void);
 
 /*
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#28 lore raw

PATCH 17/18 stm32: Use bootm_run() and bootz_run()

In reply to Simon Glass

Use the new bootm/z_run() functions to avoid having to create an argument list for the stm32prog code.

---

 .../cmd_stm32prog/cmd_stm32prog.c             | 22 +++++++++++--------
 1 file changed, 13 insertions(+), 9 deletions(-)
arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c +13 -9
index 8670535844d3..5e1dc7a03810 100644
@@ -4,6 +4,7 @@
  */
 
 #include <common.h>
+#include <bootm.h>
 #include <command.h>
 #include <dfu.h>
 #include <image.h>
@@ -125,12 +126,10 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc,
 		char dtb_addr[20];
 		char initrd_addr[40];
 		char *fdt_arg, *initrd_arg;
-		char *bootm_argv[5] = {
-			"bootm", boot_addr_start,
-		};
 		const void *uimage = (void *)data->uimage;
 		const void *dtb = (void *)data->dtb;
 		const void *initrd = (void *)data->initrd;
+		struct bootm_info bmi;
 
 		fdt_arg = dtb_addr;
 		if (!dtb)
@@ -141,7 +140,7 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc,
 		snprintf(boot_addr_start, sizeof(boot_addr_start) - 1,
 			 "0x%p", uimage);
 
-		initrd_arg = "-";
+		initrd_arg = NULL;
 		if (initrd) {
 			snprintf(initrd_addr, sizeof(initrd_addr) - 1,
 				 "0x%p:0x%zx", initrd, data->initrd_size);
@@ -149,15 +148,20 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc,
 		}
 
 		printf("Booting kernel at %s %s %s...\n\n\n", boot_addr_start,
-		       initrd_arg, fdt_arg);
-		bootm_argv[2] = initrd_arg;
-		bootm_argv[3] = fdt_arg;
+		       initrd_arg ?: "-", fdt_arg);
+
+		memset(&bmi, '\0', sizeof(bmi));
+		bmi.addr_fit = boot_addr_start;
+		bmi.conf_ramdisk = initrd_arg;
+		bmi.conf_fdt = fdt_arg;
+		bmi.boot_progress = true;
+		bmi.images = &images;
 
 		/* Try bootm for legacy and FIT format image */
 		if (genimg_get_format(uimage) != IMAGE_FORMAT_INVALID)
-			do_bootm(cmdtp, 0, 4, bootm_argv);
+			bootm_run(&bmi);
 		else if (IS_ENABLED(CONFIG_CMD_BOOTZ))
-			do_bootz(cmdtp, 0, 4, bootm_argv);
+			bootz_run(&bmi);
 	}
 	if (data->script)
 		cmd_source_script(data->script, NULL, NULL);
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#29 lore raw

PATCH 18/18 bootm: Create a function to run through the booti states

In reply to Simon Glass

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.

---

 boot/bootm.c    | 13 +++++++++++++
 include/bootm.h | 13 +++++++++++++
 2 files changed, 26 insertions(+)
boot/bootm.c +13 -0
index 22c6d1604176..f630b8c1a9c3 100644
@@ -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
index d7c9486553e4..ce5298e4ed97 100644
@@ -163,6 +163,19 @@ int bootm_run(struct bootm_info *bmi);
  */
 int bootz_run(struct bootm_info *bmi);
 
+/**
+ * booti_run() - Run the entire booti process
+ *
+ * This runs through the booti process from start to finish, using the default
+ * set of states.
+ *
+ * This uses bootm_run_states().
+ *
+ * @bmi: bootm information
+ * Return: 0 if ok, something else on error
+ */
+int booti_run(struct bootm_info *bmi);
+
 void arch_preboot_os(void);
 
 /*
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#30 lore raw
In reply to Simon Glass
Quoted 11 lines · Simon Glass

This series continues refactoring the bootm code to allow it to be used with CONFIG_COMMAND disabled. The OS-handling code is refactored and a new bootm_run() function is created to run through the bootm stages. This completes the work.

A booti_go() function is created also, in case it proves useful, but at last for now standard boot does not use this.

This is cmdd (part d of CMDLINE refactoring)
It depends on dm/bootstda-working
which depends on dm/cmdc-working

Since I would ask "what's the size impact of all of this?", I went and checked. I rebased your current cmdd-working branch on top of current next, and compared. While I'm sure this will change a little given feedback so far, generally platforms shrink a little (probably due to the bootm args stuff you dropped, but may need to keep). The only big growth I saw was branch specific and your "rpi" patch, oh yes, that grows rpi_4 given that you change a bunch of stuff there. So that doesn't count.

So generally speaking, I'm OK with this series up to cmdd-working, and will continue catching up and providing specific feedback.

Signature · 1 line
Tom
#31 lore raw

Hi Tom,

Quoted 24 lines · Tom Rini
Quoted 11 lines · Simon Glass

This series continues refactoring the bootm code to allow it to be used with CONFIG_COMMAND disabled. The OS-handling code is refactored and a new bootm_run() function is created to run through the bootm stages. This completes the work.

A booti_go() function is created also, in case it proves useful, but at last for now standard boot does not use this.

This is cmdd (part d of CMDLINE refactoring)
It depends on dm/bootstda-working
which depends on dm/cmdc-working

Since I would ask "what's the size impact of all of this?", I went and checked. I rebased your current cmdd-working branch on top of current next, and compared. While I'm sure this will change a little given feedback so far, generally platforms shrink a little (probably due to the bootm args stuff you dropped, but may need to keep). The only big growth I saw was branch specific and your "rpi" patch, oh yes, that grows rpi_4 given that you change a bunch of stuff there. So that doesn't count.

Quoted 3 lines

So generally speaking, I'm OK with this series up to cmdd-working, and will continue catching up and providing specific feedback.

OK, great. I have had a busy week but may be able to catch up a bit on the plane.

Regards,
Simon