From e6844094edce1c6acbd45c76dbb69ec18cc8e666 Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 28 Sep 2023 16:58:15 +0200 Subject: [PATCH] modules: tfm: Update Zephyr and TF-M to support UART pinctrl config Update TF-M to support UART pin config from pinctrl. Change out-of-tree support to use the device tree information and pass it to the TF-M UART driver. Update TF-M tests to define hw-flow-control, and alternate pin setup in devicetree instead of kconfig Update Zephyr to include: - nRF5340 DK flow control pins. - Revert noup commits to take upstream commits for generic NS board support - Include nrf9160 flash layout fixes and BL2 logging fixes. Signed-off-by: Joakim Andersson --- modules/tfm/tfm/boards/board/RTE_Device.h | 49 +++---- modules/tfm/tfm/boards/board/device_cfg.h | 24 ++-- modules/trusted-firmware-m/Kconfig | 130 ++---------------- tests/tfm/tfm_regression_test/app.overlay | 19 +++ .../boards/nrf5340dk_nrf5340_cpuapp_ns.conf | 9 -- tests/tfm/tfm_regression_test/prj.conf | 4 - west.yml | 4 +- 7 files changed, 66 insertions(+), 173 deletions(-) create mode 100644 tests/tfm/tfm_regression_test/app.overlay delete mode 100644 tests/tfm/tfm_regression_test/boards/nrf5340dk_nrf5340_cpuapp_ns.conf diff --git a/modules/tfm/tfm/boards/board/RTE_Device.h b/modules/tfm/tfm/boards/board/RTE_Device.h index 8901147c0f34..1caf03d3901a 100644 --- a/modules/tfm/tfm/boards/board/RTE_Device.h +++ b/modules/tfm/tfm/boards/board/RTE_Device.h @@ -8,44 +8,45 @@ #define __RTE_DEVICE_H #include +/* ARRAY_SIZE causes a conflict as it is defined both by TF-M and indirectly by devicetree.h */ +#undef ARRAY_SIZE +#include +#include + +#define UART_PIN_INIT(node_id, prop, idx) \ + DT_PROP_BY_IDX(node_id, prop, idx), /* Configuration settings for Driver_USART0. */ #if defined(CONFIG_TFM_SECURE_UART0) || DOMAIN_NS == 1U -#define RTE_USART0 1 -/* Pin Selection (0xFFFFFFFF means Disconnected) */ -#define RTE_USART0_TXD_PIN CONFIG_TFM_UART0_TXD_PIN -#define RTE_USART0_RXD_PIN CONFIG_TFM_UART0_RXD_PIN -#define RTE_USART0_RTS_PIN CONFIG_TFM_UART0_RTS_PIN -#define RTE_USART0_CTS_PIN CONFIG_TFM_UART0_CTS_PIN +#define RTE_USART0 1 -#if defined(CONFIG_TFM_UART0_HWFC_ENABLED) -#define RTE_USART0_HWFC NRF_UARTE_HWFC_ENABLED -#else -#define RTE_USART0_HWFC NRF_UARTE_HWFC_DISABLED -#endif +#define RTE_USART0_PINS \ +{ \ + DT_FOREACH_CHILD_VARGS( \ + DT_PINCTRL_BY_NAME(DT_NODELABEL(uart0), default, 0), \ + DT_FOREACH_PROP_ELEM, psels, UART_PIN_INIT \ + ) \ +} #endif /* defined(CONFIG_TFM_SECURE_UART0) || DOMAIN_NS == 1U */ /* Configuration settings for Driver_USART1. */ -#if defined(CONFIG_TFM_SECURE_UART1) +#if defined(CONFIG_TFM_SECURE_UART1) && DOMAIN_NS != 1U -#define RTE_USART1 1 -/* Pin Selection (0xFFFFFFFF means Disconnected) */ -#define RTE_USART1_TXD_PIN CONFIG_TFM_UART1_TXD_PIN -#define RTE_USART1_RXD_PIN CONFIG_TFM_UART1_RXD_PIN -#define RTE_USART1_RTS_PIN CONFIG_TFM_UART1_RTS_PIN -#define RTE_USART1_CTS_PIN CONFIG_TFM_UART1_CTS_PIN +#define RTE_USART1 1 -#if defined(CONFIG_TFM_UART1_HWFC_ENABLED) -#define RTE_USART1_HWFC NRF_UARTE_HWFC_ENABLED -#else -#define RTE_USART1_HWFC NRF_UARTE_HWFC_DISABLED -#endif +#define RTE_USART1_PINS \ +{ \ + DT_FOREACH_CHILD_VARGS( \ + DT_PINCTRL_BY_NAME(DT_NODELABEL(uart1), default, 0), \ + DT_FOREACH_PROP_ELEM, psels, UART_PIN_INIT \ + ) \ +} #endif /* defined(CONFIG_TFM_SECURE_UART1) */ /* Configuration settings for Driver_FLASH0. */ -#define RTE_FLASH0 1 +#define RTE_FLASH0 1 #endif /* __RTE_DEVICE_H */ diff --git a/modules/tfm/tfm/boards/board/device_cfg.h b/modules/tfm/tfm/boards/board/device_cfg.h index a2ddd17012a4..d35c35d71e1b 100644 --- a/modules/tfm/tfm/boards/board/device_cfg.h +++ b/modules/tfm/tfm/boards/board/device_cfg.h @@ -7,27 +7,23 @@ #ifndef DEVICE_CFG_H__ #define DEVICE_CFG_H__ -/** - * \file device_cfg.h - * \brief - * This is the default device configuration file with all peripherals - * defined and configured to be use via the secure and/or non-secure base - * address. - */ +#include + /* ARRAY_SIZE causes a conflict as it is defined both by TF-M and indirectly by devicetree.h */ #undef ARRAY_SIZE -#include #include -#define TFM_UART uart##NRF_SECURE_UART_INSTANCE +#if defined(CONFIG_TFM_SECURE_UART0) || DOMAIN_NS == 1U +#define TFM_UART uart0 +#endif /* defined(CONFIG_TFM_SECURE_UART0) || DOMAIN_NS == 1U */ + +#if defined(CONFIG_TFM_SECURE_UART1) && DOMAIN_NS != 1U +#define TFM_UART uart1 +#endif /* defined(CONFIG_TFM_SECURE_UART1) */ #define DEFAULT_UART_BAUDRATE DT_PROP_OR(DT_NODELABEL(TFM_UART), current_speed, 115200) -#if (defined(CONFIG_TFM_SECURE_UART0) || DOMAIN_NS == 1U) && \ - defined(CONFIG_TFM_UART0_HWFC_ENABLED) -#define DEFAULT_UART_CONTROL ARM_USART_FLOW_CONTROL_RTS_CTS -#elif defined(CONFIG_TFM_SECURE_UART1) && \ - defined(CONFIG_TFM_UART1_HWFC_ENABLED) +#if DT_PROP(DT_NODELABEL(TFM_UART), hw_flow_control) #define DEFAULT_UART_CONTROL ARM_USART_FLOW_CONTROL_RTS_CTS #else #define DEFAULT_UART_CONTROL 0 diff --git a/modules/trusted-firmware-m/Kconfig b/modules/trusted-firmware-m/Kconfig index cf76b254edf6..f1679f826654 100644 --- a/modules/trusted-firmware-m/Kconfig +++ b/modules/trusted-firmware-m/Kconfig @@ -26,6 +26,14 @@ config TFM_REGRESSION_NS bool select NRF_TIMER0_SECURE +config TFM_LOG_LEVEL_SILENCE + default n + depends on $(dt_nodelabel_has_prop,uart0,pinctrl-names) || \ + $(dt_nodelabel_has_prop,uart1,pinctrl-names) + help + Overrule zephyr disable TF-M secure output if the uart1 node has not + assigned GPIO pins using pinctrl. + config TFM_SECURE_UART bool "TF-M configure UART instance as secure peripheral" default y if !TFM_LOG_LEVEL_SILENCE @@ -54,11 +62,13 @@ choice TFM_SECURE_UART_INSTANCE config TFM_SECURE_UART0 bool "TF-M logging will use UART0 instance" + depends on $(dt_nodelabel_has_prop,uart0,pinctrl-names) select NRF_UARTE0_SECURE select TFM_SECURE_UART_SHARE_INSTANCE if NRFX_UARTE0 || HAS_HW_NRF_UARTE0 config TFM_SECURE_UART1 bool "TF-M logging will use UART1 instance" + depends on $(dt_nodelabel_has_prop,uart1,pinctrl-names) select NRF_UARTE1_SECURE select TFM_SECURE_UART_SHARE_INSTANCE if NRFX_UARTE1 || HAS_HW_NRF_UARTE1 @@ -66,126 +76,6 @@ endchoice endif # TFM_SECURE_UART -menu "TF-M UART pins" - visible if BUILD_WITH_TFM - -config TFM_UART0_TXD_PIN - int "UART0 TXD pin" - default 29 if BOARD_NRF9160DK_NRF9160_NS - default 27 if BOARD_NRF9161DK_NRF9161_NS - default 20 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS - default 18 if BOARD_THINGY91_NRF9160_NS - default 4294967295 # 0xffffffff i.e. disconnected - help - The GPIO pin the TFM build system will use for UART0 TXD pin. - UART0 is used by TF-M as the log output for the non-secure image. - - Note: The non-secure image is only ever used when running the - TF-M regression tests. - -config TFM_UART0_RXD_PIN - int "UART0 RXD pin" - default 28 if BOARD_NRF9160DK_NRF9160_NS - default 26 if BOARD_NRF9161DK_NRF9161_NS - default 22 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS - default 19 if BOARD_THINGY91_NRF9160_NS - default 4294967295 # 0xffffffff i.e. disconnected - help - The GPIO pin the TFM build system will use for UART0 RXD pin. - UART0 is used by TF-M as the log output for the non-secure image. - - Note: The non-secure image is only ever used when running the - TF-M regression tests. - -config TFM_UART0_RTS_PIN - int "UART0 RTS pin" - default 27 if BOARD_NRF9160DK_NRF9160_NS - default 14 if BOARD_NRF9161DK_NRF9161_NS - default 19 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS - default 20 if BOARD_THINGY91_NRF9160_NS - default 4294967295 # 0xffffffff i.e. disconnected - help - The GPIO pin the TFM build system will use for UART0 RTS pin. - UART0 is used by TF-M as the log output for the non-secure image. - - Note: The non-secure image is only ever used when running the - TF-M regression tests. - -config TFM_UART0_CTS_PIN - int "UART0 CTS pin" - default 26 if BOARD_NRF9160DK_NRF9160_NS - default 15 if BOARD_NRF9161DK_NRF9161_NS - default 21 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS - default 21 if BOARD_THINGY91_NRF9160_NS - default 4294967295 # 0xffffffff i.e. disconnected - help - The GPIO pin the TFM build system will use for UART0 CTS pin. - UART0 is used by TF-M as the log output for the non-secure image. - - Note: The non-secure image is only ever used when running the - TF-M regression tests. - -config TFM_UART0_HWFC_ENABLED - bool "UART0 hardware flow control" - help - Enable hardware flow control on UART0 in the TFM build system. - -config TFM_UART1_TXD_PIN - int "UART1 TXD pin" - depends on TFM_SECURE_UART1 - default 1 if BOARD_NRF9160DK_NRF9160_NS - default 29 if BOARD_NRF9161DK_NRF9161_NS - default 25 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS - default 22 if BOARD_THINGY91_NRF9160_NS - default 4294967295 # 0xffffffff i.e. disconnected - help - The GPIO pin the TFM build system will use for UART1 TXD pin. - UART1 is used by TF-M as the log output for the secure image. - -config TFM_UART1_RXD_PIN - int "UART1 RXD pin" - depends on TFM_SECURE_UART1 - default 0 if BOARD_NRF9160DK_NRF9160_NS - default 28 if BOARD_NRF9161DK_NRF9161_NS - default 26 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS - default 23 if BOARD_THINGY91_NRF9160_NS - default 4294967295 # 0xffffffff i.e. disconnected - help - The GPIO pin the TFM build system will use for UART1 RXD pin. - UART1 is used by TF-M as the log output for the secure image. - -config TFM_UART1_RTS_PIN - int "UART1 RTS pin" - depends on TFM_SECURE_UART1 - default 14 if BOARD_NRF9160DK_NRF9160_NS - default 16 if BOARD_NRF9161DK_NRF9161_NS - default 5 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS - default 24 if BOARD_THINGY91_NRF9160_NS - default 4294967295 # 0xffffffff i.e. disconnected - help - The GPIO pin the TFM build system will use for UART1 RTS pin. - UART1 is used by TF-M as the log output for the secure image. - -config TFM_UART1_CTS_PIN - int "UART1 CTS pin" - depends on TFM_SECURE_UART1 - default 15 if BOARD_NRF9160DK_NRF9160_NS - default 17 if BOARD_NRF9161DK_NRF9161_NS - default 6 if BOARD_NRF5340DK_NRF5340_CPUAPP_NS - default 25 if BOARD_THINGY91_NRF9160_NS - default 4294967295 # 0xffffffff i.e. disconnected - help - The GPIO pin the TFM build system will use for UART1 CTS pin. - UART1 is used by TF-M as the log output for the secure image. - -config TFM_UART1_HWFC_ENABLED - bool "UART1 hardware flow control" - help - Enable hardware flow control on UART1 in the TFM build system. - -endmenu - - choice TFM_PROFILE_TYPE default TFM_PROFILE_TYPE_MINIMAL diff --git a/tests/tfm/tfm_regression_test/app.overlay b/tests/tfm/tfm_regression_test/app.overlay new file mode 100644 index 000000000000..2318e8eff54c --- /dev/null +++ b/tests/tfm/tfm_regression_test/app.overlay @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause + */ +&uart0 { + compatible = "nordic,nrf-uarte"; + current-speed = <115200>; + status = "okay"; + hw-flow-control; +}; + +&uart1 { + compatible = "nordic,nrf-uarte"; + current-speed = <115200>; + /* Set to disabled in application, since TF-M will be using it. */ + status = "disabled"; + hw-flow-control; +}; diff --git a/tests/tfm/tfm_regression_test/boards/nrf5340dk_nrf5340_cpuapp_ns.conf b/tests/tfm/tfm_regression_test/boards/nrf5340dk_nrf5340_cpuapp_ns.conf deleted file mode 100644 index 67eea5fb47e9..000000000000 --- a/tests/tfm/tfm_regression_test/boards/nrf5340dk_nrf5340_cpuapp_ns.conf +++ /dev/null @@ -1,9 +0,0 @@ -# Using the following configuration for TFM UART1 allows both secure and -# non-secure UART output to arrive on the two COM ports available on the -# newer (>=2.0.0) dev-kits. -# Users of older versioned dev-kits should take appropriate actions in -# order to get both UART outputs. See: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/ug_tfm.html#id7 -CONFIG_TFM_UART1_RXD_PIN=32 -CONFIG_TFM_UART1_TXD_PIN=33 -CONFIG_TFM_UART1_CTS_PIN=10 -CONFIG_TFM_UART1_RTS_PIN=11 diff --git a/tests/tfm/tfm_regression_test/prj.conf b/tests/tfm/tfm_regression_test/prj.conf index aa4773cfba14..6012cfb84903 100644 --- a/tests/tfm/tfm_regression_test/prj.conf +++ b/tests/tfm/tfm_regression_test/prj.conf @@ -24,10 +24,6 @@ CONFIG_TFM_NRF_PROVISIONING=y CONFIG_TFM_IPC=y CONFIG_TFM_ISOLATION_LEVEL=2 -# We need flow control for test output -CONFIG_TFM_UART0_HWFC_ENABLED=y -CONFIG_TFM_UART1_HWFC_ENABLED=y - # RNG CONFIG_PSA_WANT_GENERATE_RANDOM=y diff --git a/west.yml b/west.yml index cbd6537d12f8..8becd1d8d089 100644 --- a/west.yml +++ b/west.yml @@ -61,7 +61,7 @@ manifest: # https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/modules.html - name: zephyr repo-path: sdk-zephyr - revision: f1ee732cab5ebaa83ddf94f0d4c6f734d2684ea7 + revision: ff85910bf8ed1aac0571bca0e7f206782234efbb import: # In addition to the zephyr repository itself, NCS also # imports the contents of zephyr/west.yml at the above @@ -145,7 +145,7 @@ manifest: - name: trusted-firmware-m repo-path: sdk-trusted-firmware-m path: modules/tee/tf-m/trusted-firmware-m - revision: 6854dd509f4252cb0f9724c4a181586abf31a12d + revision: 8f6d96538f2221ac3a5c7df2e8fdbe3bd147d2ce - name: matter repo-path: sdk-connectedhomeip path: modules/lib/matter