Small code reorganization
This commit is contained in:
parent
21a3edb150
commit
9e851d2dfd
2
Makefile
2
Makefile
@ -96,7 +96,7 @@ $(dir_build)/main.elf: $(objects_cfw)
|
|||||||
$(CC) -nostartfiles $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^
|
$(CC) -nostartfiles $(LDFLAGS) -T linker.ld $(OUTPUT_OPTION) $^
|
||||||
|
|
||||||
$(dir_build)/memory.o : CFLAGS+=-O3
|
$(dir_build)/memory.o : CFLAGS+=-O3
|
||||||
$(dir_build)/utils.o : CFLAGS += -DCONFIG_TITLE="\"$(name) $(version) configuration\""
|
$(dir_build)/config.o : CFLAGS += -DCONFIG_TITLE="\"$(name) $(version) configuration\""
|
||||||
|
|
||||||
$(dir_build)/%.o: $(dir_source)/%.c $(dir_build)/patches.h $(dir_build)/loader.h $(dir_build)/screeninit.h
|
$(dir_build)/%.o: $(dir_source)/%.c $(dir_build)/patches.h $(dir_build)/loader.h $(dir_build)/screeninit.h
|
||||||
@mkdir -p "$(@D)"
|
@mkdir -p "$(@D)"
|
||||||
|
113
source/config.c
Normal file
113
source/config.c
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* config.c
|
||||||
|
* by Aurora Wright
|
||||||
|
* Copyright (c) 2016 All Rights Reserved
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "screeninit.h"
|
||||||
|
#include "draw.h"
|
||||||
|
#include "fs.h"
|
||||||
|
#include "i2c.h"
|
||||||
|
#include "buttons.h"
|
||||||
|
|
||||||
|
void configureCFW(const char *configPath, const char *patchedFirms[])
|
||||||
|
{
|
||||||
|
initScreens();
|
||||||
|
|
||||||
|
drawString(CONFIG_TITLE, 10, 10, COLOR_TITLE);
|
||||||
|
drawString("Press A to select, START to save and reboot", 10, 30, COLOR_WHITE);
|
||||||
|
|
||||||
|
const char *optionsText[] = { "( ) Updated SysNAND mode (A9LH-only)",
|
||||||
|
"( ) Use pre-patched FIRMs",
|
||||||
|
"( ) Force A9LH detection",
|
||||||
|
"( ) Use 9.0 FIRM as default",
|
||||||
|
"( ) Use second EmuNAND as default",
|
||||||
|
"( ) Show current NAND in System Settings",
|
||||||
|
"( ) Show GBA boot screen in patched AGB_FIRM" };
|
||||||
|
|
||||||
|
u32 optionsAmount = sizeof(optionsText) / sizeof(char *);
|
||||||
|
|
||||||
|
struct option {
|
||||||
|
int posY;
|
||||||
|
u32 enabled;
|
||||||
|
} options[optionsAmount];
|
||||||
|
|
||||||
|
//Parse the existing configuration
|
||||||
|
for(u32 i = 0; i < optionsAmount; i++)
|
||||||
|
options[i].enabled = (config >> i) & 1;
|
||||||
|
|
||||||
|
options[optionsAmount].enabled = (config >> 10) & 3;
|
||||||
|
|
||||||
|
//Pre-select the first configuration option
|
||||||
|
u32 selectedOption = 0;
|
||||||
|
|
||||||
|
//Boring configuration menu
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
u16 pressed = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
options[optionsAmount].posY = drawString("Screen-init brightness: 4( ) 3( ) 2( ) 1( )", 10, 53, selectedOption == optionsAmount ? COLOR_RED : COLOR_WHITE);
|
||||||
|
|
||||||
|
for(u32 i = 0; i < optionsAmount; i++)
|
||||||
|
{
|
||||||
|
options[i].posY = drawString(optionsText[i], 10, !i ? options[optionsAmount].posY + 2 * SPACING_Y : options[i - 1].posY + SPACING_Y, selectedOption == i ? COLOR_RED : COLOR_WHITE);
|
||||||
|
drawCharacter('x', 10 + SPACING_X, options[i].posY, options[i].enabled ? (selectedOption == i ? COLOR_RED : COLOR_WHITE) : COLOR_BLACK);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(u32 i = 0; i < 4; i++)
|
||||||
|
drawCharacter('x', 10 + (26 + 5 * i) * SPACING_X, options[optionsAmount].posY, options[optionsAmount].enabled == i ? (selectedOption == optionsAmount ? COLOR_RED : COLOR_WHITE) : COLOR_BLACK);
|
||||||
|
|
||||||
|
pressed = waitInput();
|
||||||
|
}
|
||||||
|
while(!(pressed & MENU_BUTTONS));
|
||||||
|
|
||||||
|
switch(pressed)
|
||||||
|
{
|
||||||
|
case BUTTON_UP:
|
||||||
|
selectedOption = !selectedOption ? optionsAmount : selectedOption - 1;
|
||||||
|
break;
|
||||||
|
case BUTTON_DOWN:
|
||||||
|
selectedOption = selectedOption >= optionsAmount - 1 ? 0 : selectedOption + 1;
|
||||||
|
break;
|
||||||
|
case BUTTON_LEFT:
|
||||||
|
selectedOption = 0;
|
||||||
|
break;
|
||||||
|
case BUTTON_RIGHT:
|
||||||
|
selectedOption = optionsAmount - 1;
|
||||||
|
break;
|
||||||
|
case BUTTON_A:
|
||||||
|
if(selectedOption != optionsAmount) options[selectedOption].enabled = !options[selectedOption].enabled;
|
||||||
|
else options[optionsAmount].enabled = options[optionsAmount].enabled == 3 ? 0 : options[optionsAmount].enabled + 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pressed == BUTTON_START) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//If the user has been using A9LH and the "Updated SysNAND" setting changed, delete the patched 9.0 FIRM
|
||||||
|
if(((config >> 16) & 1) && ((config & 1) != options[0].enabled)) fileDelete(patchedFirms[3]);
|
||||||
|
|
||||||
|
//If the "Show GBA boot screen in patched AGB_FIRM" setting changed, delete the patched AGB_FIRM
|
||||||
|
if(((config >> 6) & 1) != options[6].enabled) fileDelete(patchedFirms[5]);
|
||||||
|
|
||||||
|
//Preserve the last-used boot options (last 12 bits)
|
||||||
|
config &= 0xFFF000;
|
||||||
|
|
||||||
|
//Parse and write the new configuration
|
||||||
|
for(u32 i = 0; i < optionsAmount; i++)
|
||||||
|
config |= options[i].enabled << i;
|
||||||
|
|
||||||
|
config |= options[optionsAmount].enabled << 10;
|
||||||
|
|
||||||
|
fileWrite(&config, configPath, 3);
|
||||||
|
|
||||||
|
//Zero the last booted FIRM flag
|
||||||
|
CFG_BOOTENV = 0;
|
||||||
|
|
||||||
|
//Reboot
|
||||||
|
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2);
|
||||||
|
while(1);
|
||||||
|
}
|
15
source/config.h
Normal file
15
source/config.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* config.h
|
||||||
|
* by Aurora Wright
|
||||||
|
* Copyright (c) 2016 All Rights Reserved
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "types.h"
|
||||||
|
|
||||||
|
#define CFG_BOOTENV (*(vu32 *)0x10010000)
|
||||||
|
|
||||||
|
u32 config;
|
||||||
|
|
||||||
|
void configureCFW(const char *configPath, const char *patchedFirms[]);
|
@ -12,6 +12,10 @@
|
|||||||
|
|
||||||
#define SPACING_Y 10
|
#define SPACING_Y 10
|
||||||
#define SPACING_X 8
|
#define SPACING_X 8
|
||||||
|
#define COLOR_TITLE 0xFF9900
|
||||||
|
#define COLOR_WHITE 0xFFFFFF
|
||||||
|
#define COLOR_RED 0x0000FF
|
||||||
|
#define COLOR_BLACK 0x000000
|
||||||
|
|
||||||
void loadSplash(void);
|
void loadSplash(void);
|
||||||
void clearScreens(void);
|
void clearScreens(void);
|
||||||
|
@ -5,15 +5,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "firm.h"
|
#include "firm.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "utils.h"
|
||||||
|
#include "fs.h"
|
||||||
#include "patches.h"
|
#include "patches.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "fs.h"
|
|
||||||
#include "emunand.h"
|
#include "emunand.h"
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "screeninit.h"
|
#include "screeninit.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
#include "utils.h"
|
|
||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
#include "../build/patches.h"
|
#include "../build/patches.h"
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ static const char *patchedFirms[] = { "/aurei/patched_firmware_sys.bin",
|
|||||||
"/aurei/patched_firmware90.bin",
|
"/aurei/patched_firmware90.bin",
|
||||||
"/aurei/patched_firmware_twl.bin",
|
"/aurei/patched_firmware_twl.bin",
|
||||||
"/aurei/patched_firmware_agb.bin" };
|
"/aurei/patched_firmware_agb.bin" };
|
||||||
|
u32 config;
|
||||||
static u32 firmSize,
|
static u32 firmSize,
|
||||||
console,
|
console,
|
||||||
mode,
|
mode,
|
||||||
@ -39,7 +40,6 @@ static u32 firmSize,
|
|||||||
usePatchedFirm,
|
usePatchedFirm,
|
||||||
emuOffset,
|
emuOffset,
|
||||||
emuHeader;
|
emuHeader;
|
||||||
u32 config;
|
|
||||||
|
|
||||||
void setupCFW(void)
|
void setupCFW(void)
|
||||||
{
|
{
|
||||||
@ -252,16 +252,7 @@ static inline void patchTwlAgb(u32 whichFirm)
|
|||||||
twlAgbFirm->arm9Entry = (u8 *)0x801301C;
|
twlAgbFirm->arm9Entry = (u8 *)0x801301C;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct patchData {
|
static const patchData twlPatches[] = {
|
||||||
u32 offset[2];
|
|
||||||
union {
|
|
||||||
u8 type0[8];
|
|
||||||
u16 type1;
|
|
||||||
} patch;
|
|
||||||
u32 type;
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct patchData twlPatches[] = {
|
|
||||||
{{0x1650C0, 0x165D64}, {{ 6, 0x00, 0x20, 0x4E, 0xB0, 0x70, 0xBD }}, 0},
|
{{0x1650C0, 0x165D64}, {{ 6, 0x00, 0x20, 0x4E, 0xB0, 0x70, 0xBD }}, 0},
|
||||||
{{0x173A0E, 0x17474A}, { .type1 = 0x2001 }, 1},
|
{{0x173A0E, 0x17474A}, { .type1 = 0x2001 }, 1},
|
||||||
{{0x174802, 0x17553E}, { .type1 = 0x2000 }, 2},
|
{{0x174802, 0x17553E}, { .type1 = 0x2000 }, 2},
|
||||||
@ -271,18 +262,17 @@ static inline void patchTwlAgb(u32 whichFirm)
|
|||||||
{{0x174D6A, 0x175AA6}, { .type1 = 0x2001 }, 2},
|
{{0x174D6A, 0x175AA6}, { .type1 = 0x2001 }, 2},
|
||||||
{{0x174E56, 0x175B92}, { .type1 = 0x2001 }, 1},
|
{{0x174E56, 0x175B92}, { .type1 = 0x2001 }, 1},
|
||||||
{{0x174E58, 0x175B94}, { .type1 = 0x4770 }, 1}
|
{{0x174E58, 0x175B94}, { .type1 = 0x4770 }, 1}
|
||||||
};
|
},
|
||||||
|
agbPatches[] = {
|
||||||
static const struct patchData agbPatches[] = {
|
|
||||||
{{0x9D2A8, 0x9DF64}, {{ 6, 0x00, 0x20, 0x4E, 0xB0, 0x70, 0xBD }}, 0},
|
{{0x9D2A8, 0x9DF64}, {{ 6, 0x00, 0x20, 0x4E, 0xB0, 0x70, 0xBD }}, 0},
|
||||||
{{0xD7A12, 0xD8B8A}, { .type1 = 0xEF26 }, 1}
|
{{0xD7A12, 0xD8B8A}, { .type1 = 0xEF26 }, 1}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Calculate the amount of patches to apply. Only count the boot screen patch for AGB_FIRM
|
/* Calculate the amount of patches to apply. Only count the boot screen patch for AGB_FIRM
|
||||||
if the matching option was enabled (keep it as last) */
|
if the matching option was enabled (keep it as last) */
|
||||||
u32 numPatches = whichFirm ? (sizeof(agbPatches) / sizeof(struct patchData)) - !((config >> 6) & 1) :
|
u32 numPatches = whichFirm ? (sizeof(agbPatches) / sizeof(patchData)) - !((config >> 6) & 1) :
|
||||||
(sizeof(twlPatches) / sizeof(struct patchData));
|
(sizeof(twlPatches) / sizeof(patchData));
|
||||||
const struct patchData *patches = whichFirm ? agbPatches : twlPatches;
|
const patchData *patches = whichFirm ? agbPatches : twlPatches;
|
||||||
|
|
||||||
//Patch
|
//Patch
|
||||||
for(u32 i = 0; i < numPatches; i++)
|
for(u32 i = 0; i < numPatches; i++)
|
||||||
|
@ -29,6 +29,15 @@ typedef struct firmHeader {
|
|||||||
firmSectionHeader section[4];
|
firmSectionHeader section[4];
|
||||||
} firmHeader;
|
} firmHeader;
|
||||||
|
|
||||||
|
typedef struct patchData {
|
||||||
|
u32 offset[2];
|
||||||
|
union {
|
||||||
|
u8 type0[8];
|
||||||
|
u16 type1;
|
||||||
|
} patch;
|
||||||
|
u32 type;
|
||||||
|
} patchData;
|
||||||
|
|
||||||
void setupCFW(void);
|
void setupCFW(void);
|
||||||
void loadFirm(void);
|
void loadFirm(void);
|
||||||
void patchFirm(void);
|
void patchFirm(void);
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "screeninit.h"
|
#include "screeninit.h"
|
||||||
|
#include "config.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
@ -13,7 +13,5 @@
|
|||||||
|
|
||||||
#define PDN_GPU_CNT (*(vu8 *)0x10141200)
|
#define PDN_GPU_CNT (*(vu8 *)0x10141200)
|
||||||
|
|
||||||
u32 config;
|
|
||||||
|
|
||||||
void deinitScreens(void);
|
void deinitScreens(void);
|
||||||
void initScreens(void);
|
void initScreens(void);
|
108
source/utils.c
108
source/utils.c
@ -11,17 +11,7 @@
|
|||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
|
|
||||||
#define COLOR_TITLE 0xFF9900
|
u32 waitInput(void)
|
||||||
#define COLOR_WHITE 0xFFFFFF
|
|
||||||
#define COLOR_RED 0x0000FF
|
|
||||||
#define COLOR_BLACK 0x000000
|
|
||||||
|
|
||||||
struct option {
|
|
||||||
int posY;
|
|
||||||
u32 enabled;
|
|
||||||
};
|
|
||||||
|
|
||||||
static u32 waitInput(void)
|
|
||||||
{
|
{
|
||||||
u32 pressedKey = 0;
|
u32 pressedKey = 0;
|
||||||
u32 key;
|
u32 key;
|
||||||
@ -47,102 +37,6 @@ static u32 waitInput(void)
|
|||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
void configureCFW(const char *configPath, const char *patchedFirms[])
|
|
||||||
{
|
|
||||||
initScreens();
|
|
||||||
|
|
||||||
drawString(CONFIG_TITLE, 10, 10, COLOR_TITLE);
|
|
||||||
drawString("Press A to select, START to save and reboot", 10, 30, COLOR_WHITE);
|
|
||||||
|
|
||||||
const char *optionsText[] = { "( ) Updated SysNAND mode (A9LH-only)",
|
|
||||||
"( ) Use pre-patched FIRMs",
|
|
||||||
"( ) Force A9LH detection",
|
|
||||||
"( ) Use 9.0 FIRM as default",
|
|
||||||
"( ) Use second EmuNAND as default",
|
|
||||||
"( ) Show current NAND in System Settings",
|
|
||||||
"( ) Show GBA boot screen in patched AGB_FIRM" };
|
|
||||||
|
|
||||||
u32 optionsAmount = sizeof(optionsText) / sizeof(char *);
|
|
||||||
struct option options[optionsAmount];
|
|
||||||
|
|
||||||
//Parse the existing configuration
|
|
||||||
for(u32 i = 0; i < optionsAmount; i++)
|
|
||||||
options[i].enabled = (config >> i) & 1;
|
|
||||||
|
|
||||||
options[optionsAmount].enabled = (config >> 10) & 3;
|
|
||||||
|
|
||||||
//Pre-select the first configuration option
|
|
||||||
u32 selectedOption = 0;
|
|
||||||
|
|
||||||
//Boring configuration menu
|
|
||||||
while(1)
|
|
||||||
{
|
|
||||||
u16 pressed = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
options[optionsAmount].posY = drawString("Screen-init brightness: 4( ) 3( ) 2( ) 1( )", 10, 53, selectedOption == optionsAmount ? COLOR_RED : COLOR_WHITE);
|
|
||||||
|
|
||||||
for(u32 i = 0; i < optionsAmount; i++)
|
|
||||||
{
|
|
||||||
options[i].posY = drawString(optionsText[i], 10, !i ? options[optionsAmount].posY + 2 * SPACING_Y : options[i - 1].posY + SPACING_Y, selectedOption == i ? COLOR_RED : COLOR_WHITE);
|
|
||||||
drawCharacter('x', 10 + SPACING_X, options[i].posY, options[i].enabled ? (selectedOption == i ? COLOR_RED : COLOR_WHITE) : COLOR_BLACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(u32 i = 0; i < 4; i++)
|
|
||||||
drawCharacter('x', 10 + (26 + 5 * i) * SPACING_X, options[optionsAmount].posY, options[optionsAmount].enabled == i ? (selectedOption == optionsAmount ? COLOR_RED : COLOR_WHITE) : COLOR_BLACK);
|
|
||||||
|
|
||||||
pressed = waitInput();
|
|
||||||
}
|
|
||||||
while(!(pressed & MENU_BUTTONS));
|
|
||||||
|
|
||||||
switch(pressed)
|
|
||||||
{
|
|
||||||
case BUTTON_UP:
|
|
||||||
selectedOption = !selectedOption ? optionsAmount : selectedOption - 1;
|
|
||||||
break;
|
|
||||||
case BUTTON_DOWN:
|
|
||||||
selectedOption = selectedOption >= optionsAmount - 1 ? 0 : selectedOption + 1;
|
|
||||||
break;
|
|
||||||
case BUTTON_LEFT:
|
|
||||||
selectedOption = 0;
|
|
||||||
break;
|
|
||||||
case BUTTON_RIGHT:
|
|
||||||
selectedOption = optionsAmount - 1;
|
|
||||||
break;
|
|
||||||
case BUTTON_A:
|
|
||||||
if(selectedOption != optionsAmount) options[selectedOption].enabled = !options[selectedOption].enabled;
|
|
||||||
else options[optionsAmount].enabled = options[optionsAmount].enabled == 3 ? 0 : options[optionsAmount].enabled + 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(pressed == BUTTON_START) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//If the user has been using A9LH and the "Updated SysNAND" setting changed, delete the patched 9.0 FIRM
|
|
||||||
if(((config >> 16) & 1) && ((config & 1) != options[0].enabled)) fileDelete(patchedFirms[3]);
|
|
||||||
|
|
||||||
//If the "Show GBA boot screen in patched AGB_FIRM" setting changed, delete the patched AGB_FIRM
|
|
||||||
if(((config >> 6) & 1) != options[6].enabled) fileDelete(patchedFirms[5]);
|
|
||||||
|
|
||||||
//Preserve the last-used boot options (last 12 bits)
|
|
||||||
config &= 0xFFF000;
|
|
||||||
|
|
||||||
//Parse and write the new configuration
|
|
||||||
for(u32 i = 0; i < optionsAmount; i++)
|
|
||||||
config |= options[i].enabled << i;
|
|
||||||
|
|
||||||
config |= options[optionsAmount].enabled << 10;
|
|
||||||
|
|
||||||
fileWrite(&config, configPath, 3);
|
|
||||||
|
|
||||||
//Zero the last booted FIRM flag
|
|
||||||
CFG_BOOTENV = 0;
|
|
||||||
|
|
||||||
//Reboot
|
|
||||||
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2);
|
|
||||||
while(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void deleteFirms(const char *firmPaths[], u32 firms)
|
void deleteFirms(const char *firmPaths[], u32 firms)
|
||||||
{
|
{
|
||||||
while(firms)
|
while(firms)
|
||||||
|
@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
#define CFG_BOOTENV (*(vu32 *)0x10010000)
|
u32 waitInput(void);
|
||||||
|
|
||||||
void configureCFW(const char *configPath, const char *patchedFirms[]);
|
|
||||||
void deleteFirms(const char *firmPaths[], u32 firms);
|
void deleteFirms(const char *firmPaths[], u32 firms);
|
||||||
void error(const char *message);
|
void error(const char *message);
|
Reference in New Issue
Block a user