78typedef enum : uint32_t {
100typedef enum : uintptr_t {
110typedef enum : uint8_t {
119typedef enum : uint8_t {
132typedef enum : uint16_t {
145typedef enum : uint8_t {
160typedef enum : uint8_t {
167static const char*
const s_tag =
"ota_ab";
228 if (text[n] ==
'\0') {
250 if (text ==
nullptr) {
283 *out_content_len = src->
len;
310 const uint32_t remaining = src->
len - src->
pos;
311 const uint32_t n = (remaining < cap) ? remaining : cap;
513 const uint32_t remaining = len - off;
548 (void)
memcpy(dst, (
const void*)(uintptr_t)addr, (
size_t)len);
699 return committed && rolled_back;
720 (void)
memset(cfg, 0,
sizeof *cfg);
722 "local://demo/manifest",
761 (void)
memset(m, 0,
sizeof *m);
882 .ecc_encoder_enable =
true,
883 .ecc_decoder_enable =
true,
935 bool committed =
false;
936 bool rolled_back =
false;
949 (void)
app_print(
"\r\nra8d2 ota_ab_orchestration (A/B stage/verify/commit/rollback)\r\n");
void main(void)
Secure fallback main entry point.
static ra8_err_t app_read_bootsel(uint8_t *out_bank, bool *out_valid)
Read the persisted boot-select record.
static ra8_rsip_sha256_ctx_t s_sha_ctx
Streaming SHA-256 context backing the OTA crypto interface.
static ra8_err_t app_net_read(void *ctx, uint8_t *dst, uint32_t cap, uint32_t *out_len)
Copy up to cap bytes from the staged image (OTA net.read).
static ra8_err_t app_sha_update(void *ctx, const uint8_t *data, uint32_t len)
Absorb bytes into the SHA-256 (OTA crypto.sha256_update).
static app_outcome_t app_run_attempt(const uint8_t *source, const ra8_ota_manifest_t *m, uint8_t *out_bank)
Drive one full A/B attempt against source and classify it.
app_mram_addr_t
Extra-MRAM option-setting addresses the demo owns (0x02E07600, 12 KiB).
@ k_app_bank_addr
Inactive-bank base (extra-MRAM start).
@ k_app_bootsel_addr
Persistent boot-select record (own block).
static ra8_err_t app_ecdsa_verify(void *ctx, uint32_t pubkey, const uint8_t bound[k_ra8_ota_sha256_bytes], const uint8_t *sig, uint32_t sig_len)
DEMO authenticity check standing in for ECDSA-P256 (OTA crypto.ecdsa_verify).
static uint8_t s_image_bad[k_app_image_bytes]
Corrupted image bytes for the rollback path (one flipped byte).
static ra8_err_t app_flash_readback(void *ctx, uint32_t addr, uint8_t *dst, uint32_t len)
Read the inactive bank back for re-hash (OTA flash.readback).
app_pattern_t
Deterministic demo-image byte-pattern + tag constants.
@ k_app_img_seed_mul
Golden-image pattern multiplier.
@ k_app_sig_tag_base
Demo signature tag base byte.
@ k_app_img_seed_add
Golden-image pattern additive bias.
@ k_app_byte_all_ones
Corrupt-flip mask / erased MRAM byte.
static void app_print(const char *text)
Print a NUL-terminated ASCII string on the board VCOM console.
static ra8_err_t app_stage_images(void)
Fill the golden/corrupt image blobs and precompute the manifest digest.
static ra8_err_t app_flash_erase(void *ctx, uint32_t addr, uint32_t len)
Erase the inactive bank region (OTA flash.erase).
app_size_t
Small byte-width and record-layout constants.
@ k_app_mram_block_bytes
Extra-MRAM erase/program granularity.
@ k_app_rec_off_seq
Boot-select record: seq byte offset.
@ k_app_rec_off_bank
Boot-select record: bank byte offset.
@ k_app_sig_bytes
Demo signature length.
@ k_app_octet_bits
Bits per octet for LE spreads.
@ k_app_rec_off_magic
Boot-select record: magic byte offset.
static void app_make_manifest(ra8_ota_manifest_t *m)
Build the demo manifest describing the good image.
static app_net_source_t s_net_source
The staged image source (rebound per scenario).
app_flash_freq_t
MRAM controller advertised clock rates for ra8_flash_init.
@ k_app_mrefreq_mhz
Extra-MRAM advertised clock (MHz).
@ k_app_mrcfreq_mhz
Code-MRAM advertised clock (MHz).
static void app_print_banner(bool staged, bool committed, bool rolled_back)
Print the one-line A/B verdict banner over the console.
static ra8_err_t app_sha_init(void *ctx)
Begin a streaming SHA-256 (OTA crypto.sha256_init).
static ra8_err_t app_write_bootsel(uint8_t bank)
Persist the A/B boot-select record for bank.
static ra8_err_t app_flash_set_startup(void *ctx, uint8_t which_bank, bool persistent)
Latch the inactive bank as the next boot bank (OTA flash.set_startup).
app_bank_t
A/B slot identifiers persisted in the boot-select record.
@ k_app_bank_b
Slot B (the inactive/update target).
@ k_app_bank_a
Slot A (the initially-active bank).
app_outcome_t
Classified result of one A/B update attempt.
@ k_app_outcome_rolled_back
Verify failed; no swap; active bank kept.
@ k_app_outcome_committed
Verify passed and the bank swap latched.
@ k_app_outcome_indeterminate
Neither terminal shape matched.
static bool app_ab_ok(bool committed, bool rolled_back)
Final demo verdict: both A/B paths behaved as designed.
static uint8_t s_image_good[k_app_image_bytes]
Golden image bytes for the commit path (deterministic pattern).
static ra8_err_t app_sha_final(void *ctx, uint8_t out[k_ra8_ota_sha256_bytes])
Finalise the SHA-256 digest (OTA crypto.sha256_final).
app_const_t
Console, MRAM layout, and demo-image sizing constants.
@ k_app_bootsel_magic
Boot-select record magic ("BOOT A/B").
@ k_app_image_bytes
Demo firmware image size (multiple of 32).
@ k_app_demo_pubkey
Opaque demo public-key handle.
@ k_app_uart_baud
J-Link OB VCOM console baud.
@ k_app_report_delay
Bounded busy-wait between banner prints.
@ k_app_bank_size_bytes
Advertised bank capacity for the OTA cfg.
static app_outcome_t app_ab_classify(ra8_err_t result, ra8_ota_state_t state)
Classify one update attempt from its return code and final state.
static uint32_t s_bootsel_seq
Monotonic sequence number stamped into each boot-select record.
static ra8_err_t app_flash_program(void *ctx, uint32_t addr, const uint8_t *src, uint32_t len)
Program bytes into the inactive bank (OTA flash.program).
static ra8_err_t app_net_close(void *ctx)
Tear down the local stream (OTA net.close); a no-op here.
static uint8_t s_image_good_digest[k_ra8_ota_sha256_bytes]
SHA-256 of s_image_good, published as the manifest digest.
static size_t app_strlen(const char *text)
Bounded length of a NUL-terminated ASCII string.
static ra8_err_t app_net_open(void *ctx, const char *url, uint32_t *out_content_len)
Begin serving the staged image (OTA net.open).
static ra8_err_t app_setup(void)
Bring up CGC + the board VCOM console + the MRAM controller.
static void app_make_cfg(ra8_ota_cfg_t *cfg)
Assemble the OTA config wired to this app's backends.
static const char * s_tag
Logging / check tag.
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
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_init(void)
Configure the clock tree to a safe default.
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_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_hw_error
Generic hardware fault detected (error flag set, fault interrupt).
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_init(const ra8_flash_cfg_t *cfg)
Initialise the MRAM controller for safe read access.
ra8_err_t ra8_flash_extra_mram_erase(uint32_t mram_addr)
Erase one 32-byte block of extra-MRAM via MACI.
ra8_err_t ra8_flash_extra_mram_write(uint32_t mram_addr, const uint8_t *src, uint32_t len)
Program 1..32 contiguous bytes into the general-purpose extra-MRAM window.
@ k_ra8_flash_extra_start
First legal Program target (FSBL setting).
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.
Phase-5 OTA firmware-update orchestration for the RA8D2.
ra8_err_t ra8_ota_commit_and_reboot(void)
Persist the bank swap and reboot.
ra8_err_t ra8_ota_download_to_inactive_bank(const ra8_ota_manifest_t *manifest)
Stream the firmware blob into the inactive MRAM bank.
ra8_ota_state_t
Cooperative state-machine states.
@ k_ra8_ota_state_error
Last operation failed; see last err.
@ k_ra8_ota_state_done
Update applied (reset is imminent).
ra8_err_t ra8_ota_init(const ra8_ota_cfg_t *cfg)
Initialise the OTA module.
ra8_ota_state_t ra8_ota_get_state(void)
Return the current state-machine value.
ra8_err_t ra8_ota_verify_signature(const ra8_ota_manifest_t *manifest)
Verify SHA-256 + ECDSA over the freshly programmed bank.
@ k_ra8_ota_sha256_bytes
SHA-256 digest length.
ra8_err_t ra8_ota_deinit(void)
Tear the OTA module down (mostly for tests / re-init).
Renesas Secure IP (RSIP-E50D) HAL driver – public API.
ra8_err_t ra8_rsip_sha256_final(ra8_rsip_sha256_ctx_t *ctx, uint8_t *digest_out)
Emit the digest of a streaming SHA-256 context.
ra8_err_t ra8_rsip_sha256_update(ra8_rsip_sha256_ctx_t *ctx, const uint8_t *data, uint32_t len)
Absorb additional bytes into a streaming SHA-256 context.
ra8_err_t ra8_rsip_sha256(const uint8_t *msg, uint32_t msg_len, uint8_t *digest)
Compute SHA-256 of an in-memory buffer.
ra8_err_t ra8_rsip_sha256_init(ra8_rsip_sha256_ctx_t *ctx)
Initialise a streaming SHA-256 context.
Secure-comparison primitives for the crypto / secure-boot paths.
In-RAM "download" cursor handed to the OTA net interface.
const uint8_t * data
Image bytes being served.
uint32_t pos
Bytes already handed to the OTA.
uint32_t len
Total image length in bytes.
Initialisation descriptor for ra8_flash_init.
Initialisation descriptor for ra8_ota_init.
ra8_ota_crypto_iface_t crypto
Crypto interface (must be fully populated).
char manifest_url[k_ra8_ota_url_max_bytes]
HTTPS URL of the manifest JSON.
uint32_t pubkey_handle
Opaque handle to the trusted ECDSA public key.
ra8_ota_flash_iface_t flash
Flash backend (must be fully populated).
ra8_ota_net_iface_t net
Network HTTPS interface (must be fully populated).
void * ctx
Opaque context passed back to every callback.
ra8_err_t(* ecdsa_verify)(void *ctx, uint32_t pubkey_handle, const uint8_t digest[k_ra8_ota_sha256_bytes], const uint8_t *sig, uint32_t sig_len)
Verify sig is a valid ECDSA signature over digest using the public key referenced by pubkey_handle.
ra8_err_t(* sha256_final)(void *ctx, uint8_t out[k_ra8_ota_sha256_bytes])
Finalise and write the 32-byte digest to out.
ra8_err_t(* sha256_update)(void *ctx, const uint8_t *data, uint32_t len)
Feed bytes to the running SHA-256 hash.
ra8_err_t(* sha256_init)(void *ctx)
Begin a SHA-256 streaming hash.
uint8_t inactive_bank_index
Bank index set_startup should select on commit.
ra8_err_t(* program)(void *ctx, uint32_t addr, const uint8_t *src, uint32_t len)
Program len bytes at addr (must be 32-byte aligned).
ra8_err_t(* set_startup)(void *ctx, uint8_t which_bank, bool persistent)
Pick the bank to boot from at the next reset.
uint32_t inactive_bank_addr
Base address of the inactive bank in the MRAM window.
uint32_t bank_size_bytes
Size of one bank in bytes.
void * ctx
Opaque context passed back to every callback.
ra8_err_t(* erase)(void *ctx, uint32_t addr, uint32_t len)
Erase len bytes starting at addr in the inactive bank.
ra8_err_t(* readback)(void *ctx, uint32_t addr, uint8_t *dst, uint32_t len)
Read back len bytes (used by verification re-hash).
Decoded representation of the server manifest.
uint8_t image_sha256[k_ra8_ota_sha256_bytes]
Expected digest.
uint16_t signature_len
Bytes used in signature.
char image_url[k_ra8_ota_url_max_bytes]
HTTPS URL of the image blob.
uint8_t signature[k_ra8_ota_signature_max_bytes]
ECDSA signature over digest.
uint32_t image_size_bytes
Image size on the wire.
char version[k_ra8_ota_version_str_bytes]
Firmware version string.
ra8_err_t(* close)(void *ctx)
Tear the streaming GET down.
ra8_err_t(* open)(void *ctx, const char *url, uint32_t *out_content_len)
Begin a streaming GET against url.
void * ctx
Opaque context passed back to every callback.
ra8_err_t(* read)(void *ctx, uint8_t *dst, uint32_t cap, uint32_t *out_len)
Read up to cap bytes from the open session.
Streaming state for incremental SHA-256.