Sherry Zhang | 3e7129f | 2021-01-13 13:42:47 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "psa/update.h" |
| 9 | #include "tfm_api.h" |
| 10 | |
| 11 | #include "psa/client.h" |
| 12 | #include "psa_manifest/sid.h" |
| 13 | |
| 14 | #define IOVEC_LEN(x) (uint32_t)(sizeof(x)/sizeof(x[0])) |
| 15 | |
| 16 | psa_status_t psa_fwu_write(const psa_image_id_t image_id, |
| 17 | size_t block_offset, |
| 18 | const void *block, |
| 19 | size_t block_size) |
| 20 | { |
| 21 | psa_status_t status; |
| 22 | psa_handle_t handle; |
| 23 | |
| 24 | psa_invec in_vec[] = { |
| 25 | { .base = &image_id, .len = sizeof(image_id) }, |
| 26 | { .base = &block_offset, .len = sizeof(block_offset) }, |
| 27 | { .base = block, .len = block_size } |
| 28 | }; |
| 29 | |
| 30 | handle = psa_connect(TFM_FWU_WRITE_SID, TFM_FWU_WRITE_VERSION); |
| 31 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 32 | return PSA_ERROR_GENERIC_ERROR; |
| 33 | } |
| 34 | |
| 35 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), NULL, |
| 36 | 0); |
| 37 | |
| 38 | psa_close(handle); |
| 39 | |
| 40 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 41 | return PSA_ERROR_INVALID_ARGUMENT; |
| 42 | } |
| 43 | |
| 44 | return status; |
| 45 | } |
| 46 | |
| 47 | psa_status_t psa_fwu_install(const psa_image_id_t image_id, |
| 48 | psa_image_id_t *dependency_uuid, |
| 49 | psa_image_version_t *dependency_version) |
| 50 | { |
| 51 | psa_status_t status; |
| 52 | psa_handle_t handle; |
| 53 | |
| 54 | psa_invec in_vec[] = { |
| 55 | { .base = &image_id, .len = sizeof(image_id) } |
| 56 | }; |
| 57 | |
| 58 | psa_outvec out_vec[] = { |
| 59 | { .base = dependency_uuid, .len = sizeof(*dependency_uuid) }, |
| 60 | { .base = dependency_version, .len = sizeof(*dependency_version)} |
| 61 | }; |
| 62 | |
| 63 | if ((dependency_uuid == NULL) || (dependency_version == NULL)) { |
| 64 | return PSA_ERROR_INVALID_ARGUMENT; |
| 65 | } |
| 66 | |
| 67 | handle = psa_connect(TFM_FWU_INSTALL_SID, TFM_FWU_INSTALL_VERSION); |
| 68 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 69 | return PSA_ERROR_GENERIC_ERROR; |
| 70 | } |
| 71 | |
| 72 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), |
| 73 | out_vec, IOVEC_LEN(out_vec)); |
| 74 | |
| 75 | psa_close(handle); |
| 76 | |
| 77 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 78 | return PSA_ERROR_INVALID_ARGUMENT; |
| 79 | } |
| 80 | |
| 81 | return status; |
| 82 | } |
| 83 | |
| 84 | psa_status_t psa_fwu_abort(const psa_image_id_t image_id) |
| 85 | { |
| 86 | psa_status_t status; |
| 87 | psa_handle_t handle; |
| 88 | |
| 89 | psa_invec in_vec[] = { |
| 90 | { .base = &image_id, .len = sizeof(image_id) } |
| 91 | }; |
| 92 | |
| 93 | handle = psa_connect(TFM_FWU_ABORT_SID, TFM_FWU_ABORT_VERSION); |
| 94 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 95 | return PSA_ERROR_GENERIC_ERROR; |
| 96 | } |
| 97 | |
| 98 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), NULL, |
| 99 | 0); |
| 100 | |
| 101 | psa_close(handle); |
| 102 | |
| 103 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 104 | return PSA_ERROR_INVALID_ARGUMENT; |
| 105 | } |
| 106 | |
| 107 | return status; |
| 108 | } |
| 109 | |
| 110 | psa_status_t psa_fwu_query(const psa_image_id_t image_id, psa_image_info_t *info) |
| 111 | { |
| 112 | psa_status_t status; |
| 113 | psa_handle_t handle; |
| 114 | |
| 115 | psa_invec in_vec[] = { |
| 116 | { .base = &image_id, .len = sizeof(image_id) } |
| 117 | }; |
| 118 | psa_outvec out_vec[] = { |
| 119 | { .base = info, .len = sizeof(*info)} |
| 120 | }; |
| 121 | |
| 122 | handle = psa_connect(TFM_FWU_QUERY_SID, TFM_FWU_QUERY_VERSION); |
| 123 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 124 | return PSA_ERROR_GENERIC_ERROR; |
| 125 | } |
| 126 | |
| 127 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), out_vec, |
| 128 | IOVEC_LEN(out_vec)); |
| 129 | |
| 130 | psa_close(handle); |
| 131 | |
| 132 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 133 | return PSA_ERROR_INVALID_ARGUMENT; |
| 134 | } |
| 135 | |
| 136 | return status; |
| 137 | } |
| 138 | |
| 139 | psa_status_t psa_fwu_request_reboot(void) |
| 140 | { |
| 141 | psa_handle_t handle; |
| 142 | psa_status_t status; |
| 143 | |
| 144 | handle = psa_connect(TFM_FWU_REQUEST_REBOOT_SID, |
| 145 | TFM_FWU_REQUEST_REBOOT_VERSION); |
| 146 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 147 | return PSA_ERROR_GENERIC_ERROR; |
| 148 | } |
| 149 | |
| 150 | status = psa_call(handle, PSA_IPC_CALL, NULL, 0, NULL, 0); |
| 151 | |
| 152 | psa_close(handle); |
| 153 | |
| 154 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 155 | return PSA_ERROR_INVALID_ARGUMENT; |
| 156 | } |
| 157 | |
| 158 | return status; |
| 159 | } |
| 160 | |
| 161 | psa_status_t psa_fwu_accept(void) |
| 162 | { |
| 163 | psa_handle_t handle; |
| 164 | psa_status_t status; |
| 165 | |
| 166 | handle = psa_connect(TFM_FWU_ACCEPT_SID, |
| 167 | TFM_FWU_ACCEPT_VERSION); |
| 168 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 169 | return PSA_ERROR_GENERIC_ERROR; |
| 170 | } |
| 171 | |
| 172 | status = psa_call(handle, PSA_IPC_CALL, NULL, 0, NULL, 0); |
| 173 | |
| 174 | psa_close(handle); |
| 175 | |
| 176 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 177 | return PSA_ERROR_INVALID_ARGUMENT; |
| 178 | } |
| 179 | |
| 180 | return status; |
| 181 | } |
| 182 | |
| 183 | psa_status_t psa_fwu_set_manifest(psa_image_id_t image_id, |
| 184 | const void *manifest, |
| 185 | size_t manifest_size, |
| 186 | psa_hash_t *manifest_dependency) |
| 187 | { |
| 188 | psa_status_t status; |
| 189 | |
| 190 | status = PSA_ERROR_NOT_SUPPORTED; |
| 191 | |
| 192 | return status; |
| 193 | } |