Skip to contentSkip to conversation

x86: zboot: Enhance the 'zboot' command

PATCH Superseded Simon Glass 2 participants 34 messages Aug 1, 2020 – Aug 13, 2020 x86

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover x86: zboot: Enhance the 'zboot' command

This command is currently monolithic and does not support scripts which want to adjust the boot process. This series updates it to be more like 'bootm', in that it has sub-commands for each stage of the boot. This allows some stages to be adjusted or skipped.

It also adds a way to dump out the setup block.

With these changes it is possible to boot an x86 Chrome OS image from a script.

Simon Glass (16):
x86: Update the bootparam header
x86: zimage: Use a state struct to hold the state
x86: zimage: Avoid using #ifdef
x86: zboot: Move kernel-version code into a function
x86: zboot: Correct image type
x86: zimage: Disable interrupts just before booting
x86: zboot: Set up a sub-command structure
x86: zboot: Add a 'go' subcommand
x86: zboot: Add an 'info' subcommand
x86: zboot: Add an 'setup' subcommand
x86: zboot: Set environment variables for image locations
x86: zboot: Allow setting a separate setup base address
x86: zboot: Add an option to dump the setup information
x86: zboot: Allow overriding the command line
cros: Update chromium documentation
cros: Add information about booting Chrome OS on x86

 README                           |   4 +
 arch/x86/include/asm/bootparam.h |  25 +-
 arch/x86/include/asm/e820.h      |   1 +
 arch/x86/include/asm/zimage.h    |  30 +-
 arch/x86/lib/bootm.c             |   2 +-
 arch/x86/lib/zimage.c            | 472 +++++++++++++++++++++++++++----
 doc/README.chromium              |  41 ++-
 7 files changed, 509 insertions(+), 66 deletions(-)
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#1 lore raw

PATCH 1/16 x86: Update the bootparam header

This header is missing a few of the newer features from the specification. Add these as well as a link to the spec. Also use the BIT() macros where appropriate.

---

 arch/x86/include/asm/bootparam.h | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
arch/x86/include/asm/bootparam.h +19 -6
index d961dddc9e1..7a3c1f51554 100644
@@ -24,6 +24,11 @@ struct setup_data {
 	__u8 data[0];
 };
 
+/**
+ * struct setup_header - Information needed by Linux to boot
+ *
+ * See https://www.kernel.org/doc/html/latest/x86/boot.html
+ */
 struct setup_header {
 	__u8	setup_sects;
 	__u16	root_flags;
@@ -43,15 +48,16 @@ struct setup_header {
 	__u16	kernel_version;
 	__u8	type_of_loader;
 	__u8	loadflags;
-#define LOADED_HIGH	(1<<0)
-#define QUIET_FLAG	(1<<5)
-#define KEEP_SEGMENTS	(1<<6)
-#define CAN_USE_HEAP	(1<<7)
+#define LOADED_HIGH	BIT(0)
+#define KASLR_FLAG	BIT(1)
+#define QUIET_FLAG	BIT(5)
+#define KEEP_SEGMENTS	BIT(6)		/* Obsolete */
+#define CAN_USE_HEAP	BIT(7)
 	__u16	setup_move_size;
 	__u32	code32_start;
 	__u32	ramdisk_image;
 	__u32	ramdisk_size;
-	__u32	bootsect_kludge;
+	__u32	bootsect_kludge;	/* Obsolete */
 	__u16	heap_end_ptr;
 	__u8	ext_loader_ver;
 	__u8	ext_loader_type;
@@ -59,7 +65,13 @@ struct setup_header {
 	__u32	initrd_addr_max;
 	__u32	kernel_alignment;
 	__u8	relocatable_kernel;
-	__u8	_pad2[3];
+	u8	min_alignment;
+#define XLF_KERNEL_64			BIT(0)
+#define XLF_CAN_BE_LOADED_ABOVE_4G	BIT(1)
+#define XLF_EFI_HANDOVER_32		BIT(2)
+#define XLF_EFI_HANDOVER_64		BIT(3)
+#define XLF_EFI_KEXEC			BIT(4)
+	u16	xloadflags;
 	__u32	cmdline_size;
 	__u32	hardware_subarch;
 	__u64	hardware_subarch_data;
@@ -69,6 +81,7 @@ struct setup_header {
 	__u64	pref_address;
 	__u32	init_size;
 	__u32	handover_offset;
+	u32	kernel_info_offset;
 } __attribute__((packed));
 
 struct sys_desc_table {
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#2 lore raw

PATCH 1/16 x86: Update the bootparam header

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 11 lines

Betreff: [PATCH 01/16] x86: Update the bootparam header

This header is missing a few of the newer features from the specification. Add these as well as a link to the spec. Also use the BIT() macros where appropriate.

---

 arch/x86/include/asm/bootparam.h | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)
#3 lore raw

PATCH 2/16 x86: zimage: Use a state struct to hold the state

In reply to Simon Glass

At present the 'zboot' command does everything in one go. It would be better if it supported sub-commands like bootm, so it is possible to examine what will be booted before actually booting it.

In preparation for this, move the 'state' of the command into a struct. This will allow it to be shared among multiple functions in this file.

---

 arch/x86/lib/zimage.c | 44 ++++++++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 15 deletions(-)
arch/x86/lib/zimage.c +29 -15
index d2b6002008a..a79971f052c 100644
@@ -45,6 +45,24 @@
 
 #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
+ */
+struct zboot_state {
+	ulong bzimage_addr;
+	ulong bzimage_size;
+	ulong initrd_addr;
+	ulong initrd_size;
+	ulong load_address;
+} state;
+
 static void build_command_line(char *command_line, int auto_boot)
 {
 	char *env_command_line;
@@ -307,15 +325,10 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
 	struct boot_params *base_ptr;
-	void *bzImage_addr = NULL;
-	ulong load_address;
 	char *s;
-	ulong bzImage_size = 0;
-	ulong initrd_addr = 0;
-	ulong initrd_size = 0;
 
 	disable_interrupts();
-
+	memset(&state, '\0', sizeof(state));
 	if (argc >= 2) {
 		/* argv[1] holds the address of the bzImage */
 		s = argv[1];
@@ -324,33 +337,34 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	}
 
 	if (s)
-		bzImage_addr = (void *)simple_strtoul(s, NULL, 16);
+		state.bzimage_addr = simple_strtoul(s, NULL, 16);
 
 	if (argc >= 3) {
 		/* argv[2] holds the size of the bzImage */
-		bzImage_size = simple_strtoul(argv[2], NULL, 16);
+		state.bzimage_size = simple_strtoul(argv[2], NULL, 16);
 	}
 
 	if (argc >= 4)
-		initrd_addr = simple_strtoul(argv[3], NULL, 16);
+		state.initrd_addr = simple_strtoul(argv[3], NULL, 16);
 	if (argc >= 5)
-		initrd_size = simple_strtoul(argv[4], NULL, 16);
+		state.initrd_size = simple_strtoul(argv[4], NULL, 16);
 
 	/* Lets look for */
-	base_ptr = load_zimage(bzImage_addr, bzImage_size, &load_address);
-
+	base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size,
+			       &state.load_address);
 	if (!base_ptr) {
 		puts("## Kernel loading failed ...\n");
 		return -1;
 	}
-	if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
-			0, initrd_addr, initrd_size)) {
+
+	if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, 0,
+			 state.initrd_addr, state.initrd_size)) {
 		puts("Setting up boot parameters failed ...\n");
 		return -1;
 	}
 
 	/* we assume that the kernel is in place */
