Flash firmware on ESP32 with esptool

Hi PlatformIO: I have been successful in flashing firmware on my ESP32 WROOM 32E using the Arduino enviroment on PlatformIO. I am uploading over the Program (UART) port on an ESP-PROG board. Now I would like to create a Python script to flash firmware on new devices for production.

I tried to use esptool.py to flash the firmware.bin that PlatformIO produces. I quickly found that there is also a bootloader that needs to be flashed. Even worse, the protocol seems to be a function of board-build.partitions, and I use different board-builds on different projects.

Is there a description somewhere of the flash protocol using esptool.py including the bootloader and other partitions needed? Is there another simple way to do it? (The ESP Flash Download Tool seems limited.) Or is this part of a secret sauce that is never talked about?

Any help would be appreciated, Thanks, Kevin

Using pio run once to build the firmware (or once for every environment with -e) and pio run -t nobuild -t upload is not enough? By using -t nobuild, PIO will directly jump to uploading the built firmware with the right parameters without compiling first.

Of course, a different approach would be to just do a verbose upload with pio run -e <env> -v -t upload to see the exact esptool.py invocation. Then just copy that into a shell script and execute it. As long as your partition table doesn’t dynmically change, that is sufficient and efficient.

Correct, see What values to use for "address" in esptool.py write_flash and read_flash functions? - ESP32 Forum.

I know this is a really old thread . . .

Is there documentation on the nobuild CLI feature?

I have an extra_scripts = pre:myscript.py which runs before each build and it even runs with the nobuild option. Is there a way to change this so it ONLY runs pre: build? Is there a way for my script.py to know whether this is a build or nobuild?

At this point, I took @maxgerhardt’s suggestion (Thank You) and ran a verbose upload and extracted the esptool.py command line and this works a treat. It is a really long command line !

You can use Flash Download Tools provided by espressif to flash the bin file to ESP32.

I record a video to show how to do it, if still have problem can leave a message to me.