|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Decryption On The Fly (DOTF) HAL driver implementation. More...
#include "ra8_dotf.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_dotf_regs.h"#include "ra8_err.h"#include "ra8_hw_err.h"#include "ra8_log.h"#include "ra8_mstp.h"Go to the source code of this file.
Data Structures | |
| struct | ra8_dotf_chan_state_t |
| Per-channel software state. More... | |
Enumerations | |
| enum | ra8_dotf_misc_t : uint8_t { k_ra8_dotf_no_region = 0xFFU , k_ra8_dotf_self_test_spin = 8U } |
| Internal small constants (no magic numbers). More... | |
| enum | ra8_dotf_bswap_const_t : uint32_t { k_ra8_dotf_bswap_byte_mask = 0xFFUL , k_ra8_dotf_bswap_byte0 = 0x000000FFUL , k_ra8_dotf_bswap_byte1 = 0x0000FF00UL , k_ra8_dotf_bswap_byte2 = 0x00FF0000UL , k_ra8_dotf_bswap_byte3 = 0xFF000000UL } |
| Byte-extraction masks and shift counts for internal_bswap32. More... | |
| enum | ra8_dotf_bswap_shift_t : uint8_t { k_ra8_dotf_bswap_shift_byte = 8U , k_ra8_dotf_bswap_shift_word = 24U } |
| Shift counts used by internal_bswap32. More... | |
| enum | ra8_dotf_key_word_count_t : uint8_t { k_ra8_dotf_key_words_128 = 4U , k_ra8_dotf_key_words_192 = 6U , k_ra8_dotf_key_words_256 = 8U } |
| Wrapped-key word counts per AES key size. More... | |
Functions | |
| static bool | internal_channel_in_range (uint8_t channel) |
| Bound-check a channel index. | |
| static uint32_t | internal_window_lo (uint8_t channel) |
| XSPI window low bound for a given DOTF channel. | |
| static uint32_t | internal_window_hi (uint8_t channel) |
| XSPI window high bound for a given DOTF channel. | |
| static uint8_t | internal_key_words (ra8_dotf_key_size_t size) |
| Word count for a given AES key size. | |
| static uint32_t | internal_sca_bits (ra8_dotf_sca_level_t level) |
| Map an SCA level enum into REG00 SCA bits. | |
| static uint32_t | internal_bswap32 (uint32_t v) |
| Big-endian byte-swap of a 32-bit word. | |
| static ra8_err_t | internal_validate_region (uint8_t channel, const ra8_dotf_region_t *region) |
| Validate region range / alignment / window. | |
| static ra8_err_t | internal_check_overlap (uint8_t channel, const ra8_dotf_region_t *region) |
| Reject a region that overlaps the live region of the OTHER channel. | |
| static uint32_t | internal_assemble_reg00 (const ra8_dotf_chan_state_t *st, bool enable) |
| Assemble the REG00 word for the channel's cached state. | |
| static void | internal_stage_key (volatile ra8_dotf_regs_t *reg, const ra8_dotf_key_handle_t *h) |
| Stage a wrapped-key payload into REG03. | |
| static void | internal_stage_iv (volatile ra8_dotf_regs_t *reg, const uint32_t *iv) |
| Stage 4 IV words into REG03 in big-endian order. | |
| static void | internal_channel_reset (volatile ra8_dotf_regs_t *reg) |
| Reset one channel's hardware to power-on state. | |
| static void | internal_state_reset (uint8_t channel) |
| Wipe all software state for one channel. | |
| ra8_err_t | ra8_dotf_init (void) |
| Power on the DOTF block and reset both channels. | |
| ra8_err_t | ra8_dotf_deinit (void) |
| Disable DOTF and gate the OSPI clock. | |
| ra8_err_t | ra8_dotf_set_region (uint8_t channel, const ra8_dotf_region_t *region) |
| Stage one DOTF region in the channel's region table. | |
| ra8_err_t | ra8_dotf_select_region (uint8_t channel, uint8_t region_id) |
| Promote a staged region into the live CONVAREAST / CONVAREAD pair. | |
| ra8_err_t | ra8_dotf_get_active_region (uint8_t channel, ra8_dotf_region_t *region) |
| Read back the active region for a channel. | |
| ra8_err_t | ra8_dotf_install_key (uint8_t channel, const ra8_dotf_key_handle_t *handle) |
| Bind a wrapped AES key handle to a DOTF channel. | |
| ra8_err_t | ra8_dotf_set_iv (uint8_t channel, const uint32_t *iv_words) |
| Stage the AES counter-mode IV for a channel via REG03. | |
| static void | internal_rotate_iv (ra8_dotf_chan_state_t *st, volatile ra8_dotf_regs_t *reg, const uint32_t *iv_words) |
| Re-stage the IV for a rotate-key call. | |
| static ra8_err_t | internal_validate_rotate_inputs (uint8_t channel, const ra8_dotf_key_handle_t *new_handle) |
| Validate the inputs to ra8_dotf_rotate_key. | |
| ra8_err_t | ra8_dotf_rotate_key (uint8_t channel, const ra8_dotf_key_handle_t *new_handle, const uint32_t *iv_words) |
| Atomically rotate the key bound to a channel. | |
| ra8_err_t | ra8_dotf_enable (uint8_t channel) |
| Enable AES decryption for one channel. | |
| ra8_err_t | ra8_dotf_disable (uint8_t channel) |
| Disable AES decryption for one channel (transparent bypass). | |
| ra8_err_t | ra8_dotf_set_sca_level (uint8_t channel, ra8_dotf_sca_level_t level) |
| Update the side-channel countermeasure level for a channel. | |
| ra8_err_t | ra8_dotf_set_key_size (uint8_t channel, ra8_dotf_key_size_t size) |
| Update the cached AES key size for a channel. | |
| ra8_err_t | ra8_dotf_run_self_test (uint8_t channel, uint32_t *out_status) |
| Trigger the built-in self-test (REG00 bit 20) for a channel. | |
| ra8_err_t | ra8_dotf_get_status (uint8_t channel, uint32_t *out_mask) |
| Read REG00 (raw control / status snapshot). | |
| ra8_err_t | ra8_dotf_clear_status (uint8_t channel) |
| Clear REG00 (force the channel into bypass). | |
| ra8_err_t | ra8_dotf_attach_handler (ra8_dotf_event_fn_t fn, void *ctx) |
| Register a fault / event callback (shared across both channels). | |
| void | ra8_dotf_dispatch (uint8_t channel) |
| Dispatch a DOTF event from the IRQ glue. | |
Variables | |
| static const char * | s_tag = "DOTF" |
| Logging tag for ra8_log_* calls. | |
| static ra8_dotf_event_fn_t | s_dotf_fn |
| Active fault / event callback. | |
| static void * | s_dotf_ctx |
| Caller-supplied context handed to s_dotf_fn. | |
| static ra8_dotf_chan_state_t | s_dotf_state [k_ra8_dotf_channel_count] |
| Per-channel state table. | |
| static const ra8_mstp_t | s_dotf_mstp_table [k_ra8_dotf_channel_count] |
| Channel-index -> MSTP id lookup. | |
Decryption On The Fly (DOTF) HAL driver implementation.
Full HUM Ch 45 (p 3048..3050) coverage of the RA8D2 DOTF block. Layered on top of the OSPI MSTP gating; every register access carries a HUM Ch 45 citation. See ra8_dotf.h for the public surface.
Driver-side state:
Definition in file ra8_dotf.c.
| enum ra8_dotf_bswap_const_t : uint32_t |
Byte-extraction masks and shift counts for internal_bswap32.
REG03 of the OSPI / DOTF FIFO is big-endian; both the host build and the RA8D2 are little-endian, so we always swap. These named constants replace the magic numbers flagged by clang-tidy (readability-magic-numbers) and document each byte position.
Definition at line 62 of file ra8_dotf.c.
| enum ra8_dotf_bswap_shift_t : uint8_t |
Shift counts used by internal_bswap32.
| Enumerator | |
|---|---|
| k_ra8_dotf_bswap_shift_byte | Shift for one-byte slide. |
| k_ra8_dotf_bswap_shift_word | Shift for byte0 <-> byte3. |
Definition at line 74 of file ra8_dotf.c.
| enum ra8_dotf_key_word_count_t : uint8_t |
Wrapped-key word counts per AES key size.
The wrapped-key payload bytes are a vendor-defined RSIP envelope; the FSP reference uses HW_SCE_AES{128,192,256}_KEY_INDEX_WORD_SIZE for the ratio. RA8D2 uses 4-word / 6-word / 8-word envelopes for the 128 / 192 / 256-bit keys respectively when staged through the OutputKeyForDotf paths (r_ospi_b.c).
| Enumerator | |
|---|---|
| k_ra8_dotf_key_words_128 | RA8 dotf key words 128. |
| k_ra8_dotf_key_words_192 | RA8 dotf key words 192. |
| k_ra8_dotf_key_words_256 | RA8 dotf key words 256. |
Definition at line 90 of file ra8_dotf.c.
| enum ra8_dotf_misc_t : uint8_t |
Internal small constants (no magic numbers).
| Enumerator | |
|---|---|
| k_ra8_dotf_no_region | Sentinel for "no region active". |
| k_ra8_dotf_self_test_spin | Bounded poll budget for self-test bit. |
Definition at line 47 of file ra8_dotf.c.
|
static |
Assemble the REG00 word for the channel's cached state.
See implementation.
| [in] | st | See implementation. |
| [in] | enable | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 395 of file ra8_dotf.c.
References ra8_dotf_chan_state_t::cached_key_size, ra8_dotf_chan_state_t::cached_sca, internal_sca_bits(), k_ra8_dotf_reg00_aes_enable, and k_ra8_dotf_reg00_mode_ctr.
Referenced by ra8_dotf_enable(), ra8_dotf_rotate_key(), ra8_dotf_set_key_size(), and ra8_dotf_set_sca_level().
|
inlinestatic |
Big-endian byte-swap of a 32-bit word.
REG03 is a big-endian FIFO per the FSP reference (r_ospi_b.c uses bswap_32big / change_endian_long). The host build runs little-endian and the target Cortex-M85 also runs little- endian, so an explicit byte-swap is required either way.
| [in] | v | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 293 of file ra8_dotf.c.
References k_ra8_dotf_bswap_byte0, k_ra8_dotf_bswap_byte1, k_ra8_dotf_bswap_byte2, k_ra8_dotf_bswap_byte3, k_ra8_dotf_bswap_shift_byte, and k_ra8_dotf_bswap_shift_word.
Referenced by internal_stage_iv(), and internal_stage_key().
|
inlinestatic |
Bound-check a channel index.
| [in] | channel | Caller-provided channel value. |
See implementation.
| k_ra8_ok | Operation succeeded. |
Definition at line 176 of file ra8_dotf.c.
References k_ra8_dotf_channel_count.
Referenced by internal_validate_rotate_inputs(), ra8_dotf_clear_status(), ra8_dotf_disable(), ra8_dotf_dispatch(), ra8_dotf_enable(), ra8_dotf_get_active_region(), ra8_dotf_get_status(), ra8_dotf_install_key(), ra8_dotf_run_self_test(), ra8_dotf_select_region(), ra8_dotf_set_iv(), ra8_dotf_set_key_size(), ra8_dotf_set_region(), and ra8_dotf_set_sca_level().
|
inlinestatic |
Reset one channel's hardware to power-on state.
See implementation.
| [in] | reg | See implementation. |
Definition at line 469 of file ra8_dotf.c.
References ra8_dotf_regs_t::CONVAREAD, ra8_dotf_regs_t::CONVAREAST, k_ra8_dotf_reg00_disable_value, and ra8_dotf_regs_t::REG00.
Referenced by ra8_dotf_init().
|
static |
Reject a region that overlaps the live region of the OTHER channel.
See implementation.
| [in] | channel | See implementation. |
| [in] | region | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 359 of file ra8_dotf.c.
References ra8_dotf_chan_state_t::active_region_id, ra8_dotf_region_t::end_addr, k_ra8_dotf_channel_count, k_ra8_dotf_no_region, k_ra8_err_conflict, k_ra8_ok, ra8_dotf_chan_state_t::regions, s_dotf_state, and ra8_dotf_region_t::start_addr.
Referenced by ra8_dotf_set_region().
|
inlinestatic |
Word count for a given AES key size.
See implementation.
| [in] | size | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 236 of file ra8_dotf.c.
References k_ra8_dotf_key_size_192, k_ra8_dotf_key_size_256, k_ra8_dotf_key_words_128, k_ra8_dotf_key_words_192, and k_ra8_dotf_key_words_256.
Referenced by internal_stage_key().
|
static |
Re-stage the IV for a rotate-key call.
If the caller provided iv_words we cache them and push them through internal_stage_iv. If the caller passed nullptr but a previous IV is cached, re-stage that one. Otherwise leave the IV registers untouched. HUM Ch 45.3 "Register Descriptions" p 3049.
| [in,out] | st | Channel state slot. |
| [in] | reg | MMIO base for the channel. |
| [in] | iv_words | Optional new IV word array. |
Definition at line 702 of file ra8_dotf.c.
References internal_stage_iv(), ra8_dotf_chan_state_t::iv_cache, ra8_dotf_chan_state_t::iv_valid, and k_ra8_dotf_iv_word_count.
Referenced by ra8_dotf_rotate_key().
|
inlinestatic |
Map an SCA level enum into REG00 SCA bits.
See implementation.
| [in] | level | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 262 of file ra8_dotf.c.
References k_ra8_dotf_reg00_sca_en, k_ra8_dotf_reg00_sca_mode, k_ra8_dotf_sca_max, and k_ra8_dotf_sca_standard.
Referenced by internal_assemble_reg00().
|
static |
Stage 4 IV words into REG03 in big-endian order.
See implementation.
| [in] | reg | See implementation. |
| [in] | iv | See implementation. |
Definition at line 446 of file ra8_dotf.c.
References internal_bswap32(), k_ra8_dotf_iv_word_count, and ra8_dotf_regs_t::REG03.
Referenced by internal_rotate_iv(), and ra8_dotf_set_iv().
|
static |
Stage a wrapped-key payload into REG03.
See implementation.
| [in] | reg | See implementation. |
| [in] | h | See implementation. |
Definition at line 420 of file ra8_dotf.c.
References internal_bswap32(), internal_key_words(), ra8_dotf_regs_t::REG03, ra8_dotf_key_handle_t::size, and ra8_dotf_key_handle_t::words.
Referenced by ra8_dotf_install_key(), and ra8_dotf_rotate_key().
|
static |
Wipe all software state for one channel.
See implementation.
| [in] | channel | See implementation. |
Definition at line 493 of file ra8_dotf.c.
References ra8_dotf_chan_state_t::active_region_id, ra8_dotf_chan_state_t::cached_key_size, ra8_dotf_chan_state_t::cached_sca, ra8_dotf_chan_state_t::enabled, ra8_dotf_region_t::end_addr, ra8_dotf_chan_state_t::iv_cache, ra8_dotf_chan_state_t::iv_valid, k_ra8_dotf_iv_word_count, k_ra8_dotf_key_size_128, k_ra8_dotf_max_regions, k_ra8_dotf_no_region, k_ra8_dotf_sca_standard, ra8_dotf_chan_state_t::key, ra8_dotf_key_handle_t::key_index, ra8_dotf_region_t::key_index, ra8_dotf_region_t::region_id, ra8_dotf_chan_state_t::region_valid, ra8_dotf_chan_state_t::regions, s_dotf_state, ra8_dotf_key_handle_t::size, ra8_dotf_region_t::start_addr, ra8_dotf_key_handle_t::valid, and ra8_dotf_key_handle_t::words.
Referenced by ra8_dotf_deinit(), and ra8_dotf_init().
|
static |
Validate region range / alignment / window.
See implementation.
| [in] | channel | See implementation. |
| [in] | region | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 317 of file ra8_dotf.c.
References ra8_dotf_region_t::end_addr, internal_window_hi(), internal_window_lo(), k_ra8_dotf_addr_low_mask, k_ra8_dotf_max_regions, k_ra8_err_invalid_arg, k_ra8_ok, ra8_dotf_region_t::region_id, and ra8_dotf_region_t::start_addr.
Referenced by ra8_dotf_set_region().
|
static |
Validate the inputs to ra8_dotf_rotate_key.
Range-checks channel and the wrapped-key fields, and rejects calls that try to rotate before any region was activated. The check for new_handle != nullptr is the caller's responsibility.
| [in] | channel | Channel index. |
| [in] | new_handle | Caller-supplied wrapped key. |
| k_ra8_err_invalid_arg | channel out of range or handle malformed. |
| k_ra8_err_invalid_state | ra8_dotf_install_region not yet called. |
Definition at line 744 of file ra8_dotf.c.
References internal_channel_in_range(), k_ra8_dotf_key_size_128, k_ra8_dotf_key_size_192, k_ra8_dotf_key_size_256, k_ra8_dotf_no_region, k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_ok, s_dotf_state, ra8_dotf_key_handle_t::size, and ra8_dotf_key_handle_t::valid.
Referenced by ra8_dotf_rotate_key().
|
inlinestatic |
XSPI window high bound for a given DOTF channel.
See implementation.
| [in] | channel | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 216 of file ra8_dotf.c.
References k_ra8_dotf0_window_hi, and k_ra8_dotf1_window_hi.
Referenced by internal_validate_region().
|
inlinestatic |
XSPI window low bound for a given DOTF channel.
See implementation.
| [in] | channel | See implementation. |
| k_ra8_ok | Operation succeeded. |
Definition at line 196 of file ra8_dotf.c.
References k_ra8_dotf0_window_lo, and k_ra8_dotf1_window_lo.
Referenced by internal_validate_region().
|
nodiscard |
Register a fault / event callback (shared across both channels).
DOTF on its own does not raise an IRQ – faults surface through the matching xSPI controller's INTS register. The platform IRQ glue forwards the channel index to ra8_dotf_dispatch which fires this callback. Useful for telemetry on key-mismatch / illegal-region hits during bring-up.
| [in] | fn | Callback fired on dispatch. |
| [in] | ctx | Context forwarded to the callback. |
Definition at line 948 of file ra8_dotf.c.
References k_ra8_ok, s_dotf_ctx, and s_dotf_fn.
|
nodiscard |
Clear REG00 (force the channel into bypass).
| [in] | channel | Channel index 0..1. |
Definition at line 928 of file ra8_dotf.c.
References internal_channel_in_range(), k_ra8_dotf_reg00_disable_value, k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_dotf_regs(), ra8_dotf_regs_t::REG00, s_dotf_state, and s_tag.
|
nodiscard |
Disable DOTF and gate the OSPI clock.
Definition at line 545 of file ra8_dotf.c.
References internal_state_reset(), k_ra8_dotf_channel_count, k_ra8_dotf_reg00_disable_value, k_ra8_ok, ra8_dotf_regs(), ra8_mstp_disable(), ra8_dotf_regs_t::REG00, s_dotf_ctx, s_dotf_fn, and s_dotf_mstp_table.
Referenced by ra8_dotf_close().
|
nodiscard |
Disable AES decryption for one channel (transparent bypass).
| [in] | channel | Channel index 0..1. |
Definition at line 823 of file ra8_dotf.c.
References internal_channel_in_range(), k_ra8_dotf_reg00_disable_value, k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_dotf_regs(), ra8_dotf_regs_t::REG00, s_dotf_state, and s_tag.
| void ra8_dotf_dispatch | ( | uint8_t | channel | ) |
Dispatch a DOTF event from the IRQ glue.
| [in] | channel | Channel index 0..1 that raised the event. Out of range channels are dropped silently. |
See implementation.
Definition at line 956 of file ra8_dotf.c.
References internal_channel_in_range(), s_dotf_ctx, and s_dotf_fn.
|
nodiscard |
Enable AES decryption for one channel.
Writes the cached REG00 word (default 0x2200_0000 ORed with the bound key-size bits, the SCA bits, and the enable bit). The channel must have a key staged and a region selected.
| [in] | channel | Channel index 0..1. |
Definition at line 804 of file ra8_dotf.c.
References ra8_dotf_chan_state_t::enabled, internal_assemble_reg00(), internal_channel_in_range(), k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_dotf_regs(), ra8_log_info_val, ra8_dotf_regs_t::REG00, s_dotf_state, and s_tag.
Referenced by internal_open_finalise().
|
nodiscard |
Read back the active region for a channel.
| [in] | channel | Channel index 0..1. |
| [out] | region | Receives a copy of the active descriptor. |
| k_ra8_ok | Descriptor returned. |
| k_ra8_err_null_ptr | region is NULL. |
| k_ra8_err_invalid_arg | Channel out of range. |
| k_ra8_err_invalid_state | No region active on channel. |
Definition at line 618 of file ra8_dotf.c.
References ra8_dotf_chan_state_t::active_region_id, internal_channel_in_range(), k_ra8_dotf_no_region, k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_dotf_chan_state_t::regions, s_dotf_state, and s_tag.
|
nodiscard |
Read REG00 (raw control / status snapshot).
| [in] | channel | Channel index 0..1. |
| [out] | out_mask | Receives REG00 contents. |
Definition at line 913 of file ra8_dotf.c.
References internal_channel_in_range(), k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_dotf_regs(), ra8_dotf_regs_t::REG00, and s_tag.
Referenced by internal_dotf_demo_sample().
|
nodiscard |
Power on the DOTF block and reset both channels.
Clears MSTPB16 (DOTF0 + XSPI0) and MSTPB17 (DOTF1 + XSPI1) via ra8_mstp_enable, then writes 0 to each channel's REG00 and clears CONVAREAST / CONVAREAD to their reset values. Also scrubs every staged region slot, the IV cache, and the bound key handles.
| k_ra8_ok | DOTF clocked and zeroed. |
| k_ra8_err_hw_init_failed | MSTP enable failed for either id. |
Definition at line 524 of file ra8_dotf.c.
References internal_channel_reset(), internal_state_reset(), k_ra8_dotf_channel_count, k_ra8_err_hw_init_failed, k_ra8_ok, ra8_dotf_regs(), ra8_log_info, ra8_mstp_enable(), RA8_RETURN_ON_ERROR, s_dotf_ctx, s_dotf_fn, s_dotf_mstp_table, and s_tag.
Referenced by internal_open_validate_init(), and main().
|
nodiscard |
Bind a wrapped AES key handle to a DOTF channel.
Copies the handle into the driver's per-channel slot and stages the wrapped-key payload into REG03 in big-endian word order. The channel is left disabled; the AES core only goes hot once ra8_dotf_enable (or ra8_dotf_rotate_key) is called. The HAL does not unwrap the key – that work belongs to ra8_rsip and runs before this call. The handle's size field is mirrored into the driver's REG00 cache so subsequent ra8_dotf_enable writes the correct key-size bits.
| [in] | channel | Channel index 0..1. |
| [in] | handle | Non-NULL handle. handle->valid must be non-0. |
| k_ra8_ok | Key staged. |
| k_ra8_err_null_ptr | handle is NULL. |
| k_ra8_err_invalid_arg | Channel out of range or handle invalid. |
Definition at line 637 of file ra8_dotf.c.
References ra8_dotf_chan_state_t::cached_key_size, internal_channel_in_range(), internal_stage_key(), k_ra8_dotf_key_size_128, k_ra8_dotf_key_size_192, k_ra8_dotf_key_size_256, k_ra8_err_invalid_arg, k_ra8_ok, ra8_dotf_chan_state_t::key, RA8_CHECK_NULL_PTR, ra8_dotf_regs(), ra8_log_info_val, s_dotf_state, s_tag, ra8_dotf_key_handle_t::size, and ra8_dotf_key_handle_t::valid.
Referenced by internal_open_stage_key_iv_region().
|
nodiscard |
Atomically rotate the key bound to a channel.
Quiesces the channel (writes 0 to REG00), re-stages the new wrapped key + IV, then re-arms the AES core with the cached key- size and SCA settings. Used by the bootloader to swap signing keys during anti-rollback handling.
Sequence:
| [in] | channel | Channel index 0..1. |
| [in] | new_handle | Non-NULL replacement key. |
| [in] | iv_words | k_ra8_dotf_iv_word_count words of new IV (or NULL to reuse the current IV). |
| k_ra8_ok | Rotation complete. |
| k_ra8_err_null_ptr | new_handle is NULL. |
| k_ra8_err_invalid_arg | Channel out of range or handle invalid. |
| k_ra8_err_invalid_state | No region active on the channel. |
Definition at line 764 of file ra8_dotf.c.
References ra8_dotf_chan_state_t::cached_key_size, ra8_dotf_chan_state_t::enabled, internal_assemble_reg00(), internal_rotate_iv(), internal_stage_key(), internal_validate_rotate_inputs(), k_ra8_dotf_reg00_disable_value, k_ra8_ok, ra8_dotf_chan_state_t::key, RA8_CHECK_NULL_PTR, ra8_dotf_regs(), ra8_log_info_val, RA8_RETURN_ON_ERROR, ra8_dotf_regs_t::REG00, s_dotf_state, s_tag, and ra8_dotf_key_handle_t::size.
|
nodiscard |
Trigger the built-in self-test (REG00 bit 20) for a channel.
HUM Ch 45.1 p 3048 ("Supports self-test function"). Sets bit 20 of REG00, polls for completion by re-reading REG00 a bounded number of times, and returns the post-test snapshot via out_status. The bit auto-clears in real hardware; in the fake the bit remains set after the spin (the host has no way to model AES timing) – callers MUST treat out_status as opaque diagnostic data, not a pass/fail indicator on the host.
| [in] | channel | Channel index 0..1. |
| [out] | out_status | Non-NULL diagnostic snapshot. |
| k_ra8_ok | Self-test triggered. |
| k_ra8_err_null_ptr | out_status is NULL. |
| k_ra8_err_invalid_arg | Channel out of range. |
| k_ra8_err_hw_timeout | SELF_TEST did not clear within the bounded wait. |
Definition at line 883 of file ra8_dotf.c.
References internal_channel_in_range(), k_ra8_dotf_reg00_self_test, k_ra8_dotf_self_test_spin, k_ra8_err_invalid_arg, RA8_CHECK_NULL_PTR, ra8_dotf_regs(), ra8_hw_wait_flag_clear32(), ra8_dotf_regs_t::REG00, and s_tag.
Referenced by internal_dotf_demo_sample().
|
nodiscard |
Promote a staged region into the live CONVAREAST / CONVAREAD pair.
Atomically writes CONVAREAD then CONVAREAST (in that order per the FSP reference comment "Set the end and start area for DOTF conversion in that order to ensure that end address is always higher than start address.", r_ospi_b.c). Caller is expected to have called ra8_dotf_disable first; the function does NOT clear REG00 itself so the AES core stays primed for the subsequent ra8_dotf_enable call.
| [in] | channel | Channel index 0..1. |
| [in] | region_id | Slot index in the channel's region table. |
| k_ra8_ok | Region promoted. |
| k_ra8_err_invalid_arg | Out-of-range channel or region_id. |
| k_ra8_err_invalid_state | The slot has not been staged. |
Definition at line 591 of file ra8_dotf.c.
References ra8_dotf_chan_state_t::active_region_id, ra8_dotf_regs_t::CONVAREAD, ra8_dotf_regs_t::CONVAREAST, ra8_dotf_region_t::end_addr, internal_channel_in_range(), k_ra8_dotf_addr_mask, k_ra8_dotf_max_regions, k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_dotf_regs(), ra8_dotf_chan_state_t::region_valid, ra8_dotf_chan_state_t::regions, s_dotf_state, s_tag, and ra8_dotf_region_t::start_addr.
Referenced by internal_open_stage_key_iv_region().
|
nodiscard |
Stage the AES counter-mode IV for a channel via REG03.
Per HUM Ch 45.1 p 3048 the AES counter is {IV[127:28], Address[31:4]}. Software still loads a full 128-bit IV; the hardware silently overwrites the bottom 28 bits with the AXI address bits at decryption time. The four 32-bit words are written into REG03 in big-endian byte order, mirroring the FSP reference (r_ospi_b.c).
| [in] | channel | Channel index 0..1. |
| [in] | iv_words | Pointer to k_ra8_dotf_iv_word_count words. |
| k_ra8_ok | Words written. |
| k_ra8_err_null_ptr | iv_words is NULL. |
| k_ra8_err_invalid_arg | Channel out of range. |
Definition at line 661 of file ra8_dotf.c.
References internal_channel_in_range(), internal_stage_iv(), ra8_dotf_chan_state_t::iv_cache, ra8_dotf_chan_state_t::iv_valid, k_ra8_dotf_iv_word_count, k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_dotf_regs(), s_dotf_state, and s_tag.
Referenced by internal_open_stage_key_iv_region().
|
nodiscard |
Update the cached AES key size for a channel.
| [in] | channel | Channel index 0..1. |
| [in] | size | k_ra8_dotf_key_size_*. |
| k_ra8_ok | Size cached; if armed, REG00 updated. |
| k_ra8_err_invalid_arg | Channel out of range or unknown size. |
Definition at line 863 of file ra8_dotf.c.
References ra8_dotf_chan_state_t::cached_key_size, ra8_dotf_chan_state_t::enabled, internal_assemble_reg00(), internal_channel_in_range(), k_ra8_dotf_key_size_128, k_ra8_dotf_key_size_192, k_ra8_dotf_key_size_256, k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_dotf_regs(), ra8_dotf_regs_t::REG00, s_dotf_state, and s_tag.
|
nodiscard |
Stage one DOTF region in the channel's region table.
Validates 4 KB alignment, start <= end, that the region falls entirely inside the matching channel's XSPI window ([0x8000_0000..0x9FFF_FFFF] for DOTF0, [0x7000_0000.. 0x7FFF_FFFF] for DOTF1), and that the region does NOT overlap the other channel's currently-armed region. On success the descriptor is copied into slot region->region_id of the channel's staging table; the slot becomes "live" only when ra8_dotf_select_region(channel, region_id) is called.
| [in] | channel | Channel index 0..1. |
| [in] | region | Non-NULL region descriptor. |
| k_ra8_ok | Region staged. |
| k_ra8_err_null_ptr | region is NULL. |
| k_ra8_err_invalid_arg | channel or region_id out of range, addresses not 4 KB aligned, start > end, or region escapes the matching XSPI window. |
| k_ra8_err_conflict | Region overlaps the other channel's currently-armed region. |
Definition at line 569 of file ra8_dotf.c.
References internal_channel_in_range(), internal_check_overlap(), internal_validate_region(), k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_info_val, ra8_log_warn_val, ra8_dotf_region_t::region_id, ra8_dotf_chan_state_t::region_valid, ra8_dotf_chan_state_t::regions, s_dotf_state, and s_tag.
Referenced by internal_open_stage_key_iv_region(), and ra8_dotf_set_region_window().
|
nodiscard |
Update the side-channel countermeasure level for a channel.
| [in] | channel | Channel index 0..1. |
| [in] | level | k_ra8_dotf_sca_off / standard / max. |
| k_ra8_ok | Cached and (if armed) written through. |
| k_ra8_err_invalid_arg | Channel out of range or unknown level. |
Definition at line 843 of file ra8_dotf.c.
References ra8_dotf_chan_state_t::cached_sca, ra8_dotf_chan_state_t::enabled, internal_assemble_reg00(), internal_channel_in_range(), k_ra8_dotf_sca_max, k_ra8_dotf_sca_off, k_ra8_dotf_sca_standard, k_ra8_err_invalid_arg, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_dotf_regs(), ra8_dotf_regs_t::REG00, s_dotf_state, and s_tag.
Referenced by internal_open_finalise().
|
static |
Caller-supplied context handed to s_dotf_fn.
Definition at line 130 of file ra8_dotf.c.
Referenced by ra8_dotf_attach_handler(), ra8_dotf_deinit(), ra8_dotf_dispatch(), and ra8_dotf_init().
|
static |
Active fault / event callback.
nullptr means "no callback".
Definition at line 124 of file ra8_dotf.c.
Referenced by ra8_dotf_attach_handler(), ra8_dotf_deinit(), ra8_dotf_dispatch(), and ra8_dotf_init().
|
static |
Channel-index -> MSTP id lookup.
DOTF0 + XSPI0 share MSTPB16; DOTF1 + XSPI1 share MSTPB17 (HUM Ch 11.2.7 MSTPCRB description references both peripherals). The MSTP wrapper enums in ra8_mstp_regs.h already encode this as k_ra8_mstp_ospi0 / k_ra8_mstp_ospi1 – the comments call them out as "OSPI0+DOTF0" / "OSPI1+DOTF1" so we just reuse them here rather than minting DOTF-specific aliases.
Definition at line 150 of file ra8_dotf.c.
Referenced by ra8_dotf_deinit(), ra8_dotf_enter_stop(), ra8_dotf_exit_stop(), and ra8_dotf_init().
|
static |
Per-channel state table.
Definition at line 136 of file ra8_dotf.c.
Referenced by internal_check_overlap(), internal_state_reset(), internal_validate_rotate_inputs(), ra8_dotf_clear_status(), ra8_dotf_disable(), ra8_dotf_enable(), ra8_dotf_get_active_region(), ra8_dotf_install_key(), ra8_dotf_rotate_key(), ra8_dotf_select_region(), ra8_dotf_set_iv(), ra8_dotf_set_key_size(), ra8_dotf_set_region(), and ra8_dotf_set_sca_level().
|
static |
Logging tag for ra8_log_* calls.
Definition at line 116 of file ra8_dotf.c.