Equalize hekate main and Nyx sd based functions

This commit is contained in:
CTCaer
2020-06-13 18:32:40 +03:00
parent 7dd3178d48
commit 21548545fc
29 changed files with 167 additions and 103 deletions

View File

@@ -171,7 +171,7 @@ int create_config_entry()
}
f_close(&fp);
sd_unmount(false);
sd_unmount();
return 0;
}
@@ -209,7 +209,7 @@ int create_nyx_config_entry()
f_puts("\n", &fp);
f_close(&fp);
sd_unmount(false);
sd_unmount();
return 0;
}

View File

@@ -919,11 +919,11 @@ out:
free(txt_buf);
free(gui->base_path);
if (!partial_sd_full_unmount)
sd_unmount(false);
sd_unmount();
else
{
partial_sd_full_unmount = false;
sd_unmount(true);
sd_end();
}
}
@@ -1503,5 +1503,5 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui)
out:
free(txt_buf);
free(gui->base_path);
sd_unmount(false);
sd_unmount();
}

View File

@@ -491,7 +491,7 @@ out_failed:
out:
free(txt_buf);
free(gui->base_path);
sd_unmount(false);
sd_unmount();
}
static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part_idx, u32 sd_part_off, sdmmc_storage_t *storage, emmc_part_t *part)
@@ -766,5 +766,5 @@ out_failed:
out:
free(txt_buf);
free(gui->base_path);
sd_unmount(false);
sd_unmount();
}

View File

@@ -264,7 +264,7 @@ static void _save_fb_to_bmp()
_save_log_to_bmp(bmp_tmr_name);
sd_unmount(false);
sd_unmount();
free(bitmap);
free(fb);
@@ -814,7 +814,7 @@ static void _launch_hos(u8 autoboot, u8 autoboot_list)
void (*main_ptr)() = (void *)nyx_str->hekate;
sd_unmount(true);
sd_end();
reconfig_hw_workaround(false, 0);
@@ -834,7 +834,7 @@ void reload_nyx()
void (*main_ptr)() = (void *)nyx_str->hekate;
sd_unmount(true);
sd_end();
reconfig_hw_workaround(false, 0);
@@ -1262,7 +1262,7 @@ static lv_res_t _create_mbox_payloads(lv_obj_t *btn)
strcpy(dir, "bootloader/payloads");
char *filelist = dirlist(dir, NULL, false, false);
sd_unmount(false);
sd_unmount();
u32 i = 0;
@@ -1687,7 +1687,7 @@ ini_parsing:
if (curr_btn_idx < 2)
no_boot_entries = true;
sd_unmount(false);
sd_unmount();
free(tmp_path);

View File

@@ -221,7 +221,7 @@ static void _create_mbox_emummc_raw()
sd_mount();
sdmmc_storage_read(&sd_storage, 0, 1, mbr);
sd_unmount(false);
sd_unmount();
sdmmc_storage_t storage;
sdmmc_t sdmmc;
@@ -406,7 +406,7 @@ static void _migrate_sd_raw_emummc_based()
free(tmp);
sd_unmount(false);
sd_unmount();
}
static void _migrate_sd_file_based()
@@ -442,7 +442,7 @@ static void _migrate_sd_file_based()
free(path2);
save_emummc_cfg(0, 0, "emuMMC/EF00");
sd_unmount(false);
sd_unmount();
}
static void _migrate_sd_backup_file_based()
@@ -492,7 +492,7 @@ static void _migrate_sd_backup_file_based()
free(path3);
save_emummc_cfg(0, 0, "emuMMC/BK00");
sd_unmount(false);
sd_unmount();
}
static lv_res_t _create_emummc_mig1_action(lv_obj_t * btns, const char * txt)
@@ -603,8 +603,6 @@ static lv_res_t _create_mbox_emummc_migrate(lv_obj_t *btn)
sd_mount();
sdmmc_storage_read(&sd_storage, 0, 1, mbr);
memcpy(mbr, mbr + 0x1BE, 0x40);
sdmmc_storage_t storage;
sdmmc_t sdmmc;
sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400);
@@ -675,7 +673,7 @@ static lv_res_t _create_mbox_emummc_migrate(lv_obj_t *btn)
else
backup = false;
sd_unmount(false);
sd_unmount();
sdmmc_storage_end(&storage);
if (backup)
@@ -794,7 +792,7 @@ static lv_res_t _save_raw_emummc_cfg_action(lv_obj_t * btn)
}
_create_emummc_saved_mbox();
sd_unmount(false);
sd_unmount();
return LV_RES_INV;
}
@@ -803,7 +801,7 @@ static lv_res_t _save_disable_emummc_cfg_action(lv_obj_t * btn)
{
save_emummc_cfg(0, 0, NULL);
_create_emummc_saved_mbox();
sd_unmount(false);
sd_unmount();
return LV_RES_INV;
}
@@ -812,7 +810,7 @@ static lv_res_t _save_file_emummc_cfg_action(lv_obj_t *btn)
{
save_emummc_cfg(0, 0, lv_list_get_btn_text(btn));
_create_emummc_saved_mbox();
sd_unmount(false);
sd_unmount();
return LV_RES_INV;
}
@@ -1032,7 +1030,7 @@ out0:;
out1:
free(path);
sd_unmount(false);
sd_unmount();
return LV_RES_OK;
}
@@ -1049,7 +1047,7 @@ lv_res_t create_win_emummc_tools(lv_obj_t *btn)
emummc_cfg_t emu_info;
load_emummc_cfg(&emu_info);
sd_unmount(false);
sd_unmount();
static lv_style_t h_style;
lv_style_copy(&h_style, &lv_style_transp);

View File

@@ -104,7 +104,7 @@ static lv_res_t _battery_dump_window_action(lv_obj_t * btn)
emmcsn_path_impl(path, "/dumps", "fuel_gauge.bin", NULL);
error = sd_save_to_file((u8 *)buf, 0x200, path);
sd_unmount(false);
sd_unmount();
}
_create_window_dump_done(error, "fuel_gauge.bin");
@@ -147,7 +147,7 @@ static lv_res_t _bootrom_dump_window_action(lv_obj_t * btn)
memcpy((void*)IPATCH_BASE, ipatch_backup, sizeof(ipatch_backup));
sd_unmount(false);
sd_unmount();
}
_create_window_dump_done(error, "evp_thunks.bin, bootrom_patched.bin, bootrom_unpatched.bin");
@@ -170,7 +170,7 @@ static lv_res_t _fuse_dump_window_action(lv_obj_t * btn)
if (!error)
error = res;
sd_unmount(false);
sd_unmount();
}
_create_window_dump_done(error, "fuse_cached.bin, fuse_array_raw.bin");
@@ -191,7 +191,7 @@ static lv_res_t _kfuse_dump_window_action(lv_obj_t * btn)
emmcsn_path_impl(path, "/dumps", "kfuses.bin", NULL);
error = sd_save_to_file((u8 *)buf, KFUSE_NUM_WORDS * 4, path);
sd_unmount(false);
sd_unmount();
}
_create_window_dump_done(error, "kfuses.bin");
@@ -210,7 +210,7 @@ static lv_res_t _tsec_keys_dump_window_action(lv_obj_t * btn)
emmcsn_path_impl(path, "/dumps", "tsec_keys.bin", NULL);
error = sd_save_to_file(tsec_keys, 0x10 * 2, path);
sd_unmount(false);
sd_unmount();
}
_create_window_dump_done(error, "tsec_keys.bin");
@@ -798,7 +798,7 @@ static lv_res_t _create_mbox_benchmark(bool sd_bench)
lv_obj_del(bar);
if (sd_bench)
sd_unmount(false);
sd_unmount();
else
sdmmc_storage_end(&emmc_storage);
}
@@ -1143,7 +1143,7 @@ static lv_res_t _create_window_sdcard_info_status(lv_obj_t *btn)
lv_obj_align(val4, desc4, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 2, 0);
free(txt_buf);
sd_unmount(false);
sd_unmount();
}
nyx_window_toggle_buttons(win, false);

View File

@@ -277,7 +277,7 @@ static void _create_autoboot_window()
}
}
sd_unmount(false);
sd_unmount();
}
static lv_res_t _autoboot_hide_delay_action(lv_obj_t *btn)
@@ -751,7 +751,7 @@ static lv_res_t _joycon_info_dump_action(lv_obj_t * btn)
f_close(&fp);
}
sd_unmount(false);
sd_unmount();
}
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);

View File

