cmake,make: Support SPIFFS image generation from build systems
This commit is contained in:
parent
ca06f73a51
commit
4d9c3a262d
2 changed files with 91 additions and 0 deletions
45
components/spiffs/Makefile.projbuild
Normal file
45
components/spiffs/Makefile.projbuild
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
SPIFFSGEN_PY:=$(COMPONENT_PATH)/spiffsgen.py
|
||||||
|
SPIFFSGEN_FLASH_IN_PROJECT=
|
||||||
|
|
||||||
|
ifdef CONFIG_SPIFFS_USE_MAGIC
|
||||||
|
USE_MAGIC = "--use-magic"
|
||||||
|
else
|
||||||
|
USE_MAGIC = ""
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef CONFIG_SPIFFS_USE_MAGIC_LENGTH
|
||||||
|
USE_MAGIC_LEN = "--use-magic-len"
|
||||||
|
else
|
||||||
|
USE_MAGIC_LEN = ""
|
||||||
|
endif
|
||||||
|
|
||||||
|
# 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 `make flash`
|
||||||
|
define spiffs_create_partition_image
|
||||||
|
|
||||||
|
|
||||||
|
$(1)_bin: $(PARTITION_TABLE_BIN) | check_python_dependencies
|
||||||
|
partition_size=`$(GET_PART_INFO) --partition-name $(1) \
|
||||||
|
--partition-table-file $(PARTITION_TABLE_BIN) \
|
||||||
|
get_partition_info --info size`; \
|
||||||
|
$(PYTHON) $(SPIFFSGEN_PY) $$$$partition_size $(2) $(BUILD_DIR_BASE)/$(1).bin \
|
||||||
|
--page-size=$(CONFIG_SPIFFS_PAGE_SIZE) \
|
||||||
|
--obj-name-len=$(CONFIG_SPIFFS_OBJ_NAME_LEN) \
|
||||||
|
--meta-len=$(CONFIG_SPIFFS_META_LENGTH) \
|
||||||
|
$(USE_MAGIC) \
|
||||||
|
$(USE_MAGIC_LEN)
|
||||||
|
|
||||||
|
all_binaries: $(1)_bin
|
||||||
|
print_flash_cmd: $(1)_bin
|
||||||
|
|
||||||
|
# Append the created binary to esptool_py args if FLASH_IN_PROJECT is set
|
||||||
|
ifeq ($(3), FLASH_IN_PROJECT)
|
||||||
|
SPIFFSGEN_FLASH_IN_PROJECT += $(1)
|
||||||
|
endif
|
||||||
|
endef
|
||||||
|
|
||||||
|
ESPTOOL_ALL_FLASH_ARGS += $(foreach partition,$(SPIFFSGEN_FLASH_IN_PROJECT), \
|
||||||
|
$(shell $(GET_PART_INFO) --partition-name $(partition) \
|
||||||
|
--partition-table-file $(PARTITION_TABLE_BIN) get_partition_info --info offset) $(BUILD_DIR_BASE)/$(partition).bin)
|
46
components/spiffs/project_include.cmake
Normal file
46
components/spiffs/project_include.cmake
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
# 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)
|
||||||
|
cmake_parse_arguments(arg "${options}" "" "" "${ARGN}")
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
# 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}
|
||||||
|
${use_magic}
|
||||||
|
${use_magic_len}
|
||||||
|
)
|
||||||
|
|
||||||
|
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" APPEND PROPERTY
|
||||||
|
ADDITIONAL_MAKE_CLEAN_FILES
|
||||||
|
${image_file})
|
||||||
|
|
||||||
|
if(arg_FLASH_IN_PROJECT)
|
||||||
|
esptool_py_flash_project_args(${partition} ${offset} ${image_file} FLASH_IN_PROJECT)
|
||||||
|
else()
|
||||||
|
esptool_py_flash_project_args(${partition} ${offset} ${image_file})
|
||||||
|
endif()
|
||||||
|
endfunction()
|
Loading…
Reference in a new issue