From f7d4af3b53e003d54a1eb080b1add14af5e24e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20Erik=20Gj=C3=B8rvad?= Date: Thu, 14 Nov 2024 13:34:00 +0100 Subject: [PATCH] nrf54l: Removing hardcoded clock frequency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding in config that takes clock-frequency from device tree and passes it to TF-m Removing hardcoded NRF_CONFIG_CPU_FREQ_MHZ Signed-off-by: Dag Erik Gjørvad --- modules/trusted-firmware-m/CMakeLists.txt | 7 +++++++ modules/trusted-firmware-m/Kconfig | 11 +++++++++++ modules/trusted-firmware-m/tfm_boards/CMakeLists.txt | 3 +++ .../tfm_boards/nrf54l15_cpuapp/ns/cpuarch_ns.cmake | 2 -- .../trusted-firmware-m/tfm_boards/ns/CMakeLists.txt | 1 + tests/tfm/tfm_psa_test/CMakeLists.txt | 1 + tests/tfm/tfm_regression_test/CMakeLists.txt | 1 + 7 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/trusted-firmware-m/CMakeLists.txt b/modules/trusted-firmware-m/CMakeLists.txt index 62ec748b929d..d3a3190c2cdd 100644 --- a/modules/trusted-firmware-m/CMakeLists.txt +++ b/modules/trusted-firmware-m/CMakeLists.txt @@ -237,6 +237,13 @@ if(CONFIG_NFCT_PINS_AS_GPIOS OR CONFIG_TFM_NFCT_PINS_AS_GPIOS) ) endif() +if(CONFIG_TFM_CPU_FREQ_MHZ) + set_property(TARGET zephyr_property_target + APPEND PROPERTY TFM_CMAKE_OPTIONS + -DTFM_CPU_FREQ_MHZ=${CONFIG_TFM_CPU_FREQ_MHZ} + ) +endif() + if(CONFIG_NRF_TRACE_PORT) set_property(TARGET zephyr_property_target APPEND PROPERTY TFM_CMAKE_OPTIONS diff --git a/modules/trusted-firmware-m/Kconfig b/modules/trusted-firmware-m/Kconfig index 7021d6771d49..6c4d9007d518 100644 --- a/modules/trusted-firmware-m/Kconfig +++ b/modules/trusted-firmware-m/Kconfig @@ -291,6 +291,17 @@ config TFM_PROFILE_TYPE_MINIMAL and reproduce the desired configuration through kconfig fragments. endchoice +config TFM_CPU_FREQ_MHZ + int + default $(div, $(dt_node_int_prop_int,/cpus/cpu@0,clock-frequency), 1000000) \ + if $(dt_node_has_prop,/cpus/cpu@0,clock-frequency) + default $(div, $(dt_node_int_prop_int,/cpus/cpu@1,clock-frequency), 1000000) \ + if $(dt_node_has_prop,/cpus/cpu@1,clock-frequency) + default 128 + help + Gives access to the cpu-clock frequency from the device tree when + building with TF-m. + config TFM_NFCT_PINS_AS_GPIOS bool default y if !DT_HAS_NORDIC_NRF_NFCT_ENABLED diff --git a/modules/trusted-firmware-m/tfm_boards/CMakeLists.txt b/modules/trusted-firmware-m/tfm_boards/CMakeLists.txt index 4cf9a85bb92c..91e309d29104 100644 --- a/modules/trusted-firmware-m/tfm_boards/CMakeLists.txt +++ b/modules/trusted-firmware-m/tfm_boards/CMakeLists.txt @@ -146,6 +146,9 @@ if (CONFIG_NFCT_PINS_AS_GPIOS) target_compile_definitions(platform_s PUBLIC CONFIG_NFCT_PINS_AS_GPIOS) endif() +if (TFM_CPU_FREQ_MHZ) + target_compile_definitions(platform_s PUBLIC NRF_CONFIG_CPU_FREQ_MHZ=${TFM_CPU_FREQ_MHZ}) +endif() if (CONFIG_NRF_TRACE_PORT) target_compile_definitions(platform_s PUBLIC ENABLE_TRACE) diff --git a/modules/trusted-firmware-m/tfm_boards/nrf54l15_cpuapp/ns/cpuarch_ns.cmake b/modules/trusted-firmware-m/tfm_boards/nrf54l15_cpuapp/ns/cpuarch_ns.cmake index 622a3414fcc8..6bec447213d9 100644 --- a/modules/trusted-firmware-m/tfm_boards/nrf54l15_cpuapp/ns/cpuarch_ns.cmake +++ b/modules/trusted-firmware-m/tfm_boards/nrf54l15_cpuapp/ns/cpuarch_ns.cmake @@ -7,6 +7,4 @@ set(PLATFORM_DIR ${CMAKE_CURRENT_LIST_DIR}) set(PLATFORM_PATH ${CMAKE_CURRENT_LIST_DIR}) -add_compile_definitions(NRF_CONFIG_CPU_FREQ_MHZ=128) - include(${CMAKE_CURRENT_LIST_DIR}/common/nrf54l15/cpuarch.cmake) diff --git a/modules/trusted-firmware-m/tfm_boards/ns/CMakeLists.txt b/modules/trusted-firmware-m/tfm_boards/ns/CMakeLists.txt index b794e386c151..de90fb7330e0 100644 --- a/modules/trusted-firmware-m/tfm_boards/ns/CMakeLists.txt +++ b/modules/trusted-firmware-m/tfm_boards/ns/CMakeLists.txt @@ -52,6 +52,7 @@ if(TFM_PARTITION_PLATFORM) PUBLIC FIRMWARE_INFO_MAGIC=${FIRMWARE_INFO_MAGIC} EXT_API_MAGIC=${EXT_API_MAGIC} + NRF_CONFIG_CPU_FREQ_MHZ=${NRF_CONFIG_CPU_FREQ_MHZ} ) target_sources(platform_ns diff --git a/tests/tfm/tfm_psa_test/CMakeLists.txt b/tests/tfm/tfm_psa_test/CMakeLists.txt index f5e54365cdf9..8667aa0c01d7 100644 --- a/tests/tfm/tfm_psa_test/CMakeLists.txt +++ b/tests/tfm/tfm_psa_test/CMakeLists.txt @@ -110,6 +110,7 @@ ExternalProject_Add(tfm_psa_arch_test_app -DCMAKE_BUILD_TYPE=${tfm_ns_CMAKE_BUILD_TYPE} -DTEST_PSA_API=${TEST_PSA_API} -DZEPHYR_NRF_MODULE_DIR=${ZEPHYR_NRF_MODULE_DIR} + -DNRF_CONFIG_CPU_FREQ_MHZ=${CONFIG_TFM_CPU_FREQ_MHZ} BUILD_COMMAND ${CMAKE_COMMAND} --build . INSTALL_COMMAND "" BUILD_ALWAYS True diff --git a/tests/tfm/tfm_regression_test/CMakeLists.txt b/tests/tfm/tfm_regression_test/CMakeLists.txt index 64f043a73421..8479dd03e898 100644 --- a/tests/tfm/tfm_regression_test/CMakeLists.txt +++ b/tests/tfm/tfm_regression_test/CMakeLists.txt @@ -68,6 +68,7 @@ ExternalProject_Add(tfm_regression_test_app -DQCBOR_PATH${QCBOR_PATH_TYPE}=${CONFIG_TFM_QCBOR_PATH} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DZEPHYR_NRF_MODULE_DIR=${ZEPHYR_NRF_MODULE_DIR} + -DNRF_CONFIG_CPU_FREQ_MHZ=${CONFIG_TFM_CPU_FREQ_MHZ} BUILD_COMMAND ${CMAKE_COMMAND} --build . INSTALL_COMMAND "" BUILD_ALWAYS True