Skip to contentSkip to conversation

fs/common.mk: add optional hook to build a verity hash tree

Buildroot Julien Olivain via buildroot 1 participant 1 message Sep 20 VFS

lore
Share & tools
lore
#0 lore raw

commit: https://gitlab.com/buildroot.org/buildroot/-/commit/7198cea534ac197c9047143cb76df267cc42cbf9
branch: https://gitlab.com/buildroot.org/buildroot/-/tree/master

Using dm-verity may be useful for any read-only filesystem read from a block device, the new hook will build the required hash tree if enabled by a per-filesystem config option.

To use this hook, the filesystem config must define a boolean option BR2_TARGET_ROOTFS_<FS>_VERITY, and a string option BR2_TARGET_ROOTFS_<FS>_VERITY_EXTRA_ARGS. The latter option allows users to override veritysetup defaults, e.g. to set a fixed hash algorithm.

In the filesystem .mk file ROOTFS_<FS>_VERITY_EXTRA_ARGS must be defined as the value of BR2_TARGET_ROOTFS_<FS>_VERITY_EXTRA_ARGS without surrounding quotes, because utils/check-symbols warns about the _EXTRA_ARGS symbol being unused if fs/common.mk uses $(qstrip $(BR2_TARGET_ROOTFS_$(2)_VERITY_EXTRA_ARGS)) directly.

---
 fs/common.mk | 9 +++++++++
 1 file changed, 9 insertions(+)
fs/common.mk +9 -0
index 2f3f8bcc7e..4b4a0995df 100644
@@ -215,6 +215,15 @@ TARGETS_ROOTFS += rootfs-$(1)
 PACKAGES += $$(filter-out rootfs-%,$$(ROOTFS_$(2)_FINAL_RECURSIVE_DEPENDENCIES))
 endif
 
+ifeq ($$(BR2_TARGET_ROOTFS_$(2)_VERITY),y)
+ROOTFS_$(2)_DEPENDENCIES += host-cryptsetup
+define ROOTFS_$(2)_VERITY_FORMAT
+	@$$(call MESSAGE,"Generating verity hash tree $$(@F).verity")
+	$(HOST_DIR)/sbin/veritysetup format --root-hash-file [email protected] $$(ROOTFS_$(2)_VERITY_EXTRA_ARGS) $$@ [email protected]
+endef
+ROOTFS_$(2)_POST_GEN_HOOKS += ROOTFS_$(2)_VERITY_FORMAT
+endif
+
 # Check for legacy POST_TARGETS rules
 ifneq ($$(ROOTFS_$(2)_POST_TARGETS),)
 $$(error Filesystem $(1) uses post-target rules, which are no longer supported.\

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot