From patchwork Sat Jul 18 20:51:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Norris X-Patchwork-Id: 1331612 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=1Meov14t; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=KRzuVFom; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4B8Kwz2p9rz9sTC for ; Sun, 19 Jul 2020 06:54:27 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RoGyPeMy2wsXaO6+KRed2t5XTXhjYDawu2yJC82uuiA=; b=1Meov14taDtQP4yAqQ7TC/oEX o6mu9UhtYRXkXHl/RvoIRuRq7zLonlo0CppUed9MkRU6iculHvilNz8hi8S1znPaKmSsUJLtk7P6a FMKlRv9MHbmOgk2MvadZujpCD5mqRBP+JxoQ6BIc72a0of1BouRj36siKJZNlHY+n/NZpD6bz0Q4J QbFQ4iIGhJ3Exxv73zywPIiX2MgQbcmtcZ0lNak8yjtJv/j8Vojhn2R9gJ+QvFobEUNfva/IFFh3u PlHQpksX3rO6sMAqr8LlE2XuQ3ImGsYqjgPP41zBfUCk/BdVWQCjotEs4IBfJjXYNz64atWt0b0Ud TYmlwIfAw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwtpQ-0002vW-9Q; Sat, 18 Jul 2020 20:53:04 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jwtpL-0002tj-3l for openwrt-devel@lists.openwrt.org; Sat, 18 Jul 2020 20:53:00 +0000 Received: by mail-pf1-x443.google.com with SMTP id a23so5481840pfk.13 for ; Sat, 18 Jul 2020 13:52:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0rT3R/qZymfG+hIZwbaqBxsDbejj4KKZqupT77TxRtk=; b=KRzuVFomnWRlle+uoN5KuRw8EIxEMMGkbHfomvtnSXfJ/3FzGXSzAh0zp5r7tqkHO1 OM5NFWCWIK8k6fSJEDZ7TETbm8ilwrSr3iVjsl64VXhxZodTCbU/BnZ/P74iKlSTUonL lK4CjTK66ji56xQ3kTPXO98QJZ6jPibQDbfL68jCgqpmJYie9oU/QQNJt72U/wIfqhfT Uhndtmg+FNuX7g4R0dOHetb9OUuw88uzGC2ZGaImFtQuL421xunRx5WCUuqF/C5kIRZ+ 2wKjWElvjeRGoFRPfIHhB/i4h/z6HaoOLzSpnKg/z6OCwfMo5R2dUGsdTyQzw41silx3 4eyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0rT3R/qZymfG+hIZwbaqBxsDbejj4KKZqupT77TxRtk=; b=Pttj8SjlcUwPs2JYgBMEktvmp36+rs8rd+tQEEE2sYHN6uQFFgNXBBETffDZyOgsPS yDc/8fgfu15Cu2mAJu9B/whgUZX/fs/ZUNWzPJHQ0N4iadbkxpDie7/M203JoQ3y6+yw USeg3onMutFgTbZ9nNuU5GOsc+oCwh+xSNAlkNzCkGHtZvw68XV6hZiiOgXQtu2FtzCx SE35cIFySkOgfkUikm4dzJQOFb1PYGZd0HUZrVVRq25GnizkLFWcO7NphGfm2VejuIUP bY6QmYC5AbWlNmSxrqauKifzU1Nso0Vo9V4kUGWoUlQehJqE4RHtWQc8x6vONNq5h6l2 X6lQ== X-Gm-Message-State: AOAM532CEn4tzWvtzrrqgHg1+Z9gYsDbVROsVa+vlQElNkQeE0LrSD1u OQRxh2yI3WoTnN8nFApPsMRRW9n2Ei4= X-Google-Smtp-Source: ABdhPJxMsNuEfoQkRwpKPEu/XQIdC7biNdXhKU3iMQXUpReeLc4Vpj9AyfdcxNoVD8kHFUDvo4vAWA== X-Received: by 2002:aa7:9419:: with SMTP id x25mr13525391pfo.67.1595105577189; Sat, 18 Jul 2020 13:52:57 -0700 (PDT) Received: from localhost ([2601:647:5800:8d47:9eef:d5ff:fefc:64ae]) by smtp.gmail.com with ESMTPSA id 200sm11591653pfy.57.2020.07.18.13.52.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Jul 2020 13:52:56 -0700 (PDT) From: Brian Norris To: openwrt-devel@lists.openwrt.org Subject: [RFC PATCH 3/5] image-commands: support Chromium OS image-type creation Date: Sat, 18 Jul 2020 20:51:46 +0000 Message-Id: <20200718205148.1743807-4-computersforpeace@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200718205148.1743807-1-computersforpeace@gmail.com> References: <20200718205148.1743807-1-computersforpeace@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200718_165259_265487_787F1ABA X-CRM114-Status: GOOD ( 12.51 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:443 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [computersforpeace[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Brian Norris Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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 --- 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 " + 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