Introduce fatal_error
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user