From e651c3d9cc4878c59e0be554176234489931e9a5 Mon Sep 17 00:00:00 2001 From: Aurora Date: Thu, 28 Apr 2016 16:11:25 +0200 Subject: [PATCH] Small cleanup --- loader/source/main.c | 6 +++--- source/draw.c | 4 ++-- source/firm.c | 10 ++++++---- source/fs.c | 35 +++++++++++++++++++---------------- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/loader/source/main.c b/loader/source/main.c index e255006..21f16ec 100644 --- a/loader/source/main.c +++ b/loader/source/main.c @@ -7,7 +7,7 @@ static u32 loadPayload(const char *pattern) { - char path[30] = "/luma/payloads"; + char path[29] = "/luma/payloads"; DIR dir; FILINFO info; @@ -26,10 +26,10 @@ static u32 loadPayload(const char *pattern) path[15 + i] = '\0'; FIL payload; - unsigned int br; + unsigned int read; f_open(&payload, path, FA_READ); - f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &br); + f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &read); f_close(&payload); return 1; diff --git a/source/draw.c b/source/draw.c index 5cf04ca..d91f422 100644 --- a/source/draw.c +++ b/source/draw.c @@ -40,8 +40,8 @@ void loadSplash(void) initScreens(); //Don't delay boot if no splash image is on the SD - if(fileRead(fb->top_left, "/luma/splash.bin", 0x46500) + - fileRead(fb->bottom, "/luma/splashbottom.bin", 0x38400)) + if(!(fileRead(fb->top_left, "/luma/splash.bin", 0x46500) + + fileRead(fb->bottom, "/luma/splashbottom.bin", 0x38400))) { u64 i = 0x1400000; while(i--) __asm("mov r0, r0"); //Less Ghetto sleep func diff --git a/source/firm.c b/source/firm.c index 1620be5..598e818 100755 --- a/source/firm.c +++ b/source/firm.c @@ -43,7 +43,7 @@ void main(void) //Attempt to read the configuration file const char configPath[] = "/luma/config.bin"; - if(fileRead(&config, configPath, 4)) needConfig = 1; + if(!fileRead(&config, configPath, 4)) needConfig = 1; else { config = 0; @@ -190,10 +190,12 @@ static inline void loadFirm(u32 firmType, u32 externalFirm) { section = firm->section; + u32 externalFirmLoaded = externalFirm && !fileRead(firm, "/luma/firmware.bin", 0) && + (((u32)section[2].address >> 8) & 0xFF) != (console ? 0x60 : 0x68); + /* If the conditions to load the external FIRM aren't met, or reading fails, or the FIRM - doesn't match the console, load it from CTRNAND */ - if(!externalFirm || !fileRead(firm, "/luma/firmware.bin", 0) || - (((u32)section[2].address >> 8) & 0xFF) != (console ? 0x60 : 0x68)) + doesn't match the console, load FIRM from CTRNAND */ + if(!externalFirmLoaded) { const char *firmFolders[3][2] = {{ "00000002", "20000002" }, { "00000102", "20000102" }, diff --git a/source/fs.c b/source/fs.c index 1f45126..84be110 100644 --- a/source/fs.c +++ b/source/fs.c @@ -19,34 +19,37 @@ u32 mountFs(void) u32 fileRead(void *dest, const char *path, u32 size) { - FRESULT fr; - FIL fp; - unsigned int br = 0; + FRESULT result; + FIL file; - fr = f_open(&fp, path, FA_READ); - if(fr == FR_OK) + result = f_open(&file, path, FA_READ); + if(result == FR_OK) { - if(!size) size = f_size(&fp); - fr = f_read(&fp, dest, size, &br); + unsigned int read; + if(!size) size = f_size(&file); + result = f_read(&file, dest, size, &read); } - f_close(&fp); + f_close(&file); - return fr ? 0 : 1; + return result; } u32 fileWrite(const void *buffer, const char *path, u32 size) { - FRESULT fr; - FIL fp; - unsigned int br = 0; + FRESULT result; + FIL file; - fr = f_open(&fp, path, FA_WRITE | FA_OPEN_ALWAYS); - if(fr == FR_OK) fr = f_write(&fp, buffer, size, &br); + result = f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS); + if(result == FR_OK) + { + unsigned int read; + result = f_write(&file, buffer, size, &read); + } - f_close(&fp); + f_close(&file); - return fr ? 0 : 1; + return result; } u32 defPayloadExists(void)