IVT, Boot Data, and SD/eMMC Offset Geometry
Master the three distinct coordinate systems of an i.MX6ULL boot container—SD/eMMC sector offsets, compact .imx file offsets, and runtime RAM pointers—while serializing the mixed-endian 32-byte IVT and 12-byte Boot Data structures.
What you'll learn
- Decode the D1 00 20 40 IVT bytes without confusing mixed byte-order fields.
- Translate SD/eMMC media offset 0x400 into compact-file and runtime coordinates.
- Validate IVT self, entry, and Boot Data pointers against a stated image layout.
Why Raw .bin Images Cannot Cold-Boot & The Three Coordinate Systems
When arm-none-eabi-objcopy -O binary bsp.elf bsp.bin strips an ELF executable down to raw ARMv7-A machine instructions, every piece of loader metadata vanishes—e_entry, PT_LOAD destination addresses, and byte lengths are gone! If you write bsp.bin onto an SD card, the i.MX6ULL Boot ROM has no way to know where in OCRAM or DDR3 those bytes belong, how many sectors to read, whether DDR3 needs register setup first, or which address holds _start. Also, why doesn't the Boot ROM simply read byte 0x0000 (LBA 0) of an SD or eMMC card? Because LBA 0 (bytes 0x000..0x1FF) holds the standard Master Boot Record (MBR) / GPT partition table! Overwriting 0x0000 would destroy filesystem partitions needed later by U-Boot and the Linux kernel.
Instead, on SD/eMMC media, the i.MX6ULL Boot ROM seeks 1 KiB (1024 B = 0x0400, two 512-byte sectors = LBA 2) into the card and looks for a 32-byte Image Vector Table (IVT). As Figure 4.2a shows, nearly every boot-image bug comes from calling three different origins "the offset" without naming its coordinate system:
- Storage Media Coordinate (
M, origin = card byte0x0000):MBRoccupies0x0000..0x03FF(LBA 0..1),IVTsits atM = 0x0400(LBA 2),Boot Datasits atM = 0x0420,DCDstarts atM = 0x042C, and our application_startpayload (Pbytes) sits atM = 0x1000(LBA 8). - Compact
.imxFile Coordinate (F = M - 0x0400, origin =IVTbyte0): Becausedd seek=2 bs=512skips the first1024 Bon the card, a compact.imxfile omits0x0000..0x03FFcompletely! File offsetF = 0x0000is theIVT,F = 0x0020isBoot Data,F = 0x002CisDCD, and the payload sits atF = 0x1000 - 0x0400 = 0x0C00(3072 B)—never0x1000! - Runtime Memory Coordinate (
R = BootData.start + M = IVT.self + F): For an entry point linked atR = 0x87800000(M = 0x1000),BootData.startequals0x87800000 - 0x1000 = 0x877FF000, placingIVT.selfat0x877FF000 + 0x0400 = 0x877FF400,Boot Dataat0x877FF420, andBootData.lengthat0x1000 + P(0x1010whenP = 16 B, even though the compact.imxfile is0x0C10bytes!).
Figure 4.2a. Exact alignment between SD/eMMC media offsets (M), compact .imx file offsets (F = M - 0x400), and runtime RAM addresses (R = start + M).
mental model: Packing a bootable .imx container is like loading a pre-assembled equipment skid (F) onto bay 2 (M = 0x0400, LBA 2) of a flatbed railcar bound for a numbered factory floor (R = 0x877FF000 + M): bay position on the railcar, byte offset inside the skid, and floor coordinates at the destination are linked by exact arithmetic, never interchangeable zeros.
Where it stops working: Unlike physical cargo labels, the i.MX6ULL Boot ROM mixes big-endian 16-bit header lengths with little-endian 32-bit ARM runtime pointers inside the very same 32-byte table.
definition (Image Vector Table () & Boot Data Structure): The i.MX6ULL Image Vector Table (IVT) is a 32-byte structure at SD/eMMC media offset 0x0400 (LBA 2). Its 4-byte header D1 00 20 40 encodes tag 0xD1, big-endian 16-bit byte length 0x0020 (32), and version 0x40—which appears as 0x402000D1 when read as one 32-bit little-endian ARM word! Seven little-endian 32-bit pointers follow: entry (+0x04), reserved1 = 0 (+0x08), dcd (+0x0C), boot_data (+0x10), self (+0x14), csf = 0 (+0x18), and reserved2 = 0 (+0x1C). Immediately following (at self + 0x20), the 12-byte Boot Data record specifies little-endian start, length, and plugin (0 for normal boot images).
Walk through the four-step coordinate conversion and pointer audit below before writing serializer code:
- Step 1. Step 1: Anchor SD/eMMC media coordinates at M_ivt = 0x0400 (LBA 2, sparing MBR) and M_payload = 0x1000 (LBA 8).
- Step 2. Step 2: Subtract 0x0400 for the compact .imx file: IVT at F = 0x0000, Boot Data at 0x0020, payload at F = 0x0C00.
- Step 3. Step 3: Map runtime RAM from BootData.start = 0x877FF000 so IVT.self = 0x877FF400 and IVT.entry = 0x87800000.
- Step 4. Step 4: Verify header D1 00 20 40, reserved words == 0, boot_data == self + 32, and entry inside [bdata+12, start+len).
Figure 4.2b. Name the coordinate origin (media M, compact file F, or runtime RAM R) on every variable before adding or comparing offsets.
Mixed-Endian Header Bytes vs Little-Endian Runtime Pointers
Study Figure 4.2b carefully to avoid a classic endianness trap. Why do hex dumps of .imx files show d1 00 20 40 byte-by-byte (od -tx1), yet 32-bit ARM word dumps (od -tx4) print 402000d1? Because the HAB/ROM container specification frames tag-length-version headers in network (big-endian) byte order—byte [0] is tag 0xD1, bytes [1..2] are big-endian length (0x00 << 8) | 0x20 = 32, and byte [3] is version 0x40—while storing all subsequent IVT and Boot Data memory addresses (+0x04..+0x28) as little-endian 32-bit ARM words! If you misread 00 20 as little-endian, you get 0x2000 = 8192 instead of 32; conversely, if you emit .byte 0xd1, 0x00, 0x20, 0x40 explicitly in assembly (target.S) or byte arrays (buf44[0..3]), host endianness can never scramble the header.
Figure 4.2b. Byte-accurate anatomy of the 32-byte IVT and 12-byte Boot Data — big-endian 16-bit header length paired with little-endian 32-bit runtime pointers.
| Container Region | SD/eMMC Media M | Compact .imx F | Runtime Address R (start = 0x877FF000) | Size & Byte-Order Rule |
|---|---|---|---|---|
MBR / Partition Table | 0x0000..0x03FF (LBA 0..1) | Omitted (dd seek=2 bs=512) | 0x877FF000..0x877FF3FF | 1024 B skipped in .imx |
IVT (image_ivt) | 0x0400 (LBA 2) | 0x0000 | 0x877FF400 (IVT.self) | 32 B (BE16 len, LE32 ptrs) |
Boot Data + DCD | 0x0420 / 0x042C | 0x0020 / 0x002C | 0x877FF420 / 0x877FF42C | 12 B LE32 + DCD (BE) |
Application _start | 0x1000 (LBA 8) | 0x0C00 | 0x87800000 (IVT.entry) | P bytes (ARMv7-A LE code) |
In target.S below, .section .ivt, "a" emits image_ivt (32 B) and image_boot_data (12 B) using linker-resolved symbols (_start, image_dcd, image_load_base, image_load_size). Notice that self (+0x14) receives image_ivt—its runtime memory address (0x877FF400), never compact-file offset 0!
learner@ksa:~/gl-e01/m04-l02$ bat -H 7 -H 8 -H 9 -H 10 -H 11 -H 12 -H 13 -H 14 -H 15 -H 16 -H 17 -H 18 target.S File: target.S .syntax unified .cpu cortex-a7 .arm .section .ivt, "a" .global image_ivt image_ivt: .byte 0xd1, 0x00, 0x20, 0x40 .word _start .word 0 .word image_dcd .word image_boot_data .word image_ivt .word 0 .word 0 image_boot_data: .word image_load_base .word image_load_size .word 0 .extern _start .extern image_dcd .extern image_load_base .extern image_load_size- Emit D1 00 20 40 as explicit bytes so big-endian length 0x0020 and little-endian word 0x402000D1 are unambiguous.
- Store image_ivt (0x877FF400) in self (+0x14) and strictly zero reserved1 (+0x08), csf (+0x18), and reserved2 (+0x1C).
- Linker-defined image_load_size spans from image_load_base (0x877FF000) through the end of initialized payload.
Serializing & Auditing 44-Byte IVT + Boot Data Coordinates in ISO C11
Never overlay a packed C struct directly onto disk bytes when fields mix endianness. In ivt_serializer_audit.c below, serialize_ivt_boot() writes into a 44-byte unsigned char array via explicit put_le32() shifts, while validate_ivt_coords() checks both perspectives on the header (get_le32(hdr) == 0x402000D1U and get_be16(hdr + 1) == 32U), enforces zero reserved words (+0x08 and +0x1C), proves self == start + media_ivt and boot_data == self + 32U, and verifies via subtraction (entry - start < len) that the ROM copy window actually covers entry!
learner@ksa:~/gl-e01/m04-l02$ bat -H 15 -H 16 -H 17 -H 18 -H 19 -H 20 -H 21 -H 22 -H 23 -H 24 -H 26 -H 27 -H 28 -H 29 -H 30 -H 31 -H 32 -H 33 -H 34 -H 35 -H 36 -H 37 ivt_serializer_audit.c File: ivt_serializer_audit.c #include <assert.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> #include <string.h> static void put_le32(unsigned char *p, uint32_t v) { for (unsigned i = 0U; i < 4U; ++i) p[i] = (unsigned char)(v >> (8U * i)); } static uint32_t get_le32(const unsigned char *p) { return (uint32_t)p[0] | ((uint32_t)p[1] << 8) | ((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24); } static uint16_t get_be16(const unsigned char *p) { return (uint16_t)(((uint16_t)p[0] << 8) | p[1]); } static void serialize_ivt_boot(unsigned char *buf44, uint32_t boot_start, uint32_t entry, uint32_t dcd, uint32_t boot_len) { memset(buf44, 0, 44U); buf44[0] = 0xd1U; buf44[1] = 0x00U; buf44[2] = 0x20U; buf44[3] = 0x40U; uint32_t self = boot_start + 0x400U; put_le32(buf44 + 4, entry); put_le32(buf44 + 12, dcd); put_le32(buf44 + 16, self + 32U); put_le32(buf44 + 20, self); put_le32(buf44 + 32, boot_start); put_le32(buf44 + 36, boot_len); } static bool validate_ivt_coords(const unsigned char *b, uint32_t media_ivt) { if (b[0] != 0xd1U || get_be16(b + 1) != 32U || (b[3] != 0x40U && b[3] != 0x41U)) return false; if (get_le32(b + 8) != 0U || get_le32(b + 28) != 0U) return false; uint32_t entry = get_le32(b + 4), bdata = get_le32(b + 16), self = get_le32(b + 20); uint32_t start = get_le32(b + 32), len = get_le32(b + 36); if (self != start + media_ivt || bdata != self + 32U) return false; return len > media_ivt && entry >= bdata + 12U && entry - start < len; } int main(void) { unsigned char hdr[44]; serialize_ivt_boot(hdr, 0x877ff000U, 0x87800000U, 0x877ff42cU, 0x1010U); assert(get_le32(hdr) == 0x402000d1U && get_be16(hdr + 1) == 32U); assert(validate_ivt_coords(hdr, 0x400U)); assert(0x400U / 512U == 2U && 0x1000U - 0x400U == 0x0c00U); put_le32(hdr + 20, 0U); /* wrong: file offset 0 written as runtime self */ assert(!validate_ivt_coords(hdr, 0x400U)); put_le32(hdr + 20, 0x877ff400U); put_le32(hdr + 8, 1U); /* wrong: nonzero reserved1 */ assert(!validate_ivt_coords(hdr, 0x400U)); printf("IVT_word=0x%08X self=0x%08X bdata=0x%08X entry=0x%08X LBA=%u\n", get_le32(hdr), 0x877ff400U, get_le32(hdr + 16), get_le32(hdr + 4), 2U); return 0; }- Emit D1 00 20 40 explicitly so big-endian length 32 and little-endian 0x402000D1 agree on every host.
- Enforce reserved1 == 0, reserved2 == 0, and self == boot_start + 0x400 (the IVT runtime address, not file offset 0).
- Require entry >= self + 32 + 12 and entry < boot_start + boot_len so the ROM actually loads the entry point.
Verifying Mixed-Endian Serialization & ARMv7-A Relocation Assembly
Build and run ivt_serializer_audit on the host, then assemble target.S with clang --target=armv7a-none-eabi to confirm clean relocation records for .section .ivt. Notice how the two fault-injection assertions in main() explicitly verify that writing 0 into self (hdr + 20) or 1 into reserved1 (hdr + 8) fails validation immediately.
learner@ksa:~/gl-e01/m04-l02gcc -std=c11 -Wall -Wextra -Werror -pedantic ivt_serializer_audit.c -o ivt_serializer_auditlearner@ksa:~/gl-e01/m04-l02./ivt_serializer_auditIVT_word=0x402000D1 self=0x877FF400 bdata=0x877FF420 entry=0x87800000 LBA=2learner@ksa:~/gl-e01/m04-l02clang --target=armv7a-none-eabi -mcpu=cortex-a7 -marm -c target.S -o target.olearner@ksa:~/gl-e01/m04-l02learner@ksa:~/gl-e01/m04-l02strace -e trace=write,exit_group \./ivt_serializer_auditwrite(1, "IVT_word=0x402000D1 self=0x877FF"..., 76) = 76exit_group(0) = ?+++ exited with 0 +++Why ENTRY(_start) Never Populates IVT.entry Automatically
Connect what you just proved back to ELF linking from Module m01. Writing ENTRY(_start) in a linker script sets e_entry inside bsp.elf for gdb—yet objcopy -O binary discards the entire ELF header! On cold boot, the i.MX6ULL Boot ROM knows your entry point solely from IVT.entry (+0x04) and copies sectors solely according to BootData.start and BootData.length (+0x20..+0x24). Keeping bsp.elf, bsp.map, and your .imx packer checked against each other guarantees IVT.entry matches _start and BootData.length covers 0x1000 + payload_bytes. Later: Lesson m04-l03 fills in image_dcd (0x877FF42C) with big-endian Device Configuration Data commands and writes a complete .imx binary file.
Common Production Pitfalls
warning: Symptom: Flashing firmware.imx onto a removable SD card with dd if=firmware.imx of=/dev/sdX bs=512 (forgetting seek=2) wipes the card's FAT/ext4 partition table while the board fails silently into USB Serial Downloader. Root Cause: Without seek=2 (1024 B), byte 0 of the compact .imx (0xD1) overwrites LBA 0 (MBR at 0x0000) instead of landing at 0x0400 (LBA 2), leaving payload padding at 0x0400 where the ROM checks for 0xD1. Fix: Always flash compact SD/eMMC .imx images with bs=512 seek=2 conv=fsync onto a verified removable block device.
warning: Symptom: A small 4 KiB blinky boots fine from SD, but after growing the firmware to 48 KiB, execution crashes randomly inside functions linked near the end of .text. Root Cause: BootData.length (+0x24) was left hardcoded to 0x4000 (16 KiB) instead of updating to 0x1000 + payload_bytes, so the Boot ROM stopped reading SD sectors partway through .text and left upper code words holding uninitialized DDR3 garbage. Fix: Compute BootData.length programmatically from the final binary byte count (0x1000 + payload_size) and assert entry + payload_size <= start + length.
Practice & Retrieval
Guided Practice: Relocating an IVT Container Into Pre-DDR OCRAM
Re-derive all runtime pointers for an SD-booted SPL executing inside OCRAM without DCD. Step 1 (Addresses): Given M_ivt = 0x0400, M_payload = 0x1000, and IVT.entry = 0x00908000, compute BootData.start (0x00908000 - 0x1000 = 0x00907000), IVT.self (0x00907400), and IVT.boot_data (0x00907420). Step 2 (Sizes & ): For a 24 KiB (0x6000 B) SPL binary with zero DCD commands, state IVT.dcd (0x00000000), compact .imx file size (0x0C00 + 0x6000 = 0x6C00 B), and BootData.length (0x1000 + 0x6000 = 0x7000 B, ending at 0x0090E000 < 0x00920000).
Independent Practice: Multi-Media IVT Validator (SD/eMMC vs QSPI)
Extend ivt_serializer_audit.c into ivt_media_check.c parameterized by media_ivt (0x0400 for SD/eMMC vs 0x1000 for QSPI NOR). Enforce 4-byte ARM alignment on entry, require dcd == 0 when targeting OCRAM [0x00907000, 0x00920000) or dcd == self + 0x2C when DCD is present, and reject any layout whose DCD overflows into the payload offset.
Key takeaways
IVTheader bytesD1 00 20 40encode tag0xD1, big-endian16-bit length32(0x0020), and version0x40, which read as0x402000D1in a32-bit little-endian ARM word.- On
SD/eMMCmedia, placing theIVTat media offset0x0400(1 KiB,LBA 2across512-byte sectors) preservesLBA 0..1partitioning structures. - Translating any media offset
M >= 0x0400into a compact.imxfile yieldsF = M - 0x0400(0x1000 -> 0x0C00), while runtime addresses followR = BootData.start + M = IVT.self + F. IVTpointers (entry,dcd,boot_data,self) andBoot Data(start,length,plugin) serialize as little-endian32-bit words with reserved fields strictly zero.- The header bytes D1 00 20 40 encode tag D1, a big-endian length of 32, and version 40.
- Those four bytes appear as 0x402000D1 when interpreted as one little-endian 32-bit word.
- The IVT runtime address, not its compact-file offset.