Drop newlib printf: log via BDK s_vprintf, add debug.ini log switch

log_write was the only vsnprintf user and pulled in newlib's printf,
dtoa, malloc and soft-float code (~44 KB). The payload now fits the
RCM limit again (146800 -> 102801 bytes); the build fails if it grows
past it. debug.ini log=1 writes sd:/config/omninx/install.log.
This commit is contained in:
niklascfw committed 2026-11-12 22:50:20 +01:00
1 parent 555ff07ae4
commit 702cce7d3e
7 files changed
+62 -13

No files matched your search

+6
View File
@@ -45,6 +45,12 @@ Create the folder `sd:/config/omninx/` on the SD card if it does not exist. Same
|-----|-----------------| |-----|-----------------|
| `skip_hekate_8gb_post_copy` | After a successful copy: the optional `hekate_8GB` / RAM menu and related file moves (see `install_hekate_8gb_post_copy` in `install.c`) | | `skip_hekate_8gb_post_copy` | After a successful copy: the optional `hekate_8GB` / RAM menu and related file moves (see `install_hekate_8gb_post_copy` in `install.c`) |
### Logging
| Key | Effect |
|-----|--------|
| `log` | Writes `sd:/config/omninx/install.log` with every deleted path, every copied file and the final result. Nothing is skipped. Slower on large packs; meant for test runs. |
## Behaviour ## Behaviour
- On startup, if `debug.ini` exists and parses successfully, the payload prints a **DEBUG-MODUS** banner listing which skips are active. - On startup, if `debug.ini` exists and parses successfully, the payload prints a **DEBUG-MODUS** banner listing which skips are active.
+1 -1
View File
@@ -60,7 +60,7 @@ OBJS_RAMTEST := $(filter-out $(BUILDDIR)/$(TARGET)/main.o,$(OBJS)) \
all: $(OUTPUTDIR)/$(OUTPUT_NAME) all: $(OUTPUTDIR)/$(OUTPUT_NAME)
$(eval BIN_SIZE = $(shell wc -c < $(OUTPUTDIR)/$(OUTPUT_NAME))) $(eval BIN_SIZE = $(shell wc -c < $(OUTPUTDIR)/$(OUTPUT_NAME)))
@echo "Payload size is $(BIN_SIZE) bytes (max $(MAX_PAYLOAD_SIZE) for RCM)" @echo "Payload size is $(BIN_SIZE) bytes (max $(MAX_PAYLOAD_SIZE) for RCM)"
@if [ $(BIN_SIZE) -gt $(MAX_PAYLOAD_SIZE) ]; then echo "WARNING: payload exceeds the RCM size limit"; fi @if [ $(BIN_SIZE) -gt $(MAX_PAYLOAD_SIZE) ]; then echo "ERROR: payload exceeds the RCM size limit"; exit 1; fi
clean: clean:
@rm -rf $(BUILDDIR) @rm -rf $(BUILDDIR)
+8 -3
View File
@@ -56,12 +56,10 @@ static u32 _putn(char *buffer, u32 v, int base, char fill, int fcnt) {
return _puts(buffer, p); return _puts(buffer, p);
} }
u32 s_printf(char *buffer, const char *fmt, ...) { u32 s_vprintf(char *buffer, const char *fmt, va_list ap) {
va_list ap;
int fill, fcnt; int fill, fcnt;
u32 count = 0; u32 count = 0;
va_start(ap, fmt);
while(*fmt) { while(*fmt) {
if (*fmt == '%') { if (*fmt == '%') {
fmt++; fmt++;
@@ -118,6 +116,13 @@ u32 s_printf(char *buffer, const char *fmt, ...) {
out: out:
buffer[count] = 0; buffer[count] = 0;
return count;
}
u32 s_printf(char *buffer, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
u32 count = s_vprintf(buffer, fmt, ap);
va_end(ap); va_end(ap);
return count; return count;
} }
+2
View File
@@ -18,7 +18,9 @@
#define _SPRINTF_H_ #define _SPRINTF_H_
#include "types.h" #include "types.h"
#include <stdarg.h>
u32 s_printf(char *buffer, const char *fmt, ...); u32 s_printf(char *buffer, const char *fmt, ...);
u32 s_vprintf(char *buffer, const char *fmt, va_list ap);
#endif #endif
+13 -7
View File
@@ -9,14 +9,15 @@
#include <string.h> #include <string.h>
#include <utils/sprintf.h> #include <utils/sprintf.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
#define FS_BUFFER_SIZE 0x100000 // 1MB copy buffer #define FS_BUFFER_SIZE 0x100000 // 1MB copy buffer
#define LOG_BUFFER_SIZE 512 #define LOG_BUFFER_SIZE 1024 // fits two 255-char paths plus text
#define LOG_SYNC_EVERY 16
// Log file handle // Log file handle
static FIL log_file; static FIL log_file;
static bool log_enabled = false; static bool log_enabled = false;
static u32 log_lines;
static char log_buf[LOG_BUFFER_SIZE]; static char log_buf[LOG_BUFFER_SIZE];
// Initialize log file // Initialize log file
@@ -24,6 +25,7 @@ void log_init(const char *path) {
int res = f_open(&log_file, path, FA_WRITE | FA_CREATE_ALWAYS); int res = f_open(&log_file, path, FA_WRITE | FA_CREATE_ALWAYS);
if (res == FR_OK) { if (res == FR_OK) {
log_enabled = true; log_enabled = true;
log_lines = 0;
log_write("=== OmniNX Installer Log ===\n\n"); log_write("=== OmniNX Installer Log ===\n\n");
} }
} }
@@ -44,15 +46,19 @@ void log_write(const char *fmt, ...) {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
// Format the message // BDK formatter (no newlib printf). Callers keep paths <= 255 chars.
vsnprintf(log_buf, LOG_BUFFER_SIZE, fmt, args); u32 len = s_vprintf(log_buf, fmt, args);
va_end(args); va_end(args);
// Write to file
UINT bw; UINT bw;
f_write(&log_file, log_buf, strlen(log_buf), &bw); f_write(&log_file, log_buf, len, &bw);
f_sync(&log_file); // Flush to ensure data is written if (++log_lines % LOG_SYNC_EVERY == 0)
f_sync(&log_file);
}
bool log_is_enabled(void) {
return log_enabled;
} }
// Convert FatFS error code to string // Convert FatFS error code to string
+1
View File
@@ -18,3 +18,4 @@ int folder_delete(const char *path);
void log_init(const char *path); void log_init(const char *path);
void log_close(void); void log_close(void);
void log_write(const char *fmt, ...); void log_write(const char *fmt, ...);
bool log_is_enabled(void);
+31 -2
View File
@@ -289,7 +289,9 @@ int folder_copy_with_progress_v2(const char *src, const char *dst, const char *d
install_set_color(COLOR_WHITE); install_set_color(COLOR_WHITE);
// Perform the copy with progress updates // Perform the copy with progress updates
log_write("COPY TREE %s -> %s (%d Eintraege)\n", src, dst, (u32)total);
res = folder_copy_progress_recursive(src, dst, &copied, total, start_x, start_y, display_name, &last_percent); res = folder_copy_progress_recursive(src, dst, &copied, total, start_x, start_y, display_name, &last_percent);
log_write("COPY TREE %s: %s\n", src, fs_error_str(res));
// Final update - overwrite the same line // Final update - overwrite the same line
gfx_con_setpos(start_x, start_y); gfx_con_setpos(start_x, start_y);
@@ -499,6 +501,7 @@ int delete_path_lists_grouped(const char *folder_display_name, ...) {
res = f_unlink(path); res = f_unlink(path);
} }
log_write("DELETE %s: %s\n", path, fs_error_str(res));
if (res == FR_OK || res == FR_NO_FILE) if (res == FR_OK || res == FR_NO_FILE)
deleted++; deleted++;
else else
@@ -1343,6 +1346,7 @@ static void install_extras_post_copy(void)
} }
#define INSTALL_DEBUG_INI "sd:/config/omninx/debug.ini" #define INSTALL_DEBUG_INI "sd:/config/omninx/debug.ini"
#define INSTALL_LOG_PATH "sd:/config/omninx/install.log"
typedef struct { typedef struct {
bool active; bool active;
@@ -1356,6 +1360,7 @@ typedef struct {
bool skip_update_staging_cleanup; bool skip_update_staging_cleanup;
bool skip_update_horizon_oc; bool skip_update_horizon_oc;
bool skip_hekate_8gb_post_copy; bool skip_hekate_8gb_post_copy;
bool log;
} install_debug_opts_t; } install_debug_opts_t;
static void install_debug_load(install_debug_opts_t *d) static void install_debug_load(install_debug_opts_t *d)
@@ -1397,6 +1402,8 @@ static void install_debug_load(install_debug_opts_t *d)
d->skip_update_horizon_oc = install_ini_kv_truth(kv->val); d->skip_update_horizon_oc = install_ini_kv_truth(kv->val);
else if (strcmp(kv->key, "skip_hekate_8gb_post_copy") == 0) else if (strcmp(kv->key, "skip_hekate_8gb_post_copy") == 0)
d->skip_hekate_8gb_post_copy = install_ini_kv_truth(kv->val); d->skip_hekate_8gb_post_copy = install_ini_kv_truth(kv->val);
else if (strcmp(kv->key, "log") == 0)
d->log = install_ini_kv_truth(kv->val);
} }
break; break;
} }
@@ -1405,7 +1412,7 @@ static void install_debug_load(install_debug_opts_t *d)
d->active = d->skip_clean_backup || d->skip_clean_wipe || d->skip_clean_restore d->active = d->skip_clean_backup || d->skip_clean_wipe || d->skip_clean_restore
|| d->skip_clean_install || d->skip_clean_staging_cleanup || d->skip_update_cleanup || d->skip_clean_install || d->skip_clean_staging_cleanup || d->skip_update_cleanup
|| d->skip_update_install || d->skip_update_staging_cleanup || d->skip_update_horizon_oc || d->skip_update_install || d->skip_update_staging_cleanup || d->skip_update_horizon_oc
|| d->skip_hekate_8gb_post_copy; || d->skip_hekate_8gb_post_copy || d->log;
} }
static void install_debug_print_banner(const install_debug_opts_t *d) static void install_debug_print_banner(const install_debug_opts_t *d)
@@ -1435,17 +1442,39 @@ static void install_debug_print_banner(const install_debug_opts_t *d)
gfx_printf(" ueberspringe: HorizonOC Update (Backup/Restore)\n"); gfx_printf(" ueberspringe: HorizonOC Update (Backup/Restore)\n");
if (d->skip_hekate_8gb_post_copy) if (d->skip_hekate_8gb_post_copy)
gfx_printf(" ueberspringe: extras RAM / Hekate-Auswahl / Post-Copy\n"); gfx_printf(" ueberspringe: extras RAM / Hekate-Auswahl / Post-Copy\n");
if (d->log)
gfx_printf(" Log: %s\n", INSTALL_LOG_PATH);
install_set_color(COLOR_WHITE); install_set_color(COLOR_WHITE);
gfx_printf("\n"); gfx_printf("\n");
} }
static int perform_installation_steps(omninx_variant_t pack_variant, install_mode_t mode, const install_debug_opts_t *d);
// Main installation function // Main installation function
int perform_installation(omninx_variant_t pack_variant, install_mode_t mode) { int perform_installation(omninx_variant_t pack_variant, install_mode_t mode) {
int res;
install_debug_opts_t dbg; install_debug_opts_t dbg;
install_debug_load(&dbg); install_debug_load(&dbg);
install_debug_print_banner(&dbg); install_debug_print_banner(&dbg);
if (dbg.log) {
log_init(INSTALL_LOG_PATH);
log_write("Version: %s\nModus: %s\nVariante: %d\n\n", VERSION,
mode == INSTALL_MODE_UPDATE ? "Update" : "Clean", (u32)pack_variant);
}
int res = perform_installation_steps(pack_variant, mode, &dbg);
if (log_is_enabled()) {
log_write("\n=== Ende: res=%d (%s) ===\n", (u32)res, fs_error_str(res));
log_close();
}
return res;
}
static int perform_installation_steps(omninx_variant_t pack_variant, install_mode_t mode, const install_debug_opts_t *d) {
int res;
const install_debug_opts_t dbg = *d;
if (mode == INSTALL_MODE_UPDATE) { if (mode == INSTALL_MODE_UPDATE) {
if (pack_variant == VARIANT_OC && !dbg.skip_update_horizon_oc) { if (pack_variant == VARIANT_OC && !dbg.skip_update_horizon_oc) {
bool had_horizon_cfg = install_path_exists(HORIZON_OC_CONFIG_PATH); bool had_horizon_cfg = install_path_exists(HORIZON_OC_CONFIG_PATH);