diff options
-rw-r--r-- | meta-oe/classes/discoverable-disk-image.bbclass | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/meta-oe/classes/discoverable-disk-image.bbclass b/meta-oe/classes/discoverable-disk-image.bbclass new file mode 100644 index 0000000000..e601bf452f --- /dev/null +++ b/meta-oe/classes/discoverable-disk-image.bbclass | |||
@@ -0,0 +1,132 @@ | |||
1 | ## | ||
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
4 | # SPDX-License-Identifier: MIT | ||
5 | # | ||
6 | # | ||
7 | # Discoverable Disk Image (DDI) | ||
8 | # | ||
9 | # "DDIs (Discoverable Disk Images) are self-describing file system | ||
10 | # images that follow the DPS ( Discoverable Partitions Specification), | ||
11 | # wrapped in a GPT partition table, that may contain root (or /usr/) | ||
12 | # filesystems for bootable OS images, system extensions, configuration | ||
13 | # extensions, portable services, containers and more, and shall be | ||
14 | # protected by signed dm-verity all combined into one. They are | ||
15 | # designed to be composable and stackable, and provide security by | ||
16 | # default." | ||
17 | # https://uapi-group.org/specifications/specs/discoverable_disk_image/ | ||
18 | # https://uapi-group.org/specifications/specs/discoverable_partitions_specification/ | ||
19 | # https://www.freedesktop.org/software/systemd/man/latest/systemd.image-policy.html | ||
20 | |||
21 | # To be able to use discoverable-disk-images with a | ||
22 | # root-verity-sig or usr-verity-sig configuration: | ||
23 | # - systemd needs to include the PACKAGECONFIG 'cryptsetup', and | ||
24 | # - the kernel needs the following features enabled: | ||
25 | # CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG=y | ||
26 | # CONFIG_DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING=y | ||
27 | # CONFIG_EROFS_FS=y | ||
28 | # CONFIG_EROFS_FS_XATTR=y | ||
29 | # CONFIG_EROFS_FS_ZIP=y | ||
30 | # CONFIG_EROFS_FS_ZIP_LZMA=y | ||
31 | # CONFIG_INTEGRITY_SIGNATURE=y | ||
32 | # CONFIG_INTEGRITY_ASYMMETRIC_KEYS=y | ||
33 | # CONFIG_INTEGRITY_PLATFORM_KEYRING=y | ||
34 | # CONFIG_SYSTEM_BLACKLIST_KEYRING=y | ||
35 | # CONFIG_SYSTEM_BLACKLIST_HASH_LIST="" | ||
36 | # CONFIG_SIGNATURE=y | ||
37 | |||
38 | # To sign DDIs, a key and certificate need to be provided by setting | ||
39 | # the variables: | ||
40 | # REPART_PRIVATE_KEY | ||
41 | # private key so sign the verity-hash | ||
42 | # REPART_PRIVATE_KEY_SOURCE | ||
43 | # optional, can be "engine:pkcs11" when using a (soft)hsm | ||
44 | # REPART_CERTIFICATE | ||
45 | # corresponding public certificate, in .pem format | ||
46 | # | ||
47 | |||
48 | # For signature verification, systemd-sysext expects the matching | ||
49 | # certificate to reside in /etc/verity.d as PEM formated .crt file. | ||
50 | # | ||
51 | # To enforce loading of only signed extension images, an appropriate | ||
52 | # image policy has to be passed to systemd-sysext, e.g.: | ||
53 | # systemd-sysext --image-policy='root=signed+absent:usr=signed+absent:=unused+absent' merge | ||
54 | |||
55 | # 'systemd-dissect' can be used to inspect, manually mount, ... a DDI. | ||
56 | |||
57 | inherit image | ||
58 | |||
59 | IMAGE_FSTYPES = "ddi" | ||
60 | |||
61 | DEPENDS += " \ | ||
62 | systemd-repart-native \ | ||
63 | erofs-utils-native \ | ||
64 | openssl-native \ | ||
65 | " | ||
66 | |||
67 | # systemd-repart --make-ddi takes one of "sysext", "confext" or "portable", | ||
68 | # which it then takes and looks up definitions in the host os; which we need | ||
69 | # to divert to the sysroot-native by setting '--definitions=' instead. | ||
70 | # | ||
71 | REPART_DDI_TYPE ?= "sysext" | ||
72 | |||
73 | REPART_DDI_EXTENSION ?= "ddi" | ||
74 | |||
75 | # systemd-repart creates temporary directoryies under /var/tmp/.#repartXXXXXXX/, | ||
76 | # to estimate partition size etc. Since files are copied there from the image/rootfs | ||
77 | # folder - which are owned by pseudo-root - this temporary location has to be | ||
78 | # added to the directories handled by pseudo; otherwise calls to e.g. | ||
79 | # fchown(0,0) inside systemd git/src/shared/copy.c end up failing. | ||
80 | PSEUDO_INCLUDE_PATHS .= ",/var/tmp/" | ||
81 | |||
82 | oe_image_systemd_repart_make_ddi() { | ||
83 | |||
84 | local additional_args="" | ||
85 | |||
86 | if [ -n "${REPART_PRIVATE_KEY}" ] | ||
87 | then | ||
88 | if [ -n "${REPART_PRIVATE_KEY_SOURCE}" ] | ||
89 | then | ||
90 | additional_args="$additional_args --private-key-source=${REPART_PRIVATE_KEY_SOURCE}" | ||
91 | fi | ||
92 | additional_args="$additional_args --private-key=${REPART_PRIVATE_KEY}" | ||
93 | fi | ||
94 | |||
95 | if [ -n "${REPART_CERTIFICATE}" ] | ||
96 | then | ||
97 | additional_args="$additional_args --certificate=${REPART_CERTIFICATE}" | ||
98 | fi | ||
99 | |||
100 | # map architectures to systemd's expected values | ||
101 | local systemd_arch="${TARGET_ARCH}" | ||
102 | case "${systemd_arch}" in | ||
103 | aarch64) | ||
104 | systemd_arch=arm64 | ||
105 | ;; | ||
106 | x86_64) | ||
107 | systemd_arch=x86-64 | ||
108 | ;; | ||
109 | esac | ||
110 | |||
111 | # prepare system-repart configuration | ||
112 | mkdir -p ${B}/definitions.repart.d | ||
113 | cp ${STAGING_LIBDIR_NATIVE}/systemd/repart/definitions/${REPART_DDI_TYPE}.repart.d/* ${B}/definitions.repart.d/ | ||
114 | # enable erofs compression | ||
115 | sed -i "/^Compression/d" ${B}/definitions.repart.d/10-root.conf | ||
116 | echo "Compression=lzma\nCompressionLevel=3" >> ${B}/definitions.repart.d/10-root.conf | ||
117 | # disable verity signature partition creation, if no key is provided | ||
118 | if [ -z "${REPART_PRIVATE_KEY}" ]; then | ||
119 | rm ${B}/definitions.repart.d/30-root-verity-sig.conf | ||
120 | fi | ||
121 | |||
122 | systemd-repart \ | ||
123 | --definitions="${B}/definitions.repart.d/" \ | ||
124 | --copy-source="${IMAGE_ROOTFS}" \ | ||
125 | --empty=create --size=auto --dry-run=no --offline=yes \ | ||
126 | --architecture="${systemd_arch}" \ | ||
127 | --json=pretty --no-pager $additional_args \ | ||
128 | "${IMGDEPLOYDIR}/${IMAGE_NAME}${IMAGE_NAME_SUFFIX}.${REPART_DDI_EXTENSION}" | ||
129 | } | ||
130 | |||
131 | IMAGE_CMD:ddi = "oe_image_systemd_repart_make_ddi" | ||
132 | do_image_ddi[deptask] += "do_unpack" | ||