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