esphome / issues

Issue Tracker for ESPHome
https://esphome.io/
292 stars 36 forks source link

ESP32-S3 with 32MB Flash fails OTA due to `OTA app partition slot 1 is not bootable` #5824

Open ptr727 opened 6 months ago

ptr727 commented 6 months ago

The problem

Using a ESP32-S3-DevKitC-1-N32R8V, that uses a ESP32-S3-WROOM-2-N32R8V module, that is a ESP32-S3R8V, 32MB Octal SPI Flash, 8MB Octal SPI PSRAM, 1.8V SPI.

Programming a Flash size of 32MB results in esp_image: Segment 3 0x3fce3810-0x3fce4f9c invalid: overlaps bootloader stack and OTA app partition slot 1 is not bootable.

There is no specific board type for ESP32-S3-WROOM-2-N32R8V / ESP32-S3-DevKitC-1-N32R8V, the closest is esp32-s3-devkitc-1 but that is for 8MB flash and no PSRAM.

To my knowledge there is no way to use custom board layouts from ESPHome (ref, ref), and I modified the esp32-s3-devkitc-1 board configuration via platformio_options and sdkconfig_options to account for 32MB Octal Flash and 8MB Octal PSRAM.

I also had to use the ESP-IDF framework, not Arduino, and change the espressif32 and esp-idf versions to the latest released versions, else even setting 32MB size would not compile and / or create a boot loop.

It appears that using ESP-IDF the Arduino partition table layout is ignored (I was not sure if any Arduino options are required), and the tooling creates its own partition layout.

large_littlefs_32MB.csv:

# Name,   Type, SubType, Offset,  Size, Flags
nvs,      data, nvs,     0x9000,  0x5000,
otadata,  data, ota,     0xe000,  0x2000,
app0,     app,  ota_0,   0x10000, 0x480000,
app1,     app,  ota_1,   0x490000,0x480000,
spiffs,   data, spiffs,  0x910000,0x16E0000,
coredump, data, coredump,0x1FF0000,0x10000,

From log output:

I (65) boot: Partition Table:
I (68) boot: ## Label            Usage          Type ST Offset   Length
I (76) boot:  0 otadata          OTA data         01 00 00009000 00002000
I (83) boot:  1 phy_init         RF data          01 01 0000b000 00001000
I (90) boot:  2 app0             OTA app          00 10 00010000 00fc0000
I (98) boot:  3 app1             OTA app          00 11 00fd0000 00fc0000
I (105) boot:  4 nvs              WiFi data        01 02 01f90000 0006d000
I (113) boot: End of partition table
I (117) esp_image: segment 0: paddr=00fd0020 vaddr=3c090020 size=25904h (153860) map
I (162) esp_image: segment 1: paddr=00ff592c vaddr=3fc98600 size=04904h ( 18692) load
I (168) esp_image: segment 2: paddr=00ffa238 vaddr=40374000 size=05de0h ( 24032) load
I (175) esp_image: segment 3: paddr=01000020 vaddr=3fce3810 size=0178ch (  6028) load
E (177) esp_image: Segment 3 0x3fce3810-0x3fce4f9c invalid: overlaps bootloader stack
E (185) boot: OTA app partition slot 1 is not bootable

Test setup:

Repeat test with 16MB Flash settings in YAML:

Which version of ESPHome has the issue?

2024.5.0

What type of installation are you using?

pip

Which version of Home Assistant has the issue?

NA

What platform are you using?

ESP32-IDF

Board

ESP32-S3-DevKitC-1-N32R8V

Component causing the issue

OTA

Example YAML snippet

# Config for ESP32-S3-DevKitC-1-N32R8V (32MB OT Flash, 8MB OT PSRAM)

# TODO: Boot log warnings
# "spi_flash: Octal flash chip is using but dio mode is selected, will automatically swich to Octal mode"
# "tsens: legacy driver is deprecated, please migrate to `driver/temperature_sensor.h`"
# "rmt(legacy): legacy driver is deprecated, please migrate to `driver/rmt_tx.h` and/or `driver/rmt_rx.h`"

# TODO: OTA does not work, succeeds but does not actually update the firmware, only USB programming works

