hekate/nyx: utilize existing block size defines

This commit is contained in:
CTCaer 2024-03-12 15:53:05 +02:00
parent f126486266
commit 82925845e3
8 changed files with 29 additions and 29 deletions

View File

@ -145,7 +145,7 @@ void print_mmc_info()
" Current Rate: %d MB/s\n" " Current Rate: %d MB/s\n"
" Type Support: ", " Type Support: ",
emmc_storage.csd.mmca_vsn, emmc_storage.ext_csd.rev, emmc_storage.ext_csd.dev_version, emmc_storage.csd.cmdclass, emmc_storage.csd.mmca_vsn, emmc_storage.ext_csd.rev, emmc_storage.ext_csd.dev_version, emmc_storage.csd.cmdclass,
emmc_storage.csd.capacity == (4096 * 512) ? "High" : "Low", speed & 0xFFFF, (speed >> 16) & 0xFFFF, emmc_storage.csd.capacity == (4096 * EMMC_BLOCKSIZE) ? "High" : "Low", speed & 0xFFFF, (speed >> 16) & 0xFFFF,
emmc_storage.csd.busspeed); emmc_storage.csd.busspeed);
gfx_con.fntsz = 8; gfx_con.fntsz = 8;
gfx_printf("%s", card_type_support); gfx_printf("%s", card_type_support);
@ -156,13 +156,13 @@ void print_mmc_info()
u32 rpmb_size = emmc_storage.ext_csd.rpmb_mult << 17; u32 rpmb_size = emmc_storage.ext_csd.rpmb_mult << 17;
gfx_printf("%keMMC Partitions:%k\n", TXT_CLR_CYAN_L, TXT_CLR_DEFAULT); gfx_printf("%keMMC Partitions:%k\n", TXT_CLR_CYAN_L, TXT_CLR_DEFAULT);
gfx_printf(" 1: %kBOOT0 %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT, gfx_printf(" 1: %kBOOT0 %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT,
boot_size / 1024, boot_size / 512); boot_size / 1024, boot_size / EMMC_BLOCKSIZE);
gfx_put_small_sep(); gfx_put_small_sep();
gfx_printf(" 2: %kBOOT1 %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT, gfx_printf(" 2: %kBOOT1 %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT,
boot_size / 1024, boot_size / 512); boot_size / 1024, boot_size / EMMC_BLOCKSIZE);
gfx_put_small_sep(); gfx_put_small_sep();
gfx_printf(" 3: %kRPMB %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT, gfx_printf(" 3: %kRPMB %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT,
rpmb_size / 1024, rpmb_size / 512); rpmb_size / 1024, rpmb_size / EMMC_BLOCKSIZE);
gfx_put_small_sep(); gfx_put_small_sep();
gfx_printf(" 0: %kGPP (USER) %k\n Size: %5d MiB (LBA Sectors: 0x%07X)\n\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT, gfx_printf(" 0: %kGPP (USER) %k\n Size: %5d MiB (LBA Sectors: 0x%07X)\n\n", TXT_CLR_GREENISH, TXT_CLR_DEFAULT,
emmc_storage.sec_cnt >> SECTORS_TO_MIB_COEFF, emmc_storage.sec_cnt); emmc_storage.sec_cnt >> SECTORS_TO_MIB_COEFF, emmc_storage.sec_cnt);

View File

@ -218,7 +218,7 @@ static void _hos_eks_get()
if (!h_cfg.eks) if (!h_cfg.eks)
{ {
// Read EKS blob. // Read EKS blob.
u8 *mbr = calloc(512 , 1); u8 *mbr = calloc(SD_BLOCKSIZE, 1);
if (!hos_eks_rw_try(mbr, false)) if (!hos_eks_rw_try(mbr, false))
goto out; goto out;
@ -248,7 +248,7 @@ static void _hos_eks_save()
bool new_eks = false; bool new_eks = false;
if (!h_cfg.eks) if (!h_cfg.eks)
{ {
h_cfg.eks = calloc(512 , 1); h_cfg.eks = calloc(SD_BLOCKSIZE, 1);
new_eks = true; new_eks = true;
} }
@ -256,7 +256,7 @@ static void _hos_eks_save()
if (h_cfg.eks->enabled != HOS_EKS_TSEC_VER) if (h_cfg.eks->enabled != HOS_EKS_TSEC_VER)
{ {
// Read EKS blob. // Read EKS blob.
u8 *mbr = calloc(512 , 1); u8 *mbr = calloc(SD_BLOCKSIZE, 1);
if (!hos_eks_rw_try(mbr, false)) if (!hos_eks_rw_try(mbr, false))
{ {
if (new_eks) if (new_eks)
@ -283,7 +283,7 @@ static void _hos_eks_save()
memcpy(h_cfg.eks->troot_dev, keys + 11 * SE_KEY_128_SIZE, SE_KEY_128_SIZE); memcpy(h_cfg.eks->troot_dev, keys + 11 * SE_KEY_128_SIZE, SE_KEY_128_SIZE);
// Encrypt EKS blob. // Encrypt EKS blob.
u8 *eks = calloc(512 , 1); u8 *eks = calloc(SD_BLOCKSIZE, 1);
memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t)); memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t));
se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t)); se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t));
@ -310,7 +310,7 @@ void hos_eks_clear(u32 kb)
if (h_cfg.eks->enabled) if (h_cfg.eks->enabled)
{ {
// Read EKS blob. // Read EKS blob.
u8 *mbr = calloc(512 , 1); u8 *mbr = calloc(SD_BLOCKSIZE, 1);
if (!hos_eks_rw_try(mbr, false)) if (!hos_eks_rw_try(mbr, false))
goto out; goto out;
@ -318,7 +318,7 @@ void hos_eks_clear(u32 kb)
h_cfg.eks->enabled = 0; h_cfg.eks->enabled = 0;
// Encrypt EKS blob. // Encrypt EKS blob.
u8 *eks = calloc(512 , 1); u8 *eks = calloc(SD_BLOCKSIZE, 1);
memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t)); memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t));
se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t)); se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t));

