Skip to content

Commit

Permalink
rxtools: Add init
Browse files Browse the repository at this point in the history
init is an alternative for bigpayload in CakeHax and
can be an entry point for delebile's arm9loaderhax.

# Conflicts:
#	rxtools/Makefile
#	rxtools/source/tool/MainMenu.h
#	rxtools/source/tool/cstart.c
#	rxtools/source/tool/features/AdvancedFileManager.c
#	rxtools/source/tool/features/CTRDecryptor.c
#	rxtools/source/tool/features/NandDumper.c
#	rxtools/source/tool/features/TitleKeyDecrypt.c
#	rxtools/source/tool/features/downgradeapp.c
#	rxtools/source/tool/features/fileexplorer.c
#	rxtools/source/tool/features/nandtools.c
#	rxtools/source/tool/features/padgen.c
#	rxtools/source/tool/lib/jsmn
#	rxtools/source/tool/lib/menu.c
  • Loading branch information
173210 committed Feb 29, 2016
1 parent a762bc1 commit 10512d0
Show file tree
Hide file tree
Showing 38 changed files with 232 additions and 136 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
[submodule "CakeBrah"]
path = CakeBrah
url = https://github.com/mid-kid/CakeBrah.git
[submodule "rxtools/source/lib/jsmn"]
path = rxtools/source/lib/jsmn
[submodule "rxtools/source/tool/lib/jsmn"]
path = rxtools/source/tool/lib/jsmn
url = https://github.com/zserge/jsmn
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ release: release-licenses release-rxtools release-doc release-lang \
release-licenses:
@mkdir -p release
@cp LICENSE release
@cp rxtools/source/lib/jsmn/LICENSE release/LICENSE_JSMN
@cp rxtools/source/tool/lib/jsmn/LICENSE release/LICENSE_JSMN
@cp rxtools/CakeHax/LICENSE.txt release/LICENSE_CakeHax.txt
@cp CakesROP/LICENSE release/LICENSE_CakesROP

release-rxtools: all-target-rxtools
@mkdir -p release/$(SYS_PATH)
@cp rxtools/build/bin/tool.bin release/$(SYS_PATH)
@cp rxtools/build/code.bin release/$(SYS_PATH)
@cp rxtools/build/font.bin release/$(SYS_PATH)

Expand Down
44 changes: 27 additions & 17 deletions rxtools/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 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 All @@ -21,7 +21,7 @@ BUILD := build
DEPS_DIR := $(BUILD)/.deps
SOURCE := source

all: $(BUILD)/code.bin
all: $(BUILD)/code.bin $(BUILD)/bin/tool.bin

include $(RXTOOLSMK)

Expand All @@ -36,35 +36,45 @@ CMACHINE := -mtune=arm946e-s
CWARNING := -Wall -Wno-multichar
CFLAGS := -g -O2 -std=c99 $(CWARNING) $(CFORCE) $(CMACHINE) $(CPPFLAGS) -DVERSION=\"$(GIT_VERSION)\"

# Use Thumb libraries because sbrk of ARM newlib in devkitPro doesn't work.
LDFLAGS := -nostartfiles -g $(CMACHINE) -mthumb -mthumb-interwork -Wl,-Tstub.ld
LDFLAGS := -nostartfiles -g $(CMACHINE)

INIT_CCOBJS := $(addprefix $(BUILD)/init/,cstart.o \
lib/crypto.o lib/draw.o lib/fs.o \
lib/fatfs/diskio.o lib/fatfs/ff.o lib/fatfs/option/unicode.o \
lib/media/nand.o lib/media/tmio/tmio.o)

INIT_OBJS := $(INIT_CCOBJS) \
$(BUILD)/init/lib/delay.o $(BUILD)/init/start.o $(BUILD)/font_ascii.o

CCOBJS := $(addprefix $(BUILD)/,main.o features/decryption.o \
TOOL_CCOBJS := $(addprefix $(BUILD)/tool/,cstart.o features/decryption.o \
features/install.o features/firm.o features/screenshot.o \
lib/fatfs/diskio.o lib/fatfs/ff.o lib/fatfs/option/unicode.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/ncch.o)
lib/jsmn/jsmn.o lib/cfg.o lib/console.o lib/hid.o \
lib/lang.o lib/log.o lib/i2c.o lib/ncch.o)

