Skip to content

Commit 896cf6c

Browse files
committed
Added cmake script
1 parent a3c5d19 commit 896cf6c

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

config/esp32/components/chip/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ if(NOT CHIP_ROOT)
3030
endif()
3131

3232
include(${CMAKE_CURRENT_LIST_DIR}/ota-image.cmake)
33+
include(${CMAKE_CURRENT_LIST_DIR}/factory.cmake)
3334

3435
set(CHIP_REQUIRE_COMPONENTS esp_eth freertos lwip bt mbedtls fatfs app_update console openthread nvs_flash spi_flash)
3536

@@ -519,6 +520,11 @@ if(CONFIG_ENABLE_PW_RPC)
519520
endforeach()
520521
endif()
521522

523+
if(CONFIG_ENABLE_FACTORY_SCRIPT)
524+
factory_partition_create_image(fctry esp_secure_cert ${CHIP_ROOT} FLASH_IN_PROJECT)
525+
add_dependencies(factory app)
526+
endif()
527+
522528
# Build Matter OTA image
523529
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
524530
chip_ota_image(chip-ota-image

config/esp32/components/chip/Kconfig

+7-1
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ menu "CHIP Device Layer"
867867
then this option gets enabled.
868868
Also, please disable ESP_SECURE_CERT_DS_PERIPHERAL from the menuconfig when this option is disabled
869869

870-
config ENABLE_ESP_INSIGHTS_TRACE
870+
config ENABLE_ESP_INSIGHTS_TRACE
871871
bool "Enable Matter ESP Insights"
872872
depends on ESP_INSIGHTS_ENABLED
873873
default y
@@ -876,6 +876,12 @@ menu "CHIP Device Layer"
876876
Enabling the above option will enable the esp32 specific tracing functionality and report the
877877
diagnostic information to the insights cloud.
878878

879+
config ENABLE_FACTORY_SCRIPT
880+
bool "enable factory script"
881+
default n
882+
help
883+
Enable the factory partititon cmake scipt.
884+
879885
endmenu
880886

881887

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
function(factory_partition_create_image partition1 partition2 esp_matter_dir)
2+
set(options FLASH_IN_PROJECT)
3+
set(multi DEPENDS)
4+
cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}")
5+
get_filename_component(esp_matter_dir_full_path ${esp_matter_dir} ABSOLUTE)
6+
7+
set(mfg_tool_py ${PYTHON} ${esp_matter_dir}/scripts/tools/generate_esp32_chip_factory_bin.py)
8+
9+
partition_table_get_partition_info(size1 "--partition-name ${partition1}" "size")
10+
partition_table_get_partition_info(offset1 "--partition-name ${partition1}" "offset")
11+
12+
partition_table_get_partition_info(size2 "--partition-name ${partition2}" "size")
13+
partition_table_get_partition_info(offset2 "--partition-name ${partition2}" "offset")
14+
15+
16+
message(STATUS "Size1 : ${size1}")
17+
message(STATUS "offset1 : ${offset1}")
18+
message(STATUS "Size2 : ${size2}")
19+
message(STATUS "offset2 : ${offset2}")
20+
if("${size1}" AND "${offset1}")
21+
set(MY_BULB_NAME "My bulb")
22+
set(VENDOR_NAME "Test-vendor")
23+
set(HARDWARE_VERSION 1)
24+
set(HARDWARE_VERSION_STR "Devkit")
25+
set(VENDOR_ID 0xFFF2)
26+
set(PRODUCT_ID 0x8001)
27+
set(DAC_CERT "${esp_matter_dir_full_path}/credentials/test/attestation/Chip-Test-DAC-FFF2-8001-0008-Cert.der")
28+
set(DAC_KEY "${esp_matter_dir_full_path}/credentials/test/attestation/Chip-Test-DAC-FFF2-8001-0008-Key.der")
29+
set(PAI_CERT "${esp_matter_dir_full_path}/credentials/test/attestation/Chip-Test-PAI-FFF2-8001-Cert.der")
30+
set(CERT_DCLRN "${esp_matter_dir_full_path}/credentials/test/certification-declaration/Chip-Test-CD-FFF2-8001.der")
31+
set(PASSCODE 20202020)
32+
set(DISCRIMINATOR 3841)
33+
34+
# Execute Factory partition image generation; this always executes as there is no way to specify for CMake to watch for
35+
# contents of the base dir changing.
36+
add_custom_target(factory ALL
37+
COMMAND ${mfg_tool_py} -d ${DISCRIMINATOR}
38+
-p ${PASSCODE}
39+
--product-name "${MY_BULB_NAME}"
40+
--vendor-name "${VENDOR_NAME}"
41+
--vendor-id ${VENDOR_ID}
42+
--product-id ${PRODUCT_ID}
43+
--hw-ver ${HARDWARE_VERSION}
44+
--hw-ver-str "${HARDWARE_VERSION_STR}"
45+
--dac-cert ${DAC_CERT}
46+
--dac-key ${DAC_KEY}
47+
--pai-cert ${PAI_CERT}
48+
--cd ${CERT_DCLRN}
49+
--dac-in-secure-cert
50+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
51+
)
52+
53+
set(image_file1 ${CMAKE_BINARY_DIR}/bin/factory_partition.bin)
54+
set(image_file2 ${CMAKE_BINARY_DIR}/bin/esp_secure_cert_partititon.bin)
55+
idf_component_get_property(main_args esptool_py FLASH_ARGS)
56+
idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
57+
58+
esptool_py_flash_target(${partition1}-flash "${main_args}" "${sub_args}" ALWAYS_PLAINTEXT)
59+
esptool_py_flash_to_partition(${partition1}-flash "${partition1}" "${image_file1}")
60+
61+
esptool_py_flash_target(${partition2}-flash "${main_args}" "${sub_args}" ALWAYS_PLAINTEXT)
62+
esptool_py_flash_to_partition(${partition2}-flash "${partition2}" "${image_file2}")
63+
64+
add_dependencies(${partition1}-flash factory)
65+
add_dependencies(${partition2}-flash factory)
66+
67+
if(arg_FLASH_IN_PROJECT)
68+
esptool_py_flash_to_partition(flash "${partition1}" "${image_file1}")
69+
esptool_py_flash_to_partition(flash "${partition2}" "${image_file2}")
70+
add_dependencies(flash factory)
71+
endif()
72+
else()
73+
set(message "Failed to create Factory partition image for partition '${partition}'. "
74+
"Check project configuration if using the correct partition table file.")
75+
fail_at_build_time(factory_${partition}_bin "${message}")
76+
77+
endif()
78+
endfunction()

0 commit comments

Comments
 (0)