31#ifdef RA8_ENABLE_ROOT_OF_TRUST
45static const char*
s_tag =
"TZBOOT";
77typedef enum : uintptr_t {
98typedef enum : uint32_t {
115typedef enum : uint16_t {
133typedef enum : uint32_t {
183 uint16_t prcr_s_last;
184 uint8_t prcr_unlock_count;
185 uint8_t prcr_relock_count;
186 uint32_t ipcsar_value;
187 uint32_t ipcpar_value;
188 uint32_t blxns_target;
189 uint32_t blxns_msp_ns;
191} ra8_tz_secure_boot_host_state_t;
202static ra8_tz_secure_boot_host_state_t s_host = {};
211 s_host = (ra8_tz_secure_boot_host_state_t){};
220 return s_host.blxns_target;
267 s_host.ipcsar_value = value;
269 s_host.ipcpar_value = value;
271 s_host.vtor_ns = value;
273 s_host.sau_ctrl = value;
280 *(
volatile uint32_t*)addr = value;
312 return s_host.ipcsar_value;
318 return *(
volatile uint32_t*)addr;
343 s_host.prcr_s_last = value;
345 s_host.prcr_unlock_count = (uint8_t)(s_host.prcr_unlock_count + 1U);
347 s_host.prcr_relock_count = (uint8_t)(s_host.prcr_relock_count + 1U);
352 *(
volatile uint16_t*)addr = value;
371#ifndef RA8_OFF_TARGET
372 __asm__
volatile(
"dsb 0xF" :::
"memory");
391#ifndef RA8_OFF_TARGET
392 __asm__
volatile(
"isb 0xF" :::
"memory");
434 s_host.sau_region_base[region] = base;
435 s_host.sau_region_limit[region] = limit;
436 s_host.sau_region_nsc[region] = (uint8_t)(is_nsc ? 1U : 0U);
513 if (ns_vector_table ==
nullptr) {
525 const void*
const ns_image = ns_vector_table;
526 const uint8_t* base = (
const uint8_t*)ns_image;
592#if !defined(RA8_OFF_TARGET) && defined(RA8_ENABLE_ROOT_OF_TRUST)
594 if (ns_body_len == 0U) {
599 if (ns_trailer ==
nullptr) {
607 (void)ns_vector_table;
616 if (((uintptr_t)ns_vector_table & 0x3U) != 0U) {
621 const uint32_t initial_sp = ns_vector_table[0];
622 const uint32_t reset_entry = ns_vector_table[1];
626 if (reset_entry == 0U || reset_entry == UINT32_MAX) {
645 s_host.blxns_target = reset_entry;
646 s_host.blxns_msp_ns = initial_sp;
660 const uint32_t ns_entry = reset_entry & ~(uint32_t)1U;
661 __asm__
volatile(
"msr msp_ns, %0\n"
664 :
"r"(initial_sp),
"r"(ns_entry)
672 uint32_t ipcpar_value,
673 const uint32_t* ns_vector_table)
static const char * s_tag
Logging / check tag.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_validation_failed
Validation rule failed (caller-supplied invariant not satisfied).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Lightweight Logging Interface for ra8-firmware.
#define ra8_log_error_val(tag, message, value)
RA8 log error val.
#define ra8_log_error(tag, message)
RA8 log error.
Root-of-trust signed-image verifier (SHA-256 + ECDSA-P256, default-deny).
ra8_err_t ra8_rot_verify_image(const uint8_t *body, uint32_t body_len, const ra8_rot_trailer_t *trailer)
Authenticate a signed image: SHA-256 + ECDSA-P256, default-deny.
const ra8_rot_trailer_t * ra8_rot_trailer_after(const void *image_base, uint32_t body_len)
Locate the trailer that immediately follows a signed image body.
ra8_tz_secure_boot_addr_t
Memory-mapped register addresses used by the secure-boot.
@ k_ra8_tz_sau_type_addr
SAU Type.
@ k_ra8_tz_prcr_s_addr
SYSC PRCR_S (16-bit).
@ k_ra8_tz_sau_rbar_addr
Region Base.
@ k_ra8_tz_scb_vtor_ns_addr
VTOR Non-Secure alias.
@ k_ra8_tz_sau_ctrl_addr
SAU Control.
@ k_ra8_tz_sau_rnr_addr
Region Num.
@ k_ra8_tz_sau_rlar_addr
Region Lim.
@ k_ra8_tz_ipcsar_addr
CPSCU IPCSAR.
@ k_ra8_tz_ipcpar_addr
CPSCU IPCPAR.
static void internal_dsb(void)
Emit a Data Synchronisation Barrier (no-op on host).
ra8_tz_secure_boot_step_t ra8_tz_secure_boot_get_step(void)
Read the boot progress counter (debug / test).
ra8_err_t ra8_tz_secure_boot_jump_ns(const uint32_t *ns_vector_table)
Switch to NS state and jump to the NS image's reset vector.
ra8_err_t ra8_tz_secure_boot_sau_init(void)
Programme the SAU regions documented in ra8_tz_sau_region_t.
uint32_t ra8_tz_secure_boot_host_blxns_target(void)
Read the captured BLXNS target (host / test).
void ra8_tz_secure_boot_host_reset(void)
Reset the host-side state for unit-test fixtures.
static void internal_write32(uintptr_t addr, uint32_t value)
Write a 32-bit MMIO register (or capture on host).
ra8_tz_secure_boot_prcr_t
PRCR_S unlock key + per-group enable bits (HUM Ch 13.2.1).
@ k_ra8_tz_prcr_s_prc4_open
PRC4 gate open (bit 4).
@ k_ra8_tz_prcr_s_open
Key | PRC4 (unlock value).
@ k_ra8_tz_prcr_s_close
Key with PRC4 = 0 (lock).
@ k_ra8_tz_prcr_s_key
Unlock key (top byte).
ra8_tz_secure_boot_partition_t
Canonical SAU region base / limit addresses (HUM Ch 4).
@ k_ra8_tz_part_ns_sram_limit
RA8 TrustZone part ns SRAM limit.
@ k_ra8_tz_part_ns_mram_base
RA8 TrustZone part ns MRAM base.
@ k_ra8_tz_part_code_nsc_base
RA8 TrustZone part code NSC base.
@ k_ra8_tz_part_sram_nsc_limit
RA8 TrustZone part SRAM NSC limit.
@ k_ra8_tz_part_ns_per_limit
RA8 TrustZone part ns per limit.
@ k_ra8_tz_part_ns_sram_base
RA8 TrustZone part ns SRAM base.
@ k_ra8_tz_part_sram_nsc_base
RA8 TrustZone part SRAM NSC base.
@ k_ra8_tz_part_ns_per_base
RA8 TrustZone part ns per base.
@ k_ra8_tz_part_ns_mram_limit
RA8 TrustZone part ns MRAM limit.
@ k_ra8_tz_part_code_nsc_limit
RA8 TrustZone part code NSC limit.
static uint32_t internal_read32(uintptr_t addr)
Read a 32-bit MMIO register (or canned host value).
uint32_t ra8_tz_ns_signed_body_len(const uint32_t *ns_vector_table)
Read the NS image's self-describing signed-body length.
static void internal_sau_set_region(uint8_t region, uint32_t base, uint32_t limit, bool is_nsc)
Programme one SAU region via RNR/RBAR/RLAR.
ra8_err_t ra8_tz_secure_boot_security_init(uint32_t ipcsar_value, uint32_t ipcpar_value)
Unlock PRCR_S.PRC4 and write IPCSAR + IPCPAR.
static ra8_err_t internal_ns_verify_or_deny(const uint32_t *ns_vector_table)
Authenticate the Non-Secure image before BLXNS (default-deny gate).
ra8_tz_secure_boot_sau_bit_t
Bit positions used to enable / configure each SAU region.
@ k_ra8_tz_sau_ctrl_allns
CTRL.ALLNS (kept 0).
@ k_ra8_tz_sau_ctrl_enable
CTRL.ENABLE.
@ k_ra8_tz_sau_rlar_enable
RLAR.ENABLE.
@ k_ra8_tz_sau_rlar_nsc
RLAR.NSC.
@ k_ra8_tz_sau_type_mask
TYPE.SREGION lower 8b.
static void internal_isb(void)
Emit an Instruction Synchronisation Barrier (no-op on host).
ra8_err_t ra8_tz_secure_boot_run(uint32_t ipcsar_value, uint32_t ipcpar_value, const uint32_t *ns_vector_table)
Run the full secure-boot sequence and (on target) BLXNS.
static void internal_write16(uintptr_t addr, uint16_t value)
Write a 16-bit MMIO register (or capture on host).
static volatile ra8_tz_secure_boot_step_t s_step
Progress counter exposed via ra8_tz_secure_boot_get_step.
FSP-style TrustZone secure-boot for the Cortex-M85 (CPU0).
@ k_ra8_tz_ns_rot_header_offset
Offset after the 16-slot NS vectors.
@ k_ra8_tz_ns_rot_header_magic
ASCII "NSR1" (little-endian).
@ k_ra8_tz_sau_region_ns_periph
Non-Secure peripheral window.
@ k_ra8_tz_sau_region_code_nsc
NSC alias for code-flash veneers.
@ k_ra8_tz_sau_region_sram_nsc
NSC alias for SRAM veneers.
@ k_ra8_tz_sau_region_count
Number of programmed regions.
@ k_ra8_tz_sau_region_ns_mram
Non-Secure upper MRAM (NS image).
@ k_ra8_tz_sau_region_ns_sram
Non-Secure upper SRAM (NS data).
ra8_tz_secure_boot_step_t
Progress markers stamped into g_ra8_tz_secure_boot_step.
@ k_ra8_tz_secure_boot_step_sau_done
SAU regions programmed.
@ k_ra8_tz_secure_boot_step_ipcsar_written
IPCSAR write landed.
@ k_ra8_tz_secure_boot_step_prcr_unlocked
PRCR_S.PRC4 set.
@ k_ra8_tz_secure_boot_step_blxns_armed
MSP_NS / VTOR set up.
@ k_ra8_tz_secure_boot_step_branched
BLXNS executed (host).
@ k_ra8_tz_secure_boot_step_prcr_relocked
PRCR_S.PRC4 cleared.
@ k_ra8_tz_secure_boot_step_idle
Pre-run sentinel.
Authenticity trailer appended after a signed image body.