From 0057ab9c5a1dcb039f0b94a4cbe8a7d2f589277f Mon Sep 17 00:00:00 2001 From: Aurora Date: Wed, 31 Aug 2016 16:11:44 +0200 Subject: [PATCH] Fix config not being written in a rare circumstance --- source/config.c | 15 +++++++++------ source/config.h | 9 ++++++++- source/firm.c | 2 +- source/firm.h | 7 ------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/source/config.c b/source/config.c index 7518ae4..2056bf4 100644 --- a/source/config.c +++ b/source/config.c @@ -43,19 +43,22 @@ bool readConfig(const char *configPath) return true; } -void writeConfig(const char *configPath, u32 configTemp) +void writeConfig(const char *configPath, u32 configTemp, ConfigurationStatus needConfig) { /* If the configuration is different from previously, overwrite it. Just the no-forcing flag being set is not enough */ - if((configTemp & 0xFFFFFFEF) != configData.config) + if(needConfig == CREATE_CONFIGURATION || (configTemp & 0xFFFFFFEF) != configData.config) { + if(needConfig == CREATE_CONFIGURATION) + { + memcpy(configData.magic, "CONF", 4); + configData.formatVersionMajor = CONFIG_VERSIONMAJOR; + configData.formatVersionMinor = CONFIG_VERSIONMINOR; + } + //Merge the new options and new boot configuration configData.config = (configData.config & 0xFFFFFFC0) | (configTemp & 0x3F); - memcpy(configData.magic, "CONF", 4); - configData.formatVersionMajor = CONFIG_VERSIONMAJOR; - configData.formatVersionMinor = CONFIG_VERSIONMINOR; - if(!fileWrite(&configData, configPath, sizeof(cfgData))) error("Error writing the configuration file"); } diff --git a/source/config.h b/source/config.h index 96f558e..f3e2bb2 100644 --- a/source/config.h +++ b/source/config.h @@ -39,8 +39,15 @@ typedef struct __attribute__((packed)) u32 config; } cfgData; +typedef enum ConfigurationStatus +{ + DONT_CONFIGURE = 0, + MODIFY_CONFIGURATION = 1, + CREATE_CONFIGURATION = 2 +} ConfigurationStatus; + extern cfgData configData; bool readConfig(const char *configPath); -void writeConfig(const char *configPath, u32 configTemp); +void writeConfig(const char *configPath, u32 configTemp, ConfigurationStatus needConfig); void configMenu(bool oldPinStatus); \ No newline at end of file diff --git a/source/firm.c b/source/firm.c index 53fc7db..2e73595 100755 --- a/source/firm.c +++ b/source/firm.c @@ -208,7 +208,7 @@ void main(void) if(!isFirmlaunch) { configTemp |= (u32)nandType | ((u32)firmSource << 2); - writeConfig(configPath, configTemp); + writeConfig(configPath, configTemp, needConfig); } u32 firmVersion = loadFirm(&firmType, firmSource); diff --git a/source/firm.h b/source/firm.h index 5053910..6f3f2f4 100644 --- a/source/firm.h +++ b/source/firm.h @@ -46,13 +46,6 @@ typedef struct firmHeader { u8 reserved2[0x30]; firmSectionHeader section[4]; } firmHeader; - -typedef enum ConfigurationStatus -{ - DONT_CONFIGURE = 0, - MODIFY_CONFIGURATION = 1, - CREATE_CONFIGURATION = 2 -} ConfigurationStatus; static inline u32 loadFirm(FirmwareType *firmType, FirmwareSource firmSource); static inline void patchNativeFirm(u32 firmVersion, FirmwareSource nandType, u32 emuHeader, bool isA9lh);