Skip to content

mtd: the report's flash size is as far as the partitions reach - #309

Merged
openipc-ai merged 1 commit into
masterfrom
mtd-size-reached-end
Dec 3, 2026
Merged

openipc-ai merged 1 commit into
masterfrom
mtd-size-reached-end

Conversation

@openipc-ai

Copy link
Copy Markdown
Contributor

For #305: the GM8128's 16 MiB NOR shows as rom: size: 15M.

The report's size was what the partitions cover, each byte once (mtd_covered_size()), rounded down to MiB. On that camera, no partition holds the 4 KiB boot header at 0x0 or the 4 KiB block at 0x66000, as its kernel's own partition lines show (comment). That leaves 16 MiB − 8 KiB, which rounds down to 15M. The GM8126 vendor dump in qemu-bench is the same with the header alone: 16 MiB − 4 KiB, also 15M.

New mtd_chip_size(): where the kernel gives offsets (sysfs, mtdparts=, or the boot log's partition lines), the chip is at least as big as the furthest any partition reaches. Without offsets, it is what the partitions cover, as before. Only the report's size: line uses it. mtd_flash_size() is unchanged: backup and restore still use the covered size, because that is what a backup holds.

On a layout with no gaps and no unpartitioned head, the two numbers are equal and nothing changes.

Tested

  • mtd_alias_test gains the reporter's partition table: 0xffe000 covered, chip 0x1000000. It also covers an existing gapped layout, the no-offsets case, and no partitions at all.
  • In qemu-bench's gm8126 machine on the GM8126 vendor image, whose kernel logs the partition offsets: master reports size: 15M, this branch size: 16M.
  • All native unit tests pass, and ipcinfo is byte-identical (153852 bytes on arm32).

On the GM8126 and GM8128 no partition holds the 4 KiB boot header at 0,
and on the camera of #305 not the block at 0x66000 either, so the bytes
the partitions cover came to 16 MiB less 8 KiB and the report said 15M.
Where the kernel gives offsets, the chip is at least as big as the last
partition reaches. Backups keep counting covered bytes: that is what they
hold.
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

mtd: report flash size as far as partitions reach, not covered bytes

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• The size: line now uses a new mtd_chip_size(), which is at least as far as the furthest
 partition reaches.
• Fixes the GM8128 (#305) reporting 15M for a 16 MiB chip, since unpartitioned header and gap bytes
 were not counted.
• backup and restore keep mtd_covered_size(), because a backup holds only partitioned bytes;
 tests cover gapped, no-offset, and empty layouts.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed calculation is called from MTD enumeration and its result is inserted into the single ROM object consumed by report and backup YAML generation.
  • These are two delivery surfaces of the same bounded hardware-inventory behavior, not independent functional domains.
Behavioral complexity 🟢 Low 🧩 Straightforward

  • The prior behavior used mtd_covered_size(); the new behavior retains that result and applies a direct maximum over known partition endpoints.
  • No new state machine, ordering protocol, compatibility transition, or algorithmic interaction is introduced.
Potential damage 🟡 Medium 🩹 Incorrect results

  • If the changed calculation regresses, generated ROM metadata can report an incorrect chip size.
  • The consequence is limited to inventory/metadata consumers; backup restore sizing still reads mtd_flash_size(), not chip_size().
  • Reverting the code restores the previous metadata calculation.
  • Existing generated reports or backup descriptions containing a wrong size would need regeneration, but no persistent flash state or external device effect is changed.
Assessed commit 35bd209
Diagram

graph TD
    enum["enum_mtd_info()"] --> covered["mtd_covered_size()"]
    enum --> chip["mtd_chip_size()"]
    chip --> covered
    chip --> size["get_mtd_info size line"]
    covered --> flash["mtd_flash_size()"]
    flash --> backup["backup / restore"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Query MEMGETINFO ioctl on /dev/mtdN
  • ➕ Returns the real device size without inferring from partition offsets
  • ➕ Handles unpartitioned head and gaps without a max-reach heuristic
  • ➖ Requires opening each MTD device and extra permissions
  • ➖ Does not help when devices are not accessible or on older kernels
  • ➖ Would still need the offset-based fallback for the no-offsets case

Recommendation: Keeping the partition-based approach is reasonable because it works from the same offsets the kernel already exposes, and it leaves backup and restore unchanged. The alternative of querying the device with the MEMGETINFO ioctl gives the true chip size directly, but it requires opening the MTD device and may fail on early boot or restricted systems. A reasonable follow-up would be to prefer MEMGETINFO when available and fall back to the current computation.

Files changed (4) +39 / -3

Enhancement (1) +9 / -0
mtd_alias.cAdd mtd_chip_size() computing furthest partition reach +9/-0

Add mtd_chip_size() computing furthest partition reach

• Implements mtd_chip_size() as the covered size, raised to the largest offset+size among partitions with known offsets. Without offsets it returns the covered size unchanged.

src/mtd_alias.c

Bug fix (1) +5 / -3
mtd.cReport size line uses the new chip size +5/-3

Report size line uses the new chip size

• Adds a chip_size static alongside flash_size, computed in enum_mtd_info() via mtd_chip_size(). The report's size line now prints chip_size, while mtd_flash_size() still returns the covered size used by backup and restore.

src/mtd.c

Tests (1) +18 / -0
mtd_alias_test.cTest chip size for GM8128 layout and edge cases +18/-0

Test chip size for GM8128 layout and edge cases

• Adds checks for the reporter's partition table (covered 0xffe000, chip 0x1000000), the existing gapped fixture, the no-offsets case, and an empty partition list.

src/mtd_alias_test.c

Documentation (1) +7 / -0
mtd_alias.hDeclare mtd_chip_size() with rationale comment +7/-0

Declare mtd_chip_size() with rationale comment

• Adds the declaration of mtd_chip_size() with a comment explaining that it counts flash no partition holds, unlike mtd_covered_size(), which backups use.

src/mtd_alias.h

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

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can move or hide resolved findings to focus on what still needs action

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@openipc-ai
openipc-ai merged commit c3aa9c4 into master Dec 3, 2026
5 checks passed
@openipc-ai
openipc-ai deleted the mtd-size-reached-end branch December 3, 2026 12:34
@openipc-ai openipc-ai mentioned this pull request Dec 3, 2026
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