ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_ota.h
Go to the documentation of this file.
1
51
52#pragma once
53
54#ifdef __cplusplus
55extern "C" {
56#endif
57
58#include <stddef.h>
59#include <stdint.h>
60
61#include "ra8_err.h"
62
82
101
123
134
148
162typedef struct {
168 ra8_err_t (*open)(void* ctx, const char* url, uint32_t* out_content_len);
169
174 ra8_err_t (*read)(void* ctx, uint8_t* dst, uint32_t cap, uint32_t* out_len);
175
179 ra8_err_t (*close)(void* ctx);
180
182 void* ctx;
184
195typedef struct {
199 ra8_err_t (*sha256_update)(void* ctx, const uint8_t* data, uint32_t len);
202
208 uint32_t pubkey_handle,
209 const uint8_t digest[k_ra8_ota_sha256_bytes],
210 const uint8_t* sig,
211 uint32_t sig_len);
212
214 void* ctx;
216
228typedef struct {
230 ra8_err_t (*erase)(void* ctx, uint32_t addr, uint32_t len);
232 ra8_err_t (*program)(void* ctx, uint32_t addr, const uint8_t* src, uint32_t len);
234 ra8_err_t (*set_startup)(void* ctx, uint8_t which_bank, bool persistent);
236 ra8_err_t (*readback)(void* ctx, uint32_t addr, uint8_t* dst, uint32_t len);
237
244
246 void* ctx;
248
280
308[[nodiscard]] ra8_err_t ra8_ota_init(const ra8_ota_cfg_t* cfg);
309
328[[nodiscard]] ra8_err_t ra8_ota_deinit(void);
329
360[[nodiscard]] ra8_err_t ra8_ota_check_for_update(ra8_ota_manifest_t* out_manifest);
361
398
433[[nodiscard]] ra8_err_t ra8_ota_verify_signature(const ra8_ota_manifest_t* manifest);
434
461[[nodiscard]] ra8_err_t ra8_ota_commit_and_reboot(void);
462
490
510[[nodiscard]] ra8_err_t ra8_ota_run_step(void);
511
531[[nodiscard]] ra8_err_t ra8_ota_run_full_update(void);
532
551
552#ifdef __cplusplus
553}
554#endif
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
ra8_err_t ra8_ota_run_step(void)
Drive the OTA state machine one step forward.
Definition ra8_ota.c:707
ra8_err_t ra8_ota_commit_and_reboot(void)
Persist the bank swap and reboot.
Definition ra8_ota.c:603
void ra8_ota_system_reset_hook(void)
Test/host hook for commit_and_reboot.
Definition ra8_ota.c:791
void(* ra8_ota_progress_cb_t)(const ra8_ota_progress_t *p)
Caller progress callback type.
Definition ra8_ota.h:147
ra8_err_t ra8_ota_download_to_inactive_bank(const ra8_ota_manifest_t *manifest)
Stream the firmware blob into the inactive MRAM bank.
Definition ra8_ota.c:534
ra8_ota_state_t
Cooperative state-machine states.
Definition ra8_ota.h:91
@ k_ra8_ota_state_count
Sentinel.
Definition ra8_ota.h:99
@ k_ra8_ota_state_error
Last operation failed; see last err.
Definition ra8_ota.h:98
@ k_ra8_ota_state_checking
Manifest fetch in flight.
Definition ra8_ota.h:93
@ k_ra8_ota_state_verifying
SHA-256 + ECDSA verification.
Definition ra8_ota.h:95
@ k_ra8_ota_state_done
Update applied (reset is imminent).
Definition ra8_ota.h:97
@ k_ra8_ota_state_committing
About to swap banks + reset.
Definition ra8_ota.h:96
@ k_ra8_ota_state_downloading
Streaming firmware to inactive bank.
Definition ra8_ota.h:94
@ k_ra8_ota_state_idle
No update in progress.
Definition ra8_ota.h:92
ra8_err_t ra8_ota_run_full_update(void)
Kick off an end-to-end update from idle.
Definition ra8_ota.c:740
ra8_err_t ra8_ota_init(const ra8_ota_cfg_t *cfg)
Initialise the OTA module.
Definition ra8_ota.c:182
ra8_ota_state_t ra8_ota_get_state(void)
Return the current state-machine value.
Definition ra8_ota.c:257
ra8_err_t ra8_ota_verify_signature(const ra8_ota_manifest_t *manifest)
Verify SHA-256 + ECDSA over the freshly programmed bank.
ra8_err_t ra8_ota_check_for_update(ra8_ota_manifest_t *out_manifest)
Fetch and decode the manifest JSON over HTTPS.
Definition ra8_ota.c:338
ra8_ota_constants_t
Compile-time bounds for the OTA module.
Definition ra8_ota.h:72
@ k_ra8_ota_url_max_bytes
NUL-terminated URL upper bound.
Definition ra8_ota.h:77
@ k_ra8_ota_sha256_bytes
SHA-256 digest length.
Definition ra8_ota.h:75
@ k_ra8_ota_version_str_bytes
NUL-terminated version string.
Definition ra8_ota.h:78
@ k_ra8_ota_thread_stack_bytes
Static ThreadX worker stack.
Definition ra8_ota.h:80
@ k_ra8_ota_chunk_bytes
Download streaming chunk size in bytes.
Definition ra8_ota.h:73
@ k_ra8_ota_max_image_bytes
512 KiB upper bound per bank.
Definition ra8_ota.h:79
@ k_ra8_ota_signature_max_bytes
ECDSA-P256 ASN.1 sig upper bound.
Definition ra8_ota.h:76
@ k_ra8_ota_manifest_max_bytes
Largest accepted manifest payload.
Definition ra8_ota.h:74
ra8_err_t ra8_ota_deinit(void)
Tear the OTA module down (mostly for tests / re-init).
Definition ra8_ota.c:224
Initialisation descriptor for ra8_ota_init.
Definition ra8_ota.h:258
ra8_ota_crypto_iface_t crypto
Crypto interface (must be fully populated).
Definition ra8_ota.h:272
char manifest_url[k_ra8_ota_url_max_bytes]
HTTPS URL of the manifest JSON.
Definition ra8_ota.h:260
uint32_t pubkey_handle
Opaque handle to the trusted ECDSA public key.
Definition ra8_ota.h:263
ra8_ota_flash_iface_t flash
Flash backend (must be fully populated).
Definition ra8_ota.h:275
bool run_as_thread
true => spawn the static ThreadX worker thread.
Definition ra8_ota.h:278
ra8_ota_net_iface_t net
Network HTTPS interface (must be fully populated).
Definition ra8_ota.h:269
ra8_ota_progress_cb_t on_progress
Progress callback (NULL == disabled).
Definition ra8_ota.h:266
Injected hash + ECDSA verification interface.
Definition ra8_ota.h:195
void * ctx
Opaque context passed back to every callback.
Definition ra8_ota.h:214
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.
Definition ra8_ota.h:207
ra8_err_t(* sha256_final)(void *ctx, uint8_t out[k_ra8_ota_sha256_bytes])
Finalise and write the 32-byte digest to out.
Definition ra8_ota.h:201
ra8_err_t(* sha256_update)(void *ctx, const uint8_t *data, uint32_t len)
Feed bytes to the running SHA-256 hash.
Definition ra8_ota.h:199
ra8_err_t(* sha256_init)(void *ctx)
Begin a SHA-256 streaming hash.
Definition ra8_ota.h:197
Injected flash backend (so tests do not need real MRAM).
Definition ra8_ota.h:228
uint8_t inactive_bank_index
Bank index set_startup should select on commit.
Definition ra8_ota.h:243
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).
Definition ra8_ota.h:232
ra8_err_t(* set_startup)(void *ctx, uint8_t which_bank, bool persistent)
Pick the bank to boot from at the next reset.
Definition ra8_ota.h:234
uint32_t inactive_bank_addr
Base address of the inactive bank in the MRAM window.
Definition ra8_ota.h:239
uint32_t bank_size_bytes
Size of one bank in bytes.
Definition ra8_ota.h:241
void * ctx
Opaque context passed back to every callback.
Definition ra8_ota.h:246
ra8_err_t(* erase)(void *ctx, uint32_t addr, uint32_t len)
Erase len bytes starting at addr in the inactive bank.
Definition ra8_ota.h:230
ra8_err_t(* readback)(void *ctx, uint32_t addr, uint8_t *dst, uint32_t len)
Read back len bytes (used by verification re-hash).
Definition ra8_ota.h:236
Decoded representation of the server manifest.
Definition ra8_ota.h:115
uint8_t image_sha256[k_ra8_ota_sha256_bytes]
Expected digest.
Definition ra8_ota.h:119
uint16_t signature_len
Bytes used in signature.
Definition ra8_ota.h:121
char image_url[k_ra8_ota_url_max_bytes]
HTTPS URL of the image blob.
Definition ra8_ota.h:117
uint8_t signature[k_ra8_ota_signature_max_bytes]
ECDSA signature over digest.
Definition ra8_ota.h:120
uint32_t image_size_bytes
Image size on the wire.
Definition ra8_ota.h:118
char version[k_ra8_ota_version_str_bytes]
Firmware version string.
Definition ra8_ota.h:116
Injected HTTPS-download interface (Dependency Inversion).
Definition ra8_ota.h:162
ra8_err_t(* close)(void *ctx)
Tear the streaming GET down.
Definition ra8_ota.h:179
ra8_err_t(* open)(void *ctx, const char *url, uint32_t *out_content_len)
Begin a streaming GET against url.
Definition ra8_ota.h:168
void * ctx
Opaque context passed back to every callback.
Definition ra8_ota.h:182
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.
Definition ra8_ota.h:174
Snapshot delivered to the caller's progress callback.
Definition ra8_ota.h:128
ra8_ota_state_t state
Current state machine value.
Definition ra8_ota.h:129
uint32_t bytes_total
Manifest-declared size.
Definition ra8_ota.h:131
uint32_t bytes_done
Bytes successfully programmed so far.
Definition ra8_ota.h:130
ra8_err_t last_err
Last error (k_ra8_ok if healthy).
Definition ra8_ota.h:132