sata: make the boot partition reproducible

The ext2 boot partition of the WD My Book Live images differs between
builds:

  -Linux rev 1.0 ext2 filesystem data, UUID=8474430c-7c37-4000-95a5-1d8f4f0607d1
  +Linux rev 1.0 ext2 filesystem data, UUID=4b8e89bb-aee0-4fde-971c-893df8d8fcd1
  -drwxr-xr-x   0     1000     1000        0 2026-09-23 08:27:40.000000 ./boot/
  +drwxr-xr-x   0     1000     1000        0 2026-09-23 10:17:28.000000 ./boot/

genext2fs copies owner, mode and mtime of the staged files from the host
and adds them in readdir() order, which also decides their inode numbers
and blocks. It leaves the UUID empty, so e2fsck fills in a random one,
and e2fsck stamps the last check with the current time.

Pass genext2fs a name sorted tarball with root ownership, group and
other write permission dropped and mtimes clamped to SOURCE_DATE_EPOCH,
derive the UUID from the file system contents and run e2fsck with
E2FSCK_TIME set to SOURCE_DATE_EPOCH. Remove the staging directory and
the tarball afterwards.

Link: https://github.com/openwrt/openwrt/pull/25357
Signed-off-by: Paul Spooren <mail@aparcar.org>
This commit is contained in:
Paul Spooren committed 2026-09-27 10:18:12 +02:00
1 parent 177bc19f27
commit 4092869bc8
1 file changed
+13 -3
+13 -3
View File
@@ -11,14 +11,24 @@ define Build/boot-img
$(CP) $(KDIR)/image-$(firstword $(DEVICE_DTS)).dtb $@.bootdir/boot/$(DEVICE_DTB)
$(CP) $(IMAGE_KERNEL) $@.bootdir/boot/uImage
$(TAR) -C $@.bootdir -cf $@.bootdir.tar --sort=name --numeric-owner \
--owner=0 --group=0 --mode=go-w \
$(if $(SOURCE_DATE_EPOCH),--mtime="@$(SOURCE_DATE_EPOCH)" --clamp-mtime) \
boot
genext2fs --block-size $(BLOCKSIZE:%k=%Ki) \
--size-in-blocks $$((1024 * $(CONFIG_TARGET_KERNEL_PARTSIZE))) \
--root $@.bootdir $@.boot
--tarball $@.bootdir.tar $@.boot
# convert it to revision 1 - needed for u-boot ext2load
$(STAGING_DIR_HOST)/bin/tune2fs -O filetype $@.boot
$(STAGING_DIR_HOST)/bin/tune2fs -O filetype \
-U $(patsubst %00,%01,$(IMG_PART_DISKGUID)) \
$@.boot
# Ignore errors because file system was intentionally broken with tune2fs
-$(STAGING_DIR_HOST)/bin/e2fsck -pDf $@.boot > /dev/null
-$(if $(SOURCE_DATE_EPOCH),E2FSCK_TIME=$(SOURCE_DATE_EPOCH)) \
$(STAGING_DIR_HOST)/bin/e2fsck -pDf $@.boot > /dev/null
rm -rf $@.bootdir $@.bootdir.tar
endef
define Build/boot-script