mirror of
https://github.com/espressif/esp-idf.git
synced 2026-04-27 11:03:11 +00:00
749c446a7e
Add a new CMake function esp_partition_flash_binary() that provides a unified API for registering partition data binaries to be flashed. It replaces the direct esptool_py_flash_target calls scattered across components (spiffs, fatfs, nvs_flash) with a single function that: - Resolves partition offset from the partition table automatically - Determines encryption requirements (auto-detect or ALWAYS_PLAINTEXT) - Creates per-partition flash targets (e.g. idf.py <partition>-flash) - Optionally includes the binary in `idf.py flash` via FLASH_IN_PROJECT On the linux target, the function registers binaries for pre-loading into the emulated flash. A build-time manifest (linux_flash_data.txt) is generated via file(GENERATE), and partition_linux.c reads it at runtime to copy each binary into the memory-mapped flash buffer at the correct offset. The partition_ops example is updated to use the new function and includes a custom_partition with pre-built data to demonstrate the full workflow, including on the linux target.
65 lines
2.6 KiB
CMake
65 lines
2.6 KiB
CMake
# spiffs_create_partition_image
|
|
#
|
|
# Create a spiffs image of the specified directory on the host during build and optionally
|
|
# have the created image flashed using `idf.py flash`
|
|
function(spiffs_create_partition_image partition base_dir)
|
|
set(options FLASH_IN_PROJECT)
|
|
set(multi DEPENDS)
|
|
cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}")
|
|
|
|
idf_build_get_property(idf_path IDF_PATH)
|
|
set(spiffsgen_py ${PYTHON} ${idf_path}/components/spiffs/spiffsgen.py)
|
|
|
|
get_filename_component(base_dir_full_path ${base_dir} ABSOLUTE)
|
|
|
|
partition_table_get_partition_info(size "--partition-name ${partition}" "size")
|
|
partition_table_get_partition_info(offset "--partition-name ${partition}" "offset")
|
|
|
|
if("${size}" AND "${offset}")
|
|
set(image_file ${CMAKE_BINARY_DIR}/${partition}.bin)
|
|
|
|
if(CONFIG_SPIFFS_USE_MAGIC)
|
|
set(use_magic "--use-magic")
|
|
endif()
|
|
|
|
if(CONFIG_SPIFFS_USE_MAGIC_LENGTH)
|
|
set(use_magic_len "--use-magic-len")
|
|
endif()
|
|
|
|
if(CONFIG_SPIFFS_FOLLOW_SYMLINKS)
|
|
set(follow_symlinks "--follow-symlinks")
|
|
endif()
|
|
|
|
# Execute SPIFFS image generation; this always executes as there is no way to specify for CMake to watch for
|
|
# contents of the base dir changing.
|
|
add_custom_target(spiffs_${partition}_bin ALL
|
|
COMMAND ${spiffsgen_py} ${size} ${base_dir_full_path} ${image_file}
|
|
--page-size=${CONFIG_SPIFFS_PAGE_SIZE}
|
|
--obj-name-len=${CONFIG_SPIFFS_OBJ_NAME_LEN}
|
|
--meta-len=${CONFIG_SPIFFS_META_LENGTH}
|
|
${follow_symlinks}
|
|
${use_magic}
|
|
${use_magic_len}
|
|
DEPENDS ${arg_DEPENDS}
|
|
)
|
|
|
|
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
|
|
ADDITIONAL_CLEAN_FILES
|
|
${image_file})
|
|
|
|
# Encryption for SPIFFS is not supported, so optional parameter ALWAYS_PLAINTEXT is passed to the function.
|
|
set(esp_partition_register_target_optional_args)
|
|
list(APPEND esp_partition_register_target_optional_args ALWAYS_PLAINTEXT DEPENDS spiffs_${partition}_bin)
|
|
|
|
if(arg_FLASH_IN_PROJECT)
|
|
list(APPEND esp_partition_register_target_optional_args FLASH_IN_PROJECT)
|
|
endif()
|
|
|
|
esp_partition_register_target(${partition} "${image_file}" ${esp_partition_register_target_optional_args})
|
|
else()
|
|
set(message "Failed to create SPIFFS image for partition '${partition}'. "
|
|
"Check project configuration if using the correct partition table file.")
|
|
fail_at_build_time(spiffs_${partition}_bin "${message}")
|
|
endif()
|
|
endfunction()
|