2019-06-30 01:03:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 naehrwert
|
|
|
|
*
|
2023-02-11 21:59:30 +00:00
|
|
|
* Copyright (c) 2018-2023 CTCaer
|
2019-06-30 01:03:00 +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>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2022-01-15 22:04:34 +00:00
|
|
|
#include <bdk.h>
|
2019-12-08 00:23:03 +00:00
|
|
|
|
2020-06-14 13:45:45 +00:00
|
|
|
#include "config.h"
|
2019-06-30 01:03:00 +00:00
|
|
|
#include "hos/hos.h"
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <ianos/ianos.h>
|
|
|
|
#include <libs/compr/blz.h>
|
|
|
|
#include <libs/fatfs/ff.h>
|
2019-06-30 01:03:00 +00:00
|
|
|
|
|
|
|
#include "frontend/fe_emmc_tools.h"
|
|
|
|
#include "frontend/gui.h"
|
|
|
|
|
2020-04-30 00:25:22 +00:00
|
|
|
nyx_config n_cfg;
|
2019-06-30 01:03:00 +00:00
|
|
|
hekate_config h_cfg;
|
2019-09-12 20:08:38 +00:00
|
|
|
|
2019-06-30 01:03:00 +00:00
|
|
|
const volatile ipl_ver_meta_t __attribute__((section ("._ipl_version"))) ipl_ver = {
|
2019-12-11 09:22:11 +00:00
|
|
|
.magic = NYX_MAGIC,
|
|
|
|
.version = (NYX_VER_MJ + '0') | ((NYX_VER_MN + '0') << 8) | ((NYX_VER_HF + '0') << 16),
|
2019-06-30 01:03:00 +00:00
|
|
|
.rsvd0 = 0,
|
|
|
|
.rsvd1 = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
volatile nyx_storage_t *nyx_str = (nyx_storage_t *)NYX_STORAGE_ADDR;
|
|
|
|
volatile boot_cfg_t *b_cfg;
|
|
|
|
|
2021-01-03 12:45:06 +00:00
|
|
|
char *emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage)
|
2019-06-30 01:03:00 +00:00
|
|
|
{
|
2021-01-03 12:45:06 +00:00
|
|
|
static char emmc_sn[9] = {0};
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2021-01-03 12:45:06 +00:00
|
|
|
// Check if eMMC S/N storage has valid data and skip parsing in that case.
|
|
|
|
if (emmc_sn[0] && strcmp(emmc_sn, "00000000"))
|
|
|
|
goto create_dir;
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2021-01-03 12:45:06 +00:00
|
|
|
// Get actual eMMC S/N.
|
2019-06-30 01:03:00 +00:00
|
|
|
if (!storage)
|
|
|
|
{
|
2022-01-20 11:15:04 +00:00
|
|
|
if (!emmc_initialize(false))
|
2021-01-03 12:45:06 +00:00
|
|
|
strcpy(emmc_sn, "00000000");
|
2019-06-30 01:03:00 +00:00
|
|
|
else
|
|
|
|
{
|
2021-02-06 02:17:31 +00:00
|
|
|
itoa(emmc_storage.cid.serial, emmc_sn, 16);
|
2022-10-11 01:19:29 +00:00
|
|
|
emmc_end();
|
2019-06-30 01:03:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2021-01-03 12:45:06 +00:00
|
|
|
itoa(storage->cid.serial, emmc_sn, 16);
|
|
|
|
|
|
|
|
create_dir:
|
|
|
|
// Check if only eMMC S/N was requested.
|
|
|
|
if (!path)
|
|
|
|
return emmc_sn;
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2021-01-03 12:45:06 +00:00
|
|
|
// Create main folder.
|
|
|
|
strcpy(path, "backup");
|
|
|
|
f_mkdir(path);
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2021-01-03 12:45:06 +00:00
|
|
|
// Create eMMC S/N folder.
|
|
|
|
strcat(path, "/");
|
|
|
|
strcat(path, emmc_sn);
|
2019-06-30 01:03:00 +00:00
|
|
|
f_mkdir(path);
|
2021-01-03 12:45:06 +00:00
|
|
|
|
|
|
|
// Create sub folder if defined. Dir slash must be included.
|
|
|
|
strcat(path, sub_dir); // Can be a null-terminator.
|
|
|
|
if (strlen(sub_dir))
|
2019-06-30 01:03:00 +00:00
|
|
|
f_mkdir(path);
|
|
|
|
|
2021-01-03 12:45:06 +00:00
|
|
|
// Add filename.
|
|
|
|
strcat(path, "/");
|
|
|
|
strcat(path, filename); // Can be a null-terminator.
|
|
|
|
|
|
|
|
return emmc_sn;
|
2019-06-30 01:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This is a safe and unused DRAM region for our payloads.
|
|
|
|
#define RELOC_META_OFF 0x7C
|
|
|
|
#define PATCHED_RELOC_SZ 0x94
|
|
|
|
#define PATCHED_RELOC_STACK 0x40007000
|
|
|
|
#define PATCHED_RELOC_ENTRY 0x40010000
|
|
|
|
#define EXT_PAYLOAD_ADDR 0xC0000000
|
|
|
|
#define RCM_PAYLOAD_ADDR (EXT_PAYLOAD_ADDR + ALIGN(PATCHED_RELOC_SZ, 0x10))
|
2020-03-21 20:18:40 +00:00
|
|
|
#define COREBOOT_END_ADDR 0xD0000000
|
2022-07-01 08:33:43 +00:00
|
|
|
#define CBFS_DRAM_EN_ADDR 0x4003E000
|
2019-06-30 01:03:00 +00:00
|
|
|
#define CBFS_DRAM_MAGIC 0x4452414D // "DRAM"
|
|
|
|
|
2020-03-21 20:18:40 +00:00
|
|
|
static void *coreboot_addr;
|
|
|
|
|
2019-06-30 01:03:00 +00:00
|
|
|
void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size)
|
|
|
|
{
|
2020-04-30 11:45:59 +00:00
|
|
|
memcpy((u8 *)payload_src, (u8 *)nyx_str->hekate, PATCHED_RELOC_SZ);
|
2019-06-30 01:03:00 +00:00
|
|
|
|
|
|
|
volatile reloc_meta_t *relocator = (reloc_meta_t *)(payload_src + RELOC_META_OFF);
|
|
|
|
|
|
|
|
relocator->start = payload_dst - ALIGN(PATCHED_RELOC_SZ, 0x10);
|
|
|
|
relocator->stack = PATCHED_RELOC_STACK;
|
|
|
|
relocator->end = payload_dst + payload_size;
|
|
|
|
relocator->ep = payload_dst;
|
|
|
|
|
|
|
|
if (payload_size == 0x7000)
|
|
|
|
{
|
2023-02-11 21:51:43 +00:00
|
|
|
memcpy((u8 *)(payload_src + ALIGN(PATCHED_RELOC_SZ, 0x10)), coreboot_addr, 0x7000); // Bootblock.
|
2019-06-30 01:03:00 +00:00
|
|
|
*(vu32 *)CBFS_DRAM_EN_ADDR = CBFS_DRAM_MAGIC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lv_res_t launch_payload(lv_obj_t *list)
|
|
|
|
{
|
|
|
|
const char *filename = lv_list_get_btn_text(list);
|
|
|
|
|
|
|
|
if (!filename || !filename[0])
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
char path[128];
|
2019-10-18 15:02:06 +00:00
|
|
|
|
2019-06-30 01:03:00 +00:00
|
|
|
strcpy(path,"bootloader/payloads/");
|
|
|
|
strcat(path, filename);
|
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!sd_mount())
|
|
|
|
goto out;
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
FIL fp;
|
|
|
|
if (f_open(&fp, path, FA_READ))
|
|
|
|
{
|
|
|
|
EPRINTFARGS("Payload file is missing!\n(%s)", path);
|
2020-12-01 22:57:32 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2020-12-01 22:57:32 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
// Read and copy the payload to our chosen address
|
|
|
|
void *buf;
|
|
|
|
u32 size = f_size(&fp);
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (size < 0x30000)
|
|
|
|
buf = (void *)RCM_PAYLOAD_ADDR;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
coreboot_addr = (void *)(COREBOOT_END_ADDR - size);
|
|
|
|
buf = coreboot_addr;
|
|
|
|
if (h_cfg.t210b01)
|
2019-06-30 01:03:00 +00:00
|
|
|
{
|
|
|
|
f_close(&fp);
|
2020-04-29 15:53:29 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
EPRINTF("Coreboot not allowed on Mariko!");
|
|
|
|
|
2019-06-30 01:03:00 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
}
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (f_read(&fp, buf, size, NULL))
|
|
|
|
{
|
2019-06-30 01:03:00 +00:00
|
|
|
f_close(&fp);
|
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
f_close(&fp);
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
sd_end();
|
2019-08-27 23:39:43 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (size < 0x30000)
|
|
|
|
{
|
|
|
|
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, ALIGN(size, 0x10));
|
|
|
|
hw_reinit_workaround(false, byte_swap_32(*(u32 *)(buf + size - sizeof(u32))));
|
2019-06-30 01:03:00 +00:00
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, 0x7000);
|
|
|
|
hw_reinit_workaround(true, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void (*ext_payload_ptr)() = (void *)EXT_PAYLOAD_ADDR;
|
|
|
|
|
|
|
|
// Some cards (Sandisk U1), do not like a fast power cycle. Wait min 100ms.
|
|
|
|
sdmmc_storage_init_wait_sd();
|
|
|
|
|
|
|
|
// Launch our payload.
|
|
|
|
(*ext_payload_ptr)();
|
2019-06-30 01:03:00 +00:00
|
|
|
|
|
|
|
out:
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_unmount();
|
2020-03-21 20:18:40 +00:00
|
|
|
|
2019-06-30 01:03:00 +00:00
|
|
|
return LV_RES_OK;
|
|
|
|
}
|
|
|
|
|
2022-10-11 03:24:52 +00:00
|
|
|
static void _load_saved_configuration()
|
2019-06-30 01:03:00 +00:00
|
|
|
{
|
|
|
|
LIST_INIT(ini_sections);
|
2020-04-29 23:00:33 +00:00
|
|
|
LIST_INIT(ini_nyx_sections);
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
|
2022-12-19 02:41:21 +00:00
|
|
|
{
|
|
|
|
create_config_entry();
|
2022-01-28 23:23:40 +00:00
|
|
|
goto skip_main_cfg_parse;
|
2022-12-19 02:41:21 +00:00
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
|
2020-04-29 23:00:33 +00:00
|
|
|
// Load hekate configuration.
|
2022-01-28 23:23:40 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
|
2019-06-30 01:03:00 +00:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
// Only parse config section.
|
|
|
|
if (ini_sec->type == INI_CHOICE && !strcmp(ini_sec->name, "config"))
|
2019-06-30 01:03:00 +00:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
|
2019-06-30 01:03:00 +00:00
|
|
|
{
|
2022-10-11 03:24:52 +00:00
|
|
|
if (!strcmp("autoboot", kv->key))
|
|
|
|
h_cfg.autoboot = atoi(kv->val);
|
2022-01-28 23:23:40 +00:00
|
|
|
else if (!strcmp("autoboot_list", kv->key))
|
|
|
|
h_cfg.autoboot_list = atoi(kv->val);
|
2022-10-11 03:24:52 +00:00
|
|
|
else if (!strcmp("bootwait", kv->key))
|
|
|
|
h_cfg.bootwait = atoi(kv->val);
|
|
|
|
else if (!strcmp("backlight", kv->key))
|
2019-06-30 01:03:00 +00:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
h_cfg.backlight = atoi(kv->val);
|
|
|
|
if (h_cfg.backlight <= 20)
|
|
|
|
h_cfg.backlight = 30;
|
2020-04-29 23:00:33 +00:00
|
|
|
}
|
2022-10-11 04:49:17 +00:00
|
|
|
else if (!strcmp("noticker", kv->key))
|
|
|
|
h_cfg.noticker = atoi(kv->val);
|
2022-10-11 03:24:52 +00:00
|
|
|
else if (!strcmp("autohosoff", kv->key))
|
|
|
|
h_cfg.autohosoff = atoi(kv->val);
|
|
|
|
else if (!strcmp("autonogc", kv->key))
|
|
|
|
h_cfg.autonogc = atoi(kv->val);
|
|
|
|
else if (!strcmp("updater2p", kv->key))
|
|
|
|
h_cfg.updater2p = atoi(kv->val);
|
2022-01-28 23:23:40 +00:00
|
|
|
else if (!strcmp("bootprotect", kv->key))
|
|
|
|
h_cfg.bootprotect = atoi(kv->val);
|
2020-04-29 23:00:33 +00:00
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
|
|
|
|
break;
|
2020-04-29 23:00:33 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2022-05-19 12:14:05 +00:00
|
|
|
ini_free(&ini_sections);
|
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
skip_main_cfg_parse:
|
|
|
|
if (!ini_parse(&ini_nyx_sections, "bootloader/nyx.ini", false))
|
|
|
|
return;
|
|
|
|
|
2020-04-29 23:00:33 +00:00
|
|
|
// Load Nyx configuration.
|
2022-01-28 23:23:40 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_nyx_sections, link)
|
2020-04-29 23:00:33 +00:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
// Only parse config section.
|
|
|
|
if (ini_sec->type == INI_CHOICE && !strcmp(ini_sec->name, "config"))
|
2020-04-29 23:00:33 +00:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
|
2020-04-29 23:00:33 +00:00
|
|
|
{
|
2022-10-11 05:32:32 +00:00
|
|
|
if (!strcmp("themebg", kv->key))
|
|
|
|
n_cfg.theme_bg = strtol(kv->val, NULL, 16);
|
|
|
|
else if (!strcmp("themecolor", kv->key))
|
2022-10-11 03:24:52 +00:00
|
|
|
n_cfg.theme_color = atoi(kv->val);
|
|
|
|
else if (!strcmp("entries5col", kv->key))
|
|
|
|
n_cfg.entries_5_col = atoi(kv->val) == 1;
|
|
|
|
else if (!strcmp("timeoff", kv->key))
|
|
|
|
n_cfg.timeoff = strtol(kv->val, NULL, 16);
|
|
|
|
else if (!strcmp("homescreen", kv->key))
|
|
|
|
n_cfg.home_screen = atoi(kv->val);
|
2022-01-28 23:23:40 +00:00
|
|
|
else if (!strcmp("verification", kv->key))
|
2022-10-11 03:24:52 +00:00
|
|
|
n_cfg.verification = atoi(kv->val);
|
|
|
|
else if (!strcmp("umsemmcrw", kv->key))
|
|
|
|
n_cfg.ums_emmc_rw = atoi(kv->val) == 1;
|
|
|
|
else if (!strcmp("jcdisable", kv->key))
|
|
|
|
n_cfg.jc_disable = atoi(kv->val) == 1;
|
2022-03-22 22:49:47 +00:00
|
|
|
else if (!strcmp("jcforceright", kv->key))
|
|
|
|
n_cfg.jc_force_right = atoi(kv->val) == 1;
|
2022-10-11 03:24:52 +00:00
|
|
|
else if (!strcmp("bpmpclock", kv->key))
|
|
|
|
n_cfg.bpmp_clock = atoi(kv->val);
|
2019-06-30 01:03:00 +00:00
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
|
|
|
|
break;
|
2019-06-30 01:03:00 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-19 12:14:05 +00:00
|
|
|
|
|
|
|
ini_free(&ini_nyx_sections);
|
2019-06-30 01:03:00 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 22:17:24 +00:00
|
|
|
static int nyx_load_resources()
|
|
|
|
{
|
|
|
|
FIL fp;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = f_open(&fp, "bootloader/sys/res.pak", FA_READ);
|
|
|
|
if (res)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
res = f_read(&fp, (void *)NYX_RES_ADDR, f_size(&fp), NULL);
|
|
|
|
f_close(&fp);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nyx_load_bg_icons()
|
|
|
|
{
|
|
|
|
// If no custom switch icon exists, load normal.
|
|
|
|
if (!f_stat("bootloader/res/icon_switch_custom.bmp", NULL))
|
|
|
|
icon_switch = bmp_to_lvimg_obj("bootloader/res/icon_switch_custom.bmp");
|
|
|
|
else
|
|
|
|
icon_switch = bmp_to_lvimg_obj("bootloader/res/icon_switch.bmp");
|
|
|
|
|
|
|
|
// If no custom payload icon exists, load normal.
|
|
|
|
if (!f_stat("bootloader/res/icon_payload_custom.bmp", NULL))
|
|
|
|
icon_payload = bmp_to_lvimg_obj("bootloader/res/icon_payload_custom.bmp");
|
|
|
|
else
|
|
|
|
icon_payload = bmp_to_lvimg_obj("bootloader/res/icon_payload.bmp");
|
|
|
|
|
|
|
|
// Load background resource if any.
|
|
|
|
hekate_bg = bmp_to_lvimg_obj("bootloader/res/background.bmp");
|
|
|
|
}
|
|
|
|
|
2020-04-27 06:56:19 +00:00
|
|
|
#define EXCP_EN_ADDR 0x4003FFFC
|
2020-07-18 09:53:05 +00:00
|
|
|
#define EXCP_MAGIC 0x30505645 // EVP0
|
2020-04-27 06:56:19 +00:00
|
|
|
#define EXCP_TYPE_ADDR 0x4003FFF8
|
2020-07-18 09:53:05 +00:00
|
|
|
#define EXCP_TYPE_RESET 0x545352 // RST
|
|
|
|
#define EXCP_TYPE_UNDEF 0x464455 // UDF
|
2020-04-27 06:56:19 +00:00
|
|
|
#define EXCP_TYPE_PABRT 0x54424150 // PABT
|
|
|
|
#define EXCP_TYPE_DABRT 0x54424144 // DABT
|
|
|
|
#define EXCP_LR_ADDR 0x4003FFF4
|
|
|
|
|
2023-02-11 22:17:24 +00:00
|
|
|
enum {
|
|
|
|
SD_NO_ERROR = 0,
|
|
|
|
SD_MOUNT_ERROR = 1,
|
|
|
|
SD_FILE_ERROR = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
static void _show_errors(int sd_error)
|
2020-04-27 06:56:19 +00:00
|
|
|
{
|
|
|
|
u32 *excp_enabled = (u32 *)EXCP_EN_ADDR;
|
|
|
|
u32 *excp_type = (u32 *)EXCP_TYPE_ADDR;
|
|
|
|
u32 *excp_lr = (u32 *)EXCP_LR_ADDR;
|
|
|
|
|
2023-02-11 22:17:24 +00:00
|
|
|
if (*excp_enabled == EXCP_MAGIC || sd_error)
|
2020-04-27 06:56:19 +00:00
|
|
|
{
|
|
|
|
gfx_clear_grey(0);
|
|
|
|
gfx_con_setpos(0, 0);
|
2022-01-15 23:33:07 +00:00
|
|
|
display_backlight_brightness(150, 1000);
|
2023-02-11 22:17:24 +00:00
|
|
|
display_init_framebuffer_log();
|
2020-04-30 11:45:59 +00:00
|
|
|
display_activate_console();
|
2023-02-11 22:17:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (sd_error)
|
|
|
|
{
|
|
|
|
case SD_MOUNT_ERROR:
|
|
|
|
WPRINTF("Failed to init or mount SD!\n");
|
|
|
|
goto error_occured;
|
|
|
|
case SD_FILE_ERROR:
|
|
|
|
WPRINTF("Failed to load GUI resources!\nres.pak not found or corrupted.\n");
|
|
|
|
goto error_occured;
|
|
|
|
case SD_NO_ERROR:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2020-04-30 11:45:59 +00:00
|
|
|
|
2023-02-11 22:17:24 +00:00
|
|
|
if (*excp_enabled == EXCP_MAGIC)
|
|
|
|
{
|
2022-01-15 23:33:07 +00:00
|
|
|
WPRINTFARGS("Nyx exception occurred (LR %08X):\n", *excp_lr);
|
2020-04-27 06:56:19 +00:00
|
|
|
switch (*excp_type)
|
|
|
|
{
|
|
|
|
case EXCP_TYPE_RESET:
|
2020-10-23 03:32:24 +00:00
|
|
|
WPRINTF("RESET");
|
2020-04-27 06:56:19 +00:00
|
|
|
break;
|
|
|
|
case EXCP_TYPE_UNDEF:
|
2020-07-14 19:41:48 +00:00
|
|
|
WPRINTF("UNDEF");
|
2020-04-27 06:56:19 +00:00
|
|
|
break;
|
|
|
|
case EXCP_TYPE_PABRT:
|
2020-07-14 19:41:48 +00:00
|
|
|
WPRINTF("PABRT");
|
2020-04-27 06:56:19 +00:00
|
|
|
break;
|
|
|
|
case EXCP_TYPE_DABRT:
|
2020-07-14 19:41:48 +00:00
|
|
|
WPRINTF("DABRT");
|
2020-04-27 06:56:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-01-15 23:33:07 +00:00
|
|
|
gfx_puts("\n");
|
2020-04-27 06:56:19 +00:00
|
|
|
|
|
|
|
// Clear the exception.
|
|
|
|
*excp_lr = 0;
|
|
|
|
*excp_type = 0;
|
|
|
|
*excp_enabled = 0;
|
|
|
|
|
2023-02-11 22:17:24 +00:00
|
|
|
error_occured:
|
|
|
|
WPRINTF("Press any key to reload Nyx...");
|
2020-04-27 06:56:19 +00:00
|
|
|
|
2023-02-11 22:17:24 +00:00
|
|
|
msleep(1000);
|
2020-04-27 06:56:19 +00:00
|
|
|
btn_wait();
|
|
|
|
|
|
|
|
reload_nyx();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-30 01:03:00 +00:00
|
|
|
void nyx_init_load_res()
|
|
|
|
{
|
|
|
|
bpmp_mmu_enable();
|
2020-04-30 11:45:59 +00:00
|
|
|
bpmp_clk_rate_get();
|
2021-05-11 06:32:38 +00:00
|
|
|
|
|
|
|
// Set a modest clock for init. It will be restored later if possible.
|
|
|
|
bpmp_clk_rate_set(BPMP_CLK_LOWER_BOOST);
|
2019-06-30 01:03:00 +00:00
|
|
|
|
|
|
|
// Set bootloader's default configuration.
|
|
|
|
set_default_configuration();
|
2020-04-30 00:25:22 +00:00
|
|
|
set_nyx_default_configuration();
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2020-12-11 15:46:44 +00:00
|
|
|
// Reset new info if magic not correct.
|
|
|
|
if (nyx_str->info.magic != NYX_NEW_INFO)
|
|
|
|
{
|
|
|
|
nyx_str->info.sd_init = 0;
|
|
|
|
for (u32 i = 0; i < 3; i++)
|
|
|
|
nyx_str->info.sd_errors[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clear info magic.
|
|
|
|
nyx_str->info.magic = 0;
|
|
|
|
|
2020-12-11 15:49:06 +00:00
|
|
|
// Set display id from previous initialization.
|
|
|
|
display_set_decoded_panel_id(nyx_str->info.disp_id);
|
|
|
|
|
2020-12-11 15:46:44 +00:00
|
|
|
// Initialize gfx console.
|
2020-04-30 11:07:26 +00:00
|
|
|
gfx_init_ctxt((u32 *)LOG_FB_ADDRESS, 1280, 656, 656);
|
2019-06-30 01:03:00 +00:00
|
|
|
gfx_con_init();
|
|
|
|
|
2020-04-30 00:25:22 +00:00
|
|
|
// Show exception errors if any.
|
2023-02-11 22:17:24 +00:00
|
|
|
_show_errors(SD_NO_ERROR);
|
2020-04-30 00:25:22 +00:00
|
|
|
|
2023-02-11 22:17:24 +00:00
|
|
|
// Try 2 times to mount SD card.
|
|
|
|
if (!sd_mount())
|
|
|
|
{
|
2023-02-22 11:46:50 +00:00
|
|
|
// Restore speed to SDR104.
|
|
|
|
sd_end();
|
|
|
|
|
|
|
|
// Retry.
|
2023-02-11 22:17:24 +00:00
|
|
|
if (!sd_mount())
|
|
|
|
_show_errors(SD_MOUNT_ERROR); // Fatal.
|
|
|
|
}
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2019-12-04 19:59:58 +00:00
|
|
|
// Train DRAM and switch to max frequency.
|
2019-06-30 01:03:00 +00:00
|
|
|
minerva_init();
|
|
|
|
|
2022-10-11 03:24:52 +00:00
|
|
|
// Load hekate/Nyx configuration.
|
|
|
|
_load_saved_configuration();
|
2019-10-18 15:02:06 +00:00
|
|
|
|
2023-02-11 22:17:24 +00:00
|
|
|
// Load Nyx resources.
|
|
|
|
if (nyx_load_resources())
|
|
|
|
{
|
|
|
|
// Try again.
|
|
|
|
if (nyx_load_resources())
|
|
|
|
_show_errors(SD_FILE_ERROR); // Fatal since resources are mandatory.
|
|
|
|
}
|
|
|
|
|
2023-02-11 21:56:16 +00:00
|
|
|
// Initialize nyx cfg to lower clock on first boot.
|
2021-05-11 06:32:38 +00:00
|
|
|
// In case of lower binned SoC, this can help with hangs.
|
|
|
|
if (!n_cfg.bpmp_clock)
|
|
|
|
{
|
2023-02-11 21:56:16 +00:00
|
|
|
// Set lower clock and save it.
|
|
|
|
n_cfg.bpmp_clock = 2;
|
2021-05-11 06:32:38 +00:00
|
|
|
create_nyx_config_entry(false);
|
2023-02-11 21:56:16 +00:00
|
|
|
|
|
|
|
// Start at max clock and test it.
|
|
|
|
n_cfg.bpmp_clock = 0;
|
2021-05-11 06:32:38 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 21:56:16 +00:00
|
|
|
// Set selected clock.
|
|
|
|
switch (n_cfg.bpmp_clock)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 1:
|
2021-05-11 06:32:38 +00:00
|
|
|
bpmp_clk_rate_set(BPMP_CLK_DEFAULT_BOOST);
|
2023-02-11 21:56:16 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
bpmp_clk_rate_set(BPMP_CLK_LOWER_BOOST);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
default:
|
|
|
|
bpmp_clk_rate_set(BPMP_CLK_LOWEST_BOOST);
|
|
|
|
break;
|
|
|
|
}
|
2021-05-11 06:32:38 +00:00
|
|
|
|
2023-02-11 22:17:24 +00:00
|
|
|
// Load default launch icons and background if it exists.
|
|
|
|
nyx_load_bg_icons();
|
2019-06-30 01:03:00 +00:00
|
|
|
|
2022-10-11 03:24:52 +00:00
|
|
|
// Unmount FAT partition.
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_unmount();
|
2019-06-30 01:03:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ipl_main()
|
|
|
|
{
|
2023-02-11 21:51:43 +00:00
|
|
|
// Set heap address.
|
2022-02-14 22:23:23 +00:00
|
|
|
heap_init((void *)IPL_HEAP_START);
|
2019-06-30 01:03:00 +00:00
|
|
|
|
|
|
|
b_cfg = (boot_cfg_t *)(nyx_str->hekate + 0x94);
|
|
|
|
|
2020-08-13 07:21:00 +00:00
|
|
|
#ifdef DEBUG_UART_PORT
|
2023-02-11 21:51:43 +00:00
|
|
|
// Enable the selected uart debug port.
|
2022-05-13 00:57:09 +00:00
|
|
|
#if (DEBUG_UART_PORT == UART_B)
|
2020-08-13 07:21:00 +00:00
|
|
|
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO);
|
2022-05-13 00:57:09 +00:00
|
|
|
#elif (DEBUG_UART_PORT == UART_C)
|
2020-08-13 07:21:00 +00:00
|
|
|
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_SPIO);
|
|
|
|
#endif
|
|
|
|
pinmux_config_uart(DEBUG_UART_PORT);
|
|
|
|
clock_enable_uart(DEBUG_UART_PORT);
|
2022-05-08 02:46:23 +00:00
|
|
|
uart_init(DEBUG_UART_PORT, DEBUG_UART_BAUDRATE, UART_AO_TX_AO_RX);
|
2020-12-11 16:14:00 +00:00
|
|
|
uart_invert(DEBUG_UART_PORT, DEBUG_UART_INVERT, UART_INVERT_TXD);
|
2020-08-13 07:21:00 +00:00
|
|
|
|
|
|
|
uart_send(DEBUG_UART_PORT, (u8 *)"hekate-NYX: Hello!\r\n", 20);
|
2022-05-08 02:46:23 +00:00
|
|
|
uart_wait_xfer(DEBUG_UART_PORT, UART_TX_IDLE);
|
2019-06-30 01:03:00 +00:00
|
|
|
#endif
|
|
|
|
|
2023-02-11 21:51:43 +00:00
|
|
|
// Initialize the rest of hw and load Nyx resources.
|
2019-06-30 01:03:00 +00:00
|
|
|
nyx_init_load_res();
|
|
|
|
|
2023-02-11 21:51:43 +00:00
|
|
|
// Initialize Nyx GUI and show it.
|
2019-06-30 01:03:00 +00:00
|
|
|
nyx_load_and_run();
|
|
|
|
|
2019-08-27 22:33:38 +00:00
|
|
|
// Halt BPMP if we managed to get out of execution.
|
2019-06-30 01:03:00 +00:00
|
|
|
while (true)
|
2019-08-27 22:33:38 +00:00
|
|
|
bpmp_halt();
|
2019-06-30 01:03:00 +00:00
|
|
|
}
|