Merge branch 'master' into developer

Conflicts:
	source/firm.c
	source/patches.c
	source/patches.h
	source/utils.h
This commit is contained in:
TuxSH
2016-05-09 20:45:06 +02:00
17 changed files with 90 additions and 77 deletions

View File

@@ -7,14 +7,15 @@
#include "screeninit.h"
#include "draw.h"
#include "fs.h"
#include "i2c.h"
#include "buttons.h"
void configureCFW(const char *configPath)
{
initScreens();
u32 needToDeinit = initScreens();
drawString(CONFIG_TITLE, 10, 10, COLOR_TITLE);
drawString("Press A to select, START to save and reboot", 10, 30, COLOR_WHITE);
drawString("Press A to select, START to save", 10, 30, COLOR_WHITE);
const char *multiOptionsText[] = { "Screen-init brightness: 4( ) 3( ) 2( ) 1( )",
"New 3DS CPU: Off( ) Clock( ) L2( ) Clock+L2( )" };
@@ -175,8 +176,16 @@ void configureCFW(const char *configPath)
fileWrite(&config, configPath, 4);
//Zero the last booted FIRM flag
CFG_BOOTENV = 0;
//Wait for the pressed buttons to change
while(HID_PAD == BUTTON_START);
mcuReboot();
if(needToDeinit)
{
//Turn off backlight
i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x16);
deinitScreens();
PDN_GPU_CNT = 1;
}
delay(0x1400000);
}

View File

@@ -6,8 +6,6 @@
#include "types.h"
#define CFG_BOOTENV (*(vu32 *)0x10010000)
#define CONFIG(a) ((config >> (a + 16)) & 1)
#define MULTICONFIG(a) ((config >> (a * 2 + 6)) & 3)
#define BOOTCONFIG(a, b) ((config >> a) & b)

View File

@@ -6,6 +6,7 @@
#include "draw.h"
#include "screeninit.h"
#include "utils.h"
#include "fs.h"
#include "memory.h"
#include "font.h"
@@ -39,10 +40,7 @@ void loadSplash(void)
//Don't delay boot if no splash image is on the SD
if(fileRead(fb->top_left, "/luma/splash.bin") +
fileRead(fb->bottom, "/luma/splashbottom.bin"))
{
u64 i = 0x1400000;
while(i--) __asm("mov r0, r0"); //Less Ghetto sleep func
}
delay(0x1400000);
}
void drawCharacter(char character, int posX, int posY, u32 color)

View File

