Skip to content

Commit

Permalink
Added cmake script
Browse files Browse the repository at this point in the history
  • Loading branch information
shripad621git committed Nov 21, 2023
1 parent a3c5d19 commit 896cf6c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 1 deletion.
6 changes: 6 additions & 0 deletions config/esp32/components/chip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
78 changes: 78 additions & 0 deletions config/esp32/components/chip/factory.cmake
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 896cf6c

Please sign in to comment.