diff --git a/fusee/fusee-primary/src/lib/printk.c b/fusee/fusee-primary/src/lib/printk.c index 8e990757b..33c368dee 100644 --- a/fusee/fusee-primary/src/lib/printk.c +++ b/fusee/fusee-primary/src/lib/printk.c @@ -13,7 +13,7 @@ * TODO: This should print via UART, console framebuffer, and to a ring for * consumption by Horizon */ -void printk(char *fmt, ...) +void printk(const char *fmt, ...) { va_list list; va_start(list, fmt); @@ -22,7 +22,7 @@ void printk(char *fmt, ...) } -void vprintk(char *fmt, va_list args) +void vprintk(const char *fmt, va_list args) { char buf[512]; vsnprintf(buf, sizeof(buf), fmt, args); diff --git a/fusee/fusee-primary/src/lib/printk.h b/fusee/fusee-primary/src/lib/printk.h index aaad8f1b4..9b0c3d710 100644 --- a/fusee/fusee-primary/src/lib/printk.h +++ b/fusee/fusee-primary/src/lib/printk.h @@ -3,7 +3,7 @@ #include -void printk(char *fmt, ...); -void vprintk(char *fmt, va_list args); +void printk(const char *fmt, ...); +void vprintk(const char *fmt, va_list args); #endif diff --git a/fusee/fusee-primary/src/main.c b/fusee/fusee-primary/src/main.c index 10a69c881..95ef2bf01 100644 --- a/fusee/fusee-primary/src/main.c +++ b/fusee/fusee-primary/src/main.c @@ -34,8 +34,7 @@ static const char *load_config(void) { } if (memcmp(g_bct0_buffer, "BCT0", 4) != 0) { - printk("Error: Unexpected magic in BCT.ini!\n"); - generic_panic(); + fatal_error("Unexpected magic in BCT.ini!\n"); } /* Return pointer to first line of the ini. */ const char *bct0 = g_bct0_buffer; @@ -43,8 +42,7 @@ static const char *load_config(void) { bct0++; } if (!bct0) { - printk("Error: BCT.ini has no newline!\n"); - generic_panic(); + fatal_error("BCT.ini has no newline!\n"); } return bct0; } @@ -116,9 +114,8 @@ int main(void) { #ifndef I_KNOW_WHAT_I_AM_DOING #error "Fusee is a work-in-progress bootloader, and is not ready for usage yet. If you want to play with it anyway, please #define I_KNOW_WHAT_I_AM_DOING -- and recognize that we will be unable to provide support until it is ready for general usage :)" - printk("Warning: Fus\e9e is not yet completed, and not ready for general testing!\n"); - printk("Please do not seek support for it until it is done.\n"); - generic_panic(); + printk("Warning: Fus\xe9" "e is not yet completed, and not ready for general testing!\n"); + fatal_error("Please do not seek support for it until it is done.\n"); #endif /* Load the BCT0 configuration ini off of the SD. */ diff --git a/fusee/fusee-primary/src/stage2.c b/fusee/fusee-primary/src/stage2.c index 3321d39ea..dded81221 100644 --- a/fusee/fusee-primary/src/stage2.c +++ b/fusee/fusee-primary/src/stage2.c @@ -49,13 +49,11 @@ void load_stage2(const char *bct0) { uintptr_t tmp_addr; if (ini_parse_string(bct0, stage2_ini_handler, &config) < 0) { - printk("Error: Failed to parse BCT.ini!\n"); - generic_panic(); + fatal_error("Failed to parse BCT.ini!\n"); } if (config.load_address == 0 || config.path[0] == '\x00') { - printk("Error: Failed to determine where to load stage2!\n"); - generic_panic(); + fatal_error("Failed to determine where to load stage2!\n"); } if (strlen(config.path) + 1 + sizeof(stage2_args_t) > CHAINLOADER_ARG_DATA_MAX_SIZE) { @@ -63,13 +61,11 @@ void load_stage2(const char *bct0) { } if (!check_32bit_address_loadable(config.entrypoint)) { - printk("Error: Stage2's entrypoint is invalid!\n"); - generic_panic(); + fatal_error("Stage2's entrypoint is invalid!\n"); } if (!check_32bit_address_loadable(config.load_address)) { - printk("Error: Stage2's load address is invalid!\n"); - generic_panic(); + fatal_error("Stage2's load address is invalid!\n"); } printk("[DEBUG] Stage 2 Config:\n"); @@ -78,26 +74,22 @@ void load_stage2(const char *bct0) { printk(" Entrypoint: 0x%p\n", config.entrypoint); if (f_stat(config.path, &info) != FR_OK) { - printk("Error: Failed to stat stage2 (%s)!\n", config.path); - generic_panic(); + fatal_error("Failed to stat stage2 (%s)!\n", config.path); } size = (size_t)info.fsize; /* the LFB is located at 0xC0000000 atm */ if (size > 0xC0000000u - 0x80000000u) { - printk("Error: Stage2 is way too big!\n"); - generic_panic(); + fatal_error("Stage2 is way too big!\n"); } if (!check_32bit_address_range_loadable(config.load_address, size)) { - printk("Error: Stage2 has an invalid load address & size combination (0x%08x 0x%08x)!\n", config.load_address, size); - generic_panic(); + fatal_error("Stage2 has an invalid load address & size combination (0x%08x 0x%08x)!\n", config.load_address, size); } if (config.entrypoint < config.load_address || config.entrypoint >= config.load_address + size) { - printk("Error: Stage2's entrypoint is outside Stage2!\n"); - generic_panic(); + fatal_error("Stage2's entrypoint is outside Stage2!\n"); } if (check_32bit_address_range_in_program(config.load_address, size)) { @@ -107,8 +99,7 @@ void load_stage2(const char *bct0) { } if (read_from_file((void *)tmp_addr, size, config.path) != size) { - printk("Error: Failed to read stage2 (%s)!\n", config.path); - generic_panic(); + fatal_error("Failed to read stage2 (%s)!\n", config.path); } g_chainloader_num_entries = 1; diff --git a/fusee/fusee-primary/src/utils.c b/fusee/fusee-primary/src/utils.c index 884066c8b..3a119a7b5 100644 --- a/fusee/fusee-primary/src/utils.c +++ b/fusee/fusee-primary/src/utils.c @@ -1,10 +1,13 @@ #include +#include #include "utils.h" #include "se.h" #include "fuse.h" #include "pmc.h" #include "timers.h" +#include "panic.h" +#include "lib/printk.h" #include "hwinit/btn.h" __attribute__((noreturn)) void watchdog_reboot(void) { @@ -45,7 +48,17 @@ __attribute__((noreturn)) void wait_for_button_and_pmc_reboot(void) { } __attribute__ ((noreturn)) void generic_panic(void) { - while(true);//panic(0xFF000006); + panic(0xFF000006); +} + +__attribute__((noreturn)) void fatal_error(const char *fmt, ...) { + va_list args; + printk("Fatal error: "); + va_start(args, fmt); + vprintk(fmt, args); + va_end(args); + printk("\nPress POWER to reboot into RCM, VOL+/VOL- to reboot normally.\n"); + wait_for_button_and_pmc_reboot(); } __attribute__((noinline)) bool overlaps(uint64_t as, uint64_t ae, uint64_t bs, uint64_t be) diff --git a/fusee/fusee-primary/src/utils.h b/fusee/fusee-primary/src/utils.h index f5b6e26ed..c5327acfa 100644 --- a/fusee/fusee-primary/src/utils.h +++ b/fusee/fusee-primary/src/utils.h @@ -105,7 +105,8 @@ __attribute__((noreturn)) void watchdog_reboot(void); __attribute__((noreturn)) void pmc_reboot(uint32_t scratch0); __attribute__((noreturn)) void wait_for_button_and_pmc_reboot(void); +__attribute__((noreturn)) void generic_panic(void); -void generic_panic(void); +__attribute__((noreturn)) void fatal_error(const char *fmt, ...); #endif diff --git a/fusee/fusee-secondary/src/loader.c b/fusee/fusee-secondary/src/loader.c index 2443d5c8c..33c81b554 100644 --- a/fusee/fusee-secondary/src/loader.c +++ b/fusee/fusee-secondary/src/loader.c @@ -52,34 +52,28 @@ static void load_list_entry(const char *key) { load_file_ctx.key = key; if (ini_parse_string(get_loader_ctx()->bct0, loadlist_entry_ini_handler, &load_file_ctx) < 0) { - printf("Error: Failed to parse BCT.ini!\n"); - generic_panic(); + fatal_error("Failed to parse BCT.ini!\n"); } if (load_file_ctx.load_address == 0 || load_file_ctx.path[0] == '\x00') { - printf("Error: Failed to determine where to load %s from!\n", key); - generic_panic(); + fatal_error("Failed to determine where to load %s from!\n", key); } if (strlen(load_file_ctx.path) > LOADER_MAX_PATH_SIZE) { - printf("Error: The filename for %s is too long!\n", key); - generic_panic(); + fatal_error("The filename for %s is too long!\n", key); } if (!check_32bit_address_loadable(load_file_ctx.load_address)) { - printf("Error: Load address 0x%08x is invalid (%s)!\n", load_file_ctx.load_address, key); - generic_panic(); + fatal_error("Load address 0x%08x is invalid (%s)!\n", load_file_ctx.load_address, key); } if (stat(load_file_ctx.path, &st) == -1) { - printf("Error: Failed to stat file %s: %s!\n", load_file_ctx.path, strerror(errno)); - generic_panic(); + fatal_error("Failed to stat file %s: %s!\n", load_file_ctx.path, strerror(errno)); } size = (size_t)st.st_size; if (!check_32bit_address_range_loadable(load_file_ctx.load_address, size)) { - printf("Error: %s has an invalid load address & size combination!\n", key); - generic_panic(); + fatal_error("%s has an invalid load address & size combination!\n", key); } entry_num = g_chainloader_num_entries++; @@ -114,8 +108,7 @@ static void parse_loadlist(const char *ll) { /* Skip to the next delimiter. */ for (; *p == ' ' || *p == '\t' || *p == '\x00'; p++) { } if (*p != '|') { - printf("Error: Load list is malformed!\n"); - generic_panic(); + fatal_error("Load list is malformed!\n"); } else { /* Skip to the next entry. */ for (; *p == ' ' || *p == '\t' || *p == '|'; p++) { } @@ -216,13 +209,11 @@ void load_payload(const char *bct0) { ctx->bct0 = bct0; if (ini_parse_string(ctx->bct0, loadlist_ini_handler, ctx) < 0) { - printf("Error: Failed to parse BCT.ini!\n"); - generic_panic(); + fatal_error("Failed to parse BCT.ini!\n"); } if (ctx->chainload_entrypoint != 0 || ctx->nb_files_to_load > 0) { - printf("Error: loadlist must be empty when booting Horizon!\n"); - generic_panic(); + fatal_error("loadlist must be empty when booting Horizon!\n"); } /* Sort the entries by ascending load addresses */ @@ -239,8 +230,8 @@ void load_payload(const char *bct0) { g_chainloader_entries[i + 1].load_address + g_chainloader_entries[i + 1].size ) ) { - printf( - "Error: Loading ranges for files %s and %s overlap!\n", + fatal_error( + "Loading ranges for files %s and %s overlap!\n", ctx->file_paths_to_load[g_chainloader_entries[i].num], ctx->file_paths_to_load[g_chainloader_entries[i + 1].num] ); @@ -260,8 +251,7 @@ void load_payload(const char *bct0) { } if (ctx->chainload_entrypoint != 0 && ctx->file_id_of_entrypoint >= ctx->nb_files_to_load) { - printf("Error: Entrypoint not in range of any of the files!\n"); - generic_panic(); + fatal_error("Entrypoint not in range of any of the files!\n"); } if (can_load_in_place) { @@ -269,8 +259,7 @@ void load_payload(const char *bct0) { chainloader_entry_t *entry = &g_chainloader_entries[i]; entry->src_address = entry->load_address; if (read_from_file((void *)entry->src_address, entry->size, ctx->file_paths_to_load[entry->num]) != entry->size) { - printf("Error: Failed to read file %s: %s!\n", ctx->file_paths_to_load[entry->num], strerror(errno)); - generic_panic(); + fatal_error("Failed to read file %s: %s!\n", ctx->file_paths_to_load[entry->num], strerror(errno)); } } } else { @@ -296,8 +285,7 @@ void load_payload(const char *bct0) { carveout = find_carveout(g_chainloader_entries, g_chainloader_num_entries, total_size); } if (carveout == 0) { - printf("Error: Failed to find a carveout!\n"); - generic_panic(); + fatal_error("Failed to find a carveout!\n"); } /* Finally, read the files into the carveout */ @@ -306,8 +294,7 @@ void load_payload(const char *bct0) { chainloader_entry_t *entry = &g_chainloader_entries[i]; entry->src_address = pos; if (read_from_file((void *)entry->src_address, entry->size, ctx->file_paths_to_load[entry->num]) != entry->size) { - printf("Error: Failed to read file %s: %s!\n", ctx->file_paths_to_load[entry->num], strerror(errno)); - generic_panic(); + fatal_error("Failed to read file %s: %s!\n", ctx->file_paths_to_load[entry->num], strerror(errno)); } pos += entry->size; } diff --git a/fusee/fusee-secondary/src/main.c b/fusee/fusee-secondary/src/main.c index 890c73ddf..fe441e78b 100644 --- a/fusee/fusee-secondary/src/main.c +++ b/fusee/fusee-secondary/src/main.c @@ -62,14 +62,12 @@ int main(int argc, void **argv) { setup_env(); if (argc != STAGE2_ARGC) { - printf("Error: Invalid argc (expected %d, got %d)!\n", STAGE2_ARGC, argc); - generic_panic(); + fatal_error("Invalid argc (expected %d, got %d)!\n", STAGE2_ARGC, argc); } g_stage2_args = (stage2_args_t *)argv[STAGE2_ARGV_ARGUMENT_STRUCT]; if(g_stage2_args->version != 0) { - printf("Error: Incorrect Stage2 args version (expected %lu, got %lu)!\n", 0ul, g_stage2_args->version); - generic_panic(); + fatal_error("Incorrect Stage2 args version (expected %lu, got %lu)!\n", 0ul, g_stage2_args->version); } printf(u8"Welcome to Atmosphère Fusée Stage 2!\n"); diff --git a/fusee/fusee-secondary/src/nxboot.c b/fusee/fusee-secondary/src/nxboot.c index 06c40ee83..d06f195e0 100644 --- a/fusee/fusee-secondary/src/nxboot.c +++ b/fusee/fusee-secondary/src/nxboot.c @@ -44,13 +44,11 @@ static void nxboot_configure_exosphere(void) { exo_cfg.target_firmware = EXOSPHERE_TARGET_FIRMWARE_MAX; if (ini_parse_string(get_loader_ctx()->bct0, exosphere_ini_handler, &exo_cfg) < 0) { - printf("Error: Failed to parse BCT.ini!\n"); - generic_panic(); + fatal_error("Failed to parse BCT.ini!\n"); } if (exo_cfg.target_firmware < EXOSPHERE_TARGET_FIRMWARE_MIN || exo_cfg.target_firmware > EXOSPHERE_TARGET_FIRMWARE_MAX) { - printf("Error: Invalid Exosphere target firmware!\n"); - generic_panic(); + fatal_error("Invalid Exosphere target firmware!\n"); } *(MAILBOX_EXOSPHERE_CONFIGURATION) = exo_cfg; @@ -78,16 +76,14 @@ void nxboot_main(void) { /* TODO: How should we deal with bootconfig? */ package2 = memalign(4096, PACKAGE2_SIZE_MAX); if (package2 == NULL) { - printf("Error: nxboot: out of memory!\n"); - generic_panic(); + fatal_error("nxboot: out of memory!\n"); } /* Read Package2 from a file, otherwise from its partition(s). */ if (loader_ctx->package2_path[0] != '\0') { pk2file = fopen(loader_ctx->package2_path, "rb"); if (pk2file == NULL) { - printf("Error: Failed to open Package2 from %s: %s!\n", loader_ctx->package2_path, strerror(errno)); - generic_panic(); + fatal_error("Failed to open Package2 from %s: %s!\n", loader_ctx->package2_path, strerror(errno)); } } else { #ifndef I_KNOW_WHAT_IM_DOING_2 @@ -98,26 +94,22 @@ void nxboot_main(void) { generic_panic(); } #else - printf("Error: Package2 must be loaded from the SD card, unless you know what you are doing!\n"); - generic_panic(); + fatal_error("Package2 must be loaded from the SD card, unless you know what you are doing!\n"); #endif } setvbuf(pk2file, NULL, _IONBF, 0); /* Workaround. */ if (fread(package2, sizeof(package2_header_t), 1, pk2file) < 1) { - printf("Error: Failed to read Package2!\n"); - generic_panic(); + fatal_error("Failed to read Package2!\n"); } package2_size = package2_meta_get_size(&package2->metadata); if (package2_size > PACKAGE2_SIZE_MAX || package2_size <= sizeof(package2_header_t)) { - printf("Error: Package2 is too big or too small!\n"); - generic_panic(); + fatal_error("Package2 is too big or too small!\n"); } if (fread(package2->data, package2_size - sizeof(package2_header_t), 1, pk2file) < 1) { - printf("Error: Failed to read Package2!\n"); - generic_panic(); + fatal_error("Failed to read Package2!\n"); } fclose(pk2file); @@ -129,8 +121,7 @@ void nxboot_main(void) { printf("Reading boot0...\n"); boot0 = fopen("boot0:/", "rb"); if (boot0 == NULL || package1_read_and_parse_boot0(&package1loader, &package1loader_size, g_keyblobs, &available_revision, boot0) == -1) { - printf("Error: Couldn't parse boot0: %s!\n", strerror(errno)); - generic_panic(); + fatal_error("Couldn't parse boot0: %s!\n", strerror(errno)); } fclose(boot0); @@ -138,27 +129,22 @@ void nxboot_main(void) { if (loader_ctx->tsecfw_path[0] != '\0') { tsec_fw_size = get_file_size(loader_ctx->tsecfw_path); if (tsec_fw_size != 0 && tsec_fw_size != 0xF00) { - printf("Error: TSEC firmware from %s has a wrong size!\n", loader_ctx->tsecfw_path); - generic_panic(); + fatal_error("TSEC firmware from %s has a wrong size!\n", loader_ctx->tsecfw_path); } else if (tsec_fw_size == 0) { - printf("Error: Could not read the TSEC firmware from %s!\n", loader_ctx->tsecfw_path); - generic_panic(); + fatal_error("Could not read the TSEC firmware from %s!\n", loader_ctx->tsecfw_path); } tsec_fw = memalign(0x100, tsec_fw_size); if (tsec_fw == NULL) { - printf("Error: nxboot_main: out of memory!\n"); - generic_panic(); + fatal_error("nxboot_main: out of memory!\n"); } if (read_from_file(tsec_fw, tsec_fw_size, loader_ctx->tsecfw_path) != tsec_fw_size) { - printf("Error: Could not read the TSEC firmware from %s!\n", loader_ctx->tsecfw_path); - generic_panic(); + fatal_error("Could not read the TSEC firmware from %s!\n", loader_ctx->tsecfw_path); } } else { tsec_fw_size = package1_get_tsec_fw(&tsec_fw, package1loader, package1loader_size); if (tsec_fw_size == 0) { - printf("Error: Failed to read the TSEC firmware from Package1loader!\n"); - generic_panic(); + fatal_error("Failed to read the TSEC firmware from Package1loader!\n"); } } @@ -168,26 +154,22 @@ void nxboot_main(void) { /* Derive keydata. */ if (derive_nx_keydata(MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware, g_keyblobs, available_revision, tsec_fw, tsec_fw_size) != 0) { - printf("Error: Key derivation failed!\n"); - generic_panic(); + fatal_error("Key derivation failed!\n"); } /* Read the warmboot firmware from a file, otherwise from PK1. */ if (loader_ctx->warmboot_path[0] != '\0') { warmboot_fw_size = get_file_size(loader_ctx->warmboot_path); if (warmboot_fw_size == 0) { - printf("Error: Could not read the warmboot firmware from %s!\n", loader_ctx->warmboot_path); - generic_panic(); + fatal_error("Could not read the warmboot firmware from %s!\n", loader_ctx->warmboot_path); } warmboot_fw = malloc(warmboot_fw_size); if (warmboot_fw == NULL) { - printf("Error: nxboot_main: out of memory!\n"); - generic_panic(); + fatal_error("nxboot_main: out of memory!\n"); } if (read_from_file(warmboot_fw, warmboot_fw_size, loader_ctx->warmboot_path) != warmboot_fw_size) { - printf("Error: Could not read the warmboot firmware from %s!\n", loader_ctx->warmboot_path); - generic_panic(); + fatal_error("Could not read the warmboot firmware from %s!\n", loader_ctx->warmboot_path); } } else { uint8_t ctr[16]; @@ -201,8 +183,7 @@ void nxboot_main(void) { } if (warmboot_fw_size == 0) { - printf("Error: Could not read the warmboot firmware from Package1!\n"); - generic_panic(); + fatal_error("Could not read the warmboot firmware from Package1!\n"); } } @@ -221,17 +202,14 @@ void nxboot_main(void) { if (loader_ctx->exosphere_path[0] != '\0') { size_t exosphere_size = get_file_size(loader_ctx->exosphere_path); if (exosphere_size == 0) { - printf(u8"Error: Could not read Exosphère from %s!\n", loader_ctx->exosphere_path); - generic_panic(); + fatal_error(u8"Error: Could not read Exosphère from %s!\n", loader_ctx->exosphere_path); } else if (exosphere_size > 0x10000) { /* The maximum is actually a bit less than that. */ - printf(u8"Error: Exosphère from %s is too big!\n", loader_ctx->exosphere_path); - generic_panic(); + fatal_error(u8"Error: Exosphère from %s is too big!\n", loader_ctx->exosphere_path); } if (read_from_file(exosphere_memaddr, exosphere_size, loader_ctx->exosphere_path) != exosphere_size) { - printf(u8"Error: Could not read Exosphère from %s!\n", loader_ctx->exosphere_path); - generic_panic(); + fatal_error(u8"Error: Could not read Exosphère from %s!\n", loader_ctx->exosphere_path); } } else { memcpy(exosphere_memaddr, exosphere_bin, exosphere_bin_size); diff --git a/fusee/fusee-secondary/src/package2.c b/fusee/fusee-secondary/src/package2.c index 88cd9345c..96973d223 100644 --- a/fusee/fusee-secondary/src/package2.c +++ b/fusee/fusee-secondary/src/package2.c @@ -39,8 +39,7 @@ void package2_rebuild_and_copy(package2_header_t *package2, uint32_t target_firm thermosphere_size = package2_get_thermosphere(&thermosphere); if (thermosphere_size != 0 && package2->metadata.section_sizes[PACKAGE2_SECTION_UNUSED] != 0) { - printf(u8"Error: Package2 has no unused section for Thermosphère!\n"); - generic_panic(); + fatal_error(u8"Error: Package2 has no unused section for Thermosphère!\n"); } /* Perform any patches we want to the NX kernel. */ @@ -56,14 +55,12 @@ void package2_rebuild_and_copy(package2_header_t *package2, uint32_t target_firm rebuilt_package2_size += package2->metadata.section_sizes[PACKAGE2_SECTION_KERNEL] + thermosphere_size + rebuilt_ini1->size; if (rebuilt_package2_size > PACKAGE2_SIZE_MAX) { - printf("Error: rebuilt package2 is too big!\n"); - generic_panic(); + fatal_error("rebuilt package2 is too big!\n"); } rebuilt_package2 = (package2_header_t *)malloc(rebuilt_package2_size); if (rebuilt_package2 == NULL) { - printf("Error: package2_rebuild: out of memory!\n"); - generic_panic(); + fatal_error("package2_rebuild: out of memory!\n"); } /* Rebuild package2. */ @@ -205,12 +202,10 @@ static uint32_t package2_decrypt_and_validate_header(package2_header_t *header, /* Ensure we successfully decrypted the header. */ if (mkey_rev > mkey_get_revision()) { - printf("Error: failed to decrypt the Package2 header (master key revision %u)!\n", mkey_get_revision()); - generic_panic(); + fatal_error("failed to decrypt the Package2 header (master key revision %u)!\n", mkey_get_revision()); } } else if (!package2_validate_metadata(&header->metadata)) { - printf("Error: Failed to validate the Package2 header!\n"); - generic_panic(); + fatal_error("Failed to validate the Package2 header!\n"); } return 0; } diff --git a/fusee/fusee-secondary/src/splash_screen.c b/fusee/fusee-secondary/src/splash_screen.c index b49db6798..c317d3797 100644 --- a/fusee/fusee-secondary/src/splash_screen.c +++ b/fusee/fusee-secondary/src/splash_screen.c @@ -9,8 +9,7 @@ void display_splash_screen_bmp(const char *custom_splash_path) { uint8_t *splash_screen = g_default_splash_screen; if (custom_splash_path != NULL && custom_splash_path[0] != '\x00') { if (!read_from_file(splash_screen, sizeof(g_default_splash_screen), custom_splash_path)) { - printf("Error: Failed to read custom splash screen from %s!\n", custom_splash_path); - generic_panic(); + fatal_error("Failed to read custom splash screen from %s!\n", custom_splash_path); } } diff --git a/fusee/fusee-secondary/src/stratosphere.c b/fusee/fusee-secondary/src/stratosphere.c index 223c9ab9c..c27d55bdb 100644 --- a/fusee/fusee-secondary/src/stratosphere.c +++ b/fusee/fusee-secondary/src/stratosphere.c @@ -47,8 +47,7 @@ ini1_header_t *stratosphere_get_ini1(uint32_t target_firmware) { g_stratosphere_ini1 = (ini1_header_t *)malloc(size); if (g_stratosphere_ini1 != NULL) { - printf("Error: stratosphere_get_ini1: out of memory!\n"); - generic_panic(); + fatal_error("stratosphere_get_ini1: out of memory!\n"); } g_stratosphere_ini1->magic = MAGIC_INI1; @@ -87,24 +86,21 @@ ini1_header_t *stratosphere_merge_inis(ini1_header_t **inis, size_t num_inis) { /* Validate all ini headers. */ for (size_t i = 0; i < num_inis; i++) { if (inis[i] == NULL || inis[i]->magic != MAGIC_INI1 || inis[i]->num_processes > INI1_MAX_KIPS) { - printf("Error: INI1s[%d] section appears to not contain an INI1!\n", i); - generic_panic(); + fatal_error("INI1s[%d] section appears to not contain an INI1!\n", i); } else { total_num_processes += inis[i]->num_processes; } } if (total_num_processes > INI1_MAX_KIPS) { - printf("Error: The resulting INI1 would have too many KIPs!\n"); - generic_panic(); + fatal_error("The resulting INI1 would have too many KIPs!\n"); } uint64_t process_list[INI1_MAX_KIPS] = {0}; ini1_header_t *merged = (ini1_header_t *)malloc(PACKAGE2_SIZE_MAX); /* because of SD file overrides */ if (merged == NULL) { - printf("Error: stratosphere_merge_inis: out of memory!\n"); - generic_panic(); + fatal_error("stratosphere_merge_inis: out of memory!\n"); } merged->magic = MAGIC_INI1; @@ -121,8 +117,7 @@ ini1_header_t *stratosphere_merge_inis(ini1_header_t **inis, size_t num_inis) { for (size_t p = 0; p < (size_t)inis[i]->num_processes; p++) { kip1_header_t *current_kip = (kip1_header_t *)(inis[i]->kip_data + offset); if (current_kip->magic != MAGIC_KIP1) { - printf("Error: INI1s[%zu][%zu] appears not to be a KIP1!\n", i, p); - generic_panic(); + fatal_error("INI1s[%zu][%zu] appears not to be a KIP1!\n", i, p); } bool already_loaded = false; @@ -144,11 +139,9 @@ ini1_header_t *stratosphere_merge_inis(ini1_header_t **inis, size_t num_inis) { if (read_size != 0) { kip1_header_t *sd_kip = (kip1_header_t *)(current_dst_kip); if (read_size < sizeof(kip1_header_t) || sd_kip->magic != MAGIC_KIP1) { - printf("Error: %s is not a KIP1?\n", sd_path); - generic_panic(); + fatal_error("%s is not a KIP1?\n", sd_path); } else if (sd_kip->title_id != current_kip->title_id) { - printf("Error: %s has wrong Title ID!\n", sd_path); - generic_panic(); + fatal_error("%s has wrong Title ID!\n", sd_path); } size_t expected_sd_kip_size = kip1_get_size_from_header(sd_kip); if (expected_sd_kip_size != read_size) { @@ -161,8 +154,7 @@ ini1_header_t *stratosphere_merge_inis(ini1_header_t **inis, size_t num_inis) { } else { size_t current_kip_size = kip1_get_size_from_header(current_kip); if (current_kip_size > remaining_size) { - printf("Error: Not enough space for all the KIP1s!\n"); - generic_panic(); + fatal_error("Not enough space for all the KIP1s!\n"); } memcpy(current_dst_kip, current_kip, current_kip_size); remaining_size -= current_kip_size; diff --git a/fusee/fusee-secondary/src/utils.c b/fusee/fusee-secondary/src/utils.c index d1420afa5..584c085bd 100644 --- a/fusee/fusee-secondary/src/utils.c +++ b/fusee/fusee-secondary/src/utils.c @@ -1,10 +1,12 @@ #include +#include #include "utils.h" #include "se.h" #include "fuse.h" #include "pmc.h" #include "timers.h" #include "hwinit/btn.h" +#include "panic.h" #include #include @@ -46,8 +48,19 @@ __attribute__((noreturn)) void wait_for_button_and_pmc_reboot(void) { } __attribute__ ((noreturn)) void generic_panic(void) { - while(true);//panic(0xFF000006); + panic(0xFF000006); } + +__attribute__((noreturn)) void fatal_error(const char *fmt, ...) { + va_list args; + printf("Fatal error: "); + va_start(args, fmt); + vprintf(fmt, args); + va_end(args); + printf("\n Press POWER to reboot into RCM, VOL+/VOL- to reboot normally.\n"); + wait_for_button_and_pmc_reboot(); +} + __attribute__((noinline)) bool overlaps(uint64_t as, uint64_t ae, uint64_t bs, uint64_t be) { if(as <= bs && bs <= ae) diff --git a/fusee/fusee-secondary/src/utils.h b/fusee/fusee-secondary/src/utils.h index 5708d23ab..d8b04c8c2 100644 --- a/fusee/fusee-secondary/src/utils.h +++ b/fusee/fusee-secondary/src/utils.h @@ -108,6 +108,9 @@ __attribute__((noreturn)) void watchdog_reboot(void); __attribute__((noreturn)) void pmc_reboot(uint32_t scratch0); __attribute__((noreturn)) void wait_for_button_and_pmc_reboot(void); -void generic_panic(void); +__attribute__((noreturn)) void generic_panic(void); + +__attribute__((noreturn)) void fatal_error(const char *fmt, ...); + #endif