Skip to contentSkip to conversation

dm-verity-upstream: Add dynamic layer for meta-security dm-verity

PATCH Superseded Atharv Dubey 3 participants 7 messages Aug 25 – Sep 3

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 dm-verity-upstream: Add dynamic layer for meta-security dm-verity

Add an optional dynamic layer enabling dm-verity block-level integrity verification of the root filesystem for TI K3 platforms, using meta-security's stock dm-verity mechanism as-is.

dm-verity hashes the rootfs at build time; at boot, a dedicated initramfs loads the root hash and the kernel checks every block read against it. Wires DM_VERITY_IMAGE/WKS_FILE for the K3 boot chain, hooking do_image_wic instead of INITRAMFS_IMAGE to avoid a 3-way circular dependency through kernel-fit-image.bbclass.

DM_VERITY_IMAGE selects which image recipe gets verity-enabled (default arago-base-image, overridable in local.conf); all effects are scoped to PN == DM_VERITY_IMAGE, so building any other image type is unaffected. Only active when the "security" layer and dm-verity-upstream feature are enabled.

---
 meta-ti-bsp/conf/layer.conf                     |  3 +++
 meta-ti-bsp/conf/machine/include/k3.inc         | 10 ++++++++++
 .../conf/include/dm-verity-upstream.inc         | 17 +++++++++++++++++
 .../udev/files/dm-verity.ignorelist             |  1 +
 .../recipes-core/udev/udev-extraconf_%.bbappend | 14 ++++++++++++++
 meta-ti-bsp/files/wic/k3-verity.wks.in          |  5 +++++
 6 files changed, 50 insertions(+)
 create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc
 create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/files/dm-verity.ignorelist
 create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend
 create mode 100644 meta-ti-bsp/files/wic/k3-verity.wks.in
meta-ti-bsp/conf/layer.conf +3 -0
index 3cc54aa4..aca35cd3 100644
@@ -20,12 +20,15 @@ LAYERDEPENDS_meta-ti-bsp = " \
 LAYERRECOMMENDS_meta-ti-bsp = " \
     openembedded-layer \
     tpm-layer \
+    security \
 "
 
 BBFILES_DYNAMIC += " \
     openembedded-layer:${LAYERDIR}/dynamic-layers/openembedded-layer/recipes*/*/*.bbappend \
     tpm-layer:${LAYERDIR}/dynamic-layers/tpm-layer/recipes*/*/*.bb \
     tpm-layer:${LAYERDIR}/dynamic-layers/tpm-layer/recipes*/*/*.bbappend \
+    security:${LAYERDIR}/dynamic-layers/security-layer/recipes*/*/*.bb \
+    security:${LAYERDIR}/dynamic-layers/security-layer/recipes*/*/*.bbappend \
 "
 
 SIGGEN_EXCLUDERECIPES_ABISAFE += " \
meta-ti-bsp/conf/machine/include/k3.inc +10 -0
index 2ebbfb9e..e23e0ead 100644
@@ -64,3 +64,13 @@ FALCON_INCLUDE = ""
 FALCON_INCLUDE:ti-falcon = "conf/machine/include/ti-falcon.inc"
 
 require ${FALCON_INCLUDE}
