What values to use for "address" in esptool.py write_flash and read_flash functions?

sunbear
Posts: 9
Joined: Thu Jan 31, 2019 4:23 pm

What values to use for "address" in esptool.py write_flash and read_flash functions?

Postby sunbear » Mon Feb 04, 2019 4:01 pm

Examples from esptool.py github https://github.com/espressif/esptool

Code: Select all

esptool.py -p PORT -b 460800 read_flash 0 0x200000 flash_contents.bin
esptool.py --port COM4 write_flash 0x00000 my_app.elf-0x00000.bin 0x40000 my_app.elf-0x40000.bin
The first will read 2MB from the flash from it's origin 0 byte and dumps the data into a file named `flash_contents.bin`.
The second does 2 writes, one starting from 0 byte of the flash and the other from 0x40000 (i.e. 262144 bytes) of the flash.

Questions:
1. For read, how does one decide how much to read? For example, if the 2MB region that was read consist of multiple files, how do I extract them from flash_contents.bin? The flash region may also have been read partially, that is one of the files is stored beyond the 2MB mark, how does one avoid such an issue?
2. For write, how does one know where to write to w/o over writing existing data in the flash? How much padding should one apply between files when writing them?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: What values to use for "address" in esptool.py write_flash and read_flash functions?

Postby ESP_Angus » Tue Feb 05, 2019 12:35 am

sunbear wrote:
Mon Feb 04, 2019 4:01 pm
1. For read, how does one decide how much to read? For example, if the 2MB region that was read consist of multiple files, how do I extract them from flash_contents.bin? The flash region may also have been read partially, that is one of the files is stored beyond the 2MB mark, how does one avoid such an issue?
The answer to this depends on the software that's in use on the ESP32. If you use ESP-IDF then the flash layout is determined by the partition table for the project. The ESP-IDF build system will build the project and then print out the esptool.py command line to flash it correctly (based on that project's partition table), or it will flash it automatically if you use the "flash" target.

For Arduino the esptool command line (with all the addresses) is generated inside the Arduino IDE, you can find it in the console log if you enable "Verbose Upload" mode.

For other software projects, you'll have to check their reference materials or source code to see how they use the flash contents.
sunbear wrote:
Mon Feb 04, 2019 4:01 pm
2. For write, how does one know where to write to w/o over writing existing data in the flash? How much padding should one apply between files when writing them?
The flash chip erase sector size is 4096 bytes, so any individual file that's written will erase 4096 byte aligned blocks of size 4096 bytes before writing. esptool.py will produce an error if the command line specifies files which overlap into the same sector.

(The actual addresses don't need to be 4096 byte aligned, but each file should be contained within separate 4096 byte erase sectors in the flash, compared to its neighbours.)

If you need to pack files more closely, merge them into a single file on the host before flashing.

Who is online

Users browsing this forum: No registered users and 100 guests