jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 1 | /** @file |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, 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 | /* Note- This file contains the functions and variables definition which are common to |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 19 | all partitions defined by test suite. These functions and variables are declared with static |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 20 | keyword because some fully isolated system may not allow to share code and data segment |
| 21 | between partitions and static will help each partition to have its own copy of code and data. |
| 22 | Moreover it can prevents symbol names conflict if these functions are separately compiled and |
| 23 | linked with each of partitions in fully isolated environment. |
| 24 | */ |
| 25 | |
| 26 | #ifndef _VAL_COMMON_SP_APIS_H_ |
| 27 | #define _VAL_COMMON_SP_APIS_H_ |
| 28 | |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 29 | #include "val.h" |
| 30 | #include "val_target.c" |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 31 | #include "val_service_defs.h" |
| 32 | |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 33 | __UNUSED STATIC_DECLARE val_status_t val_print |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 34 | (print_verbosity_t verbosity, char *string, int32_t data); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 35 | __UNUSED STATIC_DECLARE val_status_t val_ipc_connect |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 36 | (uint32_t sid, uint32_t version, psa_handle_t *handle ); |
| 37 | __UNUSED STATIC_DECLARE val_status_t val_ipc_call(psa_handle_t handle, |
| 38 | int32_t type, |
| 39 | const psa_invec *in_vec, |
| 40 | size_t in_len, |
| 41 | psa_outvec *out_vec, |
| 42 | size_t out_len); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 43 | __UNUSED STATIC_DECLARE void val_ipc_close |
| 44 | (psa_handle_t handle); |
| 45 | __UNUSED STATIC_DECLARE val_status_t val_process_connect_request(psa_signal_t sig, psa_msg_t *msg); |
| 46 | __UNUSED STATIC_DECLARE val_status_t val_process_call_request(psa_signal_t sig, psa_msg_t *msg); |
| 47 | __UNUSED STATIC_DECLARE val_status_t val_process_disconnect_request |
| 48 | (psa_signal_t sig, psa_msg_t *msg); |
| 49 | __UNUSED STATIC_DECLARE val_status_t val_execute_secure_tests |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 50 | (test_info_t test_info, client_test_t *tests_list); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 51 | __UNUSED STATIC_DECLARE val_status_t val_execute_secure_test_func |
| 52 | (psa_handle_t *handle, test_info_t test_info, uint32_t sid); |
| 53 | __UNUSED STATIC_DECLARE val_status_t val_get_secure_test_result(psa_handle_t *handle); |
| 54 | __UNUSED STATIC_DECLARE val_status_t val_err_check_set(uint32_t checkpoint, val_status_t status); |
| 55 | __UNUSED STATIC_DECLARE val_status_t val_nvmem_write(uint32_t offset, void *buffer, int size); |
| 56 | __UNUSED STATIC_DECLARE val_status_t val_set_boot_flag(boot_state_t state); |
| 57 | |
| 58 | __UNUSED static val_api_t val_api = { |
| 59 | .print = val_print, |
| 60 | .err_check_set = val_err_check_set, |
| 61 | .execute_secure_test_func = val_execute_secure_test_func, |
| 62 | .get_secure_test_result = val_get_secure_test_result, |
| 63 | .ipc_connect = val_ipc_connect, |
| 64 | .ipc_call = val_ipc_call, |
| 65 | .ipc_close = val_ipc_close, |
| 66 | .set_boot_flag = val_set_boot_flag, |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 67 | .target_get_config = val_target_get_config, |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 68 | .process_connect_request = val_process_connect_request, |
| 69 | .process_call_request = val_process_call_request, |
| 70 | .process_disconnect_request= val_process_disconnect_request, |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | __UNUSED static psa_api_t psa_api = { |
| 74 | .framework_version = psa_framework_version, |
| 75 | .version = psa_version, |
| 76 | .connect = psa_connect, |
| 77 | .call = psa_call, |
| 78 | .close = psa_close, |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 79 | .wait = psa_wait, |
| 80 | .set_rhandle = psa_set_rhandle, |
| 81 | .get = psa_get, |
| 82 | .read = psa_read, |
| 83 | .skip = psa_skip, |
| 84 | .write = psa_write, |
| 85 | .reply = psa_reply, |
| 86 | .notify = psa_notify, |
| 87 | .clear = psa_clear, |
| 88 | .eoi = psa_eoi, |
| 89 | .rot_lifecycle_state = psa_rot_lifecycle_state, |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 90 | .panic = psa_panic, |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | /** |
| 94 | @brief - Print module. This is client interface API of secure partition |
| 95 | val_print_sf API for spe world |
| 96 | @param - verbosity: Print verbosity level |
| 97 | - string : Input string |
| 98 | - data : Value for format specifier |
| 99 | @return - val_status_t |
| 100 | **/ |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 101 | STATIC_DECLARE val_status_t val_print(print_verbosity_t verbosity, char *string, int32_t data) |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 102 | { |
| 103 | int string_len = 0; |
| 104 | char *p = string; |
| 105 | psa_handle_t print_handle = 0; |
| 106 | psa_status_t status_of_call = PSA_SUCCESS; |
| 107 | val_status_t status = VAL_STATUS_SUCCESS; |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 108 | uart_fn_type_t uart_fn = UART_PRINT; |
| 109 | |
| 110 | if (verbosity < VERBOSE) |
| 111 | { |
| 112 | return VAL_STATUS_SUCCESS; |
| 113 | } |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 114 | |
| 115 | while (*p != '\0') |
| 116 | { |
| 117 | string_len++; |
| 118 | p++; |
| 119 | } |
| 120 | |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 121 | psa_invec data1[3] = {{&uart_fn, sizeof(uart_fn)}, {string, string_len+1}, {&data, sizeof(data)}}; |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 122 | print_handle = psa_connect(DRIVER_UART_SID, DRIVER_UART_VERSION); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 123 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 124 | if (PSA_HANDLE_IS_VALID(print_handle)) |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 125 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 126 | status_of_call = psa_call(print_handle, 0, data1, 3, NULL, 0); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 127 | if (status_of_call != PSA_SUCCESS) |
| 128 | { |
| 129 | status = VAL_STATUS_CALL_FAILED; |
| 130 | } |
| 131 | } |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 132 | else |
| 133 | { |
| 134 | return VAL_STATUS_CONNECTION_FAILED; |
| 135 | } |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 136 | psa_close(print_handle); |
| 137 | return status; |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * @brief Connect to given sid |
| 142 | @param -sid : RoT service id |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 143 | @param -version : version of RoT service |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 144 | @param -handle - return connection handle |
| 145 | * @return val_status_t |
| 146 | */ |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 147 | STATIC_DECLARE val_status_t val_ipc_connect(uint32_t sid, uint32_t version, |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 148 | psa_handle_t *handle ) |
| 149 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 150 | *handle = psa_connect(sid, version); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 151 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 152 | if (PSA_HANDLE_IS_VALID(*handle)) |
| 153 | return VAL_STATUS_SUCCESS; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 154 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 155 | return VAL_STATUS_CONNECTION_FAILED; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | /** |
| 159 | * @brief Call a connected Root of Trust Service.@n |
| 160 | * The caller must provide an array of ::psa_invec_t structures as the input payload. |
| 161 | * @param handle: Handle for the connection. |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 162 | * @param type: Request type. |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 163 | * @param in_vec: Array of psa_invec structures. |
| 164 | * @param in_len: Number of psa_invec structures in in_vec. |
| 165 | * @param out_vec: Array of psa_outvec structures for optional Root of Trust Service response. |
| 166 | * @param out_len: Number of psa_outvec structures in out_vec. |
| 167 | * @return val_status_t |
| 168 | */ |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 169 | STATIC_DECLARE val_status_t val_ipc_call(psa_handle_t handle, |
| 170 | int32_t type, |
| 171 | const psa_invec *in_vec, |
| 172 | size_t in_len, |
| 173 | psa_outvec *out_vec, |
| 174 | size_t out_len) |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 175 | { |
| 176 | psa_status_t call_status = PSA_SUCCESS; |
| 177 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 178 | 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] | 179 | |
| 180 | if (call_status != PSA_SUCCESS) |
| 181 | { |
| 182 | return(VAL_STATUS_CALL_FAILED); |
| 183 | } |
| 184 | |
| 185 | return VAL_STATUS_SUCCESS; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * @brief Close a connection to a Root of Trust Service. |
| 190 | * Sends the PSA_IPC_DISCONNECT message to the Root of Trust Service so |
| 191 | it can clean up resources. |
| 192 | * @param handle: Handle for the connection. |
| 193 | * @return void |
| 194 | */ |
| 195 | STATIC_DECLARE void val_ipc_close(psa_handle_t handle) |
| 196 | { |
| 197 | psa_close(handle); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * @brief Proccess a generic connect message to given rot signal. |
| 202 | @param -sig : signal to be processed |
| 203 | @param -msg : return msg info of given signal |
| 204 | * @return val_status_t. |
| 205 | */ |
| 206 | STATIC_DECLARE val_status_t val_process_connect_request(psa_signal_t sig, psa_msg_t *msg) |
| 207 | { |
| 208 | val_status_t res = VAL_STATUS_ERROR; |
| 209 | psa_signal_t signals; |
| 210 | |
| 211 | wait1: |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 212 | signals = psa_wait(PSA_WAIT_ANY, PSA_BLOCK); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 213 | if (signals & sig) |
| 214 | { |
| 215 | if (psa_get(sig, msg) != PSA_SUCCESS) |
| 216 | { |
| 217 | goto wait1; |
| 218 | } |
| 219 | |
| 220 | if ((msg->type != PSA_IPC_CONNECT) || (msg->handle <= 0)) |
| 221 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 222 | val_print(PRINT_ERROR, "\tpsa_get failed for connect message\n", 0); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 223 | res = VAL_STATUS_ERROR; |
| 224 | } |
| 225 | else |
| 226 | { |
| 227 | res = VAL_STATUS_SUCCESS; |
| 228 | } |
| 229 | } |
| 230 | else |
| 231 | { |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 232 | val_print(PRINT_ERROR, "\tpsa_wait returned with invalid signal value = 0x%x\n", signals); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 233 | res = VAL_STATUS_ERROR; |
| 234 | } |
| 235 | return res; |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * @brief Proccess a generic call message to given rot signal. |
| 240 | @param -sig : signal to be processed |
| 241 | @param -msg : return msg info of given signal |
| 242 | * @return val_status_t |
| 243 | */ |
| 244 | STATIC_DECLARE val_status_t val_process_call_request(psa_signal_t sig, psa_msg_t *msg) |
| 245 | { |
| 246 | val_status_t res = VAL_STATUS_ERROR; |
| 247 | psa_signal_t signals; |
| 248 | |
| 249 | wait2: |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 250 | signals = psa_wait(PSA_WAIT_ANY, PSA_BLOCK); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 251 | if (signals & sig) |
| 252 | { |
| 253 | if (psa_get(sig, msg) != PSA_SUCCESS) |
| 254 | { |
| 255 | goto wait2; |
| 256 | } |
| 257 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 258 | if ((msg->type < PSA_IPC_CALL) || (msg->handle <= 0)) |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 259 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 260 | val_print(PRINT_ERROR, "\tpsa_get failed for request message\n", 0); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 261 | res = VAL_STATUS_ERROR; |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | res = VAL_STATUS_SUCCESS; |
| 266 | } |
| 267 | } |
| 268 | else |
| 269 | { |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 270 | val_print(PRINT_ERROR, "\tpsa_wait returned with invalid signal value = 0x%x\n", signals); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 271 | res = VAL_STATUS_ERROR; |
| 272 | } |
| 273 | return res; |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * @brief Proccess a generic disconnect message to given rot signal. |
| 278 | @param -sig : signal to be processed |
| 279 | @param -msg : return msg info of given signal |
| 280 | * @return val_status_t |
| 281 | */ |
| 282 | STATIC_DECLARE val_status_t val_process_disconnect_request(psa_signal_t sig, psa_msg_t *msg) |
| 283 | { |
| 284 | val_status_t res = VAL_STATUS_ERROR; |
| 285 | psa_signal_t signals; |
| 286 | |
| 287 | wait3: |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 288 | signals = psa_wait(PSA_WAIT_ANY, PSA_BLOCK); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 289 | if (signals & sig) |
| 290 | { |
| 291 | if (psa_get(sig, msg) != PSA_SUCCESS) |
| 292 | { |
| 293 | goto wait3; |
| 294 | } |
| 295 | |
| 296 | if ((msg->type != PSA_IPC_DISCONNECT) || (msg->handle <= 0)) |
| 297 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 298 | val_print(PRINT_ERROR, "\tpsa_get failed for disconnect massage\n", 0); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 299 | res = VAL_STATUS_ERROR; |
| 300 | } |
| 301 | else |
| 302 | { |
| 303 | res = VAL_STATUS_SUCCESS; |
| 304 | } |
| 305 | } |
| 306 | else |
| 307 | { |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 308 | val_print(PRINT_ERROR, "\tpsa_wait returned with invalid signal value = 0x%x\n", signals); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 309 | res = VAL_STATUS_ERROR; |
| 310 | } |
| 311 | return res; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | @brief - This function executes given list of tests from secure sequentially |
| 316 | This covers secure to secure IPC API scenario |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 317 | @param - test_info_t : test_num and block_num |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 318 | @param - tests_list : list of tests to be executed |
| 319 | @return - val_status_t |
| 320 | **/ |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 321 | STATIC_DECLARE val_status_t val_execute_secure_tests(test_info_t test_info, client_test_t *tests_list) |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 322 | { |
| 323 | val_status_t status = VAL_STATUS_SUCCESS; |
| 324 | val_status_t test_status = VAL_STATUS_SUCCESS; |
| 325 | psa_handle_t handle; |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 326 | int i = test_info.block_num; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 327 | |
| 328 | while (tests_list[i] != NULL) |
| 329 | { |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 330 | if (i == 1) |
| 331 | val_print(PRINT_TEST, "[Info] Executing tests from secure\n", 0); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 332 | |
| 333 | /* Handshake with server tests */ |
| 334 | test_info.block_num = i; |
| 335 | status = val_execute_secure_test_func(&handle, test_info, SERVER_TEST_DISPATCHER_SID); |
| 336 | if (VAL_ERROR(status)) |
| 337 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 338 | val_print(PRINT_ERROR, "[Check %d] START\n", i); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 339 | return status; |
| 340 | } |
| 341 | else |
| 342 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 343 | val_print(PRINT_DEBUG, "[Check %d] START\n", i); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /* Execute client tests */ |
Gowtham Siddarth | b1cd50f | 2019-08-21 11:50:26 +0530 | [diff] [blame] | 347 | test_status = tests_list[i](CALLER_SECURE); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 348 | |
| 349 | /* Retrive Server test status */ |
| 350 | status = val_get_secure_test_result(&handle); |
| 351 | |
| 352 | status = test_status ? test_status:status; |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 353 | if (IS_TEST_SKIP(status)) |
| 354 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 355 | val_print(PRINT_DEBUG, "[Check %d] SKIPPED\n", i); |
Gowtham Siddarth | 4722308 | 2019-01-17 09:59:50 +0530 | [diff] [blame] | 356 | return status; |
| 357 | } |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 358 | if (VAL_ERROR(status)) |
| 359 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 360 | val_print(PRINT_DEBUG, "[Check %d] FAILED\n", i); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 361 | return status; |
| 362 | } |
| 363 | else |
| 364 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 365 | val_print(PRINT_DEBUG, "[Check %d] PASSED\n", i); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 366 | } |
| 367 | i++; |
| 368 | } |
| 369 | return status; |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | @brief - This function is used to handshake between: |
| 374 | - nonsecure client to server test fn |
| 375 | - secure client and server test fn |
| 376 | - nonsecure client to secure client test fn |
| 377 | @param - handle : handle returned while connecting given sid |
| 378 | @param - test_info : Test_num and block_num to be executed |
| 379 | @param - sid : RoT service to be connected. Partition dispatcher sid |
| 380 | @return - val_status_t |
| 381 | **/ |
| 382 | STATIC_DECLARE val_status_t val_execute_secure_test_func(psa_handle_t *handle, |
| 383 | test_info_t test_info, |
| 384 | uint32_t sid) |
| 385 | { |
| 386 | uint32_t test_data; |
| 387 | val_status_t status = VAL_STATUS_SUCCESS; |
| 388 | psa_status_t status_of_call = PSA_SUCCESS; |
| 389 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 390 | *handle = psa_connect(sid, 1); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 391 | |
| 392 | if (*handle < 0) |
| 393 | { |
| 394 | val_print(PRINT_ERROR, "Could not connect SID. Handle=%x\n", *handle); |
| 395 | status = VAL_STATUS_CONNECTION_FAILED; |
| 396 | } |
| 397 | |
| 398 | test_data = ((uint32_t)(test_info.test_num) | ((uint32_t)(test_info.block_num) << BLOCK_NUM_POS) |
| 399 | | ((uint32_t)(TEST_EXECUTE_FUNC) << ACTION_POS)); |
| 400 | psa_invec data[1] = {{&test_data, sizeof(test_data)}}; |
| 401 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 402 | status_of_call = psa_call(*handle, 0, data, 1, NULL, 0); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 403 | |
| 404 | if (status_of_call != PSA_SUCCESS) |
| 405 | { |
| 406 | status = VAL_STATUS_CALL_FAILED; |
| 407 | val_print(PRINT_ERROR, "Call to dispatch SF failed. Status=%x\n", status_of_call); |
| 408 | psa_close(*handle); |
| 409 | } |
| 410 | return status; |
| 411 | } |
| 412 | |
| 413 | /** |
| 414 | @brief - This function is used to retrive the status of previously connected test function |
| 415 | using val_execute_secure_test_func |
| 416 | @param - handle : handle of server function. Handle of Partition dispatcher sid |
| 417 | @return - The status of test functions |
| 418 | **/ |
| 419 | STATIC_DECLARE val_status_t val_get_secure_test_result(psa_handle_t *handle) |
| 420 | { |
| 421 | uint32_t test_data; |
| 422 | val_status_t status = VAL_STATUS_SUCCESS; |
| 423 | psa_status_t status_of_call = PSA_SUCCESS; |
| 424 | |
| 425 | test_data = (TEST_RETURN_RESULT << ACTION_POS); |
| 426 | |
| 427 | psa_outvec resp = {&status, sizeof(status)}; |
| 428 | psa_invec data[1] = {{&test_data, sizeof(test_data)}}; |
| 429 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 430 | status_of_call = psa_call(*handle, 0, data, 1, &resp, 1); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 431 | if (status_of_call != PSA_SUCCESS) |
| 432 | { |
| 433 | status = VAL_STATUS_CALL_FAILED; |
| 434 | val_print(PRINT_ERROR, "Call to dispatch SF failed. Status=%x\n", status_of_call); |
| 435 | } |
| 436 | |
| 437 | psa_close(*handle); |
| 438 | return status; |
| 439 | } |
| 440 | |
| 441 | /* |
| 442 | @brief - This function checks if the input status argument is an error. |
| 443 | On error, print the checkpoint value |
| 444 | @param - checkpoint : Test debug checkpoint |
| 445 | - val_status_t : Test status |
| 446 | @return - returns the input status back to the program. |
| 447 | */ |
| 448 | STATIC_DECLARE val_status_t val_err_check_set(uint32_t checkpoint, val_status_t status) |
| 449 | { |
| 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 | return status; |
| 460 | } |
| 461 | |
| 462 | /* |
| 463 | @brief - Writes 'size' bytes from buffer into non-volatile memory at a given |
| 464 | 'base + offset'. This is client interface API of secure partition |
| 465 | val_nvmem_write_sf API for spe world |
| 466 | - offset : Offset |
| 467 | - buffer : Pointer to source address |
| 468 | - size : Number of bytes |
| 469 | @return - val_status_t |
| 470 | */ |
| 471 | STATIC_DECLARE val_status_t val_nvmem_write(uint32_t offset, void *buffer, int size) |
| 472 | { |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 473 | nvmem_param_t nvmem_param; |
| 474 | psa_handle_t handle = 0; |
| 475 | psa_status_t status_of_call = PSA_SUCCESS; |
| 476 | val_status_t status = VAL_STATUS_SUCCESS; |
| 477 | memory_desc_t *memory_desc; |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 478 | |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 479 | status = val_target_get_config(TARGET_CONFIG_CREATE_ID(GROUP_MEMORY, MEMORY_NVMEM, 0), |
| 480 | (uint8_t **)&memory_desc, |
| 481 | (uint32_t *)sizeof(memory_desc_t)); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 482 | |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 483 | if (VAL_ERROR(status)) |
| 484 | { |
| 485 | return status; |
| 486 | } |
| 487 | |
| 488 | nvmem_param.nvmem_fn_type = NVMEM_WRITE; |
| 489 | nvmem_param.base = memory_desc->start; |
| 490 | nvmem_param.offset = offset; |
| 491 | nvmem_param.size = size; |
| 492 | psa_invec invec[2] = {{&nvmem_param, sizeof(nvmem_param)}, {buffer, size}}; |
| 493 | |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 494 | handle = psa_connect(DRIVER_NVMEM_SID, DRIVER_NVMEM_VERSION); |
| 495 | if (PSA_HANDLE_IS_VALID(handle)) |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 496 | { |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 497 | status_of_call = psa_call(handle, 0, invec, 2, NULL, 0); |
jaypit02 | ac23b5b | 2018-11-02 13:10:19 +0530 | [diff] [blame] | 498 | if (status_of_call != PSA_SUCCESS) |
| 499 | { |
| 500 | psa_close(handle); |
| 501 | return VAL_STATUS_CALL_FAILED; |
| 502 | } |
| 503 | } |
Jaykumar Pitambarbhai Patel | ccf5bf2 | 2019-12-06 11:58:32 +0530 | [diff] [blame] | 504 | else |
| 505 | { |
| 506 | return VAL_STATUS_CONNECTION_FAILED; |
| 507 | } |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 508 | psa_close(handle); |
| 509 | return VAL_STATUS_SUCCESS; |
| 510 | } |
| 511 | |
| 512 | /** |
| 513 | @brief - This function sets the given boot.state value to corresponding |
| 514 | boot NVMEM location |
| 515 | @param - state: boot_state_t |
| 516 | @return - val_status_t |
| 517 | **/ |
| 518 | STATIC_DECLARE val_status_t val_set_boot_flag(boot_state_t state) |
| 519 | { |
| 520 | boot_t boot; |
| 521 | val_status_t status; |
| 522 | |
| 523 | boot.state = state; |
| 524 | status = val_nvmem_write(VAL_NVMEM_OFFSET(NV_BOOT), &boot, sizeof(boot_t)); |
| 525 | if (VAL_ERROR(status)) |
| 526 | { |
Jaykumar Pitambarbhai Patel | f97bc88 | 2019-06-03 11:57:48 +0530 | [diff] [blame] | 527 | val_print(PRINT_ERROR, "\tval_nvmem_write failed Error=0x%x\n", status); |
jaypit02 | ea3cd06 | 2018-10-05 12:22:38 +0530 | [diff] [blame] | 528 | return status; |
| 529 | } |
| 530 | return status; |
| 531 | } |
| 532 | #endif |