Skip to contentSkip to conversation

dm-verity: Fix wic image build errors when using the wic/*.wks.in

PATCH New Kevin Hao 1 participant 4 messages Feb 22, 2024

lore
Share & tools
lore

Kevin Hao

author
#0 lore raw

cover dm-verity: Fix wic image build errors when using the wic/*.wks.in

From: Kevin Hao <[email protected]>

Hi,

So far we can't build wic image by using the meta-security/wic/*.wks.in due to the changes in the oe-core. Adjust the wic/*.wks.in and dm-verity-img.bbclass to fix these issues. Also fixes a typo in docs/dm-verity.txt.

Kevin Hao (3):
docs: dm-verity.txt: Fix a typo
dm-verity: Adjust the image names according to the oe-core change
dm-verity: Set the IMAGE_FSTYPES correctly when dm-verity is enabled

 classes/dm-verity-img.bbclass        | 30 ++++++++++++++++++++--------
 docs/dm-verity.txt                   |  2 +-
 wic/beaglebone-yocto-verity.wks.in   |  2 +-
 wic/systemd-bootdisk-dmverity.wks.in |  2 +-
 4 files changed, 25 insertions(+), 11 deletions(-)
Signature · 1 line
2.40.1
author
#1 lore raw

PATCH 1/3 docs: dm-verity.txt: Fix a typo

From: Kevin Hao <[email protected]>

---
 docs/dm-verity.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
docs/dm-verity.txt +1 -1
index c2dce739790d..a538fa20bafe 100644
@@ -3,7 +3,7 @@ dm-verity and Yocto/OE
 The dm-verity feature provides a level of data integrity and resistance to
 data tampering.  It does this by creating a hash for each data block of
 the underlying device as the base of a hash tree.  There are many
-documents out there to further explain the implementaion, such as the
+documents out there to further explain the implementation, such as the
 in-kernel one itself:
 
 https://docs.kernel.org/admin-guide/device-mapper/verity.html
Signature · 1 line
2.40.1
author
#2 lore raw

PATCH 2/3 dm-verity: Adjust the image names according to the oe-core change

In reply to Kevin Hao

From: Kevin Hao <[email protected]>

After the oe-core commit 26d97acc7137 ("image-artifact-names: include ${IMAGE_NAME_SUFFIX} directly in both ${IMAGE_NAME} and ${IMAGE_LINK_NAME}"), the image names have changed from
core-image-minimal-qemux86-64-20230307181808.rootfs.ext4 core-image-minimal-qemux86-64.ext4
to
core-image-minimal-qemux86-64.rootfs-20230307181456.ext4 core-image-minimal-qemux86-64.rootfs.ext4

Adjust the images name used by dm-verity according to this change.

---
 classes/dm-verity-img.bbclass        | 6 +++---
 wic/beaglebone-yocto-verity.wks.in   | 2 +-
 wic/systemd-bootdisk-dmverity.wks.in | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
classes/dm-verity-img.bbclass +3 -3
index 2f212d6c7bcb..62c3069b63e6 100644
@@ -111,10 +111,10 @@ process_verity() {
     # Create wks.in fragment with build specific UUIDs for partitions.
     # Unfortunately the wks.in does not support line continuations...
     # First, the unappended filesystem data partition.
-    echo 'part / --source rawcopy --ondisk sda --sourceparams="file=${DM_VERITY_DEPLOY_DIR}/${DM_VERITY_IMAGE}-${MACHINE}.rootfs.${DM_VERITY_IMAGE_TYPE}.verity" --part-name verityroot --part-type="${DM_VERITY_ROOT_GUID}"'" --uuid=\"$ROOT_UUID\"" > $WKS_INC
+    echo 'part / --source rawcopy --ondisk sda --sourceparams="file=${DM_VERITY_DEPLOY_DIR}/${DM_VERITY_IMAGE}-${MACHINE}${IMAGE_NAME_SUFFIX}.${DM_VERITY_IMAGE_TYPE}.verity" --part-name verityroot --part-type="${DM_VERITY_ROOT_GUID}"'" --uuid=\"$ROOT_UUID\"" > $WKS_INC
 
     # note: no default mount point for hash data partition
-    echo 'part --source rawcopy --ondisk sda --sourceparams="file=${DM_VERITY_DEPLOY_DIR}/${DM_VERITY_IMAGE}-${MACHINE}.${DM_VERITY_IMAGE_TYPE}.vhash" --part-name verityhash --part-type="${DM_VERITY_RHASH_GUID}"'" --uuid=\"$RHASH_UUID\"" >> $WKS_INC
+    echo 'part --source rawcopy --ondisk sda --sourceparams="file=${DM_VERITY_DEPLOY_DIR}/${DM_VERITY_IMAGE}-${MACHINE}${IMAGE_NAME_SUFFIX}.${DM_VERITY_IMAGE_TYPE}.vhash" --part-name verityhash --part-type="${DM_VERITY_RHASH_GUID}"'" --uuid=\"$RHASH_UUID\"" >> $WKS_INC
 }
 
 verity_setup() {
@@ -162,7 +162,7 @@ verity_setup() {
 verity_hash() {
     cd ${IMGDEPLOYDIR}
     ln -sf ${IMAGE_NAME}.${DM_VERITY_IMAGE_TYPE}.vhash \
-        ${IMAGE_BASENAME}-${MACHINE}.${DM_VERITY_IMAGE_TYPE}.vhash
+        ${IMAGE_BASENAME}-${MACHINE}${IMAGE_NAME_SUFFIX}.${DM_VERITY_IMAGE_TYPE}.vhash
 }
 
 VERITY_TYPES = " \
wic/beaglebone-yocto-verity.wks.in +1 -1
index d2923de12786..2d332d88bd16 100644
@@ -12,5 +12,5 @@
 # This .wks only works with the dm-verity-img class.
 
 part /boot --source bootimg-partition --ondisk mmcblk0 --fstype=vfat --label boot --active --align 4 --fixed-size 32 --sourceparams="loader=u-boot" --use-uuid
-part / --source rawcopy --ondisk mmcblk0 --sourceparams="file=${IMGDEPLOYDIR}/${DM_VERITY_IMAGE}-${MACHINE}.${DM_VERITY_IMAGE_TYPE}.verity"
+part / --source rawcopy --ondisk mmcblk0 --sourceparams="file=${IMGDEPLOYDIR}/${DM_VERITY_IMAGE}-${MACHINE}${IMAGE_NAME_SUFFIX}.${DM_VERITY_IMAGE_TYPE}.verity"
 bootloader --append="console=ttyS0,115200"
wic/systemd-bootdisk-dmverity.wks.in +1 -1
index 846636877290..0ac9ccab6af0 100644
@@ -10,7 +10,7 @@
 
 part /boot --source bootimg-efi --sourceparams="loader=systemd-boot,initrd=microcode.cpio" --ondisk sda --label msdos --active --align 1024 --use-uuid
 
-part / --source rawcopy --ondisk sda  --sourceparams="file=${IMGDEPLOYDIR}/${DM_VERITY_IMAGE}-${MACHINE}.${DM_VERITY_IMAGE_TYPE}.verity" --use-uuid
+part / --source rawcopy --ondisk sda  --sourceparams="file=${IMGDEPLOYDIR}/${DM_VERITY_IMAGE}-${MACHINE}${IMAGE_NAME_SUFFIX}.${DM_VERITY_IMAGE_TYPE}.verity" --use-uuid
 
 part swap --ondisk sda --size 44 --label swap1 --fstype=swap --use-uuid
 
Signature · 1 line
2.40.1
author
#3 lore raw

PATCH 3/3 dm-verity: Set the IMAGE_FSTYPES correctly when dm-verity is enabled

In reply to Kevin Hao

From: Kevin Hao <[email protected]>

After the using inherit_defer for the image classes in oe-core commit 451363438d38 ("classes/recipes: Switch to use inherit_defer"), the using of anonymous python function in dm-verity-img.bbclass to set the IMAGE_FSTYPES doesn't work anymore. The reason is that image.bbclass also use anonymous python function to add the do_image_xxx task for the corresponding filesystem type. The anonymous function in dm-verity-img.bbclass is evaluated much later than the one in image.bbclass. Then the task such as do_image_vhash will not be added as we expect. So we choose to use "+=" to set the IMAGE_FSTYPES.

The populate_sdk_ext.bbclass may generate a dependency list like below:
core-image-minimal.do_sdk_depends -> lib32-core-image-minimal.do_image_vhash

So we also need to make sure the do_image_vhash task for the multilib filesystem is added.

---
 classes/dm-verity-img.bbclass | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
classes/dm-verity-img.bbclass +19 -5
index 62c3069b63e6..7f79548353b0 100644
@@ -177,6 +177,24 @@ CONVERSION_CMD:verity = "verity_setup ${type}"
 CONVERSION_DEPENDS_verity = "cryptsetup-native"
 IMAGE_CMD:vhash = "verity_hash"
 
+def get_verity_fstypes(d):
+    verity_image = d.getVar('DM_VERITY_IMAGE')
+    verity_type = d.getVar('DM_VERITY_IMAGE_TYPE')
+    verity_hash = d.getVar('DM_VERITY_SEPARATE_HASH')
+    pn = d.getVar('PN')
+
+    fstypes = ""
+    if not pn.endswith(verity_image):
+        return fstypes # This doesn't concern this image
+
+    fstypes = verity_type + ".verity"
+    if verity_hash == "1":
+        fstypes += " vhash"
+
+    return fstypes
+
+IMAGE_FSTYPES += "${@get_verity_fstypes(d)}"
+
 python __anonymous() {
     verity_image = d.getVar('DM_VERITY_IMAGE')
     verity_type = d.getVar('DM_VERITY_IMAGE_TYPE')
@@ -188,16 +206,12 @@ python __anonymous() {
         bb.warn('dm-verity-img class inherited but not used')
         return
 
-    if verity_image != pn:
+    if not pn.endswith(verity_image):
         return # This doesn't concern this image
 
     if len(verity_type.split()) != 1:
         bb.fatal('DM_VERITY_IMAGE_TYPE must contain exactly one type')
 
-    d.appendVar('IMAGE_FSTYPES', ' %s.verity' % verity_type)
-    if verity_hash == "1":
-        d.appendVar('IMAGE_FSTYPES', ' vhash')
-
     # If we're using wic: we'll have to use partition images and not the rootfs
     # source plugin so add the appropriate dependency.
     if 'wic' in image_fstypes:
Signature · 1 line
2.40.1