Bare-Metal & Bootloader Bring-Up Fault Triage
Triage unzeroed .bss cold/warm reset heisenbugs, ARMv7-A AAPCS32 8-byte SP alignment faults on 64-bit printf/LDRD, U-Boot PHY/bootargs traps, and VFS rootfs panics.
What you'll learn
- Diagnose warm-vs-cold reset nondeterminism and
printf("%lld")/LDRDData Abortcrashes caused by unzeroed.bssor4-byte-misalignedARMv7-Astack pointers. - Triage
U-BootRMII Ethernet PHY reset timing,NULLphydevData Aborttraps, and truncatedbootargsenvironment strings. - Implement a C11 bring-up fault-triage engine (
lab_m05_boot_fault_triage) decoding straps,AAPCS32/.bssstartup bounds, andVFSrootfs panic signatures.
Silent C Runtime Preconditions That Linux User Space Hid From You
When you run ./verify on an Ubuntu host, Linux kernel execve() and glibc _start quietly prepare a pristine C11 execution environment before main() runs: anonymous virtual pages backing .bss are guaranteed zeroed by the MMU, and the kernel aligns the initial user stack pointer to 16 bytes (x86_64) or 8 bytes (ARMv7-A). In bare-metal Cortex-A7 code (GL-E01..E02) or custom SPL, nobody does that unless your start.S and linker script do it explicitly!
Two classic bring-up ghosts follow immediately. First, if start.S forgets to zero __bss_start .. __bss_end, static int initialized; holds random DDR3 power-on charge (or leftover values from the previous warm reset!), making firmware work once and hang on reset. Second, setting ldr sp, =0x80200004 (4-byte aligned, NOT 8-byte aligned!) works fine for int math, then explodes with a Data Abort or prints corrupted garbage the instant you call printf("%llu", ticks) because ARMv7-A AAPCS32 aligns 64-bit va_arg parameters and LDRD/STRD doubleword loads on 8-byte stack boundaries!
Figure 5.3a. Every bring-up hang localizes cleanly to one boundary: POR straps, start.S ABI, U-Boot env/PHY, or Kernel VFS.
mental model: Bringing up bare-metal C or U-Boot without zeroing .bss and 8-byte-aligning SP is like moving into a lab bench without sweeping last week's loose wire clippings off the ESD mat: trivial 1-wire probes work by luck until a wide connector shorts across residual debris.
Where it stops working: Fixing startup assembly and bootargs resolves deterministic software contract bugs; unstable DDR3 calibration or brownout rails on VDD_SOC_IN require oscilloscope eye/rail checks.
definition (AAPCS32 8-Byte Stack Alignment): Defined by the Procedure Call Standard for the ARM Architecture (AAPCS32, section 6.2.1.2), this ABI rule requires SP mod 8 == 0 at every public function call interface so 64-bit integers (uint64_t), double floats, variadic va_list 8-byte arguments, and LDRD/STRD instructions execute at naturally aligned doubleword addresses without alignment traps.
- Step 1. bic sp, sp, #7 guarantees 8-byte alignment even if a symbol or linker expression shifts by 4 bytes.
- Step 2. PHY ID 0xFFFF means MDIO pull-up/pinmux is missing or the PHY is still held in hardware reset.
- Step 3. An unescaped semicolon inside setenv bootargs '...; root=/dev/nfs' runs root= as a U-Boot command!
- Step 4. Major 179 is MMC/SD; adding rootwait tells VFS to wait until USDHC finishes asynchronous probing.
Figure 5.3b. Zero .bss, enforce SP % 8 == 0 (bic sp,sp,#7), check bootargs length, and add rootwait on mmcblk.
Decoding U-Boot Data Aborts and Kernel VFS Panic Signatures
Once U-Boot reaches its console, two subtle configuration traps dominate network and kernel bring-up. First, on i.MX6ULL ENET1/ENET2 boards using LAN8720A or KSZ8081 RMII PHYs, if the Device Tree omits phy-reset-gpios / phy-reset-duration = <15> or mismatches reg = <0> vs <1> MDIO address, mdio list misses the PHY; older vendor patches that dereference phydev without a NULL check trigger a U-Boot pc : [<...>] data abort right inside ping or tftpboot! Second, inside setenv bootargs ..., forgetting quotes around ; or exceeding CONFIG_SYS_CBSIZE truncates the tail of the kernel command line silently.
When Linux kernel 6.12 panics with VFS: Unable to mount root fs on <dev>, read the (major, minor) pair literally rather than guessing! unknown-block(0,0) means the kernel had no block device for root= — either bootargs lost root=..., or root=/dev/nfs was passed to a kernel compiled without CONFIG_ROOT_NFS=y / ip=.... Conversely, unknown-block(179,2) (major 179 = mmcblk) happens when VFS runs before the asynchronous USDHC host controller finishes card detection — cured instantly by rootwait.
Figure 5.3b. Major number 179 identifies MMC/SD block devices; (0,0) indicates no block device matched root=.
| Observed Bring-Up Symptom | Exact Primary Signal | Underlying Root Cause | Deterministic Fix |
|---|---|---|---|
| Works on 1st download, fails after warm reset | Static globals non-zero at main() entry | start.S omitted .bss zero loop | Zero [__bss_start, __bss_end) before bl main |
int prints fine; printf("%lld", x) crashes/garbles | SP = 0x80200004 (SP & 7 == 4) | Violated AAPCS32 8-byte stack alignment | Execute bic sp, sp, #7 in start.S + ALIGN(8) in .lds |
U-Boot TFTP says PHY not found / Data Abort | mdio list empty or 0xFFFF | Missing RMII PHY GPIO reset pulse or wrong MDIO reg | Set phy-reset-gpios, >= 10 ms duration, verify MDIO addr 0/1 |
VFS: Unable to mount root fs on unknown-block(179,2) | mmc1: new high speed MMC card prints after panic! | VFS raced ahead of async USDHC card probe | Append rootwait rw rootfstype=ext4 to U-Boot bootargs |
learner@ksa:~/gl-e00/m05-l03$ bat -H 11 -H 27 armv7_bringup_guard.h File: armv7_bringup_guard.h /* SPDX-License-Identifier: GPL-2.0 */ #ifndef KSA_ARMV7_BRINGUP_GUARD_H #define KSA_ARMV7_BRINGUP_GUARD_H #include <stdbool.h> #include <stdint.h> /* * Reference ARMv7-A CRT0 startup sequence (start.S): * ldr sp, =_stack_top * bic sp, sp, #7 @ Enforce AAPCS32 8-byte stack alignment * ldr r0, =__bss_start * ldr r1, =__bss_end * mov r2, #0 * 1: cmp r0, r1 * strlo r2, [r0], #4 @ Requires 4-byte aligned __bss_start/__bss_end * blo 1b * bl main */ #define ARM_AAPCS32_SP_ALIGN 8U #define IMX_SD_IVT_OFFSET 0x400U #define LINUX_MMC_BLOCK_MAJOR 179U static inline bool armv7_crt0_bounds_valid(uint32_t sp, uint32_t bss_start, uint32_t bss_end) { if ((sp & (ARM_AAPCS32_SP_ALIGN - 1U)) != 0U) return false; if (bss_end < bss_start) return false; if (((bss_start | bss_end) & 0x3U) != 0U) return false; return true; } #endif /* KSA_ARMV7_BRINGUP_GUARD_H */- bic sp, sp, #7 clears bits [2:0] so 64-bit LDRD/STRD and variadic %lld calls stay 8-byte aligned.
- Checks 8-byte SP alignment alongside 4-byte word bounds required by strlo r2, [r0], #4.
bootz(U-Boot) / kernel-parameters(7)(7) GL-E00 Quick Reference bootz(U-Boot) / kernel-parameters(7)(7) U-Boot & Linux 6.12 ROOTFS BOOTARGS TEMPLATES # eMMC / SD ext4 boot (note mandatory 'rootwait'!) setenv bootargs 'console=ttymxc0,115200 root=/dev/mmcblk1p2 rootfstype=ext4 rw rootwait' # Raw SLC NAND UBIFS boot (note quotes protecting ';' in mtdparts if present!) setenv bootargs 'console=ttymxc0,115200 ubi.mtd=4 root=ubi0:rootfs rootfstype=ubifs rw' # NFSv3 network rootfs boot (requires CONFIG_ROOT_NFS=y and static Bench NIC!) setenv bootargs 'console=ttymxc0,115200 root=/dev/nfs nfsroot=192.168.10.1:/srv/nfs/rootfs,v3,tcp ip=192.168.10.50:192.168.10.1:192.168.10.1:255.255.255.0::eth0:off rw' Kernel Systems Academy Lesson 5.3 bootz(U-Boot) / kernel-parameters(7)(7) GL-E00 quick reference · full manual page: man 7 bootz(U-Boot) / kernel-parameters(7) Modeling AAPCS32 Stack Alignment and VFS Panic Triage in Host C11
In verify.c, we prove mathematically why an odd-word SP (0x80200004) corrupts AAPCS32 64-bit stack-argument offsets (ROUND_UP(offset, 8)), verify .bss 4-byte clear bounds so strlo r2, [r0], #4 never overwrites 1..3 bytes of .data/stack past __bss_end, and classify three canonical VFS panic scenarios.
Completing this walkthrough prepares you directly for lab_m05_boot_fault_triage, where you will repair and benchmark the full bring-up diagnostic library.
learner@ksa:~/gl-e00/m05-l03$ bat -H 10 -H 29 verify.c File: verify.c #define _POSIX_C_SOURCE 200809L #include <stdbool.h> #include <stdint.h> #include <stdio.h> #include <string.h> static uint32_t aapcs32_u64_stack_addr(uint32_t sp_at_call, uint32_t slot_off) { /* AAPCS32 aligns 8-byte stack args to 8-byte offset RELATIVE to SP (assumed % 8 == 0)! */ uint32_t rel_aligned = (slot_off + 7U) & ~7U; return sp_at_call + rel_aligned; } static const char *classify_vfs_panic(const char *bootargs, uint32_t major) { if (strstr(bootargs, "root=") == NULL) return "TRUNCATED_OR_MISSING_ROOT_ARG"; if (strstr(bootargs, "root=/dev/nfs") != NULL && major == 0U) return "MISSING_CONFIG_ROOT_NFS_OR_IP_ARG"; if (major == 179U && strstr(bootargs, "rootwait") == NULL) return "ASYNC_MMC_MISSING_ROOTWAIT"; return "CHECK_ROOTFSTYPE_OR_PARTUUID"; } int main(void) { uint32_t bad_sp = 0x80200004U; uint32_t fixed_sp = bad_sp & ~7U; /* bic sp, sp, #7 -> 0x80200000 */ uint32_t bad_u64_addr = aapcs32_u64_stack_addr(bad_sp, 4U); uint32_t good_u64_addr = aapcs32_u64_stack_addr(fixed_sp, 4U); const char *p_trunc = classify_vfs_panic("console=ttymxc0,115200", 0U); const char *p_nfs = classify_vfs_panic("console=ttymxc0,115200 root=/dev/nfs rw", 0U); const char *p_mmc = classify_vfs_panic("console=ttymxc0,115200 root=/dev/mmcblk1p2 rw", 179U); if ((bad_u64_addr & 7U) == 0U || (good_u64_addr & 7U) != 0U) return 1; printf("AAPCS32 bad_sp=0x%08X u64_addr=0x%08X(mod8=%u) fixed_sp=0x%08X u64_addr=0x%08X(mod8=%u)\n", bad_sp, bad_u64_addr, bad_u64_addr & 7U, fixed_sp, good_u64_addr, good_u64_addr & 7U); printf("VFS_TRIAGE case1=%s case2=%s case3=%s\n", p_trunc, p_nfs, p_mmc); return 0; }- Compiler aligns 64-bit arg offsets assuming entry SP % 8 == 0; if SP % 8 == 4, physical addr % 8 == 4!
- bic sp, sp, #7 (bad_sp & ~7U) restores 0x80200000 so every 8-byte stack slot lands on mod8 == 0.
Confirming 64-Bit Slot Misalignment and VFS Cause Isolation
Look at AAPCS32 in the execution capture: the compiler carefully rounded slot_off = 4 up to +8 assuming SP obeyed the ABI, yet because bad_sp started at 0x80200004, 0x80200004 + 8 = 0x8020000C (mod8 = 4!) — guaranteed to fault any alignment-checked LDRD! Applying bad_sp & ~7U (bic sp, sp, #7) places the uint64_t slot at 0x80200008 (mod8 = 0).
VFS_TRIAGE likewise separates truncated bootargs, NFS kernel-config/IP omissions, and missing rootwait on major 179 (mmcblk) without guesswork.
learner@ksa:~/gl-e00/m05-l03gcc -std=c11 -Wall -Wextra -Werror verify.c -o verifylearner@ksa:~/gl-e00/m05-l03./verifyAAPCS32 bad_sp=0x80200004 u64_addr=0x8020000C(mod8=4) fixed_sp=0x80200000 u64_addr=0x80200008(mod8=0)VFS_TRIAGE case1=TRUNCATED_OR_MISSING_ROOT_ARG case2=MISSING_CONFIG_ROOT_NFS_OR_IP_ARG case3=ASYNC_MMC_MISSING_ROOTWAITlearner@ksa:~/gl-e00/m05-l03learner@ksa:~/gl-e00/m05-l03strace -e trace=write,exit_group ./verifywrite(1, "AAPCS32 bad_sp=0x80200004 u64_ad"..., 222) = 222exit_group(0) = ?+++ exited with 0 +++Subtle Linker, U-Boot Semicolon, and DTB Address Collisions
Keep one habit across every bring-up session in GL-E01..GL-E07: whenever boot fails, scroll up from the panic line to find the earliest warning (mdio, regulator, mmc, nfs, or Kernel command line: ... printed near 0.000000). The kernel literally echoes the exact bootargs string it received from U-Boot near the top of dmesg!
Comparing Kernel command line: in dmesg against what you thought setenv bootargs set catches 90% of semicolon and truncation mistakes in five seconds.
Unquoted Semicolon in mtdparts Truncating bootargs Inside U-Boot:
- Symptom: Running
setenv bootargs console=ttymxc0,115200 mtdparts=gpmi-nand:4m(boot); root=ubi0:rootfsprintsUnknown command 'root=ubi0:rootfs'or silently dropsroot=! - Root Cause:
U-Boot's Hush shell treats an unquoted;as a command separator, endingsetenv bootargsearly and trying to execute the remainder as a shell command. - Fix: Always wrap the entire
bootargsvalue in single quotes (setenv bootargs '...') and verify the full stored value withprintenv bootargs.
Word-Loop .bss Clear Overwriting Adjacent Stack When __bss_end Is Unaligned:
- Symptom: Adding a single
static char flag;at the end of.bsscausesstart.Sto corrupt3bytes of the section immediately following__bss_end. - Root Cause: A
4-bytestrlo r2, [r0], #4loop writes a full32-bit word on its final iteration if__bss_end - __bss_startis not a multiple of4bytes. - Fix: Enforce
. = ALIGN(4); __bss_end = .;inside the linker script.bssoutput section and verify((bss_start | bss_end) & 3) == 0.
Guided Practice
Add a U-Boot memory-overlap check check_bootz_overlap(uint32_t zimg_addr, uint32_t zimg_len, uint32_t dtb_addr, uint32_t dtb_len) to verify.c: if an engineer loads a 9 MiB zImage at 0x80800000 (0x80800000 .. 0x81100000) and mistakenly loads .dtb at 0x81000000 instead of 0x83000000, what happens to the 0xD00DFEED FDT header?
Verify your overlap check catches zimg_addr + zimg_len > dtb_addr before bootz jumps into a corrupted Device Tree.
Independent Practice
Open labs/lab_m05_boot_fault_triage/ and inspect starter/core.c. Fix the three intentional bugs in decode_boot_straps(), validate_startup_abi(), and triage_vfs_boot_panic() (BMOD shift/mask, 8-byte AAPCS32 SP mask vs 4-byte mask, and major == 179 rootwait check).
Run sh check.sh to pass all 5/5 TAP version 13 checks and run ./files/lab_cli --bench to inspect CLOCK_MONOTONIC host diagnostic percentiles.
Verification Checks
→ open standalone lab workbench
1. Motivation
Early board bring-up failures rarely print polite stack traces: wrong BOOT_MODE switches produce total silence, 0x80200004 stacks crash only inside 64-bit printf, and missing rootwait panics VFS 40 ms before eMMC probes.
In this studio, you implement a deterministic C11 bring-up diagnostic engine that decodes hardware strap registers, validates AAPCS32/.bss/IVT invariants, and classifies VFS boot panics.
2. Learning objectives
- Extract
SRC_SBMR2[25:24](BMOD) andSRC_SBMR1(BOOT_CFG1/BOOT_CFG2) bitfields alongside3-wireCRTSCTSconsole deadlock detection. - Enforce
8-byteAAPCS32stack alignment (sp & 7 == 0),4-byte.bsssection bounds, and0x400SD/eMMCIVTplacement. - Classify
U-BootCONFIG_SYS_CBSIZEtruncation,NFSip=omissions, andmajor 179(mmcblk) missing-rootwaitVFSpanics.
3. Environment requirements
All automated verification steps run in unprivileged user space on a POSIX Linux host using gcc -std=c11 -Wall -Wextra -Werror and clock_gettime(CLOCK_MONOTONIC). Recorded transcripts in captures.json were generated on x86_64 running kernel 7.0.0-42-generic and prove protocol, state-machine, and memory invariants only. Physical bus timing, DMA cache coherency, and board peripheral behavior require target validation on Linux kernel 6.12 LTS (ARMv7-A Cortex-A7).
4. Required software and hardware
- Host workstation:
gcc(-std=c11 -Wall -Wextra -Werror), GNUmake,ar(binutils), and POSIX/bin/sh. - Target environment (optional hardware step, Section 13):
i.MX6ULLARMv7-Aboard (SRC_SBMR10x020D8004,SRC_SBMR20x020D801C) runningU-Boot2025.x andLinux kernel6.12.
5. Complete executable commands
learner@ksa:~/gl-e00/m05-l03$ bat script.sh File: script.sh make -B -C files ./files/lab_cli ./files/lab_cli --bench sh check.sh6. Annotated source code
files/core.c enforces the production invariants that starter/core.c breaks:
learner@ksa:~/gl-e00/m05-l03$ bat example.c File: example.c if ((sp_init & 0x7U) != 0U) errs |= STARTUP_ERR_SP_ALIGN8; if (((bss_start | bss_end) & 0x3U) != 0U) errs |= STARTUP_ERR_BSS_ALIGN4; if (ivt_offset != 0x400U) errs |= STARTUP_ERR_IVT_OFFSET;starter/core.c shifts sbmr2 by 16 instead of 24 (BMOD[25:24]), masks sp_init with 0x3U (4-byte alignment) instead of 0x7U (8-byte AAPCS32 alignment), and disables the missing-rootwait detector on major 179.
7. Expected output
Passing files/ run (sh check.sh, exit code 0):
learner@ksa:~/gl-e00/m05-l03$ bat listing.txt File: listing.txt TAP version 13 1..5 ok 1 - builds libcore.a and lab_cli cleanly with -std=c11 -Wall -Wextra -Werror ok 2 - archives core.o into libcore.a and links independent TAP verifier ok 3 - decodes SRC_SBMR2[25:24] BMOD and SRC_SBMR1 BOOT_CFG1 straps plus 3-wire CRTSCTS deadlock ok 4 - enforces ARMv7-A AAPCS32 8-byte SP alignment (sp & 0x7 == 0), 4-byte .bss bounds, and 0x400 IVT offset ok 5 - classifies truncated bootargs, missing NFS ip= config, and missing rootwait on major 179 mmcblk panics # pass 5/5CLI verification output (./files/lab_cli):
learner@ksa:~/gl-e00/m05-l03$ bat listing.txt File: listing.txt STRAPS emmc_target=3 tx_deadlocked=1 sdp_override_target=1 CRT0_ABI clean_flags=0x0 broken_flags=0xd VFS_PANIC mmc_no_rootwait_kind=3Defective starter/ run (exit code 1): emits FAIL: diagnostics on the broken contract assertions.
8. Explanation of observed behavior
Restoring (sbmr2 >> 24U) & 0x3U aligns with the i.MX6ULL System Reset Controller register map, (sp_init & 0x7U) != 0U rejects 0x80200004 odd-word stacks before LDRD faults occur, and checking strstr(bootargs, "rootwait") catches asynchronous USDHC boot races.
9. Experiment variations
- Near transfer: Add
QuadSPINOR (BOOT_CFG1[7:4] == 0x1) andECSPINOR (0x3withBOOT_CFG4) decoding todecode_boot_straps(). - Far transfer: Extend
triage_vfs_boot_panic()to validateubi.mtd=+rootfstype=ubifspairing for rawGPMISLC NANDboots.
10. Performance measurements
Recorded host benchmark (./files/lab_cli --bench, CLOCK_MONOTONIC, warmup=5, N=40 batches):
learner@ksa:~/gl-e00/m05-l03$ bat listing.txt File: listing.txt BENCH lab_m05_boot_fault_triage clock=CLOCK_MONOTONIC batches=40x500 p50_ns=12696 p95_ns=27228 p99_ns=52499 sink=3./files/lab_cli --bench measures in-memory C11 bitmask and bootargs classification speed using CLOCK_MONOTONIC (40 x 500 iterations); physical POR_B, MDIO PHY reset (>= 10 ms), and USDHC probe timings must be measured on target hardware.
11. Troubleshooting
| Symptom | Root cause | Fix |
|---|---|---|
Check 3 fails with sd=0 or sdp=5 | sbmr2 is shifted by 16 instead of 24, reading reserved zeroes instead of BMOD[25:24]. | Extract (sbmr2 >> 24U) & 0x3U in decode_boot_straps(). |
Check 4 fails with sp4=0x0 | 0x80200004 & 0x3U evaluates to 0, missing the 8-byte AAPCS32 alignment violation. | Test (sp_init & 0x7U) != 0U so any non-multiple of 8 sets STARTUP_ERR_SP_ALIGN8. |
Check 5 fails with wait=0 | The rootwait check on root_major == 179U was stubbed out. | Restore strstr(bootargs, "rootwait") == NULL returning VFS_FAULT_MMC_MISSING_ROOTWAIT. |
12. Guided questions
- Why does
decode_boot_straps()checkbmod(SRC_SBMR2[25:24]) BEFORE inspectingcfg1_hi(SRC_SBMR1[7:4])?
- *Hint 1:* What happens on physical hardware when
BOOT_CFGswitches stay set toeMMCwhile you flipBOOT_MODEto01forUUUflashing? - *Hint 2:*
BOOT_MODE = 01(Serial Downloader) and00(Fuses) override externalBOOT_CFGpins completely in the mask Boot ROM.
- Why does
triage_vfs_boot_panic()checkstrlen(bootargs) >= cbsize_limit - 1Ubefore checkingstrstr(bootargs, "root=")?
- *Hint 1:* Suppose a
1024-bytebootargsline hadroot=/dev/mmcblk1p2at byte1015, chopped off toroot=/debyCONFIG_SYS_CBSIZE. - *Hint 2:* Checking buffer-limit truncation first identifies why trailing arguments (
root=orrootwait) vanished instead of reporting a misleading syntax error.
13. Independent challenges
Implement check_bootz_regions(uint32_t zimg_start, uint32_t zimg_size, uint32_t dtb_start, uint32_t dtb_size) accounting for ARM zImage's ~4x in-place self-decompression expansion so .dtb placement too close above zImage (< 32 MiB gap) is flagged before Kernel_decompress overwrites the FDT!
14. Solutions and explanations
files/core.c decodes SRC_SBMR2[25:24] prior to SRC_SBMR1, enforces 8-byte SP (0x7U mask) + 4-byte .bss + 0x400 IVT invariants, and classifies CBSIZE truncation, NFS, and mmcblk rootwait panics across all 5/5 TAP checks.
Run locally in your terminal and check off each verification milestone.
Not started
Key takeaways
- Bare-metal
ARMv7-Astart.Smust explicitly zero[__bss_start, __bss_end)before branching tomain()becauseDDR3powers up with random bit states that corrupt uninitialized C globals. - The
ARMv7-AAAPCS32ABI mandates8-byte stack alignment (SP mod 8 == 0, enforced viabic sp, sp, #7) at public call boundaries so64-bitLDRD/STRDandprintf("%lld")va_argslots do not fault or misalign. U-BootENETTFTPfailures andbootargstruncations stem from missing RMII PHY reset pulse/settle timing (>= 10 ms) or unescaped multi-linesetenv bootargsstrings exceeding console buffer limits.Kernel panic - not syncing: VFS: Unable to mount root fsencodes the exact failure stage:unknown-block(0,0)indicates missing/truncatedroot=orCONFIG_ROOT_NFS, whereasmmcblkerror -2withoutrootwaitindicates asynchronousUSDHCprobe race.