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 | |
Sherry Zhang | 3e7129f | 2021-01-13 13:42:47 +0800 | [diff] [blame] | 8 | #include "psa/client.h" |
Xinyu Zhang | ade2e0a | 2021-03-18 16:20:54 +0800 | [diff] [blame] | 9 | #include "psa/update.h" |
Sherry Zhang | 3e7129f | 2021-01-13 13:42:47 +0800 | [diff] [blame] | 10 | #include "psa_manifest/sid.h" |
Xinyu Zhang | ade2e0a | 2021-03-18 16:20:54 +0800 | [diff] [blame] | 11 | #include "tfm_api.h" |
Sherry Zhang | 3e7129f | 2021-01-13 13:42:47 +0800 | [diff] [blame] | 12 | |
| 13 | psa_status_t psa_fwu_write(const psa_image_id_t image_id, |
| 14 | size_t block_offset, |
| 15 | const void *block, |
| 16 | size_t block_size) |
| 17 | { |
| 18 | psa_status_t status; |
| 19 | psa_handle_t handle; |
| 20 | |
| 21 | psa_invec in_vec[] = { |
| 22 | { .base = &image_id, .len = sizeof(image_id) }, |
| 23 | { .base = &block_offset, .len = sizeof(block_offset) }, |
| 24 | { .base = block, .len = block_size } |
| 25 | }; |
| 26 | |
| 27 | handle = psa_connect(TFM_FWU_WRITE_SID, TFM_FWU_WRITE_VERSION); |
| 28 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 29 | return PSA_ERROR_GENERIC_ERROR; |
| 30 | } |
| 31 | |
| 32 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), NULL, |
| 33 | 0); |
| 34 | |
| 35 | psa_close(handle); |
| 36 | |
| 37 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 38 | return PSA_ERROR_INVALID_ARGUMENT; |
| 39 | } |
| 40 | |
| 41 | return status; |
| 42 | } |
| 43 | |
| 44 | psa_status_t psa_fwu_install(const psa_image_id_t image_id, |
| 45 | psa_image_id_t *dependency_uuid, |
| 46 | psa_image_version_t *dependency_version) |
| 47 | { |
| 48 | psa_status_t status; |
| 49 | psa_handle_t handle; |
| 50 | |
| 51 | psa_invec in_vec[] = { |
| 52 | { .base = &image_id, .len = sizeof(image_id) } |
| 53 | }; |
| 54 | |
| 55 | psa_outvec out_vec[] = { |
| 56 | { .base = dependency_uuid, .len = sizeof(*dependency_uuid) }, |
| 57 | { .base = dependency_version, .len = sizeof(*dependency_version)} |
| 58 | }; |
| 59 | |
| 60 | if ((dependency_uuid == NULL) || (dependency_version == NULL)) { |
| 61 | return PSA_ERROR_INVALID_ARGUMENT; |
| 62 | } |
| 63 | |
| 64 | handle = psa_connect(TFM_FWU_INSTALL_SID, TFM_FWU_INSTALL_VERSION); |
| 65 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 66 | return PSA_ERROR_GENERIC_ERROR; |
| 67 | } |
| 68 | |
| 69 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), |
| 70 | out_vec, IOVEC_LEN(out_vec)); |
| 71 | |
| 72 | psa_close(handle); |
| 73 | |
| 74 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 75 | return PSA_ERROR_INVALID_ARGUMENT; |
| 76 | } |
| 77 | |
| 78 | return status; |
| 79 | } |
| 80 | |
| 81 | psa_status_t psa_fwu_abort(const psa_image_id_t image_id) |
| 82 | { |
| 83 | psa_status_t status; |
| 84 | psa_handle_t handle; |
| 85 | |
| 86 | psa_invec in_vec[] = { |
| 87 | { .base = &image_id, .len = sizeof(image_id) } |
| 88 | }; |
| 89 | |
| 90 | handle = psa_connect(TFM_FWU_ABORT_SID, TFM_FWU_ABORT_VERSION); |
| 91 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 92 | return PSA_ERROR_GENERIC_ERROR; |
| 93 | } |
| 94 | |
| 95 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), NULL, |
| 96 | 0); |
| 97 | |
| 98 | psa_close(handle); |
| 99 | |
| 100 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 101 | return PSA_ERROR_INVALID_ARGUMENT; |
| 102 | } |
| 103 | |
| 104 | return status; |
| 105 | } |
| 106 | |
| 107 | psa_status_t psa_fwu_query(const psa_image_id_t image_id, psa_image_info_t *info) |
| 108 | { |
| 109 | psa_status_t status; |
| 110 | psa_handle_t handle; |
| 111 | |
| 112 | psa_invec in_vec[] = { |
| 113 | { .base = &image_id, .len = sizeof(image_id) } |
| 114 | }; |
| 115 | psa_outvec out_vec[] = { |
| 116 | { .base = info, .len = sizeof(*info)} |
| 117 | }; |
| 118 | |
| 119 | handle = psa_connect(TFM_FWU_QUERY_SID, TFM_FWU_QUERY_VERSION); |
| 120 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 121 | return PSA_ERROR_GENERIC_ERROR; |
| 122 | } |
| 123 | |
| 124 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), out_vec, |
| 125 | IOVEC_LEN(out_vec)); |
| 126 | |
| 127 | psa_close(handle); |
| 128 | |
| 129 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 130 | return PSA_ERROR_INVALID_ARGUMENT; |
| 131 | } |
| 132 | |
| 133 | return status; |
| 134 | } |
| 135 | |
| 136 | psa_status_t psa_fwu_request_reboot(void) |
| 137 | { |
| 138 | psa_handle_t handle; |
| 139 | psa_status_t status; |
| 140 | |
| 141 | handle = psa_connect(TFM_FWU_REQUEST_REBOOT_SID, |
| 142 | TFM_FWU_REQUEST_REBOOT_VERSION); |
| 143 | if (!PSA_HANDLE_IS_VALID(handle)) { |
| 144 | return PSA_ERROR_GENERIC_ERROR; |
| 145 | } |
| 146 | |
| 147 | status = psa_call(handle, PSA_IPC_CALL, NULL, 0, NULL, 0); |
| 148 | |
| 149 | psa_close(handle); |
| 150 | |
| 151 | if (status == (psa_status_t)TFM_ERROR_INVALID_PARAMETER) { |
| 152 | return PSA_ERROR_INVALID_ARGUMENT; |
| 153 | } |
| 154 | |
| 155 | return status; |
| 156 | } |
| 157 | |
Sherry Zhang | 2da977d | 2021-05-10 16:59:05 +0800 | [diff] [blame] | 158 | psa_status_t psa_fwu_accept(psa_image_id_t image_id) |
Sherry Zhang | 3e7129f | 2021-01-13 13:42:47 +0800 | [diff] [blame] | 159 | { |
| 160 | psa_handle_t handle; |
| 161 | psa_status_t status; |
Sherry Zhang | 2da977d | 2021-05-10 16:59:05 +0800 | [diff] [blame] | 162 | psa_invec in_vec[] = { |
| 163 | { .base = &image_id, .len = sizeof(image_id) } |
| 164 | }; |
Sherry Zhang | 3e7129f | 2021-01-13 13:42:47 +0800 | [diff] [blame] | 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 | |
Sherry Zhang | 2da977d | 2021-05-10 16:59:05 +0800 | [diff] [blame] | 172 | status = psa_call(handle, PSA_IPC_CALL, in_vec, IOVEC_LEN(in_vec), NULL, 0); |
Sherry Zhang | 3e7129f | 2021-01-13 13:42:47 +0800 | [diff] [blame] | 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 | } |