bootscript: rk35xx: simplify armbianEnv.txt corruption detection#9953
bootscript: rk35xx: simplify armbianEnv.txt corruption detection#9953mingzhangqun wants to merge 3 commits into
Conversation
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe boot script clears ChangesBoot Environment Loading and Device Selection
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@config/bootscripts/boot-seeed-rk35xx.cmd`:
- Around line 38-43: The current fallback that sets rootdev by probing MMC order
can pick mmcblk1p1 even when the system booted from mmc 0; instead, if rootdev
is empty derive it from the actual boot source: first prefer a configured
PARTUUID (use ${PARTUUID} if present), otherwise construct rootdev from the boot
source variables ${devtype} and ${devnum} (e.g., the mmc device the script was
loaded from) rather than the probe order; update the block that currently checks
"part exists mmc 1 1" / "part exists mmc 0 1" to check/choose based on PARTUUID
or build "/dev/<devtype><devnum>p1" when devtype/devnum indicate an MMC and only
fall back to probing if those variables are unset.
- Around line 24-37: Don't use rootdev itself as the corruption sentinel; save
the current value into a temp variable (e.g. saved_rootdev) before you clear
rootdev, perform the load/import as today, then if rootdev is still empty
restore saved_rootdev and only then attempt the .bak fallback; also unset the
temp saved_rootdev afterwards so you don't leak state. This keeps the corruption
check independent of an optional config key while preserving any
already-initialized rootdev.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: acc8a70a-a4f5-4972-9bb9-7dfc4d2a9ec4
📒 Files selected for processing (1)
config/bootscripts/boot-seeed-rk35xx.cmd
3410aac to
e7a3a02
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@config/bootscripts/boot-seeed-rk35xx.cmd`:
- Around line 33-43: The script restores rootdev from saved_rootdev before
attempting to import armbianEnv.txt.bak, which prevents the final fallback
(/dev/mmcblk${devnum}p1) if the .bak import fails or imports nothing; relocate
or conditionalize the setenv rootdev "${saved_rootdev}" so it only runs after
the load/import attempt (or only if rootdev is still empty after a successful
import), i.e., attempt load ${devtype} ${devnum}:${distro_bootpart} ${load_addr}
${prefix}armbianEnv.txt.bak and env import -t ${load_addr} ${filesize} first,
then restore saved_rootdev (or set saved_rootdev cleared) only if rootdev
remains unset—affecting the symbols rootdev, saved_rootdev, armbianEnv.txt.bak,
load ${devtype}..., env import -t, and setenv rootdev "/dev/mmcblk${devnum}p1".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1cd6d613-8042-4cf1-b670-6da130f74f71
📒 Files selected for processing (1)
config/bootscripts/boot-seeed-rk35xx.cmd
6a14fe2 to
7891fe7
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@config/bootscripts/boot-seeed-rk35xx.cmd`:
- Around line 39-41: The fallback sets rootdev with a hardcoded partition "p1";
update the setenv call so it derives the partition from ${distro_bootpart}
instead of "1" (i.e., build rootdev using ${devnum} and ${distro_bootpart});
modify the setenv rootdev line (the line that currently reads setenv rootdev
"/dev/mmcblk${devnum}p1") to construct "/dev/mmcblk${devnum}p${distro_bootpart}"
so the script honors non-1 boot partitions.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2c083362-32ed-429c-8aea-60841f01aa0c
📒 Files selected for processing (1)
config/bootscripts/boot-seeed-rk35xx.cmd
Replace flag-based approach with rootdev check: clear rootdev before env import, and if it remains empty the file was corrupt (e.g. 0xFF from eMMC erased block passes "env import -t" but imports zero variables). Clear rootdev before .bak fallback import too, and derive final fallback from boot source devnum instead of hardcoding mmcblk0.
7891fe7 to
de9fa7d
Compare
|
I'm wondering if this check on file content can be extended to the other files that are to be loaded. Now it's mainly focussed on |
|
I will search a bit more, but out of my loose wrist i cannot recall where an |
…ction - Mention ^@ (NUL) corruption for non-eMMC storage in comments - Add WARNING console messages for .bak fallback and rootdev derivation so failures are visible during boot for debugging
|
Thanks @djurny for the thorough review and suggestions!
That's a good idea for a future improvement. A generic
The |
Hi @mingzhangqun, Naming the "fallback" configuration Groetjes, |
Per review feedback (armbian#9953), the build-time fallback file must not collide with user backups. ".bak" is a common name users pick when editing armbianEnv.txt themselves, and it is easily removed during routine cleanup of "obsolete" backup files. Rename the fallback to ".dist" (distribution default), which signals a build-shipped asset rather than a user backup, and matches the upstream convention of shipping a default armbianEnv.txt under a distinguished name. Updates both the bootscript consumer and the build hook that creates the file.
|
Hi @djurny, Thanks for the thorough review and the suggestion! I've renamed the fallback to Regarding placing the file under The Groetjes, |
|
✅ This PR has been reviewed and approved — all set for merge! |
Summary
armbian_env_loadedflag approach with a simplerrootdevcheck to detect armbianEnv.txt corruptionpart exists mmcto probe the correct mmc device in the final fallback instead of hardcodingmmcblk0Details
Power loss can fill armbianEnv.txt with 0xFF (eMMC erased block) which passes
env import -twithout error but imports zero variables. The new approach clearsrootdevbefore import and verifies it was actually set afterward. If not, falls back to.bak, and finally usespart existsto detect which mmc device is present.Test plan
.bakfallback works.bak— verifypart existsfallback boots correctlySummary by CodeRabbit