2018-05-01 05:15:48 +00:00
|
|
|
/*
|
2018-08-05 11:40:32 +00:00
|
|
|
* Copyright (c) 2018 naehrwert
|
|
|
|
*
|
2020-03-14 07:24:24 +00:00
|
|
|
* Copyright (c) 2018-2020 CTCaer
|
2018-08-05 11:40:32 +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/>.
|
|
|
|
*/
|
2018-05-01 05:15:48 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
2018-05-01 11:17:13 +00:00
|
|
|
#include <stdlib.h>
|
2018-05-01 05:15:48 +00:00
|
|
|
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <memory_map.h>
|
2019-12-08 00:23:03 +00:00
|
|
|
|
2020-06-14 13:45:45 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <gfx/di.h>
|
|
|
|
#include <gfx_utils.h>
|
2018-08-13 08:58:24 +00:00
|
|
|
#include "gfx/logos.h"
|
|
|
|
#include "gfx/tui.h"
|
|
|
|
#include "hos/hos.h"
|
2019-04-14 01:24:37 +00:00
|
|
|
#include "hos/secmon_exo.h"
|
2019-02-24 01:03:17 +00:00
|
|
|
#include "hos/sept.h"
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <ianos/ianos.h>
|
|
|
|
#include <libs/compr/blz.h>
|
|
|
|
#include <libs/fatfs/ff.h>
|
|
|
|
#include <mem/heap.h>
|
|
|
|
#include <mem/minerva.h>
|
|
|
|
#include <mem/sdram.h>
|
|
|
|
#include <power/bq24193.h>
|
|
|
|
#include <power/max17050.h>
|
|
|
|
#include <power/max77620.h>
|
|
|
|
#include <power/max7762x.h>
|
|
|
|
#include <rtc/max77620-rtc.h>
|
|
|
|
#include <soc/bpmp.h>
|
|
|
|
#include <soc/fuse.h>
|
|
|
|
#include <soc/hw_init.h>
|
|
|
|
#include <soc/i2c.h>
|
|
|
|
#include <soc/t210.h>
|
|
|
|
#include <soc/uart.h>
|
2019-06-30 00:24:58 +00:00
|
|
|
#include "storage/emummc.h"
|
2019-04-16 17:09:04 +00:00
|
|
|
#include "storage/nx_emmc.h"
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <storage/nx_sd.h>
|
|
|
|
#include <storage/sdmmc.h>
|
|
|
|
#include <utils/btn.h>
|
|
|
|
#include <utils/dirlist.h>
|
|
|
|
#include <utils/list.h>
|
|
|
|
#include <utils/util.h>
|
2018-08-07 14:53:58 +00:00
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
#include "frontend/fe_emmc_tools.h"
|
|
|
|
#include "frontend/fe_tools.h"
|
|
|
|
#include "frontend/fe_info.h"
|
2018-08-21 01:41:16 +00:00
|
|
|
|
2018-07-01 17:45:25 +00: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 17:45:25 +00:00
|
|
|
|
2019-06-30 00:55:19 +00:00
|
|
|
volatile nyx_storage_t *nyx_str = (nyx_storage_t *)NYX_STORAGE_ADDR;
|
|
|
|
|
2018-07-22 12:24:09 +00:00
|
|
|
void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage)
|
|
|
|
{
|
|
|
|
sdmmc_storage_t storage2;
|
|
|
|
sdmmc_t sdmmc;
|
|
|
|
char emmcSN[9];
|
2018-08-13 09:12:53 +00:00
|
|
|
bool init_done = false;
|
2018-07-22 12:24:09 +00:00
|
|
|
|
2018-08-21 01:21:09 +00:00
|
|
|
memcpy(path, "backup", 7);
|
2018-07-22 12:24:09 +00:00
|
|
|
f_mkdir(path);
|
|
|
|
|
|
|
|
if (!storage)
|
|
|
|
{
|
2020-04-29 15:53:29 +00:00
|
|
|
if (!sdmmc_storage_init_mmc(&storage2, &sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
|
2018-07-22 12:24:09 +00:00
|
|
|
memcpy(emmcSN, "00000000", 9);
|
|
|
|
else
|
|
|
|
{
|
2018-08-13 09:12:53 +00:00
|
|
|
init_done = true;
|
2018-07-22 12:24:09 +00:00
|
|
|
itoa(storage2.cid.serial, emmcSN, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
itoa(storage->cid.serial, emmcSN, 16);
|
|
|
|
|
2018-08-05 11:40:32 +00:00
|
|
|
u32 sub_dir_len = strlen(sub_dir); // Can be a null-terminator.
|
|
|
|
u32 filename_len = strlen(filename); // Can be a null-terminator.
|
2018-07-22 12:24:09 +00:00
|
|
|
|
2018-08-05 11:40:32 +00:00
|
|
|
memcpy(path + strlen(path), "/", 2);
|
2018-07-22 12:24:09 +00:00
|
|
|
memcpy(path + strlen(path), emmcSN, 9);
|
|
|
|
f_mkdir(path);
|
|
|
|
memcpy(path + strlen(path), sub_dir, sub_dir_len + 1);
|
|
|
|
if (sub_dir_len)
|
|
|
|
f_mkdir(path);
|
|
|
|
memcpy(path + strlen(path), "/", 2);
|
|
|
|
memcpy(path + strlen(path), filename, filename_len + 1);
|
|
|
|
|
|
|
|
if (init_done)
|
|
|
|
sdmmc_storage_end(&storage2);
|
|
|
|
}
|
|
|
|
|
2018-09-18 21:34:05 +00:00
|
|
|
void check_power_off_from_hos()
|
|
|
|
{
|
|
|
|
// Power off on AutoRCM wakeup from HOS shutdown. For modchips/dongles.
|
|
|
|
u8 hosWakeup = i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_IRQTOP);
|
|
|
|
if (hosWakeup & MAX77620_IRQ_TOP_RTC_MASK)
|
|
|
|
{
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_end();
|
2019-02-11 22:45:27 +00:00
|
|
|
|
|
|
|
// Stop the alarm, in case we injected too fast.
|
|
|
|
max77620_rtc_stop_alarm();
|
|
|
|
|
2018-09-29 23:09:18 +00:00
|
|
|
if (h_cfg.autohosoff == 1)
|
|
|
|
{
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_clear_grey(0x1B);
|
2018-11-27 09:45:43 +00:00
|
|
|
u8 *BOOTLOGO = (void *)malloc(0x4000);
|
|
|
|
blz_uncompress_srcdest(BOOTLOGO_BLZ, SZ_BOOTLOGO_BLZ, BOOTLOGO, SZ_BOOTLOGO);
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_set_rect_grey(BOOTLOGO, X_BOOTLOGO, Y_BOOTLOGO, 326, 544);
|
2018-05-24 21:37:30 +00:00
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
display_backlight_brightness(10, 5000);
|
|
|
|
display_backlight_brightness(100, 25000);
|
2019-03-07 22:19:04 +00:00
|
|
|
msleep(600);
|
2018-11-27 09:45:43 +00:00
|
|
|
display_backlight_brightness(0, 20000);
|
|
|
|
}
|
|
|
|
power_off();
|
|
|
|
}
|
2018-05-13 01:13:17 +00:00
|
|
|
}
|
|
|
|
|
2018-08-23 02:05:31 +00: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
|
2019-03-07 22:23:19 +00:00
|
|
|
#define CBFS_DRAM_EN_ADDR 0x4003e000
|
|
|
|
#define CBFS_DRAM_MAGIC 0x4452414D // "DRAM"
|
2018-08-23 02:05:31 +00:00
|
|
|
|
2020-03-21 20:18:40 +00:00
|
|
|
static void *coreboot_addr;
|
|
|
|
|
2019-02-24 01:03:17 +00:00
|
|
|
void reloc_patcher(u32 payload_dst, u32 payload_src, u32 payload_size)
|
2018-08-23 02:05:31 +00:00
|
|
|
{
|
2019-02-24 01:03:17 +00:00
|
|
|
memcpy((u8 *)payload_src, (u8 *)IPL_LOAD_ADDR, PATCHED_RELOC_SZ);
|
2018-08-23 02:05:31 +00:00
|
|
|
|
2019-03-07 22:23:19 +00:00
|
|
|
volatile reloc_meta_t *relocator = (reloc_meta_t *)(payload_src + RELOC_META_OFF);
|
|
|
|
|
|
|
|
relocator->start = payload_dst - ALIGN(PATCHED_RELOC_SZ, 0x10);
|
|
|
|
relocator->stack = PATCHED_RELOC_STACK;
|
|
|
|
relocator->end = payload_dst + payload_size;
|
|
|
|
relocator->ep = payload_dst;
|
2018-08-23 02:05:31 +00:00
|
|
|
|
|
|
|
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-03-07 22:23:19 +00:00
|
|
|
*(vu32 *)CBFS_DRAM_EN_ADDR = CBFS_DRAM_MAGIC;
|
2018-08-23 02:05:31 +00: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 15:02:06 +00: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
|
|
|
|
2020-01-17 07:35:16 +00:00
|
|
|
bool magic_valid = update_ft->magic == ipl_ver.magic;
|
|
|
|
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;
|
|
|
|
volatile reloc_meta_t *reloc = (reloc_meta_t *)(IPL_LOAD_ADDR + RELOC_META_OFF);
|
|
|
|
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 06:30:53 +00: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 15:02:06 +00: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
|
|
|
}
|
|
|
|
|
2018-08-23 02:05:31 +00:00
|
|
|
int launch_payload(char *path, bool update)
|
|
|
|
{
|
2019-03-07 21:53:58 +00:00
|
|
|
if (!update)
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-08-23 02:05:31 +00:00
|
|
|
|
|
|
|
if (sd_mount())
|
|
|
|
{
|
|
|
|
FIL fp;
|
|
|
|
if (f_open(&fp, path, FA_READ))
|
|
|
|
{
|
2020-06-13 23:09:48 +00:00
|
|
|
gfx_con.mute = 0;
|
2018-08-23 02:05:31 +00:00
|
|
|
EPRINTFARGS("Payload file is missing!\n(%s)", path);
|
|
|
|
|
2019-12-07 00:40:56 +00:00
|
|
|
goto out;
|
2018-08-23 02:05:31 +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-03-21 20:18:40 +00:00
|
|
|
{
|
|
|
|
coreboot_addr = (void *)(COREBOOT_END_ADDR - size);
|
|
|
|
buf = coreboot_addr;
|
|
|
|
}
|
2018-08-23 02:05:31 +00:00
|
|
|
|
|
|
|
if (f_read(&fp, buf, size, NULL))
|
|
|
|
{
|
|
|
|
f_close(&fp);
|
2020-04-27 06:30:53 +00:00
|
|
|
|
2019-12-07 00:40:56 +00:00
|
|
|
goto out;
|
2018-08-23 02:05:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
f_close(&fp);
|
2019-02-23 22:59:33 +00:00
|
|
|
|
2019-12-11 22:07:18 +00:00
|
|
|
if (update && is_ipl_updated(buf, path, false))
|
2019-12-07 00:40:56 +00:00
|
|
|
goto out;
|
2019-02-24 01:04:28 +00:00
|
|
|
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_end();
|
2018-08-23 02:05:31 +00:00
|
|
|
|
|
|
|
if (size < 0x30000)
|
|
|
|
{
|
2019-03-07 21:53:58 +00:00
|
|
|
if (update)
|
|
|
|
memcpy((u8 *)(RCM_PAYLOAD_ADDR + PATCHED_RELOC_SZ), &b_cfg, sizeof(boot_cfg_t)); // Transfer boot cfg.
|
2019-02-24 00:43:13 +00:00
|
|
|
else
|
2019-03-07 21:53:58 +00:00
|
|
|
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, ALIGN(size, 0x10));
|
2019-02-24 01:03:17 +00:00
|
|
|
|
2018-09-18 21:46:32 +00:00
|
|
|
reconfig_hw_workaround(false, byte_swap_32(*(u32 *)(buf + size - sizeof(u32))));
|
2018-08-23 02:05:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-07 22:23:19 +00:00
|
|
|
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, 0x7000);
|
2018-09-18 21:46:32 +00:00
|
|
|
reconfig_hw_workaround(true, 0);
|
2018-08-23 02:05:31 +00:00
|
|
|
}
|
|
|
|
|
2019-08-27 23:39:43 +00:00
|
|
|
// Some cards (Sandisk U1), do not like a fast power cycle. Wait min 100ms.
|
|
|
|
sdmmc_storage_init_wait_sd();
|
2019-06-30 00:15:46 +00:00
|
|
|
|
2019-09-09 13:56:37 +00:00
|
|
|
void (*ext_payload_ptr)() = (void *)EXT_PAYLOAD_ADDR;
|
|
|
|
void (*update_ptr)() = (void *)RCM_PAYLOAD_ADDR;
|
|
|
|
|
2018-08-23 02:05:31 +00:00
|
|
|
// Launch our payload.
|
2018-12-16 17:04:46 +00:00
|
|
|
if (!update)
|
|
|
|
(*ext_payload_ptr)();
|
|
|
|
else
|
2019-03-07 22:08:39 +00:00
|
|
|
{
|
|
|
|
EMC(EMC_SCRATCH0) |= EMC_HEKA_UPD;
|
2018-12-16 17:04:46 +00:00
|
|
|
(*update_ptr)();
|
2019-03-07 22:08:39 +00:00
|
|
|
}
|
2018-08-23 02:05:31 +00:00
|
|
|
}
|
|
|
|
|
2019-12-07 00:40:56 +00:00
|
|
|
out:
|
|
|
|
if (!update)
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_end();
|
2019-12-07 00:40:56 +00:00
|
|
|
|
2018-08-23 02:05:31 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-08-21 01:41:16 +00:00
|
|
|
void auto_launch_update()
|
|
|
|
{
|
2019-03-07 21:53:58 +00:00
|
|
|
if (EMC(EMC_SCRATCH0) & EMC_HEKA_UPD)
|
|
|
|
EMC(EMC_SCRATCH0) &= ~EMC_HEKA_UPD;
|
|
|
|
else if (sd_mount())
|
2018-08-21 01:41:16 +00:00
|
|
|
{
|
2019-03-07 21:53:58 +00:00
|
|
|
if (!f_stat("bootloader/update.bin", NULL))
|
|
|
|
launch_payload("bootloader/update.bin", true);
|
2018-08-21 01:41:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-30 00:15:46 +00:00
|
|
|
void launch_tools()
|
2018-08-21 01:45:19 +00: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 01:45:19 +00:00
|
|
|
|
|
|
|
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3));
|
|
|
|
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-08-21 01:45:19 +00:00
|
|
|
|
|
|
|
if (sd_mount())
|
|
|
|
{
|
|
|
|
dir = (char *)malloc(256);
|
|
|
|
|
2019-06-30 00:15:46 +00:00
|
|
|
memcpy(dir, "bootloader/payloads", 20);
|
2018-08-21 01:45:19 +00:00
|
|
|
|
2020-06-13 15:16:29 +00:00
|
|
|
filelist = dirlist(dir, NULL, false, false);
|
2018-08-21 01:45:19 +00:00
|
|
|
|
|
|
|
u32 i = 0;
|
|
|
|
|
|
|
|
if (filelist)
|
|
|
|
{
|
|
|
|
// Build configuration menu.
|
|
|
|
ments[0].type = MENT_BACK;
|
|
|
|
ments[0].caption = "Back";
|
|
|
|
ments[1].type = MENT_CHGLINE;
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
if (i > max_entries || !filelist[i * 256])
|
|
|
|
break;
|
|
|
|
ments[i + 2].type = INI_CHOICE;
|
|
|
|
ments[i + 2].caption = &filelist[i * 256];
|
|
|
|
ments[i + 2].data = &filelist[i * 256];
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
2019-12-04 19:31:39 +00:00
|
|
|
|
2018-08-21 01:45:19 +00:00
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
memset(&ments[i + 2], 0, sizeof(ment_t));
|
2019-06-30 00:15:46 +00:00
|
|
|
menu_t menu = { ments, "Choose a file to launch", 0, 0 };
|
2019-10-18 15:02:06 +00:00
|
|
|
|
2019-04-13 23:30:14 +00:00
|
|
|
file_sec = (char *)tui_do_menu(&menu);
|
2018-08-21 01:45:19 +00:00
|
|
|
|
|
|
|
if (!file_sec)
|
|
|
|
{
|
|
|
|
free(ments);
|
2018-11-20 19:32:54 +00:00
|
|
|
free(dir);
|
2018-08-21 01:45:19 +00:00
|
|
|
free(filelist);
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_end();
|
2019-12-04 19:31:39 +00:00
|
|
|
|
2018-08-21 01:45:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2019-03-07 22:08:39 +00:00
|
|
|
EPRINTF("No payloads or modules found.");
|
2018-08-21 01:45:19 +00:00
|
|
|
|
|
|
|
free(ments);
|
|
|
|
free(filelist);
|
|
|
|
}
|
|
|
|
else
|
2018-08-23 01:37:02 +00:00
|
|
|
{
|
|
|
|
free(ments);
|
2018-08-21 01:45:19 +00:00
|
|
|
goto out;
|
2018-08-23 01:37:02 +00:00
|
|
|
}
|
2018-08-21 01:45:19 +00:00
|
|
|
|
|
|
|
if (file_sec)
|
|
|
|
{
|
|
|
|
memcpy(dir + strlen(dir), "/", 2);
|
|
|
|
memcpy(dir + strlen(dir), file_sec, strlen(file_sec) + 1);
|
|
|
|
|
2019-12-04 19:31:39 +00:00
|
|
|
launch_payload(dir, false);
|
|
|
|
EPRINTF("Failed to launch payload.");
|
2018-08-21 01:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_end();
|
2018-11-20 19:32:54 +00:00
|
|
|
free(dir);
|
2018-08-21 01:45:19 +00:00
|
|
|
|
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
2018-08-21 01:37:40 +00:00
|
|
|
void ini_list_launcher()
|
2018-05-01 05:15:48 +00:00
|
|
|
{
|
2018-07-01 17:29:30 +00:00
|
|
|
u8 max_entries = 61;
|
2018-08-21 01:37:40 +00:00
|
|
|
char *payload_path = NULL;
|
2020-04-27 06:30:53 +00:00
|
|
|
char *emummc_path = NULL;
|
2018-06-12 23:34:32 +00:00
|
|
|
|
2018-05-01 05:15:48 +00:00
|
|
|
ini_sec_t *cfg_sec = NULL;
|
2018-08-21 01:37:40 +00:00
|
|
|
LIST_INIT(ini_list_sections);
|
2018-05-01 05:15:48 +00:00
|
|
|
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-05-01 05:15:48 +00:00
|
|
|
|
|
|
|
if (sd_mount())
|
|
|
|
{
|
2018-08-21 01:37:40 +00:00
|
|
|
if (ini_parse(&ini_list_sections, "bootloader/ini", true))
|
2018-05-01 05:15:48 +00:00
|
|
|
{
|
2018-06-12 23:34:32 +00:00
|
|
|
// Build configuration menu.
|
2018-07-01 17:29:30 +00:00
|
|
|
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3));
|
2018-05-01 05:15:48 +00:00
|
|
|
ments[0].type = MENT_BACK;
|
|
|
|
ments[0].caption = "Back";
|
2018-07-01 17:29:30 +00:00
|
|
|
ments[1].type = MENT_CHGLINE;
|
|
|
|
|
|
|
|
u32 i = 2;
|
2018-08-21 01:37:40 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_list_sections, link)
|
2018-05-01 05:15:48 +00:00
|
|
|
{
|
2018-07-01 17:29:30 +00:00
|
|
|
if (!strcmp(ini_sec->name, "config") ||
|
|
|
|
ini_sec->type == INI_COMMENT || ini_sec->type == INI_NEWLINE)
|
2018-05-01 05:15:48 +00:00
|
|
|
continue;
|
2018-07-01 17:29:30 +00:00
|
|
|
ments[i].type = ini_sec->type;
|
2018-05-01 05:15:48 +00:00
|
|
|
ments[i].caption = ini_sec->name;
|
|
|
|
ments[i].data = ini_sec;
|
2018-07-01 17:29:30 +00:00
|
|
|
if (ini_sec->type == MENT_CAPTION)
|
|
|
|
ments[i].color = ini_sec->color;
|
2018-05-01 05:15:48 +00:00
|
|
|
i++;
|
2018-06-12 23:34:32 +00:00
|
|
|
|
2018-08-21 01:37:40 +00:00
|
|
|
if ((i - 1) > max_entries)
|
2018-06-12 23:34:32 +00:00
|
|
|
break;
|
2018-05-01 05:15:48 +00:00
|
|
|
}
|
2018-07-01 17:29:30 +00:00
|
|
|
if (i > 2)
|
2018-08-21 01:37:40 +00:00
|
|
|
{
|
|
|
|
memset(&ments[i], 0, sizeof(ment_t));
|
|
|
|
menu_t menu = {
|
|
|
|
ments, "Launch ini configurations", 0, 0
|
|
|
|
};
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
cfg_sec = (ini_sec_t *)tui_do_menu(&menu);
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
if (cfg_sec)
|
2019-02-24 00:43:13 +00:00
|
|
|
{
|
|
|
|
u32 non_cfg = 1;
|
|
|
|
for (int j = 2; j < i; j++)
|
|
|
|
{
|
|
|
|
if (ments[j].type != INI_CHOICE)
|
|
|
|
non_cfg++;
|
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
if (ments[j].data == cfg_sec)
|
2019-02-24 00:43:13 +00:00
|
|
|
{
|
2019-03-07 21:41:07 +00:00
|
|
|
b_cfg.boot_cfg = BOOT_CFG_FROM_LAUNCH;
|
|
|
|
b_cfg.autoboot = j - non_cfg;
|
|
|
|
b_cfg.autoboot_list = 1;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
payload_path = ini_check_payload_section(cfg_sec);
|
2019-02-24 01:03:17 +00:00
|
|
|
|
2020-04-27 06:30:53 +00:00
|
|
|
if (cfg_sec)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 16:23:31 +00:00
|
|
|
if (emummc_path && !emummc_set_path(emummc_path))
|
|
|
|
{
|
|
|
|
EPRINTF("emupath is wrong!");
|
|
|
|
goto wrong_emupath;
|
|
|
|
}
|
2020-04-27 06:30:53 +00:00
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
if (cfg_sec && !payload_path)
|
2019-12-15 22:53:22 +00:00
|
|
|
check_sept(cfg_sec);
|
2019-02-24 01:03:17 +00:00
|
|
|
|
2018-08-21 01:37:40 +00:00
|
|
|
if (!cfg_sec)
|
|
|
|
{
|
|
|
|
free(ments);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2019-03-07 22:08:39 +00:00
|
|
|
EPRINTF("No extra configs found.");
|
2018-08-21 01:37:40 +00:00
|
|
|
free(ments);
|
|
|
|
}
|
|
|
|
else
|
2019-02-24 00:43:13 +00:00
|
|
|
EPRINTF("Could not find any ini\nin bootloader/ini!");
|
2018-08-21 01:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cfg_sec)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (payload_path)
|
|
|
|
{
|
2019-12-04 19:31:39 +00:00
|
|
|
launch_payload(payload_path, false);
|
|
|
|
EPRINTF("Failed to launch payload.");
|
|
|
|
free(payload_path);
|
2018-08-21 01:37:40 +00:00
|
|
|
}
|
|
|
|
else if (!hos_launch(cfg_sec))
|
|
|
|
{
|
2020-05-05 16:23:31 +00:00
|
|
|
wrong_emupath:
|
|
|
|
EPRINTF("Failed to launch HOS.");
|
2020-04-27 06:30:53 +00:00
|
|
|
if (emummc_path)
|
|
|
|
{
|
|
|
|
sd_mount();
|
|
|
|
emummc_load_cfg();
|
|
|
|
}
|
2018-08-21 01:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
void launch_firmware()
|
|
|
|
{
|
|
|
|
u8 max_entries = 61;
|
2018-08-21 01:45:19 +00:00
|
|
|
char *payload_path = NULL;
|
2020-04-27 06:30:53 +00:00
|
|
|
char *emummc_path = NULL;
|
2018-08-21 01:37:40 +00:00
|
|
|
|
|
|
|
ini_sec_t *cfg_sec = NULL;
|
|
|
|
LIST_INIT(ini_sections);
|
|
|
|
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-08-21 01:37:40 +00:00
|
|
|
|
|
|
|
if (sd_mount())
|
|
|
|
{
|
|
|
|
if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
|
|
|
|
{
|
|
|
|
// Build configuration menu.
|
2018-08-21 01:45:19 +00:00
|
|
|
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 6));
|
2018-08-21 01:37:40 +00:00
|
|
|
ments[0].type = MENT_BACK;
|
|
|
|
ments[0].caption = "Back";
|
|
|
|
ments[1].type = MENT_CHGLINE;
|
|
|
|
|
|
|
|
ments[2].type = MENT_HANDLER;
|
2018-08-21 01:45:19 +00:00
|
|
|
ments[2].caption = "Payloads...";
|
2019-06-30 00:15:46 +00:00
|
|
|
ments[2].handler = launch_tools;
|
2018-08-21 01:45:19 +00:00
|
|
|
ments[3].type = MENT_HANDLER;
|
|
|
|
ments[3].caption = "More configs...";
|
|
|
|
ments[3].handler = ini_list_launcher;
|
2018-08-21 01:37:40 +00:00
|
|
|
|
2018-08-21 01:45:19 +00:00
|
|
|
ments[4].type = MENT_CHGLINE;
|
2018-08-21 01:37:40 +00:00
|
|
|
|
2018-08-21 01:45:19 +00:00
|
|
|
u32 i = 5;
|
2018-08-21 01:37:40 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link)
|
|
|
|
{
|
|
|
|
if (!strcmp(ini_sec->name, "config") ||
|
|
|
|
ini_sec->type == INI_COMMENT || ini_sec->type == INI_NEWLINE)
|
|
|
|
continue;
|
|
|
|
ments[i].type = ini_sec->type;
|
|
|
|
ments[i].caption = ini_sec->name;
|
|
|
|
ments[i].data = ini_sec;
|
|
|
|
if (ini_sec->type == MENT_CAPTION)
|
|
|
|
ments[i].color = ini_sec->color;
|
|
|
|
i++;
|
|
|
|
|
2018-08-21 01:45:19 +00:00
|
|
|
if ((i - 4) > max_entries)
|
2018-08-21 01:37:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-09-18 20:47:37 +00:00
|
|
|
if (i < 6)
|
2018-05-01 05:15:48 +00:00
|
|
|
{
|
2018-09-18 20:47:37 +00:00
|
|
|
ments[i].type = MENT_CAPTION;
|
2019-03-07 22:08:39 +00:00
|
|
|
ments[i].caption = "No main configs found...";
|
2018-09-18 20:47:37 +00:00
|
|
|
ments[i].color = 0xFFFFDD00;
|
|
|
|
i++;
|
2018-05-01 05:15:48 +00:00
|
|
|
}
|
2018-09-18 20:47:37 +00:00
|
|
|
memset(&ments[i], 0, sizeof(ment_t));
|
|
|
|
menu_t menu = {
|
|
|
|
ments, "Launch configurations", 0, 0
|
|
|
|
};
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
cfg_sec = (ini_sec_t *)tui_do_menu(&menu);
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
if (cfg_sec)
|
2019-02-24 00:43:13 +00:00
|
|
|
{
|
|
|
|
u8 non_cfg = 4;
|
|
|
|
for (int j = 5; j < i; j++)
|
|
|
|
{
|
|
|
|
if (ments[j].type != INI_CHOICE)
|
|
|
|
non_cfg++;
|
2019-07-06 19:08:37 +00:00
|
|
|
if (ments[j].data == cfg_sec)
|
2019-02-24 00:43:13 +00:00
|
|
|
{
|
2019-03-07 21:41:07 +00:00
|
|
|
b_cfg.boot_cfg = BOOT_CFG_FROM_LAUNCH;
|
|
|
|
b_cfg.autoboot = j - non_cfg;
|
|
|
|
b_cfg.autoboot_list = 0;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
payload_path = ini_check_payload_section(cfg_sec);
|
2019-02-24 01:03:17 +00:00
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
if (cfg_sec)
|
2019-06-30 00:24:58 +00:00
|
|
|
{
|
2019-07-06 19:08:37 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg_sec->kvs, link)
|
2019-06-30 00:24:58 +00:00
|
|
|
{
|
|
|
|
if (!strcmp("emummc_force_disable", kv->key))
|
|
|
|
h_cfg.emummc_force_disable = atoi(kv->val);
|
2020-04-27 06:30:53 +00:00
|
|
|
if (!strcmp("emupath", kv->key))
|
|
|
|
emummc_path = kv->val;
|
2019-06-30 00:24:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-05 16:23:31 +00:00
|
|
|
if (emummc_path && !emummc_set_path(emummc_path))
|
|
|
|
{
|
|
|
|
EPRINTF("emupath is wrong!");
|
|
|
|
goto wrong_emupath;
|
|
|
|
}
|
2020-04-27 06:30:53 +00:00
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
if (cfg_sec && !payload_path)
|
2019-12-15 22:53:22 +00:00
|
|
|
check_sept(cfg_sec);
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2018-09-18 20:47:37 +00:00
|
|
|
if (!cfg_sec)
|
|
|
|
{
|
|
|
|
free(ments);
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_end();
|
2018-09-18 20:47:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-01 05:15:48 +00:00
|
|
|
free(ments);
|
|
|
|
}
|
|
|
|
else
|
2019-02-24 00:43:13 +00:00
|
|
|
EPRINTF("Could not open 'bootloader/hekate_ipl.ini'.\nMake sure it exists!");
|
2018-05-01 05:15:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cfg_sec)
|
2018-05-24 21:41:20 +00:00
|
|
|
{
|
2019-06-30 00:15:46 +00:00
|
|
|
gfx_puts("\nUsing default launch configuration...\n");
|
|
|
|
gfx_puts("\nPress POWER to Continue.\nPress VOL to go to the menu.");
|
2018-07-22 12:24:09 +00:00
|
|
|
|
|
|
|
u32 btn = btn_wait();
|
|
|
|
if (!(btn & BTN_POWER))
|
|
|
|
goto out;
|
2018-05-24 21:41:20 +00:00
|
|
|
}
|
2018-08-21 01:45:19 +00:00
|
|
|
|
|
|
|
if (payload_path)
|
2018-06-19 14:10:59 +00:00
|
|
|
{
|
2019-12-04 19:31:39 +00:00
|
|
|
launch_payload(payload_path, false);
|
|
|
|
EPRINTF("Failed to launch payload.");
|
|
|
|
free(payload_path);
|
2018-08-21 01:45:19 +00:00
|
|
|
}
|
|
|
|
else if (!hos_launch(cfg_sec))
|
2020-04-27 06:30:53 +00:00
|
|
|
{
|
2020-05-05 16:23:31 +00:00
|
|
|
wrong_emupath:
|
|
|
|
EPRINTF("Failed to launch HOS.");
|
2020-04-27 06:30:53 +00:00
|
|
|
if (emummc_path)
|
|
|
|
{
|
|
|
|
sd_mount();
|
|
|
|
emummc_load_cfg();
|
|
|
|
}
|
|
|
|
}
|
2018-08-21 01:45:19 +00:00
|
|
|
|
2018-08-21 01:21:09 +00:00
|
|
|
out:
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_end();
|
2018-05-01 05:15:48 +00:00
|
|
|
|
2019-06-30 00:24:58 +00:00
|
|
|
h_cfg.emummc_force_disable = false;
|
|
|
|
|
2018-05-01 05:15:48 +00:00
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
#define NYX_VER_OFF 0x9C
|
|
|
|
|
2019-06-30 00:55:19 +00:00
|
|
|
void nyx_load_run()
|
|
|
|
{
|
|
|
|
sd_mount();
|
|
|
|
|
2019-08-27 22:08:57 +00:00
|
|
|
u8 *nyx = sd_file_read("bootloader/sys/nyx.bin", NULL);
|
2019-06-30 00:55:19 +00:00
|
|
|
if (!nyx)
|
|
|
|
return;
|
|
|
|
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_end();
|
2019-06-30 00:55:19 +00:00
|
|
|
|
2019-12-11 09:22:11 +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-06-30 00:55:19 +00:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
u8 *BOOTLOGO = (void *)malloc(0x4000);
|
|
|
|
blz_uncompress_srcdest(BOOTLOGO_BLZ, SZ_BOOTLOGO_BLZ, BOOTLOGO, SZ_BOOTLOGO);
|
|
|
|
gfx_set_rect_grey(BOOTLOGO, X_BOOTLOGO, Y_BOOTLOGO, 326, 544);
|
|
|
|
free(BOOTLOGO);
|
|
|
|
display_backlight_brightness(h_cfg.backlight, 1000);
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
// Check if Nyx version is old.
|
|
|
|
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");
|
|
|
|
WPRINTF("\nUpdate your bootloader folder!\n\n");
|
|
|
|
WPRINTF("Press any key...");
|
|
|
|
|
|
|
|
msleep(2000);
|
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
nyx_str->info.errors = h_cfg.errors;
|
2019-06-30 00:55:19 +00:00
|
|
|
nyx_str->cfg = 0;
|
2020-04-30 11:44:27 +00:00
|
|
|
if (b_cfg.extra_cfg)
|
2019-06-30 00:55:19 +00:00
|
|
|
{
|
2020-04-30 11:44:27 +00:00
|
|
|
if (b_cfg.extra_cfg & EXTRA_CFG_NYX_DUMP)
|
|
|
|
{
|
|
|
|
b_cfg.extra_cfg &= ~(EXTRA_CFG_NYX_DUMP);
|
|
|
|
nyx_str->cfg |= NYX_CFG_DUMP;
|
|
|
|
}
|
|
|
|
if (b_cfg.extra_cfg & EXTRA_CFG_NYX_UMS)
|
|
|
|
{
|
|
|
|
b_cfg.extra_cfg &= ~(EXTRA_CFG_NYX_UMS);
|
|
|
|
nyx_str->cfg |= NYX_CFG_UMS;
|
|
|
|
nyx_str->cfg |= b_cfg.ums << 24;
|
|
|
|
}
|
2019-06-30 00:55:19 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
nyx_str->version = ipl_ver.version - 0x303030; // Convert ASCII to numbers.
|
2019-06-30 00:55:19 +00:00
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
//memcpy((u8 *)nyx_str->irama, (void *)IRAM_BASE, 0x8000);
|
2019-06-30 00:55:19 +00:00
|
|
|
volatile reloc_meta_t *reloc = (reloc_meta_t *)(IPL_LOAD_ADDR + RELOC_META_OFF);
|
|
|
|
memcpy((u8 *)nyx_str->hekate, (u8 *)reloc->start, reloc->end - reloc->start);
|
|
|
|
|
|
|
|
void (*nyx_ptr)() = (void *)nyx;
|
|
|
|
|
|
|
|
bpmp_mmu_disable();
|
|
|
|
bpmp_clk_rate_set(BPMP_CLK_NORMAL);
|
|
|
|
minerva_periodic_training();
|
|
|
|
|
2019-07-06 19:08:37 +00:00
|
|
|
// Some cards (Sandisk U1), do not like a fast power cycle. Wait min 100ms.
|
2019-08-27 23:39:43 +00:00
|
|
|
sdmmc_storage_init_wait_sd();
|
2019-07-06 19:08:37 +00:00
|
|
|
|
2019-06-30 00:55:19 +00:00
|
|
|
(*nyx_ptr)();
|
|
|
|
}
|
|
|
|
|
2020-04-27 06:30:53 +00:00
|
|
|
static ini_sec_t *get_ini_sec_from_id(ini_sec_t *ini_sec, char **bootlogoCustomEntry, char **emummc_path)
|
2019-08-16 19:00:32 +00: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 22:12:34 +00:00
|
|
|
{
|
|
|
|
if (b_cfg.id[0] && kv->val[0] && !strcmp(b_cfg.id, kv->val))
|
2019-08-16 19:00:32 +00:00
|
|
|
cfg_sec = ini_sec;
|
2019-08-27 22:12:34 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2019-08-16 19:00:32 +00:00
|
|
|
if (!strcmp("logopath", kv->key))
|
2019-12-07 23:11:13 +00:00
|
|
|
*bootlogoCustomEntry = kv->val;
|
2019-08-16 19:00:32 +00:00
|
|
|
if (!strcmp("emummc_force_disable", kv->key))
|
|
|
|
h_cfg.emummc_force_disable = atoi(kv->val);
|
2020-04-27 06:30:53 +00:00
|
|
|
if (!strcmp("emupath", kv->key))
|
|
|
|
*emummc_path = kv->val;
|
2019-08-16 19:00:32 +00:00
|
|
|
}
|
|
|
|
if (!cfg_sec)
|
|
|
|
{
|
2019-12-07 23:11:13 +00:00
|
|
|
*bootlogoCustomEntry = NULL;
|
2020-04-27 06:30:53 +00:00
|
|
|
*emummc_path = NULL;
|
2019-08-16 19:00:32 +00:00
|
|
|
h_cfg.emummc_force_disable = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cfg_sec;
|
|
|
|
}
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
static void _auto_launch_firmware()
|
2018-07-01 17:45:52 +00:00
|
|
|
{
|
2019-07-06 19:08:37 +00:00
|
|
|
if(b_cfg.extra_cfg & EXTRA_CFG_NYX_DUMP)
|
2019-06-30 00:55:19 +00:00
|
|
|
{
|
2019-07-06 19:08:37 +00:00
|
|
|
if (!h_cfg.sept_run)
|
|
|
|
EMC(EMC_SCRATCH0) |= EMC_HEKA_UPD;
|
2019-12-15 22:53:22 +00:00
|
|
|
check_sept(NULL);
|
2019-06-30 00:55:19 +00:00
|
|
|
}
|
2020-04-30 11:44:27 +00:00
|
|
|
else if (b_cfg.extra_cfg & EXTRA_CFG_NYX_UMS)
|
|
|
|
EMC(EMC_SCRATCH0) |= EMC_HEKA_UPD;
|
2019-06-30 00:55:19 +00:00
|
|
|
|
2019-03-07 22:35:43 +00:00
|
|
|
if (!h_cfg.sept_run)
|
2019-02-24 00:43:13 +00:00
|
|
|
auto_launch_update();
|
2018-08-23 01:27:49 +00:00
|
|
|
|
2018-07-01 17:45:52 +00:00
|
|
|
u8 *BOOTLOGO = NULL;
|
2018-08-21 01:45:19 +00:00
|
|
|
char *payload_path = NULL;
|
2020-04-27 06:30:53 +00:00
|
|
|
char *emummc_path = NULL;
|
2019-02-24 00:43:13 +00:00
|
|
|
u32 btn = 0;
|
2019-08-16 19:00:32 +00: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-08-21 01:45:19 +00:00
|
|
|
|
2018-07-01 17:45:52 +00:00
|
|
|
struct _bmp_data
|
|
|
|
{
|
|
|
|
u32 size;
|
|
|
|
u32 size_x;
|
|
|
|
u32 size_y;
|
|
|
|
u32 offset;
|
|
|
|
u32 pos_x;
|
|
|
|
u32 pos_y;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _bmp_data bmpData;
|
2018-08-13 09:12:53 +00:00
|
|
|
bool bootlogoFound = false;
|
2018-07-01 17:45:52 +00:00
|
|
|
char *bootlogoCustomEntry = NULL;
|
|
|
|
|
2019-03-07 22:35:43 +00:00
|
|
|
if (!(b_cfg.boot_cfg & BOOT_CFG_FROM_LAUNCH))
|
|
|
|
gfx_con.mute = true;
|
|
|
|
|
2018-07-01 17:45:52 +00:00
|
|
|
ini_sec_t *cfg_sec = NULL;
|
|
|
|
LIST_INIT(ini_sections);
|
2018-08-21 01:37:40 +00:00
|
|
|
LIST_INIT(ini_list_sections);
|
2018-07-01 17:45:52 +00:00
|
|
|
|
|
|
|
if (sd_mount())
|
|
|
|
{
|
2019-03-07 21:53:58 +00:00
|
|
|
if (f_stat("bootloader/hekate_ipl.ini", NULL))
|
2018-09-18 20:47:37 +00:00
|
|
|
create_config_entry();
|
|
|
|
|
2018-08-21 01:37:40 +00:00
|
|
|
if (ini_parse(&ini_sections, "bootloader/hekate_ipl.ini", false))
|
2018-07-01 17:45:52 +00:00
|
|
|
{
|
|
|
|
u32 configEntry = 0;
|
|
|
|
u32 boot_entry_id = 0;
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
if (!strcmp(ini_sec->name, "config"))
|
|
|
|
{
|
|
|
|
configEntry = 1;
|
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link)
|
|
|
|
{
|
|
|
|
if (!strcmp("autoboot", kv->key))
|
|
|
|
h_cfg.autoboot = atoi(kv->val);
|
2018-08-21 01:37:40 +00:00
|
|
|
else if (!strcmp("autoboot_list", kv->key))
|
|
|
|
h_cfg.autoboot_list = atoi(kv->val);
|
2018-07-01 17:45:52 +00:00
|
|
|
else if (!strcmp("bootwait", kv->key))
|
|
|
|
h_cfg.bootwait = atoi(kv->val);
|
2018-09-18 21:01:42 +00:00
|
|
|
else if (!strcmp("backlight", kv->key))
|
|
|
|
h_cfg.backlight = atoi(kv->val);
|
2018-09-24 20:45:06 +00:00
|
|
|
else if (!strcmp("autohosoff", kv->key))
|
|
|
|
h_cfg.autohosoff = atoi(kv->val);
|
2019-02-23 23:06:24 +00:00
|
|
|
else if (!strcmp("autonogc", kv->key))
|
|
|
|
h_cfg.autonogc = atoi(kv->val);
|
2019-12-11 22:13:32 +00:00
|
|
|
else if (!strcmp("updater2p", kv->key))
|
|
|
|
h_cfg.updater2p = atoi(kv->val);
|
2019-06-30 00:55:19 +00:00
|
|
|
else if (!strcmp("brand", kv->key))
|
|
|
|
{
|
|
|
|
h_cfg.brand = malloc(strlen(kv->val) + 1);
|
|
|
|
strcpy(h_cfg.brand, kv->val);
|
|
|
|
}
|
|
|
|
else if (!strcmp("tagline", kv->key))
|
|
|
|
{
|
|
|
|
h_cfg.tagline = malloc(strlen(kv->val) + 1);
|
|
|
|
strcpy(h_cfg.tagline, kv->val);
|
|
|
|
}
|
2018-07-01 17:45:52 +00:00
|
|
|
}
|
|
|
|
boot_entry_id++;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
|
|
|
// Override autoboot, otherwise save it for a possbile sept run.
|
2019-03-07 21:41:07 +00:00
|
|
|
if (b_cfg.boot_cfg & BOOT_CFG_AUTOBOOT_EN)
|
2019-02-24 00:43:13 +00:00
|
|
|
{
|
2019-03-07 21:41:07 +00:00
|
|
|
h_cfg.autoboot = b_cfg.autoboot;
|
|
|
|
h_cfg.autoboot_list = b_cfg.autoboot_list;
|
2019-02-24 00:43:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-07 21:41:07 +00:00
|
|
|
b_cfg.autoboot = h_cfg.autoboot;
|
|
|
|
b_cfg.autoboot_list = h_cfg.autoboot_list;
|
2019-02-24 00:43:13 +00:00
|
|
|
}
|
|
|
|
|
2018-07-01 17:45:52 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-08-16 19:00:32 +00:00
|
|
|
if (boot_from_id)
|
2020-04-27 06:30:53 +00:00
|
|
|
cfg_sec = get_ini_sec_from_id(ini_sec, &bootlogoCustomEntry, &emummc_path);
|
2019-08-16 19:00:32 +00:00
|
|
|
else if (h_cfg.autoboot == boot_entry_id && configEntry)
|
2018-07-01 17:45:52 +00:00
|
|
|
{
|
2019-07-06 19:08:37 +00:00
|
|
|
cfg_sec = ini_sec;
|
2018-07-01 17:45:52 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg_sec->kvs, link)
|
|
|
|
{
|
|
|
|
if (!strcmp("logopath", kv->key))
|
|
|
|
bootlogoCustomEntry = kv->val;
|
2020-04-27 06:30:53 +00:00
|
|
|
else if (!strcmp("emummc_force_disable", kv->key))
|
2019-06-30 00:24:58 +00:00
|
|
|
h_cfg.emummc_force_disable = atoi(kv->val);
|
2020-04-27 06:30:53 +00:00
|
|
|
else if (!strcmp("emupath", kv->key))
|
|
|
|
emummc_path = kv->val;
|
2018-08-05 11:40:32 +00:00
|
|
|
}
|
2018-07-01 17:45:52 +00:00
|
|
|
}
|
2019-08-16 19:00:32 +00:00
|
|
|
if (cfg_sec)
|
|
|
|
break;
|
2018-07-01 17:45:52 +00:00
|
|
|
boot_entry_id++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-07 21:41:07 +00:00
|
|
|
if (h_cfg.autohosoff && !(b_cfg.boot_cfg & BOOT_CFG_AUTOBOOT_EN))
|
2018-09-24 20:45:06 +00:00
|
|
|
check_power_off_from_hos();
|
|
|
|
|
2019-08-16 19:00:32 +00:00
|
|
|
if (h_cfg.autoboot_list || (boot_from_id && !cfg_sec))
|
2018-08-21 01:37:40 +00:00
|
|
|
{
|
2019-08-16 19:00:32 +00:00
|
|
|
if (boot_from_id && cfg_sec)
|
|
|
|
goto skip_list;
|
|
|
|
|
2019-08-27 22:12:34 +00:00
|
|
|
cfg_sec = NULL;
|
2018-08-21 01:37:40 +00:00
|
|
|
boot_entry_id = 1;
|
|
|
|
bootlogoCustomEntry = NULL;
|
|
|
|
|
|
|
|
if (ini_parse(&ini_list_sections, "bootloader/ini", true))
|
|
|
|
{
|
|
|
|
LIST_FOREACH_ENTRY(ini_sec_t, ini_sec_list, &ini_list_sections, link)
|
|
|
|
{
|
|
|
|
if (ini_sec_list->type == INI_CHOICE)
|
|
|
|
{
|
|
|
|
if (!strcmp(ini_sec_list->name, "config"))
|
|
|
|
continue;
|
|
|
|
|
2019-08-16 19:00:32 +00:00
|
|
|
if (boot_from_id)
|
2020-04-27 06:30:53 +00:00
|
|
|
cfg_sec = get_ini_sec_from_id(ini_sec_list, &bootlogoCustomEntry, &emummc_path);
|
2019-08-16 19:00:32 +00:00
|
|
|
else if (h_cfg.autoboot == boot_entry_id)
|
2018-08-21 01:37:40 +00:00
|
|
|
{
|
2019-06-30 00:24:58 +00:00
|
|
|
h_cfg.emummc_force_disable = false;
|
2019-07-06 19:08:37 +00:00
|
|
|
cfg_sec = ini_sec_list;
|
2018-08-21 01:37:40 +00:00
|
|
|
LIST_FOREACH_ENTRY(ini_kv_t, kv, &cfg_sec->kvs, link)
|
|
|
|
{
|
|
|
|
if (!strcmp("logopath", kv->key))
|
|
|
|
bootlogoCustomEntry = kv->val;
|
2020-04-27 06:30:53 +00:00
|
|
|
else if (!strcmp("emummc_force_disable", kv->key))
|
2019-06-30 00:24:58 +00:00
|
|
|
h_cfg.emummc_force_disable = atoi(kv->val);
|
2020-04-27 06:30:53 +00:00
|
|
|
else if (!strcmp("emupath", kv->key))
|
|
|
|
emummc_path = kv->val;
|
2018-08-21 01:37:40 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-16 19:00:32 +00:00
|
|
|
if (cfg_sec)
|
|
|
|
break;
|
2018-08-21 01:37:40 +00:00
|
|
|
boot_entry_id++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-08-16 19:00:32 +00:00
|
|
|
skip_list:
|
2018-07-01 17:45:52 +00:00
|
|
|
// Add missing configuration entry.
|
|
|
|
if (!configEntry)
|
|
|
|
create_config_entry();
|
|
|
|
|
|
|
|
if (!cfg_sec)
|
2019-08-27 22:12:34 +00:00
|
|
|
goto out; // No configurations or auto boot is disabled.
|
2018-07-01 17:45:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
goto out; // Can't load hekate_ipl.ini.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
goto out;
|
|
|
|
|
2019-02-24 00:43:13 +00:00
|
|
|
u8 *bitmap = NULL;
|
2019-06-30 00:15:46 +00:00
|
|
|
if (!(b_cfg.boot_cfg & BOOT_CFG_FROM_LAUNCH) && h_cfg.bootwait && !h_cfg.sept_run)
|
2019-02-24 00:43:13 +00:00
|
|
|
{
|
2020-06-14 10:04:13 +00:00
|
|
|
u32 fsize;
|
2019-03-07 22:19:04 +00:00
|
|
|
if (bootlogoCustomEntry) // Check if user set custom logo path at the boot entry.
|
2020-06-14 10:04:13 +00:00
|
|
|
bitmap = (u8 *)sd_file_read(bootlogoCustomEntry, &fsize);
|
2019-03-07 22:19:04 +00:00
|
|
|
|
|
|
|
if (!bitmap) // Custom entry bootlogo not found, trying default custom one.
|
2020-06-14 10:04:13 +00:00
|
|
|
bitmap = (u8 *)sd_file_read("bootloader/bootlogo.bmp", &fsize);
|
2018-07-01 17:45:52 +00:00
|
|
|
|
2019-03-07 22:19:04 +00:00
|
|
|
if (bitmap)
|
2018-07-01 17:45:52 +00: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 17:45:52 +00:00
|
|
|
bmpData.size_x <= 720 &&
|
|
|
|
bmpData.size_y <= 1280)
|
|
|
|
{
|
2020-06-14 10:04:13 +00:00
|
|
|
if (bmpData.size <= fsize && ((bmpData.size - bmpData.offset) < 0x400000))
|
2018-07-01 17:45:52 +00:00
|
|
|
{
|
|
|
|
// Avoid unaligned access from BM 2-byte MAGIC and remove header.
|
|
|
|
BOOTLOGO = (u8 *)malloc(0x400000);
|
|
|
|
memcpy(BOOTLOGO, bitmap + bmpData.offset, bmpData.size - bmpData.offset);
|
|
|
|
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 12:55:09 +00:00
|
|
|
// Get background color from 1st pixel.
|
|
|
|
if (bmpData.size_x < 720 || bmpData.size_y < 1280)
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_clear_color(*(u32 *)BOOTLOGO);
|
2018-07-01 17:45:52 +00:00
|
|
|
|
2018-08-13 09:12:53 +00:00
|
|
|
bootlogoFound = true;
|
2018-07-01 17:45:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
free(bitmap);
|
|
|
|
}
|
|
|
|
|
2019-02-24 00:43:13 +00:00
|
|
|
// Render boot logo.
|
|
|
|
if (bootlogoFound)
|
|
|
|
{
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_render_bmp_argb((u32 *)BOOTLOGO, bmpData.size_x, bmpData.size_y,
|
2019-02-24 00:43:13 +00:00
|
|
|
bmpData.pos_x, bmpData.pos_y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_clear_grey(0x1B);
|
2019-02-24 00:43:13 +00:00
|
|
|
BOOTLOGO = (void *)malloc(0x4000);
|
|
|
|
blz_uncompress_srcdest(BOOTLOGO_BLZ, SZ_BOOTLOGO_BLZ, BOOTLOGO, SZ_BOOTLOGO);
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_set_rect_grey(BOOTLOGO, X_BOOTLOGO, Y_BOOTLOGO, 326, 544);
|
2019-02-24 00:43:13 +00:00
|
|
|
}
|
|
|
|
free(BOOTLOGO);
|
2018-07-01 17:45:52 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 19:34:03 +00:00
|
|
|
if (b_cfg.boot_cfg & BOOT_CFG_FROM_LAUNCH)
|
|
|
|
display_backlight_brightness(h_cfg.backlight, 0);
|
|
|
|
else if (!h_cfg.sept_run && h_cfg.bootwait)
|
2019-02-24 00:43:13 +00:00
|
|
|
display_backlight_brightness(h_cfg.backlight, 1000);
|
|
|
|
|
|
|
|
// Wait before booting. If VOL- is pressed go into bootloader menu.
|
2019-07-06 19:34:03 +00:00
|
|
|
if (!h_cfg.sept_run && !(b_cfg.boot_cfg & BOOT_CFG_FROM_LAUNCH))
|
2019-02-24 00:43:13 +00:00
|
|
|
{
|
2020-06-13 15:16:29 +00:00
|
|
|
btn = btn_wait_timeout_single(h_cfg.bootwait * 1000, BTN_VOL_DOWN | BTN_SINGLE);
|
2019-02-24 00:43:13 +00:00
|
|
|
|
|
|
|
if (btn & BTN_VOL_DOWN)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2019-03-07 22:35:43 +00:00
|
|
|
payload_path = ini_check_payload_section(cfg_sec);
|
|
|
|
|
2018-08-21 01:45:19 +00:00
|
|
|
if (payload_path)
|
2018-07-01 17:45:52 +00:00
|
|
|
{
|
2019-12-04 19:31:39 +00:00
|
|
|
launch_payload(payload_path, false);
|
|
|
|
free(payload_path);
|
2020-06-13 23:09:48 +00:00
|
|
|
goto payload_error;
|
2018-08-21 01:45:19 +00:00
|
|
|
}
|
|
|
|
else
|
2019-03-07 22:35:43 +00:00
|
|
|
{
|
2020-04-27 06:30:53 +00:00
|
|
|
if (b_cfg.boot_cfg & BOOT_CFG_TO_EMUMMC)
|
|
|
|
emummc_set_path(b_cfg.emummc_path);
|
2020-05-05 16:23:31 +00:00
|
|
|
else if (emummc_path && !emummc_set_path(emummc_path))
|
|
|
|
{
|
|
|
|
gfx_con.mute = false;
|
|
|
|
EPRINTF("emupath is wrong!");
|
|
|
|
goto wrong_emupath;
|
|
|
|
}
|
|
|
|
|
2019-12-15 22:53:22 +00:00
|
|
|
check_sept(cfg_sec);
|
2018-08-21 01:45:19 +00:00
|
|
|
hos_launch(cfg_sec);
|
2019-10-08 21:42:13 +00:00
|
|
|
|
2020-06-13 23:09:48 +00:00
|
|
|
wrong_emupath:
|
|
|
|
EPRINTF("\nFailed to launch HOS!");
|
|
|
|
|
2020-04-27 06:30:53 +00:00
|
|
|
if (emummc_path || b_cfg.boot_cfg & BOOT_CFG_TO_EMUMMC)
|
|
|
|
{
|
|
|
|
sd_mount();
|
|
|
|
emummc_load_cfg();
|
|
|
|
}
|
|
|
|
|
2020-06-13 23:09:48 +00:00
|
|
|
payload_error:
|
|
|
|
gfx_con.mute = 0;
|
2019-12-11 09:22:11 +00:00
|
|
|
gfx_printf("\nPress any key...\n");
|
2020-06-13 23:09:48 +00:00
|
|
|
display_backlight_brightness(h_cfg.backlight, 1000);
|
2019-10-08 21:42:13 +00:00
|
|
|
msleep(500);
|
|
|
|
btn_wait();
|
2019-03-07 22:35:43 +00:00
|
|
|
}
|
2018-08-21 01:45:19 +00:00
|
|
|
|
2018-08-05 11:40:32 +00:00
|
|
|
out:
|
2018-08-13 09:12:53 +00:00
|
|
|
gfx_con.mute = false;
|
2019-02-24 00:43:13 +00:00
|
|
|
|
2019-08-16 19:00:32 +00:00
|
|
|
// Clear boot reasons from binary.
|
2020-04-27 06:30:53 +00:00
|
|
|
if (b_cfg.boot_cfg & (BOOT_CFG_FROM_ID | BOOT_CFG_TO_EMUMMC))
|
2019-08-16 19:00:32 +00:00
|
|
|
memset(b_cfg.xt_str, 0, sizeof(b_cfg.xt_str));
|
2020-04-27 06:30:53 +00:00
|
|
|
b_cfg.boot_cfg &= ~(BOOT_CFG_AUTOBOOT_EN | BOOT_CFG_FROM_LAUNCH | BOOT_CFG_FROM_ID | BOOT_CFG_TO_EMUMMC);
|
2019-06-30 00:24:58 +00:00
|
|
|
h_cfg.emummc_force_disable = false;
|
2019-06-30 00:55:19 +00:00
|
|
|
|
|
|
|
nyx_load_run();
|
|
|
|
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_end();
|
2018-07-01 17:45:52 +00:00
|
|
|
}
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
static void _patched_rcm_protection()
|
2019-04-16 17:09:04 +00:00
|
|
|
{
|
|
|
|
sdmmc_storage_t storage;
|
|
|
|
sdmmc_t sdmmc;
|
|
|
|
|
2020-06-14 13:45:45 +00:00
|
|
|
u32 chip_id = (APB_MISC(APB_MISC_GP_HIDREV) >> 4) & 0xF;
|
|
|
|
|
|
|
|
if (!h_cfg.rcm_patched || chip_id != GP_HIDREV_MAJOR_T210)
|
2019-04-16 17:09:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Check if AutoRCM is enabled and protect from a permanent brick.
|
2020-04-29 15:53:29 +00:00
|
|
|
if (!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
|
2019-04-16 17:09:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
u8 *tempbuf = (u8 *)malloc(0x200);
|
2020-04-29 19:06:33 +00:00
|
|
|
sdmmc_storage_set_mmc_partition(&storage, EMMC_BOOT0);
|
2019-04-16 17:09:04 +00:00
|
|
|
|
|
|
|
u8 corr_mod_byte0;
|
|
|
|
int i, sect = 0;
|
|
|
|
if ((fuse_read_odm(4) & 3) != 3)
|
|
|
|
corr_mod_byte0 = 0xF7;
|
|
|
|
else
|
|
|
|
corr_mod_byte0 = 0x37;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
sect = (0x200 + (0x4000 * i)) / NX_EMMC_BLOCKSIZE;
|
|
|
|
sdmmc_storage_read(&storage, sect, 1, tempbuf);
|
|
|
|
|
|
|
|
// If AutoRCM is enabled, disable it.
|
|
|
|
if (tempbuf[0x10] != corr_mod_byte0)
|
|
|
|
{
|
|
|
|
tempbuf[0x10] = corr_mod_byte0;
|
|
|
|
|
|
|
|
sdmmc_storage_write(&storage, sect, 1, tempbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(tempbuf);
|
|
|
|
sdmmc_storage_end(&storage);
|
|
|
|
}
|
|
|
|
|
2020-04-27 06:56:19 +00:00
|
|
|
#define EXCP_EN_ADDR 0x4003FFFC
|
|
|
|
#define EXCP_MAGIC 0x30505645 // EVP0
|
|
|
|
#define EXCP_TYPE_ADDR 0x4003FFF8
|
|
|
|
#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_LR_ADDR 0x4003FFF4
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
static void _show_errors()
|
|
|
|
{
|
2020-04-27 06:56:19 +00:00
|
|
|
u32 *excp_enabled = (u32 *)EXCP_EN_ADDR;
|
|
|
|
u32 *excp_type = (u32 *)EXCP_TYPE_ADDR;
|
|
|
|
u32 *excp_lr = (u32 *)EXCP_LR_ADDR;
|
|
|
|
|
|
|
|
if (*excp_enabled == EXCP_MAGIC)
|
|
|
|
h_cfg.errors |= ERR_EXCEPT_ENB;
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
if (h_cfg.errors)
|
|
|
|
{
|
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2020-04-14 14:55:31 +00:00
|
|
|
display_backlight_brightness(150, 1000);
|
2019-12-11 09:22:11 +00:00
|
|
|
|
|
|
|
if (h_cfg.errors & ERR_LIBSYS_LP0)
|
2020-04-30 00:25:22 +00:00
|
|
|
WPRINTF("Missing LP0 (sleep mode) lib!\n");
|
2019-12-11 09:22:11 +00:00
|
|
|
if (h_cfg.errors & ERR_SYSOLD_MTC)
|
2020-04-30 00:25:22 +00:00
|
|
|
WPRINTF("Missing or old Minerva lib!\n");
|
2019-12-11 09:22:11 +00:00
|
|
|
|
2020-04-27 06:56:19 +00:00
|
|
|
if (h_cfg.errors & ~ERR_EXCEPT_ENB)
|
|
|
|
{
|
2020-04-30 00:25:22 +00:00
|
|
|
WPRINTF("\nUpdate bootloader folder!\n\n");
|
2020-04-27 06:56:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (h_cfg.errors & ERR_EXCEPT_ENB)
|
|
|
|
{
|
2020-04-30 00:25:22 +00:00
|
|
|
WPRINTFARGS("An exception occurred (LR %08X):\n", *excp_lr);
|
2020-04-27 06:56:19 +00:00
|
|
|
switch (*excp_type)
|
|
|
|
{
|
|
|
|
case EXCP_TYPE_RESET:
|
|
|
|
WPRINTF("Reset");
|
|
|
|
break;
|
|
|
|
case EXCP_TYPE_UNDEF:
|
|
|
|
WPRINTF("Undefined instruction");
|
|
|
|
break;
|
|
|
|
case EXCP_TYPE_PABRT:
|
|
|
|
WPRINTF("Prefetch abort");
|
|
|
|
break;
|
|
|
|
case EXCP_TYPE_DABRT:
|
|
|
|
WPRINTF("Data abort");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
WPRINTF("\n");
|
|
|
|
|
|
|
|
// Clear the exception.
|
|
|
|
*excp_enabled = 0;
|
|
|
|
}
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
WPRINTF("Press any key...");
|
|
|
|
|
|
|
|
msleep(2000);
|
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 02:54:45 +00:00
|
|
|
static void _check_low_battery()
|
|
|
|
{
|
|
|
|
int enough_battery;
|
2020-06-13 23:05:57 +00:00
|
|
|
int batt_volt = 3500;
|
2020-04-06 02:54:45 +00:00
|
|
|
int charge_status = 0;
|
|
|
|
|
|
|
|
bq24193_get_property(BQ24193_ChargeStatus, &charge_status);
|
|
|
|
max17050_get_property(MAX17050_AvgVCELL, &batt_volt);
|
|
|
|
|
|
|
|
enough_battery = charge_status ? 3250 : 3000;
|
|
|
|
|
|
|
|
if (batt_volt > enough_battery)
|
2020-06-13 23:05:57 +00:00
|
|
|
goto out;
|
2020-04-06 02:54:45 +00:00
|
|
|
|
|
|
|
// Prepare battery icon resources.
|
|
|
|
u8 *battery_res = malloc(ALIGN(SZ_BATTERY_EMPTY, 0x1000));
|
|
|
|
blz_uncompress_srcdest(BATTERY_EMPTY_BLZ, SZ_BATTERY_EMPTY_BLZ, battery_res, SZ_BATTERY_EMPTY);
|
|
|
|
|
|
|
|
u8 *battery_icon = malloc(0x95A); // 21x38x3
|
|
|
|
u8 *charging_icon = malloc(0x2F4); // 21x12x3
|
|
|
|
u8 *no_charging_icon = calloc(0x2F4, 1);
|
|
|
|
|
|
|
|
memcpy(charging_icon, battery_res, 0x2F4);
|
|
|
|
memcpy(battery_icon, battery_res + 0x2F4, 0x95A);
|
|
|
|
|
|
|
|
u32 battery_icon_y_pos = 1280 - 16 - Y_BATTERY_EMPTY_BATT;
|
|
|
|
u32 charging_icon_y_pos = 1280 - 16 - Y_BATTERY_EMPTY_BATT - 12 - Y_BATTERY_EMPTY_CHRG;
|
|
|
|
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);
|
|
|
|
enough_battery = current_charge_status ? 3250 : 3000;
|
|
|
|
|
|
|
|
if (batt_volt > enough_battery)
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Refresh charging icon.
|
|
|
|
if (screen_on && (charge_status != current_charge_status))
|
|
|
|
{
|
|
|
|
if (current_charge_status)
|
|
|
|
gfx_set_rect_rgb(charging_icon, X_BATTERY_EMPTY, Y_BATTERY_EMPTY_CHRG, 16, charging_icon_y_pos);
|
|
|
|
else
|
|
|
|
gfx_set_rect_rgb(no_charging_icon, X_BATTERY_EMPTY, Y_BATTERY_EMPTY_CHRG, 16, charging_icon_y_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if it's time to turn off display.
|
|
|
|
if (screen_on && timer < get_tmr_ms())
|
|
|
|
{
|
|
|
|
if (!current_charge_status)
|
|
|
|
{
|
|
|
|
max77620_low_battery_monitor_config(true);
|
|
|
|
power_off();
|
|
|
|
}
|
|
|
|
|
|
|
|
display_end();
|
|
|
|
screen_on = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if charging status changed or Power button was pressed.
|
2020-06-13 15:16:29 +00:00
|
|
|
if ((charge_status != current_charge_status) || (btn_wait_timeout_single(0, BTN_POWER) & BTN_POWER))
|
2020-04-06 02:54:45 +00:00
|
|
|
{
|
|
|
|
if (!screen_on)
|
|
|
|
{
|
|
|
|
display_init();
|
2020-06-13 15:16:29 +00:00
|
|
|
u32 *fb = display_init_framebuffer_pitch();
|
2020-04-06 02:54:45 +00:00
|
|
|
gfx_init_ctxt(fb, 720, 1280, 720);
|
|
|
|
|
|
|
|
gfx_set_rect_rgb(battery_icon, X_BATTERY_EMPTY, Y_BATTERY_EMPTY_BATT, 16, battery_icon_y_pos);
|
|
|
|
if (current_charge_status)
|
|
|
|
gfx_set_rect_rgb(charging_icon, X_BATTERY_EMPTY, Y_BATTERY_EMPTY_CHRG, 16, charging_icon_y_pos);
|
|
|
|
else
|
|
|
|
gfx_set_rect_rgb(no_charging_icon, X_BATTERY_EMPTY, Y_BATTERY_EMPTY_CHRG, 16, charging_icon_y_pos);
|
|
|
|
|
|
|
|
display_backlight_pwm_init();
|
|
|
|
display_backlight_brightness(100, 1000);
|
|
|
|
|
|
|
|
screen_on = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
timer = get_tmr_ms() + 15000;
|
|
|
|
}
|
|
|
|
|
2020-04-14 14:55:31 +00:00
|
|
|
// Check if forcefully continuing.
|
|
|
|
if (btn_read_vol() == (BTN_VOL_UP | BTN_VOL_DOWN))
|
|
|
|
break;
|
|
|
|
|
2020-04-06 02:54:45 +00:00
|
|
|
charge_status = current_charge_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
display_end();
|
|
|
|
|
|
|
|
free(battery_icon);
|
|
|
|
free(charging_icon);
|
|
|
|
free(no_charging_icon);
|
2020-04-27 06:30:53 +00:00
|
|
|
|
2020-06-13 23:05:57 +00:00
|
|
|
out:
|
2020-04-06 02:54:45 +00:00
|
|
|
// Re enable Low Battery Monitor shutdown.
|
|
|
|
max77620_low_battery_monitor_config(true);
|
|
|
|
}
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
static void _about()
|
2018-05-01 05:15:48 +00:00
|
|
|
{
|
2018-06-26 16:09:26 +00:00
|
|
|
static const char credits[] =
|
2019-02-23 23:06:24 +00:00
|
|
|
"\nhekate (c) 2018 naehrwert, st4rk\n\n"
|
|
|
|
"CTCaer mod (c) 2018 CTCaer\n"
|
2018-08-05 11:40:32 +00: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"
|
|
|
|
" - FatFs R0.13b,\n"
|
2019-02-23 23:06:24 +00:00
|
|
|
" Copyright (c) 2018, ChaN\n\n"
|
2018-08-05 11:40:32 +00:00
|
|
|
" - bcl-1.2.0,\n"
|
2019-02-23 23:06:24 +00:00
|
|
|
" Copyright (c) 2003-2006, Marcus Geelnard\n\n"
|
2019-12-04 15:18:16 +00:00
|
|
|
" - Atmosphere (Exo st/types, prc id patches),\n"
|
|
|
|
" Copyright (c) 2018-2019, Atmosphere-NX\n\n"
|
2018-08-07 14:53:58 +00:00
|
|
|
" - elfload,\n"
|
2019-02-23 23:06:24 +00:00
|
|
|
" Copyright (c) 2014, Owen Shepherd\n"
|
|
|
|
" Copyright (c) 2018, M4xw\n"
|
2018-08-05 11:40:32 +00:00
|
|
|
" ___________________________________________\n\n";
|
2018-05-01 05:15:48 +00:00
|
|
|
static const char octopus[] =
|
2018-08-05 11:40:32 +00: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 05:15:48 +00:00
|
|
|
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-05-01 05:15:48 +00:00
|
|
|
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_printf(credits, 0xFF00CCFF, 0xFFCCCCCC);
|
2018-06-27 21:21:05 +00:00
|
|
|
gfx_con.fntsz = 8;
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_printf(octopus, 0xFF00CCFF, 0xFF00FFCC, 0xFF00CCFF, 0xFFCCCCCC);
|
2018-05-01 05:15:48 +00:00
|
|
|
|
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
2018-07-01 17:45:25 +00:00
|
|
|
ment_t ment_options[] = {
|
2018-06-27 21:36:18 +00:00
|
|
|
MDEF_BACK(),
|
|
|
|
MDEF_CHGLINE(),
|
|
|
|
MDEF_HANDLER("Auto boot", config_autoboot),
|
2020-06-13 15:16:29 +00:00
|
|
|
MDEF_HANDLER("Boot delay", config_bootdelay),
|
|
|
|
MDEF_HANDLER("Auto NoGC", config_nogc),
|
|
|
|
MDEF_HANDLER("Auto HOS power off", config_auto_hos_poweroff),
|
2020-04-30 13:25:35 +00:00
|
|
|
MDEF_HANDLER("Backlight", config_backlight),
|
2018-06-27 21:36:18 +00:00
|
|
|
MDEF_END()
|
2018-07-01 02:06:13 +00:00
|
|
|
};
|
2018-06-27 21:36:18 +00:00
|
|
|
|
2020-04-30 13:25:35 +00:00
|
|
|
menu_t menu_options = { ment_options, "Options", 0, 0 };
|
2018-06-27 21:36:18 +00:00
|
|
|
|
2018-05-01 05:15:48 +00:00
|
|
|
ment_t ment_cinfo[] = {
|
|
|
|
MDEF_BACK(),
|
2018-05-24 21:33:11 +00:00
|
|
|
MDEF_CHGLINE(),
|
2018-06-19 13:53:41 +00:00
|
|
|
MDEF_CAPTION("---- SoC Info ----", 0xFF0AB9E6),
|
2020-04-30 00:25:22 +00:00
|
|
|
MDEF_HANDLER("Ipatches & bootrom", bootrom_ipatches_info),
|
|
|
|
MDEF_HANDLER("Fuses", print_fuseinfo),
|
2020-04-30 13:25:35 +00:00
|
|
|
//MDEF_HANDLER("Print kfuse info", print_kfuseinfo),
|
|
|
|
//MDEF_HANDLER("Print TSEC keys", print_tsec_key),
|
2018-05-24 21:33:11 +00:00
|
|
|
MDEF_CHGLINE(),
|
2018-06-19 13:53:41 +00:00
|
|
|
MDEF_CAPTION("-- Storage Info --", 0xFF0AB9E6),
|
2020-04-30 00:25:22 +00:00
|
|
|
MDEF_HANDLER("eMMC", print_mmc_info),
|
|
|
|
MDEF_HANDLER("SD Card", print_sdcard_info),
|
2018-06-24 19:38:32 +00:00
|
|
|
MDEF_CHGLINE(),
|
|
|
|
MDEF_CAPTION("------ Misc ------", 0xFF0AB9E6),
|
2020-04-30 00:25:22 +00:00
|
|
|
MDEF_HANDLER("Battery", print_battery_info),
|
2018-05-01 05:15:48 +00:00
|
|
|
MDEF_END()
|
|
|
|
};
|
2019-06-30 00:15:46 +00:00
|
|
|
|
|
|
|
menu_t menu_cinfo = { ment_cinfo, "Console Info", 0, 0 };
|
2018-05-01 05:15:48 +00:00
|
|
|
|
2018-07-01 17:46:22 +00:00
|
|
|
ment_t ment_restore[] = {
|
2018-06-27 21:36:18 +00:00
|
|
|
MDEF_BACK(),
|
|
|
|
MDEF_CHGLINE(),
|
|
|
|
MDEF_CAPTION("------ Full --------", 0xFF0AB9E6),
|
|
|
|
MDEF_HANDLER("Restore eMMC BOOT0/1", restore_emmc_boot),
|
2019-03-08 22:09:36 +00:00
|
|
|
MDEF_HANDLER("Restore eMMC RAW GPP", restore_emmc_rawnand),
|
2018-06-27 21:36:18 +00:00
|
|
|
MDEF_CHGLINE(),
|
|
|
|
MDEF_CAPTION("-- GPP Partitions --", 0xFF0AB9E6),
|
|
|
|
MDEF_HANDLER("Restore GPP partitions", restore_emmc_gpp_parts),
|
|
|
|
MDEF_END()
|
|
|
|
};
|
|
|
|
|
2019-06-30 00:15:46 +00:00
|
|
|
menu_t menu_restore = { ment_restore, "Restore Options", 0, 0 };
|
2018-06-27 21:36:18 +00:00
|
|
|
|
|
|
|
ment_t ment_backup[] = {
|
2018-05-01 05:15:48 +00:00
|
|
|
MDEF_BACK(),
|
2018-05-24 21:33:11 +00:00
|
|
|
MDEF_CHGLINE(),
|
2018-06-19 13:53:41 +00:00
|
|
|
MDEF_CAPTION("------ Full --------", 0xFF0AB9E6),
|
2018-06-04 22:55:32 +00:00
|
|
|
MDEF_HANDLER("Backup eMMC BOOT0/1", dump_emmc_boot),
|
2018-06-27 21:36:18 +00:00
|
|
|
MDEF_HANDLER("Backup eMMC RAW GPP", dump_emmc_rawnand),
|
2018-05-24 21:33:11 +00:00
|
|
|
MDEF_CHGLINE(),
|
2018-06-19 13:53:41 +00:00
|
|
|
MDEF_CAPTION("-- GPP Partitions --", 0xFF0AB9E6),
|
2018-06-04 22:55:32 +00:00
|
|
|
MDEF_HANDLER("Backup eMMC SYS", dump_emmc_system),
|
|
|
|
MDEF_HANDLER("Backup eMMC USER", dump_emmc_user),
|
2018-06-27 21:36:18 +00:00
|
|
|
MDEF_END()
|
|
|
|
};
|
|
|
|
|
2019-06-30 00:15:46 +00:00
|
|
|
menu_t menu_backup = { ment_backup, "Backup Options", 0, 0 };
|
2018-06-27 21:36:18 +00:00
|
|
|
|
|
|
|
ment_t ment_tools[] = {
|
|
|
|
MDEF_BACK(),
|
|
|
|
MDEF_CHGLINE(),
|
2020-04-30 13:25:35 +00:00
|
|
|
//MDEF_CAPTION("-- Backup & Restore --", 0xFF0AB9E6),
|
|
|
|
//MDEF_MENU("Backup", &menu_backup),
|
|
|
|
//MDEF_MENU("Restore", &menu_restore),
|
|
|
|
//MDEF_CHGLINE(),
|
2020-04-14 15:11:34 +00:00
|
|
|
//MDEF_CAPTION("-------- Misc --------", 0xFF0AB9E6),
|
|
|
|
//MDEF_HANDLER("Dump package1/2", dump_packages12),
|
2020-03-03 02:42:01 +00:00
|
|
|
//MDEF_HANDLER("Fix archive bit (except Nintendo)", fix_sd_all_attr),
|
|
|
|
//MDEF_HANDLER("Fix archive bit (Nintendo only)", fix_sd_nin_attr),
|
2018-06-28 01:05:19 +00:00
|
|
|
//MDEF_HANDLER("Fix fuel gauge configuration", fix_fuel_gauge_configuration),
|
2018-07-01 13:58:59 +00:00
|
|
|
//MDEF_HANDLER("Reset all battery cfg", reset_pmic_fuel_gauge_charger_config),
|
2020-04-14 15:11:34 +00:00
|
|
|
//MDEF_CHGLINE(),
|
2019-04-16 17:09:04 +00:00
|
|
|
MDEF_CAPTION("-------- Other -------", 0xFFFFDD00),
|
2018-08-21 01:43:00 +00:00
|
|
|
MDEF_HANDLER("AutoRCM", menu_autorcm),
|
2018-05-01 05:15:48 +00:00
|
|
|
MDEF_END()
|
|
|
|
};
|
2018-05-23 23:37:16 +00:00
|
|
|
|
2019-06-30 00:15:46 +00:00
|
|
|
menu_t menu_tools = { ment_tools, "Tools", 0, 0 };
|
2018-05-01 05:15:48 +00:00
|
|
|
|
|
|
|
ment_t ment_top[] = {
|
2018-08-21 01:37:40 +00:00
|
|
|
MDEF_HANDLER("Launch", launch_firmware),
|
2020-06-13 15:16:29 +00:00
|
|
|
//MDEF_MENU("Options", &menu_options),
|
2018-05-24 21:33:11 +00:00
|
|
|
MDEF_CAPTION("---------------", 0xFF444444),
|
2018-05-01 05:15:48 +00:00
|
|
|
MDEF_MENU("Tools", &menu_tools),
|
|
|
|
MDEF_MENU("Console info", &menu_cinfo),
|
2018-05-24 21:33:11 +00:00
|
|
|
MDEF_CAPTION("---------------", 0xFF444444),
|
|
|
|
MDEF_HANDLER("Reboot (Normal)", reboot_normal),
|
|
|
|
MDEF_HANDLER("Reboot (RCM)", reboot_rcm),
|
2018-05-01 05:15:48 +00:00
|
|
|
MDEF_HANDLER("Power off", power_off),
|
2018-05-24 21:33:11 +00:00
|
|
|
MDEF_CAPTION("---------------", 0xFF444444),
|
2019-12-11 09:22:11 +00:00
|
|
|
MDEF_HANDLER("About", _about),
|
2018-05-01 05:15:48 +00:00
|
|
|
MDEF_END()
|
|
|
|
};
|
2019-06-30 00:15:46 +00:00
|
|
|
|
2020-05-05 17:40:22 +00:00
|
|
|
menu_t menu_top = { ment_top, "hekate - CTCaer mod v5.2.1", 0, 0 };
|
2018-05-01 05:15:48 +00: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.
|
2018-12-16 17:04:46 +00:00
|
|
|
config_hw();
|
2018-05-01 05:15:48 +00: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 05:15:48 +00: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.
|
2019-03-07 22:19:04 +00:00
|
|
|
heap_init(IPL_HEAP_START);
|
2018-05-01 05:15:48 +00: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);
|
2018-12-16 14:52:38 +00:00
|
|
|
uart_wait_idle(DEBUG_UART_PORT, UART_TX_IDLE);
|
2018-12-07 20:00:19 +00:00
|
|
|
#endif
|
2018-05-01 05:15:48 +00:00
|
|
|
|
2020-04-06 02:54:45 +00:00
|
|
|
// Check if battery is enough.
|
|
|
|
_check_low_battery();
|
|
|
|
|
2018-09-18 20:38:54 +00:00
|
|
|
// Set bootloader's default configuration.
|
|
|
|
set_default_configuration();
|
|
|
|
|
2019-06-30 00:49:33 +00:00
|
|
|
sd_mount();
|
|
|
|
|
2018-08-21 01:14:31 +00:00
|
|
|
// Save sdram lp0 config.
|
2020-06-14 10:17:26 +00:00
|
|
|
if (!ianos_loader("bootloader/sys/libsys_lp0.bso", DRAM_LIB, (void *)sdram_get_params_patched()))
|
2018-12-16 17:04:46 +00:00
|
|
|
h_cfg.errors |= ERR_LIBSYS_LP0;
|
2019-09-12 20:08:38 +00:00
|
|
|
|
|
|
|
// Train DRAM and switch to max frequency.
|
2019-12-11 09:22:11 +00:00
|
|
|
if (minerva_init())
|
|
|
|
h_cfg.errors |= ERR_SYSOLD_MTC;
|
2018-08-21 01:14:31 +00:00
|
|
|
|
2018-05-01 05:15:48 +00:00
|
|
|
display_init();
|
2018-08-21 01:26:14 +00:00
|
|
|
|
2020-06-13 15:16:29 +00:00
|
|
|
u32 *fb = display_init_framebuffer_pitch();
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_init_ctxt(fb, 720, 1280, 720);
|
2018-06-23 04:04:41 +00:00
|
|
|
|
2019-04-21 14:38:29 +00:00
|
|
|
gfx_con_init();
|
2018-05-01 05:15:48 +00:00
|
|
|
|
2018-09-18 21:01:42 +00:00
|
|
|
display_backlight_pwm_init();
|
|
|
|
//display_backlight_brightness(h_cfg.backlight, 1000);
|
2018-08-21 01:26:14 +00:00
|
|
|
|
2019-06-30 00:55:19 +00:00
|
|
|
// Overclock BPMP.
|
2019-12-07 00:01:29 +00:00
|
|
|
bpmp_clk_rate_set(BPMP_CLK_DEFAULT_BOOST);
|
2019-06-30 00:55:19 +00:00
|
|
|
|
2019-04-14 01:24:37 +00:00
|
|
|
// Check if we had a panic while in CFW.
|
|
|
|
secmon_exo_check_panic();
|
|
|
|
|
2019-04-16 17:09:04 +00:00
|
|
|
// Check if RCM is patched and protect from a possible brick.
|
2019-12-11 09:22:11 +00:00
|
|
|
_patched_rcm_protection();
|
2019-04-16 17:09:04 +00:00
|
|
|
|
2019-06-30 00:24:58 +00:00
|
|
|
// Load emuMMC configuration from SD.
|
|
|
|
emummc_load_cfg();
|
|
|
|
|
2019-12-11 09:22:11 +00:00
|
|
|
// Show library errors.
|
|
|
|
_show_errors();
|
|
|
|
|
2018-07-01 17:45:52 +00:00
|
|
|
// Load saved configuration and auto boot if enabled.
|
2019-12-11 09:22:11 +00:00
|
|
|
_auto_launch_firmware();
|
2018-06-06 10:29:38 +00:00
|
|
|
|
2019-06-30 00:49:33 +00:00
|
|
|
minerva_change_freq(FREQ_800);
|
|
|
|
|
2018-09-18 20:38:54 +00:00
|
|
|
while (true)
|
2019-04-13 23:30:14 +00:00
|
|
|
tui_do_menu(&menu_top);
|
2019-10-18 15:02:06 +00:00
|
|
|
|
2019-08-27 22:33:38 +00:00
|
|
|
// Halt BPMP if we managed to get out of execution.
|
2018-09-18 20:38:54 +00:00
|
|
|
while (true)
|
2019-08-27 22:33:38 +00:00
|
|
|
bpmp_halt();
|
2018-05-01 05:15:48 +00:00
|
|
|
}
|