init: refuse to format an overlay that runs off the end of the flash - #2409
Draft
openipc-ai wants to merge 1 commit into
Draft
init: refuse to format an overlay that runs off the end of the flash#2409openipc-ai wants to merge 1 commit into
openipc-ai wants to merge 1 commit into
Conversation
SigmaStar sizes any NOR chip missing from its JEDEC table at 16MB -- drivers/sstar/flash_isp's FLASH_IC_UNKNOWN row, which declares 0x1000000 alongside a sector count that says 4MB, so it was never a real geometry. mtd.size is taken straight from it, and our bootargs end in "-(rootfs_data)", so on a real 8MB camera the overlay partition becomes 8896KB. jffs2 then mounts an aliased mirror of the squashfs rather than an overlay, and the format that follows erases past 0x800000 -- which a 3-byte-addressed chip wraps back to zero, taking the bootloader with it. The camera boots once and never again. #1998's log is that arithmetic exactly: c->nr_blocks 139 is 16384k less the 7488k the other four partitions hold, where a correctly sized chip would have given 11 blocks. Prove the wrap before refusing, so the guard can only ever stop an erase on positive evidence: compare the first sector of the flash with the sector the partition presents at each plausible real end of the chip. A blank first sector, an unreadable mtd0 or a missing rootfs_data all fall through and format as before -- the cost of a false positive is a camera that silently forgets its settings, and that must not be paid on a guess. The driver is the real fix and belongs in OpenIPC/linux. This is the half that stops the damage on the images already in the field, and it is not SigmaStar-specific: any driver that over-reports a chip lands here.
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.
Problem
A SigmaStar SSC325 camera with an 8 MB NOR chip boots OpenIPC once, comes up with no
network, and is dead after the next power cycle — the whole chip reads back
0xFF.Reported in #1998 (SSC325, 8 MB NOR) and reproduced by a second user on 2026-09-13.
The camera erases its own flash.
drivers/sstar/flash_ispsizes any chip missing fromits JEDEC table at 16 MB — the
FLASH_IC_UNKNOWNrow declares0x1000000next to asector count that says 4 MB, so it was never a real geometry — and
mtd.sizeis takenstraight from it. Our SigmaStar bootargs end in
-(rootfs_data), so the overlaypartition becomes whatever is left of the believed chip:
#1998's log says
jffs2: empty_blocks 40, bad_blocks 0, c->nr_blocks 139. jffs2 isthen scanning an aliased mirror of the squashfs — that is what the "Old JFFS2 bitmask"
noise in that log is — so it cannot mount,
/initfalls back toflash_eraseall, andthe erase walks past
0x800000. A 3-byte-addressed NOR wraps every address at or abovethe real end back to zero, so the run takes the bootloader, the environment, the kernel
and the rootfs with it, while the system is still running out of page cache.
This PR is the half that stops the damage on images already in the field. The driver is
the real fix and belongs in OpenIPC/linux; that
change is waiting on the reporter's hardware and is tracked in #1998.
The guard is not SigmaStar-specific. Any driver that over-reports a chip lands here.
Hardware tested on
Not run on a camera — opened as a draft for that reason. Nobody here has an SSC325,
and the only SigmaStar board in the lab was down. The reported failure also cannot be
reproduced without a flash chip that is absent from the vendor's table, which is not
something that can be sourced on purpose.
What can be evidenced without a board is evidenced below: the guard is driven against
synthetic chips built byte-for-byte the way the driver would present them, including the
wrap, in both the tree form and the comment-stripped form that actually ships.
Evidence
bash .github/scripts/test_overlay_format_guard.sh— the new suite, againstgeneral/overlay/init:The same suite against the form the camera executes
(
awk -f general/scripts/strip-shell-comments.awk general/overlay/init):Cases 2 and 3 are the ones that matter for a false positive. Case 3 is the geometry
openipc.org hands out when a visitor picks the 8 MB layout on a 16 MB chip: the same
partition table as the brick, on a chip that really is 16 MB. It must format, and does.
The rest of the shell gates, unchanged:
general/overlay/initwidens the matrix to every board, as it should:Scope
general/package/all-patches/linux/(those go to OpenIPC/linux)general/overlay/or in a sharedload_<vendor>script hardcodes a value specific to my boardLD_PRELOAD, and no binaries that cannot be rebuilt from sourceNote for review
general/overlay/usr/sbin/sysupgrade'sdo_wipe_overlay()erases the same partition andhas the same exposure. It is deliberately left alone here so this change stays one idea;
say the word if you would rather they move together.