I have a need to manually flash application data into ESP32 flash for use when it runs. Specifically, we have externally generated public and private SSL keys. My initial thinking was to use two separate data partitions. For the sake of some numbers, lets assume that they exist at:
0x20 0000 for 1K
0x20 0400 for 1K
I then got to thinking about using esptool to write data for 1K to 0x20 0000 and a second write of 1K to 0x20 0400
And here is where I started to get wobbly and nervous.
If I flash 1K of data to 0x20 0400 what if I then subsequently flash 1K of data to 0x20 0000 to 0x20 03FF? Do I need to worry about 4K page sizes? Is the unit of a write 4K? Is the 4K from 0x20 0000 to 0x20 0FFF erased before writing starting at 0x20 0000 and hence my data that exists at 0x20 0400 going to be overwritten?
[Answered] Small partitions and a concern about write sizes and esptool.
[Answered] Small partitions and a concern about write sizes and esptool.
Last edited by kolban on Fri Apr 27, 2018 2:28 pm, edited 1 time in total.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32
Re: Small partitions and a concern about write sizes and esptool.
Hi kolban,
You're right to be concerned about this. Recent versions of esptool will error out with an "overlap detected" error if you try to write two binaries that overlap the same sector.
On reflection, we should probably also enforce a requirement in the partition table that all partitions are sector-aligned, because otherwise there are chances that some of the partition APIs may error out in unexpected ways (I don't think they will erase data outside the partition, but you may find that you can't erase data where only part of the sector is in the partition.)
If you're using .pem format for your certificate and key, the easiest thing you can do is create a single .pem file which contains both private key and certificate (literally concatenate the two text files together). mbedTLS will parse the relevant key or certificate header as required.
If you're using .der format then it's probably easiest to keep them separate. You could use predefined offsets within the partition, or you could burn 3KB of flash and use 4KB partitions.
You're right to be concerned about this. Recent versions of esptool will error out with an "overlap detected" error if you try to write two binaries that overlap the same sector.
On reflection, we should probably also enforce a requirement in the partition table that all partitions are sector-aligned, because otherwise there are chances that some of the partition APIs may error out in unexpected ways (I don't think they will erase data outside the partition, but you may find that you can't erase data where only part of the sector is in the partition.)
If you're using .pem format for your certificate and key, the easiest thing you can do is create a single .pem file which contains both private key and certificate (literally concatenate the two text files together). mbedTLS will parse the relevant key or certificate header as required.
If you're using .der format then it's probably easiest to keep them separate. You could use predefined offsets within the partition, or you could burn 3KB of flash and use 4KB partitions.
Who is online
Users browsing this forum: Google [Bot] and 108 guests