[PATCH 00/16] bootstd: Improve ChromiumOS support

The ChromiumOS bootmeth is fairly basic at present. It is able to boot only x86 kernels and contains quite a few hard-coded offsets.
This series tidies it up by bringing in some vboot structures and adding support for ARM.
It adds a few more features to bootstd, including display of x86 setup information.
So far this does not actually boot correctly on any ARM Chromebook:
jerry - hangs when booting kernel bob - Bad Linux ARM64 Image magic! with lz4-compressed kernel
Further work can address these issues.
Simon Glass (16): bootstd: cros: Correct reporting of I/O errors bootstd: cros: Move partition reading into a function bootstd: cros: Bring in some ChromiumOS structures bootstd: cros: Support a kernel on either partition bootstd: cros: Decode some kernel preamble fields bootstd: cros: Simplify setup and cmdline expressions bootstd: Move common zimage functions to bootm.h bootstd: cros: Add docs for the kernel layout bootstd: cros: Add private info for ChromiumOS bootstd: Add private bootmeth data to the bootflow bootstd: cros: Add a function to read info from partition bootstd: cros: Add a function to read a kernel bootstd: cros: Split up reading info and kernel bootstd: Allow display of the x86 setup information bootstd: Add a command to read all files for a bootflow bootstd: cros: Add ARM support
arch/x86/include/asm/zimage.h | 37 ---- arch/x86/lib/zimage.c | 8 +- boot/Kconfig | 4 +- boot/bootflow.c | 15 ++ boot/bootm.c | 37 ++++ boot/bootmeth-uclass.c | 10 + boot/bootmeth_cros.c | 363 ++++++++++++++++++++++++++++------ boot/bootmeth_cros.h | 197 ++++++++++++++++++ cmd/bootflow.c | 47 ++++- doc/usage/cmd/bootflow.rst | 139 ++++++++++++- include/bootflow.h | 15 +- include/bootm.h | 47 +++++ include/bootmeth.h | 23 +++ 13 files changed, 836 insertions(+), 106 deletions(-) create mode 100644 boot/bootmeth_cros.h

Return -EIO when the read failed, rather than the number of blocks read.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index aa19ae097f56..6179a547f74a 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -106,7 +106,7 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) return log_msg_ret("hdr", -ENOMEM); ret = blk_read(bflow->blk, info.start, num_blks, hdr); if (ret != num_blks) - return log_msg_ret("inf", ret); + return log_msg_ret("inf", -EIO);
if (memcmp("CHROMEOS", hdr, 8)) return -ENOENT; @@ -125,7 +125,7 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) bflow->blk->name, (ulong)info.start, num_blks); ret = blk_read(bflow->blk, (ulong)info.start + 0x80, num_blks, buf); if (ret != num_blks) - return log_msg_ret("inf", ret); + return log_msg_ret("inf", -EIO); base = map_to_sysmem(buf);
setup = base + start - OFFSET_BASE - SETUP_OFFSET;

Return -EIO when the read failed, rather than the number of blocks read.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Applied to u-boot-dm/next, thanks!

Move the code which reads a partition into its own function. Add a constant for the number of bytes to 'probe' at the start of the partition.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 66 +++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 16 deletions(-)
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 6179a547f74a..f6fb521f2065 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -23,6 +23,8 @@ #include <linux/sizes.h>
enum { + PROBE_SIZE = SZ_4K, /* initial bytes read from partition */ + /* Offsets in the kernel-partition header */ KERN_START = 0x4f0, KERN_SIZE = 0x518, @@ -77,6 +79,51 @@ static int copy_cmdline(const char *from, const char *uuid, char **bufp) return 0; }
+/** + * scan_part() - Scan a kernel partition to see if has a ChromeOS header + * + * This reads the first PROBE_SIZE of a partition, loookng for CHROMEOS + * + * @blk: Block device to scan + * @partnum: Partition number to scan + * @info: Please to put partition info + * @hdrp: Return allocated keyblock header on success + */ +static int scan_part(struct udevice *blk, int partnum, + struct disk_partition *info, void **hdrp) +{ + struct blk_desc *desc = dev_get_uclass_plat(blk); + struct vb2_keyblock *hdr; + ulong num_blks; + int ret; + + ret = part_get_info(desc, partnum, info); + if (ret) + return log_msg_ret("part", ret); + + /* Make a buffer for the header information */ + num_blks = PROBE_SIZE >> desc->log2blksz; + log_debug("Reading header, blk=%s, start=%lx, blocks=%lx\n", + blk->name, (ulong)info->start, num_blks); + hdr = memalign(SZ_1K, PROBE_SIZE); + if (!hdr) + return log_msg_ret("hdr", -ENOMEM); + ret = blk_read(blk, info->start, num_blks, hdr); + if (ret != num_blks) { + free(hdr); + return log_msg_ret("inf", -EIO); + } + + if (memcmp("CHROMEOS", hdr, 8)) { + free(hdr); + return -ENOENT; + } + + *hdrp = hdr; + + return 0; +} + static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) { struct blk_desc *desc = dev_get_uclass_plat(bflow->blk); @@ -93,23 +140,10 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) return log_msg_ret("max", -ENOENT);
/* Check partition 2 */ - ret = part_get_info(desc, 2, &info); + ret = scan_part(bflow->blk, 2, &info, &hdr); if (ret) - return log_msg_ret("part", ret); - - /* Make a buffer for the header information */ - num_blks = SZ_4K >> desc->log2blksz; - log_debug("Reading header, blk=%s, start=%lx, blocks=%lx\n", - bflow->blk->name, (ulong)info.start, num_blks); - hdr = memalign(SZ_1K, SZ_4K); - if (!hdr) - return log_msg_ret("hdr", -ENOMEM); - ret = blk_read(bflow->blk, info.start, num_blks, hdr); - if (ret != num_blks) - return log_msg_ret("inf", -EIO); - - if (memcmp("CHROMEOS", hdr, 8)) - return -ENOENT; + return log_msg_ret("scan", ret); + bflow->part = 2;
log_info("Header at %lx\n", (ulong)map_to_sysmem(hdr)); start = *(u32 *)(hdr + KERN_START);

Move the code which reads a partition into its own function. Add a constant for the number of bytes to 'probe' at the start of the partition.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 66 +++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 16 deletions(-)
Applied to u-boot-dm/next, thanks!

Add a header file with structures for booting ChromiumOS, taken from the vboot tree. Using these makes it easier to understand the code.
Note that the code style has not been updated for U-Boot, with use of uint64_t, __attribute__((packed)) and one comment-style nit. This should make it easier to keep the code in sync. It was taken from commit:
5b8596ce ("2sha256_arm: Fix data abort issue")
Update the CHROMEOS string to use the defined values.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 6 +- boot/bootmeth_cros.h | 197 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 boot/bootmeth_cros.h
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index f6fb521f2065..385eca37381c 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -21,6 +21,7 @@ #include <asm/zimage.h> #endif #include <linux/sizes.h> +#include "bootmeth_cros.h"
enum { PROBE_SIZE = SZ_4K, /* initial bytes read from partition */ @@ -82,7 +83,8 @@ static int copy_cmdline(const char *from, const char *uuid, char **bufp) /** * scan_part() - Scan a kernel partition to see if has a ChromeOS header * - * This reads the first PROBE_SIZE of a partition, loookng for CHROMEOS + * This reads the first PROBE_SIZE of a partition, loookng for + * VB2_KEYBLOCK_MAGIC * * @blk: Block device to scan * @partnum: Partition number to scan @@ -114,7 +116,7 @@ static int scan_part(struct udevice *blk, int partnum, return log_msg_ret("inf", -EIO); }
- if (memcmp("CHROMEOS", hdr, 8)) { + if (memcmp(VB2_KEYBLOCK_MAGIC, hdr->magic, VB2_KEYBLOCK_MAGIC_SIZE)) { free(hdr); return -ENOENT; } diff --git a/boot/bootmeth_cros.h b/boot/bootmeth_cros.h new file mode 100644 index 000000000000..8e3038571d14 --- /dev/null +++ b/boot/bootmeth_cros.h @@ -0,0 +1,197 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Structures used by the ChromiumOS bootmeth + * + * See docs at: + * https://www.chromium.org/chromium-os/chromiumos-design-docs/verified-boot-da... + * + * Original code at: + * https://chromium.googlesource.com/chromiumos/platform/vboot_reference/+/refs... + * + * Code taken from vboot_reference commit 5b8596ce file 2struct.h + * + * Copyright 2023 Google LLC + * Written by Simon Glass sjg@chromium.org + */ + +#ifndef __BOOTMETH_CROS_H +#define __BOOTMETH_CROS_H + +/* Signature data (a secure hash, possibly signed) */ +struct vb2_signature { + /* Offset of signature data from start of this struct */ + uint32_t sig_offset; + uint32_t reserved0; + + /* Size of signature data in bytes */ + uint32_t sig_size; + uint32_t reserved1; + + /* Size of the data block which was signed in bytes */ + uint32_t data_size; + uint32_t reserved2; +} __attribute__((packed)); + +#define EXPECTED_VB2_SIGNATURE_SIZE 24 + +/* Packed public key data */ +struct vb2_packed_key { + /* Offset of key data from start of this struct */ + uint32_t key_offset; + uint32_t reserved0; + + /* Size of key data in bytes (NOT strength of key in bits) */ + uint32_t key_size; + uint32_t reserved1; + + /* Signature algorithm used by the key (enum vb2_crypto_algorithm) */ + uint32_t algorithm; + uint32_t reserved2; + + /* Key version */ + uint32_t key_version; + uint32_t reserved3; + + /* TODO: when redoing this struct, add a text description of the key */ +} __attribute__((packed)); + +#define EXPECTED_VB2_PACKED_KEY_SIZE 32 + +#define VB2_KEYBLOCK_MAGIC "CHROMEOS" +#define VB2_KEYBLOCK_MAGIC_SIZE 8 + +/* + * Keyblock, containing the public key used to sign some other chunk of data. + * + * This should be followed by: + * 1) The data_key key data, pointed to by data_key.key_offset. + * 2) The checksum data for (vb2_keyblock + data_key data), pointed to + * by keyblock_checksum.sig_offset. + * 3) The signature data for (vb2_keyblock + data_key data), pointed to + * by keyblock_signature.sig_offset. + */ +struct vb2_keyblock { + /* Magic number */ + uint8_t magic[VB2_KEYBLOCK_MAGIC_SIZE]; + + /* Version of this header format */ + uint32_t header_version_major; + uint32_t header_version_minor; + + /* + * Length of this entire keyblock, including keys, signatures, and + * padding, in bytes + */ + uint32_t keyblock_size; + uint32_t reserved0; + + /* + * Signature for this keyblock (header + data pointed to by data_key) + * For use with signed data keys + */ + struct vb2_signature keyblock_signature; + + /* + * SHA-512 hash for this keyblock (header + data pointed to by + * data_key) For use with unsigned data keys. + * + * Only supported for kernel keyblocks, not firmware keyblocks. + */ + struct vb2_signature keyblock_hash; + + /* Flags for key (VB2_KEYBLOCK_FLAG_*) */ + uint32_t keyblock_flags; + uint32_t reserved1; + + /* Key to verify the chunk of data */ + struct vb2_packed_key data_key; +} __attribute__((packed)); + +#define EXPECTED_VB2_KEYBLOCK_SIZE 112 + +/* + * Preamble block for kernel, version 2.2 + * + * This should be followed by: + * 1) The signature data for the kernel body, pointed to by + * body_signature.sig_offset. + * 2) The signature data for (vb2_kernel_preamble + body signature data), + * pointed to by preamble_signature.sig_offset. + * 3) The 16-bit vmlinuz header, which is used for reconstruction of + * vmlinuz image. + */ +struct vb2_kernel_preamble { + /* + * Size of this preamble, including keys, signatures, vmlinuz header, + * and padding, in bytes + */ + uint32_t preamble_size; + uint32_t reserved0; + + /* Signature for this preamble (header + body signature) */ + struct vb2_signature preamble_signature; + + /* Version of this header format */ + uint32_t header_version_major; + uint32_t header_version_minor; + + /* Kernel version */ + uint32_t kernel_version; + uint32_t reserved1; + + /* Load address for kernel body */ + uint64_t body_load_address; + /* TODO (vboot 2.1): we never used that */ + + /* Address of bootloader, after body is loaded at body_load_address */ + uint64_t bootloader_address; + /* TODO (vboot 2.1): should be a 32-bit offset */ + + /* Size of bootloader in bytes */ + uint32_t bootloader_size; + uint32_t reserved2; + + /* Signature for the kernel body */ + struct vb2_signature body_signature; + + /* + * TODO (vboot 2.1): fields for kernel offset and size. Right now the + * size is implicitly the same as the size of data signed by the body + * signature, and the offset is implicitly at the end of the preamble. + * But that forces us to pad the preamble to 64KB rather than just + * having a tiny preamble and an offset field. + */ + + /* + * Fields added in header version 2.1. You must verify the header + * version before reading these fields! + */ + + /* + * Address of 16-bit header for vmlinuz reassembly. Readers should + * return 0 for header version < 2.1. + */ + uint64_t vmlinuz_header_address; + + /* Size of 16-bit header for vmlinuz in bytes. Readers should return 0 + for header version < 2.1 */ + uint32_t vmlinuz_header_size; + uint32_t reserved3; + + /* + * Fields added in header version 2.2. You must verify the header + * version before reading these fields! + */ + + /* + * Flags; see VB2_KERNEL_PREAMBLE_*. Readers should return 0 for + * header version < 2.2. Flags field is currently defined as: + * [31:2] - Reserved (for future use) + * [1:0] - Kernel image type (0b00 - CrOS, + * 0b01 - bootimg, + * 0b10 - multiboot) + */ + uint32_t flags; +} __attribute__((packed)); + +#endif /* __BOOTMETH_CROS_H */

Add a header file with structures for booting ChromiumOS, taken from the vboot tree. Using these makes it easier to understand the code.
Note that the code style has not been updated for U-Boot, with use of uint64_t, __attribute__((packed)) and one comment-style nit. This should make it easier to keep the code in sync. It was taken from commit:
5b8596ce ("2sha256_arm: Fix data abort issue")
Update the CHROMEOS string to use the defined values.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 6 +- boot/bootmeth_cros.h | 197 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+), 2 deletions(-) create mode 100644 boot/bootmeth_cros.h
Applied to u-boot-dm/next, thanks!

