Skip to content

Commit b31aa03

Browse files
Ron EldorRon Eldor
authored andcommitted
Add the platfrom setup \ terminate support
Add support for Platfrom setup and termination for Cryptocell on Nrf52840
1 parent 340f22e commit b31aa03

File tree

6 files changed

+220
-23
lines changed

6 files changed

+220
-23
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* cc_platform.h
3+
*
4+
* Copyright (C) 2018, ARM Limited, All Rights Reserved
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
8+
* not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
#ifndef __CC_PLATFORM_H_
21+
#define __CC_PLATFORM_H_
22+
/**
23+
* \brief The CC platform context structure.
24+
*
25+
* \note This structure may be used to assist platform-specific
26+
* setup or teardown operations.
27+
*/
28+
typedef struct {
29+
char dummy; /**< Placeholder member, as empty structs are not portable. */
30+
}
31+
cc_platform_ctx;
32+
33+
#endif /* __CC_PLATFORM_H_ */
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* cc_platform_nrf52840.c
3+
*
4+
* Copyright (C) 2018, ARM Limited, All Rights Reserved
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
8+
* not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#include "platform_alt.h"
22+
#include "nrf52840.h"
23+
24+
int cc_platform_setup( cc_platform_ctx *ctx )
25+
{
26+
NRF_CRYPTOCELL->ENABLE = 1;
27+
return ( 0 );
28+
}
29+
30+
void cc_platform_terminate( cc_platform_ctx *ctx )
31+
{
32+
NRF_CRYPTOCELL->ENABLE = 0;
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* mbedtls_device.h
3+
*
4+
* Copyright (C) 2018, ARM Limited, All Rights Reserved
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
8+
* not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#ifndef __MBEDTLS_DEVICE__
22+
#define __MBEDTLS_DEVICE__
23+
24+
#define MBEDTLS_AES_ALT
25+
#define MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT
26+
27+
#endif //__MBEDTLS_DEVICE__
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* platform_alt.c
3+
*
4+
* Copyright (C) 2018, ARM Limited, All Rights Reserved
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
8+
* not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#include "mbedtls/platform.h"
22+
#if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
23+
#include "sns_silib.h"
24+
25+
/* once https://github.com/ARMmbed/mbedtls/issues/1200 will be supported,
26+
* rndState should be part of mbedtls_platform_context
27+
* Until then, we should keep it global and extern */
28+
29+
CRYS_RND_State_t rndState = { { 0 } } ;
30+
CRYS_RND_WorkBuff_t rndWorkBuff = { { 0 } } ;
31+
32+
33+
int mbedtls_platform_setup( mbedtls_platform_context *ctx )
34+
{
35+
int ret = 0;
36+
if( ctx == NULL )
37+
return ( -1 );
38+
39+
/* call platform specific code to setup CC driver*/
40+
if( ( ret = cc_platform_setup( &ctx->platform_impl_ctx ) ) != 0 )
41+
return ( ret );
42+
43+
if( SaSi_LibInit( &rndState, &rndWorkBuff ) != 0 )
44+
return ( -1 );
45+
return ( 0 );
46+
}
47+
48+
void mbedtls_platform_teardown( mbedtls_platform_context *ctx )
49+
{
50+
if( ctx == NULL )
51+
return;
52+
53+
SaSi_LibFini( &rndState );
54+
cc_platform_terminate( &ctx->platform_impl_ctx );
55+
}
56+
57+
#endif /* MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT*/
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* platform_alt.h
3+
*
4+
* Copyright (C) 2018, ARM Limited, All Rights Reserved
5+
* SPDX-License-Identifier: Apache-2.0
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
8+
* not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#ifndef __PLATFORM_ALT__
22+
#define __PLATFORM_ALT__
23+
#include "cc_platform.h"
24+
#include "crys_rnd.h"
25+
26+
/**
27+
* \brief The platform context structure.
28+
*
29+
* \note This structure may be used to assist platform-specific
30+
* setup or teardown operations.
31+
*/
32+
typedef struct {
33+
cc_platform_ctx platform_impl_ctx; /** A context holding all the partner's platform specific context */
34+
/*
35+
* Add CRYS_RND_State_t rndState; when https://github.com/ARMmbed/mbedtls/issues/1200 is supported
36+
* */
37+
}
38+
mbedtls_platform_context;
39+
40+
41+
/**
42+
* \brief This function performs any partner platform initialization operations,
43+
* needed top enable CryptoCell.
44+
*
45+
* \param ctx The platform specific context.
46+
*
47+
* \return \c 0 on success.
48+
*
49+
* \note This function is intended to allow platform-specific initialization for CryptoCell,
50+
* and is called before initializing the CC library(SaSi_LibInit). Its
51+
* implementation is platform-specific, and its implementation MUST be provided.
52+
*
53+
*/
54+
int cc_platform_setup( cc_platform_ctx *ctx );
55+
56+
/**
57+
* \brief This function performs any partner platform teardown operations, to disable CryptoCell.
58+
*
59+
* \param ctx The platform specific context.
60+
*
61+
* \note This function is called after terminating CC library(SaSi_LibFini)
62+
* and intended to free any resource used for CryptoCell by the platform.
63+
* Its implementation is platform-specific,and its implementation MUST be provided.
64+
*
65+
*/
66+
void cc_platform_terminate( cc_platform_ctx *ctx );
67+
68+
#endif /* __PLATFORM_ALT__ */
69+

rtos/TARGET_CORTEX/mbed_boot.c

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@
172172
#if defined(__IAR_SYSTEMS_ICC__ ) && (__VER__ >= 8000000)
173173
#include <DLib_Threads.h>
174174
#endif
175-
#if DEVICE_CRYPTOCELL
176-
#include "sns_silib.h"
177-
#endif
175+
178176
/* Heap limits - only used if set */
179177
extern unsigned char *mbed_heap_start;
180178
extern uint32_t mbed_heap_size;
@@ -332,16 +330,6 @@ void mbed_start_main(void)
332330
osKernelStart();
333331
}
334332

335-
#if DEVICE_CRYPTOCELL
336-
#if defined(TOOLCHAIN_GCC)
337-
CRYS_RND_State_t rndState = {0};
338-
CRYS_RND_WorkBuff_t rndWorkBuff = {0};
339-
#else
340-
CRYS_RND_State_t rndState;
341-
CRYS_RND_WorkBuff_t rndWorkBuff;
342-
#endif
343-
#endif
344-
345333
/******************** Toolchain specific code ********************/
346334

347335
#if defined (__CC_ARM) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
@@ -430,11 +418,6 @@ void __rt_entry (void) {
430418
/* Copy the vector table to RAM only if uVisor is not in use. */
431419
#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
432420
mbed_cpy_nvic();
433-
#endif
434-
#if DEVICE_CRYPTOCELL
435-
if (SaSi_LibInit(&rndState,&rndWorkBuff)) {
436-
mbed_die();
437-
}
438421
#endif
439422
mbed_sdk_init();
440423
_platform_post_stackheap_init();
@@ -580,11 +563,6 @@ void software_init_hook(void)
580563
/* Copy the vector table to RAM only if uVisor is not in use. */
581564
#if !(defined(FEATURE_UVISOR) && defined(TARGET_UVISOR_SUPPORTED))
582565
mbed_cpy_nvic();
583-
#endif
584-
#if DEVICE_CRYPTOCELL
585-
if (SaSi_LibInit(&rndState,&rndWorkBuff)) {
586-
mbed_die();
587-
}
588566
#endif
589567
mbed_sdk_init();
590568
osKernelInitialize();

0 commit comments

Comments
 (0)