Skip to content

Conversation

@fdcavalcanti
Copy link
Contributor

Summary

  • documentation: update documentation for MCUBoot on Espressif devices
  • arch/risc-v: change offset for SPI Flash on Espressif devices
  • boards/risc-v: fixes SPI Flash for MCUBoot usage
    Adds partitions required for MCUBoot usage and a sample defconfig.
  • arch/xtensa: add E-Fuse support on ESP32S2
    Adds support for e-fuse on ESP32S2 and fixes a gitignore issue.
  • boards/xtensa: fixes SPI Flash for MCUBoot usage
    Fixes partitions for MCUBoot usage.

This PR modifies SPI Flash and E-Fuse related code to support OTA using MCUBoot.

Impact

  • Impact on user: Yes. Adds and fixes MCUBoot defconfig (mcuboot_update_agent) so the user can execute OTA.
  • Impact on build: No.
  • Impact on hardware: Affects ESP32|S2|S3|C3|C6 which have Wi-Fi support.
  • Impact on documentation: Yes, updates or adds sections to explain how to build and execute OTA.
  • Impact on security: No.
  • Impact on compatibility: No.

Testing

This example is valid for any of the SoCs affected. Tested on all of them and also CI tested.

Building

Part 1:
First build the default mcuboot_update_agent config. This image defaults to the primary slot and already comes with Wi-Fi settings enabled.

  • ./tools/configure.sh esp32-devkitc:mcuboot_update_agent
  • make bootloader
  • make
  • flash

Verify it boots ok and the message This is MCUBoot Update Agent image appears before Nuttshell is ready.

Connect to Wi-Fi:

nsh> wapi psk wlan0 espmint123 3
nsh> wapi essid wlan0 espmint 1
nsh> renew wlan0

Keep the board as is and move to part 2.

Part 2:

On menuconfig, change MCUBoot target slot to the 2nd slot and modify the MOTD as a mean to verify the new image is being used:

kconfig-tweak -d CONFIG_ESPRESSIF_ESPTOOL_TARGET_PRIMARY
kconfig-tweak -e CONFIG_ESPRESSIF_ESPTOOL_TARGET_SECONDARY
kconfig-tweak --set-str CONFIG_NSH_MOTD_STRING "This is MCUBoot UPDATED image!

Apply the changes with make olddefconfig and rebuild with make.

This will build a binary with secondary slot as target and a custom MOTD.

Running

At this point the board is already connected to Wi-Fi and has the primary image flashed. To execute OTA, create a simple HTTP server on the NuttX directory so we can access the binary remotely:

$ cd nuttxspace/nuttx
$ python -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...

On the board, execute the update agent, setting the IP address to the one on the host machine:

nsh> mcuboot_agent http://10.42.0.1:8000/nuttx.bin
MCUboot Update Agent example
Downloading from http://10.42.0.1:8000/nuttx.bin
Firmware Update size: 1048576 bytes
Received: 512      of 1048576 bytes [0%]
Received: 1024     of 1048576 bytes [0%]
Received: 1536     of 1048576 bytes [0%]

Wait until image is transferred and the board should reboot automatically:

Application Image successfully downloaded!
Requested update for next boot. Restarting...

Nuttshell should now show the new MOTD:

NuttShell (NSH) NuttX-10.4.0
This is MCUBoot UPDATED image!
nsh> 

At this point, the image is loaded but not confirmed. To make sure it won't rollback to the previous image, you must confirm with mcuboot_confirm and reboot the board. The OTA is now complete.

@github-actions github-actions bot added Area: Documentation Improvements or additions to documentation Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: xtensa Issues related to the Xtensa architecture Board: risc-v Board: xtensa Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Jul 16, 2025
@fdcavalcanti
Copy link
Contributor Author

Seems we have an error building esp32-devkitc/mcuboot_update_agent. Works fine locally, I guess MCUBoot download has failed.

Configuration/Tool: esp32-devkitc/mcuboot_update_agent
2025-07-16 16:45:24
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Building NuttX...

make: *** [tools/Unix.mk:559: nuttx] Error 1
make: Target 'all' not remade because of errors.
  [1/1] Normalize esp32-devkitc/mcuboot_update_agent

@xiaoxiang781216
Copy link
Contributor

xiaoxiang781216 commented Jul 17, 2025

@fdcavalcanti this error happen in many pr(e.g. this pr and #16734) recently:

 Traceback (most recent call last):
  File "/usr/local/bin/esptool.py", line 37, in <module>
    esptool._main()
  File "/usr/local/lib/python3.10/dist-packages/esptool/__init__.py", line 1170, in _main
    main()
  File "/usr/local/lib/python3.10/dist-packages/esptool/__init__.py", line 983, in main
    operation_func(args)
  File "/usr/local/lib/python3.10/dist-packages/esptool/cmds.py", line 1097, in elf2image
    image.save(args.output)
  File "/usr/local/lib/python3.10/dist-packages/esptool/bin_image.py", line 778, in save
    assert (f.tell() + 8 + self.ROM_LOADER.BOOTLOADER_FLASH_OFFSET) % (
AssertionError
make: *** [tools/Unix.mk:559: nuttx] Error 1
make: Target 'all' not remade because of errors.
  [1/1] Normalize esp32-devkitc/nxlooper

please fix it.

@fdcavalcanti fdcavalcanti force-pushed the feature/esp-mcuboot-fix branch from 811e8ca to f07e51b Compare July 21, 2025 11:46
@acassis
Copy link
Contributor

acassis commented Jul 21, 2025

@fdcavalcanti please update https://nuttx.apache.org/docs/latest/platforms/xtensa/esp32/boards/esp32-devkitc/index.html#mcuboot-update-agent to include the steps you included here. This will make life easier for those is testing it.

Fixes partitions for MCUBoot usage.

Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
Adds support for e-fuse on ESP32S2 and fixes a gitignore issue.

Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
Adds partitions required for MCUBoot usage and a sample defconfig.

Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
Updates MCUBoot documentation and usage example.

Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
@fdcavalcanti
Copy link
Contributor Author

@fdcavalcanti please update https://nuttx.apache.org/docs/latest/platforms/xtensa/esp32/boards/esp32-devkitc/index.html#mcuboot-update-agent to include the steps you included here. This will make life easier for those is testing it.

Do you mean the link to the video?

@xiaoxiang781216
Copy link
Contributor

@fdcavalcanti please fix the conflict

@acassis
Copy link
Contributor

acassis commented Jul 22, 2025

@fdcavalcanti please update https://nuttx.apache.org/docs/latest/platforms/xtensa/esp32/boards/esp32-devkitc/index.html#mcuboot-update-agent to include the steps you included here. This will make life easier for those is testing it.

Do you mean the link to the video?

No, I mean the Testing steps that you included here. This way users could test it locally

@fdcavalcanti
Copy link
Contributor Author

fdcavalcanti commented Jul 22, 2025

@fdcavalcanti please update https://nuttx.apache.org/docs/latest/platforms/xtensa/esp32/boards/esp32-devkitc/index.html#mcuboot-update-agent to include the steps you included here. This will make life easier for those is testing it.

Do you mean the link to the video?

No, I mean the Testing steps that you included here. This way users could test it locally

It's still there, just linked to a different section: here

@acassis acassis merged commit bbdb75b into apache:master Jul 22, 2025
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: xtensa Issues related to the Xtensa architecture Area: Documentation Improvements or additions to documentation Board: risc-v Board: xtensa Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants