[PATCH 0/1] GatoNetworks GDSP: align SD card image; RFC on fitrw alignment
Enrico Mioso
mrkiko.rs at gmail.com
Sat Nov 21 12:58:36 PST 2026
This series has two parts: a small patch for the GatoNetworks GDSP SD
card image (fix A), and a proposal I would like to discuss before
writing any code, because it affects every device that uses fitblk on
eMMC or SD (fix B).
Background
==========
SD cards (and, to a lesser degree, eMMC) handle flash in pages of 16 KiB
or more, and erase in allocation units (AUs), typically 4 MiB on SDHC
cards and up to 64 MiB on SDXC. A write that does not cover whole,
aligned pages forces the card's FTL to read, modify and rewrite them,
and writes that wander across AU boundaries cause extra garbage
collection. Both cost write performance and, more importantly here,
endurance. f2fs is a good fit for such media because it writes
sequentially in 2 MiB segments, but only if those segments are aligned
on the medium.
Currently the GDSP SD card image has two misalignments:
1. The "FIT" partition starts at 17 KiB (sector 34), right after the
primary GPT. That is not even 4 KiB aligned.
2. fitblk maps the read-write overlay (/dev/fitrw) right after the end
of the last FIT sub-image, aligned only to 4 KiB relative to the
partition. Its absolute position on the medium therefore depends on
the image size. fstools formats it as f2fs when it is larger than
100 MiB (the mediatek default partition size is 448 MiB), or as ext4
otherwise. mkfs.f2fs aligns its segments relative to the start of
/dev/fitrw, because fitblk does not report where that device really
starts.
Fix A (this patch): start the SD card FIT partition at 4 MiB
=============================================================
The GPT is padded up to 4 MiB and the partition starts there. simplefit
now prepends the partition table instead of appending the image after
it, so check-size still applies to the FIT image itself.
Pros:
- Trivial and local: simplefit is only used by the GDSP, and nothing
depends on the partition offset (U-Boot and Linux look the partition
up by name, sysupgrade writes to the partition device).
- The overlay becomes 4 KiB aligned on the card, so 4 KiB filesystem
blocks no longer straddle flash pages.
- No compatibility issues: cards written with older images keep their
layout and keep working.
Cons:
- Does not fix misalignment 2: f2fs segments still cross AU boundaries,
because the overlay offset still follows the image size.
- Fixed 4 MiB alignment: cards with larger AUs (some SDXC cards) would
need 8 or 16 MiB. A larger value would cost more card space; 4 MiB
seemed a reasonable default, but I am open to suggestions.
- Only newly written cards benefit.
- About 4 MiB of card space is unused.
Fix B (RFC, no code yet): align the overlay itself
==================================================
This needs a change in fitblk, which is generic code, so I would like
to agree on the approach first. Options I can see:
B1. fitblk rounds the start of /dev/fitrw up to a fixed boundary (for
example 4 MiB), or to the parent queue's discard granularity, which
the MMC core sets from the card's preferred erase size.
Pros:
- Works for every filesystem and every mkfs, with no userspace
change.
- Simple to implement in the driver.
Cons:
- Moves /dev/fitrw on every fitblk device after a kernel update. The
sysupgrade backup is written by the old system's scripts right
after the FIT image (emmc_copy_config), and fstools looks for it
at the start of the overlay. Upgrading from an older image would
therefore drop the saved configuration once, unless fit.sh/emmc.sh
and fitblk are changed in lock-step and the transition is
handled somehow.
- Wastes up to one alignment unit per device.
- The boundary is either a fixed guess or taken from a queue limit
that is not always meaningful (for example, cards without erase
support).
B2. fitblk reports where /dev/fitrw really starts on the medium, so
that mkfs aligns the filesystem layout itself, without moving the
device. Two ways to do it:
a) Implement the getgeo block device operation and report the
absolute start sector (partition start + sub-image offset) as
geo.start. mkfs.f2fs reads this with HDIO_GETGEO and uses it to
align segment 0 and the main area to the zone size (2 MiB by
default), which keeps every segment inside a 4 MiB AU.
b) Set the queue's alignment_offset and io_opt limits, the standard
block topology interface that libblkid and mkfs.ext4 use.
Pros:
- /dev/fitrw does not move, so there is no compatibility issue:
existing overlays and the sysupgrade config backup keep working.
Only newly formatted overlays get the better layout, and the
overlay is reformatted on every sysupgrade anyway.
- No space is wasted.
- Formatting already adapts to the actual image size every time.
Cons:
- a) borrows a legacy (CHS) ioctl for this, although HDIO_GETGEO's
"start" field means exactly "where this device starts on the
disk", which is what we would report.
- a) does not work with the f2fs-tools currently in OpenWrt.
Version 1.16.0 guards the HDIO_GETGEO call with "#ifdef
HDIO_GETGIO", a typo, so start_sector is always 0 and mkfs.f2fs
never aligns to the real device offset, not even on regular
partitions. Upstream fixed this in commit 44ba832
("f2fs-tools: fix to use HDIO_GETGEO instead of HDIO_GETGIO"),
which is part of 1.17.0. We would need to update f2fs-tools or
backport the fix. That update would be worthwhile on its own.
- b) helps ext4 (small overlays) but not mkfs.f2fs, which does not
use alignment_offset; covering both would mean doing a) and b).
B3. Pad the rootfs sub-image at build time, so that the FIT ends on an
aligned boundary.
Pros:
- No kernel or userspace change.
Cons:
- The same sysupgrade image is often used for both raw flash and
block devices (the GDSP uses it on SPI-NOR too), so the padding
would waste up to one alignment unit on NOR/NAND as well.
- Needs changes in the generic FIT image generation, and is fragile.
My current preference is B2a together with an f2fs-tools update, maybe
plus B2b. It improves endurance on every SD and eMMC device that uses
fitblk, without moving anything on existing installations.
Questions for the list:
- Is reporting the absolute start sector through getgeo acceptable for
fitblk, or would you rather see B1 or another approach?
- Should the alignment target be fixed (4 MiB) or derived from the
parent device's queue limits?
- Is anyone already working on updating f2fs-tools to 1.17.0?
Neither fix A nor any part of fix B has been tested on GDSP hardware yet.
For fix A, I checked the generated layout with ptgen and a stand-in FIT
image: the FIT partition starts at sector 8192 (4 MiB), and the image
data starts exactly there.
Enrico Mioso (1):
mediatek: filogic: align GatoNetworks GDSP SD card FIT partition
target/linux/mediatek/image/filogic.mk | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
--
2.56.1
More information about the openwrt-devel
mailing list