|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Internal on-media format + cross-TU helpers for ra8_cache_store (#201). More...
Go to the source code of this file.
Data Structures | |
| struct | ra8_cs_super_t |
| On-flash superblock at logical sector 0 (also the checkpoint commit). More... | |
| struct | ra8_cs_entry_hdr_t |
| On-flash entry header at a run's first logical sector. More... | |
| struct | ra8_cs_dir_ent_t |
| One serialized directory entry in the checkpoint region (16 bytes). More... | |
Enumerations | |
| enum | ra8_cs_media_const_t : uint32_t { k_ra8_cs_super_magic = 0x52435331U , k_ra8_cs_entry_magic = 0x52435345U , k_ra8_cs_format_version = 1U , k_ra8_cs_dir_ent_bytes = 16U , k_ra8_cs_dir_per_sector = 32U , k_ra8_cs_crc32_poly = 0xEDB88320U , k_ra8_cs_crc32_seed = 0xFFFFFFFFU } |
| Magics + serialization sizing for the on-flash records. More... | |
| enum | ra8_cs_clean_t : uint32_t { k_ra8_cs_dirty = 0U , k_ra8_cs_clean = 1U } |
| Values of ra8_cs_super_t::clean (the shutdown marker). More... | |
Functions | |
| uint32_t | priv_cache_store_crc32 (const uint8_t *data, uint32_t len) |
| Fold a byte block into a CRC-32/ISO-HDLC value (seeded + finalised). | |
| ra8_err_t | priv_cache_store_sector_read (const ra8_cache_store_t *store, uint32_t sector, uint8_t *out512) |
| Read one LevelX logical sector into the store staging buffer region. | |
| ra8_err_t | priv_cache_store_sector_write (ra8_cache_store_t *store, uint32_t sector, const uint8_t *in512) |
| Write one LevelX logical sector from a one-sector source buffer. | |
| ra8_err_t | priv_cache_store_sector_release (ra8_cache_store_t *store, uint32_t sector) |
| Release a LevelX logical sector back to the free pool. | |
| int32_t | priv_cache_store_index_find (const ra8_cache_store_t *store, uint32_t key) |
Find the index slot holding key. | |
| int32_t | priv_cache_store_index_add (ra8_cache_store_t *store, uint32_t key, uint32_t start_sector, uint16_t sector_count, uint32_t byte_len, bool pinned) |
Claim a free index slot and populate it for key. | |
| ra8_err_t | priv_cache_store_super_write (ra8_cache_store_t *store, uint32_t clean) |
| Write the superblock (sector 0) with the given clean marker. | |
| ra8_err_t | priv_cache_store_dir_save (ra8_cache_store_t *store, uint32_t *out_entry_count) |
| Serialize the live index into the on-flash checkpoint directory. | |
Internal on-media format + cross-TU helpers for ra8_cache_store (#201).
Private to libs/ra8_cache_store/src/. Declares the three fixed-width on-flash records (superblock, entry header, directory entry) and the helpers shared between the runtime TU (ra8_cache_store.c) and the mount/recovery TU (ra8_cache_store_mount.c). Not a public interface – consumers use ra8_cache_store.h.
On-flash layout over the LevelX logical-sector space:
| Logical sector(s) | Contents |
|---|---|
| 0 | ra8_cs_super_t (superblock + clean marker) |
| [1, log_start) | directory checkpoint (ra8_cs_dir_ent_t run) |
| [log_start, logical) | append log: ra8_cs_entry_hdr_t + payload |
Records are written little-endian and consumed only by the same firmware build/platform that wrote them (host tests read back on the host; the target reads back on the target), so no byte-order translation is performed. Each record's trailing CRC-32 covers all preceding fields.
Definition in file ra8_cache_store_internal.h.
| enum ra8_cs_clean_t : uint32_t |
Values of ra8_cs_super_t::clean (the shutdown marker).
| Enumerator | |
|---|---|
| k_ra8_cs_dirty | Session open or crashed -> mount must replay the log. |
| k_ra8_cs_clean | Clean shutdown -> the checkpoint directory is valid. |
Definition at line 67 of file ra8_cache_store_internal.h.
| enum ra8_cs_media_const_t : uint32_t |
Magics + serialization sizing for the on-flash records.
| Enumerator | |
|---|---|
| k_ra8_cs_super_magic | Superblock tag 'R','C','S','1'. |
| k_ra8_cs_entry_magic | Entry-header tag 'R','C','S','E'. |
| k_ra8_cs_format_version | On-flash layout revision. |
| k_ra8_cs_dir_ent_bytes | Serialized ra8_cs_dir_ent_t size. |
| k_ra8_cs_dir_per_sector | Directory entries per 512-byte sector. |
| k_ra8_cs_crc32_poly | Reflected CRC-32/ISO-HDLC polynomial. |
| k_ra8_cs_crc32_seed | CRC-32 pre/post conditioning. |
Definition at line 52 of file ra8_cache_store_internal.h.
| uint32_t priv_cache_store_crc32 | ( | const uint8_t * | data, |
| uint32_t | len ) |
Fold a byte block into a CRC-32/ISO-HDLC value (seeded + finalised).
Standalone bitwise reflected CRC over one contiguous block: seeds and XOR-finalises with k_ra8_cs_crc32_seed internally, so the caller passes raw bytes and gets the final CRC. Used to seal every on-flash record.
| [in] | data | Bytes to fold (may be NULL only when len is 0). |
| [in] | len | Byte count. |
data. | uint32_t | CRC over the len bytes; the empty-input CRC when len==0. |
data covers len readable bytes, or len is 0. data is unmodified. Definition at line 55 of file ra8_cache_store_mount.c.
References k_ra8_cs_crc32_poly, k_ra8_cs_crc32_seed, k_ra8_cs_crc_bits, and RA8_PRIV.
Referenced by internal_hdr_read(), internal_super_is_clean(), internal_write_entry(), and priv_cache_store_super_write().
| ra8_err_t priv_cache_store_dir_save | ( | ra8_cache_store_t * | store, |
| uint32_t * | out_entry_count ) |
Serialize the live index into the on-flash checkpoint directory.
Packs every in-use slot as an ra8_cs_dir_ent_t across the directory region [1, log_start), then returns the count so the caller can put it in the superblock. Does not touch sector 0.
| [in,out] | store | Store whose index is serialized. |
| [out] | out_entry_count | Receives the number of entries written. |
| k_ra8_ok | Directory written. |
| k_ra8_err_hw_init_failed | LevelX write error. |
out_entry_count is writable. Definition at line 320 of file ra8_cache_store_mount.c.
References ra8_cache_store_t::checkpoint_dirs, internal_dir_pack_sector(), k_ra8_ok, priv_cache_store_sector_write(), RA8_CHECK_NULL_PTR, RA8_PRIV, RA8_RETURN_ON_ERROR, s_tag, and ra8_cache_store_t::staging.
Referenced by internal_checkpoint().
| int32_t priv_cache_store_index_add | ( | ra8_cache_store_t * | store, |
| uint32_t | key, | ||
| uint32_t | start_sector, | ||
| uint16_t | sector_count, | ||
| uint32_t | byte_len, | ||
| bool | pinned ) |
Claim a free index slot and populate it for key.
Claims the first free slot and records the entry's location, run length, and flags.
| [in,out] | store | Store whose index gains an entry. |
| [in] | key | Content key. |
| [in] | start_sector | Entry header logical sector. |
| [in] | sector_count | Run length (header + payload). |
| [in] | byte_len | Payload length in bytes. |
| [in] | pinned | Persist the pinned flag. |
| -1 | No free slot. |
key is not already present (caller checked). Definition at line 138 of file ra8_cache_store_mount.c.
References ra8_cache_store_entry_t::flags, ra8_cache_store_t::index, ra8_cache_store_t::index_cap, k_ra8_cache_store_flag_in_use, k_ra8_cache_store_flag_pinned, and RA8_PRIV.
Referenced by internal_dir_unpack_sector(), internal_scan_accept(), and ra8_cache_store_put().
| int32_t priv_cache_store_index_find | ( | const ra8_cache_store_t * | store, |
| uint32_t | key ) |
Find the index slot holding key.
Linear scan of the in-use index slots for a matching key.
| [in] | store | Store to search. |
| [in] | key | Content key. |
key is not present. | -1 | No in-use slot matches key. |
Definition at line 118 of file ra8_cache_store_mount.c.
References ra8_cache_store_entry_t::flags, ra8_cache_store_t::index, ra8_cache_store_t::index_cap, k_ra8_cache_store_flag_in_use, ra8_cache_store_entry_t::key, and RA8_PRIV.
Referenced by internal_put_check(), internal_scan_accept(), ra8_cache_store_evict(), ra8_cache_store_get(), and ra8_cache_store_pin().
| ra8_err_t priv_cache_store_sector_read | ( | const ra8_cache_store_t * | store, |
| uint32_t | sector, | ||
| uint8_t * | out512 ) |
Read one LevelX logical sector into the store staging buffer region.
Wraps lx_nor_flash_sector_read, mapping the LevelX status onto an ra8_err_t.
| [in] | store | Store whose LevelX flash is read. |
| [in] | sector | Logical sector index. |
| [out] | out512 | Destination of at least one sector. |
| k_ra8_ok | Sector read. |
| k_ra8_err_not_found | Sector is unmapped/released (LevelX miss). |
| k_ra8_err_hw_init_failed | LevelX read error. |
out512 covers one sector. out512 holds the sector bytes. out512 content is unspecified. Definition at line 77 of file ra8_cache_store_mount.c.
References ra8_cache_store_t::flash, k_ra8_err_hw_init_failed, k_ra8_err_not_found, k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_PRIV, and s_tag.
Referenced by internal_dir_load(), internal_hdr_read(), internal_read_at(), and internal_super_read().
| ra8_err_t priv_cache_store_sector_release | ( | ra8_cache_store_t * | store, |
| uint32_t | sector ) |
Release a LevelX logical sector back to the free pool.
Wraps lx_nor_flash_sector_release, returning the logical sector to the free pool.
| [in,out] | store | Store whose LevelX flash is released. |
| [in] | sector | Logical sector index. |
| k_ra8_ok | Sector released (or already free). |
| k_ra8_err_hw_init_failed | LevelX release error. |
sector is within the partition. sector misses until rewritten. Definition at line 107 of file ra8_cache_store_mount.c.
References ra8_cache_store_t::flash, k_ra8_err_hw_init_failed, k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_PRIV, and s_tag.
Referenced by internal_release_run().
| ra8_err_t priv_cache_store_sector_write | ( | ra8_cache_store_t * | store, |
| uint32_t | sector, | ||
| const uint8_t * | in512 ) |
Write one LevelX logical sector from a one-sector source buffer.
Wraps lx_nor_flash_sector_write, mapping a LevelX failure onto a hardware error.
| [in,out] | store | Store whose LevelX flash is written. |
| [in] | sector | Logical sector index. |
| [in] | in512 | Source of exactly one sector. |
| k_ra8_ok | Sector written. |
| k_ra8_err_hw_init_failed | LevelX write error (e.g. no free sectors). |
in512 covers one sector. in512. Definition at line 93 of file ra8_cache_store_mount.c.
References ra8_cache_store_t::flash, k_ra8_err_hw_init_failed, k_ra8_ok, RA8_CHECK_NULL_PTR, RA8_PRIV, and s_tag.
Referenced by internal_write_entry(), priv_cache_store_dir_save(), and priv_cache_store_super_write().
| ra8_err_t priv_cache_store_super_write | ( | ra8_cache_store_t * | store, |
| uint32_t | clean ) |
Write the superblock (sector 0) with the given clean marker.
Snapshots the store's live geometry (entry_count, live_sectors, next_seq, ...) plus clean into ra8_cs_super_t, seals it with a CRC, and writes sector 0 – the commit point of a checkpoint.
| [in,out] | store | Store to snapshot. |
| [in] | clean | ra8_cs_clean_t marker to stamp. |
| k_ra8_ok | Superblock written. |
| k_ra8_err_hw_init_failed | LevelX write error. |
clean. Definition at line 175 of file ra8_cache_store_mount.c.
References ra8_cs_super_t::crc, ra8_cache_store_t::data_capacity, ra8_cs_super_t::entry_count, ra8_cache_store_entry_t::flags, ra8_cache_store_t::index, ra8_cache_store_t::index_cap, k_ra8_cache_store_flag_in_use, k_ra8_cache_store_sector_bytes, k_ra8_cs_format_version, k_ra8_cs_super_magic, ra8_cache_store_t::live_sectors, ra8_cache_store_t::log_start, ra8_cache_store_t::logical_sectors, memcpy(), memset(), ra8_cache_store_t::next_seq, priv_cache_store_crc32(), priv_cache_store_sector_write(), RA8_CHECK_NULL_PTR, RA8_PRIV, s_tag, and ra8_cache_store_t::staging.
Referenced by internal_checkpoint(), internal_mark_dirty(), and internal_open_levelx().