New TSSI interface.

git-svn-id: https://svn.code.sf.net/p/chibios/svn2/trunk@11609 110e8d01-0319-4d1e-a829-52ad28d1bb01
This commit is contained in:
isiora 2018-03-07 11:46:54 +00:00
parent f33d39c832
commit 19035d3077
5 changed files with 107 additions and 106 deletions

View File

@ -116,7 +116,7 @@ include $(CHIBIOS)/os/common/startup/ARMCAx-TZ/compilers/GCC/mk/startup_sama5d2.
# HAL-OSAL files (optional). # HAL-OSAL files (optional).
include $(CHIBIOS)/os/hal/hal.mk include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/hal/ports/SAMA/SAMA5D2x/platform.mk include $(CHIBIOS)/os/hal/ports/SAMA/SAMA5D2x/platform.mk
include $(CHIBIOS)/os/hal/boards/ATSAMA5D2_XULT/board.mk include $(CHIBIOS)/os/hal/boards/ATSAMA5D2_XULT_SEC/board.mk
include $(CHIBIOS)/os/hal/osal/rt/osal.mk include $(CHIBIOS)/os/hal/osal/rt/osal.mk
# RTOS files (optional). # RTOS files (optional).
include $(CHIBIOS)/os/rt/rt.mk include $(CHIBIOS)/os/rt/rt.mk
@ -140,6 +140,7 @@ CSRC = $(STARTUPSRC) \
$(BOARDSRC) \ $(BOARDSRC) \
$(TESTSRC) \ $(TESTSRC) \
$(CHIBIOS)/os/hal/lib/streams/chprintf.c \ $(CHIBIOS)/os/hal/lib/streams/chprintf.c \
tservices.c \
main.c main.c
# C++ sources that can be compiled in ARM or THUMB mode depending on the global # C++ sources that can be compiled in ARM or THUMB mode depending on the global

View File

@ -49,7 +49,8 @@
* @details Frequency of the system timer that drives the system ticks. This * @details Frequency of the system timer that drives the system ticks. This
* setting also defines the system tick time unit. * setting also defines the system tick time unit.
*/ */
#define CH_CFG_ST_FREQUENCY 1000 //#define CH_CFG_ST_FREQUENCY 1000 /* periodic tick.*/
#define CH_CFG_ST_FREQUENCY (83000000 / 32) /* tick-less.*/
/** /**
* @brief Time intervals data size. * @brief Time intervals data size.
@ -71,7 +72,7 @@
* The value one is not valid, timeouts are rounded up to * The value one is not valid, timeouts are rounded up to
* this value. * this value.
*/ */
#define CH_CFG_ST_TIMEDELTA 0 #define CH_CFG_ST_TIMEDELTA 2
/** @} */ /** @} */

View File

@ -11,7 +11,7 @@
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="Generic TCP/IP"/> <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="Generic TCP/IP"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/> <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="true"/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/> <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value="20100000"/> <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value="27000000"/>
<intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="2331"/> <intAttribute key="org.eclipse.cdt.debug.gdbjtag.core.portNumber" value="2331"/>
<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.runCommands" value=""/> <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.runCommands" value=""/>
<booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="true"/> <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.setPcRegister" value="true"/>

View File

