Compare commits

...

42 Commits
v5.0 ... v5.4

Author SHA1 Message Date
Aurora
5b51574ebf We do not need all that space anymore 2016-04-30 03:34:28 +02:00
Aurora
df112b550b Move loadPayload to fs.c, and the path to the beginning of the chainloader 2016-04-29 17:22:13 +02:00
Aurora
85615d1916 Fix external FIRM loading 2016-04-29 15:21:49 +02:00
Aurora
c6d3158b56 Remade the chainloader to only try to load the right payload for the pressed button, got rid of the default payload (start now boots "start_NAME.bin"), sel_NAME is now select_NAME as there is no more SFN limitations anymore 2016-04-29 15:08:33 +02:00
Aurora
e651c3d9cc Small cleanup 2016-04-28 16:27:32 +02:00
Aurora
bfc2448662 Simplify makefiles 2016-04-28 00:43:25 +02:00
Aurora
5a9d0e2569 Fail 2016-04-27 16:16:25 +02:00
Aurora
041ca8451e Use the older cxi, should fix NANDs with incomplete background updates 2016-04-27 15:37:13 +02:00
Aurora
2382e6d82c Fixed oversight in the injector 2016-04-27 04:52:23 +02:00
Aurora
f9a1f1a79b Move the UNITINFO patch to the developer version 2016-04-26 21:51:57 +02:00
Aurora
a736e4602a Cleanup 2016-04-26 20:10:20 +02:00
Aurora
5202ba8826 Update ReadME 2016-04-26 14:33:01 +02:00
Aurora
0f1bc98bb7 Rename "Use SysNAND FIRM as default" to "SysNAND is updated" 2016-04-26 14:11:34 +02:00
Aurora
d40722af53 Apply the eShop update skipping patch only if the updated NAND was not booted (depends on the "Use SysNAND FIRM as default" option) 2016-04-26 14:05:48 +02:00
Aurora
c9781ab626 Added python implementation of the path changer from @TuxSH 2016-04-26 03:39:36 +02:00
Aurora
4cbf4e93e7 Minor stuff 2016-04-26 01:30:03 +02:00
Aurora
1f68c2da42 Update ReadME 2016-04-24 20:19:35 +02:00
Aurora
d786c292f3 Update submodules 2016-04-24 19:49:09 +02:00
Aurora
ada3e09784 Added L+A payload 2016-04-24 19:46:33 +02:00
Aurora
c928b3b68b New icon 2016-04-23 15:39:40 +02:00
Aurora
ae9c29629c Wrong name in the Makefile 2016-04-23 03:50:04 +02:00
Aurora
3fd4603553 Welcome Luma3DS 2016-04-23 01:43:36 +02:00
Aurora
c14526068a Minor stuff 2016-04-21 23:39:05 +02:00
Aurora
180b2a6f4d Bye bye fileSize! 2016-04-21 05:08:42 +02:00
Aurora
b926ab7dd2 Give 3ds_injector a sane makefile 2016-04-20 03:31:40 +02:00
Aurora
19d8861d27 Give 3ds_injector a sane makefile 2016-04-19 20:51:00 +02:00
Aurora
70e82e627b More cleanup 2016-04-19 17:28:18 +02:00
Aurora
67e229e5a9 Cleanup of the injector 2016-04-18 23:14:35 +02:00
Aurora
d0d6baaa85 We do not need this anymore (D9/E9/GM9 were updated) 2016-04-18 18:52:58 +02:00
Aurora
fd4352a1d6 Remove useless sdmmc code (we do not need NAND init/read from loader, or write at all 2016-04-18 18:29:37 +02:00
Aurora
08808da741 Update FatFs to 0.12 2016-04-18 18:04:04 +02:00
Aurora
a11124a3d6 Remove LFN support from the loader FatFs as it is not used. Slims down the binary by ~4 KBs 2016-04-18 04:47:53 +02:00
Aurora
d2d6e786c7 Fixed L+SELECT payload being broken (annoying LFN to 8.3 conversion rules). Now the payload is sel_NAME.bin 2016-04-18 02:55:54 +02:00
Aurora
a76c943c01 Reinstated the L+SELECT payload 2016-04-17 19:35:29 +02:00
Aurora
3c64a3a234 Updated ReadME 2016-04-17 19:11:38 +02:00
Aurora
06060c67b5 Changed the chainloader to load payloads named "BUTTON_NAME.bin", to remember which payload is which. Original idea and code by @habbbe (many thanks!) 2016-04-17 18:57:25 +02:00
Aurora
0f64fd73ec Fix bug when quitting AGB_FIRM
The wrong config.bin section was used to remember the last-used FIRM
2016-04-16 20:27:52 +02:00
Aurora
2323528975 Merge pull request #29 from habbbe/master
Made define for payload paths (removes repeated parts of file paths t…
2016-04-16 18:39:22 +02:00
habbbe
22b38a0f88 Made define for payload paths (removes repeated parts of file paths to payloads) 2016-04-16 18:21:42 +02:00
Aurora
034c0f8d7c Updated ReadME 2016-04-15 19:46:25 +02:00
Aurora
b4cd67cb8c Merge pull request #24 from ericchu94/master
Fix buffer overflow due to null character
2016-04-15 19:32:10 +02:00
Eric Chu
be83d77187 Fix buffer overflow due to null character 2016-04-15 12:54:30 -04:00
69 changed files with 6144 additions and 4524 deletions

Submodule CakeHax updated: 6b8fca0b37...5245c7b9dc

View File

@@ -11,7 +11,7 @@ AS := arm-none-eabi-as
LD := arm-none-eabi-ld LD := arm-none-eabi-ld
OC := arm-none-eabi-objcopy OC := arm-none-eabi-objcopy
name := AuReiNand name := Luma3DS
version := $(shell git describe --abbrev=0 --tags) version := $(shell git describe --abbrev=0 --tags)
dir_source := source dir_source := source
@@ -24,10 +24,10 @@ dir_ninjhax := CakeBrah
dir_build := build dir_build := build
dir_out := out dir_out := out
ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te ASFLAGS := -mcpu=arm946e-s
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2 -flto -ffast-math CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -fshort-wchar -std=c11 -Wno-main -O2 -flto -ffast-math
LDFLAGS := -nostartfiles LDFLAGS := -nostartfiles
FLAGS := name=$(name).dat dir_out=$(abspath $(dir_out)) ICON=$(abspath icon.png) APP_DESCRIPTION="Noob-friendly 3DS CFW." APP_AUTHOR="Reisyukaku/Aurora Wright" --no-print-directory FLAGS := name=$(name).dat dir_out=$(abspath $(dir_out)) ICON=$(abspath icon.png) APP_DESCRIPTION="Noob-friendly 3DS CFW." APP_AUTHOR="Aurora Wright" --no-print-directory
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
$(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \ $(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
@@ -48,10 +48,7 @@ a9lh: $(dir_out)/arm9loaderhax.bin
ninjhax: $(dir_out)/3ds/$(name) ninjhax: $(dir_out)/3ds/$(name)
.PHONY: release .PHONY: release
release: $(dir_out)/$(name).zip release: $(dir_out)/$(name)$(version).7z
.PHONY: pathchanger
pathchanger: $(dir_out)/pathchanger
.PHONY: clean .PHONY: clean
clean: clean:
@@ -63,10 +60,7 @@ clean:
@rm -rf $(dir_out) $(dir_build) @rm -rf $(dir_out) $(dir_build)
$(dir_out): $(dir_out):
@mkdir -p "$(dir_out)/aurei/payloads" @mkdir -p "$(dir_out)/luma/payloads"
$(dir_out)/pathchanger: $(dir_out)
@cc pathchanger/pathchanger.c -o out/pathchanger
$(dir_out)/$(name).dat: $(dir_build)/main.bin $(dir_out) $(dir_out)/$(name).dat: $(dir_build)/main.bin $(dir_out)
@$(MAKE) $(FLAGS) -C $(dir_mset) launcher @$(MAKE) $(FLAGS) -C $(dir_mset) launcher
@@ -80,14 +74,14 @@ $(dir_out)/3ds/$(name): $(dir_out)
@$(MAKE) $(FLAGS) -C $(dir_ninjhax) @$(MAKE) $(FLAGS) -C $(dir_ninjhax)
@mv $(dir_out)/$(name).3dsx $(dir_out)/$(name).smdh $@ @mv $(dir_out)/$(name).3dsx $(dir_out)/$(name).smdh $@
$(dir_out)/$(name).zip: launcher a9lh ninjhax $(dir_out)/$(name)$(version).7z: launcher a9lh ninjhax
@cd "$(@D)" && zip -9 -r $(name) * @7z a -mx $@ ./$(@D)/*
$(dir_build)/main.bin: $(dir_build)/main.elf $(dir_build)/main.bin: $(dir_build)/main.elf
$(OC) -S -O binary $< $@ $(OC) -S -O binary $< $@
$(dir_build)/main.elf: $(objects) $(dir_build)/main.elf: $(objects)
$(CC) $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^ $(LINK.o) -T linker.ld $(OUTPUT_OPTION) $^
$(dir_build)/patches.h: $(dir_patches)/emunand.s $(dir_patches)/reboot.s $(dir_injector)/Makefile $(dir_build)/patches.h: $(dir_patches)/emunand.s $(dir_patches)/reboot.s $(dir_injector)/Makefile
@mkdir -p "$(@D)" @mkdir -p "$(@D)"
@@ -107,8 +101,8 @@ $(dir_build)/screeninit.h: $(dir_screeninit)/Makefile
@mv $(dir_screeninit)/screeninit.bin $(@D) @mv $(dir_screeninit)/screeninit.bin $(@D)
@bin2c -o $@ -n screeninit $(@D)/screeninit.bin @bin2c -o $@ -n screeninit $(@D)/screeninit.bin
$(dir_build)/memory.o : CFLAGS += -O3 $(dir_build)/memory.o: CFLAGS += -O3
$(dir_build)/config.o : CFLAGS += -DCONFIG_TITLE="\"$(name) $(version) configuration\"" $(dir_build)/config.o: CFLAGS += -DCONFIG_TITLE="\"$(name) $(version) configuration\""
$(dir_build)/%.o: $(dir_source)/%.c $(bundled) $(dir_build)/%.o: $(dir_source)/%.c $(bundled)
@mkdir -p "$(@D)" @mkdir -p "$(@D)"
@@ -117,12 +111,4 @@ $(dir_build)/%.o: $(dir_source)/%.c $(bundled)
$(dir_build)/%.o: $(dir_source)/%.s $(dir_build)/%.o: $(dir_source)/%.s
@mkdir -p "$(@D)" @mkdir -p "$(@D)"
$(COMPILE.s) $(OUTPUT_OPTION) $< $(COMPILE.s) $(OUTPUT_OPTION) $<
$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.c
@mkdir -p "$(@D)"
$(COMPILE.c) $(OUTPUT_OPTION) $<
$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.s
@mkdir -p "$(@D)"
$(COMPILE.s) $(OUTPUT_OPTION) $<
include $(call rwildcard, $(dir_build), *.d) include $(call rwildcard, $(dir_build), *.d)

View File

@@ -1,36 +1,23 @@
# AuReiNand # Luma3DS
*A modification of the ReiNand custom firmware* *Noob-proof (N)3DS "Custom Firmware"*
**Compiling:** **Compiling:**
You'll need armips and [bin2c](https://sourceforge.net/projects/bin2c/) added to your Path. [HERE](http://www91.zippyshare.com/v/ePGpjk9r/file.html) is a pre-compiled version of armips. First you need to clone the repository recursively with: 'git clone --recursive https://github.com/AuroraWright/Luma3DS.git'
To compile, you'll need [armips](https://github.com/Kingcom/armips), [bin2c](https://sourceforge.net/projects/bin2c/), and a recent build of [makerom](https://github.com/profi200/Project_CTR) added to your PATH.
For your convenience, here are [Windows](http://www91.zippyshare.com/v/ePGpjk9r/file.html) and [Linux](https://mega.nz/#!uQ1T1IAD!Q91O0e12LXKiaXh_YjXD3D5m8_W3FuMI-hEa6KVMRDQ) builds of armips (thanks to who compiled them!).
Finally just run 'make' and everything should work!
You can find the compiled files in the 'out' folder.
You also need to have a recent build of makerom in your path for the injector to be built. **Setup / Usage / Features:**
Lastly, just run Make and everything should work! See https://github.com/AuroraWright/Luma3DS/wiki
Copy everything in 'out' folder to SD root and run!
**Usage / Features:**
See https://github.com/Reisyukaku/ReiNand and http://gbatemp.net/threads/reinand-mod-o3ds-n3ds-sysnand.411110
The FIRMs you need are [HERE](http://www77.zippyshare.com/v/oXDn2Hes/file.html).
**Credits:** **Credits:**
Rei as this is mostly his code. See https://github.com/AuroraWright/Luma3DS/wiki/Credits
The offset to detect the console, and to calculate the O3DS NAND CTR are from Decrypt9. **Licensing:**
tiniVi suggested me a way to detect a A9LH environment, and figured out screen deinit. This software is licensed under the terms of the GPLv3.
You can find a copy of the license in the LICENSE.txt file.
Delebile provided me with the FIRM writes blocking patch.
A skilled reverser gave me the new reboot patch.
The screen init code is from dark_samus, bil1s, Normmatt, delebile and everyone who contributed.
The code for printing to the screen, and the heavy revision to the reboot patch to allow for AGB/TWL loading are from CakesFW.
ARM11 userland patching is only possible thanks to @yifanlu's 3ds_injector, which is bundled in the CFW.

BIN
icon.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

170
injector/Makefile Normal file → Executable file
View File

@@ -1,161 +1,51 @@
#--------------------------------------------------------------------------------- rwildcard = $(foreach d, $(wildcard $1*), $(filter $(subst *, %, $2), $d) $(call rwildcard, $d/, $2))
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),) ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif endif
TOPDIR ?= $(CURDIR)
MAKEROM ?= makerom
include $(DEVKITARM)/3ds_rules include $(DEVKITARM)/3ds_rules
#--------------------------------------------------------------------------------- CC := arm-none-eabi-gcc
# TARGET is the name of the output AS := arm-none-eabi-as
# BUILD is the directory where object files & intermediate files will be placed LD := arm-none-eabi-ld
# SOURCES is a list of directories containing source code OC := arm-none-eabi-objcopy
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES := include
#--------------------------------------------------------------------------------- name := $(shell basename $(CURDIR))
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
CFLAGS := -flto -Wall -O2 -mword-relocations \ dir_source := source
-ffast-math -ffunction-sections -fdata-sections \ dir_build := build
$(ARCH)
CFLAGS += $(INCLUDE) -DARM11 -D_3DS LIBS := -lctru
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu99
ASFLAGS := $(ARCH)
LDFLAGS = -flto -Xlinker --defsym="__start__=0x14000000" -specs=3dsx.specs $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lctru
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(CTRULIB) LIBDIRS := $(CTRULIB)
LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
INCLUDE := $(foreach dir,$(LIBDIRS),-I$(dir)/include)
#--------------------------------------------------------------------------------- ARCH := -mcpu=mpcore -mfloat-abi=hard -mtp=soft
# no real need to edit anything past this point unless you need to add additional CFLAGS := -Wall -Wextra -MMD -MP -marm $(ARCH) -fno-builtin -std=c11 -O2 -flto -ffast-math -mword-relocations \
# rules for different file extensions -ffunction-sections -fdata-sections $(INCLUDE) -DARM11 -D_3DS
#--------------------------------------------------------------------------------- LDFLAGS := -Xlinker --defsym="__start__=0x14000000" -specs=3dsx.specs $(ARCH)
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET) objects = $(patsubst $(dir_source)/%.c, $(dir_build)/%.o, \
export TOPDIR := $(CURDIR) $(call rwildcard, $(dir_source), *.c))
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ .PHONY: all
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) all: $(name).cxi
export DEPSDIR := $(CURDIR)/$(BUILD) .PHONY: clean
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
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)) \
$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
all: $(BUILD)
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean: clean:
@echo clean ... @rm -rf $(dir_build)
@rm -fr $(BUILD) $(OUTPUT).cxi $(TARGET).elf
$(name).cxi: $(dir_build)/$(name).elf
@makerom -f ncch -rsf loader.rsf -nocodepadding -o $@ -elf $<
#--------------------------------------------------------------------------------- $(dir_build)/$(name).elf: $(objects)
else $(LINK.o) $(OUTPUT_OPTION) $^ $(LIBPATHS) $(LIBS)
DEPENDS := $(OFILES:.o=.d) $(dir_build)/memory.o : CFLAGS += -O3
#--------------------------------------------------------------------------------- $(dir_build)/%.o: $(dir_source)/%.c
# main targets @mkdir -p "$(@D)"
#--------------------------------------------------------------------------------- $(COMPILE.c) $(OUTPUT_OPTION) $<
$(OUTPUT).cxi : $(OUTPUT).elf include $(call rwildcard, $(dir_build), *.d)
$(MAKEROM) -f ncch -rsf ../loader.rsf -nocodepadding -o $@ -elf $<
$(OUTPUT).elf : $(OFILES)
#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
#---------------------------------------------------------------------------------
# rules for assembling GPU shaders
#---------------------------------------------------------------------------------
define shader-as
$(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@)))
picasso -o $(CURBIN) $1
bin2s $(CURBIN) | $(AS) -o $@
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
endef
%.shbin.o : %.v.pica %.g.pica
@echo $(notdir $^)
@$(call shader-as,$^)
%.shbin.o : %.v.pica
@echo $(notdir $<)
@$(call shader-as,$<)
%.shbin.o : %.shlist
@echo $(notdir $<)
@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file)))
-include $(DEPENDS)
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

View File

@@ -63,43 +63,4 @@ Result IFile_Read(IFile *file, u64 *total, void *buffer, u32 len)
*total = cur; *total = cur;
return res; return res;
} }
Result IFile_Write(IFile *file, u64 *total, void *buffer, u32 len, u32 flags)
{
u32 written;
u32 left;
char *buf;
u64 cur;
Result res;
if (len == 0)
{
*total = 0;
return 0;
}
buf = (char *)buffer;
cur = 0;
left = len;
while (1)
{
res = FSFILE_Write(file->handle, &written, file->pos, buf, left, flags);
if (R_FAILED(res))
{
break;
}
cur += written;
file->pos += written;
if (written == left)
{
break;
}
buf += written;
left -= written;
}
*total = cur;
return res;
}

View File

@@ -12,5 +12,4 @@ typedef struct
Result IFile_Open(IFile *file, FS_Archive archive, FS_Path path, u32 flags); Result IFile_Open(IFile *file, FS_Archive archive, FS_Path path, u32 flags);
Result IFile_Close(IFile *file); Result IFile_Close(IFile *file);
Result IFile_GetSize(IFile *file, u64 *size); Result IFile_GetSize(IFile *file, u64 *size);
Result IFile_Read(IFile *file, u64 *total, void *buffer, u32 len); Result IFile_Read(IFile *file, u64 *total, void *buffer, u32 len);
Result IFile_Write(IFile *file, u64 *total, void *buffer, u32 len, u32 flags);

View File

@@ -1,6 +1,5 @@
#include <3ds.h> #include <3ds.h>
#include <string.h> #include "memory.h"
#include <sys/iosupport.h>
#include "patcher.h" #include "patcher.h"
#include "exheader.h" #include "exheader.h"
#include "ifile.h" #include "ifile.h"
@@ -462,14 +461,14 @@ void __sync_init();
void __sync_fini(); void __sync_fini();
void __system_initSyscalls(); void __system_initSyscalls();
void __ctru_exit(int rc) void __ctru_exit()
{ {
__appExit(); __appExit();
__sync_fini(); __sync_fini();
svcExitProcess(); svcExitProcess();
} }
void initSystem(void (*retAddr)(void)) void initSystem()
{ {
__sync_init(); __sync_init();
__system_initSyscalls(); __system_initSyscalls();
@@ -521,7 +520,7 @@ int main()
if (R_FAILED(ret)) if (R_FAILED(ret))
{ {
// check if any handle has been closed // check if any handle has been closed
if (ret == 0xC920181A) if (ret == (int)0xC920181A)
{ {
if (index == -1) if (index == -1)
{ {

10
injector/source/memory.c Normal file
View File

@@ -0,0 +1,10 @@
#include "memory.h"
void memcpy(void *dest, const void *src, u32 size)
{
u8 *destc = (u8 *)dest;
const u8 *srcc = (const u8 *)src;
for(u32 i = 0; i < size; i++)
destc[i] = srcc[i];
}

5
injector/source/memory.h Normal file
View File

@@ -0,0 +1,5 @@
#pragma once
#include <3ds/types.h>
void memcpy(void *dest, const void *src, u32 size);

View File

@@ -1,17 +1,28 @@
#include <3ds.h> #include <3ds.h>
#include <string.h> #include "memory.h"
#include "patcher.h" #include "patcher.h"
#include "ifile.h" #include "ifile.h"
#ifndef PATH_MAX #ifndef PATH_MAX
#define PATH_MAX 255 #define PATH_MAX 255
#define CONFIG(a) ((config >> (a + 16)) & 1) #define CONFIG(a) ((loadConfig() >> (a + 16)) & 1)
#define MULTICONFIG(a) ((config >> (a * 2 + 6)) & 3) #define MULTICONFIG(a) ((loadConfig() >> (a * 2 + 6)) & 3)
#define BOOTCONFIG(a, b) ((config >> a) & b) #define BOOTCONFIG(a, b) ((loadConfig() >> a) & b)
#endif #endif
static u32 config = 0; static int memcmp(const void *buf1, const void *buf2, u32 size)
static u8 secureInfo[0x111] = {0}; {
const u8 *buf1c = (const u8 *)buf1;
const u8 *buf2c = (const u8 *)buf2;
for(u32 i = 0; i < size; i++)
{
int cmp = buf1c[i] - buf2c[i];
if(cmp) return cmp;
}
return 0;
}
//Quick Search algorithm, adapted from http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190 //Quick Search algorithm, adapted from http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190
static u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize) static u8 *memsearch(u8 *startPos, const void *pattern, u32 size, u32 patternSize)
@@ -62,6 +73,15 @@ static u32 patchMemory(u8 *start, u32 size, const void *pattern, u32 patSize, in
return i; return i;
} }
static inline size_t strnlen(const char *string, size_t maxlen)
{
size_t size;
for(size = 0; *string && size < maxlen; string++, size++);
return size;
}
static int fileOpen(IFile *file, FS_ArchiveID id, const char *path, int flags) static int fileOpen(IFile *file, FS_ArchiveID id, const char *path, int flags)
{ {
FS_Archive archive; FS_Archive archive;
@@ -79,55 +99,51 @@ static int fileOpen(IFile *file, FS_ArchiveID id, const char *path, int flags)
return IFile_Open(file, archive, ppath, flags); return IFile_Open(file, archive, ppath, flags);
} }
static int loadSecureInfo(void) static u32 secureInfoExists(void)
{ {
if(secureInfo[0] == 0xFF) static u32 secureInfoExists = 0;
return 0;
IFile file; if(!secureInfoExists)
Result ret = fileOpen(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ);
if(R_SUCCEEDED(ret))
{ {
u64 total; IFile file;
if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ)))
ret = IFile_Read(&file, &total, secureInfo, 0x111); {
IFile_Close(&file); secureInfoExists = 1;
if(R_SUCCEEDED(ret) && total == 0x111) IFile_Close(&file);
secureInfo[0] = 0xFF; }
} }
return ret; return secureInfoExists;
} }
static int loadConfig(void) static u32 loadConfig(void)
{ {
if(config) static u32 config = 0;
return 0;
IFile file; if(!config)
Result ret = fileOpen(&file, ARCHIVE_SDMC, "/aurei/config.bin", FS_OPEN_READ);
if(R_SUCCEEDED(ret))
{ {
u64 total; IFile file;
if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, "/luma/config.bin", FS_OPEN_READ)))
ret = IFile_Read(&file, &total, &config, 4); {
IFile_Close(&file); u64 total;
if(R_SUCCEEDED(ret)) config |= 1 << 4; if(R_SUCCEEDED(IFile_Read(&file, &total, &config, 4))) config |= 1 << 4;
IFile_Close(&file);
}
} }
return ret; return config;
} }
static int loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId) static int loadTitleLocaleConfig(u64 progId, u8 *regionId, u8 *languageId)
{ {
/* Here we look for "/aurei/locales/[u64 titleID in hex, uppercase].txt" /* Here we look for "/luma/locales/[u64 titleID in hex, uppercase].txt"
If it exists it should contain, for example, "EUR IT" */ If it exists it should contain, for example, "EUR IT" */
char path[] = "/aurei/locales/0000000000000000.txt"; char path[] = "/luma/locales/0000000000000000.txt";
u32 i = 30; u32 i = 29;
while(progId > 0) while(progId)
{ {
static const char hexDigits[] = "0123456789ABCDEF"; static const char hexDigits[] = "0123456789ABCDEF";
path[i--] = hexDigits[(u32)(progId & 0xF)]; path[i--] = hexDigits[(u32)(progId & 0xF)];
@@ -320,12 +336,6 @@ void patchCode(u64 progId, u8 *code, u32 size)
static const u8 blockAutoUpdatesPatch[] = { static const u8 blockAutoUpdatesPatch[] = {
0xE3, 0xA0 0xE3, 0xA0
}; };
static const u8 skipEshopUpdateCheckPattern[] = {
0x30, 0xB5, 0xF1, 0xB0
};
static const u8 skipEshopUpdateCheckPatch[] = {
0x00, 0x20, 0x08, 0x60, 0x70, 0x47
};
//Block silent auto-updates //Block silent auto-updates
patchMemory(code, size, patchMemory(code, size,
@@ -335,13 +345,24 @@ void patchCode(u64 progId, u8 *code, u32 size)
sizeof(blockAutoUpdatesPatch), 1 sizeof(blockAutoUpdatesPatch), 1
); );
//Skip update checks to access the EShop //Apply only if the updated NAND hasn't been booted
patchMemory(code, size, if((BOOTCONFIG(0, 3) != 0) == (BOOTCONFIG(3, 1) && CONFIG(1)))
skipEshopUpdateCheckPattern, {
sizeof(skipEshopUpdateCheckPattern), 0, static const u8 skipEshopUpdateCheckPattern[] = {
skipEshopUpdateCheckPatch, 0x30, 0xB5, 0xF1, 0xB0
sizeof(skipEshopUpdateCheckPatch), 1 };
); static const u8 skipEshopUpdateCheckPatch[] = {
0x00, 0x20, 0x08, 0x60, 0x70, 0x47
};
//Skip update checks to access the EShop
patchMemory(code, size,
skipEshopUpdateCheckPattern,
sizeof(skipEshopUpdateCheckPattern), 0,
skipEshopUpdateCheckPatch,
sizeof(skipEshopUpdateCheckPatch), 1
);
}
break; break;
} }
@@ -352,15 +373,15 @@ void patchCode(u64 progId, u8 *code, u32 size)
0xE0, 0x1E, 0xFF, 0x2F, 0xE1, 0x01, 0x01, 0x01 0xE0, 0x1E, 0xFF, 0x2F, 0xE1, 0x01, 0x01, 0x01
}; };
u8 *fdpVer = memsearch(code, fpdVerPattern, size, sizeof(fpdVerPattern)); static const u8 fpdVerPatch = 0x05;
if(fdpVer != NULL) //Allow online access to work with old friends modules
{ patchMemory(code, size,
fdpVer += sizeof(fpdVerPattern) + 1; fpdVerPattern,
sizeof(fpdVerPattern), 9,
//Allow online access to work with old friends modules &fpdVerPatch,
if(*fdpVer < 5) *fdpVer = 5; sizeof(fpdVerPatch), 1
} );
break; break;
} }
@@ -372,7 +393,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
case 0x0004001000027000LL: // KOR MSET case 0x0004001000027000LL: // KOR MSET
case 0x0004001000028000LL: // TWN MSET case 0x0004001000028000LL: // TWN MSET
{ {
if(R_SUCCEEDED(loadConfig()) && CONFIG(6)) if(CONFIG(5))
{ {
static const u16 verPattern[] = u"Ver."; static const u16 verPattern[] = u"Ver.";
const u32 currentNand = BOOTCONFIG(0, 3); const u32 currentNand = BOOTCONFIG(0, 3);
@@ -382,8 +403,8 @@ void patchCode(u64 progId, u8 *code, u32 size)
patchMemory(code, size, patchMemory(code, size,
verPattern, verPattern,
sizeof(verPattern) - sizeof(u16), 0, sizeof(verPattern) - sizeof(u16), 0,
!currentNand ? ((matchingFirm) ? u" Sys" : u"SysA") : !currentNand ? ((matchingFirm) ? u" Sys" : u"SysE") :
((currentNand == 1) ? (matchingFirm ? u" Emu" : u"EmuA") : ((matchingFirm) ? u"Emu2" : u"Em2A")), ((currentNand == 1) ? (matchingFirm ? u" Emu" : u"EmuS") : ((matchingFirm) ? u"Emu2" : u"Em2S")),
sizeof(verPattern) - sizeof(u16), 1 sizeof(verPattern) - sizeof(u16), 1
); );
} }
@@ -408,19 +429,21 @@ void patchCode(u64 progId, u8 *code, u32 size)
sizeof(stopCartUpdatesPatch), 2 sizeof(stopCartUpdatesPatch), 2
); );
if(R_SUCCEEDED(loadConfig()) && MULTICONFIG(1)) u32 cpuSetting = MULTICONFIG(1);
if(cpuSetting)
{ {
static const u8 cfgN3dsCpuPattern[] = { static const u8 cfgN3dsCpuPattern[] = {
0x40, 0xA0, 0xE1, 0x07, 0x00 0x00, 0x40, 0xA0, 0xE1, 0x07, 0x00
}; };
u8 *cfgN3dsCpuLoc = memsearch(code, cfgN3dsCpuPattern, size, sizeof(cfgN3dsCpuPattern)); u32 *cfgN3dsCpuLoc = (u32 *)memsearch(code, cfgN3dsCpuPattern, size, sizeof(cfgN3dsCpuPattern));
//Patch N3DS CPU Clock and L2 cache setting //Patch N3DS CPU Clock and L2 cache setting
if(cfgN3dsCpuLoc != NULL) if(cfgN3dsCpuLoc != NULL)
{ {
*(u32 *)(cfgN3dsCpuLoc + 3) = 0xE1A00000; *(cfgN3dsCpuLoc + 1) = 0xE1A00000;
*(u32 *)(cfgN3dsCpuLoc + 0x1F) = 0xE3A00000 | MULTICONFIG(1); *(cfgN3dsCpuLoc + 8) = 0xE3A00000 | cpuSetting;
} }
} }
@@ -444,7 +467,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
sizeof(secureinfoSigCheckPatch), 1 sizeof(secureinfoSigCheckPatch), 1
); );
if(R_SUCCEEDED(loadSecureInfo())) if(secureInfoExists())
{ {
static const u16 secureinfoFilenamePattern[] = u"SecureInfo_"; static const u16 secureinfoFilenamePattern[] = u"SecureInfo_";
static const u16 secureinfoFilenamePatch[] = u"C"; static const u16 secureinfoFilenamePatch[] = u"C";
@@ -463,7 +486,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
} }
default: default:
if(R_SUCCEEDED(loadConfig()) && CONFIG(4)) if(CONFIG(4))
{ {
u32 tidHigh = (progId & 0xFFFFFFF000000000LL) >> 0x24; u32 tidHigh = (progId & 0xFFFFFFF000000000LL) >> 0x24;
@@ -473,9 +496,7 @@ void patchCode(u64 progId, u8 *code, u32 size)
u8 regionId = 0xFF, u8 regionId = 0xFF,
languageId = 0xFF; languageId = 0xFF;
int ret = loadTitleLocaleConfig(progId, &regionId, &languageId); if(R_SUCCEEDED(loadTitleLocaleConfig(progId, &regionId, &languageId)))
if(R_SUCCEEDED(ret))
{ {
u32 CFGUHandleOffset; u32 CFGUHandleOffset;
@@ -488,8 +509,8 @@ void patchCode(u64 progId, u8 *code, u32 size)
} }
} }
} }
}
break; break;
}
} }
} }