-	return boot_linux_kernel((ulong)base_ptr, load_address, false);
+	return boot_linux_kernel((ulong)base_ptr, state.load_address, false);
 }
 
 U_BOOT_CMD(
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#4 lore raw

PATCH 2/16 x86: zimage: Use a state struct to hold the state

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 6 lines

Betreff: [PATCH 02/16] x86: zimage: Use a state struct to hold the state

At present the 'zboot' command does everything in one go. It would be better if it supported sub-commands like bootm, so it is possible to examine what will be booted before actually booting it.

Quoted 8 lines

In preparation for this, move the 'state' of the command into a struct. This will allow it to be shared among multiple functions in this file.

---

 arch/x86/lib/zimage.c | 44 ++++++++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 15 deletions(-)
#5 lore raw

PATCH 3/16 x86: zimage: Avoid using #ifdef

In reply to Simon Glass

Use IS_ENABLED() instead of #ifdef in this file.

---

 arch/x86/lib/zimage.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
arch/x86/lib/zimage.c +5 -9
index a79971f052c..3c8081a48bb 100644
@@ -303,21 +303,17 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 		build_command_line(cmd_line, auto_boot);
 	}
 
-#ifdef CONFIG_INTEL_MID
-	if (bootproto >= 0x0207)
+	if (IS_ENABLED(CONFIG_INTEL_MID) && bootproto >= 0x0207)
 		hdr->hardware_subarch = X86_SUBARCH_INTEL_MID;
-#endif
 
-#ifdef CONFIG_GENERATE_ACPI_TABLE
-	setup_base->acpi_rsdp_addr = acpi_get_rsdp_addr();
-#endif
+	if (IS_ENABLED(CONFIG_GENERATE_ACPI_TABLE))
+		setup_base->acpi_rsdp_addr = acpi_get_rsdp_addr();
 
 	setup_device_tree(hdr, (const void *)env_get_hex("fdtaddr", 0));
 	setup_video(&setup_base->screen_info);
 
-#ifdef CONFIG_EFI_STUB
-	setup_efi_info(&setup_base->efi_info);
-#endif
+	if (IS_ENABLED(CONFIG_EFI_STUB))
+		setup_efi_info(&setup_base->efi_info);
 
 	return 0;
 }
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#7 lore raw

PATCH 4/16 x86: zboot: Move kernel-version code into a function

In reply to Simon Glass

To help reduce the size and complexity of load_zimage(), move the code that reads the kernel version into a separate function. Update get_boot_protocol() to allow printing the 'Magic signature' message only once, under control of its callers.

---

 arch/x86/lib/zimage.c | 43 +++++++++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 16 deletions(-)
arch/x86/lib/zimage.c +27 -16
index 3c8081a48bb..b2c3daf225d 100644
@@ -103,21 +103,23 @@ static int kernel_magic_ok(struct setup_header *hdr)
 	}
 }
 
-static int get_boot_protocol(struct setup_header *hdr)
+static int get_boot_protocol(struct setup_header *hdr, bool verbose)
 {
 	if (hdr->header == KERNEL_V2_MAGIC) {
-		printf("Magic signature found\n");
+		if (verbose)
+			printf("Magic signature found\n");
 		return hdr->version;
 	} else {
 		/* Very old kernel */
-		printf("Magic signature not found\n");
+		if (verbose)
+			printf("Magic signature not found\n");
 		return 0x0100;
 	}
 }
 
 static int setup_device_tree(struct setup_header *hdr, const void *fdt_blob)
 {
-	int bootproto = get_boot_protocol(hdr);
+	int bootproto = get_boot_protocol(hdr, false);
 	struct setup_data *sd;
 	int size;
 
@@ -147,10 +149,24 @@ static int setup_device_tree(struct setup_header *hdr, const void *fdt_blob)
 	return 0;
 }
 
