|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Stream deterministic CBT and gzip-wrapped CBT containers. More...
#include <stdio.h>#include <string.h>#include "mdl_export.h"#include "mdl_export_internal.h"#include "miniz.h"#include "ra8_attributes.h"Go to the source code of this file.
Data Structures | |
| struct | internal_tar_sink_t |
| Direct tar sink adapter. More... | |
| struct | internal_gzip_sink_t |
| Online gzip state receiving the uncompressed tar stream. More... | |
Enumerations | |
| enum | mdl_tar_layout_t : uint16_t { k_tar_block = 512U , k_off_name = 0U , k_len_name = 100U , k_off_mode = 100U , k_off_uid = 108U , k_off_gid = 116U , k_len_id = 8U , k_off_size = 124U , k_len_size = 12U , k_off_mtime = 136U , k_len_mtime = 12U , k_off_chksum = 148U , k_len_chksum = 8U , k_off_type = 156U , k_off_magic = 257U , k_len_magic = 6U , k_off_version = 263U } |
| ustar header field offsets and widths. More... | |
| enum | mdl_tar_mode_t : uint16_t { k_file_mode = 0644U } |
| Fixed regular-file mode in deterministic tar headers. More... | |
| enum | mdl_tar_size_t : uint64_t { k_tar_size_max = 077777777777ULL } |
| Largest payload representable by the fixed eleven-digit tar field. More... | |
| enum | mdl_gzip_layout_t : uint16_t { k_gzip_header_bytes = 10U , k_gzip_u32_bytes = 4U , k_byte_bits = 8U , k_byte_mask = 255U } |
| Gzip framing and serialization constants. More... | |
| enum | mdl_gzip_header_t : uint8_t { k_gzip_id1 = 0x1FU , k_gzip_id2 = 0x8BU , k_gzip_deflate = 0x08U , k_gzip_os_unknown = 0xFFU } |
| Fixed non-zero bytes in the RFC 1952 header. More... | |
Functions | |
| static size_t | internal_round_block (size_t bytes) |
| Round one payload extent to a whole tar record. | |
| static ra8_err_t | internal_tar_header (uint8_t *block, const char *name, size_t size) |
| Build one deterministic ustar regular-file header. | |
| static ra8_err_t | internal_direct_sink (void *ctx, const uint8_t *bytes, uint32_t length) |
| Append bytes directly to an archive publication stage. | |
| static ra8_err_t | internal_write_zeros (mdl_export_sink_fn_t sink, void *ctx, uint32_t length) |
| Emit zero padding through one archive sink. | |
| static ra8_err_t | internal_tar_write_memory (mdl_export_sink_fn_t sink, void *ctx, const char *name, const uint8_t *bytes, size_t length) |
| Emit one bounded in-memory tar member. | |
| static ra8_err_t | internal_tar_write_source (mdl_storage_t *storage, const char *path, const char *member, mdl_export_sink_fn_t sink, void *ctx) |
| Emit one portable source as a verified tar member. | |
| static ra8_err_t | internal_build_tar (mdl_storage_t *storage, const char *directory, char names[][k_name_max], size_t count, const mdl_export_meta_t *meta, mdl_export_sink_fn_t sink, void *ctx) |
| Stream a complete deterministic ustar archive. | |
| static mz_bool | internal_gzip_put (const void *bytes, int length, void *ctx) |
| Append DEFLATE callback output to the active stage. | |
| static ra8_err_t | internal_gzip_sink (void *ctx, const uint8_t *bytes, uint32_t length) |
| Feed one uncompressed tar span into streaming DEFLATE. | |
| static void | internal_put_u32le (uint8_t *bytes, uint32_t value) |
| Serialize one little-endian gzip trailer scalar. | |
| ra8_err_t | priv_mdl_export_tar (mdl_storage_t *storage, const char *dir, char names[][k_name_max], size_t count, mdl_export_output_t *output, const mdl_export_meta_t *meta) |
| Write an uncompressed CBT tar archive. | |
| ra8_err_t | priv_mdl_export_tar_gzip (mdl_storage_t *storage, const char *dir, char names[][k_name_max], size_t count, mdl_export_output_t *output, const mdl_export_meta_t *meta, mdl_export_workspace_t *ws) |
| Write a gzip-wrapped CBT archive. | |
Variables | |
| static const uint8_t | s_ustar_magic [k_len_magic] = {'u', 's', 't', 'a', 'r', '\0'} |
| Fixed ustar magic and version payloads. | |
| static const uint8_t | s_ustar_version [2] = {'0', '0'} |
Stream deterministic CBT and gzip-wrapped CBT containers.
Emits ustar records directly into a caller-owned portable sink. Gzip wraps that same stream online, so no intermediate archive or host stream exists and all publication remains one validated transaction.
[Ring 4 / Domain] {World: NS}
Definition in file mdl_export_tar.c.
| enum mdl_gzip_header_t : uint8_t |
Fixed non-zero bytes in the RFC 1952 header.
| Enumerator | |
|---|---|
| k_gzip_id1 | Gzip identification byte one. |
| k_gzip_id2 | Gzip identification byte two. |
| k_gzip_deflate | DEFLATE compression method. |
| k_gzip_os_unknown | Unknown originating OS. |
Definition at line 63 of file mdl_export_tar.c.
| enum mdl_gzip_layout_t : uint16_t |
Gzip framing and serialization constants.
| Enumerator | |
|---|---|
| k_gzip_header_bytes | Fixed RFC 1952 header. |
| k_gzip_u32_bytes | Trailer scalar width. |
| k_byte_bits | Bits shifted per byte. |
| k_byte_mask | Low-byte extraction. |
Definition at line 55 of file mdl_export_tar.c.
| enum mdl_tar_layout_t : uint16_t |
ustar header field offsets and widths.
Definition at line 24 of file mdl_export_tar.c.
| enum mdl_tar_mode_t : uint16_t |
Fixed regular-file mode in deterministic tar headers.
| Enumerator | |
|---|---|
| k_file_mode | Portable regular-file permission bits. |
Definition at line 45 of file mdl_export_tar.c.
| enum mdl_tar_size_t : uint64_t |
Largest payload representable by the fixed eleven-digit tar field.
| Enumerator | |
|---|---|
| k_tar_size_max | Maximum classic octal payload size. |
Definition at line 50 of file mdl_export_tar.c.
|
static |
Stream a complete deterministic ustar archive.
Emits page members in sorted order, one generated ComicInfo member, and the two-record ustar trailer without retaining the archive.
| [in,out] | storage | Bound portable filesystem. |
| [in] | directory | Chapter directory. |
| [in] | names | Sorted page rows. |
| [in] | count | Page count. |
| [in] | meta | Metadata to encode. |
| [in] | sink | Destination callback. |
| [in,out] | ctx | Destination context. |
| k_ra8_ok | The complete archive stream was accepted. |
| k_ra8_fail | A source, metadata, or sink operation failed. |
names contains count terminated rows in desired member order. Definition at line 313 of file mdl_export_tar.c.
References internal_tar_write_memory(), internal_tar_write_source(), k_fw_fs_path_cap, k_name_max, k_ra8_ok, k_tar_block, mdl_export_build_comicinfo_pages(), priv_mdl_export_path_join(), RA8_INTERNAL, and strlen().
Referenced by priv_mdl_export_tar(), and priv_mdl_export_tar_gzip().
|
static |
Append bytes directly to an archive publication stage.
Adapts the generic tar sink contract to the exporter transaction's complete-write operation without taking ownership.
| [in,out] | ctx | Bound internal_tar_sink_t. |
| [in] | bytes | Source bytes. |
| [in] | length | Source extent. |
| k_ra8_ok | Every byte was appended. |
| k_ra8_fail | The injected transaction sink failed. |
length bytes. Definition at line 166 of file mdl_export_tar.c.
References priv_mdl_export_output_write(), and RA8_INTERNAL.
Referenced by priv_mdl_export_tar().
|
static |
Append DEFLATE callback output to the active stage.
Converts miniz's signed callback count to the bounded transaction writer contract and retains the first output failure.
| [in] | bytes | Compressed bytes. |
| [in] | length | Signed miniz byte count. |
| [in,out] | ctx | Bound internal_gzip_sink_t. |
| MZ_TRUE | The complete compressed span was accepted. |
| MZ_FALSE | Arguments or the output transaction failed. |
length compressed bytes. Definition at line 364 of file mdl_export_tar.c.
References internal_gzip_sink_t::error, k_ra8_ok, internal_gzip_sink_t::output, priv_mdl_export_output_write(), and RA8_INTERNAL.
Referenced by priv_mdl_export_tar_gzip().
|
static |
Feed one uncompressed tar span into streaming DEFLATE.
Updates the gzip CRC and modulo-size before passing the complete input span to the caller-arena compressor.
| [in,out] | ctx | Bound internal_gzip_sink_t. |
| [in] | bytes | Tar bytes. |
| [in] | length | Tar byte count. |
| k_ra8_ok | The complete tar span was consumed. |
| k_ra8_fail | Compression or compressed-output delivery failed. |
Definition at line 391 of file mdl_export_tar.c.
References internal_gzip_sink_t::compressor, internal_gzip_sink_t::crc, internal_gzip_sink_t::error, k_ra8_fail, k_ra8_ok, RA8_INTERNAL, and internal_gzip_sink_t::size.
Referenced by priv_mdl_export_tar_gzip().
|
static |
Serialize one little-endian gzip trailer scalar.
Emits the low byte first and shifts exactly once per output byte.
| [out] | bytes | Four writable bytes. |
| [in] | value | Scalar to encode. |
bytes covers k_gzip_u32_bytes bytes. Definition at line 417 of file mdl_export_tar.c.
References k_byte_bits, k_byte_mask, k_gzip_u32_bytes, and RA8_INTERNAL.
Referenced by priv_mdl_export_tar_gzip().
|
static |
Round one payload extent to a whole tar record.
Adds at most one record-minus-one before integer division so no loop or hidden state is required.
| [in] | bytes | Payload extent. |
bytes. | size_t | Record-aligned padded extent. |
bytes leaves room for one record-minus-one addition. bytes. Definition at line 102 of file mdl_export_tar.c.
References k_tar_block, and RA8_INTERNAL.
Referenced by internal_tar_write_memory(), and internal_tar_write_source().
|
static |
Build one deterministic ustar regular-file header.
Zeroes the complete record, encodes fixed owner/time fields, then computes the checksum with the checksum field represented by spaces.
| [out] | block | Writable tar record. |
| [in] | name | Bounded archive member name. |
| [in] | size | Exact payload extent. |
| k_ra8_ok | The complete header was written. |
| k_ra8_err_invalid_size | A field cannot represent its input. |
block covers k_tar_block bytes. name is NUL-terminated and stable for the call. Definition at line 124 of file mdl_export_tar.c.
References k_file_mode, k_len_chksum, k_len_id, k_len_mtime, k_len_name, k_len_size, k_off_chksum, k_off_gid, k_off_magic, k_off_mode, k_off_mtime, k_off_name, k_off_size, k_off_type, k_off_uid, k_off_version, k_ra8_err_invalid_size, k_ra8_ok, k_tar_block, k_tar_size_max, memcpy(), memset(), RA8_INTERNAL, s_ustar_magic, s_ustar_version, and strlen().
Referenced by internal_tar_write_memory(), and internal_tar_write_source().
|
static |
Emit one bounded in-memory tar member.
Writes a deterministic header, the exact payload, and record padding sequentially through the caller sink.
| [in] | sink | Destination callback. |
| [in,out] | ctx | Destination context. |
| [in] | name | Archive member name. |
| [in] | bytes | Payload bytes. |
| [in] | length | Payload extent. |
| k_ra8_ok | The complete member was emitted. |
| k_ra8_err_invalid_size | A header field or payload bound was exceeded. |
sink and ctx remain valid for all callbacks. Definition at line 214 of file mdl_export_tar.c.
References internal_round_block(), internal_tar_header(), internal_write_zeros(), k_ra8_err_invalid_size, k_ra8_ok, k_tar_block, and RA8_INTERNAL.
Referenced by internal_build_tar().
|
static |
Emit one portable source as a verified tar member.
Snapshots the regular source, writes its deterministic header, streams the first pass, verifies an independent reread, and pads.
| [in,out] | storage | Bound portable filesystem. |
| [in] | path | Canonical source path. |
| [in] | member | Archive member name. |
| [in] | sink | Destination callback. |
| [in,out] | ctx | Destination context. |
| k_ra8_ok | The complete stable source member was emitted. |
| k_ra8_err_validation_failed | The source changed between passes. |
sink and ctx remain callable for the complete member. Definition at line 256 of file mdl_export_tar.c.
References mdl_export_source_t::file, internal_round_block(), internal_tar_header(), internal_write_zeros(), fw_fs_file_t::is_open, k_ra8_err_invalid_size, k_ra8_ok, k_tar_block, priv_mdl_export_source_close(), priv_mdl_export_source_copy(), priv_mdl_export_source_open(), RA8_INTERNAL, and mdl_export_source_t::size.
Referenced by internal_build_tar().
|
static |
Emit zero padding through one archive sink.
Uses one bounded zero record and never emits a callback for a zero-length request.
| [in] | sink | Destination callback. |
| [in,out] | ctx | Destination context. |
| [in] | length | Zero-byte extent, at most one tar record. |
| k_ra8_ok | Padding was empty or completely accepted. |
| k_ra8_fail | The injected sink rejected the padding. |
sink is non-null and length does not exceed k_tar_block. ctx remains valid for the callback duration. length zero bytes. Definition at line 189 of file mdl_export_tar.c.
References k_ra8_ok, and k_tar_block.
Referenced by internal_tar_write_memory(), and internal_tar_write_source().
| ra8_err_t priv_mdl_export_tar | ( | mdl_storage_t * | storage, |
| const char * | dir, | ||
| char | names[][k_name_max], | ||
| size_t | count, | ||
| mdl_export_output_t * | output, | ||
| const mdl_export_meta_t * | meta ) |
Write an uncompressed CBT tar archive.
Streams page members and ComicInfo through deterministic ustar records without retaining the whole archive.
| [in,out] | storage | Injected portable file reader. |
| [in] | dir | Chapter directory. |
| [in] | names | Sorted page-name rows. |
| [in] | count | Page count. |
| [in,out] | output | Active validated-publication output. |
| [in] | meta | Resolved metadata. |
| k_ra8_ok | A complete CBT was written. |
| k_ra8_err_invalid_size | A ustar or metadata bound was exceeded. |
| k_ra8_fail | File I/O failed. |
output owns an active transaction. Definition at line 425 of file mdl_export_tar.c.
References internal_build_tar(), internal_direct_sink(), k_name_max, and RA8_PRIV.
Referenced by internal_export_dispatch().
| ra8_err_t priv_mdl_export_tar_gzip | ( | mdl_storage_t * | storage, |
| const char * | dir, | ||
| char | names[][k_name_max], | ||
| size_t | count, | ||
| mdl_export_output_t * | output, | ||
| const mdl_export_meta_t * | meta, | ||
| mdl_export_workspace_t * | ws ) |
Write a gzip-wrapped CBT archive.
Streams deterministic ustar records directly through caller-arena DEFLATE into the active output; no intermediate archive exists.
| [in,out] | storage | Injected portable file reader. |
| [in] | dir | Chapter directory. |
| [in] | names | Sorted page-name rows. |
| [in] | count | Page count. |
| [in,out] | output | Active validated-publication output. |
| [in] | meta | Resolved metadata. |
| [in,out] | ws | Exclusive exporter workspace. |
| k_ra8_ok | A complete gzip stream was written. |
| k_ra8_err_invalid_size | A bound or workspace was exceeded. |
| k_ra8_fail | File or compression I/O failed. |
Definition at line 436 of file mdl_export_tar.c.
References internal_gzip_sink_t::crc, internal_gzip_sink_t::error, internal_build_tar(), internal_gzip_put(), internal_gzip_sink(), internal_put_u32le(), k_gzip_deflate, k_gzip_header_bytes, k_gzip_id1, k_gzip_id2, k_gzip_os_unknown, k_gzip_u32_bytes, k_name_max, k_ra8_err_invalid_size, k_ra8_fail, k_ra8_ok, mdl_export_workspace_take(), priv_mdl_export_output_write(), RA8_PRIV, and internal_gzip_sink_t::size.
Referenced by internal_export_dispatch().
|
static |
Fixed ustar magic and version payloads.
Definition at line 85 of file mdl_export_tar.c.
Referenced by internal_tar_header().
|
static |
Definition at line 86 of file mdl_export_tar.c.
Referenced by internal_tar_header().