Boot sequence
k1_ddr_boot() (lib/k1_ddr_boot.c) decides what happens and in
which order. It owns no register knowledge beyond reading a few status words
for the report: every hardware action is a call into k1_ddr_init.c or
k1_ddrt.c. The sequence is [measured] end-to-end on both reference
boards (logsRefs/020-eeprom-cs-num-16gib/readme.md,
logsRefs/021-eeprom-cs-num-8gib/readme.md). The image wraps it in
k1_ddr_boot_fallback() so a training (or independent-eye) failure retries at
a safer rate (logsRefs/029-fallback-2666-to-2400-16gib/readme.md).
int k1_ddr_boot(const struct k1_ddr_boot_cfg *cfg,
const struct k1_ddrt_env *env,
struct k1_ddr_boot_report *rep);
int k1_ddr_boot_fallback(struct k1_ddr_boot_cfg *cfg, ...);
Steps
# |
Action |
Call |
Failure step |
|---|---|---|---|
0 |
validate arguments |
— |
|
1 |
build the hardware context, compute the final fp |
|
— |
2 |
PLL1/PLL2, lock, SW-FC to fp0, MC clock |
|
|
3 |
Device_Init with x16 timings |
|
|
4 |
first training pass at fp0 |
|
|
5 |
read MR5 and MR8 (rank 0, channel 0) |
|
|
6 |
derive size and geometry from MR8 |
|
|
7 |
if x8: MC reset, Device_Init again with x8 overlays |
|
|
8 |
program the address map |
|
— |
9 |
load the DFC table (MR21 variant when the size is 16 GiB) |
|
— |
10 |
second training pass at fp0 |
|
|
11 |
for each fp of the plan: DFC, then a pass |
|
|
12 |
16 GiB only: MR21 write |
|
— |
13 |
final DFC to the final fp |
|
|
Each failure returns at once through k1_boot_end(), which fills the report
and logs k1-ddr: <step> failed, rc <rc>.
Argument validation
Refused with -EINVAL (step args) when: rep is NULL (nothing is
written), cfg is NULL, ddr, pmu or dfc_win is 0, cs_num
is not 1 or 2, env is NULL, or env->now_us is NULL. No register
is touched in any of these cases (a test checks that the model saw zero MMIO
writes).
type == K1_DDR_LPDDR4 is enabled in k1_ddr_boot() (using the LPDDR4 IO
table, WDQS words, PHY LDO setting and the fp3 pass plan), but remains untested
on silicon (Notes, limitations and open points).
Rate handling — k1_ddr_final_fp()
|
final fp |
|---|---|
2400, 2666 |
2 |
1066 |
1 |
2133 |
3 for LPDDR4, 0 for LPDDR4X |
1333 |
0 (PLL1 at the 2666 VCO; fp0 ≈1333 MT/s) |
anything else (1200, 1600, 0, 2667, 2700, 3200, 4266 …) |
0 (PLL1 at the 2400 VCO) |
The PLL1 programming uses the 2666 pair when data_rate is 2666 or 1333
(Controller bring-up); every other value uses the 2400 setting.
Pass plan — k1_ddr_dfc_plan()
The frequency points trained after the second fp0 pass, in order:
type |
plan |
|---|---|
LPDDR4X |
1, 2 |
LPDDR4 |
1, 3, 2 |
So an LPDDR4X boot always runs four passes (fp0, fp0, fp1, fp2) and three DFCs (fp1, fp2, final), regardless of the requested rate: the final DFC is issued even when the final fp is the one just trained (it is idempotent), and for a 1066/1200/1333 request the final DFC goes back down from fp2. The report keeps up to five pass summaries (enough for LPDDR4).
x8 handling
k1_ddr_geometry() sets x8 when MR8[7:6] == 1. In that case the boot
sets rep->byte_mode, pulses the MC reset and re-runs the whole Device_Init
with the x8 overlays. The PLLs are not touched again. The first pass ran with
x16 timings on purpose: it only has to make MR8 readable.
k1_boot_pass()
Runs k1_ddrt_train_pass() with { ddr, cs_num, boot_pp = pp }, appends a
k1_ddr_pass_summary to the report, calls cfg->on_pass(pass_ctx, &res, pp)
when set, and returns the pass result. on_pass returns int: if the PI
pass succeeded, a non-zero observer code becomes the pass result (so the first
independent-eye FAIL stops the remaining frequency points). The full
struct k1_ddrt_result lives in this function’s frame and is discarded after
the observer returns.
Rate fallback
k1_ddr_boot() is one attempt at cfg->data_rate.
k1_ddr_boot_fallback() repeats it down a ladder when the failure is
retryable:
2666 → 2400 → 1066
2133 or 1333 → 1200 → 1066
2400 or 1200 → 1066
1066: no next rate
EINVAL / ENOSYS (bad arguments, unsupported MR8) and
ETIMEDOUT at PLL lock or SW-FC are not retried. Training EIO, a
DFC timeout, and a non-zero after() (the final independent eye) are.
An MC reset sits between attempts so the next k1_ddr_pll_init() starts
from a cold controller; falling to a 2400 VCO also restores the BootROM
PLL1 analog word (Controller bring-up). cfg->data_rate is left at
the rate of the last attempt. Success after a retry still returns 0.
k1_boot_dfc()
k1_ddr_dfc(hw, fp); on failure returns its code.one discarded MR14 read on rank 0 / channel 0. After a hardware frequency change to fp2 the first mode-register read returns
0x00while the second returns the actual value; this read absorbs it ([measured]mr14_1st 0:0x00 mr14_2nd 0:0x19on both boards inlogsRefs/043-docsclean-claims-sweep/readme.mdandlogsRefs/044-docsclean-claims-sweep-8gib/readme.md).k1_ddrt_check_mr14()on every (rank, channel). A mismatch is only a warning (k1-ddr: warning: MR14 differs from the fp<N> bank): the DFC engine re-sends MR14 from the new bank, so this is a cheap check that the engine ran its flow, not a failure condition.
The report
struct k1_ddr_boot_report is zeroed at entry and filled as the boot goes:
field |
filled |
|---|---|
|
after argument checks |
|
after step 5 |
|
step 7 |
|
step 8 ( |
|
after every pass |
|
on return |
|
on return, whenever the PMU base is known |
|
on return, only after the MC clock is on (reading the MC before the SW-FC and MC clock enable is not safe, so a PLL failure leaves them 0) |
|
on return |
Logging
Besides the per-pass observer, the boot logs:
k1-ddr: LPDDR4X, cs_num N, R MT/s, final fpFk1-ddr: MR5 0x.. MR8 0x..k1-ddr: <MB> MB (x8|x16, ROW_n), cs0 0x.. cs1 0x.. 0x.. geom 0x..k1-ddr: fallback A -> B MT/s (step rc N)before a retryk1-ddr: running at B MT/s (asked A)when the successful rate is not the one the SPL requestedevery line of the lower layers (PLL, Device_Init, DFC; see Acceptance and logging).
Error-injection hooks
Built only with explicit flags (never in the production image):
flag |
effect in this file |
|---|---|
|
skips |
The other two flags live in k1_ddr_init.c and k1_ddrt.c (Testing).