|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Download, validate, publish, and reopen one C6-fetched .rabook. More...
#include <stddef.h>#include <stdint.h>#include "book.h"#include "mdl_rabook_vfs.h"#include "mdl_storage_vfs.h"#include "media_download_image_internal.h"#include "miniz.h"#include "ra8_attributes.h"#include "ra8_board_ek_ra8d2.h"#include "ra8_boot_entry.h"#include "ra8_c6link.h"#include "ra8_c6link_mdl_transfer.h"#include "ra8_c6link_wifi.h"#include "ra8_err.h"#include "ra8_esp_hosted_c6link.h"#include "ra8_esp_hosted_port.h"#include "ra8_fs.h"#include "ra8_io_vfs.h"#include "ra8_isr.h"#include "ra8_mstp.h"#include "ra8_net_provision.h"#include "ra8_rsip.h"#include "ra8_sdmmc_spi.h"#include "ra8_secure.h"#include "ra8_time.h"#include "tx_api.h"Go to the source code of this file.
Macros | |
| #define | RA8_MEDIA_DOWNLOAD_SOURCE_IMAGE (0) |
| Default preserves direct validation of prebuilt .rabook bodies. | |
Enumerations | |
| enum | media_limit_t : uint32_t { k_media_uart_baud = 115200U , k_media_c6_sck_hz = 5000000U , k_media_c6_edge_poll_ms = 2U , k_media_c6_boot_wait_ms = 200U , k_media_assoc_tries = 200U , k_media_assoc_gap_ms = 50U , k_media_diagnostic_bytes = 256U , k_media_heartbeat_ms = 5000U , k_media_worker_stack_bytes = 8192U , k_media_worker_priority = 8U , k_media_c6_arena_bytes = 4096U , k_media_transfer_chunk = 1024U , k_media_transfer_chunks = 32768U , k_media_rbkc_chunk_bytes = 65536U , k_media_compressed_bytes = 66560U , k_media_table_entries = 2049U , k_media_scratch_bytes = 65536U } |
| Fixed application bounds and board integration policy. More... | |
Functions | |
| static void | internal_puts (const char *text) |
| Write one bounded NUL-terminated diagnostic to the board console. | |
| static bool | internal_fail (const char *stage, ra8_err_t err) |
| Emit one failed-stage diagnostic. | |
| static void | internal_halt (void) |
| Park the core permanently after an unrecoverable startup failure. | |
| static void | internal_setup_or_halt (void) |
| Bring up clocks, MSTP, delay timing, and the board console. | |
| 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 bool | internal_wait_connected (void) |
| Pump the C6 link until association succeeds or the fixed budget ends. | |
| 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 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 ra8_err_t | internal_sha_init (void *context) |
| Reset the caller-owned SHA-256 stream. | |
| 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. | |
| 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 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_consume (void) |
| Reopen the committed RBKC and consume its first exact inflated chunk. | |
| static ra8_err_t | internal_transfer_and_consume (const ra8_net_credentials_t *configuration) |
| Bind, execute, validate, and consume one configured media transfer. | |
| static bool | internal_run (ra8_net_credentials_t *configuration) |
| Execute the complete hardware composition once. | |
| static void | internal_heartbeat (bool passed) |
| Keep the final verdict visible without busy-waiting. | |
| static void | internal_worker (ULONG input) |
| Worker entry for the one-shot media transaction. | |
| void | tx_application_define (void *first_unused_memory) |
| Initialize ESP-hosted and create the single application worker. | |
| void | main (void) |
| Initialize the board and hand control to ThreadX. | |
Variables | |
| static const char | s_destination [] = "sd:/BOOKS/C6BOOK.RBK" |
| No-replace destination on the mounted SD card. | |
| static const char | s_stage_leaf [] = "C6STAGE.TMP" |
| Reserved sibling transaction name. | |
| static const bool | s_source_is_image = (0) != 0 |
| Build-time input policy: encoded image or prebuilt RBKC body. | |
| static uint32_t | s_cpuclk_hz |
| Cached CPU clock for the delay service. | |
| static uint32_t | s_pclka_hz |
| Cached PCLKA clock for both SPI transports. | |
| static ra8_err_t | s_port_err = k_ra8_err_not_initialized |
| ESP-hosted port initialization verdict. | |
| static TX_THREAD | s_worker |
| Worker thread object. | |
| static CHAR | s_worker_name [] = "media_download" |
| Writable ThreadX worker name. | |
| static UCHAR | s_worker_stack [k_media_worker_stack_bytes] |
| Caller-owned ThreadX worker stack. | |
| static ra8_c6link_t | s_link |
| One exclusively owned C6 link. | |
| static uint8_t | s_c6_arena [k_media_c6_arena_bytes] |
| Fixed C6 decode arena. | |
| static volatile uint8_t | s_connected |
| Station-associated event latch. | |
| static volatile uint8_t | s_disconnected |
| Station-disconnected event latch. | |
| static const ra8_net_provision_uart_t | s_provision_uart |
| Board-console binding for the shared runtime provisioner. | |
| static ra8_fs_backend_t | s_fs_backend |
| SD filesystem backend retained for the mount lifetime. | |
| static ra8_fs_mount_t * | s_mount |
| Mounted existing SD volume. | |
| static mdl_storage_vfs_t | s_storage |
| Transactional VFS storage adapter. | |
| static mdl_rabook_vfs_t | s_rabook |
| Strict RBKC validator and final reader. | |
| static ra8_rsip_sha256_ctx_t | s_sha |
| Streaming RA8-side SHA-256 context. | |
| static uint64_t | s_table [k_media_table_entries] |
| RBKC offset table: up to 128 MiB inflated at 64 KiB per chunk. | |
| static uint8_t | s_compressed [k_media_compressed_bytes] |
| One compressed zlib stream. | |
| static uint8_t | s_chunk [k_media_rbkc_chunk_bytes] |
| One inflated RBKC chunk and final-consumption destination. | |
| static uint8_t | s_scratch [k_media_scratch_bytes] |
| Independent strict semantic and CRC scratch. | |
Download, validate, publish, and reopen one C6-fetched .rabook.
This hardware-pending composition root joins Wi-Fi through the ESP32-C6, mounts an existing FAT volume on Pmod2 micro-SD, and downloads either one prebuilt RBKC .rabook body or one encoded image through the C6 media RPC. Image mode converts the source into a reader-native RABOOK1 book and RBKC container on the RA8. Both modes hash, strictly validate, transactionally publish, reopen, and consume the result. Every large workspace is caller-owned SDRAM; neither first-party heap nor stdio is used.
The image is credential-free. A bounded versioned record supplies Wi-Fi and URL configuration over the board console after boot. The app stays in hw_pending until the exact mixed RA8/C6 image and removable-media path pass physical fault-injection HIL.
Definition in file main.c.
| #define RA8_MEDIA_DOWNLOAD_SOURCE_IMAGE (0) |
| enum media_limit_t : uint32_t |
Fixed application bounds and board integration policy.
|
static |
Bind strict reader, transaction, SHA, and coordinator policy.
Connects only caller-owned workspaces and the mounted VFS to a create-new transaction whose validator reopens every RBKC stream.
| [out] | output | Complete transfer configuration. |
| k_ra8_ok | Every caller-owned seam is ready. |
Definition at line 506 of file main.c.
References internal_inflate(), internal_sha_final(), internal_sha_init(), internal_sha_update(), k_mdl_format_rabook, k_media_table_entries, k_media_transfer_chunk, k_media_transfer_chunks, k_ra8_ok, mdl_rabook_vfs_init(), mdl_rabook_vfs_validate(), mdl_storage_vfs_init(), RA8_INTERNAL, s_chunk, s_compressed, s_rabook, s_scratch, s_sha, s_stage_leaf, s_storage, and s_table.
Referenced by internal_transfer_and_consume().
|
static |
Reopen the committed RBKC and consume its first exact inflated chunk.
Revalidates final-file geometry through the reusable reader and performs one demand-paged chunk read to prove post-publication consumption.
| k_ra8_ok | Metadata and the first chunk were read successfully. |
| k_ra8_err_invalid_size | Geometry exceeds the bound workspace. |
Definition at line 558 of file main.c.
References k_ra8_err_invalid_size, k_ra8_ok, mdl_rabook_vfs_close(), mdl_rabook_vfs_info(), mdl_rabook_vfs_open(), mdl_rabook_vfs_read_chunk(), RA8_INTERNAL, s_chunk, s_destination, s_rabook, and book_header_t::total_size.
Referenced by internal_transfer_and_consume().
|
static |
Emit one failed-stage diagnostic.
Composes the stage label and canonical error spelling as bounded fragments so a failure path never needs a formatting stream or scratch.
| [in] | stage | Stable stage label. |
| [in] | err | Canonical RA8 error for that stage. |
| false | The stage failed. |
stage is a bounded NUL-terminated string. Definition at line 174 of file main.c.
References internal_puts(), ra8_err_to_str(), and RA8_INTERNAL.
Referenced by internal_run(), and internal_worker().
|
static |
Park the core permanently after an unrecoverable startup failure.
Definition at line 193 of file main.c.
References RA8_INTERNAL.
Referenced by internal_setup_or_halt(), and main().
|
static |
Keep the final verdict visible without busy-waiting.
| [in] | passed | Stable end-to-end verdict. |
Definition at line 676 of file main.c.
References internal_puts(), k_media_heartbeat_ms, RA8_INTERNAL, and tx_thread_sleep.
Referenced by internal_worker().
|
static |
Inflate one zlib-wrapped RBKC chunk without heap allocation.
Adapts miniz's bounded memory-to-memory decoder to the strict RBKC reader callback and maps an incomplete or malformed stream to validation.
| [in] | source | Compressed bytes. |
| [in] | source_bytes | Compressed byte count. |
| [out] | destination | Inflated destination. |
| [in] | destination_capacity | Writable destination capacity. |
| [out] | output_bytes | Exact inflated count. |
| k_ra8_ok | One complete stream inflated. |
| k_ra8_err_validation_failed | Miniz rejected the stream. |
Definition at line 405 of file main.c.
References k_ra8_err_null_ptr, k_ra8_err_validation_failed, k_ra8_ok, and RA8_INTERNAL.
Referenced by internal_bind_transfer(), and ra8_fmt_rabook_inspect_stream().
|
static |
Mount the existing Pmod2 SD FAT volume under the VFS name sd.
Composes the board SCI transport through SDMMC, FAT, and VFS layers, then prepares only the bounded BOOKS namespace without formatting media.
| k_ra8_ok | The mount and sd:/BOOKS directory are ready. |
| k_ra8_err_invalid_arg | BOOKS exists but is not a directory. |
Definition at line 346 of file main.c.
References ra8_io_vfs_stat_t::exists, ra8_io_vfs_stat_t::is_directory, k_ra8_board_pmod2_sci_channel, k_ra8_board_pmod2_spi_cipo, k_ra8_board_pmod2_spi_copi, k_ra8_board_pmod2_spi_cs, k_ra8_board_pmod2_spi_sck, k_ra8_err_invalid_arg, k_ra8_ok, ra8_fs_mount(), RA8_INTERNAL, ra8_io_vfs_init(), ra8_io_vfs_mkdir(), ra8_io_vfs_mount(), ra8_io_vfs_stat(), ra8_sdmmc_spi_bind_fs_backend(), ra8_sdmmc_spi_init(), ra8_sdmmc_spi_transport_sci(), s_fs_backend, s_mount, and s_pclka_hz.
Referenced by internal_run().
|
static |
Latch the two station events used by the bounded association wait.
Reduces the asynchronous event stream to the two terminal states needed by the worker's bounded association loop.
| [in] | context | Unused callback context. |
| [in] | event | C6 event record, or null for a defensive no-op. |
Definition at line 238 of file main.c.
References k_ra8_c6link_event_sta_connected, k_ra8_c6link_event_sta_disconnected, ra8_c6link_event::kind, RA8_INTERNAL, s_connected, and s_disconnected.
Referenced by internal_open_and_join().
|
static |
Open the C6 link, prove readiness, and associate its Wi-Fi station.
Binds the ESP-hosted transport, completes the C6 readiness handshake, starts Wi-Fi, and applies the supplied runtime station credentials.
| [in] | credentials | Validated runtime credential record. |
| k_ra8_ok | The C6 is ready and the station connected. |
| k_ra8_err_invalid_arg | Credentials are empty. |
Definition at line 296 of file main.c.
References ra8_c6link_cfg::arena, ra8_c6link_cfg::arena_bytes, ra8_c6link_cfg::event_cb, internal_on_event(), internal_wait_connected(), k_ra8_c6link_announce_transfers, k_ra8_err_invalid_arg, k_ra8_err_timeout, k_ra8_ok, ra8_net_credentials::psk, ra8_c6link_await_ready(), ra8_c6link_open(), ra8_c6link_sta_cfg_set(), ra8_c6link_wifi_join(), ra8_c6link_wifi_start(), ra8_esp_hosted_c6link_bind(), RA8_INTERNAL, ra8_secure_memzero(), s_c6_arena, s_link, ra8_net_credentials::ssid, and ra8_c6link_cfg::transport.
Referenced by internal_run().
|
static |
Write one bounded NUL-terminated diagnostic to the board console.
Measures only within the fixed diagnostic cap, then sends that byte span through the board's allocation-free UART adapter.
| [in] | text | NUL-terminated text to emit. |
text is non-null and terminates within the diagnostic cap. Definition at line 150 of file main.c.
References k_media_diagnostic_bytes, ra8_board_uart_console_write(), and RA8_INTERNAL.
Referenced by internal_fail(), internal_heartbeat(), internal_run(), main(), and tx_application_define().
|
static |
Execute the complete hardware composition once.
Sequences storage mount, RSIP self-test, C6 association, bounded transfer, optional image-to-RABOOK formatting, strict precommit validation, publication, and final consumption.
| true | The artifact was downloaded, committed, and consumed. |
| false | One named stage failed. |
| [in,out] | configuration | Validated runtime network and URL configuration. |
Definition at line 631 of file main.c.
References internal_fail(), internal_mount_sd(), internal_open_and_join(), internal_puts(), internal_transfer_and_consume(), k_media_c6_boot_wait_ms, k_ra8_err_invalid_arg, k_ra8_ok, ra8_net_credentials::psk, ra8_net_credentials::psk_len, ra8_c6link_close(), ra8_delay_ms(), RA8_INTERNAL, ra8_rsip_init(), ra8_secure_memzero(), s_link, s_port_err, ra8_net_credentials::ssid, ra8_net_credentials::ssid_len, and ra8_net_credentials::url.
Referenced by internal_worker().
|
static |
Bring up clocks, MSTP, delay timing, and the board console.
Establishes the clock values consumed by the C6 and SD transports before ThreadX can schedule their single owning worker.
Definition at line 211 of file main.c.
References ra8_board_clock_rates_t::cpuclk0_hz, internal_halt(), k_media_uart_baud, k_ra8_ok, ra8_board_clock_rates_t::pclka_hz, ra8_board_clocks_init(), ra8_board_uart_console_init(), RA8_INTERNAL, ra8_mstp_init(), ra8_time_init(), s_cpuclk_hz, and s_pclka_hz.
Referenced by main().
|
static |
Finalize the independent digest into the coordinator output.
Completes the RSIP stream directly into the transfer coordinator's fixed-size digest destination for comparison with the C6-advertised hash.
| [in,out] | context | Bound ra8_rsip_sha256_ctx_t. |
| [out] | output | Exact SHA-256 digest span. |
| k_ra8_ok | The complete digest was written. |
| k_ra8_err_invalid_arg | The state or output span was invalid. |
context received every accepted body byte. output covers k_ra8_mdl_sha256_bytes bytes. Definition at line 486 of file main.c.
References k_ra8_mdl_sha256_bytes, RA8_INTERNAL, and ra8_rsip_sha256_final().
Referenced by internal_bind_transfer().
|
static |
Reset the caller-owned SHA-256 stream.
Adapts the transfer coordinator's opaque context callback to the caller-owned RSIP SHA-256 state without copying or retaining input bytes.
| [in,out] | context | Bound ra8_rsip_sha256_ctx_t. |
| k_ra8_ok | The digest stream was reset. |
| k_ra8_err_invalid_arg | The bound context was invalid. |
context points to s_sha. Definition at line 442 of file main.c.
References RA8_INTERNAL, and ra8_rsip_sha256_init().
Referenced by internal_bind_transfer().
|
static |
Feed one accepted body chunk to the independent RA8 digest.
Preserves transfer order while forwarding each accepted C6 body fragment to the streaming RSIP digest used for final wire verification.
| [in,out] | context | Bound ra8_rsip_sha256_ctx_t. |
| [in] | data | Ordered body bytes. |
| [in] | length | Body byte count. |
| k_ra8_ok | The complete fragment entered the digest. |
| k_ra8_err_invalid_arg | The state or input span was invalid. |
context was initialized and data covers length bytes. length bytes. Definition at line 465 of file main.c.
References ra8_rsip_sha256_update().
Referenced by internal_bind_transfer().
|
static |
Bind, execute, validate, and consume one configured media transfer.
| [in] | configuration | Validated runtime configuration whose URL is nonempty. |
| k_ra8_ok | The artifact was transferred and consumed successfully. |
configuration is non-NULL and remains live for the synchronous call. Definition at line 597 of file main.c.
References internal_bind_transfer(), internal_consume(), k_ra8_ok, priv_media_download_image_run(), ra8_c6link_mdl_transfer(), s_destination, s_link, s_source_is_image, and ra8_net_credentials::url.
Referenced by internal_run().
|
static |
Pump the C6 link until association succeeds or the fixed budget ends.
Alternates bounded RPC polling with ThreadX sleeps and stops on the first connection, disconnection, or exhausted-attempt condition.
| true | Association completed. |
| false | Disconnection or the poll budget ended first. |
Definition at line 265 of file main.c.
References k_media_assoc_gap_ms, k_media_assoc_tries, k_ra8_c6link_announce_transfers, ra8_c6link_poll(), RA8_INTERNAL, s_connected, s_disconnected, s_link, and tx_thread_sleep.
Referenced by internal_open_and_join().
|
static |
Worker entry for the one-shot media transaction.
Runs the complete transaction exactly once and converts its stable result into a low-duty-cycle heartbeat for bench observation.
| [in] | input | Unused ThreadX entry value. |
Definition at line 696 of file main.c.
References internal_fail(), internal_heartbeat(), internal_run(), k_ra8_net_provision_timeout_ms, k_ra8_ok, RA8_INTERNAL, ra8_net_provision_clear(), ra8_net_provision_receive(), and s_provision_uart.
Referenced by tx_application_define().
| void main | ( | void | ) |
Initialize the board and hand control to ThreadX.
The application entry point Reset_Handler hands control to.
Definition at line 756 of file main.c.
References internal_halt(), internal_puts(), internal_setup_or_halt(), and ra8_isr_globals_enable().
| void tx_application_define | ( | void * | first_unused_memory | ) |
Initialize ESP-hosted and create the single application worker.
| [in] | first_unused_memory | ThreadX free-memory pointer; unused. |
Definition at line 723 of file main.c.
References internal_puts(), internal_worker(), k_media_c6_edge_poll_ms, k_media_c6_sck_hz, k_media_worker_priority, k_ra8_board_pmod1_sci_channel, ra8_esp_hosted_port_init(), s_pclka_hz, s_port_err, s_worker, s_worker_name, s_worker_stack, TX_AUTO_START, TX_NO_TIME_SLICE, TX_SUCCESS, and tx_thread_create.
|
static |
Fixed C6 decode arena.
Definition at line 105 of file main.c.
Referenced by internal_open_and_join().
|
static |
One inflated RBKC chunk and final-consumption destination.
Definition at line 134 of file main.c.
Referenced by internal_bind_transfer(), and internal_consume().
|
static |
One compressed zlib stream.
Definition at line 132 of file main.c.
Referenced by internal_bind_transfer().
|
static |
|
static |
|
static |
No-replace destination on the mounted SD card.
Definition at line 84 of file main.c.
Referenced by internal_consume(), and internal_transfer_and_consume().
|
static |
|
static |
SD filesystem backend retained for the mount lifetime.
Definition at line 118 of file main.c.
Referenced by demo_fs_format_or_panic(), and internal_mount_sd().
|
static |
|
static |
|
static |
|
static |
|
static |
Board-console binding for the shared runtime provisioner.
|
static |
Strict RBKC validator and final reader.
Definition at line 124 of file main.c.
Referenced by internal_bind_transfer(), and internal_consume().
|
static |
|
static |
Streaming RA8-side SHA-256 context.
Definition at line 126 of file main.c.
Referenced by internal_bind_transfer().
|
static |
Build-time input policy: encoded image or prebuilt RBKC body.
Definition at line 88 of file main.c.
Referenced by internal_transfer_and_consume().
|
static |
Reserved sibling transaction name.
Definition at line 86 of file main.c.
Referenced by internal_bind_transfer().
|
static |
Transactional VFS storage adapter.
Definition at line 122 of file main.c.
Referenced by internal_bind_transfer().
|
static |
|
static |
|
static |