This episode moves CVE2 from "download over JTAG every time" to "boot from flash on power-up". The bootloader occupies the first 16 KiB of a 64 KiB unified RAM; slot A and slot B are 512 KiB each at 0x00C00000 and 0x00C80000 of a GD25Q128E, with one 4 KiB metadata sector per slot. A host sends a 15-byte header plus payload over 115200 UART; the board checks CRC32, writes metadata and jumps to the application. A bad image makes it boot the older slot instead.
firmware.hex, instruction and data RAM were two separate simple_ram instances, and the loader returned to main() after a non-P byte, which armed the watchdog and reset about every 500 ms — roughly a one-second loop.The order proves four separate things: a write works, a switch works, a bad image falls back, and the same fallback happens after power-up without a host tool.
| Step | Meta seq | Write / result | Boot result |
|---|---|---|---|
| Slot A, good image | 1 | 1,021 B, CRC a8a0cdcd | LOAD_PASS → EP09 APP A + 5 heartbeats |
| Slot B, good image | 2 | 1,021 B, CRC 0a74fc2c | LOAD_PASS → EP09 APP B + 5 heartbeats |
| Force A with bad CRC | 3 | advertised 575f3232, actual a8a0cdcd | A LOAD_FAIL → FALLBACK → B LOAD_PASS |
| Cold boot run 1 / run 2 | 3 | 336 B each, cmp identical | A FAIL → B PASS, EP09 APP B + 5 heartbeats |
| Restore A, good image | 4 | 1,021 B, CRC a8a0cdcd | LOAD_PASS → EP09 APP A + 5 heartbeats |
| Final cold boot | 4 | 268 B | A direct LOAD_PASS, no FALLBACK |
The seq column is metadata sequence, not the App banner string. App A always prints VER=00000001; A4 metadata version is 4. Use the LOAD SLOT / META_PASS line for the real image version.
# Slot A
EP09 FLASH BOOTLOADER
FLASH ID=00c84018 OK
PRESS L FOR LOADER (3s)...
LOADER READY
RECV SLOT=A LEN=1021...
RX_CRC=a8a0cdcd EXPECT=a8a0cdcd
PROGRAM_PASS
META_PASS SEQ=1 ACTIVE=A
LOAD SLOT=A LEN=1021 VER=00000001 CRC=a8a0cdcd LOAD_PASS
EP09 APP A VER=00000001 RUNNING
# Slot B
RECV SLOT=B LEN=1021...
RX_CRC=0a74fc2c EXPECT=0a74fc2c
PROGRAM_PASS
META_PASS SEQ=2 ACTIVE=B
LOAD SLOT=B LEN=1021 VER=00000002 CRC=0a74fc2c LOAD_PASS
EP09 APP B VER=00000002 RUNNING# Force A: advertised CRC is wrong, payload is still a good image
FRAME slot=0 force=1 len=1021 crc=575f3232 ver=3
RX_CRC=a8a0cdcd EXPECT=575f3232
PROGRAM_PASS
META_PASS SEQ=3 ACTIVE=A
LOAD SLOT=A LEN=1021 VER=00000003 CRC=a8a0cdcd LOAD_FAIL
SWITCH_FAIL
LOAD SLOT=A LEN=1021 VER=00000003 CRC=a8a0cdcd LOAD_FAIL
FALLBACK
LOAD SLOT=B LEN=1021 VER=00000002 CRC=0a74fc2c LOAD_PASS
EP09 APP B VER=00000002 RUNNINGBoth independent cold-boot logs are 336 B and byte-identical: pick A (seq 3, bad CRC), LOAD_FAIL, FALLBACK, pick B (seq 2, good CRC), LOAD_PASS, five heartbeats. After restoring A4, the final cold boot is 268 B and starts A directly with no FALLBACK.
The first board showed only a repeating EP09 FLASH BOOTLOADER / FLASH ID=00c84018 OK / PRESS L FO... about once per second. Four independent faults overlapped:
build_ep09.tcl only read an existing firmware.hex instead of compiling first, so the first bitstream carried an old image and never printed the NO_VALID_META / LOADER READY lines that the current main.c must print.0x4000; the instruction port could not see it, so the jump still fetched stale code.loader() did a bare return on a non-P byte; main() called reboot(), armed the watchdog and reset after 500 ms.PYTHON ?= python3 expanded to Vivado's Python directory, so bin2hex.py failed.The shipped design uses one 64 KiB dpram_64k (Port A instruction-only, Port B data read/write, 16 BRAM tiles), bin2hex.py always emits 16,384 words with NOP fill, build_ep09.tcl forces make clean all and checks the bitstream mtime against the hex, and the loader is an infinite frame loop that goes straight to load_and_jump on a good write; a bad CRC calls boot() on the older slot. The main flow no longer calls reboot().
Two test-tool faults also had to be fixed: a bare python3 cap_serial.py ... & was reaped by the SSH session, and a single 1,021-byte write at 115200 overflowed the board FIFO. The working host sends 32-byte chunks with 3 ms gaps.
| Region | Address | Size | Use |
|---|---|---|---|
| Configuration | 0x00000000..0x00BFFFFF | 12 MiB | FPGA bitstream / factory area, untouched |
| Slot A | 0x00C00000..0x00C7FFFF | 512 KiB | App A |
| Slot B | 0x00C80000..0x00CFFFFF | 512 KiB | App B |
| META_A | 0x00D00000..0x00D00FFF | 4 KiB | Metadata sector A |
| META_B | 0x00D01000..0x00D01FFF | 4 KiB | Metadata sector B |
| Bootloader | 0x0000..0x3FFF | 16 KiB | Stack top 0x4000 |
| App | 0x4000..0xFFFF | 48 KiB | Stack top 0x10000 |
The 512 KiB slot is flash capacity; this App is 1,021 B and the runtime image is capped at 48 KiB by RAM. Large-image erase time is not measured here.
Header: 15 bytes, little-endian: 'P' | slot | force | len(u32) | crc32(u32) | version(u32), followed by payload. CRC is standard CRC-32 / zlib (polynomial 0xEDB88320). force=1 writes the payload but keeps the advertised CRC wrong; only for fallback testing.
Metadata record: 32 bytes — magic, seq, slot, len, crc, version, attempts, rec_crc. magic is 0x45503952; rec_crc covers the first 28 bytes. The larger seq wins; if its image fails CRC, boot() tries the other record.
The final routed report is 08:13:41 and the bitstream is 08:14:13. DRC: 0 errors, 76 warnings, 0 critical — 33 DPIP, 12 DPOP, 21 REQP-1839, 10 other. REQP-1839 is the CVE2 register-file asynchronous reset driving BRAM address pins; the reset is only asserted during configuration, kept as a boundary.
VER=00000001, while A4 metadata version is 4. This is a compile-time string and not a boot failure.# Vivado 2025.2, xc7a35t-2fgg484
vivado -mode batch -source build_ep09.tcl
vivado -mode batch -source program_ep09.tcl
# firmware
cd sw && make clean all
cd sw/app && make clean all
# host loader: bin slot force version log
python3 host_flash_loader.py sw/app/firmware_a.bin 0 0 1 /tmp/loadA.log
python3 host_flash_loader.py sw/app/firmware_b.bin 1 0 2 /tmp/loadB.log
python3 host_flash_loader.py sw/app/firmware_a.bin 0 1 3 /tmp/loadF.log
# cold boot capture
python3 cap_serial.py 8 /tmp/cold.binThe bitstream embeds sw/firmware.hex through dpram_64k's INIT_FILE, so bootloader changes need re-synthesis; App A/B go over UART and do not. The programming script must be sourced by absolute path; a relative path in an SSH compound command once failed with couldn't read file.
53 files, about 3.3 MB: bitstream, routed reports, synthesis/implementation/programming logs, raw UART captures, RTL/XDC/Tcl, bootloader and App source/ELF/HEX/disassembly, host tools, pin table and fix record.