Use f_chdir and relative paths

This commit is contained in:
Aurora 2016-10-12 02:28:08 +02:00
parent 2e069e326c
commit b499c7ee75
12 changed files with 77 additions and 64 deletions

View File

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

View File

@ -35,7 +35,7 @@ bool readConfig(void)
{ {
bool ret; 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 || memcmp(configData.magic, "CONF", 4) != 0 ||
configData.formatVersionMajor != CONFIG_VERSIONMAJOR || configData.formatVersionMajor != CONFIG_VERSIONMAJOR ||
configData.formatVersionMinor != CONFIG_VERSIONMINOR) configData.formatVersionMinor != CONFIG_VERSIONMINOR)
@ -64,7 +64,7 @@ void writeConfig(ConfigurationStatus needConfig, u32 configTemp)
//Merge the new options and new boot configuration //Merge the new options and new boot configuration
configData.config = (configData.config & 0xFFFFFE00) | (configTemp & 0x1FF); 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"); error("Error writing the configuration file");
} }
} }
@ -381,7 +381,7 @@ void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode)
u32 newPinMode = MULTICONFIG(PIN); u32 newPinMode = MULTICONFIG(PIN);
if(newPinMode != 0) newPin(oldPinStatus && newPinMode == oldPinMode, newPinMode); 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 //Wait for the pressed buttons to change
while(HID_PAD & PIN_BUTTONS); while(HID_PAD & PIN_BUTTONS);

View File

@ -28,7 +28,7 @@
#define MULTICONFIG(a) ((configData.config >> (a * 2 + 9)) & 3) #define MULTICONFIG(a) ((configData.config >> (a * 2 + 9)) & 3)
#define BOOTCONFIG(a, b) ((configData.config >> a) & b) #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_VERSIONMAJOR 1
#define CONFIG_VERSIONMINOR 6 #define CONFIG_VERSIONMINOR 6

View File

@ -34,11 +34,11 @@
bool loadSplash(void) bool loadSplash(void)
{ {
const char topSplashPath[] = "luma/splash.bin", const char *topSplashFile = "splash.bin",
bottomSplashPath[] = "luma/splashbottom.bin"; *bottomSplashFile = "splashbottom.bin";
bool isTopSplashValid = getFileSize(topSplashPath) == SCREEN_TOP_FBSIZE, bool isTopSplashValid = getFileSize(topSplashFile) == SCREEN_TOP_FBSIZE,
isBottomSplashValid = getFileSize(bottomSplashPath) == SCREEN_BOTTOM_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 //Don't delay boot nor init the screens if no splash images or invalid splash images are on the SD
if(!isTopSplashValid && !isBottomSplashValid) if(!isTopSplashValid && !isBottomSplashValid)
@ -47,8 +47,8 @@ bool loadSplash(void)
initScreens(); initScreens();
clearScreens(true, true, true); clearScreens(true, true, true);
if(isTopSplashValid) fileRead(fbs[1].top_left, topSplashPath, SCREEN_TOP_FBSIZE); if(isTopSplashValid) fileRead(fbs[1].top_left, topSplashFile, SCREEN_TOP_FBSIZE);
if(isBottomSplashValid) fileRead(fbs[1].bottom, bottomSplashPath, SCREEN_BOTTOM_FBSIZE); if(isBottomSplashValid) fileRead(fbs[1].bottom, bottomSplashFile, SCREEN_BOTTOM_FBSIZE);
swapFramebuffers(true); swapFramebuffers(true);

View File

@ -184,9 +184,9 @@ void detectAndProcessExceptionDumps(void)
} }
} }
char path[41]; char path[36];
char fileName[] = "crash_dump_00000000.dmp"; 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); findDumpFile(pathFolder, fileName);
memcpy(path, pathFolder, strlen(pathFolder) + 1); memcpy(path, pathFolder, strlen(pathFolder) + 1);

View File