ChromiumOS allows a kernel to be on either partition 2 or 4. Add support for scanning both and using the first one we find with a suitable signature.
Record the partition which is used.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 385eca37381c..7b25042bfe56 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -13,6 +13,7 @@ #include <bootdev.h> #include <bootflow.h> #include <bootmeth.h> +#include <display_options.h> #include <dm.h> #include <malloc.h> #include <mapmem.h> @@ -133,7 +134,7 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) struct disk_partition info; const char *uuid = NULL; void *buf, *hdr; - int ret; + int part, ret;
log_debug("starting, part=%d\n", bflow->part);
@@ -141,13 +142,19 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) if (bflow->part) return log_msg_ret("max", -ENOENT);
- /* Check partition 2 */ - ret = scan_part(bflow->blk, 2, &info, &hdr); - if (ret) - return log_msg_ret("scan", ret); - bflow->part = 2; + /* Check partition 2 then 4 */ + part = 2; + ret = scan_part(bflow->blk, part, &info, &hdr); + if (ret) { + part = 4; + ret = scan_part(bflow->blk, part, &info, &hdr); + if (ret) + return log_msg_ret("scan", ret); + } + bflow->part = part;
- log_info("Header at %lx\n", (ulong)map_to_sysmem(hdr)); + log_info("Selected parition %d, header at %lx\n", bflow->part, + (ulong)map_to_sysmem(hdr)); start = *(u32 *)(hdr + KERN_START); size = ALIGN(*(u32 *)(hdr + KERN_SIZE), desc->blksz); log_debug("Reading start %lx size %lx\n", start, size);

ChromiumOS allows a kernel to be on either partition 2 or 4. Add support for scanning both and using the first one we find with a suitable signature.
Record the partition which is used.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
Applied to u-boot-dm/next, thanks!

Decode the kernel start and size using the structures provided. This accesses the same data, just in a cleaner way.
Add some logging for some of the fields in the kernel preamble.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 54 ++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 17 deletions(-)
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 7b25042bfe56..2a745621e30e 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -27,10 +27,6 @@ enum { PROBE_SIZE = SZ_4K, /* initial bytes read from partition */
- /* Offsets in the kernel-partition header */ - KERN_START = 0x4f0, - KERN_SIZE = 0x518, - SETUP_OFFSET = 0x1000, /* bytes before base */ CMDLINE_OFFSET = 0x2000, /* bytes before base */ OFFSET_BASE = 0x100000, /* assumed kernel load-address */ @@ -93,7 +89,7 @@ static int copy_cmdline(const char *from, const char *uuid, char **bufp) * @hdrp: Return allocated keyblock header on success */ static int scan_part(struct udevice *blk, int partnum, - struct disk_partition *info, void **hdrp) + struct disk_partition *info, struct vb2_keyblock **hdrp) { struct blk_desc *desc = dev_get_uclass_plat(blk); struct vb2_keyblock *hdr; @@ -130,11 +126,14 @@ static int scan_part(struct udevice *blk, int partnum, static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) { struct blk_desc *desc = dev_get_uclass_plat(bflow->blk); - ulong base, start, size, setup, cmdline, num_blks, kern_base; + ulong base, start, setup, cmdline, num_blks, kern_base; + const struct vb2_kernel_preamble *preamble; + ulong body_offset, body_size; struct disk_partition info; const char *uuid = NULL; - void *buf, *hdr; + struct vb2_keyblock *hdr; int part, ret; + void *buf;
log_debug("starting, part=%d\n", bflow->part);
@@ -155,18 +154,39 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow)
log_info("Selected parition %d, header at %lx\n", bflow->part, (ulong)map_to_sysmem(hdr)); - start = *(u32 *)(hdr + KERN_START); - size = ALIGN(*(u32 *)(hdr + KERN_SIZE), desc->blksz); - log_debug("Reading start %lx size %lx\n", start, size); - bflow->size = size; - - buf = memalign(SZ_1K, size); + preamble = (void *)hdr + hdr->keyblock_size; + log_debug("Kernel preamble at %lx, version major %x, minor %x\n", + (ulong)map_to_sysmem(preamble), + preamble->header_version_major, + preamble->header_version_minor); + + start = (ulong)preamble->bootloader_address; + log_debug(" - load_address %lx, bl_addr %lx, bl_size %lx\n", + (ulong)preamble->body_load_address, + (ulong)preamble->bootloader_address, + (ulong)preamble->bootloader_size); + + body_offset = hdr->keyblock_size + preamble->preamble_size; + body_size = preamble->body_signature.data_size; + log_debug("Kernel body at %lx size %lx\n", body_offset, body_size); + bflow->size = body_size; + + buf = memalign(SZ_1K, body_size); if (!buf) return log_msg_ret("buf", -ENOMEM); - num_blks = size >> desc->log2blksz; - log_debug("Reading data, blk=%s, start=%lx, blocks=%lx\n", - bflow->blk->name, (ulong)info.start, num_blks); - ret = blk_read(bflow->blk, (ulong)info.start + 0x80, num_blks, buf); + + /* Check that the header is not smaller than permitted */ + if (body_offset < PROBE_SIZE) + return log_msg_ret("san", EFAULT); + + /* Read kernel body */ + num_blks = body_size >> desc->log2blksz; + log_debug("Reading body to %lx, blk=%s, size=%lx, blocks=%lx\n", + (ulong)map_to_sysmem(buf), bflow->blk->name, body_size, + num_blks); + ret = blk_read(bflow->blk, + info.start + (body_offset >> desc->log2blksz), + num_blks, buf); if (ret != num_blks) return log_msg_ret("inf", -EIO); base = map_to_sysmem(buf);

Decode the kernel start and size using the structures provided. This accesses the same data, just in a cleaner way.
Add some logging for some of the fields in the kernel preamble.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 54 ++++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 17 deletions(-)
Applied to u-boot-dm/next, thanks!

Create a common base from which the other parts are offset and make all of the offsets related to that. This makes the code a little easier to read.
Use X86_ prefixes for the two values which are x86-specific.
Drop OFFSET_BASE since it is available in a header field.
Drop the unnecessary 'start' variable too.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 2a745621e30e..05284713f67b 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -27,9 +27,9 @@ enum { PROBE_SIZE = SZ_4K, /* initial bytes read from partition */
- SETUP_OFFSET = 0x1000, /* bytes before base */ - CMDLINE_OFFSET = 0x2000, /* bytes before base */ - OFFSET_BASE = 0x100000, /* assumed kernel load-address */ + X86_SETUP_OFFSET = -0x1000, /* setup offset relative to base */ + CMDLINE_OFFSET = -0x2000, /* cmdline offset relative to base */ + X86_KERNEL_OFFSET = 0x4000, /* kernel offset relative to base */ };
static int cros_check(struct udevice *dev, struct bootflow_iter *iter) @@ -126,7 +126,7 @@ static int scan_part(struct udevice *blk, int partnum, static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) { struct blk_desc *desc = dev_get_uclass_plat(bflow->blk); - ulong base, start, setup, cmdline, num_blks, kern_base; + ulong base, setup, cmdline, num_blks, kern_base; const struct vb2_kernel_preamble *preamble; ulong body_offset, body_size; struct disk_partition info; @@ -160,7 +160,6 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) preamble->header_version_major, preamble->header_version_minor);
- start = (ulong)preamble->bootloader_address; log_debug(" - load_address %lx, bl_addr %lx, bl_size %lx\n", (ulong)preamble->body_load_address, (ulong)preamble->bootloader_address, @@ -189,12 +188,13 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) num_blks, buf); if (ret != num_blks) return log_msg_ret("inf", -EIO); - base = map_to_sysmem(buf); + base = map_to_sysmem(buf) + preamble->bootloader_address - + preamble->body_load_address;
- setup = base + start - OFFSET_BASE - SETUP_OFFSET; - cmdline = base + start - OFFSET_BASE - CMDLINE_OFFSET; - kern_base = base + start - OFFSET_BASE + SZ_16K; - log_debug("base %lx setup %lx, cmdline %lx, kern_base %lx\n", base, + setup = base + X86_SETUP_OFFSET; + cmdline = base + CMDLINE_OFFSET; + kern_base = base + X86_KERNEL_OFFSET; + log_debug("base %lx setup %lx cmdline %lx kern_base %lx\n", base, setup, cmdline, kern_base);
#ifdef CONFIG_X86

Create a common base from which the other parts are offset and make all of the offsets related to that. This makes the code a little easier to read.
Use X86_ prefixes for the two values which are x86-specific.
Drop OFFSET_BASE since it is available in a header field.
Drop the unnecessary 'start' variable too.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
Applied to u-boot-dm/next, thanks!

We want to avoid using #ifdefs around header files and in the code. It makes sense to collect the various functions used for loading images into a single header which can be included by all architectures. The best place for this is the arch-neutral bootm.h header, so use that.
Move some zimage functions into this bootm.h header.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/x86/include/asm/zimage.h | 27 --------------------------- boot/bootmeth_cros.c | 4 +--- include/bootm.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 30 deletions(-)
diff --git a/arch/x86/include/asm/zimage.h b/arch/x86/include/asm/zimage.h index 9ad74dc0b946..000b38ea8993 100644 --- a/arch/x86/include/asm/zimage.h +++ b/arch/x86/include/asm/zimage.h @@ -72,31 +72,4 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot, */ void zimage_dump(struct boot_params *base_ptr);
-/** - * zboot_start() - Boot a zimage - * - * Boot a zimage, given the component parts - * - * @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 - * @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 - * 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); - -/* - * zimage_get_kernel_version() - Get the version string from a kernel - * - * @params: boot_params pointer - * @kernel_base: base address of kernel - * Return: Kernel version as a NUL-terminated string - */ -const char *zimage_get_kernel_version(struct boot_params *params, - void *kernel_base); - #endif diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 05284713f67b..3b9e75540aa8 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -12,15 +12,13 @@ #include <blk.h> #include <bootdev.h> #include <bootflow.h> +#include <bootm.h> #include <bootmeth.h> #include <display_options.h> #include <dm.h> #include <malloc.h> #include <mapmem.h> #include <part.h> -#ifdef CONFIG_X86 -#include <asm/zimage.h> -#endif #include <linux/sizes.h> #include "bootmeth_cros.h"
diff --git a/include/bootm.h b/include/bootm.h index 044a4797ed36..6fe418e00272 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -9,6 +9,7 @@
#include <image.h>
+struct boot_params; struct cmd_tbl;
#define BOOTM_ERR_RESET (-1) @@ -124,4 +125,31 @@ int bootm_process_cmdline(char *buf, int maxlen, int flags); */ int bootm_process_cmdline_env(int flags);
+/** + * zboot_start() - Boot a zimage + * + * Boot a zimage, given the component parts + * + * @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 + * @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 + * 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); + +/* + * zimage_get_kernel_version() - Get the version string from a kernel + * + * @params: boot_params pointer + * @kernel_base: base address of kernel + * Return: Kernel version as a NUL-terminated string + */ +const char *zimage_get_kernel_version(struct boot_params *params, + void *kernel_base); + #endif

We want to avoid using #ifdefs around header files and in the code. It makes sense to collect the various functions used for loading images into a single header which can be included by all architectures. The best place for this is the arch-neutral bootm.h header, so use that.
Move some zimage functions into this bootm.h header.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/x86/include/asm/zimage.h | 27 --------------------------- boot/bootmeth_cros.c | 4 +--- include/bootm.h | 28 ++++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 30 deletions(-)
Applied to u-boot-dm/next, thanks!

Provide brief documentation about the ChromiumOS kernel layout.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 3b9e75540aa8..a551d43701d8 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -22,6 +22,35 @@ #include <linux/sizes.h> #include "bootmeth_cros.h"
+/* + * Layout of the ChromeOS kernel + * + * Partitions 2 and 4 contain kernels + * + * Contents are: + * + * Offset Contents + * 0 struct vb2_keyblock + * m struct vb2_kernel_preamble + * m + n kernel buffer + * + * m is keyblock->keyblock_size + * n is preamble->preamble_size + * + * The kernel buffer itself consists of various parts: + * + * Offset Contents + * m + n kernel image (Flat vmlinux binary or FIT) + * b - 8KB Command line text + * b - 4KB X86 setup block (struct boot_params, extends for about 16KB) + * b X86 bootloader (continuation of setup block) + * b + 16KB X86 setup block (copy, used for hold data pointed to) + * + * b is m + n + preamble->bootloader_address - preamble->body_load_address + * + * Useful metadata extends from b - 8KB through to b + 32 KB + */ + enum { PROBE_SIZE = SZ_4K, /* initial bytes read from partition */

Provide brief documentation about the ChromiumOS kernel layout.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
Applied to u-boot-dm/next, thanks!

Create a new private structure to hold information gleaned from the disk. This will allow separation between reading of the bootflow information and (later) reading the whole kernel.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 55 +++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 13 deletions(-)
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index a551d43701d8..16a42ad46ae0 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -59,6 +59,29 @@ enum { X86_KERNEL_OFFSET = 0x4000, /* kernel offset relative to base */ };
+/** + * struct cros_priv - Private data + * + * This is read from the disk and recorded for use when the full kernel must + * be loaded and booted + * + * @body_offset: Offset of kernel body from start of partition (in bytes) + * @body_size: Size of kernel body in bytes + * @part_start: Block offset of selected partition from the start of the disk + * @body_load_address: Nominal load address for kernel body + * @bootloader_address: Address of bootloader, after body is loaded at + * body_load_address + * @bootloader_size: Size of bootloader in bytes + */ +struct cros_priv { + ulong body_offset; + ulong body_size; + lbaint_t part_start; + ulong body_load_address; + ulong bootloader_address; + ulong bootloader_size; +}; + static int cros_check(struct udevice *dev, struct bootflow_iter *iter) { /* This only works on block and network devices */ @@ -155,7 +178,7 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) struct blk_desc *desc = dev_get_uclass_plat(bflow->blk); ulong base, setup, cmdline, num_blks, kern_base; const struct vb2_kernel_preamble *preamble; - ulong body_offset, body_size; + struct cros_priv s_priv, *priv = &s_priv; struct disk_partition info; const char *uuid = NULL; struct vb2_keyblock *hdr; @@ -192,31 +215,37 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) (ulong)preamble->bootloader_address, (ulong)preamble->bootloader_size);
- body_offset = hdr->keyblock_size + preamble->preamble_size; - body_size = preamble->body_signature.data_size; - log_debug("Kernel body at %lx size %lx\n", body_offset, body_size); - bflow->size = body_size; - - buf = memalign(SZ_1K, body_size); + priv->body_offset = hdr->keyblock_size + preamble->preamble_size; + priv->part_start = info.start; + priv->body_size = preamble->body_signature.data_size; + priv->body_load_address = preamble->body_load_address; + priv->bootloader_address = preamble->bootloader_address; + priv->bootloader_size = preamble->bootloader_size; + log_debug("Kernel body at %lx size %lx\n", priv->body_offset, + priv->body_size); + bflow->size = priv->body_size; + + buf = memalign(SZ_1K, priv->body_size); if (!buf) return log_msg_ret("buf", -ENOMEM);
/* Check that the header is not smaller than permitted */ - if (body_offset < PROBE_SIZE) + if (priv->body_offset < PROBE_SIZE) return log_msg_ret("san", EFAULT);
/* Read kernel body */ - num_blks = body_size >> desc->log2blksz; + num_blks = priv->body_size >> desc->log2blksz; log_debug("Reading body to %lx, blk=%s, size=%lx, blocks=%lx\n", - (ulong)map_to_sysmem(buf), bflow->blk->name, body_size, + (ulong)map_to_sysmem(buf), bflow->blk->name, priv->body_size, num_blks); ret = blk_read(bflow->blk, - info.start + (body_offset >> desc->log2blksz), + priv->part_start + + (priv->body_offset >> desc->log2blksz), num_blks, buf); if (ret != num_blks) return log_msg_ret("inf", -EIO); - base = map_to_sysmem(buf) + preamble->bootloader_address - - preamble->body_load_address; + base = map_to_sysmem(buf) + priv->bootloader_address - + priv->body_load_address;
setup = base + X86_SETUP_OFFSET; cmdline = base + CMDLINE_OFFSET;