+
+# Upstream dm-verity path: meta-security's own dm-verity-img.bbclass +
+# dm-verity-image-initramfs, used as-is (build-time hashing). Only active
+# when the security layer is present and this feature is explicitly
+# requested -- see dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc
+DISTRO_FEATURES[validitems] += "dm-verity-upstream"
+
+DM_VERITY_UPSTREAM_INCLUDE = "${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc', '', d)}"
+
+require ${DM_VERITY_UPSTREAM_INCLUDE}
meta-ti-bsp/dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc new file +17 -0
new file mode 100644
index 00000000..4de9e2fb
@@ -0,0 +1,17 @@
+# Enables dm-verity to check the rootfs for tampering on TI K3 boards.
+DM_VERITY_IMAGE ?= "arago-base-image"
+DM_VERITY_IMAGE_TYPE = "ext4"
+IMAGE_CLASSES += "dm-verity-img"
+
+DM_VERITY_INITRAMFS_IMAGE = "dm-verity-image-initramfs"
+
+python () {
+    if d.getVar('PN') != d.getVar('DM_VERITY_IMAGE'):
+        return
+
+    d.setVar('WKS_FILE', 'k3-verity.wks.in')
+    d.appendVar('EXTRA_IMAGE_FEATURES', ' read-only-rootfs')
+    d.appendVar('WICVARS', ' DM_VERITY_IMAGE DM_VERITY_IMAGE_TYPE IMAGE_NAME_SUFFIX IMGDEPLOYDIR')
+    d.appendVarFlag('do_image_wic', 'depends', ' %s:do_image_complete' % d.getVar('DM_VERITY_INITRAMFS_IMAGE'))
+    d.appendVar('IMAGE_BOOT_FILES', ' %s-%s.cpio.gz' % (d.getVar('DM_VERITY_INITRAMFS_IMAGE'), d.getVar('MACHINE')))
+}
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/files/dm-verity.ignorelist new file +1 -0
new file mode 100644
index 00000000..5af878c9
@@ -0,0 +1 @@
+/dev/mmcblk1p2
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend new file +14 -0
new file mode 100644
index 00000000..3940a24d
@@ -0,0 +1,14 @@
+# Under dm-verity, the raw root partition looks unmounted to udev's
+# auto-mount check, so it tries to mount it a second time on its own,
+# outside of dm-verity's protection. This tells it to skip that partition.
+FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
+
+SRC_URI += "${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'file://dm-verity.ignorelist', '', d)}"
+
+do_install:append() {
+    if ${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'true', 'false', d)}; then
+        install -m 0644 ${UNPACKDIR}/dm-verity.ignorelist ${D}${sysconfdir}/udev/mount.ignorelist.d/dm-verity
+    fi
+}
+
+FILES:${PN}-automount += "${sysconfdir}/udev/mount.ignorelist.d"
meta-ti-bsp/files/wic/k3-verity.wks.in new file +5 -0
new file mode 100644
index 00000000..6ef2c57f
@@ -0,0 +1,5 @@
+# Disk layout for a board that boots with dm-verity enabled.
+
+bootloader --timeout=3 --append="rootfstype=ext4 root=/dev/mmcblk1p2 ${TI_WKS_BOOTLOADER_APPEND}"
+part --source bootimg-efi --sourceparams="loader=${EFI_PROVIDER},initrd=${DM_VERITY_INITRAMFS_IMAGE}-${MACHINE}.cpio.gz" --fstype=vfat --label boot --active --align 1024 --use-uuid --fixed-size 128M
+part / --source rawcopy --sourceparams="file=${IMGDEPLOYDIR}/${DM_VERITY_IMAGE}-${MACHINE}${IMAGE_NAME_SUFFIX}.${DM_VERITY_IMAGE_TYPE}.verity" --align 1024
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/3 linux-ti-staging: Add dm-verity kernel config

Add a kernel config fragment enabling dm-verity and its crypto dependencies (CONFIG_DM_VERITY, CONFIG_DM_CRYPT, CONFIG_BLK_DEV_DM). Applied via KERNEL_CONFIG_FRAGMENTS, which setup-defconfig.inc reads and merges directly through merge_config.sh.

---
 .../security-layer/recipes-kernel/linux/files/dm-verity.cfg  | 5 +++++
 .../recipes-kernel/linux/linux-ti-staging_%.bbappend         | 5 +++++
 2 files changed, 10 insertions(+)
 create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/recipes-kernel/linux/files/dm-verity.cfg
 create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/recipes-kernel/linux/linux-ti-staging_%.bbappend
meta-ti-bsp/dynamic-layers/security-layer/recipes-kernel/linux/files/dm-verity.cfg new file +5 -0
new file mode 100644
index 00000000..c50ce403
@@ -0,0 +1,5 @@
+CONFIG_MD=y
+CONFIG_BLK_DEV_DM=y
+CONFIG_DM_CRYPT=y
+CONFIG_DM_VERITY=y
+CONFIG_CRYPTO_SHA256=y
meta-ti-bsp/dynamic-layers/security-layer/recipes-kernel/linux/linux-ti-staging_%.bbappend new file +5 -0
new file mode 100644
index 00000000..87bff5c2
@@ -0,0 +1,5 @@
+# Enable the dm-verity kernel config fragment via KERNEL_CONFIG_FRAGMENTS.
+FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
+
+SRC_URI += "${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'file://dm-verity.cfg', '', d)}"
+KERNEL_CONFIG_FRAGMENTS += "${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', '${UNPACKDIR}/dm-verity.cfg', '', d)}"
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/3 tisdk-uenv: Load dm-verity initramfs from U-Boot boot script

