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

@ -161,7 +161,7 @@ int create_config_entry()
}
f_close(&fp);
sd_unmount();
sd_end();
return 0;
}
@ -268,7 +268,7 @@ out2:;
free(boot_values);
free(boot_text);
sd_unmount();
sd_end();
}
void config_autoboot()
@ -380,7 +380,7 @@ out2:;
free(boot_values);
free(boot_text);
sd_unmount();
sd_end();
if (temp_autoboot == NULL)
return;

View file

@ -574,7 +574,7 @@ static void _dump_emmc_selected(emmcPartType_t dumpType)
gfx_printf("\n%kFinished and verified!%k\nPress any key...\n", 0xFF96FF00, 0xFFCCCCCC);
out:
sd_unmount();
sd_end();
btn_wait();
}
@ -911,7 +911,7 @@ static void _restore_emmc_selected(emmcPartType_t restoreType)
gfx_printf("\n%kFinished and verified!%k\nPress any key...\n", 0xFF96FF00, 0xFFCCCCCC);
out:
sd_unmount();
sd_end();
btn_wait();
}

View file

@ -93,7 +93,7 @@ void print_fuseinfo()
if (!sd_save_to_file((u8 *)words, sizeof(words), path))
gfx_puts("\nfuse_array_raw.bin saved!\n");
sd_unmount();
sd_end();
}
btn_wait();
@ -123,7 +123,7 @@ void print_kfuseinfo()
emmcsn_path_impl(path, "/dumps", "kfuses.bin", NULL);
if (!sd_save_to_file((u8 *)buf, KFUSE_NUM_WORDS * 4, path))
gfx_puts("\nDone!\n");
sd_unmount();
sd_end();
}
btn_wait();
@ -308,7 +308,7 @@ void print_sdcard_info()
gfx_printf("%kFound %s volume:%k\n Free: %d MiB\n Cluster: %d KiB\n",
0xFF00DDFF, sd_fs.fs_type == FS_EXFAT ? "exFAT" : "FAT32", 0xFFCCCCCC,
sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF, (sd_fs.csize > 1) ? (sd_fs.csize >> 1) : 512);
sd_unmount();
sd_end();
}
btn_wait();
@ -410,7 +410,7 @@ void print_tsec_key()
emmcsn_path_impl(path, "/dumps", "tsec_keys.bin", NULL);
if (!sd_save_to_file(keys, 0x10 * 2, path))
gfx_puts("\nDone!\n");
sd_unmount();
sd_end();
}
}
else
@ -576,7 +576,7 @@ void print_battery_info()
EPRINTF("\nError creating fuel.bin file.");
else
gfx_puts("\nDone!\n");
sd_unmount();
sd_end();
}
btn_wait();
@ -645,7 +645,7 @@ void bootrom_ipatches_info()
memcpy((void*)IPATCH_BASE, ipatch_backup, sizeof(ipatch_backup));
sd_unmount();
sd_end();
}
btn_wait();

View file

@ -244,7 +244,7 @@ out_free:
free(loader);
free(pkg2);
sdmmc_storage_end(&storage);
sd_unmount();
sd_end();
if (kb >= KB_FIRMWARE_VERSION_620)
se_aes_key_clear(8);
@ -499,7 +499,7 @@ void _fix_sd_attr(u32 type)
gfx_printf("Traversing all %s files!\nThis may take some time...\n\n", label);
_fix_attributes(path, &total, type, type);
gfx_printf("%kTotal archive bits cleared: %d!%k\n\nDone! Press any key...", 0xFF96FF00, total, 0xFFCCCCCC);
sd_unmount();
sd_end();
}
btn_wait();
}

View file

