From aee053c94bd6d895c7cb0ceced02f900d8f43a11 Mon Sep 17 00:00:00 2001 From: Tobias Waldekranz Date: Tue, 18 Nov 2025 20:02:34 +0100 Subject: [PATCH] board/common: Move QEMU disk creation to separate make target --- board/common/Config.in | 78 +---------- board/common/image/image-itb-qcow/Config.in | 80 +++++++++++ .../image-itb-qcow/generate.sh} | 132 ++++++------------ .../image-itb-qcow}/genimage.cfg.in | 24 ++-- .../image/image-itb-qcow/image-itb-qcow.mk | 10 ++ board/common/image/ix-image.mk | 1 + board/common/mkrauc-status.sh | 35 ----- board/common/post-image.sh | 23 +-- test/env | 20 +-- test/test.mk | 8 +- test/virt/quad/topology.dot.in | 2 +- 11 files changed, 160 insertions(+), 253 deletions(-) create mode 100644 board/common/image/image-itb-qcow/Config.in rename board/common/{mkdisk.sh => image/image-itb-qcow/generate.sh} (50%) rename board/common/{ => image/image-itb-qcow}/genimage.cfg.in (86%) create mode 100644 board/common/image/image-itb-qcow/image-itb-qcow.mk delete mode 100755 board/common/mkrauc-status.sh diff --git a/board/common/Config.in b/board/common/Config.in index a484572b..3d77fef1 100644 --- a/board/common/Config.in +++ b/board/common/Config.in @@ -2,6 +2,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-qcow/Config.in" source "$BR2_EXTERNAL_INFIX_PATH/board/common/image/image-itb-rauc/Config.in" endmenu @@ -24,83 +25,6 @@ config TRUSTED_KEYS_EXTRA_PATH string "Path to extra keys to include in image" depends on TRUSTED_KEYS -menuconfig DISK_IMAGE - bool "Disk image" - help - Compose a full disk image with redundant Linux OS partitions, - configuration partition, etc. - - This is useful when: - - Bringing up a blank system during manufacturing - - Creating a GNS3 appliance - - Developing/debugging issues in the boot process in QEMU - -menuconfig DISK_IMAGE_SIZE - string "Image size" - depends on DISK_IMAGE - default "512M" - help - Create a disk image of this size. A K/M/G suffix may be used - to multiply by powers of 1024. Suffixes like KB/MB/GB may be - used to multiply by powers of 1000. The image will be split - proportionally to fit the two rootfs, a kernel, a writable - /cfg and /var partiotions. - - Minimum supported size is 512M. - -choice - prompt "Bootloader" - depends on DISK_IMAGE - default DISK_IMAGE_BOOT_EFI if BR2_x86_64 - default DISK_IMAGE_BOOT_NONE - -config DISK_IMAGE_BOOT_NONE - bool "None" - help - Do not create any bootloader partition in the disk image. - -config DISK_IMAGE_BOOT_EFI - bool "EFI" - help - Create a boot partition from a directory containing an EFI - boot application, e.g. GRUB. - -config DISK_IMAGE_BOOT_BIN - bool "Binary" - help - Create a boot partition from a raw image containing the boot - application, e.g. U-Boot. - -endchoice - -config DISK_IMAGE_BOOT_DATA - string "Bootloader data" - depends on DISK_IMAGE - depends on DISK_IMAGE_BOOT_EFI || DISK_IMAGE_BOOT_BIN - default "${BINARIES_DIR}/efi-part/EFI" if BR2_x86_64 - help - Path to the directory or file holding the bootloader data. - -config DISK_IMAGE_BOOT_OFFSET - hex "Bootloader offset" - depends on DISK_IMAGE - depends on DISK_IMAGE_BOOT_EFI || DISK_IMAGE_BOOT_BIN - default 0x8000 - help - Offset at which the bootloader partition is placed. Remember - to make sure that the GPT still fits at the start of the - image. - -config DISK_IMAGE_RELEASE_URL - string "Infix URL" - depends on DISK_IMAGE - depends on !BR2_TARGET_ROOTFS_SQUASHFS - default "https://github.com/kernelkit/infix/releases/download/latest/infix-${BR2_ARCH}.tar.gz" - help - In situations where Infix itself is not being built, but a - disk image is, i.e. when building a bootloader: place this - Infix release in the primary and secondary partitions. - menuconfig GNS3_APPLIANCE bool "GNS3 Appliance" select DISK_IMAGE diff --git a/board/common/image/image-itb-qcow/Config.in b/board/common/image/image-itb-qcow/Config.in new file mode 100644 index 00000000..c8c55945 --- /dev/null +++ b/board/common/image/image-itb-qcow/Config.in @@ -0,0 +1,80 @@ +menuconfig IMAGE_ITB_QCOW + bool "QEMU disk image (ITB)" + default y + select IMAGE_ITB_ROOTFS + select IMAGE_ITB_AUX + select BR2_PACKAGE_HOST_GENIMAGE + help + Compose a full disk image with redundant Linux OS partitions, + configuration partition, etc., for systems using ITB images. + + This is useful when: + - Bringing up a blank system during manufacturing + - Creating a GNS3 appliance + - Developing/debugging issues in the boot process in QEMU + +menuconfig IMAGE_ITB_QCOW_SIZE + string "Image size" + depends on IMAGE_ITB_QCOW + default "512M" + help + Create a disk image of this size. A K/M/G suffix may be used + to multiply by powers of 1024. Suffixes like KB/MB/GB may be + used to multiply by powers of 1000. The image will be split + proportionally to fit the two rootfs, a kernel, a writable + /cfg and /var partiotions. + + Minimum supported size is 512M. + +choice + prompt "Bootloader" + depends on IMAGE_ITB_QCOW + default IMAGE_ITB_QCOW_BOOT_EFI if BR2_x86_64 + default IMAGE_ITB_QCOW_BOOT_NONE + +config IMAGE_ITB_QCOW_BOOT_NONE + bool "None" + help + Do not create any bootloader partition in the disk image. + +config IMAGE_ITB_QCOW_BOOT_EFI + bool "EFI" + help + Create a boot partition from a directory containing an EFI + boot application, e.g. GRUB. + +config IMAGE_ITB_QCOW_BOOT_BIN + bool "Binary" + help + Create a boot partition from a raw image containing the boot + application, e.g. U-Boot. + +endchoice + +config IMAGE_ITB_QCOW_BOOT_DATA + string "Bootloader data" + depends on IMAGE_ITB_QCOW + depends on IMAGE_ITB_QCOW_BOOT_EFI || IMAGE_ITB_QCOW_BOOT_BIN + default "${BINARIES_DIR}/efi-part/EFI" if BR2_x86_64 + help + Path to the directory or file holding the bootloader data. + +config IMAGE_ITB_QCOW_BOOT_OFFSET + hex "Bootloader offset" + depends on IMAGE_ITB_QCOW + depends on IMAGE_ITB_QCOW_BOOT_EFI || IMAGE_ITB_QCOW_BOOT_BIN + default 0x8000 + help + Offset at which the bootloader partition is placed. Remember + to make sure that the GPT still fits at the start of the + image. + +config IMAGE_ITB_QCOW_RELEASE_URL + string "Infix URL" + depends on IMAGE_ITB_QCOW + depends on !BR2_TARGET_ROOTFS_SQUASHFS + default "https://github.com/kernelkit/infix/releases/download/latest/infix-${BR2_ARCH}.tar.gz" + help + In situations where Infix itself is not being built, but a + disk image is, i.e. when building a bootloader: place this + Infix release in the primary and secondary partitions. diff --git a/board/common/mkdisk.sh b/board/common/image/image-itb-qcow/generate.sh similarity index 50% rename from board/common/mkdisk.sh rename to board/common/image/image-itb-qcow/generate.sh index dfb472b3..3969d554 100755 --- a/board/common/mkdisk.sh +++ b/board/common/image/image-itb-qcow/generate.sh @@ -1,8 +1,6 @@ #!/bin/sh set -e -. $BR2_EXTERNAL_INFIX_PATH/board/common/rootfs/etc/partition-uuid - K=10 M=20 G=30 @@ -47,43 +45,32 @@ dimension() exit 1 fi - # Size var to fit whatever is left over. Also reserve another 32K - # at the end to make room for the backup GPT. - varsize=$(($total - $auxsize - 2 * $imgsize - $cfgsize)) - if [ "$bootoffs" ]; then - varsize=$(($varsize - $bootsize)) - fi - varsize=$(($varsize - (32 << K))) + # Place aux right after the GPT... + auxoffs=$((32 << K)) if [ "$bootoffs" ]; then - # Align the end of the boot partition to an even MiB. E.g. if - # boot was dimensioned to 4M, and bootoffs is 32K, then the - # final bootsize becomes 4M - 32K, meaning aux will start on - # exactly 4M. - auxoffs=$bootsize - bootsize=$(($bootsize - $bootoffs)) - else - # No bootloader, place aux after GPT, resize it to end on an - # even MiB (as is done for boot above). - auxoffs=$((32 << K)) - auxsize=$(($auxsize - $auxoffs)) - fi -} + if [ $((bootoffs)) -lt $((32 << K)) ]; then + echo "Boot partition collides with GPT" + exit 1 + fi -probeboot() -{ - # If we have built an EFI app, typically grub, make sure to - # include it. - if [ -d $BINARIES_DIR/efi-part/EFI ]; then - bootoffs=$((32 << K)) + # ...unless we have a boot partition, in which case we place + # it after that. + auxoffs=$((auxoffs + bootsize)) fi + + # Finally, size var to fit whatever is left over by subtracting + # all other images, plus another 32K at the end for the backup + # GPT. + varsize=$((total - auxoffs - auxsize - 2 * imgsize - cfgsize - (32 << K))) } genboot() { if [ -d "$bootdata" ]; then bootimg=$(cat <$root/genimage.cfg - -mkdir -p $root/aux -cp -f $BINARIES_DIR/rootfs.itbh $root/aux/primary.itbh -cp -f $BINARIES_DIR/rootfs.itbh $root/aux/secondary.itbh -cp -f $BINARIES_DIR/rauc.status $root/aux/rauc.status - -case "$arch" in - aarch64) - mkenvimage -s 0x4000 -o "$root/aux/uboot.env" \ - "$BR2_EXTERNAL_INFIX_PATH/board/common/uboot/aux-env.txt" - ;; - x86_64) - mkdir -p "$root/aux/grub" - cp -f "$BR2_EXTERNAL_INFIX_PATH/board/$arch/grub.cfg" \ - "$BR2_EXTERNAL_INFIX_PATH/board/$arch/grubenv" \ - "$root/aux/grub/" - ;; - *) - ;; -esac - -rm -rf "$tmp" + < $PKGDIR/genimage.cfg.in >$WORKDIR/genimage.cfg genimage \ - --rootpath "$root" \ - --tmppath "$tmp" \ - --inputpath "$BINARIES_DIR" \ - --config "$root/genimage.cfg" - -qemu-img convert -c -O qcow2 "$tmpimage" "$BINARIES_DIR/$diskimg" -rm "$tmpimage" + --tmppath "${WORKDIR}"/tmp \ + --rootpath "${WORKDIR}"/root \ + --inputpath "$BINARIES_DIR" \ + --outputpath "$BINARIES_DIR" \ + --config "${WORKDIR}"/genimage.cfg diff --git a/board/common/genimage.cfg.in b/board/common/image/image-itb-qcow/genimage.cfg.in similarity index 86% rename from board/common/genimage.cfg.in rename to board/common/image/image-itb-qcow/genimage.cfg.in index 20cba95c..864b09ff 100644 --- a/board/common/genimage.cfg.in +++ b/board/common/image/image-itb-qcow/genimage.cfg.in @@ -1,16 +1,5 @@ @BOOTIMG@ -image aux.ext4 { - mountpoint = "/aux" - temporary = true - size = @AUXSIZE@ - - ext4 { - label = "aux" - use-mke2fs = true - } -} - image cfg.ext4 { empty = true temporary = true @@ -33,7 +22,8 @@ image var.ext4 { } } -image @DISKIMG@ { +image disk.img { + temporary = true size = @TOTALSIZE@ hdimage { partition-table-type = "gpt" @@ -68,5 +58,15 @@ image @DISKIMG@ { } } +image @QCOWIMG@ { + qemu { + format = "qcow2" + } + + partition disk { + image = "disk.img" + } +} + # Silence genimage warnings config {} diff --git a/board/common/image/image-itb-qcow/image-itb-qcow.mk b/board/common/image/image-itb-qcow/image-itb-qcow.mk new file mode 100644 index 00000000..98e5d05e --- /dev/null +++ b/board/common/image/image-itb-qcow/image-itb-qcow.mk @@ -0,0 +1,10 @@ +################################################################################ +# +# image-itb-qcow +# +################################################################################ + +IMAGE_ITB_QCOW_DEPENDENCIES := host-genimage image-itb-rootfs image-itb-aux +IMAGE_ITB_QCOW_CONFIG_VARS := BOOT_DATA BOOT_OFFSET SIZE + +$(eval $(ix-image)) diff --git a/board/common/image/ix-image.mk b/board/common/image/ix-image.mk index d20894cd..2da7cc2f 100644 --- a/board/common/image/ix-image.mk +++ b/board/common/image/ix-image.mk @@ -10,6 +10,7 @@ $(1): $$($(2)_DEPENDENCIES) PKGDIR=$$($(2)_DIR) \ WORKDIR=$$(BUILD_DIR)/$(1) \ BINARIES_DIR=$$(BINARIES_DIR) \ + BR2_EXTERNAL_INFIX_PATH=$$(BR2_EXTERNAL_INFIX_PATH) \ ARTIFACT=$$(INFIX_ARTIFACT) \ COMPATIBLE=$$(INFIX_COMPATIBLE) \ VERSION=$$(INFIX_VERSION) \ diff --git a/board/common/mkrauc-status.sh b/board/common/mkrauc-status.sh deleted file mode 100755 index 0560e79c..00000000 --- a/board/common/mkrauc-status.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -set -e - -# Bootstrap a RAUC status file showing the newly created image -# installed to both the primary and secondary slots. This then bundled -# in the aux partition in mkdisk.sh, so that RAUC (on the target) can -# always report the installed versions. -rauc info --no-verify --output-format=shell $1 >/tmp/rauc-$$.info -. /tmp/rauc-$$.info -rm /tmp/rauc-$$.info -tstamp=$(date -u +%FT%TZ) -cat <"$BINARIES_DIR/rauc.status" - $common/mkdisk.sh -a $BR2_ARCH -n $diskimg -s $DISK_IMAGE_SIZE $bootcfg -fi +diskimg="${NAME}$(ver).qcow2" load_cfg GNS3_APPLIANCE if [ "$GNS3_APPLIANCE" = "y" ]; then diff --git a/test/env b/test/env index b89e21ea..56fca5ef 100755 --- a/test/env +++ b/test/env @@ -74,7 +74,7 @@ get_base_img() { local files="$1" local base_img_file - base_img_file=$(echo "$files" | tr ' ' '\n' | grep -- '-disk.qcow2$') + base_img_file=$(echo "$files" | tr ' ' '\n' | grep -- '.qcow2$') echo "$envdir/qeneth/$(basename "$base_img_file")" } @@ -95,16 +95,16 @@ start_topology() ln -sf "$file" "$envdir/qeneth/$filename" done - base_img=$(get_base_img "$files") - test_img_name="${base_img%-disk.qcow2}-disk-test" - base_img_name="${base_img%-disk.qcow2}-disk" - test_img_raw="${test_img_name}.img" - base_img_raw="${base_img_name}.img" - test_img_qcow2="${test_img_name}.qcow2" + base_img_qcow2=$(get_base_img "$files") + base_img_disk="${base_img_qcow2%.qcow2}.disk" + + test_img_disk="${base_img_qcow2%.qcow2}-test.disk" + test_img_qcow2="${test_img_disk%.disk}.qcow2" + + qemu-img convert -f qcow2 -O raw "$base_img_qcow2" "$base_img_disk" + $testdir/inject-test-mode -b "$base_img_disk" -o "$test_img_disk" + qemu-img convert -f raw -O qcow2 "$test_img_disk" "$test_img_qcow2" - qemu-img convert -f qcow2 -O raw "$base_img" "$base_img_raw" - $testdir/inject-test-mode -b "$base_img_raw" -o "$test_img_raw" - qemu-img convert -f raw -O qcow2 "$test_img_raw" "$test_img_qcow2" img_name=$(basename $test_img_qcow2) sed -i "s/qn_image=\".*\"/qn_image=\"$img_name\"/" "$envdir/qeneth/topology.dot.in" diff --git a/test/test.mk b/test/test.mk index 85f3f4bb..ba4b7293 100644 --- a/test/test.mk +++ b/test/test.mk @@ -17,11 +17,11 @@ mode-qeneth := -q $(test-dir)/virt/quad mode-host := -t $(or $(TOPOLOGY),/etc/infamy.dot) mode-run := -t $(BINARIES_DIR)/qemu.dot mode := $(mode-$(TEST_MODE)) -INFIX_IMAGE_ID := $(call qstrip,$(INFIX_IMAGE_ID)) -binaries-$(ARCH) := $(addprefix $(INFIX_IMAGE_ID),.img -disk.qcow2) -pkg-$(ARCH) := -p $(O)/images/$(addprefix $(INFIX_IMAGE_ID),.pkg) + +pkg-$(ARCH) := -p $(O)/images/$(INFIX_ARTIFACT).pkg +binaries-$(ARCH) := $(INFIX_ARTIFACT).qcow2 binaries-x86_64 += OVMF.fd -binaries := $(foreach bin,$(binaries-$(ARCH)),-f $(BINARIES_DIR)/$(bin)) +binaries := $(foreach bin,$(binaries-$(ARCH)),-f $(BINARIES_DIR)/$(bin)) # Common transport override for minimal defconfigs ifneq ($(BR2_PACKAGE_ROUSETTE),y) diff --git a/test/virt/quad/topology.dot.in b/test/virt/quad/topology.dot.in index 549456d4..1242b0ea 100644 --- a/test/virt/quad/topology.dot.in +++ b/test/virt/quad/topology.dot.in @@ -9,7 +9,7 @@ graph "quad" { edge [color="cornflowerblue", penwidth="2"]; qn_template="infix-bios-x86_64"; - qn_image="infix-x86_64-disk-test.qcow2" + qn_image="infix-x86_64-test.qcow2" qn_oui="00:a0:85"; qn_append="quiet";