mirror of
https://github.com/ApacheThunder/SCKILL.git
synced 2025-06-19 03:25:32 -04:00
Commit what I've got
This commit is contained in:
parent
fcd1ca2c95
commit
83e1d4554d
110
SCFW_Stage1/scfw.s
Normal file
110
SCFW_Stage1/scfw.s
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
cart_base:
|
||||||
|
.org 0x00
|
||||||
|
b entrypoint
|
||||||
|
.org 0x04
|
||||||
|
.fill 0x9c, 0, 0
|
||||||
|
.org 0xa0
|
||||||
|
.ascii "DsBooterSCFW"
|
||||||
|
.org 0xac
|
||||||
|
.ascii "PASSsc"
|
||||||
|
.org 0xb2
|
||||||
|
.byte 0x96
|
||||||
|
.org 0xb4
|
||||||
|
.fill 8, 0, 0
|
||||||
|
.org 0xbc
|
||||||
|
.byte 0
|
||||||
|
.org 0xbd
|
||||||
|
.fill 3, 0, 0
|
||||||
|
|
||||||
|
|
||||||
|
.org 0xc0
|
||||||
|
entrypoint:
|
||||||
|
# copy and run this fn from RAM
|
||||||
|
mov r0, #0x02000000
|
||||||
|
adr r1, sc_mode_flash_rw
|
||||||
|
adr r2, sc_mode_flash_rw_end
|
||||||
|
sc_mode_flash_rw_loop:
|
||||||
|
ldr r3, [r1], # 4
|
||||||
|
str r3, [r0], # 4
|
||||||
|
cmp r1, r2
|
||||||
|
blt sc_mode_flash_rw_loop
|
||||||
|
mov lr, pc
|
||||||
|
mov pc, # 0x02000000
|
||||||
|
|
||||||
|
# detect GBA/NDS using mirroring
|
||||||
|
mov r0, # 0x02000000
|
||||||
|
mov r2, # 0
|
||||||
|
str r2, [r0]
|
||||||
|
add r1, r0, #0x00040000
|
||||||
|
mov r2, # 1
|
||||||
|
str r2, [r1]
|
||||||
|
ldr r2, [r0]
|
||||||
|
cmp r2, # 0
|
||||||
|
beq load_nds
|
||||||
|
|
||||||
|
|
||||||
|
# load & execute multiboot gba rom
|
||||||
|
load_gba:
|
||||||
|
adrl r0, gba_rom
|
||||||
|
adrl r1, gba_rom_end
|
||||||
|
mov r2, # 0x02000000
|
||||||
|
add lr, r2, # 0x000000c0
|
||||||
|
load_gba_loop:
|
||||||
|
ldr r3, [r0], # 4
|
||||||
|
str r3, [r2], # 4
|
||||||
|
cmp r0, r1
|
||||||
|
blt load_gba_loop
|
||||||
|
bx lr
|
||||||
|
# load & execute nds rom
|
||||||
|
load_nds:
|
||||||
|
adrl r0, nds_rom
|
||||||
|
ldr r1, [r0, # 0x20]
|
||||||
|
ldr r2, [r0, # 0x28]
|
||||||
|
ldr r3, [r0, # 0x2c]
|
||||||
|
add r1, r1, r0
|
||||||
|
add r3, r3, r1
|
||||||
|
load_nds_arm9_loop:
|
||||||
|
ldr r4, [r1], # 4
|
||||||
|
str r4, [r2], # 4
|
||||||
|
cmp r1, r3
|
||||||
|
blt load_nds_arm9_loop
|
||||||
|
ldr r1, [r0, # 0x30]
|
||||||
|
ldr r2, [r0, # 0x38]
|
||||||
|
ldr r3, [r0, # 0x3c]
|
||||||
|
add r1, r1, r0
|
||||||
|
add r3, r3, r1
|
||||||
|
load_nds_arm7_loop:
|
||||||
|
ldr r4, [r1], # 4
|
||||||
|
str r4, [r2], # 4
|
||||||
|
cmp r1, r3
|
||||||
|
blt load_nds_arm7_loop
|
||||||
|
mov r1, # 0x02800000
|
||||||
|
sub r1, r1, # 0x200
|
||||||
|
ldr r2, [r0, # 0x24]
|
||||||
|
str r2, [r1, # 0x24]
|
||||||
|
ldr lr, [r0, # 0x34]
|
||||||
|
bx lr
|
||||||
|
|
||||||
|
sc_mode_flash_rw:
|
||||||
|
mov r0, # 0x0a000000
|
||||||
|
sub r0, r0, #0x02
|
||||||
|
mov r1, # 0x005a
|
||||||
|
add r1, # 0xa500
|
||||||
|
strh r1, [r0]
|
||||||
|
strh r1, [r0]
|
||||||
|
mov r1, # 4
|
||||||
|
strh r1, [r0]
|
||||||
|
strh r1, [r0]
|
||||||
|
bx lr
|
||||||
|
sc_mode_flash_rw_end:
|
||||||
|
|
||||||
|
.balign 4, 0xff
|
||||||
|
gba_rom:
|
||||||
|
.incbin "../SCFW_Stage2_GBA/SCFW_Stage2_GBA_mb.gba"
|
||||||
|
gba_rom_end:
|
||||||
|
|
||||||
|
.balign 4, 0xff
|
||||||
|
nds_rom:
|
||||||
|
.incbin "../SCFW_Stage2_NDS/SCFW_Stage2_NDS.nds"
|
||||||
|
nds_rom_end:
|
||||||
|
|
135
SCFW_Stage2_GBA/Makefile
Normal file
135
SCFW_Stage2_GBA/Makefile
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# Clear the implicit built in rules
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
.SUFFIXES:
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ifeq ($(strip $(DEVKITARM)),)
|
||||||
|
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM)
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(DEVKITARM)/gba_rules
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# TARGET is the name of the output, if this ends with _mb a multiboot image is generated
|
||||||
|
# BUILD is the directory where object files & intermediate files will be placed
|
||||||
|
# SOURCES is a list of directories containing source code
|
||||||
|
# DATA is a list of directories containing data files
|
||||||
|
# INCLUDES is a list of directories containing header files
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
TARGET := $(shell basename $(CURDIR))_mb
|
||||||
|
BUILD := build
|
||||||
|
SOURCES := source
|
||||||
|
DATA :=
|
||||||
|
INCLUDES :=
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# options for code generation
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ARCH := -v -mthumb -mthumb-interwork
|
||||||
|
|
||||||
|
CFLAGS := -g -Wall -O0 -std=c99\
|
||||||
|
-mcpu=arm7tdmi -mtune=arm7tdmi\
|
||||||
|
$(ARCH)
|
||||||
|
|
||||||
|
CFLAGS += $(INCLUDE)
|
||||||
|
|
||||||
|
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
|
||||||
|
|
||||||
|
ASFLAGS := $(ARCH)
|
||||||
|
LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $@).map
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# path to tools - this can be deleted if you set the path to the toolchain in windows
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export PATH := $(DEVKITARM)/bin:$(PATH)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# any extra libraries we wish to link with the project
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
LIBS := -lfat -lgba
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# list of directories containing libraries, this must be the top level containing
|
||||||
|
# include and lib
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
LIBDIRS := $(LIBGBA)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# no real need to edit anything past this point unless you need to add additional
|
||||||
|
# rules for different file extensions
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||||
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||||
|
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||||
|
|
||||||
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# automatically build a list of object files for our project
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||||
|
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||||
|
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||||
|
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# use CXX for linking C++ projects, CC for standard C
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ifeq ($(strip $(CPPFILES)),)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export LD := $(CC)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
else
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export LD := $(CXX)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
endif
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export OFILES := $(addsuffix .o,$(BINFILES)) $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# build a list of include paths
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||||
|
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||||
|
-I$(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# build a list of library paths
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||||
|
|
||||||
|
.PHONY: $(BUILD) clean
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(BUILD):
|
||||||
|
@[ -d $@ ] || mkdir -p $@
|
||||||
|
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||||
|
|
||||||
|
all : $(BUILD)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
clean:
|
||||||
|
@echo clean ...
|
||||||
|
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
else
|
||||||
|
|
||||||
|
DEPENDS := $(OFILES:.o=.d)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# main targets
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(OUTPUT).gba : $(OUTPUT).elf
|
||||||
|
|
||||||
|
$(OUTPUT).elf : $(OFILES)
|
||||||
|
|
||||||
|
-include $(DEPENDS)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
endif
|
||||||
|
#---------------------------------------------------------------------------------
|
99
SCFW_Stage2_GBA/source/main.c
Normal file
99
SCFW_Stage2_GBA/source/main.c
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
#include <gba.h>
|
||||||
|
#include <fat.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.H>
|
||||||
|
|
||||||
|
#define GBA_ROM ((vu32*) 0x08000000)
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
SC_RAM_RO = 0x1,
|
||||||
|
SC_MEDIA = 0x3,
|
||||||
|
SC_RAM_RW = 0x5,
|
||||||
|
};
|
||||||
|
|
||||||
|
void sc_mode(u32 mode)
|
||||||
|
{
|
||||||
|
*(vu16*)0x9FFFFFE = 0xA55A;
|
||||||
|
*(vu16*)0x9FFFFFE = 0xA55A;
|
||||||
|
*(vu16*)0x9FFFFFE = mode;
|
||||||
|
*(vu16*)0x9FFFFFE = mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void waitForever() {
|
||||||
|
for (;;) {
|
||||||
|
VBlankIntrWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EWRAM_BSS u8 filebuf[0x20000];
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
irqInit();
|
||||||
|
irqEnable(IRQ_VBLANK);
|
||||||
|
|
||||||
|
consoleDemoInit();
|
||||||
|
|
||||||
|
iprintf("SCFW v0.1 GBA-mode\n\n");
|
||||||
|
|
||||||
|
if (fatInitDefault()) {
|
||||||
|
iprintf("FAT system initialised\n");
|
||||||
|
} else {
|
||||||
|
iprintf("FAT initialisation failed!\n");
|
||||||
|
waitForever();
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *kernel = fopen("scfw/kernel.gba","rb");
|
||||||
|
if (kernel) {
|
||||||
|
iprintf("Kernel file opened successfully\n");
|
||||||
|
} else {
|
||||||
|
iprintf("Kernel file open failed\n");
|
||||||
|
waitForever();
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(kernel, 0, SEEK_END);
|
||||||
|
u32 kernel_size = ftell(kernel);
|
||||||
|
if (kernel_size > 0x02000000) {
|
||||||
|
iprintf("Kernel too large to load!\n");
|
||||||
|
waitForever();
|
||||||
|
}
|
||||||
|
iprintf("Kernel size is 0x%x bytes\n", kernel_size);
|
||||||
|
fseek(kernel, 0, SEEK_SET);
|
||||||
|
|
||||||
|
u32 total_bytes = 0;
|
||||||
|
u32 bytes = 0;
|
||||||
|
do {
|
||||||
|
bytes = fread(filebuf, 1, sizeof filebuf, kernel);
|
||||||
|
sc_mode(SC_RAM_RW);
|
||||||
|
for (u32 i = 0; i < bytes; i += 4) {
|
||||||
|
GBA_ROM[(i + total_bytes) >> 2] = *(vu32*) &filebuf[i];
|
||||||
|
if (GBA_ROM[(i + total_bytes) >> 2] != *(vu32*) &filebuf[i]) {
|
||||||
|
iprintf("SDRAM write failed!\n");
|
||||||
|
waitForever();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sc_mode(SC_MEDIA);
|
||||||
|
total_bytes += bytes;
|
||||||
|
iprintf("Bytes read: 0x%x\n", total_bytes);
|
||||||
|
} while (bytes);
|
||||||
|
|
||||||
|
if (ferror(kernel)) {
|
||||||
|
iprintf("Error reading kernel.\n");
|
||||||
|
waitForever();
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_mode(SC_RAM_RO);
|
||||||
|
|
||||||
|
if ((*GBA_ROM & 0xff000000) != 0xea000000) {
|
||||||
|
iprintf("Unexpected ROM entrypont, kernel not GBA ROM?");
|
||||||
|
waitForever();
|
||||||
|
}
|
||||||
|
|
||||||
|
iprintf("Kernel loaded successfully.\n");
|
||||||
|
iprintf("Let's go.\n");
|
||||||
|
SoftReset(ROM_RESTART);
|
||||||
|
iprintf("Unreachable, panic!\n");
|
||||||
|
waitForever();
|
||||||
|
}
|
1
SCFW_Stage2_NDS/README.md
Normal file
1
SCFW_Stage2_NDS/README.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
Dummy for now, just http://www.cryptosystem.org/archives/2007/01/simple-gba-mode-switcher/
|
BIN
SCFW_Stage2_NDS/SCFW_Stage2_NDS.nds
Normal file
BIN
SCFW_Stage2_NDS/SCFW_Stage2_NDS.nds
Normal file
Binary file not shown.
126
sckiill/Makefile
Normal file
126
sckiill/Makefile
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
.SUFFIXES:
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ifeq ($(strip $(DEVKITARM)),)
|
||||||
|
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||||
|
endif
|
||||||
|
|
||||||
|
include $(DEVKITARM)/ds_rules
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# TARGET is the name of the output
|
||||||
|
# BUILD is the directory where object files & intermediate files will be placed
|
||||||
|
# SOURCES is a list of directories containing source code
|
||||||
|
# INCLUDES is a list of directories containing extra header files
|
||||||
|
# MAXMOD_SOUNDBANK contains a directory of music and sound effect files
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
TARGET := $(shell basename $(CURDIR))
|
||||||
|
BUILD := build
|
||||||
|
SOURCES := source
|
||||||
|
DATA := data
|
||||||
|
INCLUDES := include
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# options for code generation
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ARCH := -mthumb -mthumb-interwork
|
||||||
|
|
||||||
|
CFLAGS := -g -Wall -O0\
|
||||||
|
-march=armv5te -mtune=arm946e-s -fomit-frame-pointer\
|
||||||
|
-ffast-math \
|
||||||
|
$(ARCH)
|
||||||
|
|
||||||
|
CFLAGS += $(INCLUDE) -DARM9
|
||||||
|
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
|
||||||
|
|
||||||
|
ASFLAGS := -g $(ARCH)
|
||||||
|
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# any extra libraries we wish to link with the project (order is important)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
LIBS := -lnds9
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# list of directories containing libraries, this must be the top level containing
|
||||||
|
# include and lib
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
LIBDIRS := $(LIBNDS)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# no real need to edit anything past this point unless you need to add additional
|
||||||
|
# rules for different file extensions
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ifneq ($(BUILD),$(notdir $(CURDIR)))
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export OUTPUT := $(CURDIR)/$(TARGET)
|
||||||
|
|
||||||
|
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
|
||||||
|
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
|
||||||
|
|
||||||
|
export DEPSDIR := $(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
|
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
|
||||||
|
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
|
||||||
|
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
|
||||||
|
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# use CXX for linking C++ projects, CC for standard C
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
ifeq ($(strip $(CPPFILES)),)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export LD := $(CC)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
else
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
export LD := $(CXX)
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
endif
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||||
|
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||||
|
|
||||||
|
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||||
|
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||||
|
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||||
|
-I$(CURDIR)/$(BUILD)
|
||||||
|
|
||||||
|
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
|
||||||
|
|
||||||
|
.PHONY: $(BUILD) clean
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(BUILD):
|
||||||
|
@[ -d $@ ] || mkdir -p $@
|
||||||
|
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
clean:
|
||||||
|
@echo clean ...
|
||||||
|
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
else
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
# main targets
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
$(OUTPUT).nds : $(OUTPUT).elf
|
||||||
|
$(OUTPUT).elf : $(OFILES)
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
%.bin.o : %.bin
|
||||||
|
#---------------------------------------------------------------------------------
|
||||||
|
@echo $(notdir $<)
|
||||||
|
$(bin2o)
|
||||||
|
|
||||||
|
-include $(DEPSDIR)/*.d
|
||||||
|
|
||||||
|
#---------------------------------------------------------------------------------------
|
||||||
|
endif
|
||||||
|
#---------------------------------------------------------------------------------------
|
BIN
sckiill/source/scfw.bin
Normal file
BIN
sckiill/source/scfw.bin
Normal file
Binary file not shown.
8396
sckiill/source/scfw.bin.c
Normal file
8396
sckiill/source/scfw.bin.c
Normal file
File diff suppressed because it is too large
Load Diff
2
sckiill/source/scfw.bin.h
Normal file
2
sckiill/source/scfw.bin.h
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
extern unsigned char scfw_bin[];
|
||||||
|
extern unsigned int scfw_bin_len;
|
137
sckiill/source/sckill.cpp
Normal file
137
sckiill/source/sckill.cpp
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
#include <nds.h>
|
||||||
|
#include <fat.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "scfw.bin.h"
|
||||||
|
|
||||||
|
#define SC_MODE_REG (*(vu16*) 0x09fffffe)
|
||||||
|
#define SC_MODE_MAGIC ((u16) 0xa55a)
|
||||||
|
#define SC_MODE_FLASH_RW ((u16) 4)
|
||||||
|
|
||||||
|
#define SC_FLASH_MAGIC_ADDR_1 (*(vu16*) 0x08000b92)
|
||||||
|
#define SC_FLASH_MAGIC_ADDR_2 (*(vu16*) 0x0800046c)
|
||||||
|
#define SC_FLASH_MAGIC_1 ((u16) 0xaa)
|
||||||
|
#define SC_FLASH_MAGIC_2 ((u16) 0x55)
|
||||||
|
#define SC_FLASH_ERASE ((u16) 0x80)
|
||||||
|
#define SC_FLASH_ERASE_BLOCK ((u16) 0x30)
|
||||||
|
#define SC_FLASH_ERASE_CHIP ((u16) 0x10)
|
||||||
|
#define SC_FLASH_PROGRAM ((u16) 0xA0)
|
||||||
|
#define SC_FLASH_IDLE ((u16) 0xF0)
|
||||||
|
#define SC_FLASH_IDENTIFY ((u16) 0x90)
|
||||||
|
|
||||||
|
u32 sc_flash_id()
|
||||||
|
{
|
||||||
|
SC_FLASH_MAGIC_ADDR_1 = SC_FLASH_MAGIC_1;
|
||||||
|
SC_FLASH_MAGIC_ADDR_2 = SC_FLASH_MAGIC_2;
|
||||||
|
SC_FLASH_MAGIC_ADDR_1 = SC_FLASH_IDENTIFY;
|
||||||
|
|
||||||
|
// should equal 0x000422b9
|
||||||
|
u32 res = SC_FLASH_MAGIC_ADDR_1;
|
||||||
|
res |= *GBA_BUS << 16;
|
||||||
|
|
||||||
|
*GBA_BUS = SC_FLASH_IDLE;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void sc_flash_rw_enable()
|
||||||
|
{
|
||||||
|
bool buf = REG_IME;
|
||||||
|
REG_IME = 0;
|
||||||
|
SC_MODE_REG = SC_MODE_MAGIC;
|
||||||
|
SC_MODE_REG = SC_MODE_MAGIC;
|
||||||
|
SC_MODE_REG = SC_MODE_FLASH_RW;
|
||||||
|
SC_MODE_REG = SC_MODE_FLASH_RW;
|
||||||
|
REG_IME = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sc_flash_erase_chip()
|
||||||
|
{
|
||||||
|
bool buf = REG_IME;
|
||||||
|
REG_IME = 0;
|
||||||
|
SC_FLASH_MAGIC_ADDR_1 = SC_FLASH_MAGIC_1;
|
||||||
|
SC_FLASH_MAGIC_ADDR_2 = SC_FLASH_MAGIC_2;
|
||||||
|
SC_FLASH_MAGIC_ADDR_1 = SC_FLASH_ERASE;
|
||||||
|
SC_FLASH_MAGIC_ADDR_1 = SC_FLASH_MAGIC_1;
|
||||||
|
SC_FLASH_MAGIC_ADDR_2 = SC_FLASH_MAGIC_2;
|
||||||
|
SC_FLASH_MAGIC_ADDR_1 = SC_FLASH_ERASE_CHIP;
|
||||||
|
|
||||||
|
while (*GBA_BUS != *GBA_BUS) {
|
||||||
|
|
||||||
|
}
|
||||||
|
*GBA_BUS = SC_FLASH_IDLE;
|
||||||
|
REG_IME = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sc_flash_erase_block(vu16 *addr)
|
||||||
|
{
|
||||||
|
bool buf = REG_IME;
|
||||||
|
REG_IME = 0;
|
||||||
|
SC_FLASH_MAGIC_ADDR_1 = SC_FLASH_MAGIC_1;
|
||||||
|
SC_FLASH_MAGIC_ADDR_2 = SC_FLASH_MAGIC_2;
|
||||||
|
SC_FLASH_MAGIC_ADDR_1 = SC_FLASH_ERASE;
|
||||||
|
SC_FLASH_MAGIC_ADDR_1 = SC_FLASH_MAGIC_1;
|
||||||
|
SC_FLASH_MAGIC_ADDR_2 = SC_FLASH_MAGIC_2;
|
||||||
|
*addr = SC_FLASH_ERASE_BLOCK;
|
||||||
|
|
||||||
|
while (*GBA_BUS != *GBA_BUS) {
|
||||||
|
|
||||||
|
}
|
||||||
|
*GBA_BUS = SC_FLASH_IDLE;
|
||||||
|
REG_IME = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sc_flash_program(vu16 *addr, u16 val)
|
||||||
|
{
|
||||||
|
bool buf = REG_IME;
|
||||||
|
REG_IME = 0;
|
||||||
|
SC_FLASH_MAGIC_ADDR_1 = SC_FLASH_MAGIC_1;
|
||||||
|
SC_FLASH_MAGIC_ADDR_2 = SC_FLASH_MAGIC_2;
|
||||||
|
SC_FLASH_MAGIC_ADDR_1 = SC_FLASH_PROGRAM;
|
||||||
|
*addr = val;
|
||||||
|
|
||||||
|
while (*GBA_BUS != *GBA_BUS) {
|
||||||
|
|
||||||
|
}
|
||||||
|
*GBA_BUS = SC_FLASH_IDLE;
|
||||||
|
REG_IME = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
int main(void) {
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
consoleDemoInit();
|
||||||
|
|
||||||
|
sysSetCartOwner(true);
|
||||||
|
|
||||||
|
iprintf(" Death 2 supercard :3\n");
|
||||||
|
|
||||||
|
sc_flash_rw_enable();
|
||||||
|
|
||||||
|
iprintf(" Flash ID %lx\n", sc_flash_id());
|
||||||
|
|
||||||
|
iprintf(" Erasing whole chip\n");
|
||||||
|
sc_flash_erase_chip();
|
||||||
|
iprintf(" Erased whole chip\n");
|
||||||
|
|
||||||
|
for (u32 off = 0; off < scfw_bin_len; off += 2)
|
||||||
|
{
|
||||||
|
u16 val = 0;
|
||||||
|
val |= scfw_bin[off];
|
||||||
|
val |= scfw_bin[off+1] << 8;
|
||||||
|
sc_flash_program((vu16*) (0x08000000 + off), val);
|
||||||
|
if (!(off & 0x00ff))
|
||||||
|
iprintf(" Programmed %lx\n", 0x08000000 + off);
|
||||||
|
}
|
||||||
|
|
||||||
|
iprintf(" Ded!\n");
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user