ESPHome 2026.10.2
Loading...
Searching...
No Matches
ota_backend_arduino_rp2.cpp
Go to the documentation of this file.
1#ifdef USE_ARDUINO
2#ifdef USE_RP2
4#include "ota_backend.h"
5
8#include "esphome/core/log.h"
9
10#include <Updater.h>
11
12// LittleFS region bounds, provided by the arduino-pico linker script.
13// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
14extern "C" uint8_t _FS_start;
15// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
16extern "C" uint8_t _FS_end;
17
18namespace esphome::ota {
19
20static const char *const TAG = "ota";
21
22std::unique_ptr<ArduinoRP2OTABackend> make_ota_backend() { return make_unique<ArduinoRP2OTABackend>(); }
23
25 if (ota_type != OTA_TYPE_UPDATE_APP) {
27 }
28 // 0 means the size is unknown (web_server upload). The updater only checks the size
29 // against the LittleFS region it stages the image in, so ask for all of it.
30 if (image_size == 0) {
31 image_size = reinterpret_cast<uintptr_t>(&_FS_end) - reinterpret_cast<uintptr_t>(&_FS_start);
32 }
33 bool ret = Update.begin(image_size, U_FLASH);
34 if (ret) {
36 return OTA_RESPONSE_OK;
37 }
38
39 uint8_t error = Update.getError();
40 if (error == UPDATE_ERROR_BOOTSTRAP)
42 if (error == UPDATE_ERROR_NEW_FLASH_CONFIG)
44 if (error == UPDATE_ERROR_FLASH_CONFIG)
46 if (error == UPDATE_ERROR_SPACE || error == UPDATE_ERROR_SIZE)
48
49 ESP_LOGE(TAG, "Begin error: %d", error);
50
52}
53
55 Update.setMD5(md5);
56 this->md5_set_ = true;
57}
58
60 size_t written = Update.write(data, len);
61 if (written == len) {
62 return OTA_RESPONSE_OK;
63 }
64
65 uint8_t error = Update.getError();
66 ESP_LOGE(TAG, "Write error: %d", error);
67
69}
70
72 // Use strict validation (false) when MD5 is set, lenient validation (true) when no MD5
73 // This matches the behavior of the old web_server OTA implementation
74 if (Update.end(!this->md5_set_)) {
75 return OTA_RESPONSE_OK;
76 }
77
78 uint8_t error = Update.getError();
79 ESP_LOGE(TAG, "End error: %d", error);
80
82}
83
85 Update.end();
87}
88
89} // namespace esphome::ota
90#endif // USE_RP2
91#endif // USE_ARDUINO
OTAResponseTypes begin(size_t image_size, OTAType ota_type=OTA_TYPE_UPDATE_APP)
OTAResponseTypes write(uint8_t *data, size_t len)
int ret
@ OTA_RESPONSE_ERROR_WRONG_NEW_FLASH_CONFIG
Definition ota_backend.h:40
@ OTA_RESPONSE_ERROR_WRONG_CURRENT_FLASH_CONFIG
Definition ota_backend.h:39
@ OTA_RESPONSE_ERROR_WRITING_FLASH
Definition ota_backend.h:36
@ OTA_RESPONSE_ERROR_UNSUPPORTED_OTA_TYPE
Definition ota_backend.h:47
@ OTA_RESPONSE_ERROR_UPDATE_END
Definition ota_backend.h:37
@ OTA_RESPONSE_ERROR_RP2040_NOT_ENOUGH_SPACE
Definition ota_backend.h:45
@ OTA_RESPONSE_ERROR_UNKNOWN
Definition ota_backend.h:54
@ OTA_RESPONSE_ERROR_INVALID_BOOTSTRAPPING
Definition ota_backend.h:38
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:1193
uint8_t _FS_end
uint8_t _FS_start