From b58cbd228c11feb2a1314d958d99583b4ae690b5 Mon Sep 17 00:00:00 2001 From: Aurora Date: Sat, 15 Oct 2016 00:32:00 +0200 Subject: [PATCH] We don't really need two sets of blank spaces --- patches/reboot.s | 36 +++++++++++++++++++++--------------- source/firm.c | 8 +++----- source/firm.h | 4 ++-- source/main.c | 6 ++++-- source/patches.c | 4 ++-- source/patches.h | 2 +- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/patches/reboot.s b/patches/reboot.s index cae59e6..207215a 100644 --- a/patches/reboot.s +++ b/patches/reboot.s @@ -26,11 +26,10 @@ sd_notmounted equ 0xC8804465 ; Error code returned when SD is not mounted cmp r0, r2 bne pxi_wait_recv - adr r1, sd_fname - open_payload: ; Open file add r0, r7, #8 + adr r1, fname mov r2, #1 ldr r6, [fopen] orr r6, 1 @@ -40,7 +39,10 @@ sd_notmounted equ 0xC8804465 ; Error code returned when SD is not mounted ldr r2, =sd_notmounted cmp r0, r2 bne svcBreak - adr r1, nand_fname + adr r0, fname + adr r1, nand_mount + mov r2, #8 + bl memcpy16 b open_payload read_payload: @@ -54,14 +56,10 @@ sd_notmounted equ 0xC8804465 ; Error code returned when SD is not mounted blx r6 ; Copy the low TID (in UTF-16) of the wanted firm to the 5th byte of the payload - add r0, r8, 0x1A - add r1, r0, #0x10 - ldr r2, =payload_addr + 4 - copy_TID_low: - ldrh r3, [r0], #2 - strh r3, [r2], #2 - cmp r0, r1 - blo copy_TID_low + ldr r0, =payload_addr + 4 + add r1, r8, 0x1A + mov r2, #0x10 + bl memcpy16 ; Set kernel state mov r0, #0 @@ -79,6 +77,15 @@ sd_notmounted equ 0xC8804465 ; Error code returned when SD is not mounted die: b die + memcpy16: + add r2, r0, r2 + copy_loop: + ldrh r3, [r1], #2 + strh r3, [r0], #2 + cmp r0, r2 + blo copy_loop + bx lr + svcBreak: swi 0x3C b die @@ -86,11 +93,10 @@ sd_notmounted equ 0xC8804465 ; Error code returned when SD is not mounted bytes_read: .word 0 fopen: .ascii "OPEN" .pool -sd_fname: .dcw "sdmc:/arm9loaderhax.bin" - .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +fname: .dcw "sdmc:/arm9loaderhax.bin" + .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .pool -nand_fname: .dcw "nand:/arm9loaderhax.bin" - .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +nand_mount: .dcw "nand" .align 4 kernelcode_start: diff --git a/source/firm.c b/source/firm.c index 51f7cec..3aeeea6 100755 --- a/source/firm.c +++ b/source/firm.c @@ -36,7 +36,7 @@ static Firm *firm = (Firm *)0x24000000; -u32 loadFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage, bool isSdMode) +u32 loadFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage) { const char *firmwareFiles[] = { "firmware.bin", @@ -51,8 +51,6 @@ u32 loadFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStora "cetk_safe" }; - if(isSdMode && !mountFs(false, false)) error("Failed to mount CTRNAND."); - //Load FIRM from CTRNAND u32 firmVersion = firmRead(firm, (u32)*firmType); @@ -109,7 +107,7 @@ u32 loadFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStora return firmVersion; } -u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lhInstalled, bool isSdMode, u32 devMode) +u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lhInstalled, u32 devMode) { u8 *arm9Section = (u8 *)firm + firm->section[2].offset, *arm11Section1 = (u8 *)firm + firm->section[1].offset; @@ -148,7 +146,7 @@ u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, boo else if(isA9lhInstalled) ret += patchFirmWrites(process9Offset, process9Size); //Apply firmlaunch patches - ret += patchFirmlaunches(process9Offset, process9Size, process9MemAddr, isSdMode); + ret += patchFirmlaunches(process9Offset, process9Size, process9MemAddr); //11.0 FIRM patches if(firmVersion >= (ISN3DS ? 0x21 : 0x52)) diff --git a/source/firm.h b/source/firm.h index 97dd422..9970236 100644 --- a/source/firm.h +++ b/source/firm.h @@ -24,8 +24,8 @@ #include "types.h" -u32 loadFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage, bool isSdMode); -u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lhInstalled, bool isSdMode, u32 devMode); +u32 loadFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage); +u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lhInstalled, u32 devMode); u32 patchTwlFirm(u32 firmVersion, u32 devMode); u32 patchAgbFirm(u32 devMode); u32 patch1x2xNativeAndSafeFirm(u32 devMode); diff --git a/source/main.c b/source/main.c index 5739fc4..e97730c 100644 --- a/source/main.c +++ b/source/main.c @@ -225,8 +225,10 @@ void main(void) writeConfig(needConfig, configTemp); } + if(isSdMode && !mountFs(false, false)) error("Failed to mount CTRNAND."); + bool loadFromStorage = CONFIG(LOADEXTFIRMSANDMODULES); - u32 firmVersion = loadFirm(&firmType, firmSource, loadFromStorage, isSdMode); + u32 firmVersion = loadFirm(&firmType, firmSource, loadFromStorage); u32 devMode = MULTICONFIG(DEVOPTIONS); @@ -234,7 +236,7 @@ void main(void) switch(firmType) { case NATIVE_FIRM: - res = patchNativeFirm(firmVersion, nandType, emuHeader, isA9lhInstalled, isSdMode, devMode); + res = patchNativeFirm(firmVersion, nandType, emuHeader, isA9lhInstalled, devMode); break; case SAFE_FIRM: case NATIVE_FIRM1X2X: diff --git a/source/patches.c b/source/patches.c index 5b2a0ef..03b38e2 100644 --- a/source/patches.c +++ b/source/patches.c @@ -101,7 +101,7 @@ u32 patchSignatureChecks(u8 *pos, u32 size) return ret; } -u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr, bool isSdMode) +u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr) { //Look for firmlaunch code const u8 pattern[] = {0xE2, 0x20, 0x20, 0x90}; @@ -145,7 +145,7 @@ u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr, bool isSdMode) for(u32 i = 0; i < pathSize; i++) finalPath[i] = (u16)path[i]; - u8 *pos_path = memsearch(off, isSdMode ? u"sd" : u"na", reboot_bin_size, 4) + 0xA; + u8 *pos_path = memsearch(off, u"sd", reboot_bin_size, 4) + 0xA; memcpy(pos_path, finalPath, pathSize * 2); } } diff --git a/source/patches.h b/source/patches.h index 092da01..e762346 100644 --- a/source/patches.h +++ b/source/patches.h @@ -34,7 +34,7 @@ u8 *getProcess9Info(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr); u32 *getKernel11Info(u8 *pos, u32 size, u32 *baseK11VA, u8 **freeK11Space, u32 **arm11SvcHandler, u32 **arm11ExceptionsPage); u32 patchSignatureChecks(u8 *pos, u32 size); u32 patchTitleInstallMinVersionChecks(u8 *pos, u32 size, u32 firmVersion); -u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr, bool isSdMode); +u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr); u32 patchFirmWrites(u8 *pos, u32 size); u32 patchOldFirmWrites(u8 *pos, u32 size); u32 reimplementSvcBackdoor(u8 *pos, u32 *arm11SvcTable, u32 baseK11VA, u8 **freeK11Space);