]> begriffs open source - cmsis/blob - CMSIS/CoreValidation/Layer/App/Bootloader_Cortex-M/bootloader.c
Possible bugs in MMU_MemorySection(), MMU_MemoryPage() (#219)
[cmsis] / CMSIS / CoreValidation / Layer / App / Bootloader_Cortex-M / bootloader.c
1 /*
2  * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ----------------------------------------------------------------------
19  *
20  * $Date:        15. October 2016
21  * $Revision:    1.1.0
22  *
23  * Project:      TrustZone for ARMv8-M
24  * Title:        Code template for secure main function
25  *
26  *---------------------------------------------------------------------------*/
27  
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 /* Use CMSE intrinsics */
32 #include <arm_cmse.h>
33
34 #include "RTE_Components.h"
35 #include CMSIS_device_header
36  
37 /* TZ_START_NS: Start address of non-secure application */
38 #ifndef TZ_START_NS
39 #define TZ_START_NS (0x200000U)
40 #endif
41
42 #if 1
43 /* Dummy Non-secure callable (entry) function */
44 __attribute__((cmse_nonsecure_entry)) int validationDummy(int x) { 
45   return x; 
46 }
47 #endif
48  
49 /* typedef for non-secure callback functions */
50 typedef void (*funcptr_void) (void) __attribute__((cmse_nonsecure_call));
51
52 /* Secure main() */
53 int main(void) {
54   funcptr_void NonSecure_ResetHandler;
55  
56   /* Add user setup code for secure part here*/
57  
58   /* Set non-secure main stack (MSP_NS) */
59   __TZ_set_MSP_NS(*((uint32_t *)(TZ_START_NS)));
60
61   /* Set Non-Secure state for Interrupt 0
62     (used in Non-Secure TC_CoreInstr_LoadStoreExclusive Test) */
63   NVIC->ITNS[0] |= 1U;
64  
65   /* Get non-secure reset handler */
66   NonSecure_ResetHandler = (funcptr_void)(*((uint32_t *)((TZ_START_NS) + 4U)));
67  
68   /* Start non-secure state software application */
69   NonSecure_ResetHandler();
70  
71   /* Non-secure software does not return, this code is not executed */
72   while (1) {
73     __NOP();
74   }
75 }
76
77 #if defined(__CORTEX_M)
78 __NO_RETURN
79 extern void HardFault_Handler(void);
80 void HardFault_Handler(void) {
81   printf("Bootloader HardFault!\n");
82   #ifdef __MICROLIB
83   for(;;) {}
84   #else
85   exit(1);
86   #endif
87 }
88 #endif