Changed the chainloader to load payloads named "BUTTON_NAME.bin", to remember which payload is which. Original idea and code by @habbbe (many thanks!)

This commit is contained in:
Aurora 2016-04-17 18:57:25 +02:00
parent 0f64fd73ec
commit 06060c67b5
8 changed files with 53 additions and 42 deletions

View File

@ -382,8 +382,8 @@ void patchCode(u64 progId, u8 *code, u32 size)
patchMemory(code, size,
verPattern,
sizeof(verPattern) - sizeof(u16), 0,
!currentNand ? ((matchingFirm) ? u" Sys" : u"SysA") :
((currentNand == 1) ? (matchingFirm ? u" Emu" : u"EmuA") : ((matchingFirm) ? u"Emu2" : u"Em2A")),
!currentNand ? ((matchingFirm) ? u" Sys" : u"SysE") :
((currentNand == 1) ? (matchingFirm ? u" Emu" : u"EmuS") : ((matchingFirm) ? u"Emu2" : u"Em2S")),
sizeof(verPattern) - sizeof(u16), 1
);
}

View File

@ -3,11 +3,10 @@
#include "types.h"
#define HID_PAD (*(vu32 *)0x10146000 ^ 0xFFF)
#define BUTTON_X (1 << 10)
#define BUTTON_Y (1 << 11)
#define BUTTON_R1 (1 << 8)
#define BUTTON_SELECT (1 << 2)
#define BUTTON_RIGHT (1 << 4)
#define BUTTON_LEFT (1 << 5)
#define BUTTON_UP (1 << 6)
#define BUTTON_DOWN (1 << 7)
#define BUTTON_X (1 << 10)
#define BUTTON_Y (1 << 11)
#define BUTTON_R1 (1 << 8)

View File

@ -15,7 +15,7 @@
/ and optional writing functions as well. */
#define _FS_MINIMIZE 3
#define _FS_MINIMIZE 1
/* This option defines minimization level to remove some basic API functions.
/
/ 0: All basic functions are enabled.
@ -34,7 +34,7 @@
/ 2: Enable with LF-CRLF conversion. */
#define _USE_FIND 0
#define _USE_FIND 1
/* This option switches filtered directory read feature and related functions,
/ f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */

View File

@ -3,25 +3,38 @@
#include "fatfs/ff.h"
#define PAYLOAD_ADDRESS 0x23F00000
#define PAYLOADS_FOLDER "/aurei/payloads/"
#define PAYLOAD_PATH(a) PAYLOADS_FOLDER a ".bin"
#define LOAD_PAYLOAD(a) loadPayload(a "_*.bin")
static u32 loadPayload(const char *path)
static u32 loadPayload(const char *pattern)
{
char path[30] = "/aurei/payloads";
DIR dir;
FILINFO info = { .lfname = NULL };
FRESULT result = f_findfirst(&dir, &info, path, pattern);
f_closedir(&dir);
if(result != FR_OK || !info.fname[0])
return 0;
path[15] = '/';
u32 i;
for(i = 0; info.fname[i]; i++)
path[16 + i] = info.fname[i];
path[16 + i] = '\0';
FIL payload;
unsigned int br;
if(f_open(&payload, path, FA_READ) == FR_OK)
{
f_open(&payload, path, FA_READ);
f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &br);
f_close(&payload);
return 1;
}
return 0;
}
void main(void)
{
FATFS fs;
@ -31,14 +44,13 @@ void main(void)
//Get pressed buttons
u32 pressed = HID_PAD;
if(((pressed & BUTTON_RIGHT) && loadPayload(PAYLOAD_PATH("right"))) ||
((pressed & BUTTON_LEFT) && loadPayload(PAYLOAD_PATH("left"))) ||
((pressed & BUTTON_UP) && loadPayload(PAYLOAD_PATH("up"))) ||
((pressed & BUTTON_DOWN) && loadPayload(PAYLOAD_PATH("down"))) ||
((pressed & BUTTON_X) && loadPayload(PAYLOAD_PATH("x"))) ||
((pressed & BUTTON_Y) && loadPayload(PAYLOAD_PATH("y"))) ||
((pressed & BUTTON_SELECT) && loadPayload(PAYLOAD_PATH("select"))) ||
((pressed & BUTTON_R1) && loadPayload(PAYLOAD_PATH("r"))) ||
loadPayload(PAYLOAD_PATH("default")))
if(((pressed & BUTTON_RIGHT) && LOAD_PAYLOAD("right")) ||
((pressed & BUTTON_LEFT) && LOAD_PAYLOAD("left")) ||
((pressed & BUTTON_UP) && LOAD_PAYLOAD("up")) ||
((pressed & BUTTON_DOWN) && LOAD_PAYLOAD("down")) ||
((pressed & BUTTON_X) && LOAD_PAYLOAD("x")) ||
((pressed & BUTTON_Y) && LOAD_PAYLOAD("y")) ||
((pressed & BUTTON_R1) && LOAD_PAYLOAD("r")) ||
LOAD_PAYLOAD("def"))
((void (*)())PAYLOAD_ADDRESS)();
}

View File

@ -34,7 +34,7 @@
/ 2: Enable with LF-CRLF conversion. */
#define _USE_FIND 0
#define _USE_FIND 1
/* This option switches filtered directory read feature and related functions,
/ f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */

View File

@ -64,16 +64,16 @@ u32 fileSize(const char *path)
return size;
}
u32 fileExists(const char *path)
u32 defPayloadExists(void)
{
FIL fp;
u32 exists = 0;
DIR dir;
FILINFO info = { .lfname = NULL };
if(f_open(&fp, path, FA_READ) == FR_OK) exists = 1;
FRESULT result = f_findfirst(&dir, &info, "/aurei/payloads", "def_*.bin");
f_close(&fp);
f_closedir(&dir);
return exists;
return (result == FR_OK && info.fname[0]);
}
void firmRead(void *dest, const char *firmFolder)

View File

@ -12,5 +12,5 @@ u32 mountFs(void);
u32 fileRead(void *dest, const char *path, u32 size);
u32 fileWrite(const void *buffer, const char *path, u32 size);
u32 fileSize(const char *path);
u32 fileExists(const char *path);
u32 defPayloadExists(void);
void firmRead(void *dest, const char *firmFolder);

View File

@ -14,7 +14,7 @@
void loadPayload(void)
{
if(fileExists("aurei/payloads/default.bin"))
if(defPayloadExists())
{
initScreens();
memcpy((void *)PAYLOAD_ADDRESS, loader, loader_size);