Skip to contentSkip to conversation

Complete decoupling of zboot logic from commands

PATCH In review Simon Glass 2 participants 18 messages Dec 4, 2023 – Apr 10, 2024 x86

lore
Share & tools
lore
#0 lore raw

cover Complete decoupling of zboot logic from commands

This series refactors the zboot code to allow it to be used with CONFIG_COMMAND disabled.

A new zboot_run() function is used to boot a zimage.

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

Simon Glass (13):
x86: zboot: Move zimage definitions to the header file
x86: zboot: Move command code into its own file
x86: zboot: Create a separate ZBOOT option for zboot logic
x86: zboot: Avoid iteration in do_zboot_states()
x86: zboot: Create separate functions for the logic
x86: zboot: Move environment setting into zboot_load()
x86: zboot: Drop intermediate zboot_setup() function
x86: zboot: Drop intermediate zboot_go() function
x86: zboot: Move argument processing outside zboot_start()
x86: zboot: Rename zboot_start() to zboot_run()
x86: zboot: Separate logic functions from commands
x86: zboot: Use zboot_start() in zboot_run()
x86: zboot: Tidy up the comment for zboot_run()

 arch/Kconfig                  |   1 -
 arch/x86/Kconfig              |   8 +
 arch/x86/include/asm/zimage.h |  97 ++++++++++++
 arch/x86/lib/Makefile         |   2 +-
 arch/x86/lib/zimage.c         | 267 ++++------------------------------
 boot/bootmeth_cros.c          |   6 +-
 cmd/Kconfig                   |   2 +
 cmd/x86/Makefile              |   1 +
 cmd/x86/zboot.c               | 182 +++++++++++++++++++++++
 include/bootm.h               |  15 +-
 10 files changed, 333 insertions(+), 248 deletions(-)
 create mode 100644 cmd/x86/zboot.c
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#1 lore raw

PATCH 1/13 x86: zboot: Move zimage definitions to the header file

In preparation for splitting the zboot-command code into a separate file, move the definitions into the header file.

While we are here, mention when load_address and base_ptr are set up and explain bzimage_addr better. Make cmdline const since it cannot be changed.

---

 arch/x86/include/asm/zimage.h | 41 +++++++++++++++++++++++++++++++++++
 arch/x86/lib/zimage.c         | 36 +-----------------------------
 2 files changed, 42 insertions(+), 35 deletions(-)
arch/x86/include/asm/zimage.h +41 -0
index 655675b66614..a91cfb2b8dd0 100644
@@ -30,6 +30,47 @@
 #define BZIMAGE_LOAD_ADDR  0x100000
 #define ZIMAGE_LOAD_ADDR   0x10000
 
