From 290bdfcedb7b95cbf24dbf3d829bd41c492aad63 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Thu, 13 Nov 2025 22:36:28 +0100 Subject: [PATCH] board/common: Consolidate aux.ext4 generation Add a generic image target to build aux.ext4, which can be used both when creating target-specific SD-card images, and when creating regular disk images. While we're here, make sure that we don't need a RAUC bundle in order to generate aux.ext4 (which mkrauc-status.sh did). This saves us time on _every_ incremental build. --- board/common/Config.in | 7 +- board/common/image/image-itb-aux/Config.in | 10 +++ board/common/image/image-itb-aux/generate.sh | 85 +++++++++++++++++++ board/common/image/image-itb-aux/grub.cfg | 80 +++++++++++++++++ board/common/image/image-itb-aux/grubenv | 10 +++ .../image/image-itb-aux/image-itb-aux.mk | 10 +++ board/common/mkaux.sh | 40 --------- board/common/post-image.sh | 8 -- configs/riscv64_defconfig | 2 +- 9 files changed, 197 insertions(+), 55 deletions(-) create mode 100644 board/common/image/image-itb-aux/Config.in create mode 100755 board/common/image/image-itb-aux/generate.sh create mode 100644 board/common/image/image-itb-aux/grub.cfg create mode 100644 board/common/image/image-itb-aux/grubenv create mode 100644 board/common/image/image-itb-aux/image-itb-aux.mk delete mode 100755 board/common/mkaux.sh diff --git a/board/common/Config.in b/board/common/Config.in index 60904edd..a484572b 100644 --- a/board/common/Config.in +++ b/board/common/Config.in @@ -1,6 +1,7 @@ menu "Images" source "$BR2_EXTERNAL_INFIX_PATH/board/common/image/image-itb-rootfs/Config.in" +source "$BR2_EXTERNAL_INFIX_PATH/board/common/image/image-itb-aux/Config.in" source "$BR2_EXTERNAL_INFIX_PATH/board/common/image/image-itb-rauc/Config.in" endmenu @@ -144,9 +145,3 @@ config FIT_KERNEL_LOAD_ADDR string "Kernel load address" depends on FIT_IMAGE -config SDCARD_AUX - bool "Create SD-card aux partition" - help - Create and populate aux.ext4 with rootfs.itbh and rauc.status - For use with a static genimage.cfg for, e.g., SD-cards. - diff --git a/board/common/image/image-itb-aux/Config.in b/board/common/image/image-itb-aux/Config.in new file mode 100644 index 00000000..4cda6cd6 --- /dev/null +++ b/board/common/image/image-itb-aux/Config.in @@ -0,0 +1,10 @@ +config IMAGE_ITB_AUX + bool "aux partition" + depends on IMAGE_ITB_ROOTFS + select BR2_PACKAGE_HOST_UBOOT_TOOLS + select BR2_PACKAGE_HOST_GENIMAGE + help + Create and populate auxiliary partition, aux.ext4, with + metadata needed by U-Boot and RAUC to operate properly on + systems using ITB images. This may then be included as a + partition in a larger disk image. diff --git a/board/common/image/image-itb-aux/generate.sh b/board/common/image/image-itb-aux/generate.sh new file mode 100755 index 00000000..127535b3 --- /dev/null +++ b/board/common/image/image-itb-aux/generate.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +set -e + +boot="${1}" +squash="${BINARIES_DIR}"/rootfs.squashfs +itbh="${BINARIES_DIR}"/rootfs.itbh +aux="${BINARIES_DIR}"/aux.ext4 + +mkdir -p "${WORKDIR}"/aux +rm -rf "${WORKDIR}"/tmp +mkdir -p "${WORKDIR}"/tmp + +cp -f "${itbh}" "${WORKDIR}"/aux/primary.itbh +cp -f "${itbh}" "${WORKDIR}"/aux/secondary.itbh + +tstamp=$(date -u +%FT%TZ) +rootsha=$(sha256sum "${squash}" | cut -d" " -f1) +rootsize=$(stat -c %s "${squash}") +cat <"${WORKDIR}"/aux/rauc.status +[slot.rootfs.0] +bundle.compatible=${COMPATIBLE} +bundle.version=${VERSION} +status=ok +sha256=${rootsha} +size=${rootsize} +installed.timestamp=$tstamp +installed.count=1 +activated.timestamp=$tstamp +activated.count=1 + +[slot.rootfs.1] +bundle.compatible=${COMPATIBLE} +bundle.version=${VERSION} +status=ok +sha256=${rootsha} +size=${rootsize} +installed.timestamp=$tstamp +installed.count=1 +activated.timestamp=$tstamp +activated.count=1 +EOF + +case "${boot}" in + uboot) + cat <&2 + exit 1 +esac + +cat <"${WORKDIR}"/genimage.cfg +image $(basename ${aux}) { + mountpoint = "/" + size = 8M + + ext4 { + label = "aux" + use-mke2fs = true + features = "^metadata_csum,^metadata_csum_seed,uninit_bg" + extraargs = "-m 0 -i 4096" + } +} + +# Silence genimage warnings +config {} +EOF + +genimage \ + --loglevel 1 \ + --tmppath "${WORKDIR}"/tmp \ + --rootpath "${WORKDIR}"/aux \ + --inputpath "${WORKDIR}" \ + --outputpath "$(dirname ${aux})" \ + --config "${WORKDIR}"/genimage.cfg diff --git a/board/common/image/image-itb-aux/grub.cfg b/board/common/image/image-itb-aux/grub.cfg new file mode 100644 index 00000000..c62114e1 --- /dev/null +++ b/board/common/image/image-itb-aux/grub.cfg @@ -0,0 +1,80 @@ +set timeout="1" + +load_env ORDER DEBUG + +if [ -z "$ORDER" ]; then + set ORDER="primary secondary" +fi + +set ORDER="$ORDER reboot" + +for slot in $ORDER; do + if [ -z "$default" ]; then + set default="$slot" + else + # Contrary to what the documentation says, GRUB (2.06) does + # not support using titles or IDs in the fallback variable, so + # we translate to indices. + if [ "$slot" = "primary" ]; then + set fallback="$fallback 0" + elif [ "$slot" = "secondary" ]; then + set fallback="$fallback 1" + elif [ "$slot" = "net" ]; then + set fallback="$fallback 2" + elif [ "$slot" = "reboot" ]; then + set fallback="$fallback 3" + fi + fi +done + +if [ "$DEBUG" ]; then + set log="debug" +else + set log="loglevel=4" +fi + +# From board/common/rootfs/etc/partition-uuid +search -p 107ae911-a97b-4380-975c-7ce1a2dde1e0 --set primary +search -p 352bd9b2-2ca9-44e2-bdc7-edbc87ba1e02 --set secondary + +export primary +export secondary + +submenu "primary" "$log" { + set slot="$1" + set append="console=ttyS0 console=hvc0 usbcore.authorized_default=2 root=PARTLABEL=$slot $2" + set root="($primary)" + source /boot/grub/grub.cfg +} + +submenu "secondary" "$log" { + set slot="$1" + set append="console=ttyS0 console=hvc0 usbcore.authorized_default=2 root=PARTLABEL=$slot $2" + set root="($secondary)" + source /boot/grub/grub.cfg +} + +submenu "net" "$log" { + net_dhcp + + if [ "$net_efinet0_dhcp_next_server" -a "$net_efinet0_dhcp_boot_file" ]; then + set initrd=(tftp,$net_efinet0_dhcp_next_server)/$net_efinet0_dhcp_boot_file + loopback initrd $initrd + set root=(initrd) + + set slot="$1" + set append="console=ttyS0 console=hvc0 usbcore.authorized_default=2 qroot=/dev/ram0 ramdisk_size=65536 $2" + source /boot/grub/grub.cfg + else + if [ -z "$net_efinet0_dhcp_next_server" ]; then + echo "No TFTP server supplied in DHCP response" + fi + if [ -z "$net_efinet0_dhcp_boot_file" ]; then + echo "No bootfile supplied in DHCP response" + fi + fi +} + +submenu "reboot" { + reboot +} diff --git a/board/common/image/image-itb-aux/grubenv b/board/common/image/image-itb-aux/grubenv new file mode 100644 index 00000000..b1eb67d3 --- /dev/null +++ b/board/common/image/image-itb-aux/grubenv @@ -0,0 +1,10 @@ +# GRUB Environment Block +# WARNING: Do not edit this file by tools other than grub-editenv!!! +ORDER=primary secondary net +primary_OK=1 +secondary_OK=1 +net_OK=1 +primary_TRY=0 +secondary_TRY=0 +net_TRY=0 +######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################### \ No newline at end of file diff --git a/board/common/image/image-itb-aux/image-itb-aux.mk b/board/common/image/image-itb-aux/image-itb-aux.mk new file mode 100644 index 00000000..69458924 --- /dev/null +++ b/board/common/image/image-itb-aux/image-itb-aux.mk @@ -0,0 +1,10 @@ +################################################################################ +# +# image-itb-aux +# +################################################################################ + +IMAGE_ITB_AUX_DEPENDENCIES := host-uboot-tools host-genimage image-itb-rootfs +IMAGE_ITB_AUX_OPTS := $(if $(BR2_TARGET_GRUB2),grub,uboot) + +$(eval $(ix-image)) diff --git a/board/common/mkaux.sh b/board/common/mkaux.sh deleted file mode 100755 index 0adf9f0f..00000000 --- a/board/common/mkaux.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh - -rootdir=$BUILD_DIR/genimage.root -tempdir=$BUILD_DIR/genimage.tmp - -cat < /tmp/mkaux.cfg -image aux.ext4 { - mountpoint = "/aux" - size = 16M - - ext4 { - label = "aux" - use-mke2fs = true - features = "^metadata_csum,^metadata_csum_seed,uninit_bg" - extraargs = "-m 0 -i 4096" - } -} - -# Silence genimage warnings -config {} -EOF - -rm -rf "$rootdir/aux" -mkdir -p "$rootdir/aux" -cp -f "$BINARIES_DIR/rootfs.itbh" "$rootdir/aux/primary.itbh" -cp -f "$BINARIES_DIR/rootfs.itbh" "$rootdir/aux/secondary.itbh" -cp -f "$BINARIES_DIR/rauc.status" "$rootdir/aux/rauc.status" - -mkenvimage -s 0x4000 -o "$rootdir/aux/uboot.env" \ - "$BR2_EXTERNAL_INFIX_PATH/board/common/uboot/aux-env.txt" - -rm -rf "$BINARIES_DIR/aux.ext4" -rm -rf "$tempdir" - -genimage \ - --rootpath "$rootdir" \ - --tmppath "$tempdir" \ - --inputpath "$BINARIES_DIR" \ - --outputpath "$BINARIES_DIR" \ - --config "/tmp/mkaux.cfg" diff --git a/board/common/post-image.sh b/board/common/post-image.sh index 69983242..8f6d3cb4 100755 --- a/board/common/post-image.sh +++ b/board/common/post-image.sh @@ -54,14 +54,6 @@ if [ "$DISK_IMAGE" = "y" ]; then $common/mkdisk.sh -a $BR2_ARCH -n $diskimg -s $DISK_IMAGE_SIZE $bootcfg fi -load_cfg SDCARD_AUX -if [ "$SDCARD_AUX" = "y" ]; then - ixmsg "Creating initial rauc.status" - $common/mkrauc-status.sh "$BINARIES_DIR/${NAME}.pkg" >"$BINARIES_DIR/rauc.status" - ixmsg "Creating aux.ext4 for sdcard.img" - $common/mkaux.sh -fi - load_cfg GNS3_APPLIANCE if [ "$GNS3_APPLIANCE" = "y" ]; then ixmsg "Creating GNS3 Appliance, $GNS3_APPLIANCE_RAM MiB with $GNS3_APPLIANCE_IFNUM ports" diff --git a/configs/riscv64_defconfig b/configs/riscv64_defconfig index 198cd002..b4278cb8 100644 --- a/configs/riscv64_defconfig +++ b/configs/riscv64_defconfig @@ -204,7 +204,7 @@ BR2_PACKAGE_TETRIS=y BR2_PACKAGE_ROUSETTE=y BR2_PACKAGE_RAUC_INSTALLATION_STATUS=y BR2_PACKAGE_HOST_PYTHON_YANGDOC=y +IMAGE_ITB_AUX=y TRUSTED_KEYS=y TRUSTED_KEYS_DEVELOPMENT=y # GNS3_APPLIANCE is not set -SDCARD_AUX=y