|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Non-Secure Callable veneers – the only NS->S gateway. More...
Go to the source code of this file.
Enumerations | |
| enum | ra8_nsc_limits_t : uint32_t { k_ra8_nsc_xspi_max_read = 4096U , k_ra8_nsc_eth_frame_max = 1518U , k_ra8_nsc_log_msg_max_len = 128U } |
| Boundary-policy limits exposed to NS callers. More... | |
Functions | |
| ra8_err_t | ra8_nsc_xspi_read (uint32_t flash_off, uint8_t *ns_dst, uint32_t len) |
| NSC veneer: read len bytes from external XSPI flash. | |
| ra8_err_t | ra8_nsc_xspi_status (uint8_t instance, uint32_t *out_mask) |
| NSC veneer: query secure-side XSPI status. | |
| ra8_err_t | ra8_nsc_eth_send (const uint8_t *ns_frame, uint16_t len) |
| NSC veneer: hand a frame to the secure ESWM transmit path. | |
| ra8_err_t | ra8_nsc_eth_recv (uint8_t *ns_buf, uint16_t *inout_len) |
| NSC veneer: pull the next received frame to NS memory. | |
| ra8_err_t | ra8_nsc_log_emit (const char *tag, const char *message) |
| NSC veneer: emit a log line via the secure ITM channel. | |
| ra8_err_t | ra8_nsc_periph_init (void) |
| NSC veneer: bring up the secure-side peripheral substrate. | |
| ra8_err_t | ra8_nsc_wdt_start (void) |
| NSC veneer: arm the Secure WDT with the e-reader configuration. | |
| void | ra8_nsc_wdt_refresh (void) |
| NSC veneer: refresh the Secure WDT down-counter. | |
| ra8_err_t | ra8_nsc_key_vault_challenge (uint16_t slot, const uint8_t *ns_chal, uint8_t *ns_digest) |
| NSC veneer: SHA-256(key XOR challenge) for a stored slot. | |
| ra8_err_t | ra8_nsc_ota_commit (uint8_t target_bank) |
| NSC veneer: commit OTA target bank as the boot bank. | |
| ra8_err_t | ra8_nsc_flash_bank_config (uint32_t raw_value) |
| NSC veneer: write the flash bank-config word. | |
Non-Secure Callable veneers – the only NS->S gateway.
The NSC layer is the only gateway through which Non-Secure code can reach Secure-side resources. Every function declared here is a veneer that:
Definition in file ra8_nsc.h.
| enum ra8_nsc_limits_t : uint32_t |
Boundary-policy limits exposed to NS callers.
These are the hard caps the veneers enforce. NS code can read them directly so it never has to make a call that the secure side will reject.
| Enumerator | |
|---|---|
| k_ra8_nsc_xspi_max_read | Max bytes per ra8_nsc_xspi_read. |
| k_ra8_nsc_eth_frame_max | Max ethernet frame bytes. |
| k_ra8_nsc_log_msg_max_len | Truncated copy size for logs. |
|
nodiscard |
NSC veneer: pull the next received frame to NS memory.
| [out] | ns_buf | Destination buffer. |
| [in,out] | inout_len | On entry: capacity. On exit: bytes written. |
| k_ra8_ok | Bytes copied. |
| k_ra8_err_no_data | No frame ready. |
| k_ra8_err_null_ptr | ns_buf / inout_len NULL. |
| k_ra8_err_invalid_arg | Capacity zero / too small. |
NSC veneer: pull the next received frame to NS memory.
Validates capacity and pointer ranges, then forwards to ra8_net_pal_recv_frame.
| [out] | ns_buf | Non-Secure destination buffer. |
| [in,out] | inout_len | In: capacity; out: bytes written. |
| k_ra8_ok | Frame copied; *inout_len updated. |
| k_ra8_err_null_ptr | A pointer argument was NULL. |
| k_ra8_err_invalid_arg | Capacity below the frame max. |
Definition at line 82 of file ra8_nsc_eth.c.
References k_ra8_err_invalid_arg, k_ra8_nsc_eth_frame_max, RA8_CHECK_NULL_PTR, ra8_net_pal_recv_frame(), RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, and s_tag.
|
nodiscard |
NSC veneer: hand a frame to the secure ESWM transmit path.
| [in] | ns_frame | Pointer to a complete ethernet frame in NS RAM. |
| [in] | len | Frame length in bytes. |
| k_ra8_ok | Frame queued. |
| k_ra8_err_null_ptr | ns_frame NULL. |
| k_ra8_err_invalid_arg | Length out of range. |
| k_ra8_err_no_mem | TX ring full. |
NSC veneer: hand a frame to the secure ESWM transmit path.
Validates the NS-side pointer/length, runs cmse_check_address_range (TZ builds), and forwards to ra8_net_pal_send_frame.
| [in] | ns_frame | Non-Secure source buffer holding the L2 frame. |
| [in] | len | Frame length in bytes; 1..k_ra8_nsc_eth_frame_max. |
| k_ra8_ok | Frame queued for TX. |
| k_ra8_err_null_ptr | ns_frame was NULL. |
| k_ra8_err_invalid_arg | len out of range. |
Definition at line 50 of file ra8_nsc_eth.c.
References k_ra8_err_invalid_arg, k_ra8_nsc_eth_frame_max, RA8_CHECK_NULL_PTR, ra8_net_pal_send_frame(), RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_VENEER, and s_tag.
|
nodiscard |
NSC veneer: write the flash bank-config word.
| [in] | raw_value | Raw value forwarded to the secure side. |
Forwards the 32-bit raw value through ra8_ota_commit_set_bank_config which masks it down to the allowed bits inside the secure world. The veneer's value is in labelling the operation as crossing the security boundary, so static analysis can flag NS-side callers.
| [in] | raw_value | Caller-supplied bank-config word. |
| k_ra8_ok | Bank-config word latched (after secure mask). |
| k_ra8_err_invalid_arg | Secure side rejected the value. |
Definition at line 89 of file ra8_nsc_ota.c.
References RA8_NSC_VENEER, and ra8_ota_commit_set_bank_config().
|
nodiscard |
NSC veneer: SHA-256(key XOR challenge) for a stored slot.
The only operation the Non-Secure world can perform on the secure key vault. The raw key never leaves the secure world; this veneer copies the challenge into secure scratch, XORs it with the slot key, hashes the result, and copies the 32-byte digest back to NS memory. NS callers can then verify the digest matches their expected value (e.g., for HMAC or PBKDF2 style derivation) without ever seeing the key.
| [in] | slot | Vault slot index 0..7. |
| [in] | ns_chal | 32-byte challenge in NS memory. |
| [out] | ns_digest | 32-byte digest buffer in NS memory. |
| k_ra8_ok | Digest written. |
| k_ra8_err_null_ptr | ns_chal / ns_digest NULL. |
| k_ra8_err_invalid_arg | slot >= 8. |
NSC veneer: SHA-256(key XOR challenge) for a stored slot.
Validates that the NS challenge buffer (read) and the NS digest buffer (read/write) lie inside the Non-Secure region, then forwards to ra8_key_vault_sha256_xor_challenge. The raw key never leaves the secure world; only the 32-byte SHA-256 digest crosses the boundary back to NS.
The 32-byte slot bound is published by k_ra8_key_vault_chal_bytes and k_ra8_key_vault_digest_bytes; the veneer enforces it on both buffers before calling into the secure key vault.
| [in] | slot | Vault slot index. |
| [in] | ns_chal | NS challenge buffer (k_ra8_key_vault_chal_bytes). |
| [out] | ns_digest | NS destination for the SHA-256 digest (k_ra8_key_vault_digest_bytes). |
| k_ra8_ok | Digest copied to ns_digest. |
| k_ra8_err_null_ptr | A pointer argument was NULL. |
| k_ra8_err_invalid_arg | Buffer outside NS region or bad slot. |
Definition at line 65 of file ra8_nsc_key_vault.c.
References k_ra8_key_vault_chal_bytes, k_ra8_key_vault_digest_bytes, RA8_CHECK_NULL_PTR, ra8_key_vault_sha256_xor_challenge(), RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, and s_tag.
|
nodiscard |
NSC veneer: emit a log line via the secure ITM channel.
NS code cannot reach the ITM stim ports directly because they live in the System control space (0xE0000000) which lives in the secure region. The veneer copies the (tag, message) pair to a small secure-side scratch area, calls ra8_log_info, and returns. Strings longer than the scratch are truncated.
| [in] | tag | Module tag (short string). |
| [in] | message | Free-form message text. |
| k_ra8_ok | Log line emitted. |
| k_ra8_err_null_ptr | tag / message was NULL. |
NSC veneer: emit a log line via the secure ITM channel.
Copies (tag,message) into secure scratch buffers and forwards to ra8_log_info.
| [in] | tag | NUL-terminated NS string (subsystem tag). |
| [in] | message | NUL-terminated NS string (log message body). |
| k_ra8_ok | Message handed to the secure logger. |
| k_ra8_err_null_ptr | A pointer argument was NULL. |
Definition at line 94 of file ra8_nsc_log.c.
References internal_safe_strcpy(), k_ra8_nsc_log_msg_max_len, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_info, RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_VENEER, s_msg_scratch, s_tag, and s_tag_scratch.
Referenced by internal_sys_thread_entry(), internal_ui_thread_entry(), ns_reset_handler(), ui_thread_entry(), and work_thread_entry().
|
nodiscard |
NSC veneer: commit OTA target bank as the boot bank.
| [in] | target_bank | Target bank id (k_ra8_ota_bank_a or _b). |
NSC veneer: commit OTA target bank as the boot bank.
Validates target_bank and forwards to ra8_ota_commit_swap_bank in the secure world.
| [in] | target_bank | Bank to boot from (k_ra8_ota_bank_a/b). |
| k_ra8_ok | Bank-swap latched. |
| k_ra8_err_invalid_arg | Unknown bank index. |
Definition at line 52 of file ra8_nsc_ota.c.
References k_ra8_err_invalid_arg, k_ra8_ota_bank_a, k_ra8_ota_bank_b, RA8_NSC_VENEER, and ra8_ota_commit_swap_bank().
|
nodiscard |
NSC veneer: bring up the secure-side peripheral substrate.
Called once by NS code at boot. The veneer kicks off the substrate dance that NS code cannot do directly:
Once this returns success, NS code can call any of the other NSC veneers (ra8_nsc_eth_*, ra8_nsc_xspi_*, ra8_nsc_log_*).
| k_ra8_ok | Substrate up. |
| k_ra8_err_hw_init_failed | One of the substrate inits failed. |
Sequences the four substrate init calls that the Non-Secure world cannot perform because the MSTP / CGC / ICU / DMA register windows live in the secure region partitioning: ra8_mstp_init -> ra8_pwr_init -> ra8_isr_init -> ra8_dma_init.
The function is idempotent: subsequent calls return k_ra8_ok without redoing the work. On failure the latched s_initialized flag stays false so a future call may retry from scratch.
| k_ra8_ok | Substrate up (or already up). |
| k_ra8_err_hw_init_failed | One of the secure init steps failed. |
Definition at line 112 of file ra8_nsc_periph_init.c.
References k_ra8_err_hw_init_failed, k_ra8_ok, ra8_board_uart_console_init(), ra8_dma_init(), ra8_isr_init(), ra8_log_error_val, ra8_log_info, ra8_log_set_byte_sink(), ra8_mstp_init(), RA8_NSC_VENEER, ra8_pwr_init(), s_initialized, and s_tag.
Referenced by ns_reset_handler().
| void ra8_nsc_wdt_refresh | ( | void | ) |
NSC veneer: refresh the Secure WDT down-counter.
Forwards to ra8_wdt_refresh_deferred (WDTRR heartbeat). Installed as the ThreadX supervisor's ra8_wdt_sup_refresh_fn_t hook via ra8_wdt_supervisor_set_refresh_hook so the WDT is kicked only when every registered NS thread has checked in within its deadline. Returns void to match the hook signature.
Forwards to ra8_wdt_refresh_deferred (WDTRR heartbeat). Installed as the ThreadX supervisor's ra8_wdt_sup_refresh_fn_t hook so the supervisor kicks the WDT only when every registered NS thread has checked in on time.
Definition at line 106 of file ra8_nsc_wdt.c.
References RA8_NSC_VENEER, and ra8_wdt_refresh_deferred().
Referenced by internal_wdt_setup().
|
nodiscard |
NSC veneer: arm the Secure WDT with the e-reader configuration.
The WDT (HUM Ch 27) is Secure-owned; NS cannot programme WDTCR/WDTRR. This veneer forwards to ra8_wdt_init with a fixed Secure-side configuration (fully-open refresh window, expiry to NMI). In register-start mode that arms the down-counter, so NS must call this immediately before starting the ThreadX supervisor thread that will refresh it.
| k_ra8_ok | WDT configured and armed. |
| k_ra8_err_invalid_arg | The fixed configuration was rejected by the driver. |
Forwards to ra8_wdt_init with the fixed s_wdt_cfg. In register-start mode ra8_wdt_init programmes WDTCR/WDTRCR/WDTCSTPR and issues the unlock sequence that arms the down-counter, so the NS caller should invoke this immediately before starting the supervisor thread that refreshes it – keeping the arm-to-first-refresh gap small (as the flat demo does).
| k_ra8_ok | WDT configured and armed. |
| k_ra8_err_invalid_arg | The fixed configuration was rejected by the driver. |
Definition at line 82 of file ra8_nsc_wdt.c.
References RA8_NSC_VENEER, ra8_wdt_init(), and s_wdt_cfg.
Referenced by internal_wdt_setup().
|
nodiscard |
NSC veneer: read len bytes from external XSPI flash.
Wraps the secure-side ra8_xspi_* driver for Non-Secure callers (application). The veneer enforces:
| [in] | flash_off | Byte offset inside the XSPI flash window. |
| [out] | ns_dst | Destination buffer in Non-Secure RAM. |
| [in] | len | Bytes to copy. Must be > 0. |
| k_ra8_ok | Bytes copied from flash. |
| k_ra8_err_null_ptr | ns_dst was NULL. |
| k_ra8_err_invalid_arg | len zero / range out of bounds. |
| k_ra8_err_timeout | Flash COMSTT poll never cleared. |
Validates len is in (0, k_ra8_nsc_xspi_max_read] and that the NS destination buffer is in writable NS memory, then forwards to ra8_xspi_flash_read for the single configured instance.
| [in] | flash_off | Byte offset into XSPI flash. |
| [out] | ns_dst | Non-Secure destination buffer. |
| [in] | len | Bytes to read; 1..k_ra8_nsc_xspi_max_read. |
| k_ra8_ok | Bytes copied to ns_dst. |
| k_ra8_err_null_ptr | ns_dst was NULL. |
| k_ra8_err_invalid_arg | len zero / too large or range outside NS. |
Definition at line 64 of file ra8_nsc_xspi.c.
References k_ra8_err_invalid_arg, k_ra8_nsc_xspi_instance, k_ra8_nsc_xspi_max_read, RA8_CHECK_NULL_PTR, RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, ra8_xspi_flash_read(), and s_tag.
|
nodiscard |
NSC veneer: query secure-side XSPI status.
| [in] | instance | XSPI instance number. |
| [out] | out_mask | Status bits; OR of ra8_xspi status values. |
| k_ra8_ok | Status returned. |
| k_ra8_err_null_ptr | out_mask was NULL. |
| k_ra8_err_invalid_arg | Bad instance number. |
Range-checks out_mask in NS memory and forwards to ra8_xspi_get_status.
| [in] | instance | XSPI instance index. |
| [out] | out_mask | NS destination for the status mask. |
| k_ra8_ok | Status copied to *out_mask. |
| k_ra8_err_null_ptr | out_mask was NULL. |
| k_ra8_err_invalid_arg | Range outside NS region or bad instance. |
Definition at line 100 of file ra8_nsc_xspi.c.
References RA8_CHECK_NULL_PTR, RA8_NSC_CHECK_NS_RANGE_RW, RA8_NSC_VENEER, ra8_xspi_get_status(), and s_tag.