+enum {
+	ZBOOT_STATE_START	= BIT(0),
+	ZBOOT_STATE_LOAD	= BIT(1),
+	ZBOOT_STATE_SETUP	= BIT(2),
+	ZBOOT_STATE_INFO	= BIT(3),
+	ZBOOT_STATE_GO		= BIT(4),
+
+	/* This one doesn't execute automatically, so stop the count before 5 */
+	ZBOOT_STATE_DUMP	= BIT(5),
+	ZBOOT_STATE_COUNT	= 5,
+};
+
+/**
+ * struct zboot_state - Current state of the boot
+ *
+ * @bzimage_addr: Address of the bzImage to boot, or 0 if the image has already
+ *	been loaded and does not exist (as a cohesive whole) in memory
+ * @bzimage_size: Size of the bzImage, or 0 to detect this
+ * @initrd_addr: Address of the initial ramdisk, or 0 if none
+ * @initrd_size: Size of the initial ramdisk, or 0 if none
+ * @load_address: Address where the bzImage is moved before booting, either
+ *	BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
+ *	This is set up when loading the zimage
+ * @base_ptr: Pointer to the boot parameters, typically at address
+ *	DEFAULT_SETUP_BASE
+ *	This is set up when loading the zimage
+ * @cmdline: Environment variable containing the 'override' command line, or
+ *	NULL to use the one in the setup block
+ */
+struct zboot_state {
+	ulong bzimage_addr;
+	ulong bzimage_size;
+	ulong initrd_addr;
+	ulong initrd_size;
+	ulong load_address;
+	struct boot_params *base_ptr;
+	const char *cmdline;
+};
+
+extern struct zboot_state state;
+
 /**
  * load_zimage() - Load a zImage or bzImage
  *
arch/x86/lib/zimage.c +1 -35
index a41e1ccf8a65..b04d39b36dd4 100644
@@ -56,41 +56,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 #define COMMAND_LINE_SIZE	2048
 
-/**
- * struct zboot_state - Current state of the boot
- *
- * @bzimage_addr: Address of the bzImage to boot
- * @bzimage_size: Size of the bzImage, or 0 to detect this
- * @initrd_addr: Address of the initial ramdisk, or 0 if none
- * @initrd_size: Size of the initial ramdisk, or 0 if none
- * @load_address: Address where the bzImage is moved before booting, either
- *	BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
- * @base_ptr: Pointer to the boot parameters, typically at address
- *	DEFAULT_SETUP_BASE
- * @cmdline: Environment variable containing the 'override' command line, or
- *	NULL to use the one in the setup block
- */
-struct zboot_state {
-	ulong bzimage_addr;
-	ulong bzimage_size;
-	ulong initrd_addr;
-	ulong initrd_size;
-	ulong load_address;
-	struct boot_params *base_ptr;
-	char *cmdline;
-} state;
-
-enum {
-	ZBOOT_STATE_START	= BIT(0),
-	ZBOOT_STATE_LOAD	= BIT(1),
-	ZBOOT_STATE_SETUP	= BIT(2),
-	ZBOOT_STATE_INFO	= BIT(3),
-	ZBOOT_STATE_GO		= BIT(4),
-
-	/* This one doesn't execute automatically, so stop the count before 5 */
-	ZBOOT_STATE_DUMP	= BIT(5),
-	ZBOOT_STATE_COUNT	= 5,
-};
+struct zboot_state state;
 
 static void build_command_line(char *command_line, int auto_boot)
 {
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#2 lore raw

PATCH 2/13 x86: zboot: Move command code into its own file

In reply to Simon Glass

Much of the code in zimage.c deals with the zboot command. Move it into a sepatate zboot.c file within the cmd/ directory. This will eventually allow use of the zimage logic without the command being enabled.

---

 arch/x86/include/asm/zimage.h |  31 ++++++
 arch/x86/lib/zimage.c         | 199 +--------------------------------
 cmd/x86/Makefile              |   1 +
 cmd/x86/zboot.c               | 203 ++++++++++++++++++++++++++++++++++
 4 files changed, 239 insertions(+), 195 deletions(-)
 create mode 100644 cmd/x86/zboot.c
arch/x86/include/asm/zimage.h +31 -0
index a91cfb2b8dd0..ac6683ea9ef3 100644
@@ -71,6 +71,37 @@ struct zboot_state {
 
 extern struct zboot_state state;
 
+/**
+ * zimage_dump() - Dump information about a zimage
+ *
+ * @base_ptr: Pointer to the boot parameters
+ * @show_cmdline: true to show the kernel command line
+ */
+void zimage_dump(struct boot_params *base_ptr, bool show_cmdline);
+
+/**
+ * zboot_load() - Load a zimage
+ *
+ * Load the zimage into the correct place
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int zboot_load(void);
+
+/**
+ * zboot_setup() - Set up the zboot image reeady for booting
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int zboot_setup(void);
+
+/**
+ * zboot_go() - Start the image
+ *
+ * Return: 0 if OK, -ve on error
+ */
+int zboot_go(void);
+
 /**
  * load_zimage() - Load a zImage or bzImage
  *
arch/x86/lib/zimage.c +4 -195

232 lines not on this page · raw message

cmd/x86/Makefile +1 -0
index 5f82204c87e6..b1f39d3bfde5 100644
@@ -5,3 +5,4 @@ obj-y += mtrr.o
 obj-$(CONFIG_CMD_EXCEPTION) += exception.o
 obj-$(CONFIG_USE_HOB) += hob.o
 obj-$(CONFIG_HAVE_FSP) += fsp.o
+obj-$(CONFIG_CMD_ZBOOT) += zboot.o
cmd/x86/zboot.c new file +203 -0

203 lines not on this page · raw message

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

PATCH 3/13 x86: zboot: Create a separate ZBOOT option for zboot logic

In reply to Simon Glass

Most of the functionality of zboot is contained in the logic which handles a zimage. Create a separate Kconfig for the logic so that it can (later) be used without the command itself being enabled.

Enable ZBOOT by default on x86, with the command depending on that. The existing 'imply' can therefore be removed.

---

 arch/Kconfig          | 1 -
 arch/x86/Kconfig      | 8 ++++++++
 arch/x86/lib/Makefile | 2 +-
 cmd/Kconfig           | 2 ++
 4 files changed, 11 insertions(+), 2 deletions(-)
arch/Kconfig +0 -1
index 2e0528d819c9..de91aac4b8d4 100644
@@ -246,7 +246,6 @@ config X86
 	imply CMD_PCI
 	imply CMD_SF
 	imply CMD_SF_TEST
-	imply CMD_ZBOOT
 	imply DM_GPIO
 	imply DM_KEYBOARD
 	imply DM_MMC
arch/x86/Kconfig +8 -0
index 99e59d94c606..e5ee10af33c5 100644
@@ -1053,4 +1053,12 @@ config SPL_COREBOOT_SYSINFO
 	  display, memory and build information. It is stored in
 	  struct sysinfo_t after parsing by get_coreboot_info().
 
+config ZBOOT
+	bool "Support the zImage format"
+	default y
+	help
+	  Enable this to support booting the x86-specific zImage format. This
+	  uses a special, binary format containing information about the Linux
+	  format to boot.
+
 endmenu
arch/x86/lib/Makefile +1 -1
index 90a7618ecfde..8fc35e1b51ea 100644
@@ -48,7 +48,7 @@ obj-$(CONFIG_$(SPL_TPL_)GENERATE_ACPI_TABLE) += acpi_table.o
 endif
 obj-y	+= tables.o
 ifndef CONFIG_SPL_BUILD
-obj-$(CONFIG_CMD_ZBOOT)	+= zimage.o
+obj-$(CONFIG_ZBOOT) += zimage.o
 endif
 obj-$(CONFIG_USE_HOB) += hob.o
 ifndef CONFIG_TPL_BUILD
cmd/Kconfig +2 -0
index 9ebea76c2ce5..584ffd039686 100644
@@ -538,6 +538,8 @@ config THOR_RESET_OFF
 
 config CMD_ZBOOT
 	bool "zboot - x86 boot command"
+	depends on ZBOOT
+	default y
 	help
 	  With x86 machines it is common to boot a bzImage file which
 	  contains both a kernel and a setup.bin file. The latter includes
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
Reviewed-by on v1 3/13
#4 lore raw

Re: [PATCH 03/13] x86: zboot: Create a separate ZBOOT option for zboot logic

Quoted 8 lines · Simon Glass

Most of the functionality of zboot is contained in the logic which handles a zimage. Create a separate Kconfig for the logic so that it can (later) be used without the command itself being enabled.

Enable ZBOOT by default on x86, with the command depending on that. The existing 'imply' can therefore be removed.

Signature · 1 line
Tom
#5 lore raw

PATCH 4/13 x86: zboot: Avoid iteration in do_zboot_states()

In reply to Simon Glass

Drop the iteration and write out each state in full. This will allow the arguments to be reduced and adjusted in future patches.

---

 cmd/x86/zboot.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
cmd/x86/zboot.c +14 -13
index c9375fb417c1..03cab1d67ebf 100644
@@ -136,19 +136,20 @@ U_BOOT_SUBCMDS(zboot,
 int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc,
 		    char *const argv[], int state_mask)
 {
-	int i;
-
-	for (i = 0; i < ZBOOT_STATE_COUNT; i++) {
-		struct cmd_tbl *cmd = &zboot_subcmds[i];
-		int mask = 1 << i;
-		int ret;
-
-		if (mask & state_mask) {
-			ret = cmd->cmd(cmd, flag, argc, argv);
-			if (ret)
-				return ret;
-		}
-	}
+	int ret;
+
+	if (flag & ZBOOT_STATE_START)
+		ret = do_zboot_start(cmdtp, flag, argc, argv);
+	if (!ret && (flag & ZBOOT_STATE_LOAD))
+		ret = do_zboot_load(cmdtp, flag, argc, argv);
+	if (!ret && (flag & ZBOOT_STATE_SETUP))
+		ret = do_zboot_setup(cmdtp, flag, argc, argv);
+	if (!ret && (flag & ZBOOT_STATE_INFO))
+		ret = do_zboot_info(cmdtp, flag, argc, argv);
+	if (!ret && (flag & ZBOOT_STATE_GO))
+		ret = do_zboot_go(cmdtp, flag, argc, argv);
+	if (ret)
+		return ret;
 
 	return 0;
 }
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#6 lore raw

PATCH 5/13 x86: zboot: Create separate functions for the logic

In reply to Simon Glass

Separate out the commands from the logic. This will eventually allow the logic to be used when CONFIG_CMDLINE is not enabled.

---

 cmd/x86/zboot.c | 66 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 52 insertions(+), 14 deletions(-)
cmd/x86/zboot.c +52 -14
index 03cab1d67ebf..f5c90a8ba896 100644
@@ -10,8 +10,7 @@
 #include <vsprintf.h>
 #include <asm/zimage.h>
 
-static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
-			  char *const argv[])
+static void zboot_start(int argc, char *const argv[])
 {
 	const char *s;
 
@@ -53,6 +52,27 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 	}
 	if (argc >= 7)
 		state.cmdline = env_get(argv[6]);
+}
+
+static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
+			  char *const argv[])
+{
+	zboot_start(argc, argv);
+
+	return 0;
+}
+
+static int _zboot_load(void)
+{
+	int ret;
+
+	ret = zboot_load();
+	if (!ret)
+		ret = env_set_hex("zbootbase", map_to_sysmem(state.base_ptr));
+	if (!ret)
+		ret = env_set_hex("zbootaddr", state.load_address);
+	if (ret)
+		return ret;
 
 	return 0;
 }
@@ -60,18 +80,13 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
 			 char *const argv[])
 {
-	if (zboot_load())
-		return CMD_RET_FAILURE;
-
-	if (env_set_hex("zbootbase", map_to_sysmem(state.base_ptr)) ||
-	    env_set_hex("zbootaddr", state.load_address))
+	if (_zboot_load())
 		return CMD_RET_FAILURE;
 
 	return 0;
 }
 
-static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
-			  char *const argv[])
+static int _zboot_setup(void)
 {
 	struct boot_params *base_ptr = state.base_ptr;
 
@@ -87,24 +102,47 @@ static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
-			 char *const argv[])
+static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
+			  char *const argv[])
+{
+	return _zboot_setup();
+}
+
+static void zboot_info(void)
 {
 	printf("Kernel loaded at %08lx, setup_base=%p\n",
 	       state.load_address, state.base_ptr);
+}
+
+static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
+			 char *const argv[])
+{
+	zboot_info();
 
 	return 0;
 }
 
+static int _zboot_go(void)
+{
+	int ret;
+
+	ret = zboot_go();
+
+	return ret;
+}
+
 static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
 		       char *const argv[])
 {
 	int ret;
 
-	ret = zboot_go();
-	printf("Kernel returned! (err=%d)\n", ret);
+	ret = _zboot_go();
+	if (ret) {
+		printf("Kernel returned! (err=%d)\n", ret);
+		return CMD_RET_FAILURE;
+	}
 
-	return CMD_RET_FAILURE;
+	return 0;
 }
 
 static int do_zboot_dump(struct cmd_tbl *cmdtp, int flag, int argc,
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#7 lore raw

PATCH 6/13 x86: zboot: Move environment setting into zboot_load()

In reply to Simon Glass

The only difference between the command and the underlying logic is the setting of envrionment variables. Move this out of the command processing since it needs to be done in any case.

---

 arch/x86/lib/zimage.c |  7 +++++++
 cmd/x86/zboot.c       | 16 ++--------------
 2 files changed, 9 insertions(+), 14 deletions(-)
arch/x86/lib/zimage.c +7 -0
index 1d1249fc25ac..b72e2f01bd57 100644
@@ -370,6 +370,7 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 int zboot_load(void)
 {
 	struct boot_params *base_ptr;
+	int ret;
 
 	if (state.base_ptr) {
 		struct boot_params *from = (struct boot_params *)state.base_ptr;
@@ -389,6 +390,12 @@ int zboot_load(void)
 	}
 	state.base_ptr = base_ptr;
 
+	ret = env_set_hex("zbootbase", map_to_sysmem(state.base_ptr));
+	if (!ret)
+		ret = env_set_hex("zbootaddr", state.load_address);
+	if (ret)
+		return ret;
+
 	return 0;
 }
 
cmd/x86/zboot.c +2 -14
index f5c90a8ba896..d39ab6a9698f 100644
@@ -62,30 +62,18 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static int _zboot_load(void)
+static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
+			 char *const argv[])
 {
 	int ret;
 
 	ret = zboot_load();
-	if (!ret)
-		ret = env_set_hex("zbootbase", map_to_sysmem(state.base_ptr));
-	if (!ret)
-		ret = env_set_hex("zbootaddr", state.load_address);
 	if (ret)
 		return ret;
 
 	return 0;
 }
 
-static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
-			 char *const argv[])
-{
-	if (_zboot_load())
-		return CMD_RET_FAILURE;
-
-	return 0;
-}
-
 static int _zboot_setup(void)
 {
 	struct boot_params *base_ptr = state.base_ptr;
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#8 lore raw

PATCH 7/13 x86: zboot: Drop intermediate zboot_setup() function

In reply to Simon Glass

Move error checking into the caller so that do_zboot_setup() can call zboot_setup() directly.

---

 cmd/x86/zboot.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
cmd/x86/zboot.c +6 -10
index d39ab6a9698f..f392b6b3e493 100644
@@ -74,11 +74,10 @@ static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static int _zboot_setup(void)
+static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
+			  char *const argv[])
 {
-	struct boot_params *base_ptr = state.base_ptr;
-
-	if (!base_ptr) {
+	if (!state.base_ptr) {
 		printf("base is not set: use 'zboot load' first\n");
 		return CMD_RET_FAILURE;
 	}
@@ -87,13 +86,10 @@ static int _zboot_setup(void)
 		return CMD_RET_FAILURE;
 	}
 
-	return 0;
-}
+	if (zboot_setup())
+		return CMD_RET_FAILURE;
 
-static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
-			  char *const argv[])
-{
-	return _zboot_setup();
+	return 0;
 }
 
 static void zboot_info(void)
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#9 lore raw

PATCH 8/13 x86: zboot: Drop intermediate zboot_go() function

In reply to Simon Glass

This function only calls zboot_go() so drop it.

---

 cmd/x86/zboot.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
cmd/x86/zboot.c +1 -10
index f392b6b3e493..f49cdd91a1f8 100644
@@ -106,21 +106,12 @@ static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static int _zboot_go(void)
-{
-	int ret;
-
-	ret = zboot_go();
-
-	return ret;
-}
-
 static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
 		       char *const argv[])
 {
 	int ret;
 
-	ret = _zboot_go();
+	ret = zboot_go();
 	if (ret) {
 		printf("Kernel returned! (err=%d)\n", ret);
 		return CMD_RET_FAILURE;
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#10 lore raw

PATCH 9/13 x86: zboot: Move argument processing outside zboot_start()

In reply to Simon Glass

Process the arguments before calling zboot_start() so that we can separate the command line from the internal logic.

---

 cmd/x86/zboot.c | 67 +++++++++++++++++++++----------------------------
 1 file changed, 28 insertions(+), 39 deletions(-)
cmd/x86/zboot.c +28 -39
index f49cdd91a1f8..572b58a5537d 100644
@@ -10,56 +10,45 @@
 #include <vsprintf.h>
 #include <asm/zimage.h>
 
-static void zboot_start(int argc, char *const argv[])
+static int zboot_start(ulong bzimage_addr, ulong bzimage_size,
+		       ulong initrd_addr, ulong initrd_size, ulong base_addr,
+		       const char *cmdline)
 {
-	const char *s;
-
 	memset(&state, '\0', sizeof(state));
-	if (argc >= 2) {
-		/* argv[1] holds the address of the bzImage */
-		s = argv[1];
-	} else {
-		s = env_get("fileaddr");
-	}
 
-	if (s)
-		state.bzimage_addr = hextoul(s, NULL);
-
-	if (argc >= 3) {
-		/* argv[2] holds the size of the bzImage */
-		state.bzimage_size = hextoul(argv[2], NULL);
+	state.bzimage_size = bzimage_size;
+	state.initrd_addr = initrd_addr;
+	state.initrd_size = initrd_size;
+	if (base_addr) {
+		state.base_ptr = map_sysmem(base_addr, 0);
+		state.load_address = bzimage_addr;
+	} else {
+		state.bzimage_addr = bzimage_addr;
 	}
+	state.cmdline = cmdline;
 
-	if (argc >= 4)
-		state.initrd_addr = hextoul(argv[3], NULL);
-	if (argc >= 5)
-		state.initrd_size = hextoul(argv[4], NULL);
-	if (argc >= 6) {
-		/*
-		 * When the base_ptr is passed in, we assume that the image is
-		 * already loaded at the address given by argv[1] and therefore
-		 * the original bzImage is somewhere else, or not accessible.
-		 * In any case, we don't need access to the bzImage since all
-		 * the processing is assumed to be done.
-		 *
-		 * So set the base_ptr to the given address, use this arg as the
-		 * load address and set bzimage_addr to 0 so we know that it
-		 * cannot be proceesed (or processed again).
-		 */
-		state.base_ptr = (void *)hextoul(argv[5], NULL);
-		state.load_address = state.bzimage_addr;
-		state.bzimage_addr = 0;
-	}
-	if (argc >= 7)
-		state.cmdline = env_get(argv[6]);
+	return 0;
 }
 
 static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 			  char *const argv[])
 {
-	zboot_start(argc, argv);
+	ulong bzimage_addr = 0, bzimage_size, initrd_addr, initrd_size;
+	ulong base_addr;
+	const char *s, *cmdline;
 
-	return 0;
+	/* argv[1] holds the address of the bzImage */
+	s = cmd_arg1(argc, argv) ? : env_get("fileaddr");
+	if (s)
+		bzimage_addr = hextoul(s, NULL);
+	bzimage_size = argc > 2 ? hextoul(argv[2], NULL) : 0;
+	initrd_addr = argc > 3 ? hextoul(argv[3], NULL) : 0;
+	initrd_size = argc > 4 ? hextoul(argv[4], NULL) : 0;
+	base_addr = argc > 5 ? hextoul(argv[5], NULL) : 0;
+	cmdline = argc > 6 ? env_get(argv[6]) : NULL;
+
+	return zboot_start(bzimage_addr, bzimage_size, initrd_addr, initrd_size,
+			   base_addr, cmdline);
 }
 
 static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#11 lore raw

