hekate/nyx: improve cyclomatic complexity

This commit is contained in:
CTCaer 2022-01-29 01:23:40 +02:00
parent 2f1d1572f7
commit aee5861f65
9 changed files with 1733 additions and 1701 deletions

View file

@ -192,8 +192,9 @@ int launch_payload(char *path, bool update, bool clear_screen)
gfx_clear_grey(0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0); gfx_con_setpos(0, 0);
if (sd_mount()) if (!sd_mount())
{ goto out;
FIL fp; FIL fp;
if (f_open(&fp, path, FA_READ)) if (f_open(&fp, path, FA_READ))
{ {
@ -273,7 +274,6 @@ int launch_payload(char *path, bool update, bool clear_screen)
EMC(EMC_SCRATCH0) |= EMC_HEKA_UPD; EMC(EMC_SCRATCH0) |= EMC_HEKA_UPD;
(*update_ptr)(); (*update_ptr)();
} }
}
out: out:
if (!update) if (!update)
@ -282,25 +282,6 @@ out:
return 1; return 1;
} }
void auto_launch_update()
{
// Check if already chainloaded update and clear flag. Otherwise check for updates.
if (EMC(EMC_SCRATCH0) & EMC_HEKA_UPD)
EMC(EMC_SCRATCH0) &= ~EMC_HEKA_UPD;
else
{
// Check if update.bin exists and is newer and launch it. Otherwise create it.
if (!f_stat("bootloader/update.bin", NULL))
launch_payload("bootloader/update.bin", true, false);
else
{
u8 *buf = calloc(0x200, 1);
is_ipl_updated(buf, "bootloader/update.bin", true);
free(buf);
}
}
}
void launch_tools() void launch_tools()
{ {
u8 max_entries = 61; u8 max_entries = 61;
@ -313,10 +294,13 @@ void launch_tools()
gfx_clear_grey(0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0); gfx_con_setpos(0, 0);
if (sd_mount()) if (!sd_mount())
{ {
dir = (char *)malloc(256); free(ments);
goto failed_sd_mount;
}
dir = (char *)malloc(256);
memcpy(dir, "bootloader/payloads", 20); memcpy(dir, "bootloader/payloads", 20);
filelist = dirlist(dir, NULL, false, false); filelist = dirlist(dir, NULL, false, false);
@ -364,12 +348,6 @@ void launch_tools()
free(ments); free(ments);
free(filelist); free(filelist);
}
else
{
free(ments);
goto out;
}
if (file_sec) if (file_sec)
{ {
@ -380,7 +358,7 @@ void launch_tools()
EPRINTF("Failed to launch payload."); EPRINTF("Failed to launch payload.");
} }
out: failed_sd_mount:
sd_end(); sd_end();
free(dir); free(dir);
@ -399,10 +377,16 @@ void ini_list_launcher()
gfx_clear_grey(0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0); gfx_con_setpos(0, 0);
if (sd_mount()) if (!sd_mount())
{ goto parse_failed;
if (ini_parse(&ini_list_sections, "bootloader/ini", true))
// Check that ini files exist and parse them.
if (!ini_parse(&ini_list_sections, "bootloader/ini", true))
{ {
EPRINTF("Could not find any ini\nin bootloader/ini!");
goto parse_failed;
}
// Build configuration menu. // Build configuration menu.
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3)); ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3));
ments[0].type = MENT_BACK; ments[0].type = MENT_BACK;
@ -413,11 +397,14 @@ void ini_list_launcher()
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_list_sections, link) LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_list_sections, link)
{ {
if (!strcmp(ini_sec->name, "config") || if (!strcmp(ini_sec->name, "config") ||
ini_sec->type == INI_COMMENT || ini_sec->type == INI_NEWLINE) ini_sec->type == INI_COMMENT ||
ini_sec->type == INI_NEWLINE)
continue; continue;
ments[i].type = ini_sec->type; ments[i].type = ini_sec->type;
ments[i].caption = ini_sec->name; ments[i].caption = ini_sec->name;
ments[i].data = ini_sec; ments[i].data = ini_sec;
if (ini_sec->type == MENT_CAPTION) if (ini_sec->type == MENT_CAPTION)
ments[i].color = ini_sec->color; ments[i].color = ini_sec->color;
i++; i++;
@ -425,6 +412,7 @@ void ini_list_launcher()
if ((i - 1) > max_entries) if ((i - 1) > max_entries)
break; break;
} }
if (i > 2) if (i > 2)
{ {
memset(&ments[i], 0, sizeof(ment_t)); memset(&ments[i], 0, sizeof(ment_t));
@ -482,11 +470,8 @@ void ini_list_launcher()
else else
EPRINTF("No extra configs found."); EPRINTF("No extra configs found.");
free(ments); free(ments);
}
else
EPRINTF("Could not find any ini\nin bootloader/ini!");
}
parse_failed:
if (!cfg_sec) if (!cfg_sec)
goto out; goto out;
@ -524,13 +509,19 @@ void launch_firmware()
gfx_clear_grey(0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(0, 0); gfx_con_setpos(0, 0);
if (sd_mount()) if (!sd_mount())
{ goto parse_failed;
// Load emuMMC configuration. // Load emuMMC configuration.
emummc_load_cfg(); emummc_load_cfg();
if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) // Check that main configuration exists and parse it.
if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
{ {
EPRINTF("Could not open 'bootloader/hekate_ipl.ini'!");
goto parse_failed;
}
// Build configuration menu. // Build configuration menu.
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 6)); ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 6));
ments[0].type = MENT_BACK; ments[0].type = MENT_BACK;
@ -550,11 +541,14 @@ void launch_firmware()
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
{ {
if (!strcmp(ini_sec->name, "config") || if (!strcmp(ini_sec->name, "config") ||
ini_sec->type == INI_COMMENT || ini_sec->type == INI_NEWLINE) ini_sec->type == INI_COMMENT ||
ini_sec->type == INI_NEWLINE)
continue; continue;
ments[i].type = ini_sec->type; ments[i].type = ini_sec->type;
ments[i].caption = ini_sec->name; ments[i].caption = ini_sec->name;
ments[i].data = ini_sec; ments[i].data = ini_sec;
if (ini_sec->type == MENT_CAPTION) if (ini_sec->type == MENT_CAPTION)
ments[i].color = ini_sec->color; ments[i].color = ini_sec->color;
i++; i++;
@ -562,6 +556,7 @@ void launch_firmware()
if ((i - 4) > max_entries) if ((i - 4) > max_entries)
break; break;
} }
if (i < 6) if (i < 6)
{ {
ments[i].type = MENT_CAPTION; ments[i].type = MENT_CAPTION;
@ -569,6 +564,7 @@ void launch_firmware()
ments[i].color = 0xFFFFDD00; ments[i].color = 0xFFFFDD00;
i++; i++;
} }
memset(&ments[i], 0, sizeof(ment_t)); memset(&ments[i], 0, sizeof(ment_t));
menu_t menu = { menu_t menu = {
ments, "Launch configurations", 0, 0 ments, "Launch configurations", 0, 0
@ -621,11 +617,8 @@ void launch_firmware()
} }
free(ments); free(ments);
}
else
EPRINTF("Could not open 'bootloader/hekate_ipl.ini'.\nMake sure it exists!");
}
parse_failed:
if (!cfg_sec) if (!cfg_sec)
{ {
gfx_printf("\nPress any key...\n"); gfx_printf("\nPress any key...\n");
@ -769,6 +762,25 @@ static void _bootloader_corruption_protect()
} }
} }
void auto_launch_update()
{
// Check if already chainloaded update and clear flag. Otherwise check for updates.
if (EMC(EMC_SCRATCH0) & EMC_HEKA_UPD)
EMC(EMC_SCRATCH0) &= ~EMC_HEKA_UPD;
else
{
// Check if update.bin exists and is newer and launch it. Otherwise create it.
if (!f_stat("bootloader/update.bin", NULL))
launch_payload("bootloader/update.bin", true, false);
else
{
u8 *buf = calloc(0x200, 1);
is_ipl_updated(buf, "bootloader/update.bin", true);
free(buf);
}
}
}
static void _auto_launch_firmware() static void _auto_launch_firmware()
{ {
struct _bmp_data struct _bmp_data
@ -784,6 +796,8 @@ static void _auto_launch_firmware()
char *emummc_path = NULL; char *emummc_path = NULL;
char *bootlogoCustomEntry = NULL; char *bootlogoCustomEntry = NULL;
ini_sec_t *cfg_sec = NULL; ini_sec_t *cfg_sec = NULL;
u32 boot_entry_id = 0;
bool config_entry_found = false;
auto_launch_update(); auto_launch_update();
@ -803,10 +817,9 @@ static void _auto_launch_firmware()
if (f_stat("bootloader/hekate_ipl.ini", NULL)) if (f_stat("bootloader/hekate_ipl.ini", NULL))
create_config_entry(); create_config_entry();
if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) // Parse hekate main configuration.
{ if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
u32 configEntry = 0; goto out; // Can't load hekate_ipl.ini.
u32 boot_entry_id = 0;
// Load configuration. // Load configuration.
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
@ -814,9 +827,9 @@ static void _auto_launch_firmware()
// Skip other ini entries for autoboot. // Skip other ini entries for autoboot.
if (ini_sec->type == INI_CHOICE) if (ini_sec->type == INI_CHOICE)
{ {
if (!strcmp(ini_sec->name, "config")) if (!config_entry_found && !strcmp(ini_sec->name, "config"))
{ {
configEntry = 1; config_entry_found = true;
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link) LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
{ {
if (!strcmp("autoboot", kv->key)) if (!strcmp("autoboot", kv->key))
@ -863,7 +876,7 @@ static void _auto_launch_firmware()
if (boot_from_id) 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);
else if (h_cfg.autoboot == boot_entry_id && configEntry) else if (h_cfg.autoboot == boot_entry_id && config_entry_found)
{ {
cfg_sec = ini_sec; cfg_sec = ini_sec;
LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg_sec->kvs, link) LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg_sec->kvs, link)
@ -894,12 +907,14 @@ static void _auto_launch_firmware()
boot_entry_id = 1; boot_entry_id = 1;
bootlogoCustomEntry = NULL; bootlogoCustomEntry = NULL;
if (ini_parse(&ini_list_sections, "bootloader/ini", true)) if (!ini_parse(&ini_list_sections, "bootloader/ini", true))
{ goto skip_list;
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec_list, &ini_list_sections, link) LIST_FOREACH_ENTRY(ini_sec_t, ini_sec_list, &ini_list_sections, link)
{ {
if (ini_sec_list->type == INI_CHOICE) if (ini_sec_list->type != INI_CHOICE)
{ continue;
if (!strcmp(ini_sec_list->name, "config")) if (!strcmp(ini_sec_list->name, "config"))
continue; continue;
@ -925,19 +940,13 @@ static void _auto_launch_firmware()
} }
} }
}
}
skip_list: skip_list:
// Add missing configuration entry. // Add missing configuration entry.
if (!configEntry) if (!config_entry_found)
create_config_entry(); create_config_entry();
if (!cfg_sec) if (!cfg_sec)
goto out; // No configurations or auto boot is disabled. goto out; // No configurations or auto boot is disabled.
}
else
goto out; // Can't load hekate_ipl.ini.
u8 *bitmap = NULL; u8 *bitmap = NULL;
struct _bmp_data bmpData; struct _bmp_data bmpData;

View file

@ -950,8 +950,9 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa
bool use_multipart = false; bool use_multipart = false;
bool check_4MB_aligned = true; bool check_4MB_aligned = true;
if (allow_multi_part) if (!allow_multi_part)
{ goto multipart_not_allowed;
// Check to see if there is a combined file and if so then use that. // Check to see if there is a combined file and if so then use that.
if (f_stat(outFilename, &fno)) if (f_stat(outFilename, &fno))
{ {
@ -1066,8 +1067,8 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa
use_multipart = true; use_multipart = true;
_update_filename(outFilename, sdPathLen, 0); _update_filename(outFilename, sdPathLen, 0);
} }
}
multipart_not_allowed:
res = f_open(&fp, outFilename, FA_READ); res = f_open(&fp, outFilename, FA_READ);
if (use_multipart) if (use_multipart)
{ {

View file

@ -42,8 +42,9 @@ void load_emummc_cfg(emummc_cfg_t *emu_info)
// Parse emuMMC configuration. // Parse emuMMC configuration.
LIST_INIT(ini_sections); LIST_INIT(ini_sections);
if (ini_parse(&ini_sections, "emuMMC/emummc.ini", false)) if (!ini_parse(&ini_sections, "emuMMC/emummc.ini", false))
{ return;
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
{ {
if (!strcmp(ini_sec->name, "emummc")) if (!strcmp(ini_sec->name, "emummc"))
@ -61,7 +62,8 @@ void load_emummc_cfg(emummc_cfg_t *emu_info)
else if (!strcmp("nintendo_path", kv->key)) else if (!strcmp("nintendo_path", kv->key))
emu_info->nintendo_path = kv->val; emu_info->nintendo_path = kv->val;
} }
}
break;
} }
} }
} }
@ -262,6 +264,7 @@ static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_sto
retryCount = 0; retryCount = 0;
num = MIN(totalSectors, NUM_SECTORS_PER_ITER); num = MIN(totalSectors, NUM_SECTORS_PER_ITER);
while (!sdmmc_storage_read(storage, lba_curr, num, buf)) while (!sdmmc_storage_read(storage, lba_curr, num, buf))
{ {
s_printf(gui->txt_buf, s_printf(gui->txt_buf,
@ -405,6 +408,7 @@ void dump_emummc_file(emmc_tool_gui_t *gui)
memset(&bootPart, 0, sizeof(bootPart)); memset(&bootPart, 0, sizeof(bootPart));
bootPart.lba_start = 0; bootPart.lba_start = 0;
bootPart.lba_end = (BOOT_PART_SIZE / EMMC_BLOCKSIZE) - 1; bootPart.lba_end = (BOOT_PART_SIZE / EMMC_BLOCKSIZE) - 1;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
strcpy(bootPart.name, "BOOT"); strcpy(bootPart.name, "BOOT");
@ -448,7 +452,7 @@ void dump_emummc_file(emmc_tool_gui_t *gui)
rawPart.lba_start = 0; rawPart.lba_start = 0;
rawPart.lba_end = RAW_AREA_NUM_SECTORS - 1; rawPart.lba_end = RAW_AREA_NUM_SECTORS - 1;
strcpy(rawPart.name, "GPP"); strcpy(rawPart.name, "GPP");
{
s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n", s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n",
i, rawPart.name, rawPart.lba_start, rawPart.lba_end); i, rawPart.name, rawPart.lba_start, rawPart.lba_end);
lv_label_set_text(gui->label_info, txt_buf); lv_label_set_text(gui->label_info, txt_buf);
@ -465,7 +469,6 @@ void dump_emummc_file(emmc_tool_gui_t *gui)
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf); lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf);
manual_system_maintenance(true); manual_system_maintenance(true);
}
out_failed: out_failed:
timer = get_tmr_s() - timer; timer = get_tmr_s() - timer;