esphome:
  name: n32r8v-ota-test
  comment: "ESP32-S3-DevKitC-1-N32R8V Test Device"
  on_boot:
    then:
      # Change boot up LED colors to test if firmware changed
      - light.turn_on:
          id: rgb_led
          red: 0%
          green: 100%
          blue: 0%
          brightness: 25%
          effect: none

  # Modify default esp32-s3-devkitc-1 (8MB Flash, no PSRAM) board configuration for ESP32-S3-DevKitC-1-N32R8V (32MB Flash, 8MB PSRAM)
  platformio_options:
    # TODO: Are any Arduino options used when using ESP-IDF?
    # Largest "default" partition type is 16MB default_16MB.csv, no default 32MB partition, closest matching in layout is large_littlefs_32MB.csv
    # https://github.com/espressif/arduino-esp32/tree/master/tools/partitions
    board_build.arduino.partitions: large_littlefs_32MB.csv
    # board_build.arduino.partitions: default_16MB.csv
    # Octal memory type for Flash and PSRAM
    board_build.arduino.memory_type: opi_opi
    # TODO: How to add vs. replace?
    board_build.extra_flags:
      - "-DARDUINO_ESP32S3_DEV"
      # Has PSRAM
      - "-DBOARD_HAS_PSRAM"
      - "-DARDUINO_USB_MODE=1"
      - "-DARDUINO_RUNNING_CORE=1"
      - "-DARDUINO_EVENT_RUNNING_CORE=1"
    # Octal memory type for PSRAM
    board_build.psram_type: opi
    board_name: "Espressif ESP32-S3-DevKitC-1-N32R8V (32MB OT Flash, 8MB OT PSRAM)"
    # TODO: Error when setting flash size in board config?
    # "Please specify flash_size within esp32 configuration only.""
    #board_upload.flash_size: 32MB 
    # 32MB
    board_upload.maximum_size: 33554432

esp32:
  # Platformio config changes will modify esp32-s3-devkitc-1 base configuration
  board: esp32-s3-devkitc-1
  # TODO: Why can't we set flash size in board config?
  flash_size: 32MB
  # flash_size: 16MB
  framework:
    type: esp-idf
    # Using latest versions to get the 32MB flash size compiling without boot loops
    # There is no "latest" option
    platform_version: 6.7.0
    # Using latest only brings in 5.2.0 that fails to compile, while latest released is 5.2.1?
    version: 5.2.1
    # TODO: https://github.com/esphome/issues/issues/5404
    # Warning! Flash memory size mismatch detected. Expected 32MB, found 2MB!
    sdkconfig_options:
      CONFIG_ESPTOOLPY_FLASHSIZE_32MB: "y"
      # CONFIG_ESPTOOLPY_FLASHSIZE_16MB: "y"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: !secret wifi_domain
  reboot_timeout: 5min

logger:
  level: debug
  hardware_uart: UART0

ota:
  password: !secret ota_password

debug:
  update_interval: 60s

light:
  - platform: esp32_rmt_led_strip
    id: rgb_led
    disabled_by_default: true
    entity_category: config
    rgb_order: GRB
    pin: GPIO38
    num_leds: 1
    rmt_channel: 0
    chipset: WS2812

psram:
  mode: octal
  speed: 80MHz

Anything in the logs that might be useful for us?

OTA Programming:

[D][ota:154]: Starting OTA Update from 192.168.1.15...
[W][component:157]: Component ota set Warning flag: unspecified
[D][ota:330]: OTA in progress: 0.1%
[D][ota:330]: OTA in progress: 33.7%
[D][ota:330]: OTA in progress: 66.1%
[D][ota:330]: OTA in progress: 99.4%
[I][ota:363]: OTA update finished!
[W][component:170]: Component ota cleared Warning flag
[I][app:132]: Rebooting safely...
[D][esp32.preferences:114]: Saving 1 preferences to flash...
[D][esp32.preferences:142]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed

UART Log:

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
Saved PC:0x40376d89
SPIWP:0xee
Octal Flash Mode Enabled
For OPI Flash, Use Default Flash Boot Mode
mode:SLOW_RD, clock div:1
load:0x3fce3810,len:0x178c
load:0x403c9700,len:0x4
load:0x403c9704,len:0xcbc
load:0x403cc700,len:0x2da0
entry 0x403c990c
I (37) boot: ESP-IDF 5.2.1 2nd stage bootloader
I (38) boot: compile time May 19 2024 17:42:54
I (38) boot: Multicore bootloader
I (41) boot: chip revision: v0.1
I (44) boot.esp32s3: Boot SPI Speed : 80MHz
I (49) boot.esp32s3: SPI Mode       : SLOW READ
I (54) boot.esp32s3: SPI Flash Size : 32MB
I (59) boot: Enabling RNG early entropy source...
I (65) boot: Partition Table:
I (68) boot: ## Label            Usage          Type ST Offset   Length
I (76) boot:  0 otadata          OTA data         01 00 00009000 00002000
I (83) boot:  1 phy_init         RF data          01 01 0000b000 00001000
I (90) boot:  2 app0             OTA app          00 10 00010000 00fc0000
I (98) boot:  3 app1             OTA app          00 11 00fd0000 00fc0000
I (105) boot:  4 nvs              WiFi data        01 02 01f90000 0006d000
I (113) boot: End of partition table
I (117) esp_image: segment 0: paddr=00fd0020 vaddr=3c090020 size=25904h (153860) map
I (162) esp_image: segment 1: paddr=00ff592c vaddr=3fc98600 size=04904h ( 18692) load
I (168) esp_image: segment 2: paddr=00ffa238 vaddr=40374000 size=05de0h ( 24032) load
I (175) esp_image: segment 3: paddr=01000020 vaddr=3fce3810 size=0178ch (  6028) load
E (177) esp_image: Segment 3 0x3fce3810-0x3fce4f9c invalid: overlaps bootloader stack
E (185) boot: OTA app partition slot 1 is not bootable
I (191) esp_image: segment 0: paddr=00010020 vaddr=3c090020 size=25904h (153860) map
I (236) esp_image: segment 1: paddr=0003592c vaddr=3fc98600 size=04904h ( 18692) load
I (241) esp_image: segment 2: paddr=0003a238 vaddr=40374000 size=05de0h ( 24032) load
I (248) esp_image: segment 3: paddr=00040020 vaddr=42000020 size=87b58h (555864) map
I (382) esp_image: segment 4: paddr=000c7b80 vaddr=40379de0 size=0e7b0h ( 59312) load
I (407) boot: Loaded app from partition at offset 0x10000
I (407) boot: Disabling RNG early entropy source...
I (419) cpu_start: Multicore app

Additional information

Other anomalies:

OTA Logs:

> esphome run .\n32r8v-ota-test.yaml    
INFO ESPHome 2024.5.0
INFO Reading configuration .\n32r8v-ota-test.yaml...
WARNING The selected ESP-IDF framework version is not the recommended one. If there are connectivity or build issues please remove the manual version.
WARNING The selected ESP-IDF framework version is not the recommended one. If there are connectivity or build issues please remove the manual version.
INFO Generating C++ source...
INFO Updating https://github.com/espressif/esp-protocols.git@mdns-v1.2.5
INFO Compiling app...
Processing n32r8v-ota-test (board: esp32-s3-devkitc-1; framework: espidf; platform: platformio/espressif32@6.7.0)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32-s3-devkitc-1.html
PLATFORM: Espressif 32 (6.7.0) > Espressif ESP32-S3-DevKitC-1-N32R8V (32MB OT Flash, 8MB OT PSRAM)
HARDWARE: ESP32S3 240MHz, 320KB RAM, 32MB Flash
DEBUG: Current (esp-builtin) On-board (esp-builtin) External (cmsis-dap, esp-bridge, esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES: 
 - framework-espidf @ 3.50201.240515 (5.2.1) 
 - tool-cmake @ 3.16.4 
 - tool-esptoolpy @ 1.40501.0 (4.5.1) 
 - tool-idf @ 1.0.1 
 - tool-mconf @ 1.4060000.20190628 (406.0.0) 
 - tool-ninja @ 1.9.0 
 - tool-riscv32-esp-elf-gdb @ 11.2.0+20220823 
 - tool-xtensa-esp-elf-gdb @ 11.2.0+20230208 
 - toolchain-esp32ulp @ 2.35.0-20220830 
 - toolchain-riscv32-esp @ 13.2.0+20230928 
 - toolchain-xtensa-esp-elf @ 13.2.0+20230928
Reading CMake configuration...
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ off, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Retrieving maximum program size .pioenvs\n32r8v-ota-test\firmware.elf
Checking size .pioenvs\n32r8v-ota-test\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  11.3% (used 36964 bytes from 327680 bytes)
Flash: [          ]   4.9% (used 811501 bytes from 16515072 bytes)
==================================================================================================================================== [SUCCESS] Took 5.63 seconds ====================================================================================================================================
INFO Successfully compiled program.
Found multiple options for uploading, please choose one:
  [1] COM9 (Silicon Labs CP210x USB to UART Bridge (COM9))
  [2] Over The Air (n32r8v-ota-test.home.insanegenius.net)
(number): 2
INFO Resolving IP address of n32r8v-ota-test.home.insanegenius.net
INFO  -> 192.168.1.129
INFO Uploading .\.esphome\build\n32r8v-ota-test\.pioenvs\n32r8v-ota-test\firmware.bin (811872 bytes)
Uploading: [============================================================] 100% Done...

INFO Upload took 3.03 seconds, waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from COM9 with baud rate 115200
ERROR Could not connect to serial port COM9

UART logs attached. COM9_2024_05_19.17.46.46.427.txt

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.