blob: 80c47789b7cbee0d11afd2c6c1c5568c01804062 [file] [log] [blame]
Sherry Zhang3e7129f2021-01-13 13:42:47 +08001/*
Sherry Zhang71468952022-10-19 14:09:05 +08002 * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
Sherry Zhang3e7129f2021-01-13 13:42:47 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Sherry Zhang3e7129f2021-01-13 13:42:47 +08008#include "psa/client.h"
Xinyu Zhangade2e0a2021-03-18 16:20:54 +08009#include "psa/update.h"
Sherry Zhang3e7129f2021-01-13 13:42:47 +080010#include "psa_manifest/sid.h"
Sherry Zhang3e7129f2021-01-13 13:42:47 +080011
Sherry Zhang71468952022-10-19 14:09:05 +080012psa_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
25psa_status_t psa_fwu_write(psa_fwu_component_t component,
26 size_t image_offset,
Sherry Zhang3e7129f2021-01-13 13:42:47 +080027 const void *block,
28 size_t block_size)
29{
Sherry Zhang3e7129f2021-01-13 13:42:47 +080030 psa_invec in_vec[] = {
Sherry Zhang71468952022-10-19 14:09:05 +080031 { .base = &component, .len = sizeof(component) },
32 { .base = &image_offset, .len = sizeof(image_offset) },
Sherry Zhang3e7129f2021-01-13 13:42:47 +080033 { .base = block, .len = block_size }
34 };
35
Sherry Zhangf7e2ade2022-06-09 17:36:41 +080036 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_WRITE,
Sherry Zhang71468952022-10-19 14:09:05 +080037 in_vec, IOVEC_LEN(in_vec), NULL, 0);
38}
39
40psa_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,
Sherry Zhangf7e2ade2022-06-09 17:36:41 +080047 in_vec, IOVEC_LEN(in_vec), NULL, 0);
Sherry Zhang3e7129f2021-01-13 13:42:47 +080048}
49
Sherry Zhang71468952022-10-19 14:09:05 +080050psa_status_t psa_fwu_install(void)
Sherry Zhang3e7129f2021-01-13 13:42:47 +080051{
Sherry Zhangf7e2ade2022-06-09 17:36:41 +080052 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_INSTALL,
Sherry Zhang71468952022-10-19 14:09:05 +080053 NULL, 0, NULL, 0);
Sherry Zhang3e7129f2021-01-13 13:42:47 +080054}
55
Sherry Zhang71468952022-10-19 14:09:05 +080056psa_status_t psa_fwu_cancel(psa_fwu_component_t component)
Sherry Zhang3e7129f2021-01-13 13:42:47 +080057{
Sherry Zhang3e7129f2021-01-13 13:42:47 +080058 psa_invec in_vec[] = {
Sherry Zhang71468952022-10-19 14:09:05 +080059 { .base = &component, .len = sizeof(component) },
Sherry Zhang3e7129f2021-01-13 13:42:47 +080060 };
61
Sherry Zhang71468952022-10-19 14:09:05 +080062 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_CANCEL,
Sherry Zhangf7e2ade2022-06-09 17:36:41 +080063 in_vec, IOVEC_LEN(in_vec), NULL, 0);
Sherry Zhang3e7129f2021-01-13 13:42:47 +080064}
65
Sherry Zhang71468952022-10-19 14:09:05 +080066psa_status_t psa_fwu_clean(psa_fwu_component_t component)
Sherry Zhang3e7129f2021-01-13 13:42:47 +080067{
Sherry Zhang3e7129f2021-01-13 13:42:47 +080068 psa_invec in_vec[] = {
Sherry Zhang71468952022-10-19 14:09:05 +080069 { .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
76psa_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) }
Sherry Zhang3e7129f2021-01-13 13:42:47 +080081 };
82 psa_outvec out_vec[] = {
83 { .base = info, .len = sizeof(*info)}
84 };
85
Sherry Zhangf7e2ade2022-06-09 17:36:41 +080086 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_QUERY,
87 in_vec, IOVEC_LEN(in_vec), out_vec, IOVEC_LEN(out_vec));
Sherry Zhang3e7129f2021-01-13 13:42:47 +080088}
89
90psa_status_t psa_fwu_request_reboot(void)
91{
Sherry Zhangf7e2ade2022-06-09 17:36:41 +080092 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_REQUEST_REBOOT,
93 NULL, 0, NULL, 0);
Sherry Zhang3e7129f2021-01-13 13:42:47 +080094}
95
Sherry Zhang71468952022-10-19 14:09:05 +080096psa_status_t psa_fwu_accept(void)
Sherry Zhang3e7129f2021-01-13 13:42:47 +080097{
Sherry Zhangf7e2ade2022-06-09 17:36:41 +080098 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_ACCEPT,
Sherry Zhang71468952022-10-19 14:09:05 +080099 NULL, 0, NULL, 0);
Sherry Zhang3e7129f2021-01-13 13:42:47 +0800100}
101
Sherry Zhang71468952022-10-19 14:09:05 +0800102psa_status_t psa_fwu_reject(psa_status_t error)
Sherry Zhang3e7129f2021-01-13 13:42:47 +0800103{
Sherry Zhang71468952022-10-19 14:09:05 +0800104 psa_invec in_vec[] = {
105 { .base = &error, .len = sizeof(error) }
106 };
Sherry Zhang3e7129f2021-01-13 13:42:47 +0800107
Sherry Zhang71468952022-10-19 14:09:05 +0800108 return psa_call(TFM_FIRMWARE_UPDATE_SERVICE_HANDLE, TFM_FWU_REJECT,
109 in_vec, IOVEC_LEN(in_vec), NULL, 0);
Sherry Zhang3e7129f2021-01-13 13:42:47 +0800110}