Does Arduino Core support OTA on the ESP32S2?

mlefevre
Posts: 6
Joined: Sun Jun 16, 2024 4:08 pm

Does Arduino Core support OTA on the ESP32S2?

Postby mlefevre » Tue Aug 13, 2024 3:58 pm

I have a project on the Wemos ESP32S2 mini V1. It has the USB-C port for programming but I need to do OTA flash programming in the long run. With the configuration I have now, the OTA upload works just fine. It just always fails at the end with

Code: Untitled.txt Select all


Uploading: [============================================================] 99%
Uploading: [============================================================] 99%
Uploading: [============================================================] 100% Done...


04:19:52 [INFO]: Waiting for result...
04:19:52 [INFO]: Result: Could Not Activate The Firmware

04:19:52 [INFO]: Result:

04:19:52 [INFO]: Result:
04:19:52 [INFO]: Result:
04:19:52 [INFO]: Result:
04:19:52 [ERROR]: Error response from device
*** [upload] Error 1
IF I track this error result down in the core firmware, I see it being generated in ./packages/framework-arduinoespressif32/libraries/Update/src/Updater.cpp:

Code: Untitled.cpp Select all


bool UpdateClass::_verifyEnd() {
if (_command == U_FLASH) {
if (!_enablePartition(_partition) || !_partitionIsBootable(_partition)) {
_abort(UPDATE_ERROR_READ);
return false;
}

if (esp_ota_set_boot_partition(_partition)) {
_abort(UPDATE_ERROR_ACTIVATE);
return false;
}
_reset();
return true;
} else if (_command == U_SPIFFS) {
_reset();
return true;
}
return false;
}
I can't get a look at esp_ota_set_boot_partition() but that was enough to make me start looking at the partition table I'm using. It started off looking like this:

Code: Untitled.txt Select all


Name,   Type,   SubType,     Offset,     Size,      Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xE000, 0x2000,
ota_0, 0, ota_0, 0x10000, 0x1F0000,
ota_1, 0, ota_1, 0x200000, 0x1F0000,
coredump, data, coredump, 0x3F0000, 0x10000,
Since that wasn't working, I tried using default.csv but that just failed the same way. Poking around in the .platformio directory I found ./packages/framework-arduino-solo1/variants/department_of_alchemy_minimain_esp32s2/partitions-4MB-tinyuf2.csv:

Code: partitions-4MB-tinyuf2.csv Select all


# ESP-IDF Partition Table
# Name, Type, SubType, Offset, Size, Flags
# bootloader.bin,, 0x1000, 32K
# partition table, 0x8000, 4K

nvs, data, nvs, 0x9000, 20K,
otadata, data, ota, 0xe000, 8K,
ota_0, 0, ota_0, 0x10000, 1408K,
ota_1, 0, ota_1, 0x170000, 1408K,
uf2, app, factory,0x2d0000, 256K,
ffat, data, fat, 0x310000, 960K,
It's for ESP-IDF but I thought that may not matter when it comes to OTA. I modified my custom partition file to add the uf2 partition:

Code: ESP32S2mini.csv Select all


 Name,   Type,   SubType,     Offset,     Size,      Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xE000, 0x2000,
ota_0, 0, ota_0, 0x10000, 0x1D0000,
ota_1, 0, ota_1, 0x1E0000, 0x1D0000,
uf2, app, factory, 0x3B0000, 0x40000,
coredump, data, coredump, 0x3F0000, 0x10000,
Of course, that made no difference either. So, my question is, am I looking in the right place to solve this problem?

My platformio.ini looks like this:

Code: platformio.ini Select all


; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env]
platform = espressif32
board = WemosESP32S2miniV1
framework = arduino
build_type = debug
board_build.partitions = ESP32S2mini.csv

monitor_speed = 115200
monitor_port = COM27
monitor_filters = esp32_exception_decoder

; upload_protocol = esptool
; upload_resetmethod = nodemcu
; upload_port = COM4
;upload_flags = --after no_reset