Create a new private structure to hold information gleaned from the disk. This will allow separation between reading of the bootflow information and (later) reading the whole kernel.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 55 +++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 13 deletions(-)
Applied to u-boot-dm/next, thanks!

Some bootmeths need to store their own information related to the bootflow, in addition to the generic information in struct bootflow. Add a pointer for this.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootflow.c | 1 + include/bootflow.h | 2 ++ 2 files changed, 3 insertions(+)
diff --git a/boot/bootflow.c b/boot/bootflow.c index 81b5829d5b37..daf862fac788 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -432,6 +432,7 @@ void bootflow_free(struct bootflow *bflow) free(bflow->buf); free(bflow->os_name); free(bflow->fdt_fname); + free(bflow->bootmeth_priv); }
void bootflow_remove(struct bootflow *bflow) diff --git a/include/bootflow.h b/include/bootflow.h index 4152577afb71..ff2bddb51515 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -83,6 +83,7 @@ enum bootflow_flags_t { * @flags: Flags for the bootflow (see enum bootflow_flags_t) * @cmdline: OS command line, or NULL if not known (allocated) * @x86_setup: Pointer to x86 setup block inside @buf, NULL if not present + * @bootmeth_priv: Private data for the bootmeth */ struct bootflow { struct list_head bm_node; @@ -108,6 +109,7 @@ struct bootflow { int flags; char *cmdline; char *x86_setup; + void *bootmeth_priv; };
/**

Some bootmeths need to store their own information related to the bootflow, in addition to the generic information in struct bootflow. Add a pointer for this.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootflow.c | 1 + include/bootflow.h | 2 ++ 2 files changed, 3 insertions(+)
Applied to u-boot-dm/next, thanks!

The code to read the ChromiumOS information from the partition is currently all in one function. It reads the entire kernel, which is unnecessary unless it is to be booted.
Create a new function which reads just the minimum required data from the disk, then obtains what it needs from there.
For now this function is not used. Future work will plumb it in.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 121 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+)
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 16a42ad46ae0..82cbdcf2c93a 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -72,6 +72,7 @@ enum { * @bootloader_address: Address of bootloader, after body is loaded at * body_load_address * @bootloader_size: Size of bootloader in bytes + * @info_buf: Buffer containing ChromiumOS info */ struct cros_priv { ulong body_offset; @@ -80,6 +81,7 @@ struct cros_priv { ulong body_load_address; ulong bootloader_address; ulong bootloader_size; + void *info_buf; };
static int cros_check(struct udevice *dev, struct bootflow_iter *iter) @@ -173,6 +175,125 @@ static int scan_part(struct udevice *blk, int partnum, return 0; }
+/** + * cros_read_buf() - Read information into a buf and parse it + * + * @bflow: Bootflow to update + * @buf: Buffer to use + * @size: Size of buffer and number of bytes to read thereinto + * @start: Start offset to read from on disk + * @before_base: Number of bytes to read before the bootloader base + * @uuid: UUID string if supported, else NULL + * Return: 0 if OK, -ENOMEM if out of memory, -EIO on read failure + */ +static int cros_read_buf(struct bootflow *bflow, void *buf, ulong size, + loff_t start, ulong before_base, const char *uuid) +{ + struct blk_desc *desc = dev_get_uclass_plat(bflow->blk); + ulong base, setup, cmdline, kern_base; + ulong num_blks; + int ret; + + num_blks = size >> desc->log2blksz; + log_debug("Reading info to %lx, blk=%s, size=%lx, blocks=%lx\n", + (ulong)map_to_sysmem(buf), bflow->blk->name, size, num_blks); + ret = blk_read(bflow->blk, start, num_blks, buf); + if (ret != num_blks) + return log_msg_ret("inf", -EIO); + base = map_to_sysmem(buf) + before_base; + + setup = base + X86_SETUP_OFFSET; + cmdline = base + CMDLINE_OFFSET; + kern_base = base + X86_KERNEL_OFFSET; + log_debug("base %lx setup %lx cmdline %lx kern_base %lx\n", base, + setup, cmdline, kern_base); + +#ifdef CONFIG_X86 + const char *version; + + version = zimage_get_kernel_version(map_sysmem(setup, 0), + map_sysmem(kern_base, 0)); + log_debug("version %s\n", version); + if (version) + bflow->name = strdup(version); +#endif + if (!bflow->name) + bflow->name = strdup("ChromeOS"); + if (!bflow->name) + return log_msg_ret("nam", -ENOMEM); + bflow->os_name = strdup("ChromeOS"); + if (!bflow->os_name) + return log_msg_ret("os", -ENOMEM); + + ret = copy_cmdline(map_sysmem(cmdline, 0), uuid, &bflow->cmdline); + if (ret) + return log_msg_ret("cmd", ret); + bflow->x86_setup = map_sysmem(setup, 0); + + return 0; +} + +/** + * cros_read_info() - Read information and fill out the bootflow + * + * @bflow: Bootflow to update + * @uuid: UUID string if supported, else NULL + * @preamble: Kernel preamble information + * Return: 0 if OK, -ENOMEM if out of memory, -EIO on read failure + */ +static int cros_read_info(struct bootflow *bflow, const char *uuid, + const struct vb2_kernel_preamble *preamble) +{ + struct cros_priv *priv = bflow->bootmeth_priv; + struct udevice *blk = bflow->blk; + struct blk_desc *desc = dev_get_uclass_plat(blk); + ulong offset, size, before_base; + void *buf; + int ret; + + log_debug("Kernel preamble at %lx, version major %x, minor %x\n", + (ulong)map_to_sysmem(preamble), + preamble->header_version_major, + preamble->header_version_minor); + + log_debug(" - load_address %lx, bl_addr %lx, bl_size %lx\n", + (ulong)preamble->body_load_address, + (ulong)preamble->bootloader_address, + (ulong)preamble->bootloader_size); + + priv->body_size = preamble->body_signature.data_size; + priv->body_load_address = preamble->body_load_address; + priv->bootloader_address = preamble->bootloader_address; + priv->bootloader_size = preamble->bootloader_size; + log_debug("Kernel body at %lx size %lx\n", priv->body_offset, + priv->body_size); + + /* Work out how many bytes to read before the bootloader base */ + before_base = -CMDLINE_OFFSET; + + /* Read the cmdline through to the end of the bootloader */ + size = priv->bootloader_size + before_base; + offset = priv->body_offset + + (priv->bootloader_address - priv->body_load_address) + + CMDLINE_OFFSET; + buf = malloc(size); + if (!buf) + return log_msg_ret("buf", -ENOMEM); + + ret = cros_read_buf(bflow, buf, size, + priv->part_start + (offset >> desc->log2blksz), + before_base, uuid); + if (ret) { + /* Clear this since the buffer is invalid */ + bflow->x86_setup = NULL; + free(buf); + return log_msg_ret("pro", ret); + } + priv->info_buf = buf; + + return 0; +} + static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) { struct blk_desc *desc = dev_get_uclass_plat(bflow->blk);

The code to read the ChromiumOS information from the partition is currently all in one function. It reads the entire kernel, which is unnecessary unless it is to be booted.
Create a new function which reads just the minimum required data from the disk, then obtains what it needs from there.
For now this function is not used. Future work will plumb it in.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 121 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+)
Applied to u-boot-dm/next, thanks!

The code to read the ChromiumOS information from the partition is currently all in one function.
Create a new function which reads the kernel, assuming that the metadata has been parsed.
For now this function is not used. Future work will plumb it in.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 82cbdcf2c93a..8728cd18e3c1 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -294,6 +294,45 @@ static int cros_read_info(struct bootflow *bflow, const char *uuid, return 0; }
+static int cros_read_kernel(struct bootflow *bflow) +{ + struct blk_desc *desc = dev_get_uclass_plat(bflow->blk); + struct cros_priv *priv = bflow->bootmeth_priv; + ulong base, setup; + ulong num_blks; + void *buf; + int ret; + + bflow->size = priv->body_size; + + buf = memalign(SZ_1K, priv->body_size); + if (!buf) + return log_msg_ret("buf", -ENOMEM); + + /* Check that the header is not smaller than permitted */ + if (priv->body_offset < PROBE_SIZE) + return log_msg_ret("san", EFAULT); + + /* Read kernel body */ + num_blks = priv->body_size >> desc->log2blksz; + log_debug("Reading body to %lx, blk=%s, size=%lx, blocks=%lx\n", + (ulong)map_to_sysmem(buf), bflow->blk->name, priv->body_size, + num_blks); + ret = blk_read(bflow->blk, + priv->part_start + (priv->body_offset >> desc->log2blksz), + num_blks, buf); + if (ret != num_blks) + return log_msg_ret("inf", -EIO); + base = map_to_sysmem(buf) + priv->bootloader_address - + priv->body_load_address; + setup = base + X86_SETUP_OFFSET; + + bflow->buf = buf; + bflow->x86_setup = map_sysmem(setup, 0); + + return 0; +} + static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) { struct blk_desc *desc = dev_get_uclass_plat(bflow->blk);

The code to read the ChromiumOS information from the partition is currently all in one function.
Create a new function which reads the kernel, assuming that the metadata has been parsed.
For now this function is not used. Future work will plumb it in.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
Applied to u-boot-dm/next, thanks!

Use the two new functions to separate reading of the ChromiumOS info from the partition from actually reading the kernel and booting it.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 96 +++++++++++--------------------------------- 1 file changed, 23 insertions(+), 73 deletions(-)
diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 8728cd18e3c1..06709dd9171c 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -335,15 +335,12 @@ static int cros_read_kernel(struct bootflow *bflow)
static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) { - struct blk_desc *desc = dev_get_uclass_plat(bflow->blk); - ulong base, setup, cmdline, num_blks, kern_base; const struct vb2_kernel_preamble *preamble; - struct cros_priv s_priv, *priv = &s_priv; struct disk_partition info; - const char *uuid = NULL; struct vb2_keyblock *hdr; + const char *uuid = NULL; + struct cros_priv *priv; int part, ret; - void *buf;
log_debug("starting, part=%d\n", bflow->part);
@@ -362,84 +359,32 @@ static int cros_read_bootflow(struct udevice *dev, struct bootflow *bflow) } bflow->part = part;
- log_info("Selected parition %d, header at %lx\n", bflow->part, - (ulong)map_to_sysmem(hdr)); - preamble = (void *)hdr + hdr->keyblock_size; - log_debug("Kernel preamble at %lx, version major %x, minor %x\n", - (ulong)map_to_sysmem(preamble), - preamble->header_version_major, - preamble->header_version_minor); + priv = malloc(sizeof(struct cros_priv)); + if (!priv) { + free(hdr); + return log_msg_ret("buf", -ENOMEM); + } + bflow->bootmeth_priv = priv;
- log_debug(" - load_address %lx, bl_addr %lx, bl_size %lx\n", - (ulong)preamble->body_load_address, - (ulong)preamble->bootloader_address, - (ulong)preamble->bootloader_size); + log_info("Selected partition %d, header at %lx\n", bflow->part, + (ulong)map_to_sysmem(hdr));
+ /* Grab a few things from the preamble */ + preamble = (void *)hdr + hdr->keyblock_size; priv->body_offset = hdr->keyblock_size + preamble->preamble_size; priv->part_start = info.start; - priv->body_size = preamble->body_signature.data_size; - priv->body_load_address = preamble->body_load_address; - priv->bootloader_address = preamble->bootloader_address; - priv->bootloader_size = preamble->bootloader_size; - log_debug("Kernel body at %lx size %lx\n", priv->body_offset, - priv->body_size); - bflow->size = priv->body_size; - - buf = memalign(SZ_1K, priv->body_size); - if (!buf) - return log_msg_ret("buf", -ENOMEM); - - /* Check that the header is not smaller than permitted */ - if (priv->body_offset < PROBE_SIZE) - return log_msg_ret("san", EFAULT); - - /* Read kernel body */ - num_blks = priv->body_size >> desc->log2blksz; - log_debug("Reading body to %lx, blk=%s, size=%lx, blocks=%lx\n", - (ulong)map_to_sysmem(buf), bflow->blk->name, priv->body_size, - num_blks); - ret = blk_read(bflow->blk, - priv->part_start + - (priv->body_offset >> desc->log2blksz), - num_blks, buf); - if (ret != num_blks) - return log_msg_ret("inf", -EIO); - base = map_to_sysmem(buf) + priv->bootloader_address - - priv->body_load_address; - - setup = base + X86_SETUP_OFFSET; - cmdline = base + CMDLINE_OFFSET; - kern_base = base + X86_KERNEL_OFFSET; - log_debug("base %lx setup %lx cmdline %lx kern_base %lx\n", base, - setup, cmdline, kern_base); - -#ifdef CONFIG_X86 - const char *version; - - version = zimage_get_kernel_version(map_sysmem(setup, 0), - map_sysmem(kern_base, 0)); - log_debug("version %s\n", version); - if (version) - bflow->name = strdup(version); -#endif - if (!bflow->name) - bflow->name = strdup("ChromeOS"); - if (!bflow->name) - return log_msg_ret("nam", -ENOMEM); - bflow->os_name = strdup("ChromeOS"); - if (!bflow->os_name) - return log_msg_ret("os", -ENOMEM);
+ /* Now read everything we can learn about kernel */ #if CONFIG_IS_ENABLED(PARTITION_UUIDS) uuid = info.uuid; #endif - ret = copy_cmdline(map_sysmem(cmdline, 0), uuid, &bflow->cmdline); + ret = cros_read_info(bflow, uuid, preamble); + preamble = NULL; + free(hdr); if (ret) - return log_msg_ret("cmd", ret); - + return log_msg_ret("inf", ret); + bflow->size = priv->body_size; bflow->state = BOOTFLOWST_READY; - bflow->buf = buf; - bflow->x86_setup = map_sysmem(setup, 0);
return 0; } @@ -452,6 +397,11 @@ static int cros_read_file(struct udevice *dev, struct bootflow *bflow,
static int cros_boot(struct udevice *dev, struct bootflow *bflow) { + int ret; + + ret = cros_read_kernel(bflow); + if (ret) + return log_msg_ret("rd", ret); #ifdef CONFIG_X86 zboot_start(map_to_sysmem(bflow->buf), bflow->size, 0, 0, map_to_sysmem(bflow->x86_setup),

Use the two new functions to separate reading of the ChromiumOS info from the partition from actually reading the kernel and booting it.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootmeth_cros.c | 96 +++++++++++--------------------------------- 1 file changed, 23 insertions(+), 73 deletions(-)
Applied to u-boot-dm/next, thanks!

Provide an option to dump this information if available.
Move the funciion prototype to the common x86 header. Allow the command line to be left out since 'bootflow info' show this itself and it is not in the correct place in memory until the kernel is actually booted.
Fix a badly aligned heading while we are here.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/x86/include/asm/zimage.h | 10 ------ arch/x86/lib/zimage.c | 8 ++--- cmd/bootflow.c | 14 +++++++-- doc/usage/cmd/bootflow.rst | 59 ++++++++++++++++++++++++++++++++++- include/bootflow.h | 2 +- include/bootm.h | 11 +++++++ 6 files changed, 86 insertions(+), 18 deletions(-)
diff --git a/arch/x86/include/asm/zimage.h b/arch/x86/include/asm/zimage.h index 000b38ea8993..655675b66614 100644 --- a/arch/x86/include/asm/zimage.h +++ b/arch/x86/include/asm/zimage.h @@ -62,14 +62,4 @@ 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);
-/** - * zimage_dump() - Dump the metadata of a zimage - * - * This shows all available information in a zimage that has been loaded. - * - * @base_ptr: Pointer to the boot parameters, typically at address - * DEFAULT_SETUP_BASE - */ -void zimage_dump(struct boot_params *base_ptr); - #endif diff --git a/arch/x86/lib/zimage.c b/arch/x86/lib/zimage.c index 062e3d3e3151..a41e1ccf8a65 100644 --- a/arch/x86/lib/zimage.c +++ b/arch/x86/lib/zimage.c @@ -692,7 +692,7 @@ static void show_loader(struct setup_header *hdr) printf("\n"); }
-void zimage_dump(struct boot_params *base_ptr) +void zimage_dump(struct boot_params *base_ptr, bool show_cmdline) { struct setup_header *hdr; const char *version; @@ -703,7 +703,7 @@ void zimage_dump(struct boot_params *base_ptr)
printf("E820: %d entries\n", base_ptr->e820_entries); if (base_ptr->e820_entries) { - printf("%18s %16s %s\n", "Addr", "Size", "Type"); + printf("%12s %10s %s\n", "Addr", "Size", "Type"); for (i = 0; i < base_ptr->e820_entries; i++) { struct e820_entry *entry = &base_ptr->e820_map[i];
@@ -749,7 +749,7 @@ void zimage_dump(struct boot_params *base_ptr) print_num("Ext loader ver", hdr->ext_loader_ver); print_num("Ext loader type", hdr->ext_loader_type); print_num("Command line ptr", hdr->cmd_line_ptr); - if (hdr->cmd_line_ptr) { + if (show_cmdline && hdr->cmd_line_ptr) { printf(" "); /* Use puts() to avoid limits from CONFIG_SYS_PBSIZE */ puts((char *)(ulong)hdr->cmd_line_ptr); @@ -787,7 +787,7 @@ static int do_zboot_dump(struct cmd_tbl *cmdtp, int flag, int argc, printf("No zboot setup_base\n"); return CMD_RET_FAILURE; } - zimage_dump(base_ptr); + zimage_dump(base_ptr, true);
return 0; } diff --git a/cmd/bootflow.c b/cmd/bootflow.c index c0aa4f84fe8d..9562832ce438 100644 --- a/cmd/bootflow.c +++ b/cmd/bootflow.c @@ -9,6 +9,7 @@ #include <common.h> #include <bootdev.h> #include <bootflow.h> +#include <bootm.h> #include <bootstd.h> #include <command.h> #include <console.h> @@ -303,11 +304,14 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc, { struct bootstd_priv *std; struct bootflow *bflow; + bool x86_setup = false; bool dump = false; int ret;
- if (argc > 1 && *argv[1] == '-') + if (argc > 1 && *argv[1] == '-') { dump = strchr(argv[1], 'd'); + x86_setup = strchr(argv[1], 's'); + }
ret = bootstd_get_priv(&std); if (ret) @@ -319,6 +323,12 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc, } bflow = std->cur_bootflow;
+ if (IS_ENABLED(CONFIG_X86) && x86_setup) { + zimage_dump(bflow->x86_setup, false); + + return 0; + } + printf("Name: %s\n", bflow->name); printf("Device: %s\n", bflow->dev->name); printf("Block dev: %s\n", bflow->blk ? bflow->blk->name : "(none)"); @@ -508,7 +518,7 @@ static char bootflow_help_text[] = "scan [-abeGl] [bdev] - scan for valid bootflows (-l list, -a all, -e errors, -b boot, -G no global)\n" "bootflow list [-e] - list scanned bootflows (-e errors)\n" "bootflow select [<num>|<name>] - select a bootflow\n" - "bootflow info [-d] - show info on current bootflow (-d dump bootflow)\n" + "bootflow info [-ds] - show info on current bootflow (-d dump bootflow)\n" "bootflow boot - boot current bootflow (or first available if none selected)\n" "bootflow menu [-t] - show a menu of available bootflows\n" "bootflow cmdline [set|get|clear|delete|auto] <param> [<value>] - update cmdline"; diff --git a/doc/usage/cmd/bootflow.rst b/doc/usage/cmd/bootflow.rst index a8af1f8f6030..d53f8373eff0 100644 --- a/doc/usage/cmd/bootflow.rst +++ b/doc/usage/cmd/bootflow.rst @@ -11,7 +11,7 @@ Synopis bootflow scan [-abelGH] [bootdev] bootflow list [-e] bootflow select [<num|name>] - bootflow info [-d] + bootflow info [-ds] bootflow boot bootflow cmdline [set|get|clear|delete|auto] <param> [<value>]
@@ -191,6 +191,8 @@ Error
Use the `-d` flag to dump out the contents of the bootfile file.
+The `-s` flag shows any x86 setup block, instead of the above. +
bootflow boot ~~~~~~~~~~~~~ @@ -522,6 +524,61 @@ the cmdline is word-wrapped here and some parts of the command line are elided:: [ 0.000000] Command line: loglevel=7 ... usb-storage.quirks=13fe:6500:u earlycon=uart8250,mmio32,0xfe03e000,115200n8 [ 0.000000] x86/split lock detection: warning about user-space split_locks
+This shows looking at x86 setup information:: + + => bootfl sel 0 + => bootfl i -s + Setup located at 77b56010: + + ACPI RSDP addr : 0 + E820: 2 entries + Addr Size Type + 0 1000 RAM + fffff000 1000 Reserved + Setup sectors : 1e + Root flags : 1 + Sys size : 63420 + RAM size : 0 + Video mode : ffff + Root dev : 0 + Boot flag : 0 + Jump : 66eb + Header : 53726448 + Kernel V2 + Version : 20d + Real mode switch : 0 + Start sys seg : 1000 + Kernel version : 38cc + @00003acc: + Type of loader : ff + unknown + Load flags : 1 + : loaded-high + Setup move size : 8000 + Code32 start : 100000 + Ramdisk image : 0 + Ramdisk size : 0 + Bootsect kludge : 0 + Heap end ptr : 5160 + Ext loader ver : 0 + Ext loader type : 0 + Command line ptr : 735000 + Initrd addr max : 7fffffff + Kernel alignment : 200000 + Relocatable kernel : 1 + Min alignment : 15 + : 200000 + Xload flags : 3 + : 64-bit-entry can-load-above-4gb + Cmdline size : 7ff + Hardware subarch : 0 + HW subarch data : 0 + Payload offset : 26e + Payload length : 612045 + Setup data : 0 + Pref address : 1000000 + Init size : 1383000 + Handover offset : 0
Return value diff --git a/include/bootflow.h b/include/bootflow.h index ff2bddb51515..fdcfeddc1a63 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -108,7 +108,7 @@ struct bootflow { ulong fdt_addr; int flags; char *cmdline; - char *x86_setup; + void *x86_setup; void *bootmeth_priv; };
diff --git a/include/bootm.h b/include/bootm.h index 6fe418e00272..92870ff1a206 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -152,4 +152,15 @@ int zboot_start(ulong addr, ulong size, ulong initrd, ulong initrd_size, const char *zimage_get_kernel_version(struct boot_params *params, void *kernel_base);
+/** + * zimage_dump() - Dump the metadata of a zimage + * + * This shows all available information in a zimage that has been loaded. + * + * @base_ptr: Pointer to the boot parameters, typically at address + * DEFAULT_SETUP_BASE + * @show_cmdline: true to show the full command line + */ +void zimage_dump(struct boot_params *base_ptr, bool show_cmdline); + #endif

Provide an option to dump this information if available.
Move the funciion prototype to the common x86 header. Allow the command line to be left out since 'bootflow info' show this itself and it is not in the correct place in memory until the kernel is actually booted.
Fix a badly aligned heading while we are here.
Signed-off-by: Simon Glass sjg@chromium.org ---
arch/x86/include/asm/zimage.h | 10 ------ arch/x86/lib/zimage.c | 8 ++--- cmd/bootflow.c | 14 +++++++-- doc/usage/cmd/bootflow.rst | 59 ++++++++++++++++++++++++++++++++++- include/bootflow.h | 2 +- include/bootm.h | 11 +++++++ 6 files changed, 86 insertions(+), 18 deletions(-)
Applied to u-boot-dm/next, thanks!

Some bootflows (such as EFI and ChromiumOS) delay reading the kernel until it is needed to boot. This saves time when scanning and avoids needing to allocate memory for something that may never be used.
To permit reading of these files, add a new 'bootflow read' command.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/bootflow.c | 14 +++++++ boot/bootmeth-uclass.c | 10 +++++ boot/bootmeth_cros.c | 18 ++++++++- cmd/bootflow.c | 33 +++++++++++++++- doc/usage/cmd/bootflow.rst | 80 +++++++++++++++++++++++++++++++++++++- include/bootflow.h | 11 ++++++ include/bootmeth.h | 23 +++++++++++ 7 files changed, 186 insertions(+), 3 deletions(-)
diff --git a/boot/bootflow.c b/boot/bootflow.c index daf862fac788..815eaa4136bb 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -445,6 +445,20 @@ void bootflow_remove(struct bootflow *bflow) free(bflow); }
+int bootflow_read_all(struct bootflow *bflow) +{ + int ret; + + if (bflow->state != BOOTFLOWST_READY) + return log_msg_ret("rd", -EPROTO); + + ret = bootmeth_read_all(bflow->method, bflow); + if (ret) + return log_msg_ret("rd2", ret); + + return 0; +} + int bootflow_boot(struct bootflow *bflow) { int ret; diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c index eeded08dd428..4cc3d90d20be 100644 --- a/boot/bootmeth-uclass.c +++ b/boot/bootmeth-uclass.c @@ -61,6 +61,16 @@ int bootmeth_set_bootflow(struct udevice *dev, struct bootflow *bflow, return ops->set_bootflow(dev, bflow, buf, size); }
+int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow) +{ + const struct bootmeth_ops *ops = bootmeth_get_ops(dev); + + if (!ops->read_all) + return -ENOSYS; + + return ops->read_all(dev, bflow); +} + int bootmeth_boot(struct udevice *dev, struct bootflow *bflow) { const struct bootmeth_ops *ops = bootmeth_get_ops(dev); diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 06709dd9171c..570e7028329c 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -395,13 +395,28 @@ static int cros_read_file(struct udevice *dev, struct bootflow *bflow, return -ENOSYS; }
-static int cros_boot(struct udevice *dev, struct bootflow *bflow) +static int cros_read_all(struct udevice *dev, struct bootflow *bflow) { int ret;
+ if (bflow->buf) + return log_msg_ret("ld", -EALREADY); ret = cros_read_kernel(bflow); if (ret) return log_msg_ret("rd", ret); + + return 0; +} + +static int cros_boot(struct udevice *dev, struct bootflow *bflow) +{ + int ret; + + if (!bflow->buf) { + ret = cros_read_kernel(bflow); + if (ret) + return log_msg_ret("rd", ret); + } #ifdef CONFIG_X86 zboot_start(map_to_sysmem(bflow->buf), bflow->size, 0, 0, map_to_sysmem(bflow->x86_setup), @@ -425,6 +440,7 @@ static struct bootmeth_ops cros_bootmeth_ops = { .read_bootflow = cros_read_bootflow, .read_file = cros_read_file, .boot = cros_boot, + .read_all = cros_read_all, };
static const struct udevice_id cros_bootmeth_ids[] = { diff --git a/cmd/bootflow.c b/cmd/bootflow.c index 9562832ce438..3c3abaf8a3b2 100644 --- a/cmd/bootflow.c +++ b/cmd/bootflow.c @@ -379,6 +379,35 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc, return 0; }
+static int do_bootflow_read(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + struct bootstd_priv *std; + struct bootflow *bflow; + int ret; + + ret = bootstd_get_priv(&std); + if (ret) + return CMD_RET_FAILURE; + + /* + * Require a current bootflow. Users can use 'bootflow scan -b' to + * automatically scan and boot, if needed. + */ + if (!std->cur_bootflow) { + printf("No bootflow selected\n"); + return CMD_RET_FAILURE; + } + bflow = std->cur_bootflow; + ret = bootflow_read_all(bflow); + if (ret) { + printf("Failed: err=%dE\n", ret); + return CMD_RET_FAILURE; + } + + return 0; +} + static int do_bootflow_boot(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -519,7 +548,8 @@ static char bootflow_help_text[] = "bootflow list [-e] - list scanned bootflows (-e errors)\n" "bootflow select [<num>|<name>] - select a bootflow\n" "bootflow info [-ds] - show info on current bootflow (-d dump bootflow)\n" - "bootflow boot - boot current bootflow (or first available if none selected)\n" + "bootflow read - read all current-bootflow files\n" + "bootflow boot - boot current bootflow\n" "bootflow menu [-t] - show a menu of available bootflows\n" "bootflow cmdline [set|get|clear|delete|auto] <param> [<value>] - update cmdline"; #else @@ -533,6 +563,7 @@ U_BOOT_CMD_WITH_SUBCMDS(bootflow, "Boot flows", bootflow_help_text, U_BOOT_SUBCMD_MKENT(list, 2, 1, do_bootflow_list), U_BOOT_SUBCMD_MKENT(select, 2, 1, do_bootflow_select), U_BOOT_SUBCMD_MKENT(info, 2, 1, do_bootflow_info), + U_BOOT_SUBCMD_MKENT(read, 1, 1, do_bootflow_read), U_BOOT_SUBCMD_MKENT(boot, 1, 1, do_bootflow_boot), U_BOOT_SUBCMD_MKENT(menu, 2, 1, do_bootflow_menu), U_BOOT_SUBCMD_MKENT(cmdline, 4, 1, do_bootflow_cmdline), diff --git a/doc/usage/cmd/bootflow.rst b/doc/usage/cmd/bootflow.rst index d53f8373eff0..ead493d0aaf8 100644 --- a/doc/usage/cmd/bootflow.rst +++ b/doc/usage/cmd/bootflow.rst @@ -12,6 +12,7 @@ Synopis bootflow list [-e] bootflow select [<num|name>] bootflow info [-ds] + bootflow read bootflow boot bootflow cmdline [set|get|clear|delete|auto] <param> [<value>]
@@ -194,10 +195,26 @@ Use the `-d` flag to dump out the contents of the bootfile file. The `-s` flag shows any x86 setup block, instead of the above.
+bootflow read +~~~~~~~~~~~~~ + +This reads any files related to the bootflow. Some bootflows with large files +avoid doing this when the bootflow is scanned, since it uses a lot of memory +and takes extra time. The files are then automatically read when `bootflow boot` +is used. + +This command reads these files immediately. Typically this fills in the bootflow +`buf` property, which can be used to examine the bootflow. + +Note that reading the files does not result in any extra parsing, nor loading of +images in the files. This is purely used to read in the data ready for +booting, or examination. + + bootflow boot ~~~~~~~~~~~~~
-This boots the current bootflow. +This boots the current bootflow, reading any required files first.
bootflow cmdline @@ -580,6 +597,67 @@ This shows looking at x86 setup information:: Init size : 1383000 Handover offset : 0
+This shows reading a bootflow to examine the kernel:: + + => bootfl i 0 + Name: + Device: emmc@1c,0.bootdev + Block dev: emmc@1c,0.blk + Method: cros + State: ready + Partition: 2 + Subdir: (none) + Filename: <NULL> + Buffer: 0 + Size: 63ee00 (6548992 bytes) + OS: ChromeOS + Cmdline: console= loglevel=7 init=/sbin/init cros_secure oops=panic panic=-1 root=PARTUUID=35c775e7-3735-d745-93e5-d9e0238f7ed0/PARTNROFF=1 rootwait rw dm_verity.error_behavior=3 dm_verity.max_bios=-1 dm_verity.dev_wait=0 dm="1 vroot none rw 1,0 3788800 verity payload=ROOT_DEV hashtree=HASH_DEV hashstart=3788800 alg=sha1 root_hexdigest=55052b629d3ac889f25a9583ea12cdcd3ea15ff8 salt=a2d4d9e574069f4fed5e3961b99054b7a4905414b60a25d89974a7334021165c" noinitrd vt.global_cursor_default=0 kern_guid=35c775e7-3735-d745-93e5-d9e0238f7ed0 add_efi_memmap boot=local noresume noswap i915.modeset=1 tpm_tis.force=1 tpm_tis.interrupts=0 nmi_watchdog=panic,lapic disablevmx=off + X86 setup: 77b56010 + Logo: (none) + FDT: <NULL> + Error: 0 + +Note that `Buffer` is 0 so it has not be read yet. Using `bootflow read`:: + + => bootfl read + => bootfl info + Name: + Device: emmc@1c,0.bootdev + Block dev: emmc@1c,0.blk + Method: cros + State: ready + Partition: 2 + Subdir: (none) + Filename: <NULL> + Buffer: 77b7e400 + Size: 63ee00 (6548992 bytes) + OS: ChromeOS + Cmdline: console= loglevel=7 init=/sbin/init cros_secure oops=panic panic=-1 root=PARTUUID=35c775e7-3735-d745-93e5-d9e0238f7ed0/PARTNROFF=1 rootwait rw dm_verity.error_behavior=3 dm_verity.max_bios=-1 dm_verity.dev_wait=0 dm="1 vroot none rw 1,0 3788800 verity payload=ROOT_DEV hashtree=HASH_DEV hashstart=3788800 alg=sha1 root_hexdigest=55052b629d3ac889f25a9583ea12cdcd3ea15ff8 salt=a2d4d9e574069f4fed5e3961b99054b7a4905414b60a25d89974a7334021165c" noinitrd vt.global_cursor_default=0 kern_guid=35c775e7-3735-d745-93e5-d9e0238f7ed0 add_efi_memmap boot=local noresume noswap i915.modeset=1 tpm_tis.force=1 tpm_tis.interrupts=0 nmi_watchdog=panic,lapic disablevmx=off + X86 setup: 781b4400 + Logo: (none) + FDT: <NULL> + Error: 0 + +Now the buffer can be accessed:: + + => md 77b7e400 + 77b7e400: 1186f6fc 40000002 b8fa0c75 00000018 .......@u....... + 77b7e410: c08ed88e a68dd08e 000001e8 000000e8 ................ + 77b7e420: ed815d00 00000021 62c280b8 89e80100 .]..!......b.... + 77b7e430: 22f7e8c4 c0850061 22ec850f eb890061 ..."a......"a... + 77b7e440: 0230868b 01480000 21d0f7c3 00fb81c3 ..0...H....!.... + 77b7e450: 7d010000 0000bb05 c3810100 00d4f000 ...}............ + 77b7e460: 8130858d 85890061 00618132 3095010f ..0.a...2.a....0 + 77b7e470: 0f006181 c883e020 e0220f20 e000bb8d .a.. ... ."..... + 77b7e480: c0310062 001800b9 8dabf300 62e000bb b.1............b + 77b7e490: 07878d00 89000010 00bb8d07 8d0062f0 .............b.. + 77b7e4a0: 00100787 0004b900 07890000 00100005 ................ + 77b7e4b0: 08c78300 8df37549 630000bb 0183b800 ....Iu.....c.... + 77b7e4c0: 00b90000 89000008 00000507 c7830020 ............ ... + 77b7e4d0: f3754908 e000838d 220f0062 0080b9d8 .Iu.....b..".... + 77b7e4e0: 320fc000 08e8ba0f c031300f b8d0000f ...2.....01..... + 77b7e4f0: 00000020 6ad8000f 00858d10 50000002 ......j.......P +
Return value ------------ diff --git a/include/bootflow.h b/include/bootflow.h index fdcfeddc1a63..44d3741eacae 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -352,6 +352,17 @@ void bootflow_free(struct bootflow *bflow); */ int bootflow_boot(struct bootflow *bflow);
+/** + * bootflow_read_all() - Read all bootflow files + * + * Some bootmeths delay reading of large files until booting is requested. This + * causes those files to be read. + * + * @bflow: Bootflow to read + * Return: result of trying to read + */ +int bootflow_read_all(struct bootflow *bflow); + /** * bootflow_run_boot() - Try to boot a bootflow * diff --git a/include/bootmeth.h b/include/bootmeth.h index c3df9702e871..4beca16793bc 100644 --- a/include/bootmeth.h +++ b/include/bootmeth.h @@ -120,6 +120,15 @@ struct bootmeth_ops { int (*read_file)(struct udevice *dev, struct bootflow *bflow, const char *file_path, ulong addr, ulong *sizep);
+ /** + * readall() - read all files for a bootflow + * + * @dev: Bootmethod device to boot + * @bflow: Bootflow to read + * Return: 0 if OK, -EIO on I/O error, other -ve on other error + */ + int (*read_all)(struct udevice *dev, struct bootflow *bflow); + /** * boot() - boot a bootflow * @@ -223,6 +232,20 @@ int bootmeth_set_bootflow(struct udevice *dev, struct bootflow *bflow, int bootmeth_read_file(struct udevice *dev, struct bootflow *bflow, const char *file_path, ulong addr, ulong *sizep);
+/** + * bootmeth_read_all() - read all bootflow files + * + * Some bootmeths delay reading of large files until booting is requested. This + * causes those files to be read. + * + * @dev: Bootmethod device to use + * @bflow: Bootflow to read + * Return: does not return on success, since it should boot the + * Operating Systemn. Returns -EFAULT if that fails, other -ve on + * other error + */ +int bootmeth_read_all(struct udevice *dev, struct bootflow *bflow); + /** * bootmeth_boot() - boot a bootflow *

Support booting ChromiumOS on ARM devices using FIT. Add an entry into the boot implementation which does not require a command line. This can be expanded over time as the bootm code is refactored.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/Kconfig | 4 ++-- boot/bootm.c | 37 +++++++++++++++++++++++++++++++++++++ boot/bootmeth_cros.c | 16 ++++++++++------ include/bootm.h | 8 ++++++++ 4 files changed, 57 insertions(+), 8 deletions(-)
diff --git a/boot/Kconfig b/boot/Kconfig index e8fb03b80168..6fb5b1e8b430 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -464,8 +464,8 @@ config BOOTMETH_GLOBAL
config BOOTMETH_CROS bool "Bootdev support for Chromium OS" - depends on X86 || SANDBOX - default y + depends on X86 || ARM || SANDBOX + default y if !ARM help Enables support for booting Chromium OS using bootdevs. This uses the kernel A slot and obtains the kernel command line from the parameters diff --git a/boot/bootm.c b/boot/bootm.c index 75f0b4a9af8a..b1c3afe0a3ad 100644 --- a/boot/bootm.c +++ b/boot/bootm.c @@ -823,6 +823,43 @@ err: return ret; }
+int bootm_boot_start(ulong addr, const char *cmdline) +{ + static struct cmd_tbl cmd = {"bootm"}; + char addr_str[30]; + char *argv[] = {addr_str, NULL}; + int states; + int ret; + + /* + * TODO(sjg@chromium.org): This uses the command-line interface, but + * should not. To clean this up, the various bootm states need to be + * passed an info structure instead of cmdline flags. Then this can + * set up the required info and move through the states without needing + * the command line. + */ + states = BOOTM_STATE_START | BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD | + BOOTM_STATE_FINDOTHER | BOOTM_STATE_LOADOS | + BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | + BOOTM_STATE_OS_GO; + if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) + states |= BOOTM_STATE_RAMDISK; + if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS)) + states |= BOOTM_STATE_OS_CMDLINE; + images.state |= states; + + snprintf(addr_str, sizeof(addr_str), "%lx", addr); + + ret = env_set("bootargs", cmdline); + if (ret) { + printf("Failed to set cmdline\n"); + return ret; + } + ret = do_bootm_states(&cmd, 0, 1, argv, states, &images, 1); + + return ret; +} + #if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT) /** * image_get_kernel - verify legacy format kernel image diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c index 570e7028329c..da9bb6b4281c 100644 --- a/boot/bootmeth_cros.c +++ b/boot/bootmeth_cros.c @@ -417,13 +417,17 @@ static int cros_boot(struct udevice *dev, struct bootflow *bflow) if (ret) return log_msg_ret("rd", ret); } -#ifdef CONFIG_X86 - zboot_start(map_to_sysmem(bflow->buf), bflow->size, 0, 0, - map_to_sysmem(bflow->x86_setup), - bflow->cmdline); -#endif
- return log_msg_ret("go", -EFAULT); + 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); + } else { + ret = bootm_boot_start(map_to_sysmem(bflow->buf), + bflow->cmdline); + } + + return log_msg_ret("go", ret); }
static int cros_bootmeth_bind(struct udevice *dev) diff --git a/include/bootm.h b/include/bootm.h index 92870ff1a206..c3c7336207b1 100644 --- a/include/bootm.h +++ b/include/bootm.h @@ -163,4 +163,12 @@ const char *zimage_get_kernel_version(struct boot_params *params, */ void zimage_dump(struct boot_params *base_ptr, bool show_cmdline);
+/* + * bootm_boot_start() - Boot an image at the given address + * + * @addr: Image address + * @cmdline: Command line to set + */ +int bootm_boot_start(ulong addr, const char *cmdline); + #endif

Support booting ChromiumOS on ARM devices using FIT. Add an entry into the boot implementation which does not require a command line. This can be expanded over time as the bootm code is refactored.
Signed-off-by: Simon Glass sjg@chromium.org ---
boot/Kconfig | 4 ++-- boot/bootm.c | 37 +++++++++++++++++++++++++++++++++++++ boot/bootmeth_cros.c | 16 ++++++++++------ include/bootm.h | 8 ++++++++ 4 files changed, 57 insertions(+), 8 deletions(-)
Applied to u-boot-dm/next, thanks!

Hi Simon,
On 2023-07-30 20:16 +03:00, Simon Glass wrote:
The ChromiumOS bootmeth is fairly basic at present. It is able to boot only x86 kernels and contains quite a few hard-coded offsets.
This series tidies it up by bringing in some vboot structures and adding support for ARM.
It adds a few more features to bootstd, including display of x86 setup information.
Can't do a detailed review or test for a while, but had a cursory look now and wanted to reply. I'm not sure if you heard of it, but I maintain an alternate implementation of ChromiumOS verified boot userspace called depthcharge-tools [1]. Its main purpose is booting ordinary distros on Chromebooks, but it would be nice if your U-Boot implementation was also compatible with images produced from that.
I guess it boils down to:
- Enable booting from any chromeos_kernel partition (not just 2 & 4) - Fixup the ramdisk addr/size in x86 setup info after reading the kernel - Replace %U with chromeos_kernel PARTUUID (you probably already do?) - Prepend cros_secure to kernel cmdline
There's a ready made debian-installer image if you want to test [2]. Has a partitioning bug defaulting to MBR, but otherwise can install for CrOS verified boot as well. (It's what took my last year away from U-Boot).
[1] depthcharge-tools -- Tools to manage the Chrome OS bootloader https://github.com/alpernebbi/depthcharge-tools
[2] Debian Installer netboot image for amd64 Chromebooks https://d-i.debian.org/daily-images/amd64/daily/netboot/depthcharge/
So far this does not actually boot correctly on any ARM Chromebook:
jerry - hangs when booting kernel bob - Bad Linux ARM64 Image magic! with lz4-compressed kernel
Further work can address these issues.
I haven't been able to boot recent kernels with extlinux.conf on my pre-bootstd kevin U-Boot builds which I remember were working with older kernels. And I've heard people not being boot with extlinux.conf on veyrons as well. Might be the same, maybe try an older kernel for jerry?
Again, there's a debian-installer arm64 image if you want to test [3], which could work fine on bob (not with depthcharge's size limit though), but kernel support is missing for anything else.
Oh, and postmarketOS also supports CrOS verified boot [4] via depthcharge-tools, but they don't have pre-built images and it's a bit of a hassle.
[3] Debian Installer netboot image for arm64 Chromebooks https://d-i.debian.org/daily-images/arm64/daily/netboot/depthcharge/
[4] postmarketOS Wiki - Chrome OS devices https://wiki.postmarketos.org/wiki/Chrome_OS_devices
Anyway, I'm glad you're working on this, looking forward to testing it myself when I get the chance!
Simon Glass (16): bootstd: cros: Correct reporting of I/O errors bootstd: cros: Move partition reading into a function bootstd: cros: Bring in some ChromiumOS structures bootstd: cros: Support a kernel on either partition bootstd: cros: Decode some kernel preamble fields bootstd: cros: Simplify setup and cmdline expressions bootstd: Move common zimage functions to bootm.h bootstd: cros: Add docs for the kernel layout bootstd: cros: Add private info for ChromiumOS bootstd: Add private bootmeth data to the bootflow bootstd: cros: Add a function to read info from partition bootstd: cros: Add a function to read a kernel bootstd: cros: Split up reading info and kernel bootstd: Allow display of the x86 setup information bootstd: Add a command to read all files for a bootflow bootstd: cros: Add ARM support
arch/x86/include/asm/zimage.h | 37 ---- arch/x86/lib/zimage.c | 8 +- boot/Kconfig | 4 +- boot/bootflow.c | 15 ++ boot/bootm.c | 37 ++++ boot/bootmeth-uclass.c | 10 + boot/bootmeth_cros.c | 363 ++++++++++++++++++++++++++++------ boot/bootmeth_cros.h | 197 ++++++++++++++++++ cmd/bootflow.c | 47 ++++- doc/usage/cmd/bootflow.rst | 139 ++++++++++++- include/bootflow.h | 15 +- include/bootm.h | 47 +++++ include/bootmeth.h | 23 +++ 13 files changed, 836 insertions(+), 106 deletions(-) create mode 100644 boot/bootmeth_cros.h

