1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (C) Foundries Ltd. 2020 - All Rights Reserved 4 * Author: Jorge Ramirez <jorge@foundries.io> 5 */ 6 7 #include <config.h> 8 #include <initcall.h> 9 #include <se050.h> 10 11 sss_se05x_key_store_t *se050_kstore; 12 sss_se05x_session_t *se050_session; 13 struct sss_se05x_ctx se050_ctx; 14 15 TEE_Result se050_core_early_init(struct se050_scp_key *keys) 16 { 17 sss_status_t status = kStatus_SSS_Success; 18 19 status = se050_session_open(&se050_ctx, keys); 20 if (status != kStatus_SSS_Success) 21 return TEE_ERROR_GENERIC; 22 23 if (IS_ENABLED(CFG_CORE_SE05X_INIT_NVM)) { 24 status = se050_factory_reset(&se050_ctx.session.s_ctx); 25 if (status != kStatus_SSS_Success) 26 return TEE_ERROR_GENERIC; 27 } 28 29 if (se050_ctx.session.subsystem == kType_SSS_SubSystem_NONE) 30 return TEE_ERROR_GENERIC; 31 32 status = se050_key_store_and_object_init(&se050_ctx); 33 if (status != kStatus_SSS_Success) 34 return TEE_ERROR_GENERIC; 35 36 se050_session = (sss_se05x_session_t *)((void *)&se050_ctx.session); 37 se050_kstore = (sss_se05x_key_store_t *)((void *)&se050_ctx.ks); 38 39 return TEE_SUCCESS; 40 } 41 42 static TEE_Result display_info(void) 43 { 44 se050_display_board_info(se050_session); 45 /* the session must be closed after accessing board information */ 46 sss_se05x_session_close(se050_session); 47 48 return se050_core_early_init(NULL); 49 } 50 51 static TEE_Result enable_scp03(void) 52 { 53 if (se050_enable_scp03(se050_session) != kStatus_SSS_Success) 54 return TEE_ERROR_GENERIC; 55 56 return TEE_SUCCESS; 57 } 58 59 static TEE_Result se050_early_init(void) 60 { 61 TEE_Result ret = TEE_SUCCESS; 62 63 ret = se050_core_early_init(NULL); 64 65 if (!ret && IS_ENABLED(CFG_CORE_SE05X_DISPLAY_INFO)) 66 ret = display_info(); 67 68 if (!ret && IS_ENABLED(CFG_CORE_SE05X_SCP03_EARLY)) 69 return enable_scp03(); 70 71 return ret; 72 } 73 74 driver_init(se050_early_init); 75