[esphome.ota] Trim verbose comments from simplification

This commit is contained in:
J. Nick Koston
2026-04-11 08:21:11 -10:00
parent e67fac704c
commit 30de0c17ab
4 changed files with 5 additions and 19 deletions
+1 -3
View File
@@ -155,9 +155,7 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_auth_password(config[CONF_PASSWORD]))
cg.add_define("USE_OTA_PASSWORD")
cg.add_define("USE_OTA_VERSION", config[CONF_VERSION])
# Build flag (not a define in defines.h) so lwip_fast_select.c a .c file that
# can't include defines.h — can still gate its wake hook on the esphome OTA
# platform being compiled in.
# Build flag so lwip_fast_select.c (a .c file that can't include defines.h) sees it.
cg.add_build_flag("-DUSE_OTA_PLATFORM_ESPHOME")
await cg.register_component(var, config)
@@ -31,16 +31,11 @@ static constexpr size_t OTA_BUFFER_SIZE = 1024; // buffer size
static constexpr uint32_t OTA_SOCKET_TIMEOUT_HANDSHAKE = 20000; // milliseconds for initial handshake
static constexpr uint32_t OTA_SOCKET_TIMEOUT_DATA = 90000; // milliseconds for data transfer
// File-scope pointer to the single ESPHomeOTAComponent instance. The final_validate in
// __init__.py rejects multi-port configs, so only one exists. Set in setup() and used
// by the extern "C" wake trampoline below, which is called from socket wake paths
// (lwip_fast_select listener filter, raw-TCP accept_fn_).
// Single-instance pointer — multi-port configs are rejected in final_validate.
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static ESPHomeOTAComponent *global_esphome_ota_component = nullptr;
// Trampoline called from C and C++ socket wake paths. Must be safe from any context
// (LwIP TCP/IP task, user-level IRQ on RP2040). enable_loop_soon_any_context() uses
// volatile flags only — no locks, no allocations.
// Called from any context (LwIP TCP/IP task, RP2040 user-IRQ).
extern "C" void esphome_wake_ota_component_any_context() {
if (global_esphome_ota_component != nullptr) {
global_esphome_ota_component->enable_loop_soon_any_context();
@@ -12,8 +12,6 @@
#include "esphome/core/log.h"
#ifdef USE_OTA_PLATFORM_ESPHOME
// Defined in components/esphome/ota/ota_esphome.cpp. Marks the ESPHome OTA component
// pending-enable from the raw-TCP accept callback (per-pcb, implicitly filtered).
extern "C" void esphome_wake_ota_component_any_context();
#endif
@@ -861,9 +859,7 @@ err_t LWIPRawListenImpl::accept_fn_(struct tcp_pcb *newpcb, err_t err) {
tcp_recv(newpcb, LWIPRawListenImpl::s_queued_recv_fn);
LWIP_LOG("Accepted connection, queue size: %d", this->accepted_socket_count_);
#ifdef USE_OTA_PLATFORM_ESPHOME
// Mark OTA pending-enable before the wake below — flags must be visible before the
// main task runs. accept_fn_ is per-pcb, so filtering is implicit here (only fires
// for completed handshakes to whichever listener owns newpcb).
// Must run before wake_loop_any_context() so flags are visible when the main task wakes.
esphome_wake_ota_component_any_context();
#endif
// Wake the main loop immediately so it can accept the new connection.
+1 -4
View File
@@ -158,11 +158,8 @@ _Static_assert(offsetof(struct lwip_sock, rcvevent) == ESPHOME_LWIP_SOCK_RCVEVEN
static netconn_callback s_original_callback = NULL;
#ifdef USE_OTA_PLATFORM_ESPHOME
// This .c file can't include defines.h — macros.h → Arduino.h would break the C
// compile. esphome/ota/__init__.py emits -DUSE_OTA_PLATFORM_ESPHOME via
// cg.add_build_flag so both this TU and C++ call sites can see the same name.
static struct netconn *s_ota_listener_conn = NULL;
extern void esphome_wake_ota_component_any_context(void); // defined in ota_esphome.cpp
extern void esphome_wake_ota_component_any_context(void);
void esphome_fast_select_set_ota_listener_sock(struct lwip_sock *sock) {
s_ota_listener_conn = (sock != NULL) ? sock->conn : NULL;