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

Oversized-page tile self-check for ereader_comic (#344). More...

#include "cm_tiled_check.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "comic.h"
#include "comic_large_fixture.h"
#include "comic_tiles.h"
#include "jof.h"
#include "jof_produce.h"
#include "ra8_err.h"
#include "ra8_tile_cache.h"
Include dependency graph for cm_tiled_check.c:

Go to the source code of this file.

Data Structures

struct  cm_ct_blob_t
 Resident-buffer backing for the comic reader's seek+read seam. More...

Enumerations

enum  cm_tiled_cfg_t : uint32_t {
  k_ct_tile = 256U ,
  k_ct_bpp_gray = 1U ,
  k_ct_cell_bytes = k_ct_tile * k_ct_tile * k_ct_bpp_gray ,
  k_ct_cells = 8U ,
  k_ct_buckets = 16U ,
  k_ct_budget = 2U * 1024U * 1024U ,
  k_ct_pagebuf = 64U * 1024U ,
  k_ct_work = 2U * 1024U * 1024U ,
  k_ct_atlas = 2U * 1024U * 1024U ,
  k_ct_scratch = 96U * 1024U ,
  k_ct_page_cap = 4U ,
  k_ct_name_cap = 64U ,
  k_ct_fnv_offset = 2166136261U ,
  k_ct_fnv_prime = 16777619U
}
 Tile geometry, cache budget, and hashing constants for the self-check. More...

Functions

static size_t cm_ct_read (void *ctx, uint64_t off, void *buf, size_t len)
 comic_read_fn over the resident CBZ blob (bounds-clamped).
static uint32_t cm_ct_fnv (uint32_t h, const uint8_t *p, size_t n)
 FNV-1a-32 folding n bytes of p into the running hash h.
static bool cm_ct_open (size_t *out_got)
 Open the baked oversized CBZ and read page 0's encoded bytes.
static bool cm_ct_hash_tiles (const jof_info_t *info, uint32_t *out_crc)
 Decode every tile of the bound atlas, FNV-hashing the pixels.
static ra8_tile_cache_cfg_t cm_ct_cache_cfg (void)
 Tile-cache storage config over the file-static cache buffers.
cm_tiled_result_t cm_comic_tiled_selfcheck (void)
 Open the baked oversized page through the tile path and digest it.

Variables

static uint8_t s_ct_pagebuf [k_ct_pagebuf]
 SDRAM: encoded page scratch (the tile producer's input).
static uint8_t s_ct_work [k_ct_work]
 SDRAM: producer streaming work arena.
static uint8_t s_ct_atlas [k_ct_atlas]
 SDRAM: produced JOF atlas backing store.
static uint8_t s_ct_cells [(size_t) k_ct_cells *(size_t) k_ct_cell_bytes]
 SDRAM: tile-cache cell storage.
static uint8_t s_ct_scratch [k_ct_scratch]
 SDRAM: stored-tile staging for deflate tiles.
static comic_page_t s_ct_pages [k_ct_page_cap]
 SDRAM: comic page-index storage.
static char s_ct_names [k_ct_name_cap]
 SDRAM: comic name arena.
static comic_t s_ct_comic
 SDRAM: the open comic reader.
static comic_tile_reader_t s_ct_reader
 SDRAM: the comic tile reader.
static ra8_tile_key_t s_ct_keys [k_ct_cells]
 Tile-cache key storage.
static ra8_tile_dims_t s_ct_dims [k_ct_cells]
 Tile-cache dimension descriptors.
static ra8_keycache_cell_t s_ct_meta [k_ct_cells]
 Tile-cache link metadata.
static int32_t s_ct_buckets [k_ct_buckets]
 Tile-cache hash buckets.
static cm_ct_blob_t s_ct_blob
 Blob backing bound into the read seam.

Detailed Description

Oversized-page tile self-check for ereader_comic (#344).

Tag
[Ring 7 / App] {World: NS}

Opens the baked oversized single-page CBZ (k_comic_large_cbz), confirms its decoded footprint overruns the whole-decode budget, transcodes the page to a JOF atlas through comic_tiles_import, and decodes every tile of the atlas in bounded RAM, FNV-hashing the decoded pixels. The result feeds a deterministic boot banner field that pins the fix on device (ra8_emulator / silicon). Every buffer is file-static SDRAM – no heap (NASA P10 Rule 3) – and the panel framebuffer is never touched, so the reader's page-1 render is undisturbed.

Since
0.1.0

Definition in file cm_tiled_check.c.

Enumeration Type Documentation

◆ cm_tiled_cfg_t

enum cm_tiled_cfg_t : uint32_t

Tile geometry, cache budget, and hashing constants for the self-check.

Grayscale 256x256 tiles (1 bpp -> 64 KiB cells); an 8-cell cache is far smaller than the multi-MiB decoded page, so decode-on-demand paging is genuinely exercised. The budget matches the reader's whole-decode arena so the footprint decision mirrors the live path.

Since
0.1.0
Enumerator
k_ct_tile 

Square tile edge, pixels.

k_ct_bpp_gray 

Grayscale atlas bytes per pixel.

k_ct_cell_bytes 

Bytes per cache cell.

k_ct_cells 

Tile-cache cell budget.

k_ct_buckets 

Tile-cache hash buckets.

k_ct_budget 

Whole-decode budget (threshold).

k_ct_pagebuf 

Encoded page scratch, bytes.

k_ct_work 

Producer work arena, bytes.

k_ct_atlas 

Atlas memstore backing, bytes.

k_ct_scratch 

Stored-tile staging, bytes.

k_ct_page_cap 

Comic page-index capacity.

k_ct_name_cap 

Comic name-arena bytes.

k_ct_fnv_offset 

FNV-1a-32 offset basis.

k_ct_fnv_prime 

FNV-1a-32 prime.

Definition at line 46 of file cm_tiled_check.c.

Function Documentation

◆ cm_comic_tiled_selfcheck()

cm_tiled_result_t cm_comic_tiled_selfcheck ( void )

Open the baked oversized page through the tile path and digest it.

Opens k_comic_large_cbz with comic, confirms page 0's decoded footprint exceeds the whole-decode budget, transcodes it to a JOF atlas via comic_tiles_import, and decodes every tile through the owned tile cache, FNV-hashing the decoded pixels. All storage is file-static SDRAM (no heap); the panel framebuffer is never touched, so the reader's page-1 render is undisturbed.

Returns
cm_tiled_result_t The page geometry, tile count, digest, and status.
Return values
{.ok=true,...}The oversized page opened + tiled + decoded cleanly.
{.ok=false,...}The archive, footprint, import, or a tile decode failed.
Precondition
ra8_cgc_init / SDRAM bring-up have run (the SDRAM arenas are usable).
The baked k_comic_large_cbz fixture is linked in.
Postcondition
No panel framebuffer or ra8_gfx binding is modified.
On success ok is true and the digest is deterministic.
Note
Not thread-safe; single-threaded boot context.
Since
0.1.0

Definition at line 213 of file cm_tiled_check.c.

References cm_ct_cache_cfg(), cm_ct_hash_tiles(), cm_ct_open(), comic_close(), comic_tiles_footprint(), comic_tiles_import(), comic_tiles_info(), comic_tiles_init(), comic_tiles_over_budget(), cm_tiled_result_t::crc, cm_tiled_result_t::h, jof_info_t::height, k_comic_large_h, k_comic_large_w, k_ct_budget, k_ct_scratch, k_ct_tile, k_jof_codec_deflate, k_ra8_ok, cm_tiled_result_t::ok, s_ct_atlas, s_ct_comic, s_ct_pagebuf, s_ct_reader, s_ct_scratch, s_ct_work, jof_info_t::tile_count, cm_tiled_result_t::tiles, cm_tiled_result_t::w, and jof_info_t::width.

Referenced by main().

◆ cm_ct_cache_cfg()

ra8_tile_cache_cfg_t cm_ct_cache_cfg ( void )
static

Tile-cache storage config over the file-static cache buffers.

Definition at line 197 of file cm_tiled_check.c.

References k_ct_buckets, k_ct_cell_bytes, k_ct_cells, s_ct_buckets, s_ct_cells, s_ct_dims, s_ct_keys, and s_ct_meta.

Referenced by cm_comic_tiled_selfcheck().

◆ cm_ct_fnv()

uint32_t cm_ct_fnv ( uint32_t h,
const uint8_t * p,
size_t n )
static

FNV-1a-32 folding n bytes of p into the running hash h.

Definition at line 120 of file cm_tiled_check.c.

References k_ct_fnv_prime.

Referenced by cm_ct_hash_tiles().

◆ cm_ct_hash_tiles()

bool cm_ct_hash_tiles ( const jof_info_t * info,
uint32_t * out_crc )
static

Decode every tile of the bound atlas, FNV-hashing the pixels.

Parameters
[in]infoParsed atlas geometry of the imported page.
[out]out_crcReceives the digest over all tile payloads.
Returns
Whether every tile decoded cleanly.
Return values
trueAll tiles decoded; *out_crc holds the digest.
falseA tile fetch failed (digest not trustworthy).
Precondition
s_ct_reader has the page bound; info is its geometry.
out_crc is writable.
Postcondition
On true *out_crc is a deterministic digest over the decoded pixels.
Every fetched tile is released (no pin leaks).
Note
Not thread-safe.
Since
0.1.0

Definition at line 176 of file cm_tiled_check.c.

References jof_info_t::bpp, cm_ct_fnv(), comic_tiles_release(), comic_tiles_tile(), ra8_tile_t::height, k_ct_fnv_offset, k_ra8_ok, ra8_tile_t::pixels, s_ct_reader, jof_info_t::tile_cols, jof_info_t::tile_rows, and ra8_tile_t::width.

Referenced by cm_comic_tiled_selfcheck().

◆ cm_ct_open()

bool cm_ct_open ( size_t * out_got)
static

Open the baked oversized CBZ and read page 0's encoded bytes.

Parameters
[out]out_gotReceives the encoded page length.
Returns
Whether the archive opened and page 0 was extracted.
Return values
trues_ct_comic is open and s_ct_pagebuf holds the encoded page.
falseThe archive failed to open or extract.
Precondition
k_comic_large_cbz holds k_comic_large_cbz_len bytes.
out_got is writable.
Postcondition
On true *out_got > 0 and the comic stays open (caller closes it).
On false s_ct_comic is left unopened.
Note
Not thread-safe.
Since
0.1.0

Definition at line 141 of file cm_tiled_check.c.

References cm_ct_read(), comic_open(), comic_page_count(), comic_page_read(), k_comic_large_cbz, k_comic_large_cbz_len, k_ct_name_cap, k_ct_page_cap, k_ra8_ok, s_ct_blob, s_ct_comic, s_ct_names, s_ct_pagebuf, and s_ct_pages.

Referenced by cm_comic_tiled_selfcheck().

◆ cm_ct_read()

size_t cm_ct_read ( void * ctx,
uint64_t off,
void * buf,
size_t len )
static

comic_read_fn over the resident CBZ blob (bounds-clamped).

Definition at line 107 of file cm_tiled_check.c.

References cm_ct_blob_t::d, memcpy(), and cm_ct_blob_t::n.

Referenced by cm_ct_open().

Variable Documentation

◆ s_ct_atlas

uint8_t s_ct_atlas[k_ct_atlas]
static

SDRAM: produced JOF atlas backing store.

Definition at line 80 of file cm_tiled_check.c.

Referenced by cm_comic_tiled_selfcheck().

◆ s_ct_blob

cm_ct_blob_t s_ct_blob
static

Blob backing bound into the read seam.

Definition at line 103 of file cm_tiled_check.c.

Referenced by cm_ct_open().

◆ s_ct_buckets

int32_t s_ct_buckets[k_ct_buckets]
static

Tile-cache hash buckets.

Definition at line 101 of file cm_tiled_check.c.

Referenced by cm_ct_cache_cfg().

◆ s_ct_cells

uint8_t s_ct_cells[(size_t) k_ct_cells *(size_t) k_ct_cell_bytes]
static

SDRAM: tile-cache cell storage.

Definition at line 83 of file cm_tiled_check.c.

Referenced by cm_ct_cache_cfg().

◆ s_ct_comic

comic_t s_ct_comic
static

SDRAM: the open comic reader.

Definition at line 91 of file cm_tiled_check.c.

Referenced by cm_comic_tiled_selfcheck(), and cm_ct_open().

◆ s_ct_dims

ra8_tile_dims_t s_ct_dims[k_ct_cells]
static

Tile-cache dimension descriptors.

Definition at line 97 of file cm_tiled_check.c.

Referenced by cm_ct_cache_cfg().

◆ s_ct_keys

ra8_tile_key_t s_ct_keys[k_ct_cells]
static

Tile-cache key storage.

Definition at line 95 of file cm_tiled_check.c.

Referenced by cm_ct_cache_cfg().

◆ s_ct_meta

ra8_keycache_cell_t s_ct_meta[k_ct_cells]
static

Tile-cache link metadata.

Definition at line 99 of file cm_tiled_check.c.

Referenced by cm_ct_cache_cfg().

◆ s_ct_names

char s_ct_names[k_ct_name_cap]
static

SDRAM: comic name arena.

Definition at line 89 of file cm_tiled_check.c.

Referenced by cm_ct_open().

◆ s_ct_pagebuf

uint8_t s_ct_pagebuf[k_ct_pagebuf]
static

SDRAM: encoded page scratch (the tile producer's input).

Definition at line 76 of file cm_tiled_check.c.

Referenced by cm_comic_tiled_selfcheck(), and cm_ct_open().

◆ s_ct_pages

comic_page_t s_ct_pages[k_ct_page_cap]
static

SDRAM: comic page-index storage.

Definition at line 87 of file cm_tiled_check.c.

Referenced by cm_ct_open().

◆ s_ct_reader

comic_tile_reader_t s_ct_reader
static

SDRAM: the comic tile reader.

Definition at line 93 of file cm_tiled_check.c.

Referenced by cm_comic_tiled_selfcheck(), and cm_ct_hash_tiles().

◆ s_ct_scratch

uint8_t s_ct_scratch[k_ct_scratch]
static

SDRAM: stored-tile staging for deflate tiles.

Definition at line 85 of file cm_tiled_check.c.

Referenced by cm_comic_tiled_selfcheck().

◆ s_ct_work

uint8_t s_ct_work[k_ct_work]
static

SDRAM: producer streaming work arena.

Definition at line 78 of file cm_tiled_check.c.

Referenced by cm_comic_tiled_selfcheck().