Hi Alper,
On Thu, 3 Aug 2023 at 15:31, Alper Nebi Yasak alpernebiyasak@gmail.com wrote:
Hi Simon,
On 2023-07-30 20:16 +03:00, Simon Glass wrote:
The ChromiumOS bootmeth is fairly basic at present. It is able to boot only x86 kernels and contains quite a few hard-coded offsets.
This series tidies it up by bringing in some vboot structures and adding support for ARM.
It adds a few more features to bootstd, including display of x86 setup information.
Can't do a detailed review or test for a while, but had a cursory look now and wanted to reply. I'm not sure if you heard of it, but I maintain an alternate implementation of ChromiumOS verified boot userspace called depthcharge-tools [1]. Its main purpose is booting ordinary distros on Chromebooks, but it would be nice if your U-Boot implementation was also compatible with images produced from that.
I guess it boils down to:
- Enable booting from any chromeos_kernel partition (not just 2 & 4)
How do you know which ones hold kernels, and which root disks correspond to each kernel?
- Fixup the ramdisk addr/size in x86 setup info after reading the kernel
But ChromeOS doesn't use ramdisk, right?
- Replace %U with chromeos_kernel PARTUUID (you probably already do?)
Yes.
- Prepend cros_secure to kernel cmdline
Does it have to be at the start of the cmdline? Also, the cmdline comes from cros at present, so does include that normally. I think the best way is for you to give it a try and see what is needed.
There's a ready made debian-installer image if you want to test [2]. Has a partitioning bug defaulting to MBR, but otherwise can install for CrOS verified boot as well. (It's what took my last year away from U-Boot).
[1] depthcharge-tools -- Tools to manage the Chrome OS bootloader https://github.com/alpernebbi/depthcharge-tools
[2] Debian Installer netboot image for amd64 Chromebooks https://d-i.debian.org/daily-images/amd64/daily/netboot/depthcharge/
I see the installer, but how do I actually run it on bob, say?
So far this does not actually boot correctly on any ARM Chromebook:
jerry - hangs when booting kernel bob - Bad Linux ARM64 Image magic! with lz4-compressed kernel
Further work can address these issues.
I haven't been able to boot recent kernels with extlinux.conf on my pre-bootstd kevin U-Boot builds which I remember were working with older kernels. And I've heard people not being boot with extlinux.conf on veyrons as well. Might be the same, maybe try an older kernel for jerry?
Ah OK I haven't tried that.
Again, there's a debian-installer arm64 image if you want to test [3], which could work fine on bob (not with depthcharge's size limit though), but kernel support is missing for anything else.
Oh, and postmarketOS also supports CrOS verified boot [4] via depthcharge-tools, but they don't have pre-built images and it's a bit of a hassle.
[3] Debian Installer netboot image for arm64 Chromebooks https://d-i.debian.org/daily-images/arm64/daily/netboot/depthcharge/
[4] postmarketOS Wiki - Chrome OS devices https://wiki.postmarketos.org/wiki/Chrome_OS_devices
Anyway, I'm glad you're working on this, looking forward to testing it myself when I get the chance!
Great! I hope that the bootmeth can expand to be more useful over time.
Regards, Simon
Simon Glass (16): bootstd: cros: Correct reporting of I/O errors bootstd: cros: Move partition reading into a function bootstd: cros: Bring in some ChromiumOS structures bootstd: cros: Support a kernel on either partition bootstd: cros: Decode some kernel preamble fields bootstd: cros: Simplify setup and cmdline expressions bootstd: Move common zimage functions to bootm.h bootstd: cros: Add docs for the kernel layout bootstd: cros: Add private info for ChromiumOS bootstd: Add private bootmeth data to the bootflow bootstd: cros: Add a function to read info from partition bootstd: cros: Add a function to read a kernel bootstd: cros: Split up reading info and kernel bootstd: Allow display of the x86 setup information bootstd: Add a command to read all files for a bootflow bootstd: cros: Add ARM support
arch/x86/include/asm/zimage.h | 37 ---- arch/x86/lib/zimage.c | 8 +- boot/Kconfig | 4 +- boot/bootflow.c | 15 ++ boot/bootm.c | 37 ++++ boot/bootmeth-uclass.c | 10 + boot/bootmeth_cros.c | 363 ++++++++++++++++++++++++++++------ boot/bootmeth_cros.h | 197 ++++++++++++++++++ cmd/bootflow.c | 47 ++++- doc/usage/cmd/bootflow.rst | 139 ++++++++++++- include/bootflow.h | 15 +- include/bootm.h | 47 +++++ include/bootmeth.h | 23 +++ 13 files changed, 836 insertions(+), 106 deletions(-) create mode 100644 boot/bootmeth_cros.h

