Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame^] | 1 | From 6ab17eeb8225cdf4afc6956c9a2774d60866c36d Mon Sep 17 00:00:00 2001 |
| 2 | From: Satish Kumar <satish.kumar01@arm.com> |
| 3 | Date: Mon, 28 Mar 2022 05:16:50 +0100 |
| 4 | Subject: [PATCH 1/6] corstone1000: platform secure test framework |
| 5 | |
| 6 | Change-Id: Ib781927f0add93ec9c06515d251e79518ee1db6e |
| 7 | Signed-off-by: Satish Kumar <satish.kumar01@arm.com> |
| 8 | Upstream-Status: Accepted [TF-Mv1.7.0] |
| 9 | --- |
| 10 | .../arm/corstone1000/Native_Driver/firewall.c | 15 ++ |
| 11 | .../arm/corstone1000/Native_Driver/firewall.h | 5 + |
| 12 | .../ci_regression_tests/CMakeLists.txt | 45 +++++ |
| 13 | .../corstone1000/ci_regression_tests/s_test.c | 186 ++++++++++++++++++ |
| 14 | .../corstone1000/ci_regression_tests/s_test.h | 30 +++ |
| 15 | .../ci_regression_tests/s_test_config.cmake | 8 + |
| 16 | 6 files changed, 289 insertions(+) |
| 17 | create mode 100644 platform/ext/target/arm/corstone1000/ci_regression_tests/CMakeLists.txt |
| 18 | create mode 100644 platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.c |
| 19 | create mode 100644 platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.h |
| 20 | create mode 100644 platform/ext/target/arm/corstone1000/ci_regression_tests/s_test_config.cmake |
| 21 | |
| 22 | diff --git a/platform/ext/target/arm/corstone1000/Native_Driver/firewall.c b/platform/ext/target/arm/corstone1000/Native_Driver/firewall.c |
| 23 | index 788cc3ec92..356b85e9d5 100755 |
| 24 | --- a/platform/ext/target/arm/corstone1000/Native_Driver/firewall.c |
| 25 | +++ b/platform/ext/target/arm/corstone1000/Native_Driver/firewall.c |
| 26 | @@ -293,6 +293,21 @@ void fc_enable_mpl(enum rgn_mpe_t mpe, enum rgn_mpl_t mpl) |
| 27 | ptr->rgn_mpl3 |= (mpl & RGN_MPL_EN_MASK); |
| 28 | } |
| 29 | |
| 30 | +void fc_read_mpl(enum rgn_mpe_t mpe, enum rgn_mpl_t* mpl) |
| 31 | +{ |
| 32 | + struct _firewall_pe_rwe_reg_map_t *ptr = |
| 33 | + (struct _firewall_pe_rwe_reg_map_t *)fw_data.rwe_ptr; |
| 34 | + if (mpe == RGN_MPE0) |
| 35 | + *mpl = (ptr->rgn_mpl0 & RGN_MPL_EN_MASK); |
| 36 | + else if (mpe == RGN_MPE1) |
| 37 | + *mpl = (ptr->rgn_mpl1 & RGN_MPL_EN_MASK); |
| 38 | + else if (mpe == RGN_MPE2) |
| 39 | + *mpl = (ptr->rgn_mpl2 & RGN_MPL_EN_MASK); |
| 40 | + else if (mpe == RGN_MPE3) |
| 41 | + *mpl = (ptr->rgn_mpl3 & RGN_MPL_EN_MASK); |
| 42 | +} |
| 43 | + |
| 44 | + |
| 45 | void fc_disable_mpl(enum rgn_mpe_t mpe, enum rgn_mpl_t mpl) |
| 46 | { |
| 47 | struct _firewall_pe_rwe_reg_map_t *ptr = |
| 48 | diff --git a/platform/ext/target/arm/corstone1000/Native_Driver/firewall.h b/platform/ext/target/arm/corstone1000/Native_Driver/firewall.h |
| 49 | index 48c86725ef..17afe6a92f 100755 |
| 50 | --- a/platform/ext/target/arm/corstone1000/Native_Driver/firewall.h |
| 51 | +++ b/platform/ext/target/arm/corstone1000/Native_Driver/firewall.h |
| 52 | @@ -247,6 +247,11 @@ void fc_init_mpl(enum rgn_mpe_t mpe); |
| 53 | */ |
| 54 | void fc_enable_mpl(enum rgn_mpe_t mpe, enum rgn_mpl_t mpl); |
| 55 | |
| 56 | +/** |
| 57 | + * \brief Reads Master Permission List in the selected Firewall Component |
| 58 | + */ |
| 59 | +void fc_read_mpl(enum rgn_mpe_t mpe, enum rgn_mpl_t* mpl); |
| 60 | + |
| 61 | /** |
| 62 | * \brief Disables Master Permission List in the selected Firewall Component |
| 63 | */ |
| 64 | diff --git a/platform/ext/target/arm/corstone1000/ci_regression_tests/CMakeLists.txt b/platform/ext/target/arm/corstone1000/ci_regression_tests/CMakeLists.txt |
| 65 | new file mode 100644 |
| 66 | index 0000000000..70e1c20e4e |
| 67 | --- /dev/null |
| 68 | +++ b/platform/ext/target/arm/corstone1000/ci_regression_tests/CMakeLists.txt |
| 69 | @@ -0,0 +1,45 @@ |
| 70 | +#------------------------------------------------------------------------------- |
| 71 | +# Copyright (c) 2021-22, Arm Limited. All rights reserved. |
| 72 | +# |
| 73 | +# SPDX-License-Identifier: BSD-3-Clause |
| 74 | +# |
| 75 | +#------------------------------------------------------------------------------- |
| 76 | + |
| 77 | +cmake_policy(SET CMP0079 NEW) |
| 78 | + |
| 79 | +include(${CMAKE_CURRENT_SOURCE_DIR}/s_test_config.cmake) |
| 80 | + |
| 81 | +####################### Secure ################################################# |
| 82 | + |
| 83 | +add_library(corstone1000_test_s STATIC EXCLUDE_FROM_ALL) |
| 84 | + |
| 85 | +target_sources(corstone1000_test_s |
| 86 | + PRIVATE |
| 87 | + ${CMAKE_CURRENT_SOURCE_DIR}/s_test.c |
| 88 | + ../Native_Driver/firewall.c |
| 89 | +) |
| 90 | + |
| 91 | +target_include_directories(corstone1000_test_s |
| 92 | + PRIVATE |
| 93 | + ${CMAKE_CURRENT_SOURCE_DIR} |
| 94 | + ../Device/Include |
| 95 | + ../Native_Driver |
| 96 | +) |
| 97 | + |
| 98 | +# Example test links tfm_test_suite_extra_common to use related interface |
| 99 | +target_link_libraries(corstone1000_test_s |
| 100 | + PRIVATE |
| 101 | + tfm_test_suite_extra_common |
| 102 | + tfm_log |
| 103 | +) |
| 104 | + |
| 105 | +target_compile_definitions(corstone1000_test_s |
| 106 | + PRIVATE |
| 107 | + $<$<BOOL:${PLATFORM_IS_FVP}>:PLATFORM_IS_FVP> |
| 108 | +) |
| 109 | + |
| 110 | +# The corstone1000_test_s library is linked by tfm_test_suite_extra_s |
| 111 | +target_link_libraries(tfm_test_suite_extra_s |
| 112 | + PRIVATE |
| 113 | + corstone1000_test_s |
| 114 | +) |
| 115 | diff --git a/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.c b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.c |
| 116 | new file mode 100644 |
| 117 | index 0000000000..963f46d2ab |
| 118 | --- /dev/null |
| 119 | +++ b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.c |
| 120 | @@ -0,0 +1,186 @@ |
| 121 | +/* |
| 122 | + * Copyright (c) 2021-22, Arm Limited. All rights reserved. |
| 123 | + * |
| 124 | + * SPDX-License-Identifier: BSD-3-Clause |
| 125 | + * |
| 126 | + */ |
| 127 | + |
| 128 | +#include "s_test.h" |
| 129 | +#include "platform_base_address.h" |
| 130 | +#include "firewall.h" |
| 131 | +#include "tfm_log_raw.h" |
| 132 | + |
| 133 | +#define DISABLED_TEST 0 |
| 134 | + |
| 135 | +enum host_firewall_host_comp_id_t { |
| 136 | + HOST_FCTRL = (0x00u), |
| 137 | + COMP_SYSPERIPH, |
| 138 | + COMP_DBGPERIPH, |
| 139 | + COMP_AONPERIPH, |
| 140 | + COMP_XNVM, |
| 141 | + COMP_CVM, |
| 142 | + COMP_HOSTCPU, |
| 143 | + COMP_EXTSYS0, |
| 144 | + COMP_EXTSYS1, |
| 145 | + COMP_EXPSLV0, |
| 146 | + COMP_EXPSLV1, |
| 147 | + COMP_EXPMST0, |
| 148 | + COMP_EXPMST1, |
| 149 | + COMP_OCVM, |
| 150 | + COMP_DEBUG, |
| 151 | +}; |
| 152 | + |
| 153 | +const struct extra_tests_t plat_s_t = { |
| 154 | + .test_entry = s_test, |
| 155 | + .expected_ret = EXTRA_TEST_SUCCESS |
| 156 | +}; |
| 157 | + |
| 158 | +static int test_host_firewall_status(void) |
| 159 | +{ |
| 160 | + enum fw_lockdown_status_t status; |
| 161 | + uint32_t any_component_id = 2; |
| 162 | + |
| 163 | + fc_select((void *)CORSTONE1000_HOST_FIREWALL_BASE, any_component_id); |
| 164 | + status = fw_get_lockdown_status(); |
| 165 | + if (status != FW_LOCKED) { |
| 166 | + tfm_log_printf("FAIL: %s.\n\r", __func__); |
| 167 | + return EXTRA_TEST_FAILED; |
| 168 | + } |
| 169 | + |
| 170 | + tfm_log_printf("PASS: %s\n\r", __func__); |
| 171 | + return EXTRA_TEST_SUCCESS; |
| 172 | +} |
| 173 | + |
| 174 | +static int test_host_firewall_external_flash_configurations(void) |
| 175 | +{ |
| 176 | + enum rgn_mpl_t mpl_rights = 0; |
| 177 | + enum rgn_mpl_t expected_rights = 0; |
| 178 | + |
| 179 | +#if !(PLATFORM_IS_FVP) |
| 180 | + /* External flash */ |
| 181 | + fc_select((void *)CORSTONE1000_HOST_FIREWALL_BASE, COMP_EXPMST0); |
| 182 | + fc_select_region(3); |
| 183 | + fc_read_mpl(RGN_MPE0, &mpl_rights); |
| 184 | + expected_rights = (RGN_MPL_ANY_MST_MASK | RGN_MPL_SECURE_READ_MASK | |
| 185 | + RGN_MPL_SECURE_WRITE_MASK); |
| 186 | + if (mpl_rights != expected_rights) { |
| 187 | + tfm_log_printf("FAIL1: %s.\n\r", __func__); |
| 188 | + return EXTRA_TEST_FAILED; |
| 189 | + } |
| 190 | + /* XIP Permissions */ |
| 191 | + fc_select((void *)CORSTONE1000_HOST_FIREWALL_BASE, COMP_XNVM); |
| 192 | + fc_select_region(1); |
| 193 | + fc_read_mpl(RGN_MPE0, &mpl_rights); |
| 194 | + expected_rights = (RGN_MPL_ANY_MST_MASK | |
| 195 | + RGN_MPL_SECURE_READ_MASK | |
| 196 | + RGN_MPL_NONSECURE_READ_MASK); |
| 197 | + if (mpl_rights != expected_rights) { |
| 198 | + tfm_log_printf("FAIL2: %s.\n\r", __func__); |
| 199 | + return EXTRA_TEST_FAILED; |
| 200 | + } |
| 201 | +#else |
| 202 | + /* Enable the below test when FVP Host Firewall is configured. */ |
| 203 | + /* |
| 204 | + fc_select((void *)CORSTONE1000_HOST_FIREWALL_BASE, COMP_XNVM); |
| 205 | + fc_select_region(1); |
| 206 | + fc_read_mpl(RGN_MPE0, &mpl_rights); |
| 207 | + tfm_log_printf("mpl rights = %d\n\r", mpl_rights); |
| 208 | + expected_rights = (RGN_MPL_ANY_MST_MASK | |
| 209 | + RGN_MPL_SECURE_READ_MASK | |
| 210 | + RGN_MPL_SECURE_WRITE_MASK | |
| 211 | + RGN_MPL_NONSECURE_READ_MASK | |
| 212 | + RGN_MPL_NONSECURE_WRITE_MASK); |
| 213 | + if (mpl_rights != expected_rights) { |
| 214 | + tfm_log_printf("FAIL1: %s.\n\r", __func__); |
| 215 | + return EXTRA_TEST_FAILED; |
| 216 | + } |
| 217 | + */ |
| 218 | +#endif |
| 219 | + |
| 220 | + tfm_log_printf("PASS: %s\n\r", __func__); |
| 221 | + return EXTRA_TEST_SUCCESS; |
| 222 | +} |
| 223 | + |
| 224 | +static int test_host_firewall_secure_flash_configurations(void) |
| 225 | +{ |
| 226 | + enum rgn_mpl_t mpl_rights = 0; |
| 227 | + enum rgn_mpl_t expected_rights = 0; |
| 228 | + |
| 229 | +#if !(PLATFORM_IS_FVP) |
| 230 | + /* External flash */ |
| 231 | + fc_select((void *)CORSTONE1000_HOST_FIREWALL_BASE, COMP_EXPMST1); |
| 232 | + fc_select_region(1); |
| 233 | + fc_read_mpl(RGN_MPE0, &mpl_rights); |
| 234 | + expected_rights = (RGN_MPL_ANY_MST_MASK | RGN_MPL_SECURE_READ_MASK | |
| 235 | + RGN_MPL_SECURE_WRITE_MASK); |
| 236 | + if (mpl_rights != expected_rights) { |
| 237 | + tfm_log_printf("FAIL: %s.\n\r", __func__); |
| 238 | + return EXTRA_TEST_FAILED; |
| 239 | + } |
| 240 | +#endif |
| 241 | + |
| 242 | + tfm_log_printf("PASS: %s\n\r", __func__); |
| 243 | + return EXTRA_TEST_SUCCESS; |
| 244 | +} |
| 245 | + |
| 246 | +static int test_bir_programming(void) |
| 247 | +{ |
| 248 | + /* BIR is expected to bhaive like write once register */ |
| 249 | + |
| 250 | + volatile uint32_t *bir_base = (uint32_t *)CORSTONE1000_HOST_BIR_BASE; |
| 251 | + |
| 252 | + bir_base[0] = 0x1; |
| 253 | + bir_base[0] = 0x2; |
| 254 | + if (bir_base[0] != 0x1) { |
| 255 | + tfm_log_printf("FAIL: %s : (%u)\n\r", __func__, bir_base[0]); |
| 256 | + return EXTRA_TEST_FAILED; |
| 257 | + } |
| 258 | + |
| 259 | + tfm_log_printf("PASS: %s\n\r", __func__); |
| 260 | + return EXTRA_TEST_SUCCESS; |
| 261 | +} |
| 262 | + |
| 263 | +int32_t s_test(void) |
| 264 | +{ |
| 265 | + int status; |
| 266 | + int failures = 0; |
| 267 | + |
| 268 | +#if (DISABLED_TEST == 1) |
| 269 | + status = test_host_firewall_status(); |
| 270 | + if (status) { |
| 271 | + failures++; |
| 272 | + } |
| 273 | +#endif |
| 274 | + |
| 275 | + status = test_host_firewall_secure_flash_configurations(); |
| 276 | + if (status) { |
| 277 | + failures++; |
| 278 | + } |
| 279 | + |
| 280 | + status = test_host_firewall_external_flash_configurations(); |
| 281 | + if (status) { |
| 282 | + failures++; |
| 283 | + } |
| 284 | + |
| 285 | +#if (DISABLED_TEST == 1) |
| 286 | + status = test_bir_programming(); |
| 287 | + if (status) { |
| 288 | + failures++; |
| 289 | + } |
| 290 | +#endif |
| 291 | + |
| 292 | + if (failures) { |
| 293 | + tfm_log_printf("Not all platform test could pass: failures=%d\n\r", failures); |
| 294 | + return EXTRA_TEST_FAILED; |
| 295 | + } |
| 296 | + |
| 297 | + tfm_log_printf("ALL_PASS: corstone1000 platform test cases passed.\n\r"); |
| 298 | + return EXTRA_TEST_SUCCESS; |
| 299 | +} |
| 300 | + |
| 301 | +int32_t extra_tests_init(struct extra_tests_t *internal_test_t) |
| 302 | +{ |
| 303 | + /* Add platform init code here. */ |
| 304 | + |
| 305 | + return register_extra_tests(internal_test_t, &plat_s_t); |
| 306 | +} |
| 307 | diff --git a/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.h b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.h |
| 308 | new file mode 100644 |
| 309 | index 0000000000..8aff4d679c |
| 310 | --- /dev/null |
| 311 | +++ b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test.h |
| 312 | @@ -0,0 +1,30 @@ |
| 313 | +/* |
| 314 | + * Copyright (c) 2021-22, Arm Limited. All rights reserved. |
| 315 | + * |
| 316 | + * SPDX-License-Identifier: BSD-3-Clause |
| 317 | + * |
| 318 | + */ |
| 319 | + |
| 320 | +#ifndef __S_TESTS_H__ |
| 321 | +#define __S_TESTS_H__ |
| 322 | + |
| 323 | +#include "extra_tests_common.h" |
| 324 | + |
| 325 | +#ifdef __cplusplus |
| 326 | +extern "C" { |
| 327 | +#endif |
| 328 | + |
| 329 | +const struct extra_tests_t plat_s_t; |
| 330 | + |
| 331 | +/** |
| 332 | + * \brief Platform specific secure test function. |
| 333 | + * |
| 334 | + * \returns Returns error code as specified in \ref int32_t |
| 335 | + */ |
| 336 | +int32_t s_test(void); |
| 337 | + |
| 338 | +#ifdef __cplusplus |
| 339 | +} |
| 340 | +#endif |
| 341 | + |
| 342 | +#endif /* __S_TESTS_H__ */ |
| 343 | diff --git a/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test_config.cmake b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test_config.cmake |
| 344 | new file mode 100644 |
| 345 | index 0000000000..bb8d26bf1c |
| 346 | --- /dev/null |
| 347 | +++ b/platform/ext/target/arm/corstone1000/ci_regression_tests/s_test_config.cmake |
| 348 | @@ -0,0 +1,8 @@ |
| 349 | +#------------------------------------------------------------------------------- |
| 350 | +# Copyright (c) 2021-22, Arm Limited. All rights reserved. |
| 351 | +# |
| 352 | +# SPDX-License-Identifier: BSD-3-Clause |
| 353 | +# |
| 354 | +#------------------------------------------------------------------------------- |
| 355 | + |
| 356 | +############ Define secure test specific cmake configurations here ############# |
| 357 | -- |
| 358 | 2.25.1 |
| 359 | |