+static const char *get_kernel_version(struct boot_params *params,
+				      void *kernel_base)
+{
+	struct setup_header *hdr = &params->hdr;
+	int bootproto;
+
+	bootproto = get_boot_protocol(hdr, false);
+	if (bootproto < 0x0200 || hdr->setup_sects < 15)
+		return NULL;
+
+	return kernel_base + hdr->kernel_version + 0x200;
+}
+
 struct boot_params *load_zimage(char *image, unsigned long kernel_size,
 				ulong *load_addressp)
 {
 	struct boot_params *setup_base;
+	const char *version;
 	int setup_size;
 	int bootproto;
 	int big_image;
@@ -178,21 +194,16 @@ struct boot_params *load_zimage(char *image, unsigned long kernel_size,
 		printf("Error: Setup is too large (%d bytes)\n", setup_size);
 
 	/* determine boot protocol version */
-	bootproto = get_boot_protocol(hdr);
+	bootproto = get_boot_protocol(hdr, true);
 
 	printf("Using boot protocol version %x.%02x\n",
 	       (bootproto & 0xff00) >> 8, bootproto & 0xff);
 
-	if (bootproto >= 0x0200) {
-		if (hdr->setup_sects >= 15) {
-			printf("Linux kernel version %s\n",
-				(char *)params +
-				hdr->kernel_version + 0x200);
-		} else {
-			printf("Setup Sectors < 15 - "
-				"Cannot print kernel version.\n");
-		}
-	}
+	version = get_kernel_version(params, image);
+	if (version)
+		printf("Linux kernel version %s\n", version);
+	else
+		printf("Setup Sectors < 15 - Cannot print kernel version\n");
 
 	/* Determine image type */
 	big_image = (bootproto >= 0x0200) &&
@@ -261,7 +272,7 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 		 unsigned long initrd_addr, unsigned long initrd_size)
 {
 	struct setup_header *hdr = &setup_base->hdr;
-	int bootproto = get_boot_protocol(hdr);
+	int bootproto = get_boot_protocol(hdr, false);
 
 	setup_base->e820_entries = install_e820_map(
 		ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map);
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#8 lore raw

PATCH 4/16 x86: zboot: Move kernel-version code into a function

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 7 lines

Betreff: [PATCH 04/16] x86: zboot: Move kernel-version code into a function

To help reduce the size and complexity of load_zimage(), move the code that reads the kernel version into a separate function. Update get_boot_protocol() to allow printing the 'Magic signature' message only once, under control of its callers.

Quoted 5 lines

---

 arch/x86/lib/zimage.c | 43 +++++++++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 16 deletions(-)
#9 lore raw

PATCH 5/16 x86: zboot: Correct image type

In reply to Simon Glass

At present U-Boot sets a loader type of 8 which means LILO version 8, according to the spec. Update it to 0x80, which means U-Boot with no particular version.

---

 arch/x86/lib/zimage.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/lib/zimage.c +1 -2
index b2c3daf225d..ba9eb50b0ba 100644
@@ -282,8 +282,7 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 		setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET;
 	}
 	if (bootproto >= 0x0200) {
-		hdr->type_of_loader = 8;
-
+		hdr->type_of_loader = 0x80;	/* U-Boot version 0 */
 		if (initrd_addr) {
 			printf("Initial RAM disk at linear address "
 			       "0x%08lx, size %ld bytes\n",
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#10 lore raw

PATCH 5/16 x86: zboot: Correct image type

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 11 lines

Betreff: [PATCH 05/16] x86: zboot: Correct image type

At present U-Boot sets a loader type of 8 which means LILO version 8, according to the spec. Update it to 0x80, which means U-Boot with no particular version.

---

 arch/x86/lib/zimage.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
#11 lore raw

PATCH 6/16 x86: zimage: Disable interrupts just before booting

In reply to Simon Glass

At present if an error occurs while setting up the boot, interrupts are left disabled. Move this call later in the sequence to avoid this problem.

---

 arch/x86/lib/zimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/lib/zimage.c +1 -1
index ba9eb50b0ba..8651dea93b3 100644
@@ -333,7 +333,6 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	struct boot_params *base_ptr;
 	char *s;
 
-	disable_interrupts();
 	memset(&state, '\0', sizeof(state));
 	if (argc >= 2) {
 		/* argv[1] holds the address of the bzImage */
@@ -369,6 +368,7 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		return -1;
 	}
 
+	disable_interrupts();
 	/* we assume that the kernel is in place */
 	return boot_linux_kernel((ulong)base_ptr, state.load_address, false);
 }
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#12 lore raw

PATCH 6/16 x86: zimage: Disable interrupts just before booting

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 10 lines

Betreff: [PATCH 06/16] x86: zimage: Disable interrupts just before booting

At present if an error occurs while setting up the boot, interrupts are left disabled. Move this call later in the sequence to avoid this problem.

---

 arch/x86/lib/zimage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#13 lore raw

PATCH 7/16 x86: zboot: Set up a sub-command structure

In reply to Simon Glass

Add subcommands to zboot. At present there is only one called 'start' which does the whole boot. It is the default command so is optional.

Change the 's' string variable to const while we are here.

---

 arch/x86/lib/zimage.c | 64 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 58 insertions(+), 6 deletions(-)
arch/x86/lib/zimage.c +58 -6
index 8651dea93b3..3d3fe6ec05f 100644
@@ -63,6 +63,12 @@ struct zboot_state {
 	ulong load_address;
 } state;
 
+enum {
+	ZBOOT_STATE_START	= BIT(0),
+
+	ZBOOT_STATE_COUNT	= 1,
+};
+
 static void build_command_line(char *command_line, int auto_boot)
 {
 	char *env_command_line;
@@ -328,10 +334,11 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 	return 0;
 }
 
-int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
+			  char *const argv[])
 {
 	struct boot_params *base_ptr;
-	char *s;
+	const char *s;
 
 	memset(&state, '\0', sizeof(state));
 	if (argc >= 2) {
@@ -373,9 +380,53 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	return boot_linux_kernel((ulong)base_ptr, state.load_address, false);
 }
 
-U_BOOT_CMD(
-	zboot, 5, 0,	do_zboot,
-	"Boot bzImage",
+U_BOOT_SUBCMDS(zboot,
+	U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
+)
+
+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;
+		}
+	}
+
+	return 0;
+}
+
+int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
+		    char *const argv[], int *repeatable)
+{
+	/* determine if we have a sub command */
+	if (argc > 1) {
+		char *endp;
+
+		simple_strtoul(argv[1], &endp, 16);
+		/*
+		 * endp pointing to nul means that argv[0] was just a valid
+		 * number, so pass it along to the normal processing
+		 */
+		if (*endp)
+			return do_zboot(cmdtp, flag, argc, argv, repeatable);
+	}
+
+	do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START);
+
+	return CMD_RET_FAILURE;
+}
+
+U_BOOT_CMDREP_COMPLETE(
+	zboot, 8, do_zboot_parent, "Boot bzImage",
 	"[addr] [size] [initrd addr] [initrd size]\n"
 	"      addr -        The optional starting address of the bzimage.\n"
 	"                    If not set it defaults to the environment\n"
@@ -383,5 +434,6 @@ U_BOOT_CMD(
 	"      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",
+	complete_zboot
 );
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#14 lore raw

PATCH 7/16 x86: zboot: Set up a sub-command structure

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 75 lines

Betreff: [PATCH 07/16] x86: zboot: Set up a sub-command structure

Add subcommands to zboot. At present there is only one called 'start' which does the whole boot. It is the default command so is optional.

Change the 's' string variable to const while we are here.

---

 arch/x86/lib/zimage.c | 64 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 58 insertions(+), 6 deletions(-)
arch/x86/lib/zimage.c +33 -5
index 8651dea93b3..3d3fe6ec05f 100644
@@ -63,6 +63,12 @@ struct zboot_state {
 	ulong load_address;
 } state;
 
+enum {
+	ZBOOT_STATE_START	= BIT(0),
+
+	ZBOOT_STATE_COUNT	= 1,
+};
+
 static void build_command_line(char *command_line, int auto_boot)
 {
 	char *env_command_line;
@@ -328,10 +334,11 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 	return 0;
 }
 
-int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
+			  char *const argv[])
 {
 	struct boot_params *base_ptr;
-	char *s;
+	const char *s;
 
 	memset(&state, '\0', sizeof(state));
 	if (argc >= 2) {
@@ -373,9 +380,53 @@ int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	return boot_linux_kernel((ulong)base_ptr, state.load_address, false);
 }
 
-U_BOOT_CMD(
-	zboot, 5, 0,	do_zboot,
-	"Boot bzImage",
+U_BOOT_SUBCMDS(zboot,
+	U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
+)
+
+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;
+		}
+	}
+
+	return 0;
+}
+

