Skip to content

infinity6c: the split NOR layout, without device tree partitions - #266

Merged
widgetii merged 2 commits into
sigmastar-infinity6cfrom
infinity6c/split-nor-layout
Nov 19, 2026
Merged

widgetii merged 2 commits into
sigmastar-infinity6cfrom
infinity6c/split-nor-layout

Conversation

@widgetii

Copy link
Copy Markdown
Member

The split NOR layout for the 5.10.61 infinity6c kernel. It's the same code as infinity6 (#195) and the other 4.9 kernels, ported to 5.10's partition model and this family's NOR driver.

It's needed by OpenIPC/firmware#2910. The ssc377, ssc377d, ssc377de, ssc377qe, ssc378de and ssc378qe lite images outgrew their fixed slots ("size exceeded by 4KB"; locally: uImage 1992KB/1983KB, rootfs 5124KB/5120KB). That PR moves them to the split image, as #2814 did for infinity6 and infinity6b0, and its post-image-split.sh refuses a kernel without CONFIG_MTD_SPLIT_LAYOUT. So this has to land first.

Changes

  • drivers/mtd/split_layout.c (MTD_SPLIT_LAYOUT):
    • When the uImage at 0x50000 is followed by the root squashfs at the next 64 KiB boundary, it registers boot, env, firmware (to the end of the chip) and, inside firmware, kernel, rootfs and rootfs_data. The bootloader's mtdparts= is ignored then.
    • Anything else in the firmware area, including the fixed slots, or a read error, leaves the driver's partitions as before.
    • On 5.10, add_mtd_partitions() already removes what it added when one partition fails, so mtdpart.c needs none of the 4.9 port's bookkeeping. The rootfs is looked up on the master's own partition list.
  • sstar/flash/nor/mtd_serflash.c (SS_NOR_ONEBIN, what infinity6c builds): tries that first, then registers as before with the command line's partitions. A failed registration falls back to them.
  • init/do_mounts.c: sets root_dev_from_flash. The split rootfs becomes the root, and a root= naming an MTD device gives way to it.

Off unless a board config sets CONFIG_MTD_SPLIT_LAYOUT=y.

Tested

In qemu-bench, -M ssc377, with OpenIPC/firmware's ssc377_lite built against this branch. The NOR image was put together the way firmware's create_split does it: the published u-boot-ssc377-nor.bin at 0, firmware.bin at 320K, env erased.

First boot: the published U-Boot boots it from its default environment.

NOR_FLASH: split NOR layout, kernel 0x50000-0x250000, rootfs 0x250000-0x760000, rootfs_data from 0x760000
Creating 6 MTD partitions on "NOR_FLASH":
split NOR layout: root on mtdblock4
VFS: root=/dev/mtdblock3 ignored, the flash names its own root
VFS: Mounted root (squashfs filesystem) readonly on device 31:4.
...
ssc377-imx415 login:

U-Boot passes its fixed mtdparts with 8192k(rootfs) and root=/dev/mtdblock3, and the kernel overrides both. Afterwards the flash holds:

  • the jffs2 overlay in rootfs_data (106 nodes at 0x760000);
  • the first boot's sensor=imx415 in the env at 0x40000, so fw_setenv reached env.

Second boot: it boots the same way and keeps both. The overlay grew to 126 nodes, not reformatted.

Not run on hardware: there's no infinity6c board in the lab.

