Skip to content

rng: seed-error recovery for Mk3 (port of #693 to v4-legacy) - #699

Closed
Silexperience210 wants to merge 1 commit into
Coldcard:v4-legacyfrom
Silexperience210:fix/rng-seed-error-v4legacy
Closed

rng: seed-error recovery for Mk3 (port of #693 to v4-legacy)#699
Silexperience210 wants to merge 1 commit into
Coldcard:v4-legacyfrom
Silexperience210:fix/rng-seed-error-v4legacy

Conversation

@Silexperience210

Copy link
Copy Markdown

#693 fixes Mk4/Mk5/Q. This is the same change for the Mk3, filed against the branch that
actually builds it — master has no Mk3 target, so the copy of stm32/COLDCARD/rng.c
there is never compiled, while this branch carries the code that shipped as 4.2.0 on
2026-07-31.

The file here is byte-identical to master's and has the same gap: rng_init() only tests
RNGEN, but a seed error latches SEIS and stops DRDY while leaving RNGEN set, so the
peripheral is never recovered and every subsequent rng_get() times out for the rest of
the boot session. Since the hotfix wired rng_get() to the hardware TRNG, that path now
reaches the keypad scan-order shuffle in _start_scan(), which runs from a Pin.irq
callback before login.

shared/mempad.py gets the same try/except OSError as #693. This branch has no
keyboard.py, so there is nothing else to guard.

On the reference: the Mk3 is an STM32L475, covered by RM0351, which documents the
shorter clear-SEIS-then-toggle-RNGEN sequence. The 12-word pipeline flush is RM0432
wording. I kept it, with a note in the header, so this file stays identical to the Mk4/Q
version rather than quietly diverging — the extra discards are harmless. Say the word if
you would rather I trim it to the RM0351 sequence.

Should go in after #693. I have no Mk3 to test on, so this needs a look from someone who
does.

Coldcard#693 fixes the Mk4/Mk5/Q. This is the same change for the Mk3, on the
branch that actually builds it: master has no Mk3 target, so the copy of
stm32/COLDCARD/rng.c there is never compiled, and v4-legacy carries the
code that shipped as 4.2.0 on 2026-07-31.

stm32/COLDCARD/rng.c here is byte-identical to master's, and has the same
gap: rng_init() only tests RNGEN, but a seed error latches SEIS and stops
DRDY while leaving RNGEN set, so the peripheral is never recovered and
every later rng_get() times out for the rest of the boot session. Since
the hotfix wired rng_get() to the hardware TRNG, that reaches the keypad
scan-order shuffle in _start_scan(), which runs from a Pin.irq callback
before login.

mempad.py: same try/except OSError as Coldcard#693. This branch has no
keyboard.py, so nothing else to guard.

Reference note in the header: the Mk3 is an L475 (RM0351), which
documents the shorter clear-SEIS-then-toggle-RNGEN sequence. The 12-word
flush is RM0432 wording, kept so this file stays identical to the Mk4
version rather than diverging.
@Silexperience210

Copy link
Copy Markdown
Author

Closing — duplicate of #695, which predates this and is more complete (it also covers
stm32/bootloader/rng.c and the changelog). I opened this without checking existing PRs
first. Sorry for the noise.

The only thing here that isn't in #695 is a standalone testbench that mocks RNG_CR/SR/DR
and exercises the driver against nominal / transient seed error / dead 48 MHz clock /
1-in-5 glitch, if it's of any use for regression:
https://github.com/Silexperience210/firmware/tree/rng-fault-analysis — no obligation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant