]> git.plutz.net Git - blast/commitdiff
improved receipe order, simplified receipes, simplified partitioning and fstab
authorPaul Hänsch <paul@plutz.net>
Sun, 12 Apr 2026 14:01:50 +0000 (16:01 +0200)
committerPaul Hänsch <paul@plutz.net>
Sun, 12 Apr 2026 14:01:50 +0000 (16:01 +0200)
targets/raspberrypi.mk

index 8037b73f9e02b4f46f16e1dab7728c3b2ab70c29..346c975429247b2046549d317b2c4b53cefa4765 100644 (file)
@@ -1,15 +1,29 @@
-# Partition Table (2M) + Boot Partition (126M)+ Root Partition + Slack Space (1M) = 2048M
+ARCH := arm64
+fstype := ext4
+
+# Partition Table (2M) + Boot Partition Root Partition + Slack Space (1M)
 BOOT_MB := 254
-ROOT_MB := 1791
+ifdef imagesize
+  ROOT_MB := $(shell printf '%i\n' "$$(( ${imagesize} - ${BOOT_MB} - 3 ))")
+else
+  ROOT_MB := 1791
+endif
 
-fstype := ext4
+define PARTLAYOUT :=
+label: dos
+: start=2MiB, size=${BOOT_MB}MiB, type=c
+: size=${ROOT_MB}MiB, type=83
+endef
 
-ARCH := arm64
+define _fstab :=
+/dev/mmcblk0p2 /               ${fstype}       auto,nofail,rw  0 0
+/dev/mmcblk0p1 /boot/firmware  vfat    auto,nofail,ro  0 0
+endef
 
-VOLUME := ${raspi}
-PBOOT := rpi_boot.img
-PROOT := rpi_root.img
-CFGROOT := img_mount/
+VOLUME = ${raspi}
+PBOOT = rpi_boot.img.temp
+PROOT = rpi_root.img.temp
+CFGROOT := img_mount
 
 define SOURCES := 
 deb    http://deb.debian.org/debian    ${release}      main    non-free-firmware
@@ -21,8 +35,8 @@ PACKAGES += firmware-brcm80211 bluez-firmware initramfs-tools e2fsprogs raspi-fi
 .PHONY: _raspberry_clean _qemu
 .PHONY: _partition_raspi _sparse _partcopy
 .PHONY: _format _format_root _format_boot
-.PHONY: _bootloader_raspi _raspberry_fstab
-.PHONY: _mount _mount_root _mount_boot
+.PHONY: _bootloader_raspi
+.PHONY: _img_mount _mount_root _mount_boot
 .PHONY: _umount _umount_root _umount_boot
 
 _qemu: ${SYSROOT}/usr/bin/qemu-arm64-static
@@ -30,18 +44,16 @@ _sparse: ${PBOOT} ${PROOT}
 _format: _sparse
 _bootstrap: _qemu
 _partition_raspi: _sparse
-_partcopy: _partition_raspi _format
-_img_mount: _partcopy
+_partcopy: _format
+_img_mount: _partcopy _partition_raspi
 _copy: _img_mount
-_bootloader_raspi: _img_mount
-_raspberry_fstab: _img_mount
-_umount: _copy _config _bootloader_raspi _raspberry_fstab
+_umount: _config _bootloader_raspi
 _target: _umount
 clean: _raspberry_clean
 
-export VOLUME PBOOT SQUASH
+export VOLUME PBOOT PROOT SQUASH PARTLAYOUT
 
-img_mount/:
+img_mount:
        mkdir -p -m 755 "$@"
        chmod 755 "$@"
 
@@ -51,93 +63,67 @@ ${SYSROOT}/usr/bin/qemu-arm64-static: /usr/bin/qemu-arm64-static ${SYSROOT}
        cp -p "$<" "$@"
 
 ${VOLUME}: .FORCE
-       ! printf '%s\n' "$${VOLUME}" |grep -q '^/dev/'  # abort if volume should be real device
        dd count=0 of="$${VOLUME}"  # truncate
-       dd bs=1M count=0 seek=$$((3 + ${BOOT_MB} + ${ROOT_MB})) of="$${VOLUME}"
+       dd bs=1M count=0 seek=$$((3 + ${BOOT_MB} + ${ROOT_MB})) \
+          of="$${VOLUME}"
        chmod g+w "$${VOLUME}"
 
 ${PBOOT}: .FORCE
-       ! printf '%s\n' "$${PBOOT}" |grep -q '^/dev/'  # abort if volume should be real device
        dd count=0 of="$${PBOOT}"  # truncate
        dd bs=1M count=0 seek=${BOOT_MB} of="$${PBOOT}"
 
 ${PROOT}: .FORCE
-       ! printf '%s\n' "$${PROOT}" |grep -q '^/dev/'  # abort if volume should be real device
        dd count=0 of="$${PROOT}"  # truncate
        dd bs=1M count=0 seek=${ROOT_MB} of="$${PROOT}"
 
