Commit Graph

26751 Commits

Author SHA1 Message Date
J. Nick Koston 724d96dbfb Fix clang-tidy redundant-declaration for _irom0_text_end 2026-04-05 13:52:32 -10:00
J. Nick Koston f81e1c37da Merge remote-tracking branch 'upstream/esp8266-crash-handler' into integration 2026-04-05 13:39:46 -10:00
J. Nick Koston 2657bdc97a Reserve crash handler RTC region from preferences
Reduce preferences normal region from 96 to 78 words (words 32-109)
to formally reserve words 110-127 for the crash handler backtrace.
Preferences that don't fit in RTC fall back to flash storage, so
this has no functional impact for typical configurations.
2026-04-05 13:35:01 -10:00
J. Nick Koston 42f9b4225f Add RTC memory overlap comment in preferences.cpp 2026-04-05 13:33:27 -10:00
J. Nick Koston 82d178486b Address review feedback
- Add IRAM_ATTR to is_code_addr/recover_code_addr as safety net
  in case the compiler doesn't inline them
- Restore EXCVADDR logging for exception resets (faulting address
  is the key diagnostic for LoadProhibit/StoreProhibit)
- Add comment noting Xtensa stack pointer alignment assumption
2026-04-05 13:33:01 -10:00
J. Nick Koston 0614849896 Fix clang-tidy errors from CI
- Match Arduino core's declaration of _irom0_text_start/_end as
  void functions (mmu_iram.h declares them this way)
- Use C-style casts with NOLINT for int-to-ptr conversions in
  custom_crash_callback (clang-tidy performance-no-int-to-ptr)
2026-04-05 13:28:29 -10:00
J. Nick Koston 1ecd45d14d Drop addr2line hint line
The ESPHome CLI already decodes addresses inline (shown as
WARNING Decoded lines). The hint was redundant and cost ~100
bytes of flash plus 220 bytes of stack for the format buffer.
2026-04-05 13:18:48 -10:00
J. Nick Koston 4630c045bd Shorten Prohibited to Prohibit in exception cause names 2026-04-05 13:06:27 -10:00
J. Nick Koston 71649f6c1f Drop impossible exception causes and shorten strings
The LX106 (ESP8266) has no MMU, TLB, PIF, or privilege levels, so
exception causes 1, 5, 7, 8, 12-18, and 24-26 can never occur.
Remove them and shorten remaining cause names. Also drop Syscall,
Alloca, PCValue, Privileged which are unreachable on this core.
2026-04-05 13:05:40 -10:00
J. Nick Koston 9cdc6f52e0 Skip zero-init of RtcCrashData to save 15 bytes IRAM 2026-04-05 13:00:14 -10:00
J. Nick Koston 8241e385eb Remove redundant IRAM_ATTR from static inline helpers 2026-04-05 12:58:08 -10:00
J. Nick Koston 10b52df32b Fix stale comments referencing removed is_return_addr 2026-04-05 12:57:20 -10:00
J. Nick Koston d512ce24da Share TAG with other esp8266 component files 2026-04-05 12:54:42 -10:00
J. Nick Koston 9e7c990fc6 Use constexpr for ROM divide-by-zero detection 2026-04-05 12:52:01 -10:00
J. Nick Koston ed7bfa3e0f Detect divide-by-zero from ROM ILL instruction pattern
GCC's ROM divide routine triggers IllegalInstruction (exccause=0) at
ROM addresses 0x4000dce5/0x4000dd3d instead of IntegerDivideByZero
(exccause=6). Patch exccause to match the Arduino core's postmortem
handler behavior.
2026-04-05 12:51:34 -10:00
J. Nick Koston 64be4504ae Match ESP8266 Arduino core reset reason names 2026-04-05 12:49:43 -10:00
J. Nick Koston 57c95909d1 Show exception cause for all crash types
WDT resets also populate exccause in rst_info (e.g. Level1Interrupt
for stack overflow soft WDT). Show the cause string for all crash
reasons, not just REASON_EXCEPTION_RST. Also simplify PC logging
to a single line for all crash types.
2026-04-05 12:46:40 -10:00
J. Nick Koston ca623ace1a Remove s_crash_valid and crash_handler_read_and_clear
resetInfo is a global that persists until next reset — no need to
cache the crash validity in a separate bool. Check resetInfo.reason
directly in crash_handler_has_data() and crash_handler_log().
This eliminates the only RAM byte from the crash handler and removes
the now-empty crash_handler_read_and_clear() function and its call
from arch_init().
2026-04-05 12:43:18 -10:00
J. Nick Koston 9f008ba487 Reduce flash by removing rarely-useful register lines
Remove EPC2/EPC3 (always 0 on LX106, no level 2/3 interrupts) and
DEPC (extremely rare double exception). Combine PC and EXCVADDR into
one log line for exception resets. Shrink hint buffer 256->220.
Saves ~36 bytes flash in crash_handler_log.
2026-04-05 12:38:36 -10:00
J. Nick Koston 9035410fa9 Remove PROGMEM_STRING_TABLE mention from comment 2026-04-05 12:33:46 -10:00
J. Nick Koston 8a8540b247 Use if-else chains instead of switch for string lookups
Switch statements generate CSWTCH jump tables in RAM on ESP8266.
PROGMEM_STRING_TABLE causes LoadStoreError from flash cache conflicts
in API subscribe paths. If-else with LOG_STR avoids both: strings
stay in flash via PSTR, and comparison branches don't need a data
table. Zero RAM overhead confirmed via nm.
2026-04-05 12:33:32 -10:00
J. Nick Koston 58fd6ceff8 Restore progmem.h include needed for PROGMEM_STRING_TABLE 2026-04-05 12:24:30 -10:00
J. Nick Koston 6cdcdbb798 Remove flash-reading return address verification
Reading IROM addresses from IROM code causes LoadStoreError on ESP8266
due to the direct-mapped flash cache — the reading code and target
address can share a cache line, evicting the function mid-execution.

