End-to-End Embedded Workbench Preflight Capstone
Unify zImage/FDT magic checks, ELF32 armhf + PT_INTERP rootfs closure, and .ko vermagic validation into one sub-millisecond host C11 pre-deployment gate.
What you'll learn
- Verify
ARMzImage(0x016F2818at offset0x24, little-endian) and FlattenedDevice Tree.dtb(0xD00DFEEDat offset0x00, big-endian) binary headers prior toTFTPexport. - Integrate
ELF32armhfPT_INTERProotfs checks and.modinfovermagictoken-boundary audits into a single zero-false-positive pipeline. - Complete the GL-E00 Capstone Studio (
lab_m06_workbench_preflight_capstone) and measureCLOCK_MONOTONIChost preflight throughput.
Closing the Loop Across All Six GL-E00 Workbench Foundations
Over six modules, you have dismantled every host-side failure mode that trips up embedded Linux engineers before they write a single line of ARMv7-A bare-metal or driver code: VM bridges & udev rules (M01), FHS permissions, numeric-owner tarballs & LBA 2 IVT offsets (M02), APT, dual-NIC routing, TFTP & NFS no_root_squash (M03), Linux kernel CodingStyle & LIFO goto C11 hygiene (M04), 115200 8N1 consoles, BOOT_MODE straps, UUU & AAPCS32/VFS triage (M05), and ELF32/vermagic ABI contracts (M06).
Production BSP teams never rely on human memory to check all of these before copying files into /srv/tftp and /srv/nfs/rootfs. Instead, a deploy-check target runs a deterministic preflight gate on the Linux host that inspects the actual binary headers of zImage, .dtb, user-space ELF executables, and .ko modules — rejecting mismatched artifacts in < 1 ms!
Figure 6.3a. Every artifact entering /srv/tftp and /srv/nfs/rootfs is header-verified on the host before the board reboots.
mental model: A host preflight gate works like an avionics pre-takeoff checklist at the hangar door: catching a mismatched fuel grade, unlocked hatch, or missing chart in 2 milliseconds on the ground beats debugging a flameout 30 seconds after liftoff over a 115200 radio.
Where it stops working: Host preflight auditing proves binary ABI, magic headers, PT_INTERP closure, and vermagic alignment 100%, whereas electrical pinmux contention, IRQ latency, and bus waveforms still require live verification on the i.MX6ULL board.
definition (Flattened Device Tree (FDT) Magic (0xD00DFEED)): The mandatory big-endian 32-bit magic number (0xD0, 0x0D, 0xFE, 0xED at byte offset 0x00 of struct fdt_header) emitted by the Device Tree compiler (dtc -I dts -O dtb) that U-Boot's bootz command and Linux kernel early boot inspect before parsing board hardware topology.
- Step 1. Note the endianness contrast: ARM zImage magic is little-endian, whereas FDT .dtb headers are big-endian!
- Step 2. Rejecting x86_64, soft-float, and missing-interpreter binaries eliminates target execve surprises.
- Step 3. Comparing against the staged kernel's release file guarantees zImage and .ko never drift apart.
- Step 4. Your workbench is now ready for bare-metal ARMv7-A (GL-E01) through Linux 6.12 drivers (GL-E04..E07).
Figure 6.3b. Audit zImage (0x016F2818), FDT (0xD00DFEED), ELF32 armhf PT_INTERP, and .ko vermagic before boot!
Binary Magic Signatures Across zImage, FDT .dtb, ELF32, and .ko
Notice a subtle endianness detail when inspecting /srv/tftp boot artifacts in C11 on a little-endian x86_64 host! Inside an ARM 32-bit zImage (arch/arm/boot/compressed/head.S), offset 0x24 stores the little-endian 32-bit magic 0x016F2818 (bytes 18 28 6F 01), followed at 0x28 and 0x2C by compressed start/end offsets. Conversely, the Flattened Device Tree specification (devicetree.org) stores all fdt_header integers in network big-endian byte order: bytes 0..3 are D0 0D FE ED (0xD00DFEED), and bytes 4..7 hold big-endian totalsize!
Reading uint32_t endianness explicitly via byte shifts (((uint32_t)b[0] << 24) | ... for big-endian FDT, (uint32_t)b[0] | ((uint32_t)b[1] << 8) ... for little-endian zImage and ELF32) avoids unaligned-pointer UB (Undefined Behavior in ISO C11) AND works identically regardless of host CPU endianness!
Figure 6.3b. Byte-shift endian readers parse zImage (LE), FDT .dtb (BE), and ELF32 (LE) without alignment Undefined Behavior.
| Staged Artifact | Offset & Endianness | Expected Signature | Failure Caught on Host |
|---|---|---|---|
/srv/tftp/zImage | Offset 0x24, Little-Endian | 0x016F2818 (end > start) | Copying uncompressed Image, uImage, or x86 bzImage to bootz |
/srv/tftp/board.dtb | Offset 0x00, Big-Endian | 0xD00DFEED (totalsize <= file_len) | Copying uncompiled ASCII .dts or truncated TFTP file (Bad Linux ARM zImage/FDT!) |
rootfs/usr/bin/* | Elf32_Ehdr (0x00..0x33), LE | CLASS32, EM_ARM(40), 0x400, valid PT_INTERP | Host gcc (ENOEXEC), gnueabi soft-float, or missing /lib/ld-linux-armhf.so.3 (ENOENT) |
rootfs/lib/modules/**/*.ko | .modinfo NUL strings | license=GPL* & vermagic=<rel> ... ARMv7 p2v8 | KDIR host contamination or -dirty release mismatch (Invalid module format) |
learner@ksa:~/gl-e00/m06-l03$ bat -H 11 -H 19 workbench_preflight_manifest.h File: workbench_preflight_manifest.h /* SPDX-License-Identifier: GPL-2.0 */ #ifndef KSA_WORKBENCH_PREFLIGHT_MANIFEST_H #define KSA_WORKBENCH_PREFLIGHT_MANIFEST_H #include <stdint.h> #define ARM_ZIMAGE_MAGIC_OFFSET 0x24U #define ARM_ZIMAGE_MAGIC_LE 0x016F2818U #define FDT_MAGIC_BE 0xD00DFEEDU static inline uint32_t ksa_read_le32(const uint8_t *p) { return (uint32_t)p[0] | ((uint32_t)p[1] << 8U) | ((uint32_t)p[2] << 16U) | ((uint32_t)p[3] << 24U); } static inline uint32_t ksa_read_be32(const uint8_t *p) { return ((uint32_t)p[0] << 24U) | ((uint32_t)p[1] << 16U) | ((uint32_t)p[2] << 8U) | (uint32_t)p[3]; } #endif /* KSA_WORKBENCH_PREFLIGHT_MANIFEST_H */- Byte-shift little-endian reader safely extracts ARM zImage 0x016F2818 without unaligned pointer casts.
- Big-endian reader decodes FDT 0xD00DFEED magic and totalsize directly from raw .dtb bytes.
dtc(1) / mkimage(1) / file(1)(1) GL-E00 Quick Reference dtc(1) / mkimage(1) / file(1)(1) SYNOPSIS dtc -I dts -O dtb -o imx6ull-board.dtb imx6ull-board.dts dtc -I dtb -O dts imx6ull-board.dtb | head -n 25 # Decompile binary .dtb back to readable DTS! file /srv/tftp/zImage /srv/tftp/imx6ull-board.dtb PRE-DEPLOYMENT CHECKLIST (GL-E00 -> GL-E01..E07) 1. /srv/tftp/zImage 'ARM OpenFirmware FORTH' / 'Linux kernel ARM boot executable zImage (little-endian)' 2. /srv/tftp/*.dtb 'Device Tree Blob version 17' (0xD00DFEED big-endian) 3. /srv/nfs/rootfs UID 0:0 ownership, /etc/exports has (rw,sync,no_root_squash,no_subtree_check) 4. Staged ELFs & .ko EM_ARM(40) + hard-float(0x400) + /lib/ld-linux-armhf.so.3 + matching vermagic Kernel Systems Academy Lesson 6.3 dtc(1) / mkimage(1) / file(1)(1) GL-E00 quick reference · full manual page: man 1 dtc(1) / mkimage(1) / file(1) Running the Unified Boot-Blob, ELF32, and Vermagic Gate in C11
In verify.c, we assemble a mini end-to-end staging check validating ARM zImage (0x016F2818 LE at 0x24) and .dtb (0xD00DFEED BE at 0x00 + totalsize), rejecting an ASCII .dts file accidentally copied as .dtb, and confirming clean alignment across all four deployment gates.
Then step into lab_m06_workbench_preflight_capstone to complete your full C11 pre-deployment auditor across ELF32 armhf, .modinfo vermagic, and zImage/.dtb blobs!
learner@ksa:~/gl-e00/m06-l03$ bat -H 21 -H 25 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 rd_le32(const uint8_t *p) { return (uint32_t)p[0] | ((uint32_t)p[1] << 8U) | ((uint32_t)p[2] << 16U) | ((uint32_t)p[3] << 24U); } static uint32_t rd_be32(const uint8_t *p) { return ((uint32_t)p[0] << 24U) | ((uint32_t)p[1] << 16U) | ((uint32_t)p[2] << 8U) | (uint32_t)p[3]; } static bool check_zimage_dtb(const uint8_t *zimg, size_t zlen, const uint8_t *dtb, size_t dlen) { if (zlen < 0x30U || rd_le32(zimg + 0x24U) != 0x016F2818U) return false; if (rd_le32(zimg + 0x2CU) <= rd_le32(zimg + 0x28U)) return false; if (dlen < 40U || rd_be32(dtb) != 0xD00DFEEDU) return false; uint32_t fdt_size = rd_be32(dtb + 4U); return fdt_size >= 40U && fdt_size <= dlen; } int main(void) { uint8_t zimg[64] = {0}; uint8_t dtb_ok[64] = {0}; const uint8_t dts_text[64] = "/dts-v1/;\n/ { compatible = \"ksa,board\"; };\n"; /* Populate LE zImage magic 0x016F2818 @ 0x24, start=0, end=0x400000 */ zimg[0x24] = 0x18U; zimg[0x25] = 0x28U; zimg[0x26] = 0x6FU; zimg[0x27] = 0x01U; zimg[0x2E] = 0x40U; /* Populate BE FDT magic 0xD00DFEED @ 0x00, totalsize = 64 (0x00000040) @ 0x04 */ dtb_ok[0] = 0xD0U; dtb_ok[1] = 0x0DU; dtb_ok[2] = 0xFEU; dtb_ok[3] = 0xEDU; dtb_ok[7] = 64U; bool valid_pair = check_zimage_dtb(zimg, sizeof(zimg), dtb_ok, sizeof(dtb_ok)); bool text_dts_rejected = !check_zimage_dtb(zimg, sizeof(zimg), dts_text, sizeof(dts_text)); if (!valid_pair || !text_dts_rejected) return 1; printf("PREFLIGHT_BLOBS zimage_magic=0x%08X fdt_magic=0x%08X valid_pair=%d dts_text_rejected=%d\n", rd_le32(zimg + 0x24U), rd_be32(dtb_ok), valid_pair ? 1 : 0, text_dts_rejected ? 1 : 0); return 0; }- Verifies little-endian ARM zImage magic 0x016F2818 at 0x24 and non-empty compressed payload span.
- Verifies big-endian FDT magic 0xD00DFEED and ensures totalsize fits inside the downloaded file.
Confirming Little-Endian zImage and Big-Endian FDT Validation
Notice how check_zimage_dtb() rejects dts_text instantaneously because ASCII "/dts" (0x2F647473) != 0xD00DFEED, AND checks fdt_size <= dlen so a half-written or truncated TFTP .dtb file never reaches bootz.
Combined with ELF32 armhf PT_INTERP and .ko vermagic checks in the Capstone Lab, your host build script can validate an entire embedded release directory in microseconds.
learner@ksa:~/gl-e00/m06-l03gcc -std=c11 -Wall -Wextra -Werror verify.c -o verifylearner@ksa:~/gl-e00/m06-l03./verifyPREFLIGHT_BLOBS zimage_magic=0x016F2818 fdt_magic=0xD00DFEED valid_pair=1 dts_text_rejected=1learner@ksa:~/gl-e00/m06-l03learner@ksa:~/gl-e00/m06-l03strace -e trace=write,exit_group ./verifywrite(1, "PREFLIGHT_BLOBS zimage_magic=0x0"..., 94) = 94exit_group(0) = ?+++ exited with 0 +++Common Deployment Mismatches Between bootz, bootm, and FDT
With GL-E00 complete, you own a repeatable, first-principles Linux embedded engineering workbench: isolated dual-NIC TFTP/NFS networking, udev-stabilized USB/serial tools, Linux kernel CodingStyle C11 discipline, 115200 8N1 + UUU bring-up fluency, and automated ELF32/vermagic/FDT preflight gates.
Carry this preflight mindset straight into GL-E01 (imx6ull-baremetal-core), where you will write ARMv7-A startup assembly, IVT/DCD headers, and bare-metal drivers from reset vector 0x00000000.
Passing zImage to U-Boot bootm Instead of bootz (or Vice Versa):
- Symptom:
U-BootprintsWrong Image Format for bootm command / ERROR: can't get kernel image!right aftertftp 80800000 zImagesucceeds. - Root Cause:
bootmexpects a legacy64-byteuImageheader (0x27051956magic frommkimage) orFITimage, whereasbootzboots a rawARMzImage(0x016F2818at0x24) directly! - Fix: Always pair
ARM32-bitzImagewithbootz 0x80800000 - 0x83000000(note the-placeholder when no separateinitramfsis used).
Decompiling or Editing the Wrong .dtb File in arch/arm/boot/dts/nxp/imx/:
- Symptom: You modify a
Device Tree.dtsfile and runmake dtbs, yet/proc/device-tree/on the booted board shows zero changes! - Root Cause:
Linux kernel6.12 organizesARMvendor DTs underarch/arm/boot/dts/nxp/imx/; copying from a stale top-level build directory or editing an.dtsinot#included by your board's.dtsdeploys the old blob. - Fix: Run
dtc -I dtb -O dts /srv/tftp/board.dtb | grep -A4 your_nodeon the staged/srv/tftpfile before rebooting the board!
Guided Practice
Extend check_zimage_dtb() in verify.c to also reject legacy uImage headers (0x27051956 big-endian at offset 0x00) with a specific diagnostic advising the operator to switch from bootz to bootm or deploy arch/arm/boot/zImage.
Test all three cases (zImage, uImage, and truncated .dtb where fdt_size = 4096 on a 512-byte file) and confirm zero false positives.
Independent Practice
Open labs/lab_m06_workbench_preflight_capstone/ and examine starter/core.c. Repair all three intentional preflight defects: (1) reject soft-float 0x200 so EF_ARM_ABI_FLOAT_HARD (0x400) is strictly required, (2) verify PT_INTERP matches rootfs_interp (no silent pass when rootfs_interp is missing!), and (3) enforce exact token-boundary vermagic release matching (vm[rlen] == ' ') so -dirty modules are caught.
Run sh check.sh (5/5 TAP version 13 checks passing) and ./files/lab_cli --bench to complete the GL-E00 Workbench Preflight Capstone!
Verification Checks
→ open standalone lab workbench
1. Motivation
Deploying unverified cross-build outputs into /srv/tftp and /srv/nfs/rootfs turns single-line build mistakes — an uncompiled .dts, a soft-float 0x200 tool, a missing /lib/ld-linux-armhf.so.3 symlink, or a -dirty .ko — into bewildering target boot failures.
In this GL-E00 Capstone Project, you build a complete C11 binary preflight gate that validates every boot, user-space, and kernel-module artifact in microseconds before target deployment.
2. Learning objectives
- Verify
ARMzImage(0x016F2818LE) and FlattenedDevice Tree.dtb(0xD00DFEEDBE +totalsize) headers safely inpreflight_boot_blobs(). - Audit
52-byteElf32_Ehdr+Elf32_Phdrbounds,EM_ARM (40),EF_ARM_ABI_FLOAT_HARD (0x400), andPT_INTERProotfs resolution inpreflight_elf32_armhf(). - Enforce
GPLmodule licensing,ARMv7 p2v8architecture flags, and exact token-boundedUTS_RELEASEmatching inpreflight_ko_modinfo().
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): Complete
GL-E00Linux host/srv/tftp+/srv/nfs/rootfsbench servingi.MX6ULLARMv7-AU-Boot2025.x andLinux kernel6.12.
5. Complete executable commands
learner@ksa:~/gl-e00/m06-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/m06-l03$ bat example.c File: example.c eflags = rd_le32(elf + 0x24U); if ((eflags & 0x00000400U) == 0U || (eflags & 0x00000200U) != 0U) return PREFLIGHT_ERR_FLOAT_ABI; /* ... */ if (!vm || strncmp(vm, expected_release, rlen) != 0 || vm[rlen] != ' ') return PREFLIGHT_ERR_VERMAGIC_RELEASE;starter/core.c masks eflags with 0x600 (accepting soft-float 0x200 binaries!), ignores rootfs_available_interp when checking PT_INTERP, and omits vm[rlen] != ' ' (allowing 6.12.0-ksa-dirty modules to slip past 6.12.0-ksa!).
7. Expected output
Passing files/ run (sh check.sh, exit code 0):
learner@ksa:~/gl-e00/m06-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 - validates little-endian ARM zImage (0x016F2818 @ 0x24) and big-endian FDT .dtb (0xD00DFEED @ 0x00) ok 4 - rejects x86_64 ELFs, soft-float 0x200 binaries, and missing rootfs PT_INTERP dynamic linkers ok 5 - enforces GPL license, ARMv7 p2v8 tokens, and exact token-bounded vermagic release (rejecting -dirty) # pass 5/5CLI verification output (./files/lab_cli):
learner@ksa:~/gl-e00/m06-l03$ bat listing.txt File: listing.txt CAPSTONE_BLOBS status=0 CAPSTONE_ELF armhf_ok=0 softfloat_err=4 missing_interp_err=5 CAPSTONE_KO clean_ok=0 dirty_err=6Defective starter/ run (exit code 1): emits FAIL: diagnostics on the broken contract assertions.
8. Explanation of observed behavior
When all three checks are tightened, preflight_elf32_armhf() guarantees VFP hard-float register ABI compatibility and /lib/ld-linux-armhf.so.3 presence, preflight_ko_modinfo() blocks -dirty and non-ARMv7/p2v8 modules prior to finit_module(), and preflight_boot_blobs() guards bootz against malformed kernel/DTB files.
9. Experiment variations
- Near transfer: Extend
preflight_elf32_armhf()to accept static binaries (ET_EXECwith zeroPT_INTERPheaders when-staticis explicitly allowed via flag). - Far transfer: Walk
/srv/nfs/rootfsrecursively with POSIXnftw()to audit every executable and.kofile in a single host CLI command.
10. Performance measurements
Recorded host benchmark (./files/lab_cli --bench, CLOCK_MONOTONIC, warmup=5, N=40 batches):
learner@ksa:~/gl-e00/m06-l03$ bat listing.txt File: listing.txt BENCH lab_m06_workbench_preflight_capstone clock=CLOCK_MONOTONIC batches=40x500 p50_ns=37127 p95_ns=38508 p99_ns=41995 sink=0./files/lab_cli --bench records CLOCK_MONOTONIC host execution time across 40 x 500 complete 3-stage preflight sweeps (zImage/.dtb + ELF32 + .modinfo), demonstrating sub-millisecond CI/Makefile overhead on the host workstation.
11. Troubleshooting
| Symptom | Root cause | Fix |
|---|---|---|
Check 4 fails on e_sf (soft-float not rejected) | 0x05000200 & 0x600 is non-zero, letting EF_ARM_ABI_FLOAT_SOFT pass. | Require (eflags & 0x400U) != 0U && (eflags & 0x200U) == 0U. |
Check 4 fails when rootfs_available_interp is NULL | PT_INTERP string was never compared against rootfs_available_interp. | Return PREFLIGHT_ERR_MISSING_INTERP if !rootfs_available_interp or strcmp != 0. |
Check 5 fails on ko_dirty | strncmp(vm, "6.12.0-ksa", 10) returns 0 on "6.12.0-ksa-dirty ...". | Require vm[rlen] == ' ' immediately after the expected release string. |
12. Guided questions
- Why does
preflight_elf32_armhf()verifymemchr(elf + ioff, '\0', isz) != NULLBEFORE callingstrcmp((const char *)(elf + ioff), ...)?
- *Hint 1:* What if a corrupted or fuzz-crafted
ELFbinary hasPT_INTERPp_filesz = 24filled with non-zero bytes up to the end ofelf? - *Hint 2:*
strcmpscans until it hits'\0';memchr(..., '\0', isz)proves a NUL terminator exists inside the bounds-checked[ioff, ioff + isz)slice first!
- Why do
rd_le32()andrd_be32()assembleuint32_tvalues fromuint8_tbyte shifts instead of casting*(const uint32_t *)(buf + offset)?
- *Hint 1:* What does ISO C11 say when
buf + offsetis not4-byte aligned or aliases acharbuffer? - *Hint 2:* Direct
uint32_t *casts risk alignment faults/Undefined Behavior and silently depend on host CPU endianness, whereas byte shifts are 100% portable C11.
13. Independent challenges
Extend preflight_ko_modinfo() to parse depends=<mod1>,<mod2> from .modinfo and verify against a caller-supplied array of staged .ko module names that every prerequisite module is present under /srv/nfs/rootfs/lib/modules/<release>/ before depmod -a runs.
14. Solutions and explanations
The reference files/core.c combines endian-explicit zImage/FDT header checks, bounds-safe ELF32 armhf (0x400) + PT_INTERP verification, and token-bounded .modinfo vermagic/GPL validation to pass 5/5 TAP checks cleanly.
Run locally in your terminal and check off each verification milestone.
Not started
Key takeaways
- A complete embedded workbench preflight gate validates boot blobs (
ARMzImagemagic0x016F2818at0x24and big-endianDevice Tree.dtbmagic0xD00DFEEDat0x00), user-spaceELF32armhfbinaries, and.kovermagicbefore target deployment. - Every staged target executable must satisfy
ELFCLASS32,EM_ARM (40),EF_ARM_ABI_FLOAT_HARD (0x400), and physical existence of itsPT_INTERPloader andDT_NEEDEDlibraries inside/srv/nfs/rootfs. - Every staged
.komodule under/srv/nfs/rootfs/lib/modules/<release>/must carrylicense=GPL*and avermagicmatching<release>on an exact token boundary plusARMv7 p2v8. - Executing deterministic binary preflight checks on the Linux host turns
30-second reboot-and-panic mysteries into sub-millisecond build-time diagnostics with zero target flash wear.