Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 3 tries for a wrong code #36

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .gitattributes

This file was deleted.

17 changes: 9 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
.idea
CMakeLists.txt

data_output
data_input/*.bin
data_input/*.firm

*.bat
screen_init/obj
out
payload_stage1/build
payload_stage2/build
payload_stage2/data
*.elf
*.bin
*.o
*.d
51 changes: 13 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,52 +1,27 @@
.PHONY : all hax firm0 firm1 sector screen_init stage2 installer clean
.PHONY : stage1 arm11 stage2

TARGET = arm9loaderhax
PYTHON = python
INDIR = data_input
OUTDIR = data_output
OUTDIR = out

all : $(OUTDIR) hax installer

hax : $(OUTDIR) firm0 firm1 sector screen_init stage2
all : $(OUTDIR) stage1 arm11 stage2

$(OUTDIR):
@[ -d $(OUTDIR) ] || mkdir -p $(OUTDIR)

firm0:
@cd payload_stage1 && make
@cp $(INDIR)/new3ds90.firm $(OUTDIR)/firm0.bin
@dd if=payload_stage1/payload_stage1.bin of=$(OUTDIR)/firm0.bin bs=512 seek=1922 conv=notrunc
@echo FIRM0 done!

firm1:
@cp $(INDIR)/new3ds10.firm $(OUTDIR)/firm1.bin
@echo FIRM1 done!

sector:
@$(PYTHON) common/sector_generator.py $(INDIR)/secret_sector.bin $(INDIR)/otp.bin $(OUTDIR)/sector.bin
@echo SECTOR done!
arm11:
@$(MAKE) -C arm11

screen_init:
@[ -d payload_stage2/data ] || mkdir -p payload_stage2/data
$(MAKE) -C screen_init
@cp screen_init/screen_init.bin payload_stage2/data/
stage1:
@$(MAKE) -C payload_stage1
@mv payload_stage1/payload_stage1.bin $(OUTDIR)

stage2:
@cp screen_init/screen_init.bin payload_stage2/data
@[ -d payload_stage2/data ] || mkdir -p payload_stage2/data
@mv arm11/arm11.bin payload_stage2/data
@$(MAKE) -C payload_stage2
@cp payload_stage2/payload_stage2.bin $(OUTDIR)/stage0x5C000.bin

installer:
@cp $(OUTDIR)/sector.bin payload_installer/brahma2/data/sector.bin
@cp $(OUTDIR)/firm0.bin payload_installer/brahma2/data/firm0.bin
@cp $(OUTDIR)/firm1.bin payload_installer/brahma2/data/firm1.bin
@cp $(OUTDIR)/stage0x5C000.bin payload_installer/brahma2/data/stage2.bin
@cd payload_installer && make TARGET=../$(OUTDIR)/$(TARGET)
@echo INSTALLER done!
@mv payload_stage2/payload_stage2.bin $(OUTDIR)

clean:
@echo clean...
@$(MAKE) -C payload_stage1 clean
@$(MAKE) -C screen_init clean
@$(MAKE) -C arm11 clean
@$(MAKE) -C payload_stage2 clean
@$(MAKE) -C payload_installer clean TARGET=../$(TARGET)
@rm -rf $(OUTDIR)
36 changes: 17 additions & 19 deletions screen_init/Makefile → arm11/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,51 @@ LD=arm-none-eabi-ld
MV=mv -f
RM=rm -rf

LIBNAME=screen_init
LIBNAME=arm11
ELFNAME=$(LIBNAME).elf
BINNAME=$(LIBNAME).bin
DATNAME=$(LIBNAME).dat

SRC_DIR:=source/$(LIBNAME)
OBJ_DIR:=obj/$(LIBNAME)
LIB_DIR:=lib
DEP_DIR:=obj/$(LIBNAME)
SRC_DIR:=source
OBJ_DIR:=build

LIBS=
CFLAGS=-std=gnu99 -Os -g -mword-relocations -fomit-frame-pointer -ffast-math
C9FLAGS=-mcpu=arm946e-s -march=armv5te -mlittle-endian
C11FLAGS=-mcpu=mpcore -mlittle-endian
CFLAGS= -g -Wall -O2 -mword-relocations\
-ffast-math -Wno-main -std=c99\
-mcpu=mpcore -mlittle-endian $(ARCH)
LDFLAGS=$(LIBS)
OCFLAGS=--set-section-flags .bss=alloc,load,contents

OBJS:=$(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(wildcard $(SRC_DIR)/*.c))
OBJS+=$(patsubst $(SRC_DIR)/%.s, $(OBJ_DIR)/%.o, $(wildcard $(SRC_DIR)/*.s))
OBJS+=$(patsubst $(SRC_DIR)/%.S, $(OBJ_DIR)/%.o, $(wildcard $(SRC_DIR)/*.S))

OUT_DIR= obj/$(LIBNAME)
OUT_DIR=build

.PHONY: clean

all: screen_init.bin
all: $(LIBNAME).bin

screen_init.bin: $(OBJS)
$(CC) -nostartfiles --specs=$(LIBNAME).specs $(OBJS) $(LDFLAGS) -o $(ELFNAME)
$(LIBNAME).bin: $(OBJS)
$(CC) -nostartfiles --specs=../common/$(LIBNAME).specs $(OBJS) $(LDFLAGS) -o $(ELFNAME)
$(OC) $(OCFLAGS) -O binary $(ELFNAME) $(BINNAME)

obj/%.o: source/%.c | dirs
${OBJ_DIR}/%.o: source/%.c | dirs
@echo Compiling $<
$(CC) -c $(CFLAGS) $(C11FLAGS) $< -o $@
$(CC) -c $(CFLAGS) $< -o $@

obj/%.o: source/%.s | dirs
${OBJ_DIR}/%.o: source/%.s | dirs
@echo Compiling $<
$(CC) -c $(CFLAGS) $(C11FLAGS) $< -o $@
$(CC) -c $(CFLAGS) $< -o $@

obj/%.o: source/%.S | dirs
${OBJ_DIR}/%.o: source/%.S | dirs
@echo Compiling $<
$(CC) -c $(CFLAGS) $(C11FLAGS) $< -o $@
$(CC) -c $(CFLAGS) $< -o $@

dirs: ${OUT_DIR}

${OUT_DIR}:
mkdir -p ${OUT_DIR}

clean:
rm -rf *.elf *.bin obj/*
rm -rf *.elf *.bin ${OUT_DIR} ${OBJ_DIR}
117 changes: 117 additions & 0 deletions arm11/source/arm11.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include <inttypes.h>

#define BRIGHTNESS 0x39
#define FB_TOP_LEFT 0x18300000
#define FB_TOP_RIGHT 0x18300000
#define FB_BOTTOM 0x18346500

static inline void regSet();

void __attribute__ ((naked)) a11Entry()
{
__asm__ (
"CPSID aif\n\t" //Disable interrupts
"ldr r0,=_stack\n\t"
"mov sp, r0"
);

regSet();
}

static inline void regSet()
{
volatile uint32_t *entry = (uint32_t *)0x1FFFFFF8;

*(volatile uint32_t*)0x10141200 = 0x1007F;
*(volatile uint32_t*)0x10202014 = 0x00000001;
*(volatile uint32_t*)0x1020200C &= 0xFFFEFFFE;

*(volatile uint32_t*)0x10202240 = BRIGHTNESS;
*(volatile uint32_t*)0x10202A40 = BRIGHTNESS;
*(volatile uint32_t*)0x10202244 = 0x1023E;
*(volatile uint32_t*)0x10202A44 = 0x1023E;

// Top screen
*(volatile uint32_t*)0x10400400 = 0x000001c2;
*(volatile uint32_t*)0x10400404 = 0x000000d1;
*(volatile uint32_t*)0x10400408 = 0x000001c1;
*(volatile uint32_t*)0x1040040c = 0x000001c1;
*(volatile uint32_t*)0x10400410 = 0x00000000;
*(volatile uint32_t*)0x10400414 = 0x000000cf;
*(volatile uint32_t*)0x10400418 = 0x000000d1;
*(volatile uint32_t*)0x1040041c = 0x01c501c1;
*(volatile uint32_t*)0x10400420 = 0x00010000;
*(volatile uint32_t*)0x10400424 = 0x0000019d;
*(volatile uint32_t*)0x10400428 = 0x00000002;
*(volatile uint32_t*)0x1040042c = 0x00000192;
*(volatile uint32_t*)0x10400430 = 0x00000192;
*(volatile uint32_t*)0x10400434 = 0x00000192;
*(volatile uint32_t*)0x10400438 = 0x00000001;
*(volatile uint32_t*)0x1040043c = 0x00000002;
*(volatile uint32_t*)0x10400440 = 0x01960192;
*(volatile uint32_t*)0x10400444 = 0x00000000;
*(volatile uint32_t*)0x10400448 = 0x00000000;
*(volatile uint32_t*)0x1040045C = 0x00f00190;
*(volatile uint32_t*)0x10400460 = 0x01c100d1;
*(volatile uint32_t*)0x10400464 = 0x01920002;
*(volatile uint32_t*)0x10400468 = 0x18300000;
*(volatile uint32_t*)0x10400470 = 0x80341;
*(volatile uint32_t*)0x10400474 = 0x00010501;
*(volatile uint32_t*)0x10400478 = 0;
*(volatile uint32_t*)0x10400490 = 0x000002D0;
*(volatile uint32_t*)0x1040049C = 0x00000000;

// Disco register
for(volatile uint32_t i = 0; i < 256; i++)
*(volatile uint32_t*)0x10400484 = 0x10101 * i;

// Bottom screen
*(volatile uint32_t*)0x10400500 = 0x000001c2;
*(volatile uint32_t*)0x10400504 = 0x000000d1;
*(volatile uint32_t*)0x10400508 = 0x000001c1;
*(volatile uint32_t*)0x1040050c = 0x000001c1;
*(volatile uint32_t*)0x10400510 = 0x000000cd;
*(volatile uint32_t*)0x10400514 = 0x000000cf;
*(volatile uint32_t*)0x10400518 = 0x000000d1;
*(volatile uint32_t*)0x1040051c = 0x01c501c1;
*(volatile uint32_t*)0x10400520 = 0x00010000;
*(volatile uint32_t*)0x10400524 = 0x0000019d;
*(volatile uint32_t*)0x10400528 = 0x00000052;
*(volatile uint32_t*)0x1040052c = 0x00000192;
*(volatile uint32_t*)0x10400530 = 0x00000192;
*(volatile uint32_t*)0x10400534 = 0x0000004f;
*(volatile uint32_t*)0x10400538 = 0x00000050;
*(volatile uint32_t*)0x1040053c = 0x00000052;
*(volatile uint32_t*)0x10400540 = 0x01980194;
*(volatile uint32_t*)0x10400544 = 0x00000000;
*(volatile uint32_t*)0x10400548 = 0x00000011;
*(volatile uint32_t*)0x1040055C = 0x00f00140;
*(volatile uint32_t*)0x10400560 = 0x01c100d1;
*(volatile uint32_t*)0x10400564 = 0x01920052;
*(volatile uint32_t*)0x10400568 = 0x18300000 + 0x46500;
*(volatile uint32_t*)0x10400570 = 0x80301;
*(volatile uint32_t*)0x10400574 = 0x00010501;
*(volatile uint32_t*)0x10400578 = 0;
*(volatile uint32_t*)0x10400590 = 0x000002D0;
*(volatile uint32_t*)0x1040059C = 0x00000000;

// Disco register
for(volatile uint32_t i = 0; i < 256; i++)
*(volatile uint32_t*)0x10400584 = 0x10101 * i;

*(volatile uint32_t*)0x10400468 = FB_TOP_LEFT;
*(volatile uint32_t*)0x1040046c = FB_TOP_LEFT;
*(volatile uint32_t*)0x10400494 = FB_TOP_RIGHT;
*(volatile uint32_t*)0x10400498 = FB_TOP_RIGHT;
*(volatile uint32_t*)0x10400568 = FB_BOTTOM;
*(volatile uint32_t*)0x1040056c = FB_BOTTOM;

// Reset the entry
*entry = 0;

// Wait for entry to be set
while(!*entry);

// Jump
((void (*)())*entry)();
}
File renamed without changes.
4 changes: 4 additions & 0 deletions common/arm11.specs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%rename link old_link

*link:
%(old_link) -T ../common/arm11.ld%s
45 changes: 0 additions & 45 deletions common/sector_generator.py

This file was deleted.

Empty file removed data_input/.place_here
Empty file.
28 changes: 0 additions & 28 deletions payload_installer/Makefile

This file was deleted.

Loading