ESPHome 2026.6.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 if (ota_type != OTA_TYPE_UPDATE_APP) {
21 }
22 // OTA size of 0 is not currently handled, but
23 // web_server is not supported for RP2040, so this is not an issue.
24 bool ret = Update.begin(image_size, U_FLASH);
25 if (ret) {
27 return OTA_RESPONSE_OK;
28 }
29
30 uint8_t error = Update.getError();
31 if (error == UPDATE_ERROR_BOOTSTRAP)
33 if (error == UPDATE_ERROR_NEW_FLASH_CONFIG)
35 if (error == UPDATE_ERROR_FLASH_CONFIG)
37 if (error == UPDATE_ERROR_SPACE)
39
40 ESP_LOGE(TAG, "Begin error: %d", error);
41
43}
44
46 Update.setMD5(md5);
47 this->md5_set_ = true;
48}
49
51 size_t written = Update.write(data, len);
52 if (written == len) {
53 return OTA_RESPONSE_OK;
54 }
55
56 uint8_t error = Update.getError();
57 ESP_LOGE(TAG, "Write error: %d", error);
58
60}
61
63 // Use strict validation (false) when MD5 is set, lenient validation (true) when no MD5
64 // This matches the behavior of the old web_server OTA implementation
65 if (Update.end(!this->md5_set_)) {
66 return OTA_RESPONSE_OK;
67 }
68
69 uint8_t error = Update.getError();
70 ESP_LOGE(TAG, "End error: %d", error);
71
73}
74
79
80} // namespace esphome::ota
81#endif // USE_RP2040
82#endif // USE_ARDUINO
OTAResponseTypes begin(size_t image_size, OTAType ota_type=OTA_TYPE_UPDATE_APP)
OTAResponseTypes write(uint8_t *data, size_t len)
@ OTA_RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG
Definition ota_backend.h:37
@ OTA_RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG
Definition ota_backend.h:36
@ 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_RP2040_NOT_ENOUGH_SPACE
Definition ota_backend.h:42
@ OTA_RESPONSE_ERROR_UNKNOWN
Definition ota_backend.h:49
@ OTA_RESPONSE_ERROR_INVALID_BOOTSTRAPPING
Definition ota_backend.h:35
std::unique_ptr< ArduinoLibreTinyOTABackend > make_ota_backend()
void preferences_prevent_write(bool prevent)
const void size_t len
Definition hal.h:64
int written
Definition helpers.h:1045