SpacemiT_K1_DDR

Index Next: Glossary →

Methodology

Clean-room approach

The work follows a clean-room split between two roles.

Analyst. Investigates the hardware and existing boot software (including SpacemiT’s public GPL-2.0+ U-Boot BSP sources in drivers/ddr/spacemit/k1x/, static analysis of the training binary, and active hardware probing on the reference board) and writes the specification. Every fact enters the specification as either

A fact is never written as “the other firmware does X”, nor as “our code does X”, and software-internal artifacts (function names, control-flow quirks, compiler bit-packing, stack layouts) are stripped out. Opaque values needed by the hardware (for example the PI sequencer parameters) are listed as engine parameters — reset value X, the hardware needs Y — without claiming to know what the bits mean.

Implementer. Whoever writes DDR firmware from this specification uses only

The implementer does not read listings, decompilations, linker maps, strings or source code of the proprietary training binary that originally initialised this SoC, and does not transcribe function names, log strings, stack layouts or code addresses of another program. Programming the silicon’s registers described here is not copying: it is the hardware.

Rules derived from this:

  1. If a step is not in the specification, the implementer stops and asks for an amendment instead of guessing from memory of other code.
  2. New measurements (UART, MMIO reads) are welcome input to the specification; source code of another DDR training implementation is not.
  3. The specification describes hardware only. It contains no information about any particular implementation (its structure, code, timings or results).
  4. Running new firmware on the board and comparing the hardware state with the reference measurements (reference-measurements.md) does not break the clean room. Comparing a new binary with another binary byte by byte would defeat the purpose: new code does not have to be identical to anything. Equivalence is defined by the hardware state reached (status registers, trained values within the reference ranges, DRAM integrity), not by code.

Trial and error through FDL

The K1 BootROM has a USB download mode (FDL, firmware download). When the boot media fail, or when the FDL button is held at reset, the BootROM exposes a fastboot-compatible USB device that accepts a signed first-stage image, places it in SRAM and runs it. This is the tool that made the reverse engineering possible without any boot medium and without risk of bricking the board.

The experimental loop:

  1. Build a first-stage image (mainline U-Boot SPL plus a DDR image in the ddr_fw.bin slot) that programs the registers under test and dumps the resulting state over the UART.
  2. Sign it with the vendor signing tool (the BootROM verifies the image; the tool is only executed, never studied).
  3. Load and run it through FDL: fastboot stage <image> then fastboot continue.
  4. Capture the UART (115200 baud) and compare the observed state with the hypothesis.
  5. Reset the board by software (SoC watchdog or PMIC soft reset, test-platform.md); the BootROM falls back to FDL by itself and the next run starts. Runs can alternate between two variants (A/B) with nobody at the board.

Do not confuse FDL with flashing. The BootROM’s fastboot flash command reports OKAY but the fsbl partition it exposes has size 0: the image is only downloaded to SRAM, not written to the SD card or eMMC. continue then runs that SPL in download mode, where it tries to fetch the next stage over fastboot (SPL load error: bootdev=12) and stops. To change the boot medium image, boot Linux from another medium (for the reference board, the eMMC, with the SD card removed), insert the SD card while it runs (the SD host has a card-detect GPIO and accepts hot-plug) and write the partition with dd.

Kinds of experiments that produced the facts in this specification:

Confidence labels

Used throughout the documents (see also the README):

Label Meaning
measured Observed on the reference board.
required Needed by the hardware: omitting it was observed to break the initialisation, or the hardware was only observed to reach a working state with it.
inferred Consistent with all observations and with JEDEC, but not isolated by a dedicated measurement.
opaque Value known and required; meaning of the bits unknown. Write it as given.
unknown Not established. Preserve hardware values; do not invent.

Limits of the method


Index Next: Glossary →