From 7b10bec8fe63bcfa464bd221c5eeb4fae0d03a98 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Thu, 14 Nov 2019 15:57:52 +0100 Subject: [PATCH] Refactor SDK erase Add device hardware type to status 2 --- tasmota/settings.ino | 35 ++++++++++++++--------------------- tasmota/support.ino | 14 ++++++++++++++ tasmota/support_command.ino | 5 +++-- tasmota/support_wifi.ino | 3 --- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 205cc92c0..3c664bd34 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -536,17 +536,24 @@ void SettingsLoad(void) void SettingsErase(uint8_t type) { /* - 0 = Erase from program end until end of physical flash - 1 = Erase SDK parameter area at end of linker memory model (0x0FDxxx - 0x0FFFFF) solving possible wifi errors - 2 = Erase Tasmota settings + Erase only works from flash start address to SDK recognized flash end address (flashchip->chip_size = ESP.getFlashChipSize). + Addresses above SDK recognized size (up to ESP.getFlashChipRealSize) are not accessable. + The only way to erase whole flash is esptool which uses direct SPI writes to flash. + + 0 = Erase from program end until end of flash as seen by SDK + 1 = Erase 16k SDK parameter area near end of flash as seen by SDK (0x0xFCxxx - 0x0xFFFFF) solving possible wifi errors + 2 = Erase Tasmota settings (0x0xF4xxx - 0x0xFBFFF) */ #ifndef FIRMWARE_MINIMAL +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SDK: Flash size 0x%08X"), flashchip->chip_size); + uint32_t _sectorStart = (ESP.getSketchSize() / SPI_FLASH_SEC_SIZE) + 1; - uint32_t _sectorEnd = ESP.getFlashChipRealSize() / SPI_FLASH_SEC_SIZE; +// uint32_t _sectorEnd = ESP.getFlashChipRealSize() / SPI_FLASH_SEC_SIZE; + uint32_t _sectorEnd = ESP.getFlashChipSize() / SPI_FLASH_SEC_SIZE; if (1 == type) { - _sectorStart = SETTINGS_LOCATION +2; // SDK parameter area above EEPROM area (0x0FDxxx - 0x0FFFFF) - _sectorEnd = SETTINGS_LOCATION +5; + // source Esp.cpp and core_esp8266_phy.cpp + _sectorStart = (ESP.getFlashChipSize() / SPI_FLASH_SEC_SIZE) - 4; } else if (2 == type) { _sectorStart = SETTINGS_LOCATION - CFG_ROTATES; // Tasmota parameter area (0x0F4xxx - 0x0FBFFF) @@ -565,7 +572,7 @@ void SettingsErase(uint8_t type) if (result) { Serial.println(F(" " D_OK)); } else { - Serial.println(F(" " D_ERROR)); + Serial.println(F(" " D_ERROR)); // } delay(10); } @@ -574,24 +581,10 @@ void SettingsErase(uint8_t type) #endif // FIRMWARE_MINIMAL } -// Copied from 2.4.0 as 2.3.0 is incomplete -bool SettingsEraseConfig(void) { - const size_t cfgSize = 0x4000; - size_t cfgAddr = ESP.getFlashChipSize() - cfgSize; - - for (size_t offset = 0; offset < cfgSize; offset += SPI_FLASH_SEC_SIZE) { - if (!ESP.flashEraseSector((cfgAddr + offset) / SPI_FLASH_SEC_SIZE)) { - return false; - } - } - return true; -} - void SettingsSdkErase(void) { WiFi.disconnect(true); // Delete SDK wifi config SettingsErase(1); - SettingsEraseConfig(); delay(1000); } diff --git a/tasmota/support.ino b/tasmota/support.ino index 0a07edf07..77202427d 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -612,6 +612,20 @@ char* GetPowerDevice(char* dest, uint32_t idx, size_t size) return GetPowerDevice(dest, idx, size, 0); } +String GetDeviceHardware(void) +{ + // esptool.py get_efuses + uint32_t efuse1 = *(uint32_t*)(0x3FF00050); + uint32_t efuse2 = *(uint32_t*)(0x3FF00054); +// uint32_t efuse3 = *(uint32_t*)(0x3FF00058); +// uint32_t efuse4 = *(uint32_t*)(0x3FF0005C); + +// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("FUS: efuses 0x%08X 0x%08X, name %s"), efuse1, efuse2); + + bool is_8285 = ( (efuse1 & (1 << 4)) || (efuse2 & (1 << 16)) ); + return String((is_8285) ? F("ESP8285") : F("ESP8266EX")); +} + float ConvertTemp(float c) { float result = c; diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 877ff7547..939189938 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -369,9 +369,10 @@ void CmndStatus(void) if ((0 == payload) || (2 == payload)) { Response_P(PSTR("{\"" D_CMND_STATUS D_STATUS2_FIRMWARE "\":{\"" D_JSON_VERSION "\":\"%s%s\",\"" D_JSON_BUILDDATETIME "\":\"%s\",\"" - D_JSON_BOOTVERSION "\":%d,\"" D_JSON_COREVERSION "\":\"" ARDUINO_ESP8266_RELEASE "\",\"" D_JSON_SDKVERSION "\":\"%s\"}}"), + D_JSON_BOOTVERSION "\":%d,\"" D_JSON_COREVERSION "\":\"" ARDUINO_ESP8266_RELEASE "\",\"" D_JSON_SDKVERSION "\":\"%s\"," + "\"Hardware\":\"%s\"}}"), my_version, my_image, GetBuildDateAndTime().c_str(), - ESP.getBootVersion(), ESP.getSdkVersion()); + ESP.getBootVersion(), ESP.getSdkVersion(), GetDeviceHardware().c_str()); MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "2")); } diff --git a/tasmota/support_wifi.ino b/tasmota/support_wifi.ino index 162fbc2a9..f90d7cff1 100644 --- a/tasmota/support_wifi.ino +++ b/tasmota/support_wifi.ino @@ -618,6 +618,3 @@ void EspRestart(void) // ESP.restart(); // This results in exception 3 on restarts on core 2.3.0 ESP.reset(); } - - -