1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-23 02:42:09 +00:00

Write more code for stratosphere_get_ini1, make it and its caller take target_firmware

This commit is contained in:
TuxSH 2018-05-15 16:09:06 +02:00
parent 4e1a368b43
commit 3c0436b98f
5 changed files with 22 additions and 13 deletions

View file

@ -164,7 +164,7 @@ void nxboot_main(void) {
printf("Error: Package2 from %s is too big!\n", loader_ctx->package2_path); printf("Error: Package2 from %s is too big!\n", loader_ctx->package2_path);
generic_panic(); generic_panic();
} }
if (read_from_file(package2, package2_size, loader_ctx->package2_path) != package2_size) { 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); printf("Error: Could not read Package2 from %s!\n", loader_ctx->package2_path);
generic_panic(); generic_panic();
@ -183,7 +183,7 @@ void nxboot_main(void) {
} }
/* Patch package2, adding Thermosphère + custom KIPs. */ /* 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.) */ /* Copy Exophère to a good location (or read it directly to it.) */
if (MAILBOX_EXOSPHERE_CONFIGURATION->target_firmware <= EXOSPHERE_TARGET_FIRMWARE_400) { 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); printf(u8"Error: Exosphère from %s is too big!\n", loader_ctx->exosphere_path);
generic_panic(); generic_panic();
} }
if (read_from_file(exosphere_memaddr, exosphere_size, loader_ctx->exosphere_path) != exosphere_size) { 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); printf(u8"Error: Could not read Exosphère from %s!\n", loader_ctx->exosphere_path);
generic_panic(); generic_panic();

View file

@ -10,13 +10,12 @@
static void package2_decrypt(package2_header_t *package2); static void package2_decrypt(package2_header_t *package2);
static size_t package2_get_thermosphere(void **thermosphere); static size_t package2_get_thermosphere(void **thermosphere);
static void package2_patch_kernel(void *kernel, size_t kernel_size); 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_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); static void package2_fixup_header_and_section_hashes(package2_header_t *package2, size_t size);
void package2_rebuild_and_copy(void *package2_address) { void package2_rebuild_and_copy(package2_header_t *package2, uint32_t target_firmware) {
uintptr_t pk2da = (uintptr_t)package2_address + sizeof(package2_header_t); uintptr_t pk2da = (uintptr_t)package2 + sizeof(package2_header_t);
package2_header_t *package2 = (package2_header_t *)package2_address;
package2_header_t *rebuilt_package2; package2_header_t *rebuilt_package2;
size_t rebuilt_package2_size; size_t rebuilt_package2_size;
void *kernel; void *kernel;
@ -42,7 +41,7 @@ void package2_rebuild_and_copy(void *package2_address) {
package2_patch_kernel(kernel, kernel_size); package2_patch_kernel(kernel, kernel_size);
/* Perform any patches to the INI1, rebuilding it (This is where our built-in sysmodules will be added.) */ /* 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. */ /* Allocate the rebuilt package2. */
rebuilt_package2_size = sizeof(package2_header_t); 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) { 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; (*thermosphere) = NULL;
return 0; 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? */ /* 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 *inis_to_merge[STRATOSPHERE_INI1_MAX] = {0};
ini1_header_t *merged; 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; inis_to_merge[STRATOSPHERE_INI1_PACKAGE2] = ini1;
/* Merge all of the INI1s. */ /* Merge all of the INI1s. */

View file

@ -53,6 +53,6 @@ typedef struct {
}; };
} package2_header_t; } 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 #endif

View file

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include "exocfg.h"
#include "utils.h" #include "utils.h"
#include "package2.h" #include "package2.h"
#include "stratosphere.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. */ /* 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 uint8_t *boot_kip = NULL;
const uint32_t boot_kip_size = 0; const uint32_t boot_kip_size = 0;
uint8_t *data; uint8_t *data;
@ -24,6 +25,12 @@ ini1_header_t *stratosphere_get_ini1(void) {
return g_stratosphere_ini1; 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; 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); g_stratosphere_ini1 = (ini1_header_t *)malloc(size);

View file

@ -8,7 +8,7 @@
#define STRATOSPHERE_INI1_PACKAGE2 0x1 #define STRATOSPHERE_INI1_PACKAGE2 0x1
#define STRATOSPHERE_INI1_MAX 0x2 #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); void stratosphere_free_ini1(void);
ini1_header_t *stratosphere_merge_inis(ini1_header_t **inis, unsigned int num_inis); ini1_header_t *stratosphere_merge_inis(ini1_header_t **inis, unsigned int num_inis);