From 10512d0e68f99157995873e54596c53ca0c4c06a Mon Sep 17 00:00:00 2001 From: 173210 Date: Mon, 29 Feb 2016 10:50:05 +0900 Subject: [PATCH] rxtools: Add init 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 --- .gitmodules | 4 +- Makefile | 3 +- rxtools/Makefile | 44 +++++++----- rxtools/init.ld | 35 ++++++++++ rxtools/source/include/lib/ui/draw.h | 15 ++--- rxtools/source/init/cstart.c | 64 ++++++++++++++++++ rxtools/source/{ => init}/lib/crypto.c | 0 rxtools/source/{ => init}/lib/delay.s | 0 rxtools/source/{lib/ui => init/lib}/draw.c | 54 +++++---------- rxtools/source/{ => init}/lib/fatfs/diskio.c | 0 rxtools/source/{ => init}/lib/fatfs/diskio.h | 0 rxtools/source/{ => init}/lib/fatfs/ff.c | 0 .../{ => init}/lib/fatfs/option/ccsbcs.c | 0 .../{ => init}/lib/fatfs/option/unicode.c | 0 rxtools/source/{ => init}/lib/fs.c | 0 rxtools/source/{ => init}/lib/media/nand.c | 0 .../{ => init}/lib/media/tmio/command.h | 0 .../source/{ => init}/lib/media/tmio/tmio.c | 0 .../{ => init}/lib/media/tmio/tmio_hardware.h | 0 rxtools/source/init/start.s | 67 +++++++++++++++++++ rxtools/source/start.s | 39 ----------- rxtools/source/{main.c => tool/cstart.c} | 14 +--- .../source/{ => tool}/features/decryption.c | 0 rxtools/source/{ => tool}/features/firm.c | 5 -- rxtools/source/{ => tool}/features/install.c | 0 .../source/{ => tool}/features/screenshot.c | 0 rxtools/source/{ => tool}/lib/cfg.c | 0 rxtools/source/{lib/ui => tool/lib}/console.c | 0 rxtools/source/{ => tool}/lib/hid.c | 0 rxtools/source/{ => tool}/lib/i2c.c | 0 rxtools/source/{ => tool}/lib/jsmn | 0 rxtools/source/{ => tool}/lib/lang.c | 0 rxtools/source/{ => tool}/lib/log.c | 0 rxtools/source/{ => tool}/lib/ncch.c | 0 rxtools/source/{ => tool}/lib/polarssl/aes.c | 0 .../source/{ => tool}/lib/polarssl/padlock.c | 0 rxtools/source/{ => tool}/lib/polarssl/sha2.c | 0 rxtools/{stub.ld => tool.ld} | 24 +++---- 38 files changed, 232 insertions(+), 136 deletions(-) create mode 100644 rxtools/init.ld create mode 100644 rxtools/source/init/cstart.c rename rxtools/source/{ => init}/lib/crypto.c (100%) rename rxtools/source/{ => init}/lib/delay.s (100%) rename rxtools/source/{lib/ui => init/lib}/draw.c (85%) rename rxtools/source/{ => init}/lib/fatfs/diskio.c (100%) rename rxtools/source/{ => init}/lib/fatfs/diskio.h (100%) rename rxtools/source/{ => init}/lib/fatfs/ff.c (100%) rename rxtools/source/{ => init}/lib/fatfs/option/ccsbcs.c (100%) rename rxtools/source/{ => init}/lib/fatfs/option/unicode.c (100%) rename rxtools/source/{ => init}/lib/fs.c (100%) rename rxtools/source/{ => init}/lib/media/nand.c (100%) rename rxtools/source/{ => init}/lib/media/tmio/command.h (100%) rename rxtools/source/{ => init}/lib/media/tmio/tmio.c (100%) rename rxtools/source/{ => init}/lib/media/tmio/tmio_hardware.h (100%) create mode 100644 rxtools/source/init/start.s delete mode 100644 rxtools/source/start.s rename rxtools/source/{main.c => tool/cstart.c} (95%) rename rxtools/source/{ => tool}/features/decryption.c (100%) rename rxtools/source/{ => tool}/features/firm.c (97%) rename rxtools/source/{ => tool}/features/install.c (100%) rename rxtools/source/{ => tool}/features/screenshot.c (100%) rename rxtools/source/{ => tool}/lib/cfg.c (100%) rename rxtools/source/{lib/ui => tool/lib}/console.c (100%) rename rxtools/source/{ => tool}/lib/hid.c (100%) rename rxtools/source/{ => tool}/lib/i2c.c (100%) rename rxtools/source/{ => tool}/lib/jsmn (100%) rename rxtools/source/{ => tool}/lib/lang.c (100%) rename rxtools/source/{ => tool}/lib/log.c (100%) rename rxtools/source/{ => tool}/lib/ncch.c (100%) rename rxtools/source/{ => tool}/lib/polarssl/aes.c (100%) rename rxtools/source/{ => tool}/lib/polarssl/padlock.c (100%) rename rxtools/source/{ => tool}/lib/polarssl/sha2.c (100%) rename rxtools/{stub.ld => tool.ld} (76%) diff --git a/.gitmodules b/.gitmodules index 4d560f4d..b28b377f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/Makefile b/Makefile index 79ccabd1..395c66ea 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/rxtools/Makefile b/rxtools/Makefile index 1f3bdfdb..f7da9250 100644 --- a/rxtools/Makefile +++ b/rxtools/Makefile @@ -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 @@ -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) @@ -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) diff --git a/rxtools/init.ld b/rxtools/init.ld new file mode 100644 index 00000000..f78d6e4c --- /dev/null +++ b/rxtools/init.ld @@ -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*) } +} diff --git a/rxtools/source/include/lib/ui/draw.h b/rxtools/source/include/lib/ui/draw.h index dc7d98dd..68363c75 100644 --- a/rxtools/source/include/lib/ui/draw.h +++ b/rxtools/source/include/lib/ui/draw.h @@ -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 @@ -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 @@ -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(); diff --git a/rxtools/source/init/cstart.c b/rxtools/source/init/cstart.c new file mode 100644 index 00000000..74eeb243 --- /dev/null +++ b/rxtools/source/init/cstart.c @@ -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 +#include +#include +#include +#include + +__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); +} diff --git a/rxtools/source/lib/crypto.c b/rxtools/source/init/lib/crypto.c similarity index 100% rename from rxtools/source/lib/crypto.c rename to rxtools/source/init/lib/crypto.c diff --git a/rxtools/source/lib/delay.s b/rxtools/source/init/lib/delay.s similarity index 100% rename from rxtools/source/lib/delay.s rename to rxtools/source/init/lib/delay.s diff --git a/rxtools/source/lib/ui/draw.c b/rxtools/source/init/lib/draw.c similarity index 85% rename from rxtools/source/lib/ui/draw.c rename to rxtools/source/init/lib/draw.c index a520e99e..7d30d49d 100644 --- a/rxtools/source/lib/ui/draw.c +++ b/rxtools/source/init/lib/draw.c @@ -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; @@ -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)) @@ -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) diff --git a/rxtools/source/lib/fatfs/diskio.c b/rxtools/source/init/lib/fatfs/diskio.c similarity index 100% rename from rxtools/source/lib/fatfs/diskio.c rename to rxtools/source/init/lib/fatfs/diskio.c diff --git a/rxtools/source/lib/fatfs/diskio.h b/rxtools/source/init/lib/fatfs/diskio.h similarity index 100% rename from rxtools/source/lib/fatfs/diskio.h rename to rxtools/source/init/lib/fatfs/diskio.h diff --git a/rxtools/source/lib/fatfs/ff.c b/rxtools/source/init/lib/fatfs/ff.c similarity index 100% rename from rxtools/source/lib/fatfs/ff.c rename to rxtools/source/init/lib/fatfs/ff.c diff --git a/rxtools/source/lib/fatfs/option/ccsbcs.c b/rxtools/source/init/lib/fatfs/option/ccsbcs.c similarity index 100% rename from rxtools/source/lib/fatfs/option/ccsbcs.c rename to rxtools/source/init/lib/fatfs/option/ccsbcs.c diff --git a/rxtools/source/lib/fatfs/option/unicode.c b/rxtools/source/init/lib/fatfs/option/unicode.c similarity index 100% rename from rxtools/source/lib/fatfs/option/unicode.c rename to rxtools/source/init/lib/fatfs/option/unicode.c diff --git a/rxtools/source/lib/fs.c b/rxtools/source/init/lib/fs.c similarity index 100% rename from rxtools/source/lib/fs.c rename to rxtools/source/init/lib/fs.c diff --git a/rxtools/source/lib/media/nand.c b/rxtools/source/init/lib/media/nand.c similarity index 100% rename from rxtools/source/lib/media/nand.c rename to rxtools/source/init/lib/media/nand.c diff --git a/rxtools/source/lib/media/tmio/command.h b/rxtools/source/init/lib/media/tmio/command.h similarity index 100% rename from rxtools/source/lib/media/tmio/command.h rename to rxtools/source/init/lib/media/tmio/command.h diff --git a/rxtools/source/lib/media/tmio/tmio.c b/rxtools/source/init/lib/media/tmio/tmio.c similarity index 100% rename from rxtools/source/lib/media/tmio/tmio.c rename to rxtools/source/init/lib/media/tmio/tmio.c diff --git a/rxtools/source/lib/media/tmio/tmio_hardware.h b/rxtools/source/init/lib/media/tmio/tmio_hardware.h similarity index 100% rename from rxtools/source/lib/media/tmio/tmio_hardware.h rename to rxtools/source/init/lib/media/tmio/tmio_hardware.h diff --git a/rxtools/source/init/start.s b/rxtools/source/init/start.s new file mode 100644 index 00000000..58ccff0e --- /dev/null +++ b/rxtools/source/init/start.s @@ -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 diff --git a/rxtools/source/start.s b/rxtools/source/start.s deleted file mode 100644 index 8d327973..00000000 --- a/rxtools/source/start.s +++ /dev/null @@ -1,39 +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. - - .section ".text.vect" - .align 2 - .arm - - @ Vector Table - b . - b . - b . - b . - b . - b . - b . - b . - b . - b . - b . - -perm: - .word 0x33333333 - - ldr r0, perm - mcr p15, 0, r0, c5, c0, 2 - - msr CPSR_c, #0xD3 @ Disable IRQ and FIQ and enter supervisor mode diff --git a/rxtools/source/main.c b/rxtools/source/tool/cstart.c similarity index 95% rename from rxtools/source/main.c rename to rxtools/source/tool/cstart.c index f77b4347..c3dd45f0 100644 --- a/rxtools/source/main.c +++ b/rxtools/source/tool/cstart.c @@ -185,7 +185,7 @@ static void warn(const wchar_t *format, ...) ConsoleShow(); } -__attribute__((section(".text.start"), noreturn)) void _start() +__attribute__((section(".text.cstart"), noreturn)) void toolStart() { static const TCHAR fontPath[] = _T("") SYS_PATH "/" FONT_NAME; void *fontBuf; @@ -193,22 +193,10 @@ __attribute__((section(".text.start"), noreturn)) void _start() int r; FIL f; - // Enable TMIO IRQ - *(volatile uint32_t *)0x10001000 = 0x00010000; - preloadStringsA(); - - if (!FSInit()) { - DrawString(BOT_SCREEN, strings[STR_FAILED], - BOT_SCREEN_WIDTH / 2, SCREEN_HEIGHT - FONT_HEIGHT, RED, BLACK); - while (1); - } - - set_loglevel(ll_info); log(ll_info, "Initializing rxTools..."); - setConsole(); diff --git a/rxtools/source/features/decryption.c b/rxtools/source/tool/features/decryption.c similarity index 100% rename from rxtools/source/features/decryption.c rename to rxtools/source/tool/features/decryption.c diff --git a/rxtools/source/features/firm.c b/rxtools/source/tool/features/firm.c similarity index 97% rename from rxtools/source/features/firm.c rename to rxtools/source/tool/features/firm.c index 337fcd78..05e5b40a 100644 --- a/rxtools/source/features/firm.c +++ b/rxtools/source/tool/features/firm.c @@ -176,11 +176,6 @@ int rxMode(int emu) shstrtab = (char *)PATCH_ADDR + shdr[ehdr->e_shstrndx].sh_offset; for (btmShdr = shdr + ehdr->e_shnum; shdr != btmShdr; shdr++) { if (!strcmp(shstrtab + shdr->sh_name, ".patch.p9.reboot.body")) { - /* 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); diff --git a/rxtools/source/features/install.c b/rxtools/source/tool/features/install.c similarity index 100% rename from rxtools/source/features/install.c rename to rxtools/source/tool/features/install.c diff --git a/rxtools/source/features/screenshot.c b/rxtools/source/tool/features/screenshot.c similarity index 100% rename from rxtools/source/features/screenshot.c rename to rxtools/source/tool/features/screenshot.c diff --git a/rxtools/source/lib/cfg.c b/rxtools/source/tool/lib/cfg.c similarity index 100% rename from rxtools/source/lib/cfg.c rename to rxtools/source/tool/lib/cfg.c diff --git a/rxtools/source/lib/ui/console.c b/rxtools/source/tool/lib/console.c similarity index 100% rename from rxtools/source/lib/ui/console.c rename to rxtools/source/tool/lib/console.c diff --git a/rxtools/source/lib/hid.c b/rxtools/source/tool/lib/hid.c similarity index 100% rename from rxtools/source/lib/hid.c rename to rxtools/source/tool/lib/hid.c diff --git a/rxtools/source/lib/i2c.c b/rxtools/source/tool/lib/i2c.c similarity index 100% rename from rxtools/source/lib/i2c.c rename to rxtools/source/tool/lib/i2c.c diff --git a/rxtools/source/lib/jsmn b/rxtools/source/tool/lib/jsmn similarity index 100% rename from rxtools/source/lib/jsmn rename to rxtools/source/tool/lib/jsmn diff --git a/rxtools/source/lib/lang.c b/rxtools/source/tool/lib/lang.c similarity index 100% rename from rxtools/source/lib/lang.c rename to rxtools/source/tool/lib/lang.c diff --git a/rxtools/source/lib/log.c b/rxtools/source/tool/lib/log.c similarity index 100% rename from rxtools/source/lib/log.c rename to rxtools/source/tool/lib/log.c diff --git a/rxtools/source/lib/ncch.c b/rxtools/source/tool/lib/ncch.c similarity index 100% rename from rxtools/source/lib/ncch.c rename to rxtools/source/tool/lib/ncch.c diff --git a/rxtools/source/lib/polarssl/aes.c b/rxtools/source/tool/lib/polarssl/aes.c similarity index 100% rename from rxtools/source/lib/polarssl/aes.c rename to rxtools/source/tool/lib/polarssl/aes.c diff --git a/rxtools/source/lib/polarssl/padlock.c b/rxtools/source/tool/lib/polarssl/padlock.c similarity index 100% rename from rxtools/source/lib/polarssl/padlock.c rename to rxtools/source/tool/lib/polarssl/padlock.c diff --git a/rxtools/source/lib/polarssl/sha2.c b/rxtools/source/tool/lib/polarssl/sha2.c similarity index 100% rename from rxtools/source/lib/polarssl/sha2.c rename to rxtools/source/tool/lib/polarssl/sha2.c diff --git a/rxtools/stub.ld b/rxtools/tool.ld similarity index 76% rename from rxtools/stub.ld rename to rxtools/tool.ld index 3a548b4c..9af4c266 100644 --- a/rxtools/stub.ld +++ b/rxtools/tool.ld @@ -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 @@ -17,27 +17,21 @@ OUTPUT_FORMAT("elf32-littlearm") OUTPUT_ARCH(arm) -ENTRY(_start) - -MEMORY -{ - ram : ORIGIN = 0x08000000, LENGTH = 400K -} +ENTRY(toolStart) SECTIONS { + . = 0x23E00000; + .text : { - KEEP(*(.text.vect)) - KEEP(*(.text.start)) + KEEP(*(.text.cstart)) *(.text*) - } >ram - - .rodata : { *(.rodata*) } >ram - - .data : { *(.data*) } >ram + } - .bss : { *(.bss*) } >ram + .rodata : { *(.rodata*) } + .data : { *(.data*) } + .bss : { *(.bss*) } . = ALIGN(4); __end__ = ABSOLUTE(.);