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