Repository navigation
arch/arm/imxrt: add a CAAM-backed /dev/random driver - #20205
Conversation
|
@royzah please signed your PR and also add Assisted-by: AI Vendor/Model used |
4f27ea0 to
b332fc0
Compare
The part has a hardware random number generator and nothing registers it, so up_randompool_initialize() is never seeded from hardware. There is no CAAM, TRNG or RNG driver anywhere in arch/arm/src/imxrt, and the RT117x headers describe the block only as an address-map comment. imxrt_caam.c brings up job ring zero and instantiates the RNG state handle when the boot ROM has not, retrying with a longer entropy sample until the self test passes. imxrt_rng.c registers /dev/random and /dev/urandom on top, and is the i.MX9 driver's sibling: same health checks, same FIPS 140-2 continuous test, same refusal to return a short read and call it entropy. The instantiation descriptor posts no job ring completion, so the state handle is what reports it, and the ring is taken back to a known state to latch it. Job ring zero is started and the cache and watchdog bits set first: RDSTA and JRSTART both read zero out of reset on this part. Scoped to RT117x, which is the family that carries CAAM. Built for imxrt1170-evk:nsh with the driver on, and for imxrt1060-evk:nsh to confirm the shared clock-gate header still builds without it. Run on an FMU-v6X-RT (i.MX RT1176): /dev/random and /dev/urandom both return, the first read after a cold boot included, and five consecutive reads are distinct. Signed-off-by: Royyan Zahir <royzah@gmail.com>
b332fc0 to
131ec7b
Compare
|
Tried this on real hardware and it turned up a bug the build could never catch. Board is an FMU-v6X-RT, i.MX RT1176, running plain NuttX nsh. The instantiate descriptor just never answers on the job ring. The driver took that as a failure, so the first read always came back -ETIMEDOUT even though the RNG was actually fine. Generate jobs do answer, so every read after the first one worked and hid the whole thing. Straight out of reset: Before: So now it trusts the state handle instead of the ring, and resets the ring to latch it. Also starts job ring zero and sets the cache and watchdog bits first, since the boot ROM does neither. After, first read on a cold boot: Five reads in a row, all different, urandom the same. Rebased on master too. Built imxrt1170-evk:nsh with the driver on, and imxrt1060-evk:nsh without it to check the shared clock-gate header. nxstyle clean. @acassis @xiaoxiang781216 review welcome |
The board had no entropy configuration at all: no CONFIG_DEV_RANDOM, no CONFIG_DEV_URANDOM, nothing arch-backed. up_randompool_initialize() was never seeded from hardware, so every session key on this board came from a pool that is identical at every boot. The RT1176 carries a CAAM. Pin NuttX to a base with the job ring and RNG driver backported from apache/nuttx#20205 and turn it on here. IMXRT_RNG selects IMXRT_CAAM and ARCH_HAVE_RNG, and the driver is the sole provider of devrandom_register(), so CRYPTO_RANDOM_POOL stays off. CAAM bring-up is lazy, on the first read, so this cannot affect boot.
The board had no entropy configuration at all: no CONFIG_DEV_RANDOM, no CONFIG_DEV_URANDOM, nothing arch-backed. up_randompool_initialize() was never seeded from hardware, so every session key on this board came from a pool that is identical at every boot. The RT1176 carries a CAAM. Pin NuttX to a base with the job ring and RNG driver backported from apache/nuttx#20205 and turn it on here. IMXRT_RNG selects IMXRT_CAAM and ARCH_HAVE_RNG, and the driver is the sole provider of devrandom_register(), so CRYPTO_RANDOM_POOL stays off. CAAM bring-up is lazy, on the first read, so this cannot affect boot.
Summary
The i.MX RT117x has a hardware random number generator inside CAAM and nothing in NuttX registers it, so
up_randompool_initialize()is never seeded from hardware. There is no CAAM, TRNG or RNG driver anywhere inarch/arm/src/imxrt, and the RT117x headers describe the block only as an address-map comment.imxrt_caam.cimxrt_rng.c/dev/randomand/dev/urandomon top of ithardware/rt117x/imxrt117x_caam.himxrt_periphclks.hInstantiation retries with a longer entropy sample until the self test passes, which is how NXP's own code finds a value that holds across voltage and temperature.
imxrt_rng.cis the sibling of the i.MX9 driver in #20191: same health checks, same FIPS 140-2 continuous test, and the same refusal to return a short read and call it entropy.Scoped to RT117x, the family that carries CAAM.
Impact
New driver,
default n. Nothing changes for a board that does not selectIMXRT_RNG.Provenance of the register definitions
The i.MX RT1170 Reference Manual Rev. 5 describes CAAM in one page of features (section 7.7) and carries no register detail, so the header was built from NXP's own drivers for this block and cross-checked three ways.
0x4044_0000, job ring 00x4045_0000clk_enable_caam0x600/0x610/0x618/0x61c/0x6c0and their bits