|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Host tool that streams compiled books into an atomic FAT32 image. More...
#include <errno.h>#include <fcntl.h>#include <limits.h>#include <stddef.h>#include <stdint.h>#include <stdio.h>#include <string.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include "mkbookimg_internal.h"#include "mkbookimg_names.h"#include "ra8_attributes.h"#include "ra8_fs.h"Go to the source code of this file.
Data Structures | |
| struct | mkbookimg_output_t |
| Caller-owned atomic-publication state. More... | |
Functions | |
| void | priv_mkbookimg_diag (const char *text) |
| Write a complete diagnostic fragment to the standard-error descriptor. | |
| void | priv_mkbookimg_diag_u64 (uint64_t value) |
| Emit an unsigned decimal value without a formatting runtime. | |
| bool | priv_mkbookimg_pread_exact (int fd, uint64_t offset, uint8_t *bytes, size_t length) |
| Read exactly one bounded positioned byte range. | |
| static bool | internal_pwrite_exact (int fd, uint64_t offset, const uint8_t *bytes, size_t length) |
| Write exactly one bounded positioned byte range. | |
| static bool | internal_block_range (const mkbookimg_disk_t *disk, uint64_t lba, uint32_t count, uint64_t *out_offset, size_t *out_bytes) |
| Validate and translate a block range to a host byte range. | |
| static ra8_err_t | internal_disk_read (void *ctx, uint64_t lba, uint32_t count, uint8_t *buffer) |
| Read sectors from the temporary image for ra8_fs. | |
| static ra8_err_t | internal_disk_write (void *ctx, uint64_t lba, uint32_t count, const uint8_t *buffer) |
| Write sectors to the temporary image for ra8_fs. | |
| static ra8_err_t | internal_disk_capacity (void *ctx, uint64_t *block_count, uint32_t *block_size) |
| Report fixed image geometry to ra8_fs. | |
| static bool | internal_split_output (const char *path, char parent[k_host_path_cap], char final_name[k_host_name_cap]) |
| Split an output path into an existing parent directory and safe leaf. | |
| static bool | internal_temp_name (char out[k_host_name_cap], uint64_t process, uint32_t attempt) |
| Build one hidden sibling-temporary leaf from process id and attempt. | |
| static bool | internal_output_begin (const char *final_path, mkbookimg_output_t *output) |
| Create and size a private sibling temporary for atomic publication. | |
| static void | internal_output_abort (mkbookimg_output_t *output) |
| Close and remove an unpublished temporary image. | |
| static bool | internal_output_commit (mkbookimg_output_t *output) |
| Durably publish the complete image with one same-directory rename. | |
| static void | internal_print_success (const char *out_path, int book_count) |
| Print the final success diagnostic line. | |
| int | main (int argc, char **argv) |
| Validate CLI input, construct, verify, and atomically publish one image. | |
Host tool that streams compiled books into an atomic FAT32 image.
Streams a 64 MiB FAT32 image through firmware ra8_fs over a sparse sibling. Fixed chunks are verified before sync/rename; no POSIX type crosses into reusable code. This unit owns the host container: descriptor-level diagnostics, exact positioned I/O, the block device, the atomic sibling-temporary publication, and main. The population pass that streams and verifies each book is src/mkbookimg_books.c; the seam between the two is inc/mkbookimg_internal.h.
Definition in file mkbookimg.c.
|
static |
Validate and translate a block range to a host byte range.
Checks geometry, multiplication, host-offset, and size limits first.
| [in] | disk | Descriptor-backed device geometry. |
| [in] | lba | First sector. |
| [in] | count | Sector count. |
| [out] | out_offset | Host byte offset. |
| [out] | out_bytes | Host byte count. |
| true | Both outputs describe the requested range. |
| false | The range exceeds geometry or host integer limits. |
disk carries non-zero valid geometry. Definition at line 157 of file mkbookimg.c.
References mkbookimg_disk_t::block_count, mkbookimg_disk_t::block_size, and RA8_INTERNAL.
|
static |
Report fixed image geometry to ra8_fs.
Copies immutable descriptor-backed geometry into caller outputs.
| [in] | ctx | Bound mkbookimg_disk_t. |
| [out] | block_count | Receives the sector count. |
| [out] | block_size | Receives bytes per sector. |
| k_ra8_ok | Geometry was copied to both outputs. |
| k_ra8_err_null_ptr | Any argument was NULL. |
Definition at line 266 of file mkbookimg.c.
References mkbookimg_disk_t::block_count, mkbookimg_disk_t::block_size, k_ra8_err_null_ptr, and k_ra8_ok.
|
static |
Read sectors from the temporary image for ra8_fs.
Translates the whole request before issuing exact positioned I/O.
| [in,out] | ctx | Bound mkbookimg_disk_t. |
| [in] | lba | First sector. |
| [in] | count | Sector count. |
| [out] | buffer | Destination for exactly count sectors. |
| k_ra8_ok | Every sector was read exactly. |
| k_ra8_err_out_of_range | Invalid state, pointer, or range. |
| k_ra8_fail | Positioned host I/O failed. |
ctx and buffer are non-NULL. buffer contains the requested sectors. Definition at line 198 of file mkbookimg.c.
References mkbookimg_disk_t::fd, internal_block_range(), mkbookimg_disk_t::io_failed, k_ra8_err_out_of_range, k_ra8_fail, k_ra8_ok, and priv_mkbookimg_pread_exact().
|
static |
Write sectors to the temporary image for ra8_fs.
Translates the whole request before issuing exact positioned I/O.
| [in,out] | ctx | Bound mkbookimg_disk_t. |
| [in] | lba | First sector. |
| [in] | count | Sector count. |
| [in] | buffer | Source containing exactly count sectors. |
| k_ra8_ok | Every sector was written exactly. |
| k_ra8_err_out_of_range | Invalid state, pointer, or range. |
| k_ra8_fail | Positioned host I/O failed. |
ctx and buffer are non-NULL. Definition at line 233 of file mkbookimg.c.
References mkbookimg_disk_t::fd, internal_block_range(), internal_pwrite_exact(), mkbookimg_disk_t::io_failed, k_ra8_err_out_of_range, k_ra8_fail, and k_ra8_ok.
|
static |
Close and remove an unpublished temporary image.
Idempotently releases the descriptor, private leaf, and parent handle.
| [in,out] | output | Publication state from internal_output_begin. |
output is non-NULL and may be partially initialized. Definition at line 441 of file mkbookimg.c.
References mkbookimg_output_t::directory_fd, mkbookimg_output_t::image_fd, RA8_INTERNAL, mkbookimg_output_t::temp_exists, and mkbookimg_output_t::temp_name.
Referenced by main().
|
static |
Create and size a private sibling temporary for atomic publication.
Uses exclusive no-follow creation and unwinds every partial resource.
| [in] | final_path | Requested output path. |
| [out] | output | Caller-owned publication state. |
output. | true | The temporary descriptor has exact image length. |
| false | Validation, directory open, create, or truncate failed. |
output is writable and owns no descriptors. final_path is NUL-terminated. output owns one same-directory temporary. Definition at line 385 of file mkbookimg.c.
References mkbookimg_output_t::directory_fd, mkbookimg_output_t::final_name, mkbookimg_output_t::image_fd, internal_split_output(), internal_temp_name(), k_block_size, k_host_path_cap, k_img_sectors, k_output_create_mode, k_temp_create_attempts, O_CLOEXEC, O_DIRECTORY, O_NOFOLLOW, RA8_INTERNAL, mkbookimg_output_t::temp_exists, and mkbookimg_output_t::temp_name.
Referenced by main().
|
static |
Durably publish the complete image with one same-directory rename.
Syncs file data before rename and parent metadata after publication.
| [in,out] | output | Publication state owning the complete temporary image. |
| true | The final leaf atomically names the complete image. |
| false | Publication failed; before rename the old final is preserved. |
output owns a complete temporary image. Definition at line 472 of file mkbookimg.c.
References mkbookimg_output_t::directory_fd, mkbookimg_output_t::final_name, mkbookimg_output_t::image_fd, RA8_INTERNAL, renameat(), mkbookimg_output_t::temp_exists, and mkbookimg_output_t::temp_name.
Referenced by main().
|
static |
Print the final success diagnostic line.
Emits the published path and the book count as one bounded run of diagnostic fragments through the same descriptor-level writer every failure message uses, so the two can never reach different sinks.
| [in] | out_path | Published destination path. |
| [in] | book_count | Number of books written. |
out_path is a NUL-terminated string. Definition at line 515 of file mkbookimg.c.
References priv_mkbookimg_diag(), priv_mkbookimg_diag_u64(), and RA8_INTERNAL.
Referenced by main().
|
static |
Write exactly one bounded positioned byte range.
Retries interrupted calls and treats a zero write as an I/O failure.
| [in] | fd | Open regular-file descriptor. |
| [in] | offset | Absolute starting byte offset. |
| [in] | bytes | Source spanning length bytes. |
| [in] | length | Exact byte count. |
| true | The complete range reached the page cache. |
| false | Overflow or an unrecoverable/zero write occurred. |
bytes spans length readable bytes. Definition at line 116 of file mkbookimg.c.
Referenced by internal_disk_write().
|
static |
Split an output path into an existing parent directory and safe leaf.
Rejects truncation, empty leaves, and dot traversal components.
| [in] | path | Requested destination path. |
| [out] | parent | Parent path buffer. |
| [out] | final_name | Destination leaf buffer. |
| true | Both outputs are populated. |
| false | The path is empty, too long, or names ./../a directory. |
path is non-NULL and NUL-terminated. path. Definition at line 293 of file mkbookimg.c.
References k_host_name_cap, k_host_path_cap, memcpy(), RA8_INTERNAL, strcmp(), and strlen().
Referenced by internal_output_begin().
|
static |
Build one hidden sibling-temporary leaf from process id and attempt.
Uses fixed decimal buffers so collision retries require no allocation.
| [out] | out | Temporary-name buffer. |
| [in] | process | Positive process identifier. |
| [in] | attempt | Collision retry index. |
| true | out contains a complete NUL-terminated name. |
| false | The fixed output capacity was insufficient. |
out has k_host_name_cap bytes. process and attempt are finite unsigned values. Definition at line 346 of file mkbookimg.c.
References k_decimal_base, k_decimal_u64_digits, k_host_name_cap, memcpy(), and s_prefix.
Referenced by internal_output_begin().
| int main | ( | int | argc, |
| char ** | argv ) |
Validate CLI input, construct, verify, and atomically publish one image.
| [in] | argc | Argument count. |
| [in] | argv | Output path followed by one or more book paths. |
| 0 | A complete verified image was atomically published. |
| 1 | Generation or durable publication failed. |
| 2 | The command line did not contain a supported input count. |
argv contains argc entries as required by the hosted C runtime. Definition at line 539 of file mkbookimg.c.
References mkbookimg_output_t::image_fd, internal_disk_capacity(), internal_disk_read(), internal_disk_write(), internal_output_abort(), internal_output_begin(), internal_output_commit(), internal_print_success(), k_block_size, k_img_sectors, k_max_books, priv_mkbookimg_build_image(), and priv_mkbookimg_diag().
| void priv_mkbookimg_diag | ( | const char * | text | ) |
Write a complete diagnostic fragment to the standard-error descriptor.
Retries interrupted and short writes without involving stdio streams.
| [in] | text | NUL-terminated fragment. |
text is non-NULL and NUL-terminated. Definition at line 41 of file mkbookimg.c.
References strlen().
Referenced by internal_format_mount(), internal_print_success(), internal_write_books(), main(), and priv_mkbookimg_diag_u64().
| void priv_mkbookimg_diag_u64 | ( | uint64_t | value | ) |
Emit an unsigned decimal value without a formatting runtime.
Converts into fixed local buffers and forwards one bounded string.
| [in] | value | Value to emit. |
Definition at line 58 of file mkbookimg.c.
References k_decimal_base, k_decimal_u64_digits, and priv_mkbookimg_diag().
Referenced by internal_print_success(), and internal_write_books().
| bool priv_mkbookimg_pread_exact | ( | int | fd, |
| uint64_t | offset, | ||
| uint8_t * | bytes, | ||
| size_t | length ) |
Read exactly one bounded positioned byte range.
Retries interrupted calls and rejects EOF before the requested end.
| [in] | fd | Open regular-file descriptor. |
| [in] | offset | Absolute starting byte offset. |
| [out] | bytes | Destination spanning length bytes. |
| [in] | length | Exact byte count. |
| true | The destination contains the complete requested range. |
| false | EOF, overflow, or an unrecoverable read error occurred. |
bytes spans length writable bytes. bytes may hold a strict prefix. Definition at line 75 of file mkbookimg.c.
Referenced by internal_disk_read(), internal_stream_book(), and internal_verify_book().