How to Extract a Binary File from ESP32 in Simple Words

Clone Your ESP32 Firmware in 6 Easy Steps

August 23, 2024 by Alessandro Colucci
extract binary file from esp32 image

If you’ve ever needed to clone your ESP32 or ESP8266, or simply back up its firmware, you’re in the right place. Today, I’m going to walk you through how to extract the binary file (often referred to as the "firmware") from your ESP32. This file can then be uploaded to another device, allowing you to replicate the exact functionality without needing the original source code.

Why Does This Matter?

Imagine you’ve spent countless hours perfecting your code on one ESP32, and now you want to duplicate this on multiple devices. Or maybe you want to safeguard your work by backing up the firmware. Extracting the binary file is the key to achieving this without the hassle of rewriting or copying code manually.

Step 1: Set Up Your Environment

First, make sure you have:

    • Arduino IDE: Installed and configured for ESP32 development.
    • esptool.py: This handy tool will help you extract the firmware.

Step 2: Enable Verbose Output in Arduino IDE

    1. Open your Arduino IDE.
    2. Go to File > Preferences.
    3. Check the boxes for Show verbose output during compilation and upload.

This allows you to see the commands used during the upload process, which we’ll need later.

Step 3: Upload Any Sketch (Or Skip This If Already Done)

If you don’t already have a sketch uploaded to your ESP32, go ahead and upload something simple, like a basic blink sketch.

Step 4: Extracting the Flash Memory

    1. Attempt an Upload: Start an upload process, but intentionally leave your ESP32 disconnected. This will cause the upload to fail.
    2. Copy the Command: In the output window, find the last command that starts with esptool.py and copy it.
    3. Modify the Command: Replace parts of the command to read the flash memory:
       
      esptool.py --chip esp32 --port COM3 --baud 115200 read_flash 0x00000 0x400000 firmware.bin
      • Note 1: COM3 should be replaced with your actual COM port.
      • Note 2: 0x400000 represents a 4MB flash size; adjust this if your ESP32 has a different flash size.
    4. Run the Command: Open your Command Prompt or Terminal, navigate to where esptool.py is located, and paste the modified command. Press Enter and hold the BOOT button on your ESP32 when prompted.

Step 5: Verify Your Extracted Firmware

The extracted firmware will be saved as firmware.bin in your chosen directory. This file contains all the code and data from your ESP32’s flash memory.

Step 6: Uploading to Another ESP32

To clone this firmware onto another ESP32, use the following command:

esptool.py --chip esp32 --port COM3 --baud 115200 write_flash 0x00000 firmware.bin

Replace COM3 with the correct port for the new ESP32. Press Enter, hold the BOOT button, and watch the magic happen!

Wrap-Up

By following these steps, you’ve mastered the art of extracting and cloning firmware on ESP32 devices. This method is not only useful but a huge time-saver when working with multiple devices. Whether you’re backing up your work or sharing it, this process ensures you have full control over your creations.

Got questions or tips of your own? Drop them in the comments here!

Chat with us on WhatsApp