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.