#include "../common.h"
firm_h *firm_loc = (firm_h *)FCRAM_FIRM_LOC;
-static uint32_t firm_size = FCRAM_SPACING;
+uint32_t firm_size = FCRAM_SPACING;
firm_section_h firm_proc9;
exefs_h *firm_p9_exefs;
firm_h *twl_firm_loc = (firm_h *)FCRAM_TWL_FIRM_LOC;
-static uint32_t twl_firm_size = FCRAM_SPACING * 2;
+uint32_t twl_firm_size = FCRAM_SPACING * 2;
firm_section_h twl_firm_proc9;
exefs_h *twl_firm_p9_exefs;
firm_h *agb_firm_loc = (firm_h *)FCRAM_AGB_FIRM_LOC;
-static uint32_t agb_firm_size = FCRAM_SPACING;
+uint32_t agb_firm_size = FCRAM_SPACING * 2;
firm_section_h agb_firm_proc9;
exefs_h *agb_firm_p9_exefs;
};
extern firm_h *firm_loc;
+extern uint32_t firm_size;
extern struct firm_signature *current_firm;
extern firm_section_h firm_proc9;
extern exefs_h *firm_p9_exefs;
extern firm_h *twl_firm_loc;
+extern uint32_t twl_firm_size;
extern struct firm_signature *current_twl_firm;
extern firm_section_h twl_firm_proc9;
extern exefs_h *twl_firm_p9_exefs;
extern firm_h *agb_firm_loc;
+extern uint32_t agb_firm_size;
extern struct firm_signature *current_agb_firm;
extern firm_section_h agb_firm_proc9;
extern exefs_h *agb_firm_p9_exefs;
fclose(f);
// Look for the section that holds all the sysmodules
+ int section_index = 0;
firm_section_h *sysmodule_section = NULL;
for (firm_section_h *section = firm_loc->section; section < firm_loc->section + 4; section++) {
if (section->address == 0x1FF00000 && section->type == FIRM_TYPE_ARM11) {
sysmodule_section = section;
break;
}
+ section_index++;
}
if (!sysmodule_section) {
// Expand firmware module size if needed to accomodate replacement.
if (module->contentSize > sysmodule->contentSize) {
uint32_t need_units = (module->contentSize - sysmodule->contentSize);
- fprintf(stderr, "module: Would grow %d units but NYI\n", need_units);
- continue;
- // TODO - so in a nutshell, the reason Luma works is because it
- // relocates
- // the sysmodule section to its final location while fixing the
- // size.
- // Once stuff is at the right place, it no longer cares about
- // its' size.
+ memmove((uint8_t *)sysmodule + module->contentSize * 0x200,
+ (uint8_t *)sysmodule + sysmodule->contentSize * 0x200,
+ ((uint8_t *)firm_loc + firm_size) - ((uint8_t*)sysmodule + (module->contentSize * 0x200))
+ );
- // Cakes performs an in-place resize and leaves the copy for
- // later; essentially,
- // this means I need to scale EVERYTHING after the increase, and
- // adjust NCCH sections accordingly.
+ sysmodule_section->size += 0x200 * need_units;
+ for(int i=section_index+1; i < 4; i++) {
+ firm_loc->section[i].offset += 0x200 * need_units;
+ firm_loc->section[i].size += 0x200 * need_units;
+ }
- // It would be hella easier to just patch at the final location
- // in memory;
- // and this was actually mentioned on Luma's issues.
+ fprintf(stderr, "module: Grow %d units\n", need_units);
}
// Move the remaining modules closer
- if (module->contentSize < sysmodule->contentSize) {
+ else if (module->contentSize < sysmodule->contentSize) {
+ // NOTE - This doesn't change the sysmodule section size; it isn't needed to do so.
fprintf(stderr, "Module: Shrink %d units\n", sysmodule->contentSize - module->contentSize);
int remaining_size =
sysmodule_section->size - (((uint32_t)sysmodule + sysmodule->contentSize * 0x200) - ((uint32_t)firm_loc + sysmodule_section->offset));