From 1c7792e3864b70cc1f1bd95ac25d403d83b6f9a9 Mon Sep 17 00:00:00 2001 From: NaGa Date: Wed, 8 Apr 2026 17:03:38 +0200 Subject: [PATCH] emuSD & other fixes --- bdk/storage/boot_storage.c | 4 +++- bootloader/storage/emusd.c | 21 ++++++++++++------- nyx/nyx_gui/frontend/fe_emummc_tools.c | 20 ++++++++++++------ nyx/nyx_gui/frontend/fe_emusd_tools.c | 4 ++-- nyx/nyx_gui/frontend/gui.c | 1 + nyx/nyx_gui/frontend/gui_emummc_tools.c | 2 +- .../frontend/gui_tools_partition_manager.c | 21 ++++++++----------- 7 files changed, 43 insertions(+), 30 deletions(-) diff --git a/bdk/storage/boot_storage.c b/bdk/storage/boot_storage.c index a8b57eae..674bba61 100644 --- a/bdk/storage/boot_storage.c +++ b/bdk/storage/boot_storage.c @@ -66,6 +66,8 @@ static bool _boot_storage_initialize(){ } static void _boot_storage_end(bool deinit){ + BYTE prev_drive = drive_cur; + if(boot_storage_get_mounted()){ switch(drive_cur){ case DRIVE_SD: @@ -82,7 +84,7 @@ static void _boot_storage_end(bool deinit){ } if(deinit){ - switch(drive_cur){ + switch(prev_drive){ case DRIVE_SD: sd_end(); break; diff --git a/bootloader/storage/emusd.c b/bootloader/storage/emusd.c index 0f5a98d3..38e56b0e 100644 --- a/bootloader/storage/emusd.c +++ b/bootloader/storage/emusd.c @@ -36,7 +36,7 @@ void emusd_load_cfg() } LIST_INIT(ini_sections); - if(ini_parse(&ini_sections, "emuSD/emusd.ini", false)) + if(!ini_parse(&ini_sections, "emuSD/emusd.ini", false)) { LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) { @@ -77,6 +77,7 @@ bool emusd_mount() { EPRINTFARGS("emusd mount fail %d", res); return false; } + emusd_mounted = true; return true; } @@ -89,16 +90,15 @@ bool emusd_unmount() { bool emusd_set_path(char *path) { FIL fp; bool found = false; - // TODO: use emu_sd.file_path instead - strcat(emu_sd_cfg.emummc_file_based_path, ""); + strcpy(emu_sd_cfg.emummc_file_based_path, ""); strcpy(emu_sd_cfg.emummc_file_based_path, path); - strcat(emu_sd_cfg.emummc_file_based_path, "/raw_emmc_based"); + strcat(emu_sd_cfg.emummc_file_based_path, "/raw_based"); if(!f_open(&fp, emu_sd_cfg.emummc_file_based_path, FA_READ)) { if(!f_read(&fp, &emu_sd_cfg.sector, 4, NULL)){ if(emu_sd_cfg.sector){ found = true; - emu_sd_cfg.enabled = 4; + emu_sd_cfg.enabled = 1; goto out; } } @@ -266,11 +266,15 @@ void *emusd_file_read(const char *path, u32 *fsize) { strcpy(path1, "emusd:"); strcat(path1, path); FIL fp; - if (!emusd_get_mounted()) + if (!emusd_get_mounted()) { + free(path1); return NULL; + } - if (f_open(&fp, path, FA_READ) != FR_OK) + if (f_open(&fp, path1, FA_READ) != FR_OK) { + free(path1); return NULL; + } u32 size = f_size(&fp); if (fsize) @@ -282,11 +286,12 @@ void *emusd_file_read(const char *path, u32 *fsize) { { free(buf); f_close(&fp); - + free(path1); return NULL; } f_close(&fp); + free(path1); return buf; } else { diff --git a/nyx/nyx_gui/frontend/fe_emummc_tools.c b/nyx/nyx_gui/frontend/fe_emummc_tools.c index f10cb1b2..d5d0786d 100644 --- a/nyx/nyx_gui/frontend/fe_emummc_tools.c +++ b/nyx/nyx_gui/frontend/fe_emummc_tools.c @@ -1040,12 +1040,17 @@ void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 r sdmmc_storage_t *emu_storage = drive == DRIVE_SD ? &sd_storage : &emmc_storage; - boot_storage_mount(); - - if (drive == DRIVE_SD && !sd_initialize(false)) + if (drive == DRIVE_SD) { - lv_label_set_text(gui->label_info, "#FFDD00 Failed to init SD!#"); - goto out; + if (!sd_mount()) + { + lv_label_set_text(gui->label_info, "#FFDD00 Failed to init SD!#"); + goto out; + } + } + else + { + boot_storage_mount(); } if (!emmc_initialize(false)) @@ -1168,6 +1173,9 @@ out_failed: out: free(txt_buf); free(gui->base_path); - boot_storage_unmount(); + if (drive == DRIVE_SD) + sd_unmount(); + else + boot_storage_unmount(); emmc_end(); } diff --git a/nyx/nyx_gui/frontend/fe_emusd_tools.c b/nyx/nyx_gui/frontend/fe_emusd_tools.c index 0719bead..52ff6bab 100644 --- a/nyx/nyx_gui/frontend/fe_emusd_tools.c +++ b/nyx/nyx_gui/frontend/fe_emusd_tools.c @@ -19,7 +19,7 @@ void load_emusd_cfg(emusd_cfg_t *emu_info){ // Parse emuMMC configuration. LIST_INIT(ini_sections); - if (!ini_parse(&ini_sections, "emuSD/emusd.ini", false)) + if (ini_parse(&ini_sections, "emuSD/emusd.ini", false)) return; LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) @@ -264,7 +264,7 @@ int create_emusd(int part_idx, u32 sector_mbr, u32 sector_start, u32 sector_size f_mkdir(path); s_printf(path + strlen(path), "/RAW_%s%d", drive == DRIVE_SD ? "SD" : "EMMC", part_idx); f_mkdir(path); - strcat(path, "/raw_emmc_based"); + strcat(path, drive == DRIVE_SD ? "/raw_based" : "/raw_emmc_based"); f_open(&f, path, FA_CREATE_ALWAYS | FA_WRITE); f_write(&f, §or_mbr, 4, NULL); diff --git a/nyx/nyx_gui/frontend/gui.c b/nyx/nyx_gui/frontend/gui.c index 643a2254..f8e8a0c8 100644 --- a/nyx/nyx_gui/frontend/gui.c +++ b/nyx/nyx_gui/frontend/gui.c @@ -1281,6 +1281,7 @@ static void _create_tab_about(lv_theme_t * th, lv_obj_t * parent) " (c) 2018-2026, #C7EA46 CTCaer#\n" "\n" "#C7EA46 Nyx# (c) 2019-2026, #C7EA46 CTCaer#\n" + "#C7EA46 Pro# (c) 2025-2026, #C7EA46 Nautilus#, #C7EA46 naga#\n" "\n" "Thanks to: #00CCFF derrek, nedwill, plutoo, #\n" " #00CCFF shuffle2, smea, thexyz, yellows8 #\n" diff --git a/nyx/nyx_gui/frontend/gui_emummc_tools.c b/nyx/nyx_gui/frontend/gui_emummc_tools.c index ab50cfe0..8c705919 100644 --- a/nyx/nyx_gui/frontend/gui_emummc_tools.c +++ b/nyx/nyx_gui/frontend/gui_emummc_tools.c @@ -515,7 +515,7 @@ static void _create_mbox_emummc_emmc_raw() // TODO: should check for emummc guid instead // TODO: currently hard limited to 3 entries s32 gpt_idx = gpt_get_part_by_name(gpt, "emummc", -1); - while(gpt_idx != -1){ + while(gpt_idx != -1 && gpt_ctx.emmc_part_cnt < 3){ u32 offset = gpt->entries[gpt_idx].lba_start; u32 size = gpt->entries[gpt_idx].lba_end - gpt->entries[gpt_idx].lba_start + 1; diff --git a/nyx/nyx_gui/frontend/gui_tools_partition_manager.c b/nyx/nyx_gui/frontend/gui_tools_partition_manager.c index 80c79f14..66ccebda 100644 --- a/nyx/nyx_gui/frontend/gui_tools_partition_manager.c +++ b/nyx/nyx_gui/frontend/gui_tools_partition_manager.c @@ -4381,15 +4381,12 @@ lv_res_t create_window_partition_manager(lv_obj_t *btn, u8 drive) lv_obj_set_hidden(lbl_hos_os, !has_hos_os); lv_coord_t spacing; - if(drive == DRIVE_EMMC){ - if(has_hos_os){ - // adjust spacing when we have 5 sliders - spacing = (LV_DPI / 3) - (lv_obj_get_height(lbl_hos_os) + LV_DPI / 3) / 3; - }else{ - spacing = (LV_DPI / 3) - (lv_obj_get_height(lbl_hos_os) + LV_DPI / 3) / 4; - } + if(has_hos_os){ + // adjust spacing when we have 6 sliders + spacing = (LV_DPI / 3) - (lv_obj_get_height(lbl_hos_os) + LV_DPI / 3) / 3; }else{ - spacing = LV_DPI / 3; + // 5 sliders + spacing = (LV_DPI / 3) - (lv_obj_get_height(lbl_hos_os) + LV_DPI / 3) / 4; } lv_obj_t *lbl_hos = lv_label_create(h1, NULL); @@ -4404,11 +4401,11 @@ lv_res_t create_window_partition_manager(lv_obj_t *btn, u8 drive) lv_obj_t *lbl_emu_sd = lv_label_create( h1, lbl_hos); lv_label_set_static_text(lbl_emu_sd, "#FF00D6 " SYMBOL_DOT " emuSD:#"); lv_obj_align(lbl_emu_sd, lbl_emu, LV_ALIGN_OUT_BOTTOM_LEFT, 0, spacing); - lv_obj_set_hidden(lbl_emu_sd, drive == DRIVE_SD); + lv_obj_set_hidden(lbl_emu_sd, false); lv_obj_t *lbl_l4t = lv_label_create(h1, lbl_hos); lv_label_set_static_text(lbl_l4t, "#00DDFF "SYMBOL_DOT" Linux (EXT4):#"); - lv_obj_align(lbl_l4t, drive == DRIVE_SD ? lbl_emu : lbl_emu_sd, LV_ALIGN_OUT_BOTTOM_LEFT, 0, spacing); + lv_obj_align(lbl_l4t, lbl_emu_sd, LV_ALIGN_OUT_BOTTOM_LEFT, 0, spacing); lv_obj_t *lbl_and = lv_label_create(h1, lbl_hos); lv_label_set_static_text(lbl_and, "#FF8000 "SYMBOL_DOT" Android (USER):#"); @@ -4495,7 +4492,7 @@ lv_res_t create_window_partition_manager(lv_obj_t *btn, u8 drive) lv_slider_set_style(slider_emu_sd, LV_SLIDER_STYLE_KNOB, &bar_emu_sd_btn); lv_obj_align(slider_emu_sd, lbl_emu_sd, LV_ALIGN_IN_LEFT_MID, LV_DPI * 3, 0); lv_slider_set_action(slider_emu_sd, _action_slider_emu_sd); - lv_obj_set_hidden(slider_emu_sd, drive == DRIVE_SD); + lv_obj_set_hidden(slider_emu_sd, false); part_info.slider_emu_sd = slider_emu_sd; // Create HOS OS size lable @@ -4541,7 +4538,7 @@ lv_res_t create_window_partition_manager(lv_obj_t *btn, u8 drive) lv_obj_t *lbl_sl_emu_sd = lv_label_create(h1, lbl_sl_hos); lv_label_set_text(lbl_sl_emu_sd, "#FF00D6 0 GiB#"); lv_obj_align(lbl_sl_emu_sd, slider_emu_sd, LV_ALIGN_OUT_RIGHT_MID, LV_DPI * 4 / 7, 0); - lv_obj_set_hidden(lbl_sl_emu_sd, drive == DRIVE_SD); + lv_obj_set_hidden(lbl_sl_emu_sd, false); part_info.lbl_emu_sd = lbl_sl_emu_sd; // Set partition manager notes.