[RFC PATCH 3/5] image-commands: support Chromium OS image-type creation

Brian Norris computersforpeace at gmail.com
Sat Jul 18 16:51:46 EDT 2020


See the previous patches, which implemented the cros-vbutil
verified-boot payload-packing tool, and extended ptgen for the CrOS
kernel partition type. With these, it's now possible to package kernel +
rootfs to make disk images that can boot a Chrome OS-based system (e.g.,
Chromebooks, or even a few AP models).

gen_image_vboot.sh borrows a bit of structure from gen_image_generic.sh,
but I didn't feel it fit well to try and add new flags to the latter,
given the difference in its FAT kernel packaging and our raw kernel
partition packing.

Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 include/image-commands.mk  | 17 +++++++++++++++++
 scripts/gen_image_vboot.sh | 29 +++++++++++++++++++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100755 scripts/gen_image_vboot.sh

diff --git a/include/image-commands.mk b/include/image-commands.mk
index e7db7128b4ca..ca8e826ffb1e 100644
--- a/include/image-commands.mk
+++ b/include/image-commands.mk
@@ -164,6 +164,23 @@ define Build/fit
 	@mv $@.new $@
 endef
 
+define Build/cros-image
+	$(SCRIPT_DIR)/gen_image_vboot.sh \
+		  $@ \
+		  $(CONFIG_TARGET_KERNEL_PARTSIZE) $(IMAGE_KERNEL) \
+		  $(CONFIG_TARGET_ROOTFS_PARTSIZE) $(IMAGE_ROOTFS)
+endef
+
+# NB: Chrome OS bootloaders replace the '%U' in command lines with the UUID of
+# the kernel partition it chooses to boot from. This gives a flexible way to
+# consistently build and sign kernels that always use the subsequent
+# (PARTNROFF=1) partition as their rootfs.
+define Build/cros-vboot
+	$(STAGING_DIR_HOST)/bin/cros-vbutil \
+		-k $@ -c "root=PARTUUID=%U/PARTNROFF=1" -o $@.new
+	@mv $@.new $@
+endef
+
 define Build/lzma
 	$(call Build/lzma-no-dict,-lc1 -lp2 -pb2 $(1))
 endef
diff --git a/scripts/gen_image_vboot.sh b/scripts/gen_image_vboot.sh
new file mode 100755
index 000000000000..acded33de654
--- /dev/null
+++ b/scripts/gen_image_vboot.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+# Copyright (C) 2020 OpenWrt.org
+set -e -x
+[ $# == 5 ] || {
+    echo "SYNTAX: $0 <file> <kernel size> <kernel image> <rootfs size> <rootfs image>"
+    exit 1
+}
+
+OUTPUT="$1"
+KERNELSIZE="$2"
+KERNELIMAGE="$3"
+ROOTFSSIZE="$4"
+ROOTFSIMAGE="$5"
+
+rm -f "${OUTPUT}"
+
+head=16
+sect=63
+
+# create partition table
+set $(ptgen -o "$OUTPUT" -h $head -s $sect -g -T cros_kernel -p ${KERNELSIZE}m -p ${ROOTFSSIZE}m)
+
+KERNELOFFSET="$(($1 / 512))"
+KERNELSIZE="$2"
+ROOTFSOFFSET="$(($3 / 512))"
+ROOTFSSIZE="$(($4 / 512))"
+
+dd if="${KERNELIMAGE}" of="${OUTPUT}" bs=512 seek="${KERNELOFFSET}" conv=notrunc
+dd if="${ROOTFSIMAGE}" of="${OUTPUT}" bs=512 seek="${ROOTFSOFFSET}" conv=notrunc
-- 
2.27.0




More information about the openwrt-devel mailing list