OBJS := $(CCOBJS) $(addprefix $(BUILD)/, start.o font_ascii.o lib/delay.o)
DEPS := $(subst $(BUILD)/,$(DEPS_DIR)/,$(CCOBJS))
TOOL_OBJS := $(TOOL_CCOBJS)

$(call DEPDIR,$(BUILD)/rxtools.elf $(BUILD)/font.bin $(OBJS) $(DEPS))
DEPS := $(subst $(BUILD)/,$(DEPS_DIR)/,$(TOOL_CCOBJS) $(INIT_CCOBJS))

$(call DEPDIR,$(BUILD)/bin/init.elf $(BUILD)/bin/tool.elf $(BUILD)/font.bin $(INIT_OBJS) $(TOOL_OBJS) $(DEPS))

MAKEDEP = @$(COMPILE.c) -MM $< > $(patsubst $(BUILD)/%.o,$(DEPS_DIR)/%.d,$@)

.PHONY: $(BUILD)/code.bin all clean

$(BUILD)/code.bin: $(BUILD)/rxtools.bin $(BUILD)/CakeHax/D
$(call Q,MAKE,CakeHax)$(MAKE) dir_out=../$(dir $@) dir_build=../$(BUILD)/CakeHax name=$(notdir $@) filepath=$(SYS_PATH)/ -C CakeHax bigpayload
$(call Q,DD,$@)dd if=$< bs=896k conv=sync,notrunc | dd of=$@ seek=160 conv=notrunc
$(BUILD)/code.bin: $(BUILD)/bin/init.bin $(BUILD)/CakeHax/D
$(call Q,MAKE,CakeHax)$(MAKE) dir_out=../$(dir $@) dir_build=../$(BUILD)/CakeHax name=$(notdir $@) filepath=$(SYS_PATH)/ -C CakeHax
dd if=$< of=$@ bs=512 seek=144

%.bin: %.elf
$(call Q,OBJCOPY,$@)$(OBJCOPY) -O binary $< $@

$(BUILD)/rxtools.elf: $(OBJS)
$(call Q,LINK,$@)$(LINK.o) $^ $(OUTPUT_OPTION)
$(BUILD)/bin/init.elf: $(INIT_OBJS)
$(call Q,LINK,$@)$(LINK.o) -Tinit.ld $^ $(OUTPUT_OPTION)

# Use Thumb libraries because sbrk of ARM newlib in devkitPro doesn't work.
$(BUILD)/bin/tool.elf: $(BUILD)/bin/init.elf $(TOOL_OBJS)
$(call Q,LINK,$@)$(LINK.o) -mthumb -mthumb-interwork -Wl,-Ttool.ld,-R$< $(TOOL_OBJS) $(OUTPUT_OPTION)

$(BUILD)/%.o: $(SOURCE)/%.c
$(call Q,CC,$@)$(COMPILE.c) $< $(OUTPUT_OPTION)
Expand Down
35 changes: 35 additions & 0 deletions rxtools/init.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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
* 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.
*/

