ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_dfu_launch.c
Go to the documentation of this file.
1
38
39#include "ra8_attributes.h"
40#include "ra8_dfu.h"
41#include "ra8_scb.h"
42#ifdef RA8_ENABLE_ROOT_OF_TRUST
44#include "ra8_rot.h"
45#endif
46
47#ifdef RA8_ENABLE_ROOT_OF_TRUST
83RA8_INTERNAL static bool internal_launch_authorized(uintptr_t src, uint32_t img_len)
84{
85 const ra8_rot_trailer_t* trailer = ra8_rot_trailer_after((const void*)src, img_len);
86 if (ra8_rot_verify_image((const uint8_t*)src, img_len, trailer) != k_ra8_ok) {
87 return false; /* DEFAULT-DENY: unauthenticated image */
88 }
90 k_ra8_ok) {
91 return false; /* DEFAULT-DENY: downgrade, or an unreadable counter */
92 }
93 return true;
94}
95#endif /* RA8_ENABLE_ROOT_OF_TRUST */
96
97void ra8_dfu_launch(uintptr_t src, uint32_t img_len, uint32_t entry)
98{
99 if (src == 0U) {
100 return; /* nothing to copy */
101 }
102 if (!ra8_dfu_run_target_valid(entry, img_len)) {
103 return; /* entry not the run base, or bad length -> caller drops to fallback */
104 }
105
106#ifdef RA8_ENABLE_ROOT_OF_TRUST
107 /* Opt-in (see ra8_rot.h). With the flag OFF both gates are absent and the
108 * launch proceeds on the CRC32 integrity check alone. */
109 if (!internal_launch_authorized(src, img_len)) {
110 return; /* DEFAULT-DENY -> caller's fallback path, nothing copied */
111 }
112#endif /* RA8_ENABLE_ROOT_OF_TRUST */
113
114#ifndef RA8_OFF_TARGET
115 const volatile uint32_t* s = (const volatile uint32_t*)src;
116 volatile uint32_t* d = (volatile uint32_t*)(uintptr_t)k_ra8_dfu_run_base;
117 const uint32_t words = img_len / (uint32_t)sizeof(uint32_t);
118
119 __asm__ volatile("cpsid i" ::: "memory");
120 /* Bounded by img_len (<= k_ra8_dfu_img_max via ra8_dfu_run_target_valid): a
121 * statically bounded copy -- NASA Rule 2 compliant. */
122 for (uint32_t i = 0U; i < words; ++i) {
123 d[i] = s[i];
124 }
125 __asm__ volatile("dsb 0xF" ::: "memory"); /* image stores reach SRAM before fetch */
126
127 const uint32_t initial_sp = d[0];
128 const uint32_t reset_entry = d[1];
129
130 /* Point the Secure VTOR at the run base via the shared ra8_scb primitive,
131 * then fence: the vector fetch on the coming branch must see the new base. */
133 __asm__ volatile("dsb 0xF\n isb 0xF\n" ::: "memory");
134 __asm__ volatile("msr msp, %0\n"
135 "bx %1\n"
136 :
137 : "r"(initial_sp), "r"(reset_entry)
138 : "memory");
139 __builtin_unreachable();
140#endif /* !RA8_OFF_TARGET */
141}
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Controller-agnostic USB-DFU MRAM bootloader core for the RA8D2.
bool ra8_dfu_run_target_valid(uint32_t entry, uint32_t img_len)
Decide whether a validated slot's image may be copied-to-run.
@ k_ra8_dfu_run_base
SRAM copy-to-run / payload link base.
Definition ra8_dfu.h:126
DFU anti-rollback (downgrade protection) policy + storage seam.
const ra8_rot_antirollback_store_t * ra8_rot_antirollback_default_store(void)
Return the non-faking default store (reports "not provisioned").
ra8_err_t ra8_rot_antirollback_verify(const ra8_rot_antirollback_store_t *store, uint32_t image_version)
Read the stored minimum, apply the policy, and commit on accept.
void ra8_dfu_launch(uintptr_t src, uint32_t img_len, uint32_t entry)
Copy an image to the SRAM run base and branch to it (copy-to-run).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
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.
Cortex-M85 System Control Block: VTOR relocation + fault-status decode.
void ra8_scb_set_vtor(uintptr_t base)
Relocate the vector table by writing SCB->VTOR.
Definition ra8_scb.c:111
Authenticity trailer appended after a signed image body.
Definition ra8_rot.h:150
uint32_t img_version
Monotonic anti-rollback image ver.
Definition ra8_rot.h:153