2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /* FreeRTOS includes. */
\r
29 #include "secure_port_macros.h"
\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
36 #include "tzm_config.h"
\r
37 #include "pin_mux.h"
\r
38 #include "clock_config.h"
\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
46 /* Start address of non-secure application. */
\r
47 #define mainNONSECURE_APP_START_ADDRESS ( 0x00010000UL )
\r
49 /* typedef for non-secure Reset Handler. */
\r
50 typedef void ( *NonSecureResetHandler_t ) ( void ) __attribute__( ( cmse_nonsecure_call ) );
\r
51 /*-----------------------------------------------------------*/
\r
54 * @brief Boots into the non-secure code.
\r
56 * @param[in] ulNonSecureStartAddress Start address of the non-secure application.
\r
58 static void prvBootNonSecure( uint32_t ulNonSecureStartAddress );
\r
61 * @brief Application-specific implementation of the SystemInitHook() weak
\r
64 void SystemInitHook( void );
\r
65 /*-----------------------------------------------------------*/
\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
71 /* Secure main(). */
\r
74 PRINTF( "Booting Secure World.\r\n" );
\r
76 /* Attach main clock divide to FLEXCOMM0 (debug console). */
\r
77 CLOCK_AttachClk( BOARD_DEBUG_UART_CLK_ATTACH );
\r
79 /* Init board hardware. */
\r
81 BOARD_BootClockFROHF96M();
\r
82 BOARD_InitDebugConsole();
\r
84 /* Boot the non-secure code. */
\r
85 PRINTF( "Booting Non-Secure World.\r\n" );
\r
86 prvBootNonSecure( mainNONSECURE_APP_START_ADDRESS );
\r
88 /* Non-secure software does not return, this code is not executed. */
\r
91 /* Should not reach here. */
\r
94 /*-----------------------------------------------------------*/
\r
96 static void prvBootNonSecure( uint32_t ulNonSecureStartAddress )
\r
98 NonSecureResetHandler_t pxNonSecureResetHandler;
\r
100 /* Setup the non-secure vector table. */
\r
101 SCB_NS->VTOR = ulNonSecureStartAddress;
\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
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
113 /* Start non-secure state software application by jumping to the non-secure
\r
114 * Reset Handler. */
\r
115 pxNonSecureResetHandler();
\r
117 /*-----------------------------------------------------------*/
\r
119 void SystemInitHook( void )
\r
121 /* Set CP10 and CP11 full access from Non-Secure code. */
\r
122 SCB_NS->CPACR |= ( ( 3UL << 10 * 2 ) | ( 3UL << 11 * 2 ) );
\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
128 BOARD_InitTrustZone();
\r
130 /*-----------------------------------------------------------*/
\r