]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso/Projects/MCUXpresso/Secure/main_s.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTEX_MPU_M33F_NXP_LPC55S69_MCUXpresso / Projects / MCUXpresso / Secure / main_s.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /* FreeRTOS includes. */\r
29 #include "secure_port_macros.h"\r
30 \r
31 /* Device includes. */\r
32 #include "fsl_device_registers.h"\r
33 #include "fsl_debug_console.h"\r
34 #include "arm_cmse.h"\r
35 #include "board.h"\r
36 #include "tzm_config.h"\r
37 #include "pin_mux.h"\r
38 #include "clock_config.h"\r
39 \r
40 #if ( __ARM_FEATURE_CMSE & 1 ) == 0\r
41         #error "Need ARMv8-M security extensions"\r
42 #elif ( __ARM_FEATURE_CMSE & 2 ) == 0\r
43         #error "Compile with --cmse"\r
44 #endif\r
45 \r
46 /* Start address of non-secure application. */\r
47 #define mainNONSECURE_APP_START_ADDRESS         ( 0x00010000UL )\r
48 \r
49 /* typedef for non-secure Reset Handler. */\r
50 typedef void ( *NonSecureResetHandler_t ) ( void ) __attribute__( ( cmse_nonsecure_call ) );\r
51 /*-----------------------------------------------------------*/\r
52 \r
53 /**\r
54  * @brief Boots into the non-secure code.\r
55  *\r
56  * @param[in] ulNonSecureStartAddress Start address of the non-secure application.\r
57  */\r
58 static void prvBootNonSecure( uint32_t ulNonSecureStartAddress );\r
59 \r
60 /**\r
61  * @brief Application-specific implementation of the SystemInitHook() weak\r
62  * function.\r
63  */\r
64 void SystemInitHook( void );\r
65 /*-----------------------------------------------------------*/\r
66 \r
67 /* For instructions on how to build and run this demo, visit the following link:\r
68  * https://www.freertos.org/RTOS-Cortex-M33-LPC55S69-MCUXpresso-GCC.html\r
69  */\r
70 \r
71 /* Secure main(). */\r
72 int main(void)\r
73 {\r
74         PRINTF( "Booting Secure World.\r\n" );\r
75 \r
76         /* Attach main clock divide to FLEXCOMM0 (debug console). */\r
77         CLOCK_AttachClk( BOARD_DEBUG_UART_CLK_ATTACH );\r
78 \r
79         /* Init board hardware. */\r
80         BOARD_InitPins();\r
81         BOARD_BootClockFROHF96M();\r
82         BOARD_InitDebugConsole();\r
83 \r
84         /* Boot the non-secure code. */\r
85         PRINTF( "Booting Non-Secure World.\r\n" );\r
86         prvBootNonSecure( mainNONSECURE_APP_START_ADDRESS );\r
87 \r
88         /* Non-secure software does not return, this code is not executed. */\r
89         for( ; ; )\r
90         {\r
91                 /* Should not reach here. */\r
92         }\r
93 }\r
94 /*-----------------------------------------------------------*/\r
95 \r
96 static void prvBootNonSecure( uint32_t ulNonSecureStartAddress )\r
97 {\r
98         NonSecureResetHandler_t pxNonSecureResetHandler;\r
99 \r
100         /* Setup the non-secure vector table. */\r
101         SCB_NS->VTOR = ulNonSecureStartAddress;\r
102 \r
103         /* Main Stack Pointer value for the non-secure side is the first entry in\r
104          * the non-secure vector table. Read the first entry and assign the same to\r
105          * the non-secure main stack pointer(MSP_NS). */\r
106         secureportSET_MSP_NS( *( ( uint32_t * )( ulNonSecureStartAddress ) ) );\r
107 \r
108         /* Reset Handler for the non-secure side is the second entry in the\r
109          * non-secure vector table. Read the second entry to get the non-secure\r
110          * Reset Handler. */\r
111         pxNonSecureResetHandler = ( NonSecureResetHandler_t )( * ( ( uint32_t * ) ( ( ulNonSecureStartAddress ) + 4U ) ) );\r
112 \r
113         /* Start non-secure state software application by jumping to the non-secure\r
114          * Reset Handler. */\r
115         pxNonSecureResetHandler();\r
116 }\r
117 /*-----------------------------------------------------------*/\r
118 \r
119 void SystemInitHook( void )\r
120 {\r
121         /* Set CP10 and CP11 full access from Non-Secure code. */\r
122         SCB_NS->CPACR |= ( ( 3UL << 10 * 2 ) | ( 3UL << 11 * 2 ) );\r
123 \r
124         /* The TrustZone should be configured as early as possible after RESET.\r
125          * Therefore it is called from SystemInit() during startup. The\r
126          * SystemInitHook() weak function overloading is used for this purpose.\r
127          */\r
128         BOARD_InitTrustZone();\r
129 }\r
130 /*-----------------------------------------------------------*/\r