From 65f2272a450e3c1129975041ad68e8afaab5e73d Mon Sep 17 00:00:00 2001 From: Daniel Lublin Date: Fri, 30 Sep 2022 15:41:16 +0200 Subject: [PATCH] Add TRNG to testfw, document --- doc/system_description/software.md | 8 +++----- hw/application_fpga/fw/testfw/main.c | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/doc/system_description/software.md b/doc/system_description/software.md index c58cd76..8668bc4 100644 --- a/doc/system_description/software.md +++ b/doc/system_description/software.md @@ -160,8 +160,6 @@ Available commands/reponses: #### `FW_{CMD,RSP}_RUN_APP` #### `FW_{CMD,RSP}_NAME_VERSION` #### `FW_{CMD,RSP}_UID` -#### `FW_{CMD,RSP}_TRNG_DATA` -#### `FW_{CMD,RSP}_TRNG_STATUS` #### `FW_{CMD,RSP}_VERIFY_DEVICE` @@ -308,8 +306,8 @@ Assigned core prefixes: | *name* | *fw* | *app | *size* | *type* | *content* | *description* | |--------------------|------|------------|--------|---------|-----------|-----------------------------------------------------------------------| -| `TRNG_STATUS` | r | r | | | | Non-zero when an entropy word is available. | -| `TRNG_ENTROPY` | r | r | 4B | | | Entropy word. Reading a word will clear status. | +| `TRNG_STATUS` | r | r | | | | STATUS_READY_BIT is set when an entropy word is available. | +| `TRNG_ENTROPY` | r | r | 4B | u32 | | Entropy word. Reading a word will clear status. | | `TIMER_CTRL` | r/w | r/w | | | | If bit 0 in TIMER_STATUS is set then writing here starts the timer. | | | | | | | | If bit 0 in TIMER_STATUS is unset then writing here stops the timer. | | `TIMER_STATUS` | r | r | | | | If bit 0 is set, the timer is ready to start running. | @@ -324,7 +322,7 @@ Assigned core prefixes: | `UART_RX_DATA` | r | r | 1B | u8 | | Data to read. Only LSB contains data | | `UART_TX_STATUS` | r | r | 1B | u8 | | Non-zero when it's OK to write data | | `UART_TX_DATA` | w | w | 1B | u8 | | Data to send. Only LSB contains data | -| `TOUCH_STATUS` | r/w | r/w | | | | STATUS_EVENT_BIT set 1 when touched; write to it after | +| `TOUCH_STATUS` | r/w | r/w | | | | STATUS_EVENT_BIT is set when touched; write to it after | | `UDA` | r | | 16B | u8[16] | | Unique Device Authentication key. | | `UDI` | r | | 8B | u64 | | Unique Device ID (UDI). | | `QEMU_DEBUG` | w | w | | u8 | | Debug console (only in QEMU) | diff --git a/hw/application_fpga/fw/testfw/main.c b/hw/application_fpga/fw/testfw/main.c index 9930335..f64e1fe 100644 --- a/hw/application_fpga/fw/testfw/main.c +++ b/hw/application_fpga/fw/testfw/main.c @@ -21,6 +21,8 @@ volatile uint32_t *timer = (volatile uint32_t *)MTA1_MKDF_MMIO_TIMER_T volatile uint32_t *timer_prescaler = (volatile uint32_t *)MTA1_MKDF_MMIO_TIMER_PRESCALER; volatile uint32_t *timer_status = (volatile uint32_t *)MTA1_MKDF_MMIO_TIMER_STATUS; volatile uint32_t *timer_ctrl = (volatile uint32_t *)MTA1_MKDF_MMIO_TIMER_CTRL; +volatile uint32_t *trng_status = (volatile uint32_t *)MTA1_MKDF_MMIO_TRNG_STATUS; +volatile uint32_t *trng_entropy = (volatile uint32_t *)MTA1_MKDF_MMIO_TRNG_ENTROPY; // clang-format on // TODO Real UDA is 4 words (16 bytes) @@ -232,6 +234,21 @@ int main() test_puts("All tests passed.\r\n"); } + test_puts("\r\nHere are 256 bytes from the TRNG:\r\n"); + for (int j = 0; j < 8; j++) { + for (int i = 0; i < 8; i++) { + while ((*trng_status & + (1 << MTA1_MKDF_MMIO_TRNG_STATUS_READY_BIT)) == + 0) { + } + uint32_t rnd = *trng_entropy; + test_puthexn((uint8_t *)&rnd, 4); + test_puts(" "); + } + test_puts("\r\n"); + } + test_puts("\r\n"); + test_puts("Now echoing what you type...\r\n"); for (;;) { in = readbyte(); // blocks