34typedef enum : uint16_t {
46typedef enum : uint8_t {
55 .ecc_encoder_enable =
true,
56 .ecc_decoder_enable =
true,
63 if ((src ==
nullptr) || (len == 0U)) {
75 uint32_t chunk = len - off;
124 if (out_hdr ==
nullptr) {
169 if (out_seq ==
nullptr) {
208 if (data ==
nullptr) {
222 const uintptr_t dst = base + (uintptr_t)img_offset;
236 const uint32_t body_crc =
ra8_dfu_crc32((
const uint8_t*)base, img_len);
248 (
const uint8_t*)&hdr,
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
Controller-agnostic USB-DFU MRAM bootloader core for the RA8D2.
ra8_dfu_slot_t
Application-slot identifier.
@ k_ra8_dfu_slot_b
Slot B (0x02090000).
@ k_ra8_dfu_slot_a
Slot A (0x02020000).
@ k_ra8_dfu_slot_none
No valid slot present.
uint32_t ra8_dfu_crc32(const uint8_t *data, uint32_t len)
Compute the IEEE-802.3 CRC32 of a byte range (software).
bool ra8_dfu_hdr_valid(const ra8_dfu_img_hdr_t *hdr, uint32_t computed_crc)
Decide whether a slot header describes a valid bootable image.
@ k_ra8_dfu_page_size
MRAM program page (32 bytes).
@ k_ra8_dfu_hdr_offset
Header offset (slot's last page).
@ k_ra8_dfu_slot_a_base
Slot A base (app vectors here).
@ k_ra8_dfu_hdr_magic
Valid-image header magic ("RA8D").
@ k_ra8_dfu_slot_size
Per-slot size (448 KiB).
@ k_ra8_dfu_slot_b_base
Slot B base (app vectors here).
@ k_ra8_dfu_hdr_size
Image header size (32 bytes).
@ k_ra8_dfu_img_max
Max image bytes (slot - header).
@ k_ra8_dfu_run_base
SRAM copy-to-run / payload link base.
TU-shared surface for the DFU MRAM program/verify implementation.
ra8_err_t ra8_dfu_program_commit(ra8_dfu_slot_t inactive, uint32_t img_len, uint32_t seq)
Finalize a slot: CRC the programmed body, then program the header.
ra8_err_t ra8_dfu_slot_seq(ra8_dfu_slot_t slot, uint32_t *out_seq)
Read a slot header's sequence number (0 if the magic is wrong).
ra8_err_t priv_dfu_write_secure(uintptr_t addr, const uint8_t *src, uint32_t len)
Implementation of priv_dfu_write_secure() – IRQ-masked, page-at-a-time erase-then-program through the...
ra8_err_t ra8_dfu_program_image(ra8_dfu_slot_t inactive, uint32_t img_offset, const uint8_t *data, uint32_t len)
Program one image chunk into the inactive slot's body.
ra8_err_t ra8_dfu_read_header(ra8_dfu_slot_t slot, ra8_dfu_img_hdr_t *out_hdr)
Copy a slot's 32-byte header out of MRAM.
ra8_dfu_prog_fill_t
MRAM erased-state fill byte.
@ k_ra8_dfu_prog_erased_byte
Erased-state byte for an MRAM page.
uintptr_t ra8_dfu_slot_base(ra8_dfu_slot_t slot)
Return the MRAM base address of a slot.
static const ra8_flash_cfg_t s_ra8_dfu_flash_cfg
Default controller bring-up descriptor for ra8_dfu_program_prepare.
ra8_err_t ra8_dfu_program_prepare(ra8_dfu_slot_t inactive)
Open ra8_flash and fence all writes to one slot's window.
ra8_dfu_slot_t ra8_dfu_other_slot(ra8_dfu_slot_t slot)
Return the opposite slot (A<->B).
ra8_err_t ra8_dfu_program_verify(ra8_dfu_slot_t slot)
Read-back verify: re-CRC a slot's body against its stored header.
ra8_dfu_prog_cfg_t
MRAM clock notifications used to (re)open the controller.
@ k_ra8_dfu_prog_mrefreq_mhz
Extra-MRAM clock notification (MHz).
@ k_ra8_dfu_prog_mrcfreq_mhz
Code-MRAM clock notification (MHz).
bool ra8_dfu_slot_valid(ra8_dfu_slot_t slot)
Implementation of ra8_dfu_slot_valid() – guards the CRC read so a bogus img_len cannot drive an out-o...
@ k_ra8_err_crc_mismatch
CRC mismatch detected on received data.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Code MRAM + Extra MRAM + Option-Setting driver – DANGEROUS, brick-capable.
ra8_err_t ra8_flash_write_block(uint32_t mram_addr, const uint8_t *src, uint32_t len, ra8_flash_world_t world)
Program 1..32 contiguous bytes into one MRAM page.
ra8_err_t ra8_flash_set_window(uintptr_t low, uintptr_t high)
Configure the soft access window enforced by write/erase.
ra8_err_t ra8_flash_open(const ra8_flash_cfg_t *cfg)
FSP-parity bring-up: equivalent to ra8_flash_init.
@ k_ra8_flash_world_s
Open MRCPC1 (secure half).
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
IRQ-masked read-modify-write helper for shared registers.
static void ra8_register_guard_exit(const ra8_register_guard_t *guard)
Exit a critical section: restore PRIMASK.
static void ra8_register_guard_enter(ra8_register_guard_t *guard)
Enter a critical section: save PRIMASK, mask interrupts.
32-byte application-image header at the base of each slot.
uint32_t img_crc32
CRC32 (IEEE) over the image body.
uint32_t magic
Must equal k_ra8_dfu_hdr_magic.
uint32_t seq
Monotonic sequence; higher valid slot wins.
uint32_t entry
SRAM run base (== k_ra8_dfu_run_base).
uint32_t img_len
Image body length in bytes (32-byte multiple).
Initialisation descriptor for ra8_flash_init.
Opaque save-restore handle for IRQ masking.