@@ -341,7 +341,7 @@ static void usb_gadget_set_text(void *lbl, const char *text)
static lv_res_t _action_hid_jc(lv_obj_t *btn)
{
// Reduce BPMP, RAM and backlight and power off SDMMC1 to conserve power.
sd_unmount(true);
sd_end();
minerva_change_freq(FREQ_800);
bpmp_clk_rate_set(BPMP_CLK_NORMAL);
display_backlight_brightness(10, 1000);
@@ -365,7 +365,7 @@ static lv_res_t _action_hid_jc(lv_obj_t *btn)
static lv_res_t _action_hid_touch(lv_obj_t *btn)
{
// Reduce BPMP, RAM and backlight and power off SDMMC1 to conserve power.
sd_unmount(true);
sd_end();
minerva_change_freq(FREQ_800);
bpmp_clk_rate_set(BPMP_CLK_NORMAL);
display_backlight_brightness(10, 1000);
@@ -484,7 +484,7 @@ static lv_res_t _action_ums_emuemmc_boot0(lv_obj_t *btn)
}
}
}
sd_unmount(false);
sd_unmount();
if (error)
_create_mbox_ums_error(error);
@@ -526,7 +526,7 @@ static lv_res_t _action_ums_emuemmc_boot1(lv_obj_t *btn)
}
}
}
sd_unmount(false);
sd_unmount();
if (error)
_create_mbox_ums_error(error);
@@ -578,7 +578,7 @@ static lv_res_t _action_ums_emuemmc_gpp(lv_obj_t *btn)
}
}
}
sd_unmount(false);
sd_unmount();
if (error)
_create_mbox_ums_error(error);
@@ -913,7 +913,7 @@ static lv_res_t _create_window_unset_abit_tool(lv_obj_t *btn)
u32 total[2] = { 0 };
_fix_attributes(lb_val, path, total);
sd_unmount(false);
sd_unmount();
lv_obj_t *desc2 = lv_cont_create(win, NULL);
lv_obj_set_size(desc2, LV_HOR_RES * 10 / 11, LV_VER_RES - (LV_DPI * 11 / 7) * 4);
@@ -1357,7 +1357,7 @@ out_free:
free(txt_buf);
free(txt_buf2);
sdmmc_storage_end(&storage);
sd_unmount(false);
sd_unmount();
if (kb >= KB_FIRMWARE_VERSION_620)
se_aes_key_clear(8);

View File

@@ -511,7 +511,7 @@ static lv_res_t _action_delete_linux_installer_files(lv_obj_t * btns, const char
idx++;
}
sd_unmount(false);
sd_unmount();
}
return LV_RES_INV;
@@ -701,7 +701,7 @@ exit:
lv_mbox_add_btns(mbox, mbox_btn_map2, _action_delete_linux_installer_files);
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
sd_unmount(false);
sd_unmount();
}
return LV_RES_INV;
@@ -838,7 +838,7 @@ error:
exit:
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
sd_unmount(false);
sd_unmount();
return LV_RES_OK;
}
@@ -860,7 +860,7 @@ static lv_res_t _action_reboot_twrp(lv_obj_t * btns, const char * txt)
void (*main_ptr)() = (void *)nyx_str->hekate;
sd_unmount(true);
sd_end();
reconfig_hw_workaround(false, 0);
@@ -1104,7 +1104,7 @@ error:
free(txt_buf);
sd_unmount(false);
sd_unmount();
}
return LV_RES_INV;
@@ -1345,7 +1345,7 @@ static lv_res_t _create_mbox_start_partitioning(lv_obj_t *btn)
lv_label_set_text(lbl_paths[0], " ");
manual_system_maintenance(true);
sd_unmount(true);
sd_end();
while (!(btn_wait() & BTN_POWER));
@@ -1416,7 +1416,7 @@ static lv_res_t _create_mbox_start_partitioning(lv_obj_t *btn)
manual_system_maintenance(true);
_prepare_and_flash_mbr_gpt();
sd_unmount(false);
sd_unmount();
lv_label_set_text(lbl_status, "#00DDFF Status:# Done!");
manual_system_maintenance(true);
@@ -1891,7 +1891,7 @@ static lv_res_t _action_fix_mbr(lv_obj_t *btn)
memcpy(&mbr[1], &mbr[0], sizeof(mbr_t));
sd_unmount(false);
sd_unmount();
if (memcmp(&gpt.header.signature, "EFI PART", 8))
{
@@ -2013,7 +2013,7 @@ static lv_res_t _action_fix_mbr(lv_obj_t *btn)
// Write MBR.
sd_mount();
sdmmc_storage_write(&sd_storage, 0, 1, &mbr[1]);
sd_unmount(false);
sd_unmount();
lv_label_set_text(lbl_status, "#96FF00 The new Hybrid MBR was written successfully!#");
}
else
@@ -2289,7 +2289,7 @@ lv_res_t create_window_partition_manager(lv_obj_t *btn)
free(txt_buf);
sd_unmount(false);
sd_unmount();
return LV_RES_OK;
}

