guild icon
Toit
#Building a single binary .bin to flash to a device
Thread channel in help
addshore
addshore 12/10/2025 04:36 PM
In order to get a single binary easily for flashing on a device, we have flashed it to a device and read it back.
Something like...
- jag toit tool firmware --envelope=.\ble.envelope flash -pCOM70
- esptool.exe -p COM70 -b 460800 read_flash 0 ALL ble_adv_500.bin
Is there an easy way to get and or reconstruct such as binary using the toit firmware commands that I am missing?
addshore
addshore 12/10/2025 04:37 PM
TLDR this is basically for trying to make using https://docs.espressif.com/projects/esp-test-tools/en/latest/esp32/production_stage/tools/flash_download_tool.html as simple as possible, and being able to provide a single binary file for position 0
bitphlipphar
bitphlipphar 12/10/2025 05:50 PM
jag toit tool firmware extract --help
bitphlipphar
bitphlipphar 12/10/2025 05:51 PM
So something like jag toit tool firmware --envelope=ble.envelope extract --format=binary -o ble_adv_500.bin?
addshore
addshore 12/10/2025 06:24 PM
Perhaps looks at his notes from a few weeks back
addshore
addshore 12/10/2025 06:25 PM
Yes, I think thats basically what I want, and I must have also found it, I'm now wondering why I might have decided that didnt work?
It was potentially something like the bin didnt work / didnt appear to have everything in it, but let me retry shortly and see
(edited)
addshore
addshore 12/10/2025 09:23 PM
So I tried flashing this binary (from the extract command)
and post flash I just get something like this

> jag monitor Starting serial monitor of port 'COM14' ... ESP-ROM:esp32c6-20220919 Build:Sep 19 2022 rst:0x15 (USB_UART_HPSYS),boot:0x6f (SPI_FAST_FLASH_BOOT) Saved PC:0x4080082e SPIWP:0xee mode:DIO, clock div:2 load:0x42130020,len:0x489c4 load:0x40800000,len:0x762c load:0x42000020,len:0x12a814 Invalid image block, can't boot. ets_main.c 331
addshore
addshore 12/10/2025 09:24 PM
vs if I flash the envelope to the device, and read the flash back into a bin file, then use that with the esp flashing tool, it works
bitphlipphar
bitphlipphar 12/11/2025 06:18 AM
Interesting.
addshore
addshore 12/11/2025 10:37 AM
I wonder what the different between the 2 bin files looks like, lemme have a look
bitphlipphar
bitphlipphar 12/11/2025 10:42 AM
I wonder if we can repro this on an ordinary esp32.
addshore
addshore 12/11/2025 10:43 AM
So the one downloaded from the device is 4096KB (whole flash size), vs 1644KB for the extract one.
and it looks like there is a bucnh of stuff at the start missing?
addshore
addshore 12/11/2025 10:44 AM
left is the esp dump, right is from the extract tool(edited)
bitphlipphar
bitphlipphar 12/11/2025 10:44 AM
Bootloader?
addshore
addshore 12/11/2025 10:44 AM
Right, so the bin from the extract I can't just put in position 0? (I thought it might also include bootloader), but the bootloader is only added as part of jag flash ?
addshore
addshore 12/11/2025 10:45 AM
What would be neat is basically some ourput or dump from the flash command, so i could add -o full.bin or such, that gives me a full binary of everything that would be flashed in the correct locations
addshore
addshore 12/11/2025 10:46 AM
And yes it looks like bootloader, and liekly the partition table too
addshore
addshore 12/11/2025 10:46 AM
bitphlipphar
bitphlipphar 12/11/2025 10:49 AM
I would think we add the bootloader also when extracting.
bitphlipphar
bitphlipphar 12/11/2025 10:50 AM
Hmm.
bitphlipphar
bitphlipphar 12/11/2025 10:51 AM
Maybe I'm confusing myself but can you try with --format=image?
addshore
addshore 12/11/2025 10:52 AM
oooh, thats bigger
addshore
addshore 12/11/2025 10:52 AM
at a guess thats correct, will try flashing shortly
bitphlipphar
bitphlipphar 12/11/2025 10:54 AM
The naming is quite confusing here.

- binary: the binary app partition. This format can be used with the 'esptool' tool. - elf: the ELF file of the executable. This is typically used for debugging. - ubjson: a UBJSON encoding of the sections of the image. - image: a binary image suitable for running on QEMU, Wokwi, or for flashing a device. See below.
bitphlipphar
bitphlipphar 12/11/2025 10:54 AM
This is the help for the --format option.
bitphlipphar
bitphlipphar 12/11/2025 10:54 AM
We often put images in .bin files, which adds to the confusion.
bitphlipphar
bitphlipphar 12/11/2025 10:54 AM
We also use the term image for programs (sometimes).
bitphlipphar
bitphlipphar 12/11/2025 10:55 AM
The "This format can be used with the 'esptool' tool." comment associated with --format=binary seems unhelpful.
🔥1
addshore
addshore 12/11/2025 12:34 PM
maybe this tweak will help https://github.com/toitlang/toit/pull/2957
Clarified usage instructions for firmware extraction formats, specifically binary vs image, mentioning esptool in both
addshore
addshore 12/11/2025 12:34 PM
seems I still need to get to sign the CLA? :p
bitphlipphar
bitphlipphar 12/11/2025 12:48 PM
Should we mention the right format to use for the instructions around line 640 too?
bitphlipphar
bitphlipphar 12/11/2025 12:49 PM
There we use the "binary image" terminology, which is nicely confusing.
32 messages in total