Better error messaging structure

This commit is contained in:
Kostas Missos 2018-05-15 20:15:22 +03:00 committed by nwert
parent 8da015d993
commit 54187226c8
5 changed files with 51 additions and 55 deletions

View file

@ -472,8 +472,6 @@ DPRINTF("decrypted and unpacked pkg1\n");
*mb_in = 3; *mb_in = 3;
sleep(100); sleep(100);
/*PMC(0x4) = 0x7FFFF3; /*PMC(0x4) = 0x7FFFF3;
PMC(0x2C4) = 0xFFFFFFFF; PMC(0x2C4) = 0xFFFFFFFF;
PMC(0x2D8) = 0xFFAFFFFF; PMC(0x2D8) = 0xFFAFFFFF;

View file

@ -48,6 +48,10 @@
#include "pkg1.h" #include "pkg1.h"
#include "mmc.h" #include "mmc.h"
//TODO: ugly.
gfx_ctxt_t gfx_ctxt;
gfx_con_t gfx_con;
//TODO: ugly. //TODO: ugly.
sdmmc_t sd_sdmmc; sdmmc_t sd_sdmmc;
sdmmc_storage_t sd_storage; sdmmc_storage_t sd_storage;
@ -59,12 +63,26 @@ int sd_mount()
if (sd_mounted) if (sd_mounted)
return 1; return 1;
if (sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, SDMMC_1, SDMMC_BUS_WIDTH_4, 11) && if (!sdmmc_storage_init_sd(&sd_storage, &sd_sdmmc, SDMMC_1, SDMMC_BUS_WIDTH_4, 11))
f_mount(&sd_fs, "", 1) == FR_OK) {
gfx_printf(&gfx_con, "%kFailed to init SD card (make sure that it is inserted).%k\n",
0xFF0000FF, 0xFFFFFFFF);
}
else
{
int res = 0;
res = f_mount(&sd_fs, "", 1);
if (res == FR_OK)
{ {
sd_mounted = 1; sd_mounted = 1;
return 1; return 1;
} }
else
{
gfx_printf(&gfx_con, "%kFailed to mount SD card (FatFS Error %d).\n(make sure that a FAT32/exFAT partition exists)%k\n",
0xFF0000FF, res, 0xFFFFFFFF);
}
}
return 0; return 0;
} }
@ -290,10 +308,6 @@ void config_hw()
sdram_lp0_save_params(sdram_get_params()); sdram_lp0_save_params(sdram_get_params());
} }
//TODO: ugly.
gfx_ctxt_t gfx_ctxt;
gfx_con_t gfx_con;
void print_fuseinfo() void print_fuseinfo()
{ {
gfx_clear(&gfx_ctxt, 0xFF000000); gfx_clear(&gfx_ctxt, 0xFF000000);
@ -309,12 +323,7 @@ void print_fuseinfo()
u32 btn = btn_wait(); u32 btn = btn_wait();
if (btn & BTN_POWER) if (btn & BTN_POWER)
{ {
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);
}
else
{ {
FIL fuseFp; FIL fuseFp;
char fuseFilename[9]; char fuseFilename[9];
@ -353,12 +362,7 @@ void print_kfuseinfo()
u32 btn = btn_wait(); u32 btn = btn_wait();
if (btn & BTN_POWER) if (btn & BTN_POWER)
{ {
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);
}
else
{ {
FIL kfuseFp; FIL kfuseFp;
char kfuseFilename[10]; char kfuseFilename[10];
@ -528,12 +532,7 @@ void print_sdcard_info()
static const u32 SECTORS_TO_MIB_COEFF = 0x800; static const u32 SECTORS_TO_MIB_COEFF = 0x800;
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);
}
else
{ {
u32 capacity; u32 capacity;
@ -702,7 +701,7 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
{ {
if (f_open(&partialIdxFp, partialIdxFilename, FA_READ) == FR_OK) if (f_open(&partialIdxFp, partialIdxFilename, FA_READ) == FR_OK)
{ {
gfx_printf(&gfx_con, "%kFound partial dump in progress. Continuing...%k\n", 0xFF14FDAE, 0xFFFFFFFF); gfx_printf(&gfx_con, "%kFound partial dump in progress. Continuing...%k\n\n", 0xFF14FDAE, 0xFFFFFFFF);
partialDumpInProgress = 1; partialDumpInProgress = 1;
@ -713,7 +712,7 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
maxSplitParts += currPartIdx; maxSplitParts += currPartIdx;
} }
else else
gfx_printf(&gfx_con, "%kContinuing with partial dumping...%k\n", 0xFF00BAFF, 0xFFFFFFFF); gfx_printf(&gfx_con, "%kContinuing with partial dumping...%k\n\n", 0xFF00BAFF, 0xFFFFFFFF);
} }
// 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
@ -752,7 +751,11 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
FIL fp; FIL fp;
if (f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) if (f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{
gfx_printf(&gfx_con, "%kError creating file %s.%k\n", 0xFF0000FF, outFilename, 0xFFFFFFFF);
return 0; return 0;
}
static const u32 NUM_SECTORS_PER_ITER = 512; static const u32 NUM_SECTORS_PER_ITER = 512;
u8 *buf = (u8 *)malloc(NX_EMMC_BLOCKSIZE * NUM_SECTORS_PER_ITER); u8 *buf = (u8 *)malloc(NX_EMMC_BLOCKSIZE * NUM_SECTORS_PER_ITER);
@ -822,6 +825,8 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
if (f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) if (f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
{ {
gfx_printf(&gfx_con, "%kError creating file %s.%k\n", 0xFF0000FF, outFilename, 0xFFFFFFFF);
free(buf); free(buf);
return 0; return 0;
} }
@ -901,21 +906,17 @@ typedef enum
static void dump_emmc_selected(dumpType_t dumpType) static void dump_emmc_selected(dumpType_t dumpType)
{ {
int res = 0;
u32 timer = 0; 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 init/mount SD card (make sure that it is inserted).%k\n", 0xFF0000FF, 0xFFFFFFFF);
goto out; goto out;
}
else
{
gfx_puts(&gfx_con, "Checking for available free space...\n"); gfx_puts(&gfx_con, "Checking for available free space...\n");
// Get SD Card free space for partial dumping // Get SD Card free space for partial dumping
f_getfree("", &sd_fs.free_clst, NULL); f_getfree("", &sd_fs.free_clst, NULL);
}
sdmmc_storage_t storage; sdmmc_storage_t storage;
sdmmc_t sdmmc; sdmmc_t sdmmc;
@ -945,8 +946,7 @@ static void dump_emmc_selected(dumpType_t dumpType)
bootPart.name, bootPart.lba_start, bootPart.lba_end, 0xFFFFFFFF); bootPart.name, bootPart.lba_start, bootPart.lba_end, 0xFFFFFFFF);
sdmmc_storage_set_mmc_partition(&storage, i+1); sdmmc_storage_set_mmc_partition(&storage, i+1);
dump_emmc_part(bootPart.name, &storage, &bootPart); res = dump_emmc_part(bootPart.name, &storage, &bootPart);
gfx_putc(&gfx_con, '\n');
} }
} }
@ -968,8 +968,7 @@ static void dump_emmc_selected(dumpType_t dumpType)
gfx_printf(&gfx_con, "%k%02d: %s (%08X-%08X)%k\n", 0xFFFFDD00, i++, gfx_printf(&gfx_con, "%k%02d: %s (%08X-%08X)%k\n", 0xFFFFDD00, i++,
part->name, part->lba_start, part->lba_end, 0xFFFFFFFF); part->name, part->lba_start, part->lba_end, 0xFFFFFFFF);
dump_emmc_part(part->name, &storage, part); res = dump_emmc_part(part->name, &storage, part);
gfx_putc(&gfx_con, '\n');
} }
} }
@ -986,14 +985,15 @@ static void dump_emmc_selected(dumpType_t dumpType)
gfx_printf(&gfx_con, "%k%02d: %s (%08X-%08X)%k\n", 0xFFFFDD00, i++, gfx_printf(&gfx_con, "%k%02d: %s (%08X-%08X)%k\n", 0xFFFFDD00, i++,
rawPart.name, rawPart.lba_start, rawPart.lba_end, 0xFFFFFFFF); rawPart.name, rawPart.lba_start, rawPart.lba_end, 0xFFFFFFFF);
dump_emmc_part(rawPart.name, &storage, &rawPart); res = dump_emmc_part(rawPart.name, &storage, &rawPart);
gfx_putc(&gfx_con, '\n');
} }
} }
} }
gfx_putc(&gfx_con, '\n');
gfx_printf(&gfx_con, "%kTime taken: %d seconds.%k\n", 0xFF00FF96, (get_tmr() - timer) / 1000000, 0xFFFFFFFF); gfx_printf(&gfx_con, "%kTime taken: %d seconds.%k\n", 0xFF00FF96, (get_tmr() - timer) / 1000000, 0xFFFFFFFF);
sdmmc_storage_end(&storage); sdmmc_storage_end(&storage);
if (res)
gfx_puts(&gfx_con, "\nDone. Press any key.\n"); gfx_puts(&gfx_con, "\nDone. Press any key.\n");
out:; out:;
@ -1030,10 +1030,7 @@ void dump_package1()
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);
goto out; goto out;
}
sdmmc_storage_t storage; sdmmc_storage_t storage;
sdmmc_t sdmmc; sdmmc_t sdmmc;

View file

@ -56,6 +56,7 @@ PATCHSET_DEF(_secmon_5_patchset,
); );
PATCHSET_DEF(_secmon_6_patchset, PATCHSET_DEF(_secmon_6_patchset,
//Patch package2 decryption and signature/hash checks.
{ 0x12b0 + 0x4d0, _NOP() }, { 0x12b0 + 0x4d0, _NOP() },
{ 0x12b0 + 0x4dc, _NOP() }, { 0x12b0 + 0x4dc, _NOP() },
{ 0x12b0 + 0x794, _NOP() }, { 0x12b0 + 0x794, _NOP() },

View file

@ -42,7 +42,6 @@ typedef struct _pkg1_id_t
patch_t *secmon_patchset; patch_t *secmon_patchset;
} pkg1_id_t; } pkg1_id_t;
typedef struct _pk11_hdr_t typedef struct _pk11_hdr_t
{ {
u32 magic; u32 magic;

View file

@ -26,4 +26,5 @@ void se_aes_key_clear(u32 ks);
int se_aes_unwrap_key(u32 ks_dst, u32 ks_src, const void *input); int se_aes_unwrap_key(u32 ks_dst, u32 ks_src, const void *input);
int se_aes_crypt_block_ecb(u32 ks, u32 enc, void *dst, const void *src); int se_aes_crypt_block_ecb(u32 ks, u32 enc, void *dst, const void *src);
int se_aes_crypt_ctr(u32 ks, void *dst, u32 dst_size, const void *src, u32 src_size, void *ctr); int se_aes_crypt_ctr(u32 ks, void *dst, u32 dst_size, const void *src, u32 src_size, void *ctr);
#endif #endif