blob: 1a6e8f50f13f9c425a7fd9277c9692ea681ef5cd [file] [log] [blame]
Patrick Williams975a06f2022-10-21 14:42:47 -05001From 6b8ebdeb8caa6326ae2a4befaf4410a7a54d4e02 Mon Sep 17 00:00:00 2001
2From: Julian Hall <julian.hall@arm.com>
3Date: Tue, 12 Oct 2021 15:45:41 +0100
4Subject: [PATCH 13/19] Add stub capsule update service components
5
6To facilitate development of a capsule update service provider,
7stub components are added to provide a starting point for an
8implementation. The capsule update service provider is integrated
9into the se-proxy/common deployment.
10
11Upstream-Status: Pending
12Signed-off-by: Vishnu Banavath <vishnu.banavath@arm.com>
13Signed-off-by: Julian Hall <julian.hall@arm.com>
14Change-Id: I0d4049bb4de5af7ca80806403301692507085d28
15Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
16---
17 .../backend/capsule_update_backend.h | 24 ++++
18 .../provider/capsule_update_provider.c | 133 ++++++++++++++++++
19 .../provider/capsule_update_provider.h | 51 +++++++
20 .../capsule_update/provider/component.cmake | 13 ++
21 deployments/se-proxy/common/se_proxy_sp.c | 3 +
22 .../se-proxy/common/service_proxy_factory.c | 16 +++
23 .../se-proxy/common/service_proxy_factory.h | 1 +
24 deployments/se-proxy/se-proxy.cmake | 1 +
25 deployments/se-proxy/se_proxy_interfaces.h | 9 +-
26 .../capsule_update/capsule_update_proto.h | 13 ++
27 protocols/service/capsule_update/opcodes.h | 17 +++
28 protocols/service/capsule_update/parameters.h | 15 ++
29 12 files changed, 292 insertions(+), 4 deletions(-)
30 create mode 100644 components/service/capsule_update/backend/capsule_update_backend.h
31 create mode 100644 components/service/capsule_update/provider/capsule_update_provider.c
32 create mode 100644 components/service/capsule_update/provider/capsule_update_provider.h
33 create mode 100644 components/service/capsule_update/provider/component.cmake
34 create mode 100644 protocols/service/capsule_update/capsule_update_proto.h
35 create mode 100644 protocols/service/capsule_update/opcodes.h
36 create mode 100644 protocols/service/capsule_update/parameters.h
37
38diff --git a/components/service/capsule_update/backend/capsule_update_backend.h b/components/service/capsule_update/backend/capsule_update_backend.h
39new file mode 100644
40index 000000000000..f3144ff1d7d5
41--- /dev/null
42+++ b/components/service/capsule_update/backend/capsule_update_backend.h
43@@ -0,0 +1,24 @@
44+/*
45+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
46+ *
47+ * SPDX-License-Identifier: BSD-3-Clause
48+ */
49+
50+#ifndef CAPSULE_UPDATE_BACKEND_H
51+#define CAPSULE_UPDATE_BACKEND_H
52+
53+#ifdef __cplusplus
54+extern "C" {
55+#endif
56+
57+/**
58+ * Defines the common capsule update backend interface. Concrete backends
59+ * implement this interface for different types of platform.
60+ */
61+
62+
63+#ifdef __cplusplus
64+} /* extern "C" */
65+#endif
66+
67+#endif /* CAPSULE_UPDATE_BACKEND_H */
68diff --git a/components/service/capsule_update/provider/capsule_update_provider.c b/components/service/capsule_update/provider/capsule_update_provider.c
69new file mode 100644
70index 000000000000..e133753f8560
71--- /dev/null
72+++ b/components/service/capsule_update/provider/capsule_update_provider.c
73@@ -0,0 +1,133 @@
74+/*
75+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
76+ *
77+ * SPDX-License-Identifier: BSD-3-Clause
78+ */
79+
80+#include <psa/client.h>
81+#include <psa/sid.h>
82+#include <trace.h>
83+
84+#include <protocols/service/capsule_update/capsule_update_proto.h>
85+#include <protocols/rpc/common/packed-c/status.h>
86+#include "capsule_update_provider.h"
87+
88+
89+#define CAPSULE_UPDATE_REQUEST (0x1)
90+#define KERNEL_STARTED_EVENT (0x2)
91+
92+enum corstone1000_ioctl_id_t {
93+ IOCTL_CORSTONE1000_FWU_FLASH_IMAGES = 0,
94+ IOCTL_CORSTONE1000_FWU_HOST_ACK,
95+};
96+
97+/* Service request handlers */
98+static rpc_status_t update_capsule_handler(void *context, struct call_req *req);
99+static rpc_status_t boot_confirmed_handler(void *context, struct call_req *req);
100+
101+/* Handler mapping table for service */
102+static const struct service_handler handler_table[] = {
103+ {CAPSULE_UPDATE_OPCODE_UPDATE_CAPSULE, update_capsule_handler},
104+ {CAPSULE_UPDATE_OPCODE_BOOT_CONFIRMED, boot_confirmed_handler}
105+};
106+
107+struct rpc_interface *capsule_update_provider_init(
108+ struct capsule_update_provider *context)
109+{
110+ struct rpc_interface *rpc_interface = NULL;
111+
112+ if (context) {
113+
114+ service_provider_init(
115+ &context->base_provider,
116+ context,
117+ handler_table,
118+ sizeof(handler_table)/sizeof(struct service_handler));
119+
120+ rpc_interface = service_provider_get_rpc_interface(&context->base_provider);
121+ }
122+
123+ return rpc_interface;
124+}
125+
126+void capsule_update_provider_deinit(struct capsule_update_provider *context)
127+{
128+ (void)context;
129+}
130+
131+static rpc_status_t event_handler(uint32_t opcode, struct rpc_caller *caller)
132+{
133+ uint32_t ioctl_id;
134+ psa_handle_t handle;
135+ rpc_status_t rpc_status = TS_RPC_CALL_ACCEPTED;
136+
137+ struct psa_invec in_vec[] = {
138+ { .base = &ioctl_id, .len = sizeof(ioctl_id) }
139+ };
140+
141+ if(!caller) {
142+ EMSG("event_handler rpc_caller is NULL");
143+ rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
144+ return rpc_status;
145+ }
146+
147+ IMSG("event handler opcode %x", opcode);
148+ switch(opcode) {
149+ case CAPSULE_UPDATE_REQUEST:
150+ /* Openamp call with IOCTL for firmware update*/
151+ ioctl_id = IOCTL_CORSTONE1000_FWU_FLASH_IMAGES;
152+ handle = psa_connect(caller, TFM_SP_PLATFORM_IOCTL_SID,
153+ TFM_SP_PLATFORM_IOCTL_VERSION);
154+ if (handle <= 0) {
155+ EMSG("%s Invalid handle", __func__);
156+ rpc_status = TS_RPC_ERROR_INVALID_PARAMETER;
157+ return rpc_status;
158+ }
159+ psa_call(caller,handle, PSA_IPC_CALL,
160+ in_vec,IOVEC_LEN(in_vec), NULL, 0);
161+ break;
162+
163+ case KERNEL_STARTED_EVENT:
164+ ioctl_id = IOCTL_CORSTONE1000_FWU_HOST_ACK;
165+ /*openamp call with IOCTL for kernel start*/
166+ handle = psa_connect(caller, TFM_SP_PLATFORM_IOCTL_SID,
167+ TFM_SP_PLATFORM_IOCTL_VERSION);
168+ if (handle <= 0) {
169+ EMSG("%s Invalid handle", __func__);
170+ rpc_status = TS_RPC_ERROR_INVALID_PARAMETER;
171+ return rpc_status;
172+ }
173+ psa_call(caller,handle, PSA_IPC_CALL,
174+ in_vec,IOVEC_LEN(in_vec), NULL, 0);
175+ break;
176+ default:
177+ EMSG("%s unsupported opcode", __func__);
178+ rpc_status = TS_RPC_ERROR_INVALID_PARAMETER;
179+ return rpc_status;
180+ }
181+ return rpc_status;
182+
183+}
184+
185+static rpc_status_t update_capsule_handler(void *context, struct call_req *req)
186+{
187+ struct capsule_update_provider *this_instance = (struct capsule_update_provider*)context;
188+ struct rpc_caller *caller = this_instance->client.caller;
189+ uint32_t opcode = req->opcode;
190+ rpc_status_t rpc_status = TS_RPC_ERROR_NOT_READY;
191+
192+ rpc_status = event_handler(opcode, caller);
193+ return rpc_status;
194+}
195+
196+static rpc_status_t boot_confirmed_handler(void *context, struct call_req *req)
197+{
198+ struct capsule_update_provider *this_instance = (struct capsule_update_provider*)context;
199+ struct rpc_caller *caller = this_instance->client.caller;
200+ uint32_t opcode = req->opcode;
201+ rpc_status_t rpc_status = TS_RPC_ERROR_NOT_READY;
202+
203+ rpc_status = event_handler(opcode, caller);
204+
205+ return rpc_status;
206+}
207diff --git a/components/service/capsule_update/provider/capsule_update_provider.h b/components/service/capsule_update/provider/capsule_update_provider.h
208new file mode 100644
209index 000000000000..3de49854ea90
210--- /dev/null
211+++ b/components/service/capsule_update/provider/capsule_update_provider.h
212@@ -0,0 +1,51 @@
213+/*
214+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
215+ *
216+ * SPDX-License-Identifier: BSD-3-Clause
217+ */
218+
219+#ifndef CAPSULE_UPDATE_PROVIDER_H
220+#define CAPSULE_UPDATE_PROVIDER_H
221+
222+#include <rpc/common/endpoint/rpc_interface.h>
223+#include <service/common/provider/service_provider.h>
224+#include <service/common/client/service_client.h>
225+#include <service/capsule_update/backend/capsule_update_backend.h>
226+
227+#ifdef __cplusplus
228+extern "C" {
229+#endif
230+
231+/**
232+ * The capsule_update_provider is a service provider that accepts update capsule
233+ * requests and delegates them to a suitable backend that applies the update.
234+ */
235+struct capsule_update_provider
236+{
237+ struct service_provider base_provider;
238+ struct service_client client;
239+};
240+
241+/**
242+ * \brief Initialize an instance of the capsule update service provider
243+ *
244+ * @param[in] context The instance to initialize
245+ *
246+ * \return An rpc_interface or NULL on failure
247+ */
248+struct rpc_interface *capsule_update_provider_init(
249+ struct capsule_update_provider *context);
250+
251+/**
252+ * \brief Cleans up when the instance is no longer needed
253+ *
254+ * \param[in] context The instance to de-initialize
255+ */
256+void capsule_update_provider_deinit(
257+ struct capsule_update_provider *context);
258+
259+#ifdef __cplusplus
260+} /* extern "C" */
261+#endif
262+
263+#endif /* CAPSULE_UPDATE_PROVIDER_H */
264diff --git a/components/service/capsule_update/provider/component.cmake b/components/service/capsule_update/provider/component.cmake
265new file mode 100644
266index 000000000000..1d412eb234d9
267--- /dev/null
268+++ b/components/service/capsule_update/provider/component.cmake
269@@ -0,0 +1,13 @@
270+#-------------------------------------------------------------------------------
271+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
272+#
273+# SPDX-License-Identifier: BSD-3-Clause
274+#
275+#-------------------------------------------------------------------------------
276+if (NOT DEFINED TGT)
277+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
278+endif()
279+
280+target_sources(${TGT} PRIVATE
281+ "${CMAKE_CURRENT_LIST_DIR}/capsule_update_provider.c"
282+ )
283diff --git a/deployments/se-proxy/common/se_proxy_sp.c b/deployments/se-proxy/common/se_proxy_sp.c
284index a37396f4454b..a38ad6ca3f56 100644
285--- a/deployments/se-proxy/common/se_proxy_sp.c
286+++ b/deployments/se-proxy/common/se_proxy_sp.c
287@@ -77,6 +77,9 @@ void __noreturn sp_main(struct ffa_init_info *init_info)
288 }
289 rpc_demux_attach(&rpc_demux, SE_PROXY_INTERFACE_ID_ATTEST, rpc_iface);
290
291+ rpc_iface = capsule_update_proxy_create();
292+ rpc_demux_attach(&rpc_demux, SE_PROXY_INTERFACE_ID_CAPSULE_UPDATE, rpc_iface);
293+
294 /* End of boot phase */
295 result = sp_msg_wait(&req_msg);
296 if (result != SP_RESULT_OK) {
297diff --git a/deployments/se-proxy/common/service_proxy_factory.c b/deployments/se-proxy/common/service_proxy_factory.c
298index 7edeef8b434a..591cc9eeb59e 100644
299--- a/deployments/se-proxy/common/service_proxy_factory.c
300+++ b/deployments/se-proxy/common/service_proxy_factory.c
301@@ -13,6 +13,7 @@
302 #include <service/crypto/factory/crypto_provider_factory.h>
303 #include <service/secure_storage/frontend/secure_storage_provider/secure_storage_provider.h>
304 #include <trace.h>
305+#include <service/capsule_update/provider/capsule_update_provider.h>
306
307 /* Stub backends */
308 #include <service/crypto/backend/psa_ipc/crypto_ipc_backend.h>
309@@ -93,3 +94,18 @@ struct rpc_interface *its_proxy_create(void)
310
311 return secure_storage_provider_init(&its_provider, backend);
312 }
313+
314+struct rpc_interface *capsule_update_proxy_create(void)
315+{
316+ static struct capsule_update_provider capsule_update_provider;
317+ static struct rpc_caller *capsule_update_caller;
318+
319+ capsule_update_caller = openamp_caller_init(&openamp);
320+
321+ if (!capsule_update_caller)
322+ return NULL;
323+
324+ capsule_update_provider.client.caller = capsule_update_caller;
325+
326+ return capsule_update_provider_init(&capsule_update_provider);
327+}
328diff --git a/deployments/se-proxy/common/service_proxy_factory.h b/deployments/se-proxy/common/service_proxy_factory.h
329index 298d407a2371..02aa7fe2550d 100644
330--- a/deployments/se-proxy/common/service_proxy_factory.h
331+++ b/deployments/se-proxy/common/service_proxy_factory.h
332@@ -17,6 +17,7 @@ struct rpc_interface *attest_proxy_create(void);
333 struct rpc_interface *crypto_proxy_create(void);
334 struct rpc_interface *ps_proxy_create(void);
335 struct rpc_interface *its_proxy_create(void);
336+struct rpc_interface *capsule_update_proxy_create(void);
337
338 #ifdef __cplusplus
339 }
340diff --git a/deployments/se-proxy/se-proxy.cmake b/deployments/se-proxy/se-proxy.cmake
341index f647190d9559..e35b0d0f610d 100644
342--- a/deployments/se-proxy/se-proxy.cmake
343+++ b/deployments/se-proxy/se-proxy.cmake
344@@ -51,6 +51,7 @@ add_components(TARGET "se-proxy"
345 "components/service/attestation/provider/serializer/packed-c"
346 "components/service/attestation/reporter/psa_ipc"
347 "components/service/attestation/client/psa_ipc"
348+ "components/service/capsule_update/provider"
349 "components/rpc/openamp/caller/sp"
350
351 # Stub service provider backends
352diff --git a/deployments/se-proxy/se_proxy_interfaces.h b/deployments/se-proxy/se_proxy_interfaces.h
353index 48908f846990..3d4a7c204785 100644
354--- a/deployments/se-proxy/se_proxy_interfaces.h
355+++ b/deployments/se-proxy/se_proxy_interfaces.h
356@@ -8,9 +8,10 @@
357 #define SE_PROXY_INTERFACES_H
358
359 /* Interface IDs from service endpoints available from an se-proxy deployment */
360-#define SE_PROXY_INTERFACE_ID_ITS (0)
361-#define SE_PROXY_INTERFACE_ID_PS (1)
362-#define SE_PROXY_INTERFACE_ID_CRYPTO (2)
363-#define SE_PROXY_INTERFACE_ID_ATTEST (3)
364+#define SE_PROXY_INTERFACE_ID_ITS (0)
365+#define SE_PROXY_INTERFACE_ID_PS (1)
366+#define SE_PROXY_INTERFACE_ID_CRYPTO (2)
367+#define SE_PROXY_INTERFACE_ID_ATTEST (3)
368+#define SE_PROXY_INTERFACE_ID_CAPSULE_UPDATE (4)
369
370 #endif /* SE_PROXY_INTERFACES_H */
371diff --git a/protocols/service/capsule_update/capsule_update_proto.h b/protocols/service/capsule_update/capsule_update_proto.h
372new file mode 100644
373index 000000000000..8f326cd387fb
374--- /dev/null
375+++ b/protocols/service/capsule_update/capsule_update_proto.h
376@@ -0,0 +1,13 @@
377+/*
378+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
379+ *
380+ * SPDX-License-Identifier: BSD-3-Clause
381+ */
382+
383+#ifndef CAPSULE_UPDATE_PROTO_H
384+#define CAPSULE_UPDATE_PROTO_H
385+
386+#include <protocols/service/capsule_update/opcodes.h>
387+#include <protocols/service/capsule_update/parameters.h>
388+
389+#endif /* CAPSULE_UPDATE_PROTO_H */
390diff --git a/protocols/service/capsule_update/opcodes.h b/protocols/service/capsule_update/opcodes.h
391new file mode 100644
392index 000000000000..8185a0902378
393--- /dev/null
394+++ b/protocols/service/capsule_update/opcodes.h
395@@ -0,0 +1,17 @@
396+/*
397+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
398+ *
399+ * SPDX-License-Identifier: BSD-3-Clause
400+ */
401+
402+#ifndef CAPSULE_UPDATE_OPCODES_H
403+#define CAPSULE_UPDATE_OPCODES_H
404+
405+/**
406+ * Opcode definitions for the capsule update service
407+ */
408+
409+#define CAPSULE_UPDATE_OPCODE_UPDATE_CAPSULE 1
410+#define CAPSULE_UPDATE_OPCODE_BOOT_CONFIRMED 2
411+
412+#endif /* CAPSULE_UPDATE_OPCODES_H */
413diff --git a/protocols/service/capsule_update/parameters.h b/protocols/service/capsule_update/parameters.h
414new file mode 100644
415index 000000000000..285d924186be
416--- /dev/null
417+++ b/protocols/service/capsule_update/parameters.h
418@@ -0,0 +1,15 @@
419+/*
420+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
421+ *
422+ * SPDX-License-Identifier: BSD-3-Clause
423+ */
424+
425+#ifndef CAPSULE_UPDATE_PARAMETERS_H
426+#define CAPSULE_UPDATE_PARAMETERS_H
427+
428+/**
429+ * Operation parameter definitions for the capsule update service access protocol.
430+ */
431+
432+
433+#endif /* CAPSULE_UPDATE_PARAMETERS_H */
434--
4352.38.0
436