2018-07-01 17:45:25 +00:00
|
|
|
/*
|
2021-05-11 06:32:38 +00:00
|
|
|
* Copyright (c) 2018-2021 CTCaer
|
2018-08-05 11:40:32 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2018-07-01 17:45:25 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2022-01-15 22:04:34 +00:00
|
|
|
#include <bdk.h>
|
|
|
|
|
2018-07-01 17:45:25 +00:00
|
|
|
#include "config.h"
|
2020-06-14 13:45:45 +00:00
|
|
|
#include "gfx/tui.h"
|
|
|
|
#include <libs/fatfs/ff.h>
|
2018-07-01 17:45:25 +00:00
|
|
|
|
|
|
|
extern hekate_config h_cfg;
|
|
|
|
|
|
|
|
void set_default_configuration()
|
|
|
|
{
|
2022-10-11 04:51:45 +00:00
|
|
|
h_cfg.t210b01 = hw_get_chip_id() == GP_HIDREV_MAJOR_T210B01;
|
|
|
|
|
2022-10-11 04:49:17 +00:00
|
|
|
h_cfg.autoboot = 0;
|
2018-08-21 01:37:40 +00:00
|
|
|
h_cfg.autoboot_list = 0;
|
2022-10-11 04:49:17 +00:00
|
|
|
h_cfg.bootwait = 3;
|
|
|
|
h_cfg.noticker = 0; //! TODO: Add GUI option.
|
|
|
|
h_cfg.backlight = 100;
|
2022-10-11 04:51:45 +00:00
|
|
|
h_cfg.autohosoff = h_cfg.t210b01 ? 1 : 0;
|
2022-10-11 04:49:17 +00:00
|
|
|
h_cfg.autonogc = 1;
|
|
|
|
h_cfg.updater2p = 0;
|
|
|
|
h_cfg.bootprotect = 0;
|
|
|
|
|
2019-06-30 00:15:46 +00:00
|
|
|
h_cfg.errors = 0;
|
2020-04-30 00:43:29 +00:00
|
|
|
h_cfg.eks = NULL;
|
2020-06-13 15:16:29 +00:00
|
|
|
h_cfg.rcm_patched = fuse_check_patched_rcm();
|
2019-06-30 00:40:37 +00:00
|
|
|
h_cfg.emummc_force_disable = false;
|
2018-07-01 17:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int create_config_entry()
|
|
|
|
{
|
2021-05-11 06:32:38 +00:00
|
|
|
char lbuf[64];
|
2018-07-01 17:45:25 +00:00
|
|
|
FIL fp;
|
2018-09-18 20:47:37 +00:00
|
|
|
bool mainIniFound = false;
|
2018-07-01 17:45:25 +00:00
|
|
|
|
|
|
|
LIST_INIT(ini_sections);
|
|
|
|
|
2018-08-21 01:37:40 +00:00
|
|
|
if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
|
2018-09-18 20:47:37 +00:00
|
|
|
mainIniFound = true;
|
|
|
|
else
|
2018-07-01 17:45:25 +00:00
|
|
|
{
|
2018-09-18 20:47:37 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2018-07-01 17:45:25 +00:00
|
|
|
|
2018-09-18 20:47:37 +00:00
|
|
|
if (f_open(&fp, "bootloader/hekate_ipl.ini", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)
|
|
|
|
return 1;
|
2021-08-22 13:56:05 +00:00
|
|
|
|
2018-09-18 20:47:37 +00:00
|
|
|
// Add config entry.
|
|
|
|
f_puts("[config]\nautoboot=", &fp);
|
|
|
|
itoa(h_cfg.autoboot, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 13:56:05 +00:00
|
|
|
|
2018-09-18 20:47:37 +00:00
|
|
|
f_puts("\nautoboot_list=", &fp);
|
|
|
|
itoa(h_cfg.autoboot_list, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 13:56:05 +00:00
|
|
|
|
2018-09-18 20:47:37 +00:00
|
|
|
f_puts("\nbootwait=", &fp);
|
|
|
|
itoa(h_cfg.bootwait, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 13:56:05 +00:00
|
|
|
|
2018-09-18 21:01:42 +00:00
|
|
|
f_puts("\nbacklight=", &fp);
|
|
|
|
itoa(h_cfg.backlight, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 13:56:05 +00:00
|
|
|
|
2022-10-11 04:49:17 +00:00
|
|
|
f_puts("\nnoticker=", &fp);
|
|
|
|
itoa(h_cfg.noticker, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
|
|
|
|
2018-09-24 20:45:06 +00:00
|
|
|
f_puts("\nautohosoff=", &fp);
|
|
|
|
itoa(h_cfg.autohosoff, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 13:56:05 +00:00
|
|
|
|
2019-02-23 23:06:24 +00:00
|
|
|
f_puts("\nautonogc=", &fp);
|
|
|
|
itoa(h_cfg.autonogc, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 13:56:05 +00:00
|
|
|
|
2019-12-11 22:13:32 +00:00
|
|
|
f_puts("\nupdater2p=", &fp);
|
|
|
|
itoa(h_cfg.updater2p, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 13:56:05 +00:00
|
|
|
|
2020-10-20 07:16:12 +00:00
|
|
|
f_puts("\nbootprotect=", &fp);
|
|
|
|
itoa(h_cfg.bootprotect, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2018-09-18 20:47:37 +00:00
|
|
|
f_puts("\n", &fp);
|
|
|
|
|
|
|
|
if (mainIniFound)
|
|
|
|
{
|
2018-07-01 17:45:25 +00:00
|
|
|
// Re-construct existing entries.
|
|
|
|
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
|
|
|
|
{
|
|
|
|
if (!strcmp(ini_sec->name, "config"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (ini_sec->type)
|
|
|
|
{
|
|
|
|
case INI_CHOICE: // Re-construct Boot entry [ ].
|
|
|
|
f_puts("[", &fp);
|
|
|
|
f_puts(ini_sec->name, &fp);
|
|
|
|
f_puts("]\n", &fp);
|
|
|
|
// Re-construct boot entry's config.
|
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
|
|
|
|
{
|
|
|
|
f_puts(kv->key, &fp);
|
|
|
|
f_puts("=", &fp);
|
|
|
|
f_puts(kv->val, &fp);
|
|
|
|
f_puts("\n", &fp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case INI_CAPTION: // Re-construct caption entry { }.
|
|
|
|
f_puts("{", &fp);
|
|
|
|
f_puts(ini_sec->name, &fp);
|
|
|
|
f_puts("}\n", &fp);
|
|
|
|
break;
|
|
|
|
case INI_NEWLINE: // Re-construct cosmetic newline \n.
|
|
|
|
f_puts("\n", &fp);
|
|
|
|
break;
|
|
|
|
case INI_COMMENT: // Re-construct comment entry #.
|
|
|
|
f_puts("#", &fp);
|
|
|
|
f_puts(ini_sec->name, &fp);
|
|
|
|
f_puts("\n", &fp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-18 20:47:37 +00:00
|
|
|
f_close(&fp);
|
|
|
|
|
2018-07-01 17:45:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|