Does Arduino Core support OTA on the ESP32S2?

mlefevre
Posts: 5
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
  1. Uploading: [============================================================] 99%
  2. Uploading: [============================================================] 99%
  3. Uploading: [============================================================] 100% Done...
  4.  
  5.  
  6. 04:19:52 [INFO]: Waiting for result...
  7. 04:19:52 [INFO]: Result: Could Not Activate The Firmware
  8.  
  9. 04:19:52 [INFO]: Result:
  10.  
  11. 04:19:52 [INFO]: Result:
  12. 04:19:52 [INFO]: Result:
  13. 04:19:52 [INFO]: Result:
  14. 04:19:52 [ERROR]: Error response from device
  15. *** [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:
  1. bool UpdateClass::_verifyEnd() {
  2.   if (_command == U_FLASH) {
  3.     if (!_enablePartition(_partition) || !_partitionIsBootable(_partition)) {
  4.       _abort(UPDATE_ERROR_READ);
  5.       return false;
  6.     }
  7.  
  8.     if (esp_ota_set_boot_partition(_partition)) {
  9.       _abort(UPDATE_ERROR_ACTIVATE);
  10.       return false;
  11.     }
  12.     _reset();
  13.     return true;
  14.   } else if (_command == U_SPIFFS) {
  15.     _reset();
  16.     return true;
  17.   }
  18.   return false;
  19. }
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:
  1. Name,   Type,   SubType,     Offset,     Size,      Flags
  2. nvs,      data,       nvs,     0x9000,   0x5000,
  3. otadata,  data,       ota,     0xE000,   0x2000,
  4. ota_0,       0,     ota_0,    0x10000, 0x1F0000,
  5. ota_1,       0,     ota_1,   0x200000, 0x1F0000,
  6. 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:
  1. # ESP-IDF Partition Table
  2. # Name,   Type, SubType, Offset,  Size, Flags
  3. # bootloader.bin,,          0x1000, 32K
  4. # partition table,          0x8000, 4K
  5.  
  6. nvs,      data, nvs,      0x9000,  20K,
  7. otadata,  data, ota,      0xe000,  8K,
  8. ota_0,    0,    ota_0,   0x10000,  1408K,
  9. ota_1,    0,    ota_1,  0x170000,  1408K,
  10. uf2,      app,  factory,0x2d0000,  256K,
  11. 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:
  1.  Name,   Type,   SubType,     Offset,     Size,      Flags
  2. nvs,      data,       nvs,     0x9000,   0x5000,
  3. otadata,  data,       ota,     0xE000,   0x2000,
  4. ota_0,       0,     ota_0,    0x10000, 0x1D0000,
  5. ota_1,       0,     ota_1,   0x1E0000, 0x1D0000,
  6. uf2,       app,   factory,   0x3B0000,  0x40000,
  7. 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:
  1. ; PlatformIO Project Configuration File
  2. ;
  3. ;   Build options: build flags, source filter
  4. ;   Upload options: custom upload port, speed and extra flags
  5. ;   Library options: dependencies, extra library storages
  6. ;   Advanced options: extra scripting
  7. ;
  8. ; Please visit documentation for the other options and examples
  9. ; https://docs.platformio.org/page/projectconf.html
  10.  
  11. [env]
  12. platform = espressif32
  13. board = WemosESP32S2miniV1
  14. framework = arduino
  15. build_type = debug
  16. board_build.partitions = ESP32S2mini.csv
  17.  
  18. monitor_speed = 115200
  19. monitor_port = COM27
  20. monitor_filters = esp32_exception_decoder
  21.  
  22. ; upload_protocol = esptool
  23. ; upload_resetmethod = nodemcu
  24. ; upload_port = COM4
  25. ;upload_flags = --after no_reset
  26.  
  27. upload_protocol = espota
  28. upload_port = .....
  29. upload_flags = --auth=admin
  30.                --port=3232
  31.  
  32. build_flags =
  33.     -DBOARD_HAS_PSRAM
  34.     -mfix-esp32-psram-cache-issue
  35.     -Wall
  36.     -DDEBUG
  37.     -std=gnu99
  38.     -Os
  39.     -u,vfprintf
  40.     -DUSER_SETUP_LOADED=1
  41.     -DST7789_DRIVER=1
  42.     -DTFT_RGB_ORDER=TFT_BGR
  43.     -DSPI_FREQUENCY=40000000
  44.     -DTFT_MISO=-1
  45.     -DTFT_MOSI=13
  46.     -DTFT_SCLK=14
  47.     -DTFT_CS=-1
  48.     -DTFT_DC=5
  49.     -DTFT_RST=4
  50.     -DLOAD_GFXFF=1
  51.  
  52. lib_extra_dirs =
  53.     C:\Users\marc\Documents\PlatformIO\Lib
  54.  
  55. lib_deps =
  56.     bodmer/TFT_eSPI@^2.5.43
  57.     bogde/HX711@^0.7.5
  58.     arcao/Syslog@^2.0.0
  59.     milesburton/DallasTemperature@^3.11.0
  60.     https://github.com/PaulStoffregen/OneWire.git
  61.     knolleary/PubSubClient@^2.8
  62.     bblanchon/ArduinoJson@^7.1.0
  63.  
  64.  
  65. [env:tool]
  66.  
  67. build_flags =
  68.    -DTOOL
  69.    -DCLIENT_NAME="\"CH101\""
  70.    -DMY_IP_ADDRESS="....."
  71.    -DNUM_TEMPERATURE_SENSORS=3
  72.  
  73.  
  74. [env:proto]
  75.  
  76. build_flags =
  77.    -DPROTO
  78.    -DCLIENT_NAME="\"CH102\""
  79.    -DMY_IP_ADDRESS="....."
  80.    -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: 828
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: 5
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: 5
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: 828
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: No registered users and 107 guests