ESPHome 2025.9.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 {
13namespace ota {
14
15static const char *const TAG = "ota.arduino_rp2040";
16
17std::unique_ptr<ota::OTABackend> make_ota_backend() { return make_unique<ota::ArduinoRP2040OTABackend>(); }
18
20 // OTA size of 0 is not currently handled, but
21 // web_server is not supported for RP2040, so this is not an issue.
22 bool ret = Update.begin(image_size, U_FLASH);
23 if (ret) {
25 return OTA_RESPONSE_OK;
26 }
27
28 uint8_t error = Update.getError();
29 if (error == UPDATE_ERROR_BOOTSTRAP)
31 if (error == UPDATE_ERROR_NEW_FLASH_CONFIG)
33 if (error == UPDATE_ERROR_FLASH_CONFIG)
35 if (error == UPDATE_ERROR_SPACE)
37
38 ESP_LOGE(TAG, "Begin error: %d", error);
39
41}
42
44 Update.setMD5(md5);
45 this->md5_set_ = true;
46}
47
49 size_t written = Update.write(data, len);
50 if (written == len) {
51 return OTA_RESPONSE_OK;
52 }
53
54 uint8_t error = Update.getError();
55 ESP_LOGE(TAG, "Write error: %d", error);
56
58}
59
61 // Use strict validation (false) when MD5 is set, lenient validation (true) when no MD5
62 // This matches the behavior of the old web_server OTA implementation
63 if (Update.end(!this->md5_set_)) {
64 return OTA_RESPONSE_OK;
65 }
66
67 uint8_t error = Update.getError();
68 ESP_LOGE(TAG, "End error: %d", error);
69
71}
72
77
78} // namespace ota
79} // namespace esphome
80
81#endif // USE_RP2040
82#endif // USE_ARDUINO
OTAResponseTypes begin(size_t image_size) override
OTAResponseTypes write(uint8_t *data, size_t len) override
std::unique_ptr< ota::OTABackend > make_ota_backend()
@ 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:40
@ OTA_RESPONSE_ERROR_INVALID_BOOTSTRAPPING
Definition ota_backend.h:32
void preferences_prevent_write(bool prevent)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:279