(Note that I'm not objecting to merging the patchset as is, just detailing future work you/I might want to do for non-CrOS userspace support for this bootmeth.)
On 2023-08-04 06:02 +03:00, Simon Glass wrote:
On Thu, 3 Aug 2023 at 15:31, Alper Nebi Yasak alpernebiyasak@gmail.com wrote:
I guess it boils down to:
- Enable booting from any chromeos_kernel partition (not just 2 & 4)
How do you know which ones hold kernels, and which root disks correspond to each kernel?
You should search all those with FE3A2A5D-4F32-41A7-B725-ACCC3285A309 as their GPT partition type GUID. They are ordered wrt/ the type-specific Successful, Priority, Tries attribute flags (bits 56, 55-52, 51-48). The firmware is also supposed to modify these (decrement Tries on each boot attempt, set Priority = 0 if Tries == 0). All these are stock depthcharge behaviour, see ChromiumOS docs [5].
The kernels don't necessarily correspond to a specific root, that's a per-OS concept. For example on Debian, I have two or three of these partitions for the same rootfs used in a cyclic fashion to have A/B-style automatic fallback for kernel/initramfs changes. And there may not be a rootfs at all, like how Debian Installer runs entirely from its initramfs.
[5] ChromiumOS Docs - Disk Format - Selecting the kernel https://chromium.googlesource.com/chromiumos/docs/+/HEAD/disk_format.md#sele...
- Fixup the ramdisk addr/size in x86 setup info after reading the kernel
But ChromeOS doesn't use ramdisk, right?
Not in this way, AFAIK it embeds one into vmlinuz during compile-time? I guess the ramdisk addr/size in x86 setup is 0/0 for ChromeOS indicating there isn't (an external) one.
But depthcharge is so minimalistic that it loads everything at a fixed address and passes x86 setup unchanged as prepared beforehand, so I can append a ramdisk to vmlinuz and tell Linux where that will end up in memory behind depthcharge's back. (A bit more complicated than that.)
So the thing is, when bootmeth_cros reads the "kernel" data into memory somewhere other than 0x100000, the x86 setup from my images will be pointing to an unrelated location as the ramdisk, which Linux will fail to interpret as a ramdisk and panic.
- Prepend cros_secure to kernel cmdline
Does it have to be at the start of the cmdline? Also, the cmdline comes from cros at present, so does include that normally. I think the best way is for you to give it a try and see what is needed.
Doesn't have to be at the start, but Depthcharge unconditionally prepends it, I do see multiple "cros_secure"s on ChromeOS /proc/cmdline.
I'd like to have that here too as a way to identify the boot method, since non-CrOS userspaces will not have configured cmdline to have that. In Debian Installer, I do `grep cros_secure /proc/cmdline` to see if we should set up with depthcharge-tools or something else like GRUB.
(Yeah, I should be testing this, but stretched myself too thin.)
There's a ready made debian-installer image if you want to test [2]. Has a partitioning bug defaulting to MBR, but otherwise can install for CrOS verified boot as well. (It's what took my last year away from U-Boot).
[1] depthcharge-tools -- Tools to manage the Chrome OS bootloader https://github.com/alpernebbi/depthcharge-tools
[2] Debian Installer netboot image for amd64 Chromebooks https://d-i.debian.org/daily-images/amd64/daily/netboot/depthcharge/
I see the installer, but how do I actually run it on bob, say?
I hoped the names were self-evident, but I know I should be writing docs on them, just postponing until they are in better shape.
Basically `gzip -d <disk.img.gz | dd of=/dev/sdX` to a USB flash drive or microSD card. It's an compressed GPT disk image containing just one partition. With stock depthcharge, switch to Developer Mode, insert the drive/card and press Ctrl+U on the "OS verification is disabled" warning. With U-Boot and bootmeth_cros I think you would at least need to patch it for the first partition, and for the ramdisk address.
But the arm64 one won't work on stock depthcharge at all, since pre-2018 devices like bob have an ugly size limit this doesn't yet fit into, and anything else lacks kernel support on the Debian side.
... So maybe try the amd64 one on brya?