View file

@ -1608,8 +1608,9 @@ static lv_res_t _create_window_home_launch(lv_obj_t *btn)
u32 curr_btn_idx = 0; // Active buttons. u32 curr_btn_idx = 0; // Active buttons.
LIST_INIT(ini_sections); LIST_INIT(ini_sections);
if (sd_mount()) if (!sd_mount())
{ goto failed_sd_mount;
// Check if we use custom system icons. // Check if we use custom system icons.
bool icon_sw_custom = !f_stat("bootloader/res/icon_switch_custom.bmp", NULL); bool icon_sw_custom = !f_stat("bootloader/res/icon_switch_custom.bmp", NULL);
bool icon_pl_custom = !f_stat("bootloader/res/icon_payload_custom.bmp", NULL); bool icon_pl_custom = !f_stat("bootloader/res/icon_payload_custom.bmp", NULL);
@ -1631,11 +1632,11 @@ ini_parsing:
more_cfg = true; more_cfg = true;
} }
if (ini_parse_success) if (!ini_parse_success)
{ goto ini_parse_failed;
// Iterate to all boot entries and load icons. // Iterate to all boot entries and load icons.
u32 entry_idx = 1; u32 entry_idx = 1;
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
{ {
if (!strcmp(ini_sec->name, "config") || (ini_sec->type != INI_CHOICE)) if (!strcmp(ini_sec->name, "config") || (ini_sec->type != INI_CHOICE))
@ -1745,12 +1746,13 @@ ini_parsing:
if (curr_btn_idx >= max_entries) if (curr_btn_idx >= max_entries)
break; break;
} }
}
ini_parse_failed:
// Reiterate the loop with more cfgs if combined. // Reiterate the loop with more cfgs if combined.
if (combined_cfg && (curr_btn_idx < 8) && !more_cfg) if (combined_cfg && (curr_btn_idx < 8) && !more_cfg)
goto ini_parsing; goto ini_parsing;
}
failed_sd_mount:
if (curr_btn_idx < 1) if (curr_btn_idx < 1)
no_boot_entries = true; no_boot_entries = true;

