ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_io_roundtrip.c
Go to the documentation of this file.
1
17
18#include "ra8_io_roundtrip.h"
19
20#include <string.h>
21
22#include "ra8_attributes.h"
23#include "ra8_check.h"
24
44
48
70{
71 for (uint32_t i = 0U; i < len; ++i) {
72 s_payload[i] = (uint8_t)((i * (uint32_t)k_ra8_io_roundtrip_seed_mul) +
74 }
75}
76
98{
99 for (uint32_t i = 0U; i < len; ++i) {
100 s_payload[i] = (uint8_t)((uint32_t)k_ra8_io_roundtrip_note_base +
101 (i % (uint32_t)k_ra8_io_roundtrip_note_mod));
102 }
103}
104
132internal_ra8_io_roundtrip_read_verify(const char* path, uint32_t len, const char* tag)
133{
134 ra8_fs_file_t* rf = nullptr;
135 RA8_RETURN_ON_ERROR(ra8_io_vfs_open(path, k_ra8_fs_mode_read, &rf), tag, "open r");
136 memset(s_readback, 0, sizeof(s_readback));
137 uint32_t got = 0U;
138 ra8_err_t err = ra8_fs_read(rf, s_readback, len, &got);
139 (void)ra8_fs_close(rf);
140 if (err != k_ra8_ok) {
141 return err;
142 }
143 if (got != len) {
145 }
146 if (memcmp(s_payload, s_readback, (size_t)len) != 0) {
148 }
149 return k_ra8_ok;
150}
151
180 const ra8_fs_backend_t* be,
181 ra8_fs_mount_t** out_mount)
182{
183 RA8_CHECK_NULL_PTR(bd, "ra8_io_roundtrip", "bd");
184 RA8_CHECK_NULL_PTR(p, "ra8_io_roundtrip", "params");
185 RA8_CHECK_NULL_PTR(be, "ra8_io_roundtrip", "backend");
186 RA8_CHECK_NULL_PTR(out_mount, "ra8_io_roundtrip", "out_mount");
187 return k_ra8_ok;
188}
189
218 ra8_fs_mount_t** out_mount)
219{
220 ra8_fs_format_opts_t opts = {};
221 opts.type = p->fat_type;
222 opts.label = p->volume_label;
223 RA8_RETURN_ON_ERROR(ra8_fs_format(be, &opts), p->log_tag, "format");
224 ra8_fs_mount_t* mnt = nullptr;
225 RA8_RETURN_ON_ERROR(ra8_fs_mount(be, &mnt), p->log_tag, "mount");
226 RA8_RETURN_ON_ERROR(ra8_io_vfs_mount(p->vfs_prefix, mnt), p->log_tag, "vfs mount");
227 *out_mount = mnt;
228 return k_ra8_ok;
229}
230
234 ra8_fs_mount_t** out_mount)
235{
237 "ra8_io_roundtrip",
238 "args");
239 *out_mount = nullptr;
240
242 return internal_ra8_io_roundtrip_format_mount(be, p, out_mount);
243}
244
246{
247 RA8_CHECK_NULL_PTR(mnt, "ra8_io_roundtrip", "mnt");
248 RA8_CHECK_NULL_PTR(p, "ra8_io_roundtrip", "params");
249 if (p->root_bytes > (uint32_t)k_ra8_io_roundtrip_max_payload) {
251 }
252
255 p->log_tag,
256 "write");
258}
259
285{
286 ra8_fs_file_t* wf = nullptr;
288 p->log_tag,
289 "open w");
291 RA8_RETURN_ON_ERROR(ra8_fs_close(wf), p->log_tag, "close w");
292 RA8_RETURN_ON_ERROR(werr, p->log_tag, "write");
293 return k_ra8_ok;
294}
295
static uint8_t s_payload[(size_t) k_demo_payload]
Original payload, compressed-blob staging, and the inflated copy.
Definition main.c:92
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_RETURN_ON_ERROR(err, tag, message)
Early return on error, propagating the code upward.
Definition ra8_check.h:184
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
@ k_ra8_err_checksum_mismatch
Stored / transmitted checksum does not match computed value.
Definition ra8_err.h:465
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
Definition ra8_err.h:167
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
void * memset(void *dst, int value, size_t n)
Fill memory with a constant byte value.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
ra8_err_t ra8_fs_format(const ra8_fs_backend_t *backend, const ra8_fs_format_opts_t *opts)
Format a block device as a fresh, empty FAT12/FAT16/FAT32/exFAT volume.
ra8_err_t ra8_fs_write(ra8_fs_file_t *file, const uint8_t *buf, uint32_t len)
Write len bytes; allocate new clusters from FAT free-space scan as needed.
ra8_err_t ra8_fs_mount(const ra8_fs_backend_t *backend, ra8_fs_mount_t **out_handle)
Mount a FAT volume from a block-device backend, auto-selecting the first partition.
ra8_err_t ra8_fs_read(ra8_fs_file_t *file, uint8_t *buf, uint32_t max_len, uint32_t *got_len)
Read up to max_len bytes; advance the cluster chain on cluster crossings.
ra8_err_t ra8_fs_close(ra8_fs_file_t *file)
Close an open file, stamping its final modification time.
ra8_err_t ra8_fs_write_file(ra8_fs_mount_t *handle, const char *path, const uint8_t *data, uint32_t len)
Create a whole file in one call (provisioning helper).
@ k_ra8_fs_mode_read
Read-only, must exist.
@ k_ra8_fs_mode_write
Truncate (or create) for writing.
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.
ra8_err_t ra8_io_roundtrip_root_file(ra8_fs_mount_t *mnt, const ra8_io_roundtrip_params_t *p)
Whole-file write at the volume root, VFS read-back, and byte-compare.
ra8_io_roundtrip_const_t
Fixed sizing + payload-pattern knobs (no magic numbers).
@ k_ra8_io_roundtrip_note_mod
Subdir note alphabet size.
@ k_ra8_io_roundtrip_seed_add
Root payload pattern additive bias.
@ k_ra8_io_roundtrip_max_payload
Largest payload (SD sector).
@ k_ra8_io_roundtrip_note_base
Subdir note alphabet base ('A').
@ k_ra8_io_roundtrip_seed_mul
Root payload pattern multiplier.
static uint8_t s_readback[k_ra8_io_roundtrip_max_payload]
ra8_err_t ra8_io_roundtrip_mount(ra8_io_blockdev_t *bd, const ra8_io_roundtrip_params_t *p, ra8_fs_backend_t *be, ra8_fs_mount_t **out_mount)
Bridge a bound block device to ra8_fs, format + mount FAT, VFS-register.
ra8_err_t ra8_io_roundtrip_subdir_file(const ra8_io_roundtrip_params_t *p)
mkdir a subdirectory via the VFS, then round-trip a nested file.
static void internal_ra8_io_roundtrip_fill_alpha(uint32_t len)
Fill s_payload with a deterministic rolling-alphabet pattern.
static ra8_err_t internal_ra8_io_roundtrip_read_verify(const char *path, uint32_t len, const char *tag)
Read a VFS file back into s_readback and compare against s_payload.
static void internal_ra8_io_roundtrip_fill_linear(uint32_t len)
Fill s_payload with a deterministic linear byte pattern.
ra8_err_t ra8_io_vfs_mount(const char *name, ra8_fs_mount_t *mount)
Register a mounted volume under a name.
Definition ra8_io_vfs.c:418
ra8_err_t ra8_io_vfs_open(const char *path, ra8_fs_mode_t mode, ra8_fs_file_t **out_file)
Open a file by "name:/path".
Definition ra8_io_vfs.c:547
ra8_err_t ra8_io_vfs_mkdir(const char *path)
Create a directory named "name:/path".
static ra8_err_t internal_ra8_io_roundtrip_mount_check(const ra8_io_blockdev_t *bd, const ra8_io_roundtrip_params_t *p, const ra8_fs_backend_t *be, ra8_fs_mount_t **out_mount)
Null-check the four ra8_io_roundtrip_mount arguments.
static ra8_err_t internal_ra8_io_roundtrip_write_subdir(const ra8_io_roundtrip_params_t *p)
Open the subdir file for writing, emit s_payload, and close it.
static ra8_err_t internal_ra8_io_roundtrip_format_mount(ra8_fs_backend_t *be, const ra8_io_roundtrip_params_t *p, ra8_fs_mount_t **out_mount)
Format be, mount it, and expose it through the VFS prefix.
Block-device interface that ra8_fs runs on top of.
Open-file state.
Tunables for ra8_fs_format() (the on-disk geometry of a fresh volume).
ra8_fs_type_t type
FAT variant to lay down (12/16/32).
const char * label
0..11 char volume label, or NULL.
Cached parse of one mounted FAT volume.
Caller-allocated block-device handle binding a backend to its context.
Per-demo knobs for the shared ra8_io round-trip.
const char * volume_label
11-char-max FAT volume label literal.
const char * root_path
Full VFS path of the root file for read-back.
const char * subdir_path
Full VFS path of the directory to create.
ra8_fs_type_t fat_type
FAT variant laid down by the format step.
const char * root_file
Root file name for the whole-file write.
const char * log_tag
ra8_log tag used on every step failure.
const char * subdir_file
Full VFS path of the nested file.
const char * vfs_prefix
VFS volume name, e.g.
uint32_t subdir_bytes
Deterministic payload length in the subdir.
uint32_t root_bytes
Deterministic payload length at the root.