Backport changes

This commit is contained in:
Mat931
2026-05-01 10:29:41 +02:00
parent 3b6c5a5aa5
commit cb97c35d36
2 changed files with 15 additions and 22 deletions
+15 -20
View File
@@ -237,19 +237,17 @@ void ESPHomeOTAComponent::handle_handshake_() {
const bool supports_compression =
(this->ota_features_ & CLIENT_FEATURE_SUPPORTS_COMPRESSION) != 0 && this->backend_->supports_compression();
// Compose the feature-ack response. When USE_OTA_PARTITIONS is enabled and the client
// negotiates the extended protocol we emit a 2-byte response (marker + server feature flags);
// otherwise we emit the single-byte legacy response. The #ifdef wraps only the extended-proto
// branch so the legacy branch reads as unconditional code in either build configuration.
#ifdef USE_OTA_PARTITIONS
// Compose the feature-ack response. When the client negotiates the extended protocol we emit
// a 2-byte response (marker + server feature flags); otherwise we emit the single-byte
// legacy response.
this->extended_proto_ = (this->ota_features_ & CLIENT_FEATURE_SUPPORTS_EXTENDED_PROTOCOL) != 0;
if (this->extended_proto_) {
this->handshake_buf_[0] = ota::OTA_RESPONSE_FEATURE_FLAGS;
this->handshake_buf_[1] =
SERVER_FEATURE_SUPPORTS_PARTITION_ACCESS | (supports_compression ? SERVER_FEATURE_SUPPORTS_COMPRESSION : 0);
} else
this->handshake_buf_[1] = (supports_compression ? SERVER_FEATURE_SUPPORTS_COMPRESSION : 0);
#ifdef USE_OTA_PARTITIONS
this->handshake_buf_[1] |= SERVER_FEATURE_SUPPORTS_PARTITION_ACCESS;
#endif
{
} else {
this->handshake_buf_[0] =
supports_compression ? ota::OTA_RESPONSE_SUPPORTS_COMPRESSION : ota::OTA_RESPONSE_HEADER_OK;
}
@@ -257,15 +255,12 @@ void ESPHomeOTAComponent::handle_handshake_() {
}
case OTAState::FEATURE_ACK: {
#ifdef USE_OTA_PARTITIONS
const size_t ack_size = this->extended_proto_ ? 2 : 1;
#else
const size_t ack_size = 1;
#endif
static constexpr size_t STANDARD_PROTO_ACK_SIZE = 1;
static constexpr size_t EXTENDED_PROTO_ACK_SIZE = 2;
const size_t ack_size = this->extended_proto_ ? EXTENDED_PROTO_ACK_SIZE : STANDARD_PROTO_ACK_SIZE;
if (!this->try_write_(ack_size, LOG_STR("ack feature"))) {
return;
}
#ifdef USE_OTA_PASSWORD
// If password is set, move to auth phase
if (!this->password_.empty()) {
@@ -349,9 +344,7 @@ void ESPHomeOTAComponent::handle_data_() {
uint8_t buf[OTA_BUFFER_SIZE];
char *sbuf = reinterpret_cast<char *>(buf);
size_t ota_size;
#ifdef USE_OTA_PARTITIONS
ota::OTAType ota_type = ota::OTA_TYPE_UPDATE_APP;
#endif
#if USE_OTA_VERSION == 2
size_t size_acknowledged = 0;
#endif
@@ -367,7 +360,6 @@ void ESPHomeOTAComponent::handle_data_() {
// Acknowledge auth OK - 1 byte
this->write_byte_(ota::OTA_RESPONSE_AUTH_OK);
#ifdef USE_OTA_PARTITIONS
if (this->extended_proto_) {
// Read ota type, 1 byte
if (!this->readall_(buf, 1)) {
@@ -377,7 +369,6 @@ void ESPHomeOTAComponent::handle_data_() {
ota_type = static_cast<ota::OTAType>(buf[0]);
}
ESP_LOGV(TAG, "OTA type is 0x%02x", ota_type);
#endif
// Read size, 4 bytes MSB first
if (!this->readall_(buf, 4)) {
@@ -398,10 +389,14 @@ void ESPHomeOTAComponent::handle_data_() {
this->notify_state_(ota::OTA_STARTED, 0.0f, 0);
#endif
// This will block for a few seconds as it locks flash
#ifdef USE_OTA_PARTITIONS
error_code = this->backend_->begin(ota_size, ota_type);
#else
if (ota_type != ota::OTA_TYPE_UPDATE_APP) {
error_code = ota::OTA_RESPONSE_ERROR_UNSUPPORTED_OTA_TYPE;
goto error; // NOLINT(cppcoreguidelines-avoid-goto)
}
// This will block for a few seconds as it locks flash
error_code = this->backend_->begin(ota_size);
#endif
if (error_code != ota::OTA_RESPONSE_OK)
@@ -91,9 +91,7 @@ class ESPHomeOTAComponent final : public ota::OTAComponent {
std::string password_;
std::unique_ptr<uint8_t[]> auth_buf_;
#endif // USE_OTA_PASSWORD
#ifdef USE_OTA_PARTITIONS
bool extended_proto_{false};
#endif
socket::ListenSocket *server_{nullptr};
std::unique_ptr<socket::Socket> client_;