ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_vfs_compress.c
Go to the documentation of this file.
1
21
22#include "ra8_vfs_compress.h"
23
24#include <stdint.h>
25
26#include "ra8_attributes.h"
27#include "ra8_check.h"
28#include "ra8_compress.h"
29#include "ra8_err.h"
30#include "ra8_fs.h"
31#include "ra8_io_vfs.h"
32
34static const char* const s_tag = "ra8_vfs_compress";
35
67 const uint8_t* src,
68 const void* scratch,
69 const uint8_t* blob_buf,
70 const uint32_t* out_blob_len)
71{
72 RA8_CHECK_NULL_PTR(path, s_tag, "path must not be nullptr");
73 RA8_CHECK_NULL_PTR(src, s_tag, "src must not be nullptr");
74 RA8_CHECK_NULL_PTR(scratch, s_tag, "scratch must not be nullptr");
75 RA8_CHECK_NULL_PTR(blob_buf, s_tag, "blob_buf must not be nullptr");
76 RA8_CHECK_NULL_PTR(out_blob_len, s_tag, "out_blob_len must not be nullptr");
77 return k_ra8_ok;
78}
79
108internal_ra8_vfs_compress_store_blob(const char* path, const uint8_t* blob, uint32_t blob_len)
109{
110 ra8_fs_file_t* f = nullptr;
112 const ra8_err_t we = ra8_fs_write(f, blob, blob_len);
113 const ra8_err_t ce = ra8_fs_close(f);
114 if (we != k_ra8_ok) {
115 return we;
116 }
117 if (ce != k_ra8_ok) {
118 return ce;
119 }
120 return k_ra8_ok;
121}
122
124 const uint8_t* src,
125 uint32_t src_len,
126 void* scratch,
127 uint32_t scratch_len,
128 uint8_t* blob_buf,
129 uint32_t blob_cap,
130 uint32_t* out_blob_len)
131{
133 internal_ra8_vfs_compress_write_validate(path, src, scratch, blob_buf, out_blob_len),
134 s_tag,
135 "validate args");
136
137 uint32_t blob_len = 0;
139 ra8_compress(src, src_len, blob_buf, blob_cap, scratch, scratch_len, &blob_len),
140 s_tag,
141 "compress");
142
144 s_tag,
145 "store");
146 *out_blob_len = blob_len;
147 return k_ra8_ok;
148}
149
180 const uint8_t* blob_buf,
181 const uint8_t* out,
182 const uint32_t* out_len)
183{
184 RA8_CHECK_NULL_PTR(path, s_tag, "path must not be nullptr");
185 RA8_CHECK_NULL_PTR(blob_buf, s_tag, "blob_buf must not be nullptr");
186 RA8_CHECK_NULL_PTR(out, s_tag, "out must not be nullptr");
187 RA8_CHECK_NULL_PTR(out_len, s_tag, "out_len must not be nullptr");
188 return k_ra8_ok;
189}
190
224 uint8_t* blob_buf,
225 uint32_t blob_cap,
226 uint32_t* out_blob_len)
227{
228 ra8_fs_file_t* f = nullptr;
230 uint32_t blob_len = 0;
231 const ra8_err_t re = ra8_fs_read(f, blob_buf, blob_cap, &blob_len);
232 const ra8_err_t ce = ra8_fs_close(f);
233 if (re != k_ra8_ok) {
234 return re;
235 }
236 if (ce != k_ra8_ok) {
237 return ce;
238 }
239 if (blob_len >= blob_cap) {
241 }
242 *out_blob_len = blob_len;
243 return k_ra8_ok;
244}
245
247 uint8_t* blob_buf,
248 uint32_t blob_cap,
249 uint8_t* out,
250 uint32_t out_cap,
251 uint32_t* out_len)
252{
254 s_tag,
255 "validate args");
256
257 uint32_t blob_len = 0;
258 RA8_RETURN_ON_ERROR(internal_ra8_vfs_compress_load_blob(path, blob_buf, blob_cap, &blob_len),
259 s_tag,
260 "load");
261
262 RA8_RETURN_ON_ERROR(ra8_decompress(blob_buf, blob_len, out, out_cap, out_len), s_tag, "inflate");
263 return k_ra8_ok;
264}
static const char * s_tag
Logging / check tag.
Definition ra8_app.c:17
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
App-domain DEFLATE compress / decompress (zero-heap, firmware-safe).
ra8_err_t ra8_decompress(const uint8_t *src, uint32_t src_len, uint8_t *out, uint32_t out_cap, uint32_t *out_len)
Raw-DEFLATE decompress src into out.
ra8_err_t ra8_compress(const uint8_t *src, uint32_t src_len, uint8_t *out, uint32_t out_cap, void *scratch, uint32_t scratch_len, uint32_t *out_len)
Raw-DEFLATE compress src into out.
Error Code Definitions for ra8-firmware.
@ 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
Minimal FAT12/FAT16/FAT32 filesystem adapter (read + write).
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_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.
@ k_ra8_fs_mode_read
Read-only, must exist.
@ k_ra8_fs_mode_write
Truncate (or create) for writing.
ra8_io virtual filesystem – mount many volumes, address them by name.
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
static ra8_err_t internal_ra8_vfs_compress_store_blob(const char *path, const uint8_t *blob, uint32_t blob_len)
Open path for write, stream the compressed blob, and close.
static ra8_err_t internal_ra8_vfs_compress_write_validate(const char *path, const uint8_t *src, const void *scratch, const uint8_t *blob_buf, const uint32_t *out_blob_len)
Validate the five caller pointers handed to ra8_vfs_compress_write.
ra8_err_t ra8_vfs_compress_read(const char *path, uint8_t *blob_buf, uint32_t blob_cap, uint8_t *out, uint32_t out_cap, uint32_t *out_len)
Read a whole compressed file through the VFS and decompress it.
static ra8_err_t internal_ra8_vfs_compress_read_validate(const char *path, const uint8_t *blob_buf, const uint8_t *out, const uint32_t *out_len)
Validate the four caller pointers handed to ra8_vfs_compress_read.
static ra8_err_t internal_ra8_vfs_compress_load_blob(const char *path, uint8_t *blob_buf, uint32_t blob_cap, uint32_t *out_blob_len)
Open path for read, pull the whole blob into blob_buf, and close.
ra8_err_t ra8_vfs_compress_write(const char *path, const uint8_t *src, uint32_t src_len, void *scratch, uint32_t scratch_len, uint8_t *blob_buf, uint32_t blob_cap, uint32_t *out_blob_len)
Compress a payload and store it as a whole file through the VFS.
Transparent VFS-level whole-file compression (compress-on-write,decompress-on-read) over the ra8_io f...
Open-file state.