royzah commented on PR #20205:
URL: https://github.com/apache/nuttx/pull/20205#issuecomment-5770788403

   Ran this on real silicon and it found a defect the build could not.
   
   Board: NXP MR-VMU-RT1176 (PX4 FMUv6X-RT), i.MX RT1176, plain NuttX `nsh`.
   
   **What was wrong.** The instantiation descriptor posts no job ring
   completion. The driver treated that as a failure, so the first read always
   returned `-ETIMEDOUT` even though the RNG had instantiated correctly.
   Generate jobs *do* complete on the ring, so every later read worked and hid
   it. Straight off the reset state:
   
   ```
   rdsta   = 0x00000000    RNG not instantiated
   jrstart = 0x00000000    no job ring started
   mcfgr   = 0x00082301
   scfgr   = 0x30000001
   ```
   
   Before:
   
   ```
   nsh> hexdump /dev/random count=32
   nsh: hexdump: read failed: 110
   nsh> cat /dev/ttyS1
   imxrt_caam_run: ERROR: job ring did not answer      (x25, one per entropy 
delay)
   imxrt_caam_rng_init: ERROR: RNG would not instantiate
   ```
   
   **The fix.** Judge instantiation by the state handle, which is the only
   report that descriptor makes, and take the ring back to a known state to
   latch it. Start job ring zero and set the cache and watchdog bits first,
   since the boot ROM does neither.
   
   After, first read following a cold boot:
   
   ```
   nsh> hexdump /dev/random count=32
   /dev/random at 00000000:
   0000: 8f ae 90 3a a2 8a b8 5b ba d6 1c b2 2e 7e 87 71 ...:...[.....~.q
   0010: 48 45 f6 e0 02 9b c0 fe 3b 38 d9 14 be 3e 61 ed HE......;8...>a.
   ```
   
   Five consecutive reads, all distinct:
   
   ```
   0000: 7e 56 d3 32 42 d2 10 a6 7b f3 d2 48 e5 ce 84 4b
   0000: 87 8e 2b d5 54 32 01 e0 33 3a 4d 00 a4 44 9c 0e
   0000: cb 40 5d ab 78 45 b9 97 56 13 65 8f d0 ac c7 87
   0000: 8d ed e8 fc cb 0f b9 e5 cd 1e 00 6c a4 e4 89 a2
   0000: 91 db ce 98 e8 60 96 73 ec 4c 24 fa a9 3f 48 81
   ```
   
   `/dev/urandom` likewise. Also rebased onto current master.
   
   Builds checked: `imxrt1170-evk:nsh` with the driver on, `imxrt1060-evk:nsh`
   without it to confirm the shared clock-gate header still builds.
   `nxstyle` clean on both changed files.
   
   @acassis @xiaoxiang781216 review welcome.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to