Merge branch 'master' into developer

Conflicts:
	source/firm.h
	source/fs.h
	source/patches.h
This commit is contained in:
TuxSH 2016-07-02 17:44:08 +02:00
commit 2d6debddb9
16 changed files with 57 additions and 53 deletions

@ -1 +1 @@
Subproject commit bead2ce337cc31da6b7ca1c1ce30672d78a7fe00
Subproject commit 9f7cea77d4db4d743e45b2e5193df76ffed0a571

View File

@ -5,7 +5,7 @@
#ifndef PATH_MAX
#define PATH_MAX 255
#define CONFIG(a) ((loadConfig() >> (a + 16)) & 1)
#define CONFIG(a) (((loadConfig() >> (a + 16)) & 1) != 0)
#define MULTICONFIG(a) ((loadConfig() >> (a * 2 + 6)) & 3)
#define BOOTCONFIG(a, b) ((loadConfig() >> a) & b)
#endif
@ -90,21 +90,21 @@ static int fileOpen(IFile *file, FS_ArchiveID archiveId, const char *path, int f
return IFile_Open(file, archiveId, archivePath, filePath, flags);
}
static u32 secureInfoExists(void)
static bool secureInfoExists(void)
{
static u32 secureInfoExists = 0;
static bool exists = false;
if(!secureInfoExists)
if(!exists)
{
IFile file;
if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ)))
{
secureInfoExists = 1;
exists = true;
IFile_Close(&file);
}
}
return secureInfoExists;
return exists;
}
static u32 loadConfig(void)
@ -263,8 +263,8 @@ static void patchCfgGetLanguage(u8 *code, u32 size, u8 languageId, u8 *CFGU_GetC
if(instr[3] == 0xEB) //We're looking for BL
{
u8 *calledFunction = instr;
u32 i = 0,
found;
u32 i = 0;
bool found;
do
{

View File

@ -12,7 +12,7 @@
void configureCFW(const char *configPath)
{
u32 needToDeinit = initScreens();
bool needToDeinit = initScreens();
drawString(CONFIG_TITLE, 10, 10, COLOR_TITLE);
drawString("Press A to select, START to save", 10, 30, COLOR_WHITE);
@ -48,7 +48,7 @@ void configureCFW(const char *configPath)
struct singleOption {
int posY;
u32 enabled;
bool enabled;
} singleOptions[singleOptionsAmount];
//Parse the existing options
@ -153,7 +153,7 @@ void configureCFW(const char *configPath)
}
else
{
u32 oldEnabled = singleOptions[selectedOption - multiOptionsAmount].enabled;
bool oldEnabled = singleOptions[selectedOption - multiOptionsAmount].enabled;
singleOptions[selectedOption - multiOptionsAmount].enabled = !oldEnabled;
if(oldEnabled) drawCharacter(selected, 10 + SPACING_X, singleOptions[selectedOption - multiOptionsAmount].posY, COLOR_BLACK);
}
@ -176,7 +176,7 @@ void configureCFW(const char *configPath)
for(u32 i = 0; i < multiOptionsAmount; i++)
config |= multiOptions[i].enabled << (i * 2 + 6);
for(u32 i = 0; i < singleOptionsAmount; i++)
config |= singleOptions[i].enabled << (i + 16);
config |= (singleOptions[i].enabled ? 1 : 0) << (i + 16);
fileWrite(&config, configPath, 4);

View File

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

View File

@ -79,7 +79,8 @@
#define SHA_224_HASH_SIZE (224 / 8)
#define SHA_1_HASH_SIZE (160 / 8)
extern u32 emuOffset, isN3DS;
extern u32 emuOffset;
extern bool isN3DS;
extern FirmwareSource firmSource;
void ctrNandInit(void);

View File

@ -19,15 +19,15 @@ static inline int strlen(const char *string)
return stringEnd - string;
}
u32 loadSplash(void)
bool loadSplash(void)
{
initScreens();
//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"))
return 1;
return 0;
fileRead(fb->bottom, "/luma/splashbottom.bin") != 0)
return true;
return false;
}
void drawCharacter(char character, int posX, int posY, u32 color)

View File

@ -21,6 +21,6 @@
extern volatile struct fb *const fb;
u32 loadSplash(void);
bool loadSplash(void);
void drawCharacter(char character, int posX, int posY, u32 color);
int drawString(const char *string, int posX, int posY, u32 color);

View File

@ -21,16 +21,18 @@ static firmHeader *const firm = (firmHeader *)0x24000000;
static const firmSectionHeader *section;
u32 config,
isN3DS,
emuOffset;
bool isN3DS;
FirmwareSource firmSource;
void main(void)
{
u32 isFirmlaunch,
updatedSys,
newConfig,
bool isFirmlaunch,
updatedSys;
u32 newConfig,
emuHeader,
nbChronoStarted = 0;
@ -61,7 +63,7 @@ void main(void)
{
if(needConfig == CREATE_CONFIGURATION) mcuReboot();
isFirmlaunch = 1;
isFirmlaunch = true;
//'0' = NATIVE_FIRM, '1' = TWL_FIRM, '2' = AGB_FIRM
firmType = *(vu8 *)0x23F00009 == '3' ? SAFE_FIRM : (FirmwareType)(*(vu8 *)0x23F00005 - '0');
@ -92,11 +94,11 @@ void main(void)
pressed = HID_PAD;
}
isFirmlaunch = 0;
isFirmlaunch = false;
firmType = NATIVE_FIRM;
//Determine if booting with A9LH
u32 a9lhBoot = !PDN_SPI_CNT;
bool a9lhBoot = !PDN_SPI_CNT;
//Determine if A9LH is installed and the user has an updated sysNAND
if(a9lhBoot || CONFIG(2))
@ -107,7 +109,7 @@ void main(void)
else
{
a9lhMode = NO_A9LH;
updatedSys = 0;
updatedSys = false;
}
newConfig = (u32)a9lhMode << 3;
@ -149,7 +151,7 @@ void main(void)
}
//Boot options aren't being forced
if(needConfig)
if(needConfig != DONT_CONFIGURE)
{
/* If L and R/A/Select or one of the single payload buttons are pressed,
chainload an external payload */
@ -234,13 +236,13 @@ void main(void)
launchFirm(firmType, isFirmlaunch);
}
static inline void loadFirm(FirmwareType firmType, u32 externalFirm)
static inline void loadFirm(FirmwareType firmType, bool externalFirm)
{
section = firm->section;
u32 externalFirmLoaded = externalFirm &&
fileRead(firm, "/luma/firmware.bin") &&
(((u32)section[2].address >> 8) & 0xFF) == (isN3DS ? 0x60 : 0x68);
bool externalFirmLoaded = externalFirm &&
fileRead(firm, "/luma/firmware.bin") &&
(((u32)section[2].address >> 8) & 0xFF) == (isN3DS ? 0x60 : 0x68);
/* If the conditions to load the external FIRM aren't met, or reading fails, or the FIRM
doesn't match the console, load FIRM from CTRNAND */
@ -251,7 +253,7 @@ static inline void loadFirm(FirmwareType firmType, u32 externalFirm)
{ "00000202", "20000202" },
{ "00000003", "20000003" }};
firmRead(firm, firmFolders[(u32)firmType][isN3DS]);
firmRead(firm, firmFolders[(u32)firmType][isN3DS ? 1 : 0]);
decryptExeFs((u8 *)firm);
}
}
@ -261,7 +263,7 @@ static inline void patchNativeFirm(FirmwareSource nandType, u32 emuHeader, A9LHM
u8 *arm9Section = (u8 *)firm + section[2].offset,
*arm11Section1 = (u8 *)firm + section[1].offset;
u32 is90Firm;
bool is90Firm;
if(isN3DS)
{
@ -302,7 +304,7 @@ static inline void patchNativeFirm(FirmwareSource nandType, u32 emuHeader, A9LHM
patchSignatureChecks(process9Offset, process9Size);
//Apply emuNAND patches
if(nandType)
if(nandType != FIRMWARE_SYSNAND)
{
u32 branchAdditive = (u32)firm + section[2].offset - (u32)section[2].address;
patchEmuNAND(arm9Section, section[2].size, process9Offset, process9Size, emuOffset, emuHeader, branchAdditive);
@ -452,7 +454,7 @@ static inline void copySection0AndInjectSystemModules(void)
}
}
static inline void launchFirm(FirmwareType firmType, u32 isFirmlaunch)
static inline void launchFirm(FirmwareType firmType, bool isFirmlaunch)
{
//If we're booting NATIVE_FIRM, section0 needs to be copied separately to inject 3ds_injector
u32 sectionNum;

View File

@ -42,9 +42,9 @@ typedef enum A9LHMode
A9LH_WITH_SFIRM_FIRMPROT = 2
} A9LHMode;
static inline void loadFirm(FirmwareType firmType, u32 externalFirm);
static inline void loadFirm(FirmwareType firmType, bool externalFirm);
static inline void patchNativeFirm(FirmwareSource nandType, u32 emuHeader, A9LHMode a9lhMode);
static inline void patchLegacyFirm(FirmwareType firmType);
static inline void patchSafeFirm(void);
static inline void copySection0AndInjectSystemModules(void);
static inline void launchFirm(FirmwareType firmType, u32 isFirmlaunch);
static inline void launchFirm(FirmwareType firmType, bool isFirmlaunch);

View File

@ -13,12 +13,12 @@
static FATFS sdFs,
nandFs;
u32 mountFs(void)
bool mountFs(void)
{
if(f_mount(&sdFs, "0:", 1) != FR_OK) return 0;
if(f_mount(&sdFs, "0:", 1) != FR_OK) return false;
f_mount(&nandFs, "1:", 0);
return 1;
return true;
}
u32 fileRead(void *dest, const char *path)

View File

@ -8,7 +8,7 @@
#define PATTERN(a) a "_*.bin"
u32 mountFs(void);
bool mountFs(void);
u32 getFileSize(const char *path);
u32 fileRead(void *dest, const char *path);
void fileWrite(const void *buffer, const char *path, u32 size);

View File

@ -225,7 +225,7 @@ void patchTitleInstallMinVersionCheck(u8 *pos, u32 size)
if(off != NULL) off[4] = 0xE0;
}
void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType, u32 isN3DS)
void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType, bool isN3DS)
{
const patchData twlPatches[] = {
{{0x1650C0, 0x165D64}, {{ 6, 0x00, 0x20, 0x4E, 0xB0, 0x70, 0xBD }}, 0},
@ -255,12 +255,12 @@ void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType, u32 isN3DS)
switch(patches[i].type)
{
case 0:
memcpy(pos + patches[i].offset[isN3DS], patches[i].patch.type0 + 1, patches[i].patch.type0[0]);
memcpy(pos + patches[i].offset[isN3DS ? 1 : 0], patches[i].patch.type0 + 1, patches[i].patch.type0[0]);
break;
case 2:
*(u16 *)(pos + patches[i].offset[isN3DS] + 2) = 0;
*(u16 *)(pos + patches[i].offset[isN3DS ? 1 : 0] + 2) = 0;
case 1:
*(u16 *)(pos + patches[i].offset[isN3DS]) = patches[i].patch.type1;
*(u16 *)(pos + patches[i].offset[isN3DS ? 1 : 0]) = patches[i].patch.type1;
break;
}
}

