2. May 2023

How to build single flashable binary for ESP32 with esptool.py

Build of ESP-IDF project produces several files, like bootloader, application binary or partition table.

Having several files makes it harder to ship the application outside of build computer.

Solution to the problem is merging binaries into single flashable file.

Build your project with idf.py as always:

cd project
idf.py build

Merge binaries into single file. At the end of build process the tool will display command for flashing. This can be used to compose command like this:

esptool.py --chip ESP32 merge_bin -o merged-flash.bin --flash_mode dio ^
  --flash_size ^
  2MB 0x0 build\bootloader\bootloader.bin ^
  0x8000 build\partition_table\partition-table.bin ^
  0x10000 build\my_app.bin

Luckily there is a simpler way, because all those arguments are stored in build/flash_args file:

Example for Bash

(cd build; esptool.py --chip esp32 merge_bin -o merged-flash.bin @flash_args)

Example for PowerShell

cd build
esptool.py --chip esp32 merge_bin -o merged-flash.bin "@flash_args"