xref: /optee_os/core/kernel/early_ta.c (revision 1bfc10827ef2ad1accf4f2c27fd12b9d70330f56)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (c) 2017, Linaro Limited
4  * Copyright (c) 2020, Arm Limited.
5  */
6 #include <crypto/crypto.h>
7 #include <initcall.h>
8 #include <kernel/early_ta.h>
9 #include <kernel/embedded_ts.h>
10 #include <kernel/ts_store.h>
11 #include <kernel/user_ta.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <trace.h>
15 #include <utee_defines.h>
16 #include <util.h>
17 #include <zlib.h>
18 
19 static const struct embedded_ts *find_early_ta(const TEE_UUID *uuid)
20 {
21 	const struct embedded_ts *ta = NULL;
22 
23 	for_each_early_ta(ta)
24 		if (!memcmp(&ta->uuid, uuid, sizeof(*uuid)))
25 			return ta;
26 
27 	return NULL;
28 }
29 
30 static TEE_Result early_ta_open(const TEE_UUID *uuid,
31 				struct ts_store_handle **h)
32 {
33 	return emb_ts_open(uuid, h, find_early_ta);
34 }
35 
36 REGISTER_TA_STORE(2) = {
37 	.description = "early TA",
38 	.open = early_ta_open,
39 	.get_size = emb_ts_get_size,
40 	.get_tag = emb_ts_get_tag,
41 	.read = emb_ts_read,
42 	.close = emb_ts_close,
43 };
44 
45 static TEE_Result early_ta_init(void)
46 {
47 	const struct embedded_ts *ta = NULL;
48 	char __maybe_unused msg[60] = { '\0', };
49 
50 	for_each_early_ta(ta) {
51 		if (ta->uncompressed_size)
52 			snprintf(msg, sizeof(msg),
53 				 " (compressed, uncompressed %u)",
54 				 ta->uncompressed_size);
55 		else
56 			msg[0] = '\0';
57 		DMSG("Early TA %pUl size %u%s", (void *)&ta->uuid, ta->size,
58 		     msg);
59 	}
60 
61 	return TEE_SUCCESS;
62 }
63 
64 service_init(early_ta_init);
65