View file

@ -782,8 +782,10 @@ static lv_res_t _create_mbox_emummc_migrate(lv_obj_t *btn)
for (int i = 1; i < 4; i++) for (int i = 1; i < 4; i++)
{ {
mbr_ctx.sector_start = mbr->partitions[i].start_sct; mbr_ctx.sector_start = mbr->partitions[i].start_sct;
if (mbr_ctx.sector_start)
{ if (!mbr_ctx.sector_start)
continue;
sdmmc_storage_read(&sd_storage, mbr_ctx.sector_start + 0xC001, 1, efi_part); sdmmc_storage_read(&sd_storage, mbr_ctx.sector_start + 0xC001, 1, efi_part);
if (!memcmp(efi_part, "EFI PART", 8)) if (!memcmp(efi_part, "EFI PART", 8))
{ {
@ -803,7 +805,6 @@ static lv_res_t _create_mbox_emummc_migrate(lv_obj_t *btn)
} }
} }
} }
}
if (!mbr_ctx.part_idx) if (!mbr_ctx.part_idx)
{ {

View file

@ -1329,9 +1329,11 @@ static lv_res_t _create_mbox_benchmark(bool sd_bench)
} }
if (res) if (res)
lv_mbox_set_text(mbox, "#FFDD00 Failed to init Storage!#");
else
{ {
lv_mbox_set_text(mbox, "#FFDD00 Failed to init Storage!#");
goto out;
}
int error = 0; int error = 0;
u32 iters = 3; u32 iters = 3;
u32 offset_chunk_start = ALIGN_DOWN(storage->sec_cnt / 3, 0x8000); // Align to 16MB. u32 offset_chunk_start = ALIGN_DOWN(storage->sec_cnt / 3, 0x8000); // Align to 16MB.
@ -1516,7 +1518,8 @@ error:
sd_unmount(); sd_unmount();
else else
sdmmc_storage_end(&emmc_storage); sdmmc_storage_end(&emmc_storage);
}
out:
free(txt_buf); free(txt_buf);
lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); // Important. After set_text. lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action); // Important. After set_text.
@ -1559,9 +1562,10 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn)
{ {
lv_label_set_text(lb_desc, "#FFDD00 Failed to init eMMC!#"); lv_label_set_text(lb_desc, "#FFDD00 Failed to init eMMC!#");
lv_obj_set_width(lb_desc, lv_obj_get_width(desc)); lv_obj_set_width(lb_desc, lv_obj_get_width(desc));
goto out;
} }
else
{
u32 speed = 0; u32 speed = 0;
char *rsvd_blocks; char *rsvd_blocks;
char life_a_txt[8]; char life_a_txt[8];
@ -1784,8 +1788,8 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn)
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_top(mbox, true); lv_obj_set_top(mbox, true);
} }
}
out:
sdmmc_storage_end(&emmc_storage); sdmmc_storage_end(&emmc_storage);
free(txt_buf); free(txt_buf);

