Skip to content

Unable to perform OTA rollback from custom panic handler #9342

@eraetsky

Description

@eraetsky

Board

ESP32 Devkit V1

Device Description

Ordinary ESP32 Devkit V1

Hardware Configuration

Version

v2.0.14

IDE Name

VSCode, PlatformIO

Operating System

macOS

Flash frequency

40 Mhz

PSRAM enabled

no

Upload speed

115200

Description

I want to perform a rollback from a custom panic handler. I am using PlatformIO and tried with both frameworks arduino and espidf, and only arduino. When my overrided panic handler function reaches esp_ota_mark_app_invalid_rollback_and_reboot(); it gets stuck and nothing happens. I know that on arduino implementation of this function is precompiled, but I tested with espidf and found out that it freezes deep inside function call chain, on
esp_err_t spi_flash_mmap(size_t src_addr, size_t size, spi_flash_mmap_memory_t memory, const void** out_ptr, spi_flash_mmap_handle_t* out_handle)

I tested versions 2.0.14 and 2.0.6, also 2.0.6 with esp-idf version 4.4.5. On 2.0.14 I am able to call esp_restart() from the panic handler, on 2.0.6 - not. But on bare esp-idf 4.4.5 rollback from custom panic handler works fine (tested with native_ota_example on PlatformIO).

Also I tried overriding verifyRollbackLater(), setting it to return true. In this case, when esp_restart() is done from the custom panic handler, rollback goes on, but I want app received by OTA to be valid unless esp_ota_mark_app_invalid_rollback_and_reboot() is called. I understand that in this case rollback is performed because app has an unconfirmed status and reboot from any part of the code or by pressing the button will cause rollback, and it does not suit me.

My PlatformIO configurations:

  1. arduino + espidf
    platformio.ini
    [env:esp32dev] platform = espressif32 board = esp32dev framework = arduino, espidf build_flags = -std=c++17 -std=gnu++17 -DVERSION=${this.custom_prog_version} -DCONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=1 -Wl,--wrap=esp_panic_handler

  2. arduino
    platformio.ini
    [env:esp32dev] platform = espressif32 @ 5.4.0 board = esp32dev framework = arduino build_flags = -std=c++17 -std=gnu++17 -Wl,--wrap=esp_panic_handler -DVERSION=${this.custom_prog_version} -DCONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=1

I set platform = espressif32 @ 5.4.0 in order to switch to another versions.

  1. espidf only, where rollback from panic handler is possible
    platformio.ini
    `
    [platformio]
    src_dir = main

[env:esp32dev]

platform = espressif32 @ 5.4.0
board = esp32dev
framework = espidf`

Thank you in advance.

Sketch

extern "C" bool verifyRollbackLater()
{
  esp_rom_printf("Rollback verification on Arduino init disabled!\n");
  return true;
}
extern "C" void __real_esp_panic_handler(void *);
extern "C" void __wrap_esp_panic_handler(void *info)
{
  esp_rom_printf("PANIC HANDLER TRYING TO ROLLBACK\n");
  esp_ota_mark_app_invalid_rollback_and_reboot();
}

Debug Message

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1184
load:0x40078000,len:13104
load:0x40080400,len:3036
entry 0x400805e4
RK����verification on Arduino init disabled!
Setting WiFiClient as a network client
WiFi Creds: SSID [my ssid], PSWD: [my pswd]
[WiFi] WiFi is disconnected
Retry...
[WiFi] WiFi is disconnected
Retry...
[WiFi] SSID not found
Retry...
[WiFi] SSID not found
Retry...
[WiFi] SSID not found
Retry...
Network manager could not connect to any network :(
[MQTT] Creds: Broker URL [my broker]
PANIC HANDLER TRYING TO ROLLBACK

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions