Skip to content

Commit 66798e7

Browse files
mingzhangqunigorpecovnik
authored andcommitted
armbian: protect armbianEnv.txt against power-loss corruption
- bootscript: use command return values instead of rootdev sentinel for corruption detection, add .bak fallback with load/import checks - common.inc: create armbianEnv.txt.bak at build time (no systemd service)
1 parent 7d1eb48 commit 66798e7

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

config/bootscripts/boot-seeed-rk35xx.cmd

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,31 @@ test -n "${distro_bootpart}" || distro_bootpart=1
2121

2222
echo "Boot script loaded from ${devtype} ${devnum}:${distro_bootpart}"
2323

24-
if test -e ${devtype} ${devnum}:${distro_bootpart} ${prefix}armbianEnv.txt; then
25-
load ${devtype} ${devnum}:${distro_bootpart} ${load_addr} ${prefix}armbianEnv.txt
26-
env import -t ${load_addr} ${filesize}
24+
# Load armbianEnv.txt with corruption detection and .bak fallback.
25+
# sed -i + power loss can zero or truncate the file.
26+
setenv armbian_env_loaded "no"
27+
if load ${devtype} ${devnum}:${distro_bootpart} ${load_addr} ${prefix}armbianEnv.txt; then
28+
if env import -t ${load_addr} ${filesize}; then
29+
setenv armbian_env_loaded "yes"
30+
else
31+
echo "WARNING: armbianEnv.txt format error"
32+
fi
33+
fi
34+
if test "${armbian_env_loaded}" = "no"; then
35+
if load ${devtype} ${devnum}:${distro_bootpart} ${load_addr} ${prefix}armbianEnv.txt.bak; then
36+
echo "Loading armbianEnv.txt.bak as fallback"
37+
if env import -t ${load_addr} ${filesize}; then
38+
setenv armbian_env_loaded "yes"
39+
else
40+
echo "ERROR: armbianEnv.txt.bak format error"
41+
fi
42+
else
43+
echo "WARNING: no armbianEnv.txt.bak found"
44+
fi
45+
fi
46+
# Final safety: restore default rootdev if all sources failed
47+
if test -z "${rootdev}"; then
48+
setenv rootdev "/dev/mmcblk0p1"
2749
fi
2850

2951
# fdtfile is set by armbianEnv.txt (per-board BOOT_FDT_FILE).

config/sources/vendors/seeed-studio/recomputer-rk35xx-common.inc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,17 @@ function post_family_tweaks__recomputer_rk35xx_disable_armbian_hardware_optimize
510510
chroot_sdcard systemctl --no-reload disable armbian-hardware-optimize.service 2>/dev/null || true
511511
rm -f "${SDCARD}"/lib/systemd/system/armbian-hardware-optimize.service
512512
}
513+
514+
# Create armbianEnv.txt.bak at build time.
515+
# Protects against sed -i + power loss corruption.
516+
function pre_umount_final_image__recomputer_armbianenv_backup() {
517+
display_alert "$BOARD" "Creating armbianEnv.txt backup" "info"
518+
519+
local env_file="${MOUNT}/boot/armbianEnv.txt"
520+
local bak_file="${MOUNT}/boot/armbianEnv.txt.bak"
521+
522+
if [[ -f "${env_file}" ]]; then
523+
cp -a "${env_file}" "${bak_file}"
524+
display_alert "$BOARD" "armbianEnv.txt.bak created"
525+
fi
526+
}

0 commit comments

Comments
 (0)