ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_dotf_power.c
Go to the documentation of this file.
1
21
22#include <stdint.h>
23
24#include "ra8_check.h"
25#include "ra8_dotf.h"
26#include "ra8_dotf_regs.h"
27#include "ra8_err.h"
28#include "ra8_hal_internal.h"
29#include "ra8_log.h"
30#include "ra8_mstp.h"
31
36static const char* s_tag = "DOTF";
37
54
55/* =============================================================================
56 * Power
57 * =============================================================================
58 */
59
93{
96 }
97 /* Step 1: Power on the DOTF block (idempotent). HUM Ch 45.6.1 p 3050. */
98 const ra8_err_t init_err = ra8_dotf_init();
99 RA8_RETURN_ON_ERROR(init_err, s_tag, "open: init");
100 return k_ra8_ok;
101}
102
138{
139 /* Step 2: Install the wrapped key. HUM Ch 45.3 p 3049 (REG03 staging). */
140 const ra8_err_t key_err = ra8_dotf_install_key(cfg->channel, &cfg->key);
141 RA8_RETURN_ON_ERROR(key_err, s_tag, "open: install_key");
142
143 /* Step 3: Stage the IV. HUM Ch 45.1 p 3048 (counter mode). */
144 const ra8_err_t iv_err = ra8_dotf_set_iv(cfg->channel, cfg->iv_words);
145 /* GCOVR_EXCL_BR_START -- embedded IV is non-null and channel was range-checked */
146 RA8_RETURN_ON_ERROR(iv_err, s_tag, "open: set_iv");
147 /* GCOVR_EXCL_BR_STOP */
148
149 /* Step 4: Stage the conversion region. HUM Ch 45.3.1 / 45.3.2 p 3049. */
150 const ra8_err_t reg_err = ra8_dotf_set_region(cfg->channel, &cfg->region);
151 RA8_RETURN_ON_ERROR(reg_err, s_tag, "open: set_region");
152
153 /* Step 5: Promote to live region. */
154 const ra8_err_t sel_err = ra8_dotf_select_region(cfg->channel, cfg->region.region_id);
155 /* GCOVR_EXCL_BR_START -- successful set_region made this same id live-selectable */
156 RA8_RETURN_ON_ERROR(sel_err, s_tag, "open: select_region");
157 /* GCOVR_EXCL_BR_STOP */
158 return k_ra8_ok;
159}
160
191{
192 /* Step 6: Side-channel level. */
193 const ra8_err_t sca_err = ra8_dotf_set_sca_level(cfg->channel, cfg->sca_level);
194 RA8_RETURN_ON_ERROR(sca_err, s_tag, "open: set_sca_level");
195
196 /* Step 7: Optionally arm the AES core. */
197 if (cfg->enable_after) {
198 /* GCOVR_EXCL_BR_START -- validated channel maps to a non-null static DOTF block */
199 const ra8_err_t en_err = ra8_dotf_enable(cfg->channel);
200 RA8_RETURN_ON_ERROR(en_err, s_tag, "open: enable");
201 /* GCOVR_EXCL_BR_STOP */
202 }
203 return k_ra8_ok;
204}
205
207{
208 RA8_CHECK_NULL_PTR(cfg, s_tag, "cfg must not be nullptr");
209
210 const ra8_err_t vi_err = internal_open_validate_init(cfg);
211 RA8_RETURN_ON_ERROR(vi_err, s_tag, "open: validate_init");
212
214 RA8_RETURN_ON_ERROR(st_err, s_tag, "open: stage");
215
216 const ra8_err_t fi_err = internal_open_finalise(cfg);
217 RA8_RETURN_ON_ERROR(fi_err, s_tag, "open: finalise");
218 return k_ra8_ok;
219}
220
221[[nodiscard]] ra8_err_t ra8_dotf_close(void)
222{
223 /* Symmetric companion to ra8_dotf_open. HUM Ch 45.6.1 p 3050. */
224 return ra8_dotf_deinit();
225}
226
227[[nodiscard]] ra8_err_t ra8_dotf_set_region_window(uint8_t channel, uint32_t start, uint32_t len)
228{
231 }
232 if (len == 0U) {
234 }
235 if ((start & k_ra8_dotf_addr_low_mask) != 0U) {
237 }
238 if ((len & k_ra8_dotf_addr_low_mask) != 0U) {
240 }
241 /* HUM Ch 45.3.1 "CONVAREAST" p 3049 */
242 /* HUM Ch 45.3.2 "CONVAREAD" p 3049 */
243 /* end address is inclusive. */
244 const ra8_dotf_region_t r = {
245 .start_addr = start,
246 .end_addr = start + len - 1U,
247 .key_index = 0U,
248 .region_id = 0U,
249 };
250 return ra8_dotf_set_region(channel, &r);
251}
252
254{
255 for (uint8_t ch = 0U; ch < k_ra8_dotf_channel_count; ++ch) {
256 /* HUM Ch 45.6.1 "Module-stop Function" p 3050 */
258 }
259 return k_ra8_ok;
260}
261
262[[nodiscard]] ra8_err_t ra8_dotf_exit_stop(void)
263{
264 for (uint8_t ch = 0U; ch < k_ra8_dotf_channel_count; ++ch) {
265 /* HUM Ch 45.6.1 "Module-stop Function" p 3050 */
266 const ra8_err_t mst_err = ra8_mstp_enable(s_dotf_mstp_table[ch]);
267 /* GCOVR_EXCL_BR_START -- ra8_mstp_enable() error edge in the per-channel stop-exit loop */
268 RA8_RETURN_ON_ERROR(mst_err, s_tag, "exit_stop: mstp enable failed");
269 /* GCOVR_EXCL_BR_STOP */
270 }
271 return k_ra8_ok;
272}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
Definition ra8_check.h:184
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
static const ra8_mstp_t s_dotf_mstp_table[k_ra8_dotf_channel_count]
Channel-index -> MSTP id lookup.
Definition ra8_dotf.c:150
Decryption On The Fly (DOTF) HAL driver public API.
ra8_err_t ra8_dotf_deinit(void)
Disable DOTF and gate the OSPI clock.
Definition ra8_dotf.c:545
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.
Definition ra8_dotf.c:843
ra8_err_t ra8_dotf_enable(uint8_t channel)
Enable AES decryption for one channel.
Definition ra8_dotf.c:804
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.
Definition ra8_dotf.c:637
ra8_err_t ra8_dotf_select_region(uint8_t channel, uint8_t region_id)
Promote a staged region into the live CONVAREAST / CONVAREAD pair.
Definition ra8_dotf.c:591
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.
Definition ra8_dotf.c:661
ra8_err_t ra8_dotf_init(void)
Power on the DOTF block and reset both channels.
Definition ra8_dotf.c:524
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.
Definition ra8_dotf.c:569
static ra8_err_t internal_open_stage_key_iv_region(const ra8_dotf_open_cfg_t *cfg)
Stage the wrapped key, IV, and conversion region for ra8_dotf_open.
ra8_err_t ra8_dotf_exit_stop(void)
Bring the DOTF block back from low-power mode.
ra8_err_t ra8_dotf_close(void)
Tear down DOTF and release all hardware state.
ra8_err_t ra8_dotf_enter_stop(void)
Park the DOTF block prior to entering a low-power mode.
ra8_err_t ra8_dotf_open(const ra8_dotf_open_cfg_t *cfg)
One-shot DOTF bring-up: init + install_key + set_iv + set_region (+ enable).
ra8_err_t ra8_dotf_set_region_window(uint8_t channel, uint32_t start, uint32_t len)
Stage a region from a (start, length) pair instead of a struct.
static ra8_err_t internal_open_finalise(const ra8_dotf_open_cfg_t *cfg)
Apply SCA level and (optionally) arm the AES core.
static ra8_err_t internal_open_validate_init(const ra8_dotf_open_cfg_t *cfg)
Validate ra8_dotf_open inputs and power up the DOTF block.
Decryption On The Fly (DOTF) register layout for the Renesas RA8D2.
@ k_ra8_dotf_channel_count
DOTF0 + DOTF1.
@ k_ra8_dotf_addr_low_mask
Low 12 bits read as 0/1 (HUM).
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Cross-translation-unit private helpers shared inside ra8_hal.
static bool internal_ra8_dotf_internal_channel_in_range(uint8_t channel)
Bound-check a DOTF channel index.
Lightweight Logging Interface for ra8-firmware.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_enable(ra8_mstp_t id)
Reference-counted "ungate this peripheral" request.
Definition ra8_mstp.c:343
ra8_err_t ra8_mstp_disable(ra8_mstp_t id)
Reference-counted "gate this peripheral" request.
Definition ra8_mstp.c:382
ra8_mstp_t
Packed (reg << 8) | bit module-stop identifier.
@ k_ra8_mstp_ospi0
MSTPB16 OSPI0+DOTF0.
@ k_ra8_mstp_ospi1
MSTPB17 OSPI1+DOTF1.
One-shot DOTF bring-up descriptor consumed by ra8_dotf_open.
Definition ra8_dotf.h:690
bool enable_after
true => arm AES after staging.
Definition ra8_dotf.h:696
uint32_t iv_words[4]
128-bit IV in word order.
Definition ra8_dotf.h:693
ra8_dotf_sca_level_t sca_level
Side-channel level.
Definition ra8_dotf.h:695
uint8_t channel
0 = DOTF0, 1 = DOTF1.
Definition ra8_dotf.h:691
ra8_dotf_key_handle_t key
RSIP-wrapped key handle.
Definition ra8_dotf.h:692
ra8_dotf_region_t region
Initial conversion region.
Definition ra8_dotf.h:694
Conversion-area descriptor for ra8_dotf_set_region.
Definition ra8_dotf.h:172
uint8_t region_id
0..k_ra8_dotf_max_regions-1 staging slot.
Definition ra8_dotf.h:176