SD, eMMC & Raw NAND Storage Topologies and UUU Provisioning

Contrast FTL-managed block storage (SD/eMMC boot0 + LBA 2 IVT) against raw SLC NAND (MTD eraseblocks, BBT, UBI/UBIFS) and trace UUU two-stage SDP-to-Fastboot flashing.

20 minfree previewLinux 6.12C11glibc 2.39→ module 5 lab
What you'll learn
  • Contrast SD/eMMC 512-byte LBA + boot0 hardware partitions against raw SLC NAND eraseblock, page/OOB, MTD, and UBI/UBIFS geometry.
  • Analyze why placing FAT32 or ext4 directly onto raw NAND fails immediately due to factory bad blocks and missing wear leveling.
  • Trace UUU provisioning scripts from SDP: Boot ROM DCD + DDR3 download into FB: U-Boot Fastboot flash commands.

Managed FTL Block Flash Versus Raw SLC NAND Geometry

Embedded i.MX6ULL boards ship in two primary non-volatile storage variants: 8 GiB eMMC (USDHC2) and 512 MiB raw SLC NAND (GPMI), alongside a removable SD slot (USDHC1). Although all three store bits in floating-gate/charge-trap NAND cells under the hood, their software interfaces belong to two completely different worlds!

SD cards and eMMC packages integrate a dedicated controller running a Flash Translation Layer (FTL). Linux sees /dev/mmcblk0 or /dev/mmcblk1 as clean 512-byte sectors (LBA 0..N), so MBR/GPT, FAT32 (/boot), and ext4 (rootfs) work directly once Partition 1 starts at LBA 2048 (1 MiB) above u-boot.imx at 0x400 (LBA 2), or inside eMMC's hardware mmcblk1boot0 partition.

Raw SLC NAND has zero internal controller: the i.MX6ULL GPMI and BCH engines drive raw 2 KiB page writes (+ 64 B OOB ECC), 128 KiB block erases, and Bad Block Tables (BBT) through MTD (/dev/mtd0..N) paired with UBI and UBIFS.

fig_m05_l02_a.svg — Boot ROM SDP only knows how to initialize DDR3 via DCD…

Figure 5.2a. Boot ROM SDP only knows how to initialize DDR3 via DCD and jump to RAM U-Boot; U-Boot Fastboot writes the flash.

mental model: Managed SD/eMMC flash is like checking luggage at an airport desk that hides conveyor routing behind clean claim-tag numbers (LBA), whereas raw SLC NAND hands you the warehouse forklift directly — you must track worn floor bays (BBT) and erase entire shelves (128 KiB PEBs) before stacking a 2 KiB box.

Where it stops working: An internal eMMC FTL handles wear leveling and bad blocks, yet sudden power loss during metadata updates can still corrupt FAT32 or FTL tables without ext4 journaling or read-only squashfs.

definition (UBI (Unsorted Block Images)): A Linux kernel volume-management layer sitting directly above raw MTD flash devices that maps contiguous, bad-block-free Logical Eraseblocks (LEBs) onto Physical Eraseblocks (PEBs), maintaining erase-counter headers across the entire NAND chip and transparently relocating data away from newly failing blocks for UBIFS.

ast_m05_l02.svg — Keep LBA 2..2047 clear on SD, use boot0 on eMMC, use…step 1/4
  1. Step 1. Even a brand-new board with completely erased eMMC/NAND boots U-Boot into DDR3 in < 1 second via SDP.
  2. Step 2. Storing U-Boot in mmcblk1boot0 isolates bootloader updates from MBR/GPT re-partitioning in user space.
  3. Step 3. -raw2sparse avoids transferring gigabytes of unallocated ext4 zeros over USB 2.0 High-Speed.
  4. Step 4. FB: done verifies the final Fastboot ACK before you switch BOOT_MODE=10 to test standalone cold boot.

Figure 5.2b. Keep LBA 2..2047 clear on SD, use boot0 on eMMC, use UBI/UBIFS on raw NAND, and stream via UUU SDP->FB.

