2019-06-30 02:03:00 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 naehrwert
|
|
|
|
*
|
2022-01-20 11:15:04 +00:00
|
|
|
* Copyright (c) 2018-2022 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>
|
|
|
|
|
2022-01-15 22:04:34 +00:00
|
|
|
#include <bdk.h>
|
2019-12-08 00:23:03 +00:00
|
|
|
|
2020-06-14 14:45:45 +01:00
|
|
|
#include "config.h"
|
2019-06-30 02:03:00 +01:00
|
|
|
#include "hos/hos.h"
|
2020-06-14 14:45:45 +01:00
|
|
|
#include <ianos/ianos.h>
|
|
|
|
#include <libs/compr/blz.h>
|
|
|
|
#include <libs/fatfs/ff.h>
|
2019-06-30 02:03:00 +01:00
|
|
|
|
|
|
|
#include "frontend/fe_emmc_tools.h"
|
|
|
|
#include "frontend/gui.h"
|
|
|
|
|
|
|
|
#ifdef MENU_LOGO_ENABLE
|
|
|
|
u8 *Kc_MENU_LOGO;
|
|
|
|
#endif //MENU_LOGO_ENABLE
|
|
|
|
|
2020-04-30 01:25:22 +01:00
|
|
|
nyx_config n_cfg;
|
2019-06-30 02:03:00 +01:00
|
|
|
hekate_config h_cfg;
|
2019-09-12 21:08:38 +01:00
|
|
|
|
2019-06-30 02:03:00 +01: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 02:03:00 +01: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 02:03:00 +01:00
|
|
|
{
|
2021-01-03 12:45:06 +00:00
|
|
|
static char emmc_sn[9] = {0};
|
2019-06-30 02:03:00 +01: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 02:03:00 +01:00
|
|
|
|
2021-01-03 12:45:06 +00:00
|
|
|
// Get actual eMMC S/N.
|
2019-06-30 02:03:00 +01: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 02:03:00 +01:00
|
|
|
else
|
|
|
|
{
|
2021-02-06 02:17:31 +00:00
|
|
|
itoa(emmc_storage.cid.serial, emmc_sn, 16);
|
|
|
|
sdmmc_storage_end(&emmc_storage);
|
2019-06-30 02:03:00 +01: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 02:03:00 +01:00
|
|
|
|
2021-01-03 12:45:06 +00:00
|
|
|
// Create main folder.
|
|
|
|
strcpy(path, "backup");
|
|
|
|
f_mkdir(path);
|
2019-06-30 02:03:00 +01:00
|
|
|
|
2021-01-03 12:45:06 +00:00
|
|
|
// Create eMMC S/N folder.
|
|
|
|
strcat(path, "/");
|
|
|
|
strcat(path, emmc_sn);
|
2019-06-30 02:03:00 +01: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 02:03:00 +01: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 02:03:00 +01: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
|
2019-06-30 02:03:00 +01:00
|
|
|
#define CBFS_DRAM_EN_ADDR 0x4003e000
|
|
|
|
#define CBFS_DRAM_MAGIC 0x4452414D // "DRAM"
|
|
|
|
|
2020-03-21 20:18:40 +00:00
|
|
|
static void *coreboot_addr;
|
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size)
|
|
|
|
{
|
2020-04-30 12:45:59 +01:00
|
|
|
memcpy((u8 *)payload_src, (u8 *)nyx_str->hekate, PATCHED_RELOC_SZ);
|
2019-06-30 02:03:00 +01: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)
|
|
|
|
{
|
2020-03-21 20:18:40 +00:00
|
|
|
memcpy((u8 *)(payload_src + ALIGN(PATCHED_RELOC_SZ, 0x10)), coreboot_addr, 0x7000); //Bootblock
|
2019-06-30 02:03:00 +01: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 16:02:06 +01:00
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
strcpy(path,"bootloader/payloads/");
|
|
|
|
strcat(path, filename);
|
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!sd_mount())
|
|
|
|
goto out;
|
2019-06-30 02:03:00 +01: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 02:03:00 +01: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 02:03:00 +01:00
|
|
|
{
|
|
|
|
f_close(&fp);
|
2020-04-29 16:53:29 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
EPRINTF("Coreboot not allowed on Mariko!");
|
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
goto out;
|
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
}
|
2019-06-30 02:03:00 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (f_read(&fp, buf, size, NULL))
|
|
|
|
{
|
2019-06-30 02:03:00 +01:00
|
|
|
f_close(&fp);
|
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2019-06-30 02:03:00 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
f_close(&fp);
|
2019-06-30 02:03:00 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
sd_end();
|
2019-08-28 00:39:43 +01: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 02:03:00 +01: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 02:03:00 +01:00
|
|
|
|
|
|
|
out:
|
2020-06-13 16:32:40 +01:00
|
|
|
sd_unmount();
|
2020-03-21 20:18:40 +00:00
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
return LV_RES_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void load_saved_configuration()
|
|
|
|
{
|
|
|
|
LIST_INIT(ini_sections);
|
2020-04-30 00:00:33 +01:00
|
|
|
LIST_INIT(ini_nyx_sections);
|
2019-06-30 02:03:00 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
|
|
|
|
goto skip_main_cfg_parse;
|
|
|
|
|
2020-04-30 00:00:33 +01: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 02:03:00 +01: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 02:03:00 +01:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
|
2019-06-30 02:03:00 +01:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!strcmp("autoboot", kv->key))
|
|
|
|
h_cfg.autoboot = atoi(kv->val);
|
|
|
|
else if (!strcmp("autoboot_list", kv->key))
|
|
|
|
h_cfg.autoboot_list = atoi(kv->val);
|
|
|
|
else if (!strcmp("bootwait", kv->key))
|
|
|
|
h_cfg.bootwait = atoi(kv->val);
|
|
|
|
else if (!strcmp("backlight", kv->key))
|
2019-06-30 02:03:00 +01: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-30 00:00:33 +01:00
|
|
|
}
|
2022-01-28 23:23:40 +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);
|
|
|
|
else if (!strcmp("bootprotect", kv->key))
|
|
|
|
h_cfg.bootprotect = atoi(kv->val);
|
2020-04-30 00:00:33 +01:00
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
|
|
|
|
break;
|
2020-04-30 00:00:33 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-30 02:03:00 +01:00
|
|
|
|
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-30 00:00:33 +01: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-30 00:00:33 +01: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-30 00:00:33 +01:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
|
2020-04-30 00:00:33 +01:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!strcmp("themecolor", kv->key))
|
2022-05-13 01:49:32 +01:00
|
|
|
n_cfg.theme_color = atoi(kv->val);
|
|
|
|
else if (!strcmp("entries5col", kv->key))
|
|
|
|
n_cfg.entries_5_columns = atoi(kv->val) == 1;
|
2022-01-28 23:23:40 +00:00
|
|
|
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);
|
|
|
|
else if (!strcmp("verification", kv->key))
|
|
|
|
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-01-28 23:23:40 +00:00
|
|
|
else if (!strcmp("bpmpclock", kv->key))
|
|
|
|
n_cfg.bpmp_clock = strtol(kv->val, NULL, 10);
|
2019-06-30 02:03:00 +01:00
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
|
|
|
|
break;
|
2019-06-30 02:03:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-27 07:56:19 +01:00
|
|
|
#define EXCP_EN_ADDR 0x4003FFFC
|
2020-07-18 10:53:05 +01:00
|
|
|
#define EXCP_MAGIC 0x30505645 // EVP0
|
2020-04-27 07:56:19 +01:00
|
|
|
#define EXCP_TYPE_ADDR 0x4003FFF8
|
2020-07-18 10:53:05 +01:00
|
|
|
#define EXCP_TYPE_RESET 0x545352 // RST
|
|
|
|
#define EXCP_TYPE_UNDEF 0x464455 // UDF
|
2020-04-27 07:56:19 +01:00
|
|
|
#define EXCP_TYPE_PABRT 0x54424150 // PABT
|
|
|
|
#define EXCP_TYPE_DABRT 0x54424144 // DABT
|
|
|
|
#define EXCP_LR_ADDR 0x4003FFF4
|
|
|
|
|
|
|
|
static void _show_errors()
|
|
|
|
{
|
|
|
|
u32 *excp_enabled = (u32 *)EXCP_EN_ADDR;
|
|
|
|
u32 *excp_type = (u32 *)EXCP_TYPE_ADDR;
|
|
|
|
u32 *excp_lr = (u32 *)EXCP_LR_ADDR;
|
|
|
|
|
|
|
|
if (*excp_enabled == EXCP_MAGIC)
|
|
|
|
{
|
|
|
|
gfx_clear_grey(0);
|
|
|
|
gfx_con_setpos(0, 0);
|
2022-01-15 23:33:07 +00:00
|
|
|
display_backlight_brightness(150, 1000);
|
2020-04-27 07:56:19 +01:00
|
|
|
|
2020-04-30 12:45:59 +01:00
|
|
|
display_activate_console();
|
|
|
|
|
2022-01-15 23:33:07 +00:00
|
|
|
WPRINTFARGS("Nyx exception occurred (LR %08X):\n", *excp_lr);
|
2020-04-27 07:56:19 +01:00
|
|
|
switch (*excp_type)
|
|
|
|
{
|
|
|
|
case EXCP_TYPE_RESET:
|
2020-10-23 04:32:24 +01:00
|
|
|
WPRINTF("RESET");
|
2020-04-27 07:56:19 +01:00
|
|
|
break;
|
|
|
|
case EXCP_TYPE_UNDEF:
|
2020-07-14 20:41:48 +01:00
|
|
|
WPRINTF("UNDEF");
|
2020-04-27 07:56:19 +01:00
|
|
|
break;
|
|
|
|
case EXCP_TYPE_PABRT:
|
2020-07-14 20:41:48 +01:00
|
|
|
WPRINTF("PABRT");
|
2020-04-27 07:56:19 +01:00
|
|
|
break;
|
|
|
|
case EXCP_TYPE_DABRT:
|
2020-07-14 20:41:48 +01:00
|
|
|
WPRINTF("DABRT");
|
2020-04-27 07:56:19 +01:00
|
|
|
break;
|
|
|
|
}
|
2022-01-15 23:33:07 +00:00
|
|
|
gfx_puts("\n");
|
2020-04-27 07:56:19 +01:00
|
|
|
|
|
|
|
// Clear the exception.
|
|
|
|
*excp_lr = 0;
|
|
|
|
*excp_type = 0;
|
|
|
|
*excp_enabled = 0;
|
|
|
|
|
|
|
|
WPRINTF("Press any key...");
|
|
|
|
|
2022-01-15 23:33:07 +00:00
|
|
|
msleep(1500);
|
2020-04-27 07:56:19 +01:00
|
|
|
btn_wait();
|
|
|
|
|
|
|
|
reload_nyx();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
void nyx_init_load_res()
|
|
|
|
{
|
|
|
|
bpmp_mmu_enable();
|
2020-04-30 12:45:59 +01:00
|
|
|
bpmp_clk_rate_get();
|
2021-05-11 07:32:38 +01: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 02:03:00 +01:00
|
|
|
|
|
|
|
// Set bootloader's default configuration.
|
|
|
|
set_default_configuration();
|
2020-04-30 01:25:22 +01:00
|
|
|
set_nyx_default_configuration();
|
2019-06-30 02:03:00 +01: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 12:07:26 +01:00
|
|
|
gfx_init_ctxt((u32 *)LOG_FB_ADDRESS, 1280, 656, 656);
|
2019-06-30 02:03:00 +01:00
|
|
|
gfx_con_init();
|
|
|
|
|
2020-04-30 01:25:22 +01:00
|
|
|
// Show exception errors if any.
|
|
|
|
_show_errors();
|
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
sd_mount();
|
|
|
|
|
2019-12-04 19:59:58 +00:00
|
|
|
// Train DRAM and switch to max frequency.
|
2019-06-30 02:03:00 +01:00
|
|
|
minerva_init();
|
|
|
|
|
|
|
|
load_saved_configuration();
|
2019-10-18 16:02:06 +01:00
|
|
|
|
2021-05-11 07:32:38 +01:00
|
|
|
// Initialize nyx cfg to lower clock for T210.
|
|
|
|
// In case of lower binned SoC, this can help with hangs.
|
|
|
|
if (!n_cfg.bpmp_clock)
|
|
|
|
{
|
|
|
|
n_cfg.bpmp_clock = h_cfg.t210b01 ? 1 : 2; // Set lower clock for T210.
|
|
|
|
create_nyx_config_entry(false);
|
|
|
|
n_cfg.bpmp_clock = h_cfg.t210b01 ? 1 : 0; // Restore for T210 and keep for T210B01.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore clock to max.
|
|
|
|
if (n_cfg.bpmp_clock < 2)
|
|
|
|
bpmp_clk_rate_set(BPMP_CLK_DEFAULT_BOOST);
|
|
|
|
|
2019-06-30 02:03:00 +01:00
|
|
|
FIL fp;
|
2020-07-17 22:54:35 +01:00
|
|
|
if (!f_open(&fp, "bootloader/sys/res.pak", FA_READ))
|
|
|
|
{
|
|
|
|
f_read(&fp, (void *)NYX_RES_ADDR, f_size(&fp), NULL);
|
|
|
|
f_close(&fp);
|
|
|
|
}
|
2019-06-30 02:03:00 +01:00
|
|
|
|
2020-05-02 23:57:15 +01:00
|
|
|
// 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.bmp");
|
|
|
|
else
|
|
|
|
icon_switch = bmp_to_lvimg_obj("bootloader/res/icon_switch_custom.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.bmp");
|
|
|
|
else
|
|
|
|
icon_payload = bmp_to_lvimg_obj("bootloader/res/icon_payload_custom.bmp");
|
|
|
|
|
2020-05-05 17:01:08 +01:00
|
|
|
// Load background resource if any.
|
2019-06-30 02:03:00 +01:00
|
|
|
hekate_bg = bmp_to_lvimg_obj("bootloader/res/background.bmp");
|
|
|
|
|
2020-06-13 16:32:40 +01:00
|
|
|
sd_unmount();
|
2019-06-30 02:03:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ipl_main()
|
|
|
|
{
|
2022-05-13 01:57:09 +01:00
|
|
|
// Tegra/Horizon configuration goes to 0x80000000+, package2 goes to 0xA9800000, we place our heap in between.
|
2022-02-14 22:23:23 +00:00
|
|
|
heap_init((void *)IPL_HEAP_START);
|
2019-06-30 02:03:00 +01:00
|
|
|
|
|
|
|
b_cfg = (boot_cfg_t *)(nyx_str->hekate + 0x94);
|
|
|
|
|
2020-08-13 08:21:00 +01:00
|
|
|
#ifdef DEBUG_UART_PORT
|
2022-05-13 01:57:09 +01:00
|
|
|
#if (DEBUG_UART_PORT == UART_B)
|
2020-08-13 08:21:00 +01:00
|
|
|
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO);
|
2022-05-13 01:57:09 +01:00
|
|
|
#elif (DEBUG_UART_PORT == UART_C)
|
2020-08-13 08:21:00 +01: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 03:46:23 +01: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 08:21:00 +01:00
|
|
|
|
|
|
|
uart_send(DEBUG_UART_PORT, (u8 *)"hekate-NYX: Hello!\r\n", 20);
|
2022-05-08 03:46:23 +01:00
|
|
|
uart_wait_xfer(DEBUG_UART_PORT, UART_TX_IDLE);
|
2019-06-30 02:03:00 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Initialize the rest of hw and load nyx's resources.
|
|
|
|
nyx_init_load_res();
|
|
|
|
|
|
|
|
nyx_load_and_run();
|
|
|
|
|
2019-08-27 23:33:38 +01:00
|
|
|
// Halt BPMP if we managed to get out of execution.
|
2019-06-30 02:03:00 +01:00
|
|
|
while (true)
|
2019-08-27 23:33:38 +01:00
|
|
|
bpmp_halt();
|
2019-06-30 02:03:00 +01:00
|
|
|
}
|