ESPHome 2026.5.0-dev
Loading...
Searching...
No Matches
ota_backend_arduino_rp2040.cpp
Go to the documentation of this file.
1#ifdef USE_ARDUINO
2#ifdef USE_RP2040
4#include "ota_backend.h"
5
8#include "esphome/core/log.h"
9
10#include <Updater.h>
11
12namespace esphome::ota {
13
14static const char *const TAG = "ota.arduino_rp2040";
15
16std::unique_ptr<ArduinoRP2040OTABackend> make_ota_backend() { return make_unique<ArduinoRP2040OTABackend>(); }
17
19 // OTA size of 0 is not currently handled, but
20 // web_server is not supported for RP2040, so this is not an issue.
21 bool ret = Update.begin(image_size, U_FLASH);
22 if (ret) {
24 return OTA_RESPONSE_OK;
25 }
26
27 uint8_t error = Update.getError();
28 if (error == UPDATE_ERROR_BOOTSTRAP)
30 if (error == UPDATE_ERROR_NEW_FLASH_CONFIG)
32 if (error == UPDATE_ERROR_FLASH_CONFIG)
34 if (error == UPDATE_ERROR_SPACE)
36
37 ESP_LOGE(TAG, "Begin error: %d", error);
38
40}
41
43 Update.setMD5(md5);
44 this->md5_set_ = true;
45}
46
48 size_t written = Update.write(data, len);
49 if (written == len) {
50 return OTA_RESPONSE_OK;
51 }
52
53 uint8_t error = Update.getError();
54 ESP_LOGE(TAG, "Write error: %d", error);
55
57}
58
60 // Use strict validation (false) when MD5 is set, lenient validation (true) when no MD5
61 // This matches the behavior of the old web_server OTA implementation
62 if (Update.end(!this->md5_set_)) {
63 return OTA_RESPONSE_OK;
64 }
65
66 uint8_t error = Update.getError();
67 ESP_LOGE(TAG, "End error: %d", error);
68
70}
71
76
77} // namespace esphome::ota
78#endif // USE_RP2040
79#endif // USE_ARDUINO
OTAResponseTypes write(uint8_t *data, size_t len)
OTAResponseTypes begin(size_t image_size)
@ OTA_RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG
Definition ota_backend.h:34
@ OTA_RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG
Definition ota_backend.h:33
@ OTA_RESPONSE_ERROR_WRITING_FLASH
Definition ota_backend.h:30
@ OTA_RESPONSE_ERROR_UPDATE_END
Definition ota_backend.h:31
@ OTA_RESPONSE_ERROR_RP2040_NOT_ENOUGH_SPACE
Definition ota_backend.h:39
@ OTA_RESPONSE_ERROR_UNKNOWN
Definition ota_backend.h:41
@ OTA_RESPONSE_ERROR_INVALID_BOOTSTRAPPING
Definition ota_backend.h:32
std::unique_ptr< ArduinoLibreTinyOTABackend > make_ota_backend()
void preferences_prevent_write(bool prevent)
std::string size_t len
Definition helpers.h:1045
int written
Definition helpers.h:1089