[OTA] Stage exact uploaded size for ESP8266 web OTA (gzip fix) (#14741)

This commit is contained in:
Brian Kaufman
2026-03-12 16:23:29 -07:00
committed by Jesse Hills
parent 14c3e2d9d9
commit 390bb0451f
2 changed files with 6 additions and 2 deletions

View File

@@ -105,6 +105,7 @@ OTAResponseTypes ESP8266OTABackend::begin(size_t image_size) {
this->current_address_ = this->start_address_;
this->image_size_ = image_size;
this->bytes_received_ = 0;
this->buffer_len_ = 0;
this->md5_set_ = false;
@@ -140,6 +141,7 @@ OTAResponseTypes ESP8266OTABackend::write(uint8_t *data, size_t len) {
size_t to_buffer = std::min(len - written, this->buffer_size_ - this->buffer_len_);
memcpy(this->buffer_.get() + this->buffer_len_, data + written, to_buffer);
this->buffer_len_ += to_buffer;
this->bytes_received_ += to_buffer;
written += to_buffer;
// If buffer is full, write to flash
@@ -252,8 +254,8 @@ OTAResponseTypes ESP8266OTABackend::end() {
}
}
// Calculate actual bytes written
size_t actual_size = this->current_address_ - this->start_address_;
// Calculate actual bytes written (exact uploaded size, excluding flash write padding)
size_t actual_size = this->bytes_received_;
// Check if any data was written
if (actual_size == 0) {
@@ -304,6 +306,7 @@ void ESP8266OTABackend::abort() {
this->buffer_.reset();
this->buffer_len_ = 0;
this->image_size_ = 0;
this->bytes_received_ = 0;
esp8266::preferences_prevent_write(false);
}

View File

@@ -48,6 +48,7 @@ class ESP8266OTABackend final {
uint32_t start_address_{0};
uint32_t current_address_{0};
size_t image_size_{0};
size_t bytes_received_{0};
md5::MD5Digest md5_{};
uint8_t expected_md5_[16]; // Fixed-size buffer for 128-bit (16-byte) MD5 digest