In reply to Atharv Dubey

Override name_initramfs in the deployed uEnv.txt so U-Boot loads dm-verity-image-initramfs's cpio instead of ti-core-initramfs. uEnv.txt is imported before bootcmd_ti_mmc runs get_initramfs_mmc, so this override takes effect with no change to U-Boot itself.

---
 .../recipes-tisdk/tisdk-uenv/tisdk-uenv.bbappend            | 6 ++++++
 1 file changed, 6 insertions(+)
 create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/recipes-tisdk/tisdk-uenv/tisdk-uenv.bbappend
meta-ti-bsp/dynamic-layers/security-layer/recipes-tisdk/tisdk-uenv/tisdk-uenv.bbappend new file +6 -0
new file mode 100644
index 00000000..ffbd0061
@@ -0,0 +1,6 @@
+# Fetch the dm-verity initramfs instead of ti-core-initramfs.
+do_deploy:append() {
+    if ${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'true', 'false', d)}; then
+        echo "name_initramfs=${DM_VERITY_INITRAMFS_IMAGE}-${MACHINE}.cpio.gz" >> ${DEPLOYDIR}/uEnv.txt
+    fi
+}
Signature · 1 line
2.34.1
#3 lore raw
In reply to Atharv Dubey

meta-ti / na / 20260825063713.51497-1-a-dubey

PRC Results: FAIL

=========================================================
check-yocto-patches: PASS
=========================================================
Patches
----------------------------------------
All patches passed

=========================================================
apply-yocto-patch: PASS
=========================================================
master
=====================
Summary:
- Patch Series: [master][PATCH 1/3] dm-verity-upstream: Add dynamic layer for meta-security dm-verity
- Submitter: From: Atharv Dubey <[email protected]>
- Date: Date: Tue, 25 Aug 2026 12:07:11 +0530
- Num Patches: 3
- Mailing List (public inbox) Commit SHA: ac4c9e3fbd631c591c104856a1946d2ddf20edf4

Applied to:
- Repository: lcpd-prc-meta-ti
- Base Branch: master-next
- Commit Author: LCPD Automation Script <[email protected]>
- Commit Subject: CI/CD Auto-Merger: cicd.master.202608242200
- Commit SHA: 025d1864b5f1b9849379ee0319f466abe3bf27cc

Patches
----------------------------------------
All patches applied

=========================================================
check-yocto-repo: FAIL
=========================================================
master
=====================
FAIL
WARN: .bbappend files might need a guard to make them check-layer compliant. (GUARD-1)
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend

WARN: .bbappend files might need a guard to make them check-layer compliant. (GUARD-1)
meta-ti-bsp/dynamic-layers/security-layer/recipes-kernel/linux/linux-ti-staging_%.bbappend

WARN: .bbappend files might need a guard to make them check-layer compliant. (GUARD-1)
meta-ti-bsp/dynamic-layers/security-layer/recipes-tisdk/tisdk-uenv/tisdk-uenv.bbappend

WARN: Are you missing a PV = "...". (PV-1)
meta-ti-bsp/recipes-graphics/mesa/libclc_git.bb

ERROR: SUMMARY cannot be longer than 72 characters. (SUMMARY-2)
meta-ti-bsp/recipes-graphics/mesa/libclc_git.bb

For details on the above errors/warnings visit: https://lists.yoctoproject.org/g/meta-ti/wiki/40887

#4 lore raw
In reply to Atharv Dubey
Quoted 124 lines · Atharv Dubey

Add an optional dynamic layer enabling dm-verity block-level integrity verification of the root filesystem for TI K3 platforms, using meta-security's stock dm-verity mechanism as-is.

dm-verity hashes the rootfs at build time; at boot, a dedicated initramfs loads the root hash and the kernel checks every block read against it. Wires DM_VERITY_IMAGE/WKS_FILE for the K3 boot chain, hooking do_image_wic instead of INITRAMFS_IMAGE to avoid a 3-way circular dependency through kernel-fit-image.bbclass.

DM_VERITY_IMAGE selects which image recipe gets verity-enabled (default arago-base-image, overridable in local.conf); all effects are scoped to PN == DM_VERITY_IMAGE, so building any other image type is unaffected. Only active when the "security" layer and dm-verity-upstream feature are enabled.

