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)
SECTIONS
{
. = 0x24FFFF00;
. = 0x24FFFE00;
.text.start : { *(.text.start) }
.text : { *(.text) }
.data : { *(.data) }

View File

@ -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);

View File

@ -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

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -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,9 +88,9 @@ 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))
{
case FR_OK:
{
unsigned int written;
f_write(&file, buffer, size, &written);
@ -80,21 +98,17 @@ bool fileWrite(const void *buffer, const char *path, u32 size)
f_close(&file);
ret = (u32)written == size;
break;
}
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);
}
case FR_NO_PATH:
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)
{

View File

@ -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);

View File

@ -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;
}

View File

@ -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--;

View File

@ -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);
}

View File

@ -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