Skip to content

Commit d65e74c

Browse files
committed
Added cmake script
1 parent ce32d11 commit d65e74c

File tree

3 files changed

+110
-1
lines changed

3 files changed

+110
-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

@@ -520,6 +521,11 @@ if(CONFIG_ENABLE_PW_RPC)
520521
endforeach()
521522
endif()
522523

524+
if(CONFIG_ENABLE_BUILD_TIME_PARTITION_SCRIPT)
525+
generate_build_time_partition(fctry esp_secure_cert ${CHIP_ROOT} FLASH_IN_PROJECT)
526+
add_dependencies(build_time_partition app)
527+
endif()
528+
523529
# Build Matter OTA image
524530
if (CONFIG_CHIP_OTA_IMAGE_BUILD)
525531
chip_ota_image(chip-ota-image

config/esp32/components/chip/Kconfig

+10-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
@@ -882,6 +882,15 @@ menu "CHIP Device Layer"
882882
default n
883883
help
884884
This option enables the system statistics to be sent to the insights cloud.
885+
886+
config ENABLE_BUILD_TIME_PARTITION_SCRIPT
887+
bool "Enable script to build fctry and esp_secure_cert partition in during build time."
888+
default n
889+
help
890+
Enables the cmake script to generate and map the factory parition bin and esp-secure-cert
891+
partition bin to their corresponding addresses specified in partitions.csv and flash the partitons
892+
in a single idf.py flash command.
893+
885894
endmenu
886895

887896

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#
2+
# Copyright (c) 2023 Project CHIP Authors
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
function(generate_build_time_partition fctry_partition esp_secure_cert_partition chip_root)
18+
set(options FLASH_IN_PROJECT)
19+
set(multi DEPENDS)
20+
cmake_parse_arguments(arg "${options}" "" "${multi}" "${ARGN}")
21+
get_filename_component(chip_root_abs_path ${chip_root} ABSOLUTE)
22+
23+
set(generate_esp32_chip_factory_bin.py ${PYTHON} ${chip_root}/scripts/tools/generate_esp32_chip_factory_bin.py)
24+
25+
partition_table_get_partition_info(fctry_partition_size "--partition-name ${fctry_partition}" "size")
26+
partition_table_get_partition_info(fctry_partition_offset "--partition-name ${fctry_partition}" "offset")
27+
28+
partition_table_get_partition_info(secure_cert_partition_size "--partition-name ${esp_secure_cert_partition}" "size")
29+
partition_table_get_partition_info(secure_cert_partition_offset "--partition-name ${esp_secure_cert_partition}" "offset")
30+
31+
message(STATUS "fctry_partition_size : ${fctry_partition_size}")
32+
message(STATUS "fctry_partition_offset : ${fctry_partition_offset}")
33+
message(STATUS "secure_cert_partition_size : ${secure_cert_partition_size}")
34+
message(STATUS "secure_cert_partition_offset : ${secure_cert_partition_offset}")
35+
36+
if("${fctry_partition_size}" AND "${fctry_partition_offset}")
37+
set(MY_BULB_NAME "My bulb")
38+
set(VENDOR_NAME "Test-vendor")
39+
set(HARDWARE_VERSION 1)
40+
set(HARDWARE_VERSION_STR "Devkit")
41+
set(VENDOR_ID 0xFFF2)
42+
set(PRODUCT_ID 0x8001)
43+
set(DAC_CERT "${chip_root_abs_path}/credentials/test/attestation/Chip-Test-DAC-FFF2-8001-0008-Cert.der")
44+
set(DAC_KEY "${chip_root_abs_path}/credentials/test/attestation/Chip-Test-DAC-FFF2-8001-0008-Key.der")
45+
set(PAI_CERT "${chip_root_abs_path}/credentials/test/attestation/Chip-Test-PAI-FFF2-8001-Cert.der")
46+
set(CERT_DCLRN "${chip_root_abs_path}/credentials/test/certification-declaration/Chip-Test-CD-FFF2-8001.der")
47+
set(PASSCODE 20202020)
48+
set(DISCRIMINATOR 3841)
49+
50+
# Execute Factory partition image generation; this always executes as there is no way to specify for CMake to watch for
51+
# contents of the base dir changing.
52+
add_custom_target(build_time_partition ALL
53+
COMMAND ${generate_esp32_chip_factory_bin.py} -d ${DISCRIMINATOR}
54+
-p ${PASSCODE}
55+
--product-name "${MY_BULB_NAME}"
56+
--vendor-name "${VENDOR_NAME}"
57+
--vendor-id ${VENDOR_ID}
58+
--product-id ${PRODUCT_ID}
59+
--hw-ver ${HARDWARE_VERSION}
60+
--hw-ver-str "${HARDWARE_VERSION_STR}"
61+
--dac-cert ${DAC_CERT}
62+
--dac-key ${DAC_KEY}
63+
--pai-cert ${PAI_CERT}
64+
--cd ${CERT_DCLRN}
65+
--dac-in-secure-cert
66+
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
67+
)
68+
69+
set(factory_partition_bin ${CMAKE_BINARY_DIR}/bin/factory_partition.bin)
70+
set(esp_secure_cert_partition_bin ${CMAKE_BINARY_DIR}/bin/esp_secure_cert_partititon.bin)
71+
idf_component_get_property(main_args esptool_py FLASH_ARGS)
72+
idf_component_get_property(sub_args esptool_py FLASH_SUB_ARGS)
73+
74+
esptool_py_flash_target(${fctry_partition}-flash "${main_args}" "${sub_args}" ALWAYS_PLAINTEXT)
75+
esptool_py_flash_to_partition(${fctry_partition}-flash "${fctry_partition}" "${factory_partition_bin}")
76+
77+
esptool_py_flash_target(${esp_secure_cert_partition}-flash "${main_args}" "${sub_args}" ALWAYS_PLAINTEXT)
78+
esptool_py_flash_to_partition(${esp_secure_cert_partition}-flash "${esp_secure_cert_partition}" "${esp_secure_cert_partition_bin}")
79+
80+
add_dependencies(${fctry_partition}-flash build_time_partition)
81+
add_dependencies(${esp_secure_cert_partition}-flash build_time_partition)
82+
83+
if(arg_FLASH_IN_PROJECT)
84+
esptool_py_flash_to_partition(flash "${fctry_partition}" "${factory_partition_bin}")
85+
esptool_py_flash_to_partition(flash "${esp_secure_cert_partition}" "${esp_secure_cert_partition_bin}")
86+
add_dependencies(flash build_time_partition)
87+
endif()
88+
else()
89+
set(message "Failed to create Factory partition image for partition '${partition}'. "
90+
"Check project configuration if using the correct partition table file.")
91+
fail_at_build_time(factory_${partition}_bin "${message}")
92+
93+
endif()
94+
endfunction()

0 commit comments

Comments
 (0)