54#ifndef RA8_MEDIA_DOWNLOAD_SOURCE_IMAGE
56#define RA8_MEDIA_DOWNLOAD_SOURCE_IMAGE (0)
60 "RA8_MEDIA_DOWNLOAD_SOURCE_IMAGE must be 0 or 1");
63typedef enum : uint32_t {
131[[gnu::section(
".sdram_data"),
196 __asm
volatile(
"wfi");
241 if (event ==
nullptr) {
298 if ((credentials ==
nullptr) || (credentials->
ssid[0] ==
'\0')) {
408 size_t destination_capacity,
409 size_t* output_bytes)
411 if ((source ==
nullptr) || (destination ==
nullptr) || (output_bytes ==
nullptr)) {
414 const size_t inflated = tinfl_decompress_mem_to_mem(
416 destination_capacity,
419 (uint32_t)(TINFL_FLAG_PARSE_ZLIB_HEADER | TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF));
420 if (inflated == TINFL_DECOMPRESS_MEM_TO_MEM_FAILED) {
423 *output_bytes = inflated;
531 .storage = storage_interface,
562 uint64_t flat_size = 0U;
566 uint32_t first_bytes = 0U;
568 first_bytes =
s_rabook.reader.chunk_bytes;
569 if (flat_size < first_bytes) {
570 first_bytes = (uint32_t)flat_size;
572 if ((first_bytes == 0U) || (first_bytes >
sizeof(
s_chunk)) ||
581 return ((err ==
k_ra8_ok) ? close_err : err);
636 if ((configuration ==
nullptr) || (configuration->
url[0] ==
'\0')) {
662 internal_puts(
"media_download: PASS C6->RABOOK->SD publish and read\r\n");
679 internal_puts(passed ?
"media_download: alive PASS\r\n" :
"media_download: alive FAIL\r\n");
725 (void)first_unused_memory;
760 internal_puts(
"media_download: boot; C6 Pmod1 + SD Pmod2\r\n");
void main(void)
Secure fallback main entry point.
Flat, execute-in-place container for a build-time "compiled" e-book.
static volatile uint8_t s_disconnected
static uint32_t s_cpuclk_hz
static volatile uint8_t s_connected
static ra8_c6link_t s_link
static TX_THREAD s_worker
static const ra8_net_provision_uart_t s_provision_uart
Board-console binding for the shared runtime provisioner.
static CHAR s_worker_name[]
static UCHAR s_worker_stack[k_c6_cam_worker_stack]
static uint32_t s_pclka_hz
static ra8_err_t s_port_err
void tx_application_define(void *first_unused_memory)
ThreadX system-define hook: build worker thread + byte pool.
static uint8_t s_scratch[(size_t) k_ra8_compress_scratch_bytes]
Compressor scratch (one miniz tdefl_compressor) in SRAM.
#define RA8_MEDIA_DOWNLOAD_SOURCE_IMAGE
Default preserves direct validation of prebuilt .rabook bodies.
static const char s_destination[]
No-replace destination on the mounted SD card.
static ra8_err_t internal_sha_update(void *context, const uint8_t *data, uint16_t length)
Feed one accepted body chunk to the independent RA8 digest.
media_limit_t
Fixed application bounds and board integration policy.
@ k_media_table_entries
2048 chunks + terminal offset.
@ k_media_diagnostic_bytes
Maximum emitted diagnostic length.
@ k_media_worker_priority
Worker priority and threshold.
@ k_media_c6_sck_hz
Bench-proven C6 SPI rate.
@ k_media_compressed_bytes
One worst-case zlib-wrapped 64 KiB chunk.
@ k_media_worker_stack_bytes
ThreadX worker stack.
@ k_media_rbkc_chunk_bytes
Accepted inflated RBKC chunk geometry.
@ k_media_c6_edge_poll_ms
C6 side-band poll period.
@ k_media_assoc_tries
Bounded station-event polls.
@ k_media_transfer_chunks
32 MiB compressed-body ceiling.
@ k_media_c6_arena_bytes
Protobuf decode arena.
@ k_media_heartbeat_ms
Persistent verdict interval.
@ k_media_transfer_chunk
Bytes requested per C6 body pull.
@ k_media_c6_boot_wait_ms
Coprocessor settle time.
@ k_media_assoc_gap_ms
Delay between association polls.
@ k_media_scratch_bytes
Strict CRC/ownership validation scratch.
@ k_media_uart_baud
J-Link OB console rate.
static mdl_storage_vfs_t s_storage
Transactional VFS storage adapter.
static void internal_worker(ULONG input)
Worker entry for the one-shot media transaction.
static bool internal_run(ra8_net_credentials_t *configuration)
Execute the complete hardware composition once.
static ra8_err_t internal_consume(void)
Reopen the committed RBKC and consume its first exact inflated chunk.
static bool internal_fail(const char *stage, ra8_err_t err)
Emit one failed-stage diagnostic.
static void internal_puts(const char *text)
Write one bounded NUL-terminated diagnostic to the board console.
static ra8_fs_backend_t s_fs_backend
SD filesystem backend retained for the mount lifetime.
static void internal_heartbeat(bool passed)
Keep the final verdict visible without busy-waiting.
static ra8_err_t internal_open_and_join(const ra8_net_credentials_t *credentials)
Open the C6 link, prove readiness, and associate its Wi-Fi station.
static ra8_err_t internal_mount_sd(void)
Mount the existing Pmod2 SD FAT volume under the VFS name sd.
static const bool s_source_is_image
Build-time input policy: encoded image or prebuilt RBKC body.
static ra8_rsip_sha256_ctx_t s_sha
Streaming RA8-side SHA-256 context.
static ra8_err_t internal_bind_transfer(ra8_mdl_transfer_config_t *output)
Bind strict reader, transaction, SHA, and coordinator policy.
static ra8_err_t internal_sha_final(void *context, uint8_t output[k_ra8_mdl_sha256_bytes])
Finalize the independent digest into the coordinator output.
static const char s_stage_leaf[]
Reserved sibling transaction name.
static void internal_on_event(void *context, const ra8_c6link_event_t *event)
Latch the two station events used by the bounded association wait.
static ra8_err_t internal_sha_init(void *context)
Reset the caller-owned SHA-256 stream.
static ra8_err_t internal_inflate(const void *source, size_t source_bytes, void *destination, size_t destination_capacity, size_t *output_bytes)
Inflate one zlib-wrapped RBKC chunk without heap allocation.
static uint8_t s_c6_arena[k_media_c6_arena_bytes]
Fixed C6 decode arena.
static bool internal_wait_connected(void)
Pump the C6 link until association succeeds or the fixed budget ends.
static void internal_setup_or_halt(void)
Bring up clocks, MSTP, delay timing, and the board console.
static void internal_halt(void)
Park the core permanently after an unrecoverable startup failure.
static uint8_t s_chunk[k_media_rbkc_chunk_bytes]
One inflated RBKC chunk and final-consumption destination.
static mdl_rabook_vfs_t s_rabook
Strict RBKC validator and final reader.
static ra8_err_t internal_transfer_and_consume(const ra8_net_credentials_t *configuration)
Bind, execute, validate, and consume one configured media transfer.
static uint8_t s_compressed[k_media_compressed_bytes]
One compressed zlib stream.
Strict no-heap RBKC validator and reader over named RA8 VFS mounts.
ra8_err_t mdl_rabook_vfs_read_chunk(mdl_rabook_vfs_t *ctx, uint64_t offset, uint8_t *dst, uint32_t len)
Read one exact chunk-aligned flat-blob span from an open book.
ra8_err_t mdl_rabook_vfs_close(mdl_rabook_vfs_t *ctx)
Close and release an open VFS reader facade.
ra8_err_t mdl_rabook_vfs_validate(void *opaque, const char *staging_path, uint64_t total_bytes, const uint8_t sha256[k_ra8_mdl_sha256_bytes])
Strictly validate one closed private RBKC staging object.
ra8_err_t mdl_rabook_vfs_info(const mdl_rabook_vfs_t *ctx, book_header_t *out_header, uint64_t *out_flat_size)
Copy metadata from an open strictly validated book.
ra8_err_t mdl_rabook_vfs_open(mdl_rabook_vfs_t *ctx, const char *path)
Open and strictly revalidate a published RBKC object for consumption.
ra8_err_t mdl_rabook_vfs_init(mdl_rabook_vfs_t *ctx, const mdl_rabook_vfs_config_t *config)
Initialize one strict RBKC VFS workspace binding.
No-heap VFS storage binding for the media-download coordinator.
ra8_err_t mdl_storage_vfs_init(mdl_storage_vfs_t *storage, const mdl_storage_vfs_config_t *config, ra8_mdl_storage_iface_t *out_iface)
Initialise one VFS storage adapter and bind its coordinator interface.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Board-support layer for the Renesas EK-RA8D2 v1 evaluation kit.
@ k_ra8_board_pmod2_spi_cipo
Pmod2.3 CIPO (CIPO0_B), P602.
@ k_ra8_board_pmod2_spi_cs
Pmod2.1 CS (SS0_B), P604.
@ k_ra8_board_pmod2_spi_copi
Pmod2.2 COPI (COPI0_B), P603.
@ k_ra8_board_pmod2_spi_sck
Pmod2.4 SCK (SCK0_B), P601.
@ k_ra8_board_pmod1_sci_channel
Pmod1 (J26) Simple-SPI is SCI2.
@ k_ra8_board_pmod2_sci_channel
Pmod2 (J25) Simple-SPI is SCI0.
ra8_err_t ra8_board_uart_console_read(uint8_t *out, size_t cap, size_t *out_len)
Polled non-blocking read from the J-Link OB VCOM console.
ra8_err_t ra8_board_clocks_init(ra8_board_clock_rates_t *out_rates)
Initialize the standard EK-RA8D2 clock tree and return its rates.
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.
The single integration boundary between this firmware and the ESP32-C6.
@ k_ra8_c6link_announce_transfers
Transactions ra8_c6link_await_ready spends on the announcement before it probes.
ra8_err_t ra8_c6link_close(ra8_c6link_t *link)
Release a link handle.
@ k_ra8_c6link_event_sta_connected
Event_StaConnected: the station has associated with an AP.
@ k_ra8_c6link_event_sta_disconnected
Event_StaDisconnected: the station has lost or left its AP.
ra8_err_t ra8_c6link_open(ra8_c6link_t *link, const ra8_c6link_cfg_t *cfg)
Bind a transport to a link handle and make it usable.
ra8_err_t ra8_c6link_await_ready(ra8_c6link_t *link, uint16_t max_transactions, ra8_c6link_fw_version_t *out)
Announce this host and prove the co-processor is answering.
struct ra8_c6link_cfg ra8_c6link_cfg_t
ra8_err_t ra8_c6link_poll(ra8_c6link_t *link, uint16_t max_transactions, ra8_c6link_stats_t *stats)
Clock transactions, delivering whatever the co-processor sends.
struct ra8_c6link_stats ra8_c6link_stats_t
struct ra8_c6link_event ra8_c6link_event_t
struct ra8_c6link_fw_version ra8_c6link_fw_version_t
struct ra8_c6link ra8_c6link_t
Transactional RA8-side coordinator for C6 media byte streams.
ra8_err_t ra8_c6link_mdl_transfer(ra8_c6link_t *link, const char *url, const char *destination, const ra8_mdl_transfer_config_t *config, ra8_mdl_transfer_result_t *result)
Fetch, verify, and atomically publish one remote byte stream.
struct ra8_mdl_transfer_config ra8_mdl_transfer_config_t
struct ra8_mdl_storage_iface ra8_mdl_storage_iface_t
struct ra8_mdl_transfer_result ra8_mdl_transfer_result_t
Wi-Fi station bring-up and association over the C6 link.
struct ra8_c6link_sta_cfg ra8_c6link_sta_cfg_t
ra8_err_t ra8_c6link_sta_cfg_set(ra8_c6link_sta_cfg_t *cfg, const char *ssid, const char *pass)
Fill a station configuration from an SSID and a passphrase.
ra8_err_t ra8_c6link_wifi_start(ra8_c6link_t *link)
Start the co-processor's Wi-Fi radio in station mode.
ra8_err_t ra8_c6link_wifi_join(ra8_c6link_t *link, const ra8_c6link_sta_cfg_t *cfg)
Ask the station to associate with the configured network.
Error Code Definitions for ra8-firmware.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_validation_failed
Validation rule failed (caller-supplied invariant not satisfied).
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_timeout
Operation exceeded its time budget.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
const char * ra8_err_to_str(ra8_err_t err)
Human-readable string for an error code.
Binds the ra8_c6link transport seam to this port's OS vtable.
ra8_err_t ra8_esp_hosted_c6link_bind(ra8_c6link_transport_t *out)
Fill a ra8_c6link transport seam with this port's implementations.
Public entry point of the RA8D2 + ThreadX port of esp-hosted.
struct ra8_esp_hosted_port_cfg ra8_esp_hosted_port_cfg_t
ra8_err_t ra8_esp_hosted_port_init(const ra8_esp_hosted_port_cfg_t *cfg)
Bring the esp-hosted port up and publish the OS-abstraction vtable.
Minimal FAT12/FAT16/FAT32 filesystem adapter (read + write).
ra8_err_t ra8_fs_mount(const ra8_fs_backend_t *backend, ra8_fs_mount_t **out_handle)
Mount a FAT volume from a block-device backend, auto-selecting the first partition.
static vfs_slot_t s_table[(uint32_t) k_ra8_io_vfs_max_mounts]
Fixed mount table.
ra8_io virtual filesystem – mount many volumes, address them by name.
ra8_err_t ra8_io_vfs_mount(const char *name, ra8_fs_mount_t *mount)
Register a mounted volume under a name.
ra8_err_t ra8_io_vfs_mkdir(const char *path)
Create a directory named "name:/path".
ra8_err_t ra8_io_vfs_stat(const char *path, ra8_io_vfs_stat_t *out)
Query metadata for "name:/path".
ra8_err_t ra8_io_vfs_init(void)
Reset the VFS mount table to empty.
NVIC + ICU IELSR allocator.
void ra8_isr_globals_enable(void)
Globally enable maskable interrupts (PRIMASK = 0).
@ k_ra8_mdl_sha256_bytes
SHA-256 digest size in bytes.
Ref-counted Module Stop Control wrapper for the RA8D2.
ra8_err_t ra8_mstp_init(void)
Re-establish the ra8_mstp ref-count table from current hardware state.
Runtime network provisioning contract for EK-RA8D2 applications.
struct ra8_net_credentials ra8_net_credentials_t
struct ra8_net_provision_uart ra8_net_provision_uart_t
@ k_ra8_net_provision_timeout_ms
Standard application RX timeout.
ra8_err_t ra8_net_provision_receive(const ra8_net_provision_uart_t *uart, uint32_t timeout_ms, ra8_net_credentials_t *out)
Prompt once and receive one provisioning line within a fixed timeout.
void ra8_net_provision_clear(ra8_net_credentials_t *credentials)
Explicitly erase one decoded credential record.
ra8_port_pin_t
Packed (port << 8) | pin pin identifier.
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_init(const ra8_rsip_config_t *cfg)
Power on the RSIP engine and (optionally) run BIST.
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_init(ra8_rsip_sha256_ctx_t *ctx)
Initialise a streaming SHA-256 context.
SD card driver in SPI-mode (PMOD-attached cards).
ra8_err_t ra8_sdmmc_spi_transport_sci(uint8_t sci_channel, uint32_t pclk_hz, const ra8_sdmmc_spi_sci_pins_t *pins, ra8_sdmmc_spi_transport_t *out)
Build the standard EK-RA8D2 SCI Simple-SPI transport for an SD card.
ra8_err_t ra8_sdmmc_spi_init(const ra8_sdmmc_spi_transport_t *transport)
Run the SD SPI-mode identification sequence on a card.
ra8_err_t ra8_sdmmc_spi_bind_fs_backend(ra8_fs_backend_t *out_backend)
Populate an ra8_fs_backend_t that mounts onto this SD driver.
Secure-comparison primitives for the crypto / secure-boot paths.
void ra8_secure_memzero(void *ptr, size_t len)
Securely zero a buffer such that the write cannot be optimised away.
SysTick-based tick counter, delay and timestamp helpers.
ra8_err_t ra8_time_init(uint32_t cpu_hz)
Initialise SysTick for a 1 kHz tick interrupt.
void ra8_delay_ms(uint32_t ms)
Busy-wait for at least ms milliseconds.
unsigned int UINT
ThreadX-compatible unsigned int (host stub).
char CHAR
ThreadX-compatible CHAR (host stub).
unsigned long ULONG
ThreadX-compatible unsigned long (host stub).
static ra8_fs_mount_t * s_mount
Mounted FAT volume, or NULL.
Opaque thread stand-in for the host build.
Caller-owned decompression and strict-validation workspace binding.
One initialized strict validator or one open validated RBKC reader.
Immutable policy copied or retained by an adapter instance.
Caller-owned VFS transaction context.
Clock rates published by the standard EK-RA8D2 bring-up.
uint32_t pclka_hz
Peripheral clock A rate in hertz.
uint32_t cpuclk0_hz
Main Cortex-M85 clock rate in hertz.
ra8_c6link_transport_t transport
The hardware seam; every row required.
uint32_t arena_bytes
Bytes available at arena.
uint8_t * arena
Protobuf decode arena.
ra8_c6link_event_cb_t event_cb
Announcement sink, or null to count.
ra8_c6link_event_kind_t kind
Which announcement this is.
Block-device interface that ra8_fs runs on top of.
Cached parse of one mounted FAT volume.
Metadata returned by ra8_io_vfs_stat.
bool is_directory
true => path names a directory.
bool exists
true => the path resolves to an entry.
uint8_t psk_len
Decoded PSK bytes, excluding the NUL.
char psk[k_ra8_net_provision_psk_bytes_max+1U]
NUL-terminated PSK storage.
char url[k_ra8_net_provision_url_bytes_max+1U]
NUL-terminated optional URL storage.
uint8_t ssid_len
Decoded SSID bytes, excluding the NUL.
char ssid[k_ra8_net_provision_ssid_bytes_max+1U]
NUL-terminated SSID storage.
Initial configuration for ra8_rsip_init.
Streaming state for incremental SHA-256.
The four bus pins of an SCI Simple-SPI SD slot.
Driver-to-bus binding (Dependency Inversion seam).