---
  meta-ti-bsp/conf/layer.conf                     |  3 +++
  meta-ti-bsp/conf/machine/include/k3.inc         | 10 ++++++++++
  .../conf/include/dm-verity-upstream.inc         | 17 +++++++++++++++++
  .../udev/files/dm-verity.ignorelist             |  1 +
  .../recipes-core/udev/udev-extraconf_%.bbappend | 14 ++++++++++++++
  meta-ti-bsp/files/wic/k3-verity.wks.in          |  5 +++++
  6 files changed, 50 insertions(+)

create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/files/dm-verity.ignorelist create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend create mode 100644 meta-ti-bsp/files/wic/k3-verity.wks.in

meta-ti-bsp/conf/layer.conf +3 -0
index 3cc54aa4..aca35cd3 100644
@@ -20,12 +20,15 @@ LAYERDEPENDS_meta-ti-bsp = " \
  LAYERRECOMMENDS_meta-ti-bsp = " \
      openembedded-layer \
      tpm-layer \
+    security \
  "
 
  BBFILES_DYNAMIC += " \
      openembedded-layer:${LAYERDIR}/dynamic-layers/openembedded-layer/recipes*/*/*.bbappend \
      tpm-layer:${LAYERDIR}/dynamic-layers/tpm-layer/recipes*/*/*.bb \
      tpm-layer:${LAYERDIR}/dynamic-layers/tpm-layer/recipes*/*/*.bbappend \
+    security:${LAYERDIR}/dynamic-layers/security-layer/recipes*/*/*.bb \
+    security:${LAYERDIR}/dynamic-layers/security-layer/recipes*/*/*.bbappend \
  "
 
  SIGGEN_EXCLUDERECIPES_ABISAFE += " \
meta-ti-bsp/conf/machine/include/k3.inc +10 -0
index 2ebbfb9e..e23e0ead 100644
@@ -64,3 +64,13 @@ FALCON_INCLUDE = ""
  FALCON_INCLUDE:ti-falcon = "conf/machine/include/ti-falcon.inc"
 
  require ${FALCON_INCLUDE}
+
+# Upstream dm-verity path: meta-security's own dm-verity-img.bbclass +
+# dm-verity-image-initramfs, used as-is (build-time hashing). Only active
+# when the security layer is present and this feature is explicitly
+# requested -- see dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc
+DISTRO_FEATURES[validitems] += "dm-verity-upstream"
+
+DM_VERITY_UPSTREAM_INCLUDE = "${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc', '', d)}"
+
+require ${DM_VERITY_UPSTREAM_INCLUDE}
meta-ti-bsp/dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc new file +17 -0
new file mode 100644
index 00000000..4de9e2fb
@@ -0,0 +1,17 @@
+# Enables dm-verity to check the rootfs for tampering on TI K3 boards.
+DM_VERITY_IMAGE ?= "arago-base-image"
+DM_VERITY_IMAGE_TYPE = "ext4"
+IMAGE_CLASSES += "dm-verity-img"
+
+DM_VERITY_INITRAMFS_IMAGE = "dm-verity-image-initramfs"
+
+python () {
+    if d.getVar('PN') != d.getVar('DM_VERITY_IMAGE'):
+        return
+
+    d.setVar('WKS_FILE', 'k3-verity.wks.in')
+    d.appendVar('EXTRA_IMAGE_FEATURES', ' read-only-rootfs')
+    d.appendVar('WICVARS', ' DM_VERITY_IMAGE DM_VERITY_IMAGE_TYPE IMAGE_NAME_SUFFIX IMGDEPLOYDIR')
+    d.appendVarFlag('do_image_wic', 'depends', ' %s:do_image_complete' % d.getVar('DM_VERITY_INITRAMFS_IMAGE'))
+    d.appendVar('IMAGE_BOOT_FILES', ' %s-%s.cpio.gz' % (d.getVar('DM_VERITY_INITRAMFS_IMAGE'), d.getVar('MACHINE')))
+}
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/files/dm-verity.ignorelist new file +1 -0
new file mode 100644
index 00000000..5af878c9
@@ -0,0 +1 @@
+/dev/mmcblk1p2
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend new file +14 -0
new file mode 100644
index 00000000..3940a24d
@@ -0,0 +1,14 @@
+# Under dm-verity, the raw root partition looks unmounted to udev's
+# auto-mount check, so it tries to mount it a second time on its own,
+# outside of dm-verity's protection. This tells it to skip that partition.
+FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
+
+SRC_URI += "${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'file://dm-verity.ignorelist', '', d)}"
+
+do_install:append() {
+    if ${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'true', 'false', d)}; then
+        install -m 0644 ${UNPACKDIR}/dm-verity.ignorelist ${D}${sysconfdir}/udev/mount.ignorelist.d/dm-verity
+    fi
+}
+
+FILES:${PN}-automount += "${sysconfdir}/udev/mount.ignorelist.d"
meta-ti-bsp/files/wic/k3-verity.wks.in new file +0 -0
new file mode 100644
index 00000000..6ef2c57f

