ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_dfu.h
Go to the documentation of this file.
1
68
69#pragma once
70
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75#include <stdint.h>
76
77#include "ra8_err.h"
78
94typedef enum : uint32_t {
95 k_ra8_dfu_mram_base = 0x02000000U,
96 k_ra8_dfu_mram_size = 0x00100000U,
97 k_ra8_dfu_bl_size = 0x00020000U,
98 k_ra8_dfu_slot_a_base = 0x02020000U,
99 k_ra8_dfu_slot_b_base = 0x02090000U,
100 k_ra8_dfu_slot_size = 0x00070000U,
101 k_ra8_dfu_page_size = 0x00000020U,
102 k_ra8_dfu_hdr_size = 0x00000020U,
103 k_ra8_dfu_img_max = 0x0006FFE0U,
104 k_ra8_dfu_hdr_offset = 0x0006FFE0U,
105 k_ra8_dfu_hdr_magic = 0x52413844U,
108
125typedef enum : uint32_t {
126 k_ra8_dfu_run_base = 0x22020000U,
128
138
148
174typedef struct {
175 uint32_t magic;
176 uint32_t seq;
177 uint32_t img_len;
178 uint32_t img_crc32;
179 uint32_t entry;
180 uint32_t rsv0;
181 uint32_t rsv1;
182 uint32_t rsv2;
184
185static_assert(sizeof(ra8_dfu_img_hdr_t) == (uint32_t)k_ra8_dfu_hdr_size,
186 "image header must be exactly one 32-byte MRAM page");
187
213uint32_t ra8_dfu_crc32(const uint8_t* data, uint32_t len);
214
244bool ra8_dfu_hdr_valid(const ra8_dfu_img_hdr_t* hdr, uint32_t computed_crc);
245
278bool ra8_dfu_run_target_valid(uint32_t entry, uint32_t img_len);
279
315void ra8_dfu_launch(uintptr_t src, uint32_t img_len, uint32_t entry);
316
344ra8_dfu_slot_t ra8_dfu_select_slot(bool a_valid, uint32_t a_seq, bool b_valid, uint32_t b_seq);
345
376ra8_dfu_boot_decide(bool dfu_trigger, bool a_valid, uint32_t a_seq, bool b_valid, uint32_t b_seq);
377
378/* =============================================================================
379 * MRAM slot access + program / verify (ra8_dfu_program.c)
380 *
381 * These touch the code-MRAM window. On the firmware target the program path
382 * must execute from SRAM (the code-MRAM program loop must not run from MRAM --
383 * see ra8_flash.h); each consumer's linker script places this TU + ra8_flash in
384 * SRAM. The host test backs the MRAM window with fake memory, so the
385 * full program -> read-back -> verify round-trip is unit-testable.
386 * =============================================================================
387 */
388
416uintptr_t ra8_dfu_slot_base(ra8_dfu_slot_t slot);
417
445
462
485
500[[nodiscard]] ra8_err_t ra8_dfu_slot_seq(ra8_dfu_slot_t slot, uint32_t* out_seq);
501
528[[nodiscard]] ra8_err_t ra8_dfu_program_prepare(ra8_dfu_slot_t inactive);
529
558[[nodiscard]] ra8_err_t ra8_dfu_program_image(ra8_dfu_slot_t inactive,
559 uint32_t img_offset,
560 const uint8_t* data,
561 uint32_t len);
562
585[[nodiscard]] ra8_err_t
586ra8_dfu_program_commit(ra8_dfu_slot_t inactive, uint32_t img_len, uint32_t seq);
587
602
603#ifdef __cplusplus
604}
605#endif
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_dfu_slot_t
Application-slot identifier.
Definition ra8_dfu.h:133
@ k_ra8_dfu_slot_b
Slot B (0x02090000).
Definition ra8_dfu.h:135
@ k_ra8_dfu_slot_a
Slot A (0x02020000).
Definition ra8_dfu.h:134
@ k_ra8_dfu_slot_none
No valid slot present.
Definition ra8_dfu.h:136
ra8_dfu_slot_t ra8_dfu_select_slot(bool a_valid, uint32_t a_seq, bool b_valid, uint32_t b_seq)
Pick the active slot from the two slots' validity + sequence.
ra8_dfu_action_t
Outcome of the reset-time boot decision.
Definition ra8_dfu.h:143
@ k_ra8_dfu_action_jump_b
Jump to the Slot B application.
Definition ra8_dfu.h:146
@ k_ra8_dfu_action_dfu
Enter the DFU device; do not jump.
Definition ra8_dfu.h:144
@ k_ra8_dfu_action_jump_a
Jump to the Slot A application.
Definition ra8_dfu.h:145
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.
ra8_dfu_layout_t
Fixed MRAM bank-layout addresses and image-header constants.
Definition ra8_dfu.h:94
@ k_ra8_dfu_page_size
MRAM program page (32 bytes).
Definition ra8_dfu.h:101
@ k_ra8_dfu_trigger_magic
No-init SRAM DFU-request magic.
Definition ra8_dfu.h:106
@ k_ra8_dfu_hdr_offset
Header offset (slot's last page).
Definition ra8_dfu.h:104
@ k_ra8_dfu_slot_a_base
Slot A base (app vectors here).
Definition ra8_dfu.h:98
@ k_ra8_dfu_hdr_magic
Valid-image header magic ("RA8D").
Definition ra8_dfu.h:105
@ k_ra8_dfu_slot_size
Per-slot size (448 KiB).
Definition ra8_dfu.h:100
@ k_ra8_dfu_bl_size
Immutable bootloader size (128K).
Definition ra8_dfu.h:97
@ k_ra8_dfu_mram_size
Code-MRAM window size (1 MiB).
Definition ra8_dfu.h:96
@ k_ra8_dfu_slot_b_base
Slot B base (app vectors here).
Definition ra8_dfu.h:99
@ k_ra8_dfu_mram_base
Code-MRAM window base.
Definition ra8_dfu.h:95
@ k_ra8_dfu_hdr_size
Image header size (32 bytes).
Definition ra8_dfu.h:102
@ k_ra8_dfu_img_max
Max image bytes (slot - header).
Definition ra8_dfu.h:103
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.
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.
uintptr_t ra8_dfu_slot_base(ra8_dfu_slot_t slot)
Return the MRAM base address of a slot.
ra8_dfu_action_t ra8_dfu_boot_decide(bool dfu_trigger, bool a_valid, uint32_t a_seq, bool b_valid, uint32_t b_seq)
Reset-time boot decision: jump to a slot, or enter DFU.
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_run_t
Fixed SRAM copy-to-run execution base.
Definition ra8_dfu.h:125
@ k_ra8_dfu_run_base
SRAM copy-to-run / payload link base.
Definition ra8_dfu.h:126
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).
bool ra8_dfu_slot_valid(ra8_dfu_slot_t slot)
Validate a slot live: header magic/length/CRC over its real image.
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
32-byte application-image header at the base of each slot.
Definition ra8_dfu.h:174
uint32_t img_crc32
CRC32 (IEEE) over the image body.
Definition ra8_dfu.h:178
uint32_t rsv0
Reserved; programmed 0.
Definition ra8_dfu.h:180
uint32_t rsv2
Reserved; programmed 0.
Definition ra8_dfu.h:182
uint32_t magic
Must equal k_ra8_dfu_hdr_magic.
Definition ra8_dfu.h:175
uint32_t rsv1
Reserved; programmed 0.
Definition ra8_dfu.h:181
uint32_t seq
Monotonic sequence; higher valid slot wins.
Definition ra8_dfu.h:176
uint32_t entry
SRAM run base (== k_ra8_dfu_run_base).
Definition ra8_dfu.h:179
uint32_t img_len
Image body length in bytes (32-byte multiple).
Definition ra8_dfu.h:177