jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 1 | /** @file |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 2 | * Copyright (c) 2018-2020, Arm Limited or its affiliates. All rights reserved. |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 3 | * SPDX-License-Identifier : Apache-2.0 |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | **/ |
| 17 | |
| 18 | #include "val_framework.h" |
| 19 | #include "val_interfaces.h" |
| 20 | #include "val_dispatcher.h" |
| 21 | #include "val_peripherals.h" |
| 22 | #include "pal_interfaces_ns.h" |
| 23 | #include "val_target.h" |
| 24 | |
| 25 | extern val_api_t val_api; |
| 26 | extern psa_api_t psa_api; |
| 27 | |
| 28 | /* globals */ |
| 29 | test_status_buffer_t g_status_buffer; |
| 30 | |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 31 | #ifdef IPC |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 32 | /** |
| 33 | * @brief Connect to given sid |
| 34 | @param -sid : RoT service id |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 35 | @param -version : version of RoT service |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 36 | @param -handle - return connection handle |
| 37 | * @return val_status_t |
| 38 | */ |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 39 | val_status_t val_ipc_connect(uint32_t sid, uint32_t version, psa_handle_t *handle ) |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 40 | { |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 41 | *handle = psa_connect(sid, version); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 42 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 43 | if (*handle > 0) |
| 44 | return VAL_STATUS_SUCCESS; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 45 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 46 | return VAL_STATUS_CONNECTION_FAILED; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @brief Call a connected Root of Trust Service.@n |
| 51 | * The caller must provide an array of ::psa_invec_t structures as the input payload. |
| 52 | * |
| 53 | * @param handle Handle for the connection. |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 54 | * @param type Request type |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 55 | * @param in_vec Array of psa_invec structures. |
| 56 | * @param in_len Number of psa_invec structures in in_vec. |
| 57 | * @param out_vec Array of psa_outvec structures for optional Root of Trust Service response. |
| 58 | * @param out_len Number of psa_outvec structures in out_vec. |
| 59 | * @return val_status_t |
| 60 | */ |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 61 | val_status_t val_ipc_call(psa_handle_t handle, |
| 62 | int32_t type, |
| 63 | const psa_invec *in_vec, |
| 64 | size_t in_len, |
| 65 | psa_outvec *out_vec, |
| 66 | size_t out_len) |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 67 | { |
| 68 | psa_status_t call_status = PSA_SUCCESS; |
| 69 | |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 70 | call_status = psa_call(handle, type, in_vec, in_len, out_vec, out_len); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 71 | |
| 72 | if (call_status != PSA_SUCCESS) |
| 73 | { |
| 74 | return VAL_STATUS_CALL_FAILED; |
| 75 | } |
| 76 | |
| 77 | return VAL_STATUS_SUCCESS; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * @brief Close a connection to a Root of Trust Service. |
| 82 | * Sends the PSA_IPC_DISCONNECT message to the Root of Trust Service so it can clean up resources. |
| 83 | * |
| 84 | * @param handle Handle for the connection. |
| 85 | * @return void |
| 86 | */ |
| 87 | void val_ipc_close(psa_handle_t handle) |
| 88 | { |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 89 | psa_close(handle); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 90 | } |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 91 | #endif |
| 92 | |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 93 | /** |
| 94 | @brief - This function executes given list of tests from non-secure sequentially |
| 95 | This covers non-secure to secure IPC API scenario |
| 96 | @param - test_num : Test_num |
| 97 | @param - tests_list : list of tests to be executed |
| 98 | @param - server_hs : Initiate a server handshake |
| 99 | @return - val_status_t |
| 100 | **/ |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 101 | val_status_t val_execute_non_secure_tests(uint32_t test_num, const client_test_t *tests_list, |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 102 | bool_t server_hs) |
| 103 | { |
| 104 | val_status_t status = VAL_STATUS_SUCCESS; |
| 105 | val_status_t test_status = VAL_STATUS_SUCCESS; |
| 106 | boot_t boot; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 107 | uint32_t i = 1; |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 108 | #ifdef IPC |
| 109 | psa_handle_t handle; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 110 | test_info_t test_info; |
| 111 | |
| 112 | test_info.test_num = test_num; |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 113 | #endif |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 114 | |
| 115 | status = val_get_boot_flag(&boot.state); |
| 116 | if (VAL_ERROR(status)) |
| 117 | { |
| 118 | val_set_status(RESULT_FAIL(status)); |
| 119 | return status; |
| 120 | } |
| 121 | |
Gowtham Siddarth | b892626 | 2019-08-05 12:59:35 +0530 | [diff] [blame] | 122 | if (boot.state == BOOT_NOT_EXPECTED || boot.state == BOOT_EXPECTED_REENTER_TEST |
| 123 | || boot.state == BOOT_EXPECTED_CONT_TEST_EXEC) |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 124 | { |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 125 | while (tests_list[i] != NULL) |
| 126 | { |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 127 | /* |
| 128 | * Reboot have been expected by test in previous ns run, |
| 129 | * consider previous run pass and jump to second test function |
| 130 | * of the same test if available. |
| 131 | */ |
| 132 | if ((boot.state == BOOT_EXPECTED_REENTER_TEST) && (i == 1)) |
| 133 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 134 | val_print(PRINT_DEBUG, "[Check 1] PASSED\n", 0); |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 135 | i++; |
| 136 | continue; |
| 137 | } |
| 138 | |
Gowtham Siddarth | b892626 | 2019-08-05 12:59:35 +0530 | [diff] [blame] | 139 | if (boot.state != BOOT_EXPECTED_CONT_TEST_EXEC) |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 140 | { |
Gowtham Siddarth | b892626 | 2019-08-05 12:59:35 +0530 | [diff] [blame] | 141 | status = val_set_boot_flag(BOOT_NOT_EXPECTED); |
| 142 | if (VAL_ERROR(status)) |
| 143 | { |
| 144 | return status; |
| 145 | } |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | if (i == 1) |
| 149 | val_print(PRINT_TEST,"[Info] Executing tests from non-secure\n", 0); |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 150 | #ifdef IPC |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 151 | if (server_hs == TRUE) |
| 152 | { |
| 153 | /* Handshake with server tests */ |
| 154 | test_info.block_num = i; |
| 155 | status = val_execute_secure_test_func(&handle, test_info, |
| 156 | SERVER_TEST_DISPATCHER_SID); |
| 157 | if (VAL_ERROR(status)) |
| 158 | { |
| 159 | val_set_status(RESULT_FAIL(status)); |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 160 | val_print(PRINT_DEBUG, "[Check %d] START\n", i); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 161 | return status; |
| 162 | } |
| 163 | else |
| 164 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 165 | val_print(PRINT_DEBUG, "[Check %d] START\n", i); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 166 | } |
| 167 | } |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 168 | #endif |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 169 | /* Execute client tests */ |
Gowtham Siddarth | b1cd50f | 2019-08-21 11:50:26 +0530 | [diff] [blame] | 170 | test_status = tests_list[i](CALLER_NONSECURE); |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 171 | #ifdef IPC |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 172 | if (server_hs == TRUE) |
| 173 | { |
| 174 | /* Retrive Server test status */ |
| 175 | status = val_get_secure_test_result(&handle); |
| 176 | } |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 177 | #endif |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 178 | status = test_status ? test_status:status; |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 179 | if (IS_TEST_SKIP(status)) |
| 180 | { |
| 181 | val_set_status(status); |
| 182 | if (server_hs == TRUE) |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 183 | val_print(PRINT_DEBUG, "[Check %d] SKIPPED\n", i); |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 184 | return status; |
| 185 | } |
| 186 | else if (VAL_ERROR(status)) |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 187 | { |
| 188 | val_set_status(RESULT_FAIL(status)); |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 189 | if (server_hs == TRUE) |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 190 | val_print(PRINT_DEBUG, "[Check %d] FAILED\n", i); |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 191 | |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 192 | return status; |
| 193 | } |
| 194 | else |
| 195 | { |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 196 | if (server_hs == TRUE) |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 197 | val_print(PRINT_DEBUG, "[Check %d] PASSED\n", i); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 198 | } |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 199 | |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 200 | i++; |
| 201 | } |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | /* If we are here means, we are in second run of this test */ |
| 206 | status = VAL_STATUS_SUCCESS; |
| 207 | if (boot.state != BOOT_EXPECTED_S) |
| 208 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 209 | val_print(PRINT_DEBUG, "[Check 1] PASSED\n", 0); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | return status; |
| 213 | } |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 214 | |
| 215 | #ifdef IPC |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 216 | /** |
| 217 | @brief - This function is used to switch to client_partition.c |
| 218 | where client tests will be executed to cover secure to secure |
| 219 | IPC scenario. |
| 220 | @param - test_num : Test_num |
| 221 | @return - val_status_t |
| 222 | **/ |
| 223 | val_status_t val_switch_to_secure_client(uint32_t test_num) |
| 224 | { |
| 225 | val_status_t status = VAL_STATUS_SUCCESS; |
| 226 | boot_t boot; |
| 227 | psa_handle_t handle; |
| 228 | test_info_t test_info; |
| 229 | |
| 230 | test_info.test_num = test_num; |
| 231 | test_info.block_num = 1; |
| 232 | |
| 233 | status = val_get_boot_flag(&boot.state); |
| 234 | if (VAL_ERROR(status)) |
| 235 | { |
| 236 | goto exit; |
| 237 | } |
| 238 | |
| 239 | if (boot.state != BOOT_EXPECTED_S) |
| 240 | { |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 241 | /* |
| 242 | * Reboot have been expected by test in previous s run, |
| 243 | * consider previous run pass and jump to second test function |
| 244 | * of the same test if available. |
| 245 | */ |
| 246 | if (boot.state == BOOT_EXPECTED_REENTER_TEST) |
| 247 | { |
| 248 | test_info.block_num++; |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 249 | val_print(PRINT_DEBUG, "[Check 1] PASSED\n", 0); |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 250 | } |
| 251 | |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 252 | status = val_set_boot_flag(BOOT_NOT_EXPECTED); |
| 253 | if (VAL_ERROR(status)) |
| 254 | { |
| 255 | goto exit; |
| 256 | } |
| 257 | |
| 258 | /* switch to secure client */ |
| 259 | status = val_execute_secure_test_func(&handle, test_info, CLIENT_TEST_DISPATCHER_SID); |
| 260 | if (VAL_ERROR(status)) |
| 261 | { |
| 262 | goto exit; |
| 263 | } |
| 264 | |
| 265 | /* Retrive secure client test status */ |
| 266 | status = val_get_secure_test_result(&handle); |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 267 | if (IS_TEST_SKIP(status)) |
| 268 | { |
| 269 | val_set_status(status); |
| 270 | return status; |
| 271 | } |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 272 | if (VAL_ERROR(status)) |
| 273 | { |
| 274 | goto exit; |
| 275 | } |
| 276 | return status; |
| 277 | } |
| 278 | else |
| 279 | { |
| 280 | /* If we are here means, we are in third run of this test */ |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 281 | val_print(PRINT_DEBUG, "[Check 1] PASSED\n", 0); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 282 | return VAL_STATUS_SUCCESS; |
| 283 | } |
| 284 | |
| 285 | exit: |
| 286 | val_set_status(RESULT_FAIL(status)); |
| 287 | return status; |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | @brief - This function is used to handshake between: |
| 292 | - nonsecure client fn to server test fn |
| 293 | - secure client fn and server test fn |
| 294 | - nonsecure client fn to secure client test fn |
| 295 | @param - handle : handle returned while connecting given sid |
| 296 | @param - test_info : Test_num and block_num to be executed |
| 297 | @param - sid : RoT service to be connected. Partition dispatcher sid |
| 298 | @return - val_status_t |
| 299 | **/ |
| 300 | val_status_t val_execute_secure_test_func(psa_handle_t *handle, test_info_t test_info, uint32_t sid) |
| 301 | { |
| 302 | uint32_t test_data; |
| 303 | val_status_t status = VAL_STATUS_SUCCESS; |
| 304 | psa_status_t status_of_call = PSA_SUCCESS; |
| 305 | |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 306 | *handle = psa_connect(sid, 1); |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 307 | if (*handle > 0) |
| 308 | { |
| 309 | test_data = ((uint32_t)(test_info.test_num) |((uint32_t)(test_info.block_num) << BLOCK_NUM_POS) |
| 310 | | ((uint32_t)(TEST_EXECUTE_FUNC) << ACTION_POS)); |
| 311 | psa_invec data[1] = {{&test_data, sizeof(test_data)}}; |
| 312 | |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 313 | status_of_call = psa_call(*handle, 0, data, 1, NULL, 0); |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 314 | if (status_of_call != PSA_SUCCESS) |
| 315 | { |
| 316 | status = VAL_STATUS_CALL_FAILED; |
| 317 | val_print(PRINT_ERROR, "Call to dispatch SF failed. Status=%x\n", status_of_call); |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 318 | psa_close(*handle); |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | else |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 322 | { |
| 323 | val_print(PRINT_ERROR, "Could not connect SID. Handle=%x\n", *handle); |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 324 | status = VAL_STATUS_CONNECTION_FAILED; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 325 | } |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 326 | |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 327 | return status; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | @brief - This function is used to retrive the status of previously connected test function |
| 332 | using val_execute_secure_test_func |
| 333 | @param - handle : handle of server function. Handle of Partition dispatcher sid |
| 334 | @return - The status of test functions |
| 335 | **/ |
| 336 | val_status_t val_get_secure_test_result(psa_handle_t *handle) |
| 337 | { |
| 338 | uint32_t test_data; |
| 339 | val_status_t status = VAL_STATUS_SUCCESS; |
| 340 | psa_status_t status_of_call = PSA_SUCCESS; |
| 341 | |
| 342 | test_data = (TEST_RETURN_RESULT << ACTION_POS); |
| 343 | |
| 344 | psa_outvec resp = {&status, sizeof(status)}; |
| 345 | psa_invec data[1] = {{&test_data, sizeof(test_data)}}; |
| 346 | |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 347 | status_of_call = psa_call(*handle, 0, data, 1, &resp, 1); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 348 | if (status_of_call != PSA_SUCCESS) |
| 349 | { |
| 350 | status = VAL_STATUS_CALL_FAILED; |
| 351 | val_print(PRINT_ERROR, "Call to dispatch SF failed. Status=%x\n", status_of_call); |
| 352 | } |
| 353 | |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 354 | psa_close(*handle); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 355 | return status; |
| 356 | } |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 357 | #endif |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 358 | |
| 359 | /** |
| 360 | @brief - Parses input status for a given test and |
| 361 | outputs appropriate information on the console |
| 362 | @return - Test state |
| 363 | **/ |
| 364 | uint32_t val_report_status(void) |
| 365 | { |
| 366 | uint32_t status, state; |
| 367 | |
| 368 | status = val_get_status(); |
| 369 | |
| 370 | state = (status >> TEST_STATE_BIT) & TEST_STATE_MASK; |
| 371 | status = status & TEST_STATUS_MASK; |
| 372 | |
| 373 | switch (state) |
| 374 | { |
| 375 | case TEST_START: |
| 376 | state = TEST_FAIL; |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 377 | val_print(PRINT_ALWAYS, "\nTEST RESULT: FAILED (Error Code=0x%x)\n", |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 378 | VAL_STATUS_INIT_FAILED); |
| 379 | break; |
| 380 | |
| 381 | case TEST_END: |
| 382 | state = TEST_PASS; |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 383 | val_print(PRINT_ALWAYS, "\nTEST RESULT: PASSED\n", 0); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 384 | break; |
| 385 | |
| 386 | case TEST_FAIL: |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 387 | val_print(PRINT_ALWAYS, "\nTEST RESULT: FAILED (Error Code=0x%x)\n", status); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 388 | break; |
| 389 | |
| 390 | case TEST_SKIP: |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 391 | state = TEST_SKIP; |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 392 | val_print(PRINT_ALWAYS, "\nTEST RESULT: SKIPPED (Skip Code=0x%x)\n", status); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 393 | break; |
| 394 | |
| 395 | case TEST_PENDING: |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 396 | val_print(PRINT_ALWAYS, "\nTEST RESULT: SIM ERROR (Error Code=0x%x)\n", status); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 397 | break; |
| 398 | |
| 399 | default: |
| 400 | state = TEST_FAIL; |
Vinay Kumar Kotegowder | 18fcd40 | 2020-04-27 17:38:41 +0530 | [diff] [blame^] | 401 | val_print(PRINT_ALWAYS, "\nTEST RESULT: FAILED(Error Code=0x%x)\n", VAL_STATUS_INVALID); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 402 | break; |
| 403 | |
| 404 | } |
| 405 | |
| 406 | val_print(PRINT_ALWAYS, "\n******************************************\n", 0); |
| 407 | return state; |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | @brief - Records the state and status of test |
| 412 | @return - val_status_t |
| 413 | **/ |
| 414 | val_status_t val_set_status(uint32_t status) |
| 415 | { |
| 416 | g_status_buffer.state = ((status >> TEST_STATE_BIT) & TEST_STATE_MASK); |
| 417 | g_status_buffer.status = (status & TEST_STATUS_MASK); |
| 418 | |
| 419 | return VAL_STATUS_SUCCESS; |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | @brief - Updates the state and status for a given test |
| 424 | @return - test status |
| 425 | **/ |
| 426 | uint32_t val_get_status(void) |
| 427 | { |
| 428 | return ((g_status_buffer.state) << TEST_STATE_BIT) | (g_status_buffer.status); |
| 429 | } |
| 430 | |
| 431 | /* |
| 432 | @brief - This function checks if the input status argument is an error. |
| 433 | On error, we print the checkpoint value and set the status. |
| 434 | @param - checkpoint : Test debug checkpoint |
| 435 | - val_status_t : Test status |
| 436 | @return - returns the input status back to the program. |
| 437 | */ |
| 438 | |
| 439 | val_status_t val_err_check_set(uint32_t checkpoint, val_status_t status) |
| 440 | { |
| 441 | if (VAL_ERROR(status)) |
| 442 | { |
| 443 | val_print(PRINT_ERROR, "\tCheckpoint %d : ", checkpoint); |
| 444 | val_print(PRINT_ERROR, "Error Code=0x%x \n", status); |
| 445 | val_set_status(RESULT_FAIL(status)); |
| 446 | } |
| 447 | else |
| 448 | { |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 449 | status = (val_get_status() & TEST_STATUS_MASK); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 450 | if (VAL_ERROR(status)) |
| 451 | { |
| 452 | val_print(PRINT_ERROR, "\tCheckpoint %d : ", checkpoint); |
| 453 | val_print(PRINT_ERROR, "Error Code=0x%x \n", status); |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | val_print(PRINT_DEBUG, "\tCheckpoint %d \n", checkpoint); |
| 458 | } |
| 459 | } |
| 460 | return status; |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | @brief This API prints the test number, description and |
| 465 | sets the test state to TEST_START on successful execution. |
| 466 | @param test_num :unique number identifying this test |
| 467 | @param desc :brief description of the test |
| 468 | @param test_bitfield :Addition test info such as |
| 469 | - test isolation level requirement |
| 470 | - Watchdog timeout type |
| 471 | @return void |
| 472 | **/ |
| 473 | |
| 474 | void val_test_init(uint32_t test_num, char8_t *desc, uint32_t test_bitfield) |
| 475 | { |
| 476 | val_status_t status = VAL_STATUS_SUCCESS; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 477 | |
| 478 | /*global init*/ |
cherat01 | 3f02872 | 2019-02-18 14:50:37 +0530 | [diff] [blame] | 479 | g_status_buffer.state = TEST_FAIL; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 480 | g_status_buffer.status = VAL_STATUS_INVALID; |
| 481 | |
| 482 | val_print(PRINT_ALWAYS, "\nTEST: %d | DESCRIPTION: ", test_num); |
| 483 | val_print(PRINT_ALWAYS, desc, 0); |
| 484 | |
| 485 | /* common skip logic */ |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 486 | if (PLATFORM_PSA_ISOLATION_LEVEL < GET_TEST_ISOLATION_LEVEL(test_bitfield)) |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 487 | { |
| 488 | val_set_status(RESULT_SKIP(VAL_STATUS_ISOLATION_LEVEL_NOT_SUPP)); |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 489 | val_print(PRINT_ALWAYS, "\tSkipping test. Required isolation level is not supported\n", 0); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 490 | return; |
| 491 | } |
| 492 | |
Vinay Kumar Kotegowder | 9982f90 | 2019-07-15 09:13:54 +0530 | [diff] [blame] | 493 | #ifdef WATCHDOG_AVAILABLE |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 494 | /* Initialise watchdog */ |
| 495 | status = val_wd_timer_init(GET_WD_TIMOUT_TYPE(test_bitfield)); |
| 496 | if (VAL_ERROR(status)) |
| 497 | { |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 498 | val_print(PRINT_ERROR, "\tval_wd_timer_init failed Error=0x%x\n", status); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 499 | return; |
| 500 | } |
| 501 | |
| 502 | /* Enable watchdog Timer */ |
| 503 | status = val_wd_timer_enable(); |
| 504 | if (VAL_ERROR(status)) |
| 505 | { |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 506 | val_print(PRINT_ERROR, "\tval_wd_timer_enable failed Error=0x%x\n", status); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 507 | return; |
| 508 | } |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 509 | #endif |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 510 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 511 | val_set_status(RESULT_START(status)); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 512 | return; |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | @brief This API sets the test state to TEST_END if test is successfuly passed. |
| 517 | @param none |
| 518 | @return none |
| 519 | **/ |
| 520 | |
| 521 | void val_test_exit(void) |
| 522 | { |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 523 | val_status_t status = VAL_STATUS_SUCCESS; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 524 | |
Vinay Kumar Kotegowder | 9982f90 | 2019-07-15 09:13:54 +0530 | [diff] [blame] | 525 | #ifdef WATCHDOG_AVAILABLE |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 526 | status = val_wd_timer_disable(); |
| 527 | if (VAL_ERROR(status)) |
| 528 | { |
| 529 | val_print(PRINT_ERROR, "\tval_wd_timer_disable failed Error=0x%x\n", status); |
| 530 | val_set_status(RESULT_FAIL(status)); |
| 531 | return; |
| 532 | } |
| 533 | #endif |
| 534 | |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 535 | status = val_get_status(); |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 536 | |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 537 | /* return if test skipped or failed */ |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 538 | if (IS_TEST_FAIL(status) || IS_TEST_SKIP(status)) |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 539 | { |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 540 | return; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 541 | } |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 542 | else |
| 543 | { |
| 544 | val_set_status(RESULT_END(VAL_STATUS_SUCCESS)); |
| 545 | } |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | /** |
| 549 | @brief - This function returns the test ID of the last test that was run |
| 550 | @param - test_id address |
| 551 | @return - val_status_t |
| 552 | **/ |
| 553 | val_status_t val_get_last_run_test_id(test_id_t *test_id) |
| 554 | { |
| 555 | val_status_t status; |
| 556 | test_count_t test_count; |
| 557 | boot_t boot; |
| 558 | int i = 0, intermediate_boot = 0; |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 559 | boot_state_t boot_state[] = {BOOT_NOT_EXPECTED, |
| 560 | BOOT_EXPECTED_NS, |
| 561 | BOOT_EXPECTED_S, |
| 562 | BOOT_EXPECTED_BUT_FAILED, |
Gowtham Siddarth | b892626 | 2019-08-05 12:59:35 +0530 | [diff] [blame] | 563 | BOOT_EXPECTED_REENTER_TEST, |
| 564 | BOOT_EXPECTED_CONT_TEST_EXEC |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 565 | }; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 566 | |
| 567 | status = val_get_boot_flag(&boot.state); |
| 568 | if (VAL_ERROR(status)) |
| 569 | { |
| 570 | return status; |
| 571 | } |
| 572 | |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 573 | val_print(PRINT_INFO, "\n\tboot.state=0x%x", boot.state); |
| 574 | |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 575 | for (i = 0; i < (sizeof(boot_state)/sizeof(boot_state[0])); i++) |
| 576 | { |
| 577 | if (boot.state == boot_state[i]) |
| 578 | { |
| 579 | intermediate_boot = 1; |
| 580 | break; |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | if (!intermediate_boot) |
| 585 | { |
| 586 | /* First boot. Initiliase necessary data structure */ |
| 587 | status = val_set_boot_flag(BOOT_UNKNOWN); |
| 588 | if (VAL_ERROR(status)) |
| 589 | { |
| 590 | return status; |
| 591 | } |
| 592 | |
| 593 | *test_id = VAL_INVALID_TEST_ID; |
| 594 | status = val_nvmem_write(VAL_NVMEM_OFFSET(NV_TEST_ID_PREVIOUS), |
| 595 | test_id, sizeof(test_id_t)); |
| 596 | if (VAL_ERROR(status)) |
| 597 | { |
| 598 | val_print(PRINT_ALWAYS, "\n\tNVMEM write error", 0); |
| 599 | return status; |
| 600 | } |
| 601 | |
| 602 | test_count.pass_cnt = 0; |
| 603 | test_count.fail_cnt = 0; |
| 604 | test_count.skip_cnt = 0; |
| 605 | test_count.sim_error_cnt = 0; |
| 606 | |
| 607 | status = val_nvmem_write(VAL_NVMEM_OFFSET(NV_TEST_CNT), |
| 608 | &test_count, sizeof(test_count_t)); |
| 609 | if (VAL_ERROR(status)) |
| 610 | { |
| 611 | val_print(PRINT_ERROR, "\n\tNVMEM write error", 0); |
| 612 | return status; |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | status = val_nvmem_read(VAL_NVMEM_OFFSET(NV_TEST_ID_PREVIOUS), test_id, sizeof(test_id_t)); |
| 617 | if (VAL_ERROR(status)) |
| 618 | { |
| 619 | val_print(PRINT_ERROR, "\n\tNVMEM read error", 0); |
| 620 | } |
| 621 | |
| 622 | val_print(PRINT_INFO, "In val_get_last_run_test_id, test_id=%x\n", *test_id); |
| 623 | return status; |
| 624 | } |
| 625 | |
| 626 | /** |
| 627 | @brief - This function sets the given boot.state value to corresponding |
| 628 | boot NVMEM location |
| 629 | @param - state: boot_state_t |
| 630 | @return - val_status_t |
| 631 | **/ |
| 632 | val_status_t val_set_boot_flag(boot_state_t state) |
| 633 | { |
| 634 | boot_t boot; |
| 635 | val_status_t status; |
| 636 | |
| 637 | boot.state = state; |
| 638 | status = val_nvmem_write(VAL_NVMEM_OFFSET(NV_BOOT), &boot, sizeof(boot_t)); |
| 639 | if (VAL_ERROR(status)) |
| 640 | { |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 641 | val_print(PRINT_ERROR, "\tval_nvmem_write failed. Error=0x%x\n", status); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 642 | return status; |
| 643 | } |
| 644 | return status; |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | @brief - This function returns boot.state value available in boot NVMEM location |
| 649 | @param - state address |
| 650 | @return - val_status_t |
| 651 | **/ |
| 652 | val_status_t val_get_boot_flag(boot_state_t *state) |
| 653 | { |
| 654 | boot_t boot; |
| 655 | val_status_t status; |
| 656 | |
| 657 | status = val_nvmem_read(VAL_NVMEM_OFFSET(NV_BOOT), &boot, sizeof(boot_t)); |
| 658 | if (VAL_ERROR(status)) |
| 659 | { |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 660 | val_print(PRINT_ERROR, "\tval_nvmem_read failed. Error=0x%x\n", status); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 661 | return status; |
| 662 | } |
| 663 | *state = boot.state; |
| 664 | return status; |
| 665 | } |