@ -39,19 +39,19 @@ static Firm *firm = (Firm *)0x24000000;
u32 loadFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage, bool isSdMode) u32 loadFirm(FirmwareType *firmType, FirmwareSource nandType, bool loadFromStorage, bool isSdMode)
{ {
const char *firmwareFiles[] = { const char *firmwareFiles[] = {
"luma/firmware.bin", "firmware.bin",
"luma/firmware_twl.bin", "firmware_twl.bin",
"luma/firmware_agb.bin", "firmware_agb.bin",
"luma/firmware_safe.bin" "firmware_safe.bin"
}, },
*cetkFiles[] = { *cetkFiles[] = {
"luma/cetk", "cetk",
"luma/cetk_twl", "cetk_twl",
"luma/cetk_agb", "cetk_agb",
"luma/cetk_safe" "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 //Load FIRM from CTRNAND
u32 firmVersion = firmRead(firm, (u32)*firmType); u32 firmVersion = firmRead(firm, (u32)*firmType);
@ -279,7 +279,7 @@ static inline void copySection0AndInjectSystemModules(FirmwareType firmType, boo
if(loadFromStorage) if(loadFromStorage)
{ {
char fileName[29] = "luma/sysmodules/"; char fileName[24] = "sysmodules/";
const char *ext = ".cxi"; const char *ext = ".cxi";
//Read modules from files if they exist //Read modules from files if they exist

View File

@ -33,14 +33,32 @@
static FATFS sdFs, static FATFS sdFs,
nandFs; 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) 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; FIL file;
bool ret; bool ret;
FRESULT result = f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS); switch(f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS))
if(result == FR_OK)
{ {
unsigned int written; case FR_OK:
f_write(&file, buffer, size, &written); {
f_truncate(&file); unsigned int written;
f_close(&file); f_write(&file, buffer, size, &written);
f_truncate(&file);
f_close(&file);
ret = (u32)written == size; ret = (u32)written == size;
} break;
else if(result == FR_NO_PATH) }
{ case 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 = fileWrite(buffer, path, size);
ret = fileWrite(buffer, path, size);
break;
default:
ret = false;
break;
} }
else ret = false;
return ret; return ret;
} }
@ -122,7 +136,7 @@ void loadPayload(u32 pressed)
DIR dir; DIR dir;
FILINFO info; FILINFO info;
char path[27] = "luma/payloads"; char path[22] = "payloads";
FRESULT result = f_findfirst(&dir, &info, path, pattern); FRESULT result = f_findfirst(&dir, &info, path, pattern);
@ -132,7 +146,7 @@ void loadPayload(u32 pressed)
if(info.fname[0] != 0) if(info.fname[0] != 0)
{ {
u32 *loaderAddress = (u32 *)0x24FFFF00; u32 *loaderAddress = (u32 *)0x24FFFE00;
u8 *payloadAddress = (u8 *)0x24F00000; u8 *payloadAddress = (u8 *)0x24F00000;
memcpy(loaderAddress, loader_bin, loader_bin_size); memcpy(loaderAddress, loader_bin, loader_bin_size);
@ -140,7 +154,7 @@ void loadPayload(u32 pressed)
concatenateStrings(path, "/"); concatenateStrings(path, "/");
concatenateStrings(path, info.altname); concatenateStrings(path, info.altname);
u32 payloadSize = fileRead(payloadAddress, path, (u8 *)loaderAddress - payloadAddress); u32 payloadSize = fileRead(payloadAddress, path, (u32)((u8 *)loaderAddress - payloadAddress));
if(payloadSize > 0) if(payloadSize > 0)
{ {

View File

@ -26,8 +26,7 @@
#define PATTERN(a) a "_*.bin" #define PATTERN(a) a "_*.bin"
bool mountFs(bool isSd); bool mountFs(bool isSd, bool switchToCtrNand);
bool switchToCtrNand(void);
u32 fileRead(void *dest, const char *path, u32 maxSize); u32 fileRead(void *dest, const char *path, u32 maxSize);
u32 getFileSize(const char *path); u32 getFileSize(const char *path);
bool fileWrite(const void *buffer, const char *path, u32 size); bool fileWrite(const void *buffer, const char *path, u32 size);

View File

@ -44,11 +44,11 @@ void main(void)
//Mount SD or CTRNAND //Mount SD or CTRNAND
bool isSdMode; bool isSdMode;
if(mountFs(true)) isSdMode = true; if(mountFs(true, false)) isSdMode = true;
else else
{ {
firmSource = FIRMWARE_SYSNAND; 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; isSdMode = false;
} }

View File

@ -128,14 +128,14 @@ u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr, bool isSdMode)
if(CONFIG(USECUSTOMPATH)) 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) if(pathSize > 5 && pathSize < 58)
{ {
u8 path[pathSize]; u8 path[pathSize];
fileRead(path, pathPath, pathSize); fileRead(path, pathFile, pathSize);
if(path[pathSize - 1] == 0xA) pathSize--; if(path[pathSize - 1] == 0xA) pathSize--;
if(path[pathSize - 1] == 0xD) pathSize--; if(path[pathSize - 1] == 0xD) pathSize--;

View File

@ -100,7 +100,7 @@ void newPin(bool allowSkipping, u32 pinMode)
computePinHash(tmp, enteredPassword); computePinHash(tmp, enteredPassword);
memcpy(pin.hash, tmp, sizeof(tmp)); 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"); error("Error writing the PIN file");
} }
@ -108,7 +108,7 @@ bool verifyPin(u32 pinMode)
{ {
PinData pin; 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 || memcmp(pin.magic, "PINF", 4) != 0 ||
pin.formatVersionMajor != PIN_VERSIONMAJOR || pin.formatVersionMajor != PIN_VERSIONMAJOR ||
pin.formatVersionMinor != PIN_VERSIONMINOR) pin.formatVersionMinor != PIN_VERSIONMINOR)
@ -132,14 +132,14 @@ bool verifyPin(u32 pinMode)
u8 cnt = 0; u8 cnt = 0;
u32 charDrawPos = 16 * SPACING_X; 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) if(messageSize > 0 && messageSize <= 800)
{ {
char message[messageSize + 1]; char message[messageSize + 1];
fileRead(message, messagePath, messageSize); fileRead(message, messageFile, messageSize);
message[messageSize] = 0; message[messageSize] = 0;
drawString(message, false, 10, 10, COLOR_WHITE); drawString(message, false, 10, 10, COLOR_WHITE);
} }

View File

@ -28,7 +28,7 @@
#include "types.h" #include "types.h"
#define PIN_PATH "luma/pin.bin" #define PIN_FILE "pin.bin"
#define PIN_VERSIONMAJOR 1 #define PIN_VERSIONMAJOR 1
#define PIN_VERSIONMINOR 3 #define PIN_VERSIONMINOR 3