Fixed config bug, minor stuff

This commit is contained in:
Aurora Wright
2017-04-13 03:38:36 +02:00
parent c95808fa2d
commit 7f33309903
10 changed files with 52 additions and 75 deletions

View File

@@ -30,9 +30,13 @@
#include "pin.h"
CfgData configData;
ConfigurationStatus needConfig;
static CfgData oldConfig;
bool readConfig(void)
{
bool ret;
if(fileRead(&configData, CONFIG_FILE, sizeof(CfgData)) != sizeof(CfgData) ||
memcmp(configData.magic, "CONF", 4) != 0 ||
configData.formatVersionMajor != CONFIG_VERSIONMAJOR ||
@@ -40,17 +44,23 @@ bool readConfig(void)
{
configData.config = 0;
return false;
ret = false;
}
else ret = true;
return true;
oldConfig = configData;
return ret;
}
void writeConfig(ConfigurationStatus needConfig, u32 configTemp)
void writeConfig(bool isPayloadLaunch)
{
/* If the configuration is different from previously, overwrite it.
Just the no-forcing flag being set is not enough */
if(needConfig != CREATE_CONFIGURATION && (configTemp & 0xFFFFFF7F) == configData.config) return;
if(isPayloadLaunch) configData.config = (configData.config & 0xFFFFFF00) | (oldConfig.config & 0xFF);
if(needConfig != CREATE_CONFIGURATION && (configData.config & 0xFFFFFF7F) == oldConfig.config) return;
if(needConfig == CREATE_CONFIGURATION)
{
@@ -59,9 +69,6 @@ void writeConfig(ConfigurationStatus needConfig, u32 configTemp)
configData.formatVersionMinor = CONFIG_VERSIONMINOR;
}
//Merge the new options and new boot configuration
configData.config = (configData.config & 0xFFFFFF00) | (configTemp & 0xFF);
if(!fileWrite(&configData, CONFIG_FILE, sizeof(CfgData)))
error("Error writing the configuration file");
}

View File

@@ -68,5 +68,5 @@ typedef enum ConfigurationStatus
} ConfigurationStatus;
bool readConfig(void);
void writeConfig(ConfigurationStatus needConfig, u32 configTemp);
void writeConfig(bool isPayloadLaunch);
void configMenu(bool isSdMode, bool oldPinStatus, u32 oldPinMode);

View File

@@ -85,8 +85,6 @@ u32 installArm11Handlers(u32 *exceptionsPage, u32 stackAddress, u32 codeSetOffse
va_src = dAbtHandlerMemAddress + ((u8 *)pos - (u8 *)dAbtHandler);
*pos = MAKE_BRANCH((u8 *)va_src, (u8 *)va_dst);
break;
default:
break;
}
}

View File

@@ -175,9 +175,8 @@ u32 patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, boo
ret += reimplementSvcBackdoor(arm11Section1, arm11SvcTable, baseK11VA, &freeK11Space);
}
//11.3 FIRM patches
if(firmVersion >= (ISN3DS ? 0x2D : 0x5C)) //Stub svc 0x59
ret += stubSvcRestrictGpuDma(arm11Section1, arm11SvcTable, baseK11VA);
//Stub svc 0x59 on 11.3+ FIRMs
if(firmVersion >= (ISN3DS ? 0x2D : 0x5C)) ret += stubSvcRestrictGpuDma(arm11Section1, arm11SvcTable, baseK11VA);
ret += implementSvcGetCFWInfo(arm11Section1, arm11SvcTable, baseK11VA, &freeK11Space, isSafeMode);

View File

@@ -28,6 +28,7 @@
#include "screen.h"
#include "draw.h"
#include "utils.h"
#include "config.h"
#include "fatfs/ff.h"
#include "buttons.h"
#include "../build/bundled.h"
@@ -158,6 +159,8 @@ void loadPayload(u32 pressed, const char *payloadPath)
if(!payloadSize) return;
writeConfig(true);
memcpy(loaderAddress, loader_bin, loader_bin_size);
loaderAddress[1] = payloadSize;

View File

@@ -33,17 +33,16 @@
#include "crypto.h"
extern CfgData configData;
extern ConfigurationStatus needConfig;
extern FirmwareSource firmSource;
void main(void)
{
bool isA9lhInstalled,
isSafeMode = false;
u32 configTemp,
emuHeader;
u32 emuHeader;
FirmwareType firmType;
FirmwareSource nandType;
ConfigurationStatus needConfig;
//Mount SD or CTRNAND
bool isSdMode;
@@ -95,8 +94,8 @@ void main(void)
//Get pressed buttons
u32 pressed = HID_PAD;
//Save old options and begin saving the new boot configuration
configTemp = (configData.config & 0xFFFFFF00) | ((u32)ISA9LH << 6);
//Begin saving the new boot configuration
configData.config = (configData.config & 0xFFFFFF00) | ((u32)ISA9LH << 6);
//If it's a MCU reboot, try to force boot options
if(ISA9LH && CFG_BOOTENV && needConfig != CREATE_CONFIGURATION)
@@ -109,7 +108,7 @@ void main(void)
firmSource = (BOOTCFG_NAND != 0) == (BOOTCFG_FIRM != 0) ? FIRMWARE_SYSNAND : (FirmwareSource)BOOTCFG_FIRM;
//Flag to prevent multiple boot options-forcing
configTemp |= 1 << 7;
configData.config |= 1 << 7;
goto boot;
}
@@ -234,8 +233,8 @@ boot:
if(!ISFIRMLAUNCH)
{
configTemp |= (u32)nandType | ((u32)firmSource << 3);
writeConfig(needConfig, configTemp);
configData.config |= (u32)nandType | ((u32)firmSource << 3);
writeConfig(false);
}
if(isSdMode && !mountFs(false, false)) error("Failed to mount CTRNAND.");

View File

@@ -121,19 +121,15 @@ u32 patchSignatureChecks(u8 *pos, u32 size)
u32 patchOldSignatureChecks(u8 *pos, u32 size)
{
// Look for signature checks
// Pattern 2 works for 1.x, 2.x + factory FIRM.
// For patchSignatureChecks-style (temp - 1 instead of temp - 3):
// 1.x+2.x: pattern2[] = {0xB5, 0x23, 0x4E, 0x0C};
// factory: pattern2[] = {0xB5, 0x16, 0x4E, 0x0C};
const u8 pattern[] = {0xC0, 0x1C, 0xBD, 0xE7},
pattern2[] = {0x4E, 0x0C, 0x00, 0x71, 0x68};
pattern2[] = {0xB5, 0x23, 0x4E, 0x0C};
u16 *off = (u16 *)memsearch(pos, pattern, size, sizeof(pattern));
u8 *temp = memsearch(pos, pattern2, size, sizeof(pattern2));
if(off == NULL || temp == NULL) return 1;
u16 *off2 = (u16 *)(temp - 3);
u16 *off2 = (u16 *)(temp - 1);
*off = off2[0] = 0x2000;
off2[1] = 0x4770;