diff options
author | Jens Wiklander <jens.wiklander@linaro.org> | 2014-10-20 11:26:38 +0200 |
---|---|---|
committer | Jens Wiklander <jens.wiklander@linaro.org> | 2014-11-12 14:21:09 +0100 |
commit | 4de4bebcfbe3c5c1884a2ff2c66fa2aa5dede662 (patch) | |
tree | 494e55538bd2154c87f96bec8f127d0561388df2 | |
parent | 2eb765fcf0b1ca3c4ad7b5449e3f93820174830a (diff) |
Merge tee_{core,uta}_trace.h into libutil
Merges tee_core_trace.h and tee_uta_trace.h into a common trace.h
in libutil. Since the trace functions now resides libutil they have
to rely on core and libutee to provide functions to print to the
log device.
* Keeps compatible interface from tee_kta_trace.h
* Adds TAMSG() and TAMSG_RAW() to log TA related events
* Removes the TRACE_ALWAYS level
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Tested-by: Jens Wiklander <jens.wiklander@linaro.org> (QEMU virt platform)
Reviewed-by: Etienne Carriere <etienne.carriere@st.com>
Reviewed-by: Pascal Brand <pascal.brand@linaro.org>
Tested-by: Pascal Brand <pascal.brand@linaro.org> (STM platform)
69 files changed, 710 insertions, 1165 deletions
diff --git a/lib/libutee/include/tee_trace.h b/core/arch/arm32/include/kernel/tee_kta_trace.h index e20cf3bc..a60be49a 100644 --- a/lib/libutee/include/tee_trace.h +++ b/core/arch/arm32/include/kernel/tee_kta_trace.h @@ -25,22 +25,34 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TEE_TRACE_H -#define TEE_TRACE_H +#ifndef KERNEL_TEE_KTA_TRACE_H +#define KERNEL_TEE_KTA_TRACE_H -#include "tee_trace_levels.h" +#include <trace.h> -#define MAX_PRINT_SIZE 256 -#define MAX_FUNC_PRINT_SIZE 32 /* - * This define make sure that parameters are checked in the same manner as it - * is done in the normal printf function. + * This file provides legacy support for static TAs which hasn't been + * converted yet. */ -#define __PRINTFLIKE(__fmt, __varargs) __attribute__\ - ((__format__(__printf__, __fmt, __varargs))) -/* Trace backend */ -int _dprintf(const char *function, int line, int level, const char *prefix, - const char *fmt, ...) __PRINTFLIKE(5, 6); +#define ATAMSG EMSG +#define ETAMSG EMSG +#define ITAMSG IMSG +#define DTAMSG DMSG +#define FTAMSG FMSG -#endif /* TEE_TRACE_H */ +#define TAINMSG INMSG +#define TAOUTMSG OUTMSG +#define TAOUTRMSG OUTRMSG + + +#define ATAMSG_RAW EMSG_RAW +#define ETAMSG_RAW EMSG_RAW +#define ITAMSG_RAW IMSG_RAW +#define DTAMSG_RAW DMSG_RAW +#define FTAMSG_RAW FMSG_RAW + +#define set_ta_trace_level(l) trace_set_level((l)) +#define get_ta_trace_level() trace_get_level() + +#endif /*KERNEL_TEE_KTA_TRACE_H*/ diff --git a/core/arch/arm32/include/kernel/trace_ta.h b/core/arch/arm32/include/kernel/trace_ta.h new file mode 100644 index 00000000..cc90e99c --- /dev/null +++ b/core/arch/arm32/include/kernel/trace_ta.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef TRACE_TA_H +#define TRACE_TA_H + +#include <trace.h> + +/* Macros to trace TA related events, logs, TA crash info etc */ +#define TAMSG(...) EMSG(__VA_ARGS__) +#define TAMSG_RAW(...) EMSG_RAW(__VA_ARGS__) + +#endif /*TRACE_TA_H*/ + diff --git a/core/arch/arm32/kernel/mutex.c b/core/arch/arm32/kernel/mutex.c index 3a584c3f..b3851e7d 100644 --- a/core/arch/arm32/kernel/mutex.c +++ b/core/arch/arm32/kernel/mutex.c @@ -28,7 +28,7 @@ #include <kernel/tz_proc.h> #include <kernel/panic.h> #include <kernel/tee_common_unpg.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/tee_ta_manager.h> #include <kernel/thread.h> #include <kernel/tee_rpc.h> diff --git a/core/arch/arm32/kernel/sub.mk b/core/arch/arm32/kernel/sub.mk index d4c67711..aa6ad91d 100644 --- a/core/arch/arm32/kernel/sub.mk +++ b/core/arch/arm32/kernel/sub.mk @@ -1,4 +1,3 @@ -srcs-y += tee_core_trace.c srcs-y += tee_ta_manager.c srcs-y += tee_time.c diff --git a/core/arch/arm32/kernel/tee_core_trace.c b/core/arch/arm32/kernel/tee_core_trace.c deleted file mode 100644 index 9c227753..00000000 --- a/core/arch/arm32/kernel/tee_core_trace.c +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright (c) 2014, STMicroelectronics International N.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <platform_config.h> - -#include <stdio.h> -#include <stdarg.h> -#include <string.h> - -#define STR_TRACE_CORE "TEE-CORE-TZ" -#include <kernel/tee_core_trace.h> -#include <kernel/util.h> - -#ifdef WITH_UART_DRV -#include <drivers/uart.h> -#else -#include <kernel/asc.h> -#endif - -#if (CFG_TEE_CORE_LOG_LEVEL != 0) - -/* Default trace level */ -int _trace_level = CFG_TEE_CORE_LOG_LEVEL; - - -#ifdef WITH_UART_DRV -static void output_string(const char *str) -{ - const char *p = str; - - while (*p) { - uart_putc(*p, CONSOLE_UART_BASE); - if (*p == '\n') - uart_putc('\r', CONSOLE_UART_BASE); - p++; - } -} - -static void output_flush(void) -{ - uart_flush_tx_fifo(CONSOLE_UART_BASE); -} -#else -#define output_string(x) __asc_xmit(x) -#define output_flush() __asc_flush() -#endif - -void core_trace_test(void) -{ - INMSG("level: [%d]", _trace_level); - IMSG("current trace level = %d", _trace_level); - IMSG("Without args"); - AMSG("[%d] and [%s]", TRACE_ALWAYS, "TRACE_ALWAYS"); - EMSG("[%d] and [%s]", TRACE_ERROR, "TRACE_ERROR"); - IMSG("[%d] and [%s]", TRACE_INFO, "TRACE_INFO"); - DMSG("[%d] and [%s]", TRACE_DEBUG, "TRACE_DEBUG"); - FMSG("[%d] and [%s]", TRACE_FLOW, "TRACE_FLOW"); - AMSG_RAW("Raw trace in TEE CORE with level [%s]", "TRACE_ALWAYS"); - AMSG_RAW(" __ end of raw trace\n"); - DMSG_RAW("Raw trace in TEE CORE with level [%s]", "TRACE_DEBUG"); - DMSG_RAW(" __ end of raw trace\n"); - OUTMSG(""); -} - -void set_trace_level(int level) -{ - if (((int)level >= TRACE_MIN) && (level <= TRACE_MAX)) - _trace_level = level; - else - AMSG("Can't set level [%d]", level); - - core_trace_test(); - AMSG_RAW("\nLevel set to [%d]\n", _trace_level); -} - -int get_trace_level(void) -{ - return _trace_level; -} - -static const char const *_trace_level_to_string[] = { - "NONE", "ALW", "ERR", "INF", "DBG", "FLW" }; - -/* Format trace of user ta. Inline with kernel ta */ -static int format_trace(const char *function, int line, int level, - const char *prefix, const char *in, char *out) -{ - int nb_char = MAX_PRINT_SIZE; - const char *func; - int thread_id = 0; - - if (function) { -#ifdef TRACE_FUNC_LENGTH_CST - char func_buf[MAX_FUNC_PRINT_SIZE]; - int flen = strlen(function); - - /* Limit the function name to MAX_FUNC_PRINT_SIZE characters. */ - strncpy(func_buf, function, flen > MAX_FUNC_PRINT_SIZE ? - (MAX_FUNC_PRINT_SIZE - 1) : flen); - if (flen < (MAX_FUNC_PRINT_SIZE - 1)) { - memset(func_buf + flen, 0x20, - (MAX_FUNC_PRINT_SIZE - flen)); - } - func_buf[MAX_FUNC_PRINT_SIZE - 1] = '\0'; - func = func_buf; -#else - func = function; -#endif - - nb_char = - snprintf(out, MAX_PRINT_SIZE, "%s [0x%x] %s:%s:%d: %s\n", - _trace_level_to_string[level], thread_id, prefix, - func, line, in); - } else { - memcpy(out, in, MAX_PRINT_SIZE); - - /* we need to add \n and a \0 at end of the string if not - * present. We also set nb_char to the string length, including - * appended chars. */ -#if (MAX_PRINT_SIZE <= 2) -#error "cannot support MAX_PRINT_SIZE lesser than 3!" -#endif - nb_char = 0; - while (*out) { - out++; - if (++nb_char == MAX_PRINT_SIZE) { - /* force the 2 last bytes */ - *(out - 2) = '\n'; - *(out - 1) = '\0'; - return MAX_PRINT_SIZE - 1; - } - } - if (*(out - 1) != '\n') { - /* force last char to \n and append the \0 */ - *(out) = '\n'; - *(out + 1) = '\0'; - nb_char++; - } - } - return nb_char; -} - -int _dprintf(const char *function, int line, int level, const char *prefix, - const char *fmt, ...) -{ - char to_format[MAX_PRINT_SIZE]; - char formatted[MAX_PRINT_SIZE]; - va_list ap; - int nb; - - va_start(ap, fmt); - (void)vsnprintf(to_format, sizeof(to_format), fmt, ap); - va_end(ap); - - nb = format_trace(function, line, level, prefix, to_format, formatted); - - /* - * dprint is making use of the uart. - * a shared mem / circular buffer based trace could be used instead - */ - output_string(formatted); - - return nb; -} - -int _dprintf_hwsync(const char *function, int line, const char *fmt, ...) -{ - char to_format[MAX_PRINT_SIZE]; - char formatted[MAX_PRINT_SIZE]; - va_list ap; - int nb; - - va_start(ap, fmt); - (void)vsnprintf(to_format, sizeof(to_format), fmt, ap); - va_end(ap); - - nb = format_trace(function, line, TRACE_ALWAYS, "HWSYNC", to_format, - formatted); - - /* note: no contention or synchro handle with other CPU core ! */ - output_flush(); - output_string(formatted); - output_flush(); - - return nb; -} - -#if (CFG_TEE_CORE_LOG_LEVEL == TRACE_FLOW) -void _trace_syscall(int num) -{ - /* #0 is syscall return, not really interesting */ - if (num == 0) - return; - FMSG("syscall #%d", num); -} -#endif -#endif - -#if (CFG_TEE_CORE_LOG_LEVEL >= TRACE_DEBUG) -struct strbuf { - char buf[MAX_PRINT_SIZE]; - char *ptr; -}; - -static int __printf(2, 3) append(struct strbuf *sbuf, const char *fmt, ...) -{ - int left; - int len; - va_list ap; - - va_start(ap, fmt); - if (sbuf->ptr == NULL) - sbuf->ptr = sbuf->buf; - left = sizeof(sbuf->buf) - (sbuf->ptr - sbuf->buf); - len = vsnprintf(sbuf->ptr, left, fmt, ap); - if (len < 0) { - /* Format error */ - return 0; - } - if (len >= left) { - /* Output was truncated */ - return 0; - } - sbuf->ptr += MIN(left, len); - return 1; -} - -void dhex_dump(const char *function, int line, int level, const char *prefix, - const void *buf, int len) -{ - int i; - int ok; - struct strbuf sbuf; - char *in = (char *)buf; - - if (level <= _trace_level) { - sbuf.ptr = NULL; - for (i = 0; i < len; i++) { - ok = append(&sbuf, "%02x ", in[i]); - if (!ok) - goto err; - if ((i % 16) == 7) { - ok = append(&sbuf, " "); - if (!ok) - goto err; - } else if ((i % 16) == 15) { - _dprintf(function, line, level, prefix, "%s", - sbuf.buf); - sbuf.ptr = NULL; - } - } - if (sbuf.ptr) { - /* Buffer is not empty: flush it */ - _dprintf(function, line, level, prefix, "%s", - sbuf.buf); - - } - } - return; -err: - DMSG("Hex dump error"); -} -#endif diff --git a/core/arch/arm32/kernel/tee_l2cc_mutex.c b/core/arch/arm32/kernel/tee_l2cc_mutex.c index c605caec..b5bddd31 100644 --- a/core/arch/arm32/kernel/tee_l2cc_mutex.c +++ b/core/arch/arm32/kernel/tee_l2cc_mutex.c @@ -31,7 +31,7 @@ #include <tee_api_defines.h> #include <mm/core_memprot.h> #include <mm/core_mmu.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> /* * l2cc_mutex_va holds teecore virtual address of TZ L2CC mutex or NULL. diff --git a/core/arch/arm32/kernel/tee_ta_manager.c b/core/arch/arm32/kernel/tee_ta_manager.c index bc1ccbfe..691f4770 100644 --- a/core/arch/arm32/kernel/tee_ta_manager.c +++ b/core/arch/arm32/kernel/tee_ta_manager.c @@ -44,7 +44,7 @@ #include <kernel/tee_ta_manager_unpg.h> #include <kernel/tee_ta_static.h> #include <mm/tee_mm.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/tee_rpc.h> #include <kernel/tee_rpc_types.h> #include <kernel/mutex.h> diff --git a/core/arch/arm32/kernel/tee_time_arm_cntpct.c b/core/arch/arm32/kernel/tee_time_arm_cntpct.c index 4e4fa6cd..2cd26617 100644 --- a/core/arch/arm32/kernel/tee_time_arm_cntpct.c +++ b/core/arch/arm32/kernel/tee_time_arm_cntpct.c @@ -27,7 +27,7 @@ #include <kernel/misc.h> #include <kernel/tee_time.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/time_source.h> #include <mm/core_mmu.h> #include <utee_defines.h> diff --git a/core/arch/arm32/kernel/thread.c b/core/arch/arm32/kernel/thread.c index ab69748f..9f572f97 100644 --- a/core/arch/arm32/kernel/thread.c +++ b/core/arch/arm32/kernel/thread.c @@ -38,7 +38,7 @@ #include <kernel/misc.h> #include <mm/tee_mmu.h> #include <kernel/tee_ta_manager.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <assert.h> diff --git a/core/arch/arm32/mm/core_mmu.c b/core/arch/arm32/mm/core_mmu.c index 7c121885..4f5c4774 100644 --- a/core/arch/arm32/mm/core_mmu.c +++ b/core/arch/arm32/mm/core_mmu.c @@ -43,7 +43,7 @@ #include <mm/tee_mmu.h> #include <mm/tee_mmu_defs.h> #include <kernel/misc.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/tee_misc.h> /* Default NSec shared memory allocated from NSec world */ diff --git a/core/arch/arm32/mm/tee_mm.c b/core/arch/arm32/mm/tee_mm.c index 050d5693..ed3c6bd9 100644 --- a/core/arch/arm32/mm/tee_mm.c +++ b/core/arch/arm32/mm/tee_mm.c @@ -26,7 +26,7 @@ */ #include <kernel/tee_common.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <mm/tee_mm.h> #include <mm/tee_mm_unpg.h> diff --git a/core/arch/arm32/mm/tee_mmu.c b/core/arch/arm32/mm/tee_mmu.c index 19f54521..5680c48b 100644 --- a/core/arch/arm32/mm/tee_mmu.c +++ b/core/arch/arm32/mm/tee_mmu.c @@ -40,7 +40,7 @@ #include "tee_api_types.h" #include <kernel/tee_ta_manager_unpg.h> #include <kernel/tee_misc.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <mm/core_memprot.h> #include <mm/core_mmu.h> #include <mm/tee_mmu_io.h> diff --git a/core/arch/arm32/mm/tee_pager.c b/core/arch/arm32/mm/tee_pager.c index ed68b9ae..c94d028c 100644 --- a/core/arch/arm32/mm/tee_pager.c +++ b/core/arch/arm32/mm/tee_pager.c @@ -27,7 +27,7 @@ #include <kernel/tee_common.h> #include <mm/tee_mmu_defs.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <mm/tee_pager_unpg.h> #include <mm/core_mmu.h> diff --git a/core/arch/arm32/mm/tee_pager_unpg.c b/core/arch/arm32/mm/tee_pager_unpg.c index 6025e756..96ccd163 100644 --- a/core/arch/arm32/mm/tee_pager_unpg.c +++ b/core/arch/arm32/mm/tee_pager_unpg.c @@ -29,7 +29,7 @@ #include <inttypes.h> #include <kernel/tee_common_unpg.h> #include <mm/tee_mmu_defs.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <mm/tee_pager_unpg.h> diff --git a/core/arch/arm32/plat-stm/core_bootcfg.c b/core/arch/arm32/plat-stm/core_bootcfg.c index 861354d0..16a622e7 100644 --- a/core/arch/arm32/plat-stm/core_bootcfg.c +++ b/core/arch/arm32/plat-stm/core_bootcfg.c @@ -27,7 +27,7 @@ #include <platform_config.h> #include <mm/core_mmu.h> #include <mm/core_memprot.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/tee_misc.h> #ifndef CFG_DDR_TEETZ_RESERVED_START diff --git a/core/arch/arm32/plat-stm/core_chip_cannes.c b/core/arch/arm32/plat-stm/core_chip_cannes.c index b9150d0a..84d079f6 100644 --- a/core/arch/arm32/plat-stm/core_chip_cannes.c +++ b/core/arch/arm32/plat-stm/core_chip_cannes.c @@ -28,7 +28,7 @@ #include <stdint.h> #include <mm/tee_mmu_io.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/tee_misc_unpg.h> /* Cut information for Cannes */ diff --git a/core/arch/arm32/plat-stm/core_chip_orly2.c b/core/arch/arm32/plat-stm/core_chip_orly2.c index 6d82709c..52850ebd 100644 --- a/core/arch/arm32/plat-stm/core_chip_orly2.c +++ b/core/arch/arm32/plat-stm/core_chip_orly2.c @@ -28,7 +28,7 @@ #include <stdint.h> #include <mm/tee_mmu_io.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/tee_misc_unpg.h> /* Cut information for Orly2 */ diff --git a/core/arch/arm32/plat-stm/main.c b/core/arch/arm32/plat-stm/main.c index 4e0f748b..f1eed93a 100644 --- a/core/arch/arm32/plat-stm/main.c +++ b/core/arch/arm32/plat-stm/main.c @@ -40,12 +40,14 @@ #include <kernel/thread.h> #include <kernel/panic.h> #include <util.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/misc.h> #include <mm/tee_pager_unpg.h> #include <mm/core_mmu.h> #include <mm/tee_mmu_defs.h> #include <tee/entry.h> +#include <console.h> +#include <kernel/asc.h> #include <assert.h> @@ -315,3 +317,12 @@ vaddr_t core_mmu_get_ul1_ttb_va(void) thread_get_id() * TEE_MMU_UL1_NUM_ENTRIES; } +void console_putc(int ch) +{ + __asc_xmit_char((char)ch); +} + +void console_flush_tx_fifo(void) +{ + __asc_flush(); +} diff --git a/core/arch/arm32/plat-stm/rng_support.c b/core/arch/arm32/plat-stm/rng_support.c index 349ff2a1..6647e959 100644 --- a/core/arch/arm32/plat-stm/rng_support.c +++ b/core/arch/arm32/plat-stm/rng_support.c @@ -26,7 +26,7 @@ */ #include <stdlib.h> #include <rng_support.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <platform_config.h> #define USE_SW_DELAY 0 diff --git a/core/arch/arm32/plat-stm/tee_common_otp.c b/core/arch/arm32/plat-stm/tee_common_otp.c index 9b4705da..d44c4b43 100644 --- a/core/arch/arm32/plat-stm/tee_common_otp.c +++ b/core/arch/arm32/plat-stm/tee_common_otp.c @@ -27,7 +27,7 @@ #include <stddef.h> #include <string.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/tee_common_otp.h> #define SHA256_HASH_SIZE 32 diff --git a/core/arch/arm32/plat-vexpress/core_bootcfg.c b/core/arch/arm32/plat-vexpress/core_bootcfg.c index b0b13e05..0422759e 100644 --- a/core/arch/arm32/plat-vexpress/core_bootcfg.c +++ b/core/arch/arm32/plat-vexpress/core_bootcfg.c @@ -28,7 +28,7 @@ #include <mm/core_mmu.h> #include <mm/core_memprot.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #ifndef CFG_DDR_TEETZ_RESERVED_START #error "TEETZ reserved DDR start address undef: CFG_DDR_TEETZ_RESERVED_START" diff --git a/core/arch/arm32/plat-vexpress/main.c b/core/arch/arm32/plat-vexpress/main.c index 6fe46f8d..7fb24c8d 100644 --- a/core/arch/arm32/plat-vexpress/main.c +++ b/core/arch/arm32/plat-vexpress/main.c @@ -45,13 +45,14 @@ #include <arm32.h> #include <kernel/thread.h> #include <kernel/panic.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/misc.h> #include <kernel/tee_time.h> #include <mm/tee_pager_unpg.h> #include <mm/core_mmu.h> #include <mm/tee_mmu_defs.h> #include <tee/entry.h> +#include <console.h> #include <malloc.h> #include <assert.h> @@ -533,3 +534,14 @@ vaddr_t core_mmu_get_ul1_ttb_va(void) return (vaddr_t)main_mmu_ul1_ttb[thread_get_id()]; } +void console_putc(int ch) +{ + uart_putc(ch, CONSOLE_UART_BASE); + if (ch == '\n') + uart_putc('\r', CONSOLE_UART_BASE); +} + +void console_flush_tx_fifo(void) +{ + uart_flush_tx_fifo(CONSOLE_UART_BASE); +} diff --git a/core/arch/arm32/plat-vexpress/rng_support.c b/core/arch/arm32/plat-vexpress/rng_support.c index 2f30256c..87c9f612 100644 --- a/core/arch/arm32/plat-vexpress/rng_support.c +++ b/core/arch/arm32/plat-vexpress/rng_support.c @@ -26,7 +26,7 @@ */ #include <stdlib.h> #include <rng_support.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> /* Bad software version */ uint8_t hw_get_random_byte(void) diff --git a/core/arch/arm32/plat-vexpress/tee_common_otp.c b/core/arch/arm32/plat-vexpress/tee_common_otp.c index 9b4705da..d44c4b43 100644 --- a/core/arch/arm32/plat-vexpress/tee_common_otp.c +++ b/core/arch/arm32/plat-vexpress/tee_common_otp.c @@ -27,7 +27,7 @@ #include <stddef.h> #include <string.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/tee_common_otp.h> #define SHA256_HASH_SIZE 32 diff --git a/core/arch/arm32/sta/core_self_tests.c b/core/arch/arm32/sta/core_self_tests.c index 035d6268..7070c848 100644 --- a/core/arch/arm32/sta/core_self_tests.c +++ b/core/arch/arm32/sta/core_self_tests.c @@ -26,7 +26,7 @@ */ #include <malloc.h> #include <stdbool.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include "core_self_tests.h" /* diff --git a/core/arch/arm32/sta/sta_self_tests.c b/core/arch/arm32/sta/sta_self_tests.c index 5c455580..4a861322 100644 --- a/core/arch/arm32/sta/sta_self_tests.c +++ b/core/arch/arm32/sta/sta_self_tests.c @@ -26,7 +26,7 @@ */ #include <compiler.h> #include <user_ta_header.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <tee_api_types.h> #include <tee_api_defines.h> #include "core_self_tests.h" diff --git a/core/arch/arm32/tee/init.c b/core/arch/arm32/tee/init.c index 569a8cba..60eeb20e 100644 --- a/core/arch/arm32/tee/init.c +++ b/core/arch/arm32/tee/init.c @@ -30,7 +30,7 @@ #include <sm/tee_mon.h> #include <kernel/tee_misc.h> #include <mm/core_memprot.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/time_source.h> #include <mm/tee_mmu.h> #include <tee/tee_fs.h> diff --git a/core/arch/arm32/tee/tee_rpmb.c b/core/arch/arm32/tee/tee_rpmb.c index 19cc82f7..6eb3aeb4 100644 --- a/core/arch/arm32/tee/tee_rpmb.c +++ b/core/arch/arm32/tee/tee_rpmb.c @@ -29,7 +29,7 @@ #include <string.h> #include <string_ext.h> #include <util.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <tee_api_types.h> #include <kernel/tee_common_otp.h> #include <kernel/tee_rpc.h> diff --git a/core/arch/arm32/tee/tee_svc_asm.S b/core/arch/arm32/tee/tee_svc_asm.S index d661d29a..41321bcf 100644 --- a/core/arch/arm32/tee/tee_svc_asm.S +++ b/core/arch/arm32/tee/tee_svc_asm.S @@ -25,7 +25,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include "tee_syscall_numbers.h" -#include "tee_trace_levels.h" +#include "trace_levels.h" .global tee_svc_enter_user_mode .global tee_svc_sys_return @@ -88,10 +88,10 @@ tee_svc_syscall: * * System call number is passed in r7. */ -#if (CFG_TEE_CORE_LOG_LEVEL == TRACE_FLOW) +#if (CFG_TRACE_LEVEL == TRACE_FLOW) push {r0-r3} mov r0, r7 - blx _trace_syscall + blx tee_svc_trace_syscall pop {r0-r3} #endif ldr r12, =tee_svc_syscall_table diff --git a/core/core.mk b/core/core.mk index 8217201a..389b5122 100644 --- a/core/core.mk +++ b/core/core.mk @@ -19,9 +19,8 @@ cflags$(sm) += $(platform-cflags) $(core-platform-cflags) aflags$(sm) += $(platform-aflags) $(core-platform-aflags) # Config flags from mk/config.mk -cppflags$(sm) += -DCFG_TEE_TA_LOG_LEVEL=$(CFG_TEE_TA_LOG_LEVEL) cppflags$(sm) += -DCFG_TEE_FW_DEBUG=$(CFG_TEE_FW_DEBUG) -cppflags$(sm) += -DCFG_TEE_CORE_LOG_LEVEL=$(CFG_TEE_CORE_LOG_LEVEL) +cppflags$(sm) += -DCFG_TRACE_LEVEL=$(CFG_TEE_CORE_LOG_LEVEL) cppflags$(sm) += -Ilib/libutee/include diff --git a/core/drivers/gic.c b/core/drivers/gic.c index b3cd6f96..9670f300 100644 --- a/core/drivers/gic.c +++ b/core/drivers/gic.c @@ -27,7 +27,7 @@ #include <drivers/gic.h> #include <io.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <assert.h> diff --git a/core/include/console.h b/core/include/console.h new file mode 100644 index 00000000..3ad534f7 --- /dev/null +++ b/core/include/console.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef CONSOLE_H +#define CONSOLE_H + +void console_putc(int ch); +void console_flush_tx_fifo(void); + +#endif /*CONSOLE_H*/ + diff --git a/core/include/kernel/tee_core_trace.h b/core/include/kernel/tee_core_trace.h deleted file mode 100644 index c4fc279c..00000000 --- a/core/include/kernel/tee_core_trace.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright (c) 2014, STMicroelectronics International N.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef TEE_CORE_TRACE_H -#define TEE_CORE_TRACE_H - -#include <tee_trace.h> -#include <compiler.h> - -/*****************************************************************************/ - -#if (CFG_TEE_CORE_LOG_LEVEL > 0) -extern int _trace_level; -#endif - -/*****************************************************************************/ - -#ifndef STR_TRACE_CORE -#define STR_TRACE_CORE "TEE-CORE" -#endif - -/*****************************************************************************/ -/* Trace api with trace formatting */ - -/* Filtering and call backend method */ -#define dprintf_level(level, ...) \ - do { \ - if ((level) <= _trace_level) { \ - _dprintf(__func__, __LINE__, \ - level, STR_TRACE_CORE, __VA_ARGS__); \ - } \ - } while (0) - -/* Formatted trace tagged with TRACE_ALWAYS level */ -#if (CFG_TEE_CORE_LOG_LEVEL < TRACE_ALWAYS) -#define AMSG(...) (void)0 -#else -#define AMSG(...) \ - _dprintf(__func__, __LINE__, TRACE_ALWAYS, STR_TRACE_CORE, __VA_ARGS__); -#endif - -/* Formatted trace tagged with TRACE_ERROR level */ -#if (CFG_TEE_CORE_LOG_LEVEL < TRACE_ERROR) -#define EMSG(...) (void)0 -#else -#define EMSG(...) dprintf_level(TRACE_ERROR, __VA_ARGS__) -#endif - -/* Formatted trace tagged with TRACE_INFO level */ -#if (CFG_TEE_CORE_LOG_LEVEL < TRACE_INFO) -#define IMSG(...) (void)0 -#else -#define IMSG(...) dprintf_level(TRACE_INFO, __VA_ARGS__) -#endif - -/* Formatted trace tagged with TRACE_DEBUG level */ -#if (CFG_TEE_CORE_LOG_LEVEL < TRACE_DEBUG) -#define DMSG(...) (void)0 -#else -#define DMSG(...) dprintf_level(TRACE_DEBUG, __VA_ARGS__) -#endif - -/* Formatted trace tagged with TRACE_FLOW level */ -#if (CFG_TEE_CORE_LOG_LEVEL < TRACE_FLOW) -#define FMSG(...) (void)0 -#else -#define FMSG(...) dprintf_level(TRACE_FLOW, __VA_ARGS__) -#endif - -/* Formatted trace tagged with TRACE_FLOW level and prefix with '> ' */ -#define INMSG(...) FMSG("> " __VA_ARGS__) -/* Formatted trace tagged with TRACE_FLOW level and prefix with '< ' */ -#define OUTMSG(...) FMSG("< " __VA_ARGS__) -/* Formatted trace tagged with TRACE_FLOW level and prefix with '< ' and print - * an error message if r != 0 */ -#define OUTRMSG(r) \ - do { \ - OUTMSG("r=[%x]", r); \ - return r; \ - } while (0) - -#if (CFG_TEE_CORE_LOG_LEVEL < TRACE_DEBUG) -#define DHEXDUMP(buf, len) (void)0 -#else -#define DHEXDUMP(buf, len) dhex_dump(__func__, __LINE__, TRACE_DEBUG, \ - STR_TRACE_CORE, buf, len) -void dhex_dump(const char *function, int line, int level, const char *prefix, - const void *buf, int len); -#endif - -/*****************************************************************************/ -/* Trace api without trace formatting */ - -#define dprintf_raw(level, ...) \ - do { \ - if ((level) <= _trace_level) { \ - _dprintf(NULL, 0, level, STR_TRACE_CORE, __VA_ARGS__); \ - } \ - } while (0) - -/* No formatted trace tagged with TRACE_ALWAYS level */ -#if (CFG_TEE_CORE_LOG_LEVEL < TRACE_ALWAYS) -#define AMSG_RAW(...) (void)0 -#else -#define AMSG_RAW(...) \ - _dprintf(NULL, 0, TRACE_ALWAYS, STR_TRACE_CORE, __VA_ARGS__) -#endif - -/* No formatted trace tagged with TRACE_ERROR level */ -#if (CFG_TEE_CORE_LOG_LEVEL < TRACE_ERROR) -#define EMSG_RAW(...) (void)0 -#else -#define EMSG_RAW(...) dprintf_raw(TRACE_ERROR, __VA_ARGS__) -#endif - -/* No formatted trace tagged with TRACE_INFO level */ -#if (CFG_TEE_CORE_LOG_LEVEL < TRACE_INFO) -#define IMSG_RAW(...) (void)0 -#else -#define IMSG_RAW(...) dprintf_raw(TRACE_INFO, __VA_ARGS__) -#endif - -/* No formatted trace tagged with TRACE_DEBUG level */ -#if (CFG_TEE_CORE_LOG_LEVEL < TRACE_DEBUG) -#define DMSG_RAW(...) (void)0 -#else -#define DMSG_RAW(...) dprintf_raw(TRACE_DEBUG, __VA_ARGS__) -#endif - -/* No formatted trace tagged with TRACE_FLOW level */ -#if (CFG_TEE_CORE_LOG_LEVEL < TRACE_FLOW) -#define FMSG_RAW(...) (void)0 -#else -#define FMSG_RAW(...) dprintf_raw(TRACE_FLOW, __VA_ARGS__) -#endif - -#if (CFG_TEE_CORE_LOG_LEVEL == 0) -#define SMSG(...) (void)0 -static inline void set_trace_level(int level __unused) { } -static inline int get_trace_level(void) { return 0; } -static inline void core_trace_test(void) { } -#else -/* - * Synchronised flushed trace, an Always message straight to HW trace IP. - * Current only supported inside teecore (not in kernel or user TA). - */ -#define SMSG(...) _dprintf_hwsync(__func__, __LINE__, __VA_ARGS__) -int _dprintf_hwsync(const char *function, int line, const char *fmt, - ...) __PRINTFLIKE(3, 4); - -/* Accessors */ -void set_trace_level(int level); -int get_trace_level(void); -void core_trace_test(void); - -#if (CFG_TEE_CORE_LOG_LEVEL == TRACE_FLOW) -void _trace_syscall(int num); -#endif - -#endif /* CFG_TEE_CORE_LOG_LEVEL */ - -#endif /* TEE_CORE_TRACE_H */ diff --git a/core/include/kernel/tee_dispatch.h b/core/include/kernel/tee_dispatch.h index c9f59696..7b533f57 100644 --- a/core/include/kernel/tee_dispatch.h +++ b/core/include/kernel/tee_dispatch.h @@ -31,7 +31,7 @@ #include <kernel/tee_common_unpg.h> #include <tee_api_types.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> /* @@ -97,19 +97,6 @@ struct tee_dispatch_memory_in { uint32_t size; }; -#if (CFG_TEE_TA_LOG_LEVEL > 0) -/* Input arg structure specific to TEE service 'get XXX trace level'. */ -struct tee_dispatch_set_trace_level_in { - int level; -}; - -/* Output arg structure specific to TEE service 'get XXX trace level'. */ -struct tee_dispatch_get_trace_level_out { - struct tee_dispatch_out msg; - int trace_level; -}; -#endif - #if (CFG_TEE_FW_DEBUG == 1) /* Output arg structure specific to TEE service 'get core status'. */ struct tee_core_status_out { diff --git a/core/include/kernel/tee_kta_trace.h b/core/include/kernel/tee_kta_trace.h deleted file mode 100644 index fc0920e0..00000000 --- a/core/include/kernel/tee_kta_trace.h +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (c) 2014, STMicroelectronics International N.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef TEE_KTA_TRACE_H -#define TEE_KTA_TRACE_H - -#include <tee_trace.h> -#include <compiler.h> - -/*****************************************************************************/ - -extern int _ta_trace_level; - -/*****************************************************************************/ - -#ifndef STR_TRACE_KERNEL_TA -#define STR_TRACE_KERNEL_TA "KERNEL-TA" -#endif - -/*****************************************************************************/ -/* Trace api with trace formatting */ - -/* Filtering and call backend method */ -#define tadprintf(level, ...) \ - do { \ - if ((level) <= _ta_trace_level) { \ - _dprintf(__func__, __LINE__, level, \ - STR_TRACE_KERNEL_TA, __VA_ARGS__); \ - } \ - } while (0) - -/* Formatted trace tagged with TRACE_ALWAYS level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_ALWAYS) -#define ATAMSG(...) (void)0 -#else -#define ATAMSG(...) \ -_dprintf(__func__, __LINE__, TRACE_ALWAYS, STR_TRACE_KERNEL_TA, __VA_ARGS__); -#endif - -/* Formatted trace tagged with TRACE_ERROR level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_ERROR) -#define ETAMSG(...) (void)0 -#else -#define ETAMSG(...) tadprintf(TRACE_ERROR, __VA_ARGS__) -#endif - -/* Formatted trace tagged with TRACE_INFO level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_INFO) -#define ITAMSG(...) (void)0 -#else -#define ITAMSG(...) tadprintf(TRACE_INFO, __VA_ARGS__) -#endif - -/* Formatted trace tagged with TRACE_DEBUG level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_DEBUG) -#define DTAMSG(...) (void)0 -#else -#define DTAMSG(...) tadprintf(TRACE_DEBUG, __VA_ARGS__) -#endif - -/* Formatted trace tagged with TRACE_FLOW level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_FLOW) -#define FTAMSG(...) (void)0 -#else -#define FTAMSG(...) tadprintf(TRACE_FLOW, __VA_ARGS__) -#endif - -/* Formatted trace tagged with TRACE_FLOW level and prefix with '> ' */ -#define TAINMSG(...) FTAMSG("> " __VA_ARGS__) -/* Formatted trace tagged with TRACE_FLOW level and prefix with '< ' */ -#define TAOUTMSG(...) FTAMSG("< " __VA_ARGS__) -/* Formatted trace tagged with TRACE_FLOW level and prefix with '< ' and print - * an error message if r != 0 */ -#define TAOUTRMSG(r) \ - do { \ - OUTMSG("r=[%lx]", r); \ - return r; \ - } while (0) - -/*****************************************************************************/ -/* Trace api without trace formatting */ - -/* Filtering and call backend method */ -#define tadprintf_raw(level, ...) \ - do { \ - if ((level) <= _ta_trace_level) { \ - _dprintf(NULL, 0, level, STR_TRACE_KERNEL_TA, \ - __VA_ARGS__); \ - } \ - } while (0) - -/* No formatted trace tagged with TRACE_ALWAYS level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_ALWAYS) -#define ATAMSG_RAW(...) (void)0 -#else -#define ATAMSG_RAW(...) \ - _dprintf(NULL, 0, TRACE_ALWAYS, STR_TRACE_KERNEL_TA, __VA_ARGS__); -#endif - -/* No formatted trace tagged with TRACE_ERROR level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_ERROR) -#define ETAMSG_RAW(...) (void)0 -#else -#define ETAMSG_RAW(...) tadprintf_raw(TRACE_ERROR, __VA_ARGS__) -#endif - -/* No formatted trace tagged with TRACE_INFO level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_INFO) -#define ITAMSG_RAW(...) (void)0 -#else -#define ITAMSG_RAW(...) tadprintf_raw(TRACE_INFO, __VA_ARGS__) -#endif - -/* No formatted trace tagged with TRACE_DEBUG level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_DEBUG) -#define DTAMSG_RAW(...) (void)0 -#else -#define DTAMSG_RAW(...) tadprintf_raw(TRACE_DEBUG, __VA_ARGS__) -#endif - -/* No formatted trace tagged with TRACE_FLOW level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_FLOW) -#define FTAMSG_RAW(...) (void)0 -#else -#define FTAMSG_RAW(...) tadprintf_raw(TRACE_FLOW, __VA_ARGS__) -#endif - -/*****************************************************************************/ - -/* Accessors */ -#if (CFG_TEE_TA_LOG_LEVEL == 0) -static inline void set_ta_trace_level(int level __unused) { } -static inline int get_ta_trace_level(void) { return 0; } -static inline void ta_trace_test(void) { } -#else -void set_ta_trace_level(int level); -int get_ta_trace_level(void); -void ta_trace_test(void); -#endif - -#endif /* TEE_KTA_TRACE_H */ diff --git a/core/include/kernel/tee_ta_manager.h b/core/include/kernel/tee_ta_manager.h index a556adde..6d995d1f 100644 --- a/core/include/kernel/tee_ta_manager.h +++ b/core/include/kernel/tee_ta_manager.h @@ -35,7 +35,6 @@ #include "tee_ta.h" #include <kernel/kta_types.h> #include "tee_ta_manager_unpg.h" -#include "tee_trace.h" /*----------------------------------------------------------------------------- * Initializes virtual memory management by reserving virtual memory for diff --git a/core/include/kernel/tee_ta_manager_unpg.h b/core/include/kernel/tee_ta_manager_unpg.h index d6bb3d02..f06d9267 100644 --- a/core/include/kernel/tee_ta_manager_unpg.h +++ b/core/include/kernel/tee_ta_manager_unpg.h @@ -37,7 +37,6 @@ #include <sys/queue.h> #include "tee_api_types.h" #include "user_ta_header.h" -#include "tee_trace.h" TAILQ_HEAD(tee_ta_session_head, tee_ta_session); TAILQ_HEAD(tee_ta_ctx_head, tee_ta_ctx); diff --git a/core/include/tee/tee_svc.h b/core/include/tee/tee_svc.h index 6177d456..3ad8f64c 100644 --- a/core/include/tee/tee_svc.h +++ b/core/include/tee/tee_svc.h @@ -32,7 +32,6 @@ #include <tee_api_types.h> #include <tee_api_types.h> #include <utee_types.h> -#include <tee_trace.h> struct tee_ta_session; @@ -101,4 +100,7 @@ TEE_Result tee_svc_wait(uint32_t timeout); TEE_Result tee_svc_get_time(enum utee_time_category cat, TEE_Time *time); TEE_Result tee_svc_set_ta_time(const TEE_Time *time); +void tee_svc_trace_syscall(int num); + + #endif /* TEE_SVC_H */ diff --git a/core/kernel/assert.c b/core/kernel/assert.c index e3474dc1..fa08e4eb 100644 --- a/core/kernel/assert.c +++ b/core/kernel/assert.c @@ -25,7 +25,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <assert.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> /* indirected assert (see TEE_ASSERT()) */ diff --git a/core/kernel/panic.c b/core/kernel/panic.c index d82f2d53..4f492339 100644 --- a/core/kernel/panic.c +++ b/core/kernel/panic.c @@ -26,12 +26,12 @@ */ #include <kernel/panic.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> void __panic(const char *file __unused, int line __unused, const char *func __unused) { - EMSG("PANIC: %s %s:%d\n", func, file, line); + EMSG_RAW("PANIC: %s %s:%d\n", func, file, line); while (1) ; } diff --git a/core/kernel/sub.mk b/core/kernel/sub.mk index ff6c0084..1ca3f75d 100644 --- a/core/kernel/sub.mk +++ b/core/kernel/sub.mk @@ -1,8 +1,8 @@ srcs-y += assert.c srcs-y += tee_compat.c srcs-y += tee_dispatch.c -srcs-y += tee_kta_trace.c srcs-y += tee_misc.c srcs-y += tee_ta_manager_unpg.c srcs-y += panic.c srcs-y += handle.c +srcs-y += trace_ext.c diff --git a/core/kernel/tee_kta_trace.c b/core/kernel/tee_kta_trace.c deleted file mode 100644 index c6066c65..00000000 --- a/core/kernel/tee_kta_trace.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2014, STMicroelectronics International N.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <stdarg.h> - -#include <kernel/tee_ta_manager.h> -#include <kernel/tee_kta_trace.h> - -#if (CFG_TEE_TA_LOG_LEVEL != 0) - -/* Default trace level */ -int _ta_trace_level = CFG_TEE_TA_LOG_LEVEL; - -void ta_trace_test(void) -{ - TAINMSG("level: [%d]", _ta_trace_level); - ITAMSG("current trace level = %d", _ta_trace_level); - ITAMSG("Without args"); - ATAMSG("[%d] and [%s]", TRACE_ALWAYS, "TRACE_ALWAYS"); - ETAMSG("[%d] and [%s]", TRACE_ERROR, "TRACE_ERROR"); - ITAMSG("[%d] and [%s]", TRACE_INFO, "TRACE_INFO"); - DTAMSG("[%d] and [%s]", TRACE_DEBUG, "TRACE_DEBUG"); - FTAMSG("[%d] and [%s]", TRACE_FLOW, "TRACE_FLOW"); - ATAMSG_RAW("raw trace in KERNEL-TA with level [%s]", "TRACE_ALWAYS"); - ATAMSG_RAW(" __ end of raw trace\n"); - DTAMSG_RAW("raw trace in KERNEL-TA with level [%s]", "TRACE_DEBUG"); - DTAMSG_RAW(" __ end of raw trace\n"); - TAOUTMSG(""); -} - -void set_ta_trace_level(int level) -{ - if ((level <= CFG_TEE_TA_LOG_LEVEL) && - (level >= TRACE_MIN) && - (level <= TRACE_MAX)) - _ta_trace_level = level; - else { - ATAMSG("Can't set level [%d]", level); - return; - } - - /* parse all loaded TAs to set TA trace level */ - (void)tee_ta_set_trace_level(level); - - ta_trace_test(); - ATAMSG_RAW("\nLevel set to [%d]\n", _ta_trace_level); -} - -int get_ta_trace_level(void) -{ - return _ta_trace_level; -} - -#if (CFG_TEE_CORE_LOG_LEVEL == 0) -#include <compiler.h> -/* no log, sorry! implement a dummy _dprintf */ -int _dprintf(const char *function __unused, int line __unused, - int level __unused, const char *prefix __unused, - const char *fmt __unused, ...) -{ - return 0; -} -#endif -#endif - diff --git a/core/kernel/tee_misc.c b/core/kernel/tee_misc.c index 3aeb9611..67627341 100644 --- a/core/kernel/tee_misc.c +++ b/core/kernel/tee_misc.c @@ -29,7 +29,7 @@ #include <kernel/tee_misc.h> #include <mm/core_memprot.h> #include <kernel/tee_common_otp.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> static uint8_t tee_b2hs_add_base(uint8_t in) { diff --git a/core/kernel/tee_ta_manager_unpg.c b/core/kernel/tee_ta_manager_unpg.c index cd45d137..d8e053c5 100644 --- a/core/kernel/tee_ta_manager_unpg.c +++ b/core/kernel/tee_ta_manager_unpg.c @@ -30,7 +30,7 @@ #include <util.h> #include <kernel/tee_ta_manager_unpg.h> #include <tee/tee_cryp_utl.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> struct tee_ta_ctx_head tee_ctxes = TAILQ_HEAD_INITIALIZER(tee_ctxes); @@ -111,7 +111,7 @@ void *tee_ta_load_page(const uint32_t va_addr) /* check hash */ if (tee_hash_check(ts->head->hash_type, hash_offset, hash_size, - (void *)spage, cpy_size) != TEE_SUCCESS) { + (void *)spage, cpy_size) != TEE_SUCCESS) { /* Hash did not match. */ EMSG("PH 0x%x failed", (unsigned int)spage); TEE_ASSERT(0); diff --git a/core/kernel/trace_ext.c b/core/kernel/trace_ext.c new file mode 100644 index 00000000..72167a00 --- /dev/null +++ b/core/kernel/trace_ext.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include <stdbool.h> +#include <trace.h> +#include <console.h> + +const char trace_ext_prefix[] = "TEE-CORE"; + +void trace_ext_puts(bool sync, const char *str) +{ + const char *p; + + if (sync) + console_flush_tx_fifo(); + + for (p = str; *p; p++) + console_putc(*p); + + if (sync) + console_flush_tx_fifo(); +} + +int trace_ext_get_thread_id(void) +{ + return -1; +} diff --git a/core/lib/libtomcrypt/src/tee_ltc_provider.c b/core/lib/libtomcrypt/src/tee_ltc_provider.c index 6ea1592d..00e98a94 100644 --- a/core/lib/libtomcrypt/src/tee_ltc_provider.c +++ b/core/lib/libtomcrypt/src/tee_ltc_provider.c @@ -33,7 +33,7 @@ #include <stdlib.h> #include <string.h> #include <utee_defines.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <tee_api_types.h> #include <string_ext.h> #include "tomcrypt_mpa.h" diff --git a/core/tee/tee_fs.c b/core/tee/tee_fs.c index 9f8444a2..e73043fa 100644 --- a/core/tee/tee_fs.c +++ b/core/tee/tee_fs.c @@ -34,7 +34,7 @@ #include <mm/core_mmu.h> #include "tee_api_defines.h" #include <kernel/tee_common_unpg.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <kernel/handle.h> /* TEE FS operation */ diff --git a/core/tee/tee_obj.c b/core/tee/tee_obj.c index 7eb01a9c..59b3cfd2 100644 --- a/core/tee/tee_obj.c +++ b/core/tee/tee_obj.c @@ -32,7 +32,7 @@ #include <mm/tee_mmu.h> #include <tee/tee_fs.h> #include <tee/tee_pobj.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> void tee_obj_add(struct tee_ta_ctx *ctx, struct tee_obj *o) { diff --git a/core/tee/tee_pobj.c b/core/tee/tee_pobj.c index 132633ec..7c2d97c2 100644 --- a/core/tee/tee_pobj.c +++ b/core/tee/tee_pobj.c @@ -26,7 +26,7 @@ */ #include <tee/tee_pobj.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <string.h> #include <stdlib.h> diff --git a/core/tee/tee_svc.c b/core/tee/tee_svc.c index 495524fe..76deb94d 100644 --- a/core/tee/tee_svc.c +++ b/core/tee/tee_svc.c @@ -40,10 +40,20 @@ #include <kernel/tee_time.h> #include <user_ta_header.h> -#include <kernel/tee_core_trace.h> -#include <kernel/tee_kta_trace.h> +#include <trace.h> +#include <kernel/trace_ta.h> #include <kernel/chip_services.h> +#if (CFG_TRACE_LEVEL == TRACE_FLOW) +void tee_svc_trace_syscall(int num) +{ + /* #0 is syscall return, not really interesting */ + if (num == 0) + return; + FMSG("syscall #%d", num); +} +#endif + void tee_svc_sys_log(const void *buf, size_t len) { char *kbuf; @@ -58,7 +68,7 @@ void tee_svc_sys_log(const void *buf, size_t len) /* log as Info/Raw traces */ if (tee_svc_copy_from_user(NULL, kbuf, buf, len) == TEE_SUCCESS) - ATAMSG_RAW("%s", kbuf); + TAMSG_RAW("%.*s", (int)len, kbuf); free(kbuf); } diff --git a/core/tee/tee_svc_cryp.c b/core/tee/tee_svc_cryp.c index ae0af1a6..ee2f523a 100644 --- a/core/tee/tee_svc_cryp.c +++ b/core/tee/tee_svc_cryp.c @@ -34,7 +34,7 @@ #include <sys/queue.h> #include <tee/tee_obj.h> #include <tee/tee_cryp_provider.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <string_ext.h> /* Set an attribute on an object */ diff --git a/core/tee/tee_svc_storage.c b/core/tee/tee_svc_storage.c index a3e38741..2ea4a79e 100644 --- a/core/tee/tee_svc_storage.c +++ b/core/tee/tee_svc_storage.c @@ -36,7 +36,7 @@ #include <tee/tee_svc.h> #include <mm/tee_mmu.h> #include <tee/tee_pobj.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> /* SSF (Secure Storage File version 00 */ #define TEE_SVC_STORAGE_MAGIC 0x53534600; diff --git a/core/tee/tee_time_generic.c b/core/tee/tee_time_generic.c index 608858cb..b0215916 100644 --- a/core/tee/tee_time_generic.c +++ b/core/tee/tee_time_generic.c @@ -27,7 +27,7 @@ #include <string.h> #include <stdlib.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <utee_defines.h> #include <kernel/tee_time.h> diff --git a/lib/libutee/arch/arm32/user_ta_entry.c b/lib/libutee/arch/arm32/user_ta_entry.c index beb7b89f..47dc9ae5 100644 --- a/lib/libutee/arch/arm32/user_ta_entry.c +++ b/lib/libutee/arch/arm32/user_ta_entry.c @@ -104,6 +104,8 @@ static TEE_Result ta_header_add_session(uint32_t session_id) if (ta_ref_count == 1) { TEE_Result res; + trace_set_level(tahead_get_trace_level()); + bget_malloc_add_heap(ta_heap_base, ta_data_size); TEE_MathAPI_Init(); diff --git a/lib/libutee/include/tee_internal_api_extensions.h b/lib/libutee/include/tee_internal_api_extensions.h index b147e904..36b0ed33 100644 --- a/lib/libutee/include/tee_internal_api_extensions.h +++ b/lib/libutee/include/tee_internal_api_extensions.h @@ -29,7 +29,7 @@ #define TEE_INTERNAL_API_EXTENSIONS_H /* trace support */ -#include <tee_uta_trace.h> +#include <trace.h> #include <stdio.h> /* diff --git a/lib/libutee/include/tee_uta_trace.h b/lib/libutee/include/tee_uta_trace.h deleted file mode 100644 index 3d5e0f58..00000000 --- a/lib/libutee/include/tee_uta_trace.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (c) 2014, STMicroelectronics International N.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef TEE_UTA_TRACE_H -#define TEE_UTA_TRACE_H - -#include <tee_trace.h> -#include <user_ta_header.h> - -/*****************************************************************************/ - -#ifndef STR_TRACE_USER_TA -#define STR_TRACE_USER_TA "USER-TA" -#endif - -#if (CFG_TEE_TA_LOG_LEVEL > 0) -int _dprintf_uta(const char *function, int line, int level, const char *prefix, - const char *fmt, ...) __PRINTFLIKE(5, 6); -#endif - -/*****************************************************************************/ -/* Trace api with trace formatting */ - -/* Filtering and call backend method. - * Retrieve the ta level strored at kernel side by a sys call */ -#define dprintf_level(level, ...) \ -do { \ - if ((level) <= tahead_get_trace_level()) { \ - _dprintf_uta(__func__, __LINE__, level, STR_TRACE_USER_TA, __VA_ARGS__); \ - } \ -} while (0) - -/* Formmated trace tagged with TRACE_ALWAYS level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_ALWAYS) -#define AMSG(...) (void)0 -#else -#define AMSG(...) _dprintf_uta(__func__, __LINE__, TRACE_ALWAYS, STR_TRACE_USER_TA, __VA_ARGS__); -#endif - -/* Formmated trace tagged with TRACE_ERROR level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_ERROR) -#define EMSG(...) (void)0 -#else -#define EMSG(...) dprintf_level(TRACE_ERROR, __VA_ARGS__) -#endif - -/* Formmated trace tagged with TRACE_INFO level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_INFO) -#define IMSG(...) (void)0 -#else -#define IMSG(...) dprintf_level(TRACE_INFO, __VA_ARGS__) -#endif - -/* Formmated trace tagged with TRACE_DEBUG level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_INFO) -#define DMSG(...) (void)0 -#else -#define DMSG(...) dprintf_level(TRACE_DEBUG, __VA_ARGS__) -#endif - -/* Formmated trace tagged with TRACE_FLOW level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_FLOW) -#define FMSG(...) (void)0 -#else -#define FMSG(...) dprintf_level(TRACE_FLOW, __VA_ARGS__) -#endif - -/* Formmated trace tagged with TRACE_FLOW level and prefix with '> ' */ -#define INMSG(...) FMSG("> " __VA_ARGS__) -/* Formmated trace tagged with TRACE_FLOW level and prefix with '< ' */ -#define OUTMSG(...) FMSG("< " __VA_ARGS__) -/* Formmated trace tagged with TRACE_FLOW level and prefix with '< ' and print an - * error message if r != 0 */ -#define OUTRMSG(r) \ -do { \ - OUTMSG("r=[%lx]", r); \ - return r; \ -} while (0); - -/*****************************************************************************/ -/* Trace api without trace formatting */ - -/* Filtering and call backend method. - * Retrieve the ta level strored at kernel side by a sys call */ -#define dprintf_raw(level, ...) \ -do { \ - if ((level) <= tahead_get_trace_level()) { \ - _dprintf_uta(NULL, 0, level, STR_TRACE_USER_TA, __VA_ARGS__); \ - } \ -} while (0) - -/* No formatted trace tagged with TRACE_ALWAYS level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_ALWAYS) -#define AMSG_RAW(...) (void)0 -#else -#define AMSG_RAW(...) _dprintf_uta(NULL, 0, TRACE_ALWAYS, STR_TRACE_USER_TA, __VA_ARGS__) -#endif - -/* No formatted trace tagged with TRACE_ERROR level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_ERROR) -#define EMSG_RAW(...) (void)0 -#else -#define EMSG_RAW(...) dprintf_raw(TRACE_ERROR, __VA_ARGS__) -#endif - -/* No formatted trace tagged with TRACE_INFO level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_INFO) -#define IMSG_RAW(...) (void)0 -#else -#define IMSG_RAW(...) dprintf_raw(TRACE_INFO, __VA_ARGS__) -#endif - -/* No formatted trace tagged with TRACE_DEBUG level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_DEBUG) -#define DMSG_RAW(...) (void)0 -#else -#define DMSG_RAW(...) dprintf_raw(TRACE_DEBUG, __VA_ARGS__) -#endif - -/* No formatted trace tagged with TRACE_FLOW level */ -#if (CFG_TEE_TA_LOG_LEVEL < TRACE_FLOW) -#define FMSG(...) (void)0 -#else -#define FMSG_RAW(...) dprintf_raw(TRACE_FLOW, __VA_ARGS__) -#endif - -/*****************************************************************************/ - -#endif /* TEE_UTA_TRACE_H */ diff --git a/lib/libutee/include/utee_syscalls.h b/lib/libutee/include/utee_syscalls.h index eec514cd..88d4fb2e 100644 --- a/lib/libutee/include/utee_syscalls.h +++ b/lib/libutee/include/utee_syscalls.h @@ -33,7 +33,7 @@ #include <utee_types.h> #include <tee_api_types.h> -#include <tee_trace.h> +#include <trace.h> void utee_return(uint32_t ret) __noreturn; diff --git a/lib/libutee/sub.mk b/lib/libutee/sub.mk index 5e33c844..7401060a 100644 --- a/lib/libutee/sub.mk +++ b/lib/libutee/sub.mk @@ -3,7 +3,7 @@ global-incdirs-y += include srcs-y += tee_api_property.c srcs-y += tee_user_mem.c srcs-y += abort.c -srcs-y += ta_trace.c +srcs-y += trace_ext.c srcs-y += assert.c srcs-y += base64.c srcs-y += tee_api_arith.c diff --git a/lib/libutee/ta_trace.c b/lib/libutee/ta_trace.c deleted file mode 100644 index 4e80891f..00000000 --- a/lib/libutee/ta_trace.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2014, STMicroelectronics International N.V. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#if (CFG_TEE_TA_LOG_LEVEL > 0) -#include <stdio.h> -#include <stdarg.h> -#include <string.h> - -#include <tee_internal_api_extensions.h> -#include <user_ta_header.h> -#include <utee_syscalls.h> -#include "utee_misc.h" - -/*****************************************************************************/ - -static const char *const trace_level_strings[] = { - "NONE", "ALW", "ERR", "INF", "DBG", "FLW" -}; - -static const char failed[] = "uta trace failed"; - -/*****************************************************************************/ - -/* Format trace of user ta. Inline with kernel ta */ -static int format_trace(const char *function, int line, int level, - const char *prefix, const char *in, char *out) -{ - const char *func; - int nb_char = MAX_PRINT_SIZE; - - if (function) { -#ifdef TRACE_FUNC_LENGTH_CST - char func_buf[MAX_FUNC_PRINT_SIZE]; - int flen = strlen(function); - - /* Limit the function name to MAX_FUNC_PRINT_SIZE characters. */ - strncpy(func_buf, function, flen > MAX_FUNC_PRINT_SIZE ? - (MAX_FUNC_PRINT_SIZE - 1) : flen); - if (flen < (MAX_FUNC_PRINT_SIZE - 1)) { - memset(func_buf + flen, 0x20, - (MAX_FUNC_PRINT_SIZE - flen)); - } - func_buf[MAX_FUNC_PRINT_SIZE - 1] = '\0'; - func = func_buf; -#else - func = function; -#endif - nb_char = - snprintf(out, MAX_PRINT_SIZE, "%s [%p] %s:%s:%d: %s\n", - trace_level_strings[level], - (void *)utee_get_ta_exec_id(), prefix, func, line, - in); - } else { - /* copy buffer and insure '\n' terminated, before '\0' */ - memcpy(out, in, MAX_PRINT_SIZE); - *(out + MAX_PRINT_SIZE - 1) = '\0'; - nb_char = strlen(out); - if (nb_char == (MAX_PRINT_SIZE - 2)) { - *(out + (MAX_PRINT_SIZE - 2)) = '\n'; - } else if (*(out + nb_char - 1) != '\n') { - *(out + nb_char) = '\n'; - *(out + nb_char + 1) = '\0'; - } - } - return nb_char; -} - -/* To be call from user side */ -int _dprintf_uta(const char *function, int line, int level, const char *prefix, - const char *fmt, ...) -{ - char to_format[MAX_PRINT_SIZE]; - char formatted[MAX_PRINT_SIZE]; - char trunc[] = "...\n"; - va_list ap; - int s; - - va_start(ap, fmt); - s = vsnprintf(to_format, sizeof(to_format), fmt, ap); - va_end(ap); - - if (s < 0) { - utee_log(failed, strlen(failed) + 1); - return s; - } - if (((unsigned int)s >= sizeof(to_format)) && - (MAX_PRINT_SIZE > sizeof(trunc))) - memcpy(&to_format[sizeof(to_format) - sizeof(trunc)], trunc, - sizeof(trunc)); - - /* Format trace at user side */ - s = format_trace(function, line, level, prefix, to_format, formatted); - - /* sys call */ - utee_log(formatted, strlen(formatted) + 1); - - return s; -} - -/* - * printf and puts - stdio printf support - * - * 'printf()' and 'puts()' traces have the 'info' trace level. - * Traces are prefixed with string "[ta log] ". - */ -int printf(const char *fmt, ...) -{ - char to_format[MAX_PRINT_SIZE]; - char prefix[] = "[ta log] "; - char trunc[] = "...\n"; - va_list ap; - int s; - - if (tahead_get_trace_level() <= TRACE_PRINTF_LEVEL) - return 0; - - s = snprintf(to_format, sizeof(to_format), "%s", prefix); - if (s < 0) { - utee_log(failed, strlen(failed) + 1); - return s; - } - if ((unsigned int)s >= sizeof(to_format)) { - utee_log(failed, strlen(failed) + 1); - return 0; - } - - va_start(ap, fmt); - s = vsnprintf(to_format + s, sizeof(to_format) - s, fmt, ap); - va_end(ap); - - if (s < 0) { - utee_log(failed, strlen(failed) + 1); - return s; - } - if (((unsigned int)s >= (sizeof(to_format) - strlen(prefix)))) { - memcpy(&to_format[sizeof(to_format) - sizeof(trunc)], trunc, - sizeof(trunc)); - s = sizeof(to_format) - sizeof(prefix) - sizeof(trunc); - } - - /* sys call */ - utee_log(to_format, strlen(to_format) + 1); - - return s; -} - -int puts(const char *str) -{ - return printf("%s", str); -} - -#else /* CFG_TEE_TA_LOG_LEVEL */ -#include <tee_internal_api_extensions.h> -#include <compiler.h> -int printf(const char *fmt __unused, ...) -{ - return 0; -} - -int puts(const char *str __unused) -{ - return 0; -} -#endif /* CFG_TEE_TA_LOG_LEVEL */ diff --git a/lib/libutee/tee_user_mem.c b/lib/libutee/tee_user_mem.c index 9845b774..d09ffe2d 100644 --- a/lib/libutee/tee_user_mem.c +++ b/lib/libutee/tee_user_mem.c @@ -160,11 +160,11 @@ static int is_buffer_valid(void *buffer) /* * Common print of an element. */ -#if (CFG_TEE_TA_LOG_LEVEL > 0) +#if (CFG_TRACE_LEVEL > 0) static void print_buf(int tl, const char *func, int line, const char *prefix, const struct user_mem_elem *e) { - dprintf_raw(tl, "%s:%d: %slink:[%p], buf:[%p:%d]\n", + trace_printf(NULL, 0, tl, false, "%s:%d: %slink:[%p], buf:[%p:%d]\n", func, line, prefix, (void *)e, buf_addr(e), buf_size(e)); } @@ -506,11 +506,11 @@ void tee_user_mem_status(struct tee_user_mem_stats *stats) if (stats != NULL) memcpy(stats, &global_stats, sizeof(struct tee_user_mem_stats)); - AMSG("Nb alloc:\t[%d]", global_stats.nb_alloc); - AMSG("Size:\t[%d]", global_stats.size); + EMSG("Nb alloc:\t[%d]", global_stats.nb_alloc); + EMSG("Size:\t[%d]", global_stats.size); TAILQ_FOREACH(e, &user_mem_head, link) { - PB(TRACE_ALWAYS, "", e); + PB(TRACE_ERROR, "", e); } } #else diff --git a/lib/libutee/trace_ext.c b/lib/libutee/trace_ext.c new file mode 100644 index 00000000..2b197374 --- /dev/null +++ b/lib/libutee/trace_ext.c @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2014, STMicroelectronics International N.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#include <string_ext.h> +#include <trace.h> +#include <util.h> +#include <utee_syscalls.h> + +#if CFG_TRACE_LEVEL > 0 + +const char trace_ext_prefix[] = "USER-TA"; + +void trace_ext_puts(bool sync __unused, const char *str) +{ + utee_log(str, strlen(str)); +} + +int trace_ext_get_thread_id(void) +{ + return -1; +} + + +/* + * printf and puts - stdio printf support + * + * 'printf()' and 'puts()' traces have the 'info' trace level. + * Traces are prefixed with string "[ta log] ". + */ +int printf(const char *fmt, ...) +{ + char to_format[MAX_PRINT_SIZE]; + static const char prefix[] = "[ta log] "; + static const char failed[] = "uta trace failed"; + static const char trunc[] = "...\n"; + va_list ap; + int s; + + if (trace_get_level() <= TRACE_PRINTF_LEVEL) + return 0; + + s = strlcpy(to_format, prefix, sizeof(to_format)); + if ((unsigned int)s >= sizeof(to_format)) { + puts(failed); + return 0; + } + + va_start(ap, fmt); + s = vsnprintf(to_format + s, sizeof(to_format) - s, fmt, ap); + va_end(ap); + + if (s < 0) { + puts(failed); + return s; + } + if (((unsigned int)s >= (sizeof(to_format) - strlen(prefix)))) { + memcpy(&to_format[sizeof(to_format) - sizeof(trunc)], trunc, + sizeof(trunc)); + s = sizeof(to_format) - sizeof(prefix) - sizeof(trunc); + } + + puts(to_format); + + return s; +} + +int puts(const char *str) +{ + if (trace_get_level() > TRACE_PRINTF_LEVEL) + trace_ext_puts(false, str); + return 1; +} + + + +#else + +int printf(const char *fmt __unused, ...) +{ + return 0; +} + +int puts(const char *str __unused) +{ + return 0; +} +# + +#endif diff --git a/lib/libutils/ext/include/trace.h b/lib/libutils/ext/include/trace.h new file mode 100644 index 00000000..1a9205bb --- /dev/null +++ b/lib/libutils/ext/include/trace.h @@ -0,0 +1,161 @@ +/* + * Copyright (c) 2014, STMicroelectronics International N.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef TRACE_H +#define TRACE_H + +#include <stdbool.h> +#include <stddef.h> +#include <compiler.h> +#include <trace_levels.h> + +#define MAX_PRINT_SIZE 256 +#define MAX_FUNC_PRINT_SIZE 32 + +#ifndef CFG_TRACE_LEVEL +#define CFG_TRACE_LEVEL TRACE_MAX +#endif + +/* + * Symbols provided by the entity that uses this API. + */ +extern const char trace_ext_prefix[]; +void trace_ext_puts(bool sync, const char *str); +int trace_ext_get_thread_id(void); + +/* Internal functions used by the macros below */ +void trace_printf(const char *func, int line, int level, bool sync, + const char *fmt, ...) __printf(5, 6); + +#define trace_printf_helper(level, ...) \ + trace_printf(__func__, __LINE__, (level), false, __VA_ARGS__) + +/* Formatted trace tagged with TRACE_ERROR level */ +#if (CFG_TRACE_LEVEL < TRACE_ERROR) +#define EMSG(...) (void)0 +#else +#define EMSG(...) trace_printf_helper(TRACE_ERROR, __VA_ARGS__) +#endif + +/* Formatted trace tagged with TRACE_INFO level */ +#if (CFG_TRACE_LEVEL < TRACE_INFO) +#define IMSG(...) (void)0 +#else +#define IMSG(...) trace_printf_helper(TRACE_INFO, __VA_ARGS__) +#endif + +/* Formatted trace tagged with TRACE_DEBUG level */ +#if (CFG_TRACE_LEVEL < TRACE_DEBUG) +#define DMSG(...) (void)0 +#else +#define DMSG(...) trace_printf_helper(TRACE_DEBUG, __VA_ARGS__) +#endif + +/* Formatted trace tagged with TRACE_FLOW level */ +#if (CFG_TRACE_LEVEL < TRACE_FLOW) +#define FMSG(...) (void)0 +#else +#define FMSG(...) trace_printf_helper(TRACE_FLOW, __VA_ARGS__) +#endif + +/* Formatted trace tagged with TRACE_FLOW level and prefix with '> ' */ +#define INMSG(...) FMSG("> " __VA_ARGS__) +/* Formatted trace tagged with TRACE_FLOW level and prefix with '< ' */ +#define OUTMSG(...) FMSG("< " __VA_ARGS__) +/* Formatted trace tagged with TRACE_FLOW level and prefix with '< ' and print + * an error message if r != 0 */ +#define OUTRMSG(r) \ + do { \ + OUTMSG("r=[%x]", r); \ + return r; \ + } while (0) + +#if (CFG_TRACE_LEVEL < TRACE_DEBUG) +#define DHEXDUMP(buf, len) (void)0 +#else +#define DHEXDUMP(buf, len) dhex_dump(__func__, __LINE__, TRACE_DEBUG, \ + buf, len) +void dhex_dump(const char *function, int line, int level, + const void *buf, int len); +#endif + +/*****************************************************************************/ +/* Trace api without trace formatting */ + +/* No formatted trace tagged with TRACE_ERROR level */ +#if (CFG_TRACE_LEVEL < TRACE_ERROR) +#define EMSG_RAW(...) (void)0 +#else +#define EMSG_RAW(...) trace_printf(NULL, 0, TRACE_ERROR, false, __VA_ARGS__) +#endif + +/* No formatted trace tagged with TRACE_INFO level */ +#if (CFG_TRACE_LEVEL < TRACE_INFO) +#define IMSG_RAW(...) (void)0 +#else +#define IMSG_RAW(...) trace_printf(NULL, 0, TRACE_INFO, false, __VA_ARGS__) +#endif + +/* No formatted trace tagged with TRACE_DEBUG level */ +#if (CFG_TRACE_LEVEL < TRACE_DEBUG) +#define DMSG_RAW(...) (void)0 +#else +#define DMSG_RAW(...) trace_printf(NULL, 0, TRACE_DEBUG, false, __VA_ARGS__) +#endif + +/* No formatted trace tagged with TRACE_FLOW level */ +#if (CFG_TRACE_LEVEL < TRACE_FLOW) +#define FMSG_RAW(...) (void)0 +#else +#define FMSG_RAW(...) trace_printf(NULL, 0, TRACE_FLOW, false, __VA_ARGS__) +#endif + +#if (CFG_TRACE_LEVEL == 0) +#define SMSG(...) (void)0 +static inline void trace_set_level(int level __unused) +{ +} + +static inline int trace_get_level(void) +{ + return 0; +} +#else +/* + * Synchronised flushed trace, an Always message straight to HW trace IP. + * Current only supported inside OP-TEE kernel, will be just like an EMSG() + * in another context. + */ +#define SMSG(...) \ + trace_printf(__func__, __LINE__, TRACE_ERROR, true, __VA_ARGS__) + +/* Accessors */ +void trace_set_level(int level); +int trace_get_level(void); + +#endif /* CFG_TRACE_LEVEL */ + +#endif /* TRACE_H */ diff --git a/lib/libutee/include/tee_trace_levels.h b/lib/libutils/ext/include/trace_levels.h index eba74ddc..22c7144d 100644 --- a/lib/libutee/include/tee_trace_levels.h +++ b/lib/libutils/ext/include/trace_levels.h @@ -24,9 +24,8 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ - -#ifndef TEE_TRACE_LEVELS_H -#define TEE_TRACE_LEVELS_H +#ifndef TRACE_LEVELS_H +#define TRACE_LEVELS_H /* * Trace levels. @@ -47,14 +46,13 @@ */ #define TRACE_MIN 1 -#define TRACE_ALWAYS TRACE_MIN -#define TRACE_ERROR 2 -#define TRACE_INFO 3 -#define TRACE_DEBUG 4 -#define TRACE_FLOW 5 +#define TRACE_ERROR TRACE_MIN +#define TRACE_INFO 2 +#define TRACE_DEBUG 3 +#define TRACE_FLOW 4 #define TRACE_MAX TRACE_FLOW /* Trace level of the casual printf */ -#define TRACE_PRINTF_LEVEL TRACE_ALWAYS +#define TRACE_PRINTF_LEVEL TRACE_ERROR -#endif /* TEE_TRACE_LEVELS_H */ +#endif /*TRACE_LEVELS_H*/ diff --git a/lib/libutils/ext/sub.mk b/lib/libutils/ext/sub.mk index e065ee93..203bbca4 100644 --- a/lib/libutils/ext/sub.mk +++ b/lib/libutils/ext/sub.mk @@ -3,3 +3,4 @@ global-incdirs-y += include srcs-y += strlcat.c srcs-y += strlcpy.c srcs-y += buf_compare_ct.c +srcs-y += trace.c diff --git a/lib/libutils/ext/trace.c b/lib/libutils/ext/trace.c new file mode 100644 index 00000000..0040ec20 --- /dev/null +++ b/lib/libutils/ext/trace.c @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2014, STMicroelectronics International N.V. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#include <trace.h> +#include <util.h> + +#if (CFG_TRACE_LEVEL != 0) + +#if (CFG_TRACE_LEVEL < TRACE_MIN) || (CFG_TRACE_LEVEL > TRACE_MAX) +#error "Invalid value of CFG_TRACE_LEVEL" +#endif +static int trace_level = CFG_TRACE_LEVEL; + +void trace_set_level(int level) +{ + if (((int)level >= TRACE_MIN) && (level <= TRACE_MAX)) + trace_level = level; + else + trace_level = TRACE_MAX; +} + +int trace_get_level(void) +{ + return trace_level; +} + +static const char *trace_level_to_string(int level) +{ + static const char lvl_strs[][4] = { + "UKN", "ERR", "INF", "DBG", "FLW" }; + int l = 0; + + if (l >= TRACE_MIN || l <= TRACE_MAX) + l = level; + + return lvl_strs[l]; +} + +/* Format trace of user ta. Inline with kernel ta */ +void trace_printf(const char *function, int line, int level, bool sync, + const char *fmt, ...) +{ + va_list ap; + char buf[MAX_PRINT_SIZE]; + size_t boffs = 0; + int res; + + if (level > trace_level) + return; + + if (function) { + int thread_id = trace_ext_get_thread_id(); + + if (thread_id >= 0) + res = snprintf(buf, sizeof(buf), "%s [0x%x] %s:%s:%d: ", + trace_level_to_string(level), thread_id, + trace_ext_prefix, function, line); + else + res = snprintf(buf, sizeof(buf), "%s %s:%s:%d: ", + trace_level_to_string(level), + trace_ext_prefix, function, line); + if (res < 0) + return; /* "Can't happen" */ + boffs = res; + } + + va_start(ap, fmt); + res = vsnprintf(buf + boffs, sizeof(buf) - boffs, fmt, ap); + va_end(ap); + if (res > 0) + boffs += res; + + if (boffs >= sizeof(buf)) { + boffs = sizeof(buf) - 2; + /* Make there's a newline at the end */ + buf[boffs] = '\n'; + } else if (buf[boffs - 1] != '\n') { + /* Append a newline */ + buf[boffs] = '\n'; + buf[boffs + 1] = '\0'; + } + + trace_ext_puts(sync, buf); +} +#endif + +#if (CFG_TRACE_LEVEL >= TRACE_DEBUG) +struct strbuf { + char buf[MAX_PRINT_SIZE]; + char *ptr; +}; + +static int __printf(2, 3) append(struct strbuf *sbuf, const char *fmt, ...) +{ + int left; + int len; + va_list ap; + + if (sbuf->ptr == NULL) + sbuf->ptr = sbuf->buf; + left = sizeof(sbuf->buf) - (sbuf->ptr - sbuf->buf); + va_start(ap, fmt); + len = vsnprintf(sbuf->ptr, left, fmt, ap); + va_end(ap); + if (len < 0) { + /* Format error */ + return 0; + } + if (len >= left) { + /* Output was truncated */ + return 0; + } + sbuf->ptr += MIN(left, len); + return 1; +} + +void dhex_dump(const char *function, int line, int level, + const void *buf, int len) +{ + int i; + int ok; + struct strbuf sbuf; + char *in = (char *)buf; + + if (level <= trace_level) { + sbuf.ptr = NULL; + for (i = 0; i < len; i++) { + ok = append(&sbuf, "%02x ", in[i]); + if (!ok) + goto err; + if ((i % 16) == 7) { + ok = append(&sbuf, " "); + if (!ok) + goto err; + } else if ((i % 16) == 15) { + trace_printf(function, line, level, false, + "%s", sbuf.buf); + sbuf.ptr = NULL; + } + } + if (sbuf.ptr) { + /* Buffer is not empty: flush it */ + trace_printf(function, line, level, false, "%s", + sbuf.buf); + + } + } + return; +err: + DMSG("Hex dump error"); +} +#endif diff --git a/lib/libutils/isoc/dlmalloc.c b/lib/libutils/isoc/dlmalloc.c index a610be27..c3d89ff6 100644 --- a/lib/libutils/isoc/dlmalloc.c +++ b/lib/libutils/isoc/dlmalloc.c @@ -3,7 +3,7 @@ * config not revelant to exported dlmalloc.h header are defined below. */ /* redirect fprintf(stderr, ...) to teecore trace */ -#include <kernel/tee_core_trace.h> +#include <trace.h> #define fprintf(h, fmt, ...) IMSG(fmt, __VA_ARGS__) #include "dlmalloc.h" diff --git a/lib/libutils/isoc/malloc_wrapper.c b/lib/libutils/isoc/malloc_wrapper.c index a29abbe2..d258f637 100644 --- a/lib/libutils/isoc/malloc_wrapper.c +++ b/lib/libutils/isoc/malloc_wrapper.c @@ -33,7 +33,7 @@ #include <stdlib.h> #include <string.h> #include <assert.h> -#include <kernel/tee_core_trace.h> +#include <trace.h> #include <sys/queue.h> #ifdef TEE_USE_DLMALLOC diff --git a/ta/arch/arm32/user_ta_header.c b/ta/arch/arm32/user_ta_header.c index 120b40f1..85402654 100644 --- a/ta/arch/arm32/user_ta_header.c +++ b/ta/arch/arm32/user_ta_header.c @@ -29,10 +29,10 @@ #include <tee_internal_api_extensions.h> #include <user_ta_header.h> #include <user_ta_header_defines.h> -#include <tee_uta_trace.h> +#include <trace.h> #ifndef TA_TRACE_LEVEL_DEFAULT -#define TA_TRACE_LEVEL_DEFAULT CFG_TEE_TA_LOG_LEVEL +#define TA_TRACE_LEVEL_DEFAULT CFG_TRACE_LEVEL #endif /* exprted to user_ta_header.c, built within TA */ @@ -9,7 +9,7 @@ cflags$(sm) += $(platform-cflags) $(user_ta-platform-cflags) aflags$(sm) += $(platform-aflags) $(user_ta-platform-aflags) # Config flags from mk/config.mk -cppflags$(sm) += -DCFG_TEE_TA_LOG_LEVEL=$(CFG_TEE_TA_LOG_LEVEL) +cppflags$(sm) += -DCFG_TRACE_LEVEL=$(CFG_TEE_TA_LOG_LEVEL) cppflags$(sm) += -DCFG_TEE_CORE_USER_MEM_DEBUG=$(CFG_TEE_CORE_USER_MEM_DEBUG) |