Repository navigation
mtd: apple-sftl: Boot from LwVM partitions iOS scattered over the flash - #89
Merged
Merged
Conversation
block/partitions/lwvm.c adds each LwVM partition whose chunks are stored in order and back to back as an ordinary partition, and skips the others. iOS stores partitions in 16 MiB chunks out of order, so on many 32-bit devices Data, and often the partition Linux is installed in, are skipped. Add a decoder that reads the same header with the same checks (signature, CRC, media size, 1..8 partitions, no entry in the header chunk or past the disk) and keeps, for every partition, the map from partition chunk to disk chunk, and a lookup from a partition byte offset to a disk byte offset through it. A partition with a hole, a doubled or an out-of-range chunk is reported instead of mapped; "pieced" marks a valid partition the partition parser skips. KUnit (apple-sftl-lwvm) covers the chunk size, contiguous, interleaved and partial-last-chunk layouts, broken partitions and rejected tables with synthetic headers. Assisted-by: LLM Signed-off-by: Berkay Kösebay <brkosebay@users.noreply.github.com> [Henrik: split the decoder and its tests out of "mtd: apple-sftl: Serve scattered LwVM partitions as read-only disks" (#60), without the iPhone 5 profile] Signed-off-by: Henrik Klee <henrik@goat-code.com>
…w disk block/partitions/lwvm.c adds an LwVM partition to applesftlN only when its chunks are stored in order and back to back. iOS scatters partitions over the disk, so on many 32-bit devices the partition Linux is installed in gets no block device and no PARTUUID, and the system cannot boot from it with root=PARTUUID=. The 16 GB iPad mini 1 is one: its Linux partition lies in three runs of chunks. After the main disk is added, read its LwVM header (and its copy in the last page of the first chunk if the CRC fails, as the parser does) and, when it has scattered partitions, add a second disk of the same size, applesftlNlwvm. Its first page is a copy of the header that lists only the scattered partitions, each stored in order from chunk 1, with a new CRC; its other chunks are read through the chunk map from the main disk, or as zeroes. The partition parser then adds them as applesftlNlwvmP, with their LwVM number, PARTUUID and name, so the initrd and the kernel find them by root=PARTUUID= as they find any other partition. Entries the main disk has already are cleared in the view, so no partition is added twice. A partition whose map has a hole, a doubled or an out-of-range chunk is reported and left out. The view is read-only on every profile and medium and has no write path: writes end with -EROFS and other operations with -EOPNOTSUPP before the FTL is reached. Its reads take the parent's lock and buffer. On a read-write medium, a write through applesftlN into one of its chunks leaves the view's page cache stale, as a write to a whole disk does for its partitions. A disk without scattered partitions gets no view and no new message. This follows Berkay Kösebay's read-only disk per scattered partition for the iPhone 5 (#60): the same decoder and per-page lookup, but as partitions of one disk, so that they carry their PARTUUID, and on every profile. KUnit (apple-sftl-lwvm) builds a view, decodes its header with the parser's checks and looks up its pages. Assisted-by: LLM Signed-off-by: Henrik Klee <henrik@goat-code.com>
On a 16 GB iPad mini 1 (P105, iOS 9.3.5) System is stored in six runs of 16 MiB chunks, Data in order, and the Linux partition in three runs, the last chunk partial. Until now it booted only through a dm-linear table typed by hand: 0 19529728 @ 8978432, 19529728 163840 @ 30048256, 19693568 532840 @ 30474240 (sectors). Add that layout as a KUnit case, with the chunk map of the header captured from the device (OrchardLinux/orchard#438). The decoder must map the Linux partition to exactly those sectors, and the view must list System and Linux in order under their numbers, keep Linux's GUID and read the same sectors. Assisted-by: LLM Signed-off-by: Henrik Klee <henrik@goat-code.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What users notice
A 32-bit iPhone or iPad whose Linux partition iOS scattered over its flash now boots it like any other board: the kernel registers the partition, with its PARTUUID, and orchard's initrd finds the root by
root=PARTUUID=as usual. No hand-typeddm-mod.createtable, no special startup path. The 16 GB iPad mini 1 needs this: its Linux partition lies in three separate runs of flash chunks.This works on every 32-bit board and layout (P105 16 GB and 64 GB, N42 once its NAND support lands, any other). A board whose partitions are all stored in order sees no change and no new message.
How
block/partitions/lwvm.c) can only add a partition that is one contiguous range of the disk, so it skips scattered ones.applesftlNhas scattered LwVM partitions, the SFTL driver now adds a second disk of the same size,applesftlNlwvm. Its first page is a copy of the LwVM header that lists only the scattered partitions, each in order, and every other page is read through the chunk map from the main disk. The normal LwVM reader then adds them asapplesftlNlwvmP, with the same partition number, PARTUUID and name. Partitions already on the main disk are left out of the copy, so nothing shows up twice.Commits
mtd: apple-sftl: Decode LwVM chunk maps: Berkay's (@brkosebay) decoder and KUnit tests, split out of his mtd: apple: Read the iPhone 5's NAND #60 unchanged, with his authorship and sign-off.mtd: apple-sftl: Add scattered LwVM partitions as partitions of a view disk: the view disk, on every profile.mtd: apple-sftl: Test the 16 GB iPad mini 1's scattered LwVM layout: KUnit case built from the header captured on the device (initrd: boot a read-only root on a scattered LwVM partition (16 GB iPad mini 1) orchard#438,tests/fixtures/p105-scattered-lwvm.bin; the chunk map in the test matches it entry for entry). It checks that the Linux partition maps to exactly the sectors of the dm-linear table that booted it (0 19529728 @ 8978432,19529728 163840 @ 30048256,19693568 532840 @ 30474240), and that the view lists it in order with its GUID.Relation to other work
root=PARTUUID=could not find it; this series keeps his decoder and per-page lookup but puts the partitions on one view disk, on every profile. mtd: apple: Read the iPhone 5's NAND #60 can drop its block-frontend part ofServe scattered LwVM partitions as read-only disksonce this lands.apple-sftl-core.candapple-sftl-test.c), so the two apply cleanly in either order; checked with a merge of both heads. The 16 GB iPad needs both to boot reliably.Testing
checkpatch --strict: clean apart from theAssisted-bytag and one blank-line note in Berkay's unchanged code.root=PARTUUID=1746a46a-ffc1-4a28-844f-0b168b79185f ro, which should showapplesftl0lwvm: 2 scattered LwVM partitions, read-onlyand mountapplesftl0lwvm3.Written with LLM assistance (
Assisted-by: LLM).