diff --git a/bootloader/config/config.c b/bootloader/config/config.c index a6c8fbf..25ee62b 100644 --- a/bootloader/config/config.c +++ b/bootloader/config/config.c @@ -27,12 +27,6 @@ #include "../utils/list.h" #include "../utils/util.h" -extern gfx_ctxt_t gfx_ctxt; -extern gfx_con_t gfx_con; -//TODO: Create more macros (info, header, debug, etc) with different colors and utilize them for consistency. -#define EPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC) -#define EPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC) - extern hekate_config h_cfg; extern int sd_mount(); extern int sd_unmount(); diff --git a/bootloader/frontend/fe_emmc_tools.c b/bootloader/frontend/fe_emmc_tools.c index 492aa74..ccea1ed 100644 --- a/bootloader/frontend/fe_emmc_tools.c +++ b/bootloader/frontend/fe_emmc_tools.c @@ -35,19 +35,11 @@ extern sdmmc_t sd_sdmmc; extern sdmmc_storage_t sd_storage; extern FATFS sd_fs; extern hekate_config h_cfg; -extern gfx_ctxt_t gfx_ctxt; -extern gfx_con_t gfx_con; extern bool sd_mount(); extern void sd_unmount(); extern void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage); -//TODO: Create more macros (info, header, debug, etc) with different colors and utilize them for consistency. -#define EPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC) -#define EPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC) -#define WPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFFDD00, 0xFFCCCCCC) -#define WPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFFDD00, args, 0xFFCCCCCC) - static int _dump_emmc_verify(sdmmc_storage_t *storage, u32 lba_curr, char *outFilename, emmc_part_t *part) { FIL fp; diff --git a/bootloader/frontend/fe_info.c b/bootloader/frontend/fe_info.c index fa70678..47d762f 100644 --- a/bootloader/frontend/fe_info.c +++ b/bootloader/frontend/fe_info.c @@ -38,8 +38,6 @@ #include "../utils/btn.h" #include "../utils/util.h" -extern gfx_ctxt_t gfx_ctxt; -extern gfx_con_t gfx_con; extern sdmmc_storage_t sd_storage; extern FATFS sd_fs; @@ -48,12 +46,6 @@ extern void sd_unmount(); extern int sd_save_to_file(void *buf, u32 size, const char *filename); extern void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage); -//TODO: Create more macros (info, header, debug, etc) with different colors and utilize them for consistency. -#define EPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC) -#define EPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC) -#define WPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFFDD00, 0xFFCCCCCC) -#define WPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFFDD00, args, 0xFFCCCCCC) - #pragma GCC push_options #pragma GCC optimize ("Os") diff --git a/bootloader/frontend/fe_tools.c b/bootloader/frontend/fe_tools.c index 8e3c7c5..46e2df4 100644 --- a/bootloader/frontend/fe_tools.c +++ b/bootloader/frontend/fe_tools.c @@ -36,22 +36,14 @@ #include "../utils/btn.h" #include "../utils/util.h" -extern boot_cfg_t *b_cfg; +extern boot_cfg_t b_cfg; extern hekate_config h_cfg; -extern gfx_ctxt_t gfx_ctxt; -extern gfx_con_t gfx_con; -extern sdmmc_storage_t sd_storage; - extern bool sd_mount(); extern void sd_unmount(); extern int sd_save_to_file(void *buf, u32 size, const char *filename); extern void emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_storage_t *storage); -//TODO: Create more macros (info, header, debug, etc) with different colors and utilize them for consistency. -#define EPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC) -#define EPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC) - void dump_packages12() { if (!sd_mount()) @@ -100,8 +92,8 @@ void dump_packages12() if (kb >= KB_FIRMWARE_VERSION_700 && !h_cfg.sept_run) { - b_cfg->autoboot = 0; - b_cfg->autoboot_list = 0; + b_cfg.autoboot = 0; + b_cfg.autoboot_list = 0; gfx_printf(&gfx_con, "sept will run to get the keys.\nThen rerun this option."); btn_wait(); diff --git a/bootloader/gfx/gfx.h b/bootloader/gfx/gfx.h index 78fd534..d2bb614 100644 --- a/bootloader/gfx/gfx.h +++ b/bootloader/gfx/gfx.h @@ -21,6 +21,11 @@ #include "../../common/common_gfx.h" +#define EPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC) +#define EPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC) +#define WPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFFDD00, 0xFFCCCCCC) +#define WPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%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_clear_grey(gfx_ctxt_t *ctxt, u8 color); void gfx_clear_partial_grey(gfx_ctxt_t *ctxt, u8 color, u32 pos_x, u32 height); @@ -43,4 +48,8 @@ void gfx_set_rect_rgb(gfx_ctxt_t *ctxt, const u8 *buf, u32 size_x, u32 size_y, u 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_render_bmp_argb(gfx_ctxt_t *ctxt, const u32 *buf, u32 size_x, u32 size_y, u32 pos_x, u32 pos_y); +// Global gfx console and context. +gfx_ctxt_t gfx_ctxt; +gfx_con_t gfx_con; + #endif diff --git a/bootloader/hos/hos.c b/bootloader/hos/hos.c index ced1f97..24ed2c7 100644 --- a/bootloader/hos/hos.c +++ b/bootloader/hos/hos.c @@ -39,12 +39,8 @@ #include "../storage/nx_emmc.h" #include "../storage/sdmmc.h" #include "../utils/util.h" - #include "../gfx/gfx.h" -extern gfx_ctxt_t gfx_ctxt; -extern gfx_con_t gfx_con; -extern boot_cfg_t *b_cfg; extern hekate_config h_cfg; extern void sd_unmount(); @@ -52,10 +48,11 @@ extern void sd_unmount(); //#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__) #define DPRINTF(...) -#define SECMON_MB_ADDR 0x40002EF8 -#define SECMON7_MB_ADDR 0x400000F8 +#define PKG2_LOAD_ADDR 0xA9800000 // Secmon mailbox. +#define SECMON_MB_ADDR 0x40002EF8 +#define SECMON7_MB_ADDR 0x400000F8 typedef struct _secmon_mailbox_t { // < 4.0.0 Signals - 0: Not ready, 1: BCT ready, 2: DRAM and pkg2 ready, 3: Continue boot. @@ -207,7 +204,7 @@ int keygen(u8 *keyblob, u32 kb, tsec_ctxt_t *tsec_ctxt) // We rely on racing conditions, make sure we cover even the unluckiest cases. if (retries > 15) { - gfx_printf(&gfx_con, "%k\nFailed to get TSEC keys. Please try again.%k\n\n", 0xFFFF0000, 0xFFCCCCCC); + EPRINTF("\nFailed to get TSEC keys. Please try again.\n"); return 0; } } @@ -308,7 +305,7 @@ static int _read_emmc_pkg1(launch_ctxt_t *ctxt) ctxt->pkg1_id = pkg1_identify(ctxt->pkg1); if (!ctxt->pkg1_id) { - gfx_printf(&gfx_con, "%kUnknown pkg1 version.%k\n", 0xFFFF0000, 0xFFCCCCCC); + EPRINTF("Unknown pkg1 version."); goto out; } gfx_printf(&gfx_con, "Identified pkg1 and Keyblob %d\n\n", ctxt->pkg1_id->kb); @@ -388,6 +385,7 @@ int hos_launch(ini_sec_t *cfg) volatile secmon_mailbox_t *secmon_mb; memset(&ctxt, 0, sizeof(launch_ctxt_t)); + memset(&tsec_ctxt, 0, sizeof(tsec_ctxt_t)); list_init(&ctxt.kip1_list); if (!gfx_con.mute) @@ -443,7 +441,10 @@ int hos_launch(ini_sec_t *cfg) gfx_printf(&gfx_con, "Decrypted & unpacked pkg1\n"); } else + { + EPRINTF("No mandatory secmon or warmboot provided!"); return 0; + } } // Replace 'warmboot.bin' if requested. @@ -453,7 +454,7 @@ int hos_launch(ini_sec_t *cfg) { if (ctxt.pkg1_id->kb >= KB_FIRMWARE_VERSION_700) { - gfx_printf(&gfx_con, "%kNo warmboot provided!%k\n", 0xFFFF0000, 0xFFCCCCCC); + EPRINTF("No warmboot provided!"); return 0; } // Else we patch it to allow downgrading. @@ -545,7 +546,7 @@ int hos_launch(ini_sec_t *cfg) const char* unappliedPatch = pkg2_patch_kips(&kip1_info, ctxt.kip1_patches); if (unappliedPatch != NULL) { - gfx_printf(&gfx_con, "%kFailed to apply '%s'!%k\n", 0xFFFF0000, unappliedPatch, 0xFFCCCCCC); + EPRINTFARGS("Failed to apply '%s'!", unappliedPatch); sd_unmount(); // Just exiting is not enough until pkg2_patch_kips stops modifying the string passed into it. _free_launch_components(&ctxt); @@ -553,7 +554,7 @@ int hos_launch(ini_sec_t *cfg) } // Rebuild and encrypt package2. - pkg2_build_encrypt((void *)0xA9800000, 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"); diff --git a/bootloader/hos/hos_config.c b/bootloader/hos/hos_config.c index 6bdb04a..4d956de 100644 --- a/bootloader/hos/hos_config.c +++ b/bootloader/hos/hos_config.c @@ -24,7 +24,6 @@ #include "../utils/dirlist.h" #include "../gfx/gfx.h" -extern gfx_con_t gfx_con; //#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__) #define DPRINTF(...) diff --git a/bootloader/hos/pkg1.c b/bootloader/hos/pkg1.c index 806af5d..b40b791 100644 --- a/bootloader/hos/pkg1.c +++ b/bootloader/hos/pkg1.c @@ -24,8 +24,6 @@ #include "../sec/se.h" #include "../utils/aarch64_util.h" -extern gfx_con_t gfx_con; - #define _NOPv7() 0xE320F000 #define SM_100_ADR 0x4002B020 diff --git a/bootloader/hos/pkg2.c b/bootloader/hos/pkg2.c index 1fcfa8e..46641df 100644 --- a/bootloader/hos/pkg2.c +++ b/bootloader/hos/pkg2.c @@ -29,8 +29,6 @@ #pragma GCC push_options #pragma GCC optimize ("Os") -extern gfx_con_t gfx_con; - /*#include "util.h" #define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__) #define DEBUG_PRINTING*/ diff --git a/bootloader/hos/sept.c b/bootloader/hos/sept.c index 8d89212..6878c17 100644 --- a/bootloader/hos/sept.c +++ b/bootloader/hos/sept.c @@ -31,9 +31,6 @@ #include "../utils/types.h" #include "../gfx/gfx.h" -extern gfx_con_t gfx_con; -#define EPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC) -#define EPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC) #define RELOC_META_OFF 0x7C #define PATCHED_RELOC_SZ 0x94 diff --git a/bootloader/ianos/ianos.c b/bootloader/ianos/ianos.c index 0fdeb0a..0fbe7db 100644 --- a/bootloader/ianos/ianos.c +++ b/bootloader/ianos/ianos.c @@ -27,8 +27,6 @@ #define IRAM_LIB_ADDR 0x4002B000 #define DRAM_LIB_ADDR 0xE0000000 -extern gfx_ctxt_t gfx_ctxt; -extern gfx_con_t gfx_con; extern heap_t _heap; extern void *sd_file_read(char *path); diff --git a/bootloader/libs/elfload/elfload.h b/bootloader/libs/elfload/elfload.h index 51c520d..4f7418b 100644 --- a/bootloader/libs/elfload/elfload.h +++ b/bootloader/libs/elfload/elfload.h @@ -26,7 +26,6 @@ #ifdef DEBUG #include "../../gfx/gfx.h" -extern gfx_con_t gfx_con; #define EL_DEBUG(format, ...) \ gfx_printf(&gfx_con, format __VA_OPT__(, ) __VA_ARGS__) #else diff --git a/bootloader/main.c b/bootloader/main.c index 6be5d92..35d6a31 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -48,16 +48,6 @@ #include "frontend/fe_tools.h" #include "frontend/fe_info.h" -//TODO: ugly. -gfx_ctxt_t gfx_ctxt; -gfx_con_t gfx_con; - -//TODO: Create more macros (info, header, debug, etc) with different colors and utilize them for consistency. -#define EPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, 0xFFCCCCCC) -#define EPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFF0000, args, 0xFFCCCCCC) -#define WPRINTF(text) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFFDD00, 0xFFCCCCCC) -#define WPRINTFARGS(text, args...) gfx_printf(&gfx_con, "%k"text"%k\n", 0xFFFFDD00, args, 0xFFCCCCCC) - //TODO: ugly. sdmmc_t sd_sdmmc; sdmmc_storage_t sd_storage; diff --git a/bootloader/storage/sdmmc.c b/bootloader/storage/sdmmc.c index 20e3119..cc56a03 100644 --- a/bootloader/storage/sdmmc.c +++ b/bootloader/storage/sdmmc.c @@ -19,13 +19,11 @@ #include "sdmmc.h" #include "mmc.h" #include "sd.h" -#include "../utils/util.h" +#include "../gfx/gfx.h" #include "../mem/heap.h" +#include "../utils/util.h" -/*#include "gfx.h" -extern gfx_ctxt_t gfx_ctxt; -extern gfx_con_t gfx_con; -#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__)*/ +//#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__) #define DPRINTF(...) static inline u32 unstuff_bits(u32 *resp, u32 start, u32 size) diff --git a/bootloader/storage/sdmmc_driver.c b/bootloader/storage/sdmmc_driver.c index 98ecab3..13462a9 100644 --- a/bootloader/storage/sdmmc_driver.c +++ b/bootloader/storage/sdmmc_driver.c @@ -17,20 +17,18 @@ #include -#include "sdmmc.h" -#include "../utils/util.h" -#include "../soc/clock.h" #include "mmc.h" +#include "sdmmc.h" +#include "../gfx/gfx.h" #include "../power/max7762x.h" -#include "../soc/t210.h" -#include "../soc/pmc.h" -#include "../soc/pinmux.h" +#include "../soc/clock.h" #include "../soc/gpio.h" +#include "../soc/pinmux.h" +#include "../soc/pmc.h" +#include "../soc/t210.h" +#include "../utils/util.h" -/*#include "gfx.h" -extern gfx_ctxt_t gfx_ctxt; -extern gfx_con_t gfx_con; -#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__)*/ +//#define DPRINTF(...) gfx_printf(&gfx_con, __VA_ARGS__) #define DPRINTF(...) /*! SCMMC controller base addresses. */