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_check.h"
23
43
47
68static void ra8_io_roundtrip_fill_linear(uint32_t len)
69{
70 for (uint32_t i = 0U; i < len; ++i) {
71 s_payload[i] = (uint8_t)((i * (uint32_t)k_ra8_io_roundtrip_seed_mul) +
73 }
74}
75
96static void ra8_io_roundtrip_fill_alpha(uint32_t len)
97{
98 for (uint32_t i = 0U; i < len; ++i) {
99 s_payload[i] = (uint8_t)((uint32_t)k_ra8_io_roundtrip_note_base +
100 (i % (uint32_t)k_ra8_io_roundtrip_note_mod));
101 }
102}
103
130static ra8_err_t ra8_io_roundtrip_read_verify(const char* path, uint32_t len, const char* tag)
131{
132 ra8_fs_file_t* rf = nullptr;
133 RA8_RETURN_ON_ERROR(ra8_io_vfs_open(path, k_ra8_fs_mode_read, &rf), tag, "open r");
134 memset(s_readback, 0, sizeof(s_readback));
135 uint32_t got = 0U;
136 ra8_err_t err = ra8_fs_read(rf, s_readback, len, &got);
137 (void)ra8_fs_close(rf);
138 if (err != k_ra8_ok) {
139 return err;
140 }
141 if (got != len) {
143 }
144 if (memcmp(s_payload, s_readback, (size_t)len) != 0) {
146 }
147 return k_ra8_ok;
148}
149
153 ra8_fs_mount_t** out_mount)
154{
155 RA8_CHECK_NULL_PTR(bd, "ra8_io_roundtrip", "bd");
156 RA8_CHECK_NULL_PTR(p, "ra8_io_roundtrip", "params");
157 RA8_CHECK_NULL_PTR(be, "ra8_io_roundtrip", "backend");
158 RA8_CHECK_NULL_PTR(out_mount, "ra8_io_roundtrip", "out_mount");
159 *out_mount = nullptr;
160
162 ra8_fs_format_opts_t opts = {};
163 opts.type = p->fat_type;
164 opts.label = p->volume_label;
165 RA8_RETURN_ON_ERROR(ra8_fs_format(be, &opts), p->log_tag, "format");
166 ra8_fs_mount_t* mnt = nullptr;
167 RA8_RETURN_ON_ERROR(ra8_fs_mount(be, &mnt), p->log_tag, "mount");
168 RA8_RETURN_ON_ERROR(ra8_io_vfs_mount(p->vfs_prefix, mnt), p->log_tag, "vfs mount");
169 *out_mount = mnt;
170 return k_ra8_ok;
171}
172
174{
175 RA8_CHECK_NULL_PTR(mnt, "ra8_io_roundtrip", "mnt");
176 RA8_CHECK_NULL_PTR(p, "ra8_io_roundtrip", "params");
177 if (p->root_bytes > (uint32_t)k_ra8_io_roundtrip_max_payload) {
179 }
180
183 p->log_tag,
184 "write");
186}
187
189{
190 RA8_CHECK_NULL_PTR(p, "ra8_io_roundtrip", "params");
191 if (p->subdir_bytes > (uint32_t)k_ra8_io_roundtrip_max_payload) {
193 }
194
197
198 ra8_fs_file_t* wf = nullptr;
200 p->log_tag,
201 "open w");
203 RA8_RETURN_ON_ERROR(ra8_fs_close(wf), p->log_tag, "close w");
204 RA8_RETURN_ON_ERROR(werr, p->log_tag, "write");
205
207}
static uint8_t s_payload[(size_t) k_demo_payload]
Original payload, compressed-blob staging, and the inflated copy.
Definition main.c:92
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.
static ra8_err_t 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 ra8_io_roundtrip_fill_alpha(uint32_t len)
Fill s_payload with a deterministic rolling-alphabet pattern.
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]
static void ra8_io_roundtrip_fill_linear(uint32_t len)
Fill s_payload with a deterministic linear byte pattern.
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.
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".
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.