2018-11-28 19:26:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 naehrwert
|
2024-03-27 07:16:06 +00:00
|
|
|
* Copyright (c) 2018-2024 CTCaer
|
2018-11-28 19:26:16 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2022-01-15 22:04:34 +00:00
|
|
|
#include <bdk.h>
|
|
|
|
|
2018-11-28 19:26:16 +00:00
|
|
|
#include "hos.h"
|
|
|
|
#include "hos_config.h"
|
2019-03-07 23:14:43 +00:00
|
|
|
#include "fss.h"
|
2020-06-14 14:45:45 +01:00
|
|
|
#include <libs/fatfs/ff.h>
|
2018-11-28 19:26:16 +00:00
|
|
|
|
2019-04-14 00:30:14 +01:00
|
|
|
//#define DPRINTF(...) gfx_printf(__VA_ARGS__)
|
2018-11-28 19:26:16 +00:00
|
|
|
#define DPRINTF(...)
|
|
|
|
|
|
|
|
static int _config_warmboot(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
2019-03-16 21:35:43 +00:00
|
|
|
ctxt->warmboot = sd_file_read(value, &ctxt->warmboot_size);
|
|
|
|
if (!ctxt->warmboot)
|
2018-11-28 19:26:16 +00:00
|
|
|
return 0;
|
2019-10-18 16:02:06 +01:00
|
|
|
|
2018-11-28 19:26:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _config_secmon(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
2019-03-16 21:35:43 +00:00
|
|
|
ctxt->secmon = sd_file_read(value, &ctxt->secmon_size);
|
|
|
|
if (!ctxt->secmon)
|
2018-11-28 19:26:16 +00:00
|
|
|
return 0;
|
2019-03-16 21:35:43 +00:00
|
|
|
|
2018-11-28 19:26:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _config_kernel(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
2019-03-16 21:35:43 +00:00
|
|
|
ctxt->kernel = sd_file_read(value, &ctxt->kernel_size);
|
|
|
|
if (!ctxt->kernel)
|
2018-11-28 19:26:16 +00:00
|
|
|
return 0;
|
2019-03-16 21:35:43 +00:00
|
|
|
|
2018-11-28 19:26:16 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _config_kip1(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
2019-03-16 21:35:43 +00:00
|
|
|
u32 size;
|
2018-11-28 19:26:16 +00:00
|
|
|
|
|
|
|
if (!memcmp(value + strlen(value) - 1, "*", 1))
|
|
|
|
{
|
|
|
|
char *dir = (char *)malloc(256);
|
2019-12-04 13:56:53 +00:00
|
|
|
strcpy(dir, value);
|
2018-11-28 19:26:16 +00:00
|
|
|
|
|
|
|
u32 dirlen = 0;
|
|
|
|
dir[strlen(dir) - 2] = 0;
|
2024-10-09 13:22:16 +01:00
|
|
|
dirlist_t *filelist = dirlist(dir, "*.kip*", false, false);
|
2018-11-28 19:26:16 +00:00
|
|
|
|
2019-12-04 13:56:53 +00:00
|
|
|
strcat(dir, "/");
|
2018-11-28 19:26:16 +00:00
|
|
|
dirlen = strlen(dir);
|
|
|
|
|
|
|
|
u32 i = 0;
|
|
|
|
if (filelist)
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
2024-10-09 13:22:16 +01:00
|
|
|
if (!filelist->name[i])
|
2018-11-28 19:26:16 +00:00
|
|
|
break;
|
|
|
|
|
2024-10-09 13:22:16 +01:00
|
|
|
strcpy(dir + dirlen, filelist->name[i]);
|
2019-03-16 21:35:43 +00:00
|
|
|
|
|
|
|
merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t));
|
|
|
|
mkip1->kip1 = sd_file_read(dir, &size);
|
|
|
|
if (!mkip1->kip1)
|
2018-11-28 19:26:16 +00:00
|
|
|
{
|
2019-03-16 21:35:43 +00:00
|
|
|
free(mkip1);
|
2018-11-28 19:26:16 +00:00
|
|
|
free(dir);
|
|
|
|
free(filelist);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-03-16 21:35:43 +00:00
|
|
|
DPRINTF("Loaded kip1 from SD (size %08X)\n", size);
|
2018-11-28 19:26:16 +00:00
|
|
|
list_append(&ctxt->kip1_list, &mkip1->link);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(dir);
|
|
|
|
free(filelist);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t));
|
2019-03-16 21:35:43 +00:00
|
|
|
mkip1->kip1 = sd_file_read(value, &size);
|
|
|
|
if (!mkip1->kip1)
|
|
|
|
{
|
|
|
|
free(mkip1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DPRINTF("Loaded kip1 from SD (size %08X)\n", size);
|
2018-11-28 19:26:16 +00:00
|
|
|
list_append(&ctxt->kip1_list, &mkip1->link);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-02-23 23:06:24 +00:00
|
|
|
int config_kip1patch(launch_ctxt_t *ctxt, const char *value)
|
2018-11-28 19:26:16 +00:00
|
|
|
{
|
|
|
|
if (value == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2024-03-27 07:16:06 +00:00
|
|
|
int len = strlen(value);
|
|
|
|
if (!len)
|
2018-11-28 19:26:16 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ctxt->kip1_patches == NULL)
|
|
|
|
{
|
2024-03-27 07:16:06 +00:00
|
|
|
ctxt->kip1_patches = malloc(len + 1);
|
|
|
|
memcpy(ctxt->kip1_patches, value, len);
|
|
|
|
ctxt->kip1_patches[len] = 0;
|
2018-11-28 19:26:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-03-27 07:16:06 +00:00
|
|
|
char *old_addr = ctxt->kip1_patches;
|
|
|
|
int old_len = strlen(old_addr);
|
|
|
|
|
|
|
|
ctxt->kip1_patches = malloc(old_len + 1 + len + 1);
|
|
|
|
memcpy(ctxt->kip1_patches, old_addr, old_len);
|
|
|
|
free(old_addr);
|
|
|
|
|
|
|
|
ctxt->kip1_patches[old_len++] = ',';
|
|
|
|
memcpy(&ctxt->kip1_patches[old_len], value, len);
|
|
|
|
ctxt->kip1_patches[old_len + len] = 0;
|
2018-11-28 19:26:16 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-03-07 22:19:04 +00:00
|
|
|
static int _config_svcperm(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
if (*value == '1')
|
|
|
|
{
|
|
|
|
DPRINTF("Disabled SVC verification\n");
|
|
|
|
ctxt->svcperm = true;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _config_debugmode(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
if (*value == '1')
|
|
|
|
{
|
|
|
|
DPRINTF("Enabled Debug mode\n");
|
|
|
|
ctxt->debugmode = true;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-03-09 18:49:00 +00:00
|
|
|
static int _config_stock(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
if (*value == '1')
|
|
|
|
{
|
|
|
|
DPRINTF("Disabled all patching\n");
|
|
|
|
ctxt->stock = true;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-04-27 07:44:06 +01:00
|
|
|
static int _config_emummc_forced(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
if (*value == '1')
|
|
|
|
{
|
|
|
|
DPRINTF("Forced emuMMC\n");
|
|
|
|
ctxt->emummc_forced = true;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-03-07 22:19:04 +00:00
|
|
|
static int _config_atmosphere(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
if (*value == '1')
|
|
|
|
{
|
|
|
|
DPRINTF("Enabled atmosphere patching\n");
|
|
|
|
ctxt->atmosphere = true;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-09-09 15:00:13 +01:00
|
|
|
static int _config_dis_exo_user_exceptions(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
if (*value == '1')
|
|
|
|
{
|
|
|
|
DPRINTF("Disabled exosphere user exception handlers\n");
|
2020-06-13 23:29:41 +01:00
|
|
|
ctxt->exo_ctx.no_user_exceptions = true;
|
2019-09-09 15:00:13 +01:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-12-08 01:02:17 +00:00
|
|
|
static int _config_exo_user_pmu_access(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
if (*value == '1')
|
|
|
|
{
|
|
|
|
DPRINTF("Enabled user access to PMU\n");
|
2020-06-13 23:29:41 +01:00
|
|
|
ctxt->exo_ctx.user_pmu = true;
|
2019-12-08 01:02:17 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-03-17 07:31:06 +00:00
|
|
|
static int _config_exo_usb3_force(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
// Override key found.
|
2024-03-27 07:16:06 +00:00
|
|
|
ctxt->exo_ctx.usb3_force = zalloc(sizeof(bool));
|
2021-03-17 07:31:06 +00:00
|
|
|
|
|
|
|
if (*value == '1')
|
|
|
|
{
|
|
|
|
DPRINTF("Enabled USB 3.0\n");
|
|
|
|
*ctxt->exo_ctx.usb3_force = true;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2020-04-30 14:21:38 +01:00
|
|
|
static int _config_exo_cal0_blanking(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
// Override key found.
|
2024-03-27 07:16:06 +00:00
|
|
|
ctxt->exo_ctx.cal0_blank = zalloc(sizeof(bool));
|
2020-04-30 14:21:38 +01:00
|
|
|
|
|
|
|
if (*value == '1')
|
|
|
|
{
|
|
|
|
DPRINTF("Enabled prodinfo blanking\n");
|
2020-06-13 23:29:41 +01:00
|
|
|
*ctxt->exo_ctx.cal0_blank = true;
|
2020-04-30 14:21:38 +01:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _config_exo_cal0_writes_enable(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
// Override key found.
|
2024-03-27 07:16:06 +00:00
|
|
|
ctxt->exo_ctx.cal0_allow_writes_sys = zalloc(sizeof(bool));
|
2020-04-30 14:21:38 +01:00
|
|
|
|
|
|
|
if (*value == '1')
|
|
|
|
{
|
|
|
|
DPRINTF("Enabled prodinfo writes\n");
|
2020-06-13 23:29:41 +01:00
|
|
|
*ctxt->exo_ctx.cal0_allow_writes_sys = true;
|
2020-04-30 14:21:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-03-07 23:14:43 +00:00
|
|
|
static int _config_fss(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
2021-08-28 15:53:14 +01:00
|
|
|
return parse_fss(ctxt, value);
|
2019-03-07 23:14:43 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 23:41:23 +00:00
|
|
|
static int _config_exo_fatal_payload(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
ctxt->exofatal = sd_file_read(value, &ctxt->exofatal_size);
|
|
|
|
if (!ctxt->exofatal)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-07-28 01:06:20 +01:00
|
|
|
static int _config_ucid(launch_ctxt_t *ctxt, const char *value)
|
|
|
|
{
|
|
|
|
// Override uCID if set.
|
|
|
|
ctxt->ucid = atoi(value);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-11-28 19:26:16 +00:00
|
|
|
typedef struct _cfg_handler_t
|
|
|
|
{
|
|
|
|
const char *key;
|
|
|
|
int (*handler)(launch_ctxt_t *ctxt, const char *value);
|
|
|
|
} cfg_handler_t;
|
|
|
|
|
|
|
|
static const cfg_handler_t _config_handlers[] = {
|
2023-07-28 01:06:20 +01:00
|
|
|
{ "warmboot", _config_warmboot },
|
|
|
|
{ "secmon", _config_secmon },
|
|
|
|
{ "kernel", _config_kernel },
|
|
|
|
{ "kip1", _config_kip1 },
|
|
|
|
{ "kip1patch", config_kip1patch },
|
|
|
|
{ "fullsvcperm", _config_svcperm },
|
|
|
|
{ "debugmode", _config_debugmode },
|
|
|
|
{ "stock", _config_stock },
|
|
|
|
{ "atmosphere", _config_atmosphere },
|
|
|
|
{ "fss0", _config_fss },
|
|
|
|
{ "exofatal", _config_exo_fatal_payload},
|
|
|
|
{ "emummcforce", _config_emummc_forced },
|
2019-09-09 15:00:13 +01:00
|
|
|
{ "nouserexceptions", _config_dis_exo_user_exceptions },
|
2023-07-28 01:06:20 +01:00
|
|
|
{ "userpmu", _config_exo_user_pmu_access },
|
|
|
|
{ "usb3force", _config_exo_usb3_force },
|
|
|
|
{ "cal0blank", _config_exo_cal0_blanking },
|
|
|
|
{ "cal0writesys", _config_exo_cal0_writes_enable },
|
|
|
|
{ "ucid", _config_ucid },
|
2018-11-28 19:26:16 +00:00
|
|
|
{ NULL, NULL },
|
|
|
|
};
|
|
|
|
|
2019-03-09 18:49:00 +00:00
|
|
|
int parse_boot_config(launch_ctxt_t *ctxt)
|
2018-11-28 19:26:16 +00:00
|
|
|
{
|
2019-03-09 18:49:00 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ctxt->cfg->kvs, link)
|
2018-11-28 19:26:16 +00:00
|
|
|
{
|
2023-02-22 11:45:46 +00:00
|
|
|
for (u32 i = 0; _config_handlers[i].key; i++)
|
2018-11-28 19:26:16 +00:00
|
|
|
{
|
|
|
|
if (!strcmp(_config_handlers[i].key, kv->key))
|
2020-04-30 14:21:38 +01:00
|
|
|
{
|
2018-11-28 19:26:16 +00:00
|
|
|
if (!_config_handlers[i].handler(ctxt, kv->val))
|
2019-04-14 00:19:04 +01:00
|
|
|
{
|
2020-04-30 14:21:38 +01:00
|
|
|
gfx_con.mute = false;
|
2019-04-14 00:19:04 +01:00
|
|
|
EPRINTFARGS("Error while loading %s:\n%s", kv->key, kv->val);
|
2020-04-30 14:21:38 +01:00
|
|
|
|
2018-11-28 19:26:16 +00:00
|
|
|
return 0;
|
2019-04-14 00:19:04 +01:00
|
|
|
}
|
2020-04-30 14:21:38 +01:00
|
|
|
}
|
2018-11-28 19:26:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|