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" |
| 17 | #include "tfm_sst_svc_handler.h" |
| 18 | #include "tfm_ns_lock.h" |
| 19 | #ifdef CORE_TEST_SERVICES |
| 20 | #include "test/suites/core/non_secure/svc_core_test_ns.h" |
| 21 | #endif |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame^] | 22 | #ifdef SST_TEST_SERVICES |
| 23 | #include "test/test_services/tfm_sst_test_service/sst_test_service_svc.h" |
| 24 | #endif |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 25 | #ifdef TEST_FRAMEWORK_NS |
| 26 | #include "test/framework/integ_test.h" |
| 27 | #endif |
| 28 | |
| 29 | #include "Driver_USART.h" |
| 30 | |
| 31 | /* For UART the CMSIS driver is used */ |
| 32 | extern ARM_DRIVER_USART Driver_USART0; |
| 33 | |
| 34 | /** |
| 35 | * \brief Modified table template for user defined SVC functions |
| 36 | * |
| 37 | * \details RTX has a weak definition of osRtxUserSVC, which |
| 38 | * is overridden here |
| 39 | */ |
| 40 | extern void * const osRtxUserSVC[1+USER_SVC_COUNT]; |
| 41 | void * const osRtxUserSVC[1+USER_SVC_COUNT] = { |
| 42 | (void *)USER_SVC_COUNT, |
| 43 | |
| 44 | /* SERVICES_TEST_NS */ |
| 45 | (void *)tfm_sst_svc_get_handle, |
| 46 | (void *)tfm_sst_svc_create, |
| 47 | (void *)tfm_sst_svc_get_attributes, |
| 48 | (void *)tfm_sst_svc_read, |
| 49 | (void *)tfm_sst_svc_write, |
| 50 | (void *)tfm_sst_svc_delete, |
| 51 | |
| 52 | #if defined(CORE_TEST_INTERACTIVE) |
| 53 | (void *)svc_secure_decrement_ns_lock_1, |
| 54 | (void *)svc_secure_decrement_ns_lock_2, |
| 55 | #endif /* CORE_TEST_INTERACTIVE */ |
| 56 | |
| 57 | #if defined(CORE_TEST_SERVICES) |
| 58 | (void *)svc_tfm_core_test, |
| 59 | (void *)svc_tfm_core_test_multiple_calls, |
| 60 | #endif /* CORE_TEST_SERVICES */ |
| 61 | |
Jamie Fox | 5592db0 | 2017-12-18 16:48:29 +0000 | [diff] [blame^] | 62 | #if defined(SST_TEST_SERVICES) |
| 63 | (void *)sst_test_service_svc_setup, |
| 64 | (void *)sst_test_service_svc_dummy_encrypt, |
| 65 | (void *)sst_test_service_svc_dummy_decrypt, |
| 66 | (void *)sst_test_service_svc_clean, |
| 67 | #endif /* SST_TEST_SERVICES */ |
| 68 | |
Antonio de Angelis | a54ed7e | 2017-11-29 13:37:58 +0000 | [diff] [blame] | 69 | //(void *)user_function1, |
| 70 | // ... |
| 71 | }; |
| 72 | |
| 73 | /* Struct FILE is implemented in stdio.h. Used to redirect printf to UART0 */ |
| 74 | FILE __stdout; |
| 75 | /* Redirects armclang printf to UART */ |
| 76 | int fputc(int ch, FILE *f) { |
| 77 | /* Send byte to UART0 */ |
| 78 | (void)Driver_USART0.Send((const unsigned char *)&ch, 1); |
| 79 | /* Return character written */ |
| 80 | return ch; |
| 81 | } |
| 82 | /* redirects gcc printf to uart */ |
| 83 | int _write(int fd, char * str, int len) |
| 84 | { |
| 85 | (void)Driver_USART0.Send(str, len); |
| 86 | |
| 87 | return len; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * \brief List of RTOS thread attributes |
| 92 | */ |
| 93 | #ifdef TEST_FRAMEWORK_NS |
| 94 | static const osThreadAttr_t tserv_test = { |
| 95 | .name = "test_app", |
| 96 | .stack_size = 1024U |
| 97 | }; |
| 98 | #endif |
| 99 | |
| 100 | /** |
| 101 | * \brief Static globals to hold RTOS related quantities, |
| 102 | * main thread |
| 103 | */ |
| 104 | static osStatus_t status; |
| 105 | static osThreadId_t thread_id; |
| 106 | |
| 107 | /** |
| 108 | * \brief main() function |
| 109 | */ |
| 110 | __attribute__((noreturn)) |
| 111 | int main(void) |
| 112 | { |
| 113 | (void)Driver_USART0.Initialize(NULL); /* Use UART0 as stdout */ |
| 114 | Driver_USART0.Control(ARM_USART_MODE_ASYNCHRONOUS, 115200); |
| 115 | |
| 116 | status = osKernelInitialize(); |
| 117 | |
| 118 | /* Initialize the TFM NS lock */ |
| 119 | tfm_ns_lock_init(); |
| 120 | |
| 121 | #ifdef TEST_FRAMEWORK_NS |
| 122 | thread_id = osThreadNew(test_app, NULL, &tserv_test); |
| 123 | #else |
| 124 | UNUSED_VARIABLE(thread_id); |
| 125 | #endif |
| 126 | |
| 127 | status = osKernelStart(); |
| 128 | |
| 129 | /* Reached only in case of error */ |
| 130 | for (;;) { |
| 131 | } |
| 132 | } |