meta-ti-bsp/files/wic/k3-verity.wks.in line 5

Quoted 5 lines
meta-ti-bsp/files/wic/k3-verity.wks.in new file +5 -0
@@ -0,0 +1,5 @@
+# Disk layout for a board that boots with dm-verity enabled.
+
+bootloader --timeout=3 --append="rootfstype=ext4 root=/dev/mmcblk1p2 ${TI_WKS_BOOTLOADER_APPEND}"
+part --source bootimg-efi --sourceparams="loader=${EFI_PROVIDER},initrd=${DM_VERITY_INITRAMFS_IMAGE}-${MACHINE}.cpio.gz" --fstype=vfat --label boot --active --align 1024 --use-uuid --fixed-size 128M
+part / --source rawcopy --sourceparams="file=${IMGDEPLOYDIR}/${DM_VERITY_IMAGE}-${MACHINE}${IMAGE_NAME_SUFFIX}.${DM_VERITY_IMAGE_TYPE}.verity" --align 1024

Hi All,

A Gentle Reminder for a review on the patches.

Regards,
Atharv

#5 lore raw
In reply to Atharv Dubey
Quoted 10 lines · Atharv Dubey via lists.yoctoproject.org

Add an optional dynamic layer enabling dm-verity block-level integrity verification of the root filesystem for TI K3 platforms, using meta-security's stock dm-verity mechanism as-is.

dm-verity hashes the rootfs at build time; at boot, a dedicated initramfs loads the root hash and the kernel checks every block read against it. Wires DM_VERITY_IMAGE/WKS_FILE for the K3 boot chain, hooking do_image_wic instead of INITRAMFS_IMAGE to avoid a 3-way circular dependency through kernel-fit-image.bbclass.

Quoted 7 lines

DM_VERITY_IMAGE selects which image recipe gets verity-enabled (default arago-base-image, overridable in local.conf); all effects are scoped to PN == DM_VERITY_IMAGE, so building any other image type is unaffected. Only active when the "security" layer and dm-verity-upstream feature are enabled.

Hi Athrav, Thanks for the patch

Quoted 87 lines
---
 meta-ti-bsp/conf/layer.conf                     |  3 +++
 meta-ti-bsp/conf/machine/include/k3.inc         | 10 ++++++++++
 .../conf/include/dm-verity-upstream.inc         | 17 +++++++++++++++++
 .../udev/files/dm-verity.ignorelist             |  1 +
 .../recipes-core/udev/udev-extraconf_%.bbappend | 14 ++++++++++++++
 meta-ti-bsp/files/wic/k3-verity.wks.in          |  5 +++++
 6 files changed, 50 insertions(+)
 create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc
 create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/files/dm-verity.ignorelist
 create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend
 create mode 100644 meta-ti-bsp/files/wic/k3-verity.wks.in
meta-ti-bsp/conf/layer.conf +3 -0
index 3cc54aa4..aca35cd3 100644
@@ -20,12 +20,15 @@ LAYERDEPENDS_meta-ti-bsp = " \
 LAYERRECOMMENDS_meta-ti-bsp = " \
     openembedded-layer \
     tpm-layer \
+    security \
 "
 
 BBFILES_DYNAMIC += " \
     openembedded-layer:${LAYERDIR}/dynamic-layers/openembedded-layer/recipes*/*/*.bbappend \
     tpm-layer:${LAYERDIR}/dynamic-layers/tpm-layer/recipes*/*/*.bb \
     tpm-layer:${LAYERDIR}/dynamic-layers/tpm-layer/recipes*/*/*.bbappend \
+    security:${LAYERDIR}/dynamic-layers/security-layer/recipes*/*/*.bb \
+    security:${LAYERDIR}/dynamic-layers/security-layer/recipes*/*/*.bbappend \
 "
 
 SIGGEN_EXCLUDERECIPES_ABISAFE += " \
meta-ti-bsp/conf/machine/include/k3.inc +10 -0
index 2ebbfb9e..e23e0ead 100644
@@ -64,3 +64,13 @@ FALCON_INCLUDE = ""
 FALCON_INCLUDE:ti-falcon = "conf/machine/include/ti-falcon.inc"
 
 require ${FALCON_INCLUDE}
