Skip to content

openipc: SigmaStar NAND environment back to 256 KiB, as openipc-hisilicon - #111

Merged
dimerr merged 1 commit into
openipc-sigmastarfrom
sigmastar/env-256k
Nov 7, 2026
Merged

dimerr merged 1 commit into
openipc-sigmastarfrom
sigmastar/env-256k

Conversation

@dimerr

@dimerr dimerr commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

#109 made the SigmaStar NAND environment 128 KiB in its 256 KiB partition (631d8991cc1), so a bad block there would leave room for it. That breaks the OpenIPC convention: openipc-hisilicon and openipc-ingenic use CONFIG_ENV_SIZE=0x40000 in a 0x40000 range at 0xC0000, and the firmware's fw_env.config reads the environment at that size.

This puts it back to 256 KiB. The rest of #109's fixes stay: ubwrite's size check before the erase and its write bounded to the boot partition, and the recovery checks.

…icon

631d899 made it 128 KiB in the 256 KiB env partition, so a bad block
there would leave room for it. That broke the convention every OpenIPC
NAND camera follows: CONFIG_ENV_SIZE 0x40000 in a 0x40000 range at
0xC0000, which the firmware's fw_env.config reads with that size. It is
256 KiB again; ubwrite's size check and partition-bounded write stay.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Restore SigmaStar NAND environment size to 256 KiB

🐞 Bug fix ⚙️ Configuration changes 🕐 Less than 10 minutes

Grey Divider

AI Description

• Restore the 256 KiB NAND environment size expected by OpenIPC firmware tools.
• Align SigmaStar with other OpenIPC NAND layouts while retaining the existing boot-write
 safeguards.
Diagram

graph TD
  CFG["NAND config"] --> UBOOT["U-Boot environment"] --> NAND[("NAND env partition")] --> FIRM["Firmware env reader"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Reserve additional NAND space for environment redundancy
  • ➕ Could retain room to recover from a bad block.
  • ➖ Requires a partition-layout change and coordinated firmware configuration, complicating compatibility with existing images.

Recommendation: Restore the established 256 KiB size now to match firmware readers and other OpenIPC NAND targets. If bad-block tolerance is required, address it separately with a coordinated layout and firmware migration.

Files changed (3) +5 / -7

Bug fix (1) +1 / -2
nand_configRestore the SigmaStar NAND environment to 256 KiB +1/-2

Restore the SigmaStar NAND environment to 256 KiB

• Changes CONFIG_ENV_SIZE from 0x20000 to 0x40000, matching the existing environment range and partition size. Removes the obsolete comment about reserving space for a bad block.

openipc/nand_config

Documentation (2) +4 / -5
CLAUDE.mdCorrect the documented SigmaStar NAND environment size +2/-2

Correct the documented SigmaStar NAND environment size

• Describes the environment as occupying the full 256 KiB range at 0xC0000, consistent with the firmware's fw_env.config.

CLAUDE.md

openipc-common.hAlign the NAND layout comment with the restored size +2/-3

Align the NAND layout comment with the restored size

• Updates the environment comment to state that both CONFIG_ENV_SIZE and CONFIG_ENV_RANGE are 0x40000. No boot commands or safeguards change.

include/configs/openipc-common.h

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

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. Upgraded devices lose saved settings 🐞 Bug ≡ Correctness
Description
Changing CONFIG_ENV_SIZE makes env_import() validate the existing NAND record against a 256 KiB
CRC span rather than the 128 KiB span used when it was saved. A bootloader-only upgrade preserves
the old record, but its CRC fails on the next boot, causing U-Boot to use defaults without migrating
the saved variables.
Code

openipc/nand_config[16]

+CONFIG_ENV_SIZE=0x40000
Evidence
The NAND loader reads CONFIG_ENV_SIZE and requests CRC validation; that validation covers
ENV_SIZE, which derives from the configured size. The bootloader update writes only the boot
partition, leaving the old environment in place, and the default-environment autosave requires a
blank CRC word rather than the old record's populated CRC.

openipc/nand_config[14-17]
env/nand.c[341-367]
include/env_internal.h[85-85]
env/common.c[300-311]
include/configs/openipc-common.h[225-227]
common/openipc.c[1090-1107]
common/openipc.c[1178-1185]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Existing 128 KiB SigmaStar NAND environments fail CRC validation after the configured size increases to 256 KiB, so bootloader upgrades discard saved settings at runtime.
## Fix Focus Areas
- openipc/nand_config[14-17]
- env/nand.c[338-367]
- env/common.c[300-315]
## Recommended Fix
On failure of the new-size CRC check, validate the record using the former 128 KiB data span. Import only a valid old record, then persist it in the new 256 KiB format; retain the normal invalid-environment fallback when neither CRC validates.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. A bad environment block loses settings 🐞 Bug ☼ Reliability
Description
Setting CONFIG_ENV_SIZE equal to CONFIG_ENV_RANGE leaves readenv() and writeenv() no spare
NAND block to skip. On the documented 128 KiB erase-block geometry, one bad block in the two-block
environment partition makes loading fall back to defaults and prevents saveenv from completing.
Code

openipc/nand_config[16]

+CONFIG_ENV_SIZE=0x40000
Evidence
The configured range and partition are both 256 KiB, while the image's NAND geometry uses 128 KiB
blocks. Both environment loops skip bad blocks but stop at the end of CONFIG_ENV_RANGE before they
can accumulate 256 KiB from the sole remaining good block.

openipc/nand_config[14-21]
openipc/sigmastar-image.py[213-218]
env/nand.c[113-141]
env/nand.c[219-264]
env/nand.c[341-350]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A 256 KiB environment occupies the full 256 KiB NAND range, so a single bad erase block prevents a complete read or write.
## Fix Focus Areas
- openipc/nand_config[14-21]
- include/configs/openipc-common.h[200-204]
- openipc/sigmastar-image.py[267-268]
## Recommended Fix
Provide spare erase-block capacity for the 256 KiB record and update the partition layout and image metadata consistently, or document and explicitly accept the loss of bad-block tolerance if the fixed 256 KiB partition is mandatory. Keep the bootloader and firmware environment configurations aligned with the chosen layout.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Tip of the day
💡 Did you know, you can hide the parts of a finding you never read, like the evidence or the agent prompt

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@dimerr
dimerr merged commit 4bab3e8 into openipc-sigmastar Nov 7, 2026
2 checks passed
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