@ -621,7 +621,7 @@ static bool _get_fs_exfat_compatible(link_t *info)
if (strncmp((const char*)ki->kip1->name, "FS", 2))
continue;
if (!se_calc_sha256(sha_buf, ki->kip1, ki->size))
if (!se_calc_sha256_oneshot(sha_buf, ki->kip1, ki->size))
break;
pkg2_get_ids(&kip_ids, &fs_ids_cnt);
@ -823,9 +823,9 @@ int hos_launch(ini_sec_t *cfg)
u8 kernel_hash[0x20];
// Hash only Kernel when it embeds INI1.
if (!ctxt.new_pkg2)
se_calc_sha256(kernel_hash, ctxt.kernel, ctxt.kernel_size);
se_calc_sha256_oneshot(kernel_hash, ctxt.kernel, ctxt.kernel_size);
else
se_calc_sha256(kernel_hash, ctxt.kernel + PKG2_NEWKERN_START,
se_calc_sha256_oneshot(kernel_hash, ctxt.kernel + PKG2_NEWKERN_START,
pkg2_newkern_ini1_start - PKG2_NEWKERN_START);
ctxt.pkg2_kernel_id = pkg2_identify(kernel_hash);
@ -945,7 +945,7 @@ int hos_launch(ini_sec_t *cfg)
config_exosphere(&ctxt);
// Unmount SD card.
sd_unmount();
sd_end();
// Finalize MC carveout.
if (ctxt.pkg1_id->kb <= KB_FIRMWARE_VERSION_301)

View file

@ -1110,7 +1110,7 @@ const char* pkg2_patch_kips(link_t *info, char* patchNames)
if (shaBuf[0] == 0)
{
if (!se_calc_sha256(shaBuf, ki->kip1, ki->size))
if (!se_calc_sha256_oneshot(shaBuf, ki->kip1, ki->size))
memset(shaBuf, 0, sizeof(shaBuf));
}
@ -1148,7 +1148,7 @@ const char* pkg2_patch_kips(link_t *info, char* patchNames)
#ifdef DEBUG_PRINTING
u32 postDecompTime = get_tmr_us();
if (!se_calc_sha256(shaBuf, ki->kip1, ki->size))
if (!se_calc_sha256_oneshot(shaBuf, ki->kip1, ki->size))
memset(shaBuf, 0, sizeof(shaBuf));
DPRINTF("%dms %s KIP1 size %d hash %08X\n", (postDecompTime-preDecompTime) / 1000, ki->kip1->name, (int)ki->size, __builtin_bswap32(shaBuf[0]));

View file

@ -228,7 +228,7 @@ int reboot_to_sept(const u8 *tsec_fw, u32 kb, ini_sec_t *cfg_sec)
f_close(&fp);
}
sd_unmount();
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();
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();
sd_end();
break;
default:
elfBuf = malloc(ctx.memsz); // Aligned to 0x10 by default.

View file

@ -119,7 +119,7 @@ void check_power_off_from_hos()
u8 hosWakeup = i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_IRQTOP);
if (hosWakeup & MAX77620_IRQ_TOP_RTC_MASK)
{
sd_unmount();
sd_end();
// Stop the alarm, in case we injected too fast.
max77620_rtc_stop_alarm();
@ -249,7 +249,7 @@ int launch_payload(char *path, bool update)
if (update && is_ipl_updated(buf, path, false))
goto out;
sd_unmount();
sd_end();
if (size < 0x30000)
{
@ -284,7 +284,7 @@ int launch_payload(char *path, bool update)
out:
if (!update)
sd_unmount();
sd_end();
return 1;
}
@ -353,7 +353,7 @@ void launch_tools()
free(ments);
free(dir);
free(filelist);
sd_unmount();
sd_end();
return;
}
@ -380,7 +380,7 @@ void launch_tools()
}
out:
sd_unmount();
sd_end();
free(dir);
btn_wait();
@ -618,7 +618,7 @@ void launch_firmware()
if (!cfg_sec)
{
free(ments);
sd_unmount();
sd_end();
return;
}
@ -656,7 +656,7 @@ wrong_emupath:
}
out:
sd_unmount();
sd_end();
h_cfg.emummc_force_disable = false;
@ -673,7 +673,7 @@ void nyx_load_run()
if (!nyx)
return;
sd_unmount();
sd_end();
u32 expected_nyx_ver = ((NYX_VER_MJ + '0') << 24) | ((NYX_VER_MN + '0') << 16) | ((NYX_VER_HF + '0') << 8);
u32 nyx_ver = byte_swap_32(*(u32 *)(nyx + NYX_VER_OFF));
@ -1074,7 +1074,7 @@ out:
nyx_load_run();
sd_unmount();
sd_end();
}
static void _patched_rcm_protection()

