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 
psa_fwu_start(psa_fwu_component_t component,const void * manifest,size_t manifest_size)12 psa_status_t psa_fwu_start(psa_fwu_component_t component,
13                            const void *manifest,
14                            size_t manifest_size)
15 {
16     psa_invec in_vec[] = {
17         { .base = &component, .len = sizeof(component) },
18         { .base = manifest, .len = manifest_size }
19     };
20 
21     return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_START,
22                     in_vec, IOVEC_LEN(in_vec), NULL, 0);
23 }
24 
psa_fwu_write(psa_fwu_component_t component,size_t image_offset,const void * block,size_t block_size)25 psa_status_t psa_fwu_write(psa_fwu_component_t component,
26                            size_t image_offset,
27                            const void *block,
28                            size_t block_size)
29 {
30     psa_invec in_vec[] = {
31         { .base = &component, .len = sizeof(component) },
32         { .base = &image_offset, .len = sizeof(image_offset) },
33         { .base = block, .len = block_size }
34     };
35 
36     return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_WRITE,
37                       in_vec, IOVEC_LEN(in_vec), NULL, 0);
38 }
39 
psa_fwu_finish(psa_fwu_component_t component)40 psa_status_t psa_fwu_finish(psa_fwu_component_t component)
41 {
42     psa_invec in_vec[] = {
43         { .base = &component, .len = sizeof(component) },
44     };
45 
46     return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_FINISH,
47                     in_vec, IOVEC_LEN(in_vec), NULL, 0);
48 }
49 
psa_fwu_install(void)50 psa_status_t psa_fwu_install(void)
51 {
52     return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_INSTALL,
53                     NULL, 0, NULL, 0);
54 }
55 
psa_fwu_cancel(psa_fwu_component_t component)56 psa_status_t psa_fwu_cancel(psa_fwu_component_t component)
57 {
58     psa_invec in_vec[] = {
59         { .base = &component, .len = sizeof(component) },
60     };
61 
62     return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_CANCEL,
63                     in_vec, IOVEC_LEN(in_vec), NULL, 0);
64 }
65 
psa_fwu_clean(psa_fwu_component_t component)66 psa_status_t psa_fwu_clean(psa_fwu_component_t component)
67 {
68     psa_invec in_vec[] = {
69         { .base = &component, .len = sizeof(component) },
70     };
71 
72     return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_CLEAN,
73                     in_vec, IOVEC_LEN(in_vec), NULL, 0);
74 }
75 
psa_fwu_query(psa_fwu_component_t component,psa_fwu_component_info_t * info)76 psa_status_t psa_fwu_query(psa_fwu_component_t component,
77                            psa_fwu_component_info_t *info)
78 {
79     psa_invec in_vec[] = {
80         { .base = &component, .len = sizeof(component) }
81     };
82     psa_outvec out_vec[] = {
83         { .base = info, .len = sizeof(*info)}
84     };
85 
86     return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_QUERY,
87                     in_vec, IOVEC_LEN(in_vec), out_vec, IOVEC_LEN(out_vec));
88 }
89 
psa_fwu_request_reboot(void)90 psa_status_t psa_fwu_request_reboot(void)
91 {
92     return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_REQUEST_REBOOT,
93                     NULL, 0, NULL, 0);
94 }
95 
psa_fwu_accept(void)96 psa_status_t psa_fwu_accept(void)
97 {
98     return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_ACCEPT,
99                     NULL, 0, NULL, 0);
100 }
101 
psa_fwu_reject(psa_status_t error)102 psa_status_t psa_fwu_reject(psa_status_t error)
103 {
104     psa_invec in_vec[] = {
105         { .base = &error, .len = sizeof(error) }
106     };
107 
108     return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_REJECT,
109                     in_vec, IOVEC_LEN(in_vec), NULL, 0);
110 }
111