Fix configuration restore regression from 5.13.1

5.13.1a
 * Fix configuration restore regression from 5.13.1
This commit is contained in:
Theo Arends 2018-05-06 18:35:31 +02:00
parent 0c0f2236bd
commit b9acfe000c
2 changed files with 33 additions and 16 deletions

View File

@ -1,5 +1,6 @@
/* 5.13.1a
* Change user_config.h otaurl to http://sonoff.maddox.co.uk/tasmota/sonoff.bin (#2588, #2602)
* Fix configuration restore regression from 5.13.1
* Fix compile error when ADC is enabled and Rules are disabled (#2608)
* Fix rule power trigger when no backlog command is used (#2613)
* Fix several timer data input and output errors (#2597, #2620)

View File

@ -330,6 +330,8 @@ uint8_t upload_file_type;
uint8_t upload_progress_dot_count;
uint8_t config_block_count = 0;
uint8_t config_xor_on = 0;
uint8_t config_xor_on_set = CONFIG_FILE_XOR;
uint8_t *settings_new = NULL;
// Helper function to avoid code duplication (saves 4k Flash)
static void WebGetArg(const char* arg, char* out, size_t max)
@ -977,10 +979,10 @@ void HandleBackupConfiguration()
WebServer->send(200, FPSTR(HDR_CTYPE_STREAM), "");
memcpy(buffer, &Settings, sizeof(buffer));
buffer[0] = CONFIG_FILE_SIGN;
buffer[1] = (!CONFIG_FILE_XOR)?0:1;
buffer[1] = (!config_xor_on_set) ? 0 : 1;
if (buffer[1]) {
for (uint16_t i = 2; i < sizeof(buffer); i++) {
buffer[i] ^= (CONFIG_FILE_XOR +i);
buffer[i] ^= (config_xor_on_set +i);
}
}
myClient.write((const char*)buffer, sizeof(buffer));
@ -1236,6 +1238,14 @@ void HandleUpgradeFirmwareStart()
ExecuteCommand(svalue);
}
void SettingsNewFree()
{
if (settings_new != NULL) {
free(settings_new);
settings_new = NULL;
}
}
void HandleUploadDone()
{
if (HttpUser()) { return; }
@ -1275,6 +1285,7 @@ void HandleUploadDone()
page += FPSTR(HTTP_MSG_RSTRT);
restart_flag = 2;
}
SettingsNewFree();
page += F("</div><br/>");
page += FPSTR(HTTP_BTN_MAIN);
ShowPage(page);
@ -1302,7 +1313,13 @@ void HandleUploadLoop()
SettingsSave(1); // Free flash for upload
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPLOAD D_FILE " %s ..."), upload.filename.c_str());
AddLog(LOG_LEVEL_INFO);
if (!upload_file_type) {
if (upload_file_type) {
SettingsNewFree();
if (!(settings_new = (uint8_t *)malloc(sizeof(Settings)))) {
upload_error = 2;
return;
}
} else {
MqttRetryCounter(60);
#ifdef USE_EMULATION
UdpDisconnect();
@ -1347,18 +1364,7 @@ void HandleUploadLoop()
upload_error = 9;
return;
}
if (config_xor_on) {
for (uint16_t i = 2; i < upload.currentSize; i++) {
upload.buf[i] ^= (CONFIG_FILE_XOR +i);
}
}
if (0 == config_block_count) {
SettingsDefaultSet2();
memcpy((char*)&Settings +16, upload.buf +16, upload.currentSize -16);
memcpy((char*)&Settings +8, upload.buf +8, 4); // Restore version and auto upgrade
} else {
memcpy((char*)&Settings +(config_block_count * HTTP_UPLOAD_BUFLEN), upload.buf, upload.currentSize);
}
memcpy(settings_new + (config_block_count * HTTP_UPLOAD_BUFLEN), upload.buf, upload.currentSize);
config_block_count++;
}
} else { // firmware
@ -1376,7 +1382,17 @@ void HandleUploadLoop()
if (_serialoutput && (upload_progress_dot_count % 80)) {
Serial.println();
}
if (!upload_file_type) {
if (upload_file_type) {
if (config_xor_on) {
for (uint16_t i = 2; i < sizeof(Settings); i++) {
settings_new[i] ^= (config_xor_on_set +i);
}
}
SettingsDefaultSet2();
memcpy((char*)&Settings +16, settings_new +16, sizeof(Settings) -16);
memcpy((char*)&Settings +8, settings_new +8, 4); // Restore version and auto upgrade
SettingsNewFree();
} else {
if (!Update.end(true)) { // true to set the size to the current progress
if (_serialoutput) { Update.printError(Serial); }
upload_error = 6;