View file

@ -993,8 +993,9 @@ static lv_res_t _create_mbox_fix_touchscreen(lv_obj_t *btn)
} }
u8 err[2]; u8 err[2];
if (touch_panel_ito_test(err)) if (!touch_panel_ito_test(err))
{ goto ito_failed;
if (!err[0] && !err[1]) if (!err[0] && !err[1])
{ {
res = touch_execute_autotune(); res = touch_execute_autotune();
@ -1051,8 +1052,8 @@ static lv_res_t _create_mbox_fix_touchscreen(lv_obj_t *btn)
lv_mbox_set_text(mbox, txt_buf); lv_mbox_set_text(mbox, txt_buf);
goto out2; goto out2;
} }
}
ito_failed:
touch_sense_enable(); touch_sense_enable();
out: out:

View file

@ -540,9 +540,10 @@ static lv_res_t _action_flash_linux_data(lv_obj_t * btns, const char * txt)
bool succeeded = false; bool succeeded = false;
if (btn_idx)
return LV_RES_INV;
// Flash Linux. // Flash Linux.
if (!btn_idx)
{
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL); lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_style(dark_bg, &mbox_darken); lv_obj_set_style(dark_bg, &mbox_darken);
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES); lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
@ -716,7 +717,6 @@ exit:
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
sd_unmount(); sd_unmount();
}
return LV_RES_INV; return LV_RES_INV;
} }
@ -856,8 +856,9 @@ static lv_res_t _action_check_flash_linux(lv_obj_t *btn)
itoa(idx, &path[23], 10); itoa(idx, &path[23], 10);
// Check for alignment. // Check for alignment.
if (!f_stat(path, &fno)) if (f_stat(path, &fno))
{ break;
if ((u64)fno.fsize % SZ_4M) if ((u64)fno.fsize % SZ_4M)
{ {
// Check if last part. // Check if last part.
@ -882,9 +883,6 @@ static lv_res_t _action_check_flash_linux(lv_obj_t *btn)
idx--; idx--;
} }
l4t_flash_ctxt.image_size_sct += (u64)fno.fsize >> 9; l4t_flash_ctxt.image_size_sct += (u64)fno.fsize >> 9;
}
else
break;
idx++; idx++;
} }
@ -950,9 +948,10 @@ static lv_res_t _action_flash_android_data(lv_obj_t * btns, const char * txt)
// Delete parent mbox. // Delete parent mbox.
mbox_action(btns, txt); mbox_action(btns, txt);
if (btn_idx)
return LV_RES_INV;
// Flash Android components. // Flash Android components.
if (!btn_idx)
{
char path[128]; char path[128];
gpt_t *gpt = calloc(1, sizeof(gpt_t)); gpt_t *gpt = calloc(1, sizeof(gpt_t));
char *txt_buf = malloc(SZ_4K); char *txt_buf = malloc(SZ_4K);
@ -990,11 +989,16 @@ static lv_res_t _action_flash_android_data(lv_obj_t * btns, const char * txt)
goto error; goto error;
} }
strcpy(path, "switchroot/install/boot.img");
if (!f_stat(path, NULL))
{
u32 offset_sct = 0; u32 offset_sct = 0;
u32 size_sct = 0; u32 size_sct = 0;
strcpy(path, "switchroot/install/boot.img");
if (f_stat(path, NULL))
{
s_printf(txt_buf, "#FF8000 Warning:# Kernel image not found!\n");
goto boot_img_not_found;
}
for (u32 i = 0; i < gpt->header.num_part_ents; i++) for (u32 i = 0; i < gpt->header.num_part_ents; i++)
{ {
if (!memcmp(gpt->entries[i].name, (char[]) { 'L', 0, 'N', 0, 'X', 0 }, 6)) if (!memcmp(gpt->entries[i].name, (char[]) { 'L', 0, 'N', 0, 'X', 0 }, 6))
@ -1036,18 +1040,20 @@ static lv_res_t _action_flash_android_data(lv_obj_t * btns, const char * txt)
} }
else else
s_printf(txt_buf, "#FF8000 Warning:# Kernel partition not found!\n"); s_printf(txt_buf, "#FF8000 Warning:# Kernel partition not found!\n");
}
else
s_printf(txt_buf, "#FF8000 Warning:# Kernel image not found!\n");
boot_img_not_found:
lv_label_set_text(lbl_status, txt_buf); lv_label_set_text(lbl_status, txt_buf);
manual_system_maintenance(true); manual_system_maintenance(true);
strcpy(path, "switchroot/install/twrp.img"); strcpy(path, "switchroot/install/twrp.img");
if (!f_stat(path, NULL)) if (f_stat(path, NULL))
{ {
u32 offset_sct = 0; strcat(txt_buf, "#FF8000 Warning:# TWRP image not found!\n");
u32 size_sct = 0; goto twrp_not_found;
}
offset_sct = 0;
size_sct = 0;
for (u32 i = 0; i < gpt->header.num_part_ents; i++) for (u32 i = 0; i < gpt->header.num_part_ents; i++)
{ {
if (!memcmp(gpt->entries[i].name, (char[]) { 'S', 0, 'O', 0, 'S', 0 }, 6)) if (!memcmp(gpt->entries[i].name, (char[]) { 'S', 0, 'O', 0, 'S', 0 }, 6))
@ -1088,18 +1094,21 @@ static lv_res_t _action_flash_android_data(lv_obj_t * btns, const char * txt)
} }
else else
strcat(txt_buf, "#FF8000 Warning:# TWRP partition not found!\n"); strcat(txt_buf, "#FF8000 Warning:# TWRP partition not found!\n");
}
else
strcat(txt_buf, "#FF8000 Warning:# TWRP image not found!\n");
twrp_not_found:
lv_label_set_text(lbl_status, txt_buf); lv_label_set_text(lbl_status, txt_buf);
manual_system_maintenance(true); manual_system_maintenance(true);
strcpy(path, "switchroot/install/tegra210-icosa.dtb"); strcpy(path, "switchroot/install/tegra210-icosa.dtb");
if (!f_stat(path, NULL)) if (f_stat(path, NULL))
{ {
u32 offset_sct = 0; strcat(txt_buf, "#FF8000 Warning:# DTB image not found!");
u32 size_sct = 0;
goto dtb_not_found;
}
offset_sct = 0;
size_sct = 0;
for (u32 i = 0; i < gpt->header.num_part_ents; i++) for (u32 i = 0; i < gpt->header.num_part_ents; i++)
{ {
if (!memcmp(gpt->entries[i].name, (char[]) { 'D', 0, 'T', 0, 'B', 0 }, 6)) if (!memcmp(gpt->entries[i].name, (char[]) { 'D', 0, 'T', 0, 'B', 0 }, 6))
@ -1140,10 +1149,8 @@ static lv_res_t _action_flash_android_data(lv_obj_t * btns, const char * txt)
} }
else else
strcat(txt_buf, "#FF8000 Warning:# DTB partition not found!"); strcat(txt_buf, "#FF8000 Warning:# DTB partition not found!");
}
else
strcat(txt_buf, "#FF8000 Warning:# DTB image not found!");
dtb_not_found:
lv_label_set_text(lbl_status, txt_buf); lv_label_set_text(lbl_status, txt_buf);
// Check if TWRP is flashed unconditionally. // Check if TWRP is flashed unconditionally.
@ -1179,7 +1186,6 @@ error:
free(gpt); free(gpt);
sd_unmount(); sd_unmount();
}
return LV_RES_INV; return LV_RES_INV;
} }
@ -1409,8 +1415,10 @@ static lv_res_t _create_mbox_start_partitioning(lv_obj_t *btn)
u32 cluster_size = 65536; u32 cluster_size = 65536;
u32 mkfs_error = f_mkfs("sd:", FM_FAT32, cluster_size, buf, SZ_4M); u32 mkfs_error = f_mkfs("sd:", FM_FAT32, cluster_size, buf, SZ_4M);
if (mkfs_error)
{ if (!mkfs_error)
goto mkfs_no_error;
// Retry by halving cluster size. // Retry by halving cluster size.
while (cluster_size > 4096) while (cluster_size > 4096)
{ {
@ -1451,12 +1459,14 @@ static lv_res_t _create_mbox_start_partitioning(lv_obj_t *btn)
free(buf); free(buf);
goto error; goto error;
} }
lv_label_set_text(lbl_status, "#00DDFF Status:# Restored files but the operation failed!"); lv_label_set_text(lbl_status, "#00DDFF Status:# Restored files but the operation failed!");
f_mount(NULL, "ram:", 1); // Unmount ramdisk. f_mount(NULL, "ram:", 1); // Unmount ramdisk.
free(buf); free(buf);
goto error; goto error;
} }
}
mkfs_no_error:
free(buf); free(buf);
f_mount(&sd_fs, "sd:", 1); // Mount SD card. f_mount(&sd_fs, "sd:", 1); // Mount SD card.

