ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
38
39#include <stdint.h>
40#include <string.h>
41
42#include "ra8_attributes.h"
43#include "ra8_board_ek_ra8d2.h"
44#include "ra8_boot_entry.h"
45#include "ra8_cgc.h"
46#include "ra8_err.h"
47#include "ra8_isr.h"
48#include "ra8_psa_crypto.h"
49#include "ra8_time.h"
50
52typedef enum : uint32_t {
53 k_aes_demo_baud = 115200U,
56
63
72typedef enum : uint32_t {
74 (uint32_t)k_ra8_psa_usage_decrypt,
76
78static const uint8_t s_aes_demo_key[k_aes_demo_key_bytes] = {
79 0x00U,
80 0x11U,
81 0x22U,
82 0x33U,
83 0x44U,
84 0x55U,
85 0x66U,
86 0x77U,
87 0x88U,
88 0x99U,
89 0xAAU,
90 0xBBU,
91 0xCCU,
92 0xDDU,
93 0xEEU,
94 0xFFU,
95};
96
99 0xA0U,
100 0xA1U,
101 0xA2U,
102 0xA3U,
103 0xA4U,
104 0xA5U,
105 0xA6U,
106 0xA7U,
107 0xA8U,
108 0xA9U,
109 0xAAU,
110 0xABU,
111};
112
115 'R',
116 'A',
117 '8',
118 'D',
119 '2',
120 '_',
121 'O',
122 'K',
123};
124
126static const uint8_t s_aes_demo_aad[k_aes_demo_aad_bytes] = {'A', 'E', 'A', 'D'};
127
128static const uint8_t s_aes_demo_msg_ok[] = "aes: round-trip OK\r\n";
129static const uint8_t s_aes_demo_msg_fail[] = "aes: round-trip FAIL\r\n";
130
142{
143 while (1) {
144 __asm__ volatile("wfi");
145 }
146}
147
160{
161 uint32_t cpuclk0_hz = 0U;
162 if (ra8_cgc_init() != k_ra8_ok) {
164 }
167 }
168 if (ra8_time_init(cpuclk0_hz) != k_ra8_ok) {
170 }
173 }
176 }
179 }
180 if (ra8_psa_crypto_init() != k_ra8_ok) {
182 }
183}
184
211{
212 /* The PSA usage enum is intentionally a bitfield -- combining
213 * encrypt + decrypt yields 0x0C, which is a valid policy mask but
214 * not a declared enumerator. */
215 const ra8_psa_key_attr_t attr = {
219 };
220 ra8_psa_key_t key = nullptr;
222 if (err != k_ra8_ok) {
223 return err;
224 }
225
227 size_t ct_len = 0U;
228 err = ra8_psa_aead_encrypt(key,
233 (size_t)k_aes_demo_aad_bytes,
236 ct,
237 sizeof(ct),
238 &ct_len);
239 if (err != k_ra8_ok) {
240 (void)ra8_psa_key_destroy(key);
241 return err;
242 }
243
244 uint8_t recovered[k_aes_demo_plain_bytes] = {};
245 size_t rec_len = 0U;
246 err = ra8_psa_aead_decrypt(key,
251 (size_t)k_aes_demo_aad_bytes,
252 ct,
253 ct_len,
254 recovered,
255 sizeof(recovered),
256 &rec_len);
257 (void)ra8_psa_key_destroy(key);
258 if (err != k_ra8_ok) {
259 return err;
260 }
261 if (rec_len != (size_t)k_aes_demo_plain_bytes) {
263 }
264 if (memcmp(recovered, s_aes_demo_plain, (size_t)k_aes_demo_plain_bytes) != 0) {
266 }
267 return k_ra8_ok;
268}
269
270void main(void)
271{
274
275 while (1) {
278 (size_t)(sizeof(s_aes_demo_msg_ok) - 1U));
280 } else {
282 (size_t)(sizeof(s_aes_demo_msg_fail) - 1U));
284 }
286 }
288}
void main(void)
Secure fallback main entry point.
Definition main.c:37
static void internal_setup_or_halt(void)
Bring up clocks, MSTP, delay timing, and the board console.
Definition main.c:211
static void internal_panic_halt(void)
Park the core after an unrecoverable ADC demo failure.
Definition main.c:123
static const uint8_t s_aes_demo_aad[k_aes_demo_aad_bytes]
AAD (additional authenticated data).
Definition main.c:126
static const uint8_t s_aes_demo_nonce[k_ra8_psa_gcm_nonce_len]
Fixed 12-byte nonce (deterministic for the demo).
Definition main.c:98
aes_demo_usage_t
Combined AEAD usage flag (encrypt + decrypt).
Definition main.c:72
@ k_aes_demo_usage_aead
AES demo usage aead.
Definition main.c:73
aes_demo_const_t
Demo tunables.
Definition main.c:52
@ k_aes_demo_baud
AES demo baud.
Definition main.c:53
@ k_aes_demo_period_ms
AES demo period ms.
Definition main.c:54
aes_demo_layout_t
AES-128 key + plaintext sizing.
Definition main.c:58
@ k_aes_demo_key_bytes
AES demo key bytes.
Definition main.c:59
@ k_aes_demo_aad_bytes
AES demo aad bytes.
Definition main.c:61
@ k_aes_demo_plain_bytes
AES demo plain bytes.
Definition main.c:60
static const uint8_t s_aes_demo_key[k_aes_demo_key_bytes]
Fixed 128-bit AES key.
Definition main.c:78
static const uint8_t s_aes_demo_plain[k_aes_demo_plain_bytes]
Plaintext "RA8D2_OK" – 8 ASCII bytes.
Definition main.c:114
static ra8_err_t internal_one_round_trip(void)
Single AES-128-GCM encrypt -> decrypt -> compare round-trip.
Definition main.c:210
static const uint8_t s_aes_demo_msg_ok[]
Definition main.c:128
static const uint8_t s_aes_demo_msg_fail[]
Definition main.c:129
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
ra8_err_t ra8_board_led_toggle(ra8_board_led_id_t led)
Toggle led's output state.
ra8_err_t ra8_board_led_init(ra8_board_led_id_t led)
Configure led as a digital output, initial level low (off).
@ k_ra8_board_led2
LED2, GREEN, P303 (jumper E26).
@ k_ra8_board_led1
LED1, BLUE, P600 (jumper E27).
ra8_err_t ra8_board_uart_console_write(const uint8_t *data, size_t len)
Polled blocking write to the J-Link OB VCOM console.
ra8_err_t ra8_board_uart_console_init(uint32_t baud)
Configure SCI8 + PD02/PD03 as the debug-console UART.
Boot entry points shared between a vector table and its startup code.
High-level Clock Generation Circuit driver.
ra8_err_t ra8_cgc_get_clock_hz(ra8_clock_id_t id, uint32_t *out_hz)
Query the current frequency of a clock-tree domain.
Definition ra8_cgc.c:132
@ k_ra8_clock_id_cpuclk0
Cortex-M85 CPUCLK0.
Definition ra8_cgc.h:70
ra8_err_t ra8_cgc_init(void)
Configure the clock tree to a safe default.
Definition ra8_cgc.c:727
Error Code Definitions for ra8-firmware.
@ k_ra8_err_crc_mismatch
CRC mismatch detected on received data.
Definition ra8_err.h:423
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
Definition ra8_err.h:167
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
Definition ra8_isr.c:439
Application-level PSA Crypto facade over tf-psa-crypto.
ra8_psa_key_usage_t
Bitmask of allowed operations on an imported key.
@ k_ra8_psa_usage_encrypt
Allow ra8_psa_aead_encrypt.
@ k_ra8_psa_usage_decrypt
Allow ra8_psa_aead_decrypt.
ra8_err_t ra8_psa_key_destroy(ra8_psa_key_t handle)
Destroy a previously-imported key.
ra8_err_t ra8_psa_aead_decrypt(ra8_psa_key_t handle, ra8_psa_alg_t alg, const uint8_t *nonce, size_t nonce_len, const uint8_t *aad, size_t aad_len, const uint8_t *cipher, size_t cipher_len, uint8_t *out, size_t out_cap, size_t *out_len)
Decrypt + verify-tag an AES-GCM buffer.
ra8_err_t ra8_psa_crypto_init(void)
One-shot facade initialisation.
ra8_err_t ra8_psa_key_import(ra8_psa_key_t *out_handle, const ra8_psa_key_attr_t *attr, const uint8_t *data, size_t data_len)
Import a raw-byte key into the static pool.
struct ra8_psa_key_handle * ra8_psa_key_t
Opaque PSA key handle (typed pointer into the static pool).
@ k_ra8_psa_key_type_aes
Symmetric AES key.
@ k_ra8_psa_alg_aes_gcm
AES-GCM AEAD (NIST SP 800-38D).
@ k_ra8_psa_gcm_tag_len
AES-GCM authentication tag length (16 octets).
@ k_ra8_psa_gcm_nonce_len
AES-GCM nonce length used by ra8_psa_aead_* (NIST SP 800-38D).
ra8_err_t ra8_psa_aead_encrypt(ra8_psa_key_t handle, ra8_psa_alg_t alg, const uint8_t *nonce, size_t nonce_len, const uint8_t *aad, size_t aad_len, const uint8_t *plain, size_t plain_len, uint8_t *out, size_t out_cap, size_t *out_len)
Encrypt + authenticate a buffer with AES-GCM.
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
Definition ra8_time.c:59
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
Definition ra8_time.c:129
Attributes describing a key being imported.