1 /*
2 * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8 #include "psa/client.h"
9 #include "psa/update.h"
10 #include "psa_manifest/sid.h"
11 #include "tfm_api.h"
12
psa_fwu_start(psa_fwu_component_t component,const void * manifest,size_t manifest_size)13 psa_status_t psa_fwu_start(psa_fwu_component_t component,
14 const void *manifest,
15 size_t manifest_size)
16 {
17 psa_invec in_vec[] = {
18 { .base = &component, .len = sizeof(component) },
19 { .base = manifest, .len = manifest_size }
20 };
21
22 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_START,
23 in_vec, IOVEC_LEN(in_vec), NULL, 0);
24 }
25
psa_fwu_write(psa_fwu_component_t component,size_t image_offset,const void * block,size_t block_size)26 psa_status_t psa_fwu_write(psa_fwu_component_t component,
27 size_t image_offset,
28 const void *block,
29 size_t block_size)
30 {
31 psa_invec in_vec[] = {
32 { .base = &component, .len = sizeof(component) },
33 { .base = &image_offset, .len = sizeof(image_offset) },
34 { .base = block, .len = block_size }
35 };
36
37 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_WRITE,
38 in_vec, IOVEC_LEN(in_vec), NULL, 0);
39 }
40
psa_fwu_finish(psa_fwu_component_t component)41 psa_status_t psa_fwu_finish(psa_fwu_component_t component)
42 {
43 psa_invec in_vec[] = {
44 { .base = &component, .len = sizeof(component) },
45 };
46
47 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_FINISH,
48 in_vec, IOVEC_LEN(in_vec), NULL, 0);
49 }
50
psa_fwu_install(void)51 psa_status_t psa_fwu_install(void)
52 {
53 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_INSTALL,
54 NULL, 0, NULL, 0);
55 }
56
psa_fwu_cancel(psa_fwu_component_t component)57 psa_status_t psa_fwu_cancel(psa_fwu_component_t component)
58 {
59 psa_invec in_vec[] = {
60 { .base = &component, .len = sizeof(component) },
61 };
62
63 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_CANCEL,
64 in_vec, IOVEC_LEN(in_vec), NULL, 0);
65 }
66
psa_fwu_clean(psa_fwu_component_t component)67 psa_status_t psa_fwu_clean(psa_fwu_component_t component)
68 {
69 psa_invec in_vec[] = {
70 { .base = &component, .len = sizeof(component) },
71 };
72
73 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_CLEAN,
74 in_vec, IOVEC_LEN(in_vec), NULL, 0);
75 }
76
psa_fwu_query(psa_fwu_component_t component,psa_fwu_component_info_t * info)77 psa_status_t psa_fwu_query(psa_fwu_component_t component,
78 psa_fwu_component_info_t *info)
79 {
80 psa_invec in_vec[] = {
81 { .base = &component, .len = sizeof(component) }
82 };
83 psa_outvec out_vec[] = {
84 { .base = info, .len = sizeof(*info)}
85 };
86
87 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_QUERY,
88 in_vec, IOVEC_LEN(in_vec), out_vec, IOVEC_LEN(out_vec));
89 }
90
psa_fwu_request_reboot(void)91 psa_status_t psa_fwu_request_reboot(void)
92 {
93 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_REQUEST_REBOOT,
94 NULL, 0, NULL, 0);
95 }
96
psa_fwu_accept(void)97 psa_status_t psa_fwu_accept(void)
98 {
99 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_ACCEPT,
100 NULL, 0, NULL, 0);
101 }
102
psa_fwu_reject(psa_status_t error)103 psa_status_t psa_fwu_reject(psa_status_t error)
104 {
105 psa_invec in_vec[] = {
106 { .base = &error, .len = sizeof(error) }
107 };
108
109 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_REJECT,
110 in_vec, IOVEC_LEN(in_vec), NULL, 0);
111 }
112