View File

@@ -16,8 +16,8 @@ name := $(shell basename $(CURDIR))
dir_source := source dir_source := source
dir_build := build dir_build := build
ASFLAGS := -mlittle-endian -mcpu=arm946e-s -march=armv5te ASFLAGS := -mcpu=arm946e-s
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -std=c11 -Wno-main -O2 -flto -ffast-math -mthumb -mthumb-interwork CFLAGS := -Wall -Wextra -MMD -MP -mthumb -mthumb-interwork $(ASFLAGS) -fno-builtin -std=c11 -Wno-main -O2 -flto -ffast-math
LDFLAGS := -nostartfiles LDFLAGS := -nostartfiles
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
@@ -35,7 +35,7 @@ $(name).bin: $(dir_build)/$(name).elf
$(OC) -S -O binary $< $@ $(OC) -S -O binary $< $@
$(dir_build)/$(name).elf: $(objects) $(dir_build)/$(name).elf: $(objects)
$(CC) $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^ $(LINK.o) -T linker.ld $(OUTPUT_OPTION) $^
$(dir_build)/%.o: $(dir_source)/%.c $(dir_build)/%.o: $(dir_source)/%.c
@mkdir -p "$(@D)" @mkdir -p "$(@D)"
@@ -44,12 +44,4 @@ $(dir_build)/%.o: $(dir_source)/%.c
$(dir_build)/%.o: $(dir_source)/%.s $(dir_build)/%.o: $(dir_source)/%.s
@mkdir -p "$(@D)" @mkdir -p "$(@D)"
$(COMPILE.s) $(OUTPUT_OPTION) $< $(COMPILE.s) $(OUTPUT_OPTION) $<
$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.c
@mkdir -p "$(@D)"
$(COMPILE.c) $(OUTPUT_OPTION) $<
$(dir_build)/fatfs/%.o: $(dir_source)/fatfs/%.s
@mkdir -p "$(@D)"
$(COMPILE.s) $(OUTPUT_OPTION) $<
include $(call rwildcard, $(dir_build), *.d) include $(call rwildcard, $(dir_build), *.d)

View File

@@ -1,13 +0,0 @@
#pragma once
#include "types.h"
#define HID_PAD (*(vu32 *)0x10146000 ^ 0xFFF)
#define BUTTON_X (1 << 10)
#define BUTTON_Y (1 << 11)
#define BUTTON_R1 (1 << 8)
#define BUTTON_SELECT (1 << 2)
#define BUTTON_RIGHT (1 << 4)
#define BUTTON_LEFT (1 << 5)
#define BUTTON_UP (1 << 6)
#define BUTTON_DOWN (1 << 7)

11
loader/source/fatfs/00history.txt Executable file → Normal file
View File

@@ -193,7 +193,7 @@ R0.10 (October 02, 2013)
Improved write throughput of f_puts() and f_printf(). Improved write throughput of f_puts() and f_printf().
Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write(). Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
Fixed f_write() can be truncated when the file size is close to 4GB. Fixed f_write() can be truncated when the file size is close to 4GB.
Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code. Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect value on error.
@@ -243,3 +243,12 @@ R0.11a (September 05, 2015)
Fixed errors in the case conversion teble of Unicode (cc*.c). Fixed errors in the case conversion teble of Unicode (cc*.c).
R0.12 (April 12, 2016)
Added support of exFAT file system. (_FS_EXFAT)
Added f_expand(). (_USE_EXPAND)
Changed some members in FINFO structure and behavior of f_readdir().
Added an option _USE_CHMOD and removed an option _WORD_ACCESS.
Fixed errors in the case conversion teble of Unicode (cc*.c).

View File

@@ -1,21 +1,21 @@
FatFs Module Source Files R0.11 FatFs Module Source Files R0.12
FILES FILES
00readme.txt This file. 00readme.txt This file.
history.txt Revision history. history.txt Revision history.
ffconf.h Configuration file for FatFs module. ffconf.h Configuration file for FatFs module.
ff.h Common include file for FatFs and application module. ff.h Common include file for FatFs and application module.
ff.c FatFs module. ff.c FatFs module.
diskio.h Common include file for FatFs and disk I/O module. diskio.h Common include file for FatFs and disk I/O module.
diskio.c An example of glue function to attach existing disk I/O module to FatFs. diskio.c An example of glue function to attach existing disk I/O module to FatFs.
integer.h Integer type definitions for FatFs. integer.h Integer type definitions for FatFs.
option Optional external functions. option Optional external functions.
Low level disk I/O module is not included in this archive because the FatFs Low level disk I/O module is not included in this archive because the FatFs
module is only a generic file system layer and not depend on any specific module is only a generic file system layer and not depend on any specific
storage device. You have to provide a low level disk I/O module that written storage device. You have to provide a low level disk I/O module that written
to control the target storage device. to control the target storage device.

View File

