Page 1 of 1

esptool for bare flashing bare metal-binary?

Posted: Wed Nov 12, 2025 4:02 pm
by JohnnyZ
Is it possible to use esptool.py for flashing non-IDF bare metal (without bootloader and partition) binaries?
I tried:

Code: Select all

esptool --chip esp32c3 erase-flash
esptool --chip esp32c3 elf2image --flash-mode dio --flash-freq 80m --flash-size 2MB --min-rev 3 --min-rev-full 3 --max-rev-full 199 -o fw.bin fw.elf
esptool --chip esp32c3 --before=default-reset --after=hard-reset write-flash --flash-mode dio --flash-freq 80m --flash-size 2MB 0x0 fw.bin

But application won't work:

Code: Select all

ESP-ROM:esp32c3-api1-20210207
Build:Feb  7 2021
rst:0x7 (TG0WDT_SYS_RST),boot:0xf (SPI_FAST_FLASH_BOOT)
Saved PC:0x40052b02
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fc84000,len:0x28
load:0x40384300,len:0x33c
load:0x00000000,len:0xfc64
load:0x42000000,len:0x11f04
entry 0x420000a4
Guru Meditation Error: Core 0 panic'ed (Illegal instruction)
Core 0 register dump:
PC      : 0x420000a4  RA      : 0x4004a296  SP      : 0x3fcde560  GP      : 0x00000000
TP      : 0x00000000  T0      : 0x00000000  T1      : 0x00000000  T2      : 0x3fcde59c
S0      : 0x00021f10  S1      : 0x00000030  A0      : 0x00000011  A1      : 0x0000000a
A2      : 0x00000000  A3      : 0x6000001c  A4      : 0x00000000  A5      : 0x420000a4
A6      : 0x80000000  A7      : 0x00000010  S2      : 0x00000000  S3      : 0x3fce0000
S4      : 0x0000ffff  S5      : 0x3ff1c14c  S6      : 0x00021f04  S7      : 0x3fcdf000
S8      : 0x00000000  S9      : 0x00000000  S10     : 0x00000000  S11     : 0x00000000
T3      : 0x00000000  T4      : 0x00000080  T5      : 0x30000000  T6      : 0x00000000
MSTATUS : 0x00001881  MCAUSE  : 0x00000002  MTVAL   : 0x00000000  INTLEVEL: 0x00000001

Generated file looks ok:

Code: Select all

esptool v5.1.0
Image size: 139056 bytes
Detected image type: ESP32-C3

ESP32-C3 Image Header
=====================
Image version: 1
Entry point: 0x420000a4
Segments: 4
Flash size: 2MB
Flash freq: 80m
Flash mode: DIO

ESP32-C3 Extended Image Header
==============================
WP pin: 0xee (disabled)
Flash pins drive settings: clk_drv: 0x0, q_drv: 0x0, d_drv: 0x0, cs0_drv: 0x0, hd_drv: 0x0, wp_drv: 0x0
Chip ID: 5 (ESP32-C3)
Minimal chip revision: v0.3, (legacy min_rev = 3)
Maximal chip revision: v1.99

Segments Information
====================
Segment   Length   Load addr   File offs  Memory types
-------  -------  ----------  ----------  ------------
      0  0x00028  0x3fc84000  0x00000018  DRAM
      1  0x0033c  0x40384300  0x00000048  IRAM
      2  0x0fc64  0x00000000  0x0000038c  PADDING
      3  0x11f04  0x42000000  0x0000fff8  IROM

ESP32-C3 Image Footer
=====================
Checksum: 0x30 (valid)
Validation hash: 12500cf2deba948c85f3ec323412a970312022db3b076e034661a651b5f7c3b9 (valid)

Start address is okay:

Code: Select all

readelf -h fw.elf | grep Entry
  Entry point address:               0x420000a4

Same ELF can be flashed with (older version) of esp-flash-rs:

Code: Select all

espflash flash -p /dev/esp32 fw.elf

Is there a way to flash bare-metal non-IDF application ELF to the ESP32-C3 with official tools?

Re: esptool for bare flashing bare metal-binary?

Posted: Wed Nov 12, 2025 4:30 pm
by lbernstone
You need all the other files that go along with the firmware: partition table, 2nd stage bootloader, etc. There is a function in esptool (merge_bin) to merge all the contents into a single file for easy distribution.
If you want to replace just the firmware on a device without touching the auxiliary files, you can use the parttool.py, which will inspect the partition table for you and then copy it over.
If you have a good image on a device that you then want to distribute, you can also just use esptool read_flash to write the whole flash contents into a single file.

Re: esptool for bare flashing bare metal-binary?

Posted: Wed Nov 12, 2025 5:29 pm
by JohnnyZ
I have non-C bare metal application which I want to run from flash of the ESP32-C3. I don't want to use bootloader nor partitions.

Flashing that application to the MCU works with unofficial tools. I am interested in doing that with official esptool (take .elf, do "something with it" and flash it to the flash of the MCU via UART).