View File

@@ -211,7 +211,7 @@ int reboot_to_sept(const u8 *tsec_fw, u32 kb)
f_close(&fp);
}
sd_unmount(true);
sd_end();
u32 pk1t_sept = SEPT_PK1T_ADDR - (ALIGN(PATCHED_RELOC_SZ, 0x10) + WB_RST_SIZE);

View File

@@ -76,7 +76,7 @@ uintptr_t ianos_loader(bool sdmount, char *path, elfType_t type, void *moduleCon
fileBuf = sd_file_read(path, NULL);
if (sdmount)
sd_unmount(true);
sd_end();
if (!fileBuf)
goto elfLoadFinalOut;
@@ -94,7 +94,7 @@ uintptr_t ianos_loader(bool sdmount, char *path, elfType_t type, void *moduleCon
case EXEC_ELF:
case AR64_ELF:
elfBuf = (void *)DRAM_LIB_ADDR;
sd_unmount(true);
sd_end;
break;
default:
elfBuf = malloc(ctx.memsz); // Aligned to 0x10 by default.

View File

@@ -180,7 +180,7 @@ lv_res_t launch_payload(lv_obj_t *list)
f_close(&fp);
sd_unmount(true);
sd_end();
if (size < 0x30000)
{
@@ -203,7 +203,7 @@ lv_res_t launch_payload(lv_obj_t *list)
}
out:
sd_unmount(false);
sd_unmount();
return LV_RES_OK;
}
@@ -378,7 +378,7 @@ void nyx_init_load_res()
// Load background resource if any.
hekate_bg = bmp_to_lvimg_obj("bootloader/res/background.bmp");
sd_unmount(false);
sd_unmount();
h_cfg.rcm_patched = fuse_check_patched_rcm();
}

View File

@@ -120,7 +120,7 @@ bool sd_initialize(bool power_cycle)
}
else
{
sd_errors[0]++; // Increment init errors.
sd_errors[SD_ERROR_INIT_FAIL]++;
if (sd_mode == SD_INIT_FAIL)
break;
@@ -146,6 +146,7 @@ bool sd_mount()
if (res)
{
gfx_con.mute = false;
EPRINTF("Failed to init SD card.");
if (!sdmmc_get_sd_inserted())
EPRINTF("Make sure that it is inserted.");
@@ -163,6 +164,7 @@ bool sd_mount()
}
else
{
gfx_con.mute = false;
EPRINTFARGS("Failed to mount SD card (FatFS Error %d).\nMake sure that a FAT partition exists..", res);
}
}
@@ -170,7 +172,7 @@ bool sd_mount()
return false;
}
void sd_unmount(bool deinit)
static void _sd_deinit(bool deinit)
{
if (sd_mode == SD_INIT_FAIL)
sd_mode = SD_UHS_SDR104;
@@ -187,6 +189,9 @@ void sd_unmount(bool deinit)
}
}
void sd_unmount() { _sd_deinit(false); }
void sd_end() { _sd_deinit(true); }
void *sd_file_read(const char *path, u32 *fsize)
{
FIL fp;

View File

@@ -49,7 +49,8 @@ u32 sd_get_mode();
int sd_init_retry(bool power_cycle);
bool sd_initialize(bool power_cycle);
bool sd_mount();
void sd_unmount(bool deinit);
void sd_unmount();
void sd_end();
void *sd_file_read(const char *path, u32 *fsize);
int sd_save_to_file(void *buf, u32 size, const char *filename);

View File

@@ -136,7 +136,7 @@ void panic(u32 val)
void reboot_normal()
{
sd_unmount(true);
sd_end();
reconfig_hw_workaround(false, 0);
nyx_str->mtc_cfg.init_done = 0;
@@ -146,7 +146,7 @@ void reboot_normal()
void reboot_rcm()
{
sd_unmount(true);
sd_end();
reconfig_hw_workaround(false, 0);
PMC(APBDEV_PMC_SCRATCH0) = PMC_SCRATCH0_MODE_RCM;
@@ -158,7 +158,7 @@ void reboot_rcm()
void power_off()
{
sd_unmount(true);
sd_end();
reconfig_hw_workaround(false, 0);
// Stop the alarm, in case we injected and powered off too fast.