[PATCH 1/1] mediatek: filogic: align GatoNetworks GDSP SD card FIT partition
Enrico Mioso
mrkiko.rs at gmail.com
Sat Nov 21 12:58:37 PST 2026
The SD card image placed the "FIT" partition right after the primary
GPT, at 17 KiB (sector 34). That offset is not even 4 KiB aligned, so
everything inside the partition is shifted against the card's flash
pages and allocation units. This matters most for the read-write
overlay, which fitblk maps as /dev/fitrw right after the FIT image (with
4 KiB alignment relative to the partition): every 4 KiB filesystem block
written there straddles two flash pages, and the card has to
read-modify-write both. This costs write performance and endurance.
Start the partition at 4 MiB, the most common SD card allocation unit
size, and pad the GPT up to that offset. The overlay then starts at a
4 KiB aligned offset on the card. The cost is about 4 MiB of card space.
Rework simplefit to prepend the partition table to the image instead of
appending the image after it, and run check-size on the FIT image
before the GPT and padding are added. The size limit then keeps
applying to the FIT image itself, as before, and is not reduced by the
4 MiB padding.
Neither U-Boot nor Linux depends on the partition offset: both find the
partition by its "FIT" name, and sysupgrade writes to the partition
device. Cards written with older images keep their layout and keep
working; only newly written cards get the new one.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
Signed-off-by: Enrico Mioso <mrkiko.rs at gmail.com>
---
target/linux/mediatek/image/filogic.mk | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/target/linux/mediatek/image/filogic.mk b/target/linux/mediatek/image/filogic.mk
index 763250de0d..f221166598 100644
--- a/target/linux/mediatek/image/filogic.mk
+++ b/target/linux/mediatek/image/filogic.mk
@@ -49,12 +49,17 @@ define Build/mt7988-bl31-uboot
cat $(STAGING_DIR_IMAGE)/mt7988_$1-u-boot.fip >> $@
endef
+# Prepend a GPT with a single "FIT" partition holding the current image.
+# The partition starts at 4 MiB to match the allocation unit size of
+# most SD cards, so that writes to the overlay do not straddle flash
+# pages and erase blocks.
define Build/simplefit
- cp $@ $@.tmp 2>/dev/null || true
+ rm -f $@.tmp
ptgen -g -o $@.tmp -a 1 -l 1024 \
- -t 0x2e -N FIT -p $(CONFIG_TARGET_ROOTFS_PARTSIZE)M at 17k
- cat $@.tmp >> $@
- rm $@.tmp
+ -t 0x2e -N FIT -p $(CONFIG_TARGET_ROOTFS_PARTSIZE)M at 4M
+ $(call Image/pad-to,$@.tmp,4M)
+ cat $@ >> $@.tmp
+ mv $@.tmp $@
endef
define Build/mt798x-gpt
@@ -1963,8 +1968,8 @@ define Device/gatonetworks_gdsp
ARTIFACTS := preloader.bin bl31-uboot.fip sdcard.img.gz
ARTIFACT/preloader.bin := mt7981-bl2 nor-ddr3
ARTIFACT/bl31-uboot.fip := mt7981-bl31-uboot gatonetworks_gdsp
- ARTIFACT/sdcard.img.gz := simplefit |\
- append-image squashfs-sysupgrade.itb | check-size | libdeflate-gzip
+ ARTIFACT/sdcard.img.gz := append-image squashfs-sysupgrade.itb | \
+ check-size | simplefit | libdeflate-gzip
KERNEL := kernel-bin | libdeflate-gzip
KERNEL_INITRAMFS := kernel-bin | lzma | \
fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb with-initrd | pad-to 64k
--
2.56.1
More information about the openwrt-devel
mailing list