2018-05-01 06:15:48 +01:00
|
|
|
/*
|
2018-08-05 12:40:32 +01:00
|
|
|
* Copyright (c) 2018 naehrwert
|
|
|
|
*
|
2023-02-11 21:51:43 +00:00
|
|
|
* Copyright (c) 2018-2023 CTCaer
|
2018-08-05 12:40:32 +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/>.
|
|
|
|
*/
|
2018-05-01 06:15:48 +01:00
|
|
|
|
|
|
|
#include <string.h>
|
2018-05-01 12:17:13 +01:00
|
|
|
#include <stdlib.h>
|
2018-05-01 06:15:48 +01:00
|
|
|
|
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"
|
2018-08-13 09:58:24 +01:00
|
|
|
#include "gfx/logos.h"
|
|
|
|
#include "gfx/tui.h"
|
|
|
|
#include "hos/hos.h"
|
2019-04-14 02:24:37 +01:00
|
|
|
#include "hos/secmon_exo.h"
|
2022-12-20 15:00:33 +00:00
|
|
|
#include "l4t/l4t.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 01:24:58 +01:00
|
|
|
#include "storage/emummc.h"
|
2018-08-07 15:53:58 +01:00
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
#include "frontend/fe_tools.h"
|
|
|
|
#include "frontend/fe_info.h"
|
2018-08-21 02:41:16 +01:00
|
|
|
|
2018-07-01 18:45:25 +01:00
|
|
|
hekate_config h_cfg;
|
2019-03-07 21:41:07 +00:00
|
|
|
boot_cfg_t __attribute__((section ("._boot_cfg"))) b_cfg;
|
|
|
|
const volatile ipl_ver_meta_t __attribute__((section ("._ipl_version"))) ipl_ver = {
|
|
|
|
.magic = BL_MAGIC,
|
|
|
|
.version = (BL_VER_MJ + '0') | ((BL_VER_MN + '0') << 8) | ((BL_VER_HF + '0') << 16),
|
|
|
|
.rsvd0 = 0,
|
|
|
|
.rsvd1 = 0
|
|
|
|
};
|
2018-07-01 18:45:25 +01:00
|
|
|
|
2019-06-30 01:55:19 +01:00
|
|
|
volatile nyx_storage_t *nyx_str = (nyx_storage_t *)NYX_STORAGE_ADDR;
|
|
|
|
|
2018-07-22 13:24:09 +01:00
|
|
|
void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage)
|
|
|
|
{
|
2022-10-11 04:58:22 +01:00
|
|
|
static char emmc_sn[9] = {0};
|
2018-07-22 13:24:09 +01:00
|
|
|
|
2022-10-11 04:58:22 +01:00
|
|
|
// Check if not valid S/N and get actual eMMC S/N.
|
|
|
|
if (!storage && !emmc_sn[0])
|
2018-07-22 13:24:09 +01:00
|
|
|
{
|
2022-01-20 11:15:04 +00:00
|
|
|
if (!emmc_initialize(false))
|
2022-10-11 04:58:22 +01:00
|
|
|
strcpy(emmc_sn, "00000000");
|
2018-07-22 13:24:09 +01:00
|
|
|
else
|
|
|
|
{
|
2022-10-11 04:58:22 +01:00
|
|
|
itoa(emmc_storage.cid.serial, emmc_sn, 16);
|
|
|
|
emmc_end();
|
2018-07-22 13:24:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2022-10-11 04:58:22 +01:00
|
|
|
itoa(storage->cid.serial, emmc_sn, 16);
|
2018-07-22 13:24:09 +01:00
|
|
|
|
2022-10-11 04:58:22 +01:00
|
|
|
// Create main folder.
|
|
|
|
strcpy(path, "backup");
|
|
|
|
f_mkdir(path);
|
2018-07-22 13:24:09 +01:00
|
|
|
|
2022-10-11 04:58:22 +01:00
|
|
|
// Create eMMC S/N folder.
|
|
|
|
strcat(path, "/");
|
|
|
|
strcat(path, emmc_sn);
|
2018-07-22 13:24:09 +01:00
|
|
|
f_mkdir(path);
|
2022-10-11 04:58:22 +01:00
|
|
|
|
|
|
|
// Create sub folder if defined. Dir slash must be included.
|
|
|
|
strcat(path, sub_dir); // Can be a null-terminator.
|
|
|
|
if (strlen(sub_dir))
|
2018-07-22 13:24:09 +01:00
|
|
|
f_mkdir(path);
|
|
|
|
|
2022-10-11 04:58:22 +01:00
|
|
|
// Add filename.
|
|
|
|
strcat(path, "/");
|
|
|
|
strcat(path, filename); // Can be a null-terminator.
|
2018-07-22 13:24:09 +01:00
|
|
|
}
|
|
|
|
|
2018-09-18 22:34:05 +01:00
|
|
|
void check_power_off_from_hos()
|
|
|
|
{
|
2023-02-22 23:25:19 +00:00
|
|
|
// Power off on alarm wakeup from HOS shutdown. For modchips/dongles.
|
|
|
|
u8 hos_wakeup = i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_IRQTOP);
|
|
|
|
if (hos_wakeup & MAX77620_IRQ_TOP_RTC_MASK)
|
2018-09-18 22:34:05 +01:00
|
|
|
{
|
2018-09-30 00:09:18 +01:00
|
|
|
if (h_cfg.autohosoff == 1)
|
|
|
|
{
|
2022-10-11 05:49:17 +01:00
|
|
|
render_static_bootlogo();
|
2018-05-24 22:37:30 +01:00
|
|
|
|
2022-12-19 04:03:53 +00:00
|
|
|
if (display_get_decoded_panel_id() != PANEL_SAM_AMS699VC01)
|
|
|
|
{
|
|
|
|
// Slow fading for LCD panels.
|
|
|
|
display_backlight_brightness(10, 5000);
|
|
|
|
display_backlight_brightness(100, 25000);
|
|
|
|
msleep(600);
|
|
|
|
display_backlight_brightness(0, 20000);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Blink 3 times for OLED panel.
|
|
|
|
for (u32 i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
msleep(150);
|
|
|
|
display_backlight_brightness(100, 0);
|
|
|
|
msleep(150);
|
|
|
|
display_backlight_brightness(0, 0);
|
|
|
|
}
|
|
|
|
}
|
2018-11-27 09:45:43 +00:00
|
|
|
}
|
2020-12-15 17:37:52 +00:00
|
|
|
power_set_state(POWER_OFF_RESET);
|
2018-11-27 09:45:43 +00:00
|
|
|
}
|
2018-05-13 02:13:17 +01:00
|
|
|
}
|
|
|
|
|
2018-08-23 03:05:31 +01:00
|
|
|
// This is a safe and unused DRAM region for our payloads.
|
2019-03-07 22:23:19 +00:00
|
|
|
#define RELOC_META_OFF 0x7C
|
|
|
|
#define PATCHED_RELOC_SZ 0x94
|
|
|
|
#define PATCHED_RELOC_STACK 0x40007000
|
|
|
|
#define PATCHED_RELOC_ENTRY 0x40010000
|
2020-03-21 20:18:40 +00:00
|
|
|
#define EXT_PAYLOAD_ADDR 0xC0000000
|
2019-03-07 22:23:19 +00:00
|
|
|
#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
|
2021-04-11 07:18:55 +01:00
|
|
|
#define COREBOOT_VER_OFF 0x41
|
2022-06-29 10:19:19 +01:00
|
|
|
#define CBFS_DRAM_EN_ADDR 0x4003E000
|
2019-03-07 22:23:19 +00:00
|
|
|
#define CBFS_DRAM_MAGIC 0x4452414D // "DRAM"
|
2018-08-23 03:05:31 +01:00
|
|
|
|
2020-03-21 20:18:40 +00:00
|
|
|
static void *coreboot_addr;
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
static void _reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size)
|
2018-08-23 03:05:31 +01:00
|
|
|
{
|
2019-02-24 01:03:17 +00:00
|
|
|
memcpy((u8 *)payload_src, (u8 *)IPL_LOAD_ADDR, PATCHED_RELOC_SZ);
|
2018-08-23 03:05:31 +01:00
|
|
|
|
2022-10-11 05:00:24 +01:00
|
|
|
reloc_meta_t *relocator = (reloc_meta_t *)(payload_src + RELOC_META_OFF);
|
2019-03-07 22:23:19 +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;
|
2018-08-23 03:05:31 +01:00
|
|
|
|
|
|
|
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-03-07 22:23:19 +00:00
|
|
|
*(vu32 *)CBFS_DRAM_EN_ADDR = CBFS_DRAM_MAGIC;
|
2018-08-23 03:05:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 22:07:18 +00:00
|
|
|
bool is_ipl_updated(void *buf, char *path, bool force)
|
2019-03-07 21:53:58 +00:00
|
|
|
{
|
2019-10-18 16:02:06 +01:00
|
|
|
ipl_ver_meta_t *update_ft = (ipl_ver_meta_t *)(buf + PATCHED_RELOC_SZ + sizeof(boot_cfg_t));
|
2019-03-07 21:53:58 +00:00
|
|
|
|
2022-10-11 05:00:24 +01:00
|
|
|
bool magic_valid = update_ft->magic == ipl_ver.magic;
|
2020-01-17 07:35:16 +00:00
|
|
|
bool force_update = force && !magic_valid;
|
|
|
|
bool is_valid_old = magic_valid && (byte_swap_32(update_ft->version) < byte_swap_32(ipl_ver.version));
|
|
|
|
|
2019-12-11 22:07:18 +00:00
|
|
|
// Check if newer version.
|
2020-01-17 07:35:16 +00:00
|
|
|
if (!force && magic_valid)
|
2019-12-11 22:07:18 +00:00
|
|
|
if (byte_swap_32(update_ft->version) > byte_swap_32(ipl_ver.version))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Update if old or broken.
|
2020-01-17 07:35:16 +00:00
|
|
|
if (force_update || is_valid_old)
|
2019-03-07 21:53:58 +00:00
|
|
|
{
|
2019-12-11 22:07:18 +00:00
|
|
|
FIL fp;
|
2022-10-11 05:00:24 +01:00
|
|
|
reloc_meta_t *reloc = (reloc_meta_t *)(IPL_LOAD_ADDR + RELOC_META_OFF);
|
2019-12-11 22:07:18 +00:00
|
|
|
boot_cfg_t *tmp_cfg = malloc(sizeof(boot_cfg_t));
|
|
|
|
memset(tmp_cfg, 0, sizeof(boot_cfg_t));
|
|
|
|
|
|
|
|
f_open(&fp, path, FA_WRITE | FA_CREATE_ALWAYS);
|
|
|
|
f_write(&fp, (u8 *)reloc->start, reloc->end - reloc->start, NULL);
|
2020-04-27 07:30:53 +01:00
|
|
|
|
2019-12-11 22:07:18 +00:00
|
|
|
// Write needed tag in case injected ipl uses old versioning.
|
|
|
|
f_write(&fp, "ICTC49", 6, NULL);
|
|
|
|
|
|
|
|
// Reset boot storage configuration.
|
|
|
|
f_lseek(&fp, PATCHED_RELOC_SZ);
|
|
|
|
f_write(&fp, tmp_cfg, sizeof(boot_cfg_t), NULL);
|
2019-10-18 16:02:06 +01:00
|
|
|
|
2019-12-11 22:07:18 +00:00
|
|
|
f_close(&fp);
|
|
|
|
free(tmp_cfg);
|
2019-03-07 21:53:58 +00:00
|
|
|
}
|
2019-12-11 22:07:18 +00:00
|
|
|
|
|
|
|
return true;
|
2019-03-07 21:53:58 +00:00
|
|
|
}
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
static void _launch_payload(char *path, bool update, bool clear_screen)
|
2018-08-23 03:05:31 +01:00
|
|
|
{
|
2021-04-12 02:26:16 +01:00
|
|
|
if (clear_screen)
|
2019-04-14 00:30:14 +01:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-08-23 03:05:31 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
FIL fp;
|
|
|
|
if (f_open(&fp, path, FA_READ))
|
|
|
|
{
|
|
|
|
gfx_con.mute = false;
|
|
|
|
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);
|
2018-08-23 03:05:31 +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)
|
2018-08-23 03:05:31 +01:00
|
|
|
{
|
|
|
|
f_close(&fp);
|
2020-04-27 07:30:53 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
gfx_con.mute = false;
|
|
|
|
EPRINTF("Coreboot not allowed on Mariko!");
|
|
|
|
|
2019-12-07 00:40:56 +00:00
|
|
|
goto out;
|
2018-08-23 03:05:31 +01:00
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
}
|
2018-08-23 03:05:31 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (f_read(&fp, buf, size, NULL))
|
|
|
|
{
|
2018-08-23 03:05:31 +01:00
|
|
|
f_close(&fp);
|
2019-02-23 22:59:33 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2019-02-24 01:04:28 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
f_close(&fp);
|
2018-08-23 03:05:31 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (update && is_ipl_updated(buf, path, false))
|
|
|
|
goto out;
|
2019-02-24 01:03:17 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
sd_end();
|
|
|
|
|
|
|
|
if (size < 0x30000)
|
|
|
|
{
|
|
|
|
if (update)
|
|
|
|
memcpy((u8 *)(RCM_PAYLOAD_ADDR + PATCHED_RELOC_SZ), &b_cfg, sizeof(boot_cfg_t)); // Transfer boot cfg.
|
2018-08-23 03:05:31 +01:00
|
|
|
else
|
2022-12-19 03:04:50 +00:00
|
|
|
_reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, ALIGN(size, 0x10));
|
2021-04-11 07:18:55 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
hw_reinit_workaround(false, byte_swap_32(*(u32 *)(buf + size - sizeof(u32))));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-19 03:04:50 +00:00
|
|
|
_reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, 0x7000);
|
2022-01-28 23:23:40 +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);
|
|
|
|
}
|
2018-08-23 03:05:31 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
// Some cards (Sandisk U1), do not like a fast power cycle. Wait min 100ms.
|
|
|
|
sdmmc_storage_init_wait_sd();
|
2019-06-30 01:15:46 +01:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
void (*update_ptr)() = (void *)RCM_PAYLOAD_ADDR;
|
2022-01-28 23:23:40 +00:00
|
|
|
void (*ext_payload_ptr)() = (void *)EXT_PAYLOAD_ADDR;
|
2019-09-09 14:56:37 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
// Launch our payload.
|
|
|
|
if (!update)
|
|
|
|
(*ext_payload_ptr)();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set updated flag to skip check on launch.
|
|
|
|
EMC(EMC_SCRATCH0) |= EMC_HEKA_UPD;
|
|
|
|
(*update_ptr)();
|
2018-08-23 03:05:31 +01:00
|
|
|
}
|
|
|
|
|
2019-12-07 00:40:56 +00:00
|
|
|
out:
|
2022-10-11 05:21:41 +01:00
|
|
|
if (!update)
|
|
|
|
{
|
|
|
|
gfx_con.mute = false;
|
|
|
|
EPRINTF("Failed to launch payload!");
|
|
|
|
}
|
2018-08-23 03:05:31 +01:00
|
|
|
}
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
static void _launch_payloads()
|
2018-08-21 02:45:19 +01:00
|
|
|
{
|
|
|
|
u8 max_entries = 61;
|
|
|
|
char *filelist = NULL;
|
|
|
|
char *file_sec = NULL;
|
2018-11-20 19:32:54 +00:00
|
|
|
char *dir = NULL;
|
2018-08-21 02:45:19 +01:00
|
|
|
|
|
|
|
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3));
|
|
|
|
|
2019-04-14 00:30:14 +01:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-08-21 02:45:19 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!sd_mount())
|
2018-08-21 02:45:19 +01:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
free(ments);
|
|
|
|
goto failed_sd_mount;
|
|
|
|
}
|
2018-08-21 02:45:19 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
dir = (char *)malloc(256);
|
|
|
|
memcpy(dir, "bootloader/payloads", 20);
|
2018-08-21 02:45:19 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
filelist = dirlist(dir, NULL, false, false);
|
2018-08-21 02:45:19 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
u32 i = 0;
|
2018-08-21 02:45:19 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (filelist)
|
|
|
|
{
|
|
|
|
// Build configuration menu.
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[0].type = MENT_BACK;
|
2022-01-28 23:23:40 +00:00
|
|
|
ments[0].caption = "Back";
|
2023-02-11 21:51:43 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[1].type = MENT_CHGLINE;
|
2018-08-21 02:45:19 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (i > max_entries || !filelist[i * 256])
|
|
|
|
break;
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[i + 2].type = INI_CHOICE;
|
2022-01-28 23:23:40 +00:00
|
|
|
ments[i + 2].caption = &filelist[i * 256];
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[i + 2].data = &filelist[i * 256];
|
2018-08-21 02:45:19 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
i++;
|
2018-08-21 02:45:19 +01:00
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
}
|
2019-12-04 19:31:39 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
memset(&ments[i + 2], 0, sizeof(ment_t));
|
2022-10-11 05:21:41 +01:00
|
|
|
menu_t menu = { ments, "Choose a payload", 0, 0 };
|
2019-10-18 16:02:06 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
file_sec = (char *)tui_do_menu(&menu);
|
2018-08-21 02:45:19 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!file_sec)
|
|
|
|
{
|
|
|
|
free(ments);
|
|
|
|
free(dir);
|
|
|
|
free(filelist);
|
|
|
|
sd_end();
|
2019-12-04 19:31:39 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
return;
|
2018-08-21 02:45:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2022-10-11 05:21:41 +01:00
|
|
|
EPRINTF("No payloads found.");
|
2022-01-28 23:23:40 +00:00
|
|
|
|
|
|
|
free(ments);
|
|
|
|
free(filelist);
|
2018-08-21 02:45:19 +01:00
|
|
|
|
|
|
|
if (file_sec)
|
|
|
|
{
|
|
|
|
memcpy(dir + strlen(dir), "/", 2);
|
|
|
|
memcpy(dir + strlen(dir), file_sec, strlen(file_sec) + 1);
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
_launch_payload(dir, false, true);
|
2018-08-21 02:45:19 +01:00
|
|
|
}
|
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
failed_sd_mount:
|
2020-06-13 16:32:40 +01:00
|
|
|
sd_end();
|
2018-11-20 19:32:54 +00:00
|
|
|
free(dir);
|
2018-08-21 02:45:19 +01:00
|
|
|
|
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
static void _launch_ini_list()
|
2018-05-01 06:15:48 +01:00
|
|
|
{
|
2018-07-01 18:29:30 +01:00
|
|
|
u8 max_entries = 61;
|
2022-12-19 03:43:48 +00:00
|
|
|
char *special_path = NULL;
|
2022-10-11 05:21:41 +01:00
|
|
|
char *emummc_path = NULL;
|
2018-05-01 06:15:48 +01:00
|
|
|
ini_sec_t *cfg_sec = NULL;
|
2022-10-11 05:21:41 +01:00
|
|
|
|
2018-08-21 02:37:40 +01:00
|
|
|
LIST_INIT(ini_list_sections);
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2019-04-14 00:30:14 +01:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!sd_mount())
|
|
|
|
goto parse_failed;
|
|
|
|
|
|
|
|
// Check that ini files exist and parse them.
|
|
|
|
if (!ini_parse(&ini_list_sections, "bootloader/ini", true))
|
2018-05-01 06:15:48 +01:00
|
|
|
{
|
2022-10-11 05:21:41 +01:00
|
|
|
EPRINTF("No .ini files in bootloader/ini!");
|
2022-01-28 23:23:40 +00:00
|
|
|
goto parse_failed;
|
|
|
|
}
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
// Build configuration menu.
|
|
|
|
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3));
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[0].type = MENT_BACK;
|
2022-01-28 23:23:40 +00:00
|
|
|
ments[0].caption = "Back";
|
2023-02-11 21:51:43 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[1].type = MENT_CHGLINE;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
u32 sec_idx = 2;
|
2022-01-28 23:23:40 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_list_sections, link)
|
|
|
|
{
|
2023-02-11 21:51:43 +00:00
|
|
|
if (ini_sec->type == INI_COMMENT ||
|
|
|
|
ini_sec->type == INI_NEWLINE ||
|
|
|
|
!strcmp(ini_sec->name, "config"))
|
2022-01-28 23:23:40 +00:00
|
|
|
continue;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[sec_idx].type = ini_sec->type;
|
|
|
|
ments[sec_idx].caption = ini_sec->name;
|
|
|
|
ments[sec_idx].data = ini_sec;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (ini_sec->type == MENT_CAPTION)
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[sec_idx].color = ini_sec->color;
|
|
|
|
sec_idx++;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
if ((sec_idx - 1) > max_entries)
|
2022-01-28 23:23:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-02-24 01:03:17 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
if (sec_idx > 2)
|
2022-01-28 23:23:40 +00:00
|
|
|
{
|
2022-10-11 05:21:41 +01:00
|
|
|
memset(&ments[sec_idx], 0, sizeof(ment_t));
|
2022-01-28 23:23:40 +00:00
|
|
|
menu_t menu = {
|
2022-10-11 05:21:41 +01:00
|
|
|
ments, "Launch ini entries", 0, 0
|
2022-01-28 23:23:40 +00:00
|
|
|
};
|
2020-04-27 07:30:53 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
cfg_sec = (ini_sec_t *)tui_do_menu(&menu);
|
|
|
|
|
2022-12-19 03:43:48 +00:00
|
|
|
special_path = ini_check_special_section(cfg_sec);
|
2022-01-28 23:23:40 +00:00
|
|
|
|
2022-12-19 03:43:48 +00:00
|
|
|
if (cfg_sec && !special_path)
|
2022-01-28 23:23:40 +00:00
|
|
|
{
|
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg_sec->kvs, link)
|
|
|
|
{
|
|
|
|
if (!strcmp("emummc_force_disable", kv->key))
|
|
|
|
h_cfg.emummc_force_disable = atoi(kv->val);
|
|
|
|
else if (!strcmp("emupath", kv->key))
|
|
|
|
emummc_path = kv->val;
|
|
|
|
}
|
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
if (emummc_path && !emummc_set_path(emummc_path))
|
|
|
|
{
|
|
|
|
EPRINTF("emupath is wrong!");
|
|
|
|
goto wrong_emupath;
|
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cfg_sec)
|
|
|
|
{
|
2018-08-21 02:37:40 +01:00
|
|
|
free(ments);
|
2022-01-28 23:23:40 +00:00
|
|
|
|
|
|
|
return;
|
2018-08-21 02:37:40 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
else
|
|
|
|
EPRINTF("No extra configs found.");
|
|
|
|
free(ments);
|
2018-08-21 02:37:40 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
parse_failed:
|
2018-08-21 02:37:40 +01:00
|
|
|
if (!cfg_sec)
|
|
|
|
goto out;
|
|
|
|
|
2022-12-19 03:43:48 +00:00
|
|
|
if (special_path)
|
2018-08-21 02:37:40 +01:00
|
|
|
{
|
2022-12-19 03:43:48 +00:00
|
|
|
// Try to launch Payload or L4T.
|
|
|
|
if (special_path != (char *)-1)
|
|
|
|
_launch_payload(special_path, false, true);
|
2022-12-20 15:00:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
u32 entry_idx = 0;
|
|
|
|
for (u32 i = 0; i < sec_idx; i++)
|
|
|
|
{
|
|
|
|
if (ments[i].data == cfg_sec)
|
|
|
|
{
|
|
|
|
entry_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
launch_l4t(cfg_sec, entry_idx, 1, h_cfg.t210b01);
|
|
|
|
}
|
2018-08-21 02:37:40 +01:00
|
|
|
}
|
|
|
|
else if (!hos_launch(cfg_sec))
|
|
|
|
{
|
2020-05-05 17:23:31 +01:00
|
|
|
wrong_emupath:
|
2020-04-27 07:30:53 +01:00
|
|
|
if (emummc_path)
|
|
|
|
{
|
|
|
|
sd_mount();
|
2021-09-26 10:23:54 +01:00
|
|
|
emummc_load_cfg(); // Reload emuMMC config in case of emupath.
|
2020-04-27 07:30:53 +01:00
|
|
|
}
|
2018-08-21 02:37:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
static void _launch_config()
|
2018-08-21 02:37:40 +01:00
|
|
|
{
|
|
|
|
u8 max_entries = 61;
|
2022-12-19 03:43:48 +00:00
|
|
|
char *special_path = NULL;
|
2020-04-27 07:30:53 +01:00
|
|
|
char *emummc_path = NULL;
|
2018-08-21 02:37:40 +01:00
|
|
|
|
|
|
|
ini_sec_t *cfg_sec = NULL;
|
|
|
|
LIST_INIT(ini_sections);
|
|
|
|
|
2019-04-14 00:30:14 +01:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-08-21 02:37:40 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!sd_mount())
|
|
|
|
goto parse_failed;
|
|
|
|
|
|
|
|
// Load emuMMC configuration.
|
|
|
|
emummc_load_cfg();
|
|
|
|
|
2023-02-11 21:52:43 +00:00
|
|
|
// Parse main configuration.
|
|
|
|
ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false);
|
2021-09-26 10:23:54 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
// Build configuration menu.
|
|
|
|
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 6));
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[0].type = MENT_BACK;
|
2022-01-28 23:23:40 +00:00
|
|
|
ments[0].caption = "Back";
|
2023-02-11 21:51:43 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[1].type = MENT_CHGLINE;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[2].type = MENT_HANDLER;
|
2022-01-28 23:23:40 +00:00
|
|
|
ments[2].caption = "Payloads...";
|
2022-12-19 03:04:50 +00:00
|
|
|
ments[2].handler = _launch_payloads;
|
2022-10-11 05:21:41 +01:00
|
|
|
|
|
|
|
ments[3].type = MENT_HANDLER;
|
2022-01-28 23:23:40 +00:00
|
|
|
ments[3].caption = "More configs...";
|
2022-12-19 03:04:50 +00:00
|
|
|
ments[3].handler = _launch_ini_list;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[4].type = MENT_CHGLINE;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
u32 sec_idx = 5;
|
2022-01-28 23:23:40 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
|
|
|
|
{
|
2023-02-11 21:51:43 +00:00
|
|
|
if (ini_sec->type == INI_COMMENT ||
|
|
|
|
ini_sec->type == INI_NEWLINE ||
|
|
|
|
!strcmp(ini_sec->name, "config"))
|
2022-01-28 23:23:40 +00:00
|
|
|
continue;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[sec_idx].type = ini_sec->type;
|
|
|
|
ments[sec_idx].caption = ini_sec->name;
|
|
|
|
ments[sec_idx].data = ini_sec;
|
2019-02-24 01:03:17 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (ini_sec->type == MENT_CAPTION)
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[sec_idx].color = ini_sec->color;
|
|
|
|
sec_idx++;
|
2019-06-30 01:24:58 +01:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
if ((sec_idx - 4) > max_entries)
|
2022-01-28 23:23:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
if (sec_idx < 6)
|
2022-01-28 23:23:40 +00:00
|
|
|
{
|
2022-10-11 05:21:41 +01:00
|
|
|
ments[sec_idx].type = MENT_CAPTION;
|
|
|
|
ments[sec_idx].caption = "No main configs found...";
|
|
|
|
ments[sec_idx].color = TXT_CLR_WARNING;
|
|
|
|
sec_idx++;
|
2022-01-28 23:23:40 +00:00
|
|
|
}
|
2020-04-27 07:30:53 +01:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
memset(&ments[sec_idx], 0, sizeof(ment_t));
|
2022-01-28 23:23:40 +00:00
|
|
|
menu_t menu = {
|
|
|
|
ments, "Launch configurations", 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
cfg_sec = (ini_sec_t *)tui_do_menu(&menu);
|
|
|
|
|
2022-12-19 03:43:48 +00:00
|
|
|
special_path = ini_check_special_section(cfg_sec);
|
2022-01-28 23:23:40 +00:00
|
|
|
|
2022-12-19 03:43:48 +00:00
|
|
|
if (cfg_sec && !special_path)
|
2022-01-28 23:23:40 +00:00
|
|
|
{
|
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg_sec->kvs, link)
|
|
|
|
{
|
|
|
|
if (!strcmp("emummc_force_disable", kv->key))
|
|
|
|
h_cfg.emummc_force_disable = atoi(kv->val);
|
|
|
|
if (!strcmp("emupath", kv->key))
|
|
|
|
emummc_path = kv->val;
|
2018-05-01 06:15:48 +01:00
|
|
|
}
|
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
if (emummc_path && !emummc_set_path(emummc_path))
|
|
|
|
{
|
|
|
|
EPRINTF("emupath is wrong!");
|
|
|
|
goto wrong_emupath;
|
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cfg_sec)
|
|
|
|
{
|
|
|
|
free(ments);
|
|
|
|
sd_end();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(ments);
|
|
|
|
|
|
|
|
parse_failed:
|
2018-05-01 06:15:48 +01:00
|
|
|
if (!cfg_sec)
|
2018-05-24 22:41:20 +01:00
|
|
|
{
|
2021-02-06 01:27:18 +00:00
|
|
|
gfx_printf("\nPress any key...\n");
|
|
|
|
goto out;
|
2018-05-24 22:41:20 +01:00
|
|
|
}
|
2018-08-21 02:45:19 +01:00
|
|
|
|
2022-12-19 03:43:48 +00:00
|
|
|
if (special_path)
|
2018-06-19 15:10:59 +01:00
|
|
|
{
|
2022-12-19 03:43:48 +00:00
|
|
|
// Try to launch Payload or L4T.
|
|
|
|
if (special_path != (char *)-1)
|
|
|
|
_launch_payload(special_path, false, true);
|
2022-12-20 15:00:33 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
u32 entry_idx = 0;
|
|
|
|
for (u32 i = 0; i < sec_idx; i++)
|
|
|
|
{
|
|
|
|
if (ments[i].data == cfg_sec)
|
|
|
|
{
|
|
|
|
entry_idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
launch_l4t(cfg_sec, entry_idx, 0, h_cfg.t210b01);
|
|
|
|
}
|
2018-08-21 02:45:19 +01:00
|
|
|
}
|
|
|
|
else if (!hos_launch(cfg_sec))
|
2020-04-27 07:30:53 +01:00
|
|
|
{
|
2020-05-05 17:23:31 +01:00
|
|
|
wrong_emupath:
|
2020-04-27 07:30:53 +01:00
|
|
|
if (emummc_path)
|
|
|
|
{
|
|
|
|
sd_mount();
|
2021-09-26 10:23:54 +01:00
|
|
|
emummc_load_cfg(); // Reload emuMMC config in case of emupath.
|
2020-04-27 07:30:53 +01:00
|
|
|
}
|
|
|
|
}
|
2018-08-21 02:45:19 +01:00
|
|
|
|
2018-08-21 02:21:09 +01:00
|
|
|
out:
|
2020-06-13 16:32:40 +01:00
|
|
|
sd_end();
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2019-06-30 01:24:58 +01:00
|
|
|
h_cfg.emummc_force_disable = false;
|
|
|
|
|
2018-05-01 06:15:48 +01:00
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
#define NYX_VER_OFF 0x9C
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
static void _nyx_load_run()
|
2019-06-30 01:55:19 +01:00
|
|
|
{
|
2019-08-27 23:08:57 +01:00
|
|
|
u8 *nyx = sd_file_read("bootloader/sys/nyx.bin", NULL);
|
2019-06-30 01:55:19 +01:00
|
|
|
if (!nyx)
|
|
|
|
return;
|
|
|
|
|
2020-06-13 16:32:40 +01:00
|
|
|
sd_end();
|
2019-06-30 01:55:19 +01:00
|
|
|
|
2022-10-11 05:49:17 +01:00
|
|
|
render_static_bootlogo();
|
2019-06-30 01:55:19 +01:00
|
|
|
display_backlight_brightness(h_cfg.backlight, 1000);
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
// Check if Nyx version is old.
|
2020-12-11 15:25:59 +00:00
|
|
|
u32 expected_nyx_ver = ((NYX_VER_MJ + '0') << 24) | ((NYX_VER_MN + '0') << 16) | ((NYX_VER_HF + '0') << 8);
|
|
|
|
u32 nyx_ver = byte_swap_32(*(u32 *)(nyx + NYX_VER_OFF));
|
2019-12-11 09:22:11 +00:00
|
|
|
if (nyx_ver < expected_nyx_ver)
|
|
|
|
{
|
|
|
|
h_cfg.errors |= ERR_SYSOLD_NYX;
|
|
|
|
|
|
|
|
gfx_con_setpos(0, 0);
|
|
|
|
WPRINTF("Old Nyx GUI found! There will be dragons!\n");
|
2021-01-11 19:39:44 +00:00
|
|
|
WPRINTF("\nUpdate the bootloader folder!\n\n");
|
2019-12-11 09:22:11 +00:00
|
|
|
WPRINTF("Press any key...");
|
|
|
|
|
2020-07-14 20:41:48 +01:00
|
|
|
msleep(1000);
|
2019-12-11 09:22:11 +00:00
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
2020-12-11 15:25:59 +00:00
|
|
|
// Set hekate errors.
|
2019-12-11 09:22:11 +00:00
|
|
|
nyx_str->info.errors = h_cfg.errors;
|
2020-12-11 15:25:59 +00:00
|
|
|
|
|
|
|
// Set Nyx mode.
|
2019-06-30 01:55:19 +01:00
|
|
|
nyx_str->cfg = 0;
|
2022-10-11 05:21:41 +01:00
|
|
|
if (b_cfg.extra_cfg & EXTRA_CFG_NYX_UMS)
|
2019-06-30 01:55:19 +01:00
|
|
|
{
|
2022-10-11 05:21:41 +01:00
|
|
|
b_cfg.extra_cfg &= ~(EXTRA_CFG_NYX_UMS);
|
|
|
|
|
|
|
|
nyx_str->cfg |= NYX_CFG_UMS;
|
|
|
|
nyx_str->cfg |= b_cfg.ums << 24;
|
2019-06-30 01:55:19 +01:00
|
|
|
}
|
|
|
|
|
2020-12-11 15:25:59 +00:00
|
|
|
// Set hekate version used to boot Nyx.
|
2019-12-11 09:22:11 +00:00
|
|
|
nyx_str->version = ipl_ver.version - 0x303030; // Convert ASCII to numbers.
|
2019-06-30 01:55:19 +01:00
|
|
|
|
2020-12-11 15:46:44 +00:00
|
|
|
// Set SD card initialization info.
|
2022-10-11 05:21:41 +01:00
|
|
|
nyx_str->info.magic = NYX_NEW_INFO;
|
2020-12-11 15:46:44 +00:00
|
|
|
nyx_str->info.sd_init = sd_get_mode();
|
2022-10-11 05:21:41 +01:00
|
|
|
|
|
|
|
// Set SD card error info.
|
2020-12-11 15:46:44 +00:00
|
|
|
u16 *sd_errors = sd_get_error_count();
|
|
|
|
for (u32 i = 0; i < 3; i++)
|
|
|
|
nyx_str->info.sd_errors[i] = sd_errors[i];
|
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
reloc_meta_t *reloc = (reloc_meta_t *)(IPL_LOAD_ADDR + RELOC_META_OFF);
|
2019-06-30 01:55:19 +01:00
|
|
|
memcpy((u8 *)nyx_str->hekate, (u8 *)reloc->start, reloc->end - reloc->start);
|
|
|
|
|
2023-02-11 21:52:43 +00:00
|
|
|
// Do one last training.
|
|
|
|
minerva_periodic_training();
|
|
|
|
|
2019-06-30 01:55:19 +01:00
|
|
|
bpmp_mmu_disable();
|
|
|
|
bpmp_clk_rate_set(BPMP_CLK_NORMAL);
|
|
|
|
|
2023-02-11 21:51:43 +00:00
|
|
|
// Some cards (Sandisk U1), do not like a fast power cycle.
|
2019-08-28 00:39:43 +01:00
|
|
|
sdmmc_storage_init_wait_sd();
|
2019-07-06 20:08:37 +01:00
|
|
|
|
2023-02-11 21:51:43 +00:00
|
|
|
void (*nyx_ptr)() = (void *)nyx;
|
2019-06-30 01:55:19 +01:00
|
|
|
(*nyx_ptr)();
|
|
|
|
}
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
static ini_sec_t *_get_ini_sec_from_id(ini_sec_t *ini_sec, char **bootlogoCustomEntry, char **emummc_path)
|
2019-08-16 20:00:32 +01:00
|
|
|
{
|
|
|
|
ini_sec_t *cfg_sec = NULL;
|
|
|
|
|
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
|
|
|
|
{
|
|
|
|
if (!strcmp("id", kv->key))
|
2019-08-27 23:12:34 +01:00
|
|
|
{
|
|
|
|
if (b_cfg.id[0] && kv->val[0] && !strcmp(b_cfg.id, kv->val))
|
2019-08-16 20:00:32 +01:00
|
|
|
cfg_sec = ini_sec;
|
2019-08-27 23:12:34 +01:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2020-04-27 07:30:53 +01:00
|
|
|
if (!strcmp("emupath", kv->key))
|
|
|
|
*emummc_path = kv->val;
|
2022-10-11 05:21:41 +01:00
|
|
|
else if (!strcmp("logopath", kv->key))
|
|
|
|
*bootlogoCustomEntry = kv->val;
|
|
|
|
else if (!strcmp("emummc_force_disable", kv->key))
|
|
|
|
h_cfg.emummc_force_disable = atoi(kv->val);
|
2019-08-16 20:00:32 +01:00
|
|
|
}
|
|
|
|
if (!cfg_sec)
|
|
|
|
{
|
2022-10-11 05:21:41 +01:00
|
|
|
*emummc_path = NULL;
|
|
|
|
*bootlogoCustomEntry = NULL;
|
2019-08-16 20:00:32 +01:00
|
|
|
h_cfg.emummc_force_disable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfg_sec;
|
|
|
|
}
|
|
|
|
|
2020-10-20 08:16:12 +01:00
|
|
|
static void _bootloader_corruption_protect()
|
|
|
|
{
|
|
|
|
FILINFO fno;
|
|
|
|
if (!f_stat("bootloader", &fno))
|
|
|
|
{
|
|
|
|
if (!h_cfg.bootprotect && (fno.fattrib & AM_ARC))
|
2022-10-11 05:21:41 +01:00
|
|
|
f_chmod("bootloader", 0, AM_ARC);
|
2020-10-20 08:16:12 +01:00
|
|
|
else if (h_cfg.bootprotect && !(fno.fattrib & AM_ARC))
|
|
|
|
f_chmod("bootloader", AM_ARC, AM_ARC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
static void _check_for_updated_bootloader()
|
2022-01-28 23:23:40 +00:00
|
|
|
{
|
|
|
|
// Check if already chainloaded update and clear flag. Otherwise check for updates.
|
|
|
|
if (EMC(EMC_SCRATCH0) & EMC_HEKA_UPD)
|
|
|
|
EMC(EMC_SCRATCH0) &= ~EMC_HEKA_UPD;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Check if update.bin exists and is newer and launch it. Otherwise create it.
|
|
|
|
if (!f_stat("bootloader/update.bin", NULL))
|
2022-12-19 03:04:50 +00:00
|
|
|
_launch_payload("bootloader/update.bin", true, false);
|
2022-01-28 23:23:40 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
u8 *buf = calloc(0x200, 1);
|
|
|
|
is_ipl_updated(buf, "bootloader/update.bin", true);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
static void _auto_launch()
|
2018-07-01 18:45:52 +01:00
|
|
|
{
|
|
|
|
struct _bmp_data
|
|
|
|
{
|
|
|
|
u32 size;
|
|
|
|
u32 size_x;
|
|
|
|
u32 size_y;
|
|
|
|
u32 offset;
|
|
|
|
u32 pos_x;
|
|
|
|
u32 pos_y;
|
|
|
|
};
|
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
u32 boot_entry_id = 0;
|
|
|
|
ini_sec_t *cfg_sec = NULL;
|
|
|
|
char *emummc_path = NULL;
|
2018-07-01 18:45:52 +01:00
|
|
|
char *bootlogoCustomEntry = NULL;
|
2022-10-11 05:21:41 +01:00
|
|
|
bool config_entry_found = false;
|
2021-08-28 15:53:14 +01:00
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
_check_for_updated_bootloader();
|
2021-08-28 15:53:14 +01:00
|
|
|
|
|
|
|
bool boot_from_id = (b_cfg.boot_cfg & BOOT_CFG_FROM_ID) && (b_cfg.boot_cfg & BOOT_CFG_AUTOBOOT_EN);
|
|
|
|
if (boot_from_id)
|
|
|
|
b_cfg.id[7] = 0;
|
2018-07-01 18:45:52 +01:00
|
|
|
|
2019-03-07 22:35:43 +00:00
|
|
|
if (!(b_cfg.boot_cfg & BOOT_CFG_FROM_LAUNCH))
|
|
|
|
gfx_con.mute = true;
|
|
|
|
|
2018-07-01 18:45:52 +01:00
|
|
|
LIST_INIT(ini_sections);
|
2018-08-21 02:37:40 +01:00
|
|
|
LIST_INIT(ini_list_sections);
|
2018-07-01 18:45:52 +01:00
|
|
|
|
2022-01-20 11:56:36 +00:00
|
|
|
// Load emuMMC configuration.
|
|
|
|
emummc_load_cfg();
|
2021-09-26 10:23:54 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
// Parse hekate main configuration.
|
|
|
|
if (!ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
|
|
|
|
goto out; // Can't load hekate_ipl.ini.
|
2018-07-01 18:45:52 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
// Load configuration.
|
|
|
|
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
|
|
|
|
{
|
|
|
|
// Skip other ini entries for autoboot.
|
|
|
|
if (ini_sec->type == INI_CHOICE)
|
2022-01-20 11:56:36 +00:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!config_entry_found && !strcmp(ini_sec->name, "config"))
|
2018-07-01 18:45:52 +01:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
config_entry_found = true;
|
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
|
2018-07-01 18:45:52 +01:00
|
|
|
{
|
2022-10-11 05:21:41 +01:00
|
|
|
if (!strcmp("autoboot", kv->key))
|
2022-01-28 23:23:40 +00:00
|
|
|
h_cfg.autoboot = atoi(kv->val);
|
|
|
|
else if (!strcmp("autoboot_list", kv->key))
|
|
|
|
h_cfg.autoboot_list = atoi(kv->val);
|
2022-10-11 05:21:41 +01:00
|
|
|
else if (!strcmp("bootwait", kv->key))
|
2018-07-01 18:45:52 +01:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
h_cfg.bootwait = atoi(kv->val);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clamp value to default if it exceeds 20s to protect against corruption.
|
|
|
|
* 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;
|
2022-01-20 11:56:36 +00:00
|
|
|
}
|
2022-10-11 05:21:41 +01:00
|
|
|
else if (!strcmp("backlight", kv->key))
|
|
|
|
h_cfg.backlight = atoi(kv->val);
|
2022-10-11 05:49:17 +01:00
|
|
|
else if (!strcmp("noticker", kv->key))
|
|
|
|
h_cfg.noticker = atoi(kv->val);
|
2022-10-11 05:21:41 +01: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);
|
|
|
|
}
|
|
|
|
boot_entry_id++;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
// Override autoboot.
|
|
|
|
if (b_cfg.boot_cfg & BOOT_CFG_AUTOBOOT_EN)
|
|
|
|
{
|
|
|
|
h_cfg.autoboot = b_cfg.autoboot;
|
|
|
|
h_cfg.autoboot_list = b_cfg.autoboot_list;
|
|
|
|
}
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
// Apply bootloader protection against corruption.
|
|
|
|
_bootloader_corruption_protect();
|
2020-10-20 08:16:12 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-07-01 18:45:52 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (boot_from_id)
|
2022-12-19 03:04:50 +00:00
|
|
|
cfg_sec = _get_ini_sec_from_id(ini_sec, &bootlogoCustomEntry, &emummc_path);
|
2022-01-28 23:23:40 +00:00
|
|
|
else if (h_cfg.autoboot == boot_entry_id && config_entry_found)
|
|
|
|
{
|
|
|
|
cfg_sec = ini_sec;
|
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg_sec->kvs, link)
|
2022-01-20 11:56:36 +00:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!strcmp("logopath", kv->key))
|
|
|
|
bootlogoCustomEntry = kv->val;
|
|
|
|
else if (!strcmp("emupath", kv->key))
|
|
|
|
emummc_path = kv->val;
|
2022-10-11 05:21:41 +01:00
|
|
|
else if (!strcmp("emummc_force_disable", kv->key))
|
|
|
|
h_cfg.emummc_force_disable = atoi(kv->val);
|
2018-07-01 18:45:52 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
if (cfg_sec)
|
|
|
|
break;
|
|
|
|
boot_entry_id++;
|
2022-01-20 11:56:36 +00:00
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (h_cfg.autohosoff && !(b_cfg.boot_cfg & BOOT_CFG_AUTOBOOT_EN))
|
|
|
|
check_power_off_from_hos();
|
2018-07-01 18:45:52 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (h_cfg.autoboot_list || (boot_from_id && !cfg_sec))
|
|
|
|
{
|
|
|
|
if (boot_from_id && cfg_sec)
|
|
|
|
goto skip_list;
|
|
|
|
|
|
|
|
cfg_sec = NULL;
|
|
|
|
boot_entry_id = 1;
|
|
|
|
bootlogoCustomEntry = NULL;
|
2018-09-24 21:45:06 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!ini_parse(&ini_list_sections, "bootloader/ini", true))
|
|
|
|
goto skip_list;
|
|
|
|
|
|
|
|
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec_list, &ini_list_sections, link)
|
2022-01-20 11:56:36 +00:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
if (ini_sec_list->type != INI_CHOICE)
|
|
|
|
continue;
|
2019-08-16 20:00:32 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!strcmp(ini_sec_list->name, "config"))
|
|
|
|
continue;
|
2018-08-21 02:37:40 +01:00
|
|
|
|
2022-01-28 23:23:40 +00:00
|
|
|
if (boot_from_id)
|
2022-12-19 03:04:50 +00:00
|
|
|
cfg_sec = _get_ini_sec_from_id(ini_sec_list, &bootlogoCustomEntry, &emummc_path);
|
2022-01-28 23:23:40 +00:00
|
|
|
else if (h_cfg.autoboot == boot_entry_id)
|
2022-01-20 11:56:36 +00:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
h_cfg.emummc_force_disable = false;
|
|
|
|
cfg_sec = ini_sec_list;
|
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg_sec->kvs, link)
|
2018-08-21 02:37:40 +01:00
|
|
|
{
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!strcmp("logopath", kv->key))
|
|
|
|
bootlogoCustomEntry = kv->val;
|
|
|
|
else if (!strcmp("emupath", kv->key))
|
|
|
|
emummc_path = kv->val;
|
2022-10-11 05:21:41 +01:00
|
|
|
else if (!strcmp("emummc_force_disable", kv->key))
|
|
|
|
h_cfg.emummc_force_disable = atoi(kv->val);
|
2018-08-21 02:37:40 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
if (cfg_sec)
|
|
|
|
break;
|
|
|
|
boot_entry_id++;
|
2018-07-01 18:45:52 +01:00
|
|
|
}
|
2022-01-28 23:23:40 +00:00
|
|
|
}
|
|
|
|
|
2022-01-20 11:56:36 +00:00
|
|
|
skip_list:
|
2022-01-28 23:23:40 +00:00
|
|
|
if (!cfg_sec)
|
|
|
|
goto out; // No configurations or auto boot is disabled.
|
2018-07-01 18:45:52 +01:00
|
|
|
|
2022-12-19 03:43:48 +00:00
|
|
|
// Check if entry is payload or l4t special case.
|
|
|
|
char *special_path = ini_check_special_section(cfg_sec);
|
|
|
|
|
2022-12-20 15:00:33 +00:00
|
|
|
if ((!(b_cfg.boot_cfg & BOOT_CFG_FROM_LAUNCH) && h_cfg.bootwait) || // Conditional for HOS/Payload.
|
|
|
|
(special_path && special_path == (char *)-1)) // Always show for L4T.
|
2019-02-24 00:43:13 +00:00
|
|
|
{
|
2020-06-14 11:04:13 +01:00
|
|
|
u32 fsize;
|
2022-01-28 23:36:35 +00:00
|
|
|
u8 *logo_buf = NULL;
|
2022-10-11 05:21:41 +01:00
|
|
|
u8 *bitmap = NULL;
|
|
|
|
struct _bmp_data bmpData;
|
|
|
|
bool bootlogoFound = false;
|
2021-08-28 15:53:14 +01:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
// Check if user set custom logo path at the boot entry.
|
|
|
|
if (bootlogoCustomEntry)
|
2020-06-14 11:04:13 +01:00
|
|
|
bitmap = (u8 *)sd_file_read(bootlogoCustomEntry, &fsize);
|
2019-03-07 22:19:04 +00:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
// Custom entry bootlogo not found, trying default custom one.
|
|
|
|
if (!bitmap)
|
2020-06-14 11:04:13 +01:00
|
|
|
bitmap = (u8 *)sd_file_read("bootloader/bootlogo.bmp", &fsize);
|
2018-07-01 18:45:52 +01:00
|
|
|
|
2019-03-07 22:19:04 +00:00
|
|
|
if (bitmap)
|
2018-07-01 18:45:52 +01:00
|
|
|
{
|
|
|
|
// Get values manually to avoid unaligned access.
|
|
|
|
bmpData.size = bitmap[2] | bitmap[3] << 8 |
|
|
|
|
bitmap[4] << 16 | bitmap[5] << 24;
|
|
|
|
bmpData.offset = bitmap[10] | bitmap[11] << 8 |
|
|
|
|
bitmap[12] << 16 | bitmap[13] << 24;
|
|
|
|
bmpData.size_x = bitmap[18] | bitmap[19] << 8 |
|
|
|
|
bitmap[20] << 16 | bitmap[21] << 24;
|
|
|
|
bmpData.size_y = bitmap[22] | bitmap[23] << 8 |
|
|
|
|
bitmap[24] << 16 | bitmap[25] << 24;
|
|
|
|
// Sanity check.
|
|
|
|
if (bitmap[0] == 'B' &&
|
|
|
|
bitmap[1] == 'M' &&
|
2019-03-07 22:19:04 +00:00
|
|
|
bitmap[28] == 32 && // Only 32 bit BMPs allowed.
|
2018-07-01 18:45:52 +01:00
|
|
|
bmpData.size_x <= 720 &&
|
|
|
|
bmpData.size_y <= 1280)
|
|
|
|
{
|
2021-10-01 13:45:25 +01:00
|
|
|
if (bmpData.size <= fsize && ((bmpData.size - bmpData.offset) < SZ_4M))
|
2018-07-01 18:45:52 +01:00
|
|
|
{
|
|
|
|
// Avoid unaligned access from BM 2-byte MAGIC and remove header.
|
2022-01-28 23:36:35 +00:00
|
|
|
logo_buf = (u8 *)malloc(SZ_4M);
|
|
|
|
memcpy(logo_buf, bitmap + bmpData.offset, bmpData.size - bmpData.offset);
|
2018-07-01 18:45:52 +01:00
|
|
|
free(bitmap);
|
|
|
|
// Center logo if res < 720x1280.
|
|
|
|
bmpData.pos_x = (720 - bmpData.size_x) >> 1;
|
|
|
|
bmpData.pos_y = (1280 - bmpData.size_y) >> 1;
|
2018-07-09 13:55:09 +01:00
|
|
|
// Get background color from 1st pixel.
|
|
|
|
if (bmpData.size_x < 720 || bmpData.size_y < 1280)
|
2022-01-28 23:36:35 +00:00
|
|
|
gfx_clear_color(*(u32 *)logo_buf);
|
2018-07-01 18:45:52 +01:00
|
|
|
|
2018-08-13 10:12:53 +01:00
|
|
|
bootlogoFound = true;
|
2018-07-01 18:45:52 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
free(bitmap);
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:43:13 +00:00
|
|
|
// Render boot logo.
|
|
|
|
if (bootlogoFound)
|
|
|
|
{
|
2022-01-28 23:36:35 +00:00
|
|
|
gfx_render_bmp_argb((u32 *)logo_buf, bmpData.size_x, bmpData.size_y,
|
2019-02-24 00:43:13 +00:00
|
|
|
bmpData.pos_x, bmpData.pos_y);
|
2022-01-28 23:36:35 +00:00
|
|
|
free(logo_buf);
|
2022-10-11 05:49:17 +01:00
|
|
|
|
|
|
|
// Do animated waiting before booting. If VOL- is pressed go into bootloader menu.
|
|
|
|
if (render_ticker(h_cfg.bootwait, h_cfg.backlight, h_cfg.noticker))
|
|
|
|
goto out;
|
2019-02-24 00:43:13 +00:00
|
|
|
}
|
|
|
|
else
|
2022-10-11 05:49:17 +01:00
|
|
|
{
|
|
|
|
// Do animated waiting before booting. If VOL- is pressed go into bootloader menu.
|
|
|
|
if (render_ticker_logo(h_cfg.bootwait, h_cfg.backlight))
|
|
|
|
goto out;
|
|
|
|
}
|
2018-07-01 18:45:52 +01:00
|
|
|
}
|
|
|
|
|
2019-07-06 20:34:03 +01:00
|
|
|
if (b_cfg.boot_cfg & BOOT_CFG_FROM_LAUNCH)
|
|
|
|
display_backlight_brightness(h_cfg.backlight, 0);
|
2022-10-11 05:49:17 +01:00
|
|
|
else if (btn_read_vol() == BTN_VOL_DOWN) // 0s bootwait VOL- check.
|
|
|
|
goto out;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2022-12-19 03:43:48 +00:00
|
|
|
if (special_path)
|
2018-07-01 18:45:52 +01:00
|
|
|
{
|
2022-12-19 03:43:48 +00:00
|
|
|
// Try to launch Payload or L4T.
|
|
|
|
if (special_path != (char *)-1)
|
|
|
|
_launch_payload(special_path, false, false);
|
2022-12-20 15:00:33 +00:00
|
|
|
else
|
|
|
|
launch_l4t(cfg_sec, h_cfg.autoboot, h_cfg.autoboot_list, h_cfg.t210b01);
|
2022-10-11 05:21:41 +01:00
|
|
|
goto error;
|
2018-08-21 02:45:19 +01:00
|
|
|
}
|
|
|
|
else
|
2019-03-07 22:35:43 +00:00
|
|
|
{
|
2020-04-27 07:30:53 +01:00
|
|
|
if (b_cfg.boot_cfg & BOOT_CFG_TO_EMUMMC)
|
|
|
|
emummc_set_path(b_cfg.emummc_path);
|
2020-05-05 17:23:31 +01:00
|
|
|
else if (emummc_path && !emummc_set_path(emummc_path))
|
|
|
|
{
|
|
|
|
gfx_con.mute = false;
|
|
|
|
EPRINTF("emupath is wrong!");
|
|
|
|
goto wrong_emupath;
|
|
|
|
}
|
|
|
|
|
2018-08-21 02:45:19 +01:00
|
|
|
hos_launch(cfg_sec);
|
2019-10-08 22:42:13 +01:00
|
|
|
|
2020-06-14 00:09:48 +01:00
|
|
|
wrong_emupath:
|
2020-04-27 07:30:53 +01:00
|
|
|
if (emummc_path || b_cfg.boot_cfg & BOOT_CFG_TO_EMUMMC)
|
|
|
|
{
|
|
|
|
sd_mount();
|
2021-09-26 10:23:54 +01:00
|
|
|
emummc_load_cfg(); // Reload emuMMC config in case of emupath.
|
2020-04-27 07:30:53 +01:00
|
|
|
}
|
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
error:
|
2021-04-12 02:26:16 +01:00
|
|
|
gfx_con.mute = false;
|
2019-12-11 09:22:11 +00:00
|
|
|
gfx_printf("\nPress any key...\n");
|
2020-06-14 00:09:48 +01:00
|
|
|
display_backlight_brightness(h_cfg.backlight, 1000);
|
2019-10-08 22:42:13 +01:00
|
|
|
msleep(500);
|
|
|
|
btn_wait();
|
2019-03-07 22:35:43 +00:00
|
|
|
}
|
2018-08-21 02:45:19 +01:00
|
|
|
|
2018-08-05 12:40:32 +01:00
|
|
|
out:
|
2018-08-13 10:12:53 +01:00
|
|
|
gfx_con.mute = false;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2019-08-16 20:00:32 +01:00
|
|
|
// Clear boot reasons from binary.
|
2020-04-27 07:30:53 +01:00
|
|
|
if (b_cfg.boot_cfg & (BOOT_CFG_FROM_ID | BOOT_CFG_TO_EMUMMC))
|
2019-08-16 20:00:32 +01:00
|
|
|
memset(b_cfg.xt_str, 0, sizeof(b_cfg.xt_str));
|
2019-06-30 01:24:58 +01:00
|
|
|
h_cfg.emummc_force_disable = false;
|
2019-06-30 01:55:19 +01:00
|
|
|
|
2020-08-15 11:12:41 +01:00
|
|
|
// L4T: Clear custom boot mode flags from PMC_SCRATCH0.
|
|
|
|
PMC(APBDEV_PMC_SCRATCH0) &= ~PMC_SCRATCH0_MODE_CUSTOM_ALL;
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
_nyx_load_run();
|
2018-07-01 18:45:52 +01:00
|
|
|
}
|
|
|
|
|
2020-04-27 07:56:19 +01:00
|
|
|
#define EXCP_EN_ADDR 0x4003FFFC
|
2022-10-11 05:21:41 +01:00
|
|
|
#define EXCP_MAGIC 0x30505645 // "EVP0".
|
2020-04-27 07:56:19 +01:00
|
|
|
#define EXCP_TYPE_ADDR 0x4003FFF8
|
2022-10-11 05:21:41 +01:00
|
|
|
#define EXCP_TYPE_RESET 0x545352 // "RST".
|
|
|
|
#define EXCP_TYPE_UNDEF 0x464455 // "UDF".
|
|
|
|
#define EXCP_TYPE_PABRT 0x54424150 // "PABT".
|
|
|
|
#define EXCP_TYPE_DABRT 0x54424144 // "DABT".
|
|
|
|
#define EXCP_TYPE_WDT 0x544457 // "WDT".
|
2020-04-27 07:56:19 +01:00
|
|
|
#define EXCP_LR_ADDR 0x4003FFF4
|
|
|
|
|
2022-01-15 23:23:39 +00:00
|
|
|
#define PSTORE_LOG_OFFSET 0x180000
|
2022-06-29 10:19:19 +01:00
|
|
|
#define PSTORE_RAM_SIG 0x43474244 // "DBGC".
|
2022-01-15 23:23:39 +00:00
|
|
|
|
|
|
|
typedef struct _pstore_buf {
|
|
|
|
u32 sig;
|
|
|
|
u32 start;
|
|
|
|
u32 size;
|
|
|
|
} pstore_buf_t;
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
static void _show_errors()
|
|
|
|
{
|
2020-04-27 07:56:19 +01:00
|
|
|
u32 *excp_lr = (u32 *)EXCP_LR_ADDR;
|
2022-10-11 05:21:41 +01:00
|
|
|
u32 *excp_type = (u32 *)EXCP_TYPE_ADDR;
|
|
|
|
u32 *excp_enabled = (u32 *)EXCP_EN_ADDR;
|
|
|
|
|
2021-10-01 12:35:39 +01:00
|
|
|
u32 panic_status = hw_rst_status & 0xFFFFF;
|
2020-04-27 07:56:19 +01:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
// Check for exception error.
|
2020-04-27 07:56:19 +01:00
|
|
|
if (*excp_enabled == EXCP_MAGIC)
|
2020-10-23 04:32:24 +01:00
|
|
|
h_cfg.errors |= ERR_EXCEPTION;
|
2020-04-27 07:56:19 +01:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
// Check for L4T kernel panic.
|
2022-01-15 23:23:39 +00:00
|
|
|
if (PMC(APBDEV_PMC_SCRATCH37) == PMC_SCRATCH37_KERNEL_PANIC_MAGIC)
|
2020-07-19 18:32:22 +01:00
|
|
|
{
|
|
|
|
// Set error and clear flag.
|
|
|
|
h_cfg.errors |= ERR_L4T_KERNEL;
|
2022-01-15 23:23:39 +00:00
|
|
|
PMC(APBDEV_PMC_SCRATCH37) = 0;
|
2020-07-19 18:32:22 +01:00
|
|
|
}
|
2021-10-01 12:35:39 +01:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
// Check for watchdog panic.
|
2022-01-15 23:33:07 +00:00
|
|
|
if (hw_rst_reason == PMC_RST_STATUS_WATCHDOG && panic_status &&
|
2021-10-01 12:35:39 +01:00
|
|
|
panic_status <= 0xFF && panic_status != 0x20 && panic_status != 0x21)
|
2022-10-11 05:21:41 +01:00
|
|
|
{
|
2021-10-01 12:35:39 +01:00
|
|
|
h_cfg.errors |= ERR_PANIC_CODE;
|
2022-10-11 05:21:41 +01:00
|
|
|
}
|
2020-07-19 18:32:22 +01:00
|
|
|
|
2021-10-15 14:34:15 +01:00
|
|
|
// Check if we had a panic while in CFW.
|
|
|
|
secmon_exo_check_panic();
|
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
// Handle errors.
|
2019-12-11 09:22:11 +00:00
|
|
|
if (h_cfg.errors)
|
|
|
|
{
|
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2020-04-14 15:55:31 +01:00
|
|
|
display_backlight_brightness(150, 1000);
|
2019-12-11 09:22:11 +00:00
|
|
|
|
2020-08-28 07:37:48 +01:00
|
|
|
if (h_cfg.errors & ERR_SD_BOOT_EN)
|
2022-01-15 23:33:07 +00:00
|
|
|
{
|
|
|
|
WPRINTF("Failed to init or mount SD!\n");
|
|
|
|
|
|
|
|
// Clear the module bits as to not cram the error screen.
|
|
|
|
h_cfg.errors &= ~(ERR_LIBSYS_LP0 | ERR_LIBSYS_MTC);
|
|
|
|
}
|
2020-08-28 07:37:48 +01:00
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
if (h_cfg.errors & ERR_LIBSYS_LP0)
|
2022-01-15 23:33:07 +00:00
|
|
|
WPRINTF("Missing LP0 (sleep) lib!\n");
|
2020-07-19 18:32:22 +01:00
|
|
|
if (h_cfg.errors & ERR_LIBSYS_MTC)
|
2022-01-15 23:33:07 +00:00
|
|
|
WPRINTF("Missing Minerva lib!\n");
|
2019-12-11 09:22:11 +00:00
|
|
|
|
2020-10-23 04:32:24 +01:00
|
|
|
if (h_cfg.errors & (ERR_LIBSYS_LP0 | ERR_LIBSYS_MTC))
|
2020-04-30 01:25:22 +01:00
|
|
|
WPRINTF("\nUpdate bootloader folder!\n\n");
|
2020-04-27 07:56:19 +01:00
|
|
|
|
2020-10-23 04:32:24 +01:00
|
|
|
if (h_cfg.errors & ERR_EXCEPTION)
|
2020-04-27 07:56:19 +01:00
|
|
|
{
|
2022-01-15 23:33:07 +00:00
|
|
|
WPRINTFARGS("hekate exception occurred (LR %08X):\n", *excp_lr);
|
2020-04-27 07:56:19 +01:00
|
|
|
switch (*excp_type)
|
|
|
|
{
|
2022-06-29 10:19:19 +01:00
|
|
|
case EXCP_TYPE_WDT:
|
|
|
|
WPRINTF("Hang detected in LP0/Minerva!");
|
|
|
|
break;
|
2020-04-27 07:56:19 +01:00
|
|
|
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:23:39 +00:00
|
|
|
gfx_puts("\n");
|
2020-04-27 07:56:19 +01:00
|
|
|
|
|
|
|
// Clear the exception.
|
|
|
|
*excp_enabled = 0;
|
2022-06-29 10:19:19 +01:00
|
|
|
*excp_type = 0;
|
2020-04-27 07:56:19 +01:00
|
|
|
}
|
|
|
|
|
2022-01-15 23:23:39 +00:00
|
|
|
if (h_cfg.errors & ERR_L4T_KERNEL)
|
2020-07-19 18:32:22 +01:00
|
|
|
{
|
2022-01-15 23:33:07 +00:00
|
|
|
WPRINTF("Kernel panic occurred!\n");
|
2022-01-20 11:56:36 +00:00
|
|
|
if (!(h_cfg.errors & ERR_SD_BOOT_EN))
|
2022-01-15 23:23:39 +00:00
|
|
|
{
|
2022-01-20 11:56:36 +00:00
|
|
|
if (!sd_save_to_file((void *)PSTORE_ADDR, PSTORE_SZ, "L4T_panic.bin"))
|
|
|
|
WPRINTF("PSTORE saved to L4T_panic.bin");
|
|
|
|
pstore_buf_t *buf = (pstore_buf_t *)(PSTORE_ADDR + PSTORE_LOG_OFFSET);
|
2022-01-28 23:37:02 +00:00
|
|
|
if (buf->sig == PSTORE_RAM_SIG && buf->size && buf->size < 0x80000)
|
2022-01-20 11:56:36 +00:00
|
|
|
{
|
|
|
|
u32 log_offset = PSTORE_ADDR + PSTORE_LOG_OFFSET + sizeof(pstore_buf_t);
|
|
|
|
if (!sd_save_to_file((void *)log_offset, buf->size, "L4T_panic.txt"))
|
|
|
|
WPRINTF("Log saved to L4T_panic.txt");
|
|
|
|
}
|
2022-01-15 23:23:39 +00:00
|
|
|
}
|
|
|
|
gfx_puts("\n");
|
2020-07-19 18:32:22 +01:00
|
|
|
}
|
2021-10-01 12:35:39 +01:00
|
|
|
|
|
|
|
if (h_cfg.errors & ERR_PANIC_CODE)
|
|
|
|
{
|
|
|
|
u32 r = (hw_rst_status >> 20) & 0xF;
|
|
|
|
u32 g = (hw_rst_status >> 24) & 0xF;
|
|
|
|
u32 b = (hw_rst_status >> 28) & 0xF;
|
|
|
|
r = (r << 16) | (r << 20);
|
2022-10-11 05:21:41 +01:00
|
|
|
g = (g << 8) | (g << 12);
|
|
|
|
b = (b << 0) | (b << 4);
|
2021-10-01 12:35:39 +01:00
|
|
|
u32 color = r | g | b;
|
|
|
|
|
2022-01-15 23:33:07 +00:00
|
|
|
WPRINTF("HOS panic occurred!\n");
|
2022-07-01 02:37:57 +01:00
|
|
|
gfx_printf("Color: %k####%k, Code: %02X\n\n", color, TXT_CLR_DEFAULT, panic_status);
|
2021-10-01 12:35:39 +01:00
|
|
|
}
|
2020-07-19 18:32:22 +01:00
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
WPRINTF("Press any key...");
|
|
|
|
|
2021-10-01 12:35:39 +01:00
|
|
|
msleep(1000); // Guard against injection VOL+.
|
2019-12-11 09:22:11 +00:00
|
|
|
btn_wait();
|
2021-10-01 12:35:39 +01:00
|
|
|
msleep(500); // Guard against force menu VOL-.
|
2019-12-11 09:22:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 03:54:45 +01:00
|
|
|
static void _check_low_battery()
|
|
|
|
{
|
2021-01-04 00:58:07 +00:00
|
|
|
if (fuse_read_hw_state() == FUSE_NX_HW_STATE_DEV)
|
|
|
|
goto out;
|
|
|
|
|
2020-04-06 03:54:45 +01:00
|
|
|
int enough_battery;
|
2020-11-15 12:49:54 +00:00
|
|
|
int batt_volt = 0;
|
2020-04-06 03:54:45 +01:00
|
|
|
int charge_status = 0;
|
|
|
|
|
|
|
|
bq24193_get_property(BQ24193_ChargeStatus, &charge_status);
|
2022-10-11 05:21:41 +01:00
|
|
|
max17050_get_property(MAX17050_AvgVCELL, &batt_volt);
|
2020-04-06 03:54:45 +01:00
|
|
|
|
2022-12-19 03:35:45 +00:00
|
|
|
enough_battery = charge_status ? 3300 : 3100;
|
2020-04-06 03:54:45 +01:00
|
|
|
|
2022-06-04 20:03:47 +01:00
|
|
|
// If battery voltage is enough, exit.
|
2020-11-15 12:49:54 +00:00
|
|
|
if (batt_volt > enough_battery || !batt_volt)
|
2020-06-14 00:05:57 +01:00
|
|
|
goto out;
|
2020-04-06 03:54:45 +01:00
|
|
|
|
|
|
|
// Prepare battery icon resources.
|
2022-12-19 03:04:50 +00:00
|
|
|
u8 *battery_res = malloc(ALIGN(BATTERY_EMPTY_SIZE, SZ_4K));
|
|
|
|
blz_uncompress_srcdest(battery_icons_blz, BATTERY_EMPTY_BLZ_SIZE, battery_res, BATTERY_EMPTY_SIZE);
|
2020-04-06 03:54:45 +01:00
|
|
|
|
2022-10-11 05:21:41 +01:00
|
|
|
u8 *battery_icon = malloc(0x95A); // 21x38x3
|
|
|
|
u8 *charging_icon = malloc(0x2F4); // 21x12x3
|
2020-04-06 03:54:45 +01:00
|
|
|
u8 *no_charging_icon = calloc(0x2F4, 1);
|
|
|
|
|
|
|
|
memcpy(charging_icon, battery_res, 0x2F4);
|
|
|
|
memcpy(battery_icon, battery_res + 0x2F4, 0x95A);
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
u32 battery_icon_y_pos = 1280 - 16 - BATTERY_EMPTY_BATT_HEIGHT;
|
|
|
|
u32 charging_icon_y_pos = 1280 - 16 - BATTERY_EMPTY_BATT_HEIGHT - 12 - BATTERY_EMPTY_CHRG_HEIGHT;
|
2020-04-06 03:54:45 +01:00
|
|
|
free(battery_res);
|
|
|
|
|
|
|
|
charge_status = !charge_status;
|
|
|
|
|
|
|
|
u32 timer = 0;
|
|
|
|
bool screen_on = false;
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
bpmp_msleep(250);
|
|
|
|
|
|
|
|
// Refresh battery stats.
|
|
|
|
int current_charge_status = 0;
|
|
|
|
bq24193_get_property(BQ24193_ChargeStatus, ¤t_charge_status);
|
|
|
|
max17050_get_property(MAX17050_AvgVCELL, &batt_volt);
|
2022-12-19 03:35:45 +00:00
|
|
|
enough_battery = current_charge_status ? 3300 : 3100;
|
2020-04-06 03:54:45 +01:00
|
|
|
|
2022-06-04 20:03:47 +01:00
|
|
|
// If battery voltage is enough, exit.
|
2020-04-06 03:54:45 +01:00
|
|
|
if (batt_volt > enough_battery)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Refresh charging icon.
|
|
|
|
if (screen_on && (charge_status != current_charge_status))
|
|
|
|
{
|
|
|
|
if (current_charge_status)
|
2022-12-19 03:04:50 +00:00
|
|
|
gfx_set_rect_rgb(charging_icon, BATTERY_EMPTY_WIDTH, BATTERY_EMPTY_CHRG_HEIGHT, 16, charging_icon_y_pos);
|
2020-04-06 03:54:45 +01:00
|
|
|
else
|
2022-12-19 03:04:50 +00:00
|
|
|
gfx_set_rect_rgb(no_charging_icon, BATTERY_EMPTY_WIDTH, BATTERY_EMPTY_CHRG_HEIGHT, 16, charging_icon_y_pos);
|
2020-04-06 03:54:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if it's time to turn off display.
|
|
|
|
if (screen_on && timer < get_tmr_ms())
|
|
|
|
{
|
2022-06-04 20:03:47 +01:00
|
|
|
// If battery is not charging, power off.
|
2020-04-06 03:54:45 +01:00
|
|
|
if (!current_charge_status)
|
|
|
|
{
|
|
|
|
max77620_low_battery_monitor_config(true);
|
2022-06-04 20:03:47 +01:00
|
|
|
|
|
|
|
// Handle full hw deinit and power off.
|
2020-12-15 17:37:52 +00:00
|
|
|
power_set_state(POWER_OFF_RESET);
|
2020-04-06 03:54:45 +01:00
|
|
|
}
|
|
|
|
|
2022-06-04 20:03:47 +01:00
|
|
|
// If charging, just disable display.
|
2020-04-06 03:54:45 +01:00
|
|
|
display_end();
|
|
|
|
screen_on = false;
|
|
|
|
}
|
|
|
|
|
2022-06-04 20:03:47 +01:00
|
|
|
// Check if charging status changed or Power button was pressed and enable display.
|
2020-06-13 16:16:29 +01:00
|
|
|
if ((charge_status != current_charge_status) || (btn_wait_timeout_single(0, BTN_POWER) & BTN_POWER))
|
2020-04-06 03:54:45 +01:00
|
|
|
{
|
|
|
|
if (!screen_on)
|
|
|
|
{
|
|
|
|
display_init();
|
2020-06-13 16:16:29 +01:00
|
|
|
u32 *fb = display_init_framebuffer_pitch();
|
2020-04-06 03:54:45 +01:00
|
|
|
gfx_init_ctxt(fb, 720, 1280, 720);
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
gfx_set_rect_rgb(battery_icon, BATTERY_EMPTY_WIDTH, BATTERY_EMPTY_BATT_HEIGHT, 16, battery_icon_y_pos);
|
2020-04-06 03:54:45 +01:00
|
|
|
if (current_charge_status)
|
2022-12-19 03:04:50 +00:00
|
|
|
gfx_set_rect_rgb(charging_icon, BATTERY_EMPTY_WIDTH, BATTERY_EMPTY_CHRG_HEIGHT, 16, charging_icon_y_pos);
|
2020-04-06 03:54:45 +01:00
|
|
|
else
|
2022-12-19 03:04:50 +00:00
|
|
|
gfx_set_rect_rgb(no_charging_icon, BATTERY_EMPTY_WIDTH, BATTERY_EMPTY_CHRG_HEIGHT, 16, charging_icon_y_pos);
|
2020-04-06 03:54:45 +01:00
|
|
|
|
|
|
|
display_backlight_pwm_init();
|
|
|
|
display_backlight_brightness(100, 1000);
|
|
|
|
|
|
|
|
screen_on = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
timer = get_tmr_ms() + 15000;
|
|
|
|
}
|
|
|
|
|
2020-04-14 15:55:31 +01:00
|
|
|
// Check if forcefully continuing.
|
|
|
|
if (btn_read_vol() == (BTN_VOL_UP | BTN_VOL_DOWN))
|
|
|
|
break;
|
|
|
|
|
2020-04-06 03:54:45 +01:00
|
|
|
charge_status = current_charge_status;
|
|
|
|
}
|
|
|
|
|
2022-06-04 20:03:47 +01:00
|
|
|
if (screen_on)
|
|
|
|
display_end();
|
2020-04-06 03:54:45 +01:00
|
|
|
|
|
|
|
free(battery_icon);
|
|
|
|
free(charging_icon);
|
|
|
|
free(no_charging_icon);
|
2020-04-27 07:30:53 +01:00
|
|
|
|
2020-06-14 00:05:57 +01:00
|
|
|
out:
|
2020-04-06 03:54:45 +01:00
|
|
|
// Re enable Low Battery Monitor shutdown.
|
|
|
|
max77620_low_battery_monitor_config(true);
|
|
|
|
}
|
|
|
|
|
2022-12-19 03:31:35 +00:00
|
|
|
static void _r2p_get_config_t210b01()
|
|
|
|
{
|
|
|
|
rtc_reboot_reason_t rr;
|
|
|
|
if (!max77620_rtc_get_reboot_reason(&rr))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Check if reason is actually set.
|
|
|
|
if (rr.dec.reason != REBOOT_REASON_NOP)
|
|
|
|
{
|
|
|
|
// Clear boot storage.
|
|
|
|
memset(&b_cfg, 0, sizeof(boot_cfg_t));
|
|
|
|
|
|
|
|
// Enable boot storage.
|
|
|
|
b_cfg.boot_cfg |= BOOT_CFG_AUTOBOOT_EN;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (rr.dec.reason)
|
|
|
|
{
|
|
|
|
case REBOOT_REASON_NOP:
|
|
|
|
break;
|
|
|
|
case REBOOT_REASON_REC:
|
|
|
|
PMC(APBDEV_PMC_SCRATCH0) |= PMC_SCRATCH0_MODE_RECOVERY;
|
|
|
|
case REBOOT_REASON_SELF:
|
|
|
|
b_cfg.autoboot = rr.dec.autoboot_idx;
|
|
|
|
b_cfg.autoboot_list = rr.dec.autoboot_list;
|
|
|
|
break;
|
|
|
|
case REBOOT_REASON_MENU:
|
|
|
|
break;
|
|
|
|
case REBOOT_REASON_UMS:
|
|
|
|
b_cfg.extra_cfg |= EXTRA_CFG_NYX_UMS;
|
|
|
|
b_cfg.ums = rr.dec.ums_idx;
|
|
|
|
break;
|
|
|
|
case REBOOT_REASON_PANIC:
|
|
|
|
PMC(APBDEV_PMC_SCRATCH37) = PMC_SCRATCH37_KERNEL_PANIC_MAGIC;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-19 03:04:50 +00:00
|
|
|
static void _ipl_reload()
|
2020-09-15 16:57:49 +01:00
|
|
|
{
|
|
|
|
hw_reinit_workaround(false, 0);
|
|
|
|
|
|
|
|
// Reload hekate.
|
|
|
|
void (*ipl_ptr)() = (void *)IPL_LOAD_ADDR;
|
|
|
|
(*ipl_ptr)();
|
|
|
|
}
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
static void _about()
|
2018-05-01 06:15:48 +01:00
|
|
|
{
|
2018-06-26 17:09:26 +01:00
|
|
|
static const char credits[] =
|
2021-05-11 08:11:31 +01:00
|
|
|
"\nhekate (c) 2018, naehrwert, st4rk\n\n"
|
2022-01-28 23:43:35 +00:00
|
|
|
" (c) 2018-2022, CTCaer\n\n"
|
2018-08-05 12:40:32 +01:00
|
|
|
" ___________________________________________\n\n"
|
|
|
|
"Thanks to: %kderrek, nedwill, plutoo,\n"
|
|
|
|
" shuffle2, smea, thexyz, yellows8%k\n"
|
|
|
|
" ___________________________________________\n\n"
|
|
|
|
"Greetings to: fincs, hexkyz, SciresM,\n"
|
|
|
|
" Shiny Quagsire, WinterMute\n"
|
|
|
|
" ___________________________________________\n\n"
|
|
|
|
"Open source and free packages used:\n\n"
|
2022-03-22 22:24:13 +00:00
|
|
|
" - FatFs R0.13c\n"
|
2021-05-11 08:11:31 +01:00
|
|
|
" (c) 2018, ChaN\n\n"
|
|
|
|
" - bcl-1.2.0\n"
|
|
|
|
" (c) 2003-2006, Marcus Geelnard\n\n"
|
|
|
|
" - Atmosphere (Exo st/types, prc id patches)\n"
|
|
|
|
" (c) 2018-2019, Atmosphere-NX\n\n"
|
|
|
|
" - elfload\n"
|
|
|
|
" (c) 2014, Owen Shepherd\n"
|
|
|
|
" (c) 2018, M4xw\n"
|
2018-08-05 12:40:32 +01:00
|
|
|
" ___________________________________________\n\n";
|
2018-05-01 06:15:48 +01:00
|
|
|
static const char octopus[] =
|
2018-08-05 12:40:32 +01:00
|
|
|
" %k___\n"
|
|
|
|
" .-' `'.\n"
|
|
|
|
" / \\\n"
|
|
|
|
" | ;\n"
|
|
|
|
" | | ___.--,\n"
|
|
|
|
" _.._ |0) = (0) | _.---'`__.-( (_.\n"
|
|
|
|
" __.--'`_.. '.__.\\ '--. \\_.-' ,.--'` `\"\"`\n"
|
|
|
|
" ( ,.--'` ',__ /./; ;, '.__.'` __\n"
|
|
|
|
" _`) ) .---.__.' / | |\\ \\__..--\"\" \"\"\"--.,_\n"
|
|
|
|
" `---' .'.''-._.-'`_./ /\\ '. \\ _.--''````'''--._`-.__.'\n"
|
|
|
|
" | | .' _.-' | | \\ \\ '. `----`\n"
|
|
|
|
" \\ \\/ .' \\ \\ '. '-._)\n"
|
|
|
|
" \\/ / \\ \\ `=.__`'-.\n"
|
|
|
|
" / /\\ `) ) / / `\"\".`\\\n"
|
|
|
|
" , _.-'.'\\ \\ / / ( ( / /\n"
|
|
|
|
" `--'` ) ) .-'.' '.'. | (\n"
|
|
|
|
" (/` ( (` ) ) '-; %k[switchbrew]%k\n"
|
|
|
|
" ` '-; (-'%k";
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2019-04-14 00:30:14 +01:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2022-07-01 02:37:57 +01:00
|
|
|
gfx_printf(credits, TXT_CLR_CYAN_L, TXT_CLR_DEFAULT);
|
2018-06-27 22:21:05 +01:00
|
|
|
gfx_con.fntsz = 8;
|
2022-07-01 02:37:57 +01:00
|
|
|
gfx_printf(octopus, TXT_CLR_CYAN_L, TXT_CLR_TURQUOISE, TXT_CLR_CYAN_L, TXT_CLR_DEFAULT);
|
2018-05-01 06:15:48 +01:00
|
|
|
|
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
ment_t ment_cinfo[] = {
|
|
|
|
MDEF_BACK(),
|
2018-05-24 22:33:11 +01:00
|
|
|
MDEF_CHGLINE(),
|
2022-07-01 02:37:57 +01:00
|
|
|
MDEF_CAPTION("---- SoC Info ----", TXT_CLR_CYAN_L),
|
2020-04-30 01:25:22 +01:00
|
|
|
MDEF_HANDLER("Fuses", print_fuseinfo),
|
2018-05-24 22:33:11 +01:00
|
|
|
MDEF_CHGLINE(),
|
2022-07-01 02:37:57 +01:00
|
|
|
MDEF_CAPTION("-- Storage Info --", TXT_CLR_CYAN_L),
|
2022-10-11 05:21:41 +01:00
|
|
|
MDEF_HANDLER("eMMC", print_mmc_info),
|
2020-04-30 01:25:22 +01:00
|
|
|
MDEF_HANDLER("SD Card", print_sdcard_info),
|
2018-06-24 20:38:32 +01:00
|
|
|
MDEF_CHGLINE(),
|
2022-07-01 02:37:57 +01:00
|
|
|
MDEF_CAPTION("------ Misc ------", TXT_CLR_CYAN_L),
|
2020-04-30 01:25:22 +01:00
|
|
|
MDEF_HANDLER("Battery", print_battery_info),
|
2018-05-01 06:15:48 +01:00
|
|
|
MDEF_END()
|
|
|
|
};
|
2019-06-30 01:15:46 +01:00
|
|
|
|
|
|
|
menu_t menu_cinfo = { ment_cinfo, "Console Info", 0, 0 };
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2018-06-27 22:36:18 +01:00
|
|
|
ment_t ment_tools[] = {
|
|
|
|
MDEF_BACK(),
|
|
|
|
MDEF_CHGLINE(),
|
2022-07-01 02:37:57 +01:00
|
|
|
MDEF_CAPTION("-------- Other -------", TXT_CLR_WARNING),
|
2018-08-21 02:43:00 +01:00
|
|
|
MDEF_HANDLER("AutoRCM", menu_autorcm),
|
2018-05-01 06:15:48 +01:00
|
|
|
MDEF_END()
|
|
|
|
};
|
2018-05-24 00:37:16 +01:00
|
|
|
|
2019-06-30 01:15:46 +01:00
|
|
|
menu_t menu_tools = { ment_tools, "Tools", 0, 0 };
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2020-12-15 17:37:52 +00:00
|
|
|
power_state_t STATE_POWER_OFF = POWER_OFF_RESET;
|
2020-12-15 17:33:46 +00:00
|
|
|
power_state_t STATE_REBOOT_RCM = REBOOT_RCM;
|
|
|
|
power_state_t STATE_REBOOT_BYPASS_FUSES = REBOOT_BYPASS_FUSES;
|
|
|
|
|
2018-05-01 06:15:48 +01:00
|
|
|
ment_t ment_top[] = {
|
2022-12-19 03:04:50 +00:00
|
|
|
MDEF_HANDLER("Launch", _launch_config),
|
2022-07-01 02:37:57 +01:00
|
|
|
MDEF_CAPTION("---------------", TXT_CLR_GREY_DM),
|
2020-12-15 17:33:46 +00:00
|
|
|
MDEF_MENU("Tools", &menu_tools),
|
2018-05-01 06:15:48 +01:00
|
|
|
MDEF_MENU("Console info", &menu_cinfo),
|
2022-07-01 02:37:57 +01:00
|
|
|
MDEF_CAPTION("---------------", TXT_CLR_GREY_DM),
|
2022-12-19 03:04:50 +00:00
|
|
|
MDEF_HANDLER("Reload", _ipl_reload),
|
2021-01-14 21:04:21 +00:00
|
|
|
MDEF_HANDLER_EX("Reboot (OFW)", &STATE_REBOOT_BYPASS_FUSES, power_set_state_ex),
|
|
|
|
MDEF_HANDLER_EX("Reboot (RCM)", &STATE_REBOOT_RCM, power_set_state_ex),
|
|
|
|
MDEF_HANDLER_EX("Power off", &STATE_POWER_OFF, power_set_state_ex),
|
2022-07-01 02:37:57 +01:00
|
|
|
MDEF_CAPTION("---------------", TXT_CLR_GREY_DM),
|
2019-12-11 09:22:11 +00:00
|
|
|
MDEF_HANDLER("About", _about),
|
2018-05-01 06:15:48 +01:00
|
|
|
MDEF_END()
|
|
|
|
};
|
2019-06-30 01:15:46 +01:00
|
|
|
|
2023-02-22 23:25:19 +00:00
|
|
|
menu_t menu_top = { ment_top, "hekate v6.0.2", 0, 0 };
|
2018-05-01 06:15:48 +01:00
|
|
|
|
|
|
|
extern void pivot_stack(u32 stack_top);
|
|
|
|
|
|
|
|
void ipl_main()
|
|
|
|
{
|
2019-02-11 22:46:06 +00:00
|
|
|
// Do initial HW configuration. This is compatible with consecutive reruns without a reset.
|
2020-07-17 16:08:27 +01:00
|
|
|
hw_init();
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2020-03-03 02:11:13 +00:00
|
|
|
// Pivot the stack so we have enough space.
|
2019-03-07 22:19:04 +00:00
|
|
|
pivot_stack(IPL_STACK_TOP);
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2020-03-03 02:11:13 +00: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);
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2018-12-07 20:00:19 +00:00
|
|
|
#ifdef DEBUG_UART_PORT
|
2020-03-21 20:28:50 +00:00
|
|
|
uart_send(DEBUG_UART_PORT, (u8 *)"hekate: Hello!\r\n", 16);
|
2022-05-08 03:46:23 +01:00
|
|
|
uart_wait_xfer(DEBUG_UART_PORT, UART_TX_IDLE);
|
2018-12-07 20:00:19 +00:00
|
|
|
#endif
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2020-04-06 03:54:45 +01:00
|
|
|
// Check if battery is enough.
|
|
|
|
_check_low_battery();
|
|
|
|
|
2018-09-18 21:38:54 +01:00
|
|
|
// Set bootloader's default configuration.
|
|
|
|
set_default_configuration();
|
|
|
|
|
2022-12-19 03:31:35 +00:00
|
|
|
// Prep RTC regs for read. Needed for T210B01 R2P.
|
|
|
|
max77620_rtc_prep_read();
|
|
|
|
|
2022-01-20 11:57:25 +00:00
|
|
|
// Initialize display.
|
|
|
|
display_init();
|
|
|
|
|
2020-08-28 07:37:48 +01:00
|
|
|
// Mount SD Card.
|
|
|
|
h_cfg.errors |= !sd_mount() ? ERR_SD_BOOT_EN : 0;
|
2019-06-30 01:49:33 +01:00
|
|
|
|
2022-06-29 10:19:19 +01:00
|
|
|
// Check if watchdog was fired previously.
|
|
|
|
if (watchdog_fired())
|
|
|
|
goto skip_lp0_minerva_config;
|
|
|
|
|
|
|
|
// Enable watchdog protection to avoid SD corruption based hanging in LP0/Minerva config.
|
|
|
|
watchdog_start(5000000 / 2, TIMER_FIQENABL_EN); // 5 seconds.
|
|
|
|
|
2018-08-21 02:14:31 +01:00
|
|
|
// Save sdram lp0 config.
|
2021-05-11 07:32:38 +01:00
|
|
|
void *sdram_params = h_cfg.t210b01 ? sdram_get_params_t210b01() : sdram_get_params_patched();
|
2020-06-26 17:00:30 +01:00
|
|
|
if (!ianos_loader("bootloader/sys/libsys_lp0.bso", DRAM_LIB, sdram_params))
|
2018-12-16 17:04:46 +00:00
|
|
|
h_cfg.errors |= ERR_LIBSYS_LP0;
|
2019-09-12 21:08:38 +01:00
|
|
|
|
|
|
|
// Train DRAM and switch to max frequency.
|
2020-07-04 19:02:45 +01:00
|
|
|
if (minerva_init()) //!TODO: Add Tegra210B01 support to minerva.
|
2020-07-19 18:32:22 +01:00
|
|
|
h_cfg.errors |= ERR_LIBSYS_MTC;
|
2018-08-21 02:14:31 +01:00
|
|
|
|
2022-06-29 10:19:19 +01:00
|
|
|
// Disable watchdog protection.
|
|
|
|
watchdog_end();
|
|
|
|
|
|
|
|
skip_lp0_minerva_config:
|
2022-01-20 11:57:25 +00:00
|
|
|
// Initialize display window, backlight and gfx console.
|
2020-06-13 16:16:29 +01:00
|
|
|
u32 *fb = display_init_framebuffer_pitch();
|
2019-04-14 00:30:14 +01:00
|
|
|
gfx_init_ctxt(fb, 720, 1280, 720);
|
2019-04-21 15:38:29 +01:00
|
|
|
gfx_con_init();
|
2018-05-01 06:15:48 +01:00
|
|
|
|
2018-09-18 22:01:42 +01:00
|
|
|
display_backlight_pwm_init();
|
|
|
|
//display_backlight_brightness(h_cfg.backlight, 1000);
|
2018-08-21 02:26:14 +01:00
|
|
|
|
2019-06-30 01:55:19 +01:00
|
|
|
// Overclock BPMP.
|
2021-05-11 07:32:38 +01:00
|
|
|
bpmp_clk_rate_set(h_cfg.t210b01 ? BPMP_CLK_DEFAULT_BOOST : BPMP_CLK_LOWER_BOOST);
|
2019-06-30 01:55:19 +01:00
|
|
|
|
2022-12-19 03:31:35 +00:00
|
|
|
// Get R2P config from RTC.
|
|
|
|
if (h_cfg.t210b01)
|
|
|
|
_r2p_get_config_t210b01();
|
|
|
|
|
2021-10-15 14:34:15 +01:00
|
|
|
// Show exceptions, HOS errors, library errors and L4T kernel panics.
|
2019-12-11 09:22:11 +00:00
|
|
|
_show_errors();
|
|
|
|
|
2018-07-01 18:45:52 +01:00
|
|
|
// Load saved configuration and auto boot if enabled.
|
2022-01-20 11:56:36 +00:00
|
|
|
if (!(h_cfg.errors & ERR_SD_BOOT_EN))
|
2022-12-19 03:04:50 +00:00
|
|
|
_auto_launch();
|
2018-06-06 11:29:38 +01:00
|
|
|
|
2020-08-15 11:23:11 +01:00
|
|
|
// Failed to launch Nyx, unmount SD Card.
|
|
|
|
sd_end();
|
|
|
|
|
2022-01-20 11:57:25 +00:00
|
|
|
// Set ram to a freq that doesn't need periodic training.
|
2019-06-30 01:49:33 +01:00
|
|
|
minerva_change_freq(FREQ_800);
|
|
|
|
|
2018-09-18 21:38:54 +01:00
|
|
|
while (true)
|
2019-04-14 00:30:14 +01:00
|
|
|
tui_do_menu(&menu_top);
|
2019-10-18 16:02:06 +01:00
|
|
|
|
2019-08-27 23:33:38 +01:00
|
|
|
// Halt BPMP if we managed to get out of execution.
|
2018-09-18 21:38:54 +01:00
|
|
|
while (true)
|
2019-08-27 23:33:38 +01:00
|
|
|
bpmp_halt();
|
2018-05-01 06:15:48 +01:00
|
|
|
}
|