All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Q. Gylstorff" <Quirin.Gylstorff@siemens.com>
To: raphael.lisicki@siemens.com, jan.kiszka@siemens.com,
	cip-dev@lists.cip-project.org
Subject: [cip-dev][isar-cip-core]RFC v2 2/9] Add verity-img.bbclass for dm-verity based rootfs
Date: Tue, 16 Nov 2021 12:27:45 +0100	[thread overview]
Message-ID: <20211116112752.1521211-3-Quirin.Gylstorff@siemens.com> (raw)
In-Reply-To: <20211116112752.1521211-1-Quirin.Gylstorff@siemens.com>

From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

As we need the output of `veritysetup` to generate
the initrd. Therefore do_verity_image must be called before wic
generates the final disk image.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 classes/verity-img.bbclass | 73 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
 create mode 100644 classes/verity-img.bbclass

diff --git a/classes/verity-img.bbclass b/classes/verity-img.bbclass
new file mode 100644
index 0000000..3c94643
--- /dev/null
+++ b/classes/verity-img.bbclass
@@ -0,0 +1,73 @@
+#
+# CIP Core, generic profile
+#
+# Copyright (c) Siemens AG, 2021
+#
+# Authors:
+#  Quirin Gylstorff <quirin.gylstorff@siemens.com>
+#
+# SPDX-License-Identifier: MIT
+#
+IMAGER_INSTALL += "cryptsetup"
+
+VERITY_IMAGE_TYPE ?= "squashfs"
+VERITY_INPUT_IMAGE ?= "${IMAGE_FULLNAME}.${VERITY_IMAGE_TYPE}.img"
+VERITY_OUTPUT_IMAGE ?= "${IMAGE_FULLNAME}.${VERITY_IMAGE_TYPE}.verity.img"
+VERITY_IMAGE_METADATA = "${VERITY_OUTPUT_IMAGE}.metadata"
+VERITY_HASH_BLOCK_SIZE ?= "1024"
+VERITY_DATA_BLOCK_SIZE ?= "1024"
+
+create_verity_env_file() {
+
+    local ENV="${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.verity.env"
+    rm -f $ENV
+
+    local input="${WORKDIR}/${VERITY_IMAGE_METADATA}"
+    # remove header from verity meta data
+    sed -i '/VERITY header information for/d' $input
+    IFS=":"
+    while read KEY VAL; do
+        printf '%s=%s\n' \
+            "$(echo "$KEY" | tr '[:lower:]' '[:upper:]' | sed 's/ /_/g')" \
+            "$(echo "$VAL" | tr -d ' \t')" >> $ENV
+    done < $input
+}
+
+verity_setup() {
+    rm -f ${DEPLOY_DIR_IMAGE}/${VERITY_OUTPUT_IMAGE}
+    rm -f ${WORKDIR}/${VERITY_IMAGE_METADATA}
+
+    cp -a ${DEPLOY_DIR_IMAGE}/${VERITY_INPUT_IMAGE} ${DEPLOY_DIR_IMAGE}/${VERITY_OUTPUT_IMAGE}
+
+    image_do_mounts
+    sudo chroot "${BUILDCHROOT_DIR}" /sbin/veritysetup format \
+        --hash-block-size "${VERITY_HASH_BLOCK_SIZE}"  \
+        --data-block-size "${VERITY_DATA_BLOCK_SIZE}"  \
+        --data-blocks "${VERITY_DATA_BLOCKS}" \
+        --hash-offset "${VERITY_INPUT_IMAGE_SIZE}" \
+        "${PP_DEPLOY}/${VERITY_OUTPUT_IMAGE}" \
+        "${PP_DEPLOY}/${VERITY_OUTPUT_IMAGE}" \
+        >"${WORKDIR}/${VERITY_IMAGE_METADATA}"
+
+    echo "Hash offset:    	${VERITY_INPUT_IMAGE_SIZE}" \
+        >>"${WORKDIR}/${VERITY_IMAGE_METADATA}"
+}
+
+do_verity_image[cleandirs] = "${WORKDIR}/verity"
+python do_verity_image() {
+    import os
+
+    image_file = os.path.join(
+        d.getVar("DEPLOY_DIR_IMAGE"),
+        d.getVar("VERITY_INPUT_IMAGE")
+    )
+    data_block_size = int(d.getVar("VERITY_DATA_BLOCK_SIZE"))
+    size = os.stat(image_file).st_size
+    assert size % data_block_size == 0, f"image is not well-sized!"
+    d.setVar("VERITY_INPUT_IMAGE_SIZE", str(size))
+    d.setVar("VERITY_DATA_BLOCKS", str(size // data_block_size))
+
+    bb.build.exec_func('verity_setup', d)
+    bb.build.exec_func('create_verity_env_file', d)
+}
+addtask verity_image before do_image after do_image_tools
-- 
2.30.2



  parent reply	other threads:[~2021-11-16 11:27 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16 11:27 [cip-dev][isar-cip-core]RFC v2 0/9] Read-only root file system with dm-verity Q. Gylstorff
2021-11-16 11:27 ` [cip-dev][isar-cip-core]RFC v2 1/9] Add new class to create a squashfs based root file system Q. Gylstorff
2021-11-16 11:27 ` Q. Gylstorff [this message]
2021-11-16 11:27 ` [cip-dev][isar-cip-core]RFC v2 3/9] linux-cip-common: Add options necessary for dm-verity Q. Gylstorff
2021-11-16 11:27 ` [cip-dev][isar-cip-core]RFC v2 4/9] Create a initrd with support " Q. Gylstorff
2021-11-17 12:33   ` Christian Storm
2021-11-18 18:19     ` Gylstorff Quirin
2021-11-19 13:29       ` Christian Storm
2021-11-23 13:31         ` Gylstorff Quirin
2021-11-16 11:27 ` [cip-dev][isar-cip-core]RFC v2 5/9] Create an read-only rootfs with dm-verity Q. Gylstorff
2021-11-17 12:18   ` Christian Storm
2021-11-18 18:10     ` Gylstorff Quirin
2021-11-19  6:41       ` Jan Kiszka
2021-11-16 11:27 ` [cip-dev][isar-cip-core]RFC v2 6/9] Create systemd mount units for a etc overlay Q. Gylstorff
2021-11-17 12:11   ` Christian Storm
2021-11-18 18:12     ` Gylstorff Quirin
2021-11-16 11:27 ` [cip-dev][isar-cip-core]RFC v2 7/9] Mount writable home partition Q. Gylstorff
2021-11-16 11:27 ` [cip-dev][isar-cip-core]RFC v2 8/9] kas: Patch isar for correct permissions in var and home Q. Gylstorff
2021-11-17 10:27   ` Christian Storm
2021-11-17 11:41     ` Gylstorff Quirin
2021-11-16 11:27 ` [cip-dev][isar-cip-core]RFC v2 9/9] swupdate: Backport patches from SWUpdate Master Q. Gylstorff
2021-11-17 10:40   ` Christian Storm
2021-11-17 11:36     ` Gylstorff Quirin
2021-11-19  6:42       ` Jan Kiszka
2021-11-19 13:34         ` Christian Storm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211116112752.1521211-3-Quirin.Gylstorff@siemens.com \
    --to=quirin.gylstorff@siemens.com \
    --cc=cip-dev@lists.cip-project.org \
    --cc=jan.kiszka@siemens.com \
    --cc=raphael.lisicki@siemens.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.