1
0
Fork 0
mirror of https://github.com/CTCaer/hekate.git synced 2024-11-10 04:21:45 +00:00

nyx: move autorcm protection in nyx

This commit is contained in:
CTCaer 2021-10-15 16:34:15 +03:00
parent c4bf129d5e
commit d2595a00b6
2 changed files with 40 additions and 58 deletions

View file

@ -1099,47 +1099,6 @@ out:
nyx_load_run();
}
static void _patched_rcm_protection()
{
if (!h_cfg.rcm_patched || hw_get_chip_id() == GP_HIDREV_MAJOR_T210B01)
return;
// Check if AutoRCM is enabled and protect from a permanent brick.
if (!sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
return;
u8 *buf = (u8 *)malloc(0x200);
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_BOOT0);
u32 sector;
u8 corr_mod0, mod1;
// Get the correct RSA modulus byte masks.
nx_emmc_get_autorcm_masks(&corr_mod0, &mod1);
// Iterate BCTs.
for (u32 i = 0; i < 4; i++)
{
sector = 1 + (32 * i); // 0x4000 bct + 0x200 offset.
sdmmc_storage_read(&emmc_storage, sector, 1, buf);
// Check if 2nd byte of modulus is correct.
if (buf[0x11] != mod1)
continue;
// If AutoRCM is enabled, disable it.
if (buf[0x10] != corr_mod0)
{
buf[0x10] = corr_mod0;
sdmmc_storage_write(&emmc_storage, sector, 1, buf);
}
}
free(buf);
sdmmc_storage_end(&emmc_storage);
}
#define EXCP_EN_ADDR 0x4003FFFC
#define EXCP_MAGIC 0x30505645 // EVP0
#define EXCP_TYPE_ADDR 0x4003FFF8
@ -1172,6 +1131,9 @@ static void _show_errors()
panic_status <= 0xFF && panic_status != 0x20 && panic_status != 0x21)
h_cfg.errors |= ERR_PANIC_CODE;
// Check if we had a panic while in CFW.
secmon_exo_check_panic();
if (h_cfg.errors)
{
gfx_clear_grey(0x1B);
@ -1554,13 +1516,7 @@ void ipl_main()
// Overclock BPMP.
bpmp_clk_rate_set(h_cfg.t210b01 ? BPMP_CLK_DEFAULT_BOOST : BPMP_CLK_LOWER_BOOST);
// Check if we had a panic while in CFW.
secmon_exo_check_panic();
// Check if RCM is patched and protect from a possible brick.
_patched_rcm_protection();
// Show exception, library errors and L4T kernel panics.
// Show exceptions, HOS errors, library errors and L4T kernel panics.
_show_errors();
// Load saved configuration and auto boot if enabled.

View file

@ -35,6 +35,8 @@
#include <sec/se.h>
#include <soc/bpmp.h>
#include <soc/fuse.h>
#include <soc/hw_init.h>
#include <soc/t210.h>
#include "../storage/nx_emmc.h"
#include <storage/nx_sd.h>
#include <storage/sdmmc.h>
@ -67,8 +69,9 @@ static lv_obj_t *_create_container(lv_obj_t *parent)
return h1;
}
bool get_autorcm_status(bool change)
bool get_autorcm_status(bool toggle)
{
u32 sector;
u8 corr_mod0, mod1;
bool enabled = false;
@ -91,24 +94,47 @@ bool get_autorcm_status(bool change)
if (tempbuf[0x10] != corr_mod0)
enabled = true;
// Change autorcm status if requested.
if (change)
// Toggle autorcm status if requested.
if (toggle)
{
int i, sect = 0;
// Iterate BCTs.
for (i = 0; i < 4; i++)
for (u32 i = 0; i < 4; i++)
{
sect = (0x200 + (0x4000 * i)) / NX_EMMC_BLOCKSIZE;
sdmmc_storage_read(&emmc_storage, sect, 1, tempbuf);
sector = (0x200 + (0x4000 * i)) / NX_EMMC_BLOCKSIZE; // 0x4000 bct + 0x200 offset.
sdmmc_storage_read(&emmc_storage, sector, 1, tempbuf);
if (!enabled)
tempbuf[0x10] = 0;
else
tempbuf[0x10] = corr_mod0;
sdmmc_storage_write(&emmc_storage, sect, 1, tempbuf);
sdmmc_storage_write(&emmc_storage, sector, 1, tempbuf);
}
enabled = !(enabled);
enabled = !enabled;
}
// Check if RCM is patched and protect from a possible brick.
if (enabled && h_cfg.rcm_patched && hw_get_chip_id() != GP_HIDREV_MAJOR_T210B01)
{
// Iterate BCTs.
for (u32 i = 0; i < 4; i++)
{
sector = (0x200 + (0x4000 * i)) / NX_EMMC_BLOCKSIZE; // 0x4000 bct + 0x200 offset.
sdmmc_storage_read(&emmc_storage, sector, 1, tempbuf);
// Check if 2nd byte of modulus is correct.
if (tempbuf[0x11] != mod1)
continue;
// If AutoRCM is enabled, disable it.
if (tempbuf[0x10] != corr_mod0)
{
tempbuf[0x10] = corr_mod0;
sdmmc_storage_write(&emmc_storage, sector, 1, tempbuf);
}
}
enabled = false;
}
out: