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