ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
ota_backend_arduino_libretiny.cpp
Go to the documentation of this file.
1#ifdef USE_LIBRETINY
3#include "ota_backend.h"
4
6#include "esphome/core/log.h"
7
8#include <Update.h>
9
10namespace esphome::ota {
11
12static const char *const TAG = "ota.arduino_libretiny";
13
14std::unique_ptr<ArduinoLibreTinyOTABackend> make_ota_backend() { return make_unique<ArduinoLibreTinyOTABackend>(); }
15
17 if (ota_type != OTA_TYPE_UPDATE_APP) {
19 }
20 // Handle UPDATE_SIZE_UNKNOWN (0) which is used by web server OTA
21 // where the exact firmware size is unknown due to multipart encoding
22 if (image_size == 0) {
23 image_size = UPDATE_SIZE_UNKNOWN;
24 }
25 bool ret = Update.begin(image_size, U_FLASH);
26 if (ret) {
27 return OTA_RESPONSE_OK;
28 }
29
30 uint8_t error = Update.getError();
31 if (error == UPDATE_ERROR_SIZE)
33
34 ESP_LOGE(TAG, "Begin error: %d", error);
35
37}
38
40 Update.setMD5(md5);
41 this->md5_set_ = true;
42}
43
45 size_t written = Update.write(data, len);
46 if (written == len) {
47 return OTA_RESPONSE_OK;
48 }
49
50 uint8_t error = Update.getError();
51 ESP_LOGE(TAG, "Write error: %d", error);
52
54}
55
57 // Use strict validation (false) when MD5 is set, lenient validation (true) when no MD5
58 // This matches the behavior of the old web_server OTA implementation
59 if (Update.end(!this->md5_set_)) {
60 return OTA_RESPONSE_OK;
61 }
62
63 uint8_t error = Update.getError();
64 ESP_LOGE(TAG, "End error: %d", error);
65
67}
68
69void ArduinoLibreTinyOTABackend::abort() { Update.abort(); }
70
71} // namespace esphome::ota
72#endif // USE_LIBRETINY
OTAResponseTypes begin(size_t image_size, OTAType ota_type=OTA_TYPE_UPDATE_APP)
OTAResponseTypes write(uint8_t *data, size_t len)
@ OTA_RESPONSE_ERROR_ESP32_NOT_ENOUGH_SPACE
Definition ota_backend.h:39
@ OTA_RESPONSE_ERROR_WRITING_FLASH
Definition ota_backend.h:33
@ OTA_RESPONSE_ERROR_UNSUPPORTED_OTA_TYPE
Definition ota_backend.h:44
@ OTA_RESPONSE_ERROR_UPDATE_END
Definition ota_backend.h:34
@ OTA_RESPONSE_ERROR_UNKNOWN
Definition ota_backend.h:49
std::unique_ptr< ArduinoLibreTinyOTABackend > make_ota_backend()
const void size_t len
Definition hal.h:64
int written
Definition helpers.h:1045