PATCH 10/13 x86: zboot: Rename zboot_start() to zboot_run()

In reply to Simon Glass

The term 'start' is used withint bootm and zboot to indicate the first phase of booting an image.

Since zboot_start() does the whole boot, rename it to zboot_run() to align with bootm_run() etc.

Fix a log message while we are here.

---

 arch/x86/lib/zimage.c | 6 +++---
 boot/bootmeth_cros.c  | 6 +++---
 include/bootm.h       | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)
arch/x86/lib/zimage.c +3 -3
index b72e2f01bd57..e8a1849947e6 100644
@@ -437,8 +437,8 @@ int zboot_go(void)
 	return ret;
 }
 
-int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size,
-		ulong base, char *cmdline)
+int zboot_run(ulong addr, ulong size, ulong initrd, ulong initrd_size,
+	      ulong base, char *cmdline)
 {
 	int ret;
 
@@ -463,7 +463,7 @@ int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size,
 		return log_msg_ret("set", ret);
 	ret = zboot_go();
 	if (ret)
-		return log_msg_ret("set", ret);
+		return log_msg_ret("go", ret);
 
 	return -EFAULT;
 }
boot/bootmeth_cros.c +3 -3
index cd72db8250ce..f015f2e1c75f 100644
@@ -432,9 +432,9 @@ static int cros_boot(struct udevice *dev, struct bootflow *bflow)
 	}
 
 	if (IS_ENABLED(CONFIG_X86)) {
-		ret = zboot_start(map_to_sysmem(bflow->buf), bflow->size, 0, 0,
-				  map_to_sysmem(bflow->x86_setup),
-				  bflow->cmdline);
+		ret = zboot_run(map_to_sysmem(bflow->buf), bflow->size, 0, 0,
+				map_to_sysmem(bflow->x86_setup),
+				bflow->cmdline);
 	} else {
 		ret = bootm_boot_start(map_to_sysmem(bflow->buf),
 				       bflow->cmdline);
include/bootm.h +3 -3
index ce5298e4ed97..c815c40e3c4d 100644
@@ -242,7 +242,7 @@ int bootm_process_cmdline(char *buf, int maxlen, int flags);
 int bootm_process_cmdline_env(int flags);
 
 /**
- * zboot_start() - Boot a zimage
+ * zboot_run() - Run through the various steps to boot a zimage
  *
  * Boot a zimage, given the component parts
  *
@@ -255,8 +255,8 @@ int bootm_process_cmdline_env(int flags);
  * @cmdline: Command line to use for booting
  * Return: -EFAULT on error (normally it does not return)
  */
-int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size,
-		ulong base, char *cmdline);
+int zboot_run(ulong addr, ulong size, ulong initrd, ulong initrd_size,
+	      ulong base, char *cmdline);
 
 /*
  * zimage_get_kernel_version() - Get the version string from a kernel
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#12 lore raw

PATCH 11/13 x86: zboot: Separate logic functions from commands

In reply to Simon Glass

Move zboot_start() and zboot_info() in with the other logic functions.

---

 arch/x86/include/asm/zimage.h | 25 +++++++++++++++++++++++++
 arch/x86/lib/zimage.c         | 23 +++++++++++++++++++++++
 cmd/x86/zboot.c               | 32 ++++----------------------------
 3 files changed, 52 insertions(+), 28 deletions(-)
arch/x86/include/asm/zimage.h +25 -0
index ac6683ea9ef3..8b5426051701 100644
@@ -134,4 +134,29 @@ struct boot_params *load_zimage(char *image, unsigned long kernel_size,
 int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 		 ulong initrd_addr, ulong initrd_size, ulong cmdline_force);
 
+/**
+ * zboot_start() - Prepare to boot a zimage
+ *
+ * Record information about a zimage so it can be booted
+ *
+ * @bzimage_addr: Address of the bzImage to boot
+ * @bzimage_size: Size of the bzImage, or 0 to detect this
+ * @initrd_addr: Address of the initial ramdisk, or 0 if none
+ * @initrd_size: Size of the initial ramdisk, or 0 if none
+ * @base_addr: If non-zero, this indicates that the boot parameters have already
+ *	been loaded by the caller to this address, so the load_zimage() call
+ *	in zboot_load() will be skipped when booting
+ * @cmdline: Environment variable containing the 'override' command line, or
+ *	NULL to use the one in the setup block
+ */
+void zboot_start(ulong bzimage_addr, ulong bzimage_size, ulong initrd_addr,
+		 ulong initrd_size, ulong base_addr, const char *cmdline);
+
+/**
+ * zboot_info() - Show simple info about a zimage
+ *
+ * Shows wherer the kernel was loaded and also the setup base
+ */
+void zboot_info(void);
+
 #endif
