Memory, MMC, Filesystem & Network Diagnostics
Master flat 1:1 physical DRAM safety inside U-Boot: distinguish 1/2/4-byte element commands, prove overflow-safe 64-bit LBA-to-RAM bounds across eMMC hardware and filesystem partitions, and isolate RMII Ethernet link, DHCP, ICMP, and TFTP transfer faults.
What you'll learn
- Prove that an MMC transfer stays within both its partition and its RAM destination.
- Distinguish filesystem loading from raw block reads and unit-sized memory commands.
- Separate link, address, reachability and network file-transfer failures.
Why Unprotected Physical DRAM Demands Dual-Coordinate Bounds Proofs
Inside a running Linux user-space process, writing past a buffer triggers SIGSEGV because the MMU isolates every process in its own virtual address space. Inside U-Boot 2025.x, there is no virtual-memory isolation protecting the bootloader from your commands: every address you pass to mw, mmc read, fatload, ext4load, or tftpboot is a raw 1:1 physical bus address! As Figure 1.2a (1. Unprotected 1:1 Physical DRAM Map) shows, U-Boot's own relocated .text, .data, .bss, dlmalloc heap, gd_t, and active stack live near the top of our 512 MiB DDR3 ([0x9EF00000, 0xA0000000)). Overrunning a staging window ([0x82000000, 0x84000000)) or touching unclocked peripheral MMIO silently corrupts live instructions or triggers an immediate Data Abort!
Worse still, naive C or shell bounds checks contain two classic arithmetic traps. First, testing a half-open byte window [start, end) via start + n <= end wraps modulo 2^32 when start = 0xFFFFFFF0 and n = 64 (0xFFFFFFF0 + 0x40 == 0x00000030 <= end—falsely passing!). Subtracting after checking order (n != 0U && start <= end && n <= end - start) can never overflow. Second, MMC block commands count 512-byte Logical Block Addresses (LBAs), not bytes: multiplying count * 512U in 32-bit uint32_t truncates the upper bits when count >= 0x00800000, so conversion must promote to uint64_t (uint64_t bytes = (uint64_t)count * 512U) and verify bytes <= UINT32_MAX before testing RAM fit.
Figure 1.2a. Flat 1:1 physical DRAM windows versus top-of-DRAM U-Boot state (top), and eMMC hardware areas versus software partitions with 64-bit LBA-to-byte math (bottom).
Separating eMMC Hardware Areas, Filesystem Loads & Unit-Width Commands
Look at the bottom half of Figure 1.2a: an eMMC chip exposes two distinct partition layers that engineers routinely confuse. Hardware areas (boot0, boot1, RPMB, and the User Area) are switched inside the flash controller via mmc dev <dev> <hwpart> (mmc dev 0 1 selects boot0; mmc dev 0 0 selects the User Area). Only inside the User Area does an MBR or GPT table carve software partitions 0:1 (FAT boot) and 0:2 (ext4 rootfs), where raw mmc read dst lba cnt counts 512 B sectors while fatload / ext4load walk filesystem metadata by filename and publish the exact byte count into ${filesize}.
mental model: Staging MMC sectors into U-Boot DRAM without bounds math is like forklifting 512-kilogram pallets (LBAs) into an unfenced aircraft hangar where the active control-tower racks sit along the far wall: mistaking 2048 pallets for 2048 single-kilogram boxes—or picking Bay boot0 instead of Bay 0:1—destroys live equipment silently.
Where it stops working: Unlike physical pallets, 32-bit unsigned address arithmetic wraps silently past 0xFFFFFFFF back to 0x00000000 unless interval bounds use subtraction after ordering checks.
definition (Half-Open Physical Windows, LBA Coordinates & Layered Network Triage): A half-open memory window [base, end) contains end - base addressable bytes (base inclusive, end exclusive) and safely admits n non-zero bytes iff base <= end && n <= end - base. Unit-suffixed monitor commands (md.b/mw.b/cmp.b = 1 B, .w = 2 B, .l = 4 B) interpret their count argument as elements, not bytes (md.l addr 0x100 reads 1024 B). Network image triage separates L1 RMII/MDIO link state, L2/L3 address acquisition (setenv autoload no; dhcp) and ICMP reachability (ping), and L4 UDP:69 tftpboot transfer completion (${filesize} updated only on final block ACK).
Step through all four validation gates in the interactive diagram below:
- Step 1. Step 1: Pin the MMC device and hardware area (mmc dev 0 0) and inspect MBR/GPT bounds via mmc part.
- Step 2. Step 2: Prove LBA range fit (count <= blocks - lba) and widen bytes = (uint64_t)count * 512U before 32-bit narrowing.
- Step 3. Step 3: Check destination fit (bytes <= ram_end - dst) inside a reviewed free bdinfo DRAM interval.
- Step 4. Step 4: Snapshot ${filesize} immediately after load/tftpboot and verify cross-transport identity with cmp.b.
Figure 1.2b. Validate four independent coordinates on every media diagnostic: hardware area, LBA partition bound, 64-bit byte product, and half-open DRAM window.
Element-Width Multipliers & Four-Layer Ethernet TFTP Diagnostics
Study Figure 1.2b before running memory or network commands on a target board. On the left, passing ${filesize} (bytes) into cmp.l or mw.l multiplies the span by 4x (0x100 words = 1024 B), comparing or overwriting 3x past the end of the image—always pair ${filesize} with byte-granularity cmp.b! On the right, trace why *"server answers ping, yet tftpboot fails"* is completely expected: ping exercises ARP plus ICMP Echo (IP protocol 1), whereas tftpboot opens UDP port 69 (tftpd daemon, export root path, file permissions, host firewall, and 512 B lockstep DATA/ACK blocks—2048 round-trips = 1.024 s of pure RTT at 0.5 ms per block for 1 MiB). Setting setenv autoload no before dhcp acquires an IPv4 lease cleanly without immediately attempting an unwanted PXE/BOOTP file download.
Figure 1.2b. Element-width command multipliers (left) and the four-layer U-Boot /TFTP network fault-isolation ladder (right).
| Transfer Mechanism | Coordinate Unit & Protocol Work | Failure & Overwrite Boundary | Engineering Selection Rule |
|---|---|---|---|
Raw mmc read / write | 512 B LBA start + block count; 0 filesystem lookups | Supplying byte count instead of 512 B blocks overruns partition and RAM by 512x! | Fixed-offset unformatted artifacts (u-boot.imx @ 0x400, raw env) |
fatload / ext4load | dev:part (0:1, 0:2) + file path; sets ${filesize} | Fails on corrupt superblock/FAT; still clobbers top-of-DRAM if file exceeds free window | Standard local boot loading zImage and .dtb by path |
tftpboot over RMII | IPv4/UDP:69 lockstep blocks (512 B default); sets ${filesize} | ping proves ICMP only; aborted TFTP leaves partial/stale bytes at dst! | Fast workstation kernel/DTB iteration prior to eMMC flashing |
mmc / fatload / tftpboot(1) GL-E03 Quick Reference mmc / fatload / tftpboot(1) NAME md, mw, cmp, mmc, fatload, ext4load, dhcp, tftpboot - U-Boot media & RAM tools UNIT CONTRACTS md.b / mw.b / cmp.b : count = 1-byte elements (match with ${filesize}!) md.w / mw.w / cmp.w : count = 2-byte halfwords (span = 2 * count bytes) md.l / mw.l / cmp.l : count = 4-byte words (span = 4 * count bytes) mmc read dst blk cnt: blk, cnt in 512-byte LBAs (bytes = (uint64_t)cnt * 512) INVARIANTS 1. Check `bdinfo` (`relocaddr`, `sp`) before choosing scratch DRAM addresses. 2. `setenv autoload no` isolates DHCP lease acquisition from TFTP file fetch. Kernel Systems Academy Lesson 1.2 mmc / fatload / tftpboot(1) GL-E03 quick reference · full manual page: man 1 mmc / fatload / tftpboot Walk through inspect-media.cmd below: it checks bdinfo first, pins User Area mmc dev 0 0, loads zImage from 0:1 into 0x82000000, snapshots kernel_size before tftpboot overwrites ${filesize}, fetches the workstation copy into disjoint 0x84000000, and proves byte-for-byte equality with cmp.b. (Note too that U-Boot's nfs command merely copies one file into RAM—it is unrelated to the Linux kernel mounting root=/dev/nfs later in Module m05.)
learner@ksa:~/gl-e03/m01-l02$ bat -H 3 -H 8 -H 9 -H 11 -H 12 -H 13 -H 14 -H 15 inspect-media.cmd File: inspect-media.cmd bdinfo mmc list mmc dev 0 0 mmc part fatls mmc 0:1 / ext4ls mmc 0:2 / # Example RAM addresses require a reviewed free-memory map. fatload mmc 0:1 0x82000000 zImage setenv kernel_size ${filesize} md.b 0x82000000 0x40 setenv autoload no dhcp ping ${serverip} tftpboot 0x84000000 zImage cmp.b 0x82000000 0x84000000 ${kernel_size} # Alternative transport, not a kernel root mount: # nfs 0x84000000 ${serverip}:/srv/boot/zImage- Explicitly select hardware partition 0 (User Area) on MMC 0 so leftover boot0 state cannot redirect reads.
- Snapshot ${filesize} into kernel_size immediately; the subsequent tftpboot command will overwrite ${filesize}.
- Compare the two non-overlapping 32 MiB windows using byte-unit cmp.b (never cmp.l with a byte count!).
Proving Two-Domain LBA & Half-Open RAM Bounds in ISO C11
In m01-l02.c below, we prove both coordinate-system invariants in pure ISO C11 integer arithmetic without dereferencing hardware addresses. Inspect ram_fits() and read_fits():
ram_fits(start, n, end)rejectsn == 0U, checksstart <= end, and subtractsn <= end - start—catchingram_fits(0xFFFFFFF0U, 64U, UINT32_MAX)cleanly wherestart + nwould wrap to0x30.read_fits()first checksLBAbounds (count <= blocks - lba), widens(uint64_t)count * 512Ubefore multiplying, and rejectsbytes > UINT32_MAX(count = UINT32_MAXyields2,199,023,255,040 B, which would truncate to0xFFFFFE00in32-bit math!).
learner@ksa:~/gl-e03/m01-l02$ bat -H 8 -H 9 -H 10 -H 14 -H 15 -H 16 -H 17 -H 18 m01-l02.c File: m01-l02.c #include <assert.h> #include <inttypes.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <string.h> _Static_assert(sizeof(uint32_t) == 4, "32-bit format words required"); static int ram_fits(uint32_t start, uint32_t n, uint32_t end) { return n != 0U && start <= end && n <= end - start; } static int read_fits(uint32_t lba, uint32_t count, uint32_t blocks, uint32_t dst, uint32_t ram_end) { if (count == 0U || lba > blocks || count > blocks - lba) return 0; uint64_t bytes = (uint64_t)count * 512U; return bytes <= UINT32_MAX && ram_fits(dst, (uint32_t)bytes, ram_end); } int main(void) { assert(read_fits(2048U, 2048U, 8192U, 0x82000000U, 0x84000000U)); assert(read_fits(8191U, 1U, 8192U, 0x82000000U, 0x84000000U)); assert(!read_fits(8192U, 1U, 8192U, 0x82000000U, 0x84000000U)); assert(!ram_fits(0xFFFFFFF0U, 64U, UINT32_MAX)); assert(!read_fits(0U, UINT32_MAX, UINT32_MAX, 0U, UINT32_MAX)); printf("blocks=2048 bytes=%" PRIu64 "\n", (uint64_t)2048U * 512U); puts("last_block=accepted partition_overrun=rejected wrap=rejected"); return 0; }- Verify start <= end BEFORE subtracting end - start so 32-bit unsigned wraparound near UINT32_MAX is impossible.
- Cast count to uint64_t before multiplying by 512U and guard bytes <= UINT32_MAX prior to narrowing.
Executing the Bounds Verifier & Boundary-Edge Mutations
Compile and run m01-l02.c below. Notice how read_fits(8191U, 1U, 8192U, ...) (last_block=accepted) and !read_fits(8192U, 1U, 8192U, ...) (partition_overrun=rejected) pin the exact off-by-one boundary of an 8192-block partition (LBAs 0..8191). Test the exact RAM ceiling too: dst = 0x83F00000U with 2048 blocks (0x100000 bytes) ends right at 0x84000000U and passes, whereas dst = 0x83F00001U fails by 1 byte!
learner@ksa:~/gl-e03/m01-l02gcc -std=c11 -Wall -Wextra -Werror \ m01-l02.c -o m01-l02learner@ksa:~/gl-e03/m01-l02./m01-l02blocks=2048 bytes=1048576last_block=accepted partition_overrun=rejected wrap=rejectedlearner@ksa:~/gl-e03/m01-l02learner@ksa:~/gl-e03/m01-l02strace -e trace=openat,read,write,exit_group \./m01-l02openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\243\2\0\0\0\0\0"..., 832) = 832write(1, "blocks=2048 bytes=1048576\nlast_b"..., 87) = 87exit_group(0) = ?+++ exited with 0 +++Building Your Board Memory Ledger & Avoiding Stale Buffers
Why must an embedded engineer write down a board memory-map ledger (kernel_addr_r, fdt_addr_r, ramdisk_addr_r, scriptaddr, and bdinfo's relocaddr/sp) before scripting boot commands? Because non-overlapping download buffers are necessary—and still only half of the handoff story:
- When a
tftpbootorfatloadaborts mid-transfer, DRAM still holds whatever stale or half-written bytes sat at0x82000000earlier! Jumping to0x82000000just becausemd.l 0x82000000 4looks like ARM instructions boots an unverified ghost image. - Even valid compressed
zImage+.dtbdownloads need additional decompression working headroom oncezImageunpacksImagein place.
Keep integer bounds checks on the host separate from target bdinfo + cmp.b logs, and never run md/mw blindly across peripheral MMIO banks (0x02000000..0x021FFFFF) where read-sensitive FIFO registers can drop hardware state. Later: Lesson m01-l03 combines these guarded loads into bootz and signed FIT (bootm) handoff scripts that block stale buffers by construction.
Common Production Pitfalls
warning: Symptom: Running mmc write 0x82000000 0x800 0x100000 to write a 1 MiB (0x100000 byte) image reports OK, yet destroys 512 MiB of adjacent ext4 rootfs sectors! Root Cause: Raw mmc read/mmc write counts 512-byte LBAs, not bytes (0x100000 blocks * 512 B = 512 MiB!). Fix: Convert byte lengths to 512 B blocks with ceiling rounding (blocks = (bytes + 511) / 512, i.e., 0x800 blocks for 1 MiB) and verify lba + blocks stays inside mmc part bounds before writing.
warning: Symptom: ping ${serverip} succeeds with host 192.168.10.1 is alive, yet tftpboot 0x84000000 zImage prints TFTP error: 'File not found' or times out on T T T. Root Cause: ping tests L2/L3 ARP + ICMP reachability only; TFTP additionally requires a running UDP:69 daemon, host firewall permission on ephemeral server ports, world-readable file mode inside the tftpd root directory, and a unique board ethaddr MAC. Fix: Debug L4 tftpd logs and UDP:69 firewall rules independently of ping, and never boot 0x84000000 until tftpboot exits 0 and updates ${filesize}.
Practice & Retrieval
Guided Practice: Sizing Ceiling Blocks & Exact Window Fit
A custom zImage measures 6,554,100 bytes (6 MiB + 404 B) and must be written via raw mmc write into a 16,384-block (8 MiB) recovery partition starting at LBA 4096, after staging into [0x82000000, 0x83000000) (16 MiB). Step 1 (Ceiling LBA Count): Compute blocks = (6554100 + 511) / 512 = 12801 (0x3201 blocks = 6,554,112 bytes—truncating 6554100 / 512 = 12800 would chop off the last 404 bytes!). Step 2 (Dual Bounds Check): Verify read_fits(4096U, 12801U, 20480U, 0x82000000U, 0x83000000U) (12801 <= 20480 - 4096 = 16384 and 6554112 <= 16777216).
Independent Practice: Disjoint Multi-Artifact Staging Auditor (stage_map_audit.c)
Extend m01-l02.c into stage_map_audit.c validating three simultaneous U-Boot buffers—kernel [k_dst, k_dst + k_len), fdt [f_dst, f_dst + f_len), and initrd [i_dst, i_dst + i_len)—inside usable low DRAM [0x80000000U, reloc_floor) (reloc_floor = 0x9EF00000U). Reject any zero-length, wrapping, out-of-floor, or pairwise-overlapping interval, and assert both a valid (0x82000000, 8 MiB), (0x83000000, 64 KiB), (0x83800000, 12 MiB) triple and a colliding 9 MiB kernel that overruns 0x83000000 by 1 MiB.
Key takeaways
U-Bootexecutes in flat1:1physical memory withoutMMUisolation: every media read ormwmust stay strictly inside free DRAM belowbdinfo's relocated code, heap,gd_t, and stack.- Distinguish unit-suffixed element counts (
md.b/cmp.b=1 B,.w=2 B,.l=4 B),eMMChardware areas (mmc dev 0 1boot0vs0 0User Area),MBR/GPTpartitions (0:1,0:2), and512 BLBAs. - Guard both intervals without overflow: check
lba <= blocks && count <= blocks - lba, widenbytes = (uint64_t)count * 512U, checkbytes <= UINT32_MAX, and checkdst <= end && bytes <= end - dst. - Isolate network bring-up layer by layer (
RMIIlink ->autoload=no; dhcp->pingICMP->tftpbootUDP:69+${filesize}snapshot ->cmp.b). - The raw command's block count must be multiplied by its device block size.
- Reachability, server service, file selection and completed transfer are separate checks.
- Check ordering before subtraction, then compare the remaining capacity.