Nyx: emuMMC Manage window, Tools UI, and misc updates

- Add gui_emu_tools: emuMMC Manage window with correct positioning (LV_PROTECT_PARENT + re-parent to win)
- Tools: single SD button (tap = SD partition manager, 3s hold = eMMC)
- Remove emuSD from Nyx UI (tabs, UMS, partition manager); keep bootloader emusd
- Shorten Create emuMMC description text by one character
- Storage/build/config and dependency updates

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-02-20 20:49:48 +01:00
parent 4eead2c14d
commit fed7f05831
81 changed files with 6932 additions and 3462 deletions

View File

@@ -22,6 +22,7 @@
#include <bdk.h>
#include "config.h"
#include "gfx/gfx.h"
#include "gfx/logos.h"
#include "gfx/tui.h"
#include "hos/hos.h"
@@ -31,9 +32,11 @@
#include <libs/compr/blz.h>
#include <libs/fatfs/ff.h>
#include "storage/emummc.h"
#include <storage/boot_storage.h>
#include "frontend/fe_tools.h"
#include "frontend/fe_info.h"
#include "storage/emusd.h"
hekate_config h_cfg;
boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg;
@@ -92,7 +95,6 @@ static void _check_power_off_from_hos()
// This is a safe and unused DRAM region for our payloads.
#define RELOC_META_OFF 0x7C
#define PATCHED_RELOC_SZ 0x94
#define VERSION_RCFG_OFF 0x120
#define PATCHED_RELOC_STACK 0x40007000
#define PATCHED_RELOC_ENTRY 0x40010000
#define EXT_PAYLOAD_ADDR 0xC0000000
@@ -110,7 +112,7 @@ static void _reloc_append(u32 payload_dst, u32 payload_src, u32 payload_size)
relocator->ep = payload_dst;
}
bool is_ipl_updated(void *buf, u32 size, const char *path, bool force)
bool is_ipl_updated(void *buf, const char *path, bool force)
{
ipl_ver_meta_t *update_ft = (ipl_ver_meta_t *)(buf + PATCHED_RELOC_SZ + sizeof(boot_cfg_t));
@@ -120,32 +122,28 @@ bool is_ipl_updated(void *buf, u32 size, const char *path, bool force)
// Check if newer version.
if (!force && magic_valid)
{
// Copy reserved config.
if (size && !is_valid_old && memcmp((u8 *)(IPL_LOAD_ADDR + VERSION_RCFG_OFF), (u8 *)(buf + VERSION_RCFG_OFF), sizeof(rsvd_cfg_t)))
{
memcpy((u8 *)(buf + VERSION_RCFG_OFF), (u8 *)(IPL_LOAD_ADDR + VERSION_RCFG_OFF), sizeof(rsvd_cfg_t));
sd_save_to_file(buf, size, path);
}
if (byte_swap_32(update_ft->version) > byte_swap_32(ipl_ver.version))
return false;
}
// Update if old or broken.
if (force_update || is_valid_old)
{
boot_cfg_t tmp_cfg;
FIL fp;
reloc_meta_t *reloc = (reloc_meta_t *)(IPL_LOAD_ADDR + RELOC_META_OFF);
boot_cfg_t *tmp_cfg = zalloc(sizeof(boot_cfg_t));
f_open(&fp, path, FA_WRITE | FA_CREATE_ALWAYS);
f_write(&fp, (u8 *)reloc->start, reloc->end - reloc->start, NULL);
// Write needed tag in case injected ipl uses old versioning.
f_write(&fp, "ICTC49", 6, NULL);
// Reset boot storage configuration.
memcpy(&tmp_cfg, (u8 *)(reloc->start + PATCHED_RELOC_SZ), sizeof(boot_cfg_t));
memset((u8 *)(reloc->start + PATCHED_RELOC_SZ), 0, sizeof(boot_cfg_t));
f_lseek(&fp, PATCHED_RELOC_SZ);
f_write(&fp, tmp_cfg, sizeof(boot_cfg_t), NULL);
sd_save_to_file((u8 *)reloc->start, reloc->end - reloc->start, path);
// Restore boot storage configuration.
memcpy((u8 *)(reloc->start + PATCHED_RELOC_SZ), &tmp_cfg, sizeof(boot_cfg_t));
f_close(&fp);
free(tmp_cfg);
}
return true;
@@ -157,10 +155,8 @@ static void _launch_payload(char *path, bool update, bool clear_screen)
gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0);
// Read payload.
u32 size = 0;
void *buf = sd_file_read(path, &size);
if (!buf)
FIL fp;
if (f_open(&fp, path, FA_READ))
{
gfx_con.mute = false;
EPRINTFARGS("Payload file is missing!\n(%s)", path);
@@ -168,8 +164,9 @@ static void _launch_payload(char *path, bool update, bool clear_screen)
goto out;
}
if (update && is_ipl_updated(buf, size, path, false))
goto out;
// Read and copy the payload to our chosen address
void *buf;
u32 size = f_size(&fp);
// Check if it safely fits IRAM.
if (size > 0x30000)
@@ -180,7 +177,21 @@ static void _launch_payload(char *path, bool update, bool clear_screen)
goto out;
}
if (f_read(&fp, buf, size, NULL))
{
f_close(&fp);
goto out;
}
f_close(&fp);
if (update && is_ipl_updated(buf, path, false))
goto out;
boot_storage_end();
sd_end();
emmc_end();
// Copy the payload to our chosen address.
memcpy((void *)RCM_PAYLOAD_ADDR, buf, size);
@@ -209,7 +220,6 @@ static void _launch_payload(char *path, bool update, bool clear_screen)
(*payload_ptr)();
out:
free(buf);
if (!update)
{
gfx_con.mute = false;
@@ -228,15 +238,15 @@ static void _launch_payloads()
gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0);
if (!sd_mount())
goto failed_sd_mount;
if (!boot_storage_mount())
goto failed_boot_storage_mount;
ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3));
dir = (char *)malloc(256);
memcpy(dir, "bootloader/payloads", 20);
filelist = dirlist(dir, NULL, 0);
filelist = dirlist(dir, NULL, false, false);
u32 i = 0;
@@ -272,7 +282,7 @@ static void _launch_payloads()
free(ments);
free(dir);
free(filelist);
sd_end();
boot_storage_end();
return;
}
@@ -288,11 +298,11 @@ static void _launch_payloads()
_launch_payload(dir, false, true);
}
failed_sd_mount:
failed_boot_storage_mount:
free(dir);
free(ments);
free(filelist);
sd_end();
boot_storage_end();
btn_wait();
}
@@ -302,6 +312,7 @@ static void _launch_ini_list()
u8 max_entries = 61;
char *special_path = NULL;
char *emummc_path = NULL;
char *emusd_path = NULL;
ment_t *ments = NULL;
ini_sec_t *cfg_sec = NULL;
@@ -310,7 +321,7 @@ static void _launch_ini_list()
gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0);
if (!sd_mount())
if (!boot_storage_mount())
goto parse_failed;
// Check that ini files exist and parse them.
@@ -366,13 +377,22 @@ static void _launch_ini_list()
h_cfg.emummc_force_disable = atoi(kv->val);
else if (!strcmp("emupath", kv->key))
emummc_path = kv->val;
else if (!strcmp("emusdpath", kv->key))
emusd_path = kv->val;
}
// TODO: also check emuSD path
if (emummc_path && !emummc_set_path(emummc_path))
{
EPRINTF("emupath is wrong!");
goto wrong_emupath;
}
if (emusd_path && !emusd_set_path(emusd_path)){
EPRINTFARGS("path: %s", emusd_path);
EPRINTF("error: emusdpath is wrong!");
goto wrong_emupath;
}
}
if (!cfg_sec)
@@ -415,9 +435,15 @@ parse_failed:
wrong_emupath:
if (emummc_path)
{
sd_mount();
boot_storage_mount();
emummc_load_cfg(); // Reload emuMMC config in case of emupath.
}
if (emusd_path)
{
boot_storage_mount();
emusd_load_cfg();
}
}
out:
@@ -431,6 +457,7 @@ static void _launch_config()
u8 max_entries = 61;
char *special_path = NULL;
char *emummc_path = NULL;
char *emusd_path = NULL;
ment_t *ments = NULL;
ini_sec_t *cfg_sec = NULL;
@@ -440,11 +467,12 @@ static void _launch_config()
gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0);
if (!sd_mount())
if (!boot_storage_mount())
goto parse_failed;
// Load emuMMC configuration.
emummc_load_cfg();
emusd_load_cfg();
// Parse main configuration.
ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false);
@@ -511,6 +539,8 @@ static void _launch_config()
h_cfg.emummc_force_disable = atoi(kv->val);
if (!strcmp("emupath", kv->key))
emummc_path = kv->val;
if (!strcmp("emusdpath", kv->key))
emusd_path = kv->val;
}
if (emummc_path && !emummc_set_path(emummc_path))
@@ -518,12 +548,19 @@ static void _launch_config()
EPRINTF("emupath is wrong!");
goto wrong_emupath;
}
if (emusd_path && !emusd_set_path(emusd_path))
{
EPRINTFARGS("path: %s", emusd_path);
EPRINTF("error: emusdpath is wrong!");
goto wrong_emupath;
}
}
if (!cfg_sec)
{
free(ments);
sd_end();
boot_storage_end();
return;
}
@@ -560,13 +597,19 @@ parse_failed:
wrong_emupath:
if (emummc_path)
{
sd_mount();
boot_storage_mount();
emummc_load_cfg(); // Reload emuMMC config in case of emupath.
}
if (emusd_path)
{
boot_storage_mount();
emusd_load_cfg();
}
}
out:
sd_end();
boot_storage_end();
free(ments);
@@ -579,11 +622,13 @@ out:
static void _nyx_load_run()
{
u8 *nyx = sd_file_read("bootloader/sys/nyx.bin", NULL);
u8 *nyx = boot_storage_file_read("bootloader/sys/nyx.bin", NULL);
if (!nyx)
return;
boot_storage_end();
sd_end();
emmc_end();
render_static_bootlogo();
display_backlight_brightness(h_cfg.backlight, 1000);
@@ -652,13 +697,7 @@ static void _nyx_load_run()
(*nyx_ptr)();
}
void launch_nyx()
{
sd_mount();
_nyx_load_run();
}
static ini_sec_t *_get_ini_sec_from_id(ini_sec_t *ini_sec, char **bootlogoCustomEntry, char **emummc_path)
static ini_sec_t *_get_ini_sec_from_id(ini_sec_t *ini_sec, char **bootlogoCustomEntry, char **emummc_path, char **emusd_path)
{
ini_sec_t *cfg_sec = NULL;
@@ -677,10 +716,13 @@ static ini_sec_t *_get_ini_sec_from_id(ini_sec_t *ini_sec, char **bootlogoCustom
*bootlogoCustomEntry = kv->val;
else if (!strcmp("emummc_force_disable", kv->key))
h_cfg.emummc_force_disable = atoi(kv->val);
else if (!strcmp("emusdpath", kv->key))
*emusd_path = kv->val;
}
if (!cfg_sec)
{
*emummc_path = NULL;
*emusd_path = NULL;
*bootlogoCustomEntry = NULL;
h_cfg.emummc_force_disable = false;
}
@@ -713,7 +755,7 @@ static void _check_for_updated_bootloader()
else
{
u8 *buf = zalloc(0x200);
is_ipl_updated(buf, 0, "bootloader/update.bin", true);
is_ipl_updated(buf, "bootloader/update.bin", true);
free(buf);
}
}
@@ -735,9 +777,12 @@ static void _auto_launch()
u32 boot_entry_id = 0;
ini_sec_t *cfg_sec = NULL;
char *emummc_path = NULL;
char *emusd_path = NULL;
char *bootlogoCustomEntry = NULL;
bool config_entry_found = false;
_check_for_updated_bootloader();
bool boot_from_id = (b_cfg.boot_cfg & BOOT_CFG_FROM_ID) && (b_cfg.boot_cfg & BOOT_CFG_AUTOBOOT_EN);
if (boot_from_id)
b_cfg.id[7] = 0;
@@ -750,6 +795,7 @@ static void _auto_launch()
// Load emuMMC configuration.
emummc_load_cfg();
emusd_load_cfg();
// Parse hekate main configuration.
if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
@@ -805,7 +851,7 @@ static void _auto_launch()
}
if (boot_from_id)
cfg_sec = _get_ini_sec_from_id(ini_sec, &bootlogoCustomEntry, &emummc_path);
cfg_sec = _get_ini_sec_from_id(ini_sec, &bootlogoCustomEntry, &emummc_path, &emusd_path);
else if (h_cfg.autoboot == boot_entry_id && config_entry_found)
{
cfg_sec = ini_sec;
@@ -815,6 +861,8 @@ static void _auto_launch()
bootlogoCustomEntry = kv->val;
else if (!strcmp("emupath", kv->key))
emummc_path = kv->val;
else if (!strcmp("emusdpath", kv->key))
emusd_path = kv->val;
else if (!strcmp("emummc_force_disable", kv->key))
h_cfg.emummc_force_disable = atoi(kv->val);
else if (!strcmp("bootwait", kv->key))
@@ -851,7 +899,7 @@ static void _auto_launch()
continue;
if (boot_from_id)
cfg_sec = _get_ini_sec_from_id(ini_sec_list, &bootlogoCustomEntry, &emummc_path);
cfg_sec = _get_ini_sec_from_id(ini_sec_list, &bootlogoCustomEntry, &emummc_path, &emusd_path);
else if (h_cfg.autoboot == boot_entry_id)
{
h_cfg.emummc_force_disable = false;
@@ -862,6 +910,8 @@ static void _auto_launch()
bootlogoCustomEntry = kv->val;
else if (!strcmp("emupath", kv->key))
emummc_path = kv->val;
else if (!strcmp("emusdpath", kv->key))
emusd_path = kv->val;
else if (!strcmp("emummc_force_disable", kv->key))
h_cfg.emummc_force_disable = atoi(kv->val);
else if (!strcmp("bootwait", kv->key))
@@ -892,11 +942,11 @@ skip_list:
// Check if user set custom logo path at the boot entry.
if (bootlogoCustomEntry)
bitmap = (u8 *)sd_file_read(bootlogoCustomEntry, &fsize);
bitmap = (u8 *)boot_storage_file_read(bootlogoCustomEntry, &fsize);
// Custom entry bootlogo not found, trying default custom one.
if (!bitmap)
bitmap = (u8 *)sd_file_read("bootloader/bootlogo.bmp", &fsize);
bitmap = (u8 *)boot_storage_file_read("bootloader/bootlogo.bmp", &fsize);
if (bitmap)
{
@@ -975,6 +1025,7 @@ skip_list:
}
else
{
// TODO: add boot_cfg for emusd
if (b_cfg.boot_cfg & BOOT_CFG_TO_EMUMMC)
emummc_set_path(b_cfg.emummc_path);
else if (emummc_path && !emummc_set_path(emummc_path))
@@ -984,15 +1035,29 @@ skip_list:
goto wrong_emupath;
}
if (emusd_path && !emusd_set_path(emusd_path))
{
gfx_con.mute = false;
EPRINTFARGS("path: %s", emusd_path);
EPRINTF("error: emusdpath is wrong!");
goto wrong_emupath;
}
hos_launch(cfg_sec);
wrong_emupath:
if (emummc_path || b_cfg.boot_cfg & BOOT_CFG_TO_EMUMMC)
{
sd_mount();
boot_storage_mount();
emummc_load_cfg(); // Reload emuMMC config in case of emupath.
}
if (emusd_path)
{
boot_storage_mount();
emusd_load_cfg();
}
error:
gfx_con.mute = false;
gfx_printf("\nPress any key...\n");
@@ -1157,7 +1222,7 @@ static void _show_errors()
static void _check_low_battery()
{
if (h_cfg.devmode)
if (fuse_read_hw_state() == FUSE_NX_HW_STATE_DEV)
goto out;
int enough_battery;
@@ -1417,7 +1482,6 @@ ment_t ment_top[] = {
MDEF_MENU("Console info", &menu_cinfo),
MDEF_CAPTION("---------------", TXT_CLR_GREY_DM),
MDEF_HANDLER("Reload", _ipl_reload),
MDEF_HANDLER("Load Nyx", launch_nyx),
MDEF_HANDLER_EX("Reboot (OFW)", &STATE_REBOOT_BYPASS_FUSES, power_set_state_ex),
MDEF_HANDLER_EX("Reboot (RCM)", &STATE_REBOOT_RCM, power_set_state_ex),
MDEF_HANDLER_EX("Power off", &STATE_POWER_OFF, power_set_state_ex),
@@ -1450,12 +1514,12 @@ void ipl_main()
uart_wait_xfer(DEBUG_UART_PORT, UART_TX_IDLE);
#endif
// Set bootloader's default configuration.
set_default_configuration();
// Check if battery is enough.
_check_low_battery();
// Set bootloader's default configuration.
set_default_configuration();
// Prep RTC regs for read. Needed for T210B01 R2C.
max77620_rtc_prep_read();
@@ -1466,7 +1530,8 @@ void ipl_main()
bpmp_clk_rate_set(h_cfg.t210b01 ? ipl_ver.rcfg.bclk_t210b01 : ipl_ver.rcfg.bclk_t210);
// Mount SD Card.
h_cfg.errors |= !sd_mount() ? ERR_SD_BOOT_EN : 0;
// TODO: boot storage may not be sd card -> set proper error
h_cfg.errors |= !boot_storage_mount() ? ERR_SD_BOOT_EN : 0;
// Check if watchdog was fired previously.
if (watchdog_fired())
@@ -1506,13 +1571,10 @@ skip_lp0_minerva_config:
// Load saved configuration and auto boot if enabled.
if (!(h_cfg.errors & ERR_SD_BOOT_EN))
{
_check_for_updated_bootloader();
_auto_launch();
}
// Failed to launch Nyx, unmount SD Card.
sd_end();
boot_storage_end();
// Set ram to a freq that doesn't need periodic training.
minerva_change_freq(FREQ_800);