2019-04-28 03:38:23 -04:00
|
|
|
idf_component_register()
|
2018-03-22 02:27:10 -04:00
|
|
|
|
2019-05-09 22:53:08 -04:00
|
|
|
if(BOOTLOADER_BUILD)
|
|
|
|
return()
|
|
|
|
endif()
|
2018-08-16 01:01:43 -04:00
|
|
|
|
|
|
|
set(partition_csv "${PARTITION_CSV_PATH}")
|
2018-01-17 20:12:13 -05:00
|
|
|
|
|
|
|
if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
|
2018-02-26 23:45:30 -05:00
|
|
|
set(unsigned_partition_bin "partition-table-unsigned.bin")
|
|
|
|
set(final_partition_bin "partition-table.bin")
|
|
|
|
set(final_partition_target "sign_partition_table")
|
2018-01-17 20:12:13 -05:00
|
|
|
else()
|
2018-02-26 23:45:30 -05:00
|
|
|
set(unsigned_partition_bin "partition-table.bin")
|
|
|
|
set(final_partition_bin "partition-table.bin")
|
|
|
|
set(final_partition_target "build_partition_table")
|
2018-01-17 20:12:13 -05:00
|
|
|
endif()
|
|
|
|
|
2018-01-18 23:47:49 -05:00
|
|
|
if(CONFIG_PARTITION_TABLE_MD5)
|
|
|
|
set(md5_opt --disable-md5sum)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_ESPTOOLPY_FLASHSIZE)
|
|
|
|
set(flashsize_opt --flash-size ${CONFIG_ESPTOOLPY_FLASHSIZE})
|
|
|
|
endif()
|
|
|
|
|
2018-10-19 15:02:55 -04:00
|
|
|
if(CONFIG_SECURE_BOOT_ENABLED AND NOT CONFIG_SECURE_BOOT_ALLOW_SHORT_APP_PARTITION)
|
|
|
|
set(partition_secure_opt --secure)
|
|
|
|
else()
|
|
|
|
set(partition_secure_opt "")
|
|
|
|
endif()
|
|
|
|
|
2019-05-09 22:53:08 -04:00
|
|
|
idf_build_get_property(build_dir BUILD_DIR)
|
|
|
|
idf_build_get_property(python PYTHON)
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT "${build_dir}/partition_table/${unsigned_partition_bin}"
|
|
|
|
COMMAND "${python}" "${CMAKE_CURRENT_SOURCE_DIR}/gen_esp32part.py"
|
2018-11-11 02:36:10 -05:00
|
|
|
-q --offset ${PARTITION_TABLE_OFFSET} ${md5_opt} ${flashsize_opt}
|
2019-05-09 22:53:08 -04:00
|
|
|
${partition_secure_opt} ${partition_csv} ${build_dir}/partition_table/${unsigned_partition_bin}
|
2018-01-18 23:47:49 -05:00
|
|
|
DEPENDS ${partition_csv} "${CMAKE_CURRENT_SOURCE_DIR}/gen_esp32part.py"
|
|
|
|
VERBATIM)
|
2018-01-17 20:12:13 -05:00
|
|
|
|
|
|
|
# Add signing steps
|
|
|
|
if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
|
2019-01-21 22:45:45 -05:00
|
|
|
add_custom_target(gen_unsigned_partition_bin ALL DEPENDS
|
2019-05-09 22:53:08 -04:00
|
|
|
"${build_dir}/partition_table/${unsigned_partition_bin}")
|
2018-11-11 02:36:10 -05:00
|
|
|
|
2019-05-09 22:53:08 -04:00
|
|
|
add_custom_command(OUTPUT "${build_dir}/partition_table/${final_partition_bin}"
|
2018-10-19 15:02:55 -04:00
|
|
|
COMMAND ${ESPSECUREPY} sign_data --keyfile "${secure_boot_signing_key}"
|
2019-05-09 22:53:08 -04:00
|
|
|
-o "${build_dir}/partition_table/${final_partition_bin}"
|
|
|
|
"${build_dir}/partition_table/${unsigned_partition_bin}"
|
|
|
|
DEPENDS "${build_dir}/partition_table/${unsigned_partition_bin}"
|
2018-02-26 23:45:30 -05:00
|
|
|
VERBATIM)
|
2018-01-17 20:12:13 -05:00
|
|
|
endif()
|
|
|
|
|
2018-08-26 23:55:04 -04:00
|
|
|
if(EXISTS ${partition_csv})
|
2019-05-09 22:53:08 -04:00
|
|
|
add_custom_target(partition_table ALL DEPENDS "${build_dir}/partition_table/${final_partition_bin}")
|
2018-08-26 23:55:04 -04:00
|
|
|
else()
|
2018-10-19 15:02:55 -04:00
|
|
|
# If the partition input CSV is not found, create a phony partition_table target that
|
|
|
|
# fails the build. fail_at_build_time also touches CMakeCache.txt to cause a cmake run next time
|
2018-08-26 23:55:04 -04:00
|
|
|
# (to pick up a new CSV if one exists, etc.)
|
2018-10-19 15:02:55 -04:00
|
|
|
fail_at_build_time(partition_table
|
|
|
|
"Partition table CSV ${partition_csv} does not exist."
|
|
|
|
"Either change partition table in menuconfig or create this input file.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(CONFIG_SECURE_BOOT_ENABLED AND
|
|
|
|
NOT CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
|
|
|
|
add_custom_command(TARGET partition_table POST_BUILD
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"Partition table built but not signed. Sign partition data before flashing:"
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E echo
|
|
|
|
"\t${ESPSECUREPY} sign_data --keyfile KEYFILE ${CMAKE_CURRENT_BINARY_DIR}/${final_partition_bin}"
|
|
|
|
VERBATIM)
|
2018-08-26 23:55:04 -04:00
|
|
|
endif()
|
|
|
|
|
2019-02-13 04:32:23 -05:00
|
|
|
# If anti-rollback option is set then factory partition should not be in Partition Table.
|
|
|
|
# In this case, should be used the partition table with two ota app without the factory.
|
2019-03-22 03:24:23 -04:00
|
|
|
partition_table_get_partition_info(factory_offset "--partition-type app --partition-subtype factory" "offset")
|
2019-05-09 08:10:35 -04:00
|
|
|
if(CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK AND factory_offset)
|
2019-02-13 04:32:23 -05:00
|
|
|
fail_at_build_time(check_table_contents
|
|
|
|
"ERROR: Anti-rollback option is enabled. Partition table should consist of two ota app without factory partition.")
|
|
|
|
add_dependencies(bootloader check_table_contents)
|
|
|
|
add_dependencies(app check_table_contents)
|
|
|
|
endif()
|
|
|
|
|
2018-08-26 23:55:04 -04:00
|
|
|
add_dependencies(bootloader partition_table)
|
|
|
|
add_dependencies(app partition_table)
|
2018-01-18 23:47:49 -05:00
|
|
|
|
2018-02-26 23:45:30 -05:00
|
|
|
# Use global properties ESPTOOL_WRITE_FLASH_ARGS to pass this info to build
|
|
|
|
# the list of esptool write arguments for flashing
|
|
|
|
set_property(GLOBAL APPEND_STRING PROPERTY
|
|
|
|
ESPTOOL_WRITE_FLASH_ARGS
|
2019-05-09 22:53:08 -04:00
|
|
|
"${PARTITION_TABLE_OFFSET} ${build_dir}/partition_table/${final_partition_bin} ")
|
2018-01-17 20:12:13 -05:00
|
|
|
|
2019-01-21 22:45:45 -05:00
|
|
|
esptool_py_flash_project_args(partition_table ${PARTITION_TABLE_OFFSET}
|
2019-05-09 22:53:08 -04:00
|
|
|
${build_dir}/partition_table/partition-table.bin FLASH_IN_PROJECT)
|
2019-01-21 22:45:45 -05:00
|
|
|
|
2019-05-09 22:53:08 -04:00
|
|
|
partition_table_get_partition_info(app_partition_offset "--partition-boot-default" "offset")
|
|
|
|
esptool_py_flash_project_args(app ${app_partition_offset} ${build_dir}/${PROJECT_BIN} FLASH_IN_PROJECT)
|
2019-01-21 22:45:45 -05:00
|
|
|
|
2019-01-21 09:14:56 -05:00
|
|
|
if(CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT)
|
|
|
|
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/flash_encrypted_app_args.in "--encrypt ${app_partition_offset} ${PROJECT_BIN}")
|
|
|
|
esptool_py_flash_project_args(encrypted_app ${app_partition_offset} ${build_dir}/${PROJECT_BIN}
|
|
|
|
FLASH_FILE_TEMPLATE ${CMAKE_CURRENT_BINARY_DIR}/flash_encrypted_app_args.in)
|
|
|
|
endif()
|
2018-11-11 02:36:10 -05:00
|
|
|
|