@@ -30,6 +30,66 @@ math(EXPR flash_addr_offset
3030 OUTPUT_FORMAT HEXADECIMAL
3131)
3232set (gen_app_header_args --flash_addr_offset ${flash_addr_offset} )
33+ set (app_signed_enc_path ${ZEPHYR_BINARY_DIR} /${KERNEL_NAME} )
34+
35+ if (CONFIG_INFINEON_SECURE_LCS OR (DEFINED CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE) OR (DEFINED CONFIG_MCUBOOT_SIGNATURE_KEY_FILE))
36+ # Check cysecuretools
37+ find_program (CYSECURETOOLS cysecuretools REQUIRED)
38+ message ("-- Found cysecuretools: ${CYSECURETOOLS} " )
39+
40+ # Locate CySecureTools policy file
41+ if (IS_ABSOLUTE "${CONFIG_INFINEON_SECURE_POLICY} " )
42+ cmake_path(SET cysecuretools_policy "${CONFIG_INFINEON_SECURE_POLICY} " )
43+ else ()
44+ find_file (
45+ cysecuretools_policy
46+ NAMES
47+ "${CONFIG_INFINEON_SECURE_POLICY} "
48+ PATHS
49+ "${APPLICATION_SOURCE_DIR} "
50+ "${WEST_TOPDIR} "
51+ "${SOC_FULL_DIR} /cyw20829"
52+ NO_DEFAULT_PATH
53+ )
54+ endif ()
55+
56+ if (NOT IS_ABSOLUTE "${cysecuretools_policy} " OR NOT EXISTS "${cysecuretools_policy} " )
57+ message (FATAL_ERROR "Can't find policy file \" ${CONFIG_INFINEON_SECURE_POLICY} \" "
58+ "(Note: Relative paths are searched through "
59+ "APPLICATION_SOURCE_DIR=\" ${APPLICATION_SOURCE_DIR} \" "
60+ "and WEST_TOPDIR=\" ${WEST_TOPDIR} \" )" )
61+ endif ()
62+
63+ message ("-- Using cysecuretools policy: ${cysecuretools_policy} " )
64+ set (CYSECURETOOLS_POLICY ${cysecuretools_policy} CACHE PATH "cysecuretool policy" )
65+ endif ()
66+
67+ if (CONFIG_INFINEON_SECURE_LCS)
68+ #
69+ # Additional postbuild action for SECURE LCS
70+ #
71+ set (gen_app_header_args ${gen_app_header_args} --secure_lcs True )
72+ set (app_signed_path ${ZEPHYR_BINARY_DIR} /${KERNEL_NAME} .signed)
73+ set (app_signed_enc_path "${app_signed_path} " )
74+
75+ if (CONFIG_INFINEON_SMIF_ENCRYPTION)
76+ set (gen_app_header_args ${gen_app_header_args} --smif-config ${ZEPHYR_BINARY_DIR} /nonce-output .bin)
77+ set (enc_option --encrypt --nonce-output nonce-output .bin)
78+ # The encrypted image file path generated by cysecuretools
79+ set (app_signed_enc_path "${app_signed_path} _encrypted" )
80+ endif ()
81+
82+ set (bin2hex_option bin2hex --image ${app_signed_enc_path} .bin --output ${app_signed_enc_path} .hex --offset 0x60000030)
83+
84+ # Sign Zephyr L1 app in SECURE LCS
85+ set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
86+ COMMAND ${CYSECURETOOLS} -q -t cyw20829
87+ -p ${cysecuretools_policy} sign-image --image-format bootrom_next_app
88+ -i ${ZEPHYR_BINARY_DIR} /${KERNEL_BIN_NAME} -k 0 -o ${app_signed_path} .bin
89+ --slot-size ${CONFIG_FLASH_LOAD_SIZE} --app-addr 0x08000030
90+ ${enc_option} ${bin2hex_option}
91+ )
92+ endif ()
3393
3494# Generate platform specific header (TOC2, l1_desc, etc)
3595set_property (GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
@@ -39,9 +99,13 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
3999 --bootstrap-dst-addr ${bootstrap_dst_addr}
40100 )
41101
102+ set (MERGED_FILE ${CMAKE_BINARY_DIR} /zephyr/zephyr_merged.hex CACHE PATH "merged hex" )
103+
42104# Merge platform specific header and zephyr image to a single binary.
43105set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
44106 COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE} /scripts/build /mergehex.py
45- -o ${ZEPHYR_BINARY_DIR} / ${KERNEL_NAME} .hex
46- ${app_temp_path } .hex ${ZEPHYR_BINARY_DIR} /app_header.hex
107+ -o ${MERGED_FILE}
108+ ${app_signed_enc_path } .hex ${ZEPHYR_BINARY_DIR} /app_header.hex
47109 )
110+
111+ set_property (GLOBAL APPEND PROPERTY extra_post_build_byproducts ${MERGED_FILE} )
0 commit comments