Hi Alper,
On Fri, 4 Aug 2023 at 03:51, Alper Nebi Yasak alpernebiyasak@gmail.com wrote:
(Note that I'm not objecting to merging the patchset as is, just detailing future work you/I might want to do for non-CrOS userspace support for this bootmeth.)
On 2023-08-04 06:02 +03:00, Simon Glass wrote:
On Thu, 3 Aug 2023 at 15:31, Alper Nebi Yasak alpernebiyasak@gmail.com wrote:
I guess it boils down to:
- Enable booting from any chromeos_kernel partition (not just 2 & 4)
How do you know which ones hold kernels, and which root disks correspond to each kernel?
You should search all those with FE3A2A5D-4F32-41A7-B725-ACCC3285A309 as their GPT partition type GUID. They are ordered wrt/ the type-specific Successful, Priority, Tries attribute flags (bits 56, 55-52, 51-48). The firmware is also supposed to modify these (decrement Tries on each boot attempt, set Priority = 0 if Tries == 0). All these are stock depthcharge behaviour, see ChromiumOS docs [5].
The kernels don't necessarily correspond to a specific root, that's a per-OS concept. For example on Debian, I have two or three of these partitions for the same rootfs used in a cyclic fashion to have A/B-style automatic fallback for kernel/initramfs changes. And there may not be a rootfs at all, like how Debian Installer runs entirely from its initramfs.
OK I see.
[5] ChromiumOS Docs - Disk Format - Selecting the kernel https://chromium.googlesource.com/chromiumos/docs/+/HEAD/disk_format.md#sele...
- Fixup the ramdisk addr/size in x86 setup info after reading the kernel
But ChromeOS doesn't use ramdisk, right?
Not in this way, AFAIK it embeds one into vmlinuz during compile-time? I guess the ramdisk addr/size in x86 setup is 0/0 for ChromeOS indicating there isn't (an external) one.
But depthcharge is so minimalistic that it loads everything at a fixed address and passes x86 setup unchanged as prepared beforehand, so I can append a ramdisk to vmlinuz and tell Linux where that will end up in memory behind depthcharge's back. (A bit more complicated than that.)
So the thing is, when bootmeth_cros reads the "kernel" data into memory somewhere other than 0x100000, the x86 setup from my images will be pointing to an unrelated location as the ramdisk, which Linux will fail to interpret as a ramdisk and panic.
- Prepend cros_secure to kernel cmdline
Does it have to be at the start of the cmdline? Also, the cmdline comes from cros at present, so does include that normally. I think the best way is for you to give it a try and see what is needed.
Doesn't have to be at the start, but Depthcharge unconditionally prepends it, I do see multiple "cros_secure"s on ChromeOS /proc/cmdline.
I'd like to have that here too as a way to identify the boot method, since non-CrOS userspaces will not have configured cmdline to have that. In Debian Installer, I do `grep cros_secure /proc/cmdline` to see if we should set up with depthcharge-tools or something else like GRUB.
(Yeah, I should be testing this, but stretched myself too thin.)
There's a ready made debian-installer image if you want to test [2]. Has a partitioning bug defaulting to MBR, but otherwise can install for CrOS verified boot as well. (It's what took my last year away from U-Boot).
[1] depthcharge-tools -- Tools to manage the Chrome OS bootloader https://github.com/alpernebbi/depthcharge-tools
[2] Debian Installer netboot image for amd64 Chromebooks https://d-i.debian.org/daily-images/amd64/daily/netboot/depthcharge/
I see the installer, but how do I actually run it on bob, say?
I hoped the names were self-evident, but I know I should be writing docs on them, just postponing until they are in better shape.
Basically `gzip -d <disk.img.gz | dd of=/dev/sdX` to a USB flash drive or microSD card. It's an compressed GPT disk image containing just one partition. With stock depthcharge, switch to Developer Mode, insert the drive/card and press Ctrl+U on the "OS verification is disabled" warning. With U-Boot and bootmeth_cros I think you would at least need to patch it for the first partition, and for the ramdisk address.
But the arm64 one won't work on stock depthcharge at all, since pre-2018 devices like bob have an ugly size limit this doesn't yet fit into, and anything else lacks kernel support on the Debian side.
... So maybe try the amd64 one on brya?
Well I think I will apply this series (with a fix I found) and we can go from there.
I will look at using the EFI partition type to detect kernels. I will also see if I can get a test into CI for the ChromiumOS bootmeth, since it isn't much use without tests.
Then perhaps you might have time to enhance it from there for your use case?
I do imagine one day resurrecting the 2021-era vboot in U-Boot, as a proper bootmeth, but I am not sure when.
The kernel situation on ARM sounds a little grim. I will check internally to see if I can figure that out.
Regards, Simon

I have never asked to want receive emails related to chromiumos, so do not send these changes to me.
On Sunday 30 July 2023 11:16:46 Simon Glass wrote:
The ChromiumOS bootmeth is fairly basic at present. It is able to boot only x86 kernels and contains quite a few hard-coded offsets.
This series tidies it up by bringing in some vboot structures and adding support for ARM.
It adds a few more features to bootstd, including display of x86 setup information.
So far this does not actually boot correctly on any ARM Chromebook:
jerry - hangs when booting kernel bob - Bad Linux ARM64 Image magic! with lz4-compressed kernel
Further work can address these issues.
Simon Glass (16): bootstd: cros: Correct reporting of I/O errors bootstd: cros: Move partition reading into a function bootstd: cros: Bring in some ChromiumOS structures bootstd: cros: Support a kernel on either partition bootstd: cros: Decode some kernel preamble fields bootstd: cros: Simplify setup and cmdline expressions bootstd: Move common zimage functions to bootm.h bootstd: cros: Add docs for the kernel layout bootstd: cros: Add private info for ChromiumOS bootstd: Add private bootmeth data to the bootflow bootstd: cros: Add a function to read info from partition bootstd: cros: Add a function to read a kernel bootstd: cros: Split up reading info and kernel bootstd: Allow display of the x86 setup information bootstd: Add a command to read all files for a bootflow bootstd: cros: Add ARM support
arch/x86/include/asm/zimage.h | 37 ---- arch/x86/lib/zimage.c | 8 +- boot/Kconfig | 4 +- boot/bootflow.c | 15 ++ boot/bootm.c | 37 ++++ boot/bootmeth-uclass.c | 10 + boot/bootmeth_cros.c | 363 ++++++++++++++++++++++++++++------ boot/bootmeth_cros.h | 197 ++++++++++++++++++ cmd/bootflow.c | 47 ++++- doc/usage/cmd/bootflow.rst | 139 ++++++++++++- include/bootflow.h | 15 +- include/bootm.h | 47 +++++ include/bootmeth.h | 23 +++ 13 files changed, 836 insertions(+), 106 deletions(-) create mode 100644 boot/bootmeth_cros.h
-- 2.41.0.487.g6d72f3e995-goog