arch/x86/lib/zimage.c int do_zboot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) · line 416

Quoted 10 lines
arch/x86/lib/zimage.c +10 -0
+int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
+		    char *const argv[], int *repeatable)
+{
+	/* determine if we have a sub command */
+	if (argc > 1) {
+		char *endp;
+
+		simple_strtoul(argv[1], &endp, 16);
+		/*
+		 * endp pointing to nul means that argv[0] was just a valid

Do you mean argv[1] in this comment? Because that's what is checked with simple_strtoul.

Quoted 26 lines
arch/x86/lib/zimage.c +15 -1
+		 * number, so pass it along to the normal processing
+		 */
+		if (*endp)
+			return do_zboot(cmdtp, flag, argc, argv, repeatable);
+	}
+
+	do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START);
+
+	return CMD_RET_FAILURE;
+}
+
+U_BOOT_CMDREP_COMPLETE(
+	zboot, 8, do_zboot_parent, "Boot bzImage",
 	"[addr] [size] [initrd addr] [initrd size]\n"
 	"      addr -        The optional starting address of the bzimage.\n"
 	"                    If not set it defaults to the environment\n"
@@ -383,5 +434,6 @@ U_BOOT_CMD(
 	"      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",
+	complete_zboot
 );
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog

regards, Wolfgang

#15 lore raw

PATCH 8/16 x86: zboot: Add a 'go' subcommand

In reply to Simon Glass

Split out the code that actually boots linux into a separate sub-command. Add base_ptr to the state to support this.

Show an error if the boot fails, since this should not happen.

---

 arch/x86/lib/zimage.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
arch/x86/lib/zimage.c +23 -3
index 3d3fe6ec05f..5b096e9b0b0 100644
@@ -54,6 +54,8 @@
  * @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
  */
 struct zboot_state {
 	ulong bzimage_addr;
@@ -61,12 +63,14 @@ struct zboot_state {
 	ulong initrd_addr;
 	ulong initrd_size;
 	ulong load_address;
+	struct boot_params *base_ptr;
 } state;
 
 enum {
 	ZBOOT_STATE_START	= BIT(0),
+	ZBOOT_STATE_GO		= BIT(1),
 
-	ZBOOT_STATE_COUNT	= 1,
+	ZBOOT_STATE_COUNT	= 2,
 };
 
 static void build_command_line(char *command_line, int auto_boot)
@@ -368,6 +372,7 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 		puts("## Kernel loading failed ...\n");
 		return -1;
 	}
+	state.base_ptr = base_ptr;
 
 	if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, 0,
 			 state.initrd_addr, state.initrd_size)) {
@@ -375,13 +380,27 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 		return -1;
 	}
 
+	return 0;
+}
+
+static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
+		       char *const argv[])
+{
+	int ret;
+
 	disable_interrupts();
+
 	/* we assume that the kernel is in place */
-	return boot_linux_kernel((ulong)base_ptr, state.load_address, false);
+	ret = boot_linux_kernel((ulong)state.base_ptr, state.load_address,
+				false);
+	printf("Kernel returned! (err=%d)\n", ret);
+
+	return CMD_RET_FAILURE;
 }
 
 U_BOOT_SUBCMDS(zboot,
 	U_BOOT_CMD_MKENT(start, 8, 1, do_zboot_start, "", ""),
+	U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
 )
 
 int do_zboot_states(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -420,7 +439,8 @@ int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
 			return do_zboot(cmdtp, flag, argc, argv, repeatable);
 	}
 