@ -16,10 +16,10 @@
#include "ch.h" #include "ch.h"
#include "hal.h" #include "hal.h"
#include "chtssi.h"
#include "rt_test_root.h" #include "rt_test_root.h"
#include "oslib_test_root.h" #include "oslib_test_root.h"
#include "chprintf.h" #include "chprintf.h"
#include "chsmc.h"
/* /*
* LED blinker thread, times are in milliseconds. * LED blinker thread, times are in milliseconds.
@ -52,51 +52,11 @@ static const SerialConfig sdcfg = {
UART_MR_PAR_NO UART_MR_PAR_NO
}; };
/**
* Dummy trust service thread.
*/
static THD_WORKING_AREA(waDummyTrustedService, 512);
static THD_FUNCTION(DummyTrustedService, arg) {
(void) arg;
msg_t msg;
smc_service_t *svcp;
chRegSetThreadName("DTS");
/* Register the trust service.*/
svcp = smcRegisterMeAsService("DummyTrustedService");
if (svcp == NULL) {
/* Error: the service is already registered
* or memory is exhausted.*/
return;
}
/* Wait and process requests.*/
while (true) {
msg = smcServiceWaitRequest(svcp, MSG_OK);
if (msg == MSG_OK && svcp->svc_datalen > 0) {
*((char *)svcp->svc_data + svcp->svc_datalen - 1) = '\0';
#if 1
chprintf((BaseSequentialStream*)&SD1,
"My non secure 'alter ego' has a request.\r\n");
chprintf((BaseSequentialStream*)&SD1,
"She tells: '");
#endif
chprintf((BaseSequentialStream*)&SD1, (char *)svcp->svc_data);
chprintf((BaseSequentialStream*)&SD1, "'\r\n");
}
chThdSleepMilliseconds(500);
}
}
/* /*
* Application entry point. * Application entry point.
*/ */
int main(void) { int main(void) {
uint32_t n;
/* /*
* System initializations. * System initializations.
* - HAL initialization, this also initializes the configured device drivers * - HAL initialization, this also initializes the configured device drivers
@ -107,7 +67,6 @@ int main(void) {
*/ */
halInit(); halInit();
chSysInit(); chSysInit();
smcInit();
/* /*
* Activates the serial driver 0 using the driver default configuration. * Activates the serial driver 0 using the driver default configuration.
@ -117,72 +76,18 @@ int main(void) {
/* Redirecting UART0 RX on PD2 and UART0 TX on PD3. */ /* Redirecting UART0 RX on PD2 and UART0 TX on PD3. */
palSetGroupMode(PIOD, PAL_PORT_BIT(2) | PAL_PORT_BIT(3), 0U, palSetGroupMode(PIOD, PAL_PORT_BIT(2) | PAL_PORT_BIT(3), 0U,
PAL_SAMA_FUNC_PERIPH_A | PAL_MODE_SECURE); PAL_SAMA_FUNC_PERIPH_A | PAL_MODE_SECURE);
/*
* Creates the blinker thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-64, Thread1, NULL);
/*
* Creates the dummy service thread.
*/
n = 0;
chThdCreateStatic(waDummyTrustedService, sizeof(waDummyTrustedService), NORMALPRIO-32,
DummyTrustedService, (void *)n);
++n;
/* /*
* The DDR memory is divided in 4 regions. Each region is 2MB large. * Creates the blinker thread (and any other ancillary thread).
* The first region is split in two areas, each 1MB large.
* The lower area of this first region is non secure.
* All the rest of the regions space is secured.
*/ */
mtxSetSlaveRegionSize(MATRIX0, H64MX_SLAVE_DDR_PORT0, MATRIX_AREA_SIZE_2M, REGION_0_MSK); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+10, Thread1, NULL);
mtxSetSlaveRegionSize(MATRIX0, H64MX_SLAVE_DDR_PORT1, MATRIX_AREA_SIZE_2M, REGION_0_MSK);
mtxSetSlaveSplitAddr(MATRIX0, H64MX_SLAVE_DDR_PORT0, MATRIX_AREA_SIZE_1M, REGION_0_MSK);
mtxSetSlaveSplitAddr(MATRIX0, H64MX_SLAVE_DDR_PORT0, MATRIX_AREA_SIZE_2M,
REGION_1_MSK | REGION_2_MSK | REGION_3_MSK);
mtxSetSlaveSplitAddr(MATRIX0, H64MX_SLAVE_DDR_PORT1, MATRIX_AREA_SIZE_1M, REGION_0_MSK);
mtxSetSlaveSplitAddr(MATRIX0, H64MX_SLAVE_DDR_PORT1, MATRIX_AREA_SIZE_2M,
REGION_1_MSK | REGION_2_MSK | REGION_3_MSK);
mtxConfigSlaveSec(MATRIX0, H64MX_SLAVE_DDR_PORT0,
mtxRegionLansech(REGION_0, UPPER_AREA_SECURABLE) |
mtxRegionLansech(REGION_1, UPPER_AREA_SECURABLE) |
mtxRegionLansech(REGION_2, UPPER_AREA_SECURABLE) |
mtxRegionLansech(REGION_3, UPPER_AREA_SECURABLE),
mtxRegionRdnsech(REGION_0, NOT_SECURE_READ) |
mtxRegionRdnsech(REGION_1, NOT_SECURE_READ) |
mtxRegionRdnsech(REGION_2, NOT_SECURE_READ) |
mtxRegionRdnsech(REGION_3, NOT_SECURE_READ),
mtxRegionWrnsech(REGION_0, NOT_SECURE_WRITE) |
mtxRegionWrnsech(REGION_1, NOT_SECURE_WRITE) |
mtxRegionWrnsech(REGION_2, NOT_SECURE_WRITE) |
mtxRegionWrnsech(REGION_3, NOT_SECURE_WRITE));
mtxConfigSlaveSec(MATRIX0, H64MX_SLAVE_DDR_PORT1,
mtxRegionLansech(REGION_0, UPPER_AREA_SECURABLE) |
mtxRegionLansech(REGION_1, UPPER_AREA_SECURABLE) |
mtxRegionLansech(REGION_2, UPPER_AREA_SECURABLE) |
mtxRegionLansech(REGION_3, UPPER_AREA_SECURABLE),
mtxRegionRdnsech(REGION_0, NOT_SECURE_READ) |
mtxRegionRdnsech(REGION_1, NOT_SECURE_READ) |
mtxRegionRdnsech(REGION_2, NOT_SECURE_READ) |
mtxRegionRdnsech(REGION_3, NOT_SECURE_READ),
mtxRegionWrnsech(REGION_0, NOT_SECURE_WRITE) |
mtxRegionWrnsech(REGION_1, NOT_SECURE_WRITE) |
mtxRegionWrnsech(REGION_2, NOT_SECURE_WRITE) |
mtxRegionWrnsech(REGION_3, NOT_SECURE_WRITE));
/* /*
* Wait that all services are initialized * System initializations.
* - TSSI initialization, the trusted services are created and started.
* Lastly, the thread "main" becomes the non secure execution environment.
*/ */
smcWaitServicesStarted(n); tssiInit();
/*
* Jump in the NON SECURE world
* This 'main' thread become the non secure environment as view by
* the secure world.
*/
chprintf((BaseSequentialStream*)&SD1, "Jumping in the non secure world\n\r");
_ns_trampoline(NSEC_IMAGE_START_ADDR);
/* /*
* It never goes here * It never goes here
*/ */

View File

@ -0,0 +1,94 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* @file tservices.c
* @brief Trusted services application file.
*
* @addtogroup TSSI
* @{
*/
#include "ch.h"
#include "hal.h"
#include "chtssi.h"
#include "chprintf.h"
/*===========================================================================*/
/* Module local definitions. */
/*===========================================================================*/
/*===========================================================================*/
/* Module exported variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local types. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local variables. */
/*===========================================================================*/
/*===========================================================================*/
/* Module local functions. */
/*===========================================================================*/
static THD_WORKING_AREA(waTsSimpleService, 1024);
static THD_FUNCTION(TsSimpleService, tsstate) {
/* WARNING: do not put blocking call out of the cycle,
* i.e. no calls that suspend
* the current thread!.*/
ts_state_t *svcp = tsstate;
/* Start the request/process/response cycle.*/
while (tssiWaitRequest(tsstate) == SMC_SVC_OK) {
int i;
chprintf((BaseSequentialStream*)&SD1,
"TsSimpleService received a new request.\r\n");
if (svcp->ts_datalen > 0) {
*(TS_GET_DATA(svcp) + TS_GET_DATALEN(svcp) - 1) = '\0';
chprintf((BaseSequentialStream*)&SD1,
"My non secure 'alter ego' has a request.\r\n");
chprintf((BaseSequentialStream*)&SD1,
"She tells: '");
chprintf((BaseSequentialStream*)&SD1, TS_GET_DATA(svcp));
chprintf((BaseSequentialStream*)&SD1, "'\r\n");
}
for (i = 0; i < 100000; ++i)
;
TS_SET_STATUS(svcp, i);
}
/* It never goes here.*/
}
/*===========================================================================*/
/* Module exported functions. */
/*===========================================================================*/
/**
* @brief TSSI services table definition
* @note This table is filled by the user.
*/
TS_STATE_TABLE
TS_CONF_TABLE_BEGIN
TS_CONF_TABLE_ENTRY("TsSimpleService", waTsSimpleService, TS_BASE_PRIO, TsSimpleService, TS_STATE(0))
TS_CONF_TABLE_END
/** @} */