OUTPUT_FORMAT("elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(initStart)

SECTIONS
{
. = 0x23F00000;
.text :
{
KEEP(*(.text.start))
KEEP(*(.text.cstart))
*(.text*)
}

.rodata : { *(.rodata*) }
.data : { *(.data*) }
.bss : { *(.bss*) }
}
15 changes: 7 additions & 8 deletions rxtools/source/include/lib/ui/draw.h
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 @@ -31,9 +31,9 @@
#define FONT_HEIGHT 16
#define FONT_HWIDTH (FONT_WIDTH>>1)
#define FONT_CJK_START 0x2400
#define TOP_SCREEN (uint8_t*)(*(uint32_t*)0x080FFFC0)
#define TOP_SCREEN2 (uint8_t*)(*(uint32_t*)0x080FFFC8)
#define BOT_SCREEN (uint8_t*)(*(uint32_t*)0x080FFFD0)
#define TOP_SCREEN (*(uint8_t **)0x23FFFE00)
#define TOP_SCREEN2 (*(uint8_t **)0x23FFFE04)
#define BOT_SCREEN (*(uint8_t **)0x23FFFE08)

//Colors Macros
#define ARGB(a,r,g,b) (a<<24|r<<16|g<<8|b) //console asks for B,G,R in bytes
Expand Down Expand Up @@ -66,11 +66,10 @@ void DrawCharacter(uint8_t *screen, wchar_t character, uint32_t x, uint32_t y, u
void DrawString(uint8_t *screen, const wchar_t *str, uint32_t x, uint32_t y, uint32_t color, uint32_t bgcolor);
void DrawPixel(uint8_t *screen, uint32_t x, uint32_t y, uint32_t color);
uint32_t GetPixel(uint8_t *screen, uint32_t x, uint32_t y);
void Debug(const char *format, ...);

void DrawSplash(uint8_t *screen, TCHAR splash_file[]);
void DrawBottomSplash(TCHAR splash_file[]);
void DrawTopSplash(TCHAR splash_file[], TCHAR splash_fileL[], TCHAR splash_fileR[]);
int DrawSplash(uint8_t *screen, TCHAR splash_file[]);
int DrawBottomSplash(TCHAR splash_file[]);
int DrawTopSplash(TCHAR splash_file[], TCHAR splash_fileL[], TCHAR splash_fileR[]);
void SplashScreen();
void DrawFadeScreen(uint8_t *screen, uint16_t Width, uint16_t Height, uint32_t f);
void fadeOut();
Expand Down
64 changes: 64 additions & 0 deletions rxtools/source/init/cstart.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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
* 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.
*/

#include <stddef.h>
#include <stdint.h>
#include <lib/fatfs/ff.h>
#include <lib/ui/draw.h>
#include <lib/fs.h>

__attribute__((section(".text.cstart"), noreturn)) void initStart()
{
const uintptr_t p = 0x23E00000;
const wchar_t *msg;
UINT br;
int r;
FIL f;

// Enable TMIO IRQ
*(volatile uint32_t *)0x10001000 = 0x00010000;

// Unknown register to fix mounting of SDMC
*(volatile uint32_t *)0x10000020 = 0x340;

if (!FSInit()) {
msg = L"Failed to initialize FS";
goto fatal;
}

r = f_open(&f, L"" SYS_PATH "/tool.bin", FA_READ);
if (r != FR_OK) {
msg = L"Failed to open tool";
goto fatal;
}

r = f_read(&f, (void *)p, 0x100000, &br);
if (r != FR_OK) {
msg = L"Failed to read tool";
goto fatal;
}

f_close(&f);

((void (*)())p)();
__builtin_unreachable();

fatal:
DrawString(BOT_SCREEN, msg,
BOT_SCREEN_WIDTH / 2, SCREEN_HEIGHT - FONT_HEIGHT, RED, BLACK);
while (1);
}
File renamed without changes.
File renamed without changes.
54 changes: 18 additions & 36 deletions rxtools/source/lib/ui/draw.c → rxtools/source/init/lib/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,6 @@ void DrawHexWithName(uint8_t *screen, const wchar_t *str, uint32_t hex, uint32_t
DrawHex(screen, hex, x + wcslen(str) * FONT_HWIDTH, y, color, bgcolor);
}

void Debug(const char *format, ...)
{
char *str;
va_list va;

va_start(va, format);
vasprintf(&str, format, va);
va_end(va);
wchar_t wstr[strlen(str)+1];
mbstowcs(wstr, str, strlen(str)+1);
free(str);
DrawString(TOP_SCREEN, wstr, 10, current_y, RGB(255, 255, 255), RGB(0, 0, 0));

current_y += 10;
}
//No need to enter and exit again and again, isn't it
inline void writeByte(uint8_t *address, uint8_t value) {
*(address) = value;
Expand Down Expand Up @@ -182,7 +167,7 @@ uint32_t GetPixel(uint8_t *screen, uint32_t x, uint32_t y){

//----------------New Splash Screen Stuff------------------

void DrawTopSplash(TCHAR splash_file[], TCHAR splash_fileL[], TCHAR splash_fileR[]) {
int DrawTopSplash(TCHAR splash_file[], TCHAR splash_fileL[], TCHAR splash_fileR[]) {
unsigned int n = 0, bin_size;
File Splash, SplashL, SplashR;
if (FileOpen(&SplashL, splash_fileL, 0)&&FileOpen(&SplashR, splash_fileR, 0))
Expand Down Expand Up @@ -211,34 +196,31 @@ void DrawTopSplash(TCHAR splash_file[], TCHAR splash_fileL[], TCHAR splash_fileR
}
else
{
wchar_t tmp[256];
swprintf(tmp, sizeof(tmp)/sizeof(tmp[0]), strings[STR_ERROR_OPENING], splash_file);
DrawString(BOT_SCREEN, tmp, FONT_WIDTH, SCREEN_HEIGHT - FONT_HEIGHT, RED, BLACK);
return -1;
}

return 0;
}

void DrawBottomSplash(TCHAR splash_file[]) {
DrawSplash(BOT_SCREEN, splash_file);
int DrawBottomSplash(TCHAR splash_file[]) {
return DrawSplash(BOT_SCREEN, splash_file);
}

void DrawSplash(uint8_t *screen, TCHAR splash_file[]) {
int DrawSplash(uint8_t *screen, TCHAR splash_file[]) {
unsigned int n = 0, bin_size;
File Splash;
if(FileOpen(&Splash, splash_file, 0))
{
//Load the spash image
bin_size = 0;
while ((n = FileRead(&Splash, (void*)((uint32_t)screen + bin_size), 0x100000, bin_size)) > 0) {
bin_size += n;
}
FileClose(&Splash);
}
else
{
wchar_t tmp[256];
swprintf(tmp, sizeof(tmp)/sizeof(tmp[0]), strings[STR_ERROR_OPENING], splash_file);
DrawString(BOT_SCREEN, tmp, FONT_WIDTH, SCREEN_HEIGHT - FONT_HEIGHT, RED, BLACK);

if(!FileOpen(&Splash, splash_file, 0))
return -1;

//Load the spash image
bin_size = 0;
while ((n = FileRead(&Splash, (void*)((uint32_t)screen + bin_size), 0x100000, bin_size)) > 0) {
bin_size += n;
}
FileClose(&Splash);

return 0;
}

void DrawFadeScreen(uint8_t *screen, uint16_t Width, uint16_t Height, uint32_t f)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
67 changes: 67 additions & 0 deletions rxtools/source/init/start.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 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.

.section .text.start
.arm

msr CPSR_c, #0xD3 @ Disable IRQ and FIQ and enter supervisor mode

mov sp, #0x28000000

mov r0, #0x18000000 @ address: 0x18000000
orr r0, #0x2D @ size: 8M, enable
mcr p15, 0, r0, c6, c0, 0 @ MPU area 0

ldr r0, =0x01FF801D @ address: 0x01FF8000, size: 32K, enable
mcr p15, 0, r0, c6, c1, 0 @ MPU area 1

mov r0, #0x08000000 @ address 0x08000000
orr r0, #0x29 @ size: 2M, enable
mcr p15, 0, r0, c6, c2, 0 @ MPU area 2

mov r0, #0x10000000 @ address: 0x1000000
orr r0, #0x21 @ size: 128K, enable
mcr p15, 0, r0, c6, c3, 0 @ MPU area 3

ldr r0, =0x10100025 @ address: 10100000, size: 512K, enable
mcr p15, 0, r0, c6, c4, 0 @ MPU area 4

mov r0, #0x20000000 @ address: 0x20000000
orr r0, #0x35 @ size: 128M, enable
mcr p15, 0, r0, c6, c5, 0 @ MPU area 5

mov r0, #0 @ disable
mcr p15, 0, r0, c6, c6, 0 @ MPU area 6
mcr p15, 0, r0, c6, c7, 0 @ MPU area 7

ldr r0, =0x00333333 @ permit reading and writing for all areas
mcr p15, 0, r0, c5, c0, 2 @ write data permission bits

mov r0, #0x00600000 @ permit reading for area 2
orr r0, #0x00000600 @ permit reading for area 5
mcr p15, 0, r0, c5, c0, 3 @ write instruction permission bits

mov r0, #0x25 @ area 0, 2, and 5
mcr p15, 0, r0, c3, c0, 0 @ write data bufferable bits
mcr p15, 0, r0, c2, c0, 0 @ write data cacheable bits

mov r0, #0x24 @ area 2 and 5
mcr p15, 0, r12, c2, c0, 1 @ write instruction cacheable bits

mov r0, #0x43000 @ enable ITCM, use alternative vector
orr r0, #0x00005 @ enable instruction and data cache, enable MPU
mcr p15, 0, r0, c1, c0, 0 @ write control register

b initStart
Loading

0 comments on commit 10512d0

Please sign in to comment.