@@ -16,20 +16,89 @@ zephyr_compile_definitions(COMPONENT_CM33)
16
16
zephyr_compile_definitions (FLASH_BOOT )
17
17
zephyr_compile_definitions (CY_PDL_FLASH_BOOT )
18
18
19
- # Use custome linker script
19
+ # Use custom linker script
20
20
set (SOC_LINKER_SCRIPT ${ZEPHYR_BASE} /soc/infineon/cat1b/cyw20829/linker.ld CACHE INTERNAL "" )
21
21
22
22
# Get sram_bootstrap address and size
23
23
dt_nodelabel (sram_bootstrap NODELABEL "sram_bootstrap" )
24
24
dt_reg_addr (bootstrap_dst_addr PATH ${sram_bootstrap} )
25
25
dt_reg_size (bootstrap_size PATH ${sram_bootstrap} )
26
26
27
+ set (gen_app_header_args )
28
+ set (app_signed_enc_path ${ZEPHYR_BINARY_DIR} /${KERNEL_NAME} )
29
+
30
+ if (CONFIG_INFINEON_SECURE_LCS OR (DEFINED CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE ) OR (DEFINED CONFIG_MCUBOOT_SIGNATURE_KEY_FILE ))
31
+ # Check cysecuretools
32
+ find_program (CYSECURETOOLS cysecuretools REQUIRED )
33
+ message ("-- Found cysecuretools: ${CYSECURETOOLS} " )
34
+
35
+ # Locate CySecureTools policy file
36
+ if (IS_ABSOLUTE "${CONFIG_INFINEON_SECURE_POLICY} " )
37
+ cmake_path (SET cysecuretools_policy "${CONFIG_INFINEON_SECURE_POLICY} " )
38
+ else ()
39
+ find_file (
40
+ cysecuretools_policy
41
+ NAMES
42
+ "${CONFIG_INFINEON_SECURE_POLICY} "
43
+ PATHS
44
+ "${APPLICATION_SOURCE_DIR} "
45
+ "${WEST_TOPDIR} "
46
+ "${SOC_FULL_DIR} /cyw20829"
47
+ NO_DEFAULT_PATH
48
+ )
49
+ endif ()
50
+
51
+ if (NOT IS_ABSOLUTE "${cysecuretools_policy} " OR NOT EXISTS "${cysecuretools_policy} " )
52
+ message (FATAL_ERROR "Can't find policy file \" ${CONFIG_INFINEON_SECURE_POLICY} \" "
53
+ "(Note: Relative paths are searched through "
54
+ "APPLICATION_SOURCE_DIR=\" ${APPLICATION_SOURCE_DIR} \" "
55
+ "and WEST_TOPDIR=\" ${WEST_TOPDIR} \" )" )
56
+ endif ()
57
+
58
+ message ("-- Using cysecuretools policy: ${cysecuretools_policy} " )
59
+ set (CYSECURETOOLS_POLICY ${cysecuretools_policy} CACHE PATH "cysecuretools policy" )
60
+ endif ()
61
+
62
+ if (CONFIG_INFINEON_SECURE_LCS )
63
+ #
64
+ # Additional postbuild action for SECURE LCS
65
+ #
66
+ set (gen_app_header_args ${gen_app_header_args} --secure_lcs True )
67
+ set (app_signed_path ${ZEPHYR_BINARY_DIR} /${KERNEL_NAME}.signed )
68
+ set (app_signed_enc_path "${app_signed_path} " )
69
+
70
+ if (CONFIG_INFINEON_SMIF_ENCRYPTION )
71
+ set (gen_app_header_args ${gen_app_header_args} --smif-config ${ZEPHYR_BINARY_DIR} /nonce-output.bin )
72
+ set (enc_option --encrypt --nonce-output nonce-output.bin )
73
+ # The encrypted image file path generated by cysecuretools
74
+ set (app_signed_enc_path "${app_signed_path} _encrypted" )
75
+ endif ()
76
+
77
+ set (bin2hex_option bin2hex --image ${app_signed_enc_path} .bin --output ${app_signed_enc_path} .hex --offset 0x60000030 )
78
+
79
+ # Sign Zephyr L1 app in SECURE LCS
80
+ set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
81
+ COMMAND ${CYSECURETOOLS} -q -t cyw20829
82
+ -p ${cysecuretools_policy} sign-image --image-format bootrom_next_app
83
+ -i ${ZEPHYR_BINARY_DIR} /${KERNEL_BIN_NAME} -k 0 -o ${app_signed_path} .bin
84
+ --slot-size ${CONFIG_FLASH_LOAD_SIZE} --app-addr 0x08000030
85
+ ${enc_option} ${bin2hex_option}
86
+ )
87
+ endif ()
88
+
89
+ # By default the MCUboot header size if set to 0x400 by the cysecuretools
90
+ # https://github.com/Infineon/edgeprotecttools/blob/master/docs/README_GENERAL.md#sign-image
91
+ set (mcuboot_header_offset 0 )
92
+ if ((DEFINED CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE ) OR (DEFINED CONFIG_MCUBOOT_SIGNATURE_KEY_FILE ))
93
+ set (mcuboot_header_offset 0x400 )
94
+ endif ()
95
+
27
96
# Calculate the place in flash
28
97
math (EXPR flash_addr_offset
29
- "${CONFIG_CYW20829_FLASH_SAHB_ADDR} + ${CONFIG_FLASH_LOAD_OFFSET} + ${CONFIG_ROM_START_OFFSET } "
98
+ "${CONFIG_CYW20829_FLASH_SAHB_ADDR} + ${CONFIG_FLASH_LOAD_OFFSET} + ${mcuboot_header_offset } "
30
99
OUTPUT_FORMAT HEXADECIMAL
31
100
)
32
- set (gen_app_header_args --flash_addr_offset ${flash_addr_offset} )
101
+ set (gen_app_header_args ${gen_app_header_args} --flash_addr_offset ${flash_addr_offset} )
33
102
34
103
# Generate platform specific header (TOC2, l1_desc, etc)
35
104
set_property (GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
@@ -45,7 +114,13 @@ set(MERGED_FILE ${CMAKE_BINARY_DIR}/zephyr/zephyr_merged.hex CACHE PATH "merged
45
114
set_property (GLOBAL APPEND PROPERTY extra_post_build_commands
46
115
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE} /scripts/build/mergehex.py
47
116
-o ${MERGED_FILE}
48
- ${ZEPHYR_BINARY_DIR} /${KERNEL_NAME }.hex ${ZEPHYR_BINARY_DIR} /app_header.hex
117
+ ${app_signed_enc_path } .hex ${ZEPHYR_BINARY_DIR} /app_header.hex
49
118
)
50
119
51
120
set_property (GLOBAL APPEND PROPERTY extra_post_build_byproducts ${MERGED_FILE} )
121
+
122
+ # Use custom mcuboot cmake for sign/encrypt by using cysecuretools
123
+ if (CONFIG_BOOTLOADER_MCUBOOT )
124
+ set_target_properties (zephyr_property_target PROPERTIES SIGNING_SCRIPT
125
+ ${CMAKE_CURRENT_LIST_DIR} /mcuboot.cmake )
126
+ endif ()
0 commit comments