Remove is_return_addr() and rely on linker-symbol IROM bounds
(_irom0_text_start/_end) to eliminate false positives instead. This
is less precise but crash-safe.
2026-04-05 12:24:05 -10:00
J. Nick Koston af6e10816d Fix namespace for progmem_read_byte 2026-04-05 12:12:06 -10:00
J. Nick Koston b99a4aab98 Fix crash in is_return_addr reading unmapped flash
Two issues:
1. safe_read_code_byte used volatile cast which prevented the compiler
   from using flash-safe l32i instructions, causing LoadStoreError on
   IROM addresses. Replace with progmem_read_byte.
2. IROM upper bound (0x40400000 = 2MB) was too generous for devices
   with smaller flash (e.g. 1MB), causing both false positives in the
   backtrace and faults when is_return_addr tried to verify CALL
   instructions at unmapped addresses. Use _irom0_text_start/end
   linker symbols for precise firmware code bounds.
2026-04-05 12:11:38 -10:00
J. Nick Koston a328726bfd Derive exception cause range bounds from table sizes 2026-04-05 12:08:05 -10:00
J. Nick Koston c1c45cfd23 Derive magic word masks from bit positions at compile time 2026-04-05 12:07:30 -10:00
J. Nick Koston 5aac3e1317 Replace switch tables with PROGMEM_STRING_TABLE to save 132B RAM
GCC generates CSWTCH jump tables in RAM rodata on ESP8266 for switch
statements. Convert exception cause and reset reason lookups to
PROGMEM_STRING_TABLE which keeps data in flash. Exception causes are
split into two tables (0-9 and 12-29) to stay under the 255-byte
blob limit. Added static_asserts on reset reason enum values.
2026-04-05 12:06:46 -10:00
J. Nick Koston ac76f1fc3d Add return address verification and scan full stack
- Verify each candidate is a real return address by checking that the
  instruction at addr-3 is a CALL/CALLX (Xtensa 3-byte call opcodes).
  This filtering happens at log time when flash is readable, similar
  to the ESP32 RISC-V handler's is_return_addr() approach.
- Scan the entire stack instead of just 64 words — with filtering,
  false positives from stale stack data are eliminated.
- Skip epc1 during scanning (already reported as fault PC).
- Increase to 16 RTC slots (72 bytes) for broader capture before
  filtering. Bump hint buffer to 256 for more addresses.