-	do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START);
+	do_zboot_states(cmdtp, flag, argc, argv, ZBOOT_STATE_START |
+			ZBOOT_STATE_GO);
 
 	return CMD_RET_FAILURE;
 }
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#16 lore raw

PATCH 8/16 x86: zboot: Add a 'go' subcommand

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 5 lines

Betreff: [PATCH 08/16] x86: zboot: Add a 'go' subcommand

Split out the code that actually boots linux into a separate sub-command. Add base_ptr to the state to support this.

Quoted 7 lines

Show an error if the boot fails, since this should not happen.

---

 arch/x86/lib/zimage.c | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
#17 lore raw

PATCH 9/16 x86: zboot: Add an 'info' subcommand

In reply to Simon Glass

Add a little subcommand that prints out where the kernel was loaded and its setup pointer. Run it by default in the normal boot.

---

 arch/x86/lib/zimage.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
arch/x86/lib/zimage.c +14 -3
index 5b096e9b0b0..2210ff69b72 100644
@@ -68,9 +68,10 @@ struct zboot_state {
 
 enum {
 	ZBOOT_STATE_START	= BIT(0),
-	ZBOOT_STATE_GO		= BIT(1),
+	ZBOOT_STATE_INFO	= BIT(1),
+	ZBOOT_STATE_GO		= BIT(2),
 
-	ZBOOT_STATE_COUNT	= 2,
+	ZBOOT_STATE_COUNT	= 3,
 };
 
 static void build_command_line(char *command_line, int auto_boot)
@@ -383,6 +384,15 @@ static int do_zboot_start(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[])
+{
+	printf("Kernel loaded at %08lx, setup_base=%p\n",
+	       state.load_address, state.base_ptr);
+
+	return 0;
+}
+
 static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
 		       char *const argv[])
 {
@@ -400,6 +410,7 @@ 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(info, 1, 1, do_zboot_info, "", ""),
 	U_BOOT_CMD_MKENT(go, 1, 1, do_zboot_go, "", ""),
 )
 
@@ -440,7 +451,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_GO);
+			ZBOOT_STATE_INFO | ZBOOT_STATE_GO);
 
 	return CMD_RET_FAILURE;
 }
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#18 lore raw

PATCH 9/16 x86: zboot: Add an 'info' subcommand

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 10 lines

Betreff: [PATCH 09/16] x86: zboot: Add an 'info' subcommand

Add a little subcommand that prints out where the kernel was loaded and its setup pointer. Run it by default in the normal boot.

---

 arch/x86/lib/zimage.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
#19 lore raw

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

In reply to Simon Glass

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

---

 arch/x86/lib/zimage.c | 52 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 10 deletions(-)
arch/x86/lib/zimage.c +42 -10
index 2210ff69b72..49f43721415 100644
@@ -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
 );
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#20 lore raw

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

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 9 lines

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

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

---

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

PATCH 11/16 x86: zboot: Set environment variables for image locations

In reply to Simon Glass

At present it is not possible to tell from a script where the setup block is, or where the image was loaded to. Add environment variables for this.

---

 README                | 4 ++++
 arch/x86/lib/zimage.c | 3 +++
 2 files changed, 7 insertions(+)
README +4 -0
index d4bf74ce75d..13ac6dd373d 100644
@@ -3462,6 +3462,10 @@ List of environment variables (most likely not complete):
   mempos	- Index position of the last match found by the 'ms' command,
 		  in units of the size (.b, .w, .l) of the search
 
+  zbootbase	- Base address of the bzImage 'setup' block
+
+  zbootaddr	- Address of the loaded bzImage, typically BZIMAGE_LOAD_ADDR
+		  which is 0x100000
 
 The following image location variables contain the location of images
 used in booting. The "Image" column gives the role of the image and is
arch/x86/lib/zimage.c +3 -0
index 49f43721415..4a0a69c8f7c 100644
@@ -382,6 +382,9 @@ static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
 		return CMD_RET_FAILURE;
 	}
 	state.base_ptr = base_ptr;
+	if (env_set_hex("zbootbase", (ulong)base_ptr) ||
+	    env_set_hex("zbootaddr", state.load_address))
+		return CMD_RET_FAILURE;
 
 	return 0;
 }
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#22 lore raw

PATCH 11/16 x86: zboot: Set environment variables for image locations

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 11 lines

Betreff: [PATCH 11/16] x86: zboot: Set environment variables for image locations

At present it is not possible to tell from a script where the setup block is, or where the image was loaded to. Add environment variables for this.

---

 README                | 4 ++++
 arch/x86/lib/zimage.c | 3 +++
 2 files changed, 7 insertions(+)
#23 lore raw

PATCH 12/16 x86: zboot: Allow setting a separate setup base address

In reply to Simon Glass

At present the setup block is always obtained from the image automatically. In some cases it can be useful to use a setup block obtained elsewhere, e.g. if the image has already been unpacked. Add an argument to support this and update the logic to use it if provided.

---

 arch/x86/lib/zimage.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
arch/x86/lib/zimage.c +22 -6
index 4a0a69c8f7c..b64d0196f2d 100644
@@ -366,6 +366,11 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 		state.initrd_addr = simple_strtoul(argv[3], NULL, 16);
 	if (argc >= 5)
 		state.initrd_size = simple_strtoul(argv[4], NULL, 16);
+	if (argc >= 6) {
+		state.base_ptr = (void *)simple_strtoul(argv[5], NULL, 16);
+		state.load_address = state.bzimage_addr;
+		state.bzimage_addr = 0;
+	}
 
 	return 0;
 }
