Files
bfe-core1106-sdk/qemu/rootfs/etc/rc
T
BFE EngineeringandClaude Fable 5 7ab07a35d3 qemu: real-image milestone — boot an actual flare-edge build in the VM
mkimage gains --rootfs-image/--oem-image (raw ext4 matched pair placed
into slot A, size-checked fail-closed; slot B keeps the skeleton as a
known-good fallback), and stage-1 rc now hands the live devtmpfs to the
new root across switch_root — busybox switch_root moves nothing, our
skeleton init remounted defensively, but a REAL image's getty opens
/dev/console immediately and looped on ENOENT without it.

Verified with the 2026-08-24 flare-edge build (rootfs 192M + oem 26M):
the image's own rcS chain runs on the 6.18 virt kernel, real daemons
start (warden-modbus confirmed running via root shell; the shipped
0.2.4 flared reproduces flare-edge#106 exactly, and S99hciinit reports
the issue-#4 btlpm symptom — the VM doubles as a faithful reproducer of
known field bugs), and a getty answers on the console.
qemu/tests/real-image-boot.sh asserts switch_root + daemon starts +
login prompt, credential-free. REAL-IMAGE-BOOT-PASS.

Regression sweep after the shared-path changes: OTA-APPLY-PASS,
PORTAL-SCENARIO-PASS, UI-SHOT-PASS, boot smoke OK.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018HUayid7W5w7jBdb9Rrj1K
2026-08-30 11:00:02 -06:00

51 lines
1.7 KiB
Plaintext
Executable File

#!/bin/busybox sh
# shellcheck shell=dash
# Stage-1 rc: sourced by /init (still PID 1, initramfs root) when a virtio
# disk is present. Emulates U-Boot's slot choice — mount the validated slot's
# rootfs and switch_root into it. This is an EMULATION of the A/B selection
# outcome, not the BCB/bootcount mechanism itself.
#
# Every guarded failure path `return`s to /init (valid in a sourced script;
# /init then falls through to shell/poweroff). The final exec is the one
# unguardable step: if switch_root itself fails to launch, the shell — PID 1 —
# exits and the kernel panics; the applet-existence check below catches the
# only preventable variant of that.
# shellcheck source=qemu/rootfs/etc/warden-lib.sh disable=SC1091
. /etc/warden-lib.sh
warden_populate_by_name
slot="$(warden_slot)"
root="/dev/block/by-name/rootfs${slot}"
if [ ! -e "$root" ]; then
echo "rc: $root missing — staying in initramfs"
return 0
fi
mkdir -p /mnt
if ! mount -t ext4 "$root" /mnt; then
echo "rc: mount of $root failed — staying in initramfs"
return 0
fi
if [ ! -x /mnt/sbin/init ]; then
echo "rc: $root has no /sbin/init — staying in initramfs"
umount /mnt
return 0
fi
if ! command -v switch_root >/dev/null; then
echo "rc: busybox lacks switch_root — staying in initramfs"
umount /mnt
return 0
fi
# Hand the live devtmpfs to the new root: busybox switch_root moves nothing,
# and a REAL device rootfs's init expects /dev to already be there (its getty
# opens /dev/console immediately). Our own skeleton init remounts devtmpfs
# defensively either way.
mkdir -p /mnt/dev
mount -o move /dev /mnt/dev 2>/dev/null || mount --move /dev /mnt/dev
echo "rc: switching root to rootfs${slot} ($root)"
exec switch_root /mnt /sbin/init