notes

The JH7110 TRNG: sources, bring-up and health testing

Name: ratified 2026-10-18 (calef, convention-rulings Rule 3).

This is the reference behind the jh7110_entropy crate (partsfoundry/jh7110_entropy), which holds the TRNG's register layout, its device-tree query and the decision of whether a generation succeeded. Nothing here has been checked against real silicon. Every fact below comes from documentation and other drivers, so the milestone's gate stays HARDWARE.

Sources

The vendor spelling

The tree nife is handed on the VisionFive 2 is the vendor U-Boot's control DTB (U-Boot 2021.10, per crates/serial_console/tests/fixtures/captured/vf2-2026-09-01-manual-boot.log). StarFive's fork spells the node as follows (uboot-dtsi).

The node is trng@1600C000 (upper-case C) in arch/riscv/dts/jh7110.dtsi of StarFive's U-Boot fork, branch JH7110_VisionFive2_devel, commit bfbdce9b86a2, fetched 2026-09-03. It carries the compatible string starfive,trng, a four-cell reg window of 0x4000 bytes at 0x1600C000, interrupt 30, two clocks (hclk and miscahb_clk), one reset, and status set to disabled.

It is the same device, window and interrupt under a different string: a stale fork, not different silicon. Accepting starfive,trng is a claim about the register layout, and the vendor Linux driver at the firmware's own vintage (vendor-driver) backs it. It defines STARFIVE_CTRL 0x00, STAT 0x04, MODE 0x08, SMODE 0x0C, IE 0x10, ISTAT 0x14, RAND0..RAND7 0x20..0x3C, AUTO_RQSTS 0x60 and AUTO_AGE 0x64. Its CTRL, STAT and ISTAT bit positions match mainline's jh7110-trng.c. Two drivers written against one IP block agree completely.

discover reports the node's status and does not act on it. The vendor tree marks the TRNG disabled because U-Boot has no driver for it, not because the silicon is absent; StarFive's own Linux enables the node from jh7110-common.dtsi (&trng { status = "okay"; };). The same DTB marks the S7 monitor core okay and claims an Sv39 MMU for it, and both are false (notes/visionfive2.md, "Second bench stop"). So the crate says what the tree says, and the caller neither refuses a device that is there nor trusts one that is not.

The bring-up order

All three drivers (mainline, the vendor's, NetBSD's) agree on this sequence. A driver that skips a step relies on a reset value nobody documented.

  1. Write 0 to AUTO_AGE and AUTO_RQSTS. Otherwise a nonzero reset counter raises an alarm later, in a register the driver may not decode.
  2. Clear ISTAT (write-1-to-clear). RAND_RDY is latched, so a driver that never acknowledges it sees "ready" at once on every request after the first and reads stale words.
  3. Write MODE_R256. Without it, eight assembled words may claim 32 bytes from a block that answered 16.
  4. Enable interrupts, or deliberately leave IE at zero to poll. ISTAT latches either way.
  5. Write CTRL_COMMAND_RESEED, wait for SEED_DONE and acknowledge it. Until then STAT.SEEDED is clear and every poll answers unseeded.

Then, per generation: acknowledge any stale RAND_RDY, write CTRL_COMMAND_GENERATE, poll (STAT, ISTAT), and acknowledge RAND_RDY once the words are read.

Health testing

A hardware status bit that is merely read is nearly free. A software SP 800-90B suite (repetition count, adaptive proportion) is real design and verification work. So the question was whether the chip documents a health signal.

It documents one fault signal: ISTAT.LFSR_LOCKUP. Linux treats it as a single-event upset and reseeds. The crate surfaces it as its own outcome rather than "not ready yet", so a caller can count it, retry, or refuse to serve bytes past it.

It catches a stuck post-processing stage, not a degraded ring oscillator that keeps running. Neither the datasheet nor the driver documents an SP 800-90B-class test. Whether this project needs one before trusting these bytes for anything security-shaped is undecided. It is an architect's call, and no section in design/decisions/ records it yet.

The kernel's wiring

kernel/src/user/entropy_service.rs gives the TRNG driver less authority than any other entropy backend: a request endpoint it receives on, a readiness endpoint it sends on once, and one page of device memory. That page is the first 0x1000 of the binding's 0x4000 register window, mapped device-typed. jh7110_entropy::registers reaches only 0x68, and a driver that cannot name a register cannot touch it. It gets no DMA page, because the device writes nothing to memory. It gets no Interrupt capability, because the driver polls. And it gets no VirtualIo capability, because there is no transport. With no DMA there is nothing for an IOMMU to confine, which is a narrower attack surface rather than a weaker claim.

This is the shape of fatal risk 6's experiment (design/fatal-risks/README.md): an unprivileged process holding one device page and two endpoints, driving a real device that is not virtio. Whether it runs at real speed is what the bench measures.

The kernel enables the TRNG's two clocks and releases its reset before the spawn. The driver's first act is to read STAT, and a gated block answers that read with zeros. The clock and reset controller is admin plane and stays in the kernel (kernel/src/drivers/jh7110_clock_and_reset.rs), on the argument of ยง86 (whether an NVMe driver can leave the kernel). A virtio-rng needs no such step, since a QEMU device comes up running.

The driver's own choices

components/src/jh7110_entropy.rs polls ISTAT rather than taking PLIC line 30. A wrong interrupt binding fails silently, as a hang. A wrong poll bound fails loudly, as NO_ENTROPY. Switching to the interrupt once the board confirms the binding is reversible.

It draws the first 32 bytes before it reports, and the bytes decide the readiness word. A device whose clock is gated reads as zeros, and an all-zero first generation reports STEP_FIRST_ALL_ZERO. That device is then refused for the rest of the boot. A client only ever sees a reply, so a service that reported dead and went on serving its zero buffer would hand those zeros out as randomness to everyone not watching the handshake. The service treats a first generation of 32 equal nonzero bytes (STEP_FIRST_ALL_SAME) the same way. A device that answered with nothing is not refused. It has told the truth at every step, take answers NO_ENTROPY while it stays dry, and it recovers by itself if it starts answering.

The readiness message has a fixed layout. Word 0 is the verdict. Word 1 holds the byte count, and in its high half the STAT read right after the bring-up writes. Word 2 is always (STAT << 32) | ISTAT, read at report time, whatever word 0 says. An all-zero pair says the register window read as nothing: a gated clock, a reset still asserted, or a base that is not the TRNG. A nonzero STAT with SEEDED clear says the device is alive and seeding did not finish.

One question about the bytes is open. MODE.R256 has never been read back on silicon. If radon's STAT.R256, in word 1's high half, reads clear, the upper four RAND words are not device output and only 16 bytes per generation may be served. One line of a bench transcript closes it.