+
+# Upstream dm-verity path: meta-security's own dm-verity-img.bbclass +
+# dm-verity-image-initramfs, used as-is (build-time hashing). Only active
+# when the security layer is present and this feature is explicitly
+# requested -- see dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc
+DISTRO_FEATURES[validitems] += "dm-verity-upstream"
+
+DM_VERITY_UPSTREAM_INCLUDE = "${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc', '', d)}"
+
+require ${DM_VERITY_UPSTREAM_INCLUDE}
meta-ti-bsp/dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc new file +17 -0
new file mode 100644
index 00000000..4de9e2fb
@@ -0,0 +1,17 @@
+# Enables dm-verity to check the rootfs for tampering on TI K3 boards.
+DM_VERITY_IMAGE ?= "arago-base-image"
+DM_VERITY_IMAGE_TYPE = "ext4"
+IMAGE_CLASSES += "dm-verity-img"
+
+DM_VERITY_INITRAMFS_IMAGE = "dm-verity-image-initramfs"
+
+python () {
+    if d.getVar('PN') != d.getVar('DM_VERITY_IMAGE'):
+        return
+
+    d.setVar('WKS_FILE', 'k3-verity.wks.in')
+    d.appendVar('EXTRA_IMAGE_FEATURES', ' read-only-rootfs')
+    d.appendVar('WICVARS', ' DM_VERITY_IMAGE DM_VERITY_IMAGE_TYPE IMAGE_NAME_SUFFIX IMGDEPLOYDIR')
+    d.appendVarFlag('do_image_wic', 'depends', ' %s:do_image_complete' % d.getVar('DM_VERITY_INITRAMFS_IMAGE'))
+    d.appendVar('IMAGE_BOOT_FILES', ' %s-%s.cpio.gz' % (d.getVar('DM_VERITY_INITRAMFS_IMAGE'), d.getVar('MACHINE')))
+}
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/files/dm-verity.ignorelist new file +1 -0
new file mode 100644
index 00000000..5af878c9
@@ -0,0 +1 @@
+/dev/mmcblk1p2
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend new file +0 -0
new file mode 100644
index 00000000..3940a24d

meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend line 9

Quoted 9 lines
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend new file +9 -0
@@ -0,0 +1,14 @@
+# Under dm-verity, the raw root partition looks unmounted to udev's
+# auto-mount check, so it tries to mount it a second time on its own,
+# outside of dm-verity's protection. This tells it to skip that partition.
+FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
+
+SRC_URI += "${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'file://dm-verity.ignorelist', '', d)}"
+
+do_install:append() {
+    if ${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'true', 'false', d)}; then

Add install -d ${D}${sysconfdir}/udev/mount.ignorelist.d before installing the file.

meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend line 14

Quoted 5 lines
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend new file +5 -0
+        install -m 0644 ${UNPACKDIR}/dm-verity.ignorelist ${D}${sysconfdir}/udev/mount.ignorelist.d/dm-verity
+    fi
+}
+
+FILES:${PN}-automount += "${sysconfdir}/udev/mount.ignorelist.d"

FILES variable just adds the folder here (misses the dm-verity file) it should be FILES:${PN}-automount += "${sysconfdir}/udev/mount.ignorelist.d/dm-verity"

meta-ti-bsp/files/wic/k3-verity.wks.in line 3

Quoted 9 lines
meta-ti-bsp/files/wic/k3-verity.wks.in new file +3 -0
new file mode 100644
index 00000000..6ef2c57f
@@ -0,0 +1,5 @@
+# Disk layout for a board that boots with dm-verity enabled.
+
+bootloader --timeout=3 --append="rootfstype=ext4 root=/dev/mmcblk1p2 ${TI_WKS_BOOTLOADER_APPEND}"

root variable should not be hardcoded to /dev/mmcblk1p2, not all machines will use the same partition numbering. Better to use uuid.

meta-ti-bsp/files/wic/k3-verity.wks.in line 5

