]> Chaos Git - corbenik/corbenik.git/commitdiff
Looks like it was some kind of issue with globals or order of application or somethin...
authorchaoskagami <chaos.kagami@gmail.com>
Mon, 13 Jun 2016 19:35:03 +0000 (15:35 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Mon, 13 Jun 2016 19:35:03 +0000 (15:35 -0400)
Makefile
host/copy.sh
source/patch/emunand.c
source/patch/module.c
source/patcher.c

index f36b9f4240cc17c69c8a63f8f943e35d960dc363..03791aaed9c81ba317d6234340cacb8958edf371 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,7 @@ dir_out    := out
 REVISION := r$(shell git rev-list --count HEAD):$(shell git rev-parse HEAD | head -c8)
 
 ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te
-CFLAGS  := -MMD -MP -Wall -Wextra -Werror -fomit-frame-pointer -Os $(ASFLAGS) -fshort-wchar -fno-builtin -std=c11 -DVERSION=\"$(REVISION)\"
+CFLAGS  := -MMD -MP -Wall -Wextra -Werror -fomit-frame-pointer -Os $(ASFLAGS) -fshort-wchar -fno-builtin -std=gnu11 -DVERSION=\"$(REVISION)\"
 FLAGS   := dir_out=$(abspath $(dir_out)) --no-print-directory
 LDFLAGS := -nostdlib -Wl,-z,defs -lgcc -Wl,-Map,$(dir_build)/link.map
 
index 6837bb45bb3d13d53a0477b3617f76fcb4dfe896..2bae3bae7835fe81bb52de3fd7e5a8938e7d820d 100755 (executable)
@@ -9,9 +9,7 @@ dev=/dev/sdb
 mnt=/mnt/ext1
 
 mount ${dev}1 $mnt || exit 0
-cp out/arm9loaderhax.bin $mnt/anim/boot/none.bin || exit 0
-cp out/arm9loaderhax.bin $mnt/anim/boot/r.bin || exit 0
-cp out/arm9loaderhax.bin $mnt/anim/boot/l.bin || exit 0
+cp out/arm9loaderhax.bin $mnt/arm9loaderhax.bin || exit 0
 rm -rf $mnt/corbenik
 cp -r out/corbenik $mnt/ || exit 0
 cp -r input/corbenik $mnt/ || exit 0
index 0f3186a06094a5de0c358acef8fb2a77c19c1bd9..7cc3aba0e2d067977da5e803a3e00aa8340ee69b 100644 (file)
@@ -13,7 +13,7 @@
 #include "../firm/headers.h"
 #include "../patch_format.h"
 
-uint8_t *temp = (uint8_t *)FCRAM_JUNK_LOC;
+uint8_t *emunand_temp = (uint8_t *)FCRAM_JUNK_LOC;
 
 void
 verify_loop_emunand(char *filename)
@@ -24,7 +24,7 @@ verify_loop_emunand(char *filename)
     uint32_t offset = get_file_sector(filename); // Get the sector of the file
 
     // Check for RedNAND image on SD
-    if (!sdmmc_sdcard_readsectors(offset, 1, temp) && *(uint32_t *)(temp + 0x100) == NCSD_MAGIC) {
+    if (!sdmmc_sdcard_readsectors(offset, 1, emunand_temp) && *(uint32_t *)(emunand_temp + 0x100) == NCSD_MAGIC) {
         fprintf(stderr, "emunand: found NCSD magic\n");
     } else {
         abort("emunand: selected NAND image is not valid.\n");
@@ -43,7 +43,7 @@ verify_emunand(uint32_t index, uint32_t *off, uint32_t *head)
         offset = 0x200000 * index;
 
     // Check for RedNAND/Normal physical layout on SD
-    if (!sdmmc_sdcard_readsectors(offset + 1, 1, temp) && *(uint32_t *)(temp + 0x100) == NCSD_MAGIC) {
+    if (!sdmmc_sdcard_readsectors(offset + 1, 1, emunand_temp) && *(uint32_t *)(emunand_temp + 0x100) == NCSD_MAGIC) {
         *off = offset + 1;
         *head = offset + 1;
 
@@ -51,7 +51,7 @@ verify_emunand(uint32_t index, uint32_t *off, uint32_t *head)
         fprintf(stderr, "emunand: layout is normal\n");
     }
     // Check for GW EmuNAND on SD
-    else if (!sdmmc_sdcard_readsectors(offset + nandSize, 1, temp) && *(uint32_t *)(temp + 0x100) == NCSD_MAGIC) {
+    else if (!sdmmc_sdcard_readsectors(offset + nandSize, 1, emunand_temp) && *(uint32_t *)(emunand_temp + 0x100) == NCSD_MAGIC) {
         *off = offset;
         *head = offset + nandSize;
 
@@ -68,7 +68,7 @@ getEmuCode(uint8_t *pos, uint32_t size)
     const uint8_t pattern[] = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 };
 
     // Looking for the last free space before Process9
-    void *ret = memfind(pos + 0x13500, size - 0x13500, pattern, 6) + 0x455;
+    uint8_t *ret = memfind(pos + 0x13500, size - 0x13500, pattern, 6) + 0x455;
 
     if (ret) {
         fprintf(stderr, "emunand: free space @ %x\n", ret);
@@ -101,13 +101,16 @@ patchNANDRW(uint8_t *pos, uint32_t size, uint32_t branchOffset)
     const uint8_t pattern[] = { 0x1E, 0x00, 0xC8, 0x05 };
 
     uint16_t *readOffset = (uint16_t *)memfind(pos, size, pattern, 4) - 3;
-    uint16_t *writeOffset = (uint16_t *)memfind((uint8_t *)(readOffset + 5), 0x100, pattern, 4) - 3;
+    uint16_t *writeOffset = (uint16_t *)memfind((uint8_t*)(readOffset + 5), 0x100, pattern, 4) - 3;
 
-    *readOffset = nandRedir[0];
+    if (!readOffset || !writeOffset)
+        abort("emunand: pattern for r/w missing!\n");
+
+    readOffset[0] = nandRedir[0];
     readOffset[1] = nandRedir[1];
     ((uint32_t *)readOffset)[1] = branchOffset;
 
-    *writeOffset = nandRedir[0];
+    writeOffset[0] = nandRedir[0];
     writeOffset[1] = nandRedir[1];
     ((uint32_t *)writeOffset)[1] = branchOffset;
 
@@ -135,9 +138,6 @@ patchMPU(uint8_t *pos, uint32_t size)
 void
 patch_emunand(uint32_t index)
 {
-    // uint8_t *arm9Section, uint32_t arm9SectionSize, uint8_t *process9Offset, uint32_t process9Size, uint32_t emuOffset, uint32_t emuHeader, uint32_t
-    // branchAdditive)
-
     // ARM9 section.
     uint8_t *arm9Section = (uint8_t *)firm_loc + firm_loc->section[2].offset;
     uint32_t arm9SectionSize = firm_loc->section[2].size;
@@ -158,22 +158,23 @@ patch_emunand(uint32_t index)
     fread(emuCodeOffset, 1, emunand_size, f);
     fclose(f);
 
-    uint32_t branchOffset = (uint32_t)emuCodeOffset - ((uint32_t)firm_loc + firm_loc->section[2].offset - firm_loc->section[2].address);
+    uint32_t branchOffset = (uintptr_t)emuCodeOffset - ((uintptr_t)firm_loc + firm_loc->section[2].offset - firm_loc->section[2].address);
 
-    fprintf(stderr, "emunand: read in emunand code - %x\n", emuCodeOffset);
+    fprintf(stderr, "emunand: read in emunand code\n");
 
     // Add the data of the found emuNAND
-    uint32_t *pos_offset = (uint32_t *)memfind(emuCodeOffset, emunand_size, "NAND", 4), *pos_head = (uint32_t *)memfind(emuCodeOffset, emunand_size, "NCSD", 4),
-             *pos_sdmmc = (uint32_t *)memfind(emuCodeOffset, emunand_size, "SDMC", 4);
+    uint32_t *pos_offset = (uint32_t *)memfind(emuCodeOffset, emunand_size, "NAND", 4),
+             *pos_head   = (uint32_t *)memfind(emuCodeOffset, emunand_size, "NCSD", 4),
+             *pos_sdmmc  = (uint32_t *)memfind(emuCodeOffset, emunand_size, "SDMC", 4);
+
+    if (!pos_offset || !pos_head || !pos_sdmmc)
+        abort("emunand: couldn't find pattern in hook?\n");
 
     verify_emunand(index, pos_offset, pos_head);
 
     fprintf(stderr, "emunand: nand is on sector %u\n", *pos_offset);
     fprintf(stderr, "emunand: head is on sector %u\n", *pos_head);
 
-    if (!pos_offset || !pos_head || !pos_sdmmc)
-        abort("emunand: couldn't find pattern in hook?\n");
-
     // Add emuNAND hooks
     patchNANDRW(process9Offset, process9Size, branchOffset);
 
index 61ede7c4fd682282559aee31188f76eebf7b0199..17b4485cf25eafbaa20836796b199dc889d82080 100644 (file)
@@ -11,8 +11,8 @@ PATCH(modules)
         return 2;
     }
 
-    uint32_t size = fsize(f);
-    fread((uint8_t *)FCRAM_JUNK_LOC, 1, size, f);
+    size_t size = fsize(f);
+    fread((void *)FCRAM_JUNK_LOC, 1, size, f);
     fclose(f);
 
     // Look for the section that holds all the sysmodules
index 066cc10ce0849e65d0e777605c06d8204d03d5c4..698c36bc0554bfcfea93b5602f0f34efb15ead4f 100644 (file)
@@ -61,15 +61,6 @@ patch_firm_all()
 {
     execb(PATH_LOADER_CACHE "/BOOT", 0);
 
-    // Replace loader?
-    if (config.options[OPTION_LOADER]) {
-        if (patch_modules()) {
-            abort("Fatal. Loader inject has failed.");
-        }
-        // This requires OPTION_SIGPATCH.
-        wait();
-    }
-
     // Hook firmlaunch?
     if (config.options[OPTION_REBOOT]) {
         patch_reboot();
@@ -77,6 +68,14 @@ patch_firm_all()
         wait();
     }
 
+    // Use EmuNAND?
+    if (config.options[OPTION_EMUNAND]) {
+        // Yes.
+        patch_emunand(config.options[OPTION_EMUNAND_INDEX]);
+
+        wait();
+    }
+
     // Inject services?
     if (config.options[OPTION_SVCS]) {
         if (patch_services()) {
@@ -85,19 +84,20 @@ patch_firm_all()
         wait();
     }
 
-    // Use ARM9 hook thread?
-    if (config.options[OPTION_ARM9THREAD]) {
-        // Yes.
-
-        // FIXME - NYI
+    // Replace loader?
+    if (config.options[OPTION_LOADER]) {
+        if (patch_modules()) {
+            abort("Fatal. Loader inject has failed.");
+        }
+        // This requires OPTION_SIGPATCH.
         wait();
     }
 
-    // Use EmuNAND?
-    if (config.options[OPTION_EMUNAND]) {
+    // Use ARM9 hook thread?
+    if (config.options[OPTION_ARM9THREAD]) {
         // Yes.
-        patch_emunand(config.options[OPTION_EMUNAND_INDEX]);
 
+        // FIXME - NYI
         wait();
     }