ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_ftl.h
Go to the documentation of this file.
1
89
90#pragma once
91
92#ifdef __cplusplus
93extern "C" {
94#endif
95
96#include <stdint.h>
97
98#include "ra8_err.h"
99#include "ra8_io_blockdev.h"
100
101/* =============================================================================
102 * Constants
103 * =============================================================================
104 */
105
118typedef enum : uint16_t {
123
140
141/* =============================================================================
142 * Per-physical-block metadata
143 * =============================================================================
144 */
145
162typedef struct {
163 uint32_t erase_count;
164 uint8_t state;
166
167/* =============================================================================
168 * Handle
169 * =============================================================================
170 */
171
190typedef struct {
192 uint16_t* map;
194 uint8_t* scratch;
195 uint32_t logical_blocks;
197 uint8_t erase_value;
198} ra8_ftl_t;
199
200/* =============================================================================
201 * API
202 * =============================================================================
203 */
204
250[[nodiscard]] ra8_err_t ra8_ftl_init(ra8_ftl_t* bd,
251 const ra8_io_blockdev_t* raw,
252 uint16_t* map,
253 uint32_t logical_blocks,
254 ra8_ftl_pblock_t* pblocks,
255 uint32_t physical_blocks,
256 uint8_t* scratch);
257
287
315[[nodiscard]] ra8_err_t
316ra8_ftl_wear_stats(const ra8_ftl_t* ftl, uint32_t* max_out, uint32_t* min_out);
317
352[[nodiscard]] ra8_err_t ra8_ftl_phys_of(const ra8_ftl_t* ftl, uint32_t lbn, uint16_t* phys_out);
353
385[[nodiscard]] ra8_err_t ra8_ftl_checkpoint_size(const ra8_ftl_t* ftl, uint32_t* size_out);
386
430[[nodiscard]] ra8_err_t
431ra8_ftl_checkpoint_save(const ra8_ftl_t* ftl, uint8_t* buf, uint32_t buf_len);
432
480[[nodiscard]] ra8_err_t
481ra8_ftl_checkpoint_load(ra8_ftl_t* ftl, const uint8_t* buf, uint32_t buf_len);
482
483#ifdef __cplusplus
484}
485#endif
Error Code Definitions for ra8-firmware.
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
ra8_ftl_const_t
FTL sizing and sentinel constants.
Definition ra8_ftl.h:118
@ k_ra8_ftl_unmapped
map[] sentinel: logical block unwritten.
Definition ra8_ftl.h:119
@ k_ra8_ftl_max_pblocks
Max physical blocks an FTL may wrap.
Definition ra8_ftl.h:120
@ k_ra8_ftl_min_spare
Minimum spare blocks (P - L >= 1).
Definition ra8_ftl.h:121
ra8_err_t ra8_ftl_checkpoint_load(ra8_ftl_t *ftl, const uint8_t *buf, uint32_t buf_len)
Restore FTL mapping state from a checkpoint produced by save.
ra8_err_t ra8_ftl_checkpoint_save(const ra8_ftl_t *ftl, uint8_t *buf, uint32_t buf_len)
Serialise the FTL's mapping state into a caller buffer.
ra8_ftl_pstate_t
Lifecycle state of one physical erase block.
Definition ra8_ftl.h:135
@ k_ra8_ftl_pstate_free
Blank (reads as erase value); allocatable.
Definition ra8_ftl.h:136
@ k_ra8_ftl_pstate_live
Holds current data for one logical block.
Definition ra8_ftl.h:137
@ k_ra8_ftl_pstate_stale
Superseded; reclaimable by erase to FREE.
Definition ra8_ftl.h:138
ra8_err_t ra8_ftl_wear_stats(const ra8_ftl_t *ftl, uint32_t *max_out, uint32_t *min_out)
Report the highest per-physical-block erase count seen so far.
Definition ra8_ftl.c:769
ra8_err_t ra8_ftl_init(ra8_ftl_t *bd, const ra8_io_blockdev_t *raw, uint16_t *map, uint32_t logical_blocks, ra8_ftl_pblock_t *pblocks, uint32_t physical_blocks, uint8_t *scratch)
Initialise an FTL over an erase-before-write block device.
Definition ra8_ftl.c:724
ra8_err_t ra8_ftl_checkpoint_size(const ra8_ftl_t *ftl, uint32_t *size_out)
Report the buffer size a checkpoint of this FTL requires, in bytes.
ra8_err_t ra8_ftl_as_blockdev(ra8_ftl_t *ftl, ra8_io_blockdev_t *out)
Expose an initialised FTL as a free-overwrite ra8_io_blockdev_t.
Definition ra8_ftl.c:757
ra8_err_t ra8_ftl_phys_of(const ra8_ftl_t *ftl, uint32_t lbn, uint16_t *phys_out)
Report the physical block currently backing a logical block.
Definition ra8_ftl.c:793
ra8_io block-device fabric – one LBA vtable across every storage medium.
Caller-owned metadata for one physical erase block.
Definition ra8_ftl.h:162
uint32_t erase_count
Cumulative erases of this block (wear metric).
Definition ra8_ftl.h:163
uint8_t state
ra8_ftl_pstate_t lifecycle state (private).
Definition ra8_ftl.h:164
Caller-allocated FTL handle binding the wrapper to the raw device.
Definition ra8_ftl.h:190
ra8_ftl_pblock_t * pblocks
Per-physical metadata (private).
Definition ra8_ftl.h:193
uint32_t physical_blocks
Blocks in the raw dev (private).
Definition ra8_ftl.h:196
uint8_t * scratch
512-byte copy scratch (private).
Definition ra8_ftl.h:194
uint16_t * map
logical->physical map (private).
Definition ra8_ftl.h:192
uint8_t erase_value
Raw medium erase byte (private).
Definition ra8_ftl.h:197
const ra8_io_blockdev_t * raw
Underlying erase-before-write dev.
Definition ra8_ftl.h:191
uint32_t logical_blocks
Blocks presented to FAT (private).
Definition ra8_ftl.h:195
Caller-allocated block-device handle binding a backend to its context.