From 95d06c115ac67305bdfd1f76562cf25659615043 Mon Sep 17 00:00:00 2001 From: Aurora Date: Mon, 2 May 2016 02:02:31 +0200 Subject: [PATCH] Fixed crashes loading an emuNAND if the SD was too small to be able to hold it --- source/buttons.h | 2 ++ source/draw.c | 3 --- source/draw.h | 8 ++++++-- source/emunand.c | 40 ++++++++++++++++++---------------------- source/fs.c | 3 --- source/fs.h | 3 +++ source/screeninit.c | 2 -- source/screeninit.h | 3 ++- 8 files changed, 31 insertions(+), 33 deletions(-) diff --git a/source/buttons.h b/source/buttons.h index 9c9b884..fd50eb3 100644 --- a/source/buttons.h +++ b/source/buttons.h @@ -7,6 +7,7 @@ #include "types.h" #define HID_PAD (*(vu32 *)0x10146000 ^ 0xFFF) + #define BUTTON_R1 (1 << 8) #define BUTTON_L1 (1 << 9) #define BUTTON_A 1 @@ -19,6 +20,7 @@ #define BUTTON_LEFT (1 << 5) #define BUTTON_UP (1 << 6) #define BUTTON_DOWN (1 << 7) + #define SAFE_MODE (BUTTON_R1 | BUTTON_L1 | BUTTON_A | BUTTON_UP) #define OVERRIDE_BUTTONS (BUTTON_B ^ 0xFFF) #define SINGLE_PAYLOAD_BUTTONS (BUTTON_LEFT | BUTTON_RIGHT | BUTTON_UP | BUTTON_DOWN | BUTTON_START | BUTTON_X | BUTTON_Y) diff --git a/source/draw.c b/source/draw.c index d91f422..08a834d 100644 --- a/source/draw.c +++ b/source/draw.c @@ -10,9 +10,6 @@ #include "memory.h" #include "font.h" -#define SCREEN_TOP_WIDTH 400 -#define SCREEN_TOP_HEIGHT 240 - static const struct fb { u8 *top_left; u8 *top_right; diff --git a/source/draw.h b/source/draw.h index 53522a6..a8959bf 100644 --- a/source/draw.h +++ b/source/draw.h @@ -8,8 +8,12 @@ #include "types.h" -#define SPACING_Y 10 -#define SPACING_X 8 +#define SCREEN_TOP_WIDTH 400 +#define SCREEN_TOP_HEIGHT 240 + +#define SPACING_Y 10 +#define SPACING_X 8 + #define COLOR_TITLE 0xFF9900 #define COLOR_WHITE 0xFFFFFF #define COLOR_RED 0x0000FF diff --git a/source/emunand.c b/source/emunand.c index 6139389..c6efbb6 100644 --- a/source/emunand.c +++ b/source/emunand.c @@ -15,31 +15,27 @@ void getEmunandSect(u32 *off, u32 *head, u32 *emuNAND) (nandSize > 0x200000 ? 0x400000 : 0x200000); //Check for RedNAND - if(sdmmc_sdcard_readsectors(nandOffset + 1, 1, temp) == 0) + if(!sdmmc_sdcard_readsectors(nandOffset + 1, 1, temp) && + *(u32 *)(temp + 0x100) == NCSD_MAGIC) { - if(*(u32 *)(temp + 0x100) == NCSD_MAGIC) - { - *off = nandOffset + 1; - *head = nandOffset + 1; - } + *off = nandOffset + 1; + *head = nandOffset + 1; + } - //Check for Gateway emuNAND - else if(sdmmc_sdcard_readsectors(nandOffset + nandSize, 1, temp) == 0) - { - if(*(u32 *)(temp + 0x100) == NCSD_MAGIC) - { - *off = nandOffset; - *head = nandOffset + nandSize; - } + //Check for Gateway emuNAND + else if(!sdmmc_sdcard_readsectors(nandOffset + nandSize, 1, temp) && + *(u32 *)(temp + 0x100) == NCSD_MAGIC) + { + *off = nandOffset; + *head = nandOffset + nandSize; + } - /* Fallback to the first emuNAND if there's no second one, - or to SysNAND if there isn't any */ - else - { - (*emuNAND)--; - if(*emuNAND) getEmunandSect(off, head, emuNAND); - } - } + /* Fallback to the first emuNAND if there's no second one, + or to SysNAND if there isn't any */ + else + { + (*emuNAND)--; + if(*emuNAND) getEmunandSect(off, head, emuNAND); } } diff --git a/source/fs.c b/source/fs.c index 64686dc..1fa5622 100644 --- a/source/fs.c +++ b/source/fs.c @@ -9,9 +9,6 @@ #include "buttons.h" #include "../build/loader.h" -#define PAYLOAD_ADDRESS 0x24F00000 -#define PATTERN(a) a "_*.bin" - static FATFS sdFs, nandFs; diff --git a/source/fs.h b/source/fs.h index 5f7180e..d251c8e 100644 --- a/source/fs.h +++ b/source/fs.h @@ -6,6 +6,9 @@ #include "types.h" +#define PAYLOAD_ADDRESS 0x24F00000 +#define PATTERN(a) a "_*.bin" + u32 mountFs(void); u32 fileRead(void *dest, const char *path, u32 size); u32 fileWrite(const void *buffer, const char *path, u32 size); diff --git a/source/screeninit.c b/source/screeninit.c index 11e6e11..367adcb 100644 --- a/source/screeninit.c +++ b/source/screeninit.c @@ -12,8 +12,6 @@ #include "i2c.h" #include "../build/screeninit.h" -#define SCREENINIT_ADDRESS 0x24F02000 - vu32 *arm11Entry = (u32 *)0x1FFFFFF8; void deinitScreens(void) diff --git a/source/screeninit.h b/source/screeninit.h index f0aa323..c004332 100644 --- a/source/screeninit.h +++ b/source/screeninit.h @@ -9,7 +9,8 @@ #include "types.h" -#define PDN_GPU_CNT (*(vu8 *)0x10141200) +#define PDN_GPU_CNT (*(vu8 *)0x10141200) +#define SCREENINIT_ADDRESS 0x24F02000 void deinitScreens(void); void initScreens(void); \ No newline at end of file