46 "usage: ra8_emulator <firmware.elf> [--view] [--ppm <out.ppm>]"
47 " [--panel <file.toml>] [--size WxH] [--click X Y] [--touch-seq S] [--input <str>]"
49 " [--usb-in <str>] [--button <1|2>] [--reboot <N>] [--dump-sym <name>]"
50 " [--stop-sym <name> <N>]"
51 " [--trace-sym <name>] [--sd-new <N[k|m|g][:fat16|fat32]>] [--save-sd <out>] [--fast-sd]"
52 " [--eink] [--device ra8d2|ra8p1]\n"
53 " --view open a macOS window: live board view; click panel"
54 " (touch) / on-screen SW1/SW2, type -> UART\n"
55 " --ppm <file> write the final composite (panel + status) to a PPM\n"
56 " --record <dir> record frames (panel + status) to <dir>/frame_NNNNNN.ppm\n"
57 " --record-secs N headless: record N emulated seconds, then stop (~20 fps)\n"
58 " --rotate DEG display rotation 90/180/270 (e.g. portrait)\n"
59 " --panel <file> display descriptor (name/width/height) to size the panel\n"
60 " --size WxH panel size in pixels; overrides --panel (default 1024x600)\n"
61 " --click X Y headless: inject one touch at X,Y once the UI is up\n"
62 " --touch-seq S headless: queue raw GT911 taps \"x0:y0,x1:y1,...\" served\n"
63 " one per drained frame (multi-tap flows, e.g. touch_cal)\n"
64 " --input <str> feed <str> to the console UART RX (SCI8); \\n / \\r / \\t ok\n"
65 " --keys <str> type <str> via the window-key path -> console UART RX\n"
66 " --usb-in <str> feed <str> to the USB CDC bulk OUT pipe (echo test)\n"
67 " --button <1|2> hold user switch SW1 (P009) / SW2 (P008) pressed\n"
68 " --battery <pct> set the fuel-gauge state-of-charge (0..100; MAX17048 @ 0x36)\n"
69 " --charge mark the battery charging (fuel-gauge CRATE reads positive)\n"
70 " --reboot <N> warm-reboot N times (re-run from reset vector; VBATT-backup\n"
71 " + reset-cause survive) to exercise reset-survival apps\n"
72 " --sd <image> serve a FAT/exFAT image as the microSD card (read + write)\n"
73 " --sd-new <N[k|m|g][:fat16|fat32]> blank FAT card of N MiB (k/m/g unit; e.g. 30g)\n"
74 " --save-sd <out> after the run, dump the SD card image (with firmware writes)\n"
75 " --fast-sd serve SD blocks direct from the image (skip the per-byte SPI\n"
76 " protocol; byte-identical render) so a big book loads fast; opt-in\n"
77 " --eink attach a modelled IT8951 e-paper controller on SPI_B (drives\n"
78 " the ra8_epaper path: HRDY ready, GET_DEV_INFO, load + display)\n"
79 " --dump-sym <s> print 32-bit global <s> from memory after the run (memprobe)\n"
80 " --stop-sym <s> <N> end the run once 32-bit global <s> reaches N (counter memprobe)\n"
81 " --trace-sym <s> log every entry to function <s> (+LR): trace a bring-up path\n"
82 " --trace log each LED/GPIO transition + NVIC IRQ as it happens\n"
83 " --primary-core m85|m33 label the primary core; m33 leaves the M85-only\n"
84 " instruction seams (MVE / long-shift) off (default m85)\n"
85 " --device ra8d2|ra8p1 select the emulated part (default ra8d2). ra8p1 adds\n"
86 " the Ethos-U55 NPU (0x40140000) as a mapped-but-unmodelled\n"
87 " window; else identical to the RA8D2 model\n"
88 " --low-power model the M33's 4:1-slower clock (1/4 chunk budget); the\n"
89 " GUI low-power button toggles it live under --view\n");
148 if (
strncmp(argv[idx],
"--view",
sizeof(
"--view")) == 0) {
150 }
else if (
strncmp(argv[idx],
"--usbhs-loop",
sizeof(
"--usbhs-loop")) == 0) {
155 }
else if (
strncmp(argv[idx],
"--trace",
sizeof(
"--trace")) == 0) {
157 }
else if (
strncmp(argv[idx],
"--low-power",
sizeof(
"--low-power")) == 0) {
159 }
else if (
strncmp(argv[idx],
"--fast-sd",
sizeof(
"--fast-sd")) == 0) {
161 }
else if (
strncmp(argv[idx],
"--eink",
sizeof(
"--eink")) == 0) {
163 }
else if (
strncmp(argv[idx],
"--modem",
sizeof(
"--modem")) == 0) {
165 }
else if ((
strncmp(argv[idx],
"--primary-core",
sizeof(
"--primary-core")) == 0) &&
166 ((idx + 1) < argc)) {
170 }
else if ((
strncmp(argv[idx],
"--device",
sizeof(
"--device")) == 0) && ((idx + 1) < argc)) {
205 if ((
strncmp(argv[idx],
"--ppm",
sizeof(
"--ppm")) == 0) && ((idx + 1) < argc)) {
208 }
else if ((
strncmp(argv[idx],
"--record-secs",
sizeof(
"--record-secs")) == 0) &&
209 ((idx + 1) < argc)) {
213 }
else if ((
strncmp(argv[idx],
"--record",
sizeof(
"--record")) == 0) && ((idx + 1) < argc)) {
216 }
else if ((
strncmp(argv[idx],
"--rotate",
sizeof(
"--rotate")) == 0) && ((idx + 1) < argc)) {
222 }
else if ((
strncmp(argv[idx],
"--panel",
sizeof(
"--panel")) == 0) && ((idx + 1) < argc)) {
225 }
else if ((
strncmp(argv[idx],
"--size",
sizeof(
"--size")) == 0) && ((idx + 1) < argc)) {
229 ((end !=
nullptr) && (*end ==
'x')) ? strtol(end + 1,
nullptr, (
int)
k_strtol_base10) : 0L;
231 out->
view_w = (uint16_t)w;
232 out->
view_h = (uint16_t)h;
265 if ((
strncmp(argv[idx],
"--ns",
sizeof(
"--ns")) == 0) && ((idx + 1) < argc)) {
270 }
else if ((
strncmp(argv[idx],
"--input",
sizeof(
"--input")) == 0) && ((idx + 1) < argc)) {
273 }
else if ((
strncmp(argv[idx],
"--keys",
sizeof(
"--keys")) == 0) && ((idx + 1) < argc)) {
276 }
else if ((
strncmp(argv[idx],
"--touch-seq",
sizeof(
"--touch-seq")) == 0) &&
277 ((idx + 1) < argc)) {
280 }
else if ((
strncmp(argv[idx],
"--usb-in",
sizeof(
"--usb-in")) == 0) && ((idx + 1) < argc)) {
283 }
else if ((
strncmp(argv[idx],
"--click",
sizeof(
"--click")) == 0) && ((idx + 2) < argc)) {
317 char* endp =
nullptr;
322 const char unit = (char)(((endp !=
nullptr) && (*endp !=
'\0')) ? tolower((
int)*endp) :
'm');
325 }
else if (unit ==
'g') {
327 }
else if (unit ==
't') {
331 const uint64_t bytes = (num > 0L) ? ((uint64_t)num * mult) : 0ULL;
333 const char* colon = (endp !=
nullptr) ?
strchr(endp,
':') :
nullptr;
334 const uint64_t fat32_min_bytes =
336 uint8_t fat = (bytes >= fat32_min_bytes) ? (uint8_t)32U : (uint8_t)16U;
337 if (colon !=
nullptr) {
338 fat = (
strstr(colon,
"32") !=
nullptr) ? (uint8_t)32U : (uint8_t)16U;
340 if ((sectors > 0ULL) && (sectors <= (uint64_t)
k_sd_u32_max)) {
343 (void)
priv_emu_io_errf(
"ra8_emulator: --sd-new: size exceeds the 2 TiB FAT limit\n");
371 if ((
strncmp(argv[idx],
"--sd",
sizeof(
"--sd")) == 0) && ((idx + 1) < argc)) {
374 }
else if ((
strncmp(argv[idx],
"--sd-new",
sizeof(
"--sd-new")) == 0) && ((idx + 1) < argc)) {
381 }
else if ((
strncmp(argv[idx],
"--save-sd",
sizeof(
"--save-sd")) == 0) && ((idx + 1) < argc)) {
415 if ((
strncmp(argv[idx],
"--dump-sym",
sizeof(
"--dump-sym")) == 0) && ((idx + 1) < argc)) {
421 }
else if ((
strncmp(argv[idx],
"--stop-sym",
sizeof(
"--stop-sym")) == 0) && ((idx + 2) < argc)) {
429 }
else if ((
strncmp(argv[idx],
"--trace-sym",
sizeof(
"--trace-sym")) == 0) &&
430 ((idx + 1) < argc)) {
466 if ((
strncmp(argv[idx],
"--button",
sizeof(
"--button")) == 0) && ((idx + 1) < argc)) {
469 }
else if ((
strncmp(argv[idx],
"--battery",
sizeof(
"--battery")) == 0) && ((idx + 1) < argc)) {
473 }
else if (
strncmp(argv[idx],
"--charge",
sizeof(
"--charge")) == 0) {
476 }
else if ((
strncmp(argv[idx],
"--reboot",
sizeof(
"--reboot")) == 0) && ((idx + 1) < argc)) {
492 for (
int i = 2; i < argc; i++) {
@ k_board_device_ra8p1
Renesas RA8P1: adds the Ethos-U55 NPU.
@ k_board_device_ra8d2
Renesas RA8D2 (default): no NPU.
IT8951 e-paper SPI-device model for ra8_emulator (attached to SPI_B).
bool board_eink_attach(void)
Attach (arm) the modelled IT8951 e-paper controller.
Cellular AT-modem device model for ra8_emulator (attached to SCI7 UART).
bool board_modem_attach(void)
Attach (arm) the modelled AT cellular modem.
SD-card-over-SPI device model for ra8_emulator (attached to SPI_B).
bool board_sd_attach(const char *path)
Attach an SD-card image from a host file.
bool board_sd_attach_blank(uint32_t total_sectors, uint8_t fat_bits, const char *label)
Create a blank, FAT-formatted sparse SD card and attach it.
static bool internal_args_try_control(int argc, char **argv, int *i, emu_args_t *out)
Parse the button / battery / reboot run-control options.
static void internal_args_print_usage(void)
Print the ra8_emulator CLI usage text to injected error sink.
static void internal_args_defaults(const char *elf_path, emu_args_t *out)
Seed the parsed-args struct with every option's default.
static bool internal_args_try_sym(int argc, char **argv, int *i, emu_args_t *out)
Parse the symbol-probe options.
static bool internal_args_try_sd(int argc, char **argv, int *i, emu_args_t *out)
Parse the microSD options.
bool emu_args_parse(int argc, char **argv, emu_args_t *out)
Parse the ra8_emulator command line into out (or print usage).
static bool internal_args_try_input(int argc, char **argv, int *i, emu_args_t *out)
Parse the input-injection options.
static bool internal_args_try_display(int argc, char **argv, int *i, emu_args_t *out)
Parse the display / output options.
static void internal_args_attach_blank_sd(const char *spec)
Parse a --sd-new size spec and attach a blank formatted card.
static bool internal_args_try_mode(int argc, char **argv, int *i, emu_args_t *out)
Parse the mode / core / device / attach-flag options.
ra8_emulator command-line parsing (usage text + option decoding)
Bounded raw-descriptor I/O seam for the RA8 emulator.
emu_io_result_t priv_emu_io_err_text(const char *text)
Write a NUL-terminated literal to the injected error descriptor.
emu_io_result_t priv_emu_io_errf(const char *format,...)
Format bounded text and write it to the injected error descriptor.
@ k_sectors_per_mib
512-byte sectors per MiB (–sd-new).
@ k_max_panel_px
Largest –size dimension.
@ k_dump_sym_max
Max –dump-sym globals per run.
@ k_fat32_min_mib
FAT32 default threshold, in MiB.
@ k_bytes_per_sector
SD logical sector size in bytes.
@ k_size_kib
One kibibyte (k suffix multiplier).
@ k_sd_u32_max
32-bit sector-count ceiling.
Armv8.1-M instruction-emulation seams (M85 ops on Unicorn's M33).
void emu_fast_sd_enable(void)
Opt in to the –fast-sd block-serving seam for this run.
@ k_trace_sym_max
Max –trace-sym functions per run.
Board-view presentation: frames, composition, input routing, panels.
void emu_set_primary_core(board_primary_core_t core)
Select the primary core (CLI –primary-core).
@ k_rotate_0
Native orientation.
@ k_rotate_90
90 deg clockwise (-> portrait).
@ k_rotate_270
90 deg counter-clockwise.
@ k_rotate_180
Upside down.
@ k_strtol_base10
Base-10 radix for strtol parses.
void emu_set_low_power(bool on)
Set the low-power clock model (CLI –low-power / GUI toggle).
@ k_core_m33
Cortex-M33 primary: the M85-only instruction seams stay off.
@ k_core_m85
Cortex-M85 primary (default): MVE/long-shift seams armed.
@ k_view_default_h
Default window height (EK-RA8D2 panel).
@ k_view_default_w
Default window width (EK-RA8D2 panel).
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
int strncmp(const char *s1, const char *s2, size_t n)
Compare two strings up to a specified length.
char * strstr(const char *haystack, const char *needle)
Locate substring in string.
char * strchr(const char *s, int c)
Locate first occurrence of character in string.
Every value the ra8_emulator CLI parse produces for the setup phase.
uint32_t stop_sym_thresh
–stop-sym stop threshold.
int click_x
–click column (-1 = unset).
const char * elf_path
Firmware ELF path (argv[1]).
const char * touch_seq_str
–touch-seq raw-point FIFO string.
int click_y
–click row (-1 = unset).
const char * stop_sym_name
–stop-sym watch global (NULL = off).
uint32_t trace_sym_n
Count of –trace-sym entries.
uint16_t view_w
Panel width in pixels.
uint32_t dump_sym_n
Count of –dump-sym entries.
const char * usb_in_str
–usb-in CDC bulk OUT string.
int battery_soc
–battery pct (-1 = model default).
bool usbhs_loop
–usbhs-loop chip-internal self-loop.
bool want_view
–view live window.
const char * panel_path
–panel descriptor path (NULL = none).
const char * trace_sym_names[k_trace_sym_max]
–trace-sym functions to log.
int button_press
–button: 1=SW1, 2=SW2, 0=none.
bool battery_opt
Any battery flag given.
const char * ns_elf_path
–ns second (NS) image path.
bool want_trace
–trace transition logging.
const char * save_sd_path
–save-sd dump path (NULL = off).
int reboot_count
–reboot N warm reboots.
uint16_t view_h
Panel height in pixels.
const char * dump_sym_names[k_dump_sym_max]
–dump-sym globals to read.
bool battery_charging
–charge given.
const char * record_dir
–record directory (NULL = off).
board_device_t emu_device
–device selected part (RA8D2 default).
bool size_set
–size given (wins over –panel).
const char * keys_str
–keys window-key path string.
const char * ppm_path
–ppm output path (NULL = off).
bool want_click
–click armed with valid coordinates.
uint32_t record_secs
–record-secs bound (0 = unbounded).
uint32_t rotate_deg
–rotate display rotation (0 default).
const char * input_str
–input console RX string.