mimxrt1180_crypto.c
Go to the documentation of this file.
1 /**
2  * @file mimxrt1180_crypto.c
3  * @brief i.MX RT1180 hardware cryptographic accelerator (ELE)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneCRYPTO Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.5.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL CRYPTO_TRACE_LEVEL
33 
34 //Dependencies
35 #include "fsl_device_registers.h"
36 #include "ele_crypto.h"
37 #include "ele_fw.h"
38 #include "core/crypto.h"
41 #include "debug.h"
42 
43 //Global variables
45 
46 
47 /**
48  * @brief Initialize hardware cryptographic accelerator
49  * @return Error code
50  **/
51 
53 {
54  error_t error;
55  uint32_t version;
56  status_t status;
57 
58  //Initialize status code
59  error = NO_ERROR;
60 
61  //Create a mutex to prevent simultaneous access to the hardware
62  //cryptographic accelerator
64  {
65  //Failed to create mutex
66  error = ERROR_OUT_OF_RESOURCES;
67  }
68 
69  //Check status code
70  if(!error)
71  {
72  //Debug message
73  TRACE_INFO("Loading ELE firmware...\r\n");
74 
75  //Load ELE firmware
76  status = ELE_LoadFw(MU_APPS_S3MUA, ele_fw);
77 
78  //Check status code
79  if(status == kStatus_Success)
80  {
81  //Retrieve ELE firmware version
82  status = ELE_GetFwVersion(MU_APPS_S3MUA, &version);
83  }
84 
85  //Check status code
86  if(status == kStatus_Success)
87  {
88  //Dump firmware version
89  TRACE_INFO("ELE firmware version: 0x%08X\r\n", version);
90 
91  //Successful initialization
92  error = NO_ERROR;
93  }
94  else
95  {
96  //Report an error
97  error = ERROR_FAILURE;
98  }
99  }
100 
101 #if (MIMXRT1180_CRYPTO_TRNG_SUPPORT == ENABLED)
102  //Check status code
103  if(!error)
104  {
105  //Initialize TRNG module
106  error = trngInit();
107  }
108 #endif
109 
110  //Return status code
111  return error;
112 }
bool_t osCreateMutex(OsMutex *mutex)
Create a mutex object.
@ ERROR_OUT_OF_RESOURCES
Definition: error.h:64
uint8_t version
Definition: coap_common.h:177
error_t trngInit(void)
TRNG module initialization.
error_t
Error codes.
Definition: error.h:43
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
i.MX RT1180 true random number generator
General definitions for cryptographic algorithms.
OsMutex mimxrt1180CryptoMutex
#define TRACE_INFO(...)
Definition: debug.h:105
Mutex object.
i.MX RT1180 hardware cryptographic accelerator (ELE)
error_t mimxrt1180CryptoInit(void)
Initialize hardware cryptographic accelerator.
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.