eMMC Partition Offsets Versus NAND FCB, MTD, and LEB Sizing

Compare exact byte layouts on both media types so partition math never collides with the Boot ROM! On SD (USDHC1) or eMMC User Area, LBA 0 (0x000..0x1FF) holds the 512-byte MBR; byte 0x400 (LBA 2, 1 KiB offset) holds u-boot.imx (IVT magic 0xD1 followed by DCD and U-Boot binary, ~500..800 KiB); and Partition 1 begins cleanly at LBA 2048 (1 MiB = 0x100000), leaving 1,023 KiB of protected headroom.

On 512 MiB SLC NAND (4,096 PEBs x 128 KiB, 64 pages/block x 2,048 B + 64 B OOB), block 0 cannot simply hold raw u-boot.imx: the Boot ROM expects a Flash Control Block (FCB, written with redundant copies + BCH ECC by kobs-ng or U-Boot bcb) and Discovered Bad Block Table (DBBT). Above U-Boot, DTB, and zImage MTD partitions, UBI subtracts 2 pages (4 KiB: EC + VID headers) from each 128 KiB PEB (LEB = 124 KiB) and reserves ~20 PEBs per 1,024 (2%) for bad-block replacement.

fig_m05_l02_b.svg — UBI consumes 2 NAND pages (EC + VID headers = 4 KiB on…

Figure 5.2b. UBI consumes 2 NAND pages (EC + VID headers = 4 KiB on 2 KiB-page SLC NAND) per 128 KiB physical eraseblock.

DimensionSD / eMMC (USDHC1/2)Raw SLC NAND (GPMI)Operational Consequence
Controller & ECCInternal FTL MCU handles ECC & wearHost i.MX6ULL GPMI + BCH hardware ECCRaw NAND exposes bitflips (-EUCLEAN) and bad blocks to MTD
Minimum write / erase512 B LBA sector (FTL-managed)Write 2 KiB page; erase 128 KiB PEBIn-place sector overwrite is physically impossible on raw NAND
Bootloader headerIVT at 0x400 (LBA 2 or boot0)FCB + DBBT in Block 0 + redundant copiesRaw dd of u-boot.imx to /dev/mtd0 fails without FCB ECC!
Root filesystemext4 or squashfs on /dev/mmcblkXp2UBIFS on UBI volume (ubi0:rootfs)bootargs differ: root=/dev/mmcblk1p2 rootwait vs ubi.mtd=4 root=ubi0:rootfs
learner@ksa: ~/gl-e00/m05-l02
learner@ksa:~/gl-e00/m05-l02$ bat -H 4 -H 13 emmc_nand_provision.uuu File: emmc_nand_provision.uuu    uuu_version 1.4.182        # Stage 1: Stream U-Boot (+ IVT/DCD) over USB OTG1 HID SDP into DDR3 RAM  SDP: boot -f u-boot-imx6ull-14x14-evk-emmc.imx        # Stage 2: RAM U-Boot runs USB Fastboot gadget on OTG1    FB: ucmd setenv fastboot_dev mmc    FB: ucmd setenv mmcdev 1    FB: ucmd mmc dev 1        # Program U-Boot into dedicated eMMC boot0 hardware partition & enable boot0    FB: flash bootloader u-boot-imx6ull-14x14-evk-emmc.imx  FB: ucmd mmc partconf 1 1 1 0        # Stream full MBR + FAT32 (zImage/dtb) + ext4 rootfs with sparse zero-skipping    FB: flash -raw2sparse all core-image-minimal-imx6ull.sdcard    FB: Sync    FB: done
  1. SDP: talks directly to the i.MX6ULL mask Boot ROM over USB HID to init DDR3 via DCD and boot U-Boot in RAM.
  2. mmc partconf 1 1 1 0 configures eMMC EXT_CSD[179] so Internal Boot reads boot0 with BOOT_ACK enabled.
uuu(1) / ubiattach(8)(1) at a glance — GL-E00
uuu(1) / ubiattach(8)(1)    GL-E00 Quick Reference    uuu(1) / ubiattach(8)(1) SYNOPSIS       sudo uuu -lsusb # Verify board enumerates as 15a2:0080 (SE Blank 6ULL)       in BOOT_MODE=01 sudo uuu -b emmc_all u-boot.imx rootfs.sdcard sudo uuu       emmc_nand_provision.uuu        KEY STORAGE COMMANDS (Target Linux / U-Boot) dd if=u-boot.imx       of=/dev/sdX bs=1K seek=1 conv=fsync # SD card 1 KiB (0x400) IVT offset       ubiformat /dev/mtd4 -f rootfs.ubi # Preserves UBI erase counters (never       raw nandwrite over UBI!) ubiattach -p /dev/mtd4 && mount -t ubifs       ubi0:rootfs /mnt Kernel Systems Academy           Lesson 5.2           uuu(1) / ubiattach(8)(1) GL-E00 quick reference · full manual page: man 1 uuu(1) / ubiattach(8) 

Verifying LBA Headroom, UBI LEB Overhead, and UUU Ordering in C11

Storage-layout arithmetic bugs wipe partition tables or underestimate UBIFS image limits when mkfs.ubifs -m 2048 -e 126976 -c ... is configured. In verify.c, we validate SD/eMMC IVT (0x400) + u-boot.imx bounds against Partition 1 (LBA 2048), compute exact UBI LEB size (126,976 bytes = 124 KiB) and usable capacity on a 512 MiB SLC NAND chip, and check UUU SDP -> FB transition order.

All geometry math executes deterministically in host C11; actual USB SDP enumeration and GPMI BCH ECC timings belong strictly to physical i.MX6ULL target hardware.

learner@ksa: ~/gl-e00/m05-l02
learner@ksa:~/gl-e00/m05-l02$ bat -H 17 -H 28 verify.c File: verify.c    #define _POSIX_C_SOURCE 200809L    #include <stdbool.h>    #include <stdint.h>    #include <stdio.h>    #include <string.h>        struct nand_ubi_geom {    	uint32_t total_pebs;    	uint32_t leb_bytes;    	uint32_t reserved_bad_pebs;    	uint32_t usable_lebs;    };        static struct nand_ubi_geom calc_ubi_geom(uint32_t mtd_pebs, uint32_t peb_bytes, uint32_t page_bytes)    {    	struct nand_ubi_geom g;  	g.total_pebs = mtd_pebs;    	g.leb_bytes = peb_bytes - (2U * page_bytes); /* EC + VID headers = 2 pages on non-subpage SLC */    	g.reserved_bad_pebs = (4096U * 20U) / 1024U; /* Per-chip 20/1024 BBT pool charged to UBI */    	g.usable_lebs = mtd_pebs - g.reserved_bad_pebs - 4U; /* 2 layout + 2 WL/atomic PEBs */    	return g;    }        static bool validate_uuu_steps(const char **cmds, size_t n)    {    	bool ram_uboot_live = false;    	for (size_t i = 0U; i < n; i++) {  		if (strncmp(cmds[i], "SDP: boot", 9U) == 0)    			ram_uboot_live = true;    		else if (strncmp(cmds[i], "FB:", 3U) == 0 && !ram_uboot_live)    			return false;    	}    	return ram_uboot_live;    }        int main(void)    {    	uint32_t ivt_offset = 0x400U;          /* LBA 2 = 1024 B */    	uint32_t uboot_bytes = 640U * 1024U;   /* 640 KiB u-boot.imx */    	uint32_t part1_lba = 2048U;            /* 1 MiB = 1,048,576 B */    	bool sd_safe = (ivt_offset + uboot_bytes) <= (part1_lba * 512U);        	/* 480 MiB rootfs MTD partition = 3840 PEBs of 128 KiB, 2 KiB page */    	struct nand_ubi_geom ubi = calc_ubi_geom(3840U, 131072U, 2048U);    	const char *good_uuu[] = {"SDP: boot -f u-boot.imx", "FB: ucmd mmc dev 1", "FB: done"};    	const char *bad_uuu[] = {"FB: flash bootloader u-boot.imx", "SDP: boot -f u-boot.imx"};        	if (!sd_safe || ubi.leb_bytes != 126976U || !validate_uuu_steps(good_uuu, 3U) || validate_uuu_steps(bad_uuu, 2U))    		return 1;        	printf("SD_LAYOUT ivt=0x%x uboot_end=%u part1_start=%u headroom_B=%u\n",    	       ivt_offset, ivt_offset + uboot_bytes, part1_lba * 512U,    	       (part1_lba * 512U) - (ivt_offset + uboot_bytes));    	printf("NAND_UBI leb_B=%u bad_rsv_pebs=%u usable_lebs=%u usable_MiB=%.1f\n",    	       ubi.leb_bytes, ubi.reserved_bad_pebs, ubi.usable_lebs,    	       ((double)ubi.usable_lebs * (double)ubi.leb_bytes) / (1024.0 * 1024.0));    	printf("UUU_SEQ valid_sdp_then_fb=1 reversed_fb_first_rejected=1\n");    	return 0;    }
  1. Without subpage writes, UBI places EC and VID headers in 2 separate 2 KiB pages -> LEB = 126,976 B.
  2. Any FB: Fastboot command fails unless an earlier SDP: boot command already started U-Boot in RAM!

Checking Partition Headroom and mkfs.ubifs Parameters

Notice the 126,976-byte (124 KiB) leb_B figure in NAND_UBI: that exact integer is what you pass to mkfs.ubifs -m 2048 -e 126976 -c 3756 when building a NAND rootfs on your Linux host! Passing 131072 (128 KiB raw PEB size) by mistake produces a UBIFS image that ubiupdatevol immediately rejects at runtime.

Notice also why reserved_bad_pebs equals 80 (20/1024 of the entire 4,096-PEB 512 MiB chip, not just the 3,840-PEB rootfs MTD partition!): Linux kernel UBI sizes its bad-block pool against total chip capacity because factory bad blocks cluster unpredictably.

learner@ksa: ~/gl-e00/m05-l02
learner@ksa:~/gl-e00/m05-l02gcc -std=c11 -Wall -Wextra -Werror verify.c -o verifylearner@ksa:~/gl-e00/m05-l02./verifySD_LAYOUT ivt=0x400 uboot_end=656384 part1_start=1048576 headroom_B=392192NAND_UBI leb_B=126976 bad_rsv_pebs=80 usable_lebs=3756 usable_MiB=454.8UUU_SEQ valid_sdp_then_fb=1 reversed_fb_first_rejected=1learner@ksa:~/gl-e00/m05-l02
strace — learner@ksa: ~/gl-e00/m05-l02
learner@ksa:~/gl-e00/m05-l02strace -e trace=write,exit_group ./verifywrite(1, "SD_LAYOUT ivt=0x400 uboot_end=65"..., 204) = 204exit_group(0)                           = ?+++ exited with 0 +++

Provisioning and Flash-Wear Hazards on eMMC and NAND

Keep your host udev rules from Module 1 updated for both UUU USB IDs (15a2:0080 NXP SDP HID and 0525:a4a5 / 1b67:4fff U-Boot Fastboot gadget) so uuu runs reliably without erratic USB permission drops mid-script when the board re-enumerates between SDP: and FB:!

And when updating an existing UBI partition in the field, always use ubiformat or ubiupdatevol — never flash_erase + raw nandwrite, which wipes EC wear-leveling counters.

UUU Hangs at Waiting for Known USB Device Between SDP and FB:

  • Symptom: SDP: boot -f u-boot.imx reaches 100%, then uuu stalls indefinitely waiting for FB: Fastboot enumeration.
  • Root Cause: Either the flashed u-boot.imx lacks CONFIG_USB_FUNCTION_FASTBOOT / DCD matching the board's DDR3 size, OR a Linux VM (VirtualBox/VMware) captured 15a2:0080 (SDP) but failed to auto-capture the new 0525:a4a5 (Fastboot) USB VID:PID on re-enumeration!
  • Fix: Add both NXP SDP (15a2:0080) and U-Boot Fastboot (0525:a4a5) USB filters to your VM configuration and /etc/udev/rules.d/.

Forgetting bs=1K seek=1 When Writing u-boot.imx to SD Card:

  • Symptom: Running dd if=u-boot.imx of=/dev/sdb boots U-Boot, yet lsblk and Linux kernel report the SD card's MBR partition table is completely gone!
  • Root Cause: Omitting seek=1 bs=1K (seek=2 bs=512) writes u-boot.imx at byte 0x000 (LBA 0), overwriting the 512-byte MBR AND placing the IVT at 0x000 instead of 0x400!
  • Fix: Always include bs=1K seek=1 conv=fsync (preserving bytes 0..1023, including LBA 0 MBR), and verify Partition 1 starts at >= LBA 2048.

Guided Practice

Modify verify.c to test what happens when an oversized U-Boot + environment blob grows to 1,100 KiB while Partition 1 starts at LBA 2048 (1,024 KiB). Does sd_safe catch the 77 KiB overlap into the FAT32 Boot Sector?

Compute the minimum 4 MiB-aligned starting sector (LBA 8192) required to give U-Boot and redundant U-Boot environment sectors (env + env_redund) generous 4 MiB headroom.

Independent Practice

Write a C11 parser parse_mtdparts(const char *spec) for mtdparts=gpmi-nand:4m(boot),8m(kernel),1m(dtb),-(rootfs) on a 512 MiB (524,288 KiB) NAND chip that calculates the exact byte offset and PEB count (128 KiB/PEB) of every partition including the remaining -(rootfs) slice.

Confirm that 4 + 8 + 1 = 13 MiB leaves 499 MiB (3,992 PEBs) for rootfs with zero unaligned PEB remainders.

Verification Checks

quiz · 1 of 3

Why does Linux kernel mount UBIFS over UBI + MTD on raw 512 MiB SLC NAND instead of formatting /dev/mtdblock4 directly as ext4?

quiz · 2 of 3

During UUU provisioning of a completely blank board (BOOT_MODE = 01), why are two distinct USB protocols (SDP: followed by FB:) used?

quiz · 3 of 3

Retrieval check from Lesson 5.1: On an SD card (USDHC1), why do we write u-boot.imx with dd if=u-boot.imx of=/dev/sdX bs=1K seek=1 and start Partition 1 at LBA 2048?

Key takeaways

  • SD (USDHC1) and eMMC (USDHC2) embed an on-chip Flash Translation Layer (FTL) exposing 512-byte LBA sectors, with i.MX6ULL IVT placed at byte 0x400 (LBA 2) and eMMC providing dedicated boot0/boot1 hardware partitions.
  • Raw SLC NAND (GPMI + BCH ECC) exposes physical eraseblocks (128 KiB) and factory/wear bad blocks directly without an FTL, requiring Linux kernel MTD, Bad Block Tables (BBT), and UBI/UBIFS rather than FAT32/ext4.
  • With BOOT_MODE[1:0] = 01, UUU Stage 1 (SDP: boot -f u-boot.imx) uses the Boot ROM's USB_OTG1 HID protocol to execute DCD DDR3 init and run U-Boot directly in RAM.
  • UUU Stage 2 (FB:) speaks USB Fastboot to the RAM-resident U-Boot gadget to partition and program eMMC (boot0 + GPT/MBR) or NAND (MTD/UBI) unattended.
Progress is saved on this device.

search — fzf

0/0 ───────────────────────────────────────────

keyboard shortcuts — less

/
search
f
focus mode
[
previous
]
next
?
help
Esc
close

figure