Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 1 | /* |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, Arm Limited. All rights reserved. |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <string.h> |
| 10 | #include <stdbool.h> |
| 11 | |
| 12 | #include "cmsis.h" |
| 13 | #include "tfm_api.h" |
| 14 | #include "cmsis_os2.h" |
| 15 | #include "tfm_integ_test.h" |
| 16 | #include "tfm_ns_svc.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 17 | #include "tfm_ns_lock.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 18 | #ifdef TEST_FRAMEWORK_NS |
| 19 | #include "test/framework/integ_test.h" |
| 20 | #endif |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 21 | #ifdef TFM_PARTITION_TEST_SECURE_SERVICES |
| 22 | #include \ |
| 23 | "test/test_services/tfm_secure_client_service/tfm_secure_client_service_svc.h" |
| 24 | #endif |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 25 | |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame^] | 26 | #include "target_cfg.h" |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 27 | #include "Driver_USART.h" |
| 28 | |
| 29 | /* For UART the CMSIS driver is used */ |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame^] | 30 | extern ARM_DRIVER_USART NS_DRIVER_STDIO; |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * \brief Modified table template for user defined SVC functions |
| 34 | * |
| 35 | * \details RTX has a weak definition of osRtxUserSVC, which |
| 36 | * is overridden here |
| 37 | */ |
| 38 | extern void * const osRtxUserSVC[1+USER_SVC_COUNT]; |
| 39 | void * const osRtxUserSVC[1+USER_SVC_COUNT] = { |
| 40 | (void *)USER_SVC_COUNT, |
| 41 | |
Antonio de Angelis | d9cd66e | 2018-03-27 11:19:59 +0100 | [diff] [blame] | 42 | #define X(SVC_ENUM, SVC_HANDLER) (void*)SVC_HANDLER, |
| 43 | /* SVC API for Services */ |
| 44 | LIST_SVC_DISPATCHERS |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 45 | |
| 46 | #if defined(CORE_TEST_INTERACTIVE) |
Antonio de Angelis | d9cd66e | 2018-03-27 11:19:59 +0100 | [diff] [blame] | 47 | LIST_SVC_CORE_TEST_INTERACTIVE |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 48 | #endif /* CORE_TEST_INTERACTIVE */ |
| 49 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 50 | #if defined(TFM_PARTITION_TEST_CORE) |
Antonio de Angelis | d9cd66e | 2018-03-27 11:19:59 +0100 | [diff] [blame] | 51 | LIST_SVC_TFM_PARTITION_TEST_CORE |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 52 | #endif /* TFM_PARTITION_TEST_CORE */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 53 | |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 54 | #if defined(TFM_PARTITION_TEST_SST) |
Antonio de Angelis | d9cd66e | 2018-03-27 11:19:59 +0100 | [diff] [blame] | 55 | LIST_SVC_TFM_PARTITION_TEST_SST |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 56 | #endif /* TFM_PARTITION_TEST_SST */ |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame] | 57 | |
Ben Davis | 6d7256b | 2018-04-18 14:16:53 +0100 | [diff] [blame] | 58 | #if defined(TFM_PARTITION_TEST_SECURE_SERVICES) |
| 59 | LIST_SVC_TFM_PARTITION_TEST_SECURE_SERVICES |
| 60 | #endif /* TFM_PARTITION_TEST_SECURE_SERVICES */ |
| 61 | |
Antonio de Angelis | d9cd66e | 2018-03-27 11:19:59 +0100 | [diff] [blame] | 62 | #undef X |
| 63 | |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 64 | //(void *)user_function1, |
| 65 | // ... |
| 66 | }; |
| 67 | |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame^] | 68 | /* Struct FILE is implemented in stdio.h. Used to redirect printf to |
| 69 | * NS_DRIVER_STDIO |
| 70 | */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 71 | FILE __stdout; |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame^] | 72 | /* Redirects armclang printf to NS_DRIVER_STDIO */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 73 | int fputc(int ch, FILE *f) { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame^] | 74 | /* Send byte to NS_DRIVER_STDIO */ |
| 75 | (void)NS_DRIVER_STDIO.Send((const unsigned char *)&ch, 1); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 76 | /* Return character written */ |
| 77 | return ch; |
| 78 | } |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame^] | 79 | /* redirects gcc printf to NS_DRIVER_STDIO */ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 80 | int _write(int fd, char * str, int len) |
| 81 | { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame^] | 82 | (void)NS_DRIVER_STDIO.Send(str, len); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 83 | |
| 84 | return len; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * \brief List of RTOS thread attributes |
| 89 | */ |
| 90 | #ifdef TEST_FRAMEWORK_NS |
| 91 | static const osThreadAttr_t tserv_test = { |
| 92 | .name = "test_app", |
| 93 | .stack_size = 1024U |
| 94 | }; |
| 95 | #endif |
| 96 | |
| 97 | /** |
| 98 | * \brief Static globals to hold RTOS related quantities, |
| 99 | * main thread |
| 100 | */ |
| 101 | static osStatus_t status; |
| 102 | static osThreadId_t thread_id; |
| 103 | |
| 104 | /** |
| 105 | * \brief main() function |
| 106 | */ |
Mate Toth-Pal | 31a2d96 | 2018-03-09 13:14:44 +0100 | [diff] [blame] | 107 | #ifndef __GNUC__ |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 108 | __attribute__((noreturn)) |
Mate Toth-Pal | 31a2d96 | 2018-03-09 13:14:44 +0100 | [diff] [blame] | 109 | #endif |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 110 | int main(void) |
| 111 | { |
Gabor Kertesz | eb953f5 | 2018-07-17 13:36:28 +0200 | [diff] [blame^] | 112 | (void)NS_DRIVER_STDIO.Initialize(NULL); |
| 113 | NS_DRIVER_STDIO.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200); |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 114 | |
| 115 | status = osKernelInitialize(); |
| 116 | |
| 117 | /* Initialize the TFM NS lock */ |
| 118 | tfm_ns_lock_init(); |
| 119 | |
| 120 | #ifdef TEST_FRAMEWORK_NS |
| 121 | thread_id = osThreadNew(test_app, NULL, &tserv_test); |
| 122 | #else |
| 123 | UNUSED_VARIABLE(thread_id); |
| 124 | #endif |
| 125 | |
| 126 | status = osKernelStart(); |
| 127 | |
| 128 | /* Reached only in case of error */ |
| 129 | for (;;) { |
| 130 | } |
| 131 | } |