mirror of
https://github.com/CTCaer/hekate.git
synced 2024-11-11 12:56:41 +00:00
[Main] Use printf macros to reduce clutter
This commit is contained in:
parent
526ffd4414
commit
08a7511760
1 changed files with 33 additions and 34 deletions
67
ipl/main.c
67
ipl/main.c
|
@ -52,6 +52,10 @@
|
||||||
gfx_ctxt_t gfx_ctxt;
|
gfx_ctxt_t gfx_ctxt;
|
||||||
gfx_con_t gfx_con;
|
gfx_con_t gfx_con;
|
||||||
|
|
||||||
|
//TODO: Create more macros (info, header, debug, etc) with different colors and utilize them for consistency.
|
||||||
|
#define EPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFF0000FF, 0xFFFFFFFF)
|
||||||
|
#define EPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFF0000FF, args, 0xFFFFFFFF)
|
||||||
|
|
||||||
//TODO: ugly.
|
//TODO: ugly.
|
||||||
sdmmc_t sd_sdmmc;
|
sdmmc_t sd_sdmmc;
|
||||||
sdmmc_storage_t sd_storage;
|
sdmmc_storage_t sd_storage;
|
||||||
|
@ -65,8 +69,7 @@ int sd_mount()
|
||||||
|
|
||||||
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))
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%kFailed to init SD card (make sure that it is inserted).%k\n",
|
EPRINTF("Failed to init SD card (make sure that it is inserted).");
|
||||||
0xFF0000FF, 0xFFFFFFFF);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -79,8 +82,7 @@ int sd_mount()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%kFailed to mount SD card (FatFS Error %d).\n(make sure that a FAT32/exFAT partition exists)%k\n",
|
EPRINTFARGS("Failed to mount SD card (FatFS Error %d).\n(make sure that a FAT32/exFAT partition exists)", res);
|
||||||
0xFF0000FF, res, 0xFFFFFFFF);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +363,7 @@ void print_kfuseinfo()
|
||||||
gfx_printf(&gfx_con, "%kKFuse contents:\n\n%k", 0xFFFF9955, 0xFFFFFFFF);
|
gfx_printf(&gfx_con, "%kKFuse contents:\n\n%k", 0xFFFF9955, 0xFFFFFFFF);
|
||||||
u32 buf[KFUSE_NUM_WORDS];
|
u32 buf[KFUSE_NUM_WORDS];
|
||||||
if (!kfuse_read(buf))
|
if (!kfuse_read(buf))
|
||||||
gfx_printf(&gfx_con, "%kCRC fail.\n", 0xFF0000FF);
|
EPRINTF("CRC fail.");
|
||||||
else
|
else
|
||||||
gfx_hexdump(&gfx_con, 0, (u8 *)buf, KFUSE_NUM_WORDS * 4);
|
gfx_hexdump(&gfx_con, 0, (u8 *)buf, KFUSE_NUM_WORDS * 4);
|
||||||
|
|
||||||
|
@ -404,7 +406,7 @@ void print_mmc_info()
|
||||||
|
|
||||||
if(!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4))
|
if(!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4))
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%kFailed to init eMMC.%k\n", 0xFF0000FF, 0xFFFFFFFF);
|
EPRINTF("Failed to init eMMC.");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -447,12 +449,12 @@ void print_mmc_info()
|
||||||
storage.cid.prv, storage.cid.serial, storage.cid.month, storage.cid.year);
|
storage.cid.prv, storage.cid.serial, storage.cid.month, storage.cid.year);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
gfx_printf(&gfx_con, "%keMMC has unknown MMCA version %d%k\n", 0xFF0000FF, storage.csd.mmca_vsn, 0xFFFFFFFF);
|
EPRINTFARGS("eMMC has unknown MMCA version %d", storage.csd.mmca_vsn);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storage.csd.structure == 0)
|
if (storage.csd.structure == 0)
|
||||||
gfx_printf(&gfx_con, "%kUnknown CSD structure%k\n", 0xFF0000FF, 0xFFFFFFFF);
|
EPRINTF("Unknown CSD structure.");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%kExtended Card-Specific Data V1.%d:%k\n",
|
gfx_printf(&gfx_con, "%kExtended Card-Specific Data V1.%d:%k\n",
|
||||||
|
@ -618,8 +620,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 package1 version to read TSEC firmware (= '%s').%k\n",
|
EPRINTFARGS("Could not identify package1 version to read TSEC firmware (= '%s').",
|
||||||
0xFF0000FF, (char *)pkg1 + 0x10, 0xFFFFFFFF);
|
(char *)pkg1 + 0x10);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,7 +637,7 @@ void print_tsec_key()
|
||||||
gfx_printf(&gfx_con, "%02X", key[i]);
|
gfx_printf(&gfx_con, "%02X", key[i]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
gfx_printf(&gfx_con, "%kERROR %X", 0xFF0000FF, res);
|
EPRINTFARGS("ERROR %X", res);
|
||||||
gfx_putc(&gfx_con, '\n');
|
gfx_putc(&gfx_con, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -704,7 +706,7 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
|
||||||
|
|
||||||
if (!maxSplitParts)
|
if (!maxSplitParts)
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%kNot enough free space for partial dumping.%k\n", 0xFF0000FF, 0xFFFFFFFF);
|
EPRINTF("Not enough free space for partial dumping.");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -723,7 +725,7 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
|
||||||
|
|
||||||
if (!maxSplitParts)
|
if (!maxSplitParts)
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%kNot enough free space for partial dumping.%k\n", 0xFF0000FF, 0xFFFFFFFF);
|
EPRINTF("Not enough free space for partial dumping.");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -771,7 +773,7 @@ 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);
|
EPRINTFARGS("Error creating file %s.", outFilename);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -818,7 +820,7 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%k\nError creating partial.idx file.%k\n", 0xFF0000FF, 0xFFFFFFFF);
|
EPRINTF("\nError creating partial.idx file.");
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -841,7 +843,7 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
|
||||||
// Create next part
|
// Create next 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);
|
EPRINTFARGS("Error creating file %s.", outFilename);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -853,14 +855,14 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
|
||||||
u32 num = MIN(totalSectors, NUM_SECTORS_PER_ITER);
|
u32 num = MIN(totalSectors, NUM_SECTORS_PER_ITER);
|
||||||
while(!sdmmc_storage_read(storage, lba_curr, num, buf))
|
while(!sdmmc_storage_read(storage, lba_curr, num, buf))
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%kError reading %d blocks @ LBA %08X from eMMC (try %d)%k\n",
|
EPRINTFARGS("Error reading %d blocks @ LBA %08X from eMMC (try %d)",
|
||||||
0xFF0000FF, num, lba_curr, ++retryCount, 0xFFFFFFFF);
|
num, lba_curr, ++retryCount);
|
||||||
|
|
||||||
sleep(500000);
|
sleep(500000);
|
||||||
if (retryCount >= 10)
|
if (retryCount >= 10)
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%k\nFailed to read %d blocks @ LBA %08X from eMMC. Aborting..%k\n",
|
EPRINTFARGS("\nFailed to read %d blocks @ LBA %08X from eMMC. Aborting..",
|
||||||
0xFF0000FF, num, lba_curr, 0xFFFFFFFF);
|
num, lba_curr);
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
f_close(&fp);
|
f_close(&fp);
|
||||||
|
@ -870,11 +872,8 @@ int dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t *part)
|
||||||
res = f_write(&fp, buf, NX_EMMC_BLOCKSIZE * num, NULL);
|
res = f_write(&fp, buf, NX_EMMC_BLOCKSIZE * num, NULL);
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%k\nFatal error (%d) when writing to SD Card%k\n\n",
|
EPRINTFARGS("\nFatal error (%d) when writing to SD Card", res);
|
||||||
0xFF0000FF, res, 0xFFFFFFFF);
|
EPRINTF("\nPress any key and try again.");
|
||||||
|
|
||||||
gfx_printf(&gfx_con, "%k\nPress any key and try again.%k\n",
|
|
||||||
0xFF0000FF, 0xFFFFFFFF);
|
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
f_close(&fp);
|
f_close(&fp);
|
||||||
|
@ -940,7 +939,7 @@ static void dump_emmc_selected(dumpType_t dumpType)
|
||||||
sdmmc_t sdmmc;
|
sdmmc_t sdmmc;
|
||||||
if(!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4))
|
if(!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4))
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%kFailed to init eMMC.%k\n", 0xFF0000FF, 0xFFFFFFFF);
|
EPRINTF("Failed to init eMMC.");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1054,7 +1053,7 @@ void dump_package1()
|
||||||
sdmmc_t sdmmc;
|
sdmmc_t sdmmc;
|
||||||
if(!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4))
|
if(!sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4))
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%kFailed to init eMMC.%k\n", 0xFF0000FF, 0xFFFFFFFF);
|
EPRINTF("Failed to init eMMC.");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
sdmmc_storage_set_mmc_partition(&storage, 1);
|
sdmmc_storage_set_mmc_partition(&storage, 1);
|
||||||
|
@ -1065,7 +1064,7 @@ void dump_package1()
|
||||||
const pk11_hdr_t *hdr = (pk11_hdr_t *)(pkg1 + pkg1_id->pkg11_off + 0x20);
|
const pk11_hdr_t *hdr = (pk11_hdr_t *)(pkg1 + pkg1_id->pkg11_off + 0x20);
|
||||||
if (!pkg1_id)
|
if (!pkg1_id)
|
||||||
{
|
{
|
||||||
gfx_printf(&gfx_con, "%kCould not identify package1 version to read TSEC firmware (= '%s').%k\n", 0xFF0000FF, (char *)pkg1 + 0x10, 0xFFFFFFFF);
|
EPRINTFARGS("Could not identify package1 version to read TSEC firmware (= '%s').", (char *)pkg1 + 0x10);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1081,9 +1080,9 @@ void dump_package1()
|
||||||
pkg1_unpack(warmboot, secmon, pkg1_id, pkg1);
|
pkg1_unpack(warmboot, secmon, pkg1_id, pkg1);
|
||||||
|
|
||||||
// display info
|
// display info
|
||||||
gfx_printf(&gfx_con, "%kSecure monitor addr: %08X\n", 0xFF0000FF, pkg1_id->secmon_base);
|
gfx_printf(&gfx_con, "%kSecure monitor addr: %08X\n", 0xFF00FFA8, pkg1_id->secmon_base);
|
||||||
gfx_printf(&gfx_con, "%kSecure monitor size: %08X\n", 0xFF0000FF, hdr->sm_size);
|
gfx_printf(&gfx_con, "%kSecure monitor size: %08X\n", 0xFF00FFA8, hdr->sm_size);
|
||||||
gfx_printf(&gfx_con, "%kSecure monitor off: %08X\n", 0xFF0000FF, hdr->sm_off);
|
gfx_printf(&gfx_con, "%kSecure monitor off: %08X\n", 0xFF00FFA8, hdr->sm_off);
|
||||||
|
|
||||||
// dump package1
|
// dump package1
|
||||||
if (save_to_file(pkg1, 0x40000, "pkg_decr.bin") == -1) {
|
if (save_to_file(pkg1, 0x40000, "pkg_decr.bin") == -1) {
|
||||||
|
@ -1155,18 +1154,18 @@ void launch_firmware()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
gfx_printf(&gfx_con, "%kNo launch configurations found.%k\n", 0xFF0000FF, 0xFFFFFFFF);
|
EPRINTF("No launch configurations found.");
|
||||||
free(ments);
|
free(ments);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
gfx_printf(&gfx_con, "%kFailed to load 'hekate_ipl.ini'.%k\n", 0xFF0000FF, 0xFFFFFFFF);
|
EPRINTF("Failed to load 'hekate_ipl.ini'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cfg_sec)
|
if (!cfg_sec)
|
||||||
gfx_printf(&gfx_con, "Using default launch configuration.\n");
|
gfx_printf(&gfx_con, "Using default launch configuration.\n");
|
||||||
|
|
||||||
if (!hos_launch(cfg_sec))
|
if (!hos_launch(cfg_sec))
|
||||||
gfx_printf(&gfx_con, "%kFailed to launch firmware.%k\n", 0xFF0000FF, 0xFFFFFFFF);
|
EPRINTF("Failed to launch firmware.");
|
||||||
|
|
||||||
//TODO: free ini.
|
//TODO: free ini.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue