[PATCH v2 10/16] x86: zboot: Add an 'setup' subcommand

Simon Glass sjg at chromium.org
Sat Aug 29 23:41:51 CEST 2020


Add a subcommand that sets up the kernel ready for execution.

Signed-off-by: Simon Glass <sjg at chromium.org>
Reviewed-by: Wolfgang Wallner <wolfgang.wallner at br-automation.com>
---

(no changes since v1)

 arch/x86/lib/zimage.c | 52 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 10 deletions(-)

diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c
index 460282e1312..a39ef9d288f 100644
--- a/arch/x86/lib/zimage.c
+++ b/arch/x86/lib/zimage.c
@@ -68,10 +68,12 @@ struct zboot_state {
 
 enum {
 	ZBOOT_STATE_START	= BIT(0),
-	ZBOOT_STATE_INFO	= BIT(1),
-	ZBOOT_STATE_GO		= BIT(2),
+	ZBOOT_STATE_LOAD	= BIT(1),
+	ZBOOT_STATE_SETUP	= BIT(2),
+	ZBOOT_STATE_INFO	= BIT(3),
+	ZBOOT_STATE_GO		= BIT(4),
 
-	ZBOOT_STATE_COUNT	= 3,
+	ZBOOT_STATE_COUNT	= 5,
 };
 
 static void build_command_line(char *command_line, int auto_boot)
@@ -342,7 +344,6 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 			  char *const argv[])
 {
-	struct boot_params *base_ptr;
 	const char *s;
 
 	memset(&state, '\0', sizeof(state));
@@ -366,19 +367,40 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 	if (argc >= 5)
 		state.initrd_size = simple_strtoul(argv[4], NULL, 16);
 
-	/* Lets look for */
+	return 0;
+}
+
+static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
+			 char *const argv[])
+{
+	struct boot_params *base_ptr;
+
 	base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size,
 			       &state.load_address);
 	if (!base_ptr) {
 		puts("## Kernel loading failed ...\n");
-		return -1;
+		return CMD_RET_FAILURE;
 	}
 	state.base_ptr = base_ptr;
 
-	if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, 0,
-			 state.initrd_addr, state.initrd_size)) {
+	return 0;
+}
+
+static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
+			  char *const argv[])
+{
+	struct boot_params *base_ptr = state.base_ptr;
+	int ret;
+
+	if (!base_ptr) {
+		printf("base is not set: use 'zboot load' first\n");
+		return CMD_RET_FAILURE;
+	}
+	ret = setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
+			   0, state.initrd_addr, state.initrd_size);
+	if (ret) {
 		puts("Setting up boot parameters failed ...\n");
-		return -1;
+		return CMD_RET_FAILURE;
 	}
 
 	return 0;
@@ -410,6 +432,8 @@ static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
 
 U_BOOT_SUBCMDS(zboot,
 	U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
+	U_BOOT_CMD_MKENT(load, 1, 1, do_zboot_load, "", ""),
+	U_BOOT_CMD_MKENT(setup, 1, 1, do_zboot_setup, "", ""),
 	U_BOOT_CMD_MKENT(info, 1, 1, do_zboot_info, "", ""),
 	U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
 )
@@ -451,6 +475,7 @@ int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
 	}
 
 	do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START |
+			ZBOOT_STATE_LOAD | ZBOOT_STATE_SETUP |
 			ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
 
 	return CMD_RET_FAILURE;
@@ -465,6 +490,13 @@ U_BOOT_CMDREP_COMPLETE(
 	"      size -        The optional size of the bzimage. Defaults to\n"
 	"                    zero.\n"
 	"      initrd addr - The address of the initrd image to use, if any.\n"
-	"      initrd size - The size of the initrd image to use, if any.\n",
+	"      initrd size - The size of the initrd image to use, if any.\n"
+	"\n"
+	"Sub-commands to do part of the zboot sequence:\n"
+	"\tstart [addr [arg ...]] - specify arguments\n"
+	"\tload   - load OS image\n"
+	"\tsetup  - set up table\n"
+	"\tinfo   - show sumary info\n"
+	"\tgo     - start OS\n",
 	complete_zboot
 );
-- 
2.28.0.402.g5ffc5be6b7-goog



More information about the U-Boot mailing list