ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
10
11#include <stddef.h>
12#include <stdint.h>
13#include <unistd.h>
14
15#include "ra8_attributes.h"
18#include "ra8_log.h"
19
21typedef enum : uint8_t {
24
34
36static const char s_usage[] =
37 "usage:\n"
38 " ra8_fmt convert --format <fmt> --in <file> --out <file>\n"
39 " ra8_fmt inspect <container> [--verbose]\n"
40 " ra8_fmt verify --format <fmt> --in <file> [--out <dump.ppm>]\n"
41 "\nformats:\n"
42 " jof .jof [convert] [inspect] [verify] band-tile atlas (JOF): "
43 "display-native, O(1) random access per tile\n"
44 " rabook .rabook [inspect] chunked book container (RBKC): compiled "
45 "book, "
46 "one unit = one book\n";
47
61static void internal_usage(const ra8_fmt_sink_t* errors)
62{
63 (void)errors->write(errors->ctx, (const uint8_t*)s_usage, sizeof(s_usage) - 1U);
64}
65
84static int internal_dispatch(int argc, char** argv, bool* handled)
85{
86 int status = priv_fmt_try_portable_convert(argc,
87 argv,
88 s_cli_workspace.bytes,
90 handled);
91 if (!*handled) {
92 status = priv_fmt_try_portable_verify(argc, argv, &s_cli_workspace, handled);
93 }
94 if (!*handled) {
95 status = priv_fmt_try_portable_inspect(argc, argv, &s_cli_workspace, handled);
96 }
97 return status;
98}
99
100int main(int argc, char** argv)
101{
102 ra8_fmt_host_fd_sink_t error_state = {.fd = STDERR_FILENO};
103 const ra8_fmt_sink_t errors = priv_fmt_host_fd_sink(&error_state);
105 bool handled = false;
106 const int status = internal_dispatch(argc, argv, &handled);
107 if (handled) {
108 return status;
109 }
110 internal_usage(&errors);
111 return (int)k_main_exit_usage;
112}
void main(void)
Secure fallback main entry point.
Definition main.c:37
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Raw file-descriptor adapters for the portable format-tool contracts.
void priv_fmt_host_log_byte(void *ctx, uint8_t byte)
Adapt a logging byte to an injected raw-fd sink.
ra8_fmt_sink_t priv_fmt_host_fd_sink(ra8_fmt_host_fd_sink_t *state)
Obtain the exact-write portable sink for a raw descriptor.
Caller-workspace CLI composition for every supported tool verb.
int priv_fmt_try_portable_convert(int argc, char **argv, uint8_t *arena, size_t arena_cap, bool *handled)
Try the caller-workspace JOF-convert command path.
@ k_ra8_fmt_cli_convert_arena_bytes
Convert prefix (8 MiB).
int priv_fmt_try_portable_verify(int argc, char **argv, ra8_fmt_cli_workspace_t *workspace, bool *handled)
Try the bounded two-spool JOF-verification command path.
int priv_fmt_try_portable_inspect(int argc, char **argv, ra8_fmt_cli_workspace_t *workspace, bool *handled)
Try strict streamed JOF or RBKC inspection.
Lightweight Logging Interface for ra8-firmware.
void ra8_log_set_byte_sink(ra8_log_byte_sink_fn_t fn, void *ctx)
Install (or clear) an optional byte sink for log output.
Definition ra8_log.c:56
static void internal_usage(void)
Print CLI usage and the explicit compiled cache ceiling.
One explicit, shared composition-root workspace for portable verbs.
Append sink backed by a caller-owned descriptor.
Injected append-only sink.
static int internal_dispatch(int argc, char **argv, bool *handled)
Try every portable dispatcher in stable command order.
Definition main.c:84
static ra8_fmt_cli_workspace_t s_cli_workspace
Existing explicit high-water shared by mutually exclusive CLI verbs.
Definition main.c:33
main_exit_t
Process status returned when no supported command owns the input.
Definition main.c:21
@ k_main_exit_usage
Invalid or unsupported command line.
Definition main.c:22
static const char s_usage[]
Established usage banner and supported-format inventory.
Definition main.c:36