Quoted 2 lines
meta-ti-bsp/files/wic/k3-verity.wks.in new file +2 -0
+part --source bootimg-efi --sourceparams="loader=${EFI_PROVIDER},initrd=${DM_VERITY_INITRAMFS_IMAGE}-${MACHINE}.cpio.gz" --fstype=vfat --label boot --active --align 1024 --use-uuid --fixed-size 128M
+part / --source rawcopy --sourceparams="file=${IMGDEPLOYDIR}/${DM_VERITY_IMAGE}-${MACHINE}${IMAGE_NAME_SUFFIX}.${DM_VERITY_IMAGE_TYPE}.verity" --align 1024

-- Yogesh

#6 lore raw

Hi Yogesh,

Quoted 110 lines · Yogesh Hegde
Quoted 10 lines · Atharv Dubey via lists.yoctoproject.org

Add an optional dynamic layer enabling dm-verity block-level integrity verification of the root filesystem for TI K3 platforms, using meta-security's stock dm-verity mechanism as-is.

dm-verity hashes the rootfs at build time; at boot, a dedicated initramfs loads the root hash and the kernel checks every block read against it. Wires DM_VERITY_IMAGE/WKS_FILE for the K3 boot chain, hooking do_image_wic instead of INITRAMFS_IMAGE to avoid a 3-way circular dependency through kernel-fit-image.bbclass.

Quoted 7 lines

DM_VERITY_IMAGE selects which image recipe gets verity-enabled (default arago-base-image, overridable in local.conf); all effects are scoped to PN == DM_VERITY_IMAGE, so building any other image type is unaffected. Only active when the "security" layer and dm-verity-upstream feature are enabled.

Hi Athrav, Thanks for the patch

Quoted 90 lines
---
  meta-ti-bsp/conf/layer.conf                     |  3 +++
  meta-ti-bsp/conf/machine/include/k3.inc         | 10 ++++++++++
  .../conf/include/dm-verity-upstream.inc         | 17 +++++++++++++++++
  .../udev/files/dm-verity.ignorelist             |  1 +
  .../recipes-core/udev/udev-extraconf_%.bbappend | 14 ++++++++++++++
  meta-ti-bsp/files/wic/k3-verity.wks.in          |  5 +++++
  6 files changed, 50 insertions(+)

create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/files/dm-verity.ignorelist create mode 100644 meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend create mode 100644 meta-ti-bsp/files/wic/k3-verity.wks.in

meta-ti-bsp/conf/layer.conf +3 -0
index 3cc54aa4..aca35cd3 100644
@@ -20,12 +20,15 @@ LAYERDEPENDS_meta-ti-bsp = " \
  LAYERRECOMMENDS_meta-ti-bsp = " \
      openembedded-layer \
      tpm-layer \
+    security \
  "
 
  BBFILES_DYNAMIC += " \
      openembedded-layer:${LAYERDIR}/dynamic-layers/openembedded-layer/recipes*/*/*.bbappend \
      tpm-layer:${LAYERDIR}/dynamic-layers/tpm-layer/recipes*/*/*.bb \
      tpm-layer:${LAYERDIR}/dynamic-layers/tpm-layer/recipes*/*/*.bbappend \
+    security:${LAYERDIR}/dynamic-layers/security-layer/recipes*/*/*.bb \
+    security:${LAYERDIR}/dynamic-layers/security-layer/recipes*/*/*.bbappend \
  "
 
  SIGGEN_EXCLUDERECIPES_ABISAFE += " \
meta-ti-bsp/conf/machine/include/k3.inc +10 -0
index 2ebbfb9e..e23e0ead 100644
@@ -64,3 +64,13 @@ FALCON_INCLUDE = ""
  FALCON_INCLUDE:ti-falcon = "conf/machine/include/ti-falcon.inc"
 
  require ${FALCON_INCLUDE}
