Skip to content

Commit e714793

Browse files
npal-cysreeramIfx
authored andcommitted
soc: cyw20829: Initial integrate Cypress MCUBoot for 20829
Added custom mcuboot cmake for sign/encrypt by using cysecuretools Signed-off-by: Nazar Palamar <[email protected]>
1 parent 97f406c commit e714793

File tree

7 files changed

+459
-78
lines changed

7 files changed

+459
-78
lines changed

boards/infineon/cyw920829m2evk_02/cyw920829m2evk_02.dts

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
chosen {
2121
zephyr,sram = &sram0;
22-
zephyr,flash = &app_region;
22+
zephyr,flash = &flash0;
23+
zephyr,code-partition = &slot0_partition;
2324
zephyr,console = &uart2;
2425
zephyr,shell-uart = &uart2;
2526
zephyr,bt-hci = &bluetooth;
@@ -99,45 +100,48 @@ uart2: &scb2 {
99100
status = "okay";
100101
};
101102

102-
/ {
103-
qspi_flash: qspi_flash@40890000 {
104-
compatible = "infineon,cat1-qspi-flash";
105-
reg = <0x40890000 0x30000>;
103+
104+
&qspi_flash {
105+
flash0: flash@8000000 {
106+
compatible = "soc-nv-flash";
107+
reg = <0x08000000 DT_SIZE_M(1)>;
108+
write-block-size = <1>;
109+
erase-block-size = <DT_SIZE_K(4)>;
106110
#address-cells = <1>;
107111
#size-cells = <1>;
108112

109-
flash0: flash@8000000 {
110-
compatible = "soc-nv-flash";
111-
reg = <0x08000000 DT_SIZE_K(512)>;
112-
write-block-size = <1>;
113-
erase-block-size = <DT_SIZE_K(4)>;
113+
/* Keep bootstrap_region node to know size, finaly it will
114+
* locate on beginning of code-partition. The BootROM copies
115+
* bootstrap application in RAM and launches it.
116+
*/
117+
bootstrap_region: bootstrap_region@0 {
118+
reg = <0 BOOTSTRAP_SIZE>;
119+
};
120+
121+
partitions {
122+
compatible = "fixed-partitions";
114123
#address-cells = <1>;
115124
#size-cells = <1>;
116125

117-
toc2_region: toc2_region@8000000 {
118-
compatible = "zephyr,memory-region", "soc-nv-flash";
119-
zephyr,memory-region = "APP_HEADER_FLASH";
120-
reg = <0x08000000 0x50>;
121-
};
122-
bootstrap_region: bootstrap_region@8000050 {
123-
compatible = "zephyr,memory-region", "soc-nv-flash";
124-
zephyr,memory-region = "BOOTSTRAP_FLASH";
125-
reg = <0x08000050 DT_SIZE_K(12)>;
126+
boot_partition: partition@0 {
127+
label = "mcuboot";
128+
reg = <0x0 0x20000>;
129+
read-only;
126130
};
127-
app_region: app_region@8003050 {
128-
compatible = "soc-nv-flash";
129-
reg = <0x08003050 0x6CFB0>; /* 435kb */
131+
132+
slot0_partition: partition@20000 {
133+
label = "image-0";
134+
reg = <0x20000 0x60000>;
130135
};
131136

132-
partitions {
133-
compatible = "fixed-partitions";
134-
#address-cells = <1>;
135-
#size-cells = <1>;
137+
slot1_partition: partition@80000 {
138+
label = "image-1";
139+
reg = <0x80000 0x60000>;
140+
};
136141

137-
storage_partition: storage_partition@60000 {
138-
compatible = "soc-nv-flash";
139-
reg = <0x60000 DT_SIZE_K(64)>;
140-
};
142+
storage_partition: storage_partition@E0000 {
143+
compatible = "soc-nv-flash";
144+
reg = <0xE0000 DT_SIZE_K(64)>;
141145
};
142146
};
143147
};

boards/infineon/cyw920829m2evk_02/doc/index.rst

Lines changed: 130 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
Overview
44
********
55

6-
The AIROC™ CYW20829 Bluetooth® LE MCU Evaluation Kit (CYW920829M2EVK-02) with its included on-board peripherals enables evaluation, prototyping, and development of a wide array of Bluetooth® Low Energy applications, all on Infineon's low power, high performance AIROC™ CYW20829. The AIROC™ CYW20829's robust RF performance and 10 dBm TX output power without an external power amplifier (PA). This provides enough link budget for the entire spectrum of Bluetooth® LE use cases including industrial IoT applications, smart home, asset tracking, beacons and sensors, and medical devices.
7-
8-
The system features Dual Arm® Cortex® - M33s for powering the MCU and Bluetooth subsystem with programmable and reconfigurable analog and digital blocks. In addition, on the kit, there is a suite of on-board peripherals including six-axis inertial measurement unit (IMU), thermistor, analog mic, user programmable buttons (2), LEDs (2), and RGB LED. There is also extensive GPIO support with extended headers and Arduino Uno R3 compatibility for third-party shields.
6+
The AIROC™ CYW20829 Bluetooth® LE MCU Evaluation Kit (CYW920829M2EVK-02) with its included on-board
7+
peripherals enables evaluation, prototyping, and development of a wide array of
8+
Bluetooth® Low Energy applications, all on Infineon's low power, high performance AIROC™ CYW20829.
9+
The AIROC™ CYW20829's robust RF performance and 10 dBm TX output power without an external power
10+
amplifier (PA). This provides enough link budget for the entire spectrum of Bluetooth® LE use cases
11+
including industrial IoT applications, smart home, asset tracking, beacons and sensors, and
12+
medical devices.
13+
14+
The system features Dual Arm® Cortex® - M33s for powering the MCU and Bluetooth subsystem with
15+
programmable and reconfigurable analog and digital blocks. In addition, on the kit, there is a
16+
suite of on-board peripherals including six-axis inertial measurement unit (IMU), thermistor,
17+
analog mic, user programmable buttons (2), LEDs (2), and RGB LED. There is also extensive GPIO
18+
support with extended headers and Arduino Uno R3 compatibility for third-party shields.
919

1020
Hardware
1121
********
@@ -20,7 +30,8 @@ Kit Features:
2030

2131
- AIROC™ CYW20829 Bluetooth® LE MCU in 56 pin QFN package
2232
- Arduino compatible headers for hardware expansion
23-
- On-board sensors - 6-axis IMU, Thermistor, Infineon analog microphone, and Infineon digital microphone
33+
- On-board sensors - 6-axis IMU, Thermistor, Infineon analog microphone,
34+
and Infineon digital microphone
2435
- User switches, RGB LED and user LEDs
2536
- USB connector for power, programming and USB-UART bridge
2637

@@ -71,24 +82,38 @@ Programming and Debugging
7182

7283
.. zephyr:board-supported-runners::
7384
74-
The CYW920829M2EVK-02 includes an onboard programmer/debugger (`KitProg3`_) to provide debugging, flash programming, and serial communication over USB. Flash and debug commands use OpenOCD and require a custom Infineon OpenOCD version, that supports KitProg3, to be installed.
85+
The CYW920829M2EVK-02 includes an onboard programmer/debugger (`KitProg3`_) to provide debugging,
86+
flash programming, and serial communication over USB. Flash and debug commands use OpenOCD and
87+
require a custom Infineon OpenOCD version, that supports KitProg3, to be installed.
7588

76-
The CYW920829M2EVK-02 supports RTT via a SEGGER JLink device, under the target name cyw20829_tm. This can be enabled for an application by building with the rtt-console snippet or setting the following config values: CONFIG_UART_CONSOLE=n, CONFIG_RTT_CONSOLE=y, and CONFIG_USE_SEGGER_RTT=y.
89+
The CYW920829M2EVK-02 supports RTT via a SEGGER JLink device, under the target name cyw20829_tm.
90+
This can be enabled for an application by building with the rtt-console snippet or setting the
91+
following config values: CONFIG_UART_CONSOLE=n, CONFIG_RTT_CONSOLE=y, and CONFIG_USE_SEGGER_RTT=y.
7792
e.g. west build -p always -b cyw920829m2evk_02 samples/basic/blinky -S rtt-console
7893

79-
As an additional note there is currently a discrepancy in RAM address between SEGGER and the CYW920829M2EVK-02 device. So, for RTT control block, do not use "Auto Detection". Instead, set the search range to something reflecting: RAM RangeStart at 0x20000000 and RAM RangeSize of 0x3d000.
94+
As an additional note there is currently a discrepancy in RAM address between SEGGER and the
95+
CYW920829M2EVK-02 device. So, for RTT control block, do not use "Auto Detection". Instead, set
96+
the search range to something reflecting: RAM RangeStart at 0x20000000 and RAM RangeSize of 0x3d000.
8097

8198
Infineon OpenOCD Installation
8299
=============================
83100

84-
Both the full `ModusToolbox`_ and the `ModusToolbox Programming Tools`_ packages include Infineon OpenOCD. Installing either of these packages will also install Infineon OpenOCD. If neither package is installed, a minimal installation can be done by downloading the `Infineon OpenOCD`_ release for your system and manually extract the files to a location of your choice.
101+
Both the full `ModusToolbox`_ and the `ModusToolbox Programming Tools`_ packages include Infineon
102+
OpenOCD. Installing either of these packages will also install Infineon OpenOCD. If neither package
103+
is installed, a minimal installation can be done by downloading the `Infineon OpenOCD`_ release for
104+
your system and manually extract the files to a location of your choice.
85105

86-
.. note:: Linux requires device access rights to be set up for KitProg3. This is handled automatically by the ModusToolbox and ModusToolbox Programming Tools installations. When doing a minimal installation, this can be done manually by executing the script ``openocd/udev_rules/install_rules.sh``.
106+
.. note:: Linux requires device access rights to be set up for KitProg3. This is handled
107+
automatically by the ModusToolbox and ModusToolbox Programming Tools installations.
108+
When doing a minimal installation, this can be done manually by executing the
109+
script ``openocd/udev_rules/install_rules.sh``.
87110

88111
West Commands
89112
=============
90113

91-
The path to the installed Infineon OpenOCD executable must be available to the ``west`` tool commands. There are multiple ways of doing this. The example below uses a permanent CMake argument to set the CMake variable ``OPENOCD``.
114+
The path to the installed Infineon OpenOCD executable must be available to the ``west`` tool
115+
commands. There are multiple ways of doing this. The example below uses a permanent CMake argument
116+
to set the CMake variable ``OPENOCD``.
92117

93118
.. tabs::
94119
.. group-tab:: Windows
@@ -117,7 +142,101 @@ The path to the installed Infineon OpenOCD executable must be available to the `
117142
west flash
118143
west debug
119144
120-
Once the gdb console starts after executing the west debug command, you may now set breakpoints and perform other standard GDB debugging on the CYW20829 CM33 core.
145+
Once the gdb console starts after executing the west debug command, you may now set breakpoints and
146+
perform other standard GDB debugging on the CYW20829 CM33 core.
147+
148+
Operate in SECURE Lifecycle Stage
149+
*********************************
150+
151+
The device lifecycle stage (LCS) is a key aspect of the security of the AIROC™
152+
CYW20829 Bluetooth® MCU. The lifecycle stages follow a strict, irreversible progression dictated by
153+
the programming of the eFuse bits (changing the value from "0" to "1"). This system is used to
154+
protect the device's data and code at the level required by the user.
155+
SECURE is the lifecycle stage of a secured device.
156+
Follow the instructions in `AN239590 Provision CYW20829 to SECURE LCS`_ to transition the device
157+
to SECURE LCS. In the SECURE LCS stage, the protection state is set to secure. A secured device
158+
will only boot if the authentication of its flash content is successful.
159+
160+
The following configuration options can be used to build for a device which has been provisioned
161+
to SECURE LCS and configured to use an encrypted flash interface:
162+
163+
- ``CONFIG_INFINEON_SECURE_LCS=y``: Enable if the target device is in SECURE LCS
164+
- ``CONFIG_INFINEON_SECURE_POLICY="path/to/policy_secure.json"``: Path to the policy JSON file,
165+
which was created for provisioning the device to SECURE LCS (refer to section 3.2 "Key creation"
166+
of `AN239590 Provision CYW20829 to SECURE LCS`_)
167+
- ``CONFIG_INFINEON_SMIF_ENCRYPTION=y``: Enable to use encrypted flash interface when provisioned to
168+
SECURE LCS.
169+
170+
Here is an example for building the :zephyr:code-sample:`blinky` sample application for SECURE LCS.
171+
172+
.. zephyr-app-commands::
173+
:goals: build
174+
:board: cyw920829m2evk_02
175+
:zephyr-app: samples/basic/blinky
176+
:west-args: -p always
177+
:gen-args: -DCONFIG_INFINEON_SECURE_LCS=y -DCONFIG_INFINEON_SECURE_POLICY=\"policy/policy_secure.json\"
178+
179+
Using MCUboot
180+
*************
181+
182+
CYW20829 devices are supported by the Cypress MCU bootloader (MCUBootApp) from the
183+
`Cypress branch of MCUboot`_.
184+
185+
Building Cypress MCU Bootloader MCUBootApp
186+
==========================================
187+
188+
Please refer to the `CYW20829 platform description`_ and follow the instructions to understand the
189+
MCUBootApp building process for normal/secure silicon and its overall usage as a bootloader.
190+
Place keys and policy-related folders in the cypress directory ``mcuboot/boot/cypress/``.
191+
192+
Ensure the default memory map matches the memory map of the Zephyr application (refer to partitions
193+
of flash0 in :zephyr_file:`boards/infineon/cyw920829m2evk_02/cyw920829m2evk_02.dts`).
194+
195+
You can use ``west flash`` to flash MCUBootApp:
196+
197+
.. code-block:: shell
198+
199+
# Flash MCUBootApp.hex
200+
west flash --skip-rebuild --hex-file /path/to/cypress/mcuboot/boot/cypress/MCUBootApp/out/CYW20829/Debug/MCUBootApp.hex
201+
202+
.. note:: ``west flash`` requires an existing Zephyr build directory which can be created by first
203+
building any Zephyr application for the target board.
204+
205+
Build Zephyr application
206+
========================
207+
Here is an example for building and flashing the :zephyr:code-sample:`blinky` sample application
208+
for MCUboot.
209+
210+
.. zephyr-app-commands::
211+
:goals: build flash
212+
:board: cyw920829m2evk_02
213+
:zephyr-app: samples/basic/blinky
214+
:west-args: -p always
215+
:gen-args: -DCONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE=\"/path/to/cypress/mcuboot/boot/cypress/keys/cypress-test-ec-p256.pem\"
216+
217+
If you use ``CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE`` to generate an encrypted image then the final
218+
hex will be ``zephyr.signed.encrypted.hex`` and the corresponding bin file will
219+
be ``zephyr.signed.encrypted.bin``. Use these files for flashing and ota uploading respectively.
220+
For example, to build and flash an encrypted :zephyr:code-sample:`blinky` sample application
221+
image for MCUboot:
222+
223+
.. zephyr-app-commands::
224+
:goals: build flash
225+
:board: cyw920829m2evk_02
226+
:zephyr-app: samples/basic/blinky
227+
:west-args: -p always
228+
:gen-args: -DCONFIG_BOOTLOADER_MCUBOOT=y -DCONFIG_MCUBOOT_SIGNATURE_KEY_FILE=\"/path/to/cypress/mcuboot/boot/cypress/keys/cypress-test-ec-p256.pem\" -DCONFIG_MCUBOOT_ENCRYPTION_KEY_FILE=\"/path/to/cypress/mcuboot/enc-ec256-pub.pem\"
229+
:flash-args: --hex-file build/zephyr/zephyr.signed.encrypted.hex
230+
231+
232+
.. _CYW20829 platform description:
233+
https://github.com/mcu-tools/mcuboot/blob/v1.9.4-cypress/boot/cypress/platforms/CYW20829.md
234+
235+
.. _Cypress branch of MCUboot:
236+
https://github.com/mcu-tools/mcuboot/tree/cypress
237+
238+
.. _AN239590 Provision CYW20829 to SECURE LCS:
239+
https://www.infineon.com/dgdl/Infineon-AN239590_Provision_CYW20829_CYW89829_to_Secure_LCS-ApplicationNotes-v02_00-EN.pdf?fileId=8ac78c8c8d2fe47b018e3677dd517258
121240

122241
.. _CYW20829 SoC Website:
123242
https://www.infineon.com/cms/en/product/wireless-connectivity/airoc-bluetooth-le-bluetooth-multiprotocol/airoc-bluetooth-le/cyw20829/

soc/infineon/cat1b/cyw20829/CMakeLists.txt

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -32,63 +32,55 @@ math(EXPR flash_addr_offset
3232
set(gen_app_header_args --flash_addr_offset ${flash_addr_offset})
3333
set(app_signed_enc_path ${ZEPHYR_BINARY_DIR}/${KERNEL_NAME})
3434

35-
if(CONFIG_INFINEON_SECURE_LCS OR CONFIG_BOOTLOADER_MCUBOOT)
35+
if(CONFIG_INFINEON_SECURE_LCS OR (DEFINED CONFIG_MCUBOOT_ENCRYPTION_KEY_FILE) OR (DEFINED CONFIG_MCUBOOT_SIGNATURE_KEY_FILE))
3636
# Check cysecuretools
3737
find_program(CYSECURETOOLS cysecuretools)
3838
if(NOT CYSECURETOOLS)
3939
message(FATAL_ERROR "Can't find cysecuretools. To fix, install cysecuretools with pip3.")
4040
else()
4141
message("-- Found cysecuretools: ${CYSECURETOOLS}")
4242
endif()
43-
endif()
4443

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()
44+
# Locate CySecureTools policy file
45+
if(IS_ABSOLUTE "${CONFIG_INFINEON_SECURE_POLICY}")
46+
cmake_path(SET cysecuretools_policy "${CONFIG_INFINEON_SECURE_POLICY}")
47+
else()
48+
find_file(
49+
cysecuretools_policy
50+
NAMES
51+
"${CONFIG_INFINEON_SECURE_POLICY}"
52+
PATHS
53+
"${APPLICATION_SOURCE_DIR}"
54+
"${WEST_TOPDIR}"
55+
"${SOC_FULL_DIR}/cyw20829"
56+
NO_DEFAULT_PATH
57+
)
5858
endif()
5959

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}")
60+
if(NOT IS_ABSOLUTE "${cysecuretools_policy}" OR NOT EXISTS "${cysecuretools_policy}")
61+
message(FATAL_ERROR "Can't find policy file \"${CONFIG_INFINEON_SECURE_POLICY}\" "
62+
"(Note: Relative paths are searched through "
63+
"APPLICATION_SOURCE_DIR=\"${APPLICATION_SOURCE_DIR}\" "
64+
"and WEST_TOPDIR=\"${WEST_TOPDIR}\")")
7565
endif()
7666

77-
set(cysecuretools_policy ${default_policy} CACHE PATH "cysecuretools policy")
7867
message("-- Using cysecuretools policy: ${cysecuretools_policy}")
68+
set(CYSECURETOOLS_POLICY ${cysecuretools_policy} CACHE PATH "cysecuretool policy")
7969
endif()
8070

8171
if(CONFIG_INFINEON_SECURE_LCS)
8272
#
83-
# Addition postbuild action for SECURE LCS
73+
# Additional postbuild action for SECURE LCS
8474
#
8575
set(gen_app_header_args ${gen_app_header_args} --secure_lcs True)
86-
set(app_signed_enc_path ${ZEPHYR_BINARY_DIR}/${KERNEL_NAME}.signed)
76+
set(app_signed_path ${ZEPHYR_BINARY_DIR}/${KERNEL_NAME}.signed)
77+
set(app_signed_enc_path "${app_signed_path}")
8778

8879
if(CONFIG_INFINEON_SMIF_ENCRYPTION)
8980
set(gen_app_header_args ${gen_app_header_args} --smif-config ${ZEPHYR_BINARY_DIR}/nonce-output.bin)
9081
set(enc_option --encrypt --nonce-output nonce-output.bin)
91-
set(app_signed_enc_path ${ZEPHYR_BINARY_DIR}/${KERNEL_NAME}.signed.encrypted)
82+
# The encrypted image file path generated by cysecuretools
83+
set(app_signed_enc_path "${app_signed_path}_encrypted")
9284
endif()
9385

9486
set(bin2hex_option bin2hex --image ${app_signed_enc_path}.bin --output ${app_signed_enc_path}.hex --offset 0x60000030)
@@ -97,7 +89,7 @@ if(CONFIG_INFINEON_SECURE_LCS)
9789
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
9890
COMMAND ${CYSECURETOOLS} -q -t cyw20829
9991
-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
92+
-i ${ZEPHYR_BINARY_DIR}/${KERNEL_BIN_NAME} -k 0 -o ${app_signed_path}.bin
10193
--slot-size ${CONFIG_FLASH_LOAD_SIZE} --app-addr 0x08000030
10294
${enc_option} ${bin2hex_option}
10395
)
@@ -111,7 +103,7 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands COMMAND
111103
--bootstrap-dst-addr ${bootstrap_dst_addr}
112104
)
113105

114-
set(MERGED_FILE ${CMAKE_BINARY_DIR}/zephyr/zephyr_merged.hex)
106+
set(MERGED_FILE ${CMAKE_BINARY_DIR}/zephyr/zephyr_merged.hex CACHE PATH "merged hex")
115107

116108
# Merge platform specific header and zephyr image to a single binary.
117109
set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
@@ -121,3 +113,9 @@ set_property(GLOBAL APPEND PROPERTY extra_post_build_commands
121113
)
122114

123115
set_property(GLOBAL APPEND PROPERTY extra_post_build_byproducts ${MERGED_FILE})
116+
117+
# Use custom mcuboot cmake for sign/encrypt by using cysecuretools
118+
if(CONFIG_BOOTLOADER_MCUBOOT)
119+
set_target_properties(zephyr_property_target PROPERTIES SIGNING_SCRIPT
120+
${CMAKE_CURRENT_LIST_DIR}/mcuboot.cmake)
121+
endif()

soc/infineon/cat1b/cyw20829/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ config INFINEON_SECURE_LCS
2626

2727
config INFINEON_SECURE_POLICY
2828
string "Path to policy JSON file"
29+
default "default_policy.json"
2930
help
3031
Policy is a text file in JSON format that contains a set of properties
3132
for the device configuration (e.g., enabling/disabling debug access ports,

0 commit comments

Comments
 (0)