hekate/nyx: move emmc ops to bdk and adhere to changes

This commit is contained in:
CTCaer
2022-01-20 13:15:04 +02:00
parent b08e36a7b0
commit 28167b7304
24 changed files with 176 additions and 576 deletions

View File

@@ -1,7 +1,7 @@
/*
* Copyright (c) 2018 naehrwert
* Copyright (c) 2018 Rajko Stojadinovic
* Copyright (c) 2018-2021 CTCaer
* Copyright (c) 2018-2022 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,
@@ -28,7 +28,6 @@
#include "fe_emummc_tools.h"
#include "../config.h"
#include <libs/fatfs/ff.h>
#include "../storage/nx_emmc.h"
#define NUM_SECTORS_PER_ITER 8192 // 4MB Cache.
#define OUT_FILENAME_SZ 128
@@ -175,7 +174,7 @@ static int _dump_emmc_verify(emmc_tool_gui_t *gui, sdmmc_storage_t *storage, u32
}
char chunkSizeAscii[10];
itoa(NUM_SECTORS_PER_ITER * NX_EMMC_BLOCKSIZE, chunkSizeAscii, 10);
itoa(NUM_SECTORS_PER_ITER * EMMC_BLOCKSIZE, chunkSizeAscii, 10);
chunkSizeAscii[9] = '\0';
f_puts("# chunksize: ", &hashFp);
@@ -402,7 +401,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
if ((sd_storage.csd.capacity >> (20 - sd_storage.csd.read_blkbits)) <= 8192)
multipartSplitSize = (1u << 30);
// Maximum parts fitting the free space available.
maxSplitParts = (sd_fs.free_clst * sd_fs.csize) / (multipartSplitSize / NX_EMMC_BLOCKSIZE);
maxSplitParts = (sd_fs.free_clst * sd_fs.csize) / (multipartSplitSize / EMMC_BLOCKSIZE);
// Check if the USER partition or the RAW eMMC fits the sd card free space.
if (totalSectors > (sd_fs.free_clst * sd_fs.csize))
@@ -423,7 +422,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
}
}
// Check if we are continuing a previous raw eMMC or USER partition backup in progress.
if (f_open(&partialIdxFp, partialIdxFilename, FA_READ) == FR_OK && totalSectors > (FAT32_FILESIZE_LIMIT / NX_EMMC_BLOCKSIZE))
if (f_open(&partialIdxFp, partialIdxFilename, FA_READ) == FR_OK && totalSectors > (FAT32_FILESIZE_LIMIT / EMMC_BLOCKSIZE))
{
s_printf(gui->txt_buf, "\n#AEFD14 Partial Backup in progress. Continuing...#\n");
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, gui->txt_buf);
@@ -456,9 +455,9 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
}
// Check if filesystem is FAT32 or the free space is smaller and backup in parts.
if (((sd_fs.fs_type != FS_EXFAT) && totalSectors > (FAT32_FILESIZE_LIMIT / NX_EMMC_BLOCKSIZE)) || isSmallSdCard)
if (((sd_fs.fs_type != FS_EXFAT) && totalSectors > (FAT32_FILESIZE_LIMIT / EMMC_BLOCKSIZE)) || isSmallSdCard)
{
u32 multipartSplitSectors = multipartSplitSize / NX_EMMC_BLOCKSIZE;
u32 multipartSplitSectors = multipartSplitSize / EMMC_BLOCKSIZE;
numSplitParts = (totalSectors + multipartSplitSectors - 1) / multipartSplitSectors;
outFilename[sdPathLen++] = '.';
@@ -512,8 +511,8 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
// Continue from where we left, if Partial Backup in progress.
if (partialDumpInProgress)
{
lba_curr += currPartIdx * (multipartSplitSize / NX_EMMC_BLOCKSIZE);
totalSectors -= currPartIdx * (multipartSplitSize / NX_EMMC_BLOCKSIZE);
lba_curr += currPartIdx * (multipartSplitSize / EMMC_BLOCKSIZE);
totalSectors -= currPartIdx * (multipartSplitSize / EMMC_BLOCKSIZE);
lbaStartPart = lba_curr; // Update the start LBA for verification.
}
u64 totalSize = (u64)((u64)totalSectors << 9);
@@ -652,7 +651,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
}
manual_system_maintenance(false);
res = f_write_fast(&fp, buf, NX_EMMC_BLOCKSIZE * num);
res = f_write_fast(&fp, buf, EMMC_BLOCKSIZE * num);
if (res)
{
@@ -682,7 +681,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_part,
lba_curr += num;
totalSectors -= num;
bytesWritten += num * NX_EMMC_BLOCKSIZE;
bytesWritten += num * EMMC_BLOCKSIZE;
// Force a flush after a lot of data if not splitting.
if (numSplitParts == 0 && bytesWritten >= multipartSplitSize)
@@ -769,7 +768,7 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui)
// Get SD Card free space for Partial Backup.
f_getfree("", &sd_fs.free_clst, NULL);
if (!sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
if (!emmc_initialize(false))
{
lv_label_set_text(gui->label_info, "#FFDD00 Failed to init eMMC!#");
goto out;
@@ -792,7 +791,7 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui)
emmc_part_t bootPart;
memset(&bootPart, 0, sizeof(bootPart));
bootPart.lba_start = 0;
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
bootPart.lba_end = (BOOT_PART_SIZE / EMMC_BLOCKSIZE) - 1;
for (i = 0; i < 2; i++)
{
strcpy(bootPart.name, "BOOT");
@@ -832,7 +831,7 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui)
strcpy(gui->base_path, sdPath);
LIST_INIT(gpt);
nx_emmc_gpt_parse(&gpt, &emmc_storage);
emmc_gpt_parse(&gpt);
LIST_FOREACH_ENTRY(emmc_part_t, part, &gpt, link)
{
if ((dumpType & PART_USER) == 0 && !strcmp(part->name, "USER"))
@@ -863,7 +862,7 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui)
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf);
manual_system_maintenance(true);
}
nx_emmc_gpt_free(&gpt);
emmc_gpt_free(&gpt);
}
if (dumpType & PART_RAW)
@@ -1304,7 +1303,7 @@ static int _restore_emmc_part(emmc_tool_gui_t *gui, char *sd_path, int active_pa
lba_curr += num;
totalSectors -= num;
bytesWritten += num * NX_EMMC_BLOCKSIZE;
bytesWritten += num * EMMC_BLOCKSIZE;
}
lv_bar_set_value(gui->bar, 100);
lv_label_set_text(gui->label_pct, " "SYMBOL_DOT" 100%");
@@ -1407,7 +1406,7 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui)
goto out;
}
if (!sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
if (!emmc_initialize(false))
{
lv_label_set_text(gui->label_info, "#FFDD00 Failed to init eMMC!#");
goto out;
@@ -1428,7 +1427,7 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui)
emmc_part_t bootPart;
memset(&bootPart, 0, sizeof(bootPart));
bootPart.lba_start = 0;
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
bootPart.lba_end = (BOOT_PART_SIZE / EMMC_BLOCKSIZE) - 1;
for (i = 0; i < 2; i++)
{
strcpy(bootPart.name, "BOOT");
@@ -1466,7 +1465,7 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui)
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_GPP);
LIST_INIT(gpt);
nx_emmc_gpt_parse(&gpt, &emmc_storage);
emmc_gpt_parse(&gpt);
LIST_FOREACH_ENTRY(emmc_part_t, part, &gpt, link)
{
s_printf(txt_buf, "#00DDFF %02d: %s#\n#00DDFF Range: 0x%08X - 0x%08X#\n\n\n\n\n",
@@ -1488,7 +1487,7 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui)
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf);
manual_system_maintenance(true);
}
nx_emmc_gpt_free(&gpt);
emmc_gpt_free(&gpt);
}
if (restoreType & PART_RAW)

View File

@@ -1,7 +1,7 @@
/*
* Copyright (c) 2018 naehrwert
* Copyright (c) 2018 Rajko Stojadinovic
* Copyright (c) 2018-2021 CTCaer
* Copyright (c) 2018-2022 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,
@@ -28,7 +28,6 @@
#include "../config.h"
#include <libs/fatfs/diskio.h>
#include <libs/fatfs/ff.h>
#include "../storage/nx_emmc.h"
#include "../storage/nx_emmc_bis.h"
#define OUT_FILENAME_SZ 128
@@ -169,9 +168,9 @@ static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_sto
}
// Check if filesystem is FAT32 or the free space is smaller and backup in parts.
if (totalSectors > (FAT32_FILESIZE_LIMIT / NX_EMMC_BLOCKSIZE))
if (totalSectors > (FAT32_FILESIZE_LIMIT / EMMC_BLOCKSIZE))
{
u32 multipartSplitSectors = multipartSplitSize / NX_EMMC_BLOCKSIZE;
u32 multipartSplitSectors = multipartSplitSize / EMMC_BLOCKSIZE;
numSplitParts = (totalSectors + multipartSplitSectors - 1) / multipartSplitSectors;
// Continue from where we left, if Partial Backup in progress.
@@ -296,7 +295,7 @@ static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_sto
manual_system_maintenance(false);
res = f_write_fast(&fp, buf, NX_EMMC_BLOCKSIZE * num);
res = f_write_fast(&fp, buf, EMMC_BLOCKSIZE * num);
manual_system_maintenance(false);
@@ -325,7 +324,7 @@ static int _dump_emummc_file_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_sto
lba_curr += num;
totalSectors -= num;
bytesWritten += num * NX_EMMC_BLOCKSIZE;
bytesWritten += num * EMMC_BLOCKSIZE;
// Force a flush after a lot of data if not splitting.
if (numSplitParts == 0 && bytesWritten >= multipartSplitSize)
@@ -374,7 +373,7 @@ void dump_emummc_file(emmc_tool_gui_t *gui)
// Get SD Card free space for Partial Backup.
f_getfree("", &sd_fs.free_clst, NULL);
if (!sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
if (!emmc_initialize(false))
{
lv_label_set_text(gui->label_info, "#FFDD00 Failed to init eMMC!#");
goto out;
@@ -406,7 +405,7 @@ void dump_emummc_file(emmc_tool_gui_t *gui)
emmc_part_t bootPart;
memset(&bootPart, 0, sizeof(bootPart));
bootPart.lba_start = 0;
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
bootPart.lba_end = (BOOT_PART_SIZE / EMMC_BLOCKSIZE) - 1;
for (i = 0; i < 2; i++)
{
strcpy(bootPart.name, "BOOT");
@@ -497,7 +496,7 @@ out:
sd_unmount();
}
static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part_idx, u32 sd_part_off, sdmmc_storage_t *storage, emmc_part_t *part, u32 resized_count)
static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part_idx, u32 sd_part_off, emmc_part_t *part, u32 resized_count)
{
u32 num = 0;
u32 pct = 0;
@@ -529,8 +528,8 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part
{
// Get USER partition info.
LIST_INIT(gpt_parsed);
nx_emmc_gpt_parse(&gpt_parsed, storage);
emmc_part_t *user_part = nx_emmc_part_find(&gpt_parsed, "USER");
emmc_gpt_parse(&gpt_parsed);
emmc_part_t *user_part = emmc_part_find(&gpt_parsed, "USER");
if (!user_part)
{
s_printf(gui->txt_buf, "\n#FFDD00 USER partition not found!#\n");
@@ -542,7 +541,7 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part
user_offset = user_part->lba_start;
part->lba_end = user_offset - 1;
nx_emmc_gpt_free(&gpt_parsed);
emmc_gpt_free(&gpt_parsed);
}
u32 totalSectors = part->lba_end - part->lba_start + 1;
@@ -564,7 +563,7 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part
num = MIN(totalSectors, NUM_SECTORS_PER_ITER);
// Read data from eMMC.
while (!sdmmc_storage_read(storage, lba_curr, num, buf))
while (!sdmmc_storage_read(&emmc_storage, lba_curr, num, buf))
{
s_printf(gui->txt_buf,
"\n#FFDD00 Error reading %d blocks @LBA %08X,#\n"
@@ -697,9 +696,9 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part
mbr_t mbr;
gpt_t *gpt = calloc(1, sizeof(gpt_t));
gpt_header_t gpt_hdr_backup;
sdmmc_storage_read(storage, 0, 1, &mbr);
sdmmc_storage_read(storage, 1, sizeof(gpt_t) >> 9, gpt);
sdmmc_storage_read(storage, gpt->header.alt_lba, 1, &gpt_hdr_backup);
sdmmc_storage_read(&emmc_storage, 0, 1, &mbr);
sdmmc_storage_read(&emmc_storage, 1, sizeof(gpt_t) >> 9, gpt);
sdmmc_storage_read(&emmc_storage, gpt->header.alt_lba, 1, &gpt_hdr_backup);
// Find USER partition.
u32 gpt_entry_idx = 0;
@@ -747,7 +746,7 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part
sdmmc_storage_write(&sd_storage, sd_sector_off, 1, &mbr);
// Clear nand patrol.
memset(buf, 0, NX_EMMC_BLOCKSIZE);
memset(buf, 0, EMMC_BLOCKSIZE);
sdmmc_storage_write(&sd_storage, sd_part_off + NAND_PATROL_SECTOR, 1, buf);
free(gpt);
@@ -774,12 +773,12 @@ static int _emummc_raw_derive_bis_keys(emmc_tool_gui_t *gui, u32 resized_count)
// Read and decrypt CAL0 for validation of working BIS keys.
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_GPP);
LIST_INIT(gpt);
nx_emmc_gpt_parse(&gpt, &emmc_storage);
emmc_part_t *cal0_part = nx_emmc_part_find(&gpt, "PRODINFO"); // check if null
emmc_gpt_parse(&gpt);
emmc_part_t *cal0_part = emmc_part_find(&gpt, "PRODINFO"); // check if null
nx_emmc_bis_init(cal0_part, false, 0);
nx_emmc_bis_read(0, 0x40, cal0_buf);
nx_emmc_bis_end();
nx_emmc_gpt_free(&gpt);
emmc_gpt_free(&gpt);
nx_emmc_cal0_t *cal0 = (nx_emmc_cal0_t *)cal0_buf;
@@ -850,7 +849,7 @@ void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 r
goto out;
}
if (!sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
if (!emmc_initialize(false))
{
lv_label_set_text(gui->label_info, "#FFDD00 Failed to init eMMC!#");
goto out;
@@ -879,7 +878,7 @@ void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 r
emmc_part_t bootPart;
memset(&bootPart, 0, sizeof(bootPart));
bootPart.lba_start = 0;
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
bootPart.lba_end = (BOOT_PART_SIZE / EMMC_BLOCKSIZE) - 1;
// Clear partition start.
memset((u8 *)MIXD_BUF_ALIGNED, 0, SZ_16M);
@@ -901,7 +900,7 @@ void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 r
sdmmc_storage_set_mmc_partition(&emmc_storage, i + 1);
strcat(sdPath, bootPart.name);
res = _dump_emummc_raw_part(gui, i, part_idx, sector_start, &emmc_storage, &bootPart, 0);
res = _dump_emummc_raw_part(gui, i, part_idx, sector_start, &bootPart, 0);
if (!res)
{
@@ -935,7 +934,7 @@ void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start, u32 r
lv_label_ins_text(gui->label_log, LV_LABEL_POS_LAST, txt_buf);
manual_system_maintenance(true);
res = _dump_emummc_raw_part(gui, 2, part_idx, sector_start, &emmc_storage, &rawPart, resized_count);
res = _dump_emummc_raw_part(gui, 2, part_idx, sector_start, &rawPart, resized_count);
if (!res)
s_printf(txt_buf, "#FFDD00 Failed!#\n");

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021 CTCaer
* Copyright (c) 2019-2022 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,
@@ -218,7 +218,7 @@ static void _create_mbox_emummc_raw()
sdmmc_storage_read(&sd_storage, 0, 1, mbr);
sd_unmount();
sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400);
emmc_initialize(false);
u32 emmc_size_safe = emmc_storage.sec_cnt + 0xC000; // eMMC GPP size + BOOT0/1.
@@ -769,7 +769,7 @@ static lv_res_t _create_mbox_emummc_migrate(lv_obj_t *btn)
sd_mount();
sdmmc_storage_read(&sd_storage, 0, 1, mbr);
sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400);
emmc_initialize(false);
em_raw = false;
em_file = false;

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018 naehrwert
* Copyright (c) 2018-2021 CTCaer
* Copyright (c) 2018-2022 CTCaer
* Copyright (c) 2018 balika011
*
* This program is free software; you can redistribute it and/or modify it
@@ -262,7 +262,7 @@ static lv_res_t _create_mbox_cal0(lv_obj_t *btn)
sd_mount();
// Init eMMC.
if (!sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
if (!emmc_initialize(false))
{
lv_label_set_text(lb_desc, "#FFDD00 Failed to init eMMC!#");
@@ -278,12 +278,12 @@ static lv_res_t _create_mbox_cal0(lv_obj_t *btn)
// Read and decrypt CAL0.
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_GPP);
LIST_INIT(gpt);
nx_emmc_gpt_parse(&gpt, &emmc_storage);
emmc_part_t *cal0_part = nx_emmc_part_find(&gpt, "PRODINFO"); // check if null
emmc_gpt_parse(&gpt);
emmc_part_t *cal0_part = emmc_part_find(&gpt, "PRODINFO"); // check if null
nx_emmc_bis_init(cal0_part, false, 0);
nx_emmc_bis_read(0, 0x40, cal0_buf);
nx_emmc_bis_end();
nx_emmc_gpt_free(&gpt);
emmc_gpt_free(&gpt);
// Clear BIS keys slots.
hos_bis_keys_clear();
@@ -1123,7 +1123,7 @@ static lv_res_t _create_mbox_emmc_sandisk_report(lv_obj_t * btn)
lv_obj_align(lb_desc2, lb_desc, LV_ALIGN_OUT_RIGHT_TOP, 0, 0);
if (!sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
if (!emmc_initialize(false))
{
lv_label_set_text(lb_desc, "#FFDD00 Failed to init eMMC!#");
@@ -1321,7 +1321,7 @@ static lv_res_t _create_mbox_benchmark(bool sd_bench)
else
{
storage = &emmc_storage;
res = !sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400);
res = !emmc_initialize(false);
if (!res)
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_GPP);
}
@@ -1553,7 +1553,7 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn)
txt_buf[0] = '\n';
txt_buf[1] = 0;
if (!sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
if (!emmc_initialize(false))
{
lv_label_set_text(lb_desc, "#FFDD00 Failed to init eMMC!#");
lv_obj_set_width(lb_desc, lv_obj_get_width(desc));
@@ -1711,7 +1711,7 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn)
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_GPP);
LIST_INIT(gpt);
nx_emmc_gpt_parse(&gpt, &emmc_storage);
emmc_gpt_parse(&gpt);
u32 idx = 0;
LIST_FOREACH_ENTRY(emmc_part_t, part, &gpt, link)
@@ -1741,7 +1741,7 @@ static lv_res_t _create_window_emmc_info_status(lv_obj_t *btn)
if (!idx)
strcat(txt_buf, "#FFDD00 Partition table is empty!#");
nx_emmc_gpt_free(&gpt);
emmc_gpt_free(&gpt);
lv_label_set_text(lb_desc2, txt_buf);
lv_obj_set_width(lb_desc2, lv_obj_get_width(desc2));

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018 naehrwert
* Copyright (c) 2018-2021 CTCaer
* Copyright (c) 2018-2022 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,
@@ -29,7 +29,6 @@
#include "../hos/pkg2.h"
#include "../hos/hos.h"
#include <libs/fatfs/ff.h>
#include "../storage/nx_emmc.h"
extern volatile boot_cfg_t *b_cfg;
extern hekate_config h_cfg;
@@ -64,11 +63,11 @@ bool get_autorcm_status(bool toggle)
if (h_cfg.t210b01)
return false;
sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400);
emmc_initialize(false);
u8 *tempbuf = (u8 *)malloc(0x200);
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_BOOT0);
sdmmc_storage_read(&emmc_storage, 0x200 / NX_EMMC_BLOCKSIZE, 1, tempbuf);
sdmmc_storage_read(&emmc_storage, 0x200 / EMMC_BLOCKSIZE, 1, tempbuf);
// Get the correct RSA modulus byte masks.
nx_emmc_get_autorcm_masks(&corr_mod0, &mod1);
@@ -86,7 +85,7 @@ bool get_autorcm_status(bool toggle)
// Iterate BCTs.
for (u32 i = 0; i < 4; i++)
{
sector = (0x200 + (0x4000 * i)) / NX_EMMC_BLOCKSIZE; // 0x4000 bct + 0x200 offset.
sector = (0x200 + (0x4000 * i)) / EMMC_BLOCKSIZE; // 0x4000 bct + 0x200 offset.
sdmmc_storage_read(&emmc_storage, sector, 1, tempbuf);
if (!enabled)
@@ -104,7 +103,7 @@ bool get_autorcm_status(bool toggle)
// Iterate BCTs.
for (u32 i = 0; i < 4; i++)
{
sector = (0x200 + (0x4000 * i)) / NX_EMMC_BLOCKSIZE; // 0x4000 bct + 0x200 offset.
sector = (0x200 + (0x4000 * i)) / EMMC_BLOCKSIZE; // 0x4000 bct + 0x200 offset.
sdmmc_storage_read(&emmc_storage, sector, 1, tempbuf);
// Check if 2nd byte of modulus is correct.
@@ -1104,7 +1103,7 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn)
char *txt_buf = (char *)malloc(SZ_16K);
if (!sdmmc_storage_init_mmc(&emmc_storage, &emmc_sdmmc, SDMMC_BUS_WIDTH_8, SDHCI_TIMING_MMC_HS400))
if (!emmc_initialize(false))
{
lv_label_set_text(lb_desc, "#FFDD00 Failed to init eMMC!#");
@@ -1120,7 +1119,7 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn)
char *build_date = malloc(32);
u32 pk1_offset = h_cfg.t210b01 ? sizeof(bl_hdr_t210b01_t) : 0; // Skip T210B01 OEM header.
sdmmc_storage_read(&emmc_storage, BOOTLOADER_MAIN_OFFSET / NX_EMMC_BLOCKSIZE, BOOTLOADER_SIZE / NX_EMMC_BLOCKSIZE, pkg1);
sdmmc_storage_read(&emmc_storage, BOOTLOADER_MAIN_OFFSET / EMMC_BLOCKSIZE, BOOTLOADER_SIZE / EMMC_BLOCKSIZE, pkg1);
const pkg1_id_t *pkg1_id = pkg1_identify(pkg1 + pk1_offset, build_date);
@@ -1159,8 +1158,8 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn)
tsec_ctxt.secmon_base = pkg1_id->secmon_base;
// Read keyblob.
u8 *keyblob = (u8 *)calloc(NX_EMMC_BLOCKSIZE, 1);
sdmmc_storage_read(&emmc_storage, HOS_KEYBLOBS_OFFSET / NX_EMMC_BLOCKSIZE + kb, 1, keyblob);
u8 *keyblob = (u8 *)calloc(EMMC_BLOCKSIZE, 1);
sdmmc_storage_read(&emmc_storage, HOS_KEYBLOBS_OFFSET / EMMC_BLOCKSIZE + kb, 1, keyblob);
// Decrypt.
hos_keygen(keyblob, kb, &tsec_ctxt);
@@ -1256,23 +1255,23 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn)
sdmmc_storage_set_mmc_partition(&emmc_storage, EMMC_GPP);
// Parse eMMC GPT.
LIST_INIT(gpt);
nx_emmc_gpt_parse(&gpt, &emmc_storage);
emmc_gpt_parse(&gpt);
// Find package2 partition.
emmc_part_t *pkg2_part = nx_emmc_part_find(&gpt, "BCPKG2-1-Normal-Main");
emmc_part_t *pkg2_part = emmc_part_find(&gpt, "BCPKG2-1-Normal-Main");
if (!pkg2_part)
goto out;
// Read in package2 header and get package2 real size.
u8 *tmp = (u8 *)malloc(NX_EMMC_BLOCKSIZE);
nx_emmc_part_read(&emmc_storage, pkg2_part, 0x4000 / NX_EMMC_BLOCKSIZE, 1, tmp);
u8 *tmp = (u8 *)malloc(EMMC_BLOCKSIZE);
emmc_part_read(pkg2_part, 0x4000 / EMMC_BLOCKSIZE, 1, tmp);
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.
u32 pkg2_size_aligned = ALIGN(pkg2_size, NX_EMMC_BLOCKSIZE);
u32 pkg2_size_aligned = ALIGN(pkg2_size, EMMC_BLOCKSIZE);
pkg2 = malloc(pkg2_size_aligned);
nx_emmc_part_read(&emmc_storage, pkg2_part, 0x4000 / NX_EMMC_BLOCKSIZE,
pkg2_size_aligned / NX_EMMC_BLOCKSIZE, pkg2);
emmc_part_read(pkg2_part, 0x4000 / EMMC_BLOCKSIZE,
pkg2_size_aligned / EMMC_BLOCKSIZE, pkg2);
// Dump encrypted package2.
emmcsn_path_impl(path, "/pkg2", "pkg2_encr.bin", &emmc_storage);
@@ -1384,7 +1383,7 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn)
free(kip_buffer);
out:
nx_emmc_gpt_free(&gpt);
emmc_gpt_free(&gpt);
out_free:
free(pkg1);
free(secmon);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021 CTCaer
* Copyright (c) 2019-2022 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 @@
#include "gui_tools_partition_manager.h"
#include <libs/fatfs/diskio.h>
#include <libs/lvgl/lvgl.h>
#include "../storage/nx_emmc.h"
extern volatile boot_cfg_t *b_cfg;
extern volatile nyx_storage_t *nyx_str;
@@ -693,7 +692,7 @@ static lv_res_t _action_flash_linux_data(lv_obj_t * btns, const char * txt)
lba_curr += num;
total_size_sct -= num;
bytesWritten += num * NX_EMMC_BLOCKSIZE;
bytesWritten += num * EMMC_BLOCKSIZE;
}
lv_bar_set_value(bar, 100);
lv_label_set_text(label_pct, " "SYMBOL_DOT" 100%");
@@ -2110,7 +2109,7 @@ static lv_res_t _action_fix_mbr(lv_obj_t *btn)
break;
}
nx_emmc_gpt_free(&gpt_parsed);
emmc_gpt_free(&gpt_parsed);
// Set GPT protective partition.
mbr[1].partitions[mbr_idx].type = 0xEE;