Added error screen when booting an unsupported NAND with no firmware.bin or writing to the config fails, added code for creating the "luma" directory if it is missing

This commit is contained in:
Aurora 2016-07-18 22:42:55 +02:00
parent 8175642a2a
commit a68e14def3
8 changed files with 52 additions and 18 deletions

View File

@ -193,7 +193,12 @@ void configureCFW(const char *configPath)
for(u32 i = 0; i < singleOptionsAmount; i++) for(u32 i = 0; i < singleOptionsAmount; i++)
config |= (singleOptions[i].enabled ? 1 : 0) << (i + 16); 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 //Wait for the pressed buttons to change
while(HID_PAD == BUTTON_START); while(HID_PAD == BUTTON_START);

View File

@ -15,7 +15,7 @@
/ and optional writing functions as well. */ / 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. /* This option defines minimization level to remove some basic API functions.
/ /
/ 0: All basic functions are enabled. / 0: All basic functions are enabled.

View File

@ -203,7 +203,8 @@ void main(void)
//Preserve user settings (last 26 bits) //Preserve user settings (last 26 bits)
newConfig |= config & 0xFFFFFFC0; 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(!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; firmVersion = 0x49;
} }
else decryptExeFs((u8 *)firm); else decryptExeFs((u8 *)firm);
@ -296,9 +300,9 @@ static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32
static inline void patchLegacyFirm(FirmwareType firmType) static inline void patchLegacyFirm(FirmwareType firmType)
{ {
//On N3DS, decrypt ARM9Bin and patch ARM9 entrypoint to skip arm9loader
if(isN3DS) if(isN3DS)
{ {
//Decrypt ARM9Bin and patch ARM9 entrypoint to skip arm9loader
arm9Loader((u8 *)firm + section[3].offset); arm9Loader((u8 *)firm + section[3].offset);
firm->arm9Entry = (u8 *)0x801301C; firm->arm9Entry = (u8 *)0x801301C;
} }

View File

@ -31,12 +31,10 @@
static FATFS sdFs, static FATFS sdFs,
nandFs; 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); f_mount(&nandFs, "1:", 0);
return true;
} }
u32 fileRead(void *dest, const char *path) u32 fileRead(void *dest, const char *path)
@ -56,7 +54,7 @@ u32 fileRead(void *dest, const char *path)
return size; return size;
} }
void fileWrite(const void *buffer, const char *path, u32 size) bool fileWrite(const void *buffer, const char *path, u32 size)
{ {
FIL file; FIL file;
@ -65,7 +63,16 @@ void fileWrite(const void *buffer, const char *path, u32 size)
unsigned int written; unsigned int written;
f_write(&file, buffer, size, &written); f_write(&file, buffer, size, &written);
f_close(&file); f_close(&file);
return true;
} }
return false;
}
void createDirectory(const char *path)
{
f_mkdir(path);
} }
void loadPayload(u32 pressed) void loadPayload(u32 pressed)

View File

@ -28,8 +28,9 @@
extern bool isN3DS; extern bool isN3DS;
bool mountFs(void); void mountFs(void);
u32 fileRead(void *dest, const char *path); 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); void loadPayload(u32 pressed);
u32 firmRead(void *dest, u32 firmType); u32 firmRead(void *dest, u32 firmType);

View File

@ -30,7 +30,7 @@
#include "types.h" #include "types.h"
#define PDN_GPU_CNT (*(vu8 *)0x10141200) #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)(); #define WAIT_FOR_ARM9() *arm11Entry = 0; while(!*arm11Entry); ((void (*)())*arm11Entry)();
static volatile struct fb { static volatile struct fb {

View File

@ -23,7 +23,8 @@
#include "utils.h" #include "utils.h"
#include "i2c.h" #include "i2c.h"
#include "buttons.h" #include "buttons.h"
#include "memory.h" #include "screen.h"
#include "draw.h"
#include "cache.h" #include "cache.h"
u32 waitInput(void) u32 waitInput(void)
@ -97,3 +98,19 @@ void stopChrono(void)
{ {
for(u32 i = 0; i < 4; i++) REG_TIMER_CNT(i) &= ~0x80; 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);
}

View File

@ -24,12 +24,12 @@
#include "types.h" #include "types.h"
u32 waitInput(void);
void mcuReboot(void);
#define TICKS_PER_SEC 67027964ULL #define TICKS_PER_SEC 67027964ULL
#define REG_TIMER_CNT(i) *(vu16 *)(0x10003002 + 4 * i) #define REG_TIMER_CNT(i) *(vu16 *)(0x10003002 + 4 * i)
#define REG_TIMER_VAL(i) *(vu16 *)(0x10003000 + 4 * i) #define REG_TIMER_VAL(i) *(vu16 *)(0x10003000 + 4 * i)
u32 waitInput(void);
void mcuReboot(void);
void chrono(u32 seconds); void chrono(u32 seconds);
void stopChrono(void); void stopChrono(void);
void error(const char *message);