@@ -103,8 +103,16 @@ void main(void)
//If no configuration file exists or SELECT is held, load configuration menu
if(needConfig == 2 || (pressed & BUTTON_SELECT))
{
configureCFW(configPath);
//Zero the last booted FIRM flag
CFG_BOOTENV = 0;
//Update pressed buttons
pressed = HID_PAD;
}
u32 devMode = CONFIG(5);
if(devMode)
@@ -247,7 +255,7 @@ void main(void)
break;
}
launchFirm(bootType);
launchFirm(!firmType, bootType);
}
static inline void loadFirm(u32 firmType, u32 externalFirm)
@@ -414,14 +422,13 @@ static inline void patchReboots(u8 *arm9Section, u8 *proc9Offset)
static inline void copySection0AndInjectLoader(void)
{
u32 loaderSize;
u8 *arm11Section0 = (u8 *)firm + section[0].offset;
u32 injectorOffset = (u8 *)getLoader((u8 *)firm + section[0].offset, section[0].size, &loaderSize) - arm11Section0;
u32 remaining = section[0].size - (injectorOffset + loaderSize);
memcpy(section[0].address, arm11Section0, injectorOffset);
memcpy(section[0].address + injectorOffset, injector, injector_size);
memcpy(section[0].address + injectorOffset + injector_size, arm11Section0 + section[0].size - remaining, remaining);
u32 loaderSize;
u32 loaderOffset = getLoader(arm11Section0, &loaderSize);
memcpy(section[0].address, arm11Section0, loaderOffset);
memcpy(section[0].address + loaderOffset, injector, injector_size);
memcpy(section[0].address + loaderOffset + injector_size, arm11Section0 + loaderOffset + loaderSize, section[0].size - (loaderOffset + loaderSize));
}
static inline void patchLegacyFirm(u32 firmType)
@@ -503,10 +510,10 @@ static void patchFirmWrites(u8 *arm9Section, u32 mode)
}
}
static inline void launchFirm(u32 bootType)
static inline void launchFirm(u32 firstSectionToCopy, u32 bootType)
{
//Copy FIRM sections to respective memory locations
for(u32 i = 1; i < 4 && section[i].size; i++)
for(u32 i = firstSectionToCopy; i < 4 && section[i].size; i++)
memcpy(section[i].address, (u8 *)firm + section[i].offset, section[i].size);
//Determine the ARM11 entry to use

View File

@@ -8,6 +8,7 @@
#define PDN_MPCORE_CFG (*(vu32 *)0x10140FFC)
#define PDN_SPI_CNT (*(vu32 *)0x101401C0)
#define CFG_BOOTENV (*(vu32 *)0x10010000)
//FIRM Header layout
typedef struct firmSectionHeader {
@@ -44,4 +45,4 @@ static inline void copySection0AndInjectLoader(void);
static inline void patchLegacyFirm(u32 firmType);
static inline void patchSafeFirm(void);
static void patchFirmWrites(u8 *arm9Section, u32 mode);
static inline void launchFirm(u32 bootType);
static inline void launchFirm(u32 firstSectionToCopy, u32 bootType);

View File

@@ -82,18 +82,19 @@ u8 *getUnitInfoValueSet(u8 *pos, u32 size)
return memsearch(pos, pattern, size, 4) + 3;
}
void *getLoader(u8 *pos, u32 size, u32 *loaderSize)
u32 getLoader(u8 *pos, u32 *loaderSize)
{
u8 *off = pos;
do
u32 size;
while(1)
{
if(*(u32 *)(off + 0x200) == 0x64616F6C) break; //"load"
off += *(u32 *)(off + 0x104) * 0x200; //size of the CXI
size = *(u32 *)(off + 0x104) * 0x200;
if(*(u32 *)(off + 0x200) == 0x64616F6C) break;
off += size;
}
while(off < pos + size);
if(off >= pos + size) return NULL;
*loaderSize = *(u32 *)(off + 0x104) * 0x200;
return off;
*loaderSize = size;
return (u32)(off - pos);
}

View File

@@ -26,4 +26,4 @@ u32 getfOpen(u8 *proc9Offset, void *rebootOffset);
u16 *getFirmWrite(u8 *pos, u32 size);
u16 *getFirmWriteSafe(u8 *pos, u32 size);
u8 *getUnitInfoValueSet(u8 *pos, u32 size);
void *getLoader(u8 *pos, u32 size, u32 *loaderSize);
u32 getLoader(u8 *pos, u32 *loaderSize);

View File

@@ -43,9 +43,11 @@ void deinitScreens(void)
}
}
void initScreens(void)
u32 initScreens(void)
{
if(PDN_GPU_CNT == 1)
u32 needToInit = PDN_GPU_CNT == 1;
if(needToInit)
{
u32 *const screenInitAddress = (u32 *)0x24FFFC00;
@@ -62,4 +64,6 @@ void initScreens(void)
}
clearScreens();
return needToInit;
}

View File

@@ -9,7 +9,7 @@
#include "types.h"
#define PDN_GPU_CNT (*(vu8 *)0x10141200)
#define PDN_GPU_CNT (*(vu8 *)0x10141200)
void deinitScreens(void);
void initScreens(void);
u32 initScreens(void);

View File

@@ -33,6 +33,11 @@ u32 waitInput(void)
return key;
}
void delay(u64 length)
{
while(length--) __asm("mov r0, r0");
}
void mcuReboot(void)
{
i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 2);

View File

@@ -7,5 +7,5 @@
#include "types.h"
u32 waitInput(void);
void mcuReboot(void);
void error(const char *message);
void delay(u64 length);
void mcuReboot(void);