[OTA] Fix minimal OTA size computations (#2707)

Fixes: #2707

The computations did not take into account the needed extra space for 4k block alignment for OTA.
This commit is contained in:
Gijs Noorlander
2019-11-03 12:35:41 +01:00
parent de7668cc24
commit 78336b656b
7 changed files with 47 additions and 11 deletions
+3 -3
View File
@@ -74,12 +74,12 @@ for ENV in \
do
MAX_FILESIZE=1044464
if [[ ${ENV} == *"_1M"* ]]; then
# max 871 kiB
# max 872 kiB - 16 bytes
MAX_FILESIZE=892912
fi
if [[ ${ENV} == *"_1M_OTA"* ]]; then
# max 602 kiB
MAX_FILESIZE=616448
# max 600 kiB - 16 bytes
MAX_FILESIZE=614384
fi
if [[ ${ENV} == *"esp32"* ]]; then
MAX_FILESIZE=1310720
+1 -1
View File
@@ -161,7 +161,7 @@ extern NotificationStruct Notification[NPLUGIN_MAX];
#include <ESP8266mDNS.h>
#endif
#define SMALLEST_OTA_IMAGE 276848 // smallest known 2-step OTA image
#define MAX_SKETCH_SIZE 1044464
#define MAX_SKETCH_SIZE 1044464 // 1020 kB - 16 bytes
#define PIN_D_MAX 16
#endif
#if defined(ESP32)
+12 -5
View File
@@ -2676,13 +2676,20 @@ void play_rtttl(uint8_t _pin, const char *p )
bool OTA_possible(uint32_t& maxSketchSize, bool& use2step) {
#if defined(ESP8266)
maxSketchSize = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
const bool otaPossible = maxSketchSize > SMALLEST_OTA_IMAGE;
use2step = maxSketchSize < ESP.getSketchSize();
// Compute the current free space and sketch size, rounded to 4k blocks.
// These block bounaries are needed for erasing a full block on flash.
const uint32_t freeSketchSpace = (ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000;
const uint32_t currentSketchSize = (ESP.getSketchSize() + 0x1000) & 0xFFFFF000;
const uint32_t smallestOtaImageSizeNeeded = (((SMALLEST_OTA_IMAGE + 16) + 0x1000) & 0xFFFFF000);
const bool otaPossible = freeSketchSpace >= smallestOtaImageSizeNeeded;
use2step = freeSketchSpace < currentSketchSize; // Assume the new image has the same size.
if (use2step) {
const uint32_t totalSketchSpace = ESP.getFreeSketchSpace() + ESP.getSketchSize();
maxSketchSize = totalSketchSpace - SMALLEST_OTA_IMAGE;
const uint32_t totalSketchSpace = freeSketchSpace + currentSketchSize;
maxSketchSize = totalSketchSpace - smallestOtaImageSizeNeeded;
} else {
maxSketchSize = freeSketchSpace;
}
maxSketchSize -= 16; // Must leave 16 bytes at the end.
if (maxSketchSize > MAX_SKETCH_SIZE) maxSketchSize = MAX_SKETCH_SIZE;
return otaPossible;
#else
+6
View File
@@ -91,6 +91,9 @@ String getLabel(LabelType::Enum label) {
case LabelType::SKETCH_FREE: return F("Sketch Free");
case LabelType::SPIFFS_SIZE: return F("SPIFFS Size");
case LabelType::SPIFFS_FREE: return F("SPIFFS Free");
case LabelType::MAX_OTA_SKETCH_SIZE: return F("Max. OTA Sketch Size");
case LabelType::OTA_2STEP: return F("OTA 2-step Needed");
case LabelType::OTA_POSSIBLE: return F("OTA possible");
}
return F("MissingString");
@@ -189,6 +192,9 @@ String getValue(LabelType::Enum label) {
case LabelType::SKETCH_FREE: break;
case LabelType::SPIFFS_SIZE: break;
case LabelType::SPIFFS_FREE: break;
case LabelType::MAX_OTA_SKETCH_SIZE: break;
case LabelType::OTA_2STEP: break;
case LabelType::OTA_POSSIBLE: break;
}
return F("MissingString");
+3
View File
@@ -91,6 +91,9 @@ enum Enum : short {
SKETCH_FREE,
SPIFFS_SIZE,
SPIFFS_FREE,
MAX_OTA_SKETCH_SIZE,
OTA_2STEP,
OTA_POSSIBLE,
};
+19 -1
View File
@@ -529,6 +529,24 @@ void handle_sysinfo_Storage() {
TXBuffer += F(" kB free)");
# endif // if defined(ESP8266)
{
uint32_t maxSketchSize;
bool use2step;
bool otaEnabled = OTA_possible(maxSketchSize, use2step);
addRowLabel(getLabel(LabelType::MAX_OTA_SKETCH_SIZE));
TXBuffer += maxSketchSize / 1024;
TXBuffer += F(" kB (");
TXBuffer += maxSketchSize;
TXBuffer += F(" bytes)");
addRowLabel(getLabel(LabelType::OTA_POSSIBLE));
TXBuffer += boolToString(otaEnabled);
addRowLabel(getLabel(LabelType::OTA_2STEP));
TXBuffer += boolToString(use2step);
}
addRowLabel(getLabel(LabelType::SPIFFS_SIZE));
TXBuffer += SpiffsTotalBytes() / 1024;
TXBuffer += F(" kB (");
@@ -597,4 +615,4 @@ void handle_sysinfo_Storage() {
# endif // ifdef ESP32
}
#endif // ifdef WEBSERVER_SYSINFO
#endif // ifdef WEBSERVER_SYSINFO
+3 -1
View File
@@ -136,7 +136,9 @@ void handle_tools() {
}
TXBuffer += F(" Max sketch size: ");
TXBuffer += maxSketchSize / 1024;
TXBuffer += F(" kB");
TXBuffer += F(" kB (");
TXBuffer += maxSketchSize;
TXBuffer += F(" bytes)");
}
# endif // ifndef NO_HTTP_UPDATER
}