Improvements to ini/payload handling

- Allow no hekate_ipl.ini and create it at 1st hekate boot
- Show Payloads/More configs options when no boot entry in main .ini
- Fix black screen on empty ini/payload folders
- Fix some stack corruption with freeing ini lists (wip)
This commit is contained in:
Kostas Missos 2018-09-18 23:47:37 +03:00
parent fdd94ffd2b
commit 780736591e
4 changed files with 83 additions and 58 deletions

View file

@ -54,13 +54,32 @@ int create_config_entry()
char lbuf[16]; char lbuf[16];
FIL fp; FIL fp;
bool mainIniFound = false;
LIST_INIT(ini_sections); LIST_INIT(ini_sections);
if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
mainIniFound = true;
else
{ {
u8 res = f_open(&fp, "bootloader/hekate_ipl.ini", FA_READ);
if (res == FR_NO_FILE || res == FR_NO_PATH)
{
f_mkdir("bootloader");
f_mkdir("bootloader/ini");
f_mkdir("bootloader/payloads");
f_mkdir("bootloader/sys");
}
else
{
if (!res)
f_close(&fp);
return 1;
}
}
if (f_open(&fp, "bootloader/hekate_ipl.ini", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) if (f_open(&fp, "bootloader/hekate_ipl.ini", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)
return 0; return 1;
// Add config entry. // Add config entry.
f_puts("[config]\nautoboot=", &fp); f_puts("[config]\nautoboot=", &fp);
itoa(h_cfg.autoboot, lbuf, 10); itoa(h_cfg.autoboot, lbuf, 10);
@ -79,6 +98,8 @@ int create_config_entry()
f_puts(lbuf, &fp); f_puts(lbuf, &fp);
f_puts("\n", &fp); f_puts("\n", &fp);
if (mainIniFound)
{
// Re-construct existing entries. // Re-construct existing entries.
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
{ {
@ -115,13 +136,12 @@ int create_config_entry()
break; break;
} }
} }
}
f_close(&fp); f_close(&fp);
sd_unmount(); sd_unmount();
}
else
return 1;
if (mainIniFound)
ini_free(&ini_sections); ini_free(&ini_sections);
return 0; return 0;
@ -185,11 +205,6 @@ void _config_autoboot_list()
break; break;
} }
} }
if (i < 3)
{
EPRINTF("No launch configurations found.");
goto out;
}
memset(&ments[i], 0, sizeof(ment_t)); memset(&ments[i], 0, sizeof(ment_t));
menu_t menu = {ments, "Select a list entry to auto boot", 0, 0}; menu_t menu = {ments, "Select a list entry to auto boot", 0, 0};
@ -309,8 +324,10 @@ void config_autoboot()
} }
if (i < 6 && !h_cfg.autoboot_list) if (i < 6 && !h_cfg.autoboot_list)
{ {
EPRINTF("No launch configurations found."); ments[i].type = MENT_CAPTION;
goto out; ments[i].caption = "No main configurations found...";
ments[i].color = 0xFFFFDD00;
i++;
} }
memset(&ments[i], 0, sizeof(ment_t)); memset(&ments[i], 0, sizeof(ment_t));

View file

@ -254,15 +254,7 @@ char *ini_check_payload_section(ini_sec_t *cfg)
} }
if (path) if (path)
{
if (strlen(path) > 1)
return path; return path;
else
{
free(path);
return NULL;
}
}
else else
return NULL; return NULL;
} }

View file

@ -80,7 +80,7 @@ gfx_con_t gfx_con;
sdmmc_t sd_sdmmc; sdmmc_t sd_sdmmc;
sdmmc_storage_t sd_storage; sdmmc_storage_t sd_storage;
FATFS sd_fs; FATFS sd_fs;
bool sd_mounted; static bool sd_mounted;
#ifdef MENU_LOGO_ENABLE #ifdef MENU_LOGO_ENABLE
u8 *Kc_MENU_LOGO; u8 *Kc_MENU_LOGO;
@ -95,7 +95,7 @@ bool sd_mount()
if (!sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, SDMMC_1, SDMMC_BUS_WIDTH_4, 11)) if (!sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, SDMMC_1, SDMMC_BUS_WIDTH_4, 11))
{ {
EPRINTF("Failed to init SD card.\nMake sure that it is inserted."); EPRINTF("Failed to init SD card.\nMake sure that it is inserted.\nOr that SD reader is properly seated!");
} }
else else
{ {
@ -2124,8 +2124,13 @@ void launch_firmware()
if ((i - 4) > max_entries) if ((i - 4) > max_entries)
break; break;
} }
if (i > 5) if (i < 6)
{ {
ments[i].type = MENT_CAPTION;
ments[i].caption = "No main configurations found...";
ments[i].color = 0xFFFFDD00;
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
@ -2138,9 +2143,7 @@ void launch_firmware()
sd_unmount(); sd_unmount();
return; return;
} }
}
else
EPRINTF("No launch configurations found.");
free(ments); free(ments);
ini_free(&ini_sections); ini_free(&ini_sections);
} }
@ -2193,6 +2196,7 @@ void auto_launch_firmware()
u8 *BOOTLOGO = NULL; u8 *BOOTLOGO = NULL;
char *payload_path = NULL; char *payload_path = NULL;
FIL fp;
struct _bmp_data struct _bmp_data
{ {
@ -2217,6 +2221,11 @@ void auto_launch_firmware()
if (sd_mount()) if (sd_mount())
{ {
if (f_open(&fp, "bootloader/hekate_ipl.ini", FA_READ))
create_config_entry();
else
f_close(&fp);
if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false)) if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
{ {
u32 configEntry = 0; u32 configEntry = 0;

View file

@ -51,6 +51,13 @@ char *dirlist(char *directory)
continue; continue;
} }
f_closedir(&dir); f_closedir(&dir);
if (!k)
{
free(temp);
free(dir_entries);
return NULL;
}
} }
else else
{ {