2019-03-04 23:05:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 naehrwert
|
|
|
|
*
|
2021-05-12 21:38:34 +00:00
|
|
|
* Copyright (c) 2018-2021 CTCaer
|
|
|
|
* Copyright (c) 2019-2021 shchmue
|
2019-03-04 23:05:42 +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>
|
|
|
|
|
2020-06-26 20:17:06 +00:00
|
|
|
#include "config.h"
|
2021-05-12 21:38:34 +00:00
|
|
|
#include <display/di.h>
|
2020-06-26 20:17:06 +00:00
|
|
|
#include <gfx_utils.h>
|
2019-09-17 15:51:30 +00:00
|
|
|
#include "gfx/tui.h"
|
2020-06-26 20:17:06 +00:00
|
|
|
#include <libs/fatfs/ff.h>
|
|
|
|
#include <mem/heap.h>
|
|
|
|
#include <mem/minerva.h>
|
|
|
|
#include <power/bq24193.h>
|
|
|
|
#include <power/max17050.h>
|
|
|
|
#include <power/max77620.h>
|
|
|
|
#include <rtc/max77620-rtc.h>
|
|
|
|
#include <soc/bpmp.h>
|
2020-12-04 18:20:01 +00:00
|
|
|
#include <soc/hw_init.h>
|
2019-09-17 15:51:30 +00:00
|
|
|
#include "storage/emummc.h"
|
2019-09-27 22:30:44 +00:00
|
|
|
#include "storage/nx_emmc.h"
|
2020-06-26 20:17:06 +00:00
|
|
|
#include <storage/nx_sd.h>
|
|
|
|
#include <storage/sdmmc.h>
|
|
|
|
#include <utils/btn.h>
|
|
|
|
#include <utils/dirlist.h>
|
|
|
|
#include <utils/ini.h>
|
|
|
|
#include <utils/sprintf.h>
|
|
|
|
#include <utils/util.h>
|
2019-03-04 23:05:42 +00:00
|
|
|
|
|
|
|
#include "keys/keys.h"
|
|
|
|
|
2019-09-17 04:18:41 +00:00
|
|
|
hekate_config h_cfg;
|
2019-04-18 16:47:34 +00:00
|
|
|
boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg;
|
2019-03-04 23:05:42 +00:00
|
|
|
|
2019-12-09 02:17:46 +00:00
|
|
|
volatile nyx_storage_t *nyx_str = (nyx_storage_t *)NYX_STORAGE_ADDR;
|
|
|
|
|
2019-04-18 16:47:34 +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
|
2019-11-01 03:08:58 +00:00
|
|
|
#define PATCHED_RELOC_ENTRY 0x40010000
|
2020-04-15 22:18:58 +00:00
|
|
|
#define EXT_PAYLOAD_ADDR 0xC0000000
|
2019-11-01 03:08:58 +00:00
|
|
|
#define RCM_PAYLOAD_ADDR (EXT_PAYLOAD_ADDR + ALIGN(PATCHED_RELOC_SZ, 0x10))
|
2020-04-15 22:18:58 +00:00
|
|
|
#define COREBOOT_END_ADDR 0xD0000000
|
2021-05-12 21:38:34 +00:00
|
|
|
#define COREBOOT_VER_OFF 0x41
|
2019-04-18 16:47:34 +00:00
|
|
|
#define CBFS_DRAM_EN_ADDR 0x4003e000
|
|
|
|
#define CBFS_DRAM_MAGIC 0x4452414D // "DRAM"
|
2019-03-04 23:05:42 +00:00
|
|
|
|
2020-04-15 22:18:58 +00:00
|
|
|
static void *coreboot_addr;
|
|
|
|
|
2019-04-18 16:47:34 +00:00
|
|
|
void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size)
|
2019-03-04 23:05:42 +00:00
|
|
|
{
|
2019-11-01 03:08:58 +00:00
|
|
|
memcpy((u8 *)payload_src, (u8 *)IPL_LOAD_ADDR, PATCHED_RELOC_SZ);
|
2019-03-04 23:05:42 +00:00
|
|
|
|
2019-11-01 03:08:58 +00:00
|
|
|
volatile reloc_meta_t *relocator = (reloc_meta_t *)(payload_src + RELOC_META_OFF);
|
2019-03-04 23:05:42 +00:00
|
|
|
|
2019-11-01 03:08:58 +00:00
|
|
|
relocator->start = payload_dst - ALIGN(PATCHED_RELOC_SZ, 0x10);
|
|
|
|
relocator->stack = PATCHED_RELOC_STACK;
|
|
|
|
relocator->end = payload_dst + payload_size;
|
|
|
|
relocator->ep = payload_dst;
|
2019-03-04 23:05:42 +00:00
|
|
|
|
2019-11-01 03:08:58 +00:00
|
|
|
if (payload_size == 0x7000)
|
|
|
|
{
|
2020-04-15 22:18:58 +00:00
|
|
|
memcpy((u8 *)(payload_src + ALIGN(PATCHED_RELOC_SZ, 0x10)), coreboot_addr, 0x7000); //Bootblock
|
2019-11-01 03:08:58 +00:00
|
|
|
*(vu32 *)CBFS_DRAM_EN_ADDR = CBFS_DRAM_MAGIC;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 21:38:34 +00:00
|
|
|
int launch_payload(char *path, bool clear_screen)
|
2019-11-01 03:08:58 +00:00
|
|
|
{
|
2021-05-12 21:38:34 +00:00
|
|
|
if (clear_screen)
|
|
|
|
gfx_clear_grey(0x1B);
|
2019-11-01 03:08:58 +00:00
|
|
|
gfx_con_setpos(0, 0);
|
|
|
|
if (!path)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (sd_mount())
|
|
|
|
{
|
|
|
|
FIL fp;
|
|
|
|
if (f_open(&fp, path, FA_READ))
|
|
|
|
{
|
2021-05-12 21:38:34 +00:00
|
|
|
gfx_con.mute = false;
|
2019-11-01 03:08:58 +00:00
|
|
|
EPRINTFARGS("Payload file is missing!\n(%s)", path);
|
|
|
|
|
2021-05-12 21:38:34 +00:00
|
|
|
goto out;
|
2019-11-01 03:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read and copy the payload to our chosen address
|
|
|
|
void *buf;
|
|
|
|
u32 size = f_size(&fp);
|
|
|
|
|
|
|
|
if (size < 0x30000)
|
|
|
|
buf = (void *)RCM_PAYLOAD_ADDR;
|
|
|
|
else
|
2020-04-15 22:18:58 +00:00
|
|
|
{
|
|
|
|
coreboot_addr = (void *)(COREBOOT_END_ADDR - size);
|
|
|
|
buf = coreboot_addr;
|
2021-05-12 21:38:34 +00:00
|
|
|
if (h_cfg.t210b01)
|
|
|
|
{
|
|
|
|
f_close(&fp);
|
|
|
|
|
|
|
|
gfx_con.mute = false;
|
|
|
|
EPRINTF("Coreboot not allowed on Mariko!");
|
|
|
|
|
|
|
|
goto out;
|
|
|
|
}
|
2020-04-15 22:18:58 +00:00
|
|
|
}
|
2019-11-01 03:08:58 +00:00
|
|
|
|
|
|
|
if (f_read(&fp, buf, size, NULL))
|
|
|
|
{
|
|
|
|
f_close(&fp);
|
|
|
|
|
2021-05-12 21:38:34 +00:00
|
|
|
goto out;
|
2019-11-01 03:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
f_close(&fp);
|
|
|
|
|
2021-05-12 21:38:34 +00:00
|
|
|
sd_end();
|
2019-11-01 03:08:58 +00:00
|
|
|
|
|
|
|
if (size < 0x30000)
|
|
|
|
{
|
|
|
|
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, ALIGN(size, 0x10));
|
|
|
|
|
2020-12-04 18:20:01 +00:00
|
|
|
hw_reinit_workaround(false, byte_swap_32(*(u32 *)(buf + size - sizeof(u32))));
|
2019-11-01 03:08:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, 0x7000);
|
2021-05-12 21:38:34 +00:00
|
|
|
|
|
|
|
// Get coreboot seamless display magic.
|
|
|
|
u32 magic = 0;
|
|
|
|
char *magic_ptr = buf + COREBOOT_VER_OFF;
|
|
|
|
memcpy(&magic, magic_ptr + strlen(magic_ptr) - 4, 4);
|
|
|
|
hw_reinit_workaround(true, magic);
|
2019-11-01 03:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Some cards (Sandisk U1), do not like a fast power cycle. Wait min 100ms.
|
|
|
|
sdmmc_storage_init_wait_sd();
|
|
|
|
|
|
|
|
void (*ext_payload_ptr)() = (void *)EXT_PAYLOAD_ADDR;
|
|
|
|
|
|
|
|
// Launch our payload.
|
|
|
|
(*ext_payload_ptr)();
|
|
|
|
}
|
|
|
|
|
2021-05-12 21:38:34 +00:00
|
|
|
out:
|
|
|
|
sd_end();
|
2019-11-01 03:08:58 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void launch_tools()
|
|
|
|
{
|
|
|
|
u8 max_entries = 61;
|
|
|
|
char *filelist = NULL;
|
|
|
|
char *file_sec = NULL;
|
|
|
|
char *dir = NULL;
|
|
|
|
|
|
|
|
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3));
|
|
|
|
|
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
|
|
|
|
|
|
|
if (sd_mount())
|
|
|
|
{
|
|
|
|
dir = (char *)malloc(256);
|
|
|
|
|
|
|
|
memcpy(dir, "sd:/bootloader/payloads", 24);
|
|
|
|
|
2020-06-26 20:17:06 +00:00
|
|
|
filelist = dirlist(dir, NULL, false, false);
|
2019-11-01 03:08:58 +00:00
|
|
|
|
|
|
|
u32 i = 0;
|
|
|
|
u32 i_off = 2;
|
|
|
|
|
|
|
|
if (filelist)
|
|
|
|
{
|
|
|
|
// Build configuration menu.
|
|
|
|
u32 color_idx = 0;
|
|
|
|
|
|
|
|
ments[0].type = MENT_BACK;
|
|
|
|
ments[0].caption = "Back";
|
|
|
|
ments[0].color = colors[(color_idx++) % 6];
|
|
|
|
ments[1].type = MENT_CHGLINE;
|
|
|
|
ments[1].color = colors[(color_idx++) % 6];
|
|
|
|
if (!f_stat("sd:/atmosphere/reboot_payload.bin", NULL))
|
|
|
|
{
|
|
|
|
ments[i_off].type = INI_CHOICE;
|
|
|
|
ments[i_off].caption = "reboot_payload.bin";
|
|
|
|
ments[i_off].color = colors[(color_idx++) % 6];
|
|
|
|
ments[i_off].data = "sd:/atmosphere/reboot_payload.bin";
|
|
|
|
i_off++;
|
|
|
|
}
|
|
|
|
if (!f_stat("sd:/ReiNX.bin", NULL))
|
|
|
|
{
|
|
|
|
ments[i_off].type = INI_CHOICE;
|
|
|
|
ments[i_off].caption = "ReiNX.bin";
|
|
|
|
ments[i_off].color = colors[(color_idx++) % 6];
|
|
|
|
ments[i_off].data = "sd:/ReiNX.bin";
|
|
|
|
i_off++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (i > max_entries || !filelist[i * 256])
|
|
|
|
break;
|
|
|
|
ments[i + i_off].type = INI_CHOICE;
|
|
|
|
ments[i + i_off].caption = &filelist[i * 256];
|
|
|
|
ments[i + i_off].color = colors[(color_idx++) % 6];
|
|
|
|
ments[i + i_off].data = &filelist[i * 256];
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
memset(&ments[i + i_off], 0, sizeof(ment_t));
|
|
|
|
menu_t menu = { ments, "Choose a file to launch", 0, 0 };
|
|
|
|
|
|
|
|
file_sec = (char *)tui_do_menu(&menu);
|
|
|
|
|
|
|
|
if (!file_sec)
|
|
|
|
{
|
|
|
|
free(ments);
|
|
|
|
free(dir);
|
|
|
|
free(filelist);
|
2021-05-12 21:38:34 +00:00
|
|
|
sd_end();
|
|
|
|
|
2019-11-01 03:08:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
EPRINTF("No payloads or modules found.");
|
|
|
|
|
|
|
|
free(ments);
|
|
|
|
free(filelist);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
free(ments);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file_sec)
|
|
|
|
{
|
2020-05-18 22:51:37 +00:00
|
|
|
if (memcmp("sd:/", file_sec, 4) != 0)
|
2020-05-17 23:45:48 +00:00
|
|
|
{
|
2019-11-01 03:08:58 +00:00
|
|
|
memcpy(dir + strlen(dir), "/", 2);
|
|
|
|
memcpy(dir + strlen(dir), file_sec, strlen(file_sec) + 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
memcpy(dir, file_sec, strlen(file_sec) + 1);
|
|
|
|
|
2021-05-12 21:38:34 +00:00
|
|
|
launch_payload(dir, true);
|
|
|
|
EPRINTF("Failed to launch payload.");
|
2019-11-01 03:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2021-05-12 21:38:34 +00:00
|
|
|
sd_end();
|
2019-11-01 03:08:58 +00:00
|
|
|
free(dir);
|
|
|
|
|
|
|
|
btn_wait();
|
2019-03-04 23:05:42 +00:00
|
|
|
}
|
|
|
|
|
2019-09-17 15:51:30 +00:00
|
|
|
void dump_sysnand()
|
|
|
|
{
|
2019-11-01 03:08:58 +00:00
|
|
|
h_cfg.emummc_force_disable = true;
|
2020-07-02 15:42:49 +00:00
|
|
|
emu_cfg.enabled = false;
|
2019-11-01 03:08:58 +00:00
|
|
|
b_cfg.extra_cfg &= ~EXTRA_CFG_DUMP_EMUMMC;
|
|
|
|
dump_keys();
|
2019-09-17 15:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dump_emunand()
|
|
|
|
{
|
2019-11-01 03:08:58 +00:00
|
|
|
if (h_cfg.emummc_force_disable)
|
|
|
|
return;
|
2020-07-02 15:42:49 +00:00
|
|
|
emu_cfg.enabled = true;
|
2019-11-01 03:08:58 +00:00
|
|
|
b_cfg.extra_cfg |= EXTRA_CFG_DUMP_EMUMMC;
|
|
|
|
dump_keys();
|
2019-09-17 15:51:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 21:38:34 +00:00
|
|
|
power_state_t STATE_POWER_OFF = POWER_OFF_RESET;
|
|
|
|
power_state_t STATE_REBOOT_FULL = POWER_OFF_REBOOT;
|
|
|
|
power_state_t STATE_REBOOT_RCM = REBOOT_RCM;
|
|
|
|
power_state_t STATE_REBOOT_BYPASS_FUSES = REBOOT_BYPASS_FUSES;
|
|
|
|
|
2019-09-17 15:51:30 +00:00
|
|
|
ment_t ment_top[] = {
|
2019-11-01 03:08:58 +00:00
|
|
|
MDEF_HANDLER("Dump from SysNAND | Key generation: unk", dump_sysnand, COLOR_RED),
|
|
|
|
MDEF_HANDLER("Dump from EmuNAND | Key generation: unk", dump_emunand, COLOR_ORANGE),
|
|
|
|
MDEF_CAPTION("---------------", COLOR_YELLOW),
|
|
|
|
MDEF_HANDLER("Payloads...", launch_tools, COLOR_GREEN),
|
|
|
|
MDEF_CAPTION("---------------", COLOR_BLUE),
|
2021-05-12 21:38:34 +00:00
|
|
|
MDEF_HANDLER_EX("Reboot (OFW)", &STATE_REBOOT_BYPASS_FUSES, power_set_state_ex, COLOR_VIOLET),
|
|
|
|
MDEF_HANDLER_EX("Reboot (RCM)", &STATE_REBOOT_RCM, power_set_state_ex, COLOR_RED),
|
|
|
|
MDEF_HANDLER_EX("Power off", &STATE_POWER_OFF, power_set_state_ex, COLOR_ORANGE),
|
2019-11-01 03:08:58 +00:00
|
|
|
MDEF_END()
|
2019-09-17 15:51:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
menu_t menu_top = { ment_top, NULL, 0, 0 };
|
|
|
|
|
2020-05-17 23:45:48 +00:00
|
|
|
void _get_key_generations(char *sysnand_label, char *emunand_label)
|
|
|
|
{
|
2019-11-01 03:08:58 +00:00
|
|
|
sdmmc_t sdmmc;
|
|
|
|
sdmmc_storage_t storage;
|
2020-05-18 20:11:27 +00:00
|
|
|
sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400);
|
2020-12-08 02:11:33 +00:00
|
|
|
u8 *pkg1 = (u8 *)malloc(PKG1_MAX_SIZE);
|
2020-05-18 20:11:27 +00:00
|
|
|
sdmmc_storage_set_mmc_partition(&storage, EMMC_BOOT0);
|
2020-12-08 02:11:33 +00:00
|
|
|
sdmmc_storage_read(&storage, PKG1_OFFSET / NX_EMMC_BLOCKSIZE, PKG1_MAX_SIZE / NX_EMMC_BLOCKSIZE, pkg1);
|
2019-11-01 03:08:58 +00:00
|
|
|
sdmmc_storage_end(&storage);
|
|
|
|
|
2020-12-08 02:11:33 +00:00
|
|
|
u32 pk1_offset = h_cfg.t210b01 ? sizeof(bl_hdr_t210b01_t) : 0; // Skip T210B01 OEM header.
|
2021-04-06 22:43:44 +00:00
|
|
|
const pkg1_id_t *pkg1_id = pkg1_identify(pkg1 + pk1_offset);
|
|
|
|
if (pkg1_id) {
|
2021-05-12 21:38:34 +00:00
|
|
|
s_printf(sysnand_label + 36, "% 3d", pkg1_id->kb);
|
2021-04-06 22:43:44 +00:00
|
|
|
ment_top[0].caption = sysnand_label;
|
|
|
|
if (h_cfg.emummc_force_disable)
|
|
|
|
{
|
|
|
|
free(pkg1);
|
|
|
|
return;
|
|
|
|
}
|
2019-11-01 03:08:58 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 21:38:34 +00:00
|
|
|
emummc_storage_init_mmc();
|
2020-12-08 02:11:33 +00:00
|
|
|
memset(pkg1, 0, PKG1_MAX_SIZE);
|
2021-05-12 21:38:34 +00:00
|
|
|
emummc_storage_set_mmc_partition(EMMC_BOOT0);
|
|
|
|
emummc_storage_read(PKG1_OFFSET / NX_EMMC_BLOCKSIZE, PKG1_MAX_SIZE / NX_EMMC_BLOCKSIZE, pkg1);
|
|
|
|
emummc_storage_end();
|
2019-11-01 03:08:58 +00:00
|
|
|
|
2020-12-08 02:11:33 +00:00
|
|
|
pkg1_id = pkg1_identify(pkg1 + pk1_offset);
|
2021-04-06 22:43:44 +00:00
|
|
|
if (pkg1_id) {
|
2021-05-12 21:38:34 +00:00
|
|
|
s_printf(emunand_label + 36, "% 3d", pkg1_id->kb);
|
2021-04-06 22:43:44 +00:00
|
|
|
free(pkg1);
|
|
|
|
ment_top[1].caption = emunand_label;
|
|
|
|
}
|
2019-09-27 22:30:44 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 23:05:42 +00:00
|
|
|
extern void pivot_stack(u32 stack_top);
|
|
|
|
|
2019-05-11 21:51:44 +00:00
|
|
|
void ipl_main()
|
|
|
|
{
|
2020-04-15 22:18:58 +00:00
|
|
|
// Do initial HW configuration. This is compatible with consecutive reruns without a reset.
|
2020-12-04 18:20:01 +00:00
|
|
|
hw_init();
|
2020-04-15 22:18:58 +00:00
|
|
|
|
|
|
|
// Pivot the stack so we have enough space.
|
2019-11-01 03:08:58 +00:00
|
|
|
pivot_stack(IPL_STACK_TOP);
|
2020-04-15 22:18:58 +00:00
|
|
|
|
|
|
|
// Tegra/Horizon configuration goes to 0x80000000+, package2 goes to 0xA9800000, we place our heap in between.
|
2019-11-01 03:08:58 +00:00
|
|
|
heap_init(IPL_HEAP_START);
|
2019-03-04 23:05:42 +00:00
|
|
|
|
2020-06-26 20:17:06 +00:00
|
|
|
#ifdef DEBUG_UART_PORT
|
|
|
|
uart_send(DEBUG_UART_PORT, (u8 *)"hekate: Hello!\r\n", 16);
|
|
|
|
uart_wait_idle(DEBUG_UART_PORT, UART_TX_IDLE);
|
|
|
|
#endif
|
|
|
|
|
2020-04-15 22:18:58 +00:00
|
|
|
// Set bootloader's default configuration.
|
2019-11-01 03:08:58 +00:00
|
|
|
set_default_configuration();
|
2019-09-17 04:18:41 +00:00
|
|
|
|
2020-12-04 18:20:01 +00:00
|
|
|
// Mount SD Card.
|
|
|
|
h_cfg.errors |= !sd_mount() ? ERR_SD_BOOT_EN : 0;
|
2020-04-15 22:18:58 +00:00
|
|
|
|
2020-12-04 18:20:01 +00:00
|
|
|
// Train DRAM and switch to max frequency.
|
|
|
|
if (minerva_init()) //!TODO: Add Tegra210B01 support to minerva.
|
|
|
|
h_cfg.errors |= ERR_LIBSYS_MTC;
|
2019-11-01 03:08:58 +00:00
|
|
|
minerva_change_freq(FREQ_1600);
|
2019-09-25 18:18:08 +00:00
|
|
|
|
2019-11-01 03:08:58 +00:00
|
|
|
display_init();
|
2020-04-15 22:18:58 +00:00
|
|
|
|
2020-06-26 20:17:06 +00:00
|
|
|
u32 *fb = display_init_framebuffer_pitch();
|
2019-11-01 03:08:58 +00:00
|
|
|
gfx_init_ctxt(fb, 720, 1280, 720);
|
2020-04-15 22:18:58 +00:00
|
|
|
|
2019-11-01 03:08:58 +00:00
|
|
|
gfx_con_init();
|
2020-04-15 22:18:58 +00:00
|
|
|
|
2019-11-01 03:08:58 +00:00
|
|
|
display_backlight_pwm_init();
|
2019-03-04 23:05:42 +00:00
|
|
|
|
2020-04-15 22:18:58 +00:00
|
|
|
// Overclock BPMP.
|
2021-05-12 21:38:34 +00:00
|
|
|
bpmp_clk_rate_set(h_cfg.t210b01 ? BPMP_CLK_DEFAULT_BOOST : BPMP_CLK_LOWER_BOOST);
|
2019-09-15 04:16:10 +00:00
|
|
|
|
2021-05-12 21:38:34 +00:00
|
|
|
// Load emuMMC configuration from SD.
|
2020-06-26 20:17:06 +00:00
|
|
|
emummc_load_cfg();
|
|
|
|
// Ignore whether emummc is enabled.
|
|
|
|
h_cfg.emummc_force_disable = emu_cfg.sector == 0 && !emu_cfg.path;
|
2020-07-02 15:42:49 +00:00
|
|
|
emu_cfg.enabled = !h_cfg.emummc_force_disable;
|
2019-09-17 15:51:30 +00:00
|
|
|
|
2020-06-26 20:17:06 +00:00
|
|
|
// Grey out emummc option if not present.
|
2019-11-01 03:08:58 +00:00
|
|
|
if (h_cfg.emummc_force_disable)
|
|
|
|
{
|
|
|
|
ment_top[1].type = MENT_CAPTION;
|
|
|
|
ment_top[1].color = 0xFF555555;
|
|
|
|
ment_top[1].handler = NULL;
|
|
|
|
}
|
2019-09-17 15:51:30 +00:00
|
|
|
|
2020-12-08 02:11:33 +00:00
|
|
|
// Grey out reboot to RCM option if on Mariko or patched console.
|
|
|
|
if (h_cfg.t210b01 || h_cfg.rcm_patched)
|
|
|
|
{
|
|
|
|
ment_top[6].type = MENT_CAPTION;
|
|
|
|
ment_top[6].color = 0xFF555555;
|
|
|
|
ment_top[6].handler = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h_cfg.rcm_patched)
|
|
|
|
{
|
2021-05-12 21:38:34 +00:00
|
|
|
ment_top[6].data = &STATE_REBOOT_FULL;
|
2020-12-08 02:11:33 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 20:17:06 +00:00
|
|
|
// Update key generations listed in menu.
|
2019-11-01 03:08:58 +00:00
|
|
|
_get_key_generations((char *)ment_top[0].caption, (char *)ment_top[1].caption);
|
2019-09-27 22:30:44 +00:00
|
|
|
|
2019-11-01 03:08:58 +00:00
|
|
|
while (true)
|
|
|
|
tui_do_menu(&menu_top);
|
2019-09-17 15:51:30 +00:00
|
|
|
|
2020-04-15 22:18:58 +00:00
|
|
|
// Halt BPMP if we managed to get out of execution.
|
2019-11-01 03:08:58 +00:00
|
|
|
while (true)
|
|
|
|
bpmp_halt();
|
2019-03-04 23:05:42 +00:00
|
|
|
}
|