+
+# Upstream dm-verity path: meta-security's own dm-verity-img.bbclass +
+# dm-verity-image-initramfs, used as-is (build-time hashing). Only active
+# when the security layer is present and this feature is explicitly
+# requested -- see dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc
+DISTRO_FEATURES[validitems] += "dm-verity-upstream"
+
+DM_VERITY_UPSTREAM_INCLUDE = "${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc', '', d)}"
+
+require ${DM_VERITY_UPSTREAM_INCLUDE}
meta-ti-bsp/dynamic-layers/security-layer/conf/include/dm-verity-upstream.inc new file +17 -0
new file mode 100644
index 00000000..4de9e2fb
@@ -0,0 +1,17 @@
+# Enables dm-verity to check the rootfs for tampering on TI K3 boards.
+DM_VERITY_IMAGE ?= "arago-base-image"
+DM_VERITY_IMAGE_TYPE = "ext4"
+IMAGE_CLASSES += "dm-verity-img"
+
+DM_VERITY_INITRAMFS_IMAGE = "dm-verity-image-initramfs"
+
+python () {
+    if d.getVar('PN') != d.getVar('DM_VERITY_IMAGE'):
+        return
+
+    d.setVar('WKS_FILE', 'k3-verity.wks.in')
+    d.appendVar('EXTRA_IMAGE_FEATURES', ' read-only-rootfs')
+    d.appendVar('WICVARS', ' DM_VERITY_IMAGE DM_VERITY_IMAGE_TYPE IMAGE_NAME_SUFFIX IMGDEPLOYDIR')
+    d.appendVarFlag('do_image_wic', 'depends', ' %s:do_image_complete' % d.getVar('DM_VERITY_INITRAMFS_IMAGE'))
+    d.appendVar('IMAGE_BOOT_FILES', ' %s-%s.cpio.gz' % (d.getVar('DM_VERITY_INITRAMFS_IMAGE'), d.getVar('MACHINE')))
+}
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/files/dm-verity.ignorelist new file +1 -0
new file mode 100644
index 00000000..5af878c9
@@ -0,0 +1 @@
+/dev/mmcblk1p2
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend new file +3 -0
new file mode 100644
index 00000000..3940a24d
@@ -0,0 +1,14 @@
+# Under dm-verity, the raw root partition looks unmounted to udev's
+# auto-mount check, so it tries to mount it a second time on its own,
+# outside of dm-verity's protection. This tells it to skip that partition.
Quoted 8 lines

meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend line 9

Quoted 6 lines
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend new file +6 -0
+FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
+
+SRC_URI += "${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'file://dm-verity.ignorelist', '', d)}"
+
+do_install:append() {
+    if ${@bb.utils.contains('DISTRO_FEATURES', 'dm-verity-upstream', 'true', 'false', d)}; then

Add install -d ${D}${sysconfdir}/udev/mount.ignorelist.d before installing the file.

Sure will make the change in the next revision.

Quoted 8 lines

meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend line 14

Quoted 6 lines
meta-ti-bsp/dynamic-layers/security-layer/recipes-core/udev/udev-extraconf_%.bbappend new file +5 -0
+        install -m 0644 ${UNPACKDIR}/dm-verity.ignorelist ${D}${sysconfdir}/udev/mount.ignorelist.d/dm-verity
+    fi
+}
+
+FILES:${PN}-automount += "${sysconfdir}/udev/mount.ignorelist.d"

FILES variable just adds the folder here (misses the dm-verity file) it should be FILES:${PN}-automount += "${sysconfdir}/udev/mount.ignorelist.d/dm-verity"

Yeah, good catch will update this in next version.

Quoted 12 lines

meta-ti-bsp/files/wic/k3-verity.wks.in line 3

Quoted 10 lines
meta-ti-bsp/files/wic/k3-verity.wks.in new file +3 -0
new file mode 100644
index 00000000..6ef2c57f
@@ -0,0 +1,5 @@
+# Disk layout for a board that boots with dm-verity enabled.
+
+bootloader --timeout=3 --append="rootfstype=ext4 root=/dev/mmcblk1p2 ${TI_WKS_BOOTLOADER_APPEND}"

root variable should not be hardcoded to /dev/mmcblk1p2, not all machines will use the same partition numbering. Better to use uuid.

Sure will do this in the next version .

Quoted 5 lines

meta-ti-bsp/files/wic/k3-verity.wks.in line 5

Quoted 3 lines
meta-ti-bsp/files/wic/k3-verity.wks.in new file +2 -0
+part --source bootimg-efi --sourceparams="loader=${EFI_PROVIDER},initrd=${DM_VERITY_INITRAMFS_IMAGE}-${MACHINE}.cpio.gz" --fstype=vfat --label boot --active --align 1024 --use-uuid --fixed-size 128M
+part / --source rawcopy --sourceparams="file=${IMGDEPLOYDIR}/${DM_VERITY_IMAGE}-${MACHINE}${IMAGE_NAME_SUFFIX}.${DM_VERITY_IMAGE_TYPE}.verity" --align 1024

-- Yogesh

Thanks,
Atharv