@leemoore1966, I'm glad you ask. Yes, I found a solution.
As a little background, here is my situation, in contrast to the original response I received to my question:
- I have an application that does not require the embedded web pages (or "web application") to operate since it operates with a REST API. So in that sense, the web application is not tightly coupled to my application. However, it is functionally coupled, of course, and is always provided as a convenience to the user as a pre-built client that uses the REST API.
- The embedded web application isn't terribly large, but it's large enough that it would be very impractical to simply make it a big pile of string data in the application partition itself.
Given the constraints, here is the solution that I came up with. I have two OTA application partitions but only one SPIFFs partition, as is required. I configured my application to build a SPIFFs partition file which is a .bin product output of the build process. I inject this binary into the elf using the technique described in
Embedding Binary Data. When my application boots up, it checks to see if the current SPIFFs partition matches the binary SPIFFs image embedded in the ELF file. This is done by a literal compare which is unsophisticated but effective and only takes a second. If it does not match, it copies the ELF SPIFF binary image to the SPIFFs partition. This way, the SPIFF partition will always match whatever application version is booted up. I use the `esp_partition_find_first`, `esp_partition_erase_range`, `esp_partition_read` and `esp_partition_write` functions to do this.
Here is the CMakeList.txt file at the main app level that I use:
Code: Select all
cmake_minimum_required(VERSION 3.16.0)
cmake_policy(SET CMP0076 NEW)
set(PROJECT_VER "1.0")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(MyProject)
# ..... OTHER STUFF IN MY CMakeList.txt .....
# Create the www SPIFFS partition binary and inject into elf
set(WWW_SIZE "0x30000") # This should match the size of the SPIFFs partition
set(WWW_DIR ${CMAKE_CURRENT_SOURCE_DIR}/web_root)
set(SPIFFSGEN_DIR ${IDF_PATH}/components/spiffs)
set(WWW_FILE "www.bin")
file(GLOB_RECURSE WWW_SRC ${WWW_DIR}/*.*)
if(EXISTS ${WWW_DIR})
add_custom_command(OUTPUT ${BUILD_DIR}/${WWW_FILE}
COMMAND python ${SPIFFSGEN_DIR}/spiffsgen.py ${WWW_SIZE} ${WWW_DIR} ${BUILD_DIR}/${WWW_FILE} --page-size=256 --obj-name-len=64 --meta-len=4 --use-magic --use-magic-len
DEPENDS ${WWW_SRC}
)
target_add_binary_data(${PROJECT_NAME}.elf ${BUILD_DIR}/${WWW_FILE} BINARY)
add_custom_target(www_fs DEPENDS ${BUILD_DIR}/${WWW_FILE})
add_dependencies(${PROJECT_NAME}.elf www_fs)
else()
message(FATAL_ERROR "${WWW_DIR} not found")
endif()
This is my partition file:
Code: Select all
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0xa000, 0x3000,
otadata, data, ota, 0xd000, 0x2000,
phy_init, data, phy, 0xf000, 0x1000,
ota_0, app, ota_0, 0x10000, 0x1e0000,
ota_1, app, ota_1, 0x1f0000,0x1e0000,
www, data, spiffs, 0x3D0000,0x30000
As you would expect, I need to have 0x30000 bytes of space available in both OTA partitions to contain the application code itself and the appropriate copy of the SPIFF partition data. This means I do have a redundant copy of the SPIFF image, but I have enough available memory, so it's not a problem for me and the convenience is worth it.