upload_protocol = espota
upload_port = .....
upload_flags = --auth=admin
--port=3232

build_flags =
-DBOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
-Wall
-DDEBUG
-std=gnu99
-Os
-u,vfprintf
-DUSER_SETUP_LOADED=1
-DST7789_DRIVER=1
-DTFT_RGB_ORDER=TFT_BGR
-DSPI_FREQUENCY=40000000
-DTFT_MISO=-1
-DTFT_MOSI=13
-DTFT_SCLK=14
-DTFT_CS=-1
-DTFT_DC=5
-DTFT_RST=4
-DLOAD_GFXFF=1

lib_extra_dirs =
C:\Users\marc\Documents\PlatformIO\Lib

lib_deps =
bodmer/TFT_eSPI@^2.5.43
bogde/HX711@^0.7.5
arcao/Syslog@^2.0.0
milesburton/DallasTemperature@^3.11.0
https://github.com/PaulStoffregen/OneWire.git
knolleary/PubSubClient@^2.8
bblanchon/ArduinoJson@^7.1.0


[env:tool]

build_flags =
-DTOOL
-DCLIENT_NAME="\"CH101\""
-DMY_IP_ADDRESS="....."
-DNUM_TEMPERATURE_SENSORS=3


[env:proto]

build_flags =
-DPROTO
-DCLIENT_NAME="\"CH102\""
-DMY_IP_ADDRESS="....."
-DNUM_TEMPERATURE_SENSORS=1
I'm using esptool in PlatformIO to do the OTA upload:

esptool.py v4.5.1 - Espressif chips ROM Bootloader Utility

I have some experience with the ESP32 but this is my first project with the S2 and USB boot loader.

lbernstone
Posts: 1131
Joined: Mon Jul 22, 2019 3:20 pm

Re: Does Arduino Core support OTA on the ESP32S2?

Postby lbernstone » Wed Aug 14, 2024 5:54 am

I use a extended version of the OTAWebUpdater as a pre-loader on my devices. It works on all the variants AFAIK.
This error generally indicates that the file is damaged or the wrong type. What are you uploading to it? There will be a couple bin files in your compile directory. Make sure you use the <sketch_name>.ino.bin file.
You haven't done anything with secure boot on these devices, have you?

mlefevre
Posts: 6
Joined: Sun Jun 16, 2024 4:08 pm

Re: Does Arduino Core support OTA on the ESP32S2?

Postby mlefevre » Wed Aug 14, 2024 3:39 pm

I'm just uploading new sketches. I'm not using SPIFFS or LITTLEFS so it's just the sketches. I have not configured any security on the device (at least not intentionally). I can erase the flash with esptool and no special arguments.

mlefevre
Posts: 6
Joined: Sun Jun 16, 2024 4:08 pm

Re: Does Arduino Core support OTA on the ESP32S2?

Postby mlefevre » Wed Aug 14, 2024 3:42 pm

I assume that the OTA system is happy with the file since it proceeds to 100% during the upload phase. That progress is not just data transfer but actual flash programming, right? It seems like we get down to the very end and decide not to switch to the alternate OTA partition.

lbernstone
Posts: 1131
Joined: Mon Jul 22, 2019 3:20 pm

Re: Does Arduino Core support OTA on the ESP32S2?

Postby lbernstone » Wed Aug 14, 2024 5:30 pm

Please test with the OTAWebUpdater code and see if that works properly with the image.
The Update library checks that the first byte of the file is correct. Depending on how you implement it, it may not do any other checking on the validity of the image or the ota partition until that set_boot_partition command. The set_boot_partition is going to run a full image validation, which looks at the image metadata and matches it to the data. This also makes sure your bootloader matches your image (you cannot run an IDF 4.x image on a 5.x bootloader, eg).
Updater.cpp does not differentiate the various errors, but if you modify Updater.cpp to capture the result of that function, you can figure out why it is failing

Who is online

Users browsing this forum: Bing [Bot] and 1 guest