View file

@ -138,8 +138,9 @@ lv_res_t launch_payload(lv_obj_t *list)
strcpy(path,"bootloader/payloads/"); strcpy(path,"bootloader/payloads/");
strcat(path, filename); strcat(path, filename);
if (sd_mount()) if (!sd_mount())
{ goto out;
FIL fp; FIL fp;
if (f_open(&fp, path, FA_READ)) if (f_open(&fp, path, FA_READ))
{ {
@ -197,7 +198,6 @@ lv_res_t launch_payload(lv_obj_t *list)
// Launch our payload. // Launch our payload.
(*ext_payload_ptr)(); (*ext_payload_ptr)();
}
out: out:
sd_unmount(); sd_unmount();
@ -210,9 +210,10 @@ void load_saved_configuration()
LIST_INIT(ini_sections); LIST_INIT(ini_sections);
LIST_INIT(ini_nyx_sections); LIST_INIT(ini_nyx_sections);
if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
goto skip_main_cfg_parse;
// Load hekate configuration. // Load hekate configuration.
if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
{
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
{ {
// Only parse config section. // Only parse config section.
@ -245,11 +246,12 @@ void load_saved_configuration()
break; break;
} }
} }
}
skip_main_cfg_parse:
if (!ini_parse(&ini_nyx_sections, "bootloader/nyx.ini", false))
return;
// Load Nyx configuration. // Load Nyx configuration.
if (ini_parse(&ini_nyx_sections, "bootloader/nyx.ini", false))
{
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_nyx_sections, link) LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_nyx_sections, link)
{ {
// Only parse config section. // Only parse config section.
@ -276,7 +278,6 @@ void load_saved_configuration()
break; break;
} }
} }
}
} }
#define EXCP_EN_ADDR 0x4003FFFC #define EXCP_EN_ADDR 0x4003FFFC