2018-11-27 09:45:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 naehrwert
|
2022-01-20 11:15:04 +00:00
|
|
|
* Copyright (c) 2018-2022 CTCaer
|
2018-11-27 09:45:43 +00:00
|
|
|
* Copyright (c) 2018 Reisyukaku
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2022-01-15 22:04:34 +00:00
|
|
|
#include <bdk.h>
|
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
#include "fe_tools.h"
|
2020-06-14 13:45:45 +00:00
|
|
|
#include "../config.h"
|
2018-11-27 09:45:43 +00:00
|
|
|
#include "../gfx/tui.h"
|
|
|
|
#include "../hos/hos.h"
|
|
|
|
#include "../hos/pkg1.h"
|
|
|
|
#include "../hos/pkg2.h"
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <libs/fatfs/ff.h>
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2019-03-07 22:02:37 +00:00
|
|
|
extern boot_cfg_t b_cfg;
|
2018-11-27 09:45:43 +00:00
|
|
|
extern hekate_config h_cfg;
|
2019-02-23 22:59:33 +00:00
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
extern void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage);
|
|
|
|
|
2019-06-30 00:15:46 +00:00
|
|
|
#pragma GCC push_options
|
|
|
|
#pragma GCC optimize ("Os")
|
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
void dump_packages12()
|
|
|
|
{
|
|
|
|
if (!sd_mount())
|
|
|
|
return;
|
|
|
|
|
2019-04-21 14:37:12 +00:00
|
|
|
char path[64];
|
|
|
|
|
2021-10-01 12:45:25 +00:00
|
|
|
u8 *pkg1 = (u8 *)calloc(1, SZ_256K);
|
|
|
|
u8 *warmboot = (u8 *)calloc(1, SZ_256K);
|
|
|
|
u8 *secmon = (u8 *)calloc(1, SZ_256K);
|
|
|
|
u8 *loader = (u8 *)calloc(1, SZ_256K);
|
2018-11-27 09:45:43 +00:00
|
|
|
u8 *pkg2 = NULL;
|
2018-12-02 09:11:07 +00:00
|
|
|
u8 kb = 0;
|
|
|
|
|
|
|
|
tsec_ctxt_t tsec_ctxt;
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_clear_partial_grey(0x1B, 0, 1256);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2022-01-20 11:15:04 +00:00
|
|
|
if (!emmc_initialize(false))
|
2018-11-27 09:45:43 +00:00
|
|
|
{
|
|
|
|
EPRINTF("Failed to init eMMC.");
|
|
|
|
goto out_free;
|
|
|
|
}
|
2021-02-06 01:19:42 +00:00
|
|
|
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_BOOT0);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
// Read package1.
|
2022-01-20 11:15:04 +00:00
|
|
|
sdmmc_storage_read(&emmc_storage, 0x100000 / EMMC_BLOCKSIZE, SZ_256K / EMMC_BLOCKSIZE, pkg1);
|
2018-11-27 09:45:43 +00:00
|
|
|
const pkg1_id_t *pkg1_id = pkg1_identify(pkg1);
|
|
|
|
if (!pkg1_id)
|
|
|
|
{
|
2019-02-23 22:59:33 +00:00
|
|
|
EPRINTF("Unknown pkg1 version for reading\nTSEC firmware.");
|
2019-04-21 14:37:12 +00:00
|
|
|
// Dump package1.
|
2021-02-06 01:19:42 +00:00
|
|
|
emmcsn_path_impl(path, "/pkg1", "pkg1_enc.bin", &emmc_storage);
|
2021-10-01 12:45:25 +00:00
|
|
|
if (sd_save_to_file(pkg1, SZ_256K, path))
|
2019-04-21 14:37:12 +00:00
|
|
|
goto out_free;
|
|
|
|
gfx_puts("\nEnc pkg1 dumped to pkg1_enc.bin\n");
|
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
2018-12-02 09:11:07 +00:00
|
|
|
kb = pkg1_id->kb;
|
|
|
|
|
2021-08-28 14:53:14 +00:00
|
|
|
tsec_ctxt.fw = (void *)pkg1 + pkg1_id->tsec_off;
|
|
|
|
tsec_ctxt.pkg1 = (void *)pkg1;
|
|
|
|
tsec_ctxt.pkg11_off = pkg1_id->pkg11_off;
|
|
|
|
tsec_ctxt.secmon_base = pkg1_id->secmon_base;
|
2019-02-24 01:03:17 +00:00
|
|
|
|
2021-08-28 14:53:14 +00:00
|
|
|
// Read keyblob.
|
2022-01-20 11:15:04 +00:00
|
|
|
u8 *keyblob = (u8 *)calloc(EMMC_BLOCKSIZE, 1);
|
|
|
|
sdmmc_storage_read(&emmc_storage, 0x180000 / EMMC_BLOCKSIZE + kb, 1, keyblob);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2021-08-28 14:53:14 +00:00
|
|
|
// Decrypt.
|
|
|
|
hos_keygen(keyblob, kb, &tsec_ctxt, false, false);
|
|
|
|
free(keyblob);
|
2018-12-02 09:11:07 +00:00
|
|
|
|
|
|
|
if (kb <= KB_FIRMWARE_VERSION_600)
|
|
|
|
pkg1_decrypt(pkg1_id, pkg1);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2019-02-23 22:59:33 +00:00
|
|
|
if (kb <= KB_FIRMWARE_VERSION_620)
|
|
|
|
{
|
2020-07-04 18:32:36 +00:00
|
|
|
const u8 *sec_map = pkg1_unpack(warmboot, NULL, secmon, loader, pkg1_id, pkg1);
|
2020-07-14 20:29:48 +00:00
|
|
|
|
|
|
|
pk11_hdr_t *hdr_pk11 = (pk11_hdr_t *)(pkg1 + pkg1_id->pkg11_off + 0x20);
|
|
|
|
|
|
|
|
// Use correct sizes.
|
|
|
|
u32 sec_size[3] = { hdr_pk11->wb_size, hdr_pk11->ldr_size, hdr_pk11->sm_size };
|
|
|
|
for (u32 i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
if (sec_map[i] == PK11_SECTION_WB)
|
|
|
|
hdr_pk11->wb_size = sec_size[i];
|
|
|
|
else if (sec_map[i] == PK11_SECTION_LD)
|
|
|
|
hdr_pk11->ldr_size = sec_size[i];
|
|
|
|
else if (sec_map[i] == PK11_SECTION_SM)
|
|
|
|
hdr_pk11->sm_size = sec_size[i];
|
|
|
|
}
|
2019-10-18 15:02:06 +00:00
|
|
|
|
2019-02-23 22:59:33 +00:00
|
|
|
// Display info.
|
2022-07-01 01:37:57 +00:00
|
|
|
gfx_printf("%kNX Bootloader size: %k0x%05X\n\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT, hdr_pk11->ldr_size);
|
2019-10-18 15:02:06 +00:00
|
|
|
|
2022-07-01 01:37:57 +00:00
|
|
|
gfx_printf("%kSecure monitor addr: %k0x%05X\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT, pkg1_id->secmon_base);
|
|
|
|
gfx_printf("%kSecure monitor size: %k0x%05X\n\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT, hdr_pk11->sm_size);
|
2019-10-18 15:02:06 +00:00
|
|
|
|
2022-07-01 01:37:57 +00:00
|
|
|
gfx_printf("%kWarmboot addr: %k0x%05X\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT, pkg1_id->warmboot_base);
|
|
|
|
gfx_printf("%kWarmboot size: %k0x%05X\n\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT, hdr_pk11->wb_size);
|
2019-02-23 22:59:33 +00:00
|
|
|
|
|
|
|
// Dump package1.1.
|
2021-02-06 01:19:42 +00:00
|
|
|
emmcsn_path_impl(path, "/pkg1", "pkg1_decr.bin", &emmc_storage);
|
2021-10-01 12:45:25 +00:00
|
|
|
if (sd_save_to_file(pkg1, SZ_256K, path))
|
2019-02-23 22:59:33 +00:00
|
|
|
goto out_free;
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_puts("\npkg1 dumped to pkg1_decr.bin\n");
|
2019-10-18 15:02:06 +00:00
|
|
|
|
2019-02-23 22:59:33 +00:00
|
|
|
// Dump nxbootloader.
|
2021-02-06 01:19:42 +00:00
|
|
|
emmcsn_path_impl(path, "/pkg1", "nxloader.bin", &emmc_storage);
|
2020-07-14 20:29:48 +00:00
|
|
|
if (sd_save_to_file(loader, hdr_pk11->ldr_size, path))
|
2019-02-23 22:59:33 +00:00
|
|
|
goto out_free;
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_puts("NX Bootloader dumped to nxloader.bin\n");
|
2019-10-18 15:02:06 +00:00
|
|
|
|
2019-02-23 22:59:33 +00:00
|
|
|
// Dump secmon.
|
2021-02-06 01:19:42 +00:00
|
|
|
emmcsn_path_impl(path, "/pkg1", "secmon.bin", &emmc_storage);
|
2020-07-14 20:29:48 +00:00
|
|
|
if (sd_save_to_file(secmon, hdr_pk11->sm_size, path))
|
2019-02-23 22:59:33 +00:00
|
|
|
goto out_free;
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_puts("Secure Monitor dumped to secmon.bin\n");
|
2019-10-18 15:02:06 +00:00
|
|
|
|
2019-02-23 22:59:33 +00:00
|
|
|
// Dump warmboot.
|
2021-02-06 01:19:42 +00:00
|
|
|
emmcsn_path_impl(path, "/pkg1", "warmboot.bin", &emmc_storage);
|
2020-07-14 20:29:48 +00:00
|
|
|
if (sd_save_to_file(warmboot, hdr_pk11->wb_size, path))
|
2019-02-23 22:59:33 +00:00
|
|
|
goto out_free;
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_puts("Warmboot dumped to warmboot.bin\n\n\n");
|
2019-02-23 22:59:33 +00:00
|
|
|
}
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
// Dump package2.1.
|
2021-02-06 01:19:42 +00:00
|
|
|
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_GPP);
|
2018-11-27 09:45:43 +00:00
|
|
|
// Parse eMMC GPT.
|
|
|
|
LIST_INIT(gpt);
|
2022-01-20 11:15:04 +00:00
|
|
|
emmc_gpt_parse(&gpt);
|
2018-11-27 09:45:43 +00:00
|
|
|
// Find package2 partition.
|
2022-01-20 11:15:04 +00:00
|
|
|
emmc_part_t *pkg2_part = emmc_part_find(&gpt, "BCPKG2-1-Normal-Main");
|
2018-11-27 09:45:43 +00:00
|
|
|
if (!pkg2_part)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
// Read in package2 header and get package2 real size.
|
2022-01-20 11:15:04 +00:00
|
|
|
u8 *tmp = (u8 *)malloc(EMMC_BLOCKSIZE);
|
|
|
|
emmc_part_read(pkg2_part, 0x4000 / EMMC_BLOCKSIZE, 1, tmp);
|
2018-11-27 09:45:43 +00:00
|
|
|
u32 *hdr_pkg2_raw = (u32 *)(tmp + 0x100);
|
|
|
|
u32 pkg2_size = hdr_pkg2_raw[0] ^ hdr_pkg2_raw[2] ^ hdr_pkg2_raw[3];
|
|
|
|
free(tmp);
|
|
|
|
// Read in package2.
|
2022-01-20 11:15:04 +00:00
|
|
|
u32 pkg2_size_aligned = ALIGN(pkg2_size, EMMC_BLOCKSIZE);
|
2018-11-27 09:45:43 +00:00
|
|
|
pkg2 = malloc(pkg2_size_aligned);
|
2022-01-20 11:15:04 +00:00
|
|
|
emmc_part_read(pkg2_part, 0x4000 / EMMC_BLOCKSIZE,
|
|
|
|
pkg2_size_aligned / EMMC_BLOCKSIZE, pkg2);
|
2021-08-28 14:53:14 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
emmcsn_path_impl(path, "/pkg2", "pkg2_encr.bin", &emmc_storage);
|
|
|
|
if (sd_save_to_file(pkg2, pkg2_size_aligned, path))
|
|
|
|
goto out;
|
|
|
|
gfx_puts("\npkg2 dumped to pkg2_encr.bin\n");
|
|
|
|
#endif
|
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
// Decrypt package2 and parse KIP1 blobs in INI1 section.
|
2021-08-28 14:53:14 +00:00
|
|
|
pkg2_hdr_t *pkg2_hdr = pkg2_decrypt(pkg2, kb, false);
|
2019-04-23 00:38:35 +00:00
|
|
|
if (!pkg2_hdr)
|
|
|
|
{
|
|
|
|
gfx_printf("Pkg2 decryption failed!\n");
|
|
|
|
goto out;
|
|
|
|
}
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
// Display info.
|
2022-07-01 01:37:57 +00:00
|
|
|
gfx_printf("%kKernel size: %k0x%05X\n\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT, pkg2_hdr->sec_size[PKG2_SEC_KERNEL]);
|
|
|
|
gfx_printf("%kINI1 size: %k0x%05X\n\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT, pkg2_hdr->sec_size[PKG2_SEC_INI1]);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
// Dump pkg2.1.
|
2021-02-06 01:19:42 +00:00
|
|
|
emmcsn_path_impl(path, "/pkg2", "pkg2_decr.bin", &emmc_storage);
|
2018-11-27 09:45:43 +00:00
|
|
|
if (sd_save_to_file(pkg2, pkg2_hdr->sec_size[PKG2_SEC_KERNEL] + pkg2_hdr->sec_size[PKG2_SEC_INI1], path))
|
|
|
|
goto out;
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_puts("\npkg2 dumped to pkg2_decr.bin\n");
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
// Dump kernel.
|
2021-02-06 01:19:42 +00:00
|
|
|
emmcsn_path_impl(path, "/pkg2", "kernel.bin", &emmc_storage);
|
2018-11-27 09:45:43 +00:00
|
|
|
if (sd_save_to_file(pkg2_hdr->data, pkg2_hdr->sec_size[PKG2_SEC_KERNEL], path))
|
|
|
|
goto out;
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_puts("Kernel dumped to kernel.bin\n");
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
// Dump INI1.
|
2021-02-06 01:19:42 +00:00
|
|
|
emmcsn_path_impl(path, "/pkg2", "ini1.bin", &emmc_storage);
|
2019-04-21 14:37:12 +00:00
|
|
|
u32 ini1_off = pkg2_hdr->sec_size[PKG2_SEC_KERNEL];
|
|
|
|
u32 ini1_size = pkg2_hdr->sec_size[PKG2_SEC_INI1];
|
|
|
|
if (!ini1_size)
|
|
|
|
{
|
2019-09-12 20:37:00 +00:00
|
|
|
pkg2_get_newkern_info(pkg2_hdr->data);
|
|
|
|
ini1_off = pkg2_newkern_ini1_start;
|
|
|
|
ini1_size = pkg2_newkern_ini1_end - pkg2_newkern_ini1_start;
|
2019-04-21 14:37:12 +00:00
|
|
|
}
|
2020-04-14 14:40:41 +00:00
|
|
|
if (ini1_off)
|
|
|
|
{
|
|
|
|
if (sd_save_to_file(pkg2_hdr->data + ini1_off, ini1_size, path))
|
|
|
|
goto out;
|
|
|
|
gfx_puts("INI1 dumped to ini1.bin\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gfx_puts("Failed to dump INI1!\n");
|
2018-11-27 09:45:43 +00:00
|
|
|
goto out;
|
2020-04-14 14:40:41 +00:00
|
|
|
}
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_puts("\nDone. Press any key...\n");
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
out:
|
2022-01-20 11:15:04 +00:00
|
|
|
emmc_gpt_free(&gpt);
|
2018-11-27 09:45:43 +00:00
|
|
|
out_free:
|
|
|
|
free(pkg1);
|
|
|
|
free(secmon);
|
|
|
|
free(warmboot);
|
|
|
|
free(loader);
|
|
|
|
free(pkg2);
|
2021-02-06 01:19:42 +00:00
|
|
|
sdmmc_storage_end(&emmc_storage);
|
2020-06-13 15:32:40 +00:00
|
|
|
sd_end();
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2018-12-02 09:11:07 +00:00
|
|
|
if (kb >= KB_FIRMWARE_VERSION_620)
|
|
|
|
se_aes_key_clear(8);
|
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _toggle_autorcm(bool enable)
|
|
|
|
{
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_clear_partial_grey(0x1B, 0, 1256);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2022-01-20 11:15:04 +00:00
|
|
|
if (!emmc_initialize(false))
|
2018-11-27 09:45:43 +00:00
|
|
|
{
|
|
|
|
EPRINTF("Failed to init eMMC.");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 *tempbuf = (u8 *)malloc(0x200);
|
2021-02-06 01:19:42 +00:00
|
|
|
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_BOOT0);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
int i, sect = 0;
|
2020-12-26 14:38:21 +00:00
|
|
|
u8 corr_mod0, mod1;
|
2019-04-16 17:05:35 +00:00
|
|
|
|
2020-12-26 14:38:21 +00:00
|
|
|
// Get the correct RSA modulus byte masks.
|
|
|
|
nx_emmc_get_autorcm_masks(&corr_mod0, &mod1);
|
|
|
|
|
|
|
|
// Iterate BCTs.
|
2018-11-27 09:45:43 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
2022-01-20 11:15:04 +00:00
|
|
|
sect = (0x200 + (0x4000 * i)) / EMMC_BLOCKSIZE;
|
2021-02-06 01:19:42 +00:00
|
|
|
sdmmc_storage_read(&emmc_storage, sect, 1, tempbuf);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2020-12-26 14:38:21 +00:00
|
|
|
// Check if 2nd byte of modulus is correct.
|
|
|
|
if (tempbuf[0x11] != mod1)
|
|
|
|
continue;
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2020-12-26 14:38:21 +00:00
|
|
|
if (enable)
|
|
|
|
tempbuf[0x10] = 0;
|
2018-11-27 09:45:43 +00:00
|
|
|
else
|
2020-12-26 14:38:21 +00:00
|
|
|
tempbuf[0x10] = corr_mod0;
|
2021-02-06 01:19:42 +00:00
|
|
|
sdmmc_storage_write(&emmc_storage, sect, 1, tempbuf);
|
2018-11-27 09:45:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(tempbuf);
|
2021-02-06 01:19:42 +00:00
|
|
|
sdmmc_storage_end(&emmc_storage);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
if (enable)
|
2022-07-01 01:37:57 +00:00
|
|
|
gfx_printf("%kAutoRCM mode enabled!%k", TXT_CLR_ORANGE, TXT_CLR_DEFAULT);
|
2018-11-27 09:45:43 +00:00
|
|
|
else
|
2022-07-01 01:37:57 +00:00
|
|
|
gfx_printf("%kAutoRCM mode disabled!%k", TXT_CLR_GREENISH, TXT_CLR_DEFAULT);
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_printf("\n\nPress any key...\n");
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
btn_wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _enable_autorcm() { _toggle_autorcm(true); }
|
|
|
|
void _disable_autorcm() { _toggle_autorcm(false); }
|
|
|
|
|
|
|
|
void menu_autorcm()
|
|
|
|
{
|
2019-04-13 23:30:14 +00:00
|
|
|
gfx_clear_grey(0x1B);
|
|
|
|
gfx_con_setpos(0, 0);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2019-04-16 17:09:04 +00:00
|
|
|
if (h_cfg.rcm_patched)
|
|
|
|
{
|
2021-10-15 13:26:57 +00:00
|
|
|
WPRINTF("This device is RCM patched and the\nfunction is disabled to avoid BRICKS!\n");
|
2019-04-16 17:09:04 +00:00
|
|
|
btn_wait();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
// Do a simple check on the main BCT.
|
|
|
|
bool disabled = true;
|
|
|
|
|
2022-01-20 11:15:04 +00:00
|
|
|
if (!emmc_initialize(false))
|
2018-11-27 09:45:43 +00:00
|
|
|
{
|
|
|
|
EPRINTF("Failed to init eMMC.");
|
|
|
|
btn_wait();
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-12-26 14:38:21 +00:00
|
|
|
u8 mod0, mod1;
|
|
|
|
// Get the correct RSA modulus byte masks.
|
|
|
|
nx_emmc_get_autorcm_masks(&mod0, &mod1);
|
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
u8 *tempbuf = (u8 *)malloc(0x200);
|
2021-02-06 01:19:42 +00:00
|
|
|
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_BOOT0);
|
2022-01-20 11:15:04 +00:00
|
|
|
sdmmc_storage_read(&emmc_storage, 0x200 / EMMC_BLOCKSIZE, 1, tempbuf);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2020-12-26 14:38:21 +00:00
|
|
|
// Check if 2nd byte of modulus is correct.
|
|
|
|
if (tempbuf[0x11] == mod1)
|
|
|
|
if (tempbuf[0x10] != mod0)
|
2019-04-16 17:05:35 +00:00
|
|
|
disabled = false;
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
free(tempbuf);
|
2021-02-06 01:19:42 +00:00
|
|
|
sdmmc_storage_end(&emmc_storage);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
// Create AutoRCM menu.
|
|
|
|
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * 6);
|
|
|
|
|
|
|
|
ments[0].type = MENT_BACK;
|
|
|
|
ments[0].caption = "Back";
|
|
|
|
|
|
|
|
ments[1].type = MENT_CHGLINE;
|
|
|
|
|
|
|
|
ments[2].type = MENT_CAPTION;
|
|
|
|
ments[3].type = MENT_CHGLINE;
|
|
|
|
if (disabled)
|
|
|
|
{
|
|
|
|
ments[2].caption = "Status: Disabled!";
|
2022-07-01 01:37:57 +00:00
|
|
|
ments[2].color = TXT_CLR_GREENISH;
|
2018-11-27 09:45:43 +00:00
|
|
|
ments[4].caption = "Enable AutoRCM";
|
|
|
|
ments[4].handler = _enable_autorcm;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ments[2].caption = "Status: Enabled!";
|
2022-07-01 01:37:57 +00:00
|
|
|
ments[2].color = TXT_CLR_ORANGE;
|
2018-11-27 09:45:43 +00:00
|
|
|
ments[4].caption = "Disable AutoRCM";
|
|
|
|
ments[4].handler = _disable_autorcm;
|
|
|
|
}
|
|
|
|
ments[4].type = MENT_HDLR_RE;
|
2018-12-16 18:21:59 +00:00
|
|
|
ments[4].data = NULL;
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
memset(&ments[5], 0, sizeof(ment_t));
|
2021-01-11 19:39:44 +00:00
|
|
|
menu_t menu = {ments, "This corrupts BOOT0!", 0, 0};
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2019-04-13 23:30:14 +00:00
|
|
|
tui_do_menu(&menu);
|
2018-11-27 09:45:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-30 00:15:46 +00:00
|
|
|
#pragma GCC pop_options
|