Repository navigation
mtd: apple-sftl: Add fenced 64 GB PPN 1.3 (j2a) write, erase, and reclaim support - #167
alistairreay wants to merge 5 commits into
Conversation
Generalize the strictly read-only S5L8945X H2FMI/PPN driver to match both measured iPad3,3 geometries from the PPN Device Info parameter page: - 32 GB PPN 1.6: 2 CAUs/CE (cau_bits 3), 2048 blocks (11 bits), 8 lanes, 4-byte row / 8-byte full read address (PPN >= 1.5) - 64 GB PPN 1.3: 4 CAUs/CE (cau_bits 2), 2064 blocks (12 bits), 16 lanes, 3-byte row / 7-byte full read address (PPN <= 1.4, verified in iBEC) Both capacities share 8 KiB data + 32 B OOB pages (8224 raw bytes, 256 MLC / 128 SLC pages per block) and remain strictly read-only with no write or erase opcodes. Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
Add the measured read-only SFTL geometry for 64 GB PPN 1.3 iPad 3 units (4 packages x 4 CAUs = 16 lanes, 2064 blocks/CAU, 256 MLC / 128 SLC pages, 8 KiB pages / lpp=2, 2057 superblocks, VFL in block 2061 of lanes 0-7, 15625000 exported + 16 hidden logical pages). Strictly read-only (writer = false). Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
…LwVM fence Generalize the Apple SFTL append, close, evacuation, accounting, and reclamation paths from hardcoded 16 KiB (lpp=4) pages to support 8 KiB (lpp=2) pages on the measured 64 GB PPN 1.3 iPad 3 (j2a) layout (2057 superblocks, 24 opaque context records, map_batch=16, map_min=32). Add default-off CONFIG_MTD_APPLE_SFTL_J2A_WRITE and an immutable LwVM write allowlist (apple_sftl_lwvm_build_fence / apple_sftl_lwvm_lba_writable) that restricts block writes strictly to validated contiguous Linux or XBOOTLDR LwVM partition chunks, keeping chunk 0, HFS+ iOS partitions, free chunks, and raw MTDs strictly read-only. Also fix a pre-existing bug in apple_sftl_rotate_vfl() where cold->lpp, cold->psize, and cold->osize were left zeroed, breaking sftl_test_rotate_mounted. Add PPN 1.3 64 GB geometry/split-join helpers to mtd-apple-h2fmi.h and extend all KUnit suites (apple-h2fmi, apple-sftl, apple-sftl-reclaim, apple-sftl-accounting, apple-sftl-lwvm). All 119 ARM KUnit tests pass in QEMU with CONFIG_MTD_APPLE_SFTL_J2A_WRITE=y, and 117 pass / 2 skip with it disabled (strictly read-only). Zero hardware writes are enabled in apple-h2fmi-ro.c. Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
Wire PPN 1.3 page program (0x8a + 3-byte row + 8224 B PIO + 0x17 + 0x79) and block erase (0x6a 0xd7 + 3-byte row + 0x79 + 0x77 0x7d + 0x77) into the SFTL PPN provider when CONFIG_MTD_APPLE_SFTL_J2A_WRITE is enabled and the probed packages match the 64 GB PPN 1.3 (16-lane, 2064-block) geometry. Raw MTD devices remain strictly read-only (MTD_NO_ERASE, no MTD_WRITEABLE). Block 0 and the top 32 bootstrap/VFL/factory blocks (2032..2063) are rejected with -EPERM. Every program verifies the target page reads back erased (0x49 + all 0xff) beforehand and compares all 8224 bytes on readback afterward; every erase checks CMD 79 mutation status (0x64 on PPN 1.3: BIT(6) ready, BIT(0)|BIT(4) clear), CMD 77 7D completion status (0x40), and verifies all 256 pages read back erased. Any failure latches a sticky failed flag refusing further mutations. Assisted-by: LLM Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
… for 64 GB j2a On 12H321 (iOS 8.4.1) 64 GB PPN 1.3 media, blank DIRTY_FREE (role 9) superblocks hold no live pages and can be wear-leveled, erased, and reused without touching iOS's native CLEAN_FREE pool. Add sftl_reuse_blank_dirty() gated on fenced_write + native_context + erase_block, with end-page blank checks, live-map verification, and full erased readback. Also add a CONFIG_MTD_APPLE_SFTL_J2A_WRITE-gated debugfs helper (apple_sftl_j2a/lwvm_install and status) that validates a shrunk-Data + contiguous-Linux-p3 LwVM table before writing backup (LBA 16383) then primary (LBA 0) with readback verification, fix a misleading journal-floor warning when the LwVM fence keeps a stock 2-partition disk read-only, and add KUnit coverage for blank dirty-free reclaim on sftl_64gb_8k. Assisted-by: LLM Signed-off-by: Alistair Reay <alistair.reay@gmail.com>
|
Thanks for all the work here, @alistairreay. The KUnit coverage and the 8 KiB-page ( It has the same open points we raised on #69, and it builds a second copy of #69's design in the same files (
What we'd like: you and @brkosebay agree on one shared writer design, along the four-part split from the #59 review (#59):
Alongside that: one flash-controller driver (H2FMI) with per-chip match data for A5, A5X and A6, not a driver per board. Once that shared base exists, the j2a-specific part should shrink to a layout table entry. Happy to review a design sketch before you two write more code. |
Builds on #155 (which remains read-only; this PR adds opt-in, LwVM-fenced write, erase, and blank
DIRTY_FREEsuperblock reclaim for 64 GB PPN 1.3 8 KiB /lpp=2iPad3,3(j2a) hardware).Summary
CONFIG_MTD_APPLE_SFTL_J2A_WRITE, defaultn): Keepssftl_64gb_8kstrictly read-only unless explicitly enabled. Raw MTD devices (j2a-lane*) always remainMTD_NO_ERASEwithoutMTD_WRITEABLE(-EROFS).lpp=2(8 KiB) SFTL writer + LwVM chunk fence: Generalizesapple-sftl-{core,block,account,reclaim}for 2 logical 4 KiB pages per physical 8 KiB page, and adds an immutable LwVM chunk allowlist (apple_sftl_lwvm_build_fence/apple_sftl_lwvm_lba_writable) so only contiguous Linux (0fc63daf-...) or XBOOTLDR (bc13c2ff-...) partitions are writable; chunk 0 (LwVM headers), iOSSystem, iOSData, and free chunks always return-EROFS. Also fixes a pre-existingapple_sftl_rotate_vfl()bug wherecold->{lpp,psize,osize}were left zeroed.program_pageanderase_block(drivers/misc/apple-h2fmi-ro.c): Implements 3-byte row0x8a/0x17/0x79program and0x6a 0xd7/0x79/0x77 0x7d/0x77erase (accepting PPN 1.3's0x64CMD79ready status withBIT(0)|BIT(4)clear, followed by0x40completion status). Protects block0and bootstrap/VFL/factory blocks2032..2063with-EPERM, verifies erased pre-readback and byte-for-byte post-readback on every program, verifies all 256 pages read back erased after every erase, and latches a stickyfailedflag on any error.DIRTY_FREEsuperblock reclaim (sftl_reuse_blank_dirty): Wear-levels, end-checks, verifies unmapped, and erases blankDIRTY_FREE(role 9) superblocks on12H321native media while leaving iOS's nativeCLEAN_FREEpool untouched.apple_sftl_j2a/lwvm_install): Validatesp1untouched,p2shrunk (>= 8 GiB) with retained chunks unchanged, and contiguousp3before writing backup (LBA16383) then primary (LBA0) with readback verification.Verification
CONFIG_MTD_APPLE_SFTL_J2A_WRITE=y: 120 / 120 passed (0failed,0skipped), including newsftl_64gb_8kwrite, BTOC close/reload, program-failure evacuation, blankDIRTY_FREEreclaim, LwVM fence, accounting, reclaim, and PPN 1.3 H2FMI tests.CONFIG_MTD_APPLE_SFTL_J2A_WRITE=n: 117 passed, 3 skipped, 0 failed.drivers/misc/apple-h2fmi-ro.o,drivers/mtd/apple-sftl-*.o, and fullzImagebuild with zero warnings for both=yand=n.iPad3,3(j2a, iOS 8.4.1 /12H321) hardware tests:-EROFS/ permission denial on/dev/applesftl0(LBA 0),/dev/applesftl0p1(System),/dev/applesftl0p2(Data), and/dev/mtd0.p3(4 GiBLinux) and a32 MiBext4filesystem +5 MiBtest files (4,788verified 8 KiB page programs + BTOC superblock close); rebooted cleanly into iOS 8.4.1 (System & Data mounted, SFTL checkpointed); rebooted back to Linux with bit-for-bit SHA-256 match.192 MiBext4image +16 MiBrandom file (208 MiBtotal in132.9 s,1.6 MB/ssustained), reclaiming 7 blankDIRTY_FREEsuperblocks (112verified PPN 1.3 block erases,26,894verified page programs,6closed0x401cBTOC footers, zero errors); rebooted cleanly into iOS 8.4.1 (SFTL checkpointed all 7 superblocks cleanly,/and/private/varintact); rebooted back to Linux with bit-for-bit SHA-256 match.