-_partition_raspi: ${VOLUME}
-       printf 'label: dos\n\n: start=2MiB, size=%iMiB, type=c\n: start=%iMiB, size=%iMiB, type=83\n' \
-               ${BOOT_MB} "$$((${BOOT_MB} + 2))" ${ROOT_MB} | sfdisk "$${VOLUME}"
-
-_raspberry_fstab:
-       printf '%s\n' \
-              'LABEL=FSROOT / ${fstype} auto,nofail,rw 0 0' \
-              'LABEL=BOOT /boot/firmware vfat auto,nofail,ro 0 0' \
-              >"$${CFGROOT}/etc/fstab"
-
-
-ifeq "${fstype}" "ext4"
-  fsflag:=-F
-else
-  fsflag:=-f
-endif
+_partition_raspi: ${VOLUME} .FORCE
+       printf "$${PARTLAYOUT}" |sfdisk "$${VOLUME}"
 
 _format_root: ${PROOT}
-       -umount "$${CFGROOT}/boot/firmware" "$${CFGROOT}" "${PROOT}"
-       mkfs.${fstype} ${fsflag} -L FSROOT "$${PROOT}"
+       mkfs.${fstype} -L FSROOT "$${PROOT}"
 
 _format_boot: ${PBOOT}
-       -umount "$${CFGROOT}/boot/firmware" "${PBOOT}"
        mkfs.fat -F 32 -n BOOT "$${PBOOT}"
 
 _format: _format_root _format_boot
 
-${CFGROOT}/boot/firmware/cmdline.txt: ${CFGROOT} .FORCE
+${CFGROOT}/boot/firmware/cmdline.txt: _config .FORCE
        sed -Ei 's;root=/dev/loop[0-9]+;root=/dev/mmcblk0p2;' "$@"
 
-_bootloader_raspi: ${CFGROOT} ${CFGROOT}/boot/firmware/cmdline.txt
+_bootloader_raspi: ${CFGROOT}/boot/firmware/cmdline.txt
 
 _partcopy: ${VOLUME} ${PROOT} ${PBOOT}
-       dd conv=notrunc,sparse bs=1M seek=2 if="$${PBOOT}" of="$${VOLUME}"
-       dd conv=notrunc,sparse bs=1M seek=$$((2 + ${BOOT_MB})) if="$${PROOT}" of="$${VOLUME}"
-
-_mount_root: ${PROOT} ${CFGROOT}
-       mountpoint "$${CFGROOT}" \
-       || mount -t ${fstype} "$${PROOT}" "$${CFGROOT}"
-       chmod 755 "$${CFGROOT}"
-
-_mount_boot: ${PBOOT}
+       dd conv=notrunc,sparse bs=1M seek=2 \
+          if="$${PBOOT}" of="$${VOLUME}"
+       dd conv=notrunc,sparse bs=1M seek=$$((2 + ${BOOT_MB})) \
+          if="$${PROOT}" of="$${VOLUME}"
+       rm -- "$${PBOOT}" "$${PROOT}"
+
+_mount_boot: _mount_root
+       mountpoint "$${CFGROOT}" || false
        mkdir -p -m 755 "$${CFGROOT}/boot/firmware"
        mountpoint "$${CFGROOT}/boot/firmware" \
-       || mount -t vfat "$${PBOOT}" "$${CFGROOT}/boot/firmware"
-
-_mount: _mount_root _mount_boot
+       || mount -o loop,offset=2M,sizelimit=${BOOT_MB}M \
+                -t vfat "$${VOLUME}" "$${CFGROOT}/boot/firmware"
 
-_img_mount: ${CFGROOT}
+_mount_root: ${CFGROOT}
        mountpoint "$${CFGROOT}" \
        || mount -o loop,offset="$$((${BOOT_MB} + 2))"M,sizelimit=${ROOT_MB}M \
                 -t ${fstype} "$${VOLUME}" "$${CFGROOT}"
        chmod 755 "$${CFGROOT}"
-       mkdir -p -m 755 "$${CFGROOT}/boot/firmware"
-       mountpoint "$${CFGROOT}/boot/firmware" \
-       || mount -o loop,offset=2M,sizelimit=${BOOT_MB}M \
-                -t vfat "$${VOLUME}" "$${CFGROOT}/boot/firmware"
 
-_umount_boot: ${CFGROOT} _config
-       sync
+_img_mount: _mount_boot _mount_root
+
+_umount_boot: _config
        -umount "$${CFGROOT}/boot/firmware"
 
 _umount_root: _umount_boot _config
-       sync
-       umount "$${CFGROOT}" && rmdir "$${CFGROOT}"
+       -umount "$${CFGROOT}"
+       rmdir "$${CFGROOT}"
 
 _umount: _umount_boot _umount_root
 
-_raspberry_clean:
-       -umount img_mount/boot/firmware
-       -umount img_mount
-       -rmdir img_mount
-       -rm rpi_boot.img
-       -rm rpi_root.img
-       -[ -f "$${VOLUME}" ] && rm "$${VOLUME}"
+_raspberry_clean: _umount_boot _umount_root
+       -rm -- "$${PBOOT}"
+       -rm -- "$${PROOT}"
+       -rm -- "$${VOLUME}"