Skip to content

Commit

Permalink
Merge pull request #444 from 173210/firm
Browse files Browse the repository at this point in the history
Update firm launching code
  • Loading branch information
AlbertoSONIC committed Feb 27, 2016
2 parents 3cd3763 + a0e56f3 commit b287897
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 67 deletions.
2 changes: 2 additions & 0 deletions rxmode/native_firm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ ifdef PLATFORM_KTR
LDSCRIPT_ROM := ktr_rom.ld
LDSCRIPT_RAM := ktr_ram.ld
CFLAGS += -DPLATFORM_KTR

OBJS += $(BUILD)/k11_entry.o
else
LDSCRIPT_ROM := ctr_rom.ld
LDSCRIPT_RAM := ctr_ram.ld
Expand Down
3 changes: 3 additions & 0 deletions rxmode/native_firm/ktr.ld
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ SECTIONS

. = 0x1ff824d4;
.patch.k11.codeset.addr : { *(.patch.k11.codeset.addr) }

. = 0x1ffae070;
.patch.k11.entry : { *(.patch.k11.entry) }
}
29 changes: 29 additions & 0 deletions rxmode/native_firm/source/k11_entry.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (C) 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
* 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.
*/

@ This patch fixes 3D adjustment on KTR

.section .patch.k11.entry, "a"

ldr r1, =0x10202000
str r0, [r1, #0x00C]
str r0, [r1, #0x014]
str r0, [r1, #0x244]
str r0, [r1, #0xA44]
b pooled
.pool
pooled:
3 changes: 1 addition & 2 deletions rxtools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
40 changes: 34 additions & 6 deletions rxtools/source/features/firm.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -165,14 +163,16 @@ static void setAgbBios()

int rxMode(int emu)
{
const Elf32_Addr line = 32;
wchar_t path[64];
const char *shstrtab;
const wchar_t *msg;
uint8_t keyx[16];
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;
Expand Down Expand Up @@ -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();
}
}
Expand Down
59 changes: 0 additions & 59 deletions rxtools/source/features/reboot.S

This file was deleted.

0 comments on commit b287897

Please sign in to comment.