Hi Pali,
On Sun, 6 Aug 2023 at 05:00, Pali Rohár pali@kernel.org wrote:
I have never asked to want receive emails related to chromiumos, so do not send these changes to me.
You received the last patch (and therefore the cover letter) because you committed to boot/bootm.c recently, which is affected by that patch.
On Sunday 30 July 2023 11:16:46 Simon Glass wrote:
The ChromiumOS bootmeth is fairly basic at present. It is able to boot only x86 kernels and contains quite a few hard-coded offsets.
This series tidies it up by bringing in some vboot structures and adding support for ARM.
It adds a few more features to bootstd, including display of x86 setup information.
So far this does not actually boot correctly on any ARM Chromebook:
jerry - hangs when booting kernel bob - Bad Linux ARM64 Image magic! with lz4-compressed kernel
Further work can address these issues.
Simon Glass (16): bootstd: cros: Correct reporting of I/O errors bootstd: cros: Move partition reading into a function bootstd: cros: Bring in some ChromiumOS structures bootstd: cros: Support a kernel on either partition bootstd: cros: Decode some kernel preamble fields bootstd: cros: Simplify setup and cmdline expressions bootstd: Move common zimage functions to bootm.h bootstd: cros: Add docs for the kernel layout bootstd: cros: Add private info for ChromiumOS bootstd: Add private bootmeth data to the bootflow bootstd: cros: Add a function to read info from partition bootstd: cros: Add a function to read a kernel bootstd: cros: Split up reading info and kernel bootstd: Allow display of the x86 setup information bootstd: Add a command to read all files for a bootflow bootstd: cros: Add ARM support
arch/x86/include/asm/zimage.h | 37 ---- arch/x86/lib/zimage.c | 8 +- boot/Kconfig | 4 +- boot/bootflow.c | 15 ++ boot/bootm.c | 37 ++++ boot/bootmeth-uclass.c | 10 + boot/bootmeth_cros.c | 363 ++++++++++++++++++++++++++++------ boot/bootmeth_cros.h | 197 ++++++++++++++++++ cmd/bootflow.c | 47 ++++- doc/usage/cmd/bootflow.rst | 139 ++++++++++++- include/bootflow.h | 15 +- include/bootm.h | 47 +++++ include/bootmeth.h | 23 +++ 13 files changed, 836 insertions(+), 106 deletions(-) create mode 100644 boot/bootmeth_cros.h
-- 2.41.0.487.g6d72f3e995-goog
Regards, Simon

On Sunday 06 August 2023 08:28:12 Simon Glass wrote:
Hi Pali,
On Sun, 6 Aug 2023 at 05:00, Pali Rohár pali@kernel.org wrote:
I have never asked to want receive emails related to chromiumos, so do not send these changes to me.
You received the last patch (and therefore the cover letter) because you committed to boot/bootm.c recently, which is affected by that patch.
So stop sending me these emails. I'm not going to review any chromiumos changes.
On Sunday 30 July 2023 11:16:46 Simon Glass wrote:
The ChromiumOS bootmeth is fairly basic at present. It is able to boot only x86 kernels and contains quite a few hard-coded offsets.
This series tidies it up by bringing in some vboot structures and adding support for ARM.
It adds a few more features to bootstd, including display of x86 setup information.
So far this does not actually boot correctly on any ARM Chromebook:
jerry - hangs when booting kernel bob - Bad Linux ARM64 Image magic! with lz4-compressed kernel
Further work can address these issues.
Simon Glass (16): bootstd: cros: Correct reporting of I/O errors bootstd: cros: Move partition reading into a function bootstd: cros: Bring in some ChromiumOS structures bootstd: cros: Support a kernel on either partition bootstd: cros: Decode some kernel preamble fields bootstd: cros: Simplify setup and cmdline expressions bootstd: Move common zimage functions to bootm.h bootstd: cros: Add docs for the kernel layout bootstd: cros: Add private info for ChromiumOS bootstd: Add private bootmeth data to the bootflow bootstd: cros: Add a function to read info from partition bootstd: cros: Add a function to read a kernel bootstd: cros: Split up reading info and kernel bootstd: Allow display of the x86 setup information bootstd: Add a command to read all files for a bootflow bootstd: cros: Add ARM support
arch/x86/include/asm/zimage.h | 37 ---- arch/x86/lib/zimage.c | 8 +- boot/Kconfig | 4 +- boot/bootflow.c | 15 ++ boot/bootm.c | 37 ++++ boot/bootmeth-uclass.c | 10 + boot/bootmeth_cros.c | 363 ++++++++++++++++++++++++++++------ boot/bootmeth_cros.h | 197 ++++++++++++++++++ cmd/bootflow.c | 47 ++++- doc/usage/cmd/bootflow.rst | 139 ++++++++++++- include/bootflow.h | 15 +- include/bootm.h | 47 +++++ include/bootmeth.h | 23 +++ 13 files changed, 836 insertions(+), 106 deletions(-) create mode 100644 boot/bootmeth_cros.h
-- 2.41.0.487.g6d72f3e995-goog
Regards, Simon
participants (3)
-
Alper Nebi Yasak
-
Pali Rohár
-
Simon Glass