hekate/nyx: use size defines where applicable

This commit is contained in:
CTCaer
2021-10-01 15:45:25 +03:00
parent c801ef8dda
commit 91b08f10fd
12 changed files with 90 additions and 90 deletions

View File

@@ -53,10 +53,10 @@ void dump_packages12()
char path[64];
u8 *pkg1 = (u8 *)calloc(1, 0x40000);
u8 *warmboot = (u8 *)calloc(1, 0x40000);
u8 *secmon = (u8 *)calloc(1, 0x40000);
u8 *loader = (u8 *)calloc(1, 0x40000);
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);
u8 *pkg2 = NULL;
u8 kb = 0;
@@ -73,14 +73,14 @@ void dump_packages12()
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_BOOT0);
// Read package1.
sdmmc_storage_read(&emmc_storage, 0x100000 / NX_EMMC_BLOCKSIZE, 0x40000 / NX_EMMC_BLOCKSIZE, pkg1);
sdmmc_storage_read(&emmc_storage, 0x100000 / NX_EMMC_BLOCKSIZE, SZ_256K / NX_EMMC_BLOCKSIZE, pkg1);
const pkg1_id_t *pkg1_id = pkg1_identify(pkg1);
if (!pkg1_id)
{
EPRINTF("Unknown pkg1 version for reading\nTSEC firmware.");
// Dump package1.
emmcsn_path_impl(path, "/pkg1", "pkg1_enc.bin", &emmc_storage);
if (sd_save_to_file(pkg1, 0x40000, path))
if (sd_save_to_file(pkg1, SZ_256K, path))
goto out_free;
gfx_puts("\nEnc pkg1 dumped to pkg1_enc.bin\n");
@@ -134,7 +134,7 @@ void dump_packages12()
// Dump package1.1.
emmcsn_path_impl(path, "/pkg1", "pkg1_decr.bin", &emmc_storage);
if (sd_save_to_file(pkg1, 0x40000, path))
if (sd_save_to_file(pkg1, SZ_256K, path))
goto out_free;
gfx_puts("\npkg1 dumped to pkg1_decr.bin\n");

View File

@@ -285,8 +285,8 @@ static void _hos_eks_save()
}
// Get keys.
u8 *keys = (u8 *)calloc(0x2000, 1);
se_get_aes_keys(keys + 0x1000, keys, SE_KEY_128_SIZE);
u8 *keys = (u8 *)calloc(SZ_4K, 2);
se_get_aes_keys(keys + SZ_4K, keys, SE_KEY_128_SIZE);
// Set magic and personalized info.
h_cfg.eks->magic = HOS_EKS_MAGIC;
@@ -611,7 +611,7 @@ int hos_keygen(void *keyblob, u32 kb, tsec_ctxt_t *tsec_ctxt, bool stock, bool i
static int _read_emmc_pkg1(launch_ctxt_t *ctxt)
{
const u32 BOOTLOADER_SIZE = 0x40000;
const u32 BOOTLOADER_SIZE = SZ_256K;
const u32 BOOTLOADER_MAIN_OFFSET = 0x100000;
const u32 BOOTLOADER_BACKUP_OFFSET = 0x140000;
const u32 HOS_KEYBLOBS_OFFSET = 0x180000;
@@ -685,7 +685,7 @@ DPRINTF("Parsed GPT\n");
goto out;
// Read in package2 header and get package2 real size.
const u32 BCT_SIZE = 0x4000;
const u32 BCT_SIZE = SZ_16K;
bctBuf = (u8 *)malloc(BCT_SIZE);
nx_emmc_part_read(&emmc_storage, pkg2_part, BCT_SIZE / NX_EMMC_BLOCKSIZE, 1, bctBuf);
u32 *hdr = (u32 *)(bctBuf + 0x100);
@@ -1109,15 +1109,15 @@ int hos_launch(ini_sec_t *cfg)
// Clear BCT area for retail units and copy it over if dev unit.
if (kb <= KB_FIRMWARE_VERSION_500 && !is_exo)
{
memset((void *)SECMON_BCT_CFG_ADDR, 0, 0x3000);
memset((void *)SECMON_BCT_CFG_ADDR, 0, SZ_4K + SZ_8K);
if (fuse_read_hw_state() == FUSE_NX_HW_STATE_DEV)
memcpy((void *)SECMON_BCT_CFG_ADDR, bootConfigBuf, 0x1000);
memcpy((void *)SECMON_BCT_CFG_ADDR, bootConfigBuf, SZ_4K);
}
else
{
memset((void *)SECMON6_BCT_CFG_ADDR, 0, 0x800);
memset((void *)SECMON6_BCT_CFG_ADDR, 0, SZ_2K);
if (fuse_read_hw_state() == FUSE_NX_HW_STATE_DEV)
memcpy((void *)SECMON6_BCT_CFG_ADDR, bootConfigBuf, 0x800);
memcpy((void *)SECMON6_BCT_CFG_ADDR, bootConfigBuf, SZ_2K);
}
free(bootConfigBuf);

View File

@@ -131,7 +131,7 @@ typedef struct _atm_fatal_error_ctx
#define ATM_FATAL_MAGIC 0x30454641 // AFE0
#define ATM_EXO_FATAL_ADDR 0x80020000
#define ATM_EXO_FATAL_SIZE 0x20000
#define ATM_EXO_FATAL_SIZE SZ_128K
#define ATM_WB_HEADER_OFF 0x244
#define ATM_WB_MAGIC 0x30544257 // WBT0

View File

@@ -110,7 +110,7 @@ void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t
void render_default_bootlogo()
{
gfx_clear_grey(0x1B);
u8 *BOOTLOGO = (void *)malloc(0x4000);
u8 *BOOTLOGO = (void *)malloc(SZ_16K);
blz_uncompress_srcdest(BOOTLOGO_BLZ, SZ_BOOTLOGO_BLZ, BOOTLOGO, SZ_BOOTLOGO);
gfx_set_rect_grey(BOOTLOGO, X_BOOTLOGO, Y_BOOTLOGO, 326, 544);
free(BOOTLOGO);
@@ -1002,10 +1002,10 @@ skip_list:
bmpData.size_x <= 720 &&
bmpData.size_y <= 1280)
{
if (bmpData.size <= fsize && ((bmpData.size - bmpData.offset) < 0x400000))
if (bmpData.size <= fsize && ((bmpData.size - bmpData.offset) < SZ_4M))
{
// Avoid unaligned access from BM 2-byte MAGIC and remove header.
BOOTLOGO = (u8 *)malloc(0x400000);
BOOTLOGO = (u8 *)malloc(SZ_4M);
memcpy(BOOTLOGO, bitmap + bmpData.offset, bmpData.size - bmpData.offset);
free(bitmap);
// Center logo if res < 720x1280.
@@ -1262,7 +1262,7 @@ static void _check_low_battery()
goto out;
// Prepare battery icon resources.
u8 *battery_res = malloc(ALIGN(SZ_BATTERY_EMPTY, 0x1000));
u8 *battery_res = malloc(ALIGN(SZ_BATTERY_EMPTY, SZ_4K));
blz_uncompress_srcdest(BATTERY_EMPTY_BLZ, SZ_BATTERY_EMPTY_BLZ, battery_res, SZ_BATTERY_EMPTY);
u8 *battery_icon = malloc(0x95A); // 21x38x3