From 896cf6cb5a14c95fd77c947db956b350f76677de Mon Sep 17 00:00:00 2001 From: shripad621git Date: Thu, 9 Nov 2023 17:38:37 +0530 Subject: [PATCH] Added cmake script --- config/esp32/components/chip/CMakeLists.txt | 6 ++ config/esp32/components/chip/Kconfig | 8 ++- config/esp32/components/chip/factory.cmake | 78 +++++++++++++++++++++ 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 config/esp32/components/chip/factory.cmake diff --git a/config/esp32/components/chip/CMakeLists.txt b/config/esp32/components/chip/CMakeLists.txt index b2058fe75df41c..19e9fb168f3181 100644 --- a/config/esp32/components/chip/CMakeLists.txt +++ b/config/esp32/components/chip/CMakeLists.txt @@ -30,6 +30,7 @@ if(NOT CHIP_ROOT) endif() include(${CMAKE_CURRENT_LIST_DIR}/ota-image.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/factory.cmake) set(CHIP_REQUIRE_COMPONENTS esp_eth freertos lwip bt mbedtls fatfs app_update console openthread nvs_flash spi_flash) @@ -519,6 +520,11 @@ if(CONFIG_ENABLE_PW_RPC) endforeach() endif() +if(CONFIG_ENABLE_FACTORY_SCRIPT) + factory_partition_create_image(fctry esp_secure_cert ${CHIP_ROOT} FLASH_IN_PROJECT) + add_dependencies(factory app) +endif() + # Build Matter OTA image if (CONFIG_CHIP_OTA_IMAGE_BUILD) chip_ota_image(chip-ota-image diff --git a/config/esp32/components/chip/Kconfig b/config/esp32/components/chip/Kconfig index b73398bca4c2bf..ed8c541c425cd2 100644 --- a/config/esp32/components/chip/Kconfig +++ b/config/esp32/components/chip/Kconfig @@ -867,7 +867,7 @@ menu "CHIP Device Layer" then this option gets enabled. Also, please disable ESP_SECURE_CERT_DS_PERIPHERAL from the menuconfig when this option is disabled - config ENABLE_ESP_INSIGHTS_TRACE + config ENABLE_ESP_INSIGHTS_TRACE bool "Enable Matter ESP Insights" depends on ESP_INSIGHTS_ENABLED default y @@ -876,6 +876,12 @@ menu "CHIP Device Layer" Enabling the above option will enable the esp32 specific tracing functionality and report the diagnostic information to the insights cloud. + config ENABLE_FACTORY_SCRIPT + bool "enable factory script" + default n + help + Enable the factory partititon cmake scipt. + endmenu diff --git a/config/esp32/components/chip/factory.cmake b/config/esp32/components/chip/factory.cmake new file mode 100644 index 00000000000000..9c63d5504a4402 --- /dev/null +++ b/config/esp32/components/chip/factory.cmake @@ -0,0 +1,78 @@ +function(factory_partition_create_image partition1 partition2 esp_matter_dir) + set(options FLASH_IN_PROJECT) + set(multi DEPENDS) + cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}") + get_filename_component(esp_matter_dir_full_path ${esp_matter_dir} ABSOLUTE) + + set(mfg_tool_py ${PYTHON} ${esp_matter_dir}/scripts/tools/generate_esp32_chip_factory_bin.py) + + partition_table_get_partition_info(size1 "--partition-name ${partition1}" "size") + partition_table_get_partition_info(offset1 "--partition-name ${partition1}" "offset") + + partition_table_get_partition_info(size2 "--partition-name ${partition2}" "size") + partition_table_get_partition_info(offset2 "--partition-name ${partition2}" "offset") + + + message(STATUS "Size1 : ${size1}") + message(STATUS "offset1 : ${offset1}") + message(STATUS "Size2 : ${size2}") + message(STATUS "offset2 : ${offset2}") + if("${size1}" AND "${offset1}") + set(MY_BULB_NAME "My bulb") + set(VENDOR_NAME "Test-vendor") + set(HARDWARE_VERSION 1) + set(HARDWARE_VERSION_STR "Devkit") + set(VENDOR_ID 0xFFF2) + set(PRODUCT_ID 0x8001) + set(DAC_CERT "${esp_matter_dir_full_path}/credentials/test/attestation/Chip-Test-DAC-FFF2-8001-0008-Cert.der") + set(DAC_KEY "${esp_matter_dir_full_path}/credentials/test/attestation/Chip-Test-DAC-FFF2-8001-0008-Key.der") + set(PAI_CERT "${esp_matter_dir_full_path}/credentials/test/attestation/Chip-Test-PAI-FFF2-8001-Cert.der") + set(CERT_DCLRN "${esp_matter_dir_full_path}/credentials/test/certification-declaration/Chip-Test-CD-FFF2-8001.der") + set(PASSCODE 20202020) + set(DISCRIMINATOR 3841) + + # Execute Factory partition 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(factory ALL + COMMAND ${mfg_tool_py} -d ${DISCRIMINATOR} + -p ${PASSCODE} + --product-name "${MY_BULB_NAME}" + --vendor-name "${VENDOR_NAME}" + --vendor-id ${VENDOR_ID} + --product-id ${PRODUCT_ID} + --hw-ver ${HARDWARE_VERSION} + --hw-ver-str "${HARDWARE_VERSION_STR}" + --dac-cert ${DAC_CERT} + --dac-key ${DAC_KEY} + --pai-cert ${PAI_CERT} + --cd ${CERT_DCLRN} + --dac-in-secure-cert + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + + set(image_file1 ${CMAKE_BINARY_DIR}/bin/factory_partition.bin) + set(image_file2 ${CMAKE_BINARY_DIR}/bin/esp_secure_cert_partititon.bin) + idf_component_get_property(main_args esptool_py FLASH_ARGS) + idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS) + + esptool_py_flash_target(${partition1}-flash "${main_args}" "${sub_args}" ALWAYS_PLAINTEXT) + esptool_py_flash_to_partition(${partition1}-flash "${partition1}" "${image_file1}") + + esptool_py_flash_target(${partition2}-flash "${main_args}" "${sub_args}" ALWAYS_PLAINTEXT) + esptool_py_flash_to_partition(${partition2}-flash "${partition2}" "${image_file2}") + + add_dependencies(${partition1}-flash factory) + add_dependencies(${partition2}-flash factory) + + if(arg_FLASH_IN_PROJECT) + esptool_py_flash_to_partition(flash "${partition1}" "${image_file1}") + esptool_py_flash_to_partition(flash "${partition2}" "${image_file2}") + add_dependencies(flash factory) + endif() + else() + set(message "Failed to create Factory partition image for partition '${partition}'. " + "Check project configuration if using the correct partition table file.") + fail_at_build_time(factory_${partition}_bin "${message}") + + endif() +endfunction()