hekate/Nyx: remove Sept completely
- remove any reference to sept and parsing of it - completely refactor and simplify keygen - use new Atmo tsec keygen for 7.0.0 and up - simplify all info/tools that depend on hos keygen and bis keys
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
|
||||
#include "gui.h"
|
||||
#include "fe_emummc_tools.h"
|
||||
#include "../hos/sept.h"
|
||||
#include "../config.h"
|
||||
#include <utils/ini.h>
|
||||
#include <libs/fatfs/diskio.h>
|
||||
@@ -752,133 +751,18 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part
|
||||
return 1;
|
||||
}
|
||||
|
||||
u32 kb = 0;
|
||||
u8 *tsec_fw = NULL;
|
||||
bool sept_error = false;
|
||||
|
||||
static lv_res_t _emummc_raw_check_sept_action(lv_obj_t *btns, const char * txt)
|
||||
{
|
||||
int btn_idx = lv_btnm_get_pressed(btns);
|
||||
|
||||
mbox_action(btns, txt);
|
||||
|
||||
if (btn_idx == 1 && !sept_error)
|
||||
{
|
||||
// Set boot cfg.
|
||||
b_cfg->autoboot = 0;
|
||||
b_cfg->autoboot_list = 0;
|
||||
b_cfg->extra_cfg = EXTRA_CFG_NYX_SEPT;
|
||||
b_cfg->sept = NYX_SEPT_EMUF;
|
||||
|
||||
sd_mount();
|
||||
reboot_to_sept(tsec_fw, kb);
|
||||
}
|
||||
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
static int _emummc_raw_check_sept(emmc_tool_gui_t *gui, u32 resized_count)
|
||||
static int _emummc_raw_derive_bis_keys(emmc_tool_gui_t *gui, u32 resized_count)
|
||||
{
|
||||
if (!resized_count)
|
||||
return 1;
|
||||
|
||||
bool sept_needed = false;
|
||||
sept_error = false;
|
||||
tsec_fw = NULL;
|
||||
bool error = false;
|
||||
|
||||
char *txt_buf = (char *)malloc(0x4000);
|
||||
txt_buf[0] = 0;
|
||||
|
||||
// Read package1.
|
||||
static const u32 BOOTLOADER_SIZE = 0x40000;
|
||||
static const u32 BOOTLOADER_MAIN_OFFSET = 0x100000;
|
||||
static const u32 BOOTLOADER_BACKUP_OFFSET = 0x140000;
|
||||
static const u32 HOS_KEYBLOBS_OFFSET = 0x180000;
|
||||
|
||||
u32 bootloader_offset = BOOTLOADER_MAIN_OFFSET;
|
||||
u32 pk1_offset = h_cfg.t210b01 ? sizeof(bl_hdr_t210b01_t) : 0; // Skip T210B01 OEM header.
|
||||
u8 *pkg1 = (u8 *)malloc(BOOTLOADER_SIZE);
|
||||
|
||||
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_BOOT0);
|
||||
|
||||
try_load:
|
||||
sdmmc_storage_read(&emmc_storage, bootloader_offset / NX_EMMC_BLOCKSIZE, BOOTLOADER_SIZE / NX_EMMC_BLOCKSIZE, pkg1);
|
||||
|
||||
char *build_date = malloc(32);
|
||||
const pkg1_id_t *pkg1_id = pkg1_identify(pkg1 + pk1_offset, build_date);
|
||||
|
||||
s_printf(txt_buf + strlen(txt_buf), "#00DDFF Found pkg1 ('%s')#\n", build_date);
|
||||
free(build_date);
|
||||
|
||||
if (!pkg1_id)
|
||||
{
|
||||
strcat(txt_buf, "#FFDD00 Unknown pkg1 version!#\n");
|
||||
// Try backup bootloader.
|
||||
if (bootloader_offset != BOOTLOADER_BACKUP_OFFSET)
|
||||
{
|
||||
strcat(txt_buf, "Trying backup bootloader...\n");
|
||||
bootloader_offset = BOOTLOADER_BACKUP_OFFSET;
|
||||
goto try_load;
|
||||
}
|
||||
|
||||
sept_error = true;
|
||||
goto out;
|
||||
}
|
||||
|
||||
kb = pkg1_id->kb;
|
||||
|
||||
// Skip if Mariko.
|
||||
if (h_cfg.t210b01)
|
||||
goto bis_derivation;
|
||||
|
||||
tsec_ctxt_t tsec_ctxt;
|
||||
tsec_ctxt.fw = (u8 *)pkg1 + pkg1_id->tsec_off;
|
||||
tsec_ctxt.pkg1 = pkg1;
|
||||
tsec_ctxt.pkg11_off = pkg1_id->pkg11_off;
|
||||
tsec_ctxt.secmon_base = pkg1_id->secmon_base;
|
||||
|
||||
// Get keys.
|
||||
hos_eks_get();
|
||||
if (kb >= KB_FIRMWARE_VERSION_700 && !h_cfg.sept_run)
|
||||
{
|
||||
u32 key_idx = 0;
|
||||
if (kb >= KB_FIRMWARE_VERSION_810)
|
||||
key_idx = 1;
|
||||
|
||||
if (h_cfg.eks && h_cfg.eks->enabled[key_idx] >= kb)
|
||||
h_cfg.sept_run = true;
|
||||
else
|
||||
{
|
||||
// Check that BCT is proper so sept can run.
|
||||
u8 *bct_bldr = (u8 *)calloc(1, 512);
|
||||
sdmmc_storage_read(&emmc_storage, 0x2200 / NX_EMMC_BLOCKSIZE, 1, bct_bldr);
|
||||
u32 bootloader_entrypoint = *(u32 *)&bct_bldr[0x144];
|
||||
free(bct_bldr);
|
||||
if (bootloader_entrypoint > SEPT_PRI_ENTRY)
|
||||
{
|
||||
strcpy(txt_buf, "#FFDD00 Failed to run sept because main BCT is improper!#\n"
|
||||
"#FFDD00 Run sept with proper BCT at least once to cache keys.#\n");
|
||||
sept_error = true;
|
||||
goto out;
|
||||
}
|
||||
|
||||
// Set TSEC fw.
|
||||
tsec_fw = (u8 *)tsec_ctxt.fw;
|
||||
|
||||
sept_needed = true;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
bis_derivation:;
|
||||
// Read the correct keyblob.
|
||||
u8 *keyblob = (u8 *)calloc(NX_EMMC_BLOCKSIZE, 1);
|
||||
sdmmc_storage_read(&emmc_storage, HOS_KEYBLOBS_OFFSET / NX_EMMC_BLOCKSIZE + kb, 1, keyblob);
|
||||
|
||||
// Generate BIS keys
|
||||
hos_bis_keygen(keyblob, kb, &tsec_ctxt);
|
||||
|
||||
free(keyblob);
|
||||
// Generate BIS keys.
|
||||
hos_bis_keygen();
|
||||
|
||||
u8 *cal0_buf = malloc(0x10000);
|
||||
|
||||
@@ -894,32 +778,25 @@ bis_derivation:;
|
||||
|
||||
nx_emmc_cal0_t *cal0 = (nx_emmc_cal0_t *)cal0_buf;
|
||||
|
||||
// If successful, save BIS keys.
|
||||
// Check keys validity.
|
||||
if (memcmp(&cal0->magic, "CAL0", 4))
|
||||
{
|
||||
hos_bis_keys_clear();
|
||||
hos_eks_bis_clear();
|
||||
// Clear EKS keys.
|
||||
hos_eks_clear(KB_FIRMWARE_VERSION_MAX);
|
||||
|
||||
strcpy(txt_buf, "#FFDD00 BIS keys validation failed!#\n");
|
||||
sept_error = true;
|
||||
error = true;
|
||||
}
|
||||
else
|
||||
hos_eks_bis_save();
|
||||
|
||||
free(cal0_buf);
|
||||
|
||||
out:
|
||||
// Check if sept is not needed.
|
||||
if (!sept_needed)
|
||||
free(pkg1);
|
||||
|
||||
if (sept_needed || sept_error)
|
||||
if (error)
|
||||
{
|
||||
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_style(dark_bg, &mbox_darken);
|
||||
lv_obj_set_size(dark_bg, LV_HOR_RES, LV_VER_RES);
|
||||
|
||||
static const char * mbox_btn_map[] = { "\211", "\222Launch", "\222Close", "\211", "" };
|
||||
static const char * mbox_btn_map2[] = { "\211", "\222Close", "\211", "" };
|
||||
static const char * mbox_btn_map[] = { "\211", "\222Close", "\211", "" };
|
||||
lv_obj_t * mbox = lv_mbox_create(dark_bg, NULL);
|
||||
lv_mbox_set_recolor_text(mbox, true);
|
||||
lv_obj_set_width(mbox, LV_HOR_RES / 9 * 5);
|
||||
@@ -932,18 +809,8 @@ out:
|
||||
lv_label_set_style(lb_desc, &monospace_text);
|
||||
lv_obj_set_width(lb_desc, LV_HOR_RES / 9 * 4);
|
||||
|
||||
if (sept_error)
|
||||
{
|
||||
lv_label_set_text(lb_desc, txt_buf);
|
||||
lv_mbox_add_btns(mbox, mbox_btn_map2, _emummc_raw_check_sept_action);
|
||||
free(pkg1);
|
||||
}
|
||||
else
|
||||
{
|
||||
lv_label_set_text(lb_desc, "Sept needs to launch in order to generate keys\nneeded for emuMMC resizing.\n"
|
||||
"After that enter this menu again.");
|
||||
lv_mbox_add_btns(mbox, mbox_btn_map, _emummc_raw_check_sept_action);
|
||||
}
|
||||
lv_label_set_text(lb_desc, txt_buf);
|
||||
lv_mbox_add_btns(mbox, mbox_btn_map, mbox_action);
|
||||
|
||||
lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_obj_set_top(mbox, true);
|
||||
@@ -953,7 +820,7 @@ out:
|
||||
return 0;
|
||||
}
|
||||
|
||||
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_GPP);
|
||||
free(txt_buf);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -984,7 +851,7 @@ void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 r
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!_emummc_raw_check_sept(gui, resized_count))
|
||||
if (!_emummc_raw_derive_bis_keys(gui, resized_count))
|
||||
{
|
||||
s_printf(gui->txt_buf, "#FFDD00 For formatting USER partition,#\n#FFDD00 BIS keys are needed!#\n");
|
||||
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
|
||||
|
||||
@@ -1868,7 +1868,7 @@ static void _create_tab_home(lv_theme_t *th, lv_obj_t *parent)
|
||||
label_btn = lv_label_create(btn_emummc, label_btn);
|
||||
s_printf(btn_colored_text, "%s%s", text_color, " "SYMBOL_LIST"#");
|
||||
lv_label_set_text(label_btn, btn_colored_text);
|
||||
lv_btn_set_action(btn_emummc, LV_BTN_ACTION_CLICK,create_win_emummc_tools);
|
||||
lv_btn_set_action(btn_emummc, LV_BTN_ACTION_CLICK, create_win_emummc_tools);
|
||||
lv_btn_set_layout(btn_emummc, LV_LAYOUT_OFF);
|
||||
lv_obj_align(label_btn, NULL, LV_ALIGN_CENTER, 0, -28);
|
||||
lv_obj_set_pos(btn_emummc, 959, 160);
|
||||
@@ -2208,28 +2208,8 @@ static void _nyx_main_menu(lv_theme_t * th)
|
||||
// Option save button.
|
||||
lv_tabview_set_tab_load_action(tv, _show_hide_save_button);
|
||||
|
||||
// If we rebooted to run sept for dumping, lunch dump immediately.
|
||||
if (nyx_str->cfg & NYX_CFG_SEPT)
|
||||
{
|
||||
u32 type = nyx_str->cfg >> 24;
|
||||
nyx_str->cfg &= ~(NYX_CFG_SEPT | NYX_CFG_EXTRA);
|
||||
|
||||
if (type == NYX_SEPT_DUMP)
|
||||
{
|
||||
lv_task_t *task_run_dump = lv_task_create(sept_run_dump, LV_TASK_ONESHOT, LV_TASK_PRIO_MID, NULL);
|
||||
lv_task_once(task_run_dump);
|
||||
}
|
||||
else if (type == NYX_SEPT_CAL0)
|
||||
{
|
||||
lv_task_t *task_run_cal0 = lv_task_create(sept_run_cal0, LV_TASK_ONESHOT, LV_TASK_PRIO_LOWEST, NULL);
|
||||
lv_task_once(task_run_cal0);
|
||||
}
|
||||
else if (type == NYX_SEPT_EMUF)
|
||||
{
|
||||
// TODO: Maybe automatically relaunch emuMMC creation in the future.
|
||||
}
|
||||
}
|
||||
else if (nyx_str->cfg & NYX_CFG_UMS)
|
||||
// Check if Nyx was launched with a function set.
|
||||
if (nyx_str->cfg & NYX_CFG_UMS)
|
||||
{
|
||||
nyx_str->cfg &= ~(NYX_CFG_UMS);
|
||||
lv_task_t *task_run_ums = lv_task_create(nyx_run_ums, LV_TASK_ONESHOT, LV_TASK_PRIO_MID, (void *)&nyx_str->cfg);
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include "../hos/pkg1.h"
|
||||
#include "../hos/pkg2.h"
|
||||
#include "../hos/hos.h"
|
||||
#include "../hos/sept.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <mem/heap.h>
|
||||
#include <sec/se.h>
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "../config.h"
|
||||
#include "../hos/hos.h"
|
||||
#include "../hos/pkg1.h"
|
||||
#include "../hos/sept.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <input/touch.h>
|
||||
#include <mem/emc.h>
|
||||
@@ -302,108 +301,16 @@ static lv_res_t _create_mbox_cal0(lv_obj_t *btn)
|
||||
|
||||
sd_mount();
|
||||
|
||||
// Read package1.
|
||||
static const u32 BOOTLOADER_SIZE = 0x40000;
|
||||
static const u32 BOOTLOADER_MAIN_OFFSET = 0x100000;
|
||||
static const u32 BOOTLOADER_BACKUP_OFFSET = 0x140000;
|
||||
static const u32 HOS_KEYBLOBS_OFFSET = 0x180000;
|
||||
|
||||
u8 kb = 0;
|
||||
u32 bootloader_offset = BOOTLOADER_MAIN_OFFSET;
|
||||
u32 pk1_offset = h_cfg.t210b01 ? sizeof(bl_hdr_t210b01_t) : 0; // Skip T210B01 OEM header.
|
||||
u8 *pkg1 = (u8 *)malloc(BOOTLOADER_SIZE);
|
||||
|
||||
// Init eMMC.
|
||||
if (!sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
|
||||
{
|
||||
lv_label_set_text(lb_desc, "#FFDD00 Failed to init eMMC!#");
|
||||
|
||||
goto out;
|
||||
}
|
||||
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_BOOT0);
|
||||
|
||||
try_load:
|
||||
sdmmc_storage_read(&emmc_storage, bootloader_offset / NX_EMMC_BLOCKSIZE, BOOTLOADER_SIZE / NX_EMMC_BLOCKSIZE, pkg1);
|
||||
|
||||
char *build_date = malloc(32);
|
||||
const pkg1_id_t *pkg1_id = pkg1_identify(pkg1 + pk1_offset, build_date);
|
||||
|
||||
s_printf(txt_buf + strlen(txt_buf), "#00DDFF Found pkg1 ('%s')#\n", build_date);
|
||||
free(build_date);
|
||||
|
||||
if (!pkg1_id)
|
||||
{
|
||||
strcat(txt_buf, "#FFDD00 Unknown pkg1 version!#\n");
|
||||
// Try backup bootloader.
|
||||
if (bootloader_offset != BOOTLOADER_BACKUP_OFFSET)
|
||||
{
|
||||
strcat(txt_buf, "Trying backup bootloader...\n");
|
||||
bootloader_offset = BOOTLOADER_BACKUP_OFFSET;
|
||||
goto try_load;
|
||||
}
|
||||
lv_label_set_text(lb_desc, txt_buf);
|
||||
|
||||
goto out;
|
||||
}
|
||||
|
||||
kb = pkg1_id->kb;
|
||||
|
||||
// Skip if Mariko.
|
||||
if (h_cfg.t210b01)
|
||||
goto t210b01;
|
||||
|
||||
tsec_ctxt_t tsec_ctxt;
|
||||
tsec_ctxt.fw = (u8 *)pkg1 + pkg1_id->tsec_off;
|
||||
tsec_ctxt.pkg1 = pkg1;
|
||||
tsec_ctxt.pkg11_off = pkg1_id->pkg11_off;
|
||||
tsec_ctxt.secmon_base = pkg1_id->secmon_base;
|
||||
|
||||
// Get keys.
|
||||
hos_eks_get();
|
||||
if (kb >= KB_FIRMWARE_VERSION_700 && !h_cfg.sept_run)
|
||||
{
|
||||
u32 key_idx = 0;
|
||||
if (kb >= KB_FIRMWARE_VERSION_810)
|
||||
key_idx = 1;
|
||||
|
||||
if (h_cfg.eks && h_cfg.eks->enabled[key_idx] >= kb)
|
||||
h_cfg.sept_run = true;
|
||||
else
|
||||
{
|
||||
// Check that BCT is proper so sept can run.
|
||||
u8 *bct_bldr = (u8 *)calloc(1, 512);
|
||||
sdmmc_storage_read(&emmc_storage, 0x2200 / NX_EMMC_BLOCKSIZE, 1, bct_bldr);
|
||||
u32 bootloader_entrypoint = *(u32 *)&bct_bldr[0x144];
|
||||
free(bct_bldr);
|
||||
if (bootloader_entrypoint > SEPT_PRI_ENTRY)
|
||||
{
|
||||
lv_label_set_text(lb_desc, "#FFDD00 Main BCT is improper! Failed to run sept.#\n"
|
||||
"#FFDD00 Run sept with proper BCT at least once#\n#FFDD00 to cache keys.#\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
// Set boot cfg.
|
||||
b_cfg->autoboot = 0;
|
||||
b_cfg->autoboot_list = 0;
|
||||
b_cfg->extra_cfg = EXTRA_CFG_NYX_SEPT;
|
||||
b_cfg->sept = NYX_SEPT_CAL0;
|
||||
|
||||
if (!reboot_to_sept((u8 *)tsec_ctxt.fw, kb))
|
||||
{
|
||||
lv_label_set_text(lb_desc, "#FFDD00 Failed to run sept#\n");
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t210b01:;
|
||||
// Read the correct keyblob.
|
||||
u8 *keyblob = (u8 *)calloc(NX_EMMC_BLOCKSIZE, 1);
|
||||
sdmmc_storage_read(&emmc_storage, HOS_KEYBLOBS_OFFSET / NX_EMMC_BLOCKSIZE + kb, 1, keyblob);
|
||||
|
||||
// Generate BIS keys
|
||||
hos_bis_keygen(keyblob, kb, &tsec_ctxt);
|
||||
|
||||
free(keyblob);
|
||||
hos_bis_keygen();
|
||||
|
||||
if (!cal0_buf)
|
||||
cal0_buf = malloc(0x10000);
|
||||
@@ -418,24 +325,23 @@ t210b01:;
|
||||
nx_emmc_bis_end();
|
||||
nx_emmc_gpt_free(&gpt);
|
||||
|
||||
// Clear BIS keys slots and reinstate SBK.
|
||||
// Clear BIS keys slots.
|
||||
hos_bis_keys_clear();
|
||||
|
||||
nx_emmc_cal0_t *cal0 = (nx_emmc_cal0_t *)cal0_buf;
|
||||
|
||||
// If successful, save BIS keys.
|
||||
// Check keys validity.
|
||||
if (memcmp(&cal0->magic, "CAL0", 4))
|
||||
{
|
||||
free(cal0_buf);
|
||||
cal0_buf = NULL;
|
||||
|
||||
hos_eks_bis_clear();
|
||||
// Clear EKS keys.
|
||||
hos_eks_clear(KB_FIRMWARE_VERSION_MAX);
|
||||
|
||||
lv_label_set_text(lb_desc, "#FFDD00 CAL0 is corrupt or wrong keys!#\n");
|
||||
goto out;
|
||||
}
|
||||
else
|
||||
hos_eks_bis_save();
|
||||
|
||||
u32 hash[8];
|
||||
se_calc_sha256_oneshot(hash, (u8 *)cal0 + 0x40, cal0->body_size);
|
||||
@@ -526,7 +432,6 @@ t210b01:;
|
||||
lv_label_set_text(lb_desc, txt_buf);
|
||||
|
||||
out:
|
||||
free(pkg1);
|
||||
free(txt_buf);
|
||||
sd_unmount();
|
||||
sdmmc_storage_end(&emmc_storage);
|
||||
@@ -1042,11 +947,6 @@ static lv_res_t _create_window_fuses_info_status(lv_obj_t *btn)
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
void sept_run_cal0(void *param)
|
||||
{
|
||||
_create_window_fuses_info_status(NULL);
|
||||
}
|
||||
|
||||
static char *ipatches_txt;
|
||||
static void _ipatch_process(u32 offset, u32 value)
|
||||
{
|
||||
@@ -1098,7 +998,7 @@ static lv_res_t _create_window_tsec_keys_status(lv_obj_t *btn)
|
||||
{
|
||||
u32 retries = 0;
|
||||
|
||||
tsec_ctxt_t tsec_ctxt;
|
||||
tsec_ctxt_t tsec_ctxt = {0};
|
||||
|
||||
lv_obj_t *win = nyx_create_standard_window(SYMBOL_CHIP" TSEC Keys");
|
||||
|
||||
@@ -1173,28 +1073,35 @@ try_load:
|
||||
tsec_ctxt.secmon_base = pkg1_id->secmon_base;
|
||||
|
||||
if (pkg1_id->kb <= KB_FIRMWARE_VERSION_600)
|
||||
{
|
||||
tsec_ctxt.size = 0xF00;
|
||||
else if (pkg1_id->kb == KB_FIRMWARE_VERSION_620)
|
||||
tsec_ctxt.size = 0x2900;
|
||||
else if (pkg1_id->kb == KB_FIRMWARE_VERSION_700)
|
||||
{
|
||||
tsec_ctxt.size = 0x3000;
|
||||
// Exit after TSEC key generation.
|
||||
*((vu16 *)((u32)tsec_ctxt.fw + 0x2DB5)) = 0x02F8;
|
||||
tsec_ctxt.type = TSEC_FW_TYPE_OLD;
|
||||
}
|
||||
else
|
||||
tsec_ctxt.size = 0x3300;
|
||||
|
||||
if (pkg1_id->kb == KB_FIRMWARE_VERSION_620)
|
||||
else if (pkg1_id->kb == KB_FIRMWARE_VERSION_620)
|
||||
{
|
||||
tsec_ctxt.size = 0x2900;
|
||||
tsec_ctxt.type = TSEC_FW_TYPE_EMU;
|
||||
|
||||
u8 *tsec_paged = (u8 *)page_alloc(3);
|
||||
memcpy(tsec_paged, (void *)tsec_ctxt.fw, tsec_ctxt.size);
|
||||
tsec_ctxt.fw = tsec_paged;
|
||||
}
|
||||
else if (pkg1_id->kb == KB_FIRMWARE_VERSION_700)
|
||||
{
|
||||
tsec_ctxt.size = 0x3000;
|
||||
tsec_ctxt.type = TSEC_FW_TYPE_NEW;
|
||||
// Exit after TSEC key generation.
|
||||
*((vu16 *)((u32)tsec_ctxt.fw + 0x2DB5)) = 0x02F8;
|
||||
}
|
||||
else
|
||||
{
|
||||
tsec_ctxt.size = 0x3300;
|
||||
tsec_ctxt.type = TSEC_FW_TYPE_NEW;
|
||||
}
|
||||
|
||||
int res = 0;
|
||||
|
||||
while (tsec_query((u8 *)tsec_keys, pkg1_id->kb, &tsec_ctxt) < 0)
|
||||
while (tsec_query((u8 *)tsec_keys, &tsec_ctxt) < 0)
|
||||
{
|
||||
memset(tsec_keys, 0x00, 0x20);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2019 CTCaer
|
||||
* Copyright (c) 2018-2021 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include <libs/lvgl/lvgl.h>
|
||||
|
||||
void sept_run_cal0(void *param);
|
||||
void create_tab_info(lv_theme_t *th, lv_obj_t *parent);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "../hos/pkg1.h"
|
||||
#include "../hos/pkg2.h"
|
||||
#include "../hos/hos.h"
|
||||
#include "../hos/sept.h"
|
||||
#include <input/touch.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <mem/heap.h>
|
||||
@@ -1138,62 +1137,19 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn)
|
||||
|
||||
kb = pkg1_id->kb;
|
||||
|
||||
if (!h_cfg.se_keygen_done)
|
||||
{
|
||||
tsec_ctxt_t tsec_ctxt;
|
||||
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;
|
||||
tsec_ctxt_t tsec_ctxt = {0};
|
||||
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;
|
||||
|
||||
hos_eks_get();
|
||||
// Read keyblob.
|
||||
u8 *keyblob = (u8 *)calloc(NX_EMMC_BLOCKSIZE, 1);
|
||||
sdmmc_storage_read(&emmc_storage, HOS_KEYBLOBS_OFFSET / NX_EMMC_BLOCKSIZE + kb, 1, keyblob);
|
||||
|
||||
if (!h_cfg.t210b01 && kb >= KB_FIRMWARE_VERSION_700 && !h_cfg.sept_run)
|
||||
{
|
||||
u32 key_idx = 0;
|
||||
if (kb >= KB_FIRMWARE_VERSION_810)
|
||||
key_idx = 1;
|
||||
|
||||
if (h_cfg.eks && h_cfg.eks->enabled[key_idx] >= kb)
|
||||
h_cfg.sept_run = true;
|
||||
else
|
||||
{
|
||||
// Check that BCT is proper so sept can run.
|
||||
u8 *bct_bldr = (u8 *)calloc(1, 512);
|
||||
sdmmc_storage_read(&emmc_storage, 0x2200 / NX_EMMC_BLOCKSIZE, 1, bct_bldr);
|
||||
u32 bootloader_entrypoint = *(u32 *)&bct_bldr[0x144];
|
||||
free(bct_bldr);
|
||||
if (bootloader_entrypoint > SEPT_PRI_ENTRY)
|
||||
{
|
||||
lv_label_set_text(lb_desc, "#FFDD00 Failed to run sept because main BCT is improper!#\n"
|
||||
"#FFDD00 Run sept with proper BCT at least once to cache keys.#\n");
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
// Set boot cfg.
|
||||
b_cfg->autoboot = 0;
|
||||
b_cfg->autoboot_list = 0;
|
||||
b_cfg->extra_cfg = EXTRA_CFG_NYX_SEPT;
|
||||
b_cfg->sept = NYX_SEPT_DUMP;
|
||||
|
||||
if (!reboot_to_sept((u8 *)tsec_ctxt.fw, kb))
|
||||
{
|
||||
lv_label_set_text(lb_desc, "#FFDD00 Failed to run sept#\n");
|
||||
goto out_free;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read keyblob.
|
||||
u8 *keyblob = (u8 *)calloc(NX_EMMC_BLOCKSIZE, 1);
|
||||
sdmmc_storage_read(&emmc_storage, HOS_KEYBLOBS_OFFSET / NX_EMMC_BLOCKSIZE + kb, 1, keyblob);
|
||||
|
||||
// Decrypt.
|
||||
hos_keygen(keyblob, kb, &tsec_ctxt);
|
||||
if (kb <= KB_FIRMWARE_VERSION_600)
|
||||
h_cfg.se_keygen_done = 1;
|
||||
free(keyblob);
|
||||
}
|
||||
// Decrypt.
|
||||
hos_keygen(keyblob, kb, &tsec_ctxt);
|
||||
free(keyblob);
|
||||
|
||||
if (h_cfg.t210b01 || kb <= KB_FIRMWARE_VERSION_600)
|
||||
{
|
||||
@@ -1316,13 +1272,11 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn)
|
||||
lv_label_set_text(lb_desc, txt_buf);
|
||||
manual_system_maintenance(true);
|
||||
|
||||
// Clear EKS slot, in case something went wrong with sept keygen.
|
||||
// Clear EKS slot, in case something went wrong with tsec keygen.
|
||||
hos_eks_clear(kb);
|
||||
|
||||
goto out;
|
||||
}
|
||||
else if (kb >= KB_FIRMWARE_VERSION_700)
|
||||
hos_eks_save(kb); // Save EKS slot if it doesn't exist.
|
||||
|
||||
// Display info.
|
||||
s_printf(txt_buf + strlen(txt_buf),
|
||||
@@ -1429,11 +1383,6 @@ out_end:
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
void sept_run_dump(void *param)
|
||||
{
|
||||
_create_window_dump_pk12_tool(NULL);
|
||||
}
|
||||
|
||||
static void _create_tab_tools_emmc_pkg12(lv_theme_t *th, lv_obj_t *parent)
|
||||
{
|
||||
lv_page_set_scrl_layout(parent, LV_LAYOUT_PRETTY);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018-2019 CTCaer
|
||||
* Copyright (c) 2018-2021 CTCaer
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
@@ -23,7 +23,6 @@ extern lv_obj_t *ums_mbox;
|
||||
|
||||
void create_tab_tools(lv_theme_t *th, lv_obj_t *parent);
|
||||
void nyx_run_ums(void *param);
|
||||
void sept_run_dump(void *param);
|
||||
bool get_autorcm_status(bool change);
|
||||
lv_res_t action_ums_sd(lv_obj_t *btn);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user