2026-04-05 12:02:05 -10:00
J. Nick Koston a89a4e1353 Always log EXCVADDR for exception resets
A null EXCVADDR (0x00000000) is the key diagnostic for null pointer
crashes (LoadProhibited/StoreProhibited). Suppressing it when zero
hides the most useful information.
2026-04-05 11:59:02 -10:00
J. Nick Koston 73326bce07 Fix stale docstring and extract stack scan limit constant 2026-04-05 11:56:43 -10:00
J. Nick Koston eb7ce1b684 Replace magic numbers with named constexpr constants 2026-04-05 11:54:37 -10:00
J. Nick Koston 0d93f2fcd1 Increase max backtrace to 8 entries for deep ESP8266 stacks
ESP8266 call stacks are typically deep due to Arduino/LWIP/WiFi
layers. 8 entries (36 bytes, 9 RTC blocks) better captures the
WiFi -> LWIP -> socket -> ESPHome -> component call chain.
2026-04-05 11:54:01 -10:00
J. Nick Koston 8dc30bc54d Reduce RTC memory footprint from 32 to 20 bytes
Pack backtrace count into the magic word and reduce max backtrace
entries from 6 to 4, saving 3 RTC blocks (12 bytes).
2026-04-05 11:52:02 -10:00
J. Nick Koston 50073a24b5 [esp8266] Add crash handler for post-mortem diagnostics
Add a crash handler for ESP8266 that captures and logs crash data
from previous boots, matching the existing ESP32 and RP2040
implementations. Uses the SDK's rst_info (always available after
reboot) for basic crash info and Arduino's custom_crash_callback
to scan the stack for return addresses stored in RTC user memory.
2026-04-05 11:50:35 -10:00
J. Nick Koston 57c7f6e32f Merge remote-tracking branch 'upstream/dev' into integration 2026-04-05 11:28:56 -10:00
J. Nick Koston 88f47c5241 Merge remote-tracking branch 'upstream/api-noise-split-state-action' into integration 2026-04-05 11:15:50 -10:00
J. Nick Koston 9a8d17e3c8 [api] Split Noise handshake state_action_ to reduce stack pressure
On RP2040, the core0 stack lives in a 4KB SCRATCH_Y RAM bank. The Noise
protocol handshake calls into curve25519 scalar multiplication which
needs ~2KB+ of stack. When all handshake state branches lived in a
single function, the compiler allocated stack space for all branches
simultaneously (SERVER_HELLO msg[46]+mac[13], HANDSHAKE buffer[65],
NoiseBuffer, etc.), leaving insufficient headroom for the crypto path.

Split state_action_() into per-state methods so each state's locals
occupy separate stack frames. The crypto path (WRITE_MESSAGE) now only
carries its own 85 bytes of locals instead of ~200+ bytes from all
branches combined.
2026-04-05 11:12:47 -10:00
Ross Tyler c7a163441e [ethernet] Add interface configuration variable for esp-idf (#10285)
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2026-04-05 20:57:41 +00:00
J. Nick Koston 1582e230dd Merge branch 'enhancement/ethernet-spi-interface' into integration 2026-04-05 10:32:44 -10:00
J. Nick Koston ddb024cfb1 Merge branch 'dev' into enhancement/ethernet-spi-interface 2026-04-05 10:32:31 -10:00
J. Nick Koston 47c5734793 bot comments 2026-04-05 10:00:45 -10:00
J. Nick Koston 3509e1ee21 Merge remote-tracking branch 'origin/fix-ota-handshake-flush' into integration 2026-04-05 09:54:52 -10:00
J. Nick Koston a084f5199c Merge remote-tracking branch 'upstream/dev' into integration 2026-04-05 09:53:52 -10:00
J. Nick Koston 2243e34981 [ota] Fix OTA handshake failure by switching to blocking before feature ACK write
Switch to blocking mode before writing the feature ACK byte in the
no-password path. lwIP may not transmit data written in non-blocking
mode when the socket immediately switches to blocking and blocks in
recv(). Writing the feature ACK in blocking mode ensures it is flushed
to the wire before entering the blocking data transfer phase.
2026-04-05 09:51:37 -10:00
J. Nick Koston bf39dfef6a [ota] Fix OTA handshake failure by flushing pending writes before blocking read
Add delay(0) after switching to blocking mode in handle_data_() to
flush any pending non-blocking writes (the feature ACK byte) before
entering the blocking read loop. lwIP may not transmit data written
in non-blocking mode until the task yields.
2026-04-05 09:49:08 -10:00
J. Nick Koston f070ef6d08 preen 2026-04-05 09:43:58 -10:00
J. Nick Koston c2f5b5f770 amek proper validator 2026-04-05 09:36:37 -10:00
J. Nick Koston bfb6f2d0fd match 2026-04-05 09:36:18 -10:00
J. Nick Koston 8f26903c8c match 2026-04-05 09:34:26 -10:00