40 (void)
memcpy(dst, src, len);
50typedef enum : uint32_t {
55typedef enum : uint8_t {
89 for (
size_t i = 0U; i < len; ++i) {
90 state ^= (uint32_t)data[i];
153 uint64_t end = (uint64_t)off + ((uint64_t)count * (uint64_t)elem);
154 return (off <= total) && (end <= (uint64_t)total);
221 const char expect[8] = {
'R',
'A',
'B',
'O',
'O',
'K',
'1',
'\0'};
223 for (uint8_t i = 0U; i < (uint8_t)
sizeof(expect); ++i) {
224 if (hdr->
magic[i] != expect[i]) {
255 if ((total <
sizeof(
book_header_t)) || ((
size_t)total > size)) {
259 const bool tables_ok =
280 const uint8_t* body = &((
const uint8_t*)base)[
sizeof(
book_header_t)];
291 uint32_t* out_chunk_bytes,
299 if ((
char)hdr[i] != cmagic[i]) {
303 uint32_t chunk_bytes = 0U;
306 uint32_t reserved = 0U;
311 if ((chunk_bytes == 0U) || (total == 0U) || (reserved != 0U)) {
314 const uint64_t want_count = (total + (uint64_t)chunk_bytes - 1U) / (uint64_t)chunk_bytes;
315 if ((uint64_t)count != want_count) {
318 *out_chunk_bytes = chunk_bytes;
398 const uint64_t entries = (uint64_t)out_view->
chunk_count + 1U;
403 if ((uint64_t)scratch_cap < out_view->total) {
413 for (uint32_t i = 1U; i <= out_view->
chunk_count; ++i) {
459 for (uint32_t i = 0U; i < view->
chunk_count; ++i) {
462 const uint64_t dst_off = (uint64_t)i * view->
chunk_bytes;
463 uint64_t expected = view->
total - dst_off;
467 size_t produced = 0U;
469 (
size_t)(next - off),
470 &scratch[(
size_t)dst_off],
476 if (produced != (
size_t)expected) {
522 const void** out_base,
539 *out_size = (size_t)view.
total;
548 const void** out_base,
static bool internal_image_pixfmts_known(const void *base, const book_header_t *hdr)
Whether every image descriptor declares a pixel format this build knows.
static ra8_err_t internal_container_view(const uint8_t *bytes, size_t file_len, size_t scratch_cap, book_container_view_t *out_view)
Parse + bounds-check a resident "RBKC" container against its file.
@ k_book_crc_bits_per_byte
Reflected updates per input byte.
static bool internal_magic_ok(const book_header_t *hdr)
Whether the header's magic field equals the "RABOOK1" tag.
book_crc_const_t
Constants for the reflected CRC-32/ISO-HDLC used in the trailer.
@ k_book_crc_init
CRC seed and final XOR mask.
@ k_book_crc_poly
Reflected polynomial.
static const char *const s_tag_book
Log tag for book validation diagnostics.
static ra8_err_t internal_open_body(const uint8_t *bytes, size_t file_len, book_inflate_fn inflate, void *scratch, size_t scratch_cap, const void **out_base, size_t *out_size)
Parse, inflate, validate, and publish an already-guarded open.
static uint32_t internal_crc32(const uint8_t *data, size_t len)
Compute CRC-32/ISO-HDLC over one resident byte span.
uint64_t priv_book_container_table_entry(const uint8_t *table, uint32_t idx)
Implementation of priv_book_container_table_entry() – unaligned-safe memcpy load.
uint32_t priv_book_crc32_extend(uint32_t crc, const uint8_t *data, size_t len)
Extend a reflected CRC-32 over one byte span.
static bool internal_table_fits(uint32_t off, uint32_t count, uint32_t elem, uint32_t total)
Implementation of internal_table_fits() – overflow-safe extent check.
static ra8_err_t internal_inflate_chunks(const book_container_view_t *view, book_inflate_fn inflate, uint8_t *scratch)
Inflate every chunk of a validated container view into scratch.
ra8_err_t book_validate(const void *base, size_t size)
Validate that a byte buffer is a well-formed, intact .rabook blob.
ra8_err_t priv_book_container_header_fields(const uint8_t *hdr, uint32_t *out_chunk_bytes, uint64_t *out_total, uint32_t *out_count)
Implementation of priv_book_container_header_fields() – memcpy field decode.
static void internal_copy_object(void *dst, const void *src, size_t len)
Copy an object representation through compatible byte-pointer types.
ra8_err_t book_open(const void *file, size_t file_len, book_inflate_fn inflate, void *scratch, size_t scratch_cap, const void **out_base, size_t *out_size)
Open a .rabook file: check the container, inflate, validate the blob.
Flat, execute-in-place container for a build-time "compiled" e-book.
static const book_image_t * book_images(const void *base)
Base of the image table.
@ k_book_format_version
Current .rabook layout revision.
@ k_book_flag_mask_known
Every bit this firmware understands; a set bit outside this mask fails book_validate().
@ k_book_pixfmt_gray8
8bpp grayscale, 1px/byte (lossless against any grey panel).
@ k_book_container_header_len
Fixed header bytes ahead of the chunk table.
@ k_book_container_entry_len
One chunk-table entry (uint64 LE offset).
@ k_book_container_magic_len
Length of the "RBKC" magic.
ra8_err_t(* book_inflate_fn)(const void *src, size_t src_len, void *dst, size_t dst_cap, size_t *out_len)
Caller-supplied DEFLATE inflater used by book_open().
book DOM-walk helpers shared across the library's translation units.
@ k_book_cont_off_total
uint64 LE: flat-blob inflated total.
@ k_book_cont_off_count
uint32 LE: number of chunks.
@ k_book_cont_off_chunk_bytes
uint32 LE: inflated bytes per chunk.
@ k_book_cont_off_reserved
uint32 LE: reserved, must be 0.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_NO_RECURSION
NASA Power-of-10 Rule 1: no direct or indirect self-call.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
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.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_range_check_failed
Value outside range enforced by RA8_CHECK_RANGE / RA8_CHECK_RANGE_TAG.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ 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.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
One name="value" attribute on an element.
One spine document (a renderable chapter) plus its TOC label.
Parsed, bounds-checked view of a resident "RBKC" container file.
uint64_t payload_len
Concatenated stream bytes in the file.
uint32_t chunk_bytes
Inflated bytes per chunk (last short).
const uint8_t * table
First chunk-table byte (unaligned).
uint64_t total
Flat-blob inflated total in bytes.
const uint8_t * payload
First byte of the chunk zlib streams.
uint32_t chunk_count
Number of chunks.
Descriptor for one transcoded image in the image pool.
A preserved CSS stylesheet and the chapter it scopes to.