@@ -375,11 +380,20 @@ static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
 {
 	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 CMD_RET_FAILURE;
+	if (state.base_ptr) {
+		struct boot_params *from = (struct boot_params *)state.base_ptr;
+
+		base_ptr = (struct boot_params *)DEFAULT_SETUP_BASE;
+		printf("Building boot_params at 0x%8.8lx\n", (ulong)base_ptr);
+		memset(base_ptr, '\0', sizeof(*base_ptr));
+		base_ptr->hdr = from->hdr;
+	} else {
+		base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size,
+				       &state.load_address);
+		if (!base_ptr) {
+			puts("## Kernel loading failed ...\n");
+			return CMD_RET_FAILURE;
+		}
 	}
 	state.base_ptr = base_ptr;
 	if (env_set_hex("zbootbase", (ulong)base_ptr) ||
@@ -486,7 +500,7 @@ int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
 
 U_BOOT_CMDREP_COMPLETE(
 	zboot, 8, do_zboot_parent, "Boot bzImage",
-	"[addr] [size] [initrd addr] [initrd size]\n"
+	"[addr] [size] [initrd addr] [initrd size] [setup]\n"
 	"      addr -        The optional starting address of the bzimage.\n"
 	"                    If not set it defaults to the environment\n"
 	"                    variable \"fileaddr\".\n"
@@ -494,6 +508,8 @@ U_BOOT_CMDREP_COMPLETE(
 	"                    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"
+	"      setup -       The address of the kernel setup region, if this\n"
+	"                    is not at addr\n"
 	"\n"
 	"Sub-commands to do part of the zboot sequence:\n"
 	"\tstart [addr [arg ...]] - specify arguments\n"
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#24 lore raw

PATCH 12/16 x86: zboot: Allow setting a separate setup base address

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 18 lines

Betreff: [PATCH 12/16] x86: zboot: Allow setting a separate setup base address

At present the setup block is always obtained from the image automatically. In some cases it can be useful to use a setup block obtained elsewhere, e.g. if the image has already been unpacked. Add an argument to support this and update the logic to use it if provided.

---

 arch/x86/lib/zimage.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
arch/x86/lib/zimage.c +0 -0
index 4a0a69c8f7c..b64d0196f2d 100644

arch/x86/lib/zimage.c static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc, · line 372

Quoted 7 lines
arch/x86/lib/zimage.c +4 -0
@@ -366,6 +366,11 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 		state.initrd_addr = simple_strtoul(argv[3], NULL, 16);
 	if (argc >= 5)
 		state.initrd_size = simple_strtoul(argv[4], NULL, 16);
+	if (argc >= 6) {
+		state.base_ptr = (void *)simple_strtoul(argv[5], NULL, 16);
+		state.load_address = state.bzimage_addr;
+		state.bzimage_addr = 0;

Nit: I found it rather confusing to understand what is going in the case when this parameter is used compared to the 'normal' operation. Maybe you could add comments here or in do_zboot_load() when the parameter is used?

Quoted 50 lines
arch/x86/lib/zimage.c +18 -6
+	}
 
 	return 0;
 }
@@ -375,11 +380,20 @@ static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
 {
 	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 CMD_RET_FAILURE;
+	if (state.base_ptr) {
+		struct boot_params *from = (struct boot_params *)state.base_ptr;
+
+		base_ptr = (struct boot_params *)DEFAULT_SETUP_BASE;
+		printf("Building boot_params at 0x%8.8lx\n", (ulong)base_ptr);
+		memset(base_ptr, '\0', sizeof(*base_ptr));
+		base_ptr->hdr = from->hdr;
+	} else {
+		base_ptr = load_zimage((void *)state.bzimage_addr, state.bzimage_size,
+				       &state.load_address);
+		if (!base_ptr) {
+			puts("## Kernel loading failed ...\n");
+			return CMD_RET_FAILURE;
+		}
 	}
 	state.base_ptr = base_ptr;
 	if (env_set_hex("zbootbase", (ulong)base_ptr) ||
@@ -486,7 +500,7 @@ int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
 
 U_BOOT_CMDREP_COMPLETE(
 	zboot, 8, do_zboot_parent, "Boot bzImage",
-	"[addr] [size] [initrd addr] [initrd size]\n"
+	"[addr] [size] [initrd addr] [initrd size] [setup]\n"
 	"      addr -        The optional starting address of the bzimage.\n"
 	"                    If not set it defaults to the environment\n"
 	"                    variable \"fileaddr\".\n"
@@ -494,6 +508,8 @@ U_BOOT_CMDREP_COMPLETE(
 	"                    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"
+	"      setup -       The address of the kernel setup region, if this\n"
+	"                    is not at addr\n"
 	"\n"
 	"Sub-commands to do part of the zboot sequence:\n"
 	"\tstart [addr [arg ...]] - specify arguments\n"
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#25 lore raw

PATCH 13/16 x86: zboot: Add an option to dump the setup information

In reply to Simon Glass

There is a lot of information in the setup block and it is quite hard to decode manually. Add a 'zboot dump' command to decode it into a human-readable format.

---

 arch/x86/include/asm/e820.h |   1 +
 arch/x86/lib/zimage.c       | 199 +++++++++++++++++++++++++++++++++++-
 2 files changed, 199 insertions(+), 1 deletion(-)
arch/x86/include/asm/e820.h +1 -0
index 9d29f82f972..d7f8a4ba1df 100644
@@ -8,6 +8,7 @@
 #define E820_ACPI	3
 #define E820_NVS	4
 #define E820_UNUSABLE	5
+#define E820_COUNT	6	/* Number of types */
 
 #ifndef __ASSEMBLY__
 #include <linux/types.h>
arch/x86/lib/zimage.c +198 -1

222 lines not on this page · raw message

Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#26 lore raw

PATCH 13/16 x86: zboot: Add an option to dump the setup information

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 6 lines

Betreff: [PATCH 13/16] x86: zboot: Add an option to dump the setup information

There is a lot of information in the setup block and it is quite hard to decode manually. Add a 'zboot dump' command to decode it into a human-readable format.

Quoted 6 lines

---

 arch/x86/include/asm/e820.h |   1 +
 arch/x86/lib/zimage.c       | 199 +++++++++++++++++++++++++++++++++++-
 2 files changed, 199 insertions(+), 1 deletion(-)
#27 lore raw

PATCH 14/16 x86: zboot: Allow overriding the command line

In reply to Simon Glass

When booting Chrome OS images the command line is stored separately from the kernel. Add a way to specify this address so that images boot correctly.

Also add comments to the zimage.h header.

---

 arch/x86/include/asm/zimage.h | 30 +++++++++++++++++++++++++++++-
 arch/x86/lib/bootm.c          |  2 +-
 arch/x86/lib/zimage.c         | 21 ++++++++++++++++-----
 3 files changed, 46 insertions(+), 7 deletions(-)
arch/x86/include/asm/zimage.h +29 -1
index 80e128ccf36..64c0e6e857b 100644
@@ -30,10 +30,38 @@
 #define BZIMAGE_LOAD_ADDR  0x100000
 #define ZIMAGE_LOAD_ADDR   0x10000
 
+/**
+ * load_zimage() - Load a zImage or bzImage
+ *
+ * This copies an image into the standard location ready for setup
+ *
+ * @image: Address of image to load
+ * @kernel_size: Size of kernel including setup block (or 0 if the kernel is
+ *	new enough to have a 'syssize' value)
+ * @load_addressp: Returns the address where the kernel has been loaded
+ * @return address of setup block, or NULL if something went wrong
+ */
 struct boot_params *load_zimage(char *image, unsigned long kernel_size,
 				ulong *load_addressp);
+
+/**
+ * setup_zimage() - Set up a loaded zImage or bzImage ready for booting
+ *
+ * @setup_base: Pointer to the boot parameters, typically at address
+ *	DEFAULT_SETUP_BASE
+ * @cmd_line: Place to put the command line, or NULL to use the one in the setup
+ *	block
+ * @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
+ * @cmdline_force: Address of 'override' command line, or 0 to use the one in
+ *	the *	setup block
+ * @return 0 (always)
+ */
 int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
-		 unsigned long initrd_addr, unsigned long initrd_size);
+		 ulong initrd_addr, ulong initrd_size, ulong cmdline_force);
+
 void setup_video(struct screen_info *screen_info);
 void setup_efi_info(struct efi_info *efi_info);
 
arch/x86/lib/bootm.c +1 -1
index 1198a52ecac..da6b8ce1ec1 100644
@@ -136,7 +136,7 @@ static int boot_prep_linux(bootm_headers_t *images)
 	printf("Setup at %#08lx\n", images->ep);
 	ret = setup_zimage((void *)images->ep, cmd_line_dest,
 			0, images->rd_start,
-			images->rd_end - images->rd_start);
+			images->rd_end - images->rd_start, 0);
 
 	if (ret) {
 		printf("## Setting up boot parameters failed ...\n");
arch/x86/lib/zimage.c +16 -5
index 140dc5cebb6..187eba80221 100644
@@ -56,6 +56,8 @@
  *	BZIMAGE_LOAD_ADDR or ZIMAGE_LOAD_ADDR
  * @base_ptr: Pointer to the boot parameters, typically at address
  *	DEFAULT_SETUP_BASE
+ * @cmdline: Address of 'override' command line, or 0 to use the one in the
+ *	setup block
  */
 struct zboot_state {
 	ulong bzimage_addr;
@@ -64,6 +66,7 @@ struct zboot_state {
 	ulong initrd_size;
 	ulong load_address;
 	struct boot_params *base_ptr;
+	ulong cmdline;
 } state;
 
 enum {
@@ -284,7 +287,7 @@ 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,
-		 unsigned long initrd_addr, unsigned long initrd_size)
+		 ulong initrd_addr, ulong initrd_size, ulong cmdline_force)
 {
 	struct setup_header *hdr = &setup_base->hdr;
 	int bootproto = get_boot_protocol(hdr, false);
@@ -325,7 +328,10 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
 		}
 
 		/* build command line at COMMAND_LINE_OFFSET */
-		build_command_line(cmd_line, auto_boot);
+		if (cmdline_force)
+			strcpy(cmd_line, (char *)cmdline_force);
+		else
+			build_command_line(cmd_line, auto_boot);
 	}
 
 	if (IS_ENABLED(CONFIG_INTEL_MID) && bootproto >= 0x0207)
@@ -373,6 +379,8 @@ static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 		state.load_address = state.bzimage_addr;
 		state.bzimage_addr = 0;
 	}
+	if (argc >= 7)
+		state.cmdline = simple_strtoul(argv[6], NULL, 16);
 
 	return 0;
 }
@@ -416,7 +424,8 @@ static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
 		return CMD_RET_FAILURE;
 	}
 	ret = setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
