ketan vadodariya wrote: ↑Mon Dec 26, 2022 9:14 am
Hi,
Thank you for the details explanation, but I am not much expert on ESP32 device. This is the first time I used esp32 so not much knowledge on partition handling and spiffs stuff.
I just went through this with my application. The OTA only downloads one bin file, so it cannot do a SPIFS partition separately. Therefore, your code needs to handle the update of the SPIFS, if needed, when it boots up.
Would be mind to share the some sample code for handling such kind of stuff. ?
I figured this out by reading the ESP-IDF documentation online, which is pretty good documentation.
The `CMakeList.txt` file excerpt I showed in my prior post is what's needed to do the steps #1 and #2 I mentioned.
To do step #3, you need to be able to access the data that was attached in steps #1 and #2. This is described in the ESP-IDF documentation for the Build System, under
Embedding Binary Data. It gives a pretty clear example of the simple mechanism used to access the data.
Once you can access the data (which in this case, represents what you want your new SPIFFS partition contents to be), you'll want to compare that to the existing SPIFFS partition, one block of memory at a time. I picked a block size of 512 just so that I could stop the compare process pretty quickly if a difference is found (because then it's confirmed it's different, and the new partition data needs to be written).
Functions for accessing the partition data are described in ESP-IDF documentation under
SPI Flash API. Here, you'll find the following functions that you'll need:
`esp_partition_find_first` - finds a partition with specified attributes, such as partition type (so you can find the first SPIFFs partition, for example). It returns a pointer to a partition descriptor (a "handle", basically) which is type `esp_partition_t`.
`esp_partition_read` - reads data from the partition specified by the given partition descriptor
`esp_partition_erase_range` - erases a range of addresses in the given partition. If you check the ESP-IDF documentation, it says you need to erase the partition before you can re-write it.
`esp_partition_write` - writes data to the partition specified by the given partition descriptor.
These are the essential building blocks you need. Have a go at it and read the documentation. If you're not totally sure you can always try something as an experiment and see if what you tried works.