Hey,
I have successfully created a Trusted Application (TA) for OP-TEE following the developer guide.
The compilation and execution of the TA via the host application seem to work because I do not get any errors, and the "printf"
command in the CA prints output to the terminal.
However, I am unable to see the debug output from DMSG()
and IMSG()
in my Trusted Application.
I would like to know how to correctly retrieve OP-TEE debug messages.
Additionally, in the developer guide, I read that some TAs need to be signed. Do I have to do that for my own created TA, or is signing only required for specific use cases?
Here is my code:
** Makefile - Root **
HOST_CROSS_COMPILE ?= $(CROSS_COMPILE)
TA_CROSS_COMPILE ?= $(CROSS_COMPILE)
.PHONY: all
all:
$(MAKE) -C host CROSS_COMPILE="$(HOST_CROSS_COMPILE)" --no-builtin-variables
$(MAKE) -C ta CROSS_COMPILE="$(TA_CROSS_COMPILE)" LDFLAGS=""
.PHONY: clean
clean:
$(MAKE) -C host clean
$(MAKE) -C ta clean
** host/Makefile **
CC ?= $(CROSS_COMPILE)gcc
CFLAGS += -Wall -I../ta/include -I$(TEEC_EXPORT)/include -I./include
CFLAGS += -fstack-protector-strong
LDADD += -lteec -L$(TEEC_EXPORT)/lib
BINARY = gpio_host_app
OBJS = main.o
.PHONY: all
all: $(BINARY)
$(BINARY): $(OBJS)
$(CC) -o $@ $^ $(LDADD)
.PHONY: clean
clean:
rm -f $(OBJS) $(BINARY)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
** host/main.c **
#include <err.h>
#include <stdio.h>
#include <string.h>
#include <tee_client_api.h>
#include <gpio_ta.h>
int main(void) {
TEEC_Context ctx;
TEEC_Session sess;
TEEC_Result res;
TEEC_Operation op;
uint32_t err_origin;
TEEC_UUID uuid = GPIO_TA_UUID;
res = TEEC_InitializeContext(NULL, &ctx);
if (res != TEEC_SUCCESS)
errx(1, "TEEC_InitializeContext failed with code 0x%x", res);
res = TEEC_OpenSession(&ctx, &sess, &uuid, TEEC_LOGIN_PUBLIC, NULL, NULL, &err_origin);
if (res != TEEC_SUCCESS)
errx(1, "TEEC_OpenSession failed with code 0x%x origin 0x%x", res, err_origin);
memset(&op, 0, sizeof(op));
res = TEEC_InvokeCommand(&sess, GPIO_TA_VAR, &op, &err_origin);
if (res != TEEC_SUCCESS)
errx(1, "TEEC_InvokeCommand failed with code 0x%x origin 0x%x", res, err_origin);
TEEC_CloseSession(&sess);
TEEC_FinalizeContext(&ctx);
printf("GPIO set to HIGH successfully!\n");
return 0;
}
** ta/Makefile **
BINARY=12345678-1234-1234-1234-567890abcdef
include $(TA_DEV_KIT_DIR)/mk/ta_dev_kit.mk
** ta/sub.mk**
srcs-y += gpio_ta.c
global-incdirs-y += include
** ta/user_ta_header_defines.h**
#ifndef USER_TA_HEADER_DEFINES_H
#define USER_TA_HEADER_DEFINES_H
#include <gpio_ta.h>
#define TA_UUID GPIO_TA_UUID
#define TA_FLAGS (TA_FLAG_EXEC_DDR | TA_FLAG_SINGLE_INSTANCE | TA_FLAG_MULTI_SESSION)
#define TA_STACK_SIZE (2 * 1024)
#define TA_DATA_SIZE (32 * 1024)
#define TA_CURRENT_TA_EXT_PROPERTIES \
{ "gp.ta.description", USER_TA_PROP_TYPE_STRING, "GPIO TA" }, \
{ "gp.ta.version", USER_TA_PROP_TYPE_U32, &(const uint32_t){ 0x0100 } }
#endif /* USER_TA_HEADER_DEFINES_H */
** ta/gpio_ta.c**
#include <tee_internal_api.h>
#include <tee_api.h>
#include <tee_internal_api_extensions.h>
#include <gpio_ta.h>
TEE_Result TA_CreateEntryPoint(void) {
DMSG("TA_CreateEntryPoint has been called");
return TEE_SUCCESS;
}
void TA_DestroyEntryPoint(void) {
DMSG("TA_DestroyEntryPoint has been called");
}
TEE_Result TA_OpenSessionEntryPoint(uint32_t param_types,
TEE_Param __maybe_unused params[4],
void __maybe_unused **session)
{
uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_NONE,
TEE_PARAM_TYPE_NONE,
TEE_PARAM_TYPE_NONE,
TEE_PARAM_TYPE_NONE);
DMSG("Session open has been called");
if (param_types != exp_param_types)
return TEE_ERROR_BAD_PARAMETERS;
(void)¶ms;
(void)&session;
IMSG("Session created successfully!");
return TEE_SUCCESS;
}
void TA_CloseSessionEntryPoint(void *session) {
(void)&session;
DMSG("TA_CloseSessionEntryPoint has been called");
IMSG("Closing session.");
}
TEE_Result TA_InvokeCommandEntryPoint(void *session, uint32_t command_id, uint32_t param_types,
TEE_Param params[4]) {
(void)&session;
(void)¶m_types;
(void)¶ms;
switch (command_id) {
case GPIO_TA_VAR:
DMSG("DMSG TEST");
IMSG("IMSG TEST.");
return TEE_SUCCESS;
default:
return TEE_ERROR_NOT_SUPPORTED;
}
}
** ta/include/gpio_ta.h**
#ifndef GPIO_TA_H
#define GPIO_TA_H
#define GPIO_TA_VAR 0
#define GPIO_TA_UUID \
{ 0x12345678, 0x1234, 0x1234, \
{ 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef} }
#endif /* GPIO_TA_H */