@@ -30,6 +30,78 @@ 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 CONFIG_BOOTLOADER_MCUBOOT)
36+ # Check cysecuretools
37+ find_program (CYSECURETOOLS cysecuretools)
38+ if (NOT CYSECURETOOLS)
39+ message (FATAL_ERROR "Can't find cysecuretools. To fix, install cysecuretools with pip3." )
40+ else ()
41+ message ("-- Found cysecuretools: ${CYSECURETOOLS} " )
42+ endif ()
43+ endif ()
44+
45+ if (CONFIG_INFINEON_SECURE_LCS)
46+ set (default_policy)
47+ set (default_policy_name)
48+
49+ # Cysecuretools policy.
50+ if (NOT CONFIG_INFINEON_SECURE_POLICY)
51+ # Get default cysecuretools policy
52+ if (CONFIG_INFINEON_SECURE_LCS)
53+ message (INFO "CONFIG_INFINEON_SECURE_POLICY was not defined." )
54+ set (default_policy_name policy_secure.json)
55+ else ()
56+ set (default_policy_name policy_no_secure.json)
57+ endif ()
58+ endif ()
59+
60+ find_file (
61+ default_policy
62+ NAMES
63+ ${CONFIG_INFINEON_SECURE_POLICY}
64+ ${default_policy_name}
65+ PATHS
66+ ${APPLICATION_SOURCE_DIR}
67+ ${ZEPHYR_BASE}
68+ NO_DEFAULT_PATH
69+ )
70+
71+ if (NOT default_policy)
72+ message (FATAL_ERROR "Can't find policy:${CONFIG_INFINEON_SECURE_POLICY} "
73+ "/${default_policy_name} "
74+ "Checked locations: ${APPLICATION_SOURCE_DIR} , ${ZEPHYR_BASE} " )
75+ endif ()
76+
77+ set (cysecuretools_policy ${default_policy} CACHE PATH "cysecuretools policy" )
78+ message ("-- Using cysecuretools policy: ${cysecuretools_policy} " )
79+ endif ()
80+
81+ if (CONFIG_INFINEON_SECURE_LCS)
82+ #
83+ # Addition postbuild action for SECURE LCS
84+ #
85+ set (gen_app_header_args ${gen_app_header_args} --secure_lcs True )
86+ set (app_signed_enc_path ${ZEPHYR_BINARY_DIR} /${KERNEL_NAME} .signed)
87+
88+ if (CONFIG_INFINEON_SMIF_ENCRYPTION)
89+ set (gen_app_header_args ${gen_app_header_args} --smif-config ${ZEPHYR_BINARY_DIR} /nonce-output .bin)
90+ set (enc_option --encrypt --nonce-output nonce-output .bin)
91+ set (app_signed_enc_path ${ZEPHYR_BINARY_DIR} /${KERNEL_NAME} .signed.encrypted)
92+ endif ()
93+
94+ set (bin2hex_option bin2hex --image ${app_signed_enc_path} .bin --output ${app_signed_enc_path} .hex --offset 0x60000030)
95+
96+ # Sign Zephyr L1 app in SECURE LCS
97+ set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
98+ COMMAND ${CYSECURETOOLS} -q -t cyw20829
99+ -p ${cysecuretools_policy} sign-image --image-format bootrom_next_app
100+ -i ${ZEPHYR_BINARY_DIR} /${KERNEL_BIN_NAME} -k 0 -o ${app_signed_enc_path} .bin
101+ --slot-size ${CONFIG_FLASH_LOAD_SIZE} --app-addr 0x08000030
102+ ${enc_option} ${bin2hex_option}
103+ )
104+ endif ()
33105
34106# Generate platform specific header (TOC2, l1_desc, etc)
35107set_property (GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
@@ -39,9 +111,13 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
39111 --bootstrap-dst-addr ${bootstrap_dst_addr}
40112 )
41113
114+ set (MERGED_FILE ${CMAKE_BINARY_DIR} /zephyr/zephyr_merged.hex)
115+
42116# Merge platform specific header and zephyr image to a single binary.
43117set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
44118 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
119+ -o ${MERGED_FILE}
120+ ${app_signed_enc_path } .hex ${ZEPHYR_BINARY_DIR} /app_header.hex
47121 )
122+
123+ set_property (GLOBAL APPEND PROPERTY extra_post_build_byproducts ${MERGED_FILE} )
0 commit comments