View file

@ -168,7 +168,7 @@ out:
int emummc_storage_end(sdmmc_storage_t *storage)
{
sd_unmount();
sd_end();
sdmmc_storage_end(storage);
return 1;

View file

@ -23,13 +23,42 @@
#include "../mem/heap.h"
static bool sd_mounted = false;
static u16 sd_errors[3] = { 0 }; // Init and Read/Write errors.
static u32 sd_mode = SD_UHS_SDR82;
sdmmc_t sd_sdmmc;
sdmmc_storage_t sd_storage;
FATFS sd_fs;
void sd_error_count_increment(u8 type)
{
switch (type)
{
case SD_ERROR_INIT_FAIL:
sd_errors[0]++;
break;
case SD_ERROR_RW_FAIL:
sd_errors[1]++;
break;
case SD_ERROR_RW_RETRY:
sd_errors[2]++;
break;
}
}
u16 *sd_get_error_count()
{
return sd_errors;
}
bool sd_get_card_removed()
{
if (!sdmmc_get_sd_inserted())
return true;
return false;
}
u32 sd_get_mode()
{
return sd_mode;
@ -85,10 +114,15 @@ bool sd_initialize(bool power_cycle)
sd_mode = SD_UHS_SDR82;
break;
}
else if (sd_mode == SD_INIT_FAIL)
break;
else
res = !sd_init_retry(true);
{
sd_errors[SD_ERROR_INIT_FAIL]++;
if (sd_mode == SD_INIT_FAIL)
break;
else
res = !sd_init_retry(true);
}
}
sdmmc_storage_end(&sd_storage);
@ -130,9 +164,11 @@ bool sd_mount()
return false;
}
void sd_unmount()
static void _sd_deinit()
{
sd_mode = SD_UHS_SDR82;
if (sd_mode == SD_INIT_FAIL)
sd_mode = SD_UHS_SDR82;
if (sd_mounted)
{
f_mount(NULL, "", 1);
@ -141,6 +177,9 @@ void sd_unmount()
}
}
void sd_unmount() { _sd_deinit(); }
void sd_end() { _sd_deinit(); }
void *sd_file_read(const char *path, u32 *fsize)
{
FIL fp;

View file

@ -28,17 +28,29 @@ enum
SD_1BIT_HS25 = 1,
SD_4BIT_HS25 = 2,
SD_UHS_SDR82 = 3,
SD_UHS_SDR104 = 4
};
enum
{
SD_ERROR_INIT_FAIL = 0,
SD_ERROR_RW_FAIL = 1,
SD_ERROR_RW_RETRY = 2
};
extern sdmmc_t sd_sdmmc;
extern sdmmc_storage_t sd_storage;
extern FATFS sd_fs;
void sd_error_count_increment(u8 type);
u16 *sd_get_error_count();
bool sd_get_card_removed();
u32 sd_get_mode();
int sd_init_retry(bool power_cycle);
bool sd_initialize(bool power_cycle);
bool sd_mount();
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

@ -187,6 +187,8 @@ reinit_try:
else
retries--;
sd_error_count_increment(SD_ERROR_RW_RETRY);
msleep(50);
} while (retries);
@ -194,10 +196,17 @@ reinit_try:
if (storage->sdmmc->id == SDMMC_1)
{
int res;
sd_error_count_increment(SD_ERROR_RW_FAIL);
if (!first_reinit)
res = sd_initialize(true);
else
{
res = sd_init_retry(true);
if (!res)
sd_error_count_increment(SD_ERROR_INIT_FAIL);
}
retries = 3;
first_reinit = true;

View file

@ -137,7 +137,7 @@ void reboot_normal()
{
bpmp_mmu_disable();
sd_unmount();
sd_end();
display_end();
nyx_str->mtc_cfg.init_done = 0;
@ -149,7 +149,7 @@ void reboot_rcm()
{
bpmp_mmu_disable();
sd_unmount();
sd_end();
display_end();
nyx_str->mtc_cfg.init_done = 0;
@ -163,7 +163,7 @@ void reboot_rcm()
void power_off()
{
sd_unmount();
sd_end();
display_end();
nyx_str->mtc_cfg.init_done = 0;

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.