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
+205 -156

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)
+127 -122
View File
@@ -1,123 +1,128 @@
/* /*
* Copyright (c) 2019-2020 shchmue * Copyright (c) 2019-2020 shchmue
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License, * under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation. * version 2, as published by the Free Software Foundation.
* *
* This program is distributed in the hope it will be useful, but WITHOUT * This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "sprintf.h" #include "sprintf.h"
#include <stdarg.h> #include <stdarg.h>
static void _putc(char *buffer, const char c) { static void _putc(char *buffer, const char c) {
*buffer = c; *buffer = c;
} }
static u32 _puts(char *buffer, const char *s) { static u32 _puts(char *buffer, const char *s) {
u32 count = 0; u32 count = 0;
for (; *s; s++, count++) for (; *s; s++, count++)
_putc(buffer + count, *s); _putc(buffer + count, *s);
return count; return count;
} }
static u32 _putn(char *buffer, u32 v, int base, char fill, int fcnt) { static u32 _putn(char *buffer, u32 v, int base, char fill, int fcnt) {
char buf[0x121]; char buf[0x121];
static const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; static const char digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
char *p; char *p;
int c = fcnt; int c = fcnt;
if (base > 36) if (base > 36)
return 0; return 0;
p = buf + 0x120; p = buf + 0x120;
*p = 0; *p = 0;
do { do {
c--; c--;
*--p = digits[v % base]; *--p = digits[v % base];
v /= base; v /= base;
} while (v); } while (v);
if (fill != 0) { if (fill != 0) {
while (c > 0) { while (c > 0) {
*--p = fill; *--p = fill;
c--; c--;
} }
} }
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;
while(*fmt) {
va_start(ap, fmt); if (*fmt == '%') {
while(*fmt) { fmt++;
if (*fmt == '%') { fill = 0;
fmt++; fcnt = 0;
fill = 0; if ((*fmt >= '0' && *fmt <= '9') || *fmt == ' ') {
fcnt = 0; fcnt = *fmt;
if ((*fmt >= '0' && *fmt <= '9') || *fmt == ' ') { fmt++;
fcnt = *fmt; if (*fmt >= '0' && *fmt <= '9') {
fmt++; fill = fcnt;
if (*fmt >= '0' && *fmt <= '9') { fcnt = *fmt - '0';
fill = fcnt; fmt++;
fcnt = *fmt - '0'; } else {
fmt++; fill = ' ';
} else { fcnt -= '0';
fill = ' '; }
fcnt -= '0'; }
} switch (*fmt) {
} case 'c':
switch (*fmt) { _putc(buffer + count, va_arg(ap, u32));
case 'c': count++;
_putc(buffer + count, va_arg(ap, u32)); break;
count++; case 's':
break; count += _puts(buffer + count, va_arg(ap, char *));
case 's': break;
count += _puts(buffer + count, va_arg(ap, char *)); case 'd':
break; count += _putn(buffer + count, va_arg(ap, u32), 10, fill, fcnt);
case 'd': break;
count += _putn(buffer + count, va_arg(ap, u32), 10, fill, fcnt); case 'p':
break; case 'P':
case 'p': case 'x':
case 'P': case 'X':
case 'x': count += _putn(buffer + count, va_arg(ap, u32), 16, fill, fcnt);
case 'X': break;
count += _putn(buffer + count, va_arg(ap, u32), 16, fill, fcnt); case '%':
break; _putc(buffer + count, '%');
case '%': count++;
_putc(buffer + count, '%'); break;
count++; case '\0':
break; goto out;
case '\0': default:
goto out; _putc(buffer + count, '%');
default: count++;
_putc(buffer + count, '%'); _putc(buffer + count, *fmt);
count++; count++;
_putc(buffer + count, *fmt); break;
count++; }
break; } else {
} _putc(buffer + count, *fmt);
} else { count++;
_putc(buffer + count, *fmt); }
count++; fmt++;
} }
fmt++;
} out:
buffer[count] = 0;
out: return count;
buffer[count] = 0; }
va_end(ap);
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);
return count;
} }
+26 -24
View File
@@ -1,24 +1,26 @@
/* /*
* Copyright (c) 2019-2020 shchmue * Copyright (c) 2019-2020 shchmue
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License, * under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation. * version 2, as published by the Free Software Foundation.
* *
* This program is distributed in the hope it will be useful, but WITHOUT * This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details. * more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _SPRINTF_H_ #ifndef _SPRINTF_H_
#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, ...);
#endif u32 s_vprintf(char *buffer, const char *fmt, va_list ap);
#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);