ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c File Reference

On-silicon HIL: epub parse layer runs on the target (#139). More...

#include <stddef.h>
#include <stdint.h>
#include "epub.h"
#include "epub_fixture.h"
#include "ra8_board_ek_ra8d2.h"
#include "ra8_boot_entry.h"
#include "ra8_cgc.h"
#include "ra8_err.h"
#include "ra8_isr.h"
#include "ra8_mstp.h"
#include "ra8_time.h"
Include dependency graph for main.c:

Go to the source code of this file.

Enumerations

enum  ep_consts_t : uint32_t {
  k_ep_uart_baud = 115200U ,
  k_ep_expect_chap = 2U ,
  k_ep_chap_cap = 4096U ,
  k_ep_crc_init = 0xFFFFFFFFU ,
  k_ep_crc_poly = 0xEDB88320U ,
  k_ep_crc_bits = 8U ,
  k_ep_hex_nibbles = 8U ,
  k_ep_nibble_bits = 4U ,
  k_ep_nibble_mask = 0x0FU ,
  k_ep_dec_ten = 10U
}
 Console / parse knobs (no magic numbers). More...

Functions

static void ep_print (const uint8_t *msg, uint32_t len)
 Emit a byte run on the SCI8 console.
static void ep_panic_halt (const uint8_t *msg, uint32_t len)
 Print the fail banner and trap (ra8_emulator halts on the BKPT).
static uint32_t ep_crc32 (const uint8_t *data, size_t len)
 CRC-32 (reflected, poly 0xEDB88320) over data.
static void ep_print_hex (uint32_t value)
 Print a 32-bit value as 8 upper-case hex digits.
static void ep_print_uint (uint32_t value)
 Print a small unsigned integer in decimal.
static void ep_setup_or_halt (void)
 Bring up clocks/MSTP/time + the SCI8 console; halt on failure.
static uint16_t ep_parse_or_halt (uint32_t *out_crc)
 Open the baked EPUB, verify the spine, load + CRC chapter 0.
void main (void)
 App entry: parse the baked EPUB on silicon, print the banner.

Variables

static epub_book_t s_book
 Opened book (large – file-scope, not on the stack).
static uint8_t s_chapter [k_ep_chap_cap]
 Chapter-0 XHTML scratch (file-scope to keep the stack small).
static const uint8_t k_msg_boot [] = "epub-parse-hil: boot\r\n"
static const uint8_t k_msg_fail [] = "epub-parse-hil: FAIL init\r\n"
static const uint8_t k_msg_open [] = "epub: FAIL open\r\n"
static const uint8_t k_msg_chap [] = "epub: FAIL chapters\r\n"
static const uint8_t k_msg_load [] = "epub: FAIL load\r\n"
static const uint8_t k_msg_meta [] = "epub: FAIL meta\r\n"
static const uint8_t k_msg_pre [] = "epub: chapters="
static const uint8_t k_msg_crc [] = " ch0_crc="
static const uint8_t k_msg_ok [] = " PASS\r\n"

Detailed Description

On-silicon HIL: epub parse layer runs on the target (#139).

First firmware app to exercise epub (+ vendored miniz ZIP + bounded XML reader) on real silicon. The EPUB parse path is byte-twiddling C/C++ that has only ever run on the x86 host; this gate runs it on the EK-RA8D2.

It opens a baked known-good .epub (the seed_two_chapters fuzzer seed) in memory, exercising both miniz allocation paths through the zero-heap epub_miniz_alloc static arena – epub_open (ZIP central directory) and epub_load_chapter (DEFLATE decompressor) – then CRC-32s chapter 0's decompressed XHTML and reads the Dublin Core metadata. The console banner is:

epub: chapters=2 ch0_crc=<8hex> PASS

Deterministic (a fixed blob through a deterministic parser), so the banner is identical on host, ra8_emulator, and silicon. Any failure on any path prints a FAIL banner and halts on a BKPT before the PASS line, so the gate is exact.

[Ring 7 / App] {World: NS}

Since
0.1.0

Definition in file main.c.

Enumeration Type Documentation

◆ ep_consts_t

enum ep_consts_t : uint32_t

Console / parse knobs (no magic numbers).

Enumerator
k_ep_uart_baud 

Console baud.

k_ep_expect_chap 

Spine length of the baked seed.

k_ep_chap_cap 

Chapter XHTML scratch capacity.

k_ep_crc_init 

CRC-32 initial value.

k_ep_crc_poly 

CRC-32 reflected polynomial.

k_ep_crc_bits 

Bits folded per byte.

k_ep_hex_nibbles 

Hex digits in a 32-bit value.

k_ep_nibble_bits 

Bits per hex nibble.

k_ep_nibble_mask 

Low-nibble mask.

k_ep_dec_ten 

Hex digit / decimal split.

Definition at line 44 of file main.c.

Function Documentation

◆ ep_crc32()

uint32_t ep_crc32 ( const uint8_t * data,
size_t len )
static

CRC-32 (reflected, poly 0xEDB88320) over data.

Definition at line 89 of file main.c.

References k_ep_crc_bits, k_ep_crc_init, and k_ep_crc_poly.

Referenced by ep_parse_or_halt().

◆ ep_panic_halt()

void ep_panic_halt ( const uint8_t * msg,
uint32_t len )
static

Print the fail banner and trap (ra8_emulator halts on the BKPT).

Definition at line 79 of file main.c.

References ep_print().

◆ ep_parse_or_halt()

uint16_t ep_parse_or_halt ( uint32_t * out_crc)
static

Open the baked EPUB, verify the spine, load + CRC chapter 0.

Exercises both miniz allocation paths through the static arena: the open (central directory) and the chapter load (DEFLATE decompressor). Halts on any failure before returning.

Parameters
[out]out_crcReceives the CRC-32 of chapter 0's decompressed XHTML.
Returns
The chapter (spine) count.

Definition at line 162 of file main.c.

References ep_crc32(), ep_panic_halt(), epub_get_chapter_count(), epub_get_metadata(), epub_load_chapter(), epub_open(), k_ep_chap_cap, k_ep_expect_chap, k_epub_fixture, k_epub_fixture_len, k_msg_chap, k_msg_load, k_msg_meta, k_msg_open, k_ra8_ok, s_book, and s_chapter.

Referenced by main().

◆ ep_print()

void ep_print ( const uint8_t * msg,
uint32_t len )
static

Emit a byte run on the SCI8 console.

Definition at line 73 of file main.c.

References ra8_board_uart_console_write().

Referenced by ep_panic_halt(), ep_print_hex(), ep_print_uint(), and main().

◆ ep_print_hex()

void ep_print_hex ( uint32_t value)
static

Print a 32-bit value as 8 upper-case hex digits.

Definition at line 103 of file main.c.

References ep_print(), k_ep_dec_ten, k_ep_hex_nibbles, k_ep_nibble_bits, and k_ep_nibble_mask.

Referenced by main().

◆ ep_print_uint()

void ep_print_uint ( uint32_t value)
static

Print a small unsigned integer in decimal.

Definition at line 115 of file main.c.

References ep_print(), and k_ep_dec_ten.

Referenced by main().

◆ ep_setup_or_halt()

void ep_setup_or_halt ( void )
static

Bring up clocks/MSTP/time + the SCI8 console; halt on failure.

Definition at line 134 of file main.c.

References ep_panic_halt(), k_ep_uart_baud, k_msg_fail, k_ra8_clock_id_cpuclk0, k_ra8_ok, ra8_board_uart_console_init(), ra8_cgc_get_clock_hz(), ra8_cgc_init(), ra8_mstp_init(), and ra8_time_init().

Referenced by main().

◆ main()

void main ( void )

App entry: parse the baked EPUB on silicon, print the banner.

The application entry point Reset_Handler hands control to.

Precondition
Reset_Handler copied .data and zeroed .bss.
SystemInit set VTOR / FPU / priority grouping.
Postcondition
The chapters/ch0-CRC banner is emitted; the CPU then loops in WFI.
Since
0.1.0

Definition at line 194 of file main.c.

References ep_parse_or_halt(), ep_print(), ep_print_hex(), ep_print_uint(), ep_setup_or_halt(), k_msg_boot, k_msg_crc, k_msg_ok, k_msg_pre, and ra8_isr_globals_enable().

Variable Documentation

◆ k_msg_boot

const uint8_t k_msg_boot[] = "epub-parse-hil: boot\r\n"
static

Definition at line 62 of file main.c.

◆ k_msg_chap

const uint8_t k_msg_chap[] = "epub: FAIL chapters\r\n"
static

Definition at line 65 of file main.c.

Referenced by ep_parse_or_halt(), and est_open_or_halt().

◆ k_msg_crc

const uint8_t k_msg_crc[] = " ch0_crc="
static

Definition at line 69 of file main.c.

◆ k_msg_fail

◆ k_msg_load

const uint8_t k_msg_load[] = "epub: FAIL load\r\n"
static

Definition at line 66 of file main.c.

Referenced by ep_parse_or_halt().

◆ k_msg_meta

const uint8_t k_msg_meta[] = "epub: FAIL meta\r\n"
static

Definition at line 67 of file main.c.

Referenced by ep_parse_or_halt().

◆ k_msg_ok

const uint8_t k_msg_ok[] = " PASS\r\n"
static

Definition at line 70 of file main.c.

◆ k_msg_open

const uint8_t k_msg_open[] = "epub: FAIL open\r\n"
static

Definition at line 64 of file main.c.

Referenced by ec_render_cover_or_halt(), ep_parse_or_halt(), est_open_or_halt(), and main().

◆ k_msg_pre

const uint8_t k_msg_pre[] = "epub: chapters="
static

Definition at line 68 of file main.c.

◆ s_book

epub_book_t s_book
static

Opened book (large – file-scope, not on the stack).

Definition at line 58 of file main.c.

◆ s_chapter

uint8_t s_chapter[k_ep_chap_cap]
static

Chapter-0 XHTML scratch (file-scope to keep the stack small).

Definition at line 60 of file main.c.