The split NOR layout for the 5.10.61 SigmaStar infinity6c kernel, the same
code as infinity6 (#195) and the other 4.9 kernels, on 5.10's partition
model:

- drivers/mtd/split_layout.c (MTD_SPLIT_LAYOUT): when the uImage at
  0x50000 is followed by the root squashfs at the next 64 KiB boundary,
  register boot, env, firmware (to the end of the chip) and inside it
  kernel, rootfs and rootfs_data; the bootloader's mtdparts= is not used
  then. Anything else in the firmware area -- the fixed slots above all --
  or a read error leaves the driver's partitions as before.
  5.10's add_mtd_partitions() removes what it added when one partition
  fails, so the table is all there or not at all, and mtdpart.c needs none
  of the 4.9 port's bookkeeping; the root is looked up on the master's own
  partition list.
- sstar/flash/nor/mtd_serflash.c (SS_NOR_ONEBIN, what infinity6c builds):
  tries that first, then registers as before with the command line's
  partitions. A registration that fails falls back to them.
- init/do_mounts.c: root_dev_from_flash: the split rootfs is the root, and
  a root= naming an MTD device gives way to it.

The SigmaStar U-Boot reads 2 MiB from 0x50000 and bootm's it, so it boots
this layout unchanged. infinity6c's 8 MB lite images outgrew the fixed
5120K rootfs slot (OpenIPC/firmware ssc377/ssc378 lite: "size exceeded by
4KB"), and the split image lets the kernel's slack in its 2 MiB slot go to
them. Off unless a board config sets CONFIG_MTD_SPLIT_LAYOUT=y.
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Support split NOR firmware layout on infinity6c

✨ Enhancement 🕐 40+ Minutes

Grey Divider

AI Description

• Detect split NOR images and derive partitions from their uImage and squashfs headers.
• Preserve command-line partitions for other layouts or detection failures.
• Mount the detected rootfs despite bootloader MTD root settings.
Merge Risk 🟡 Medium

Blast radius 🟡 Medium 💥 2 capabilities

  • 2 affected capabilities within one bounded functional scope: OpenIPC NOR firmware boot and partition integration.
  • The changed probe, layout detector, MTD partition registration, and root selection implement one bounded NOR firmware integration.
  • Partition exposure is a distinct useful operation from root argument selection, but both concern the same flash-image boot integration rather than independent deployment layers.
  • The inferred rootfs partition and the root-device override produce the end-to-end outcome of mounting the firmware's root filesystem.
  • This is a distinct boot operation, while remaining within the same bounded NOR firmware integration as partition exposure.
  • This is the same bounded root-boot capability as the inferred ROOT_DEV path: root_names_flash and prepare_namespace determine which root is mounted after the flash layout has been registered.
  • It is not an independent functional scope merely because it executes in init rather than the MTD driver.
Behavioral complexity 🟡 Medium 🧩 Interacting branches, Data transformation

  • Before, the SStar probe registered the master using the command-line partition configuration.
  • After, it conditionally parses a uImage followed by a validated SquashFS superblock, rounds image-derived offsets, handles a fixed-slot conflict, constructs several related partitions, and changes ROOT_DEV.
  • The new correctness conditions are that image recognition must reject non-split layouts, every derived boundary must remain within the chip and preserve non-overlapping partition semantics, and the rootfs selected for mounting must be the same partition represented by the inferred offsets.
  • These are interacting validation branches and a nontrivial offset transformation, not merely reuse of an existing MTD registration helper.
Potential damage 🟡 Medium 🩹 Incorrect results

  • An incorrect inferred offset or size can make MTD reads and writes address the wrong portions of the NOR image, so partition-level operations can return or modify the wrong content.
  • Reverting the kernel restores the old registration logic, but any writes made through an incorrect partition before rollback would require restoring the affected flash contents from a known-good image; code rollback alone does not repair those writes.
  • Usually recoverable by booting a kernel without the feature and re-flashing known-good firmware, assuming the bootloader and boot partition remain usable.
  • If an incorrect partition mapping caused a write to overwrite firmware or environment state, recovery requires an external/recovery-flash procedure and is not automatic.
Assessed commit 63f5fd4
Diagram

graph TD
  Driver["NOR Driver"] --> Inspect["Inspect Images"] --> Found{"Split Layout?"} -->|yes| Split["Split Partitions"] --> Root["Select Rootfs"] --> Mount["Mount Root"]
  Found -->|no or error| Legacy["Existing Partitions"]
Loading
High-Level Assessment

The opt-in detector is appropriate for a kernel that takes NOR partitions from the command line rather than device tree. Device-tree-backed mtdsplit would require a broader platform migration; this approach preserves existing layouts through the driver's fallback.

Files changed (7) +288 / -0

Enhancement (5) +275 / -0
split_layout.cDetect images and register split NOR partitions +199/-0

Detect images and register split NOR partitions

• Validates the uImage and squashfs headers to locate the kernel, rootfs, and optional rootfs_data within the flash. Registers image-derived partitions and selects the newly registered rootfs; unrecognized contents and read failures leave registration to the driver.

drivers/mtd/split_layout.c

mtd_serflash.cTry split layout registration during NOR probe +13/-0

Try split layout registration during NOR probe

• Attempts image-derived partition registration before the driver's existing registration path. If detection does not apply or registration fails, the probe falls back to its previous behavior.

drivers/sstar/flash/nor/mtd_serflash.c

split_layout.hExpose the optional split layout registration API +21/-0

Expose the optional split layout registration API

• Declares the detector's return-value contract and supplies a fallback stub when the feature is disabled.

include/linux/mtd/split_layout.h

root_dev.hDeclare the flash-selected root flag +7/-0

Declare the flash-selected root flag

• Exposes the flag used to tell root mounting that the flash identified its own rootfs.

include/linux/root_dev.h

do_mounts.cHonor the detected rootfs over bootloader MTD root settings +35/-0

Honor the detected rootfs over bootloader MTD root settings

• When the flash selected a rootfs, ignores a bootloader root= naming an MTD device and clears its rootfstype restriction. Root settings for other device types remain eligible.

init/do_mounts.c

Other (2) +13 / -0
KconfigAdd an opt-in split NOR layout setting +12/-0

Add an opt-in split NOR layout setting

• Adds CONFIG_MTD_SPLIT_LAYOUT, dependent on built-in MTD and MTD block support. Its help text defines the recognized image layout and fallback behavior.

drivers/mtd/Kconfig

MakefileBuild the split layout detector when enabled +1/-0

Build the split layout detector when enabled

• Includes split_layout.o only when CONFIG_MTD_SPLIT_LAYOUT is selected.

drivers/mtd/Makefile

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Fixed-slot boots fail on stale padding ✓ Resolved
Description
split_find() accepts a SquashFS header from the calculated kernel boundary based only on its magic
and an in-range bytes_used, then registers that location as rootfs. If a bootable fixed-slot
image has stale or corrupt SquashFS-looking bytes in the padding before its actual rootfs slot,
registration succeeds, the bootloader’s MTD root= is ignored, and the invalid partition fails to
mount.

Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

…et fixed slots win

Review on #266: split_find() took any "hsqs" with an in-range bytes_used
right after the kernel as the root. The root is mounted from what it
accepts, and a root= naming the bootloader's partition gives way to it, so
a false match is a camera that does not boot.

- The superblock must be one squashfs mounts: version 4.0, a block size of
  4K-1M equal to 1 << block_log, and bytes_used at least a superblock and
  inside the chip.
- A fixed-slot image written over an older split one, without erasing the
  kernel slot's tail, can leave the old split squashfs right after the new
  kernel, its end overwritten by the slot's own rootfs. When the squashfs
  after the kernel runs on over the fixed rootfs slot (0x250000) and a valid
  superblock starts there, the flash is fixed slots, and the driver
  registers its partitions as before.

Checked with split_find() built on the host over crafted 8 MB images (the
real ssc377 squashfs; a 1 MiB uImage puts the boundary at 0x160000):

  split image (qemu-booted)       split, rootfs 0x250000, data 0x760000
  split, small kernel             split, rootfs 0x160000, data 0x670000
  stale split under fixed slots   not split   (was: split at 0x160000)
  fixed slots, gap erased         not split
  squashfs version 3              not split   (was: split)
  block_size != 1 << block_log    not split   (was: split)
  "hsqs" followed by noise        not split

And in qemu-bench -M ssc377: the ssc377_lite split image still boots from
the published U-Boot, twice, root on mtdblock4, overlay kept.
@widgetii

Copy link
Copy Markdown
Member Author

Addressed in 63f5fd4. The finding is right: the root is mounted from whatever split_find() accepts, and a root= naming the bootloader's partition gives way to it, so a false match leaves a camera that doesn't boot.

  • Superblock checks: the superblock now has to be one that squashfs_fill_super() would mount. That means version 4.0, a block_size from 4K to 1M equal to 1 << block_log, and bytes_used at least one superblock and inside the chip.
  • Your stale-padding case: a fixed-slot image written over an older split one can leave the old squashfs right after the new kernel, with its tail overwritten by the slot's own rootfs. When the squashfs after the kernel runs across the fixed rootfs slot (0x250000) and a valid superblock starts there, the flash now counts as fixed slots, and the driver registers its usual partitions.

I tested split_find() compiled on the host against crafted 8 MB images, using the real ssc377 squashfs, before and after the fix:

image before after
split image (qemu-booted) split split, rootfs 0x250000
split, small kernel (boundary 0x160000) split split, rootfs 0x160000
stale split squashfs under fixed slots split not split
fixed slots, gap erased not split not split
squashfs version 3 split not split
block_size != 1 << block_log split not split
hsqs followed by noise not split not split

The ssc377_lite split image still boots in qemu-bench -M ssc377 from the published U-Boot, twice: root on mtdblock4 and the overlay kept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant