From 3c0436b98fc3458e7a0359d0153809955bd63cfa Mon Sep 17 00:00:00 2001 From: TuxSH Date: Tue, 15 May 2018 16:09:06 +0200 Subject: [PATCH] Write more code for stratosphere_get_ini1, make it and its caller take target_firmware --- fusee/fusee-secondary/src/nxboot.c | 6 +++--- fusee/fusee-secondary/src/package2.c | 16 +++++++++------- fusee/fusee-secondary/src/package2.h | 2 +- fusee/fusee-secondary/src/stratosphere.c | 9 ++++++++- fusee/fusee-secondary/src/stratosphere.h | 2 +- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/fusee/fusee-secondary/src/nxboot.c b/fusee/fusee-secondary/src/nxboot.c index d56a3f99d..1deb04841 100644 --- a/fusee/fusee-secondary/src/nxboot.c +++ b/fusee/fusee-secondary/src/nxboot.c @@ -164,7 +164,7 @@ void nxboot_main(void) { printf("Error: Package2 from %s is too big!\n", loader_ctx->package2_path); generic_panic(); } - + if (read_from_file(package2, package2_size, loader_ctx->package2_path) != package2_size) { printf("Error: Could not read Package2 from %s!\n", loader_ctx->package2_path); generic_panic(); @@ -183,7 +183,7 @@ void nxboot_main(void) { } /* Patch package2, adding Thermosphère + custom KIPs. */ - package2_rebuild_and_copy(package2); + package2_rebuild_and_copy(package2, MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware); /* Copy Exophère to a good location (or read it directly to it.) */ if (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware <= EXOSPHERE_TARGET_FIRMWARE_400) { @@ -202,7 +202,7 @@ void nxboot_main(void) { printf(u8"Error: Exosphère from %s is too big!\n", loader_ctx->exosphere_path); generic_panic(); } - + 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(); diff --git a/fusee/fusee-secondary/src/package2.c b/fusee/fusee-secondary/src/package2.c index 523538967..fcaec754d 100644 --- a/fusee/fusee-secondary/src/package2.c +++ b/fusee/fusee-secondary/src/package2.c @@ -10,13 +10,12 @@ static void package2_decrypt(package2_header_t *package2); static size_t package2_get_thermosphere(void **thermosphere); static void package2_patch_kernel(void *kernel, size_t kernel_size); -static ini1_header_t *package2_rebuild_ini1(ini1_header_t *ini1); +static ini1_header_t *package2_rebuild_ini1(ini1_header_t *ini1, uint32_t target_firmware); static void package2_append_section(size_t id, package2_header_t *package2, void *data, size_t size); static void package2_fixup_header_and_section_hashes(package2_header_t *package2, size_t size); -void package2_rebuild_and_copy(void *package2_address) { - uintptr_t pk2da = (uintptr_t)package2_address + sizeof(package2_header_t); - package2_header_t *package2 = (package2_header_t *)package2_address; +void package2_rebuild_and_copy(package2_header_t *package2, uint32_t target_firmware) { + uintptr_t pk2da = (uintptr_t)package2 + sizeof(package2_header_t); package2_header_t *rebuilt_package2; size_t rebuilt_package2_size; void *kernel; @@ -42,7 +41,7 @@ void package2_rebuild_and_copy(void *package2_address) { package2_patch_kernel(kernel, kernel_size); /* Perform any patches to the INI1, rebuilding it (This is where our built-in sysmodules will be added.) */ - rebuilt_ini1 = package2_rebuild_ini1((ini1_header_t *)(pk2da + package2->metadata.section_offsets[PACKAGE2_SECTION_INI1])); + rebuilt_ini1 = package2_rebuild_ini1((ini1_header_t *)(pk2da + package2->metadata.section_offsets[PACKAGE2_SECTION_INI1]), target_firmware); /* Allocate the rebuilt package2. */ rebuilt_package2_size = sizeof(package2_header_t); @@ -234,6 +233,9 @@ static void package2_decrypt(package2_header_t *package2) { } static size_t package2_get_thermosphere(void **thermosphere) { + /*extern const uint8_t thermosphere_bin[]; + extern const uint32_t thermosphere_bin_size;*/ + /* TODO: enable when tested. */ (*thermosphere) = NULL; return 0; } @@ -245,12 +247,12 @@ static void package2_patch_kernel(void *kernel, size_t size) { } -static ini1_header_t *package2_rebuild_ini1(ini1_header_t *ini1) { +static ini1_header_t *package2_rebuild_ini1(ini1_header_t *ini1, uint32_t target_firmware) { /* TODO: Do we want to support loading another INI from sd:/whatever/INI1.bin? */ ini1_header_t *inis_to_merge[STRATOSPHERE_INI1_MAX] = {0}; ini1_header_t *merged; - inis_to_merge[STRATOSPHERE_INI1_EMBEDDED] = stratosphere_get_ini1(); + inis_to_merge[STRATOSPHERE_INI1_EMBEDDED] = stratosphere_get_ini1(target_firmware); inis_to_merge[STRATOSPHERE_INI1_PACKAGE2] = ini1; /* Merge all of the INI1s. */ diff --git a/fusee/fusee-secondary/src/package2.h b/fusee/fusee-secondary/src/package2.h index e16d64a4a..e62bd478d 100644 --- a/fusee/fusee-secondary/src/package2.h +++ b/fusee/fusee-secondary/src/package2.h @@ -53,6 +53,6 @@ typedef struct { }; } package2_header_t; -void package2_rebuild_and_copy(void *package2_address); +void package2_rebuild_and_copy(package2_header_t *package2, uint32_t target_firmware); #endif diff --git a/fusee/fusee-secondary/src/stratosphere.c b/fusee/fusee-secondary/src/stratosphere.c index 5b7318c56..22c25b5ea 100644 --- a/fusee/fusee-secondary/src/stratosphere.c +++ b/fusee/fusee-secondary/src/stratosphere.c @@ -1,6 +1,7 @@ #include #include #include +#include "exocfg.h" #include "utils.h" #include "package2.h" #include "stratosphere.h" @@ -15,7 +16,7 @@ extern const uint32_t loader_kip_size, pm_kip_size, sm_kip_size; /* GCC doesn't consider the size as const... we have to write it ourselves. */ -ini1_header_t *stratosphere_get_ini1(void) { +ini1_header_t *stratosphere_get_ini1(uint32_t target_firmware) { //const uint8_t *boot_kip = NULL; const uint32_t boot_kip_size = 0; uint8_t *data; @@ -24,6 +25,12 @@ ini1_header_t *stratosphere_get_ini1(void) { return g_stratosphere_ini1; } + if (target_firmware <= EXOSPHERE_TARGET_FIRMWARE_100) { + /* TODO. */ + } else { + /* TODO. */ + } + size_t size = sizeof(ini1_header_t) + loader_kip_size + pm_kip_size + sm_kip_size + boot_kip_size; g_stratosphere_ini1 = (ini1_header_t *)malloc(size); diff --git a/fusee/fusee-secondary/src/stratosphere.h b/fusee/fusee-secondary/src/stratosphere.h index 399b699ec..2c72fab85 100644 --- a/fusee/fusee-secondary/src/stratosphere.h +++ b/fusee/fusee-secondary/src/stratosphere.h @@ -8,7 +8,7 @@ #define STRATOSPHERE_INI1_PACKAGE2 0x1 #define STRATOSPHERE_INI1_MAX 0x2 -ini1_header_t *stratosphere_get_ini1(void); +ini1_header_t *stratosphere_get_ini1(uint32_t target_firmware); void stratosphere_free_ini1(void); ini1_header_t *stratosphere_merge_inis(ini1_header_t **inis, unsigned int num_inis);