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

@ -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) {

View file

@ -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. */

View file

@ -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

View file

@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#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);

View file

@ -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);