@@ -10,7 +10,6 @@
#include "diskio.h" /* FatFs lower layer API */ #include "diskio.h" /* FatFs lower layer API */
#include "sdmmc/sdmmc.h" #include "sdmmc/sdmmc.h"
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* Get Drive Status */ /* Get Drive Status */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
@@ -69,14 +68,14 @@ DRESULT disk_read (
DRESULT disk_write ( DRESULT disk_write (
__attribute__((unused)) __attribute__((unused))
BYTE pdrv, /* Physical drive nmuber to identify the drive */ BYTE pdrv, /* Physical drive nmuber to identify the drive */
__attribute__((unused))
const BYTE *buff, /* Data to be written */ const BYTE *buff, /* Data to be written */
__attribute__((unused))
DWORD sector, /* Sector address in LBA */ DWORD sector, /* Sector address in LBA */
__attribute__((unused))
UINT count /* Number of sectors to write */ UINT count /* Number of sectors to write */
) )
{ {
if(sdmmc_sdcard_writesectors(sector, count, (BYTE *)buff))
return RES_PARERR;
return RES_OK; return RES_OK;
} }
#endif #endif

3933
loader/source/fatfs/ff.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

170
loader/source/fatfs/ff.h Executable file → Normal file
View File

@@ -1,10 +1,10 @@
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ FatFs - FAT file system module include R0.11a (C)ChaN, 2015 / FatFs - FAT file system module include R0.12 (C)ChaN, 2016
/----------------------------------------------------------------------------/ /----------------------------------------------------------------------------/
/ FatFs module is a free software that opened under license policy of / FatFs module is a free software that opened under license policy of
/ following conditions. / following conditions.
/ /
/ Copyright (C) 2015, ChaN, all right reserved. / Copyright (C) 2016, ChaN, all right reserved.
/ /
/ 1. Redistributions of source code must retain the above copyright notice, / 1. Redistributions of source code must retain the above copyright notice,
/ this condition and the following disclaimer. / this condition and the following disclaimer.
@@ -17,7 +17,7 @@
#ifndef _FATFS #ifndef _FATFS
#define _FATFS 64180 /* Revision ID */ #define _FATFS 88100 /* Revision ID */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -53,7 +53,7 @@ extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
/* Type of path name strings on FatFs API */ /* Type of path name strings on FatFs API */
#if _LFN_UNICODE /* Unicode string */ #if _LFN_UNICODE /* Unicode string */
#if !_USE_LFN #if _USE_LFN == 0
#error _LFN_UNICODE must be 0 at non-LFN cfg. #error _LFN_UNICODE must be 0 at non-LFN cfg.
#endif #endif
#ifndef _INC_TCHAR #ifndef _INC_TCHAR
@@ -76,51 +76,91 @@ typedef char TCHAR;
/* File system object structure (FATFS) */ /* File system object structure (FATFS) */
typedef struct { typedef struct {
BYTE fs_type; /* FAT sub-type (0:Not mounted) */ BYTE fs_type; /* File system type (0:N/A) */
BYTE drv; /* Physical drive number */ BYTE drv; /* Physical drive number */
BYTE csize; /* Sectors per cluster (1,2,4...128) */ BYTE n_fats; /* Number of FATs (1 or 2) */
BYTE n_fats; /* Number of FAT copies (1 or 2) */
BYTE wflag; /* win[] flag (b0:dirty) */ BYTE wflag; /* win[] flag (b0:dirty) */
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */ BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
WORD id; /* File system mount ID */ WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
WORD csize; /* Cluster size [sectors] */
#if _MAX_SS != _MIN_SS #if _MAX_SS != _MIN_SS
WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */ WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
#endif
#if _FS_EXFAT
BYTE* dirbuf; /* Directory entry block scratchpad buffer */
#endif #endif
#if _FS_REENTRANT #if _FS_REENTRANT
_SYNC_t sobj; /* Identifier of sync object */ _SYNC_t sobj; /* Identifier of sync object */
#endif #endif
#if !_FS_READONLY #if !_FS_READONLY
DWORD last_clust; /* Last allocated cluster */ DWORD last_clst; /* Last allocated cluster */
DWORD free_clust; /* Number of free clusters */ DWORD free_clst; /* Number of free clusters */
#endif #endif
#if _FS_RPATH #if _FS_RPATH != 0
DWORD cdir; /* Current directory start cluster (0:root) */ DWORD cdir; /* Current directory start cluster (0:root) */
#if _FS_EXFAT
DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */
DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */
DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */
#endif #endif
DWORD n_fatent; /* Number of FAT entries, = number of clusters + 2 */ #endif
DWORD fsize; /* Sectors per FAT */ DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
DWORD volbase; /* Volume start sector */ DWORD fsize; /* Size of an FAT [sectors] */
DWORD fatbase; /* FAT start sector */ DWORD volbase; /* Volume base sector */
DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */ DWORD fatbase; /* FAT base sector */
DWORD database; /* Data start sector */ DWORD dirbase; /* Root directory base sector/cluster */
DWORD database; /* Data base sector */
DWORD winsect; /* Current sector appearing in the win[] */ DWORD winsect; /* Current sector appearing in the win[] */
BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */ BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
} FATFS; } FATFS;
/* Type of file size variables and object identifier */
#if _FS_EXFAT
#if _USE_LFN == 0
#error LFN must be enabled when enable exFAT
#endif
typedef QWORD FSIZE_t;
#else
typedef DWORD FSIZE_t;
#endif
/* Object ID and allocation information (_FDID) */
typedef struct {
FATFS* fs; /* Pointer to the owner file system object */
WORD id; /* Owner file system mount ID */
BYTE attr; /* Object attribute */
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous (no data on FAT), =3:got flagmented, b2:sub-directory stretched) */
DWORD sclust; /* Object start cluster (0:no cluster or root directory) */
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
#if _FS_EXFAT
DWORD n_cont; /* Size of coutiguous part, clusters - 1 (valid when stat == 3) */
DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */
DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */
DWORD c_ofs; /* Offset in the containing directory (valid when sclust != 0) */
#endif
#if _FS_LOCK != 0
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
#endif
} _FDID;
/* File object structure (FIL) */ /* File object structure (FIL) */
typedef struct { typedef struct {
FATFS* fs; /* Pointer to the related file system object (**do not change order**) */ _FDID obj; /* Object identifier */
WORD id; /* Owner file system mount ID (**do not change order**) */ BYTE flag; /* File status flags */
BYTE flag; /* Status flags */
BYTE err; /* Abort flag (error code) */ BYTE err; /* Abort flag (error code) */
DWORD fptr; /* File read/write pointer (Zeroed on file open) */ FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
DWORD fsize; /* File size */
DWORD sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */
DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */ DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */
DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */ DWORD sect; /* Sector number appearing in buf[] (0:invalid) */
#if !_FS_READONLY #if !_FS_READONLY
DWORD dir_sect; /* Sector number containing the directory entry */ DWORD dir_sect; /* Sector number containing the directory entry */
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */ BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */
@@ -128,9 +168,6 @@ typedef struct {
#if _USE_FASTSEEK #if _USE_FASTSEEK
DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */ DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */
#endif #endif
#if _FS_LOCK
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
#endif
#if !_FS_TINY #if !_FS_TINY
BYTE buf[_MAX_SS]; /* File private data read/write window */ BYTE buf[_MAX_SS]; /* File private data read/write window */
#endif #endif
@@ -141,23 +178,18 @@ typedef struct {
/* Directory object structure (DIR) */ /* Directory object structure (DIR) */
typedef struct { typedef struct {
FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */ _FDID obj; /* Object identifier */
WORD id; /* Owner file system mount ID (**do not change order**) */ DWORD dptr; /* Current read/write offset */
WORD index; /* Current read/write index number */
DWORD sclust; /* Table start cluster (0:Root dir) */
DWORD clust; /* Current cluster */ DWORD clust; /* Current cluster */
DWORD sect; /* Current sector */ DWORD sect; /* Current sector */
BYTE* dir; /* Pointer to the current SFN entry in the win[] */ BYTE* dir; /* Pointer to the directory item in the win[] */
BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */ BYTE* fn; /* Pointer to the SFN (in/out) {body[8],ext[3],status[1]} */
#if _FS_LOCK #if _USE_LFN != 0
UINT lockid; /* File lock ID (index of file semaphore table Files[]) */ DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
#endif
#if _USE_LFN
WCHAR* lfn; /* Pointer to the LFN working buffer */ WCHAR* lfn; /* Pointer to the LFN working buffer */
WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
#endif #endif
#if _USE_FIND #if _USE_FIND
const TCHAR* pat; /* Pointer to the name matching pattern */ const TCHAR* pat; /* Pointer to the name matching pattern */
#endif #endif
} DIR; } DIR;
@@ -166,14 +198,15 @@ typedef struct {
/* File information structure (FILINFO) */ /* File information structure (FILINFO) */
typedef struct { typedef struct {
DWORD fsize; /* File size */ FSIZE_t fsize; /* File size */
WORD fdate; /* Last modified date */ WORD fdate; /* Modified date */
WORD ftime; /* Last modified time */ WORD ftime; /* Modified time */
BYTE fattrib; /* Attribute */ BYTE fattrib; /* File attribute */
TCHAR fname[13]; /* Short file name (8.3 format) */ #if _USE_LFN != 0
#if _USE_LFN TCHAR altname[13]; /* Altenative file name */
TCHAR* lfname; /* Pointer to the LFN buffer */ TCHAR fname[_MAX_LFN + 1]; /* Primary file name */
UINT lfsize; /* Size of LFN buffer in TCHAR */ #else
TCHAR fname[13]; /* File name */
#endif #endif
} FILINFO; } FILINFO;
@@ -213,8 +246,7 @@ FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a f
FRESULT f_close (FIL* fp); /* Close an open file object */ FRESULT f_close (FIL* fp); /* Close an open file object */
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */ FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */ FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */ FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of a file object */
FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */
FRESULT f_truncate (FIL* fp); /* Truncate file */ FRESULT f_truncate (FIL* fp); /* Truncate file */
FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */ FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */ FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
@@ -227,13 +259,15 @@ FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or direc
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */ FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */ FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of the file/dir */ FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of the file/dir */
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */ FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of the file/dir */
FRESULT f_chdir (const TCHAR* path); /* Change current directory */ FRESULT f_chdir (const TCHAR* path); /* Change current directory */
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */ FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */ FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */ FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */ FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */ FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt); /* Allocate a contiguous block to the file */
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */ FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */ FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */
FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */ FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
@@ -242,10 +276,10 @@ int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */ int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
#define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize)) #define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
#define f_error(fp) ((fp)->err) #define f_error(fp) ((fp)->err)
#define f_tell(fp) ((fp)->fptr) #define f_tell(fp) ((fp)->fptr)
#define f_size(fp) ((fp)->fsize) #define f_size(fp) ((fp)->obj.objsize)
#define f_rewind(fp) f_lseek((fp), 0) #define f_rewind(fp) f_lseek((fp), 0)
#define f_rewinddir(dp) f_readdir((dp), 0) #define f_rewinddir(dp) f_readdir((dp), 0)
@@ -265,7 +299,7 @@ DWORD get_fattime (void);
#endif #endif
/* Unicode support functions */ /* Unicode support functions */
#if _USE_LFN /* Unicode - OEM code conversion */ #if _USE_LFN != 0 /* Unicode - OEM code conversion */
WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */ WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */
WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */ WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */
#if _USE_LFN == 3 /* Memory functions */ #if _USE_LFN == 3 /* Memory functions */
@@ -292,16 +326,13 @@ int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
/* File access control and file status flags (FIL.flag) */ /* File access control and file status flags (FIL.flag) */
#define FA_READ 0x01 #define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00
#if !_FS_READONLY
#define FA_WRITE 0x02 #define FA_WRITE 0x02
#define FA_OPEN_EXISTING 0x00
#define FA_CREATE_NEW 0x04 #define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08 #define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10 #define FA_OPEN_ALWAYS 0x10
#define FA__WRITTEN 0x20 #define _FA_MODIFIED 0x20
#define FA__DIRTY 0x40 #define _FA_DIRTY 0x40
#endif
/* FAT sub type (FATFS.fs_type) */ /* FAT sub type (FATFS.fs_type) */
@@ -309,6 +340,7 @@ int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
#define FS_FAT12 1 #define FS_FAT12 1
#define FS_FAT16 2 #define FS_FAT16 2
#define FS_FAT32 3 #define FS_FAT32 3
#define FS_EXFAT 4
/* File attribute bits for directory entry */ /* File attribute bits for directory entry */
@@ -323,26 +355,10 @@ int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
#define AM_MASK 0x3F /* Mask of defined bits */ #define AM_MASK 0x3F /* Mask of defined bits */
/* Fast seek feature */ /* Fast seek controls */
#define CREATE_LINKMAP 0xFFFFFFFF #define CREATE_LINKMAP ((FSIZE_t)0 - 1)
/*--------------------------------*/
/* Multi-byte word access macros */
#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
#else /* Use byte-by-byte access to the FAT structure */
#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

144
loader/source/fatfs/ffconf.h Executable file → Normal file
View File

@@ -1,8 +1,8 @@
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ FatFs - FAT file system module configuration file R0.11a (C)ChaN, 2015 / FatFs - FAT file system module configuration file R0.12 (C)ChaN, 2016
/---------------------------------------------------------------------------*/ /---------------------------------------------------------------------------*/
#define _FFCONF 64180 /* Revision ID */ #define _FFCONF 88100 /* Revision ID */
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ Function Configurations / Function Configurations
@@ -19,8 +19,8 @@
/* This option defines minimization level to remove some basic API functions. /* This option defines minimization level to remove some basic API functions.
/ /
/ 0: All basic functions are enabled. / 0: All basic functions are enabled.
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(), / 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
/ f_truncate() and f_rename() function are removed. / are removed.
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. / 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
/ 3: f_lseek() function is removed in addition to 2. */ / 3: f_lseek() function is removed in addition to 2. */
@@ -35,8 +35,8 @@
#define _USE_FIND 0 #define _USE_FIND 0
/* This option switches filtered directory read feature and related functions, /* This option switches filtered directory read functions, f_findfirst() and
/ f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */ / f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
#define _USE_MKFS 0 #define _USE_MKFS 0
@@ -44,7 +44,16 @@
#define _USE_FASTSEEK 0 #define _USE_FASTSEEK 0
/* This option switches fast seek feature. (0:Disable or 1:Enable) */ /* This option switches fast seek function. (0:Disable or 1:Enable) */
#define _USE_EXPAND 0
/* This option switches f_expand function. (0:Disable or 1:Enable) */
#define _USE_CHMOD 0
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
/ (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */
#define _USE_LABEL 0 #define _USE_LABEL 0
@@ -54,14 +63,14 @@
#define _USE_FORWARD 0 #define _USE_FORWARD 0
/* This option switches f_forward() function. (0:Disable or 1:Enable) /* This option switches f_forward() function. (0:Disable or 1:Enable)
/ To enable it, also _FS_TINY need to be set to 1. */ / To enable it, also _FS_TINY need to be 1. */
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations / Locale and Namespace Configurations
/---------------------------------------------------------------------------*/ /---------------------------------------------------------------------------*/
#define _CODE_PAGE 437 #define _CODE_PAGE 1
/* This option specifies the OEM code page to be used on the target system. /* This option specifies the OEM code page to be used on the target system.
/ Incorrect setting of the code page can cause a file open failure. / Incorrect setting of the code page can cause a file open failure.
/ /
@@ -90,17 +99,19 @@
*/ */
#define _USE_LFN 2 #define _USE_LFN 0
#define _MAX_LFN 255 #define _MAX_LFN 255
/* The _USE_LFN option switches the LFN feature. /* The _USE_LFN switches the support of long file name (LFN).
/ /
/ 0: Disable LFN feature. _MAX_LFN has no effect. / 0: Disable support of LFN. _MAX_LFN has no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. / 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
/ 2: Enable LFN with dynamic working buffer on the STACK. / 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP. / 3: Enable LFN with dynamic working buffer on the HEAP.
/ /
/ When enable the LFN feature, Unicode handling functions (option/unicode.c) must / To enable the LFN, Unicode handling functions (option/unicode.c) must be added
/ be added to the project. The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. / to the project. The working buffer occupies (_MAX_LFN + 1) * 2 bytes and
/ additional 608 bytes at exFAT enabled. _MAX_LFN can be in range from 12 to 255.
/ It should be set 255 to support full featured LFN operations.
/ When use stack for the working buffer, take care on stack overflow. When use heap / When use stack for the working buffer, take care on stack overflow. When use heap
/ memory for the working buffer, memory management functions, ff_memalloc() and / memory for the working buffer, memory management functions, ff_memalloc() and
/ ff_memfree(), must be added to the project. */ / ff_memfree(), must be added to the project. */
@@ -108,12 +119,12 @@
#define _LFN_UNICODE 0 #define _LFN_UNICODE 0
/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode) /* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)
/ To use Unicode string for the path name, enable LFN feature and set _LFN_UNICODE / To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1.
/ to 1. This option also affects behavior of string I/O functions. */ / This option also affects behavior of string I/O functions. */
#define _STRF_ENCODE 3 #define _STRF_ENCODE 3
/* When _LFN_UNICODE is 1, this option selects the character encoding on the file to /* When _LFN_UNICODE == 1, this option selects the character encoding on the file to
/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf(). / be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
/ /
/ 0: ANSI/OEM / 0: ANSI/OEM
@@ -121,17 +132,16 @@
/ 2: UTF-16BE / 2: UTF-16BE
/ 3: UTF-8 / 3: UTF-8
/ /
/ When _LFN_UNICODE is 0, this option has no effect. */ / This option has no effect when _LFN_UNICODE == 0. */
#define _FS_RPATH 0 #define _FS_RPATH 0
/* This option configures relative path feature. /* This option configures support of relative path.
/ /
/ 0: Disable relative path feature and remove related functions. / 0: Disable relative path and remove related functions.
/ 1: Enable relative path feature. f_chdir() and f_chdrive() are available. / 1: Enable relative path. f_chdir() and f_chdrive() are available.
/ 2: f_getcwd() function is available in addition to 1. / 2: f_getcwd() function is available in addition to 1.
/ */
/ Note that directory items read via f_readdir() are affected by this option. */
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
@@ -144,7 +154,7 @@
#define _STR_VOLUME_ID 0 #define _STR_VOLUME_ID 0
#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3" #define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
/* _STR_VOLUME_ID option switches string volume ID feature. /* _STR_VOLUME_ID switches string support of volume ID.
/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive / When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
/ number in the path name. _VOLUME_STRS defines the drive ID strings for each / number in the path name. _VOLUME_STRS defines the drive ID strings for each
/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for / logical drives. Number of items must be equal to _VOLUMES. Valid characters for
@@ -152,11 +162,12 @@
#define _MULTI_PARTITION 0 #define _MULTI_PARTITION 0
/* This option switches multi-partition feature. By default (0), each logical drive /* This option switches support of multi-partition on a physical drive.
/ number is bound to the same physical drive number and only an FAT volume found on / By default (0), each logical drive number is bound to the same physical drive
/ the physical drive will be mounted. When multi-partition feature is enabled (1), / number and only an FAT volume found on the physical drive will be mounted.
/ each logical drive number is bound to arbitrary physical drive and partition / When multi-partition is enabled (1), each logical drive number can be bound to
/ listed in the VolToPart[]. Also f_fdisk() funciton will be available. */ / arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
/ funciton will be available. */
#define _MIN_SS 512 #define _MIN_SS 512
@@ -170,8 +181,8 @@
#define _USE_TRIM 0 #define _USE_TRIM 0
/* This option switches ATA-TRIM feature. (0:Disable or 1:Enable) /* This option switches support of ATA-TRIM. (0:Disable or 1:Enable)
/ To enable Trim feature, also CTRL_TRIM command should be implemented to the / To enable Trim function, also CTRL_TRIM command should be implemented to the
/ disk_ioctl() function. */ / disk_ioctl() function. */
@@ -194,46 +205,51 @@
#define _FS_TINY 0 #define _FS_TINY 0
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) /* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
/ At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS / At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS bytes.
/ bytes. Instead of private sector buffer eliminated from the file object, / Instead of private sector buffer eliminated from the file object, common sector
/ common sector buffer in the file system object (FATFS) is used for the file / buffer in the file system object (FATFS) is used for the file data transfer. */
/ data transfer. */
#define _FS_EXFAT 0
/* This option switches support of exFAT file system in addition to the traditional
/ FAT file system. (0:Disable or 1:Enable) To enable exFAT, also LFN must be enabled.
/ Note that enabling exFAT discards C89 compatibility. */
#define _FS_NORTC 1 #define _FS_NORTC 1
#define _NORTC_MON 1 #define _NORTC_MON 3
#define _NORTC_MDAY 1 #define _NORTC_MDAY 1
#define _NORTC_YEAR 2015 #define _NORTC_YEAR 2016
/* The _FS_NORTC option switches timestamp feature. If the system does not have /* The option _FS_NORTC switches timestamp functiton. If the system does not have
/ an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable / any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable
/ the timestamp feature. All objects modified by FatFs will have a fixed timestamp / the timestamp function. All objects modified by FatFs will have a fixed timestamp
/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR. / defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR in local time.
/ When timestamp feature is enabled (_FS_NORTC == 0), get_fattime() function need / To enable timestamp function (_FS_NORTC = 0), get_fattime() function need to be
/ to be added to the project to read current time form RTC. _NORTC_MON, / added to the project to get current time form real-time clock. _NORTC_MON,
/ _NORTC_MDAY and _NORTC_YEAR have no effect. / _NORTC_MDAY and _NORTC_YEAR have no effect.
/ These options have no effect at read-only configuration (_FS_READONLY == 1). */ / These options have no effect at read-only configuration (_FS_READONLY = 1). */
#define _FS_LOCK 0 #define _FS_LOCK 0
/* The _FS_LOCK option switches file lock feature to control duplicated file open /* The option _FS_LOCK switches file lock function to control duplicated file open
/ and illegal operation to open objects. This option must be 0 when _FS_READONLY / and illegal operation to open objects. This option must be 0 when _FS_READONLY
/ is 1. / is 1.
/ /
/ 0: Disable file lock feature. To avoid volume corruption, application program / 0: Disable file lock function. To avoid volume corruption, application program
/ should avoid illegal open, remove and rename to the open objects. / should avoid illegal open, remove and rename to the open objects.
/ >0: Enable file lock feature. The value defines how many files/sub-directories / >0: Enable file lock function. The value defines how many files/sub-directories
/ can be opened simultaneously under file lock control. Note that the file / can be opened simultaneously under file lock control. Note that the file
/ lock feature is independent of re-entrancy. */ / lock control is independent of re-entrancy. */
#define _FS_REENTRANT 0 #define _FS_REENTRANT 0
#define _FS_TIMEOUT 1000 #define _FS_TIMEOUT 1000
#define _SYNC_t HANDLE #define _SYNC_t HANDLE
/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs /* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
/ module itself. Note that regardless of this option, file access to different / module itself. Note that regardless of this option, file access to different
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() / volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
/ and f_fdisk() function, are always not re-entrant. Only file/directory access / and f_fdisk() function, are always not re-entrant. Only file/directory access
/ to the same volume is under control of this feature. / to the same volume is under control of this function.
/ /
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect. / 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
/ 1: Enable re-entrancy. Also user provided synchronization handlers, / 1: Enable re-entrancy. Also user provided synchronization handlers,
@@ -247,30 +263,4 @@
/ included somewhere in the scope of ff.c. */ / included somewhere in the scope of ff.c. */
#define _WORD_ACCESS 0 /*--- End of configuration options ---*/
/* The _WORD_ACCESS option is an only platform dependent option. It defines
/ which access method is used to the word data on the FAT volume.
/
/ 0: Byte-by-byte access. Always compatible with all platforms.
/ 1: Word access. Do not choose this unless under both the following conditions.
/
/ * Address misaligned memory access is always allowed to ALL instructions.
/ * Byte order on the memory is little-endian.
/
/ If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.
/ Following table shows allowable settings of some type of processors.
/
/ ARM7TDMI 0 *2 ColdFire 0 *1 V850E 0 *2
/ Cortex-M3 0 *3 Z80 0/1 V850ES 0/1
/ Cortex-M0 0 *2 x86 0/1 TLCS-870 0/1
/ AVR 0/1 RX600(LE) 0/1 TLCS-900 0/1
/ AVR32 0 *1 RL78 0 *2 R32C 0 *2
/ PIC18 0/1 SH-2 0 *1 M16C 0/1
/ PIC24 0 *2 H8S 0 *1 MSP430 0 *2
/ PIC32 0 *1 H8/300H 0 *1 8051 0/1
/
/ *1:Big-endian.
/ *2:Unaligned memory access is not supported.
/ *3:Some compilers generate LDM/STM for mem_cpy function.
*/

15
loader/source/fatfs/integer.h Executable file → Normal file
View File

@@ -5,13 +5,19 @@
#ifndef _FF_INTEGER #ifndef _FF_INTEGER
#define _FF_INTEGER #define _FF_INTEGER
#ifdef _WIN32 /* Development platform */ #ifdef _WIN32 /* FatFs development platform */
#include <windows.h> #include <windows.h>
#include <tchar.h> #include <tchar.h>
typedef unsigned __int64 QWORD;
#else /* Embedded platform */ #else /* Embedded platform */
/* These types MUST be 16-bit or 32-bit */
typedef int INT;
typedef unsigned int UINT;
/* This type MUST be 8-bit */ /* This type MUST be 8-bit */
typedef unsigned char BYTE; typedef unsigned char BYTE;
@@ -20,14 +26,13 @@ typedef short SHORT;
typedef unsigned short WORD; typedef unsigned short WORD;
typedef unsigned short WCHAR; typedef unsigned short WCHAR;
/* These types MUST be 16-bit or 32-bit */
typedef int INT;
typedef unsigned int UINT;
/* These types MUST be 32-bit */ /* These types MUST be 32-bit */
typedef long LONG; typedef long LONG;
typedef unsigned long DWORD; typedef unsigned long DWORD;
/* This type MUST be 64-bit (Remove this for C89 compatibility) */
typedef unsigned long long QWORD;
#endif #endif
#endif #endif

View File

@@ -1,348 +0,0 @@
/*------------------------------------------------------------------------*/
/* Unicode - Local code bidirectional converter (C)ChaN, 2015 */
/* (SBCS code pages) */
/*------------------------------------------------------------------------*/
/* 437 U.S.
/ 720 Arabic
/ 737 Greek
/ 771 KBL
/ 775 Baltic
/ 850 Latin 1
/ 852 Latin 2
/ 855 Cyrillic
/ 857 Turkish
/ 860 Portuguese
/ 861 Icelandic
/ 862 Hebrew
/ 863 Canadian French
/ 864 Arabic
/ 865 Nordic
/ 866 Russian
/ 869 Greek 2
*/
#include "../ff.h"
#if _CODE_PAGE == 437
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP437(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 720
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP720(0x80-0xFF) to Unicode conversion table */
0x0000, 0x0000, 0x00E9, 0x00E2, 0x0000, 0x00E0, 0x0000, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0000, 0x0000, 0x0000,
0x0000, 0x0651, 0x0652, 0x00F4, 0x00A4, 0x0640, 0x00FB, 0x00F9, 0x0621, 0x0622, 0x0623, 0x0624, 0x00A3, 0x0625, 0x0626, 0x0627,
0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F, 0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x0636, 0x0637, 0x0638, 0x0639, 0x063A, 0x0641, 0x00B5, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064A,
0x2261, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F, 0x0650, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 737
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP737(0x80-0xFF) to Unicode conversion table */
0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0,
0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, 0x03B8,
0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x03C9, 0x03AC, 0x03AD, 0x03AE, 0x03CA, 0x03AF, 0x03CC, 0x03CD, 0x03CB, 0x03CE, 0x0386, 0x0388, 0x0389, 0x038A, 0x038C, 0x038E,
0x038F, 0x00B1, 0x2265, 0x2264, 0x03AA, 0x03AB, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 771
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP771(0x80-0xFF) to Unicode conversion table */
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x0104, 0x0105, 0x010C, 0x010D,
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
0x0118, 0x0119, 0x0116, 0x0117, 0x012E, 0x012F, 0x0160, 0x0161, 0x0172, 0x0173, 0x016A, 0x016B, 0x017D, 0x017E, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 775
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP775(0x80-0xFF) to Unicode conversion table */
0x0106, 0x00FC, 0x00E9, 0x0101, 0x00E4, 0x0123, 0x00E5, 0x0107, 0x0142, 0x0113, 0x0156, 0x0157, 0x012B, 0x0179, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x014D, 0x00F6, 0x0122, 0x00A2, 0x015A, 0x015B, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x00A4,
0x0100, 0x012A, 0x00F3, 0x017B, 0x017C, 0x017A, 0x201D, 0x00A6, 0x00A9, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x0141, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0104, 0x010C, 0x0118, 0x0116, 0x2563, 0x2551, 0x2557, 0x255D, 0x012E, 0x0160, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0172, 0x016A, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x017D,
0x0105, 0x010D, 0x0119, 0x0117, 0x012F, 0x0161, 0x0173, 0x016B, 0x017E, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x00D3, 0x00DF, 0x014C, 0x0143, 0x00F5, 0x00D5, 0x00B5, 0x0144, 0x0136, 0x0137, 0x013B, 0x013C, 0x0146, 0x0112, 0x0145, 0x2019,
0x00AD, 0x00B1, 0x201C, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x201E, 0x00B0, 0x2219, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 850
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP850(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE, 0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 852
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP852(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x016F, 0x0107, 0x00E7, 0x0142, 0x00EB, 0x0150, 0x0151, 0x00EE, 0x0179, 0x00C4, 0x0106,
0x00C9, 0x0139, 0x013A, 0x00F4, 0x00F6, 0x013D, 0x013E, 0x015A, 0x015B, 0x00D6, 0x00DC, 0x0164, 0x0165, 0x0141, 0x00D7, 0x010D,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x0104, 0x0105, 0x017D, 0x017E, 0x0118, 0x0119, 0x00AC, 0x017A, 0x010C, 0x015F, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x011A, 0x015E, 0x2563, 0x2551, 0x2557, 0x255D, 0x017B, 0x017C, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0102, 0x0103, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
0x0111, 0x0110, 0x010E, 0x00CB, 0x010F, 0x0147, 0x00CD, 0x00CE, 0x011B, 0x2518, 0x250C, 0x2588, 0x2584, 0x0162, 0x016E, 0x2580,
0x00D3, 0x00DF, 0x00D4, 0x0143, 0x0144, 0x0148, 0x0160, 0x0161, 0x0154, 0x00DA, 0x0155, 0x0170, 0x00FD, 0x00DD, 0x0163, 0x00B4,
0x00AD, 0x02DD, 0x02DB, 0x02C7, 0x02D8, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x02D9, 0x0171, 0x0158, 0x0159, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 855
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP855(0x80-0xFF) to Unicode conversion table */
0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404, 0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408,
0x0459, 0x0409, 0x045A, 0x040A, 0x045B, 0x040B, 0x045C, 0x040C, 0x045E, 0x040E, 0x045F, 0x040F, 0x044E, 0x042E, 0x044A, 0x042A,
0x0430, 0x0410, 0x0431, 0x0411, 0x0446, 0x0426, 0x0434, 0x0414, 0x0435, 0x0415, 0x0444, 0x0424, 0x0433, 0x0413, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0445, 0x0425, 0x0438, 0x0418, 0x2563, 0x2551, 0x2557, 0x255D, 0x0439, 0x0419, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x043A, 0x041A, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
0x043B, 0x041B, 0x043C, 0x041C, 0x043D, 0x041D, 0x043E, 0x041E, 0x043F, 0x2518, 0x250C, 0x2588, 0x2584, 0x041F, 0x044F, 0x2580,
0x042F, 0x0440, 0x0420, 0x0441, 0x0421, 0x0442, 0x0422, 0x0443, 0x0423, 0x0436, 0x0416, 0x0432, 0x0412, 0x044C, 0x042C, 0x2116,
0x00AD, 0x044B, 0x042B, 0x0437, 0x0417, 0x0448, 0x0428, 0x044D, 0x042D, 0x0449, 0x0429, 0x0447, 0x0427, 0x00A7, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 857
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP857(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0131, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x0130, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x015E, 0x015F,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x011E, 0x011F, 0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0, 0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
0x00BA, 0x00AA, 0x00CA, 0x00CB, 0x00C8, 0x0000, 0x00CD, 0x00CE, 0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x0000, 0x00D7, 0x00DA, 0x00DB, 0x00D9, 0x00EC, 0x00FF, 0x00AF, 0x00B4,
0x00AD, 0x00B1, 0x0000, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8, 0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 860
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP860(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E3, 0x00E0, 0x00C1, 0x00E7, 0x00EA, 0x00CA, 0x00E8, 0x00CD, 0x00D4, 0x00EC, 0x00C3, 0x00C2,
0x00C9, 0x00C0, 0x00C8, 0x00F4, 0x00F5, 0x00F2, 0x00DA, 0x00F9, 0x00CC, 0x00D5, 0x00DC, 0x00A2, 0x00A3, 0x00D9, 0x20A7, 0x00D3,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x00D2, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 861
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP861(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E6, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00D0, 0x00F0, 0x00DE, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00FE, 0x00FB, 0x00DD, 0x00FD, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x20A7, 0x0192,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00C1, 0x00CD, 0x00D3, 0x00DA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 862
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP862(0x80-0xFF) to Unicode conversion table */
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7, 0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7, 0x05E8, 0x05E9, 0x05EA, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 863
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP863(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00C2, 0x00E0, 0x00B6, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x2017, 0x00C0,
0x00C9, 0x00C8, 0x00CA, 0x00F4, 0x00CB, 0x00CF, 0x00FB, 0x00F9, 0x00A4, 0x00D4, 0x00DC, 0x00A2, 0x00A3, 0x00D9, 0x00DB, 0x0192,
0x00A6, 0x00B4, 0x00F3, 0x00FA, 0x00A8, 0x00BB, 0x00B3, 0x00AF, 0x00CE, 0x3210, 0x00AC, 0x00BD, 0x00BC, 0x00BE, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2219,
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 864
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP864(0x80-0xFF) to Unicode conversion table */
0x00B0, 0x00B7, 0x2219, 0x221A, 0x2592, 0x2500, 0x2502, 0x253C, 0x2524, 0x252C, 0x251C, 0x2534, 0x2510, 0x250C, 0x2514, 0x2518,
0x03B2, 0x221E, 0x03C6, 0x00B1, 0x00BD, 0x00BC, 0x2248, 0x00AB, 0x00BB, 0xFEF7, 0xFEF8, 0x0000, 0x0000, 0xFEFB, 0xFEFC, 0x0000,
0x00A0, 0x00AD, 0xFE82, 0x00A3, 0x00A4, 0xFE84, 0x0000, 0x20AC, 0xFE8E, 0xFE8F, 0xFE95, 0xFE99, 0x060C, 0xFE9D, 0xFEA1, 0xFEA5,
0x0660, 0x0661, 0x0662, 0x0663, 0x0664, 0x0665, 0x0666, 0x0667, 0x0668, 0x0669, 0xFED1, 0x061B, 0xFEB1, 0xFEB5, 0xFEB9, 0x061F,
0x00A2, 0xFE80, 0xFE81, 0xFE83, 0xFE85, 0xFECA, 0xFE8B, 0xFE8D, 0xFE91, 0xFE93, 0xFE97, 0xFE9B, 0xFE9F, 0xFEA3, 0xFEA7, 0xFEA9,
0xFEAB, 0xFEAD, 0xFEAF, 0xFEB3, 0xFEB7, 0xFEBB, 0xFEBF, 0xFEC1, 0xFEC5, 0xFECB, 0xFECF, 0x00A6, 0x00AC, 0x00F7, 0x00D7, 0xFEC9,
0x0640, 0xFED3, 0xFED7, 0xFEDB, 0xFEDF, 0xFEE3, 0xFEE7, 0xFEEB, 0xFEED, 0xFEEF, 0xFEF3, 0xFEBD, 0xFECC, 0xFECE, 0xFECD, 0xFEE1,
0xFE7D, 0x0651, 0xFEE5, 0xFEE9, 0xFEEC, 0xFEF0, 0xFEF2, 0xFED0, 0xFED5, 0xFEF5, 0xFEF6, 0xFEDD, 0xFED9, 0xFEF1, 0x25A0, 0x0000
};
#elif _CODE_PAGE == 865
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP865(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7, 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C5, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9, 0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x20A7, 0x0192,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA, 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00A4,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x2558, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4, 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 866
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP866(0x80-0xFF) to Unicode conversion table */
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417, 0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427, 0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437, 0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447, 0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E, 0x00B0, 0x2219, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 869
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP869(0x80-0xFF) to Unicode conversion table */
0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x00B7, 0x0386, 0x00B7, 0x00B7, 0x00AC, 0x00A6, 0x2018, 0x2019, 0x0388, 0x2015, 0x0389,
0x038A, 0x03AA, 0x038C, 0x00B7, 0x00B7, 0x038E, 0x03AB, 0x00A9, 0x038F, 0x00B2, 0x00B3, 0x03AC, 0x00A3, 0x03AD, 0x03AE, 0x03AF,
0x03CA, 0x0390, 0x03CC, 0x03CD, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x00BD, 0x0398, 0x0399, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x039A, 0x039B, 0x039C, 0x039D, 0x2563, 0x2551, 0x2557, 0x255D, 0x039E, 0x039F, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0A30, 0x03A1, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x03A3,
0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9, 0x03B1, 0x03B2, 0x03B3, 0x2518, 0x250C, 0x2588, 0x2584, 0x03B4, 0x03B5, 0x2580,
0x03B6, 0x03B7, 0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0, 0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x0384,
0x00AD, 0x00B1, 0x03C5, 0x03C6, 0x03C7, 0x00A7, 0x03C8, 0x0385, 0x00B0, 0x00A8, 0x03C9, 0x03CB, 0x03B0, 0x03CE, 0x25A0, 0x00A0
};
#endif
#if !_TBLDEF || !_USE_LFN
#error This file is not needed at current configuration. Remove from the project.
#endif
WCHAR ff_convert ( /* Converted character, Returns zero on error */
WCHAR chr, /* Character code to be converted */
UINT dir /* 0: Unicode to OEM code, 1: OEM code to Unicode */
)
{
WCHAR c;
if (chr < 0x80) { /* ASCII */
c = chr;
} else {
if (dir) { /* OEM code to Unicode */
c = (chr >= 0x100) ? 0 : Tbl[chr - 0x80];
} else { /* Unicode to OEM code */
for (c = 0; c < 0x80; c++) {
if (chr == Tbl[c]) break;
}
c = (c + 0x80) & 0xFF;
}
}
return c;
}
WCHAR ff_wtoupper ( /* Returns upper converted character */
WCHAR chr /* Unicode character to be upper converted */
)
{
static const WCHAR lower[] = { /* Lower case characters to be converted */
/* Latin Supplement */ 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,
/* Latin Extended-A */ 0x101,0x103,0x105,0x107,0x109,0x10B,0x10D,0x10F,0x111,0x113,0x115,0x117,0x119,0x11B,0x11D,0x11F,0x121,0x123,0x125,0x127,0x129,0x12B,0x12D,0x12F,0x131,0x133,0x135,0x137,0x13A,0x13C,0x13E,0x140,0x142,0x144,0x146,0x148,0x14B,0x14D,0x14F,0x151,0x153,0x155,0x157,0x159,0x15B,0x15D,0x15F,0x161,0x163,0x165,0x167,0x169,0x16B,0x16D,0x16F,0x171,0x173,0x175,0x177,0x17A,0x17C,0x17E,
/* Latin Extended-B */ 0x183,0x185,0x188,0x18C,0x192,0x199,0x1A1,0x1A3,0x1A8,0x1AD,0x1B0,0x1B4,0x1B6,0x1B9,0x1BD,0x1C6,0x1C9,0x1CC,0x1CE,0x1D0,0x1D2,0x1D4,0x1D6,0x1D8,0x1DA,0x1DC,0x1DD,0x1DF,0x1E1,0x1E3,0x1E5,0x1E7,0x1E9,0x1EB,0x1ED,0x1EF,0x1F3,0x1F5,0x1FB,0x1FD,0x1FF,0x201,0x203,0x205,0x207,0x209,0x20B,0x20D,0x20F,0x211,0x213,0x215,0x217,
/* Greek, Coptic */ 0x3B1,0x3B2,0x3B3,0x3B4,0x3B5,0x3B6,0x3B7,0x3B8,0x3B9,0x3BA,0x3BB,0x3BC,0x3BD,0x3BE,0x3BF,0x3C0,0x3C1,0x3C3,0x3C4,0x3C5,0x3C6,0x3C7,0x3C8,0x3C9,0x3CA,0x3CB,0x3CC,0x3CD,0x3CE,0x3E3,0x3E5,0x3E7,0x3E9,0x3EB,
/* Cyrillic */ 0x430,0x431,0x432,0x433,0x434,0x435,0x436,0x437,0x438,0x439,0x43A,0x43B,0x43C,0x43D,0x43E,0x43F,0x440,0x441,0x442,0x443,0x444,0x445,0x446,0x447,0x448,0x449,0x44A,0x44B,0x44C,0x44D,0x44E,0x44F,0x452,0x453,0x454,0x455,0x456,0x457,0x458,0x459,0x45A,0x45B,0x45C,0x45E,0x45F,0x461,0x463,0x465,0x467,0x469,0x46B,0x46D,0x46F,0x471,0x473,0x475,0x477,0x479,0x47B,0x47D,0x47F,0x481,0x491,0x493,0x495,0x497,0x499,0x49B,0x49D,0x49F,0x4A1,0x4A3,0x4A5,0x4A7,0x4A9,0x4AB,0x4AD,0x4AF,0x4B1,0x4B3,0x4B5,0x4B7,0x4B9,0x4BB,0x4BD,0x4BF,0x4C2,0x4C4,0x4C8,0x4D1,0x4D3,0x4D5,0x4D7,0x4D9,0x4DB,0x4DD,0x4DF,0x4E1,0x4E3,0x4E5,0x4E7,0x4E9,0x4EB,0x4ED,0x4EF,0x4F1,0x4F3,0x4F5,0x4F9,
/* Armenian */ 0x561,0x562,0x563,0x564,0x565,0x566,0x567,0x568,0x569,0x56A,0x56B,0x56C,0x56D,0x56E,0x56F,0x570,0x571,0x572,0x573,0x574,0x575,0x576,0x577,0x578,0x579,0x57A,0x57B,0x57C,0x57D,0x57E,0x57F,0x580,0x581,0x582,0x583,0x584,0x585,0x586,
/* Latin Extended Additional */ 0x1E01,0x1E03,0x1E05,0x1E07,0x1E09,0x1E0B,0x1E0D,0x1E0F,0x1E11,0x1E13,0x1E15,0x1E17,0x1E19,0x1E1B,0x1E1D,0x1E1F,0x1E21,0x1E23,0x1E25,0x1E27,0x1E29,0x1E2B,0x1E2D,0x1E2F,0x1E31,0x1E33,0x1E35,0x1E37,0x1E39,0x1E3B,0x1E3D,0x1E3F,0x1E41,0x1E43,0x1E45,0x1E47,0x1E49,0x1E4B,0x1E4D,0x1E4F,0x1E51,0x1E53,0x1E55,0x1E57,0x1E59,0x1E5B,0x1E5D,0x1E5F,0x1E61,0x1E63,0x1E65,0x1E67,0x1E69,0x1E6B,0x1E6D,0x1E6F,0x1E71,0x1E73,0x1E75,0x1E77,0x1E79,0x1E7B,0x1E7D,0x1E7F,0x1E81,0x1E83,0x1E85,0x1E87,0x1E89,0x1E8B,0x1E8D,0x1E8F,0x1E91,0x1E93,0x1E95,0x1E97,0x1E99,0x1E9B,0x1E9D,0x1E9F,0x1EA1,0x1EA3,0x1EA5,0x1EA7,0x1EA9,0x1EAB,0x1EAD,0x1EAF,0x1EB1,0x1EB3,0x1EB5,0x1EB7,0x1EB9,0x1EBB,0x1EBD,0x1EBF,0x1EC1,0x1EC3,0x1EC5,0x1EC7,0x1EC9,0x1ECB,0x1ECD,0x1ECF,0x1ED1,0x1ED3,0x1ED5,0x1ED7,0x1ED9,0x1EDB,0x1EDD,0x1EDF,0x1EE1,0x1EE3,0x1EE5,0x1EE7,0x1EE9,0x1EEB,0x1EED,0x1EEF,0x1EF1,0x1EF3,0x1EF5,0x1EF7,0x1EF9,
/* Number forms */ 0x2170,0x2171,0x2172,0x2173,0x2174,0x2175,0x2176,0x2177,0x2178,0x2179,0x217A,0x217B,0x217C,0x217D,0x217E,0x217F,
/* Full-width */ 0xFF41,0xFF42,0xFF43,0xFF44,0xFF45,0xFF46,0xFF47,0xFF48,0xFF49,0xFF4A,0xFF4B,0xFF4C,0xFF4D,0xFF4E,0xFF4F,0xFF50,0xFF51,0xFF52,0xFF53,0xFF54,0xFF55,0xFF56,0xFF57,0xFF58,0xFF59,0xFF5A
};
static const WCHAR upper[] = { /* Upper case characters correspond to lower[] */
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x178,
0x100,0x102,0x104,0x106,0x108,0x10A,0x10C,0x10E,0x110,0x112,0x114,0x116,0x118,0x11A,0x11C,0x11E,0x120,0x122,0x124,0x126,0x128,0x12A,0x12C,0x12E,0x130,0x132,0x134,0x136,0x139,0x13B,0x13D,0x13F,0x141,0x143,0x145,0x147,0x14A,0x14C,0x14E,0x150,0x152,0x154,0x156,0x158,0x15A,0x15C,0x15E,0x160,0x162,0x164,0x166,0x168,0x16A,0x16C,0x16E,0x170,0x172,0x174,0x176,0x179,0x17B,0x17D,
0x182,0x184,0x187,0x18B,0x191,0x198,0x1A0,0x1A2,0x1A7,0x1AC,0x1AF,0x1B3,0x1B5,0x1B8,0x1BC,0x1C4,0x1C7,0x1CA,0x1CD,0x1CF,0x1D1,0x1D3,0x1D5,0x1D7,0x1D9,0x1DB,0x18E,0x1DE,0x1E0,0x1E2,0x1E4,0x1E6,0x1E8,0x1EA,0x1EC,0x1EE,0x1F1,0x1F4,0x1FA,0x1FC,0x1FE,0x200,0x202,0x204,0x206,0x208,0x20A,0x20C,0x20E,0x210,0x212,0x214,0x216,
0x391,0x392,0x393,0x394,0x395,0x396,0x397,0x398,0x399,0x39A,0x39B,0x39C,0x39D,0x39E,0x39F,0x3A0,0x3A1,0x3A3,0x3A4,0x3A5,0x3A6,0x3A7,0x3A8,0x3A9,0x3AA,0x3AB,0x38C,0x38E,0x38F,0x3E2,0x3E4,0x3E6,0x3E8,0x3EA,
0x410,0x411,0x412,0x413,0x414,0x415,0x416,0x417,0x418,0x419,0x41A,0x41B,0x41C,0x41D,0x41E,0x41F,0x420,0x421,0x422,0x423,0x424,0x425,0x426,0x427,0x428,0x429,0x42A,0x42B,0x42C,0x42D,0x42E,0x42F,0x402,0x403,0x404,0x405,0x406,0x407,0x408,0x409,0x40A,0x40B,0x40C,0x40E,0x40F,0x460,0x462,0x464,0x466,0x468,0x46A,0x46C,0x46E,0x470,0x472,0x474,0x476,0x478,0x47A,0x47C,0x47E,0x480,0x490,0x492,0x494,0x496,0x498,0x49A,0x49C,0x49E,0x4A0,0x4A2,0x4A4,0x4A6,0x4A8,0x4AA,0x4AC,0x4AE,0x4B0,0x4B2,0x4B4,0x4B6,0x4B8,0x4BA,0x4BC,0x4BE,0x4C1,0x4C3,0x5C7,0x4D0,0x4D2,0x4D4,0x4D6,0x4D8,0x4DA,0x4DC,0x4DE,0x4E0,0x4E2,0x4E4,0x4E6,0x4E8,0x4EA,0x4EC,0x4EE,0x4F0,0x4F2,0x4F4,0x4F8,
0x531,0x532,0x533,0x534,0x535,0x536,0x537,0x538,0x539,0x53A,0x53B,0x53C,0x53D,0x53E,0x53F,0x540,0x541,0x542,0x543,0x544,0x545,0x546,0x547,0x548,0x549,0x54A,0x54B,0x54C,0x54D,0x54E,0x54F,0x550,0x551,0x552,0x553,0x554,0x555,0x556,
0x1E00,0x1E02,0x1E04,0x1E06,0x1E08,0x1E0A,0x1E0C,0x1E0E,0x1E10,0x1E12,0x1E14,0x1E16,0x1E18,0x1E1A,0x1E1C,0x1E1E,0x1E20,0x1E22,0x1E24,0x1E26,0x1E28,0x1E2A,0x1E2C,0x1E2E,0x1E30,0x1E32,0x1E34,0x1E36,0x1E38,0x1E3A,0x1E3C,0x1E3E,0x1E40,0x1E42,0x1E44,0x1E46,0x1E48,0x1E4A,0x1E4C,0x1E4E,0x1E50,0x1E52,0x1E54,0x1E56,0x1E58,0x1E5A,0x1E5C,0x1E5E,0x1E60,0x1E62,0x1E64,0x1E66,0x1E68,0x1E6A,0x1E6C,0x1E6E,0x1E70,0x1E72,0x1E74,0x1E76,0x1E78,0x1E7A,0x1E7C,0x1E7E,0x1E80,0x1E82,0x1E84,0x1E86,0x1E88,0x1E8A,0x1E8C,0x1E8E,0x1E90,0x1E92,0x1E94,0x1E96,0x1E98,0x1E9A,0x1E9C,0x1E9E,0x1EA0,0x1EA2,0x1EA4,0x1EA6,0x1EA8,0x1EAA,0x1EAC,0x1EAE,0x1EB0,0x1EB2,0x1EB4,0x1EB6,0x1EB8,0x1EBA,0x1EBC,0x1EBE,0x1EC0,0x1EC2,0x1EC4,0x1EC6,0x1EC8,0x1ECA,0x1ECC,0x1ECE,0x1ED0,0x1ED2,0x1ED4,0x1ED6,0x1ED8,0x1EDA,0x1EDC,0x1EDE,0x1EE0,0x1EE2,0x1EE4,0x1EE6,0x1EE8,0x1EEA,0x1EEC,0x1EEE,0x1EF0,0x1EF2,0x1EF4,0x1EF6,0x1EF8,
0x2160,0x2161,0x2162,0x2163,0x2164,0x2165,0x2166,0x2167,0x2168,0x2169,0x216A,0x216B,0x216C,0x216D,0x216E,0x216F,
0xFF21,0xFF22,0xFF23,0xFF24,0xFF25,0xFF26,0xFF27,0xFF28,0xFF29,0xFF2A,0xFF2B,0xFF2C,0xFF2D,0xFF2E,0xFF2F,0xFF30,0xFF31,0xFF32,0xFF33,0xFF34,0xFF35,0xFF36,0xFF37,0xFF38,0xFF39,0xFF3A
};
UINT i, n, hi, li;
if (chr < 0x80) { /* ASCII characters (acceleration) */
if (chr >= 0x61 && chr <= 0x7A) chr -= 0x20;
} else { /* Non ASCII characters (table search) */
n = 12; li = 0; hi = sizeof lower / sizeof lower[0];
do {
i = li + (hi - li) / 2;
if (chr == lower[i]) break;
if (chr > lower[i]) li = i; else hi = i;
} while (--n);
if (n) chr = upper[i];
}
return chr;
}

View File

@@ -1,4 +1,15 @@
#pragma once #pragma once
#include <stdbool.h> #include <stdbool.h>
#include "../../types.h" #include <stdint.h>
#include <stdlib.h>
//Common data types
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef volatile u8 vu8;
typedef volatile u16 vu16;
typedef volatile u32 vu32;
typedef volatile u64 vu64;

View File

@@ -5,8 +5,7 @@
#include "sdmmc.h" #include "sdmmc.h"
#include "delay.h" #include "delay.h"
struct mmcdevice handleNAND; static struct mmcdevice handleSD;
struct mmcdevice handleSD;
static inline u16 sdmmc_read16(u16 reg) { static inline u16 sdmmc_read16(u16 reg) {
return *(vu16*)(SDMMC_BASE + reg); return *(vu16*)(SDMMC_BASE + reg);
@@ -38,13 +37,6 @@ static inline void setckl(u32 data)
sdmmc_mask16(REG_SDCLKCTL, 0x0, 0x100); sdmmc_mask16(REG_SDCLKCTL, 0x0, 0x100);
} }
mmcdevice *getMMCDevice(int drive)
{
if(drive==0) return &handleNAND;
return &handleSD;
}
static u32 __attribute__((noinline)) geterror(struct mmcdevice *ctx) static u32 __attribute__((noinline)) geterror(struct mmcdevice *ctx)
{ {
return (ctx->error << 29) >> 31; return (ctx->error << 29) >> 31;
@@ -150,20 +142,6 @@ static void __attribute__((noinline)) sdmmc_send_command(struct mmcdevice *ctx,
} }
} }
u32 __attribute__((noinline)) sdmmc_sdcard_writesectors(u32 sector_no, u32 numsectors, vu8 *in)
{
if (handleSD.isSDHC == 0)
sector_no <<= 9;
inittarget(&handleSD);
sdmmc_write16(REG_SDSTOP,0x100);
sdmmc_write16(REG_SDBLKCOUNT,numsectors);
handleSD.data = in;
handleSD.size = numsectors << 9;
sdmmc_send_command(&handleSD,0x52C19,sector_no);
return geterror(&handleSD);
}
u32 __attribute__((noinline)) sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, vu8 *out) u32 __attribute__((noinline)) sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, vu8 *out)
{ {
if (handleSD.isSDHC == 0) if (handleSD.isSDHC == 0)
@@ -178,38 +156,6 @@ u32 __attribute__((noinline)) sdmmc_sdcard_readsectors(u32 sector_no, u32 numsec
return geterror(&handleSD); return geterror(&handleSD);
} }
u32 __attribute__((noinline)) sdmmc_nand_readsectors(u32 sector_no, u32 numsectors, vu8 *out)
{
if (handleNAND.isSDHC == 0)
sector_no <<= 9;
inittarget(&handleNAND);
sdmmc_write16(REG_SDSTOP,0x100);
sdmmc_write16(REG_SDBLKCOUNT,numsectors);
handleNAND.data = out;
handleNAND.size = numsectors << 9;
sdmmc_send_command(&handleNAND,0x33C12,sector_no);
inittarget(&handleSD);
return geterror(&handleNAND);
}
u32 __attribute__((noinline)) sdmmc_nand_writesectors(u32 sector_no, u32 numsectors, vu8 *in) //experimental
{
if (handleNAND.isSDHC == 0)
sector_no <<= 9;
inittarget(&handleNAND);
sdmmc_write16(REG_SDSTOP,0x100);
sdmmc_write16(REG_SDBLKCOUNT,numsectors);
handleNAND.data = in;
handleNAND.size = numsectors << 9;
sdmmc_send_command(&handleNAND,0x52C19,sector_no);
inittarget(&handleSD);
return geterror(&handleNAND);
}
static u32 calcSDSize(u8* csd, int type) static u32 calcSDSize(u8* csd, int type)
{ {
u32 result = 0; u32 result = 0;
@@ -241,14 +187,6 @@ static u32 calcSDSize(u8* csd, int type)
static void InitSD() static void InitSD()
{ {
//NAND
handleNAND.isSDHC = 0;
handleNAND.SDOPT = 0;
handleNAND.res = 0;
handleNAND.initarg = 1;
handleNAND.clk = 0x80;
handleNAND.devicenumber = 1;
//SD //SD
handleSD.isSDHC = 0; handleSD.isSDHC = 0;
handleSD.SDOPT = 0; handleSD.SDOPT = 0;
@@ -281,56 +219,6 @@ static void InitSD()
inittarget(&handleSD); inittarget(&handleSD);
} }
static int Nand_Init()
{
inittarget(&handleNAND);
ioDelay(0xF000);
sdmmc_send_command(&handleNAND,0,0);
do {
do {
sdmmc_send_command(&handleNAND,0x10701,0x100000);
} while ( !(handleNAND.error & 1) );
} while((handleNAND.ret[0] & 0x80000000) == 0);
sdmmc_send_command(&handleNAND,0x10602,0x0);
if (handleNAND.error & 0x4) return -1;
sdmmc_send_command(&handleNAND,0x10403,handleNAND.initarg << 0x10);
if (handleNAND.error & 0x4) return -1;
sdmmc_send_command(&handleNAND,0x10609,handleNAND.initarg << 0x10);
if (handleNAND.error & 0x4) return -1;
handleNAND.total_size = calcSDSize((u8*)&handleNAND.ret[0],0);
handleNAND.clk = 1;
setckl(1);
sdmmc_send_command(&handleNAND,0x10407,handleNAND.initarg << 0x10);
if (handleNAND.error & 0x4) return -1;
handleNAND.SDOPT = 1;
sdmmc_send_command(&handleNAND,0x10506,0x3B70100);
if (handleNAND.error & 0x4) return -1;
sdmmc_send_command(&handleNAND,0x10506,0x3B90100);
if (handleNAND.error & 0x4) return -1;
sdmmc_send_command(&handleNAND,0x1040D,handleNAND.initarg << 0x10);
if (handleNAND.error & 0x4) return -1;
sdmmc_send_command(&handleNAND,0x10410,0x200);
if (handleNAND.error & 0x4) return -1;
handleNAND.clk |= 0x200;
inittarget(&handleSD);
return 0;
}
static int SD_Init() static int SD_Init()
{ {
inittarget(&handleSD); inittarget(&handleSD);
@@ -395,10 +283,8 @@ static int SD_Init()
return 0; return 0;
} }
int sdmmc_sdcard_init() void sdmmc_sdcard_init()
{ {
InitSD(); InitSD();
int result = Nand_Init(); SD_Init();
return result | SD_Init(); }
}

View File

@@ -118,10 +118,5 @@ typedef struct mmcdevice {
u32 res; u32 res;
} mmcdevice; } mmcdevice;
int sdmmc_sdcard_init(); void sdmmc_sdcard_init();
u32 sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, vu8 *out); u32 sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, vu8 *out);
u32 sdmmc_sdcard_writesectors(u32 sector_no, u32 numsectors, vu8 *in);
mmcdevice *getMMCDevice(int drive);
u32 sdmmc_nand_readsectors(u32 sector_no, u32 numsectors, vu8 *out);
u32 sdmmc_nand_writesectors(u32 sector_no, u32 numsectors, vu8 *in);

View File

@@ -1,42 +1,19 @@
#include "types.h"
#include "buttons.h"
#include "fatfs/ff.h" #include "fatfs/ff.h"
#define PAYLOAD_ADDRESS 0x23F00000 #define PAYLOAD_ADDRESS 0x23F00000
static u32 loadPayload(const char *path)
{
FIL payload;
unsigned int br;
if(f_open(&payload, path, FA_READ) == FR_OK)
{
f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &br);
f_close(&payload);
return 1;
}
return 0;
}
void main(void) void main(void)
{ {
FATFS fs; FATFS fs;
f_mount(&fs, "0:", 1); f_mount(&fs, "0:", 1);
//Get pressed buttons FIL payload;
u32 pressed = HID_PAD; unsigned int read;
if(((pressed & BUTTON_RIGHT) && loadPayload("/aurei/payloads/right.bin")) || f_open(&payload, (char *)0x24F00004, FA_READ);
((pressed & BUTTON_LEFT) && loadPayload("/aurei/payloads/left.bin")) || f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &read);
((pressed & BUTTON_UP) && loadPayload("/aurei/payloads/up.bin")) || f_close(&payload);
((pressed & BUTTON_DOWN) && loadPayload("/aurei/payloads/down.bin")) ||
((pressed & BUTTON_X) && loadPayload("/aurei/payloads/x.bin")) || ((void (*)())PAYLOAD_ADDRESS)();
((pressed & BUTTON_Y) && loadPayload("/aurei/payloads/y.bin")) ||
((pressed & BUTTON_SELECT) && loadPayload("/aurei/payloads/select.bin")) ||
((pressed & BUTTON_R1) && loadPayload("/aurei/payloads/r.bin")) ||
loadPayload("/aurei/payloads/default.bin"))
((void (*)())PAYLOAD_ADDRESS)();
} }

View File

@@ -2,10 +2,11 @@
.align 4 .align 4
.global _start .global _start
_start: _start:
@ Fix payloads like Decrypt9 b start
mov r0, #0x5
mcr p15, 0, r0, c3, c0, 0 @ data bufferable
.word 0, 0, 0, 0, 0, 0, 0
start:
@ Flush caches @ Flush caches
mov r0, #0 mov r0, #0
mcr p15, 0, r0, c7, c5, 0 @ flush I-cache mcr p15, 0, r0, c7, c5, 0 @ flush I-cache

View File

@@ -1,20 +0,0 @@
/*
* types.h
* by Reisyukaku
* Copyright (c) 2015 All Rights Reserved
*/
#pragma once
#include <stdint.h>
#include <stdlib.h>
//Common data types
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef volatile u8 vu8;
typedef volatile u16 vu16;
typedef volatile u32 vu32;
typedef volatile u64 vu64;

View File

@@ -80,7 +80,7 @@ fopen: .ascii "OPEN"
.pool .pool
bin_fname: .dcw "sdmc:/arm9loaderhax.bin" bin_fname: .dcw "sdmc:/arm9loaderhax.bin"
.word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
dat_fname: .dcw "sdmc:/AuReiNand.dat" dat_fname: .dcw "sdmc:/Luma3DS.dat"
.word 0 .word 0
.align 4 .align 4

View File

@@ -43,7 +43,7 @@ static int fsize(FILE *fp)
static void error(FILE *payload, const char *message) static void error(FILE *payload, const char *message)
{ {
fclose(payload); fclose(payload);
printf("%s, are you sure you're using an AuReiNand payload?\n", message); printf("%s, are you sure you're using a Luma3DS payload?\n", message);
exit(0); exit(0);
} }
@@ -51,7 +51,7 @@ int main(int argc, char **argv)
{ {
if(argc == 1) if(argc == 1)
{ {
printf("Usage: %s <AuReiNand payload path>\n", argv[0]); printf("Usage: %s <Luma3DS payload path>\n", argv[0]);
exit(0); exit(0);
} }
@@ -76,14 +76,14 @@ int main(int argc, char **argv)
error(payload, "Pattern not found"); error(payload, "Pattern not found");
} }
u8 input[37] = {0}; u8 input[38] = {0};
u8 payloadname[2 * sizeof(input)] = {0}; u8 payloadname[2 * (sizeof(input) - 1)] = {0};
printf("Enter the payload's path (37 characters max): "); printf("Enter the payload's path (37 characters max): ");
scanf("%37s", input); scanf("%37s", input);
unsigned int i; unsigned int i;
for (i = 0; i < sizeof(input); i++) for (i = 0; i < sizeof(input) - 1; i++)
payloadname[2 * i] = input[i]; payloadname[2 * i] = input[i];
memcpy(found + 12, payloadname, sizeof(payloadname)); memcpy(found + 12, payloadname, sizeof(payloadname));

View File

@@ -0,0 +1,40 @@
#!/usr/bin/env python
# Requires Python >= 3.2 or >= 2.7
# This is part of Luma3DS
__author__ = "TuxSH"
__copyright__ = "Copyright (c) 2016 TuxSH"
__license__ = "GPLv3"
__version__ = "v1.0"
import argparse
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Changes the path to Luma3DS for reboot patches")
parser.add_argument("payload", help="Path to the Luma3DS payload")
parser.add_argument("new_path", help="New Luma3DS payload path")
args = parser.parse_args()
data = b""
if len(args.new_path) > 37:
raise SystemExit("The new payload path is too large (37 characters max.)")
with open(args.payload, "rb") as f: data = bytearray(f.read())
if len(data) == 0: raise SystemExit("Could not read {0}".format(args.payload))
if len(data) > 0x20000:
raise SystemExit("The input file is too large, are you sure you're using a Luma3DS payload?")
found_index = data.find("sdmc:/".encode("utf-16-le"))
if found_index == -1:
raise SystemExit("The pattern was not found, are you sure you're usinga a Luma3DS payload?")
namebuf = args.new_path.encode("utf-16-le")
namebuf += b'\x00' * (74 - len(namebuf))
data[found_index + 12 : found_index + 12 + 74] = namebuf
with open(args.payload, "wb+") as f: f.write(data)

View File

@@ -16,8 +16,8 @@ name := $(shell basename $(CURDIR))
dir_source := source dir_source := source
dir_build := build dir_build := build
ASFLAGS := -mlittle-endian -mcpu=mpcore ASFLAGS := -mcpu=mpcore -mfloat-abi=hard
CFLAGS := -Wall -Wextra -MMD -MP -marm $(ASFLAGS) -fno-builtin -std=c11 -Wno-main -O2 -flto -ffast-math -mthumb -mthumb-interwork CFLAGS := -Wall -Wextra -MMD -MP -mthumb -mthumb-interwork $(ASFLAGS) -fno-builtin -std=c11 -Wno-main -O2 -flto -ffast-math
LDFLAGS := -nostdlib LDFLAGS := -nostdlib
objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \ objects = $(patsubst $(dir_source)/%.s, $(dir_build)/%.o, \
@@ -35,7 +35,7 @@ $(name).bin: $(dir_build)/$(name).elf
$(OC) -S -O binary $< $@ $(OC) -S -O binary $< $@
$(dir_build)/$(name).elf: $(objects) $(dir_build)/$(name).elf: $(objects)
$(CC) $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^ $(LINK.o) -T linker.ld $(OUTPUT_OPTION) $^
$(dir_build)/%.o: $(dir_source)/%.c $(dir_build)/%.o: $(dir_source)/%.c
@mkdir -p "$(@D)" @mkdir -p "$(@D)"

View File

@@ -1,7 +1,7 @@
ENTRY(_start) ENTRY(_start)
SECTIONS SECTIONS
{ {
. = 0x24F03000; . = 0x24F02000;
.text.start : { *(.text.start) } .text.start : { *(.text.start) }
.text : { *(.text) } .text : { *(.text) }
.data : { *(.data) } .data : { *(.data) }

View File

@@ -3,7 +3,7 @@
void main(void) void main(void)
{ {
const u32 brightness[4] = {0x5F, 0x4C, 0x39, 0x26}; const u32 brightness[4] = {0x5F, 0x4C, 0x39, 0x26};
u32 brightnessLevel = *(vu32 *)0x24F03008; u32 brightnessLevel = *(vu32 *)0x24F02008;
vu32 *const arm11 = (u32 *)0x1FFFFFF8; vu32 *const arm11 = (u32 *)0x1FFFFFF8;
*(vu32 *)0x10141200 = 0x1007F; *(vu32 *)0x10141200 = 0x1007F;

View File

@@ -1,9 +1,3 @@
/*
* types.h
* by Reisyukaku
* Copyright (c) 2015 All Rights Reserved
*/
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>

View File

@@ -1,7 +1,5 @@
/* /*
* buttons.h * buttons.h
* by Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#pragma once #pragma once
@@ -21,9 +19,8 @@
#define BUTTON_LEFT (1 << 5) #define BUTTON_LEFT (1 << 5)
#define BUTTON_UP (1 << 6) #define BUTTON_UP (1 << 6)
#define BUTTON_DOWN (1 << 7) #define BUTTON_DOWN (1 << 7)
#define BUTTON_L1R1 (BUTTON_R1 | BUTTON_L1) #define SAFE_MODE (BUTTON_R1 | BUTTON_L1 | BUTTON_A | BUTTON_UP)
#define SAFE_MODE (BUTTON_L1R1 | BUTTON_A | BUTTON_UP)
#define OVERRIDE_BUTTONS (BUTTON_B ^ 0xFFF) #define OVERRIDE_BUTTONS (BUTTON_B ^ 0xFFF)
#define SINGLE_PAYLOAD_BUTTONS (BUTTON_LEFT | BUTTON_RIGHT | BUTTON_UP | BUTTON_DOWN | BUTTON_START | BUTTON_X | BUTTON_Y) #define SINGLE_PAYLOAD_BUTTONS (BUTTON_LEFT | BUTTON_RIGHT | BUTTON_UP | BUTTON_DOWN | BUTTON_START | BUTTON_X | BUTTON_Y)
#define L_PAYLOAD_BUTTONS (BUTTON_R1 | BUTTON_SELECT) #define L_PAYLOAD_BUTTONS (BUTTON_R1 | BUTTON_A | BUTTON_SELECT)
#define MENU_BUTTONS (BUTTON_LEFT | BUTTON_RIGHT | BUTTON_UP | BUTTON_DOWN | BUTTON_A | BUTTON_START) #define MENU_BUTTONS (BUTTON_LEFT | BUTTON_RIGHT | BUTTON_UP | BUTTON_DOWN | BUTTON_A | BUTTON_START)

View File

@@ -1,7 +1,5 @@
/* /*
* config.c * config.c
* by Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#include "config.h" #include "config.h"
@@ -22,11 +20,10 @@ void configureCFW(const char *configPath)
"New 3DS CPU: Off( ) Clock( ) L2( ) Clock+L2( )" }; "New 3DS CPU: Off( ) Clock( ) L2( ) Clock+L2( )" };
const char *singleOptionsText[] = { "( ) Autoboot SysNAND", const char *singleOptionsText[] = { "( ) Autoboot SysNAND",
"( ) Use SysNAND FIRM as default (A9LH-only)", "( ) SysNAND is updated (A9LH-only)",
"( ) Force A9LH detection", "( ) Force A9LH detection",
"( ) Use second EmuNAND as default", "( ) Use second EmuNAND as default",
"( ) Enable region/language emulation", "( ) Enable region/language emulation",
"( ) Use developer UNITINFO",
"( ) Show current NAND in System Settings", "( ) Show current NAND in System Settings",
"( ) Show GBA boot screen in patched AGB_FIRM", "( ) Show GBA boot screen in patched AGB_FIRM",
"( ) Enable splash screen with no screen-init" }; "( ) Enable splash screen with no screen-init" };

View File

@@ -1,7 +1,5 @@
/* /*
* config.h * config.h
* by Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#pragma once #pragma once
@@ -14,6 +12,6 @@
#define MULTICONFIG(a) ((config >> (a * 2 + 6)) & 3) #define MULTICONFIG(a) ((config >> (a * 2 + 6)) & 3)
#define BOOTCONFIG(a, b) ((config >> a) & b) #define BOOTCONFIG(a, b) ((config >> a) & b)
extern u32 config; extern u32 config;
void configureCFW(const char *configPath); void configureCFW(const char *configPath);

View File

@@ -1,9 +1,7 @@
/* /*
* crypto.c * crypto.c
* by Reisyukaku / Aurora Wright
* Crypto libs from http://github.com/b1l1s/ctr
* *
* Copyright (c) 2016 All Rights Reserved * Crypto libs from http://github.com/b1l1s/ctr
*/ */
#include "crypto.h" #include "crypto.h"
@@ -11,7 +9,7 @@
#include "fatfs/sdmmc/sdmmc.h" #include "fatfs/sdmmc/sdmmc.h"
/**************************************************************** /****************************************************************
* Crypto Libs * Crypto libs
****************************************************************/ ****************************************************************/
/* original version by megazig */ /* original version by megazig */
@@ -273,7 +271,7 @@ static void sha(void *res, const void *src, u32 size, u32 mode)
} }
/**************************************************************** /****************************************************************
* Nand/FIRM Crypto stuff * NAND/FIRM crypto
****************************************************************/ ****************************************************************/
static u8 nandCTR[0x10], static u8 nandCTR[0x10],
@@ -350,9 +348,9 @@ void decryptExeFs(u8 *inbuf)
void arm9Loader(u8 *arm9Section, u32 mode) void arm9Loader(u8 *arm9Section, u32 mode)
{ {
//Firm keys //Firm keys
u8 keyY[0x10]; u8 keyY[0x10],
u8 arm9BinCTR[0x10]; arm9BinCTR[0x10],
u8 arm9BinSlot = mode ? 0x16 : 0x15; arm9BinSlot = mode ? 0x16 : 0x15;
//Setup keys needed for arm9bin decryption //Setup keys needed for arm9bin decryption
memcpy(keyY, arm9Section + 0x10, 0x10); memcpy(keyY, arm9Section + 0x10, 0x10);
@@ -386,8 +384,8 @@ void arm9Loader(u8 *arm9Section, u32 mode)
//Set >=9.6 KeyXs //Set >=9.6 KeyXs
if(mode) if(mode)
{ {
u8 keyData[] = {0xDD, 0xDA, 0xA4, 0xC6, 0x2C, 0xC4, 0x50, 0xE9, 0xDA, 0xB6, 0x9B, 0x0D, 0x9D, 0x2A, 0x21, 0x98}; u8 keyData[0x10] = {0xDD, 0xDA, 0xA4, 0xC6, 0x2C, 0xC4, 0x50, 0xE9, 0xDA, 0xB6, 0x9B, 0x0D, 0x9D, 0x2A, 0x21, 0x98},
u8 decKey[0x10]; decKey[0x10];
//Set keys 0x19..0x1F keyXs //Set keys 0x19..0x1F keyXs
aes_use_keyslot(0x11); aes_use_keyslot(0x11);

View File

@@ -1,9 +1,7 @@
/* /*
* crypto.h * crypto.h
* by Reisyukaku / Aurora Wright
* Crypto libs from http://github.com/b1l1s/ctr
* *
* Copyright (c) 2016 All Rights Reserved * Crypto libs from http://github.com/b1l1s/ctr
*/ */
#pragma once #pragma once

View File

@@ -1,9 +1,7 @@
/* /*
* draw.c * draw.c
* by Reisyukaku / Aurora Wright
* Code to print to the screen by mid-kid @CakesFW
* *
* Copyright (c) 2016 All Rights Reserved * Code to print to the screen by mid-kid @CakesFW
*/ */
#include "draw.h" #include "draw.h"
@@ -24,6 +22,7 @@ static const struct fb {
static inline int strlen(const char *string) static inline int strlen(const char *string)
{ {
char *stringEnd = (char *)string; char *stringEnd = (char *)string;
while(*stringEnd) stringEnd++; while(*stringEnd) stringEnd++;
return stringEnd - string; return stringEnd - string;
@@ -41,11 +40,11 @@ void loadSplash(void)
initScreens(); initScreens();
//Don't delay boot if no splash image is on the SD //Don't delay boot if no splash image is on the SD
if(fileRead(fb->top_left, "/aurei/splash.bin", 0x46500) + if(!(fileRead(fb->top_left, "/luma/splash.bin", 0x46500) +
fileRead(fb->bottom, "/aurei/splashbottom.bin", 0x38400)) fileRead(fb->bottom, "/luma/splashbottom.bin", 0x38400)))
{ {
u64 i = 0x1400000; u64 i = 0x1400000;
while(--i) __asm("mov r0, r0"); //Less Ghetto sleep func while(i--) __asm("mov r0, r0"); //Less Ghetto sleep func
} }
} }

View File

@@ -1,9 +1,7 @@
/* /*
* draw.h * draw.h
* by Reisyukaku / Aurora Wright
* Code to print to the screen by mid-kid @CakesFW
* *
* Copyright (c) 2016 All Rights Reserved * Code to print to the screen by mid-kid @CakesFW
*/ */
#pragma once #pragma once

View File

@@ -1,7 +1,5 @@
/* /*
* emunand.c * emunand.c
* by Reisyukaku / Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#include "emunand.h" #include "emunand.h"

View File

@@ -1,14 +1,12 @@
/* /*
* emunand.h * emunand.h
* by Reisyukaku / Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#pragma once #pragma once
#include "types.h" #include "types.h"
#define NCSD_MAGIC (0x4453434E) #define NCSD_MAGIC 0x4453434E
void getEmunandSect(u32 *off, u32 *head, u32 *emuNAND); void getEmunandSect(u32 *off, u32 *head, u32 *emuNAND);
u32 getSDMMC(u8 *pos, u32 size); u32 getSDMMC(u8 *pos, u32 size);

View File

@@ -1,180 +1,254 @@
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
Revision history of FatFs module Revision history of FatFs module
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
R0.00 (February 26, 2006) R0.00 (February 26, 2006)
Prototype.
Prototype.
R0.01 (April 29, 2006)
First stable version.
R0.01 (April 29, 2006)
R0.02 (June 01, 2006) First stable version.
Added FAT12 support.
Removed unbuffered mode.
Fixed a problem on small (<32M) partition.
R0.02 (June 01, 2006)
R0.02a (June 10, 2006) Added FAT12 support.
Added a configuration option (_FS_MINIMUM). Removed unbuffered mode.
Fixed a problem on small (<32M) partition.
R0.03 (September 22, 2006)
Added f_rename().
Changed option _FS_MINIMUM to _FS_MINIMIZE. R0.02a (June 10, 2006)
Added a configuration option (_FS_MINIMUM).
R0.03a (December 11, 2006)
Improved cluster scan algorithm to write files fast.
Fixed f_mkdir() creates incorrect directory on FAT32.
R0.03 (September 22, 2006)
R0.04 (February 04, 2007) Added f_rename().
Added f_mkfs(). Changed option _FS_MINIMUM to _FS_MINIMIZE.
Supported multiple drive system.
Changed some interfaces for multiple drive system.
Changed f_mountdrv() to f_mount().
R0.03a (December 11, 2006)
R0.04a (April 01, 2007) Improved cluster scan algorithm to write files fast.
Supported multiple partitions on a physical drive. Fixed f_mkdir() creates incorrect directory on FAT32.
Added a capability of extending file size to f_lseek().
Added minimization level 3.
Fixed an endian sensitive code in f_mkfs().
R0.04 (February 04, 2007)
R0.04b (May 05, 2007) Added f_mkfs().
Added a configuration option _USE_NTFLAG. Supported multiple drive system.
Added FSINFO support. Changed some interfaces for multiple drive system.
Fixed DBCS name can result FR_INVALID_NAME. Changed f_mountdrv() to f_mount().
Fixed short seek (<= csize) collapses the file object.
R0.05 (August 25, 2007) R0.04a (April 01, 2007)
Changed arguments of f_read(), f_write() and f_mkfs().
Fixed f_mkfs() on FAT32 creates incorrect FSINFO. Supported multiple partitions on a physical drive.
Fixed f_mkdir() on FAT32 creates incorrect directory. Added a capability of extending file size to f_lseek().
Added minimization level 3.
Fixed an endian sensitive code in f_mkfs().
R0.05a (February 03, 2008)
Added f_truncate() and f_utime().
Fixed off by one error at FAT sub-type determination.
Fixed btr in f_read() can be mistruncated. R0.04b (May 05, 2007)
Fixed cached sector is not flushed when create and close without write.
Added a configuration option _USE_NTFLAG.
Added FSINFO support.
R0.06 (April 01, 2008) Fixed DBCS name can result FR_INVALID_NAME.
Added fputc(), fputs(), fprintf() and fgets(). Fixed short seek (<= csize) collapses the file object.
Improved performance of f_lseek() on moving to the same or following cluster.
R0.07 (April 01, 2009) R0.05 (August 25, 2007)
Merged Tiny-FatFs as a configuration option. (_FS_TINY)
Added long file name feature. (_USE_LFN) Changed arguments of f_read(), f_write() and f_mkfs().
Added multiple code page feature. (_CODE_PAGE) Fixed f_mkfs() on FAT32 creates incorrect FSINFO.
Added re-entrancy for multitask operation. (_FS_REENTRANT) Fixed f_mkdir() on FAT32 creates incorrect directory.
Added auto cluster size selection to f_mkfs().
Added rewind option to f_readdir().
Changed result code of critical errors.
Renamed string functions to avoid name collision. R0.05a (February 03, 2008)
Added f_truncate() and f_utime().
R0.07a (April 14, 2009) Fixed off by one error at FAT sub-type determination.
Septemberarated out OS dependent code on reentrant cfg. Fixed btr in f_read() can be mistruncated.
Added multiple sector size feature. Fixed cached sector is not flushed when create and close without write.
R0.07c (June 21, 2009)
Fixed f_unlink() can return FR_OK on error. R0.06 (April 01, 2008)
Fixed wrong cache control in f_lseek().
Added relative path feature. Added fputc(), fputs(), fprintf() and fgets().
Added f_chdir() and f_chdrive(). Improved performance of f_lseek() on moving to the same or following cluster.
Added proper case conversion to extended character.
R0.07e (November 03, 2009) R0.07 (April 01, 2009)
Septemberarated out configuration options from ff.h to ffconf.h.
Fixed f_unlink() fails to remove a sub-directory on _FS_RPATH. Merged Tiny-FatFs as a configuration option. (_FS_TINY)
Fixed name matching error on the 13 character boundary. Added long file name feature. (_USE_LFN)
Added a configuration option, _LFN_UNICODE. Added multiple code page feature. (_CODE_PAGE)
Changed f_readdir() to return the SFN with always upper case on non-LFN cfg. Added re-entrancy for multitask operation. (_FS_REENTRANT)
Added auto cluster size selection to f_mkfs().
Added rewind option to f_readdir().
R0.08 (May 15, 2010) Changed result code of critical errors.
Added a memory configuration option. (_USE_LFN = 3) Renamed string functions to avoid name collision.
Added file lock feature. (_FS_SHARE)
Added fast seek feature. (_USE_FASTSEEK)
Changed some types on the API, XCHAR->TCHAR.
Changed .fname in the FILINFO structure on Unicode cfg. R0.07a (April 14, 2009)
String functions support UTF-8 encoding files on Unicode cfg.
Septemberarated out OS dependent code on reentrant cfg.
Added multiple sector size feature.
R0.08a (August 16, 2010)
Added f_getcwd(). (_FS_RPATH = 2)
Added sector erase feature. (_USE_ERASE)
Moved file lock semaphore table from fs object to the bss. R0.07c (June 21, 2009)
Fixed f_mkfs() creates wrong FAT32 volume.
Fixed f_unlink() can return FR_OK on error.
Fixed wrong cache control in f_lseek().
R0.08b (January 15, 2011) Added relative path feature.
Fast seek feature is also applied to f_read() and f_write(). Added f_chdir() and f_chdrive().
f_lseek() reports required table size on creating CLMP. Added proper case conversion to extended character.
Extended format syntax of f_printf().
Ignores duplicated directory separators in given path name.
R0.07e (November 03, 2009)
R0.09 (September 06, 2011)
f_mkfs() supports multiple partition to complete the multiple partition feature. Septemberarated out configuration options from ff.h to ffconf.h.
Added f_fdisk(). Fixed f_unlink() fails to remove a sub-directory on _FS_RPATH.
Fixed name matching error on the 13 character boundary.
Added a configuration option, _LFN_UNICODE.
R0.09a (August 27, 2012) Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
Changed f_open() and f_opendir() reject null object pointer to avoid crash.
Changed option name _FS_SHARE to _FS_LOCK.
Fixed assertion failure due to OS/2 EA on FAT12/16 volume.
R0.08 (May 15, 2010)
R0.09b (January 24, 2013) Added a memory configuration option. (_USE_LFN = 3)
Added f_setlabel() and f_getlabel(). Added file lock feature. (_FS_SHARE)
Added fast seek feature. (_USE_FASTSEEK)
Changed some types on the API, XCHAR->TCHAR.
R0.10 (October 02, 2013) Changed .fname in the FILINFO structure on Unicode cfg.
Added selection of character encoding on the file. (_STRF_ENCODE) String functions support UTF-8 encoding files on Unicode cfg.
Added f_closedir().
Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
Added forced mount feature with changes of f_mount().
Improved behavior of volume auto detection. R0.08a (August 16, 2010)
Improved write throughput of f_puts() and f_printf().
Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write(). Added f_getcwd(). (_FS_RPATH = 2)
Fixed f_write() can be truncated when the file size is close to 4GB. Added sector erase feature. (_USE_ERASE)
Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect error code. Moved file lock semaphore table from fs object to the bss.
Fixed f_mkfs() creates wrong FAT32 volume.
R0.10a (January 15, 2014)
Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
Added a configuration option of minimum sector size. (_MIN_SS) R0.08b (January 15, 2011)
2nd argument of f_rename() can have a drive number and it will be ignored.
Fixed f_mount() with forced mount fails when drive number is >= 1. (appeared at R0.10) Fast seek feature is also applied to f_read() and f_write().
Fixed f_close() invalidates the file object without volume lock. f_lseek() reports required table size on creating CLMP.
Fixed f_closedir() returns but the volume lock is left acquired. (appeared at R0.10) Extended format syntax of f_printf().
Fixed creation of an entry with LFN fails on too many SFN collisions. (appeared at R0.07) Ignores duplicated directory separators in given path name.
R0.10b (May 19, 2014)
Fixed a hard error in the disk I/O layer can collapse the directory entry. R0.09 (September 06, 2011)
Fixed LFN entry is not deleted on delete/rename an object with lossy converted SFN. (appeared at R0.07)
f_mkfs() supports multiple partition to complete the multiple partition feature.
Added f_fdisk().
R0.10c (November 09, 2014)
Added a configuration option for the platforms without RTC. (_FS_NORTC)
Changed option name _USE_ERASE to _USE_TRIM.
Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel(). (appeared at R0.09b) R0.09a (August 27, 2012)
Fixed a potential problem of FAT access that can appear on disk error.
Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08) Changed f_open() and f_opendir() reject null object pointer to avoid crash.
Changed option name _FS_SHARE to _FS_LOCK.
Fixed assertion failure due to OS/2 EA on FAT12/16 volume.
R0.11 (February 09, 2015)
Added f_findfirst(), f_findnext() and f_findclose(). (_USE_FIND)
Fixed f_unlink() does not remove cluster chain of the file. (appeared at R0.10c)
Fixed _FS_NORTC option does not work properly. (appeared at R0.10c) R0.09b (January 24, 2013)
Added f_setlabel() and f_getlabel().
R0.10 (October 02, 2013)
Added selection of character encoding on the file. (_STRF_ENCODE)
Added f_closedir().
Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO)
Added forced mount feature with changes of f_mount().
Improved behavior of volume auto detection.
Improved write throughput of f_puts() and f_printf().
Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write().
Fixed f_write() can be truncated when the file size is close to 4GB.
Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect value on error.
R0.10a (January 15, 2014)
Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID)
Added a configuration option of minimum sector size. (_MIN_SS)
2nd argument of f_rename() can have a drive number and it will be ignored.
Fixed f_mount() with forced mount fails when drive number is >= 1. (appeared at R0.10)
Fixed f_close() invalidates the file object without volume lock.
Fixed f_closedir() returns but the volume lock is left acquired. (appeared at R0.10)
Fixed creation of an entry with LFN fails on too many SFN collisions. (appeared at R0.07)
R0.10b (May 19, 2014)
Fixed a hard error in the disk I/O layer can collapse the directory entry.
Fixed LFN entry is not deleted on delete/rename an object with lossy converted SFN. (appeared at R0.07)
R0.10c (November 09, 2014)
Added a configuration option for the platforms without RTC. (_FS_NORTC)
Changed option name _USE_ERASE to _USE_TRIM.
Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel(). (appeared at R0.09b)
Fixed a potential problem of FAT access that can appear on disk error.
Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08)
R0.11 (February 09, 2015)
Added f_findfirst(), f_findnext() and f_findclose(). (_USE_FIND)
Fixed f_unlink() does not remove cluster chain of the file. (appeared at R0.10c)
Fixed _FS_NORTC option does not work properly. (appeared at R0.10c)
R0.11a (September 05, 2015)
Fixed wrong media change can lead a deadlock at thread-safe configuration.
Added code page 771, 860, 861, 863, 864, 865 and 869. (_CODE_PAGE)
Removed some code pages actually not exist on the standard systems. (_CODE_PAGE)
Fixed errors in the case conversion teble of code page 437 and 850 (ff.c).
Fixed errors in the case conversion teble of Unicode (cc*.c).
R0.12 (April 12, 2016)
Added support of exFAT file system. (_FS_EXFAT)
Added f_expand(). (_USE_EXPAND)
Changed some members in FINFO structure and behavior of f_readdir().
Added an option _USE_CHMOD and removed an option _WORD_ACCESS.
Fixed errors in the case conversion teble of Unicode (cc*.c).

View File

@@ -1,21 +1,21 @@
FatFs Module Source Files R0.11 FatFs Module Source Files R0.12
FILES FILES
00readme.txt This file. 00readme.txt This file.
history.txt Revision history. history.txt Revision history.
ffconf.h Configuration file for FatFs module. ffconf.h Configuration file for FatFs module.
ff.h Common include file for FatFs and application module. ff.h Common include file for FatFs and application module.
ff.c FatFs module. ff.c FatFs module.
diskio.h Common include file for FatFs and disk I/O module. diskio.h Common include file for FatFs and disk I/O module.
diskio.c An example of glue function to attach existing disk I/O module to FatFs. diskio.c An example of glue function to attach existing disk I/O module to FatFs.
integer.h Integer type definitions for FatFs. integer.h Integer type definitions for FatFs.
option Optional external functions. option Optional external functions.
Low level disk I/O module is not included in this archive because the FatFs Low level disk I/O module is not included in this archive because the FatFs
module is only a generic file system layer and not depend on any specific module is only a generic file system layer and not depend on any specific
storage device. You have to provide a low level disk I/O module that written storage device. You have to provide a low level disk I/O module that written
to control the target storage device. to control the target storage device.

View File

@@ -33,7 +33,6 @@ DSTATUS disk_status (
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
DSTATUS disk_initialize ( DSTATUS disk_initialize (
__attribute__((unused))
BYTE pdrv /* Physical drive nmuber to identify the drive */ BYTE pdrv /* Physical drive nmuber to identify the drive */
) )
{ {
@@ -57,7 +56,6 @@ DSTATUS disk_initialize (
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
DRESULT disk_read ( DRESULT disk_read (
__attribute__((unused))
BYTE pdrv, /* Physical drive nmuber to identify the drive */ BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */ BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address in LBA */ DWORD sector, /* Sector address in LBA */
@@ -87,7 +85,6 @@ DRESULT disk_read (
#if _USE_WRITE #if _USE_WRITE
DRESULT disk_write ( DRESULT disk_write (
__attribute__((unused))
BYTE pdrv, /* Physical drive nmuber to identify the drive */ BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */ const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address in LBA */ DWORD sector, /* Sector address in LBA */

3933
source/fatfs/ff.c Executable file → Normal file

File diff suppressed because it is too large Load Diff

170
source/fatfs/ff.h Executable file → Normal file
View File

@@ -1,10 +1,10 @@
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ FatFs - FAT file system module include R0.11a (C)ChaN, 2015 / FatFs - FAT file system module include R0.12 (C)ChaN, 2016
/----------------------------------------------------------------------------/ /----------------------------------------------------------------------------/
/ FatFs module is a free software that opened under license policy of / FatFs module is a free software that opened under license policy of
/ following conditions. / following conditions.
/ /
/ Copyright (C) 2015, ChaN, all right reserved. / Copyright (C) 2016, ChaN, all right reserved.
/ /
/ 1. Redistributions of source code must retain the above copyright notice, / 1. Redistributions of source code must retain the above copyright notice,
/ this condition and the following disclaimer. / this condition and the following disclaimer.
@@ -17,7 +17,7 @@
#ifndef _FATFS #ifndef _FATFS
#define _FATFS 64180 /* Revision ID */ #define _FATFS 88100 /* Revision ID */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@@ -53,7 +53,7 @@ extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
/* Type of path name strings on FatFs API */ /* Type of path name strings on FatFs API */
#if _LFN_UNICODE /* Unicode string */ #if _LFN_UNICODE /* Unicode string */
#if !_USE_LFN #if _USE_LFN == 0
#error _LFN_UNICODE must be 0 at non-LFN cfg. #error _LFN_UNICODE must be 0 at non-LFN cfg.
#endif #endif
#ifndef _INC_TCHAR #ifndef _INC_TCHAR
@@ -76,51 +76,91 @@ typedef char TCHAR;
/* File system object structure (FATFS) */ /* File system object structure (FATFS) */
typedef struct { typedef struct {
BYTE fs_type; /* FAT sub-type (0:Not mounted) */ BYTE fs_type; /* File system type (0:N/A) */
BYTE drv; /* Physical drive number */ BYTE drv; /* Physical drive number */
BYTE csize; /* Sectors per cluster (1,2,4...128) */ BYTE n_fats; /* Number of FATs (1 or 2) */
BYTE n_fats; /* Number of FAT copies (1 or 2) */
BYTE wflag; /* win[] flag (b0:dirty) */ BYTE wflag; /* win[] flag (b0:dirty) */
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */ BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
WORD id; /* File system mount ID */ WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
WORD csize; /* Cluster size [sectors] */
#if _MAX_SS != _MIN_SS #if _MAX_SS != _MIN_SS
WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */ WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
#endif
#if _FS_EXFAT
BYTE* dirbuf; /* Directory entry block scratchpad buffer */
#endif #endif
#if _FS_REENTRANT #if _FS_REENTRANT
_SYNC_t sobj; /* Identifier of sync object */ _SYNC_t sobj; /* Identifier of sync object */
#endif #endif
#if !_FS_READONLY #if !_FS_READONLY
DWORD last_clust; /* Last allocated cluster */ DWORD last_clst; /* Last allocated cluster */
DWORD free_clust; /* Number of free clusters */ DWORD free_clst; /* Number of free clusters */
#endif #endif
#if _FS_RPATH #if _FS_RPATH != 0
DWORD cdir; /* Current directory start cluster (0:root) */ DWORD cdir; /* Current directory start cluster (0:root) */
#if _FS_EXFAT
DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */
DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */
DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */
#endif #endif
DWORD n_fatent; /* Number of FAT entries, = number of clusters + 2 */ #endif
DWORD fsize; /* Sectors per FAT */ DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
DWORD volbase; /* Volume start sector */ DWORD fsize; /* Size of an FAT [sectors] */
DWORD fatbase; /* FAT start sector */ DWORD volbase; /* Volume base sector */
DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */ DWORD fatbase; /* FAT base sector */
DWORD database; /* Data start sector */ DWORD dirbase; /* Root directory base sector/cluster */
DWORD database; /* Data base sector */
DWORD winsect; /* Current sector appearing in the win[] */ DWORD winsect; /* Current sector appearing in the win[] */
BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */ BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
} FATFS; } FATFS;
/* Type of file size variables and object identifier */
#if _FS_EXFAT
#if _USE_LFN == 0
#error LFN must be enabled when enable exFAT
#endif
typedef QWORD FSIZE_t;
#else
typedef DWORD FSIZE_t;
#endif
/* Object ID and allocation information (_FDID) */
typedef struct {
FATFS* fs; /* Pointer to the owner file system object */
WORD id; /* Owner file system mount ID */
BYTE attr; /* Object attribute */
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous (no data on FAT), =3:got flagmented, b2:sub-directory stretched) */
DWORD sclust; /* Object start cluster (0:no cluster or root directory) */
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
#if _FS_EXFAT
DWORD n_cont; /* Size of coutiguous part, clusters - 1 (valid when stat == 3) */
DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */
DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */
DWORD c_ofs; /* Offset in the containing directory (valid when sclust != 0) */
#endif
#if _FS_LOCK != 0
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
#endif
} _FDID;
/* File object structure (FIL) */ /* File object structure (FIL) */
typedef struct { typedef struct {
FATFS* fs; /* Pointer to the related file system object (**do not change order**) */ _FDID obj; /* Object identifier */
WORD id; /* Owner file system mount ID (**do not change order**) */ BYTE flag; /* File status flags */
BYTE flag; /* Status flags */
BYTE err; /* Abort flag (error code) */ BYTE err; /* Abort flag (error code) */
DWORD fptr; /* File read/write pointer (Zeroed on file open) */ FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
DWORD fsize; /* File size */
DWORD sclust; /* File start cluster (0:no cluster chain, always 0 when fsize is 0) */
DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */ DWORD clust; /* Current cluster of fpter (not valid when fprt is 0) */
DWORD dsect; /* Sector number appearing in buf[] (0:invalid) */ DWORD sect; /* Sector number appearing in buf[] (0:invalid) */
#if !_FS_READONLY #if !_FS_READONLY
DWORD dir_sect; /* Sector number containing the directory entry */ DWORD dir_sect; /* Sector number containing the directory entry */
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */ BYTE* dir_ptr; /* Pointer to the directory entry in the win[] */
@@ -128,9 +168,6 @@ typedef struct {
#if _USE_FASTSEEK #if _USE_FASTSEEK
DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */ DWORD* cltbl; /* Pointer to the cluster link map table (Nulled on file open) */
#endif #endif
#if _FS_LOCK
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
#endif
#if !_FS_TINY #if !_FS_TINY
BYTE buf[_MAX_SS]; /* File private data read/write window */ BYTE buf[_MAX_SS]; /* File private data read/write window */
#endif #endif
@@ -141,23 +178,18 @@ typedef struct {
/* Directory object structure (DIR) */ /* Directory object structure (DIR) */
typedef struct { typedef struct {
FATFS* fs; /* Pointer to the owner file system object (**do not change order**) */ _FDID obj; /* Object identifier */
WORD id; /* Owner file system mount ID (**do not change order**) */ DWORD dptr; /* Current read/write offset */
WORD index; /* Current read/write index number */
DWORD sclust; /* Table start cluster (0:Root dir) */
DWORD clust; /* Current cluster */ DWORD clust; /* Current cluster */
DWORD sect; /* Current sector */ DWORD sect; /* Current sector */
BYTE* dir; /* Pointer to the current SFN entry in the win[] */ BYTE* dir; /* Pointer to the directory item in the win[] */
BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */ BYTE* fn; /* Pointer to the SFN (in/out) {body[8],ext[3],status[1]} */
#if _FS_LOCK #if _USE_LFN != 0
UINT lockid; /* File lock ID (index of file semaphore table Files[]) */ DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
#endif
#if _USE_LFN
WCHAR* lfn; /* Pointer to the LFN working buffer */ WCHAR* lfn; /* Pointer to the LFN working buffer */
WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
#endif #endif
#if _USE_FIND #if _USE_FIND
const TCHAR* pat; /* Pointer to the name matching pattern */ const TCHAR* pat; /* Pointer to the name matching pattern */
#endif #endif
} DIR; } DIR;
@@ -166,14 +198,15 @@ typedef struct {
/* File information structure (FILINFO) */ /* File information structure (FILINFO) */
typedef struct { typedef struct {
DWORD fsize; /* File size */ FSIZE_t fsize; /* File size */
WORD fdate; /* Last modified date */ WORD fdate; /* Modified date */
WORD ftime; /* Last modified time */ WORD ftime; /* Modified time */
BYTE fattrib; /* Attribute */ BYTE fattrib; /* File attribute */
TCHAR fname[13]; /* Short file name (8.3 format) */ #if _USE_LFN != 0
#if _USE_LFN TCHAR altname[13]; /* Altenative file name */
TCHAR* lfname; /* Pointer to the LFN buffer */ TCHAR fname[_MAX_LFN + 1]; /* Primary file name */
UINT lfsize; /* Size of LFN buffer in TCHAR */ #else
TCHAR fname[13]; /* File name */
#endif #endif
} FILINFO; } FILINFO;
@@ -213,8 +246,7 @@ FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a f
FRESULT f_close (FIL* fp); /* Close an open file object */ FRESULT f_close (FIL* fp); /* Close an open file object */
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */ FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from a file */
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */ FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to a file */
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */ FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of a file object */
FRESULT f_lseek (FIL* fp, DWORD ofs); /* Move file pointer of a file object */
FRESULT f_truncate (FIL* fp); /* Truncate file */ FRESULT f_truncate (FIL* fp); /* Truncate file */
FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */ FRESULT f_sync (FIL* fp); /* Flush cached data of a writing file */
FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */ FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */
@@ -227,13 +259,15 @@ FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or direc
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */ FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */ FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of the file/dir */ FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of the file/dir */
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change times-tamp of the file/dir */ FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of the file/dir */
FRESULT f_chdir (const TCHAR* path); /* Change current directory */ FRESULT f_chdir (const TCHAR* path); /* Change current directory */
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */ FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */ FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */ FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */ FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */ FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
FRESULT f_expand (FIL* fp, FSIZE_t szf, BYTE opt); /* Allocate a contiguous block to the file */
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */ FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */ FRESULT f_mkfs (const TCHAR* path, BYTE sfd, UINT au); /* Create a file system on the volume */
FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */ FRESULT f_fdisk (BYTE pdrv, const DWORD szt[], void* work); /* Divide a physical drive into some partitions */
@@ -242,10 +276,10 @@ int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */ int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */ TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
#define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize)) #define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
#define f_error(fp) ((fp)->err) #define f_error(fp) ((fp)->err)
#define f_tell(fp) ((fp)->fptr) #define f_tell(fp) ((fp)->fptr)
#define f_size(fp) ((fp)->fsize) #define f_size(fp) ((fp)->obj.objsize)
#define f_rewind(fp) f_lseek((fp), 0) #define f_rewind(fp) f_lseek((fp), 0)
#define f_rewinddir(dp) f_readdir((dp), 0) #define f_rewinddir(dp) f_readdir((dp), 0)
@@ -265,7 +299,7 @@ DWORD get_fattime (void);
#endif #endif
/* Unicode support functions */ /* Unicode support functions */
#if _USE_LFN /* Unicode - OEM code conversion */ #if _USE_LFN != 0 /* Unicode - OEM code conversion */
WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */ WCHAR ff_convert (WCHAR chr, UINT dir); /* OEM-Unicode bidirectional conversion */
WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */ WCHAR ff_wtoupper (WCHAR chr); /* Unicode upper-case conversion */
#if _USE_LFN == 3 /* Memory functions */ #if _USE_LFN == 3 /* Memory functions */
@@ -292,16 +326,13 @@ int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
/* File access control and file status flags (FIL.flag) */ /* File access control and file status flags (FIL.flag) */
#define FA_READ 0x01 #define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00
#if !_FS_READONLY
#define FA_WRITE 0x02 #define FA_WRITE 0x02
#define FA_OPEN_EXISTING 0x00
#define FA_CREATE_NEW 0x04 #define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08 #define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10 #define FA_OPEN_ALWAYS 0x10
#define FA__WRITTEN 0x20 #define _FA_MODIFIED 0x20
#define FA__DIRTY 0x40 #define _FA_DIRTY 0x40
#endif
/* FAT sub type (FATFS.fs_type) */ /* FAT sub type (FATFS.fs_type) */
@@ -309,6 +340,7 @@ int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
#define FS_FAT12 1 #define FS_FAT12 1
#define FS_FAT16 2 #define FS_FAT16 2
#define FS_FAT32 3 #define FS_FAT32 3
#define FS_EXFAT 4
/* File attribute bits for directory entry */ /* File attribute bits for directory entry */
@@ -323,26 +355,10 @@ int ff_del_syncobj (_SYNC_t sobj); /* Delete a sync object */
#define AM_MASK 0x3F /* Mask of defined bits */ #define AM_MASK 0x3F /* Mask of defined bits */
/* Fast seek feature */ /* Fast seek controls */
#define CREATE_LINKMAP 0xFFFFFFFF #define CREATE_LINKMAP ((FSIZE_t)0 - 1)
/*--------------------------------*/
/* Multi-byte word access macros */
#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
#else /* Use byte-by-byte access to the FAT structure */
#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

142
source/fatfs/ffconf.h Executable file → Normal file
View File

@@ -1,8 +1,8 @@
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ FatFs - FAT file system module configuration file R0.11a (C)ChaN, 2015 / FatFs - FAT file system module configuration file R0.12 (C)ChaN, 2016
/---------------------------------------------------------------------------*/ /---------------------------------------------------------------------------*/
#define _FFCONF 64180 /* Revision ID */ #define _FFCONF 88100 /* Revision ID */
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
/ Function Configurations / Function Configurations
@@ -19,8 +19,8 @@
/* This option defines minimization level to remove some basic API functions. /* This option defines minimization level to remove some basic API functions.
/ /
/ 0: All basic functions are enabled. / 0: All basic functions are enabled.
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(), / 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
/ f_truncate() and f_rename() function are removed. / are removed.
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. / 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
/ 3: f_lseek() function is removed in addition to 2. */ / 3: f_lseek() function is removed in addition to 2. */
@@ -34,9 +34,9 @@
/ 2: Enable with LF-CRLF conversion. */ / 2: Enable with LF-CRLF conversion. */
#define _USE_FIND 0 #define _USE_FIND 1
/* This option switches filtered directory read feature and related functions, /* This option switches filtered directory read functions, f_findfirst() and
/ f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */ / f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
#define _USE_MKFS 0 #define _USE_MKFS 0
@@ -44,7 +44,16 @@
#define _USE_FASTSEEK 0 #define _USE_FASTSEEK 0
/* This option switches fast seek feature. (0:Disable or 1:Enable) */ /* This option switches fast seek function. (0:Disable or 1:Enable) */
#define _USE_EXPAND 0
/* This option switches f_expand function. (0:Disable or 1:Enable) */
#define _USE_CHMOD 0
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
/ (0:Disable or 1:Enable) Also _FS_READONLY needs to be 0 to enable this option. */
#define _USE_LABEL 0 #define _USE_LABEL 0
@@ -54,7 +63,7 @@
#define _USE_FORWARD 0 #define _USE_FORWARD 0
/* This option switches f_forward() function. (0:Disable or 1:Enable) /* This option switches f_forward() function. (0:Disable or 1:Enable)
/ To enable it, also _FS_TINY need to be set to 1. */ / To enable it, also _FS_TINY need to be 1. */
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
@@ -92,15 +101,17 @@
#define _USE_LFN 2 #define _USE_LFN 2
#define _MAX_LFN 255 #define _MAX_LFN 255
/* The _USE_LFN option switches the LFN feature. /* The _USE_LFN switches the support of long file name (LFN).
/ /
/ 0: Disable LFN feature. _MAX_LFN has no effect. / 0: Disable support of LFN. _MAX_LFN has no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. / 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
/ 2: Enable LFN with dynamic working buffer on the STACK. / 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP. / 3: Enable LFN with dynamic working buffer on the HEAP.
/ /
/ When enable the LFN feature, Unicode handling functions (option/unicode.c) must / To enable the LFN, Unicode handling functions (option/unicode.c) must be added
/ be added to the project. The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. / to the project. The working buffer occupies (_MAX_LFN + 1) * 2 bytes and
/ additional 608 bytes at exFAT enabled. _MAX_LFN can be in range from 12 to 255.
/ It should be set 255 to support full featured LFN operations.
/ When use stack for the working buffer, take care on stack overflow. When use heap / When use stack for the working buffer, take care on stack overflow. When use heap
/ memory for the working buffer, memory management functions, ff_memalloc() and / memory for the working buffer, memory management functions, ff_memalloc() and
/ ff_memfree(), must be added to the project. */ / ff_memfree(), must be added to the project. */
@@ -108,12 +119,12 @@
#define _LFN_UNICODE 0 #define _LFN_UNICODE 0
/* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode) /* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)
/ To use Unicode string for the path name, enable LFN feature and set _LFN_UNICODE / To use Unicode string for the path name, enable LFN and set _LFN_UNICODE = 1.
/ to 1. This option also affects behavior of string I/O functions. */ / This option also affects behavior of string I/O functions. */
#define _STRF_ENCODE 3 #define _STRF_ENCODE 3
/* When _LFN_UNICODE is 1, this option selects the character encoding on the file to /* When _LFN_UNICODE == 1, this option selects the character encoding on the file to
/ be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf(). / be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
/ /
/ 0: ANSI/OEM / 0: ANSI/OEM
@@ -121,17 +132,16 @@
/ 2: UTF-16BE / 2: UTF-16BE
/ 3: UTF-8 / 3: UTF-8
/ /
/ When _LFN_UNICODE is 0, this option has no effect. */ / This option has no effect when _LFN_UNICODE == 0. */
#define _FS_RPATH 0 #define _FS_RPATH 0
/* This option configures relative path feature. /* This option configures support of relative path.
/ /
/ 0: Disable relative path feature and remove related functions. / 0: Disable relative path and remove related functions.
/ 1: Enable relative path feature. f_chdir() and f_chdrive() are available. / 1: Enable relative path. f_chdir() and f_chdrive() are available.
/ 2: f_getcwd() function is available in addition to 1. / 2: f_getcwd() function is available in addition to 1.
/ */
/ Note that directory items read via f_readdir() are affected by this option. */
/*---------------------------------------------------------------------------/ /*---------------------------------------------------------------------------/
@@ -144,7 +154,7 @@
#define _STR_VOLUME_ID 0 #define _STR_VOLUME_ID 0
#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3" #define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
/* _STR_VOLUME_ID option switches string volume ID feature. /* _STR_VOLUME_ID switches string support of volume ID.
/ When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive / When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
/ number in the path name. _VOLUME_STRS defines the drive ID strings for each / number in the path name. _VOLUME_STRS defines the drive ID strings for each
/ logical drives. Number of items must be equal to _VOLUMES. Valid characters for / logical drives. Number of items must be equal to _VOLUMES. Valid characters for
@@ -152,11 +162,12 @@
#define _MULTI_PARTITION 0 #define _MULTI_PARTITION 0
/* This option switches multi-partition feature. By default (0), each logical drive /* This option switches support of multi-partition on a physical drive.
/ number is bound to the same physical drive number and only an FAT volume found on / By default (0), each logical drive number is bound to the same physical drive
/ the physical drive will be mounted. When multi-partition feature is enabled (1), / number and only an FAT volume found on the physical drive will be mounted.
/ each logical drive number is bound to arbitrary physical drive and partition / When multi-partition is enabled (1), each logical drive number can be bound to
/ listed in the VolToPart[]. Also f_fdisk() funciton will be available. */ / arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
/ funciton will be available. */
#define _MIN_SS 512 #define _MIN_SS 512
@@ -170,8 +181,8 @@
#define _USE_TRIM 0 #define _USE_TRIM 0
/* This option switches ATA-TRIM feature. (0:Disable or 1:Enable) /* This option switches support of ATA-TRIM. (0:Disable or 1:Enable)
/ To enable Trim feature, also CTRL_TRIM command should be implemented to the / To enable Trim function, also CTRL_TRIM command should be implemented to the
/ disk_ioctl() function. */ / disk_ioctl() function. */
@@ -194,46 +205,51 @@
#define _FS_TINY 0 #define _FS_TINY 0
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) /* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
/ At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS / At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS bytes.
/ bytes. Instead of private sector buffer eliminated from the file object, / Instead of private sector buffer eliminated from the file object, common sector
/ common sector buffer in the file system object (FATFS) is used for the file / buffer in the file system object (FATFS) is used for the file data transfer. */
/ data transfer. */
#define _FS_EXFAT 0
/* This option switches support of exFAT file system in addition to the traditional
/ FAT file system. (0:Disable or 1:Enable) To enable exFAT, also LFN must be enabled.
/ Note that enabling exFAT discards C89 compatibility. */
#define _FS_NORTC 1 #define _FS_NORTC 1
#define _NORTC_MON 1 #define _NORTC_MON 3
#define _NORTC_MDAY 1 #define _NORTC_MDAY 1
#define _NORTC_YEAR 2015 #define _NORTC_YEAR 2016
/* The _FS_NORTC option switches timestamp feature. If the system does not have /* The option _FS_NORTC switches timestamp functiton. If the system does not have
/ an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable / any RTC function or valid timestamp is not needed, set _FS_NORTC = 1 to disable
/ the timestamp feature. All objects modified by FatFs will have a fixed timestamp / the timestamp function. All objects modified by FatFs will have a fixed timestamp
/ defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR. / defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR in local time.
/ When timestamp feature is enabled (_FS_NORTC == 0), get_fattime() function need / To enable timestamp function (_FS_NORTC = 0), get_fattime() function need to be
/ to be added to the project to read current time form RTC. _NORTC_MON, / added to the project to get current time form real-time clock. _NORTC_MON,
/ _NORTC_MDAY and _NORTC_YEAR have no effect. / _NORTC_MDAY and _NORTC_YEAR have no effect.
/ These options have no effect at read-only configuration (_FS_READONLY == 1). */ / These options have no effect at read-only configuration (_FS_READONLY = 1). */
#define _FS_LOCK 0 #define _FS_LOCK 0
/* The _FS_LOCK option switches file lock feature to control duplicated file open /* The option _FS_LOCK switches file lock function to control duplicated file open
/ and illegal operation to open objects. This option must be 0 when _FS_READONLY / and illegal operation to open objects. This option must be 0 when _FS_READONLY
/ is 1. / is 1.
/ /
/ 0: Disable file lock feature. To avoid volume corruption, application program / 0: Disable file lock function. To avoid volume corruption, application program
/ should avoid illegal open, remove and rename to the open objects. / should avoid illegal open, remove and rename to the open objects.
/ >0: Enable file lock feature. The value defines how many files/sub-directories / >0: Enable file lock function. The value defines how many files/sub-directories
/ can be opened simultaneously under file lock control. Note that the file / can be opened simultaneously under file lock control. Note that the file
/ lock feature is independent of re-entrancy. */ / lock control is independent of re-entrancy. */
#define _FS_REENTRANT 0 #define _FS_REENTRANT 0
#define _FS_TIMEOUT 1000 #define _FS_TIMEOUT 1000
#define _SYNC_t HANDLE #define _SYNC_t HANDLE
/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs /* The option _FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
/ module itself. Note that regardless of this option, file access to different / module itself. Note that regardless of this option, file access to different
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs() / volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
/ and f_fdisk() function, are always not re-entrant. Only file/directory access / and f_fdisk() function, are always not re-entrant. Only file/directory access
/ to the same volume is under control of this feature. / to the same volume is under control of this function.
/ /
/ 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect. / 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
/ 1: Enable re-entrancy. Also user provided synchronization handlers, / 1: Enable re-entrancy. Also user provided synchronization handlers,
@@ -247,30 +263,4 @@
/ included somewhere in the scope of ff.c. */ / included somewhere in the scope of ff.c. */
#define _WORD_ACCESS 0 /*--- End of configuration options ---*/
/* The _WORD_ACCESS option is an only platform dependent option. It defines
/ which access method is used to the word data on the FAT volume.
/
/ 0: Byte-by-byte access. Always compatible with all platforms.
/ 1: Word access. Do not choose this unless under both the following conditions.
/
/ * Address misaligned memory access is always allowed to ALL instructions.
/ * Byte order on the memory is little-endian.
/
/ If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.
/ Following table shows allowable settings of some type of processors.
/
/ ARM7TDMI 0 *2 ColdFire 0 *1 V850E 0 *2
/ Cortex-M3 0 *3 Z80 0/1 V850ES 0/1
/ Cortex-M0 0 *2 x86 0/1 TLCS-870 0/1
/ AVR 0/1 RX600(LE) 0/1 TLCS-900 0/1
/ AVR32 0 *1 RL78 0 *2 R32C 0 *2
/ PIC18 0/1 SH-2 0 *1 M16C 0/1
/ PIC24 0 *2 H8S 0 *1 MSP430 0 *2
/ PIC32 0 *1 H8/300H 0 *1 8051 0/1
/
/ *1:Big-endian.
/ *2:Unaligned memory access is not supported.
/ *3:Some compilers generate LDM/STM for mem_cpy function.
*/

15
source/fatfs/integer.h Executable file → Normal file
View File

@@ -5,13 +5,19 @@
#ifndef _FF_INTEGER #ifndef _FF_INTEGER
#define _FF_INTEGER #define _FF_INTEGER
#ifdef _WIN32 /* Development platform */ #ifdef _WIN32 /* FatFs development platform */
#include <windows.h> #include <windows.h>
#include <tchar.h> #include <tchar.h>
typedef unsigned __int64 QWORD;
#else /* Embedded platform */ #else /* Embedded platform */
/* These types MUST be 16-bit or 32-bit */
typedef int INT;
typedef unsigned int UINT;
/* This type MUST be 8-bit */ /* This type MUST be 8-bit */
typedef unsigned char BYTE; typedef unsigned char BYTE;
@@ -20,14 +26,13 @@ typedef short SHORT;
typedef unsigned short WORD; typedef unsigned short WORD;
typedef unsigned short WCHAR; typedef unsigned short WCHAR;
/* These types MUST be 16-bit or 32-bit */
typedef int INT;
typedef unsigned int UINT;
/* These types MUST be 32-bit */ /* These types MUST be 32-bit */
typedef long LONG; typedef long LONG;
typedef unsigned long DWORD; typedef unsigned long DWORD;
/* This type MUST be 64-bit (Remove this for C89 compatibility) */
typedef unsigned long long QWORD;
#endif #endif
#endif #endif

108
source/fatfs/option/ccsbcs.c Executable file → Normal file
View File

@@ -300,47 +300,87 @@ WCHAR ff_convert ( /* Converted character, Returns zero on error */
WCHAR ff_wtoupper ( /* Returns upper converted character */ WCHAR ff_wtoupper ( /* Returns upper converted character */
WCHAR chr /* Unicode character to be upper converted */ WCHAR chr /* Unicode character to be upper converted (BMP only) */
) )
{ {
static const WCHAR lower[] = { /* Lower case characters to be converted */ /* Compressed upper conversion table */
/* Latin Supplement */ 0xE0,0xE1,0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9,0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF, static const WCHAR cvt1[] = { /* U+0000 - U+0FFF */
/* Latin Extended-A */ 0x101,0x103,0x105,0x107,0x109,0x10B,0x10D,0x10F,0x111,0x113,0x115,0x117,0x119,0x11B,0x11D,0x11F,0x121,0x123,0x125,0x127,0x129,0x12B,0x12D,0x12F,0x131,0x133,0x135,0x137,0x13A,0x13C,0x13E,0x140,0x142,0x144,0x146,0x148,0x14B,0x14D,0x14F,0x151,0x153,0x155,0x157,0x159,0x15B,0x15D,0x15F,0x161,0x163,0x165,0x167,0x169,0x16B,0x16D,0x16F,0x171,0x173,0x175,0x177,0x17A,0x17C,0x17E, /* Basic Latin */
/* Latin Extended-B */ 0x183,0x185,0x188,0x18C,0x192,0x199,0x1A1,0x1A3,0x1A8,0x1AD,0x1B0,0x1B4,0x1B6,0x1B9,0x1BD,0x1C6,0x1C9,0x1CC,0x1CE,0x1D0,0x1D2,0x1D4,0x1D6,0x1D8,0x1DA,0x1DC,0x1DD,0x1DF,0x1E1,0x1E3,0x1E5,0x1E7,0x1E9,0x1EB,0x1ED,0x1EF,0x1F3,0x1F5,0x1FB,0x1FD,0x1FF,0x201,0x203,0x205,0x207,0x209,0x20B,0x20D,0x20F,0x211,0x213,0x215,0x217, 0x0061,0x031A,
/* Greek, Coptic */ 0x3B1,0x3B2,0x3B3,0x3B4,0x3B5,0x3B6,0x3B7,0x3B8,0x3B9,0x3BA,0x3BB,0x3BC,0x3BD,0x3BE,0x3BF,0x3C0,0x3C1,0x3C3,0x3C4,0x3C5,0x3C6,0x3C7,0x3C8,0x3C9,0x3CA,0x3CB,0x3CC,0x3CD,0x3CE,0x3E3,0x3E5,0x3E7,0x3E9,0x3EB, /* Latin-1 Supplement */
/* Cyrillic */ 0x430,0x431,0x432,0x433,0x434,0x435,0x436,0x437,0x438,0x439,0x43A,0x43B,0x43C,0x43D,0x43E,0x43F,0x440,0x441,0x442,0x443,0x444,0x445,0x446,0x447,0x448,0x449,0x44A,0x44B,0x44C,0x44D,0x44E,0x44F,0x452,0x453,0x454,0x455,0x456,0x457,0x458,0x459,0x45A,0x45B,0x45C,0x45E,0x45F,0x461,0x463,0x465,0x467,0x469,0x46B,0x46D,0x46F,0x471,0x473,0x475,0x477,0x479,0x47B,0x47D,0x47F,0x481,0x491,0x493,0x495,0x497,0x499,0x49B,0x49D,0x49F,0x4A1,0x4A3,0x4A5,0x4A7,0x4A9,0x4AB,0x4AD,0x4AF,0x4B1,0x4B3,0x4B5,0x4B7,0x4B9,0x4BB,0x4BD,0x4BF,0x4C2,0x4C4,0x4C8,0x4D1,0x4D3,0x4D5,0x4D7,0x4D9,0x4DB,0x4DD,0x4DF,0x4E1,0x4E3,0x4E5,0x4E7,0x4E9,0x4EB,0x4ED,0x4EF,0x4F1,0x4F3,0x4F5,0x4F9, 0x00E0,0x0317, 0x00F8,0x0307, 0x00FF,0x0001,0x0178,
/* Armenian */ 0x561,0x562,0x563,0x564,0x565,0x566,0x567,0x568,0x569,0x56A,0x56B,0x56C,0x56D,0x56E,0x56F,0x570,0x571,0x572,0x573,0x574,0x575,0x576,0x577,0x578,0x579,0x57A,0x57B,0x57C,0x57D,0x57E,0x57F,0x580,0x581,0x582,0x583,0x584,0x585,0x586, /* Latin Extended-A */
/* Latin Extended Additional */ 0x1E01,0x1E03,0x1E05,0x1E07,0x1E09,0x1E0B,0x1E0D,0x1E0F,0x1E11,0x1E13,0x1E15,0x1E17,0x1E19,0x1E1B,0x1E1D,0x1E1F,0x1E21,0x1E23,0x1E25,0x1E27,0x1E29,0x1E2B,0x1E2D,0x1E2F,0x1E31,0x1E33,0x1E35,0x1E37,0x1E39,0x1E3B,0x1E3D,0x1E3F,0x1E41,0x1E43,0x1E45,0x1E47,0x1E49,0x1E4B,0x1E4D,0x1E4F,0x1E51,0x1E53,0x1E55,0x1E57,0x1E59,0x1E5B,0x1E5D,0x1E5F,0x1E61,0x1E63,0x1E65,0x1E67,0x1E69,0x1E6B,0x1E6D,0x1E6F,0x1E71,0x1E73,0x1E75,0x1E77,0x1E79,0x1E7B,0x1E7D,0x1E7F,0x1E81,0x1E83,0x1E85,0x1E87,0x1E89,0x1E8B,0x1E8D,0x1E8F,0x1E91,0x1E93,0x1E95,0x1E97,0x1E99,0x1E9B,0x1E9D,0x1E9F,0x1EA1,0x1EA3,0x1EA5,0x1EA7,0x1EA9,0x1EAB,0x1EAD,0x1EAF,0x1EB1,0x1EB3,0x1EB5,0x1EB7,0x1EB9,0x1EBB,0x1EBD,0x1EBF,0x1EC1,0x1EC3,0x1EC5,0x1EC7,0x1EC9,0x1ECB,0x1ECD,0x1ECF,0x1ED1,0x1ED3,0x1ED5,0x1ED7,0x1ED9,0x1EDB,0x1EDD,0x1EDF,0x1EE1,0x1EE3,0x1EE5,0x1EE7,0x1EE9,0x1EEB,0x1EED,0x1EEF,0x1EF1,0x1EF3,0x1EF5,0x1EF7,0x1EF9, 0x0100,0x0130, 0x0132,0x0106, 0x0139,0x0110, 0x014A,0x012E, 0x0179,0x0106,
/* Number forms */ 0x2170,0x2171,0x2172,0x2173,0x2174,0x2175,0x2176,0x2177,0x2178,0x2179,0x217A,0x217B,0x217C,0x217D,0x217E,0x217F, /* Latin Extended-B */
/* Full-width */ 0xFF41,0xFF42,0xFF43,0xFF44,0xFF45,0xFF46,0xFF47,0xFF48,0xFF49,0xFF4A,0xFF4B,0xFF4C,0xFF4D,0xFF4E,0xFF4F,0xFF50,0xFF51,0xFF52,0xFF53,0xFF54,0xFF55,0xFF56,0xFF57,0xFF58,0xFF59,0xFF5A 0x0180,0x004D,0x0243,0x0181,0x0182,0x0182,0x0184,0x0184,0x0186,0x0187,0x0187,0x0189,0x018A,0x018B,0x018B,0x018D,0x018E,0x018F,0x0190,0x0191,0x0191,0x0193,0x0194,0x01F6,0x0196,0x0197,0x0198,0x0198,0x023D,0x019B,0x019C,0x019D,0x0220,0x019F,0x01A0,0x01A0,0x01A2,0x01A2,0x01A4,0x01A4,0x01A6,0x01A7,0x01A7,0x01A9,0x01AA,0x01AB,0x01AC,0x01AC,0x01AE,0x01AF,0x01AF,0x01B1,0x01B2,0x01B3,0x01B3,0x01B5,0x01B5,0x01B7,0x01B8,0x01B8,0x01BA,0x01BB,0x01BC,0x01BC,0x01BE,0x01F7,0x01C0,0x01C1,0x01C2,0x01C3,0x01C4,0x01C5,0x01C4,0x01C7,0x01C8,0x01C7,0x01CA,0x01CB,0x01CA,
0x01CD,0x0110, 0x01DD,0x0001,0x018E, 0x01DE,0x0112, 0x01F3,0x0003,0x01F1,0x01F4,0x01F4, 0x01F8,0x0128,
0x0222,0x0112, 0x023A,0x0009,0x2C65,0x023B,0x023B,0x023D,0x2C66,0x023F,0x0240,0x0241,0x0241, 0x0246,0x010A,
/* IPA Extensions */
0x0253,0x0040,0x0181,0x0186,0x0255,0x0189,0x018A,0x0258,0x018F,0x025A,0x0190,0x025C,0x025D,0x025E,0x025F,0x0193,0x0261,0x0262,0x0194,0x0264,0x0265,0x0266,0x0267,0x0197,0x0196,0x026A,0x2C62,0x026C,0x026D,0x026E,0x019C,0x0270,0x0271,0x019D,0x0273,0x0274,0x019F,0x0276,0x0277,0x0278,0x0279,0x027A,0x027B,0x027C,0x2C64,0x027E,0x027F,0x01A6,0x0281,0x0282,0x01A9,0x0284,0x0285,0x0286,0x0287,0x01AE,0x0244,0x01B1,0x01B2,0x0245,0x028D,0x028E,0x028F,0x0290,0x0291,0x01B7,
/* Greek, Coptic */
0x037B,0x0003,0x03FD,0x03FE,0x03FF, 0x03AC,0x0004,0x0386,0x0388,0x0389,0x038A, 0x03B1,0x0311,
0x03C2,0x0002,0x03A3,0x03A3, 0x03C4,0x0308, 0x03CC,0x0003,0x038C,0x038E,0x038F, 0x03D8,0x0118,
0x03F2,0x000A,0x03F9,0x03F3,0x03F4,0x03F5,0x03F6,0x03F7,0x03F7,0x03F9,0x03FA,0x03FA,
/* Cyrillic */
0x0430,0x0320, 0x0450,0x0710, 0x0460,0x0122, 0x048A,0x0136, 0x04C1,0x010E, 0x04CF,0x0001,0x04C0, 0x04D0,0x0144,
/* Armenian */
0x0561,0x0426,
0x0000
}; };
static const WCHAR upper[] = { /* Upper case characters correspond to lower[] */ static const WCHAR cvt2[] = { /* U+1000 - U+FFFF */
0xC0,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7,0xC8,0xC9,0xCA,0xCB,0xCC,0xCD,0xCE,0xCF,0xD0,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6,0xD8,0xD9,0xDA,0xDB,0xDC,0xDD,0xDE,0x178, /* Phonetic Extensions */
0x100,0x102,0x104,0x106,0x108,0x10A,0x10C,0x10E,0x110,0x112,0x114,0x116,0x118,0x11A,0x11C,0x11E,0x120,0x122,0x124,0x126,0x128,0x12A,0x12C,0x12E,0x130,0x132,0x134,0x136,0x139,0x13B,0x13D,0x13F,0x141,0x143,0x145,0x147,0x14A,0x14C,0x14E,0x150,0x152,0x154,0x156,0x158,0x15A,0x15C,0x15E,0x160,0x162,0x164,0x166,0x168,0x16A,0x16C,0x16E,0x170,0x172,0x174,0x176,0x179,0x17B,0x17D, 0x1D7D,0x0001,0x2C63,
0x182,0x184,0x187,0x18B,0x191,0x198,0x1A0,0x1A2,0x1A7,0x1AC,0x1AF,0x1B3,0x1B5,0x1B8,0x1BC,0x1C4,0x1C7,0x1CA,0x1CD,0x1CF,0x1D1,0x1D3,0x1D5,0x1D7,0x1D9,0x1DB,0x18E,0x1DE,0x1E0,0x1E2,0x1E4,0x1E6,0x1E8,0x1EA,0x1EC,0x1EE,0x1F1,0x1F4,0x1FA,0x1FC,0x1FE,0x200,0x202,0x204,0x206,0x208,0x20A,0x20C,0x20E,0x210,0x212,0x214,0x216, /* Latin Extended Additional */
0x391,0x392,0x393,0x394,0x395,0x396,0x397,0x398,0x399,0x39A,0x39B,0x39C,0x39D,0x39E,0x39F,0x3A0,0x3A1,0x3A3,0x3A4,0x3A5,0x3A6,0x3A7,0x3A8,0x3A9,0x3AA,0x3AB,0x38C,0x38E,0x38F,0x3E2,0x3E4,0x3E6,0x3E8,0x3EA, 0x1E00,0x0196, 0x1EA0,0x015A,
0x410,0x411,0x412,0x413,0x414,0x415,0x416,0x417,0x418,0x419,0x41A,0x41B,0x41C,0x41D,0x41E,0x41F,0x420,0x421,0x422,0x423,0x424,0x425,0x426,0x427,0x428,0x429,0x42A,0x42B,0x42C,0x42D,0x42E,0x42F,0x402,0x403,0x404,0x405,0x406,0x407,0x408,0x409,0x40A,0x40B,0x40C,0x40E,0x40F,0x460,0x462,0x464,0x466,0x468,0x46A,0x46C,0x46E,0x470,0x472,0x474,0x476,0x478,0x47A,0x47C,0x47E,0x480,0x490,0x492,0x494,0x496,0x498,0x49A,0x49C,0x49E,0x4A0,0x4A2,0x4A4,0x4A6,0x4A8,0x4AA,0x4AC,0x4AE,0x4B0,0x4B2,0x4B4,0x4B6,0x4B8,0x4BA,0x4BC,0x4BE,0x4C1,0x4C3,0x5C7,0x4D0,0x4D2,0x4D4,0x4D6,0x4D8,0x4DA,0x4DC,0x4DE,0x4E0,0x4E2,0x4E4,0x4E6,0x4E8,0x4EA,0x4EC,0x4EE,0x4F0,0x4F2,0x4F4,0x4F8, /* Greek Extended */
0x531,0x532,0x533,0x534,0x535,0x536,0x537,0x538,0x539,0x53A,0x53B,0x53C,0x53D,0x53E,0x53F,0x540,0x541,0x542,0x543,0x544,0x545,0x546,0x547,0x548,0x549,0x54A,0x54B,0x54C,0x54D,0x54E,0x54F,0x550,0x551,0x552,0x553,0x554,0x555,0x556, 0x1F00,0x0608, 0x1F10,0x0606, 0x1F20,0x0608, 0x1F30,0x0608, 0x1F40,0x0606,
0x1E00,0x1E02,0x1E04,0x1E06,0x1E08,0x1E0A,0x1E0C,0x1E0E,0x1E10,0x1E12,0x1E14,0x1E16,0x1E18,0x1E1A,0x1E1C,0x1E1E,0x1E20,0x1E22,0x1E24,0x1E26,0x1E28,0x1E2A,0x1E2C,0x1E2E,0x1E30,0x1E32,0x1E34,0x1E36,0x1E38,0x1E3A,0x1E3C,0x1E3E,0x1E40,0x1E42,0x1E44,0x1E46,0x1E48,0x1E4A,0x1E4C,0x1E4E,0x1E50,0x1E52,0x1E54,0x1E56,0x1E58,0x1E5A,0x1E5C,0x1E5E,0x1E60,0x1E62,0x1E64,0x1E66,0x1E68,0x1E6A,0x1E6C,0x1E6E,0x1E70,0x1E72,0x1E74,0x1E76,0x1E78,0x1E7A,0x1E7C,0x1E7E,0x1E80,0x1E82,0x1E84,0x1E86,0x1E88,0x1E8A,0x1E8C,0x1E8E,0x1E90,0x1E92,0x1E94,0x1E96,0x1E98,0x1E9A,0x1E9C,0x1E9E,0x1EA0,0x1EA2,0x1EA4,0x1EA6,0x1EA8,0x1EAA,0x1EAC,0x1EAE,0x1EB0,0x1EB2,0x1EB4,0x1EB6,0x1EB8,0x1EBA,0x1EBC,0x1EBE,0x1EC0,0x1EC2,0x1EC4,0x1EC6,0x1EC8,0x1ECA,0x1ECC,0x1ECE,0x1ED0,0x1ED2,0x1ED4,0x1ED6,0x1ED8,0x1EDA,0x1EDC,0x1EDE,0x1EE0,0x1EE2,0x1EE4,0x1EE6,0x1EE8,0x1EEA,0x1EEC,0x1EEE,0x1EF0,0x1EF2,0x1EF4,0x1EF6,0x1EF8, 0x1F51,0x0007,0x1F59,0x1F52,0x1F5B,0x1F54,0x1F5D,0x1F56,0x1F5F, 0x1F60,0x0608,
0x2160,0x2161,0x2162,0x2163,0x2164,0x2165,0x2166,0x2167,0x2168,0x2169,0x216A,0x216B,0x216C,0x216D,0x216E,0x216F, 0x1F70,0x000E,0x1FBA,0x1FBB,0x1FC8,0x1FC9,0x1FCA,0x1FCB,0x1FDA,0x1FDB,0x1FF8,0x1FF9,0x1FEA,0x1FEB,0x1FFA,0x1FFB,
0xFF21,0xFF22,0xFF23,0xFF24,0xFF25,0xFF26,0xFF27,0xFF28,0xFF29,0xFF2A,0xFF2B,0xFF2C,0xFF2D,0xFF2E,0xFF2F,0xFF30,0xFF31,0xFF32,0xFF33,0xFF34,0xFF35,0xFF36,0xFF37,0xFF38,0xFF39,0xFF3A 0x1F80,0x0608, 0x1F90,0x0608, 0x1FA0,0x0608, 0x1FB0,0x0004,0x1FB8,0x1FB9,0x1FB2,0x1FBC,
0x1FCC,0x0001,0x1FC3, 0x1FD0,0x0602, 0x1FE0,0x0602, 0x1FE5,0x0001,0x1FEC, 0x1FF2,0x0001,0x1FFC,
/* Letterlike Symbols */
0x214E,0x0001,0x2132,
/* Number forms */
0x2170,0x0210, 0x2184,0x0001,0x2183,
/* Enclosed Alphanumerics */
0x24D0,0x051A, 0x2C30,0x042F,
/* Latin Extended-C */
0x2C60,0x0102, 0x2C67,0x0106, 0x2C75,0x0102,
/* Coptic */
0x2C80,0x0164,
/* Georgian Supplement */
0x2D00,0x0826,
/* Full-width */
0xFF41,0x031A,
0x0000
}; };
UINT i, n, hi, li; const WCHAR *p;
WCHAR bc, nc, cmd;
if (chr < 0x80) { /* ASCII characters (acceleration) */ p = chr < 0x1000 ? cvt1 : cvt2;
if (chr >= 0x61 && chr <= 0x7A) chr -= 0x20; for (;;) {
bc = *p++; /* Get block base */
} else { /* Non ASCII characters (table search) */ if (!bc || chr < bc) break;
n = 12; li = 0; hi = sizeof lower / sizeof lower[0]; nc = *p++; cmd = nc >> 8; nc &= 0xFF; /* Get processing command and block size */
do { if (chr < bc + nc) { /* In the block? */
i = li + (hi - li) / 2; switch (cmd) {
if (chr == lower[i]) break; case 0: chr = p[chr - bc]; break; /* Table conversion */
if (chr > lower[i]) li = i; else hi = i; case 1: chr -= (chr - bc) & 1; break; /* Case pairs */
} while (--n); case 2: chr -= 16; break; /* Shift -16 */
if (n) chr = upper[i]; case 3: chr -= 32; break; /* Shift -32 */
case 4: chr -= 48; break; /* Shift -48 */
case 5: chr -= 26; break; /* Shift -26 */
case 6: chr += 8; break; /* Shift +8 */
case 7: chr -= 80; break; /* Shift -80 */
case 8: chr -= 0x1C60; break; /* Shift -0x1C60 */
}
break;
}
if (!cmd) p += nc;
} }
return chr; return chr;

View File

@@ -194,22 +194,6 @@ u32 __attribute__((noinline)) sdmmc_nand_readsectors(u32 sector_no, u32 numsecto
return geterror(&handleNAND); return geterror(&handleNAND);
} }
u32 __attribute__((noinline)) sdmmc_nand_writesectors(u32 sector_no, u32 numsectors, vu8 *in) //experimental
{
if (handleNAND.isSDHC == 0)
sector_no <<= 9;
inittarget(&handleNAND);
sdmmc_write16(REG_SDSTOP,0x100);
sdmmc_write16(REG_SDBLKCOUNT,numsectors);
handleNAND.data = in;
handleNAND.size = numsectors << 9;
sdmmc_send_command(&handleNAND,0x52C19,sector_no);
inittarget(&handleSD);
return geterror(&handleNAND);
}
static u32 calcSDSize(u8* csd, int type) static u32 calcSDSize(u8* csd, int type)
{ {
u32 result = 0; u32 result = 0;
@@ -395,11 +379,11 @@ static int SD_Init()
return 0; return 0;
} }
int sdmmc_sdcard_init() void sdmmc_sdcard_init()
{ {
InitSD(); InitSD();
int result = Nand_Init(); Nand_Init();
return result | SD_Init(); SD_Init();
} }
int sdmmc_get_cid(int isNand, uint32_t *info) int sdmmc_get_cid(int isNand, uint32_t *info)

View File

@@ -118,11 +118,12 @@ typedef struct mmcdevice {
u32 res; u32 res;
} mmcdevice; } mmcdevice;
int sdmmc_sdcard_init(); mmcdevice *getMMCDevice(int drive);
void sdmmc_sdcard_init();
u32 sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, vu8 *out); u32 sdmmc_sdcard_readsectors(u32 sector_no, u32 numsectors, vu8 *out);
u32 sdmmc_sdcard_writesectors(u32 sector_no, u32 numsectors, vu8 *in); u32 sdmmc_sdcard_writesectors(u32 sector_no, u32 numsectors, vu8 *in);
mmcdevice *getMMCDevice(int drive);
int sdmmc_get_cid( int isNand, uint32_t *info);
u32 sdmmc_nand_readsectors(u32 sector_no, u32 numsectors, vu8 *out); u32 sdmmc_nand_readsectors(u32 sector_no, u32 numsectors, vu8 *out);
u32 sdmmc_nand_writesectors(u32 sector_no, u32 numsectors, vu8 *in);
int sdmmc_get_cid( int isNand, uint32_t *info);

View File

@@ -1,7 +1,5 @@
/* /*
* firm.c * firm.c
* by Reisyukaku / Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#include "firm.h" #include "firm.h"
@@ -14,7 +12,6 @@
#include "crypto.h" #include "crypto.h"
#include "draw.h" #include "draw.h"
#include "screeninit.h" #include "screeninit.h"
#include "loader.h"
#include "buttons.h" #include "buttons.h"
#include "../build/patches.h" #include "../build/patches.h"
@@ -44,8 +41,8 @@ void main(void)
mountFs(); mountFs();
//Attempt to read the configuration file //Attempt to read the configuration file
const char configPath[] = "/aurei/config.bin"; const char configPath[] = "/luma/config.bin";
if(fileRead(&config, configPath, 4)) needConfig = 1; if(!fileRead(&config, configPath, 4)) needConfig = 1;
else else
{ {
config = 0; config = 0;
@@ -80,9 +77,6 @@ void main(void)
//Get pressed buttons //Get pressed buttons
u32 pressed = HID_PAD; u32 pressed = HID_PAD;
//Determine if we need to autoboot sysNAND
u32 autoBootSys = CONFIG(0);
//Determine if A9LH is installed and the user has an updated sysNAND //Determine if A9LH is installed and the user has an updated sysNAND
if(a9lhBoot || CONFIG(2)) if(a9lhBoot || CONFIG(2))
@@ -111,7 +105,7 @@ void main(void)
if(previousFirm == 7) if(previousFirm == 7)
{ {
nandType = 0; nandType = 0;
firmSource = updatedSys ? 0 : BOOTCONFIG(0, 3); firmSource = updatedSys ? 0 : BOOTCONFIG(2, 1);
needConfig = 0; needConfig = 0;
//Flag to prevent multiple boot options-forcing //Flag to prevent multiple boot options-forcing
@@ -134,14 +128,16 @@ void main(void)
the Safe Mode combo is not pressed, chainload an external payload */ the Safe Mode combo is not pressed, chainload an external payload */
if(((pressed & SINGLE_PAYLOAD_BUTTONS) || ((pressed & BUTTON_L1) && (pressed & L_PAYLOAD_BUTTONS))) if(((pressed & SINGLE_PAYLOAD_BUTTONS) || ((pressed & BUTTON_L1) && (pressed & L_PAYLOAD_BUTTONS)))
&& pressed != SAFE_MODE) && pressed != SAFE_MODE)
loadPayload(); loadPayload(pressed);
//If no configuration file exists or SELECT is held, load configuration menu //If no configuration file exists or SELECT is held, load configuration menu
if(needConfig == 2 || (pressed & BUTTON_SELECT)) if(needConfig == 2 || (pressed & BUTTON_SELECT))
configureCFW(configPath); configureCFW(configPath);
//If screens are inited or the corresponding option is set, load splash screen //If screens are inited or the corresponding option is set, load splash screen
if(PDN_GPU_CNT != 1 || CONFIG(8)) loadSplash(); if(PDN_GPU_CNT != 1 || CONFIG(7)) loadSplash();
u32 autoBootSys = CONFIG(0);
//Determine if we need to boot an emuNAND or sysNAND //Determine if we need to boot an emuNAND or sysNAND
nandType = (pressed & BUTTON_L1) ? autoBootSys : ((pressed & BUTTON_R1) ? updatedSys : !autoBootSys); nandType = (pressed & BUTTON_L1) ? autoBootSys : ((pressed & BUTTON_R1) ? updatedSys : !autoBootSys);
@@ -181,7 +177,7 @@ void main(void)
} }
} }
loadFirm(firmType, !firmType && (nandType == 2 || updatedSys == !firmSource)); loadFirm(firmType, !firmType && updatedSys == !firmSource);
if(!firmType) patchNativeFirm(nandType, emuHeader, a9lhInstalled); if(!firmType) patchNativeFirm(nandType, emuHeader, a9lhInstalled);
else patchTwlAgbFirm(firmType); else patchTwlAgbFirm(firmType);
@@ -189,29 +185,17 @@ void main(void)
launchFirm(bootType); launchFirm(bootType);
} }
//Load FIRM into FCRAM
static inline void loadFirm(u32 firmType, u32 externalFirm) static inline void loadFirm(u32 firmType, u32 externalFirm)
{ {
section = firm->section; section = firm->section;
u32 firmSize; u32 externalFirmLoaded = externalFirm &&
!fileRead(firm, "/luma/firmware.bin", 0) &&
(((u32)section[2].address >> 8) & 0xFF) == (console ? 0x60 : 0x68);
if(externalFirm) /* If the conditions to load the external FIRM aren't met, or reading fails, or the FIRM
{ doesn't match the console, load FIRM from CTRNAND */
const char *path = "/aurei/firmware.bin"; if(!externalFirmLoaded)
firmSize = fileSize(path);
if(firmSize)
{
fileRead(firm, path, firmSize);
//Check that the loaded FIRM matches the console
if((((u32)section[2].address >> 8) & 0xFF) != (console ? 0x60 : 0x68)) firmSize = 0;
}
}
else firmSize = 0;
if(!firmSize)
{ {
const char *firmFolders[3][2] = {{ "00000002", "20000002" }, const char *firmFolders[3][2] = {{ "00000002", "20000002" },
{ "00000102", "20000102" }, { "00000102", "20000102" },
@@ -273,13 +257,6 @@ static inline void patchNativeFirm(u32 nandType, u32 emuHeader, u32 a9lhInstalle
*(u16 *)sigOffset2 = sigPatch[0]; *(u16 *)sigOffset2 = sigPatch[0];
*((u16 *)sigOffset2 + 1) = sigPatch[1]; *((u16 *)sigOffset2 + 1) = sigPatch[1];
if(CONFIG(5))
{
//Apply UNITINFO patch
u8 *unitInfoOffset = getUnitInfoValueSet(arm9Section, section[2].size);
*unitInfoOffset = unitInfoPatch;
}
//Replace the FIRM loader with the injector //Replace the FIRM loader with the injector
injectLoader(); injectLoader();
} }
@@ -383,7 +360,8 @@ static inline void patchTwlAgbFirm(u32 firmType)
/* Calculate the amount of patches to apply. Only count the boot screen patch for AGB_FIRM /* Calculate the amount of patches to apply. Only count the boot screen patch for AGB_FIRM
if the matching option was enabled (keep it as last) */ if the matching option was enabled (keep it as last) */
u32 numPatches = firmType == 1 ? (sizeof(twlPatches) / sizeof(patchData)) : (sizeof(agbPatches) / sizeof(patchData) - !CONFIG(7)); u32 numPatches = firmType == 1 ? (sizeof(twlPatches) / sizeof(patchData)) :
(sizeof(agbPatches) / sizeof(patchData) - !CONFIG(6));
const patchData *patches = firmType == 1 ? twlPatches : agbPatches; const patchData *patches = firmType == 1 ? twlPatches : agbPatches;
//Patch //Patch
@@ -405,7 +383,7 @@ static inline void patchTwlAgbFirm(u32 firmType)
static inline void launchFirm(u32 bootType) static inline void launchFirm(u32 bootType)
{ {
//Copy firm partitions to respective memory locations //Copy FIRM sections to respective memory locations
for(u32 i = 0; i < 4 && section[i].size; i++) for(u32 i = 0; i < 4 && section[i].size; i++)
memcpy(section[i].address, (u8 *)firm + section[i].offset, section[i].size); memcpy(section[i].address, (u8 *)firm + section[i].offset, section[i].size);
@@ -421,6 +399,6 @@ static inline void launchFirm(u32 bootType)
//Set ARM11 kernel entrypoint //Set ARM11 kernel entrypoint
*arm11 = (u32)firm->arm11Entry; *arm11 = (u32)firm->arm11Entry;
//Final jump to arm9 kernel //Final jump to ARM9 kernel
((void (*)())firm->arm9Entry)(); ((void (*)())firm->arm9Entry)();
} }

View File

@@ -1,7 +1,5 @@
/* /*
* firm.h * firm.h
* by Reisyukaku / Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#pragma once #pragma once

View File

@@ -1,12 +1,16 @@
/* /*
* fs.c * fs.c
* by Reisyukaku / Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#include "fs.h" #include "fs.h"
#include "memory.h" #include "memory.h"
#include "screeninit.h"
#include "fatfs/ff.h" #include "fatfs/ff.h"
#include "buttons.h"
#include "../build/loader.h"
#define PAYLOAD_ADDRESS 0x24F00000
#define PATTERN(a) a "_*.bin"
static FATFS sdFs, static FATFS sdFs,
nandFs; nandFs;
@@ -21,59 +25,73 @@ u32 mountFs(void)
u32 fileRead(void *dest, const char *path, u32 size) u32 fileRead(void *dest, const char *path, u32 size)
{ {
FRESULT fr; FRESULT result;
FIL fp; FIL file;
unsigned int br = 0;
fr = f_open(&fp, path, FA_READ); result = f_open(&file, path, FA_READ);
if(fr == FR_OK) if(result == FR_OK)
{ {
if(!size) size = f_size(&fp); unsigned int read;
fr = f_read(&fp, dest, size, &br); if(!size) size = f_size(&file);
result = f_read(&file, dest, size, &read);
} }
f_close(&fp); f_close(&file);
return fr ? 0 : 1; return result;
} }
u32 fileWrite(const void *buffer, const char *path, u32 size) u32 fileWrite(const void *buffer, const char *path, u32 size)
{ {
FRESULT fr; FRESULT result;
FIL fp; FIL file;
unsigned int br = 0;
fr = f_open(&fp, path, FA_WRITE | FA_OPEN_ALWAYS); result = f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS);
if(fr == FR_OK) fr = f_write(&fp, buffer, size, &br); if(result == FR_OK)
{
unsigned int read;
result = f_write(&file, buffer, size, &read);
}
f_close(&fp); f_close(&file);
return fr ? 0 : 1; return result;
} }
u32 fileSize(const char *path) void loadPayload(u32 pressed)
{ {
FIL fp; const char *pattern;
u32 size = 0;
if(f_open(&fp, path, FA_READ) == FR_OK) if(pressed & BUTTON_RIGHT) pattern = PATTERN("right");
size = f_size(&fp); else if(pressed & BUTTON_LEFT) pattern = PATTERN("left");
else if(pressed & BUTTON_UP) pattern = PATTERN("up");
else if(pressed & BUTTON_DOWN) pattern = PATTERN("down");
else if(pressed & BUTTON_X) pattern = PATTERN("x");
else if(pressed & BUTTON_Y) pattern = PATTERN("y");
else if(pressed & BUTTON_R1) pattern = PATTERN("r");
else if(pressed & BUTTON_A) pattern = PATTERN("a");
else if(pressed & BUTTON_START) pattern = PATTERN("start");
else pattern = PATTERN("select");
f_close(&fp); DIR dir;
FILINFO info;
char path[] = "/luma/payloads";
return size; FRESULT result = f_findfirst(&dir, &info, path, pattern);
}
u32 fileExists(const char *path) f_closedir(&dir);
{
FIL fp;
u32 exists = 0;
if(f_open(&fp, path, FA_READ) == FR_OK) exists = 1; if(result == FR_OK && info.fname[0])
{
initScreens();
memcpy((void *)PAYLOAD_ADDRESS, loader, loader_size);
f_close(&fp); path[sizeof(path) - 1] = '/';
memcpy((void *)(PAYLOAD_ADDRESS + 4), path, sizeof(path));
memcpy((void *)(PAYLOAD_ADDRESS + 4 + sizeof(path)), info.altname, 13);
return exists; ((void (*)())PAYLOAD_ADDRESS)();
}
} }
void firmRead(void *dest, const char *firmFolder) void firmRead(void *dest, const char *firmFolder)
@@ -82,31 +100,28 @@ void firmRead(void *dest, const char *firmFolder)
memcpy(&path[18], firmFolder, 8); memcpy(&path[18], firmFolder, 8);
DIR dir; DIR dir;
FILINFO info = { .lfname = NULL }; FILINFO info;
f_opendir(&dir, path); f_opendir(&dir, path);
u32 id = 0; u32 id = 0xFFFFFFFF;
//Parse the target directory //Parse the target directory
while(f_readdir(&dir, &info) == FR_OK) while(f_readdir(&dir, &info) == FR_OK && info.fname[0])
{ {
//We've parsed the whole folder
if(!info.fname[0]) break;
//Not a cxi //Not a cxi
if(info.fname[9] != 'a' && info.fname[9] != 'A') continue; if(info.altname[9] != 'A') continue;
//Convert the .app name to an integer //Convert the .app name to an integer
u32 tempId = 0; u32 tempId = 0;
for(char *tmp = info.fname; *tmp != '.'; tmp++) for(char *tmp = info.altname; *tmp != '.'; tmp++)
{ {
tempId <<= 4; tempId <<= 4;
tempId += *tmp > '9' ? *tmp - 'A' + 10 : *tmp - '0'; tempId += *tmp > '9' ? *tmp - 'A' + 10 : *tmp - '0';
} }
//Found a newer cxi //Found an older cxi
if(tempId > id) id = tempId; if(tempId < id) id = tempId;
} }
f_closedir(&dir); f_closedir(&dir);
@@ -114,12 +129,12 @@ void firmRead(void *dest, const char *firmFolder)
//Complete the string with the .app name //Complete the string with the .app name
memcpy(&path[34], "/00000000.app", 14); memcpy(&path[34], "/00000000.app", 14);
//Last digit of the .app
u32 i = 42; u32 i = 42;
//Convert back the .app name from integer to array //Convert back the .app name from integer to array
while(id > 0) while(id)
{ {
//Last digit of the .app
static const char hexDigits[] = "0123456789ABCDEF"; static const char hexDigits[] = "0123456789ABCDEF";
path[i--] = hexDigits[id & 0xF]; path[i--] = hexDigits[id & 0xF];
id >>= 4; id >>= 4;

View File

@@ -1,7 +1,5 @@
/* /*
* fs.h * fs.h
* by Reisyukaku / Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#pragma once #pragma once
@@ -11,6 +9,5 @@
u32 mountFs(void); u32 mountFs(void);
u32 fileRead(void *dest, const char *path, u32 size); u32 fileRead(void *dest, const char *path, u32 size);
u32 fileWrite(const void *buffer, const char *path, u32 size); u32 fileWrite(const void *buffer, const char *path, u32 size);
u32 fileSize(const char *path); void loadPayload(u32 pressed);
u32 fileExists(const char *path);
void firmRead(void *dest, const char *firmFolder); void firmRead(void *dest, const char *firmFolder);

View File

@@ -22,26 +22,26 @@ static inline u8 i2cGetDeviceRegAddr(u8 device_id)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static vu8* reg_data_addrs[] = { static vu8 *reg_data_addrs[] = {
(vu8*)(I2C1_REG_OFF + I2C_REG_DATA), (vu8 *)(I2C1_REG_OFF + I2C_REG_DATA),
(vu8*)(I2C2_REG_OFF + I2C_REG_DATA), (vu8 *)(I2C2_REG_OFF + I2C_REG_DATA),
(vu8*)(I2C3_REG_OFF + I2C_REG_DATA), (vu8 *)(I2C3_REG_OFF + I2C_REG_DATA),
}; };
static inline vu8* i2cGetDataReg(u8 bus_id) static inline vu8 *i2cGetDataReg(u8 bus_id)
{ {
return reg_data_addrs[bus_id]; return reg_data_addrs[bus_id];
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static vu8* reg_cnt_addrs[] = { static vu8 *reg_cnt_addrs[] = {
(vu8*)(I2C1_REG_OFF + I2C_REG_CNT), (vu8 *)(I2C1_REG_OFF + I2C_REG_CNT),
(vu8*)(I2C2_REG_OFF + I2C_REG_CNT), (vu8 *)(I2C2_REG_OFF + I2C_REG_CNT),
(vu8*)(I2C3_REG_OFF + I2C_REG_CNT), (vu8 *)(I2C3_REG_OFF + I2C_REG_CNT),
}; };
static inline vu8* i2cGetCntReg(u8 bus_id) static inline vu8 *i2cGetCntReg(u8 bus_id)
{ {
return reg_cnt_addrs[bus_id]; return reg_cnt_addrs[bus_id];
} }
@@ -94,16 +94,16 @@ u32 i2cWriteRegister(u8 dev_id, u8 reg, u8 data)
u8 bus_id = i2cGetDeviceBusId(dev_id); u8 bus_id = i2cGetDeviceBusId(dev_id);
u8 dev_addr = i2cGetDeviceRegAddr(dev_id); u8 dev_addr = i2cGetDeviceRegAddr(dev_id);
for (u32 i = 0; i < 8; i++) for(u32 i = 0; i < 8; i++)
{ {
if (i2cSelectDevice(bus_id, dev_addr) && i2cSelectRegister(bus_id, reg)) if(i2cSelectDevice(bus_id, dev_addr) && i2cSelectRegister(bus_id, reg))
{ {
i2cWaitBusy(bus_id); i2cWaitBusy(bus_id);
*i2cGetDataReg(bus_id) = data; *i2cGetDataReg(bus_id) = data;
*i2cGetCntReg(bus_id) = 0xC1; *i2cGetCntReg(bus_id) = 0xC1;
i2cStop(bus_id, 0); i2cStop(bus_id, 0);
if (i2cGetResult(bus_id)) if(i2cGetResult(bus_id))
return 1; return 1;
} }
*i2cGetCntReg(bus_id) = 0xC5; *i2cGetCntReg(bus_id) = 0xC5;

View File

@@ -1,23 +0,0 @@
/*
* loader.c
* by Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/
#include "loader.h"
#include "fs.h"
#include "memory.h"
#include "screeninit.h"
#include "../build/loader.h"
#define PAYLOAD_ADDRESS 0x24F00000
void loadPayload(void)
{
if(fileExists("aurei/payloads/default.bin"))
{
initScreens();
memcpy((void *)PAYLOAD_ADDRESS, loader, loader_size);
((void (*)())PAYLOAD_ADDRESS)();
}
}

View File

@@ -1,11 +0,0 @@
/*
* loader.h
* by Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/
#pragma once
#include "types.h"
void loadPayload(void);

View File

@@ -1,7 +1,5 @@
/* /*
* memory.c * memory.c
* by Reisyukaku / Aurora Wright
* Copyright (c) 2016 All Rights Reserved
* *
* Quick Search algorithm adapted from http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190 * Quick Search algorithm adapted from http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190
*/ */

View File

@@ -1,7 +1,5 @@
/* /*
* memory.h * memory.h
* by Reisyukaku / Aurora Wright
* Copyright (c) 2016 All Rights Reserved
* *
* Quick Search algorithm adapted from http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190 * Quick Search algorithm adapted from http://igm.univ-mlv.fr/~lecroq/string/node19.html#SECTION00190
*/ */

View File

@@ -1,7 +1,5 @@
/* /*
* patches.c * patches.c
* by Reisyukaku / Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#include "patches.h" #include "patches.h"
@@ -13,13 +11,9 @@
const u32 mpuPatch[3] = {0x00360003, 0x00200603, 0x001C0603}; const u32 mpuPatch[3] = {0x00360003, 0x00200603, 0x001C0603};
const u16 nandRedir[2] = {0x4C00, 0x47A0}; const u16 nandRedir[2] = {0x4C00, 0x47A0},
sigPatch[2] = {0x2000, 0x4770},
const u16 sigPatch[2] = {0x2000, 0x4770}; writeBlock[2] = {0x2000, 0x46C0};
const u16 writeBlock[2] = {0x2000, 0x46C0};
const u8 unitInfoPatch = 0xE3;
/************************************************** /**************************************************
* Functions * Functions
@@ -69,14 +63,6 @@ u16 *getFirmWrite(u8 *pos, u32 size)
return (u16 *)memsearch(off - 0x100, pattern, 0x100, 4); return (u16 *)memsearch(off - 0x100, pattern, 0x100, 4);
} }
u8 *getUnitInfoValueSet(u8 *pos, u32 size)
{
//Look for UNITINFO value being set
const u8 pattern[] = {0x01, 0x10, 0xA0, 0x13};
return memsearch(pos, pattern, size, 4) + 3;
}
void *getLoader(u8 *pos, u32 size, u32 *loaderSize) void *getLoader(u8 *pos, u32 size, u32 *loaderSize)
{ {
u8 *const off = memsearch(pos, "loade", size, 5); u8 *const off = memsearch(pos, "loade", size, 5);

View File

@@ -1,7 +1,5 @@
/* /*
* patches.h * patches.h
* by Reisyukaku / Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#pragma once #pragma once
@@ -12,10 +10,9 @@
* Patches * Patches
**************************************************/ **************************************************/
const u32 mpuPatch[3]; const u32 mpuPatch[3];
const u16 nandRedir[2]; const u16 nandRedir[2],
const u16 sigPatch[2]; sigPatch[2],
const u16 writeBlock[2]; writeBlock[2];
const u8 unitInfoPatch;
/************************************************** /**************************************************
* Functions * Functions
@@ -25,5 +22,4 @@ void getSigChecks(u8 *pos, u32 size, u32 *off, u32 *off2);
void *getReboot(u8 *pos, u32 size); void *getReboot(u8 *pos, u32 size);
u32 getfOpen(u8 *proc9Offset, void *rebootOffset); u32 getfOpen(u8 *proc9Offset, void *rebootOffset);
u16 *getFirmWrite(u8 *pos, u32 size); u16 *getFirmWrite(u8 *pos, u32 size);
u8 *getUnitInfoValueSet(u8 *pos, u32 size);
void *getLoader(u8 *pos, u32 size, u32 *loaderSize); void *getLoader(u8 *pos, u32 size, u32 *loaderSize);

View File

@@ -1,10 +1,8 @@
/* /*
* screeninit.c * screeninit.c
* by Aurora Wright *
* Screen init code by dark_samus, bil1s, Normmatt, delebile and others. * Screen init code by dark_samus, bil1s, Normmatt, delebile and others.
* Screen deinit code by tiniVi. * Screen deinit code by tiniVi.
*
* Copyright (c) 2016 All Rights Reserved
*/ */
#include "screeninit.h" #include "screeninit.h"
@@ -14,7 +12,7 @@
#include "i2c.h" #include "i2c.h"
#include "../build/screeninit.h" #include "../build/screeninit.h"
#define SCREENINIT_ADDRESS 0x24F03000 #define SCREENINIT_ADDRESS 0x24F02000
vu32 *arm11Entry = (u32 *)0x1FFFFFF8; vu32 *arm11Entry = (u32 *)0x1FFFFFF8;

View File

@@ -1,10 +1,8 @@
/* /*
* screeninit.h * screeninit.h
* by Aurora Wright *
* Screen init code by dark_samus, bil1s, Normmatt, delebile and others. * Screen init code by dark_samus, bil1s, Normmatt, delebile and others.
* Screen deinit code by tiniVi. * Screen deinit code by tiniVi.
*
* Copyright (c) 2016 All Rights Reserved
*/ */
#pragma once #pragma once

View File

@@ -1,7 +1,5 @@
/* /*
* types.h * types.h
* by Reisyukaku
* Copyright (c) 2015 All Rights Reserved
*/ */
#pragma once #pragma once

View File

@@ -1,7 +1,5 @@
/* /*
* utils.c * utils.c
* by Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#include "utils.h" #include "utils.h"

View File

@@ -1,7 +1,5 @@
/* /*
* utils.h * utils.h
* by Aurora Wright
* Copyright (c) 2016 All Rights Reserved
*/ */
#pragma once #pragma once