diff --git a/rxtools/Makefile b/rxtools/Makefile index 58bfca06..ee00e0e1 100644 --- a/rxtools/Makefile +++ b/rxtools/Makefile @@ -48,8 +48,7 @@ CCOBJS := $(addprefix $(BUILD)/,main.o features/CTRDecryptor.o \ lib/media/nand.o lib/media/tmio/tmio.o \ lib/polarssl/padlock.o lib/polarssl/sha2.o lib/polarssl/aes.o \ lib/ui/console.o lib/ui/draw.o lib/cfg.o lib/crypto.o lib/fs.o lib/hid.o \ - lib/lang.o lib/log.o lib/i2c.o lib/jsmn/jsmn.o lib/menu.o lib/ncch.o \ - features/reboot.o) + lib/lang.o lib/log.o lib/i2c.o lib/jsmn/jsmn.o lib/menu.o lib/ncch.o) OBJS := $(CCOBJS) $(addprefix $(BUILD)/, start.o font_ascii.o lib/delay.o) DEPS := $(subst $(BUILD)/,$(DEPS_DIR)/,$(CCOBJS)) diff --git a/rxtools/source/features/firm.c b/rxtools/source/features/firm.c index b9e2379b..101dbda5 100644 --- a/rxtools/source/features/firm.c +++ b/rxtools/source/features/firm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The PASTA Team + * Copyright (C) 2015-2016 The PASTA Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -44,8 +44,6 @@ const wchar_t firmPatchPathFmt[] = _T("") FIRM_PATCH_PATH_FMT; unsigned int emuNandMounted = 0; _Noreturn void (* const _softreset)() = (void *)0x080F0000; -_Noreturn void execReboot(uint32_t, void *, uintptr_t, const Elf32_Shdr *); - static FRESULT loadExecReboot() { FIL fd; @@ -165,6 +163,7 @@ static void setAgbBios() int rxMode(int emu) { + const Elf32_Addr line = 32; wchar_t path[64]; const char *shstrtab; const wchar_t *msg; @@ -172,7 +171,8 @@ int rxMode(int emu) uint32_t tid; int r, sector; Elf32_Ehdr *ehdr; - Elf32_Shdr *shdr, *btm; + Elf32_Shdr *shdr, *btmShdr; + Elf32_Addr cur, btm; void *keyxArg; FIL fd; UINT br, fsz; @@ -245,9 +245,37 @@ int rxMode(int emu) ehdr = (void *)PATCH_ADDR; shdr = (void *)(PATCH_ADDR + ehdr->e_shoff); shstrtab = (char *)PATCH_ADDR + shdr[ehdr->e_shstrndx].sh_offset; - for (btm = shdr + ehdr->e_shnum; shdr != btm; shdr++) { + for (btmShdr = shdr + ehdr->e_shnum; shdr != btmShdr; shdr++) { if (!strcmp(shstrtab + shdr->sh_name, ".patch.p9.reboot.body")) { - execReboot(sector, keyxArg, ehdr->e_entry, shdr); + /* Set MPU area 2. + address: 0x0800000, size: 2^0x28 = 2M, enable */ + __asm__ volatile ("mcr p15, 0, %0, c6, c2, 0" + :: "r"(0x08000029)); + + memcpy((void *)ehdr->e_entry, + (void *)(PATCH_ADDR + shdr->sh_offset), + shdr->sh_size); + + // Drain write buffer + __asm__ volatile ("mcr p15, 0, %0, c7, c10, 4" :: "r"(0)); + + cur = ehdr->e_entry & ~(line - 1); + btm = ehdr->e_entry + shdr->sh_size; + while (cur < btm) { + __asm__ volatile ( + // Clean Dcache + "mcr p15, 0, %0, c7, c10, 1\n\t" + + // Flush Icache + "mcr p15, 0, %0, c7, c5, 1" + :: "r"(cur)); + + cur += line; + } + + ((void (*)(uint32_t, void *, uintptr_t))ehdr->e_entry)( + sector, keyxArg, 0x1FFFFFF8); + __builtin_unreachable(); } } diff --git a/rxtools/source/features/reboot.S b/rxtools/source/features/reboot.S deleted file mode 100644 index dcd9f9cc..00000000 --- a/rxtools/source/features/reboot.S +++ /dev/null @@ -1,59 +0,0 @@ -@ Copyright (C) 2015 The PASTA Team -@ -@ This program is free software; you can redistribute it and/or -@ modify it under the terms of the GNU General Public License -@ version 2 as published by the Free Software Foundation -@ -@ This program is distributed in the hope that it will be useful, -@ but WITHOUT ANY WARRANTY; without even the implied warranty of -@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -@ GNU General Public License for more details. -@ -@ You should have received a copy of the GNU General Public License -@ along with this program; if not, write to the Free Software -@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -#define ASM -#include - -line = 32 - - .arm - .global execReboot - .type execReboot, %function -execReboot: - mov r4, #0x08000000 @ Address - orr r4, #0x29 @ Size: 2^0x28 = 2M, Enable - mcr p15, 0, r4, c6, c2, 0 @ Set MPU area 2 - - ldr r4, [r3, #20] - add r5, r2, r4 - - ldr r3, [r3, #16] - add r3, #PATCH_ADDR & 0xFFF00000 - add r3, #PATCH_ADDR & 0x000FFFFF -loop: - ldr r6, [r3], #4 - str r6, [r2], #4 - tst r2, #line - 1 - bleq flushInLoop - cmp r2, r5 - blo loop - - tst r2, #line - 1 - bicne r6, r2, #line - 1 - blne flush - - mov r2, #0x1FFFFFF8 - mov r3, #0 - mcr p15, 0, r3, c7, c10, 4 @ Drain write buffer - sub pc, r5, r4 - -flushInLoop: - sub r6, r2, #line -flush: - mcr p15, 0, r6, c7, c10, 1 @ Clean Dcache - mcr p15, 0, r6, c7, c5, 1 @ Flush Icache - bx lr - - .size execReboot, . - execReboot