1*2daf84b2SAndrew Geisslerdm-verity and Yocto/OE
2*2daf84b2SAndrew Geissler----------------------
3*2daf84b2SAndrew GeisslerThe dm-verity feature provides a level of data integrity and resistance to
4*2daf84b2SAndrew Geisslerdata tampering.  It does this by creating a hash for each data block of
5*2daf84b2SAndrew Geisslerthe underlying device as the base of a hash tree.  There are many
6*2daf84b2SAndrew Geisslerdocuments out there to further explain the implementaion, such as the
7*2daf84b2SAndrew Geisslerin-kernel one itself:
8*2daf84b2SAndrew Geissler
9*2daf84b2SAndrew Geisslerhttps://docs.kernel.org/admin-guide/device-mapper/verity.html
10*2daf84b2SAndrew Geissler
11*2daf84b2SAndrew GeisslerThe goal of this document is not to reproduce that content, but instead to
12*2daf84b2SAndrew Geisslercapture the Yocto/OE specifics of the dm-verity infrastructure used here.
13*2daf84b2SAndrew Geissler
14*2daf84b2SAndrew GeisslerIdeally this should enable a person to build and deploy an image on one of
15*2daf84b2SAndrew Geisslerthe supported reference platforms, and then further adapt to their own
16*2daf84b2SAndrew Geisslerplatform and specific storage requirements.
17*2daf84b2SAndrew Geissler
18*2daf84b2SAndrew GeisslerBasic Settings
19*2daf84b2SAndrew Geissler--------------
20*2daf84b2SAndrew GeisslerLargely everything is driven off of a dm-verity image class; a typical
21*2daf84b2SAndrew Geisslerblock of non MACHINE specific settings are shown below:
22*2daf84b2SAndrew Geissler
23*2daf84b2SAndrew GeisslerINITRAMFS_IMAGE = "dm-verity-image-initramfs"
24*2daf84b2SAndrew GeisslerDM_VERITY_IMAGE = "core-image-minimal"
25*2daf84b2SAndrew GeisslerDM_VERITY_IMAGE_TYPE = "ext4"
26*2daf84b2SAndrew GeisslerIMAGE_CLASSES += "dm-verity-img"
27*2daf84b2SAndrew GeisslerINITRAMFS_IMAGE_BUNDLE = "1"
28*2daf84b2SAndrew Geissler
29*2daf84b2SAndrew GeisslerKernel Configuration
30*2daf84b2SAndrew Geissler--------------------
31*2daf84b2SAndrew GeisslerKernel configuration for dm-verity happens automatically via IMAGE_CLASSES
32*2daf84b2SAndrew Geisslerwhich will source features/device-mapper/dm-verity.scc when dm-verity-img
33*2daf84b2SAndrew Geissleris used. [See commit d9feafe991c]
34*2daf84b2SAndrew Geissler
35*2daf84b2SAndrew GeisslerSupported Platforms
36*2daf84b2SAndrew Geissler-------------------
37*2daf84b2SAndrew GeisslerIn theory, you can use dm-verity anywhere - there is nothing arch/BSP
38*2daf84b2SAndrew Geisslerspecific in the core kernel support.  However, at the BSP level, one
39*2daf84b2SAndrew Geisslereventually has to decide what device(s) are to be hashed, and where the
40*2daf84b2SAndrew Geisslerhash tables are stored.
41*2daf84b2SAndrew Geissler
42*2daf84b2SAndrew GeisslerTo that end, the BSP storage specifics live in meta-security/wic dir and
43*2daf84b2SAndrew Geisslerrepresent the current set of example configurations that have been tested
44*2daf84b2SAndrew Geisslerand submitted at some point.
45*2daf84b2SAndrew Geissler
46*2daf84b2SAndrew GeisslerGetting Started
47*2daf84b2SAndrew Geissler---------------
48*2daf84b2SAndrew GeisslerThis document assumes you are starting from the basic auto-created
49*2daf84b2SAndrew Geisslerconf/local.conf and conf/bblayers.conf from the oe-init-build-env
50*2daf84b2SAndrew Geissler
51*2daf84b2SAndrew GeisslerFirstly, you need the meta-security layer to conf/bblayers.conf along with
52*2daf84b2SAndrew Geisslerthe dependencies it has -- see the top level meta-security README for that.
53*2daf84b2SAndrew Geissler
54*2daf84b2SAndrew GeisslerNext, assuming you'll be using dm-verity for validation of your rootfs,
55*2daf84b2SAndrew Geissleryou'll need to enable read-only rootfs support in your local.conf with:
56*2daf84b2SAndrew Geissler
57*2daf84b2SAndrew GeisslerEXTRA_IMAGE_FEATURES = "read-only-rootfs"
58*2daf84b2SAndrew Geissler
59*2daf84b2SAndrew GeisslerFor more details, see the associated documentation:
60*2daf84b2SAndrew Geissler
61*2daf84b2SAndrew Geisslerhttps://docs.yoctoproject.org/dev/dev-manual/read-only-rootfs.html
62*2daf84b2SAndrew Geissler
63*2daf84b2SAndrew GeisslerAlso add the basic block of dm-verity settings shown above, and select
64*2daf84b2SAndrew Geissleryour MACHINE from one of the supported platforms.
65*2daf84b2SAndrew Geissler
66*2daf84b2SAndrew GeisslerIf there is a dm-verity-<MACHINE>.txt file for your BSP, check that for
67*2daf84b2SAndrew Geisslerany additional platform specific recommended settings, such as the
68*2daf84b2SAndrew GeisslerWKS_FILES which can specify board specific storage layout discussed below.
69*2daf84b2SAndrew Geissler
70*2daf84b2SAndrew GeisslerThen you should be able to do a "bitbake core-image-minimal" just like any
71*2daf84b2SAndrew Geisslerother normal build.  What you will notice, is the content in
72*2daf84b2SAndrew Geisslertmp/deploy/images/<MACHINE>/ now have suffixes like "rootfs.ext4.verity"
73*2daf84b2SAndrew Geissler
74*2daf84b2SAndrew GeisslerWhile you can manually work with these images just like any other build,
75*2daf84b2SAndrew Geisslerthis is where the BSP specific recipes in meta-security/wic can simplify
76*2daf84b2SAndrew Geisslerthings and remove a bunch of manual steps that might be error prone.
77*2daf84b2SAndrew Geissler
78*2daf84b2SAndrew GeisslerConsider for example, the beaglebone black WIC file, which contains:
79*2daf84b2SAndrew Geissler
80*2daf84b2SAndrew Geisslerpart /boot --source bootimg-partition --ondisk mmcblk0 --fstype=vfat
81*2daf84b2SAndrew Geissler--label boot --active --align 4 --fixed-size 32 --sourceparams="loader=u-boot" --use-uuid
82*2daf84b2SAndrew Geisslerpart / --source rawcopy --ondisk mmcblk0 --sourceparams="file=${IMGDEPLOYDIR}/${DM_VERITY_IMAGE}-${MACHINE}.${DM_VERITY_IMAGE_TYPE}.verity"
83*2daf84b2SAndrew Geisslerbootloader --append="console=ttyS0,115200"
84*2daf84b2SAndrew Geissler
85*2daf84b2SAndrew GeisslerAs can be seen, it maps out the partitions, including the bootloader, and
86*2daf84b2SAndrew Geisslersaves doing a whole bunch of manual partitioning and dd steps.
87*2daf84b2SAndrew Geissler
88*2daf84b2SAndrew GeisslerThis file is copied into tmp/deploy/images/<MACHINE>/ with bitbake
89*2daf84b2SAndrew Geisslervariables expanded with their corresponding values for wic to make use of.
90*2daf84b2SAndrew Geissler
91*2daf84b2SAndrew GeisslerContinuing with the beaglebone example, we'll see output similar to:
92*2daf84b2SAndrew Geissler
93*2daf84b2SAndrew Geissler             ----------------------
94*2daf84b2SAndrew Geissler$ wic create -e core-image-minimal beaglebone-yocto-verity
95*2daf84b2SAndrew Geissler
96*2daf84b2SAndrew Geissler[...]
97*2daf84b2SAndrew Geissler
98*2daf84b2SAndrew GeisslerINFO: Creating image(s)...
99*2daf84b2SAndrew Geissler
100*2daf84b2SAndrew GeisslerINFO: The new image(s) can be found here:
101*2daf84b2SAndrew Geissler  ./beaglebone-yocto-verity.wks-202303070223-mmcblk0.direct
102*2daf84b2SAndrew Geissler
103*2daf84b2SAndrew GeisslerThe following build artifacts were used to create the image(s):
104*2daf84b2SAndrew Geissler  BOOTIMG_DIR:       /home/paul/poky/build-bbb-verity/tmp/work/beaglebone_yocto-poky-linux-gnueabi/core-image-minimal/1.0-r0/recipe-sysroot/usr/share
105*2daf84b2SAndrew Geissler  KERNEL_DIR:        /home/paul/poky/build-bbb-verity/tmp/deploy/images/beaglebone-yocto
106*2daf84b2SAndrew Geissler  NATIVE_SYSROOT:    /home/paul/poky/build-bbb-verity/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/wic-tools/1.0-r0/recipe-sysroot-native
107*2daf84b2SAndrew Geissler
108*2daf84b2SAndrew GeisslerINFO: The image(s) were created using OE kickstart file:
109*2daf84b2SAndrew Geissler  /home/paul/poky/meta-security/wic/beaglebone-yocto-verity.wks.in
110*2daf84b2SAndrew Geissler             ----------------------
111*2daf84b2SAndrew Geissler
112*2daf84b2SAndrew GeisslerThe "direct" image contains the partition table, bootloader, and dm-verity
113*2daf84b2SAndrew Geisslerenabled ext4 image all in one -- ready to write to a raw device, such as a
114*2daf84b2SAndrew Geissleru-SD card in the case of the beaglebone.
115