arch/x86/lib/zimage.c +23 -0
index e8a1849947e6..f2d4f3b50162 100644
@@ -652,3 +652,26 @@ void zimage_dump(struct boot_params *base_ptr, bool show_cmdline)
 	if (get_boot_protocol(hdr, false) >= 0x215)
 		print_num("Kernel info offset", hdr->kernel_info_offset);
 }
+
+void zboot_start(ulong bzimage_addr, ulong bzimage_size, ulong initrd_addr,
+		 ulong initrd_size, ulong base_addr, const char *cmdline)
+{
+	memset(&state, '\0', sizeof(state));
+
+	state.bzimage_size = bzimage_size;
+	state.initrd_addr = initrd_addr;
+	state.initrd_size = initrd_size;
+	if (base_addr) {
+		state.base_ptr = map_sysmem(base_addr, 0);
+		state.load_address = bzimage_addr;
+	} else {
+		state.bzimage_addr = bzimage_addr;
+	}
+	state.cmdline = cmdline;
+}
+
+void zboot_info(void)
+{
+	printf("Kernel loaded at %08lx, setup_base=%p\n",
+	       state.load_address, state.base_ptr);
+}
cmd/x86/zboot.c +4 -28
index 572b58a5537d..addf28cb4aae 100644
@@ -10,26 +10,6 @@
 #include <vsprintf.h>
 #include <asm/zimage.h>
 
-static int zboot_start(ulong bzimage_addr, ulong bzimage_size,
-		       ulong initrd_addr, ulong initrd_size, ulong base_addr,
-		       const char *cmdline)
-{
-	memset(&state, '\0', sizeof(state));
-
-	state.bzimage_size = bzimage_size;
-	state.initrd_addr = initrd_addr;
-	state.initrd_size = initrd_size;
-	if (base_addr) {
-		state.base_ptr = map_sysmem(base_addr, 0);
-		state.load_address = bzimage_addr;
-	} else {
-		state.bzimage_addr = bzimage_addr;
-	}
-	state.cmdline = cmdline;
-
-	return 0;
-}
-
 static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 			  char *const argv[])
 {
@@ -47,8 +27,10 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 	base_addr = argc > 5 ? hextoul(argv[5], NULL) : 0;
 	cmdline = argc > 6 ? env_get(argv[6]) : NULL;
 
-	return zboot_start(bzimage_addr, bzimage_size, initrd_addr, initrd_size,
-			   base_addr, cmdline);
+	zboot_start(bzimage_addr, bzimage_size, initrd_addr, initrd_size,
+		    base_addr, cmdline);
+
+	return 0;
 }
 
 static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -81,12 +63,6 @@ static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static void zboot_info(void)
