Bin image consists of an image header https://github.com/espressif/esptool/wi ... ile-header (ESP32 header is a bit longer) and segments https://github.com/espressif/esptool/wi ... at#segment.
ROM bootloader reads image header and interprets the next bytes as segment header. Segment header contains also information about how big the segment is. Bootloader reads (and tries to copy) data in that segment and right after that data it expects another segment header and so on.
Bin image should look like:
[Image headers][Segment 0 headers][Segment 0 data][Segment 1 headers][Segment 1 data] ....
So basically we need at least padding segment headers so that bootloader could work correctly. We do not need to send segment data themself. But we would have to do something like:
Code: Select all
esptool.py --chip esp32 write_flash 0x10000 app_part1.bin 0x4000000 app_part2.bin ...
ESP_Angus wrote:Pretty much. ROM bootloader (ie first stage bootloader) actually uses this header to further configure the SPI flash (based on mode, flash frequency, flash size which are all encoded there).michprev wrote:So after first stage bootloader configures SPI flash it does something like this (lets assume we do not use secure boot):
- check image header at 0x1000 as described here https://github.com/espressif/esptool/wi ... ile-header (ESP32 probably has additional bytes in header)
There's an additional 16 bytes of header for ESP32, for a total of 24. Most of this extra header is unused (see the load_extended_header function in esptool.py if you're interested).
For the ROM bootloader, it actually tries to copy every segment to the specified load address. If the load address is in a flash cache mapped space then I believe what you'll get is essentially a lot of no-op writes as it reads from flash and discards the output by writing it into a black hole.michprev wrote: [*] iterate over segments with their headers as described here https://github.com/espressif/esptool/wi ... at#segment; based on memory offset decide[/list]
- if this is a RAM segment copy it to the corresponding RAM space
- if this is a flash segment leave it right as it is
(This is one of the reasons the ESP-IDF software bootloader runs 100% from IRAM/DRAM.)
This is also why any padding segments (mapped at address 0x0) cause it to crash (memory protection is applied for 0x0)..