-			   0, state.initrd_addr, state.initrd_size);
+			   0, state.initrd_addr, state.initrd_size,
+			   state.cmdline);
 	if (ret) {
 		puts("Setting up boot parameters failed ...\n");
 		return CMD_RET_FAILURE;
@@ -616,7 +625,7 @@ int do_zboot_dump(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	if (hdr->cmd_line_ptr) {
 		printf("   ");
 		/* Use puts() to avoid limits from CONFIG_SYS_PBSIZE */
-		puts((char *)hdr->cmd_line_ptr);
+		puts((char *)(ulong)hdr->cmd_line_ptr);
 		printf("\n");
 	}
 	print_num("Initrd addr max", hdr->initrd_addr_max);
@@ -696,7 +705,7 @@ int do_zboot_parent(struct cmd_tbl *cmdtp, int flag, int argc,
 
 U_BOOT_CMDREP_COMPLETE(
 	zboot, 8, do_zboot_parent, "Boot bzImage",
-	"[addr] [size] [initrd addr] [initrd size] [setup]\n"
+	"[addr] [size] [initrd addr] [initrd size] [setup] [cmdline]\n"
 	"      addr -        The optional starting address of the bzimage.\n"
 	"                    If not set it defaults to the environment\n"
 	"                    variable \"fileaddr\".\n"
@@ -706,6 +715,8 @@ U_BOOT_CMDREP_COMPLETE(
 	"      initrd size - The size of the initrd image to use, if any.\n"
 	"      setup -       The address of the kernel setup region, if this\n"
 	"                    is not at addr\n"
+	"      cmdline -     The address of the kernel command line, to\n"
+	"                    override U-Boot's normal cmdline generation\n"
 	"\n"
 	"Sub-commands to do part of the zboot sequence:\n"
 	"\tstart [addr [arg ...]] - specify arguments\n"
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#28 lore raw

PATCH 14/16 x86: zboot: Allow overriding the command line

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 8 lines

Betreff: [PATCH 14/16] x86: zboot: Allow overriding the command line

When booting Chrome OS images the command line is stored separately from the kernel. Add a way to specify this address so that images boot correctly.

Also add comments to the zimage.h header.

Quoted 7 lines

---

 arch/x86/include/asm/zimage.h | 30 +++++++++++++++++++++++++++++-
 arch/x86/lib/bootm.c          |  2 +-
 arch/x86/lib/zimage.c         | 21 ++++++++++++++++-----
 3 files changed, 46 insertions(+), 7 deletions(-)
#29 lore raw

PATCH 15/16 cros: Update chromium documentation

In reply to Simon Glass

A few things have changed since this was written about 18 months ago. Update the README.

---

 doc/README.chromium | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
doc/README.chromium +6 -3
index 8f67da6c728..c56545cb7ff 100644
@@ -23,6 +23,10 @@ available:
         from U-Boot in 2013) and coreboot. See below for more information on
         this.
 
+   - Running U-Boot from coreboot. This allows U-Boot to run on more devices
+        since many of them only support coreboot as the bootloader and have
+        no bare-metal support in U-Boot. For this, use the 'coreboot' target.
+
 
 U-Boot with Chromium OS verified boot
 -------------------------------------
@@ -168,14 +172,13 @@ existed in U-Boot were not brought over to coreboot or depthcharge.
 The U-Boot tests ('make check') do operate, but at present there are no
 Chromium OS tests available. These will hopefully come together over time. Of
 course the above sandbox feature provides a sort of functional test and can
-detecte problems that affect the flow or particular vboot features.
+detect problems that affect the flow or particular vboot features.
 
 
 TO DO
 -----
 
-- Support for booting from coreboot (patches expected March 2019)
-- Support for booting from an ARM board, e.g. bob
+Get the full ACPI tables working with Coral
 
 
 Simon Glass
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#30 lore raw

PATCH 15/16 cros: Update chromium documentation

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 10 lines

Betreff: [PATCH 15/16] cros: Update chromium documentation

A few things have changed since this was written about 18 months ago. Update the README.

---

 doc/README.chromium | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
#31 lore raw

PATCH 16/16 cros: Add information about booting Chrome OS on x86

In reply to Simon Glass

Recent versions of Chrome OS do not have a kernel in the root disk, to save space.

With the improvements to the 'zboot' command it is fairly easy to load the kernel from the raw partition. Add instructions on how to do this.

---

 doc/README.chromium | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
doc/README.chromium +32 -0
index c56545cb7ff..75f2f24042c 100644
@@ -27,6 +27,9 @@ available:
         since many of them only support coreboot as the bootloader and have
         no bare-metal support in U-Boot. For this, use the 'coreboot' target.
 
+   - Running U-Boot and booting into a Chrome OS image, but without verified
+        boot. This can be useful for testing.
+
 
 U-Boot with Chromium OS verified boot
 -------------------------------------
@@ -175,6 +178,35 @@ course the above sandbox feature provides a sort of functional test and can
 detect problems that affect the flow or particular vboot features.
 
 
+U-Boot without Chromium OS verified boot
+----------------------------------------
+
+The following script can be used to boot a Chrome OS image on coral:
+
+   # Read the image header and obtain the address of the kernel
+   # The offset 4f0 is defined by verified boot and may change for other
+   # Chromebooks
+   read mmc 2:2 100000 0 80; setexpr loader *001004f0;
+
+   # Get the kernel size and calculate the number of blocks (0x200 bytes each)
+   setexpr size *00100518; setexpr blocks $size / 200;
+
+   # Read the full kernel and calculate the address of the setup block
+   read mmc 2:2 100000 80 $blocks; setexpr setup $loader - 1000;
+
+   # Locate the command line
+   setexpr cmdline $loader - 2000;
+
+   # Start the zboot process with the loaded kernel, setup block and cmdline
+   zboot start 100000 0 0 0 $setup $cmdline;
+
+   # Load the kernel, fix up the 'setup' block, dump information
+   zboot load; zboot setup; zboot dump
+
+   # Boot into Chrome OS
+   zboot go
+
+
 TO DO
 -----
 
Signature · 1 line
2.28.0.163.g6104cc2f0b6-goog
#32 lore raw

PATCH 16/16 cros: Add information about booting Chrome OS on x86

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 5 lines

Betreff: [PATCH 16/16] cros: Add information about booting Chrome OS on x86

Recent versions of Chrome OS do not have a kernel in the root disk, to save space.

Quoted 8 lines

With the improvements to the 'zboot' command it is fairly easy to load the kernel from the raw partition. Add instructions on how to do this.

---

 doc/README.chromium | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
#33 lore raw

cover x86: zboot: Enhance the 'zboot' command

In reply to Simon Glass

Hi Simon,

-----"Simon Glass" <[email protected]> schrieb: -----

Quoted 8 lines

Betreff: [PATCH 00/16] x86: zboot: Enhance the 'zboot' command

This command is currently monolithic and does not support scripts which want to adjust the boot process. This series updates it to be more like 'bootm', in that it has sub-commands for each stage of the boot. This allows some stages to be adjusted or skipped.

It also adds a way to dump out the setup block.

That series is really appreciated, especially 'zboot dump' :)

regards, Wolfgang