|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Block-device dispatcher – forwards each public call into the bound backend vtable, and bridges any backend to an ra8_fs_backend_t. More...
#include "ra8_io_blockdev.h"#include <stdint.h>#include "ra8_attributes.h"#include "ra8_check.h"#include "ra8_err.h"#include "ra8_fs.h"#include "ra8_io_blockdev_backend.h"#include "ra8_log.h"Go to the source code of this file.
Functions | |
| static ra8_err_t | internal_validate (const ra8_io_blockdev_t *bd) |
| Reject a handle that is NULL or has no backend bound. | |
| ra8_err_t | ra8_io_blockdev_read (const ra8_io_blockdev_t *bd, uint32_t lba, uint32_t count, uint8_t *buf) |
| Read count logical blocks starting at lba into buf. | |
| ra8_err_t | ra8_io_blockdev_write (const ra8_io_blockdev_t *bd, uint32_t lba, uint32_t count, const uint8_t *buf) |
| Write count logical blocks from buf starting at lba. | |
| ra8_err_t | ra8_io_blockdev_erase (const ra8_io_blockdev_t *bd, uint32_t lba, uint32_t count) |
| Erase count blocks starting at lba to the medium's erase value. | |
| ra8_err_t | ra8_io_blockdev_get_caps (const ra8_io_blockdev_t *bd, ra8_io_blockdev_caps_t *out) |
| Report the bound backend's medium capabilities. | |
| ra8_err_t | ra8_io_blockdev_sync (const ra8_io_blockdev_t *bd) |
| Flush any backend write buffering to the medium. | |
| static ra8_err_t | internal_fs_read (void *ctx, uint64_t lba, uint32_t count, uint8_t *buf) |
| ra8_fs read trampoline – forward into the bound block device. | |
| static ra8_err_t | internal_fs_write (void *ctx, uint64_t lba, uint32_t count, const uint8_t *buf) |
| ra8_fs write trampoline – forward into the bound block device. | |
| static ra8_err_t | internal_fs_get_capacity (void *ctx, uint64_t *block_count, uint32_t *block_size) |
| ra8_fs capacity trampoline – map block-device caps to (count, size). | |
| static ra8_err_t | internal_fs_erase (void *ctx, uint64_t lba, uint64_t count) |
| ra8_fs erase trampoline – only advertise erase on zero-erase media. | |
| ra8_err_t | ra8_io_blockdev_as_fs_backend (const ra8_io_blockdev_t *bd, ra8_fs_backend_t *out) |
| Expose a bound block device as an ra8_fs_backend_t for ra8_fs. | |
Variables | |
| static const char *const | s_tag = "ra8_io_blockdev" |
| Module log tag. | |
Block-device dispatcher – forwards each public call into the bound backend vtable, and bridges any backend to an ra8_fs_backend_t.
Stateless dispatcher: it validates the handle, then forwards through the bound ra8_io_blockdev_iface. A NULL optional callback maps to a defined result (no erase => not-supported, no sync => success). The bridge installs static trampolines whose ctx is the ra8_io_blockdev_t itself.
Definition in file ra8_io_blockdev.c.
|
static |
ra8_fs erase trampoline – only advertise erase on zero-erase media.
ra8_fs's formatter requires an erased range to read back as 0x00. Flash media erase to 0xFF, so for those this returns k_ra8_err_not_supported and the formatter falls back to writing zeros explicitly.
| [in] | ctx | The ra8_io_blockdev_t handle (as a void cookie). |
| [in] | lba | First logical block address. |
| [in] | count | Number of blocks to erase. |
| k_ra8_ok | Range erased to zero. |
| k_ra8_err_null_ptr | ctx was NULL. |
| k_ra8_err_not_supported | Medium does not erase to zero. |
| k_ra8_err_* | Propagated from ra8_io_blockdev_erase. |
Definition at line 289 of file ra8_io_blockdev.c.
References ra8_io_blockdev_caps_t::erase_value, k_ra8_err_not_supported, k_ra8_err_out_of_range, k_ra8_io_erase_value_zero, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_io_blockdev_erase(), ra8_io_blockdev_get_caps(), and s_tag.
Referenced by ra8_io_blockdev_as_fs_backend().
|
static |
ra8_fs capacity trampoline – map block-device caps to (count, size).
Queries the block-device capabilities and reports block_count plus the 512-byte logical block size ra8_fs expects.
| [in] | ctx | The ra8_io_blockdev_t handle (as a void cookie). |
| [out] | block_count | Total blocks reported to ra8_fs. |
| [out] | block_size | Bytes per block reported to ra8_fs (always 512). |
| k_ra8_ok | Capacity reported. |
| k_ra8_err_null_ptr | Any pointer argument was NULL. |
| k_ra8_err_* | Propagated from ra8_io_blockdev_get_caps. |
Definition at line 246 of file ra8_io_blockdev.c.
References ra8_io_blockdev_caps_t::block_count, k_ra8_ok, ra8_io_blockdev_caps_t::logical_block_bytes, RA8_CHECK_NULL_PTR, ra8_io_blockdev_get_caps(), and s_tag.
Referenced by ra8_io_blockdev_as_fs_backend(), and ra8_sdmmc_spi_bind_fs_backend().
|
static |
ra8_fs read trampoline – forward into the bound block device.
Casts the ra8_fs cookie back to the block-device handle and dispatches the read.
| [in] | ctx | The ra8_io_blockdev_t handle (as a void cookie). |
| [in] | lba | First logical block address. |
| [in] | count | Number of blocks to read. |
| [out] | buf | Destination buffer. |
| k_ra8_ok | Blocks read. |
| k_ra8_err_null_ptr | ctx or buf was NULL. |
| k_ra8_err_* | Propagated from ra8_io_blockdev_read. |
Definition at line 169 of file ra8_io_blockdev.c.
References k_ra8_err_out_of_range, RA8_CHECK_NULL_PTR, ra8_io_blockdev_read(), and s_tag.
Referenced by ra8_io_blockdev_as_fs_backend().
|
static |
ra8_fs write trampoline – forward into the bound block device.
Casts the ra8_fs cookie back to the block-device handle and dispatches the write.
| [in] | ctx | The ra8_io_blockdev_t handle (as a void cookie). |
| [in] | lba | First logical block address. |
| [in] | count | Number of blocks to write. |
| [in] | buf | Source buffer. |
| k_ra8_ok | Blocks written. |
| k_ra8_err_null_ptr | ctx or buf was NULL. |
| k_ra8_err_* | Propagated from ra8_io_blockdev_write. |
Definition at line 210 of file ra8_io_blockdev.c.
References k_ra8_err_out_of_range, RA8_CHECK_NULL_PTR, ra8_io_blockdev_write(), and s_tag.
Referenced by ra8_io_blockdev_as_fs_backend().
|
static |
Reject a handle that is NULL or has no backend bound.
Run on every dispatch path. Kept tiny so each public entry point stays well under the NASA Power-of-10 Rule 4 sixty-line cap.
| [in] | bd | Candidate handle. |
| k_ra8_ok | bd is non-NULL with a bound backend. |
| k_ra8_err_null_ptr | bd was NULL. |
| k_ra8_err_not_initialized | bd->iface was NULL (never bound). |
Definition at line 62 of file ra8_io_blockdev.c.
References ra8_io_blockdev_t::iface, k_ra8_err_not_initialized, k_ra8_err_null_ptr, and k_ra8_ok.
Referenced by mdl_storage_vfs_init(), ra8_io_blockdev_as_fs_backend(), ra8_io_blockdev_erase(), ra8_io_blockdev_get_caps(), ra8_io_blockdev_read(), ra8_io_blockdev_sync(), and ra8_io_blockdev_write().
|
nodiscard |
Expose a bound block device as an ra8_fs_backend_t for ra8_fs.
Fills out with trampolines that forward ra8_fs's read_block / write_block / get_capacity / erase_blocks calls into this fabric, with out->ctx pointing at bd. The erase trampoline advertises itself to the formatter only when the medium erases to zero (ra8_fs requires erased ranges to read back as 0x00); on all-ones flash it returns k_ra8_err_not_supported so the formatter falls back to writing zeros. After this call any existing ra8_fs API (ra8_fs_mount, ra8_fs_format, ...) works on the bound medium.
| [in] | bd | Bound block-device handle (must out-live the filesystem use). |
| [out] | out | ra8_fs_backend_t to populate. |
| k_ra8_ok | *out wired to bd. |
| k_ra8_err_null_ptr | bd or out was NULL. |
| k_ra8_err_not_initialized | No backend is bound to bd. |
Definition at line 307 of file ra8_io_blockdev.c.
References ra8_fs_backend_t::ctx, ra8_fs_backend_t::erase_blocks, ra8_fs_backend_t::get_capacity, internal_fs_erase(), internal_fs_get_capacity(), internal_fs_read(), internal_fs_write(), internal_validate(), k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_fs_backend_t::read_block, s_tag, and ra8_fs_backend_t::write_block.
Referenced by fileops_mount_volume(), internal_demo_mount(), internal_demo_mount(), internal_demo_probe_fat(), internal_demo_probe_foreign(), internal_swap_run_one(), ra8_io_roundtrip_mount(), sdhi_demo_mount_via_io(), selftest_mount_volume(), selftest_mount_volume(), selftest_mount_volume(), selftest_mount_volume(), and selftest_mount_volume().
|
nodiscard |
Erase count blocks starting at lba to the medium's erase value.
After a successful erase the range reads back as caps.erase_value (zero for RAM media, all-ones for NOR/MRAM). Backends whose medium has no erase concept may omit the operation, in which case this returns k_ra8_err_not_supported.
| [in] | bd | Bound block-device handle. |
| [in] | lba | First logical block address to erase. |
| [in] | count | Number of consecutive blocks to erase. |
| k_ra8_ok | Range erased. |
| k_ra8_err_null_ptr | bd was NULL. |
| k_ra8_err_not_initialized | No backend is bound to bd. |
| k_ra8_err_not_supported | The backend has no erase primitive. |
| k_ra8_err_out_of_range | lba + count exceeds the device capacity. |
Definition at line 102 of file ra8_io_blockdev.c.
References ra8_io_blockdev_t::ctx, ra8_io_blockdev_iface::erase, ra8_io_blockdev_t::iface, internal_validate(), k_ra8_err_not_supported, and k_ra8_ok.
Referenced by demo_checkpoint(), internal_alloc_blank(), internal_cache_erase(), internal_demo_roundtrip(), internal_fs_erase(), and internal_reclaim_stale().
|
nodiscard |
Report the bound backend's medium capabilities.
| [in] | bd | Bound block-device handle. |
| [out] | out | Capabilities snapshot. |
| k_ra8_ok | *out populated. |
| k_ra8_err_null_ptr | bd or out was NULL. |
| k_ra8_err_not_initialized | No backend is bound to bd. |
Definition at line 114 of file ra8_io_blockdev.c.
References ra8_io_blockdev_t::ctx, ra8_io_blockdev_iface::get_caps, ra8_io_blockdev_t::iface, internal_validate(), k_ra8_ok, RA8_CHECK_NULL_PTR, and s_tag.
Referenced by internal_cache_get_caps(), internal_fs_erase(), internal_fs_get_capacity(), and ra8_ftl_init().
|
nodiscard |
Read count logical blocks starting at lba into buf.
Forwards to the bound backend's read primitive. buf must hold at least count * k_ra8_io_block_size_bytes bytes. Reading past the device capacity is rejected by the backend, not silently truncated.
| [in] | bd | Bound block-device handle. |
| [in] | lba | First logical block address to read. |
| [in] | count | Number of consecutive blocks to read. |
| [out] | buf | Destination buffer (>= count * 512 bytes). |
| k_ra8_ok | Blocks read into buf. |
| k_ra8_err_null_ptr | bd or buf was NULL. |
| k_ra8_err_not_initialized | No backend is bound to bd. |
| k_ra8_err_out_of_range | lba + count exceeds the device capacity. |
| k_ra8_err_invalid_arg | Backend rejected the request. |
Definition at line 79 of file ra8_io_blockdev.c.
References ra8_io_blockdev_t::ctx, ra8_io_blockdev_t::iface, internal_validate(), k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_io_blockdev_iface::read, and s_tag.
Referenced by demo_reopen_naive(), demo_restore(), demo_write_verify(), fileops_probe_layout(), internal_bd_read_middle(), internal_bd_read_sector(), internal_cache_read_block(), internal_demo_roundtrip(), internal_fs_read(), and internal_read_one().
|
nodiscard |
Flush any backend write buffering to the medium.
For buffered backends (e.g. a NOR write-coalescing shim) this commits pending data. Backends with no buffering treat it as a successful no-op.
| [in] | bd | Bound block-device handle. |
| k_ra8_ok | Pending writes committed (or none pending). |
| k_ra8_err_null_ptr | bd was NULL. |
| k_ra8_err_not_initialized | No backend is bound to bd. |
Definition at line 125 of file ra8_io_blockdev.c.
References ra8_io_blockdev_t::ctx, ra8_io_blockdev_t::iface, internal_validate(), k_ra8_ok, and ra8_io_blockdev_iface::sync.
Referenced by internal_cache_sync(), and internal_dev_sync().
|
nodiscard |
Write count logical blocks from buf starting at lba.
Forwards to the bound backend's write primitive. On media that require an erase before programming the backend performs the necessary read-modify-write or erase internally; callers that want erase-aligned efficiency should use ra8_io_blockdev_erase plus aligned writes.
| [in] | bd | Bound block-device handle. |
| [in] | lba | First logical block address to write. |
| [in] | count | Number of consecutive blocks to write. |
| [in] | buf | Source buffer (>= count * 512 bytes). |
| k_ra8_ok | Blocks written. |
| k_ra8_err_null_ptr | bd or buf was NULL. |
| k_ra8_err_not_initialized | No backend is bound to bd. |
| k_ra8_err_out_of_range | lba + count exceeds the device capacity. |
| k_ra8_err_not_supported | The device is read-only. |
Definition at line 91 of file ra8_io_blockdev.c.
References ra8_io_blockdev_t::ctx, ra8_io_blockdev_t::iface, internal_validate(), k_ra8_ok, RA8_CHECK_NULL_PTR, s_tag, and ra8_io_blockdev_iface::write.
Referenced by demo_checkpoint(), demo_write_verify(), internal_bdsink_commit_sector(), internal_cache_write_block(), internal_demo_probe_foreign(), internal_demo_roundtrip(), internal_fs_write(), and internal_write_one().
|
static |
Module log tag.
Definition at line 31 of file ra8_io_blockdev.c.