Use bool instead of u32 where it's relevant

This commit is contained in:
TuxSH 2016-07-02 14:44:01 +02:00
parent 730e716f0f
commit 96211813e3
15 changed files with 56 additions and 52 deletions

View File

@ -5,7 +5,7 @@
#ifndef PATH_MAX #ifndef PATH_MAX
#define PATH_MAX 255 #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 MULTICONFIG(a) ((loadConfig() >> (a * 2 + 6)) & 3)
#define BOOTCONFIG(a, b) ((loadConfig() >> a) & b) #define BOOTCONFIG(a, b) ((loadConfig() >> a) & b)
#endif #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); 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; IFile file;
if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ))) if(R_SUCCEEDED(fileOpen(&file, ARCHIVE_NAND_RW, "/sys/SecureInfo_C", FS_OPEN_READ)))
{ {
secureInfoExists = 1; exists = true;
IFile_Close(&file); IFile_Close(&file);
} }
} }
return secureInfoExists; return exists;
} }
static u32 loadConfig(void) 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 if(instr[3] == 0xEB) //We're looking for BL
{ {
u8 *calledFunction = instr; u8 *calledFunction = instr;
u32 i = 0, u32 i = 0;
found; bool found;
do do
{ {

View File

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

View File

@ -6,7 +6,7 @@
#include "types.h" #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 MULTICONFIG(a) ((config >> (a * 2 + 6)) & 3)
#define BOOTCONFIG(a, b) ((config >> a) & b) #define BOOTCONFIG(a, b) ((config >> a) & b)

View File

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

View File

@ -19,15 +19,15 @@ static inline int strlen(const char *string)
return stringEnd - string; return stringEnd - string;
} }
u32 loadSplash(void) bool loadSplash(void)
{ {
initScreens(); initScreens();
//Don't delay boot if no splash image is on the SD //Don't delay boot if no splash image is on the SD
if(fileRead(fb->top_left, "/luma/splash.bin") + if(fileRead(fb->top_left, "/luma/splash.bin") +
fileRead(fb->bottom, "/luma/splashbottom.bin")) fileRead(fb->bottom, "/luma/splashbottom.bin") != 0)
return 1; return true;
return 0; return false;
} }
void drawCharacter(char character, int posX, int posY, u32 color) void drawCharacter(char character, int posX, int posY, u32 color)

View File

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

View File

@ -20,16 +20,18 @@ static firmHeader *const firm = (firmHeader *)0x24000000;
static const firmSectionHeader *section; static const firmSectionHeader *section;
u32 config, u32 config,
isN3DS,
emuOffset; emuOffset;
bool isN3DS;
FirmwareSource firmSource; FirmwareSource firmSource;
void main(void) void main(void)
{ {
u32 isFirmlaunch, bool isFirmlaunch,
updatedSys, updatedSys;
newConfig,
u32 newConfig,
emuHeader, emuHeader,
nbChronoStarted = 0; nbChronoStarted = 0;
@ -54,7 +56,7 @@ void main(void)
{ {
if(needConfig == CREATE_CONFIGURATION) mcuReboot(); if(needConfig == CREATE_CONFIGURATION) mcuReboot();
isFirmlaunch = 1; isFirmlaunch = true;
//'0' = NATIVE_FIRM, '1' = TWL_FIRM, '2' = AGB_FIRM //'0' = NATIVE_FIRM, '1' = TWL_FIRM, '2' = AGB_FIRM
firmType = *(vu8 *)0x23F00009 == '3' ? SAFE_FIRM : (FirmwareType)(*(vu8 *)0x23F00005 - '0'); firmType = *(vu8 *)0x23F00009 == '3' ? SAFE_FIRM : (FirmwareType)(*(vu8 *)0x23F00005 - '0');
@ -85,11 +87,11 @@ void main(void)
pressed = HID_PAD; pressed = HID_PAD;
} }
isFirmlaunch = 0; isFirmlaunch = false;
firmType = NATIVE_FIRM; firmType = NATIVE_FIRM;
//Determine if booting with A9LH //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 //Determine if A9LH is installed and the user has an updated sysNAND
if(a9lhBoot || CONFIG(2)) if(a9lhBoot || CONFIG(2))
@ -100,7 +102,7 @@ void main(void)
else else
{ {
a9lhMode = NO_A9LH; a9lhMode = NO_A9LH;
updatedSys = 0; updatedSys = false;
} }
newConfig = (u32)a9lhMode << 3; newConfig = (u32)a9lhMode << 3;
@ -142,7 +144,7 @@ void main(void)
} }
//Boot options aren't being forced //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, /* If L and R/A/Select or one of the single payload buttons are pressed,
chainload an external payload */ chainload an external payload */
@ -227,11 +229,11 @@ void main(void)
launchFirm(firmType, isFirmlaunch); launchFirm(firmType, isFirmlaunch);
} }
static inline void loadFirm(FirmwareType firmType, u32 externalFirm) static inline void loadFirm(FirmwareType firmType, bool externalFirm)
{ {
section = firm->section; section = firm->section;
u32 externalFirmLoaded = externalFirm && bool externalFirmLoaded = externalFirm &&
fileRead(firm, "/luma/firmware.bin") && fileRead(firm, "/luma/firmware.bin") &&
(((u32)section[2].address >> 8) & 0xFF) == (isN3DS ? 0x60 : 0x68); (((u32)section[2].address >> 8) & 0xFF) == (isN3DS ? 0x60 : 0x68);
@ -244,7 +246,7 @@ static inline void loadFirm(FirmwareType firmType, u32 externalFirm)
{ "00000202", "20000202" }, { "00000202", "20000202" },
{ "00000003", "20000003" }}; { "00000003", "20000003" }};
firmRead(firm, firmFolders[(u32)firmType][isN3DS]); firmRead(firm, firmFolders[(u32)firmType][isN3DS ? 1 : 0]);
decryptExeFs((u8 *)firm); decryptExeFs((u8 *)firm);
} }
} }
@ -253,7 +255,7 @@ static inline void patchNativeFirm(FirmwareSource nandType, u32 emuHeader, A9LHM
{ {
u8 *arm9Section = (u8 *)firm + section[2].offset; u8 *arm9Section = (u8 *)firm + section[2].offset;
u32 is90Firm; bool is90Firm;
if(isN3DS) if(isN3DS)
{ {
@ -294,7 +296,7 @@ static inline void patchNativeFirm(FirmwareSource nandType, u32 emuHeader, A9LHM
patchSignatureChecks(process9Offset, process9Size); patchSignatureChecks(process9Offset, process9Size);
//Apply emuNAND patches //Apply emuNAND patches
if(nandType) if(nandType != FIRMWARE_SYSNAND)
{ {
u32 branchAdditive = (u32)firm + section[2].offset - (u32)section[2].address; u32 branchAdditive = (u32)firm + section[2].offset - (u32)section[2].address;
patchEmuNAND(arm9Section, section[2].size, process9Offset, process9Size, emuOffset, emuHeader, branchAdditive); patchEmuNAND(arm9Section, section[2].size, process9Offset, process9Size, emuOffset, emuHeader, branchAdditive);
@ -355,7 +357,7 @@ static inline void copySection0AndInjectLoader(void)
memcpy(section[0].address + loaderOffset + injector_size, arm11Section0 + loaderOffset + loaderSize, section[0].size - (loaderOffset + loaderSize)); memcpy(section[0].address + loaderOffset + injector_size, arm11Section0 + loaderOffset + loaderSize, section[0].size - (loaderOffset + loaderSize));
} }
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 //If we're booting NATIVE_FIRM, section0 needs to be copied separately to inject 3ds_injector
u32 sectionNum; u32 sectionNum;

View File

@ -42,9 +42,9 @@ typedef enum A9LHMode
A9LH_WITH_SFIRM_FIRMPROT = 2 A9LH_WITH_SFIRM_FIRMPROT = 2
} A9LHMode; } 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 patchNativeFirm(FirmwareSource nandType, u32 emuHeader, A9LHMode a9lhMode);
static inline void patchLegacyFirm(FirmwareType firmType); static inline void patchLegacyFirm(FirmwareType firmType);
static inline void patchSafeFirm(void); static inline void patchSafeFirm(void);
static inline void copySection0AndInjectLoader(void); static inline void copySection0AndInjectLoader(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, static FATFS sdFs,
nandFs; 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); f_mount(&nandFs, "1:", 0);
return 1; return true;
} }
u32 fileRead(void *dest, const char *path) u32 fileRead(void *dest, const char *path)

View File

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

View File

@ -121,7 +121,7 @@ void patchTitleInstallMinVersionCheck(u8 *pos, u32 size)
if(off != NULL) off[4] = 0xE0; 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[] = { const patchData twlPatches[] = {
{{0x1650C0, 0x165D64}, {{ 6, 0x00, 0x20, 0x4E, 0xB0, 0x70, 0xBD }}, 0}, {{0x1650C0, 0x165D64}, {{ 6, 0x00, 0x20, 0x4E, 0xB0, 0x70, 0xBD }}, 0},
@ -151,12 +151,12 @@ void applyLegacyFirmPatches(u8 *pos, FirmwareType firmType, u32 isN3DS)
switch(patches[i].type) switch(patches[i].type)
{ {
case 0: 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; break;
case 2: case 2:
*(u16 *)(pos + patches[i].offset[isN3DS] + 2) = 0; *(u16 *)(pos + patches[i].offset[isN3DS ? 1 : 0] + 2) = 0;
case 1: 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; break;
} }
} }

View File

@ -22,5 +22,5 @@ void patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr);
void patchFirmWrites(u8 *pos, u32 size); void patchFirmWrites(u8 *pos, u32 size);
void patchFirmWriteSafe(u8 *pos, u32 size); void patchFirmWriteSafe(u8 *pos, u32 size);
void reimplementSvcBackdoor(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);
u32 getLoader(u8 *pos, u32 *loaderSize); u32 getLoader(u8 *pos, u32 *loaderSize);

View File

@ -29,13 +29,13 @@ void __attribute__((naked)) arm11Stub(void)
static inline void invokeArm11Function(void (*func)()) static inline void invokeArm11Function(void (*func)())
{ {
static u32 hasCopiedStub = 0; static bool hasCopiedStub = false;
if(!hasCopiedStub) if(!hasCopiedStub)
{ {
memcpy((void *)ARM11_STUB_ADDRESS, arm11Stub, 0x40); memcpy((void *)ARM11_STUB_ADDRESS, arm11Stub, 0x40);
flushDCacheRange((void *)ARM11_STUB_ADDRESS, 0x40); flushDCacheRange((void *)ARM11_STUB_ADDRESS, 0x40);
hasCopiedStub = 1; hasCopiedStub = true;
} }
*arm11Entry = (u32)func; *arm11Entry = (u32)func;
@ -122,9 +122,9 @@ void clearScreens(void)
invokeArm11Function(ARM11); 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) void __attribute__((naked)) ARM11(void)
{ {

View File

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

View File

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