View File

@ -28,5 +28,5 @@ void patchSvcBreak11(u8 *pos, u32 size);
void patchUnitInfoValueSet(u8 *pos, u32 size);
void patchKernelFCRAMAndVRAMMappingPermissions(u8 *pos, u32 size);
void reimplementSvcBackdoor(u8 *pos, u32 size);
void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType, u32 isN3DS);
void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType, bool isN3DS);
u8 *getUnitInfoValueSet(u8 *pos, u32 size);

View File

@ -29,13 +29,13 @@ void __attribute__((naked)) arm11Stub(void)
static inline void invokeArm11Function(void (*func)())
{
static u32 hasCopiedStub = 0;
static bool hasCopiedStub = false;
if(!hasCopiedStub)
{
memcpy((void *)ARM11_STUB_ADDRESS, arm11Stub, 0x40);
flushDCacheRange((void *)ARM11_STUB_ADDRESS, 0x40);
hasCopiedStub = 1;
hasCopiedStub = true;
}
*arm11Entry = (u32)func;
@ -122,9 +122,9 @@ void clearScreens(void)
invokeArm11Function(ARM11);
}
u32 initScreens(void)
bool initScreens(void)
{
u32 needToInit = PDN_GPU_CNT == 1;
bool needToInit = PDN_GPU_CNT == 1;
void __attribute__((naked)) ARM11(void)
{

View File

@ -22,4 +22,4 @@ struct fb {
void deinitScreens(void);
void updateBrightness(u32 brightnessIndex);
void clearScreens(void);
u32 initScreens(void);
bool initScreens(void);

View File

@ -6,6 +6,7 @@
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
//Common data types
typedef uint8_t u8;