Test: Enable CoreTest config on Muscas and AN524
Add abstraction for platform features that are used by the core tests.
This makes possible that platforms that do not support certain platform
features can mock the platform behaviour.
Detailed changes:
* Enable Core tests in MUSCA_A, MUSCA_B1 and AN524 platforms
* Add tfm_plat_test.h enumerating the test interface expected from
platform implementations by the Core Tests
* Move platform features used by Core tests to the platform directory
on MPS2 platforms
* Mock platform features used by Core tests in the platform directory
on MUSCA_A, MUSCA_B1 and AN524 platforms
* Link MT25QL device driver structure to TFM_SP_STORAGE partition so
that SST init can run in isolation level 3
Change-Id: I7385f34e364b8be330cf214b8f148affaa76613d
Signed-off-by: Mate Toth-Pal <mate.toth-pal@arm.com>
diff --git a/platform/ext/Mps2AN519.cmake b/platform/ext/Mps2AN519.cmake
index 1268299..6dcf5f9 100644
--- a/platform/ext/Mps2AN519.cmake
+++ b/platform/ext/Mps2AN519.cmake
@@ -50,6 +50,7 @@
embedded_include_directories(PATH "${PLATFORM_DIR}/target/mps2/an519/retarget" ABSOLUTE)
embedded_include_directories(PATH "${PLATFORM_DIR}/target/mps2/an519/native_drivers" ABSOLUTE)
embedded_include_directories(PATH "${PLATFORM_DIR}/target/mps2/an519/partition" ABSOLUTE)
+embedded_include_directories(PATH "${PLATFORM_DIR}/../include" ABSOLUTE)
#Gather all source files we need.
if (NOT DEFINED BUILD_CMSIS_CORE)
@@ -126,6 +127,12 @@
embedded_include_directories(PATH "${PLATFORM_DIR}/common" ABSOLUTE)
endif()
+if (NOT DEFINED BUILD_PLAT_TEST)
+ message(FATAL_ERROR "Configuration variable BUILD_PLAT_TEST (true|false) is undefined!")
+elseif(BUILD_PLAT_TEST)
+ list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/mps2/an519/plat_test.c")
+endif()
+
if (NOT DEFINED BUILD_TARGET_HARDWARE_KEYS)
message(FATAL_ERROR "Configuration variable BUILD_TARGET_HARDWARE_KEYS (true|false) is undefined!")
elseif(BUILD_TARGET_HARDWARE_KEYS)
diff --git a/platform/ext/Mps2AN521.cmake b/platform/ext/Mps2AN521.cmake
index 339ebf0..90192c4 100644
--- a/platform/ext/Mps2AN521.cmake
+++ b/platform/ext/Mps2AN521.cmake
@@ -51,6 +51,7 @@
embedded_include_directories(PATH "${PLATFORM_DIR}/target/mps2/an521/retarget" ABSOLUTE)
embedded_include_directories(PATH "${PLATFORM_DIR}/target/mps2/an521/native_drivers" ABSOLUTE)
embedded_include_directories(PATH "${PLATFORM_DIR}/target/mps2/an521/partition" ABSOLUTE)
+embedded_include_directories(PATH "${PLATFORM_DIR}/../include" ABSOLUTE)
#Gather all source files we need.
if (NOT DEFINED BUILD_CMSIS_CORE)
@@ -127,6 +128,12 @@
embedded_include_directories(PATH "${PLATFORM_DIR}/common" ABSOLUTE)
endif()
+if (NOT DEFINED BUILD_PLAT_TEST)
+ message(FATAL_ERROR "Configuration variable BUILD_PLAT_TEST (true|false) is undefined!")
+elseif(BUILD_PLAT_TEST)
+ list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/mps2/an521/plat_test.c")
+endif()
+
if (NOT DEFINED BUILD_TARGET_HARDWARE_KEYS)
message(FATAL_ERROR "Configuration variable BUILD_TARGET_HARDWARE_KEYS (true|false) is undefined!")
elseif(BUILD_TARGET_HARDWARE_KEYS)
diff --git a/platform/ext/Mps3AN524.cmake b/platform/ext/Mps3AN524.cmake
index 0230d2e..04d0e03 100644
--- a/platform/ext/Mps3AN524.cmake
+++ b/platform/ext/Mps3AN524.cmake
@@ -133,6 +133,12 @@
embedded_include_directories(PATH "${PLATFORM_DIR}/common" ABSOLUTE)
endif()
+if (NOT DEFINED BUILD_PLAT_TEST)
+ message(FATAL_ERROR "Configuration variable BUILD_PLAT_TEST (true|false) is undefined!")
+elseif(BUILD_PLAT_TEST)
+ list(APPEND ALL_SRC_C_S "${AN524_DIR}/plat_test.c")
+endif()
+
if (NOT DEFINED BUILD_TARGET_HARDWARE_KEYS)
message(FATAL_ERROR "Configuration variable BUILD_TARGET_HARDWARE_KEYS (true|false) is undefined!")
elseif(BUILD_TARGET_HARDWARE_KEYS)
diff --git a/platform/ext/musca_a.cmake b/platform/ext/musca_a.cmake
index 950e96b..d8db31a 100644
--- a/platform/ext/musca_a.cmake
+++ b/platform/ext/musca_a.cmake
@@ -48,6 +48,7 @@
embedded_include_directories(PATH "${PLATFORM_DIR}/target/musca_a/Native_Driver" ABSOLUTE)
embedded_include_directories(PATH "${PLATFORM_DIR}/target/musca_a/partition" ABSOLUTE)
embedded_include_directories(PATH "${PLATFORM_DIR}/target/musca_a/Libraries" ABSOLUTE)
+embedded_include_directories(PATH "${PLATFORM_DIR}/../include" ABSOLUTE)
#Gather all source files we need.
if (NOT DEFINED BUILD_CMSIS_CORE)
@@ -127,6 +128,12 @@
embedded_include_directories(PATH "${PLATFORM_DIR}/common" ABSOLUTE)
endif()
+if (NOT DEFINED BUILD_PLAT_TEST)
+ message(FATAL_ERROR "Configuration variable BUILD_PLAT_TEST (true|false) is undefined!")
+elseif(BUILD_PLAT_TEST)
+ list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/musca_a/plat_test.c")
+endif()
+
if (NOT DEFINED BUILD_TARGET_HARDWARE_KEYS)
message(FATAL_ERROR "Configuration variable BUILD_TARGET_HARDWARE_KEYS (true|false) is undefined!")
elseif(BUILD_TARGET_HARDWARE_KEYS)
diff --git a/platform/ext/musca_b1.cmake b/platform/ext/musca_b1.cmake
index 894d731..4eb6f3b 100644
--- a/platform/ext/musca_b1.cmake
+++ b/platform/ext/musca_b1.cmake
@@ -52,6 +52,7 @@
embedded_include_directories(PATH "${PLATFORM_DIR}/target/musca_b1/Native_Driver" ABSOLUTE)
embedded_include_directories(PATH "${PLATFORM_DIR}/target/musca_b1/partition" ABSOLUTE)
embedded_include_directories(PATH "${PLATFORM_DIR}/target/musca_b1/services/include" ABSOLUTE)
+embedded_include_directories(PATH "${PLATFORM_DIR}/../include" ABSOLUTE)
# Gather all source files we need.
if (TFM_PARTITION_PLATFORM)
@@ -133,6 +134,12 @@
embedded_include_directories(PATH "${PLATFORM_DIR}/common" ABSOLUTE)
endif()
+if (NOT DEFINED BUILD_PLAT_TEST)
+ message(FATAL_ERROR "Configuration variable BUILD_PLAT_TEST (true|false) is undefined!")
+elseif(BUILD_PLAT_TEST)
+ list(APPEND ALL_SRC_C_S "${PLATFORM_DIR}/target/musca_b1/plat_test.c")
+endif()
+
if (NOT DEFINED BUILD_TARGET_HARDWARE_KEYS)
message(FATAL_ERROR "Configuration variable BUILD_TARGET_HARDWARE_KEYS (true|false) is undefined!")
elseif (BUILD_TARGET_HARDWARE_KEYS)
diff --git a/platform/ext/target/mps2/an519/plat_test.c b/platform/ext/target/mps2/an519/plat_test.c
new file mode 100644
index 0000000..a136386
--- /dev/null
+++ b/platform/ext/target/mps2/an519/plat_test.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "platform_retarget.h"
+#include "platform_retarget_dev.h"
+#include "tfm_plat_test.h"
+
+#include "smm_mps2.h"
+
+#define USERLED_MASK (0x3)
+#define MPS2_USERPB0_BASE (0x50302008)
+#define MPS2_USERPB0_MASK (0x1)
+
+void tfm_plat_test_wait_user_button_pressed(void)
+{
+ volatile uint32_t *p_btn = (volatile uint32_t *) MPS2_USERPB0_BASE;
+
+ /* Wait until user button 0 is pressed */
+ while (!(*p_btn & MPS2_USERPB0_MASK)) {
+ ;
+ }
+}
+
+void tfm_plat_test_wait_user_button_released(void)
+{
+ volatile uint32_t *p_btn = (volatile uint32_t *) MPS2_USERPB0_BASE;
+
+ /* Wait until user button 0 is released */
+ while ((*p_btn & MPS2_USERPB0_MASK)) {
+ ;
+ }
+}
+
+uint32_t tfm_plat_test_get_led_status(void)
+{
+ struct arm_mps2_fpgaio_t *fpgaio = SEC_MPS2_FPGAIO;
+ return fpgaio->LED;
+}
+
+void tfm_plat_test_set_led_status(uint32_t status)
+{
+ struct arm_mps2_fpgaio_t *fpgaio = SEC_MPS2_FPGAIO;
+ fpgaio->LED = status;
+}
+
+uint32_t tfm_plat_test_get_userled_mask(void)
+{
+ return USERLED_MASK;
+}
+
diff --git a/platform/ext/target/mps2/an521/plat_test.c b/platform/ext/target/mps2/an521/plat_test.c
new file mode 100644
index 0000000..a136386
--- /dev/null
+++ b/platform/ext/target/mps2/an521/plat_test.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "platform_retarget.h"
+#include "platform_retarget_dev.h"
+#include "tfm_plat_test.h"
+
+#include "smm_mps2.h"
+
+#define USERLED_MASK (0x3)
+#define MPS2_USERPB0_BASE (0x50302008)
+#define MPS2_USERPB0_MASK (0x1)
+
+void tfm_plat_test_wait_user_button_pressed(void)
+{
+ volatile uint32_t *p_btn = (volatile uint32_t *) MPS2_USERPB0_BASE;
+
+ /* Wait until user button 0 is pressed */
+ while (!(*p_btn & MPS2_USERPB0_MASK)) {
+ ;
+ }
+}
+
+void tfm_plat_test_wait_user_button_released(void)
+{
+ volatile uint32_t *p_btn = (volatile uint32_t *) MPS2_USERPB0_BASE;
+
+ /* Wait until user button 0 is released */
+ while ((*p_btn & MPS2_USERPB0_MASK)) {
+ ;
+ }
+}
+
+uint32_t tfm_plat_test_get_led_status(void)
+{
+ struct arm_mps2_fpgaio_t *fpgaio = SEC_MPS2_FPGAIO;
+ return fpgaio->LED;
+}
+
+void tfm_plat_test_set_led_status(uint32_t status)
+{
+ struct arm_mps2_fpgaio_t *fpgaio = SEC_MPS2_FPGAIO;
+ fpgaio->LED = status;
+}
+
+uint32_t tfm_plat_test_get_userled_mask(void)
+{
+ return USERLED_MASK;
+}
+
diff --git a/platform/ext/target/mps3/an524/plat_test.c b/platform/ext/target/mps3/an524/plat_test.c
new file mode 100644
index 0000000..80408a9
--- /dev/null
+++ b/platform/ext/target/mps3/an524/plat_test.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "platform/include/tfm_plat_defs.h"
+#include "tfm_plat_test.h"
+
+#define USERLED_MASK (0x3)
+#define BTN_WAIT_INIT_COUNTER_VALUE (10000u)
+
+/**
+ * \brief Store the state of the mocked LED
+ *
+ * This variable have to be linked to the data section of the partition
+ * TFM_SP_CORE_TEST so that in case of in case of isolation within the secure
+ * domain the Core Test service can access it.
+ */
+uint32_t led_status
+ TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_SP_CORE_TEST")
+ = 0x02u;
+
+/**
+ * \brief Simulate user reaction time
+ */
+static void busy_wait_to_simulate_user(void)
+{
+ volatile uint32_t counter = BTN_WAIT_INIT_COUNTER_VALUE;
+ while (counter)
+ {
+ --counter;
+ }
+}
+
+void tfm_plat_test_wait_user_button_pressed(void)
+{
+ busy_wait_to_simulate_user();
+}
+
+void tfm_plat_test_wait_user_button_released(void)
+{
+ busy_wait_to_simulate_user();
+}
+
+uint32_t tfm_plat_test_get_led_status(void)
+{
+ return led_status;
+}
+
+void tfm_plat_test_set_led_status(uint32_t status)
+{
+ led_status = status & USERLED_MASK;
+}
+
+uint32_t tfm_plat_test_get_userled_mask(void)
+{
+ return USERLED_MASK;
+}
+
diff --git a/platform/ext/target/mps3/an524/tfm_peripherals_def.h b/platform/ext/target/mps3/an524/tfm_peripherals_def.h
index e56cde2..97922be 100644
--- a/platform/ext/target/mps3/an524/tfm_peripherals_def.h
+++ b/platform/ext/target/mps3/an524/tfm_peripherals_def.h
@@ -19,6 +19,7 @@
extern struct tfm_spm_partition_platform_data_t tfm_peripheral_std_uart;
#define TFM_PERIPHERAL_STD_UART (&tfm_peripheral_std_uart)
+#define TFM_PERIPHERAL_FPGA_IO (0)
#ifdef __cplusplus
}
diff --git a/platform/ext/target/musca_a/Device/Source/device_definition.c b/platform/ext/target/musca_a/Device/Source/device_definition.c
index cdafe2b..5b93b46 100644
--- a/platform/ext/target/musca_a/Device/Source/device_definition.c
+++ b/platform/ext/target/musca_a/Device/Source/device_definition.c
@@ -26,6 +26,7 @@
#include "device_cfg.h"
#include "device_definition.h"
#include "platform_base_address.h"
+#include "tfm_plat_defs.h"
/* ======= Peripheral configuration structure definitions ======= */
/* MUSCA A1 SCC driver structures */
@@ -620,7 +621,9 @@
#endif
#if (defined(MT25QL_NS) && defined(QSPI_IP6514E_NS))
-struct mt25ql_dev_t MT25QL_DEV_NS = {
+struct mt25ql_dev_t MT25QL_DEV_NS
+ TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_SP_STORAGE")
+ = {
.controller = &QSPI_DEV_NS,
.direct_access_start_addr = MUSCA_QSPI_FLASH_NS_BASE,
.baud_rate_div = 4U,
diff --git a/platform/ext/target/musca_a/plat_test.c b/platform/ext/target/musca_a/plat_test.c
new file mode 100644
index 0000000..80408a9
--- /dev/null
+++ b/platform/ext/target/musca_a/plat_test.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "platform/include/tfm_plat_defs.h"
+#include "tfm_plat_test.h"
+
+#define USERLED_MASK (0x3)
+#define BTN_WAIT_INIT_COUNTER_VALUE (10000u)
+
+/**
+ * \brief Store the state of the mocked LED
+ *
+ * This variable have to be linked to the data section of the partition
+ * TFM_SP_CORE_TEST so that in case of in case of isolation within the secure
+ * domain the Core Test service can access it.
+ */
+uint32_t led_status
+ TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_SP_CORE_TEST")
+ = 0x02u;
+
+/**
+ * \brief Simulate user reaction time
+ */
+static void busy_wait_to_simulate_user(void)
+{
+ volatile uint32_t counter = BTN_WAIT_INIT_COUNTER_VALUE;
+ while (counter)
+ {
+ --counter;
+ }
+}
+
+void tfm_plat_test_wait_user_button_pressed(void)
+{
+ busy_wait_to_simulate_user();
+}
+
+void tfm_plat_test_wait_user_button_released(void)
+{
+ busy_wait_to_simulate_user();
+}
+
+uint32_t tfm_plat_test_get_led_status(void)
+{
+ return led_status;
+}
+
+void tfm_plat_test_set_led_status(uint32_t status)
+{
+ led_status = status & USERLED_MASK;
+}
+
+uint32_t tfm_plat_test_get_userled_mask(void)
+{
+ return USERLED_MASK;
+}
+
diff --git a/platform/ext/target/musca_a/tfm_peripherals_def.h b/platform/ext/target/musca_a/tfm_peripherals_def.h
index f47e756..872a73a 100644
--- a/platform/ext/target/musca_a/tfm_peripherals_def.h
+++ b/platform/ext/target/musca_a/tfm_peripherals_def.h
@@ -15,5 +15,6 @@
extern struct tfm_spm_partition_platform_data_t tfm_peripheral_std_uart;
#define TFM_PERIPHERAL_STD_UART (&tfm_peripheral_std_uart)
+#define TFM_PERIPHERAL_FPGA_IO (0)
#endif /* __TFM_PERIPHERALS_DEF_H__ */
diff --git a/platform/ext/target/musca_b1/plat_test.c b/platform/ext/target/musca_b1/plat_test.c
new file mode 100644
index 0000000..80408a9
--- /dev/null
+++ b/platform/ext/target/musca_b1/plat_test.c
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "platform/include/tfm_plat_defs.h"
+#include "tfm_plat_test.h"
+
+#define USERLED_MASK (0x3)
+#define BTN_WAIT_INIT_COUNTER_VALUE (10000u)
+
+/**
+ * \brief Store the state of the mocked LED
+ *
+ * This variable have to be linked to the data section of the partition
+ * TFM_SP_CORE_TEST so that in case of in case of isolation within the secure
+ * domain the Core Test service can access it.
+ */
+uint32_t led_status
+ TFM_LINK_SET_RW_IN_PARTITION_SECTION("TFM_SP_CORE_TEST")
+ = 0x02u;
+
+/**
+ * \brief Simulate user reaction time
+ */
+static void busy_wait_to_simulate_user(void)
+{
+ volatile uint32_t counter = BTN_WAIT_INIT_COUNTER_VALUE;
+ while (counter)
+ {
+ --counter;
+ }
+}
+
+void tfm_plat_test_wait_user_button_pressed(void)
+{
+ busy_wait_to_simulate_user();
+}
+
+void tfm_plat_test_wait_user_button_released(void)
+{
+ busy_wait_to_simulate_user();
+}
+
+uint32_t tfm_plat_test_get_led_status(void)
+{
+ return led_status;
+}
+
+void tfm_plat_test_set_led_status(uint32_t status)
+{
+ led_status = status & USERLED_MASK;
+}
+
+uint32_t tfm_plat_test_get_userled_mask(void)
+{
+ return USERLED_MASK;
+}
+
diff --git a/platform/ext/target/musca_b1/tfm_peripherals_def.h b/platform/ext/target/musca_b1/tfm_peripherals_def.h
index 6663f8b..eae19a1 100644
--- a/platform/ext/target/musca_b1/tfm_peripherals_def.h
+++ b/platform/ext/target/musca_b1/tfm_peripherals_def.h
@@ -19,6 +19,7 @@
extern struct tfm_spm_partition_platform_data_t tfm_peripheral_std_uart;
#define TFM_PERIPHERAL_STD_UART (&tfm_peripheral_std_uart)
+#define TFM_PERIPHERAL_FPGA_IO (0)
#ifdef __cplusplus
}
diff --git a/platform/include/tfm_plat_test.h b/platform/include/tfm_plat_test.h
new file mode 100644
index 0000000..a71c0fc
--- /dev/null
+++ b/platform/include/tfm_plat_test.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2019, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_PLAT_TEST_H__
+#define __TFM_PLAT_TEST_H__
+
+#include "tfm_plat_defs.h"
+
+/**
+ * \brief Busy wait until the user presses a specific button
+ */
+TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_CORE_TEST")
+void tfm_plat_test_wait_user_button_pressed(void);
+
+/**
+ * \brief Busy wait until the user releases a specific button
+ */
+TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_CORE_TEST")
+void tfm_plat_test_wait_user_button_released(void);
+
+/**
+ * \brief Get the status of the LEDs used by tests
+ *
+ * \return Returns the current status of LEDs
+ */
+TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_CORE_TEST")
+uint32_t tfm_plat_test_get_led_status(void);
+
+/**
+ * \brief Sets the status of the LEDs used by tests
+ *
+ * \param[in] status The status to be set
+ */
+TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_CORE_TEST")
+void tfm_plat_test_set_led_status(uint32_t status);
+
+/**
+ * \brief Get the mask of the LEDs used for testing
+ *
+ * \return Returns the mask of the LEDs used for testing
+ */
+TFM_LINK_SET_RO_IN_PARTITION_SECTION("TFM_SP_CORE_TEST")
+uint32_t tfm_plat_test_get_userled_mask(void);
+
+#endif /* __TFM_PLAT_TEST_H__ */