| 
									
										
										
										
											2019-01-22 16:14:47 +08:00
										 |  |  | # 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)
 | 
					
						
							| 
									
										
										
										
											2019-05-05 15:42:39 +08:00
										 |  |  |     set(multi DEPENDS)
 | 
					
						
							|  |  |  |     cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}")
 | 
					
						
							| 
									
										
										
										
											2019-01-22 16:14:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-10 10:53:08 +08:00
										 |  |  |     idf_build_get_property(idf_path IDF_PATH)
 | 
					
						
							|  |  |  |     set(spiffsgen_py ${PYTHON} ${idf_path}/components/spiffs/spiffsgen.py)
 | 
					
						
							| 
									
										
										
										
											2019-01-22 16:14:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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")
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-05 14:52:14 +08:00
										 |  |  |     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 | 
					
						
							| 
									
										
										
										
											2023-05-08 15:41:30 +08:00
										 |  |  |             ADDITIONAL_CLEAN_FILES
 | 
					
						
							| 
									
										
										
										
											2019-11-05 14:52:14 +08:00
										 |  |  |             ${image_file})
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-20 09:55:02 +08:00
										 |  |  |         idf_component_get_property(main_args esptool_py FLASH_ARGS)
 | 
					
						
							|  |  |  |         idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
 | 
					
						
							| 
									
										
										
										
											2020-11-18 17:47:36 +08:00
										 |  |  |         # Last (optional) parameter is the encryption for the target. In our
 | 
					
						
							|  |  |  |         # case, spiffs is not encrypt so pass FALSE to the function.
 | 
					
						
							| 
									
										
										
										
											2020-11-26 12:19:41 +08:00
										 |  |  |         esptool_py_flash_target(${partition}-flash "${main_args}" "${sub_args}" ALWAYS_PLAINTEXT)
 | 
					
						
							| 
									
										
										
										
											2020-11-18 17:47:36 +08:00
										 |  |  |         esptool_py_flash_to_partition(${partition}-flash "${partition}" "${image_file}")
 | 
					
						
							| 
									
										
										
										
											2019-12-20 09:55:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-07 13:43:19 +08:00
										 |  |  |         add_dependencies(${partition}-flash spiffs_${partition}_bin)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-05 14:52:14 +08:00
										 |  |  |         if(arg_FLASH_IN_PROJECT)
 | 
					
						
							| 
									
										
										
										
											2020-11-18 17:47:36 +08:00
										 |  |  |             esptool_py_flash_to_partition(flash "${partition}" "${image_file}")
 | 
					
						
							| 
									
										
										
										
											2020-04-07 13:43:19 +08:00
										 |  |  |             add_dependencies(flash spiffs_${partition}_bin)
 | 
					
						
							| 
									
										
										
										
											2019-11-05 14:52:14 +08:00
										 |  |  |         endif()
 | 
					
						
							| 
									
										
										
										
											2019-01-22 16:14:47 +08:00
										 |  |  |     else()
 | 
					
						
							| 
									
										
										
										
											2019-11-05 14:52:14 +08:00
										 |  |  |         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}")
 | 
					
						
							| 
									
										
										
										
											2019-01-22 16:14:47 +08:00
										 |  |  |     endif()
 | 
					
						
							| 
									
										
										
										
											2019-07-14 16:45:35 +02:00
										 |  |  | endfunction()
 |