diff --git a/loader/linker.ld b/loader/linker.ld index 2ca0165..2bb7325 100644 --- a/loader/linker.ld +++ b/loader/linker.ld @@ -1,7 +1,7 @@ ENTRY(_start) SECTIONS { - . = 0x24FFFF00; + . = 0x24FFFE00; .text.start : { *(.text.start) } .text : { *(.text) } .data : { *(.data) } diff --git a/source/config.c b/source/config.c index 23676cb..fc42ee8 100644 --- a/source/config.c +++ b/source/config.c @@ -35,7 +35,7 @@ bool readConfig(void) { bool ret; - if(fileRead(&configData, CONFIG_PATH, sizeof(CfgData)) != sizeof(CfgData) || + if(fileRead(&configData, CONFIG_FILE, sizeof(CfgData)) != sizeof(CfgData) || memcmp(configData.magic, "CONF", 4) != 0 || configData.formatVersionMajor != CONFIG_VERSIONMAJOR || configData.formatVersionMinor != CONFIG_VERSIONMINOR) @@ -64,7 +64,7 @@ void writeConfig(ConfigurationStatus needConfig, u32 configTemp) //Merge the new options and new boot configuration configData.config = (configData.config & 0xFFFFFE00) | (configTemp & 0x1FF); - if(!fileWrite(&configData, CONFIG_PATH, sizeof(CfgData))) + if(!fileWrite(&configData, CONFIG_FILE, sizeof(CfgData))) error("Error writing the configuration file"); } } @@ -381,7 +381,7 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode) u32 newPinMode = MULTICONFIG(PIN); if(newPinMode != 0) newPin(oldPinStatus && newPinMode == oldPinMode, newPinMode); - else if(oldPinStatus) fileDelete(PIN_PATH); + else if(oldPinStatus) fileDelete(PIN_FILE); //Wait for the pressed buttons to change while(HID_PAD & PIN_BUTTONS); diff --git a/source/config.h b/source/config.h index a7fd02b..9a710b5 100644 --- a/source/config.h +++ b/source/config.h @@ -28,7 +28,7 @@ #define MULTICONFIG(a) ((configData.config >> (a * 2 + 9)) & 3) #define BOOTCONFIG(a, b) ((configData.config >> a) & b) -#define CONFIG_PATH "luma/config.bin" +#define CONFIG_FILE "config.bin" #define CONFIG_VERSIONMAJOR 1 #define CONFIG_VERSIONMINOR 6 diff --git a/source/draw.c b/source/draw.c index 2fc917f..dd37e1c 100644 --- a/source/draw.c +++ b/source/draw.c @@ -34,11 +34,11 @@ bool loadSplash(void) { - const char topSplashPath[] = "luma/splash.bin", - bottomSplashPath[] = "luma/splashbottom.bin"; + const char *topSplashFile = "splash.bin", + *bottomSplashFile = "splashbottom.bin"; - bool isTopSplashValid = getFileSize(topSplashPath) == SCREEN_TOP_FBSIZE, - isBottomSplashValid = getFileSize(bottomSplashPath) == SCREEN_BOTTOM_FBSIZE; + bool isTopSplashValid = getFileSize(topSplashFile) == SCREEN_TOP_FBSIZE, + isBottomSplashValid = getFileSize(bottomSplashFile) == SCREEN_BOTTOM_FBSIZE; //Don't delay boot nor init the screens if no splash images or invalid splash images are on the SD if(!isTopSplashValid && !isBottomSplashValid) @@ -47,8 +47,8 @@ bool loadSplash(void) initScreens(); clearScreens(true, true, true); - if(isTopSplashValid) fileRead(fbs[1].top_left, topSplashPath, SCREEN_TOP_FBSIZE); - if(isBottomSplashValid) fileRead(fbs[1].bottom, bottomSplashPath, SCREEN_BOTTOM_FBSIZE); + if(isTopSplashValid) fileRead(fbs[1].top_left, topSplashFile, SCREEN_TOP_FBSIZE); + if(isBottomSplashValid) fileRead(fbs[1].bottom, bottomSplashFile, SCREEN_BOTTOM_FBSIZE); swapFramebuffers(true); diff --git a/source/exceptions.c b/source/exceptions.c index e31f31d..fe41933 100644 --- a/source/exceptions.c +++ b/source/exceptions.c @@ -184,9 +184,9 @@ void detectAndProcessExceptionDumps(void) } } - char path[41]; + char path[36]; char fileName[] = "crash_dump_00000000.dmp"; - const char *pathFolder = dumpHeader->processor == 9 ? "luma/dumps/arm9" : "luma/dumps/arm11"; + const char *pathFolder = dumpHeader->processor == 9 ? "dumps/arm9" : "dumps/arm11"; findDumpFile(pathFolder, fileName); memcpy(path, pathFolder, strlen(pathFolder) + 1); diff --git a/source/firm.c b/source/firm.c index 0d8226c..34bb8d8 100755 --- a/source/firm.c +++ b/source/firm.c @@ -39,19 +39,19 @@ static Firm *firm = (Firm *)0x24000000; u32 loadFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage, bool isSdMode) { const char *firmwareFiles[] = { - "luma/firmware.bin", - "luma/firmware_twl.bin", - "luma/firmware_agb.bin", - "luma/firmware_safe.bin" + "firmware.bin", + "firmware_twl.bin", + "firmware_agb.bin", + "firmware_safe.bin" }, *cetkFiles[] = { - "luma/cetk", - "luma/cetk_twl", - "luma/cetk_agb", - "luma/cetk_safe" + "cetk", + "cetk_twl", + "cetk_agb", + "cetk_safe" }; - if(isSdMode && !mountFs(false)) error("Failed to mount CTRNAND."); + if(isSdMode && !mountFs(false, false)) error("Failed to mount CTRNAND."); //Load FIRM from CTRNAND u32 firmVersion = firmRead(firm, (u32)*firmType); @@ -279,7 +279,7 @@ static inline void copySection0AndInjectSystemModules(FirmwareType firmType, boo if(loadFromStorage) { - char fileName[29] = "luma/sysmodules/"; + char fileName[24] = "sysmodules/"; const char *ext = ".cxi"; //Read modules from files if they exist diff --git a/source/fs.c b/source/fs.c index 4a45379..5d7102b 100644 --- a/source/fs.c +++ b/source/fs.c @@ -33,14 +33,32 @@ static FATFS sdFs, nandFs; -bool mountFs(bool isSd) +static bool switchToMainDir(bool isSd) { - return isSd ? f_mount(&sdFs, "0:", 1) == FR_OK : f_mount(&nandFs, "1:", 1) == FR_OK; + const char *mainDir = isSd ? "/luma" : "/rw/luma"; + bool ret; + + switch(f_chdir(mainDir)) + { + case FR_OK: + ret = true; + break; + case FR_NO_PATH: + f_mkdir(mainDir); + ret = switchToMainDir(isSd); + break; + default: + ret = false; + break; + } + + return ret; } -bool switchToCtrNand(void) +bool mountFs(bool isSd, bool switchToCtrNand) { - return f_chdrive("1:") == FR_OK && f_chdir("/rw") == FR_OK; + return isSd ? f_mount(&sdFs, "0:", 1) == FR_OK && switchToMainDir(true) : + f_mount(&nandFs, "1:", 1) == FR_OK && (!switchToCtrNand || (f_chdrive("1:") == FR_OK && switchToMainDir(false))); } u32 fileRead(void *dest, const char *path, u32 maxSize) @@ -70,31 +88,27 @@ bool fileWrite(const void *buffer, const char *path, u32 size) FIL file; bool ret; - FRESULT result = f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS); - - if(result == FR_OK) + switch(f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS)) { - unsigned int written; - f_write(&file, buffer, size, &written); - f_truncate(&file); - f_close(&file); + case FR_OK: + { + unsigned int written; + f_write(&file, buffer, size, &written); + f_truncate(&file); + f_close(&file); - ret = (u32)written == size; - } - else if(result == FR_NO_PATH) - { - for(u32 i = 1; path[i] != 0; i++) - if(path[i] == '/') - { - char folder[i + 1]; - memcpy(folder, path, i); - folder[i] = 0; - f_mkdir(folder); - } + ret = (u32)written == size; + break; + } + case FR_NO_PATH: - ret = fileWrite(buffer, path, size); + + ret = fileWrite(buffer, path, size); + break; + default: + ret = false; + break; } - else ret = false; return ret; } @@ -122,7 +136,7 @@ void loadPayload(u32 pressed) DIR dir; FILINFO info; - char path[27] = "luma/payloads"; + char path[22] = "payloads"; FRESULT result = f_findfirst(&dir, &info, path, pattern); @@ -132,7 +146,7 @@ void loadPayload(u32 pressed) if(info.fname[0] != 0) { - u32 *loaderAddress = (u32 *)0x24FFFF00; + u32 *loaderAddress = (u32 *)0x24FFFE00; u8 *payloadAddress = (u8 *)0x24F00000; memcpy(loaderAddress, loader_bin, loader_bin_size); @@ -140,7 +154,7 @@ void loadPayload(u32 pressed) concatenateStrings(path, "/"); concatenateStrings(path, info.altname); - u32 payloadSize = fileRead(payloadAddress, path, (u8 *)loaderAddress - payloadAddress); + u32 payloadSize = fileRead(payloadAddress, path, (u32)((u8 *)loaderAddress - payloadAddress)); if(payloadSize > 0) { diff --git a/source/fs.h b/source/fs.h index 3fbd87c..fffb530 100644 --- a/source/fs.h +++ b/source/fs.h @@ -26,8 +26,7 @@ #define PATTERN(a) a "_*.bin" -bool mountFs(bool isSd); -bool switchToCtrNand(void); +bool mountFs(bool isSd, bool switchToCtrNand); u32 fileRead(void *dest, const char *path, u32 maxSize); u32 getFileSize(const char *path); bool fileWrite(const void *buffer, const char *path, u32 size); diff --git a/source/main.c b/source/main.c index edc31fd..28ebe10 100644 --- a/source/main.c +++ b/source/main.c @@ -44,11 +44,11 @@ void main(void) //Mount SD or CTRNAND bool isSdMode; - if(mountFs(true)) isSdMode = true; + if(mountFs(true, false)) isSdMode = true; else { firmSource = FIRMWARE_SYSNAND; - if(!mountFs(false) || !switchToCtrNand()) error("Failed to mount SD and CTRNAND."); + if(!mountFs(false, true)) error("Failed to mount SD and CTRNAND."); isSdMode = false; } diff --git a/source/patches.c b/source/patches.c index 52448e2..992c089 100644 --- a/source/patches.c +++ b/source/patches.c @@ -128,14 +128,14 @@ u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr, bool isSdMode) if(CONFIG(USECUSTOMPATH)) { - const char pathPath[] = "luma/path.txt"; + const char *pathFile = "path.txt"; - u32 pathSize = getFileSize(pathPath); + u32 pathSize = getFileSize(pathFile); if(pathSize > 5 && pathSize < 58) { u8 path[pathSize]; - fileRead(path, pathPath, pathSize); + fileRead(path, pathFile, pathSize); if(path[pathSize - 1] == 0xA) pathSize--; if(path[pathSize - 1] == 0xD) pathSize--; diff --git a/source/pin.c b/source/pin.c index b27e1e7..129bfb3 100644 --- a/source/pin.c +++ b/source/pin.c @@ -100,7 +100,7 @@ void newPin(bool allowSkipping, u32 pinMode) computePinHash(tmp, enteredPassword); memcpy(pin.hash, tmp, sizeof(tmp)); - if(!fileWrite(&pin, PIN_PATH, sizeof(PinData))) + if(!fileWrite(&pin, PIN_FILE, sizeof(PinData))) error("Error writing the PIN file"); } @@ -108,7 +108,7 @@ bool verifyPin(u32 pinMode) { PinData pin; - if(fileRead(&pin, PIN_PATH, sizeof(PinData)) != sizeof(PinData) || + if(fileRead(&pin, PIN_FILE, sizeof(PinData)) != sizeof(PinData) || memcmp(pin.magic, "PINF", 4) != 0 || pin.formatVersionMajor != PIN_VERSIONMAJOR || pin.formatVersionMinor != PIN_VERSIONMINOR) @@ -132,14 +132,14 @@ bool verifyPin(u32 pinMode) u8 cnt = 0; u32 charDrawPos = 16 * SPACING_X; - const char messagePath[] = "luma/pinmessage.txt"; + const char *messageFile = "pinmessage.txt"; - u32 messageSize = getFileSize(messagePath); + u32 messageSize = getFileSize(messageFile); if(messageSize > 0 && messageSize <= 800) { char message[messageSize + 1]; - fileRead(message, messagePath, messageSize); + fileRead(message, messageFile, messageSize); message[messageSize] = 0; drawString(message, false, 10, 10, COLOR_WHITE); } diff --git a/source/pin.h b/source/pin.h index 456593e..c781508 100644 --- a/source/pin.h +++ b/source/pin.h @@ -28,7 +28,7 @@ #include "types.h" -#define PIN_PATH "luma/pin.bin" +#define PIN_FILE "pin.bin" #define PIN_VERSIONMAJOR 1 #define PIN_VERSIONMINOR 3