[GFX] Refactor gfx to utilize global contexts

This commit is contained in:
ctcaer@gmail.com 2019-04-14 02:30:14 +03:00
parent 5ba4848571
commit b0af57f98a
17 changed files with 519 additions and 519 deletions

View file

@ -154,20 +154,20 @@ int create_config_entry()
static void _save_config() static void _save_config()
{ {
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
if (!create_config_entry()) if (!create_config_entry())
gfx_puts(&gfx_con, "\nConfiguration was saved!\n"); gfx_puts("\nConfiguration was saved!\n");
else else
EPRINTF("\nConfiguration saving failed!"); EPRINTF("\nConfiguration saving failed!");
gfx_puts(&gfx_con, "\nPress any key..."); gfx_puts("\nPress any key...");
} }
static void _config_autoboot_list(void *ent) static void _config_autoboot_list(void *ent)
{ {
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
u32 *temp_autoboot = NULL; u32 *temp_autoboot = NULL;
@ -225,7 +225,7 @@ static void _config_autoboot_list(void *ent)
memset(&ments[i], 0, sizeof(ment_t)); memset(&ments[i], 0, sizeof(ment_t));
menu_t menu = {ments, "Select an entry to auto boot", 0, 0}; menu_t menu = {ments, "Select an entry to auto boot", 0, 0};
temp_autoboot = (u32 *)tui_do_menu(&gfx_con, &menu); temp_autoboot = (u32 *)tui_do_menu(&menu);
if (temp_autoboot != NULL) if (temp_autoboot != NULL)
{ {
h_cfg.autoboot = *(u32 *)temp_autoboot; h_cfg.autoboot = *(u32 *)temp_autoboot;
@ -258,8 +258,8 @@ out2:;
void config_autoboot() void config_autoboot()
{ {
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
u32 *temp_autoboot = NULL; u32 *temp_autoboot = NULL;
@ -341,7 +341,7 @@ void config_autoboot()
memset(&ments[i], 0, sizeof(ment_t)); memset(&ments[i], 0, sizeof(ment_t));
menu_t menu = {ments, "Disable or select entry to auto boot", 0, 0}; menu_t menu = {ments, "Disable or select entry to auto boot", 0, 0};
temp_autoboot = (u32 *)tui_do_menu(&gfx_con, &menu); temp_autoboot = (u32 *)tui_do_menu(&menu);
if (temp_autoboot != NULL) if (temp_autoboot != NULL)
{ {
h_cfg.autoboot = *(u32 *)temp_autoboot; h_cfg.autoboot = *(u32 *)temp_autoboot;
@ -374,8 +374,8 @@ out2:;
void config_bootdelay() void config_bootdelay()
{ {
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
u32 delay_entries = 6; u32 delay_entries = 6;
@ -416,7 +416,7 @@ void config_bootdelay()
memset(&ments[i + 2], 0, sizeof(ment_t)); memset(&ments[i + 2], 0, sizeof(ment_t));
menu_t menu = {ments, "Time delay for entering bootloader menu", 0, 0}; menu_t menu = {ments, "Time delay for entering bootloader menu", 0, 0};
u32 *temp_bootwait = (u32 *)tui_do_menu(&gfx_con, &menu); u32 *temp_bootwait = (u32 *)tui_do_menu(&menu);
if (temp_bootwait != NULL) if (temp_bootwait != NULL)
{ {
h_cfg.bootwait = *(u32 *)temp_bootwait; h_cfg.bootwait = *(u32 *)temp_bootwait;
@ -434,8 +434,8 @@ void config_bootdelay()
void config_verification() void config_verification()
{ {
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * 6); ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * 6);
u32 *vr_values = (u32 *)malloc(sizeof(u32) * 3); u32 *vr_values = (u32 *)malloc(sizeof(u32) * 3);
@ -469,7 +469,7 @@ void config_verification()
memset(&ments[5], 0, sizeof(ment_t)); memset(&ments[5], 0, sizeof(ment_t));
menu_t menu = {ments, "Backup & Restore verification", 0, 0}; menu_t menu = {ments, "Backup & Restore verification", 0, 0};
u32 *temp_verification = (u32 *)tui_do_menu(&gfx_con, &menu); u32 *temp_verification = (u32 *)tui_do_menu(&menu);
if (temp_verification != NULL) if (temp_verification != NULL)
{ {
h_cfg.verification = *(u32 *)temp_verification; h_cfg.verification = *(u32 *)temp_verification;
@ -487,8 +487,8 @@ void config_verification()
void config_backlight() void config_backlight()
{ {
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
u32 bri_entries = 11; u32 bri_entries = 11;
@ -528,7 +528,7 @@ void config_backlight()
memset(&ments[i + 1], 0, sizeof(ment_t)); memset(&ments[i + 1], 0, sizeof(ment_t));
menu_t menu = {ments, "Backlight brightness", 0, 0}; menu_t menu = {ments, "Backlight brightness", 0, 0};
u32 *temp_backlight = (u32 *)tui_do_menu(&gfx_con, &menu); u32 *temp_backlight = (u32 *)tui_do_menu(&menu);
if (temp_backlight != NULL) if (temp_backlight != NULL)
{ {
h_cfg.backlight = (*(u32 *)temp_backlight) * 2; h_cfg.backlight = (*(u32 *)temp_backlight) * 2;
@ -546,8 +546,8 @@ void config_backlight()
void config_auto_hos_poweroff() void config_auto_hos_poweroff()
{ {
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * 6); ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * 6);
u32 *hp_values = (u32 *)malloc(sizeof(u32) * 3); u32 *hp_values = (u32 *)malloc(sizeof(u32) * 3);
@ -586,7 +586,7 @@ void config_auto_hos_poweroff()
memset(&ments[5], 0, sizeof(ment_t)); memset(&ments[5], 0, sizeof(ment_t));
menu_t menu = {ments, "Power off if woke up from HOS", 0, 0}; menu_t menu = {ments, "Power off if woke up from HOS", 0, 0};
u32 *temp_autohosoff = (u32 *)tui_do_menu(&gfx_con, &menu); u32 *temp_autohosoff = (u32 *)tui_do_menu(&menu);
if (temp_autohosoff != NULL) if (temp_autohosoff != NULL)
{ {
h_cfg.autohosoff = *(u32 *)temp_autohosoff; h_cfg.autohosoff = *(u32 *)temp_autohosoff;
@ -603,8 +603,8 @@ void config_auto_hos_poweroff()
void config_nogc() void config_nogc()
{ {
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * 5); ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * 5);
u32 *cb_values = (u32 *)malloc(sizeof(u32) * 2); u32 *cb_values = (u32 *)malloc(sizeof(u32) * 2);
@ -635,7 +635,7 @@ void config_nogc()
memset(&ments[4], 0, sizeof(ment_t)); memset(&ments[4], 0, sizeof(ment_t));
menu_t menu = {ments, "No Gamecard", 0, 0}; menu_t menu = {ments, "No Gamecard", 0, 0};
u32 *temp_nogc = (u32 *)tui_do_menu(&gfx_con, &menu); u32 *temp_nogc = (u32 *)tui_do_menu(&menu);
if (temp_nogc != NULL) if (temp_nogc != NULL)
{ {
h_cfg.autonogc = *(u32 *)temp_nogc; h_cfg.autonogc = *(u32 *)temp_nogc;

View file

@ -66,7 +66,7 @@ static int _dump_emmc_verify(sdmmc_storage_t *storage, u32 lba_curr, char *outFi
u8 *bufSd = (u8 *)SDXC_BUF_ALIGNED; u8 *bufSd = (u8 *)SDXC_BUF_ALIGNED;
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);
tui_pbar(&gfx_con, 0, gfx_con.y, pct, 0xFF96FF00, 0xFF155500); tui_pbar(0, gfx_con.y, pct, 0xFF96FF00, 0xFF155500);
u32 num = 0; u32 num = 0;
while (totalSectorsVer > 0) while (totalSectorsVer > 0)
@ -114,7 +114,7 @@ static int _dump_emmc_verify(sdmmc_storage_t *storage, u32 lba_curr, char *outFi
pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start);
if (pct != prevPct) if (pct != prevPct)
{ {
tui_pbar(&gfx_con, 0, gfx_con.y, pct, 0xFF96FF00, 0xFF155500); tui_pbar(0, gfx_con.y, pct, 0xFF96FF00, 0xFF155500);
prevPct = pct; prevPct = pct;
} }
@ -138,7 +138,7 @@ static int _dump_emmc_verify(sdmmc_storage_t *storage, u32 lba_curr, char *outFi
} }
f_close(&fp); f_close(&fp);
tui_pbar(&gfx_con, 0, gfx_con.y, pct, 0xFFCCCCCC, 0xFF555555); tui_pbar(0, gfx_con.y, pct, 0xFFCCCCCC, 0xFF555555);
return 0; return 0;
} }
@ -183,7 +183,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
memcpy(partialIdxFilename, "partial.idx", 12); memcpy(partialIdxFilename, "partial.idx", 12);
gfx_con.fntsz = 8; gfx_con.fntsz = 8;
gfx_printf(&gfx_con, "\nSD Card free space: %d MiB, Total backup size %d MiB\n\n", gfx_printf("\nSD Card free space: %d MiB, Total backup size %d MiB\n\n",
sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF, sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF,
totalSectors >> SECTORS_TO_MIB_COEFF); totalSectors >> SECTORS_TO_MIB_COEFF);
@ -198,7 +198,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
{ {
isSmallSdCard = true; isSmallSdCard = true;
gfx_printf(&gfx_con, "%k\nSD card free space is smaller than total backup size.%k\n", 0xFFFFBA00, 0xFFCCCCCC); gfx_printf("%k\nSD card free space is smaller than total backup size.%k\n", 0xFFFFBA00, 0xFFCCCCCC);
if (!maxSplitParts) if (!maxSplitParts)
{ {
@ -211,7 +211,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
// Check if we are continuing a previous raw eMMC or USER partition backup in progress. // 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 / NX_EMMC_BLOCKSIZE))
{ {
gfx_printf(&gfx_con, "%kFound Partial Backup in progress. Continuing...%k\n\n", 0xFFAEFD14, 0xFFCCCCCC); gfx_printf("%kFound Partial Backup in progress. Continuing...%k\n\n", 0xFFAEFD14, 0xFFCCCCCC);
partialDumpInProgress = true; partialDumpInProgress = true;
// Force partial dumping, even if the card is larger. // Force partial dumping, even if the card is larger.
@ -232,7 +232,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
maxSplitParts += currPartIdx; maxSplitParts += currPartIdx;
} }
else if (isSmallSdCard) else if (isSmallSdCard)
gfx_printf(&gfx_con, "%kPartial Backup enabled (with %d MiB parts)...%k\n\n", 0xFFFFBA00, multipartSplitSize >> 20, 0xFFCCCCCC); gfx_printf("%kPartial Backup enabled (with %d MiB parts)...%k\n\n", 0xFFFFBA00, multipartSplitSize >> 20, 0xFFCCCCCC);
// Check if filesystem is FAT32 or the free space is smaller and backup in parts. // 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 / NX_EMMC_BLOCKSIZE)) | isSmallSdCard)
@ -247,7 +247,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
} }
FIL fp; FIL fp;
gfx_con_getpos(&gfx_con, &gfx_con.savedx, &gfx_con.savedy); gfx_con_getpos(&gfx_con.savedx, &gfx_con.savedy);
if (!f_open(&fp, outFilename, FA_READ)) if (!f_open(&fp, outFilename, FA_READ))
{ {
f_close(&fp); f_close(&fp);
@ -260,10 +260,10 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
if (!(btn_wait() & BTN_POWER)) if (!(btn_wait() & BTN_POWER))
return 0; return 0;
gfx_con.fntsz = 8; gfx_con.fntsz = 8;
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, gfx_con.savedy, 48); gfx_clear_partial_grey(0x1B, gfx_con.savedy, 48);
} }
gfx_con_setpos(&gfx_con, gfx_con.savedx, gfx_con.savedy); gfx_con_setpos(gfx_con.savedx, gfx_con.savedy);
gfx_printf(&gfx_con, "Filename: %s\n\n", outFilename); gfx_printf("Filename: %s\n\n", outFilename);
res = f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE); res = f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE);
if (res) if (res)
{ {
@ -338,7 +338,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
// More parts to backup that do not currently fit the sd card free space or fatal error. // More parts to backup that do not currently fit the sd card free space or fatal error.
if (currPartIdx >= maxSplitParts) if (currPartIdx >= maxSplitParts)
{ {
gfx_puts(&gfx_con, "\n\n1. Press any key to unmount SD Card.\n\ gfx_puts("\n\n1. Press any key to unmount SD Card.\n\
2. Remove SD Card and move files to free space.\n\ 2. Remove SD Card and move files to free space.\n\
Don\'t move the partial.idx file!\n\ Don\'t move the partial.idx file!\n\
3. Re-insert SD Card.\n\ 3. Re-insert SD Card.\n\
@ -350,8 +350,8 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
} }
// Create next part. // Create next part.
gfx_con_setpos(&gfx_con, gfx_con.savedx, gfx_con.savedy); gfx_con_setpos(gfx_con.savedx, gfx_con.savedy);
gfx_printf(&gfx_con, "Filename: %s\n\n", outFilename); gfx_printf("Filename: %s\n\n", outFilename);
lbaStartPart = lba_curr; lbaStartPart = lba_curr;
res = f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE); res = f_open(&fp, outFilename, FA_CREATE_ALWAYS | FA_WRITE);
if (res) if (res)
@ -404,7 +404,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start);
if (pct != prevPct) if (pct != prevPct)
{ {
tui_pbar(&gfx_con, 0, gfx_con.y, pct, 0xFFCCCCCC, 0xFF555555); tui_pbar(0, gfx_con.y, pct, 0xFFCCCCCC, 0xFF555555);
prevPct = pct; prevPct = pct;
} }
@ -433,7 +433,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
return 0; return 0;
} }
} }
tui_pbar(&gfx_con, 0, gfx_con.y, 100, 0xFFCCCCCC, 0xFF555555); tui_pbar(0, gfx_con.y, 100, 0xFFCCCCCC, 0xFF555555);
// Backup operation ended successfully. // Backup operation ended successfully.
f_close(&fp); f_close(&fp);
@ -448,7 +448,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
return 0; return 0;
} }
else else
tui_pbar(&gfx_con, 0, gfx_con.y, 100, 0xFF96FF00, 0xFF155500); tui_pbar(0, gfx_con.y, 100, 0xFF96FF00, 0xFF155500);
} }
gfx_con.fntsz = 16; gfx_con.fntsz = 16;
@ -456,9 +456,9 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
if (isSmallSdCard) if (isSmallSdCard)
{ {
f_unlink(partialIdxFilename); f_unlink(partialIdxFilename);
gfx_printf(&gfx_con, "%k\n\nYou can now join the files\nand get the complete eMMC RAW GPP backup.", 0xFFCCCCCC); gfx_printf("%k\n\nYou can now join the files\nand get the complete eMMC RAW GPP backup.", 0xFFCCCCCC);
} }
gfx_puts(&gfx_con, "\n\n"); gfx_puts("\n\n");
return 1; return 1;
} }
@ -476,14 +476,14 @@ static void _dump_emmc_selected(emmcPartType_t dumpType)
{ {
int res = 0; int res = 0;
u32 timer = 0; u32 timer = 0;
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
tui_sbar(&gfx_con, true); tui_sbar(true);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
if (!sd_mount()) if (!sd_mount())
goto out; goto out;
gfx_puts(&gfx_con, "Checking for available free space...\n\n"); gfx_puts("Checking for available free space...\n\n");
// Get SD Card free space for Partial Backup. // Get SD Card free space for Partial Backup.
f_getfree("", &sd_fs.free_clst, NULL); f_getfree("", &sd_fs.free_clst, NULL);
@ -516,7 +516,7 @@ static void _dump_emmc_selected(emmcPartType_t dumpType)
bootPart.name[4] = (u8)('0' + i); bootPart.name[4] = (u8)('0' + i);
bootPart.name[5] = 0; bootPart.name[5] = 0;
gfx_printf(&gfx_con, "%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i, gfx_printf("%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i,
bootPart.name, bootPart.lba_start, bootPart.lba_end, 0xFFCCCCCC); bootPart.name, bootPart.lba_start, bootPart.lba_end, 0xFFCCCCCC);
sdmmc_storage_set_mmc_partition(&storage, i + 1); sdmmc_storage_set_mmc_partition(&storage, i + 1);
@ -541,7 +541,7 @@ static void _dump_emmc_selected(emmcPartType_t dumpType)
if ((dumpType & PART_SYSTEM) == 0 && strcmp(part->name, "USER")) if ((dumpType & PART_SYSTEM) == 0 && strcmp(part->name, "USER"))
continue; continue;
gfx_printf(&gfx_con, "%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i++, gfx_printf("%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i++,
part->name, part->lba_start, part->lba_end, 0xFFCCCCCC); part->name, part->lba_start, part->lba_end, 0xFFCCCCCC);
emmcsn_path_impl(sdPath, "/partitions", part->name, &storage); emmcsn_path_impl(sdPath, "/partitions", part->name, &storage);
@ -564,7 +564,7 @@ static void _dump_emmc_selected(emmcPartType_t dumpType)
rawPart.lba_end = RAW_AREA_NUM_SECTORS - 1; rawPart.lba_end = RAW_AREA_NUM_SECTORS - 1;
strcpy(rawPart.name, "rawnand.bin"); strcpy(rawPart.name, "rawnand.bin");
{ {
gfx_printf(&gfx_con, "%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i++, gfx_printf("%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i++,
rawPart.name, rawPart.lba_start, rawPart.lba_end, 0xFFCCCCCC); rawPart.name, rawPart.lba_start, rawPart.lba_end, 0xFFCCCCCC);
emmcsn_path_impl(sdPath, "", rawPart.name, &storage); emmcsn_path_impl(sdPath, "", rawPart.name, &storage);
@ -573,14 +573,14 @@ static void _dump_emmc_selected(emmcPartType_t dumpType)
} }
} }
gfx_putc(&gfx_con, '\n'); gfx_putc('\n');
timer = get_tmr_s() - timer; timer = get_tmr_s() - timer;
gfx_printf(&gfx_con, "Time taken: %dm %ds.\n", timer / 60, timer % 60); gfx_printf("Time taken: %dm %ds.\n", timer / 60, timer % 60);
sdmmc_storage_end(&storage); sdmmc_storage_end(&storage);
if (res && h_cfg.verification) if (res && h_cfg.verification)
gfx_printf(&gfx_con, "\n%kFinished and verified!%k\nPress any key...\n", 0xFF96FF00, 0xFFCCCCCC); gfx_printf("\n%kFinished and verified!%k\nPress any key...\n", 0xFF96FF00, 0xFFCCCCCC);
else if (res) else if (res)
gfx_printf(&gfx_con, "\nFinished! Press any key...\n"); gfx_printf("\nFinished! Press any key...\n");
out: out:
sd_unmount(); sd_unmount();
@ -610,7 +610,7 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part
FIL fp; FIL fp;
FILINFO fno; FILINFO fno;
gfx_con_getpos(&gfx_con, &gfx_con.savedx, &gfx_con.savedy); gfx_con_getpos(&gfx_con.savedx, &gfx_con.savedy);
bool use_multipart = false; bool use_multipart = false;
@ -620,7 +620,7 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part
if (f_stat(outFilename, &fno)) if (f_stat(outFilename, &fno))
{ {
// If not, check if there are partial files and the total size matches. // If not, check if there are partial files and the total size matches.
gfx_printf(&gfx_con, "No single file, checking for part files...\n"); gfx_printf("No single file, checking for part files...\n");
outFilename[sdPathLen++] = '.'; outFilename[sdPathLen++] = '.';
@ -629,8 +629,8 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part
{ {
_update_filename(outFilename, sdPathLen, 99, numSplitParts); _update_filename(outFilename, sdPathLen, 99, numSplitParts);
gfx_con_setpos(&gfx_con, gfx_con.savedx, gfx_con.savedy); gfx_con_setpos(gfx_con.savedx, gfx_con.savedy);
gfx_printf(&gfx_con, "\nFilename: %s\n", outFilename); gfx_printf("\nFilename: %s\n", outFilename);
if (f_stat(outFilename, &fno)) if (f_stat(outFilename, &fno))
{ {
@ -643,7 +643,7 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part
numSplitParts++; numSplitParts++;
} }
gfx_printf(&gfx_con, "\n%X sectors total.\n", (u32)((u64)totalCheckFileSize >> (u64)9)); gfx_printf("\n%X sectors total.\n", (u32)((u64)totalCheckFileSize >> (u64)9));
if ((u32)((u64)totalCheckFileSize >> (u64)9) != totalSectors) if ((u32)((u64)totalCheckFileSize >> (u64)9) != totalSectors)
{ {
@ -661,8 +661,8 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part
} }
res = f_open(&fp, outFilename, FA_READ); res = f_open(&fp, outFilename, FA_READ);
gfx_con_setpos(&gfx_con, gfx_con.savedx, gfx_con.savedy); gfx_con_setpos(gfx_con.savedx, gfx_con.savedy);
gfx_printf(&gfx_con, "\nFilename: %s\n", outFilename); gfx_printf("\nFilename: %s\n", outFilename);
if (res) if (res)
{ {
if (res != FR_NO_FILE) if (res != FR_NO_FILE)
@ -684,7 +684,7 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part
else else
{ {
fileSize = (u64)f_size(&fp); fileSize = (u64)f_size(&fp);
gfx_printf(&gfx_con, "\nTotal restore size: %d MiB.\n\n", gfx_printf("\nTotal restore size: %d MiB.\n\n",
(u32)((use_multipart ? (u64)totalCheckFileSize : fileSize) >> (u64)9) >> SECTORS_TO_MIB_COEFF); (u32)((use_multipart ? (u64)totalCheckFileSize : fileSize) >> (u64)9) >> SECTORS_TO_MIB_COEFF);
} }
@ -698,7 +698,7 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part
u32 num = 0; u32 num = 0;
u32 pct = 0; u32 pct = 0;
gfx_con_getpos(&gfx_con, &gfx_con.savedx, &gfx_con.savedy); gfx_con_getpos(&gfx_con.savedx, &gfx_con.savedy);
while (totalSectors > 0) while (totalSectors > 0)
{ {
@ -724,8 +724,8 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part
_update_filename(outFilename, sdPathLen, numSplitParts, currPartIdx); _update_filename(outFilename, sdPathLen, numSplitParts, currPartIdx);
// Read from next part. // Read from next part.
gfx_con_setpos(&gfx_con, gfx_con.savedx, gfx_con.savedy); gfx_con_setpos(gfx_con.savedx, gfx_con.savedy);
gfx_printf(&gfx_con, "Filename: %s\n\n", outFilename); gfx_printf("Filename: %s\n\n", outFilename);
lbaStartPart = lba_curr; lbaStartPart = lba_curr;
@ -775,7 +775,7 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part
pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start); pct = (u64)((u64)(lba_curr - part->lba_start) * 100u) / (u64)(part->lba_end - part->lba_start);
if (pct != prevPct) if (pct != prevPct)
{ {
tui_pbar(&gfx_con, 0, gfx_con.y, pct, 0xFFCCCCCC, 0xFF555555); tui_pbar(0, gfx_con.y, pct, 0xFFCCCCCC, 0xFF555555);
prevPct = pct; prevPct = pct;
} }
@ -783,7 +783,7 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part
totalSectors -= num; totalSectors -= num;
bytesWritten += num * NX_EMMC_BLOCKSIZE; bytesWritten += num * NX_EMMC_BLOCKSIZE;
} }
tui_pbar(&gfx_con, 0, gfx_con.y, 100, 0xFFCCCCCC, 0xFF555555); tui_pbar(0, gfx_con.y, 100, 0xFFCCCCCC, 0xFF555555);
// Restore operation ended successfully. // Restore operation ended successfully.
f_close(&fp); f_close(&fp);
@ -798,11 +798,11 @@ static int _restore_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part
return 0; return 0;
} }
else else
tui_pbar(&gfx_con, 0, gfx_con.y, 100, 0xFF96FF00, 0xFF155500); tui_pbar(0, gfx_con.y, 100, 0xFF96FF00, 0xFF155500);
} }
gfx_con.fntsz = 16; gfx_con.fntsz = 16;
gfx_puts(&gfx_con, "\n\n"); gfx_puts("\n\n");
return 1; return 1;
} }
@ -811,33 +811,33 @@ static void _restore_emmc_selected(emmcPartType_t restoreType)
{ {
int res = 0; int res = 0;
u32 timer = 0; u32 timer = 0;
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
tui_sbar(&gfx_con, true); tui_sbar(true);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
gfx_printf(&gfx_con, "%kThis may render your device inoperative!\n\n", 0xFFFFDD00); gfx_printf("%kThis may render your device inoperative!\n\n", 0xFFFFDD00);
gfx_printf(&gfx_con, "Are you really sure?\n\n%k", 0xFFCCCCCC); gfx_printf("Are you really sure?\n\n%k", 0xFFCCCCCC);
if ((restoreType & PART_BOOT) || (restoreType & PART_GP_ALL)) if ((restoreType & PART_BOOT) || (restoreType & PART_GP_ALL))
{ {
gfx_puts(&gfx_con, "The mode you selected will only restore\nthe "); gfx_puts("The mode you selected will only restore\nthe ");
if (restoreType & PART_BOOT) if (restoreType & PART_BOOT)
gfx_puts(&gfx_con, "boot "); gfx_puts("boot ");
gfx_puts(&gfx_con, "partitions that it can find.\n"); gfx_puts("partitions that it can find.\n");
gfx_puts(&gfx_con, "If it is not found, it will be skipped\nand continue with the next.\n\n"); gfx_puts("If it is not found, it will be skipped\nand continue with the next.\n\n");
} }
gfx_con_getpos(&gfx_con, &gfx_con.savedx, &gfx_con.savedy); gfx_con_getpos(&gfx_con.savedx, &gfx_con.savedy);
u8 failsafe_wait = 10; u8 failsafe_wait = 10;
while (failsafe_wait > 0) while (failsafe_wait > 0)
{ {
gfx_con_setpos(&gfx_con, gfx_con.savedx, gfx_con.savedy); gfx_con_setpos(gfx_con.savedx, gfx_con.savedy);
gfx_printf(&gfx_con, "%kWait... (%ds) %k", 0xFF888888, failsafe_wait, 0xFFCCCCCC); gfx_printf("%kWait... (%ds) %k", 0xFF888888, failsafe_wait, 0xFFCCCCCC);
msleep(1000); msleep(1000);
failsafe_wait--; failsafe_wait--;
} }
gfx_con_setpos(&gfx_con, gfx_con.savedx, gfx_con.savedy); gfx_con_setpos(gfx_con.savedx, gfx_con.savedy);
gfx_puts(&gfx_con, "Press POWER to Continue.\nPress VOL to go to the menu.\n\n\n"); gfx_puts("Press POWER to Continue.\nPress VOL to go to the menu.\n\n\n");
u32 btn = btn_wait(); u32 btn = btn_wait();
if (!(btn & BTN_POWER)) if (!(btn & BTN_POWER))
@ -872,7 +872,7 @@ static void _restore_emmc_selected(emmcPartType_t restoreType)
bootPart.name[4] = (u8)('0' + i); bootPart.name[4] = (u8)('0' + i);
bootPart.name[5] = 0; bootPart.name[5] = 0;
gfx_printf(&gfx_con, "%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i, gfx_printf("%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i,
bootPart.name, bootPart.lba_start, bootPart.lba_end, 0xFFCCCCCC); bootPart.name, bootPart.lba_start, bootPart.lba_end, 0xFFCCCCCC);
sdmmc_storage_set_mmc_partition(&storage, i + 1); sdmmc_storage_set_mmc_partition(&storage, i + 1);
@ -890,7 +890,7 @@ static void _restore_emmc_selected(emmcPartType_t restoreType)
nx_emmc_gpt_parse(&gpt, &storage); nx_emmc_gpt_parse(&gpt, &storage);
LIST_FOREACH_ENTRY(emmc_part_t, part, &gpt, link) LIST_FOREACH_ENTRY(emmc_part_t, part, &gpt, link)
{ {
gfx_printf(&gfx_con, "%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i++, gfx_printf("%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i++,
part->name, part->lba_start, part->lba_end, 0xFFCCCCCC); part->name, part->lba_start, part->lba_end, 0xFFCCCCCC);
emmcsn_path_impl(sdPath, "/restore/partitions/", part->name, &storage); emmcsn_path_impl(sdPath, "/restore/partitions/", part->name, &storage);
@ -910,7 +910,7 @@ static void _restore_emmc_selected(emmcPartType_t restoreType)
rawPart.lba_end = RAW_AREA_NUM_SECTORS - 1; rawPart.lba_end = RAW_AREA_NUM_SECTORS - 1;
strcpy(rawPart.name, "rawnand.bin"); strcpy(rawPart.name, "rawnand.bin");
{ {
gfx_printf(&gfx_con, "%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i++, gfx_printf("%k%02d: %s (%07X-%07X)%k\n", 0xFF00DDFF, i++,
rawPart.name, rawPart.lba_start, rawPart.lba_end, 0xFFCCCCCC); rawPart.name, rawPart.lba_start, rawPart.lba_end, 0xFFCCCCCC);
emmcsn_path_impl(sdPath, "/restore", rawPart.name, &storage); emmcsn_path_impl(sdPath, "/restore", rawPart.name, &storage);
@ -918,14 +918,14 @@ static void _restore_emmc_selected(emmcPartType_t restoreType)
} }
} }
gfx_putc(&gfx_con, '\n'); gfx_putc('\n');
timer = get_tmr_s() - timer; timer = get_tmr_s() - timer;
gfx_printf(&gfx_con, "Time taken: %dm %ds.\n", timer / 60, timer % 60); gfx_printf("Time taken: %dm %ds.\n", timer / 60, timer % 60);
sdmmc_storage_end(&storage); sdmmc_storage_end(&storage);
if (res && h_cfg.verification) if (res && h_cfg.verification)
gfx_printf(&gfx_con, "\n%kFinished and verified!%k\nPress any key...\n", 0xFF96FF00, 0xFFCCCCCC); gfx_printf("\n%kFinished and verified!%k\nPress any key...\n", 0xFF96FF00, 0xFFCCCCCC);
else if (res) else if (res)
gfx_printf(&gfx_con, "\nFinished! Press any key...\n"); gfx_printf("\nFinished! Press any key...\n");
out: out:
sd_unmount(); sd_unmount();

View file

@ -48,8 +48,8 @@ extern void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_st
void print_fuseinfo() void print_fuseinfo()
{ {
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
u32 burntFuses = 0; u32 burntFuses = 0;
for (u32 i = 0; i < 32; i++) for (u32 i = 0; i < 32; i++)
@ -58,26 +58,26 @@ void print_fuseinfo()
burntFuses++; burntFuses++;
} }
gfx_printf(&gfx_con, "\nSKU: %X - ", FUSE(FUSE_SKU_INFO)); gfx_printf("\nSKU: %X - ", FUSE(FUSE_SKU_INFO));
switch (fuse_read_odm(4) & 3) switch (fuse_read_odm(4) & 3)
{ {
case 0: case 0:
gfx_printf(&gfx_con, "Retail\n"); gfx_printf("Retail\n");
break; break;
case 3: case 3:
gfx_printf(&gfx_con, "Dev\n"); gfx_printf("Dev\n");
break; break;
} }
gfx_printf(&gfx_con, "Sdram ID: %d\n", (fuse_read_odm(4) >> 3) & 0x1F); gfx_printf("Sdram ID: %d\n", (fuse_read_odm(4) >> 3) & 0x1F);
gfx_printf(&gfx_con, "Burnt fuses: %d / 64\n", burntFuses); gfx_printf("Burnt fuses: %d / 64\n", burntFuses);
gfx_printf(&gfx_con, "Secure key: %08X%08X%08X%08X\n\n\n", gfx_printf("Secure key: %08X%08X%08X%08X\n\n\n",
byte_swap_32(FUSE(FUSE_PRIVATE_KEY0)), byte_swap_32(FUSE(FUSE_PRIVATE_KEY1)), byte_swap_32(FUSE(FUSE_PRIVATE_KEY0)), byte_swap_32(FUSE(FUSE_PRIVATE_KEY1)),
byte_swap_32(FUSE(FUSE_PRIVATE_KEY2)), byte_swap_32(FUSE(FUSE_PRIVATE_KEY3))); byte_swap_32(FUSE(FUSE_PRIVATE_KEY2)), byte_swap_32(FUSE(FUSE_PRIVATE_KEY3)));
gfx_printf(&gfx_con, "%k(Unlocked) fuse cache:\n\n%k", 0xFF00DDFF, 0xFFCCCCCC); gfx_printf("%k(Unlocked) fuse cache:\n\n%k", 0xFF00DDFF, 0xFFCCCCCC);
gfx_hexdump(&gfx_con, 0x7000F900, (u8 *)0x7000F900, 0x2FC); gfx_hexdump(0x7000F900, (u8 *)0x7000F900, 0x2FC);
gfx_puts(&gfx_con, "\nPress POWER to dump them to SD Card.\nPress VOL to go to the menu.\n"); gfx_puts("\nPress POWER to dump them to SD Card.\nPress VOL to go to the menu.\n");
u32 btn = btn_wait(); u32 btn = btn_wait();
if (btn & BTN_POWER) if (btn & BTN_POWER)
@ -87,7 +87,7 @@ void print_fuseinfo()
char path[64]; char path[64];
emmcsn_path_impl(path, "/dumps", "fuses.bin", NULL); emmcsn_path_impl(path, "/dumps", "fuses.bin", NULL);
if (!sd_save_to_file((u8 *)0x7000F900, 0x2FC, path)) if (!sd_save_to_file((u8 *)0x7000F900, 0x2FC, path))
gfx_puts(&gfx_con, "\nDone!\n"); gfx_puts("\nDone!\n");
sd_unmount(); sd_unmount();
} }
@ -97,17 +97,17 @@ void print_fuseinfo()
void print_kfuseinfo() void print_kfuseinfo()
{ {
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
gfx_printf(&gfx_con, "%kKFuse contents:\n\n%k", 0xFF00DDFF, 0xFFCCCCCC); gfx_printf("%kKFuse contents:\n\n%k", 0xFF00DDFF, 0xFFCCCCCC);
u32 buf[KFUSE_NUM_WORDS]; u32 buf[KFUSE_NUM_WORDS];
if (!kfuse_read(buf)) if (!kfuse_read(buf))
EPRINTF("CRC fail."); EPRINTF("CRC fail.");
else else
gfx_hexdump(&gfx_con, 0, (u8 *)buf, KFUSE_NUM_WORDS * 4); gfx_hexdump(0, (u8 *)buf, KFUSE_NUM_WORDS * 4);
gfx_puts(&gfx_con, "\nPress POWER to dump them to SD Card.\nPress VOL to go to the menu.\n"); gfx_puts("\nPress POWER to dump them to SD Card.\nPress VOL to go to the menu.\n");
u32 btn = btn_wait(); u32 btn = btn_wait();
if (btn & BTN_POWER) if (btn & BTN_POWER)
@ -117,7 +117,7 @@ void print_kfuseinfo()
char path[64]; char path[64];
emmcsn_path_impl(path, "/dumps", "kfuses.bin", NULL); emmcsn_path_impl(path, "/dumps", "kfuses.bin", NULL);
if (!sd_save_to_file((u8 *)buf, KFUSE_NUM_WORDS * 4, path)) if (!sd_save_to_file((u8 *)buf, KFUSE_NUM_WORDS * 4, path))
gfx_puts(&gfx_con, "\nDone!\n"); gfx_puts("\nDone!\n");
sd_unmount(); sd_unmount();
} }
@ -127,8 +127,8 @@ void print_kfuseinfo()
void print_mmc_info() void print_mmc_info()
{ {
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
static const u32 SECTORS_TO_MIB_COEFF = 11; static const u32 SECTORS_TO_MIB_COEFF = 11;
@ -145,12 +145,12 @@ void print_mmc_info()
u16 card_type; u16 card_type;
u32 speed = 0; u32 speed = 0;
gfx_printf(&gfx_con, "%kCID:%k\n", 0xFF00DDFF, 0xFFCCCCCC); gfx_printf("%kCID:%k\n", 0xFF00DDFF, 0xFFCCCCCC);
switch (storage.csd.mmca_vsn) switch (storage.csd.mmca_vsn)
{ {
case 0: /* MMC v1.0 - v1.2 */ case 0: /* MMC v1.0 - v1.2 */
case 1: /* MMC v1.4 */ case 1: /* MMC v1.4 */
gfx_printf(&gfx_con, gfx_printf(
" Vendor ID: %03X\n" " Vendor ID: %03X\n"
" Model: %c%c%c%c%c%c%c\n" " Model: %c%c%c%c%c%c%c\n"
" HW rev: %X\n" " HW rev: %X\n"
@ -166,7 +166,7 @@ void print_mmc_info()
case 2: /* MMC v2.0 - v2.2 */ case 2: /* MMC v2.0 - v2.2 */
case 3: /* MMC v3.1 - v3.3 */ case 3: /* MMC v3.1 - v3.3 */
case 4: /* MMC v4 */ case 4: /* MMC v4 */
gfx_printf(&gfx_con, gfx_printf(
" Vendor ID: %X\n" " Vendor ID: %X\n"
" Card/BGA: %X\n" " Card/BGA: %X\n"
" OEM ID: %02X\n" " OEM ID: %02X\n"
@ -188,7 +188,7 @@ void print_mmc_info()
EPRINTF("Unknown CSD structure."); EPRINTF("Unknown CSD structure.");
else else
{ {
gfx_printf(&gfx_con, "%kExtended CSD V1.%d:%k\n", gfx_printf("%kExtended CSD V1.%d:%k\n",
0xFF00DDFF, storage.ext_csd.ext_struct, 0xFFCCCCCC); 0xFF00DDFF, storage.ext_csd.ext_struct, 0xFFCCCCCC);
card_type = storage.ext_csd.card_type; card_type = storage.ext_csd.card_type;
u8 card_type_support[96]; u8 card_type_support[96];
@ -226,7 +226,7 @@ void print_mmc_info()
} }
card_type_support[pos_type] = 0; card_type_support[pos_type] = 0;
gfx_printf(&gfx_con, gfx_printf(
" Spec Version: %02X\n" " Spec Version: %02X\n"
" Extended Rev: 1.%d\n" " Extended Rev: 1.%d\n"
" Dev Version: %d\n" " Dev Version: %d\n"
@ -239,26 +239,26 @@ void print_mmc_info()
storage.csd.capacity == (4096 * 512) ? "High" : "Low", speed & 0xFFFF, (speed >> 16) & 0xFFFF, storage.csd.capacity == (4096 * 512) ? "High" : "Low", speed & 0xFFFF, (speed >> 16) & 0xFFFF,
storage.csd.busspeed); storage.csd.busspeed);
gfx_con.fntsz = 8; gfx_con.fntsz = 8;
gfx_printf(&gfx_con, "%s", card_type_support); gfx_printf("%s", card_type_support);
gfx_con.fntsz = 16; gfx_con.fntsz = 16;
gfx_printf(&gfx_con, "\n\n", card_type_support); gfx_printf("\n\n", card_type_support);
u32 boot_size = storage.ext_csd.boot_mult << 17; u32 boot_size = storage.ext_csd.boot_mult << 17;
u32 rpmb_size = storage.ext_csd.rpmb_mult << 17; u32 rpmb_size = storage.ext_csd.rpmb_mult << 17;
gfx_printf(&gfx_con, "%keMMC Partitions:%k\n", 0xFF00DDFF, 0xFFCCCCCC); gfx_printf("%keMMC Partitions:%k\n", 0xFF00DDFF, 0xFFCCCCCC);
gfx_printf(&gfx_con, " 1: %kBOOT0 %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", 0xFF96FF00, 0xFFCCCCCC, gfx_printf(" 1: %kBOOT0 %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", 0xFF96FF00, 0xFFCCCCCC,
boot_size / 1024, boot_size / 1024 / 512); boot_size / 1024, boot_size / 1024 / 512);
gfx_put_small_sep(&gfx_con); gfx_put_small_sep(&gfx_con);
gfx_printf(&gfx_con, " 2: %kBOOT1 %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", 0xFF96FF00, 0xFFCCCCCC, gfx_printf(" 2: %kBOOT1 %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", 0xFF96FF00, 0xFFCCCCCC,
boot_size / 1024, boot_size / 1024 / 512); boot_size / 1024, boot_size / 1024 / 512);
gfx_put_small_sep(&gfx_con); gfx_put_small_sep(&gfx_con);
gfx_printf(&gfx_con, " 3: %kRPMB %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", 0xFF96FF00, 0xFFCCCCCC, gfx_printf(" 3: %kRPMB %k\n Size: %5d KiB (LBA Sectors: 0x%07X)\n", 0xFF96FF00, 0xFFCCCCCC,
rpmb_size / 1024, rpmb_size / 1024 / 512); rpmb_size / 1024, rpmb_size / 1024 / 512);
gfx_put_small_sep(&gfx_con); gfx_put_small_sep(&gfx_con);
gfx_printf(&gfx_con, " 0: %kGPP (USER) %k\n Size: %5d MiB (LBA Sectors: 0x%07X)\n\n", 0xFF96FF00, 0xFFCCCCCC, gfx_printf(" 0: %kGPP (USER) %k\n Size: %5d MiB (LBA Sectors: 0x%07X)\n\n", 0xFF96FF00, 0xFFCCCCCC,
storage.sec_cnt >> SECTORS_TO_MIB_COEFF, storage.sec_cnt); storage.sec_cnt >> SECTORS_TO_MIB_COEFF, storage.sec_cnt);
gfx_put_small_sep(&gfx_con); gfx_put_small_sep(&gfx_con);
gfx_printf(&gfx_con, "%kGPP (eMMC USER) partition table:%k\n", 0xFF00DDFF, 0xFFCCCCCC); gfx_printf("%kGPP (eMMC USER) partition table:%k\n", 0xFF00DDFF, 0xFFCCCCCC);
sdmmc_storage_set_mmc_partition(&storage, 0); sdmmc_storage_set_mmc_partition(&storage, 0);
LIST_INIT(gpt); LIST_INIT(gpt);
@ -266,7 +266,7 @@ void print_mmc_info()
int gpp_idx = 0; int gpp_idx = 0;
LIST_FOREACH_ENTRY(emmc_part_t, part, &gpt, link) LIST_FOREACH_ENTRY(emmc_part_t, part, &gpt, link)
{ {
gfx_printf(&gfx_con, " %02d: %k%s%k\n Size: % 5d MiB (LBA Sectors 0x%07X)\n LBA Range: %08X-%08X\n", gfx_printf(" %02d: %k%s%k\n Size: % 5d MiB (LBA Sectors 0x%07X)\n LBA Range: %08X-%08X\n",
gpp_idx++, 0xFFAEFD14, part->name, 0xFFCCCCCC, (part->lba_end - part->lba_start + 1) >> SECTORS_TO_MIB_COEFF, gpp_idx++, 0xFFAEFD14, part->name, 0xFFCCCCCC, (part->lba_end - part->lba_start + 1) >> SECTORS_TO_MIB_COEFF,
part->lba_end - part->lba_start + 1, part->lba_start, part->lba_end); part->lba_end - part->lba_start + 1, part->lba_start, part->lba_end);
gfx_put_small_sep(&gfx_con); gfx_put_small_sep(&gfx_con);
@ -285,15 +285,15 @@ void print_sdcard_info()
{ {
static const u32 SECTORS_TO_MIB_COEFF = 11; static const u32 SECTORS_TO_MIB_COEFF = 11;
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
if (sd_mount()) if (sd_mount())
{ {
u32 capacity; u32 capacity;
gfx_printf(&gfx_con, "%kCard IDentification:%k\n", 0xFF00DDFF, 0xFFCCCCCC); gfx_printf("%kCard IDentification:%k\n", 0xFF00DDFF, 0xFFCCCCCC);
gfx_printf(&gfx_con, gfx_printf(
" Vendor ID: %02x\n" " Vendor ID: %02x\n"
" OEM ID: %c%c\n" " OEM ID: %c%c\n"
" Model: %c%c%c%c%c\n" " Model: %c%c%c%c%c\n"
@ -307,9 +307,9 @@ void print_sdcard_info()
sd_storage.cid.hwrev, sd_storage.cid.fwrev, sd_storage.cid.serial, sd_storage.cid.hwrev, sd_storage.cid.fwrev, sd_storage.cid.serial,
sd_storage.cid.month, sd_storage.cid.year); sd_storage.cid.month, sd_storage.cid.year);
gfx_printf(&gfx_con, "%kCard-Specific Data V%d.0:%k\n", 0xFF00DDFF, sd_storage.csd.structure + 1, 0xFFCCCCCC); gfx_printf("%kCard-Specific Data V%d.0:%k\n", 0xFF00DDFF, sd_storage.csd.structure + 1, 0xFFCCCCCC);
capacity = sd_storage.csd.capacity >> (20 - sd_storage.csd.read_blkbits); capacity = sd_storage.csd.capacity >> (20 - sd_storage.csd.read_blkbits);
gfx_printf(&gfx_con, gfx_printf(
" Cmd Classes: %02X\n" " Cmd Classes: %02X\n"
" Capacity: %d MiB\n" " Capacity: %d MiB\n"
" Bus Width: %d\n" " Bus Width: %d\n"
@ -324,9 +324,9 @@ void print_sdcard_info()
sd_storage.ssr.speed_class, sd_storage.ssr.uhs_grade, sd_storage.ssr.video_class, sd_storage.ssr.speed_class, sd_storage.ssr.uhs_grade, sd_storage.ssr.video_class,
sd_storage.ssr.app_class, sd_storage.csd.write_protect); sd_storage.ssr.app_class, sd_storage.csd.write_protect);
gfx_puts(&gfx_con, "Acquiring FAT volume info...\n\n"); gfx_puts("Acquiring FAT volume info...\n\n");
f_getfree("", &sd_fs.free_clst, NULL); f_getfree("", &sd_fs.free_clst, NULL);
gfx_printf(&gfx_con, "%kFound %s volume:%k\n Free: %d MiB\n Cluster: %d KiB\n", gfx_printf("%kFound %s volume:%k\n Free: %d MiB\n Cluster: %d KiB\n",
0xFF00DDFF, sd_fs.fs_type == FS_EXFAT ? "exFAT" : "FAT32", 0xFFCCCCCC, 0xFF00DDFF, sd_fs.fs_type == FS_EXFAT ? "exFAT" : "FAT32", 0xFFCCCCCC,
sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF, (sd_fs.csize > 1) ? (sd_fs.csize >> 1) : 512); sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF, (sd_fs.csize > 1) ? (sd_fs.csize >> 1) : 512);
sd_unmount(); sd_unmount();
@ -337,8 +337,8 @@ void print_sdcard_info()
void print_tsec_key() void print_tsec_key()
{ {
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
u32 retries = 0; u32 retries = 0;
@ -401,25 +401,25 @@ void print_tsec_key()
} }
} }
gfx_printf(&gfx_con, "%kTSEC key: %k", 0xFF00DDFF, 0xFFCCCCCC); gfx_printf("%kTSEC key: %k", 0xFF00DDFF, 0xFFCCCCCC);
if (res >= 0) if (res >= 0)
{ {
for (u32 j = 0; j < 0x10; j++) for (u32 j = 0; j < 0x10; j++)
gfx_printf(&gfx_con, "%02X", keys[j]); gfx_printf("%02X", keys[j]);
if (pkg1_id->kb == KB_FIRMWARE_VERSION_620) if (pkg1_id->kb == KB_FIRMWARE_VERSION_620)
{ {
gfx_printf(&gfx_con, "\n%kTSEC root: %k", 0xFF00DDFF, 0xFFCCCCCC); gfx_printf("\n%kTSEC root: %k", 0xFF00DDFF, 0xFFCCCCCC);
for (u32 j = 0; j < 0x10; j++) for (u32 j = 0; j < 0x10; j++)
gfx_printf(&gfx_con, "%02X", keys[0x10 + j]); gfx_printf("%02X", keys[0x10 + j]);
} }
} }
else else
EPRINTFARGS("ERROR %X\n", res); EPRINTFARGS("ERROR %X\n", res);
gfx_puts(&gfx_con, "\n\nPress POWER to dump them to SD Card.\nPress VOL to go to the menu.\n"); gfx_puts("\n\nPress POWER to dump them to SD Card.\nPress VOL to go to the menu.\n");
u32 btn = btn_wait(); u32 btn = btn_wait();
if (btn & BTN_POWER) if (btn & BTN_POWER)
@ -429,7 +429,7 @@ void print_tsec_key()
char path[64]; char path[64];
emmcsn_path_impl(path, "/dumps", "tsec_keys.bin", NULL); emmcsn_path_impl(path, "/dumps", "tsec_keys.bin", NULL);
if (!sd_save_to_file(keys, 0x10 * 2, path)) if (!sd_save_to_file(keys, 0x10 * 2, path))
gfx_puts(&gfx_con, "\nDone!\n"); gfx_puts("\nDone!\n");
sd_unmount(); sd_unmount();
} }
} }
@ -447,124 +447,124 @@ void print_fuel_gauge_info()
{ {
int value = 0; int value = 0;
gfx_printf(&gfx_con, "%kFuel Gauge IC Info:\n%k", 0xFF00DDFF, 0xFFCCCCCC); gfx_printf("%kFuel Gauge IC Info:\n%k", 0xFF00DDFF, 0xFFCCCCCC);
max17050_get_property(MAX17050_RepSOC, &value); max17050_get_property(MAX17050_RepSOC, &value);
gfx_printf(&gfx_con, "Capacity now: %3d%\n", value >> 8); gfx_printf("Capacity now: %3d%\n", value >> 8);
max17050_get_property(MAX17050_RepCap, &value); max17050_get_property(MAX17050_RepCap, &value);
gfx_printf(&gfx_con, "Capacity now: %4d mAh\n", value); gfx_printf("Capacity now: %4d mAh\n", value);
max17050_get_property(MAX17050_FullCAP, &value); max17050_get_property(MAX17050_FullCAP, &value);
gfx_printf(&gfx_con, "Capacity full: %4d mAh\n", value); gfx_printf("Capacity full: %4d mAh\n", value);
max17050_get_property(MAX17050_DesignCap, &value); max17050_get_property(MAX17050_DesignCap, &value);
gfx_printf(&gfx_con, "Capacity (design): %4d mAh\n", value); gfx_printf("Capacity (design): %4d mAh\n", value);
max17050_get_property(MAX17050_Current, &value); max17050_get_property(MAX17050_Current, &value);
if (value >= 0) if (value >= 0)
gfx_printf(&gfx_con, "Current now: %d mA\n", value / 1000); gfx_printf("Current now: %d mA\n", value / 1000);
else else
gfx_printf(&gfx_con, "Current now: -%d mA\n", ~value / 1000); gfx_printf("Current now: -%d mA\n", ~value / 1000);
max17050_get_property(MAX17050_AvgCurrent, &value); max17050_get_property(MAX17050_AvgCurrent, &value);
if (value >= 0) if (value >= 0)
gfx_printf(&gfx_con, "Current average: %d mA\n", value / 1000); gfx_printf("Current average: %d mA\n", value / 1000);
else else
gfx_printf(&gfx_con, "Current average: -%d mA\n", ~value / 1000); gfx_printf("Current average: -%d mA\n", ~value / 1000);
max17050_get_property(MAX17050_VCELL, &value); max17050_get_property(MAX17050_VCELL, &value);
gfx_printf(&gfx_con, "Voltage now: %4d mV\n", value); gfx_printf("Voltage now: %4d mV\n", value);
max17050_get_property(MAX17050_OCVInternal, &value); max17050_get_property(MAX17050_OCVInternal, &value);
gfx_printf(&gfx_con, "Voltage open-circuit: %4d mV\n", value); gfx_printf("Voltage open-circuit: %4d mV\n", value);
max17050_get_property(MAX17050_MinVolt, &value); max17050_get_property(MAX17050_MinVolt, &value);
gfx_printf(&gfx_con, "Min voltage reached: %4d mV\n", value); gfx_printf("Min voltage reached: %4d mV\n", value);
max17050_get_property(MAX17050_MaxVolt, &value); max17050_get_property(MAX17050_MaxVolt, &value);
gfx_printf(&gfx_con, "Max voltage reached: %4d mV\n", value); gfx_printf("Max voltage reached: %4d mV\n", value);
max17050_get_property(MAX17050_V_empty, &value); max17050_get_property(MAX17050_V_empty, &value);
gfx_printf(&gfx_con, "Empty voltage (design): %4d mV\n", value); gfx_printf("Empty voltage (design): %4d mV\n", value);
max17050_get_property(MAX17050_TEMP, &value); max17050_get_property(MAX17050_TEMP, &value);
if (value >= 0) if (value >= 0)
gfx_printf(&gfx_con, "Battery temperature: %d.%d oC\n", value / 10, value % 10); gfx_printf("Battery temperature: %d.%d oC\n", value / 10, value % 10);
else else
gfx_printf(&gfx_con, "Battery temperature: -%d.%d oC\n", ~value / 10, (~value) % 10); gfx_printf("Battery temperature: -%d.%d oC\n", ~value / 10, (~value) % 10);
} }
void print_battery_charger_info() void print_battery_charger_info()
{ {
int value = 0; int value = 0;
gfx_printf(&gfx_con, "%k\n\nBattery Charger IC Info:\n%k", 0xFF00DDFF, 0xFFCCCCCC); gfx_printf("%k\n\nBattery Charger IC Info:\n%k", 0xFF00DDFF, 0xFFCCCCCC);
bq24193_get_property(BQ24193_InputVoltageLimit, &value); bq24193_get_property(BQ24193_InputVoltageLimit, &value);
gfx_printf(&gfx_con, "Input voltage limit: %4d mV\n", value); gfx_printf("Input voltage limit: %4d mV\n", value);
bq24193_get_property(BQ24193_InputCurrentLimit, &value); bq24193_get_property(BQ24193_InputCurrentLimit, &value);
gfx_printf(&gfx_con, "Input current limit: %4d mA\n", value); gfx_printf("Input current limit: %4d mA\n", value);
bq24193_get_property(BQ24193_SystemMinimumVoltage, &value); bq24193_get_property(BQ24193_SystemMinimumVoltage, &value);
gfx_printf(&gfx_con, "Min voltage limit: %4d mV\n", value); gfx_printf("Min voltage limit: %4d mV\n", value);
bq24193_get_property(BQ24193_FastChargeCurrentLimit, &value); bq24193_get_property(BQ24193_FastChargeCurrentLimit, &value);
gfx_printf(&gfx_con, "Fast charge current limit: %4d mA\n", value); gfx_printf("Fast charge current limit: %4d mA\n", value);
bq24193_get_property(BQ24193_ChargeVoltageLimit, &value); bq24193_get_property(BQ24193_ChargeVoltageLimit, &value);
gfx_printf(&gfx_con, "Charge voltage limit: %4d mV\n", value); gfx_printf("Charge voltage limit: %4d mV\n", value);
bq24193_get_property(BQ24193_ChargeStatus, &value); bq24193_get_property(BQ24193_ChargeStatus, &value);
gfx_printf(&gfx_con, "Charge status: "); gfx_printf("Charge status: ");
switch (value) switch (value)
{ {
case 0: case 0:
gfx_printf(&gfx_con, "Not charging\n"); gfx_printf("Not charging\n");
break; break;
case 1: case 1:
gfx_printf(&gfx_con, "Pre-charging\n"); gfx_printf("Pre-charging\n");
break; break;
case 2: case 2:
gfx_printf(&gfx_con, "Fast charging\n"); gfx_printf("Fast charging\n");
break; break;
case 3: case 3:
gfx_printf(&gfx_con, "Charge terminated\n"); gfx_printf("Charge terminated\n");
break; break;
default: default:
gfx_printf(&gfx_con, "Unknown (%d)\n", value); gfx_printf("Unknown (%d)\n", value);
break; break;
} }
bq24193_get_property(BQ24193_TempStatus, &value); bq24193_get_property(BQ24193_TempStatus, &value);
gfx_printf(&gfx_con, "Temperature status: "); gfx_printf("Temperature status: ");
switch (value) switch (value)
{ {
case 0: case 0:
gfx_printf(&gfx_con, "Normal\n"); gfx_printf("Normal\n");
break; break;
case 2: case 2:
gfx_printf(&gfx_con, "Warm\n"); gfx_printf("Warm\n");
break; break;
case 3: case 3:
gfx_printf(&gfx_con, "Cool\n"); gfx_printf("Cool\n");
break; break;
case 5: case 5:
gfx_printf(&gfx_con, "Cold\n"); gfx_printf("Cold\n");
break; break;
case 6: case 6:
gfx_printf(&gfx_con, "Hot\n"); gfx_printf("Hot\n");
break; break;
default: default:
gfx_printf(&gfx_con, "Unknown (%d)\n", value); gfx_printf("Unknown (%d)\n", value);
break; break;
} }
} }
void print_battery_info() void print_battery_info()
{ {
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
print_fuel_gauge_info(); print_fuel_gauge_info();
@ -572,7 +572,7 @@ void print_battery_info()
u8 *buf = (u8 *)malloc(0x100 * 2); u8 *buf = (u8 *)malloc(0x100 * 2);
gfx_printf(&gfx_con, "%k\n\nBattery Fuel Gauge Registers:\n%k", 0xFF00DDFF, 0xFFCCCCCC); gfx_printf("%k\n\nBattery Fuel Gauge Registers:\n%k", 0xFF00DDFF, 0xFFCCCCCC);
for (int i = 0; i < 0x200; i += 2) for (int i = 0; i < 0x200; i += 2)
{ {
@ -580,9 +580,9 @@ void print_battery_info()
usleep(2500); usleep(2500);
} }
gfx_hexdump(&gfx_con, 0, (u8 *)buf, 0x200); gfx_hexdump(0, (u8 *)buf, 0x200);
gfx_puts(&gfx_con, "\nPress POWER to dump them to SD Card.\nPress VOL to go to the menu.\n"); gfx_puts("\nPress POWER to dump them to SD Card.\nPress VOL to go to the menu.\n");
u32 btn = btn_wait(); u32 btn = btn_wait();
@ -595,7 +595,7 @@ void print_battery_info()
if (sd_save_to_file((u8 *)buf, 0x200, path)) if (sd_save_to_file((u8 *)buf, 0x200, path))
EPRINTF("\nError creating fuel.bin file."); EPRINTF("\nError creating fuel.bin file.");
else else
gfx_puts(&gfx_con, "\nDone!\n"); gfx_puts("\nDone!\n");
sd_unmount(); sd_unmount();
} }
@ -606,24 +606,24 @@ void print_battery_info()
void _ipatch_process(u32 offset, u32 value) void _ipatch_process(u32 offset, u32 value)
{ {
gfx_printf(&gfx_con, "%8x %8x", BOOTROM_BASE + offset, value); gfx_printf("%8x %8x", BOOTROM_BASE + offset, value);
u8 lo = value & 0xff; u8 lo = value & 0xff;
switch (value >> 8) switch (value >> 8)
{ {
case 0x20: case 0x20:
gfx_printf(&gfx_con, " MOVS R0, #0x%02X", lo); gfx_printf(" MOVS R0, #0x%02X", lo);
break; break;
case 0xDF: case 0xDF:
gfx_printf(&gfx_con, " SVC #0x%02X", lo); gfx_printf(" SVC #0x%02X", lo);
break; break;
} }
gfx_puts(&gfx_con, "\n"); gfx_puts("\n");
} }
void bootrom_ipatches_info() void bootrom_ipatches_info()
{ {
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
static const u32 BOOTROM_SIZE = 0x18000; static const u32 BOOTROM_SIZE = 0x18000;
@ -631,7 +631,7 @@ void bootrom_ipatches_info()
if (res != 0) if (res != 0)
EPRINTFARGS("Failed to read ipatches. Error: %d", res); EPRINTFARGS("Failed to read ipatches. Error: %d", res);
gfx_puts(&gfx_con, "\nPress POWER to dump them to SD Card.\nPress VOL to go to the menu.\n"); gfx_puts("\nPress POWER to dump them to SD Card.\nPress VOL to go to the menu.\n");
u32 btn = btn_wait(); u32 btn = btn_wait();
if (btn & BTN_POWER) if (btn & BTN_POWER)
@ -646,7 +646,7 @@ void bootrom_ipatches_info()
{ {
emmcsn_path_impl(path, "/dumps", "evp_thunks.bin", NULL); emmcsn_path_impl(path, "/dumps", "evp_thunks.bin", NULL);
if (!sd_save_to_file((u8 *)iram_evp_thunks, iram_evp_thunks_len, path)) if (!sd_save_to_file((u8 *)iram_evp_thunks, iram_evp_thunks_len, path))
gfx_puts(&gfx_con, "\nevp_thunks.bin saved!\n"); gfx_puts("\nevp_thunks.bin saved!\n");
} }
else else
EPRINTFARGS("Failed to read evp_thunks. Error: %d", res); EPRINTFARGS("Failed to read evp_thunks. Error: %d", res);
@ -655,11 +655,11 @@ void bootrom_ipatches_info()
read_raw_fuses(words); read_raw_fuses(words);
emmcsn_path_impl(path, "/dumps", "raw_fuses.bin", NULL); emmcsn_path_impl(path, "/dumps", "raw_fuses.bin", NULL);
if (!sd_save_to_file((u8 *)words, sizeof(words), path)) if (!sd_save_to_file((u8 *)words, sizeof(words), path))
gfx_puts(&gfx_con, "\nipatches.bin saved!\n"); gfx_puts("\nipatches.bin saved!\n");
emmcsn_path_impl(path, "/dumps", "bootrom_patched.bin", NULL); emmcsn_path_impl(path, "/dumps", "bootrom_patched.bin", NULL);
if (!sd_save_to_file((u8 *)BOOTROM_BASE, BOOTROM_SIZE, path)) if (!sd_save_to_file((u8 *)BOOTROM_BASE, BOOTROM_SIZE, path))
gfx_puts(&gfx_con, "\nbootrom_patched.bin saved!\n"); gfx_puts("\nbootrom_patched.bin saved!\n");
u32 ipatch_backup[14]; u32 ipatch_backup[14];
memcpy(ipatch_backup, (void *)IPATCH_BASE, sizeof(ipatch_backup)); memcpy(ipatch_backup, (void *)IPATCH_BASE, sizeof(ipatch_backup));
@ -667,7 +667,7 @@ void bootrom_ipatches_info()
emmcsn_path_impl(path, "/dumps", "bootrom_unpatched.bin", NULL); emmcsn_path_impl(path, "/dumps", "bootrom_unpatched.bin", NULL);
if (!sd_save_to_file((u8 *)BOOTROM_BASE, BOOTROM_SIZE, path)) if (!sd_save_to_file((u8 *)BOOTROM_BASE, BOOTROM_SIZE, path))
gfx_puts(&gfx_con, "\nbootrom_unpatched.bin saved!\n"); gfx_puts("\nbootrom_unpatched.bin saved!\n");
memcpy((void*)IPATCH_BASE, ipatch_backup, sizeof(ipatch_backup)); memcpy((void*)IPATCH_BASE, ipatch_backup, sizeof(ipatch_backup));

View file

@ -58,8 +58,8 @@ void dump_packages12()
tsec_ctxt_t tsec_ctxt; tsec_ctxt_t tsec_ctxt;
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
sdmmc_storage_t storage; sdmmc_storage_t storage;
sdmmc_t sdmmc; sdmmc_t sdmmc;
@ -95,12 +95,12 @@ void dump_packages12()
b_cfg.autoboot = 0; b_cfg.autoboot = 0;
b_cfg.autoboot_list = 0; b_cfg.autoboot_list = 0;
gfx_printf(&gfx_con, "sept will run to get the keys.\nThen rerun this option."); gfx_printf("sept will run to get the keys.\nThen rerun this option.");
btn_wait(); btn_wait();
if (!reboot_to_sept((u8 *)tsec_ctxt.fw)) if (!reboot_to_sept((u8 *)tsec_ctxt.fw))
{ {
gfx_printf(&gfx_con, "Failed to run sept\n"); gfx_printf("Failed to run sept\n");
goto out_free; goto out_free;
} }
} }
@ -126,37 +126,37 @@ void dump_packages12()
pkg1_unpack(warmboot, secmon, loader, pkg1_id, pkg1); pkg1_unpack(warmboot, secmon, loader, pkg1_id, pkg1);
// Display info. // Display info.
gfx_printf(&gfx_con, "%kNX Bootloader size: %k0x%05X\n\n", 0xFFC7EA46, 0xFFCCCCCC, hdr->ldr_size); gfx_printf("%kNX Bootloader size: %k0x%05X\n\n", 0xFFC7EA46, 0xFFCCCCCC, hdr->ldr_size);
gfx_printf(&gfx_con, "%kSecure monitor addr: %k0x%05X\n", 0xFFC7EA46, 0xFFCCCCCC, pkg1_id->secmon_base); gfx_printf("%kSecure monitor addr: %k0x%05X\n", 0xFFC7EA46, 0xFFCCCCCC, pkg1_id->secmon_base);
gfx_printf(&gfx_con, "%kSecure monitor size: %k0x%05X\n\n", 0xFFC7EA46, 0xFFCCCCCC, hdr->sm_size); gfx_printf("%kSecure monitor size: %k0x%05X\n\n", 0xFFC7EA46, 0xFFCCCCCC, hdr->sm_size);
gfx_printf(&gfx_con, "%kWarmboot addr: %k0x%05X\n", 0xFFC7EA46, 0xFFCCCCCC, pkg1_id->warmboot_base); gfx_printf("%kWarmboot addr: %k0x%05X\n", 0xFFC7EA46, 0xFFCCCCCC, pkg1_id->warmboot_base);
gfx_printf(&gfx_con, "%kWarmboot size: %k0x%05X\n\n", 0xFFC7EA46, 0xFFCCCCCC, hdr->wb_size); gfx_printf("%kWarmboot size: %k0x%05X\n\n", 0xFFC7EA46, 0xFFCCCCCC, hdr->wb_size);
// Dump package1.1. // Dump package1.1.
emmcsn_path_impl(path, "/pkg1", "pkg1_decr.bin", &storage); emmcsn_path_impl(path, "/pkg1", "pkg1_decr.bin", &storage);
if (sd_save_to_file(pkg1, 0x40000, path)) if (sd_save_to_file(pkg1, 0x40000, path))
goto out_free; goto out_free;
gfx_puts(&gfx_con, "\npkg1 dumped to pkg1_decr.bin\n"); gfx_puts("\npkg1 dumped to pkg1_decr.bin\n");
// Dump nxbootloader. // Dump nxbootloader.
emmcsn_path_impl(path, "/pkg1", "nxloader.bin", &storage); emmcsn_path_impl(path, "/pkg1", "nxloader.bin", &storage);
if (sd_save_to_file(loader, hdr->ldr_size, path)) if (sd_save_to_file(loader, hdr->ldr_size, path))
goto out_free; goto out_free;
gfx_puts(&gfx_con, "NX Bootloader dumped to nxloader.bin\n"); gfx_puts("NX Bootloader dumped to nxloader.bin\n");
// Dump secmon. // Dump secmon.
emmcsn_path_impl(path, "/pkg1", "secmon.bin", &storage); emmcsn_path_impl(path, "/pkg1", "secmon.bin", &storage);
if (sd_save_to_file(secmon, hdr->sm_size, path)) if (sd_save_to_file(secmon, hdr->sm_size, path))
goto out_free; goto out_free;
gfx_puts(&gfx_con, "Secure Monitor dumped to secmon.bin\n"); gfx_puts("Secure Monitor dumped to secmon.bin\n");
// Dump warmboot. // Dump warmboot.
emmcsn_path_impl(path, "/pkg1", "warmboot.bin", &storage); emmcsn_path_impl(path, "/pkg1", "warmboot.bin", &storage);
if (sd_save_to_file(warmboot, hdr->wb_size, path)) if (sd_save_to_file(warmboot, hdr->wb_size, path))
goto out_free; goto out_free;
gfx_puts(&gfx_con, "Warmboot dumped to warmboot.bin\n\n\n"); gfx_puts("Warmboot dumped to warmboot.bin\n\n\n");
} }
// Dump package2.1. // Dump package2.1.
@ -185,30 +185,30 @@ void dump_packages12()
// Display info. // Display info.
u32 kernel_crc32 = crc32c(pkg2_hdr->data, pkg2_hdr->sec_size[PKG2_SEC_KERNEL]); u32 kernel_crc32 = crc32c(pkg2_hdr->data, pkg2_hdr->sec_size[PKG2_SEC_KERNEL]);
gfx_printf(&gfx_con, "\n%kKernel CRC32C: %k0x%08X\n\n", 0xFFC7EA46, 0xFFCCCCCC, kernel_crc32); gfx_printf("\n%kKernel CRC32C: %k0x%08X\n\n", 0xFFC7EA46, 0xFFCCCCCC, kernel_crc32);
gfx_printf(&gfx_con, "%kKernel size: %k0x%05X\n\n", 0xFFC7EA46, 0xFFCCCCCC, pkg2_hdr->sec_size[PKG2_SEC_KERNEL]); gfx_printf("%kKernel size: %k0x%05X\n\n", 0xFFC7EA46, 0xFFCCCCCC, pkg2_hdr->sec_size[PKG2_SEC_KERNEL]);
gfx_printf(&gfx_con, "%kINI1 size: %k0x%05X\n\n", 0xFFC7EA46, 0xFFCCCCCC, pkg2_hdr->sec_size[PKG2_SEC_INI1]); gfx_printf("%kINI1 size: %k0x%05X\n\n", 0xFFC7EA46, 0xFFCCCCCC, pkg2_hdr->sec_size[PKG2_SEC_INI1]);
// Dump pkg2.1. // Dump pkg2.1.
emmcsn_path_impl(path, "/pkg2", "pkg2_decr.bin", &storage); emmcsn_path_impl(path, "/pkg2", "pkg2_decr.bin", &storage);
if (sd_save_to_file(pkg2, pkg2_hdr->sec_size[PKG2_SEC_KERNEL] + pkg2_hdr->sec_size[PKG2_SEC_INI1], path)) if (sd_save_to_file(pkg2, pkg2_hdr->sec_size[PKG2_SEC_KERNEL] + pkg2_hdr->sec_size[PKG2_SEC_INI1], path))
goto out; goto out;
gfx_puts(&gfx_con, "\npkg2 dumped to pkg2_decr.bin\n"); gfx_puts("\npkg2 dumped to pkg2_decr.bin\n");
// Dump kernel. // Dump kernel.
emmcsn_path_impl(path, "/pkg2", "kernel.bin", &storage); emmcsn_path_impl(path, "/pkg2", "kernel.bin", &storage);
if (sd_save_to_file(pkg2_hdr->data, pkg2_hdr->sec_size[PKG2_SEC_KERNEL], path)) if (sd_save_to_file(pkg2_hdr->data, pkg2_hdr->sec_size[PKG2_SEC_KERNEL], path))
goto out; goto out;
gfx_puts(&gfx_con, "Kernel dumped to kernel.bin\n"); gfx_puts("Kernel dumped to kernel.bin\n");
// Dump INI1. // Dump INI1.
emmcsn_path_impl(path, "/pkg2", "ini1.bin", &storage); emmcsn_path_impl(path, "/pkg2", "ini1.bin", &storage);
if (sd_save_to_file(pkg2_hdr->data + pkg2_hdr->sec_size[PKG2_SEC_KERNEL], if (sd_save_to_file(pkg2_hdr->data + pkg2_hdr->sec_size[PKG2_SEC_KERNEL],
pkg2_hdr->sec_size[PKG2_SEC_INI1], path)) pkg2_hdr->sec_size[PKG2_SEC_INI1], path))
goto out; goto out;
gfx_puts(&gfx_con, "INI1 dumped to ini1.bin\n"); gfx_puts("INI1 dumped to ini1.bin\n");
gfx_puts(&gfx_con, "\nDone. Press any key...\n"); gfx_puts("\nDone. Press any key...\n");
out: out:
nx_emmc_gpt_free(&gpt); nx_emmc_gpt_free(&gpt);
@ -234,8 +234,8 @@ void _toggle_autorcm(bool enable)
u8 randomXor = 0; u8 randomXor = 0;
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
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))
{ {
@ -270,10 +270,10 @@ void _toggle_autorcm(bool enable)
sdmmc_storage_end(&storage); sdmmc_storage_end(&storage);
if (enable) if (enable)
gfx_printf(&gfx_con, "%kAutoRCM mode enabled!%k", 0xFFFFBA00, 0xFFCCCCCC); gfx_printf("%kAutoRCM mode enabled!%k", 0xFFFFBA00, 0xFFCCCCCC);
else else
gfx_printf(&gfx_con, "%kAutoRCM mode disabled!%k", 0xFF96FF00, 0xFFCCCCCC); gfx_printf("%kAutoRCM mode disabled!%k", 0xFF96FF00, 0xFFCCCCCC);
gfx_printf(&gfx_con, "\n\nPress any key...\n"); gfx_printf("\n\nPress any key...\n");
out: out:
btn_wait(); btn_wait();
@ -284,8 +284,8 @@ void _disable_autorcm() { _toggle_autorcm(false); }
void menu_autorcm() void menu_autorcm()
{ {
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
// Do a simple check on the main BCT. // Do a simple check on the main BCT.
sdmmc_storage_t storage; sdmmc_storage_t storage;
@ -340,7 +340,7 @@ void menu_autorcm()
memset(&ments[5], 0, sizeof(ment_t)); memset(&ments[5], 0, sizeof(ment_t));
menu_t menu = {ments, "This corrupts your BOOT0!", 0, 0}; menu_t menu = {ments, "This corrupts your BOOT0!", 0, 0};
tui_do_menu(&gfx_con, &menu); tui_do_menu(&menu);
} }
int _fix_attributes(char *path, u32 *total, u32 hos_folder, u32 check_first_run) int _fix_attributes(char *path, u32 *total, u32 hos_folder, u32 check_first_run)
@ -421,8 +421,8 @@ int _fix_attributes(char *path, u32 *total, u32 hos_folder, u32 check_first_run)
void _fix_sd_attr(u32 type) void _fix_sd_attr(u32 type)
{ {
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
char path[256]; char path[256];
char label[16]; char label[16];
@ -443,9 +443,9 @@ void _fix_sd_attr(u32 type)
break; break;
} }
gfx_printf(&gfx_con, "Traversing all %s files!\nThis may take some time...\n\n", label); gfx_printf("Traversing all %s files!\nThis may take some time...\n\n", label);
_fix_attributes(path, &total, type, type); _fix_attributes(path, &total, type, type);
gfx_printf(&gfx_con, "%kTotal archive bits cleared: %d!%k\n\nDone! Press any key...", 0xFF96FF00, total, 0xFFCCCCCC); gfx_printf("%kTotal archive bits cleared: %d!%k\n\nDone! Press any key...", 0xFF96FF00, total, 0xFFCCCCCC);
sd_unmount(); sd_unmount();
} }
btn_wait(); btn_wait();
@ -456,20 +456,20 @@ void fix_sd_nin_attr() { _fix_sd_attr(1); }
void fix_battery_desync() void fix_battery_desync()
{ {
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
max77620_low_battery_monitor_config(); max77620_low_battery_monitor_config();
gfx_puts(&gfx_con, "\nDone!\n"); gfx_puts("\nDone!\n");
btn_wait(); btn_wait();
} }
/* void fix_fuel_gauge_configuration() /* void fix_fuel_gauge_configuration()
{ {
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
int battVoltage, avgCurrent; int battVoltage, avgCurrent;
@ -483,23 +483,23 @@ void fix_battery_desync()
EPRINTF("You need to be connected to a wall adapter,\nto apply this fix!"); EPRINTF("You need to be connected to a wall adapter,\nto apply this fix!");
else else
{ {
gfx_printf(&gfx_con, "%kAre you really sure?\nThis will reset your fuel gauge completely!\n", 0xFFFFDD00); gfx_printf("%kAre you really sure?\nThis will reset your fuel gauge completely!\n", 0xFFFFDD00);
gfx_printf(&gfx_con, "Additionally this will power off your console.\n%k", 0xFFCCCCCC); gfx_printf("Additionally this will power off your console.\n%k", 0xFFCCCCCC);
gfx_puts(&gfx_con, "\nPress POWER to Continue.\nPress VOL to go to the menu.\n\n\n"); gfx_puts("\nPress POWER to Continue.\nPress VOL to go to the menu.\n\n\n");
u32 btn = btn_wait(); u32 btn = btn_wait();
if (btn & BTN_POWER) if (btn & BTN_POWER)
{ {
max17050_fix_configuration(); max17050_fix_configuration();
msleep(1000); msleep(1000);
gfx_con_getpos(&gfx_con, &gfx_con.savedx, &gfx_con.savedy); gfx_con_getpos(&gfx_con.savedx, &gfx_con.savedy);
u16 value = 0; u16 value = 0;
gfx_printf(&gfx_con, "%kThe console will power off in 45 seconds.\n%k", 0xFFFFDD00, 0xFFCCCCCC); gfx_printf("%kThe console will power off in 45 seconds.\n%k", 0xFFFFDD00, 0xFFCCCCCC);
while (value < 46) while (value < 46)
{ {
gfx_con_setpos(&gfx_con, gfx_con.savedx, gfx_con.savedy); gfx_con_setpos(gfx_con.savedx, gfx_con.savedy);
gfx_printf(&gfx_con, "%2ds elapsed", value); gfx_printf("%2ds elapsed", value);
msleep(1000); msleep(1000);
value++; value++;
} }
@ -521,31 +521,31 @@ void fix_battery_desync()
{ {
int avgCurrent; int avgCurrent;
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
gfx_printf(&gfx_con, "%k\nThis will wipe your battery stats completely!\n" gfx_printf("%k\nThis will wipe your battery stats completely!\n"
"%kAnd it may not power on without physically\nremoving and re-inserting the battery.\n%k" "%kAnd it may not power on without physically\nremoving and re-inserting the battery.\n%k"
"\nAre you really sure?%k\n", 0xFFFFDD00, 0xFFFF0000, 0xFFFFDD00, 0xFFCCCCCC); "\nAre you really sure?%k\n", 0xFFFFDD00, 0xFFFF0000, 0xFFFFDD00, 0xFFCCCCCC);
gfx_puts(&gfx_con, "\nPress POWER to Continue.\nPress VOL to go to the menu.\n\n\n"); gfx_puts("\nPress POWER to Continue.\nPress VOL to go to the menu.\n\n\n");
u32 btn = btn_wait(); u32 btn = btn_wait();
if (btn & BTN_POWER) if (btn & BTN_POWER)
{ {
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
gfx_printf(&gfx_con, "%kKeep the USB cable connected!%k\n\n", 0xFFFFDD00, 0xFFCCCCCC); gfx_printf("%kKeep the USB cable connected!%k\n\n", 0xFFFFDD00, 0xFFCCCCCC);
gfx_con_getpos(&gfx_con, &gfx_con.savedx, &gfx_con.savedy); gfx_con_getpos(&gfx_con.savedx, &gfx_con.savedy);
u8 value = 30; u8 value = 30;
while (value > 0) while (value > 0)
{ {
gfx_con_setpos(&gfx_con, gfx_con.savedx, gfx_con.savedy); gfx_con_setpos(gfx_con.savedx, gfx_con.savedy);
gfx_printf(&gfx_con, "%kWait... (%ds) %k", 0xFF888888, value, 0xFFCCCCCC); gfx_printf("%kWait... (%ds) %k", 0xFF888888, value, 0xFFCCCCCC);
msleep(1000); msleep(1000);
value--; value--;
} }
gfx_con_setpos(&gfx_con, gfx_con.savedx, gfx_con.savedy); gfx_con_setpos(gfx_con.savedx, gfx_con.savedy);
//Check if still connected. //Check if still connected.
max17050_get_property(MAX17050_AvgCurrent, &avgCurrent); max17050_get_property(MAX17050_AvgCurrent, &avgCurrent);
@ -555,7 +555,7 @@ void fix_battery_desync()
{ {
// Apply fix. // Apply fix.
bq24193_fake_battery_removal(); bq24193_fake_battery_removal();
gfx_printf(&gfx_con, "Done! \n" gfx_printf("Done! \n"
"%k1. Remove the USB cable\n" "%k1. Remove the USB cable\n"
"2. Press POWER for 15s.\n" "2. Press POWER for 15s.\n"
"3. Reconnect the USB to power-on!%k\n", 0xFFFFDD00, 0xFFCCCCCC); "3. Reconnect the USB to power-on!%k\n", 0xFFFFDD00, 0xFFCCCCCC);
@ -573,22 +573,22 @@ void fix_battery_desync()
void minerva() void minerva()
{ {
gfx_clear_partial_grey(&gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
u32 curr_ram_idx = 0; u32 curr_ram_idx = 0;
if (!sd_mount()) if (!sd_mount())
return; return;
gfx_printf(&gfx_con, "-- Minerva Training Cell --\n\n"); gfx_printf("-- Minerva Training Cell --\n\n");
// Set table to ram. // Set table to ram.
mtc_cfg.mtc_table = NULL; mtc_cfg.mtc_table = NULL;
mtc_cfg.sdram_id = (fuse_read_odm(4) >> 3) & 0x1F; mtc_cfg.sdram_id = (fuse_read_odm(4) >> 3) & 0x1F;
ianos_loader(false, "bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)&mtc_cfg); ianos_loader(false, "bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)&mtc_cfg);
gfx_printf(&gfx_con, "\nStarting training process..\n\n"); gfx_printf("\nStarting training process..\n\n");
// Get current frequency // Get current frequency
for (curr_ram_idx = 0; curr_ram_idx < 10; curr_ram_idx++) for (curr_ram_idx = 0; curr_ram_idx < 10; curr_ram_idx++)
@ -603,21 +603,21 @@ void minerva()
mtc_cfg.rate_from = mtc_cfg.mtc_table[curr_ram_idx].rate_khz; mtc_cfg.rate_from = mtc_cfg.mtc_table[curr_ram_idx].rate_khz;
mtc_cfg.rate_to = 800000; mtc_cfg.rate_to = 800000;
mtc_cfg.train_mode = OP_TRAIN_SWITCH; mtc_cfg.train_mode = OP_TRAIN_SWITCH;
gfx_printf(&gfx_con, "Training and switching %7d -> %7d\n\n", mtc_cfg.mtc_table[curr_ram_idx].rate_khz, 800000); gfx_printf("Training and switching %7d -> %7d\n\n", mtc_cfg.mtc_table[curr_ram_idx].rate_khz, 800000);
ianos_loader(false, "bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)&mtc_cfg); ianos_loader(false, "bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)&mtc_cfg);
// Thefollowing frequency needs periodic training every 100ms. // Thefollowing frequency needs periodic training every 100ms.
//msleep(200); //msleep(200);
//mtc_cfg.rate_to = 1600000; //mtc_cfg.rate_to = 1600000;
//gfx_printf(&gfx_con, "Training and switching %7d -> %7d\n\n", mtc_cfg.current_emc_table->rate_khz, 1600000); //gfx_printf("Training and switching %7d -> %7d\n\n", mtc_cfg.current_emc_table->rate_khz, 1600000);
//ianos_loader(false, "bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)&mtc_cfg); //ianos_loader(false, "bootloader/sys/libsys_minerva.bso", DRAM_LIB, (void *)&mtc_cfg);
//mtc_cfg.train_mode = OP_PERIODIC_TRAIN; //mtc_cfg.train_mode = OP_PERIODIC_TRAIN;
sd_unmount(); sd_unmount();
gfx_printf(&gfx_con, "Finished!"); gfx_printf("Finished!");
btn_wait(); btn_wait();
} }

View file

@ -117,73 +117,73 @@ static const u8 _gfx_font[] = {
0x00, 0x00, 0x00, 0x4C, 0x32, 0x00, 0x00, 0x00 // Char 126 (~) 0x00, 0x00, 0x00, 0x4C, 0x32, 0x00, 0x00, 0x00 // Char 126 (~)
}; };
void gfx_init_ctxt(gfx_ctxt_t *ctxt, u32 *fb, u32 width, u32 height, u32 stride) void gfx_init_ctxt(u32 *fb, u32 width, u32 height, u32 stride)
{ {
ctxt->fb = fb; gfx_ctxt.fb = fb;
ctxt->width = width; gfx_ctxt.width = width;
ctxt->height = height; gfx_ctxt.height = height;
ctxt->stride = stride; gfx_ctxt.stride = stride;
} }
void gfx_clear_grey(gfx_ctxt_t *ctxt, u8 color) void gfx_clear_grey(u8 color)
{ {
memset(ctxt->fb, color, 0x3C0000); memset(gfx_ctxt.fb, color, 0x3C0000);
} }
void gfx_clear_color(gfx_ctxt_t *ctxt, u32 color) void gfx_clear_color(u32 color)
{ {
for (u32 i = 0; i < ctxt->height * ctxt->stride; i++) for (u32 i = 0; i < gfx_ctxt.height * gfx_ctxt.stride; i++)
ctxt->fb[i] = color; gfx_ctxt.fb[i] = color;
} }
void gfx_clear_partial_grey(gfx_ctxt_t *ctxt, u8 color, u32 pos_x, u32 height) void gfx_clear_partial_grey(u8 color, u32 pos_x, u32 height)
{ {
memset(ctxt->fb + pos_x * ctxt->stride, color, height * 4 * ctxt->stride); memset(gfx_ctxt.fb + pos_x * gfx_ctxt.stride, color, height * 4 * gfx_ctxt.stride);
} }
void gfx_con_init(gfx_con_t *con, gfx_ctxt_t *ctxt) void gfx_con_init()
{ {
con->gfx_ctxt = ctxt; gfx_con.gfx_ctxt = &gfx_ctxt;
con->fntsz = 16; gfx_con.fntsz = 16;
con->x = 0; gfx_con.x = 0;
con->y = 0; gfx_con.y = 0;
con->savedx = 0; gfx_con.savedx = 0;
con->savedy = 0; gfx_con.savedy = 0;
con->fgcol = 0xFFCCCCCC; gfx_con.fgcol = 0xFFCCCCCC;
con->fillbg = 0; gfx_con.fillbg = 0;
con->bgcol = 0xFF1B1B1B; gfx_con.bgcol = 0xFF1B1B1B;
con->mute = 0; gfx_con.mute = 0;
} }
void gfx_con_setcol(gfx_con_t *con, u32 fgcol, int fillbg, u32 bgcol) void gfx_con_setcol(u32 fgcol, int fillbg, u32 bgcol)
{ {
con->fgcol = fgcol; gfx_con.fgcol = fgcol;
con->fillbg = fillbg; gfx_con.fillbg = fillbg;
con->bgcol = bgcol; gfx_con.bgcol = bgcol;
} }
void gfx_con_getpos(gfx_con_t *con, u32 *x, u32 *y) void gfx_con_getpos(u32 *x, u32 *y)
{ {
*x = con->x; *x = gfx_con.x;
*y = con->y; *y = gfx_con.y;
} }
void gfx_con_setpos(gfx_con_t *con, u32 x, u32 y) void gfx_con_setpos(u32 x, u32 y)
{ {
con->x = x; gfx_con.x = x;
con->y = y; gfx_con.y = y;
} }
void gfx_putc(gfx_con_t *con, char c) void gfx_putc(char c)
{ {
// Duplicate code for performance reasons. // Duplicate code for performance reasons.
switch (con->fntsz) switch (gfx_con.fntsz)
{ {
case 16: case 16:
if (c >= 32 && c <= 126) if (c >= 32 && c <= 126)
{ {
u8 *cbuf = (u8 *)&_gfx_font[8 * (c - 32)]; u8 *cbuf = (u8 *)&_gfx_font[8 * (c - 32)];
u32 *fb = con->gfx_ctxt->fb + con->x + con->y * con->gfx_ctxt->stride; u32 *fb = gfx_ctxt.fb + gfx_con.x + gfx_con.y * gfx_ctxt.stride;
for (u32 i = 0; i < 16; i+=2) for (u32 i = 0; i < 16; i+=2)
{ {
@ -194,33 +194,33 @@ void gfx_putc(gfx_con_t *con, char c)
{ {
if (v & 1) if (v & 1)
{ {
*fb = con->fgcol; *fb = gfx_con.fgcol;
fb++; fb++;
*fb = con->fgcol; *fb = gfx_con.fgcol;
} }
else if (con->fillbg) else if (gfx_con.fillbg)
{ {
*fb = con->bgcol; *fb = gfx_con.bgcol;
fb++; fb++;
*fb = con->bgcol; *fb = gfx_con.bgcol;
} }
else else
fb++; fb++;
v >>= 1; v >>= 1;
fb++; fb++;
} }
fb += con->gfx_ctxt->stride - 16; fb += gfx_ctxt.stride - 16;
v = *cbuf; v = *cbuf;
} }
} }
con->x += 16; gfx_con.x += 16;
} }
else if (c == '\n') else if (c == '\n')
{ {
con->x = 0; gfx_con.x = 0;
con->y +=16; gfx_con.y +=16;
if (con->y > con->gfx_ctxt->height - 16) if (gfx_con.y > gfx_ctxt.height - 16)
con->y = 0; gfx_con.y = 0;
} }
break; break;
case 8: case 8:
@ -228,45 +228,45 @@ void gfx_putc(gfx_con_t *con, char c)
if (c >= 32 && c <= 126) if (c >= 32 && c <= 126)
{ {
u8 *cbuf = (u8 *)&_gfx_font[8 * (c - 32)]; u8 *cbuf = (u8 *)&_gfx_font[8 * (c - 32)];
u32 *fb = con->gfx_ctxt->fb + con->x + con->y * con->gfx_ctxt->stride; u32 *fb = gfx_ctxt.fb + gfx_con.x + gfx_con.y * gfx_ctxt.stride;
for (u32 i = 0; i < 8; i++) for (u32 i = 0; i < 8; i++)
{ {
u8 v = *cbuf++; u8 v = *cbuf++;
for (u32 j = 0; j < 8; j++) for (u32 j = 0; j < 8; j++)
{ {
if (v & 1) if (v & 1)
*fb = con->fgcol; *fb = gfx_con.fgcol;
else if (con->fillbg) else if (gfx_con.fillbg)
*fb = con->bgcol; *fb = gfx_con.bgcol;
v >>= 1; v >>= 1;
fb++; fb++;
} }
fb += con->gfx_ctxt->stride - 8; fb += gfx_ctxt.stride - 8;
} }
con->x += 8; gfx_con.x += 8;
} }
else if (c == '\n') else if (c == '\n')
{ {
con->x = 0; gfx_con.x = 0;
con->y += 8; gfx_con.y += 8;
if (con->y > con->gfx_ctxt->height - 8) if (gfx_con.y > gfx_ctxt.height - 8)
con->y = 0; gfx_con.y = 0;
} }
break; break;
} }
} }
void gfx_puts(gfx_con_t *con, const char *s) void gfx_puts(const char *s)
{ {
if (!s || con->mute) if (!s || gfx_con.mute)
return; return;
for (; *s; s++) for (; *s; s++)
gfx_putc(con, *s); gfx_putc(*s);
} }
static void _gfx_putn(gfx_con_t *con, u32 v, int base, char fill, int fcnt) static void _gfx_putn(u32 v, int base, char fill, int fcnt)
{ {
char buf[65]; char buf[65];
static const char digits[] = "0123456789ABCDEFghijklmnopqrstuvwxyz"; static const char digits[] = "0123456789ABCDEFghijklmnopqrstuvwxyz";
@ -294,28 +294,28 @@ static void _gfx_putn(gfx_con_t *con, u32 v, int base, char fill, int fcnt)
} }
} }
gfx_puts(con, p); gfx_puts(p);
} }
void gfx_put_small_sep(gfx_con_t *con) void gfx_put_small_sep(gfx_con_t *con)
{ {
u8 prevFontSize = con->fntsz; u8 prevFontSize = gfx_con.fntsz;
con->fntsz = 8; gfx_con.fntsz = 8;
gfx_putc(con, '\n'); gfx_putc('\n');
con->fntsz = prevFontSize; gfx_con.fntsz = prevFontSize;
} }
void gfx_put_big_sep(gfx_con_t *con) void gfx_put_big_sep(gfx_con_t *con)
{ {
u8 prevFontSize = con->fntsz; u8 prevFontSize = gfx_con.fntsz;
con->fntsz = 16; gfx_con.fntsz = 16;
gfx_putc(con, '\n'); gfx_putc('\n');
con->fntsz = prevFontSize; gfx_con.fntsz = prevFontSize;
} }
void gfx_printf(gfx_con_t *con, const char *fmt, ...) void gfx_printf(const char *fmt, ...)
{ {
if (con->mute) if (gfx_con.mute)
return; return;
va_list ap; va_list ap;
@ -348,40 +348,40 @@ void gfx_printf(gfx_con_t *con, const char *fmt, ...)
switch(*fmt) switch(*fmt)
{ {
case 'c': case 'c':
gfx_putc(con, va_arg(ap, u32)); gfx_putc(va_arg(ap, u32));
break; break;
case 's': case 's':
gfx_puts(con, va_arg(ap, char *)); gfx_puts(va_arg(ap, char *));
break; break;
case 'd': case 'd':
_gfx_putn(con, va_arg(ap, u32), 10, fill, fcnt); _gfx_putn(va_arg(ap, u32), 10, fill, fcnt);
break; break;
case 'p': case 'p':
case 'P': case 'P':
case 'x': case 'x':
case 'X': case 'X':
_gfx_putn(con, va_arg(ap, u32), 16, fill, fcnt); _gfx_putn(va_arg(ap, u32), 16, fill, fcnt);
break; break;
case 'k': case 'k':
con->fgcol = va_arg(ap, u32); gfx_con.fgcol = va_arg(ap, u32);
break; break;
case 'K': case 'K':
con->bgcol = va_arg(ap, u32); gfx_con.bgcol = va_arg(ap, u32);
con->fillbg = 1; gfx_con.fillbg = 1;
break; break;
case '%': case '%':
gfx_putc(con, '%'); gfx_putc('%');
break; break;
case '\0': case '\0':
goto out; goto out;
default: default:
gfx_putc(con, '%'); gfx_putc('%');
gfx_putc(con, *fmt); gfx_putc(*fmt);
break; break;
} }
} }
else else
gfx_putc(con, *fmt); gfx_putc(*fmt);
fmt++; fmt++;
} }
@ -389,33 +389,33 @@ void gfx_printf(gfx_con_t *con, const char *fmt, ...)
va_end(ap); va_end(ap);
} }
void gfx_hexdump(gfx_con_t *con, u32 base, const u8 *buf, u32 len) void gfx_hexdump(u32 base, const u8 *buf, u32 len)
{ {
if (con->mute) if (gfx_con.mute)
return; return;
u8 prevFontSize = con->fntsz; u8 prevFontSize = gfx_con.fntsz;
con->fntsz = 8; gfx_con.fntsz = 8;
for(u32 i = 0; i < len; i++) for(u32 i = 0; i < len; i++)
{ {
if(i % 0x10 == 0) if(i % 0x10 == 0)
{ {
if(i != 0) if(i != 0)
{ {
gfx_puts(con, "| "); gfx_puts("| ");
for(u32 j = 0; j < 0x10; j++) for(u32 j = 0; j < 0x10; j++)
{ {
u8 c = buf[i - 0x10 + j]; u8 c = buf[i - 0x10 + j];
if(c >= 32 && c <= 126) if(c >= 32 && c <= 126)
gfx_putc(con, c); gfx_putc(c);
else else
gfx_putc(con, '.'); gfx_putc('.');
} }
gfx_putc(con, '\n'); gfx_putc('\n');
} }
gfx_printf(con, "%08x: ", base + i); gfx_printf("%08x: ", base + i);
} }
gfx_printf(con, "%02x ", buf[i]); gfx_printf("%02x ", buf[i]);
if (i == len - 1) if (i == len - 1)
{ {
int ln = len % 0x10 != 0; int ln = len % 0x10 != 0;
@ -424,22 +424,22 @@ void gfx_hexdump(gfx_con_t *con, u32 base, const u8 *buf, u32 len)
{ {
k = (len & 0xF) - 1; k = (len & 0xF) - 1;
for (u32 j = 0; j < 0x10 - k; j++) for (u32 j = 0; j < 0x10 - k; j++)
gfx_puts(con, " "); gfx_puts(" ");
} }
gfx_puts(con, "| "); gfx_puts("| ");
for(u32 j = 0; j < (ln ? k : k + 1); j++) for(u32 j = 0; j < (ln ? k : k + 1); j++)
{ {
u8 c = buf[i - k + j]; u8 c = buf[i - k + j];
if(c >= 32 && c <= 126) if(c >= 32 && c <= 126)
gfx_putc(con, c); gfx_putc(c);
else else
gfx_putc(con, '.'); gfx_putc('.');
} }
gfx_putc(con, '\n'); gfx_putc('\n');
} }
} }
gfx_putc(con, '\n'); gfx_putc('\n');
con->fntsz = prevFontSize; gfx_con.fntsz = prevFontSize;
} }
static int abs(int x) static int abs(int x)
@ -449,12 +449,12 @@ static int abs(int x)
return x; return x;
} }
void gfx_set_pixel(gfx_ctxt_t *ctxt, u32 x, u32 y, u32 color) void gfx_set_pixel(u32 x, u32 y, u32 color)
{ {
ctxt->fb[x + y * ctxt->stride] = color; gfx_ctxt.fb[x + y * gfx_ctxt.stride] = color;
} }
void gfx_line(gfx_ctxt_t *ctxt, int x0, int y0, int x1, int y1, u32 color) void gfx_line(int x0, int y0, int x1, int y1, u32 color)
{ {
int dx = abs(x1 - x0), sx = x0 < x1 ? 1 : -1; int dx = abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
int dy = abs(y1 - y0), sy = y0 < y1 ? 1 : -1; int dy = abs(y1 - y0), sy = y0 < y1 ? 1 : -1;
@ -462,7 +462,7 @@ void gfx_line(gfx_ctxt_t *ctxt, int x0, int y0, int x1, int y1, u32 color)
while (1) while (1)
{ {
gfx_set_pixel(ctxt, x0, y0, color); gfx_set_pixel(x0, y0, color);
if (x0 == x1 && y0 == y1) if (x0 == x1 && y0 == y1)
break; break;
e2 = err; e2 = err;
@ -479,46 +479,46 @@ void gfx_line(gfx_ctxt_t *ctxt, int x0, int y0, int x1, int y1, u32 color)
} }
} }
void gfx_set_rect_grey(gfx_ctxt_t *ctxt, const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y) void gfx_set_rect_grey(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y)
{ {
u32 pos = 0; u32 pos = 0;
for (u32 y = pos_y; y < (pos_y + size_y); y++) for (u32 y = pos_y; y < (pos_y + size_y); y++)
{ {
for (u32 x = pos_x; x < (pos_x + size_x); x++) for (u32 x = pos_x; x < (pos_x + size_x); x++)
{ {
memset(&ctxt->fb[x + y*ctxt->stride], buf[pos], 4); memset(&gfx_ctxt.fb[x + y*gfx_ctxt.stride], buf[pos], 4);
pos++; pos++;
} }
} }
} }
void gfx_set_rect_rgb(gfx_ctxt_t *ctxt, const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y) void gfx_set_rect_rgb(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y)
{ {
u32 pos = 0; u32 pos = 0;
for (u32 y = pos_y; y < (pos_y + size_y); y++) for (u32 y = pos_y; y < (pos_y + size_y); y++)
{ {
for (u32 x = pos_x; x < (pos_x + size_x); x++) for (u32 x = pos_x; x < (pos_x + size_x); x++)
{ {
ctxt->fb[x + y*ctxt->stride] = buf[pos + 2] | (buf[pos + 1] << 8) | (buf[pos] << 16); gfx_ctxt.fb[x + y * gfx_ctxt.stride] = buf[pos + 2] | (buf[pos + 1] << 8) | (buf[pos] << 16);
pos+=3; pos+=3;
} }
} }
} }
void gfx_set_rect_argb(gfx_ctxt_t *ctxt, const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y) void gfx_set_rect_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y)
{ {
u32 *ptr = (u32 *)buf; u32 *ptr = (u32 *)buf;
for (u32 y = pos_y; y < (pos_y + size_y); y++) for (u32 y = pos_y; y < (pos_y + size_y); y++)
for (u32 x = pos_x; x < (pos_x + size_x); x++) for (u32 x = pos_x; x < (pos_x + size_x); x++)
ctxt->fb[x + y * ctxt->stride] = *ptr++; gfx_ctxt.fb[x + y * gfx_ctxt.stride] = *ptr++;
} }
void gfx_render_bmp_argb(gfx_ctxt_t *ctxt, const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y) void gfx_render_bmp_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y)
{ {
for (u32 y = pos_y; y < (pos_y + size_y); y++) for (u32 y = pos_y; y < (pos_y + size_y); y++)
{ {
for (u32 x = pos_x; x < (pos_x + size_x); x++) for (u32 x = pos_x; x < (pos_x + size_x); x++)
ctxt->fb[x + y * ctxt->stride] = buf[(size_y + pos_y - 1 - y ) * size_x + x - pos_x]; gfx_ctxt.fb[x + y * gfx_ctxt.stride] = buf[(size_y + pos_y - 1 - y ) * size_x + x - pos_x];
} }
} }

View file

@ -21,32 +21,32 @@
#include "../../common/common_gfx.h" #include "../../common/common_gfx.h"
#define EPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC) #define EPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC)
#define EPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC) #define EPRINTFARGS(text, args...) gfx_printf("%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC)
#define WPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFFDD00, 0xFFCCCCCC) #define WPRINTF(text) gfx_printf("%k"text"%k\n", 0xFFFFDD00, 0xFFCCCCCC)
#define WPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFFDD00, args, 0xFFCCCCCC) #define WPRINTFARGS(text, args...) gfx_printf("%k"text"%k\n", 0xFFFFDD00, args, 0xFFCCCCCC)
void gfx_init_ctxt(gfx_ctxt_t *ctxt, u32 *fb, u32 width, u32 height, u32 stride); void gfx_init_ctxt(u32 *fb, u32 width, u32 height, u32 stride);
void gfx_clear_grey(gfx_ctxt_t *ctxt, u8 color); void gfx_clear_grey(u8 color);
void gfx_clear_partial_grey(gfx_ctxt_t *ctxt, u8 color, u32 pos_x, u32 height); void gfx_clear_partial_grey(u8 color, u32 pos_x, u32 height);
void gfx_clear_color(gfx_ctxt_t *ctxt, u32 color); void gfx_clear_color(u32 color);
void gfx_con_init(gfx_con_t *con, gfx_ctxt_t *ctxt); void gfx_con_init();
void gfx_con_setcol(gfx_con_t *con, u32 fgcol, int fillbg, u32 bgcol); void gfx_con_setcol(u32 fgcol, int fillbg, u32 bgcol);
void gfx_con_getpos(gfx_con_t *con, u32 *x, u32 *y); void gfx_con_getpos(u32 *x, u32 *y);
void gfx_con_setpos(gfx_con_t *con, u32 x, u32 y); void gfx_con_setpos(u32 x, u32 y);
void gfx_putc(gfx_con_t *con, char c); void gfx_putc(char c);
void gfx_puts(gfx_con_t *con, const char *s); void gfx_puts(const char *s);
void gfx_printf(gfx_con_t *con, const char *fmt, ...); void gfx_printf(const char *fmt, ...);
void gfx_hexdump(gfx_con_t *con, u32 base, const u8 *buf, u32 len); void gfx_hexdump(u32 base, const u8 *buf, u32 len);
void gfx_set_pixel(gfx_ctxt_t *ctxt, u32 x, u32 y, u32 color); void gfx_set_pixel(u32 x, u32 y, u32 color);
void gfx_line(gfx_ctxt_t *ctxt, int x0, int y0, int x1, int y1, u32 color); void gfx_line(int x0, int y0, int x1, int y1, u32 color);
void gfx_put_small_sep(gfx_con_t *con); void gfx_put_small_sep(gfx_con_t *con);
void gfx_put_big_sep(gfx_con_t *con); void gfx_put_big_sep(gfx_con_t *con);
void gfx_set_rect_grey(gfx_ctxt_t *ctxt, const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); void gfx_set_rect_grey(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y);
void gfx_set_rect_rgb(gfx_ctxt_t *ctxt, const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); void gfx_set_rect_rgb(const u8 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y);
void gfx_set_rect_argb(gfx_ctxt_t *ctxt, const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); void gfx_set_rect_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y);
void gfx_render_bmp_argb(gfx_ctxt_t *ctxt, const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); void gfx_render_bmp_argb(const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y);
// Global gfx console and context. // Global gfx console and context.
gfx_ctxt_t gfx_ctxt; gfx_ctxt_t gfx_ctxt;

View file

@ -32,7 +32,7 @@ extern u8 *Kc_MENU_LOGO;
extern hekate_config h_cfg; extern hekate_config h_cfg;
void tui_sbar(gfx_con_t *con, bool force_update) void tui_sbar(bool force_update)
{ {
u32 cx, cy; u32 cx, cy;
@ -41,78 +41,78 @@ void tui_sbar(gfx_con_t *con, bool force_update)
if (timePassed < 5) if (timePassed < 5)
return; return;
u8 prevFontSize = con->fntsz; u8 prevFontSize = gfx_con.fntsz;
con->fntsz = 16; gfx_con.fntsz = 16;
h_cfg.sbar_time_keeping = get_tmr_s(); h_cfg.sbar_time_keeping = get_tmr_s();
u32 battPercent = 0; u32 battPercent = 0;
int battVoltCurr = 0; int battVoltCurr = 0;
gfx_con_getpos(con, &cx, &cy); gfx_con_getpos(&cx, &cy);
gfx_con_setpos(con, 0, 1260); gfx_con_setpos(0, 1260);
max17050_get_property(MAX17050_RepSOC, (int *)&battPercent); max17050_get_property(MAX17050_RepSOC, (int *)&battPercent);
max17050_get_property(MAX17050_VCELL, &battVoltCurr); max17050_get_property(MAX17050_VCELL, &battVoltCurr);
gfx_clear_partial_grey(con->gfx_ctxt, 0x30, 1256, 24); gfx_clear_partial_grey(0x30, 1256, 24);
gfx_printf(con, "%K%k Battery: %d.%d%% (%d mV) - Charge:", 0xFF303030, 0xFF888888, gfx_printf("%K%k Battery: %d.%d%% (%d mV) - Charge:", 0xFF303030, 0xFF888888,
(battPercent >> 8) & 0xFF, (battPercent & 0xFF) / 26, battVoltCurr); (battPercent >> 8) & 0xFF, (battPercent & 0xFF) / 26, battVoltCurr);
max17050_get_property(MAX17050_AvgCurrent, &battVoltCurr); max17050_get_property(MAX17050_Current, &battVoltCurr);
if (battVoltCurr >= 0) if (battVoltCurr >= 0)
gfx_printf(con, " %k+%d mA%k%K\n", gfx_printf(" %k+%d mA%k%K\n",
0xFF008800, battVoltCurr / 1000, 0xFFCCCCCC, 0xFF1B1B1B); 0xFF008800, battVoltCurr / 1000, 0xFFCCCCCC, 0xFF1B1B1B);
else else
gfx_printf(con, " %k-%d mA%k%K\n", gfx_printf(" %k-%d mA%k%K\n",
0xFF880000, (~battVoltCurr) / 1000, 0xFFCCCCCC, 0xFF1B1B1B); 0xFF880000, (~battVoltCurr) / 1000, 0xFFCCCCCC, 0xFF1B1B1B);
con->fntsz = prevFontSize; gfx_con.fntsz = prevFontSize;
gfx_con_setpos(con, cx, cy); gfx_con_setpos(cx, cy);
} }
void tui_pbar(gfx_con_t *con, int x, int y, u32 val, u32 fgcol, u32 bgcol) void tui_pbar(int x, int y, u32 val, u32 fgcol, u32 bgcol)
{ {
u32 cx, cy; u32 cx, cy;
if (val > 200) if (val > 200)
val = 200; val = 200;
gfx_con_getpos(con, &cx, &cy); gfx_con_getpos(&cx, &cy);
gfx_con_setpos(con, x, y); gfx_con_setpos(x, y);
gfx_printf(con, "%k[%3d%%]%k", fgcol, val, 0xFFCCCCCC); gfx_printf("%k[%3d%%]%k", fgcol, val, 0xFFCCCCCC);
x += 7 * con->fntsz; x += 7 * gfx_con.fntsz;
for (int i = 0; i < (con->fntsz >> 3) * 6; i++) for (int i = 0; i < (gfx_con.fntsz >> 3) * 6; i++)
{ {
gfx_line(con->gfx_ctxt, x, y + i + 1, x + 3 * val, y + i + 1, fgcol); gfx_line(x, y + i + 1, x + 3 * val, y + i + 1, fgcol);
gfx_line(con->gfx_ctxt, x + 3 * val, y + i + 1, x + 3 * 100, y + i + 1, bgcol); gfx_line(x + 3 * val, y + i + 1, x + 3 * 100, y + i + 1, bgcol);
} }
gfx_con_setpos(con, cx, cy); gfx_con_setpos(cx, cy);
// Update status bar. // Update status bar.
tui_sbar(con, false); tui_sbar(false);
} }
void *tui_do_menu(gfx_con_t *con, menu_t *menu) void *tui_do_menu(menu_t *menu)
{ {
int idx = 0, prev_idx = 0, cnt = 0x7FFFFFFF; int idx = 0, prev_idx = 0, cnt = 0x7FFFFFFF;
gfx_clear_partial_grey(con->gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
tui_sbar(con, true); tui_sbar(true);
#ifdef MENU_LOGO_ENABLE #ifdef MENU_LOGO_ENABLE
gfx_set_rect_rgb(con->gfx_ctxt, Kc_MENU_LOGO, gfx_set_rect_rgb(Kc_MENU_LOGO,
X_MENU_LOGO, Y_MENU_LOGO, X_POS_MENU_LOGO, Y_POS_MENU_LOGO); X_MENU_LOGO, Y_MENU_LOGO, X_POS_MENU_LOGO, Y_POS_MENU_LOGO);
#endif //MENU_LOGO_ENABLE #endif //MENU_LOGO_ENABLE
while (true) while (true)
{ {
gfx_con_setcol(con, 0xFFCCCCCC, 1, 0xFF1B1B1B); gfx_con_setcol(0xFFCCCCCC, 1, 0xFF1B1B1B);
gfx_con_setpos(con, menu->x, menu->y); gfx_con_setpos(menu->x, menu->y);
gfx_printf(con, "[%s]\n\n", menu->caption); gfx_printf("[%s]\n\n", menu->caption);
// Skip caption or seperator lines selection. // Skip caption or seperator lines selection.
while (menu->ents[idx].type == MENT_CAPTION || while (menu->ents[idx].type == MENT_CAPTION ||
@ -143,30 +143,30 @@ void *tui_do_menu(gfx_con_t *con, menu_t *menu)
for (cnt = 0; menu->ents[cnt].type != MENT_END; cnt++) for (cnt = 0; menu->ents[cnt].type != MENT_END; cnt++)
{ {
if (cnt == idx) if (cnt == idx)
gfx_con_setcol(con, 0xFF1B1B1B, 1, 0xFFCCCCCC); gfx_con_setcol(0xFF1B1B1B, 1, 0xFFCCCCCC);
else else
gfx_con_setcol(con, 0xFFCCCCCC, 1, 0xFF1B1B1B); gfx_con_setcol(0xFFCCCCCC, 1, 0xFF1B1B1B);
if (menu->ents[cnt].type == MENT_CAPTION) if (menu->ents[cnt].type == MENT_CAPTION)
gfx_printf(con, "%k %s", menu->ents[cnt].color, menu->ents[cnt].caption); gfx_printf("%k %s", menu->ents[cnt].color, menu->ents[cnt].caption);
else if (menu->ents[cnt].type != MENT_CHGLINE) else if (menu->ents[cnt].type != MENT_CHGLINE)
gfx_printf(con, " %s", menu->ents[cnt].caption); gfx_printf(" %s", menu->ents[cnt].caption);
if(menu->ents[cnt].type == MENT_MENU) if(menu->ents[cnt].type == MENT_MENU)
gfx_printf(con, "%k...", 0xFF0099EE); gfx_printf("%k...", 0xFF0099EE);
gfx_printf(con, " \n"); gfx_printf(" \n");
} }
gfx_con_setcol(con, 0xFFCCCCCC, 1, 0xFF1B1B1B); gfx_con_setcol(0xFFCCCCCC, 1, 0xFF1B1B1B);
gfx_putc(con, '\n'); gfx_putc('\n');
// Print help and battery status. // Print help and battery status.
gfx_con_setpos(con, 0, 1127); gfx_con_setpos(0, 1127);
if (h_cfg.errors) if (h_cfg.errors)
{ {
gfx_printf(con, "%k Warning: %k", 0xFF800000, 0xFF555555); gfx_printf("%k Warning: %k", 0xFF800000, 0xFF555555);
if (h_cfg.errors & ERR_LIBSYS_LP0) if (h_cfg.errors & ERR_LIBSYS_LP0)
gfx_printf(con, "Sleep mode library is missing!\n"); gfx_printf("Sleep mode library is missing!\n");
} }
gfx_con_setpos(con, 0, 1191); gfx_con_setpos(0, 1191);
gfx_printf(con, "%k VOL: Move up/down\n PWR: Select option%k", 0xFF555555, 0xFFCCCCCC); gfx_printf("%k VOL: Move up/down\n PWR: Select option%k", 0xFF555555, 0xFFCCCCCC);
display_backlight_brightness(h_cfg.backlight, 1000); display_backlight_brightness(h_cfg.backlight, 1000);
@ -196,7 +196,7 @@ void *tui_do_menu(gfx_con_t *con, menu_t *menu)
ent->handler(ent->data); ent->handler(ent->data);
break; break;
case MENT_MENU: case MENT_MENU:
return tui_do_menu(con, ent->menu); return tui_do_menu(ent->menu);
break; break;
case MENT_DATA: case MENT_DATA:
return ent->data; return ent->data;
@ -212,14 +212,14 @@ void *tui_do_menu(gfx_con_t *con, menu_t *menu)
default: default:
break; break;
} }
con->fntsz = 16; gfx_con.fntsz = 16;
gfx_clear_partial_grey(con->gfx_ctxt, 0x1B, 0, 1256); gfx_clear_partial_grey(0x1B, 0, 1256);
#ifdef MENU_LOGO_ENABLE #ifdef MENU_LOGO_ENABLE
gfx_set_rect_rgb(con->gfx_ctxt, Kc_MENU_LOGO, gfx_set_rect_rgb(Kc_MENU_LOGO,
X_MENU_LOGO, Y_MENU_LOGO, X_POS_MENU_LOGO, Y_POS_MENU_LOGO); X_MENU_LOGO, Y_MENU_LOGO, X_POS_MENU_LOGO, Y_POS_MENU_LOGO);
#endif //MENU_LOGO_ENABLE #endif //MENU_LOGO_ENABLE
} }
tui_sbar(con, false); tui_sbar(false);
} }
return NULL; return NULL;

View file

@ -59,8 +59,8 @@ typedef struct _menu_t
#define MDEF_CAPTION(caption, color) { MENT_CAPTION, caption, color } #define MDEF_CAPTION(caption, color) { MENT_CAPTION, caption, color }
#define MDEF_CHGLINE() {MENT_CHGLINE} #define MDEF_CHGLINE() {MENT_CHGLINE}
void tui_sbar(gfx_con_t *con, bool force_update); void tui_sbar(bool force_update);
void tui_pbar(gfx_con_t *con, int x, int y, u32 val, u32 fgcol, u32 bgcol); void tui_pbar(int x, int y, u32 val, u32 fgcol, u32 bgcol);
void *tui_do_menu(gfx_con_t *con, menu_t *menu); void *tui_do_menu(menu_t *menu);
#endif #endif

View file

@ -87,7 +87,7 @@ int parse_fss(launch_ctxt_t *ctxt, const char *value)
if (fss_meta->magic == FSS0_MAGIC) if (fss_meta->magic == FSS0_MAGIC)
{ {
gfx_printf(&gfx_con, "Found FSS0, Atmosphere %d.%d.%d-%08x\n" gfx_printf("Found FSS0, Atmosphere %d.%d.%d-%08x\n"
"Max HOS supported: %d.%d.%d\n" "Max HOS supported: %d.%d.%d\n"
"Unpacking and loading components.. ", "Unpacking and loading components.. ",
fss_meta->version >> 24, (fss_meta->version >> 16) & 0xFF, (fss_meta->version >> 8) & 0xFF, fss_meta->git_rev, fss_meta->version >> 24, (fss_meta->version >> 16) & 0xFF, (fss_meta->version >> 8) & 0xFF, fss_meta->git_rev,
@ -131,7 +131,7 @@ int parse_fss(launch_ctxt_t *ctxt, const char *value)
f_read(&fp, content, curr_fss_cnt[i].size, NULL); f_read(&fp, content, curr_fss_cnt[i].size, NULL);
} }
gfx_printf(&gfx_con, "Done!\n"); gfx_printf("Done!\n");
f_close(&fp); f_close(&fp);
return 1; return 1;

View file

@ -45,7 +45,7 @@ extern hekate_config h_cfg;
extern void sd_unmount(); extern void sd_unmount();
//#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__) //#define DPRINTF(...) gfx_printf(__VA_ARGS__)
#define DPRINTF(...) #define DPRINTF(...)
#define PKG2_LOAD_ADDR 0xA9800000 #define PKG2_LOAD_ADDR 0xA9800000
@ -112,17 +112,17 @@ static void _se_lock(bool lock_se)
SB(SB_CSR) = 0x10; // Protected IROM enable. SB(SB_CSR) = 0x10; // Protected IROM enable.
// This is useful for documenting the bits in the SE config registers, so we can keep it around. // This is useful for documenting the bits in the SE config registers, so we can keep it around.
/*gfx_printf(&gfx_con, "SE(SE_SECURITY_0) = %08X\n", SE(SE_SECURITY_0)); /*gfx_printf("SE(SE_SECURITY_0) = %08X\n", SE(SE_SECURITY_0));
gfx_printf(&gfx_con, "SE(0x4) = %08X\n", SE(0x4)); gfx_printf("SE(0x4) = %08X\n", SE(0x4));
gfx_printf(&gfx_con, "SE(SE_KEY_TABLE_ACCESS_LOCK_OFFSET) = %08X\n", SE(SE_KEY_TABLE_ACCESS_LOCK_OFFSET)); gfx_printf("SE(SE_KEY_TABLE_ACCESS_LOCK_OFFSET) = %08X\n", SE(SE_KEY_TABLE_ACCESS_LOCK_OFFSET));
gfx_printf(&gfx_con, "SE(SE_RSA_KEYTABLE_ACCESS_LOCK_OFFSET) = %08X\n", SE(SE_RSA_KEYTABLE_ACCESS_LOCK_OFFSET)); gfx_printf("SE(SE_RSA_KEYTABLE_ACCESS_LOCK_OFFSET) = %08X\n", SE(SE_RSA_KEYTABLE_ACCESS_LOCK_OFFSET));
for(u32 i = 0; i < 16; i++) for(u32 i = 0; i < 16; i++)
gfx_printf(&gfx_con, "%02X ", SE(SE_KEY_TABLE_ACCESS_REG_OFFSET + i * 4) & 0xFF); gfx_printf("%02X ", SE(SE_KEY_TABLE_ACCESS_REG_OFFSET + i * 4) & 0xFF);
gfx_putc(&gfx_con, '\n'); gfx_putc('\n');
for(u32 i = 0; i < 2; i++) for(u32 i = 0; i < 2; i++)
gfx_printf(&gfx_con, "%02X ", SE(SE_RSA_KEYTABLE_ACCESS_REG_OFFSET + i * 4) & 0xFF); gfx_printf("%02X ", SE(SE_RSA_KEYTABLE_ACCESS_REG_OFFSET + i * 4) & 0xFF);
gfx_putc(&gfx_con, '\n'); gfx_putc('\n');
gfx_hexdump(&gfx_con, SE_BASE, (void *)SE_BASE, 0x400);*/ gfx_hexdump(SE_BASE, (void *)SE_BASE, 0x400);*/
} }
void _pmc_scratch_lock(u32 kb) void _pmc_scratch_lock(u32 kb)
@ -308,7 +308,7 @@ static int _read_emmc_pkg1(launch_ctxt_t *ctxt)
EPRINTF("Unknown pkg1 version."); EPRINTF("Unknown pkg1 version.");
goto out; goto out;
} }
gfx_printf(&gfx_con, "Identified pkg1 and Keyblob %d\n\n", ctxt->pkg1_id->kb); gfx_printf("Identified pkg1 and Keyblob %d\n\n", ctxt->pkg1_id->kb);
// Read the correct keyblob. // Read the correct keyblob.
ctxt->keyblob = (u8 *)calloc(NX_EMMC_BLOCKSIZE, 1); ctxt->keyblob = (u8 *)calloc(NX_EMMC_BLOCKSIZE, 1);
@ -392,10 +392,10 @@ int hos_launch(ini_sec_t *cfg)
ctxt.cfg = cfg; ctxt.cfg = cfg;
if (!gfx_con.mute) if (!gfx_con.mute)
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
gfx_printf(&gfx_con, "Initializing...\n\n"); gfx_printf("Initializing...\n\n");
// Read package1 and the correct keyblob. // Read package1 and the correct keyblob.
if (!_read_emmc_pkg1(&ctxt)) if (!_read_emmc_pkg1(&ctxt))
@ -412,7 +412,7 @@ int hos_launch(ini_sec_t *cfg)
if (h_cfg.autonogc && !(fuse_read_odm(7) & ~0xF) && ctxt.pkg1_id->kb >= KB_FIRMWARE_VERSION_400) if (h_cfg.autonogc && !(fuse_read_odm(7) & ~0xF) && ctxt.pkg1_id->kb >= KB_FIRMWARE_VERSION_400)
config_kip1patch(&ctxt, "nogc"); config_kip1patch(&ctxt, "nogc");
gfx_printf(&gfx_con, "Loaded pkg1 & keyblob\n"); gfx_printf("Loaded pkg1 & keyblob\n");
// Generate keys. // Generate keys.
if (!h_cfg.se_keygen_done || ctxt.pkg1_id->kb == KB_FIRMWARE_VERSION_620) if (!h_cfg.se_keygen_done || ctxt.pkg1_id->kb == KB_FIRMWARE_VERSION_620)
@ -424,7 +424,7 @@ int hos_launch(ini_sec_t *cfg)
if (ctxt.pkg1_id->kb >= KB_FIRMWARE_VERSION_700 && !h_cfg.sept_run) if (ctxt.pkg1_id->kb >= KB_FIRMWARE_VERSION_700 && !h_cfg.sept_run)
{ {
gfx_printf(&gfx_con, "Failed to run sept\n"); gfx_printf("Failed to run sept\n");
return 0; return 0;
} }
@ -444,7 +444,7 @@ int hos_launch(ini_sec_t *cfg)
if (ctxt.pkg1_id->kb <= KB_FIRMWARE_VERSION_620) if (ctxt.pkg1_id->kb <= KB_FIRMWARE_VERSION_620)
{ {
pkg1_unpack((void *)ctxt.pkg1_id->warmboot_base, (void *)ctxt.pkg1_id->secmon_base, NULL, ctxt.pkg1_id, ctxt.pkg1); pkg1_unpack((void *)ctxt.pkg1_id->warmboot_base, (void *)ctxt.pkg1_id->secmon_base, NULL, ctxt.pkg1_id, ctxt.pkg1);
gfx_printf(&gfx_con, "Decrypted & unpacked pkg1\n"); gfx_printf("Decrypted & unpacked pkg1\n");
} }
else else
{ {
@ -465,7 +465,7 @@ int hos_launch(ini_sec_t *cfg)
} }
// Else we patch it to allow downgrading. // Else we patch it to allow downgrading.
patch_t *warmboot_patchset = ctxt.pkg1_id->warmboot_patchset; patch_t *warmboot_patchset = ctxt.pkg1_id->warmboot_patchset;
gfx_printf(&gfx_con, "%kPatching Warmboot%k\n", 0xFFFFBA00, 0xFFCCCCCC); gfx_printf("%kPatching Warmboot%k\n", 0xFFFFBA00, 0xFFCCCCCC);
for (u32 i = 0; warmboot_patchset[i].off != 0xFFFFFFFF; i++) for (u32 i = 0; warmboot_patchset[i].off != 0xFFFFFFFF; i++)
*(vu32 *)(ctxt.pkg1_id->warmboot_base + warmboot_patchset[i].off) = warmboot_patchset[i].val; *(vu32 *)(ctxt.pkg1_id->warmboot_base + warmboot_patchset[i].off) = warmboot_patchset[i].val;
} }
@ -480,32 +480,32 @@ int hos_launch(ini_sec_t *cfg)
{ {
// Else we patch it to allow for an unsigned package2 and patched kernel. // Else we patch it to allow for an unsigned package2 and patched kernel.
patch_t *secmon_patchset = ctxt.pkg1_id->secmon_patchset; patch_t *secmon_patchset = ctxt.pkg1_id->secmon_patchset;
gfx_printf(&gfx_con, "%kPatching Security Monitor%k\n", 0xFFFFBA00, 0xFFCCCCCC); gfx_printf("%kPatching Security Monitor%k\n", 0xFFFFBA00, 0xFFCCCCCC);
for (u32 i = 0; secmon_patchset[i].off != 0xFFFFFFFF; i++) for (u32 i = 0; secmon_patchset[i].off != 0xFFFFFFFF; i++)
*(vu32 *)(ctxt.pkg1_id->secmon_base + secmon_patchset[i].off) = secmon_patchset[i].val; *(vu32 *)(ctxt.pkg1_id->secmon_base + secmon_patchset[i].off) = secmon_patchset[i].val;
} }
gfx_printf(&gfx_con, "Loaded warmboot and secmon\n"); gfx_printf("Loaded warmboot and secmon\n");
// Read package2. // Read package2.
u8 *bootConfigBuf = _read_emmc_pkg2(&ctxt); u8 *bootConfigBuf = _read_emmc_pkg2(&ctxt);
if (!bootConfigBuf) if (!bootConfigBuf)
return 0; return 0;
gfx_printf(&gfx_con, "Read pkg2\n"); gfx_printf("Read pkg2\n");
// Decrypt package2 and parse KIP1 blobs in INI1 section. // Decrypt package2 and parse KIP1 blobs in INI1 section.
pkg2_hdr_t *pkg2_hdr = pkg2_decrypt(ctxt.pkg2); pkg2_hdr_t *pkg2_hdr = pkg2_decrypt(ctxt.pkg2);
if (!pkg2_hdr) if (!pkg2_hdr)
{ {
gfx_printf(&gfx_con, "Pkg2 decryption failed!\n"); gfx_printf("Pkg2 decryption failed!\n");
return 0; return 0;
} }
LIST_INIT(kip1_info); LIST_INIT(kip1_info);
pkg2_parse_kips(&kip1_info, pkg2_hdr); pkg2_parse_kips(&kip1_info, pkg2_hdr);
gfx_printf(&gfx_con, "Parsed ini1\n"); gfx_printf("Parsed ini1\n");
// Use the kernel included in package2 in case we didn't load one already. // Use the kernel included in package2 in case we didn't load one already.
if (!ctxt.kernel) if (!ctxt.kernel)
@ -522,7 +522,7 @@ int hos_launch(ini_sec_t *cfg)
kernel_patch_t *kernel_patchset = ctxt.pkg2_kernel_id->kernel_patchset; kernel_patch_t *kernel_patchset = ctxt.pkg2_kernel_id->kernel_patchset;
if (kernel_patchset != NULL) if (kernel_patchset != NULL)
{ {
gfx_printf(&gfx_con, "%kPatching kernel%k\n", 0xFFFFBA00, 0xFFCCCCCC); gfx_printf("%kPatching kernel%k\n", 0xFFFFBA00, 0xFFCCCCCC);
u32 *temp; u32 *temp;
for (u32 i = 0; kernel_patchset[i].id != 0xFFFFFFFF; i++) for (u32 i = 0; kernel_patchset[i].id != 0xFFFFFFFF; i++)
{ {
@ -544,7 +544,7 @@ int hos_launch(ini_sec_t *cfg)
} }
// Merge extra KIP1s into loaded ones. // Merge extra KIP1s into loaded ones.
gfx_printf(&gfx_con, "%kPatching kips%k\n", 0xFFFFBA00, 0xFFCCCCCC); gfx_printf("%kPatching kips%k\n", 0xFFFFBA00, 0xFFCCCCCC);
LIST_FOREACH_ENTRY(merge_kip_t, mki, &ctxt.kip1_list, link) LIST_FOREACH_ENTRY(merge_kip_t, mki, &ctxt.kip1_list, link)
pkg2_merge_kip(&kip1_info, (pkg2_kip1_t *)mki->kip1); pkg2_merge_kip(&kip1_info, (pkg2_kip1_t *)mki->kip1);
@ -562,9 +562,9 @@ int hos_launch(ini_sec_t *cfg)
// Rebuild and encrypt package2. // Rebuild and encrypt package2.
pkg2_build_encrypt((void *)PKG2_LOAD_ADDR, ctxt.kernel, ctxt.kernel_size, &kip1_info); pkg2_build_encrypt((void *)PKG2_LOAD_ADDR, ctxt.kernel, ctxt.kernel_size, &kip1_info);
gfx_printf(&gfx_con, "Rebuilt & loaded pkg2\n"); gfx_printf("Rebuilt & loaded pkg2\n");
gfx_printf(&gfx_con, "\n%kBooting...%k\n", 0xFF96FF00, 0xFFCCCCCC); gfx_printf("\n%kBooting...%k\n", 0xFF96FF00, 0xFFCCCCCC);
// Clear pkg1/pkg2 keys. // Clear pkg1/pkg2 keys.
se_aes_key_clear(8); se_aes_key_clear(8);

View file

@ -26,7 +26,7 @@
#include "../gfx/gfx.h" #include "../gfx/gfx.h"
//#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__) //#define DPRINTF(...) gfx_printf(__VA_ARGS__)
#define DPRINTF(...) #define DPRINTF(...)
extern void *sd_file_read(const char *path, u32 *fsize); extern void *sd_file_read(const char *path, u32 *fsize);

View file

@ -151,7 +151,7 @@ const pkg1_id_t *pkg1_identify(u8 *pkg1)
char build_date[15]; char build_date[15];
memcpy(build_date, (char *)(pkg1 + 0x10), 14); memcpy(build_date, (char *)(pkg1 + 0x10), 14);
build_date[14] = 0; build_date[14] = 0;
gfx_printf(&gfx_con, "Found pkg1 ('%s').\n\n", build_date); gfx_printf("Found pkg1 ('%s').\n\n", build_date);
for (u32 i = 0; _pkg1_ids[i].id; i++) for (u32 i = 0; _pkg1_ids[i].id; i++)
if (!memcmp(pkg1 + 0x10, _pkg1_ids[i].id, 12)) if (!memcmp(pkg1 + 0x10, _pkg1_ids[i].id, 12))

View file

@ -27,7 +27,7 @@
#include "../gfx/gfx.h" #include "../gfx/gfx.h"
/*#include "util.h" /*#include "util.h"
#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__) #define DPRINTF(...) gfx_printf(__VA_ARGS__)
#define DEBUG_PRINTING*/ #define DEBUG_PRINTING*/
#define DPRINTF(...) #define DPRINTF(...)
@ -680,10 +680,10 @@ int pkg2_decompress_kip(pkg2_kip1_info_t* ki, u32 sectsToDecomp)
unsigned int compSize = hdr.sections[sectIdx].size_comp; unsigned int compSize = hdr.sections[sectIdx].size_comp;
unsigned int outputSize = hdr.sections[sectIdx].size_decomp; unsigned int outputSize = hdr.sections[sectIdx].size_decomp;
gfx_printf(&gfx_con, "Decomping %s KIP1 sect %d of size %d...\n", (const char*)hdr.name, sectIdx, compSize); gfx_printf("Decomping %s KIP1 sect %d of size %d...\n", (const char*)hdr.name, sectIdx, compSize);
if (blz_uncompress_srcdest(srcDataPtr, compSize, dstDataPtr, outputSize) == 0) if (blz_uncompress_srcdest(srcDataPtr, compSize, dstDataPtr, outputSize) == 0)
{ {
gfx_printf(&gfx_con, "%kERROR decomping sect %d of %s KIP!%k\n", 0xFFFF0000, sectIdx, (char*)hdr.name, 0xFFCCCCCC); gfx_printf("%kERROR decomping sect %d of %s KIP!%k\n", 0xFFFF0000, sectIdx, (char*)hdr.name, 0xFFCCCCCC);
free(newKip); free(newKip);
return 1; return 1;
@ -844,7 +844,7 @@ const char* pkg2_patch_kips(link_t *info, char* patchNames)
u32 appliedMask = 1u << currEnabIdx; u32 appliedMask = 1u << currEnabIdx;
if (currPatchset->patches == NULL) if (currPatchset->patches == NULL)
{ {
gfx_printf(&gfx_con, "Patch '%s' not necessary for %s KIP1\n", currPatchset->name, (const char*)ki->kip1->name); gfx_printf("Patch '%s' not necessary for %s KIP1\n", currPatchset->name, (const char*)ki->kip1->name);
patchesApplied |= appliedMask; patchesApplied |= appliedMask;
break; break;
} }
@ -854,7 +854,7 @@ const char* pkg2_patch_kips(link_t *info, char* patchNames)
{ {
if (bitsAffected & (1u << currSectIdx)) if (bitsAffected & (1u << currSectIdx))
{ {
gfx_printf(&gfx_con, "Applying patch '%s' on %s KIP1 sect %d\n", currPatchset->name, (const char*)ki->kip1->name, currSectIdx); gfx_printf("Applying patch '%s' on %s KIP1 sect %d\n", currPatchset->name, (const char*)ki->kip1->name, currSectIdx);
for (const kip1_patch_t* currPatch=currPatchset->patches;currPatch != NULL && currPatch->length != 0; currPatch++) for (const kip1_patch_t* currPatch=currPatchset->patches;currPatch != NULL && currPatch->length != 0; currPatch++)
{ {
if (GET_KIP_PATCH_SECTION(currPatch->offset) != currSectIdx) if (GET_KIP_PATCH_SECTION(currPatch->offset) != currSectIdx)
@ -863,7 +863,7 @@ const char* pkg2_patch_kips(link_t *info, char* patchNames)
u32 currOffset = GET_KIP_PATCH_OFFSET(currPatch->offset); u32 currOffset = GET_KIP_PATCH_OFFSET(currPatch->offset);
if (memcmp(&kipSectData[currOffset], currPatch->srcData, currPatch->length) != 0) if (memcmp(&kipSectData[currOffset], currPatch->srcData, currPatch->length) != 0)
{ {
gfx_printf(&gfx_con, "%kDATA MISMATCH FOR PATCH AT OFFSET 0x%x!!!%k\n", 0xFFFF0000, currOffset, 0xFFCCCCCC); gfx_printf("%kDATA MISMATCH FOR PATCH AT OFFSET 0x%x!!!%k\n", 0xFFFF0000, currOffset, 0xFFCCCCCC);
return currPatchset->name; // MUST stop here as kip is likely corrupt. return currPatchset->name; // MUST stop here as kip is likely corrupt.
} }
else else
@ -907,7 +907,7 @@ pkg2_hdr_t *pkg2_decrypt(void *data)
// Decrypt header. // Decrypt header.
se_aes_crypt_ctr(8, hdr, sizeof(pkg2_hdr_t), hdr, sizeof(pkg2_hdr_t), hdr); se_aes_crypt_ctr(8, hdr, sizeof(pkg2_hdr_t), hdr, sizeof(pkg2_hdr_t), hdr);
//gfx_hexdump(&gfx_con, (u32)hdr, hdr, 0x100); //gfx_hexdump((u32)hdr, hdr, 0x100);
if (hdr->magic != PKG2_MAGIC) if (hdr->magic != PKG2_MAGIC)
return NULL; return NULL;
@ -919,7 +919,7 @@ DPRINTF("sec %d has size %08X\n", i, hdr->sec_size[i]);
continue; continue;
se_aes_crypt_ctr(8, pdata, hdr->sec_size[i], pdata, hdr->sec_size[i], &hdr->sec_ctr[i * 0x10]); se_aes_crypt_ctr(8, pdata, hdr->sec_size[i], pdata, hdr->sec_size[i], &hdr->sec_ctr[i * 0x10]);
//gfx_hexdump(&gfx_con, (u32)pdata, pdata, 0x100); //gfx_hexdump((u32)pdata, pdata, 0x100);
pdata += hdr->sec_size[i]; pdata += hdr->sec_size[i];
} }

View file

@ -70,19 +70,19 @@ void ianos_print_error(int errorno)
switch (errorno) switch (errorno)
{ {
case 1: case 1:
gfx_printf(&gfx_con, "Can't find library!\n"); gfx_printf("Can't find library!\n");
break; break;
case 2: case 2:
gfx_printf(&gfx_con, "Cant init ELF context!\n"); gfx_printf("Cant init ELF context!\n");
break; break;
case 3: case 3:
gfx_printf(&gfx_con, "Cant alloc memory!\n"); gfx_printf("Cant alloc memory!\n");
break; break;
case 4: case 4:
gfx_printf(&gfx_con, "Error loading ELF!\n"); gfx_printf("Error loading ELF!\n");
break; break;
case 5: case 5:
gfx_printf(&gfx_con, "Error relocating ELF!\n"); gfx_printf("Error relocating ELF!\n");
break; break;
} }
} }

View file

@ -25,7 +25,7 @@
#include "diskio.h" /* Declarations of device I/O functions */ #include "diskio.h" /* Declarations of device I/O functions */
#include "../../gfx/gfx.h" #include "../../gfx/gfx.h"
#define EFSPRINTF(text, ...) print_error(); gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFFFF00, 0xFFFFFFFF); #define EFSPRINTF(text, ...) print_error(); gfx_printf("%k"text"%k\n", 0xFFFFFF00, 0xFFFFFFFF);
//#define EFSPRINTF(...) //#define EFSPRINTF(...)
/*-------------------------------------------------------------------------- /*--------------------------------------------------------------------------
@ -583,7 +583,7 @@ static const BYTE DbcTbl[] = MKCVTBL(TBL_DC, FF_CODE_PAGE);
void print_error() void print_error()
{ {
gfx_printf(&gfx_con, "\n\n\n%k[FatFS] Error: %k", 0xFFFFFF00, 0xFFFFFFFF); gfx_printf("\n\n\n%k[FatFS] Error: %k", 0xFFFFFF00, 0xFFFFFFFF);
} }

View file

@ -198,10 +198,10 @@ void check_power_off_from_hos()
if (h_cfg.autohosoff == 1) if (h_cfg.autohosoff == 1)
{ {
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
u8 *BOOTLOGO = (void *)malloc(0x4000); u8 *BOOTLOGO = (void *)malloc(0x4000);
blz_uncompress_srcdest(BOOTLOGO_BLZ, SZ_BOOTLOGO_BLZ, BOOTLOGO, SZ_BOOTLOGO); blz_uncompress_srcdest(BOOTLOGO_BLZ, SZ_BOOTLOGO_BLZ, BOOTLOGO, SZ_BOOTLOGO);
gfx_set_rect_grey(&gfx_ctxt, BOOTLOGO, X_BOOTLOGO, Y_BOOTLOGO, 326, 544); gfx_set_rect_grey(BOOTLOGO, X_BOOTLOGO, Y_BOOTLOGO, 326, 544);
display_backlight_brightness(10, 5000); display_backlight_brightness(10, 5000);
display_backlight_brightness(100, 25000); display_backlight_brightness(100, 25000);
@ -259,8 +259,8 @@ bool is_ipl_updated(void *buf)
int launch_payload(char *path, bool update) int launch_payload(char *path, bool update)
{ {
if (!update) if (!update)
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
if (!path) if (!path)
return 1; return 1;
@ -351,8 +351,8 @@ void launch_tools(u8 type)
ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3)); ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3));
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
if (sd_mount()) if (sd_mount())
{ {
@ -394,7 +394,7 @@ void launch_tools(u8 type)
"Choose a file to launch", 0, 0 "Choose a file to launch", 0, 0
}; };
file_sec = (char *)tui_do_menu(&gfx_con, &menu); file_sec = (char *)tui_do_menu(&menu);
if (!file_sec) if (!file_sec)
{ {
@ -454,8 +454,8 @@ void ini_list_launcher()
ini_sec_t *cfg_sec = NULL; ini_sec_t *cfg_sec = NULL;
LIST_INIT(ini_list_sections); LIST_INIT(ini_list_sections);
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
if (sd_mount()) if (sd_mount())
{ {
@ -490,7 +490,7 @@ void ini_list_launcher()
ments, "Launch ini configurations", 0, 0 ments, "Launch ini configurations", 0, 0
}; };
cfg_tmp = (ini_sec_t *)tui_do_menu(&gfx_con, &menu); cfg_tmp = (ini_sec_t *)tui_do_menu(&menu);
if (cfg_tmp) if (cfg_tmp)
{ {
@ -568,8 +568,8 @@ void launch_firmware()
ini_sec_t *cfg_sec = NULL; ini_sec_t *cfg_sec = NULL;
LIST_INIT(ini_sections); LIST_INIT(ini_sections);
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
if (sd_mount()) if (sd_mount())
{ {
@ -618,7 +618,7 @@ void launch_firmware()
ments, "Launch configurations", 0, 0 ments, "Launch configurations", 0, 0
}; };
cfg_tmp = (ini_sec_t *)tui_do_menu(&gfx_con, &menu); cfg_tmp = (ini_sec_t *)tui_do_menu(&menu);
if (cfg_tmp) if (cfg_tmp)
{ {
@ -661,8 +661,8 @@ void launch_firmware()
if (!cfg_sec) if (!cfg_sec)
{ {
gfx_puts(&gfx_con, "\nPress POWER to Continue.\nPress VOL to go to the menu.\n\n"); gfx_puts("\nPress POWER to Continue.\nPress VOL to go to the menu.\n\n");
gfx_printf(&gfx_con, "\nUsing default launch configuration...\n\n\n"); gfx_printf("\nUsing default launch configuration...\n\n\n");
u32 btn = btn_wait(); u32 btn = btn_wait();
if (!(btn & BTN_POWER)) if (!(btn & BTN_POWER))
@ -876,7 +876,7 @@ void auto_launch_firmware()
bmpData.pos_y = (1280 - bmpData.size_y) >> 1; bmpData.pos_y = (1280 - bmpData.size_y) >> 1;
// Get background color from 1st pixel. // Get background color from 1st pixel.
if (bmpData.size_x < 720 || bmpData.size_y < 1280) if (bmpData.size_x < 720 || bmpData.size_y < 1280)
gfx_clear_color(&gfx_ctxt, *(u32 *)BOOTLOGO); gfx_clear_color(*(u32 *)BOOTLOGO);
bootlogoFound = true; bootlogoFound = true;
} }
@ -888,15 +888,15 @@ void auto_launch_firmware()
// Render boot logo. // Render boot logo.
if (bootlogoFound) if (bootlogoFound)
{ {
gfx_render_bmp_argb(&gfx_ctxt, (u32 *)BOOTLOGO, bmpData.size_x, bmpData.size_y, gfx_render_bmp_argb((u32 *)BOOTLOGO, bmpData.size_x, bmpData.size_y,
bmpData.pos_x, bmpData.pos_y); bmpData.pos_x, bmpData.pos_y);
} }
else else
{ {
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
BOOTLOGO = (void *)malloc(0x4000); BOOTLOGO = (void *)malloc(0x4000);
blz_uncompress_srcdest(BOOTLOGO_BLZ, SZ_BOOTLOGO_BLZ, BOOTLOGO, SZ_BOOTLOGO); blz_uncompress_srcdest(BOOTLOGO_BLZ, SZ_BOOTLOGO_BLZ, BOOTLOGO, SZ_BOOTLOGO);
gfx_set_rect_grey(&gfx_ctxt, BOOTLOGO, X_BOOTLOGO, Y_BOOTLOGO, 326, 544); gfx_set_rect_grey(BOOTLOGO, X_BOOTLOGO, Y_BOOTLOGO, 326, 544);
} }
free(BOOTLOGO); free(BOOTLOGO);
} }
@ -988,12 +988,12 @@ void about()
" (/` ( (` ) ) '-; %k[switchbrew]%k\n" " (/` ( (` ) ) '-; %k[switchbrew]%k\n"
" ` '-; (-'%k"; " ` '-; (-'%k";
gfx_clear_grey(&gfx_ctxt, 0x1B); gfx_clear_grey(0x1B);
gfx_con_setpos(&gfx_con, 0, 0); gfx_con_setpos(0, 0);
gfx_printf(&gfx_con, credits, 0xFF00CCFF, 0xFFCCCCCC); gfx_printf(credits, 0xFF00CCFF, 0xFFCCCCCC);
gfx_con.fntsz = 8; gfx_con.fntsz = 8;
gfx_printf(&gfx_con, octopus, 0xFF00CCFF, 0xFF00FFCC, 0xFF00CCFF, 0xFFCCCCCC); gfx_printf(octopus, 0xFF00CCFF, 0xFF00FFCC, 0xFF00CCFF, 0xFFCCCCCC);
btn_wait(); btn_wait();
} }
@ -1149,14 +1149,14 @@ void ipl_main()
display_init(); display_init();
u32 *fb = display_init_framebuffer(); u32 *fb = display_init_framebuffer();
gfx_init_ctxt(&gfx_ctxt, fb, 720, 1280, 720); gfx_init_ctxt(fb, 720, 1280, 720);
#ifdef MENU_LOGO_ENABLE #ifdef MENU_LOGO_ENABLE
Kc_MENU_LOGO = (u8 *)malloc(ALIGN(SZ_MENU_LOGO, 0x1000)); Kc_MENU_LOGO = (u8 *)malloc(ALIGN(SZ_MENU_LOGO, 0x1000));
blz_uncompress_srcdest(Kc_MENU_LOGO_blz, SZ_MENU_LOGO_BLZ, Kc_MENU_LOGO, SZ_MENU_LOGO); blz_uncompress_srcdest(Kc_MENU_LOGO_blz, SZ_MENU_LOGO_BLZ, Kc_MENU_LOGO, SZ_MENU_LOGO);
#endif #endif
gfx_con_init(&gfx_con, &gfx_ctxt); gfx_con_init(&gfx_ctxt);
display_backlight_pwm_init(); display_backlight_pwm_init();
//display_backlight_brightness(h_cfg.backlight, 1000); //display_backlight_brightness(h_cfg.backlight, 1000);
@ -1165,7 +1165,7 @@ void ipl_main()
auto_launch_firmware(); auto_launch_firmware();
while (true) while (true)
tui_do_menu(&gfx_con, &menu_top); tui_do_menu(&menu_top);
while (true) while (true)
; ;

View file

@ -215,16 +215,16 @@ int tsec_query(u8 *tsec_keys, u8 kb, tsec_ctxt_t *tsec_ctxt)
smmu_deinit_for_tsec(); smmu_deinit_for_tsec();
// for (int i = 0; i < kidx; i++) // for (int i = 0; i < kidx; i++)
// gfx_printf(&gfx_con, "key %08X\n", key[i]); // gfx_printf("key %08X\n", key[i]);
// gfx_printf(&gfx_con, "cpuctl (%08X) mbox (%08X)\n", TSEC(TSEC_CPUCTL), TSEC(TSEC_STATUS)); // gfx_printf("cpuctl (%08X) mbox (%08X)\n", TSEC(TSEC_CPUCTL), TSEC(TSEC_STATUS));
// u32 errst = MC(MC_ERR_STATUS); // u32 errst = MC(MC_ERR_STATUS);
// gfx_printf(&gfx_con, " MC %08X %08X %08X\n", MC(MC_INTSTATUS), errst, MC(MC_ERR_ADR)); // gfx_printf(" MC %08X %08X %08X\n", MC(MC_INTSTATUS), errst, MC(MC_ERR_ADR));
// gfx_printf(&gfx_con, " type: %02X\n", errst >> 28); // gfx_printf(" type: %02X\n", errst >> 28);
// gfx_printf(&gfx_con, " smmu: %02X\n", (errst >> 25) & 3); // gfx_printf(" smmu: %02X\n", (errst >> 25) & 3);
// gfx_printf(&gfx_con, " dir: %s\n", (errst >> 16) & 1 ? "W" : "R"); // gfx_printf(" dir: %s\n", (errst >> 16) & 1 ? "W" : "R");
// gfx_printf(&gfx_con, " cid: %02x\n", errst & 0xFF); // gfx_printf(" cid: %02x\n", errst & 0xFF);
} }
else else
{ {