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 18 static const struct embedded_ts *find_early_ta(const TEE_UUID *uuid) 19 { 20 const struct embedded_ts *ta = NULL; 21 22 for_each_early_ta(ta) 23 if (!memcmp(&ta->uuid, uuid, sizeof(*uuid))) 24 return ta; 25 26 return NULL; 27 } 28 29 static TEE_Result early_ta_open(const TEE_UUID *uuid, 30 struct ts_store_handle **h) 31 { 32 return emb_ts_open(uuid, h, find_early_ta); 33 } 34 35 REGISTER_TA_STORE(2) = { 36 .description = "early TA", 37 .open = early_ta_open, 38 .get_size = emb_ts_get_size, 39 .get_tag = emb_ts_get_tag, 40 .read = emb_ts_read, 41 .close = emb_ts_close, 42 }; 43 44 static TEE_Result early_ta_init(void) 45 { 46 const struct embedded_ts *ta = NULL; 47 char __maybe_unused msg[60] = { '\0', }; 48 49 for_each_early_ta(ta) { 50 if (ta->uncompressed_size) 51 snprintf(msg, sizeof(msg), 52 " (compressed, uncompressed %u)", 53 ta->uncompressed_size); 54 else 55 msg[0] = '\0'; 56 DMSG("Early TA %pUl size %u%s", (void *)&ta->uuid, ta->size, 57 msg); 58 } 59 60 return TEE_SUCCESS; 61 } 62 63 service_init(early_ta_init); 64