View File

@ -436,7 +436,7 @@ int pkg1_warmboot_config(void *hos_ctxt, u32 warmboot_base, u32 fuses_fw, u8 kb)
void pkg1_warmboot_rsa_mod(u32 warmboot_base) void pkg1_warmboot_rsa_mod(u32 warmboot_base)
{ {
// Set warmboot binary rsa modulus. // Set warmboot binary rsa modulus.
u8 *rsa_mod = (u8 *)malloc(512); u8 *rsa_mod = (u8 *)malloc(EMMC_BLOCKSIZE);
emmc_set_partition(EMMC_BOOT0); emmc_set_partition(EMMC_BOOT0);

View File

@ -57,7 +57,7 @@ static void _get_valid_partition(u32 *sector_start, u32 *sector_size, u32 *part_
{ {
if (backup) if (backup)
{ {
u8 gpt_check[512] = { 0 }; u8 gpt_check[SD_BLOCKSIZE] = { 0 };
sdmmc_storage_read(&sd_storage, *sector_start + 0xC001, 1, gpt_check); sdmmc_storage_read(&sd_storage, *sector_start + 0xC001, 1, gpt_check);
if (!memcmp(gpt_check, "EFI PART", 8)) if (!memcmp(gpt_check, "EFI PART", 8))
{ {

View File

@ -1107,7 +1107,7 @@ static lv_res_t _create_mbox_emmc_sandisk_report(lv_obj_t * btn)
lv_mbox_set_text(mbox, "#C7EA46 Sandisk Device Report#"); lv_mbox_set_text(mbox, "#C7EA46 Sandisk Device Report#");
u8 *buf = calloc(512, 1); u8 *buf = calloc(EMMC_BLOCKSIZE, 1);
char *txt_buf = (char *)malloc(SZ_32K); char *txt_buf = (char *)malloc(SZ_32K);
char *txt_buf2 = (char *)malloc(SZ_32K); char *txt_buf2 = (char *)malloc(SZ_32K);
txt_buf[0] = 0; txt_buf[0] = 0;
@ -1694,7 +1694,7 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn)
emmc_storage.csd.cmdclass, speed & 0xFFFF, (speed >> 16) & 0xFFFF, emmc_storage.csd.cmdclass, speed & 0xFFFF, (speed >> 16) & 0xFFFF,
emmc_storage.csd.busspeed, card_type_support, emmc_storage.csd.busspeed, card_type_support,
!(cache % 1024) ? (cache / 1024) : cache, !(cache % 1024) ? "MiB" : "KiB", !(cache % 1024) ? (cache / 1024) : cache, !(cache % 1024) ? "MiB" : "KiB",
emmc_storage.ext_csd.max_enh_mult * 512 / 1024, emmc_storage.ext_csd.max_enh_mult * EMMC_BLOCKSIZE / 1024,
life_a_txt, life_b_txt, rsvd_blocks); life_a_txt, life_b_txt, rsvd_blocks);
lv_label_set_static_text(lb_desc, lv_label_set_static_text(lb_desc,
@ -1735,9 +1735,9 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn)
u32 boot_size = emmc_storage.ext_csd.boot_mult << 17; u32 boot_size = emmc_storage.ext_csd.boot_mult << 17;
u32 rpmb_size = emmc_storage.ext_csd.rpmb_mult << 17; u32 rpmb_size = emmc_storage.ext_csd.rpmb_mult << 17;
strcpy(txt_buf, "#00DDFF eMMC Physical Partitions:#\n"); strcpy(txt_buf, "#00DDFF eMMC Physical Partitions:#\n");
s_printf(txt_buf + strlen(txt_buf), "1: #96FF00 BOOT0# Size: %6d KiB (Sect: 0x%08X)\n", boot_size / 1024, boot_size / 512); s_printf(txt_buf + strlen(txt_buf), "1: #96FF00 BOOT0# Size: %6d KiB (Sect: 0x%08X)\n", boot_size / 1024, boot_size / EMMC_BLOCKSIZE);
s_printf(txt_buf + strlen(txt_buf), "2: #96FF00 BOOT1# Size: %6d KiB (Sect: 0x%08X)\n", boot_size / 1024, boot_size / 512); s_printf(txt_buf + strlen(txt_buf), "2: #96FF00 BOOT1# Size: %6d KiB (Sect: 0x%08X)\n", boot_size / 1024, boot_size / EMMC_BLOCKSIZE);
s_printf(txt_buf + strlen(txt_buf), "3: #96FF00 RPMB# Size: %6d KiB (Sect: 0x%08X)\n", rpmb_size / 1024, rpmb_size / 512); s_printf(txt_buf + strlen(txt_buf), "3: #96FF00 RPMB# Size: %6d KiB (Sect: 0x%08X)\n", rpmb_size / 1024, rpmb_size / EMMC_BLOCKSIZE);
s_printf(txt_buf + strlen(txt_buf), "0: #96FF00 GPP# Size: %6d MiB (Sect: 0x%08X)\n", emmc_storage.sec_cnt >> SECTORS_TO_MIB_COEFF, emmc_storage.sec_cnt); s_printf(txt_buf + strlen(txt_buf), "0: #96FF00 GPP# Size: %6d MiB (Sect: 0x%08X)\n", emmc_storage.sec_cnt >> SECTORS_TO_MIB_COEFF, emmc_storage.sec_cnt);
strcat(txt_buf, "\n#00DDFF GPP (eMMC USER) Partition Table:#\n"); strcat(txt_buf, "\n#00DDFF GPP (eMMC USER) Partition Table:#\n");
@ -2119,7 +2119,7 @@ static lv_res_t _create_window_sdcard_info_status(lv_obj_t *btn)
s_printf(txt_buf, "\n%s\n%d %s\n%d/%d MiB", s_printf(txt_buf, "\n%s\n%d %s\n%d/%d MiB",
sd_fs.fs_type == FS_EXFAT ? ("exFAT "SYMBOL_SHRK) : ("FAT32"), sd_fs.fs_type == FS_EXFAT ? ("exFAT "SYMBOL_SHRK) : ("FAT32"),
(sd_fs.csize > 1) ? (sd_fs.csize >> 1) : 512, (sd_fs.csize > 1) ? (sd_fs.csize >> 1) : SD_BLOCKSIZE,
(sd_fs.csize > 1) ? "KiB" : "B", (sd_fs.csize > 1) ? "KiB" : "B",
(u32)(sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF), (u32)(sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF),
(u32)(sd_fs.n_fatent * sd_fs.csize >> SECTORS_TO_MIB_COEFF)); (u32)(sd_fs.n_fatent * sd_fs.csize >> SECTORS_TO_MIB_COEFF));

View File

@ -595,7 +595,7 @@ static lv_res_t _action_ums_emuemmc_gpp(lv_obj_t *btn)
error = 1; error = 1;
usbs.offset = emu_info.sector + 0x4000; usbs.offset = emu_info.sector + 0x4000;
u8 *gpt = malloc(512); u8 *gpt = malloc(SD_BLOCKSIZE);
if (sdmmc_storage_read(&sd_storage, usbs.offset + 1, 1, gpt)) if (sdmmc_storage_read(&sd_storage, usbs.offset + 1, 1, gpt))
{ {
if (!memcmp(gpt, "EFI PART", 8)) if (!memcmp(gpt, "EFI PART", 8))

View File

@ -926,8 +926,8 @@ static lv_res_t _action_check_flash_linux(lv_obj_t *btn)
goto error; goto error;
} }
// Last part. Align size to LBA (512 bytes). // Last part. Align size to LBA (SD_BLOCKSIZE).
fno.fsize = ALIGN((u64)fno.fsize, 512); fno.fsize = ALIGN((u64)fno.fsize, SD_BLOCKSIZE);
idx--; idx--;
} }
l4t_flash_ctxt.image_size_sct += (u64)fno.fsize >> 9; l4t_flash_ctxt.image_size_sct += (u64)fno.fsize >> 9;
@ -1231,7 +1231,7 @@ dtb_not_found:
{ {
if (!memcmp(gpt->entries[i].name, (char[]) { 'S', 0, 'O', 0, 'S', 0 }, 6) || !memcmp(gpt->entries[i].name, (char[]) { 'r', 0, 'e', 0, 'c', 0, 'o', 0, 'v', 0, 'e', 0, 'r', 0, 'y', 0 }, 16)) if (!memcmp(gpt->entries[i].name, (char[]) { 'S', 0, 'O', 0, 'S', 0 }, 6) || !memcmp(gpt->entries[i].name, (char[]) { 'r', 0, 'e', 0, 'c', 0, 'o', 0, 'v', 0, 'e', 0, 'r', 0, 'y', 0 }, 16))
{ {
u8 *buf = malloc(512); u8 *buf = malloc(SD_BLOCKSIZE);
sdmmc_storage_read(&sd_storage, gpt->entries[i].lba_start, 1, buf); sdmmc_storage_read(&sd_storage, gpt->entries[i].lba_start, 1, buf);
if (!memcmp(buf, "ANDROID", 7)) if (!memcmp(buf, "ANDROID", 7))
boot_recovery = true; boot_recovery = true;
@ -2429,7 +2429,7 @@ check_changes:
gpt_hdr_backup.crc32 = crc32_calc(0, (const u8 *)&gpt_hdr_backup, gpt_hdr_backup.size); gpt_hdr_backup.crc32 = crc32_calc(0, (const u8 *)&gpt_hdr_backup, gpt_hdr_backup.size);
// Write main GPT. // Write main GPT.
u32 aligned_entries_size = ALIGN(entries_size, 512); u32 aligned_entries_size = ALIGN(entries_size, SD_BLOCKSIZE);
sdmmc_storage_write(&sd_storage, gpt->header.my_lba, (sizeof(gpt_header_t) + aligned_entries_size) >> 9, gpt); sdmmc_storage_write(&sd_storage, gpt->header.my_lba, (sizeof(gpt_header_t) + aligned_entries_size) >> 9, gpt);
// Write backup GPT partition table. // Write backup GPT partition table.

View File

@ -210,7 +210,7 @@ static void _hos_eks_get()
if (!h_cfg.eks) if (!h_cfg.eks)
{ {
// Read EKS blob. // Read EKS blob.
u8 *mbr = calloc(512 , 1); u8 *mbr = calloc(SD_BLOCKSIZE, 1);
if (!hos_eks_rw_try(mbr, false)) if (!hos_eks_rw_try(mbr, false))
goto out; goto out;
@ -240,7 +240,7 @@ static void _hos_eks_save()
bool new_eks = false; bool new_eks = false;
if (!h_cfg.eks) if (!h_cfg.eks)
{ {
h_cfg.eks = calloc(512 , 1); h_cfg.eks = calloc(SD_BLOCKSIZE, 1);
new_eks = true; new_eks = true;
} }
@ -248,7 +248,7 @@ static void _hos_eks_save()
if (h_cfg.eks->enabled != HOS_EKS_TSEC_VER) if (h_cfg.eks->enabled != HOS_EKS_TSEC_VER)
{ {
// Read EKS blob. // Read EKS blob.
u8 *mbr = calloc(512 , 1); u8 *mbr = calloc(SD_BLOCKSIZE, 1);
if (!hos_eks_rw_try(mbr, false)) if (!hos_eks_rw_try(mbr, false))
{ {
if (new_eks) if (new_eks)
@ -275,7 +275,7 @@ static void _hos_eks_save()
memcpy(h_cfg.eks->troot_dev, keys + 11 * SE_KEY_128_SIZE, SE_KEY_128_SIZE); memcpy(h_cfg.eks->troot_dev, keys + 11 * SE_KEY_128_SIZE, SE_KEY_128_SIZE);
// Encrypt EKS blob. // Encrypt EKS blob.
u8 *eks = calloc(512 , 1); u8 *eks = calloc(SD_BLOCKSIZE, 1);
memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t)); memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t));
se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t)); se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t));
@ -302,7 +302,7 @@ void hos_eks_clear(u32 kb)
if (h_cfg.eks->enabled) if (h_cfg.eks->enabled)
{ {
// Read EKS blob. // Read EKS blob.
u8 *mbr = calloc(512 , 1); u8 *mbr = calloc(SD_BLOCKSIZE, 1);
if (!hos_eks_rw_try(mbr, false)) if (!hos_eks_rw_try(mbr, false))
goto out; goto out;
@ -310,7 +310,7 @@ void hos_eks_clear(u32 kb)
h_cfg.eks->enabled = 0; h_cfg.eks->enabled = 0;
// Encrypt EKS blob. // Encrypt EKS blob.
u8 *eks = calloc(512 , 1); u8 *eks = calloc(SD_BLOCKSIZE, 1);
memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t)); memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t));
se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t)); se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t));