-{
-	printf("Kernel loaded at %08lx, setup_base=%p\n",
-	       state.load_address, state.base_ptr);
-}
-
 static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
 			 char *const argv[])
 {
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#14 lore raw

PATCH 12/13 x86: zboot: Use zboot_start() in zboot_run()

In reply to Simon Glass

Now that we have a function to start the process of booting a zimage, use it in zboot_run() to avoid duplicated logic.

---

 arch/x86/lib/zimage.c | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)
arch/x86/lib/zimage.c +1 -13
index f2d4f3b50162..d7403876c13d 100644
@@ -442,19 +442,7 @@ int zboot_run(ulong addr, ulong size, ulong initrd, ulong initrd_size,
 {
 	int ret;
 
-	memset(&state, '\0', sizeof(state));
-
-	if (base) {
-		state.base_ptr = map_sysmem(base, 0);
-		state.load_address = addr;
-	} else {
-		state.bzimage_addr = addr;
-	}
-	state.bzimage_size = size;
-	state.initrd_addr = initrd;
-	state.initrd_size = initrd_size;
-	state.cmdline = cmdline;
-
+	zboot_start(addr, size, initrd, initrd_size, base, cmdline);
 	ret = zboot_load();
 	if (ret)
 		return log_msg_ret("ld", ret);
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#15 lore raw

PATCH 13/13 x86: zboot: Tidy up the comment for zboot_run()

In reply to Simon Glass

The current use case (ChromeOS) is the uncommon case. Document how this function is more normally used, where base is 0 and cmdline is NULL

---

 include/bootm.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
include/bootm.h +6 -3
index c815c40e3c4d..1800ca32c264 100644
@@ -248,11 +248,14 @@ int bootm_process_cmdline_env(int flags);
  *
  * @addr: Address where the bzImage is moved before booting, either
  *	BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
- * @base: Pointer to the boot parameters, typically at address
- *	DEFAULT_SETUP_BASE
+ * @size: Size of bzImage, or 0 to detect this
  * @initrd: Address of the initial ramdisk, or 0 if none
  * @initrd_size: Size of the initial ramdisk, or 0 if none
- * @cmdline: Command line to use for booting
+ * @base_addr: If non-zero, this indicates that the boot parameters have already
+ *	been loaded by the caller to this address, so the load_zimage() call
+ *	in zboot_load() will be skipped when booting
+ * @cmdline: If non-NULL, the environment variable containing the command line
+ *	to use for booting
  * Return: -EFAULT on error (normally it does not return)
  */
 int zboot_run(ulong addr, ulong size, ulong initrd, ulong initrd_size,
Signature · 1 line
2.43.0.rc2.451.g8631bc7472-goog
#16 lore raw
In reply to Simon Glass
Quoted 9 lines · Simon Glass

This series refactors the zboot code to allow it to be used with CONFIG_COMMAND disabled.

A new zboot_run() function is used to boot a zimage.

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

Just FYI, at this point all of the required series are now in -next so this could come in via the x86 tree now.

Signature · 1 line
Tom
#17 lore raw
In reply to Simon Glass
Quoted 11 lines · Simon Glass

This series refactors the zboot code to allow it to be used with CONFIG_COMMAND disabled.

A new zboot_run() function is used to boot a zimage.

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

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom