@@ -16,6 +16,8 @@ zephyr_compile_definitions(COMPONENT_CM33)
1616zephyr_compile_definitions(FLASH_BOOT)
1717zephyr_compile_definitions(CY_PDL_FLASH_BOOT)
1818
19+ set (user_app_start_offset 0)
20+
1921# Use custome linker script
2022set (SOC_LINKER_SCRIPT ${ZEPHYR_BASE} /soc/infineon/cat1b/cyw20829/linker.ld CACHE INTERNAL "" )
2123
@@ -24,12 +26,76 @@ dt_nodelabel(sram_bootstrap NODELABEL "sram_bootstrap")
2426dt_reg_addr(bootstrap_dst_addr PATH ${sram_bootstrap} )
2527dt_reg_size(bootstrap_size PATH ${sram_bootstrap} )
2628
29+ set (gen_app_header_args)
30+ set (app_signed_enc_path ${ZEPHYR_BINARY_DIR} /${KERNEL_NAME} )
31+
32+ if (CONFIG_INFINEON_SECURE_LCS OR (DEFINED CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE) OR (DEFINED CONFIG_MCUBOOT_SIGNATURE_KEY_FILE))
33+ # Check cysecuretools
34+ find_program (CYSECURETOOLS cysecuretools REQUIRED)
35+ message ("-- Found cysecuretools: ${CYSECURETOOLS} " )
36+
37+ set (user_app_start_offset 0x400)
38+
39+ # Locate CySecureTools policy file
40+ if (IS_ABSOLUTE "${CONFIG_INFINEON_SECURE_POLICY} " )
41+ cmake_path(SET cysecuretools_policy "${CONFIG_INFINEON_SECURE_POLICY} " )
42+ else ()
43+ find_file (
44+ cysecuretools_policy
45+ NAMES
46+ "${CONFIG_INFINEON_SECURE_POLICY} "
47+ PATHS
48+ "${APPLICATION_SOURCE_DIR} "
49+ "${WEST_TOPDIR} "
50+ "${SOC_FULL_DIR} /cyw20829"
51+ NO_DEFAULT_PATH
52+ )
53+ endif ()
54+
55+ if (NOT IS_ABSOLUTE "${cysecuretools_policy} " OR NOT EXISTS "${cysecuretools_policy} " )
56+ message (FATAL_ERROR "Can't find policy file \" ${CONFIG_INFINEON_SECURE_POLICY} \" "
57+ "(Note: Relative paths are searched through "
58+ "APPLICATION_SOURCE_DIR=\" ${APPLICATION_SOURCE_DIR} \" "
59+ "and WEST_TOPDIR=\" ${WEST_TOPDIR} \" )" )
60+ endif ()
61+
62+ message ("-- Using cysecuretools policy: ${cysecuretools_policy} " )
63+ set (CYSECURETOOLS_POLICY ${cysecuretools_policy} CACHE PATH "cysecuretool policy" )
64+ endif ()
65+
66+ if (CONFIG_INFINEON_SECURE_LCS)
67+ #
68+ # Additional postbuild action for SECURE LCS
69+ #
70+ set (gen_app_header_args ${gen_app_header_args} --secure_lcs True )
71+ set (app_signed_path ${ZEPHYR_BINARY_DIR} /${KERNEL_NAME} .signed)
72+ set (app_signed_enc_path "${app_signed_path} " )
73+
74+ if (CONFIG_INFINEON_SMIF_ENCRYPTION)
75+ set (gen_app_header_args ${gen_app_header_args} --smif-config ${ZEPHYR_BINARY_DIR} /nonce-output .bin)
76+ set (enc_option --encrypt --nonce-output nonce-output .bin)
77+ # The encrypted image file path generated by cysecuretools
78+ set (app_signed_enc_path "${app_signed_path} _encrypted" )
79+ endif ()
80+
81+ set (bin2hex_option bin2hex --image ${app_signed_enc_path} .bin --output ${app_signed_enc_path} .hex --offset 0x60000030)
82+
83+ # Sign Zephyr L1 app in SECURE LCS
84+ set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
85+ COMMAND ${CYSECURETOOLS} -q -t cyw20829
86+ -p ${cysecuretools_policy} sign-image --image-format bootrom_next_app
87+ -i ${ZEPHYR_BINARY_DIR} /${KERNEL_BIN_NAME} -k 0 -o ${app_signed_path} .bin
88+ --slot-size ${CONFIG_FLASH_LOAD_SIZE} --app-addr 0x08000030
89+ ${enc_option} ${bin2hex_option}
90+ )
91+ endif ()
92+
2793# Calculate the place in flash
2894math (EXPR flash_addr_offset
29- "${CONFIG_CYW20829_FLASH_SAHB_ADDR} + ${CONFIG_FLASH_LOAD_OFFSET} + ${CONFIG_ROM_START_OFFSET } "
95+ "${CONFIG_CYW20829_FLASH_SAHB_ADDR} + ${CONFIG_FLASH_LOAD_OFFSET} + ${user_app_start_offset } "
3096 OUTPUT_FORMAT HEXADECIMAL
3197)
32- set (gen_app_header_args --flash_addr_offset ${flash_addr_offset} )
98+ set (gen_app_header_args ${gen_app_header_args} --flash_addr_offset ${flash_addr_offset} )
3399
34100# Generate platform specific header (TOC2, l1_desc, etc)
35101set_property (GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
@@ -45,7 +111,13 @@ set(MERGED_FILE ${CMAKE_BINARY_DIR}/zephyr/zephyr_merged.hex CACHE PATH "merged
45111set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
46112 COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE} /scripts/build /mergehex.py
47113 -o ${MERGED_FILE}
48- ${ZEPHYR_BINARY_DIR} / ${KERNEL_NAME } .hex ${ZEPHYR_BINARY_DIR} /app_header.hex
114+ ${app_signed_enc_path } .hex ${ZEPHYR_BINARY_DIR} /app_header.hex
49115 )
50116
51117set_property (GLOBAL APPEND PROPERTY extra_post_build_byproducts ${MERGED_FILE} )
118+
119+ # Use custom mcuboot cmake for sign/encrypt by using cysecuretools
120+ if (CONFIG_BOOTLOADER_MCUBOOT)
121+ set_target_properties (zephyr_property_target PROPERTIES SIGNING_SCRIPT
122+ ${CMAKE_CURRENT_LIST_DIR} /mcuboot.cmake)
123+ endif ()
0 commit comments