| ← Previous: Open Questions & Gaps | Index | Next: Appendix: Message Block Fields → |
This chapter documents the build, flashing, and recovery procedures for testing first-stage bootloader (SPL/FSBL) and PMU firmware images on the SpacemiT K3 Pico-ITX platform.
Before modifying SPI NOR flash:
bootinfo, fsbl, env, and the persisted DDRT training envelope at bootinfo+0x10000).uboot stores the EDK2 firmware volume (fit), not a standalone U-Boot payload. Overwriting uboot with u-boot.itb breaks the UEFI boot chain.fsbl.DANGER — Never access PHY/PMU MMIO from Linux (
/dev/mem): Reading or writing DPHY/PMU MMIO registers after the OS boots stalls the SoC interconnect and requires a physical power cycle. Perform all PHY/PMU inspection from the bootloader while the PMU is powered, or via JTAG.
FSBL.bin packaging, CRC, and RSA-2048 signingEvery FSBL.bin image on the K3—both the factory image and images built from the open-source U-Boot tree—is packaged by tools/build_binary_file.py using board/spacemit/k3/configs/fsbl.json:
fsbl.json constructs FSBL.bin with the following modules:
ROTPK (0x000–0x0ff): 256-byte RSA-2048 root public key extracted from board/spacemit/k3/configs/key/root_key_prv.key.image_header (header0 + crc0 at 0x100): magic = "AIHD", version = 1, secure = 0, load_addr = 0xc0800000, and header_crc = crc32(header0).image_config + oem_pubkey: key table, rotpk_hash = SHA256(root_key), and the 256-byte RSA-2048 SPL public key extracted from key/spl_key_prv.key.cert0 (signature0): SHA256+RSA2048 signature over header0 + crc0 + keydata + oem_key, signed with key/root_key_prv.key.spl (header1 + crc1 + u-boot-spl.bin + signature1): second AIHD header (imgsize = sizeof(fsbl)), header_crc = crc32(header1), img_crc = crc32(fsbl), the u-boot-spl.bin payload, and signature1 (SHA256+RSA2048 over header1 + crc1 + fsbl, signed with key/spl_key_prv.key).Because SpacemiT includes the private keys (root_key_prv.key and spl_key_prv.key) directly in board/spacemit/k3/configs/key/ and secure = 0 is set in the header (with CONFIG_SPACEMIT_SECURE_BOARD and CONFIG_FIT_SIGNATURE disabled for subsequent FIT stages), any FSBL.bin built from source via make is automatically signed and accepted by the K3 BootROM.
FSBL.bin failsModifying bytes directly inside an already-packaged FSBL.bin (for example, replacing an embedded PMU firmware payload in-place with a hex editor, even if compressed and decompressed sizes match) invalidates crc1.img_crc and signature1, causing the BootROM to reject the image. Always rebuild FSBL.bin through make (or re-run tools/build_binary_file.py -c board/spacemit/k3/configs/fsbl.json -o FSBL.bin) after changing SPL code or embedded PMU blobs. Keep an unmodified copy of a known-good FSBL.bin as a recovery artifact.
From the bootloader source tree root, build in-tree using a 64-bit RISC-V GNU toolchain:
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- k3_defconfig
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- -j"$(nproc)"
Key generated artifacts:
FSBL.bin — first-stage bootloader containing SPL and embedded DDR/PMU initialization payloads;bootinfo_spinor.bin — SPI NOR boot header;u-boot-env-default.bin — default environment image;u-boot.itb — later-stage FIT image (do not flash over the EDK2 uboot partition on UEFI systems).When compiling independent PMU firmware for the embedded ARCv2 EM core, enforce all constraints specified in 12-arc-execution-environment.md and 13-firmware-behavioral-requirements.md:
-mcpu=em -mrf16 -mmpy-option=wlh5 -mdiv-rem -mno-sdata -mlittle-endian.-mrf16 at both compile and link stages: When -flto is enabled, LTRANS regenerates machine code at link time and will emit illegal r16–r25 instructions unless -mrf16 is present on the linker command line.0x0 targeting effective startup at 0x1fc.0x80010000..bss at 0x80004000 so startup zeroing never overwrites host-supplied phypara data at 0x80000400 (including ODT settings at 0x80000424).__muldi3, __udivsi3, and __divsi3 (using hardware mpymu/mpyu/divu instructions) without -flto so LTO cannot discard the global replacements.arc-elf32-objdump -d firmware.elf | grep -E '\br(1[6-9]|2[0-5])\b'
This check must return zero instruction matches. Also confirm the binary fits within the 64 KiB IMEM window (<= 0x10000 bytes for full training, <= 0x6800 bytes for quickboot decompression).
Example toolchain invocation pattern:
ARC_CC=arc-elf32-gcc
# Compile firmware sources with -mrf16, hardware multiply/divide, and -mno-sdata
"$ARC_CC" -std=gnu23 -mcpu=em -mrf16 -mmpy-option=wlh5 -mdiv-rem -mno-sdata \
-mlittle-endian -Os -flto \
-ffreestanding -fno-builtin -ffunction-sections -fdata-sections \
-c firmware_main.c -o firmware_main.o
# Compile global arithmetic libcall overrides WITHOUT -flto
"$ARC_CC" -std=gnu23 -mcpu=em -mrf16 -mmpy-option=wlh5 -mdiv-rem -mno-sdata \
-mlittle-endian -Os \
-ffreestanding -fno-builtin \
-c pmu_libcalls.c -o pmu_libcalls.o
# Link with -mrf16 explicitly passed to the linker driver
"$ARC_CC" -mcpu=em -mrf16 -mmpy-option=wlh5 -mdiv-rem -mno-sdata \
-flto -nostdlib -static \
-Wl,--gc-sections -Wl,--no-warn-mismatch \
-Wl,-T,pmu_firmware.ld -o firmware.elf startup.o firmware_main.o pmu_libcalls.o -lgcc
The reference board uses an 8 MiB Winbond SPI NOR flash (JEDEC 0xef 0x6017, 4 KiB erase size) divided into six partitions:
| Partition | SPI range | Size | Role |
|---|---|---|---|
bootinfo |
0x000000–0x020000 |
128 KiB | BootROM header; stores the 0x9800-byte DDRT training envelope at offset +0x10000 |
fsbl |
0x020000–0x0a0000 |
512 KiB | First-stage bootloader (FSBL.bin: SPL + LZOP-compressed PMU images) |
env |
0x0a0000–0x0b0000 |
64 KiB | Bootloader environment |
esos |
0x0b0000–0x1b0000 |
1 MiB | Real-time co-processor firmware (esos.itb) |
opensbi |
0x1b0000–0x210000 |
384 KiB | RISC-V OpenSBI runtime (fw_dynamic.itb) |
uboot |
0x210000–0x800000 |
~5.9 MiB | EDK2/UEFI FIT image on UEFI systems — do not overwrite with u-boot.itb |
Always verify partition names via /proc/mtd rather than assuming fixed /dev/mtdX indices across different kernel configurations.
FSBL.bin from LinuxWhen updating fsbl from a running Linux system:
flash_erase /dev/mtdX 0 0
mtd_debug write /dev/mtdX 0 <fsbl-byte-length> FSBL.bin
FSBL.bin only to the fsbl partition.bootinfo unless intentionally invalidating or restoring the DDRT training envelope at bootinfo+0x10000.bootinfo+0x10000 invalidates magic (0x54524444) and forces full training on the next boot.When the fsbl partition in SPI NOR is erased, the BootROM automatically enters USB Firmware Download (FDL) mode on power-up. This allows staging and executing a candidate FSBL.bin directly in RAM without wearing or risking SPI flash:
fastboot stage FSBL.bin
fastboot continue
(Select the specific USB device path with -s usb:... if multiple fastboot devices are attached.)
If a candidate firmware image hangs the PMU or stalls the DPHY/APB bus:
fsbl erased (or FDL straps active), allow the board to enumerate in fastboot/FDL mode.fastboot stage known_good_FSBL.bin
fastboot continue
fastboot flash fsbl is a no-op for SPI NOR. To write SPI NOR permanently during recovery, either boot into Linux via a staged FSBL.bin and use flash_erase/mtd_debug, or stage U-Boot and use U-Boot sf / mtd commands against the staged download buffer.After every hardware test run:
0xff) occurred.FSBL.bin and valid DDRT envelope in bootinfo+0x10000, perform a cold boot, and confirm that quickboot completes in ~9 ms.