Remade the chainloader to only try to load the right payload for the pressed button, got rid of the default payload (start now boots "start_NAME.bin"), sel_NAME is now select_NAME as there is no more SFN limitations anymore

This commit is contained in:
Aurora 2016-04-29 14:28:37 +02:00
parent e651c3d9cc
commit c6d3158b56
10 changed files with 55 additions and 85 deletions

View File

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

View File

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

View File

@ -1,4 +1,15 @@
#pragma once #pragma once
#include <stdbool.h> #include <stdbool.h>
#include "../../types.h" #include <stdint.h>
#include <stdlib.h>
//Common data types
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef volatile u8 vu8;
typedef volatile u16 vu16;
typedef volatile u32 vu32;
typedef volatile u64 vu64;

View File

@ -1,39 +1,6 @@
#include "types.h"
#include "buttons.h"
#include "fatfs/ff.h" #include "fatfs/ff.h"
#define PAYLOAD_ADDRESS 0x23F00000 #define PAYLOAD_ADDRESS 0x23F00000
#define LOAD_PAYLOAD(a) loadPayload(a "_*.bin")
static u32 loadPayload(const char *pattern)
{
char path[29] = "/luma/payloads";
DIR dir;
FILINFO info;
FRESULT result = f_findfirst(&dir, &info, path, pattern);
f_closedir(&dir);
if(result != FR_OK || !info.fname[0])
return 0;
path[14] = '/';
u32 i;
for(i = 0; info.fname[i]; i++)
path[15 + i] = info.fname[i];
path[15 + i] = '\0';
FIL payload;
unsigned int read;
f_open(&payload, path, FA_READ);
f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &read);
f_close(&payload);
return 1;
}
void main(void) void main(void)
{ {
@ -41,18 +8,12 @@ void main(void)
f_mount(&fs, "0:", 1); f_mount(&fs, "0:", 1);
//Get pressed buttons FIL payload;
u32 pressed = HID_PAD; unsigned int read;
f_open(&payload, (char *)0x24F02000, FA_READ);
f_read(&payload, (void *)PAYLOAD_ADDRESS, f_size(&payload), &read);
f_close(&payload);
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")) ||
((pressed & BUTTON_A) && LOAD_PAYLOAD("a")) ||
((pressed & BUTTON_SELECT) && LOAD_PAYLOAD("sel")) ||
LOAD_PAYLOAD("def"))
((void (*)())PAYLOAD_ADDRESS)(); ((void (*)())PAYLOAD_ADDRESS)();
} }

View File

@ -1,14 +0,0 @@
#pragma once
#include <stdint.h>
#include <stdlib.h>
//Common data types
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef volatile u8 vu8;
typedef volatile u16 vu16;
typedef volatile u32 vu32;
typedef volatile u64 vu64;

View File

@ -129,7 +129,7 @@ void main(void)
the Safe Mode combo is not pressed, chainload an external payload */ the Safe Mode combo is not pressed, chainload an external payload */
if(((pressed & SINGLE_PAYLOAD_BUTTONS) || ((pressed & BUTTON_L1) && (pressed & L_PAYLOAD_BUTTONS))) if(((pressed & SINGLE_PAYLOAD_BUTTONS) || ((pressed & BUTTON_L1) && (pressed & L_PAYLOAD_BUTTONS)))
&& pressed != SAFE_MODE) && pressed != SAFE_MODE)
loadPayload(); loadPayload(pressed);
//If no configuration file exists or SELECT is held, load configuration menu //If no configuration file exists or SELECT is held, load configuration menu
if(needConfig == 2 || (pressed & BUTTON_SELECT)) if(needConfig == 2 || (pressed & BUTTON_SELECT))

View File

@ -4,8 +4,11 @@
#include "fs.h" #include "fs.h"
#include "memory.h" #include "memory.h"
#include "buttons.h"
#include "fatfs/ff.h" #include "fatfs/ff.h"
#define PATTERN(a) a "_*.bin"
static FATFS sdFs, static FATFS sdFs,
nandFs; nandFs;
@ -52,16 +55,39 @@ u32 fileWrite(const void *buffer, const char *path, u32 size)
return result; return result;
} }
u32 defPayloadExists(void) u32 payloadExists(u32 pressed)
{ {
const char *pattern;
if(pressed & BUTTON_RIGHT) pattern = PATTERN("right");
else if(pressed & BUTTON_LEFT) pattern = PATTERN("left");
else if(pressed & BUTTON_UP) pattern = PATTERN("up");
else if(pressed & BUTTON_DOWN) pattern = PATTERN("down");
else if(pressed & BUTTON_X) pattern = PATTERN("x");
else if(pressed & BUTTON_Y) pattern = PATTERN("y");
else if(pressed & BUTTON_R1) pattern = PATTERN("r");
else if(pressed & BUTTON_A) pattern = PATTERN("a");
else if(pressed & BUTTON_START) pattern = PATTERN("start");
else pattern = PATTERN("select");
DIR dir; DIR dir;
FILINFO info; FILINFO info;
char path[] = "/luma/payloads";
FRESULT result = f_findfirst(&dir, &info, "/luma/payloads", "def_*.bin"); FRESULT result = f_findfirst(&dir, &info, path, pattern);
f_closedir(&dir); f_closedir(&dir);
return (result == FR_OK && info.fname[0]); if(result == FR_OK && info.fname[0])
{
path[sizeof(path) - 1] = '/';
memcpy((void *)0x24F02000, path, sizeof(path));
memcpy((void *)(0x24F02000 + sizeof(path)), info.altname, 13);
return 1;
}
return 0;
} }
void firmRead(void *dest, const char *firmFolder) void firmRead(void *dest, const char *firmFolder)

View File

@ -9,5 +9,5 @@
u32 mountFs(void); u32 mountFs(void);
u32 fileRead(void *dest, const char *path, u32 size); u32 fileRead(void *dest, const char *path, u32 size);
u32 fileWrite(const void *buffer, const char *path, u32 size); u32 fileWrite(const void *buffer, const char *path, u32 size);
u32 defPayloadExists(void); u32 payloadExists(u32 pressed);
void firmRead(void *dest, const char *firmFolder); void firmRead(void *dest, const char *firmFolder);

View File

@ -10,9 +10,9 @@
#define PAYLOAD_ADDRESS 0x24F00000 #define PAYLOAD_ADDRESS 0x24F00000
void loadPayload(void) void loadPayload(u32 pressed)
{ {
if(defPayloadExists()) if(payloadExists(pressed))
{ {
initScreens(); initScreens();
memcpy((void *)PAYLOAD_ADDRESS, loader, loader_size); memcpy((void *)PAYLOAD_ADDRESS, loader, loader_size);

View File

@ -6,4 +6,4 @@
#include "types.h" #include "types.h"
void loadPayload(void); void loadPayload(u32 pressed);