diff --git a/source/config.c b/source/config.c index 69be337..183a098 100644 --- a/source/config.c +++ b/source/config.c @@ -193,7 +193,12 @@ void configureCFW(const char *configPath) for(u32 i = 0; i < singleOptionsAmount; i++) config |= (singleOptions[i].enabled ? 1 : 0) << (i + 16); - fileWrite(&config, configPath, 4); + if(!fileWrite(&config, configPath, 4)) + { + createDirectory("luma"); + if(!fileWrite(&config, configPath, 4)) + error("Error writing the configuration file"); + } //Wait for the pressed buttons to change while(HID_PAD == BUTTON_START); diff --git a/source/fatfs/ffconf.h b/source/fatfs/ffconf.h index 264f4cd..f40a383 100644 --- a/source/fatfs/ffconf.h +++ b/source/fatfs/ffconf.h @@ -15,7 +15,7 @@ / and optional writing functions as well. */ -#define _FS_MINIMIZE 1 +#define _FS_MINIMIZE 0 /* This option defines minimization level to remove some basic API functions. / / 0: All basic functions are enabled. diff --git a/source/firm.c b/source/firm.c index 7b6d093..74fc484 100755 --- a/source/firm.c +++ b/source/firm.c @@ -203,7 +203,8 @@ void main(void) //Preserve user settings (last 26 bits) newConfig |= config & 0xFFFFFFC0; - fileWrite(&newConfig, configPath, 4); + if(!fileWrite(&newConfig, configPath, 4)) + error("Error writing the configuration file"); } } @@ -241,7 +242,10 @@ static inline u32 loadFirm(FirmwareType firmType) if(!isN3DS && firmType == NATIVE_FIRM && firmVersion < 0x25) { - if(!fileRead(firm, "/luma/firmware.bin") || (((u32)section[2].address >> 8) & 0xFF) != 0x68) mcuReboot(); + if(!fileRead(firm, "/luma/firmware.bin") || (((u32)section[2].address >> 8) & 0xFF) != 0x68) + error("An old unsupported FIRM has been detected.\nCopy firmware.bin in /luma to boot"); + + //9.6 O3DS FIRM firmVersion = 0x49; } else decryptExeFs((u8 *)firm); @@ -296,9 +300,9 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 static inline void patchLegacyFirm(FirmwareType firmType) { - //On N3DS, decrypt ARM9Bin and patch ARM9 entrypoint to skip arm9loader if(isN3DS) { + //Decrypt ARM9Bin and patch ARM9 entrypoint to skip arm9loader arm9Loader((u8 *)firm + section[3].offset); firm->arm9Entry = (u8 *)0x801301C; } diff --git a/source/fs.c b/source/fs.c index 66210ed..fb9f107 100644 --- a/source/fs.c +++ b/source/fs.c @@ -31,12 +31,10 @@ static FATFS sdFs, nandFs; -bool mountFs(void) +void mountFs(void) { - if(f_mount(&sdFs, "0:", 1) != FR_OK) return false; + f_mount(&sdFs, "0:", 1); f_mount(&nandFs, "1:", 0); - - return true; } u32 fileRead(void *dest, const char *path) @@ -56,7 +54,7 @@ u32 fileRead(void *dest, const char *path) return size; } -void fileWrite(const void *buffer, const char *path, u32 size) +bool fileWrite(const void *buffer, const char *path, u32 size) { FIL file; @@ -65,7 +63,16 @@ void fileWrite(const void *buffer, const char *path, u32 size) unsigned int written; f_write(&file, buffer, size, &written); f_close(&file); + + return true; } + + return false; +} + +void createDirectory(const char *path) +{ + f_mkdir(path); } void loadPayload(u32 pressed) diff --git a/source/fs.h b/source/fs.h index 339d41a..3daf016 100644 --- a/source/fs.h +++ b/source/fs.h @@ -28,8 +28,9 @@ extern bool isN3DS; -bool mountFs(void); +void mountFs(void); u32 fileRead(void *dest, const char *path); -void fileWrite(const void *buffer, const char *path, u32 size); +bool fileWrite(const void *buffer, const char *path, u32 size); +void createDirectory(const char *path); void loadPayload(u32 pressed); u32 firmRead(void *dest, u32 firmType); \ No newline at end of file diff --git a/source/screen.h b/source/screen.h index 08e59f7..e387825 100644 --- a/source/screen.h +++ b/source/screen.h @@ -30,7 +30,7 @@ #include "types.h" #define PDN_GPU_CNT (*(vu8 *)0x10141200) -#define ARM11_STUB_ADDRESS (0x25000000 - 0x40) //It's currently only 0x28 bytes large. We're putting 0x40 just to be sure here +#define ARM11_STUB_ADDRESS (0x25000000 - 0x30) //It's currently only 0x28 bytes large. We're putting 0x30 just to be sure here #define WAIT_FOR_ARM9() *arm11Entry = 0; while(!*arm11Entry); ((void (*)())*arm11Entry)(); static volatile struct fb { diff --git a/source/utils.c b/source/utils.c index 79225dc..76cbdeb 100644 --- a/source/utils.c +++ b/source/utils.c @@ -23,7 +23,8 @@ #include "utils.h" #include "i2c.h" #include "buttons.h" -#include "memory.h" +#include "screen.h" +#include "draw.h" #include "cache.h" u32 waitInput(void) @@ -96,4 +97,20 @@ void chrono(u32 seconds) void stopChrono(void) { for(u32 i = 0; i < 4; i++) REG_TIMER_CNT(i) &= ~0x80; +} + +void error(const char *message) +{ + initScreens(); + + drawString("An error has occurred:", 10, 10, COLOR_RED); + int posY = drawString(message, 10, 30, COLOR_WHITE); + drawString("Press any button to shutdown", 10, posY + 2 * SPACING_Y, COLOR_WHITE); + + waitInput(); + + flushEntireDCache(); //Ensure that all memory transfers have completed and that the data cache has been flushed + + i2cWriteRegister(I2C_DEV_MCU, 0x20, 1); + while(1); } \ No newline at end of file diff --git a/source/utils.h b/source/utils.h index b30cea2..224eb62 100644 --- a/source/utils.h +++ b/source/utils.h @@ -24,12 +24,12 @@ #include "types.h" -u32 waitInput(void); -void mcuReboot(void); - #define TICKS_PER_SEC 67027964ULL #define REG_TIMER_CNT(i) *(vu16 *)(0x10003002 + 4 * i) #define REG_TIMER_VAL(i) *(vu16 *)(0x10003000 + 4 * i) +u32 waitInput(void); +void mcuReboot(void); void chrono(u32 seconds); -void stopChrono(void); \ No newline at end of file +void stopChrono(void); +void error(const char *message); \ No newline at end of file