2019-06-30 02:03:00 +01:00
|
|
|
/*
|
2021-05-11 07:32:38 +01:00
|
|
|
* Copyright (c) 2018-2021 CTCaer
|
2019-06-30 02:03:00 +01: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "config.h"
|
2020-06-14 14:45:45 +01:00
|
|
|
#include <utils/ini.h>
|
|
|
|
#include <gfx_utils.h>
|
|
|
|
#include <libs/fatfs/ff.h>
|
|
|
|
#include <soc/fuse.h>
|
2020-06-26 20:40:06 +01:00
|
|
|
#include <soc/hw_init.h>
|
2020-06-14 14:45:45 +01:00
|
|
|
#include <soc/t210.h>
|
|
|
|
#include <storage/nx_sd.h>
|
|
|
|
#include <storage/sdmmc.h>
|
|
|
|
#include <utils/btn.h>
|
|
|
|
#include <utils/list.h>
|
|
|
|
#include <utils/util.h>
|
2019-06-30 02:03:00 +01:00
|
|
|
|
|
|
|
extern hekate_config h_cfg;
|
2020-04-30 00:00:33 +01:00
|
|
|
extern nyx_config n_cfg;
|
2019-06-30 02:03:00 +01:00
|
|
|
|
|
|
|
void set_default_configuration()
|
|
|
|
{
|
|
|
|
h_cfg.autoboot = 0;
|
|
|
|
h_cfg.autoboot_list = 0;
|
|
|
|
h_cfg.bootwait = 3;
|
|
|
|
h_cfg.backlight = 100;
|
|
|
|
h_cfg.autohosoff = 0;
|
|
|
|
h_cfg.autonogc = 1;
|
2019-12-11 22:13:32 +00:00
|
|
|
h_cfg.updater2p = 0;
|
2020-10-20 08:16:12 +01:00
|
|
|
h_cfg.bootprotect = 0;
|
2019-09-09 14:56:37 +01:00
|
|
|
h_cfg.errors = 0;
|
2020-04-30 01:43:29 +01:00
|
|
|
h_cfg.eks = NULL;
|
2019-06-30 02:03:00 +01:00
|
|
|
h_cfg.rcm_patched = fuse_check_patched_rcm();
|
2019-09-09 14:56:37 +01:00
|
|
|
h_cfg.emummc_force_disable = false;
|
2020-06-26 20:40:06 +01:00
|
|
|
h_cfg.t210b01 = hw_get_chip_id() == GP_HIDREV_MAJOR_T210B01;
|
2019-09-12 21:08:38 +01:00
|
|
|
|
2020-01-17 07:19:58 +00:00
|
|
|
sd_power_cycle_time_start = 0;
|
2019-06-30 02:03:00 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 00:00:33 +01:00
|
|
|
void set_nyx_default_configuration()
|
|
|
|
{
|
2020-04-30 02:04:24 +01:00
|
|
|
n_cfg.themecolor = 167;
|
2020-04-30 12:51:48 +01:00
|
|
|
n_cfg.timeoff = 0;
|
2020-04-30 12:49:28 +01:00
|
|
|
n_cfg.home_screen = 0;
|
2020-04-30 00:00:33 +01:00
|
|
|
n_cfg.verification = 1;
|
2020-05-05 17:26:10 +01:00
|
|
|
n_cfg.ums_emmc_rw = 0;
|
2020-10-20 08:21:48 +01:00
|
|
|
n_cfg.jc_disable = 0;
|
2021-05-11 07:32:38 +01:00
|
|
|
n_cfg.bpmp_clock = 0;
|
2020-04-30 00:00:33 +01:00
|
|
|
}
|
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
int create_config_entry()
|
|
|
|
{
|
|
|
|
if (!sd_mount())
|
|
|
|
return 1;
|
|
|
|
|
2021-05-11 07:32:38 +01:00
|
|
|
char lbuf[64];
|
2019-06-30 02:03:00 +01:00
|
|
|
FIL fp;
|
|
|
|
bool mainIniFound = false;
|
|
|
|
|
|
|
|
LIST_INIT(ini_sections);
|
|
|
|
|
|
|
|
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)
|
|
|
|
return 1;
|
2021-08-22 14:56:05 +01:00
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
// Add config entry.
|
|
|
|
f_puts("[config]\nautoboot=", &fp);
|
|
|
|
itoa(h_cfg.autoboot, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 14:56:05 +01:00
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
f_puts("\nautoboot_list=", &fp);
|
|
|
|
itoa(h_cfg.autoboot_list, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-28 15:57:36 +01:00
|
|
|
/*
|
2021-09-17 21:34:16 +01:00
|
|
|
* Clamp value to default if it exceeds 20s to protect against corruption.
|
2021-08-28 15:57:36 +01:00
|
|
|
* Allow up to 20s though for use in cases where user needs lots of time.
|
|
|
|
* For example dock-only use and r2p with enough time to reach dock and cancel it.
|
|
|
|
*/
|
|
|
|
if (h_cfg.bootwait > 20)
|
|
|
|
h_cfg.bootwait = 3;
|
2019-06-30 02:03:00 +01:00
|
|
|
f_puts("\nbootwait=", &fp);
|
|
|
|
itoa(h_cfg.bootwait, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 14:56:05 +01:00
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
f_puts("\nbacklight=", &fp);
|
|
|
|
itoa(h_cfg.backlight, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 14:56:05 +01:00
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
f_puts("\nautohosoff=", &fp);
|
|
|
|
itoa(h_cfg.autohosoff, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 14:56:05 +01:00
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
f_puts("\nautonogc=", &fp);
|
|
|
|
itoa(h_cfg.autonogc, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-08-22 14:56:05 +01: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 14:56:05 +01:00
|
|
|
|
2020-10-20 08:16:12 +01:00
|
|
|
f_puts("\nbootprotect=", &fp);
|
|
|
|
itoa(h_cfg.bootprotect, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2019-06-30 02:03:00 +01:00
|
|
|
f_puts("\n", &fp);
|
|
|
|
|
|
|
|
if (mainIniFound)
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
f_close(&fp);
|
2020-06-13 16:32:40 +01:00
|
|
|
sd_unmount();
|
2019-06-30 02:03:00 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-07-06 20:08:37 +01:00
|
|
|
|
2021-05-11 07:32:38 +01:00
|
|
|
int create_nyx_config_entry(bool force_unmount)
|
2020-04-30 00:00:33 +01:00
|
|
|
{
|
2021-05-11 07:32:38 +01:00
|
|
|
bool sd_mounted = sd_get_card_mounted();
|
|
|
|
|
2020-04-30 00:00:33 +01:00
|
|
|
if (!sd_mount())
|
|
|
|
return 1;
|
|
|
|
|
2021-05-11 07:32:38 +01:00
|
|
|
char lbuf[64];
|
2020-04-30 00:00:33 +01:00
|
|
|
FIL fp;
|
|
|
|
|
|
|
|
// Make sure that bootloader folder exists.
|
|
|
|
f_mkdir("bootloader");
|
|
|
|
|
|
|
|
if (f_open(&fp, "bootloader/nyx.ini", FA_WRITE | FA_CREATE_ALWAYS) != FR_OK)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
// Add config entry.
|
2020-04-30 02:04:24 +01:00
|
|
|
f_puts("[config]\nthemecolor=", &fp);
|
|
|
|
itoa(n_cfg.themecolor, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2020-04-30 12:51:48 +01:00
|
|
|
f_puts("\ntimeoff=", &fp);
|
2020-05-05 17:20:04 +01:00
|
|
|
itoa(n_cfg.timeoff, lbuf, 16);
|
2020-04-30 12:51:48 +01:00
|
|
|
f_puts(lbuf, &fp);
|
2020-04-30 12:49:28 +01:00
|
|
|
f_puts("\nhomescreen=", &fp);
|
|
|
|
itoa(n_cfg.home_screen, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2020-04-30 02:04:24 +01:00
|
|
|
f_puts("\nverification=", &fp);
|
2020-04-30 00:00:33 +01:00
|
|
|
itoa(n_cfg.verification, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2020-05-05 17:26:10 +01:00
|
|
|
f_puts("\numsemmcrw=", &fp);
|
|
|
|
itoa(n_cfg.ums_emmc_rw, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2020-10-20 08:21:48 +01:00
|
|
|
f_puts("\njcdisable=", &fp);
|
|
|
|
itoa(n_cfg.jc_disable, lbuf, 10);
|
|
|
|
f_puts(lbuf, &fp);
|
2021-05-11 07:32:38 +01:00
|
|
|
f_puts("\nbpmpclock=", &fp);
|
|
|
|
itoa(n_cfg.bpmp_clock, lbuf, 10);
|
2020-12-02 00:07:31 +00:00
|
|
|
f_puts(lbuf, &fp);
|
2020-04-30 00:00:33 +01:00
|
|
|
f_puts("\n", &fp);
|
|
|
|
|
|
|
|
f_close(&fp);
|
2021-05-11 07:32:38 +01:00
|
|
|
|
|
|
|
if (force_unmount || !sd_mounted)
|
|
|
|
sd_unmount();
|
2020-04-30 00:00:33 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|