* Make button check delay 1s to avoid button repressing from "button ip" state
* Dumping: Fix part logic and honor user actions on ignoring errors
* Add time taken to dump emmc
This commit is contained in:
Kostas Missos 2018-05-14 01:42:59 +03:00 committed by nwert
parent 8ddb6c16c5
commit 0f5ffb4c43

View file

@ -607,7 +607,8 @@ void print_tsec_key()
const pkg1_id_t *pkg1_id = pkg1_identify(pkg1); const pkg1_id_t *pkg1_id = pkg1_identify(pkg1);
if (!pkg1_id) if (!pkg1_id)
{ {
gfx_printf(&gfx_con, "%kCould not identify package 1 version to read TSEC firmware (= '%s').%k\n", 0xFF0000FF, (char *)pkg1 + 0x10, 0xFFFFFFFF); gfx_printf(&gfx_con, "%kCould not identify package 1 version to read TSEC firmware (= '%s').%k\n",
0xFF0000FF, (char *)pkg1 + 0x10, 0xFFFFFFFF);
goto out; goto out;
} }
@ -630,7 +631,7 @@ void print_tsec_key()
out:; out:;
free(pkg1); free(pkg1);
sdmmc_storage_end(&storage); sdmmc_storage_end(&storage);
sleep(100000); sleep(1000000);
btn_wait(); btn_wait();
} }
@ -657,7 +658,7 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
{ {
static const u32 FAT32_FILESIZE_LIMIT = 0xFFFFFFFF; static const u32 FAT32_FILESIZE_LIMIT = 0xFFFFFFFF;
static const u32 MULTIPART_SPLIT_SIZE = (1u << 31); static const u32 MULTIPART_SPLIT_SIZE = (1u << 31);
static const u32 SECTORS_TO_MB_COEFF = 0x800; static const u32 SECTORS_TO_MIB_COEFF = 0x800;
u32 totalSectors = part->lba_end - part->lba_start + 1; u32 totalSectors = part->lba_end - part->lba_start + 1;
u32 currPartIdx = 0; u32 currPartIdx = 0;
@ -675,9 +676,9 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
memcpy(partialIdxFilename, "partial.idx", 11); memcpy(partialIdxFilename, "partial.idx", 11);
partialIdxFilename[11] = 0; partialIdxFilename[11] = 0;
gfx_printf(&gfx_con, "SD Card free space: %dMB, Total dump size %dMB\n", gfx_printf(&gfx_con, "SD Card free space: %d MiB, Total dump size %d MiB\n",
sd_fs.free_clst * sd_fs.csize / SECTORS_TO_MB_COEFF, sd_fs.free_clst * sd_fs.csize / SECTORS_TO_MIB_COEFF,
totalSectors / SECTORS_TO_MB_COEFF); totalSectors / SECTORS_TO_MIB_COEFF);
// Check if the USER partition or the RAW eMMC fits the sd card free space // Check if the USER partition or the RAW eMMC fits the sd card free space
if (totalSectors > (sd_fs.free_clst * sd_fs.csize)) if (totalSectors > (sd_fs.free_clst * sd_fs.csize))
@ -715,7 +716,7 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
} }
// Check if filesystem is FAT32 or the free space is smaller and dump in parts // Check if filesystem is FAT32 or the free space is smaller and dump in parts
if (((sd_fs.fs_type != FS_EXFAT) || isSmallSdCard) && totalSectors > (FAT32_FILESIZE_LIMIT/NX_EMMC_BLOCKSIZE)) if (((sd_fs.fs_type != FS_EXFAT) && totalSectors > (FAT32_FILESIZE_LIMIT/NX_EMMC_BLOCKSIZE)) | isSmallSdCard)
{ {
static const u32 MULTIPART_SPLIT_SECTORS = MULTIPART_SPLIT_SIZE/NX_EMMC_BLOCKSIZE; static const u32 MULTIPART_SPLIT_SECTORS = MULTIPART_SPLIT_SIZE/NX_EMMC_BLOCKSIZE;
numSplitParts = (totalSectors+MULTIPART_SPLIT_SECTORS-1)/MULTIPART_SPLIT_SECTORS; numSplitParts = (totalSectors+MULTIPART_SPLIT_SECTORS-1)/MULTIPART_SPLIT_SECTORS;
@ -799,6 +800,7 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
free(buf); free(buf);
return 0; return 0;
} }
// Sd card fatal error.
if (res && !ignoreWriteErrors) if (res && !ignoreWriteErrors)
{ {
gfx_printf(&gfx_con, "%k\nPress any key and try again.%k\n", gfx_printf(&gfx_con, "%k\nPress any key and try again.%k\n",
@ -833,25 +835,25 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
0xFF0000FF, num, lba_curr, ++retryCount, 0xFFFFFFFF); 0xFF0000FF, num, lba_curr, ++retryCount, 0xFFFFFFFF);
sleep(500000); sleep(500000);
if (retryCount >= 10) if (retryCount >= 10)
goto out; goto out;
} }
res = f_write(&fp, buf, NX_EMMC_BLOCKSIZE * num, NULL); res = f_write(&fp, buf, NX_EMMC_BLOCKSIZE * num, NULL);
if (res && !ignoreWriteErrors) if (res && !ignoreWriteErrors)
{ {
gfx_printf(&gfx_con, "%kFatal error %d when writing to SD Card%k\n\ gfx_printf(&gfx_con, "%k\nFatal error %d when writing to SD Card%k\n\n\
Press VOL to abort and try again\nPress POWER to ignore errors (will produce a corrupt dump)", Press VOL to abort and try again.\nPress POWER to ignore errors (will produce a corrupt dump).\n",
0xFF0000FF, res, 0xFFFFFFFF); 0xFF0000FF, res, 0xFFFFFFFF);
u32 btn = btn_wait(); u32 btn = btn_wait();
if (btn & BTN_POWER) if (btn & BTN_POWER)
{ {
bytesWritten = MULTIPART_SPLIT_SIZE - num * NX_EMMC_BLOCKSIZE; ignoreWriteErrors = 1;
currPartIdx--;
} }
else else
{ {
ignoreWriteErrors = 1; bytesWritten = MULTIPART_SPLIT_SIZE - num * NX_EMMC_BLOCKSIZE;
currPartIdx--;
} }
} }
u32 pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); u32 pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start);
@ -881,8 +883,9 @@ out:;
if(partialDumpInProgress) if(partialDumpInProgress)
{ {
f_unlink(partialIdxFilename); f_unlink(partialIdxFilename);
gfx_printf(&gfx_con, "\n\nYou can now join the files and get the complete raw eMMC dump.\n"); gfx_printf(&gfx_con, "\n\nYou can now join the files and get the complete raw eMMC dump.");
} }
gfx_putc(&gfx_con, '\n');
return 1; return 1;
} }
@ -897,12 +900,13 @@ typedef enum
static void dump_emmc_selected(dumpType_t dumpType) static void dump_emmc_selected(dumpType_t dumpType)
{ {
u32 timer = 0;
gfx_clear(&gfx_ctxt, 0xFF000000); gfx_clear(&gfx_ctxt, 0xFF000000);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(&gfx_con, 0, 0);
if (!sd_mount()) if (!sd_mount())
{ {
gfx_printf(&gfx_con, "%kFailed to mount SD card (make sure that it is inserted).%k\n", 0xFF0000FF, 0xFFFFFFFF); gfx_printf(&gfx_con, "%kFailed to init/mount SD card (make sure that it is inserted).%k\n", 0xFF0000FF, 0xFFFFFFFF);
goto out; goto out;
} }
else else
@ -921,6 +925,7 @@ static void dump_emmc_selected(dumpType_t dumpType)
} }
int i = 0; int i = 0;
timer = get_tmr();
if (dumpType & DUMP_BOOT) if (dumpType & DUMP_BOOT)
{ {
static const u32 BOOT_PART_SIZE = 0x400000; static const u32 BOOT_PART_SIZE = 0x400000;
@ -986,11 +991,12 @@ static void dump_emmc_selected(dumpType_t dumpType)
} }
} }
gfx_printf(&gfx_con, "%kTime taken: %d seconds.%k\n", 0xFF00FF96, (get_tmr() - timer) / 1000000, 0xFFFFFFFF);
sdmmc_storage_end(&storage); sdmmc_storage_end(&storage);
gfx_puts(&gfx_con, "Done. Press any key.\n"); gfx_puts(&gfx_con, "\nDone. Press any key.\n");
out:; out:;
sleep(100000); sleep(1000000);
btn_wait(); btn_wait();
} }
@ -1092,7 +1098,7 @@ out:;
free(pkg1); free(pkg1);
free(secmon); free(secmon);
free(warmboot); free(warmboot);
sleep(100000); sleep(1000000);
btn_wait(); btn_wait();
} }