Skip to content

Commit a69c7ee

Browse files
jackson-cooperdstgloorious
authored andcommitted
LIB: Use tfm_log for fatal error logging
Replace the existing implementation which used printf. Change-Id: Ie3e37eb905583c8793578bc138e6cc11222f378e Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com> (cherry picked from commit 182bcbf) Signed-off-by: Stefan Gloor <stefan.gloor@siemens.com>
1 parent cf67fee commit a69c7ee

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed
Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*
2-
* Copyright (c) 2024, Arm Limited. All rights reserved.
2+
* SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
66
*/
77

8-
#include <stdio.h>
8+
#include <stddef.h>
9+
#include <inttypes.h>
10+
#include "tfm_log.h"
911
#include "fatal_error.h"
1012
#include "tfm_hal_device_header.h"
1113
#include "uart_stdout.h"
@@ -15,31 +17,40 @@ __WEAK bool log_error_permissions_check(uint32_t err, bool is_fatal)
1517
return true;
1618
}
1719

20+
#define LOG_FATAL_NON_FATAL_ERR(_is_fatal, ...) \
21+
do { \
22+
if (_is_fatal) { \
23+
ERROR_RAW(__VA_ARGS__); \
24+
} else { \
25+
WARN_RAW(__VA_ARGS__); \
26+
} \
27+
} while (0);
28+
1829
__WEAK void log_error(char *file, uint32_t line, uint32_t err, void *sp, bool is_fatal)
1930
{
2031
if (stdio_is_initialized()) {
2132
if (is_fatal) {
22-
printf("[ERR] Fatal error ");
33+
ERROR("Fatal error ");
2334
} else {
24-
printf("[WRN] Non-fatal error ");
35+
WARN("Non-fatal error ");
2536
}
2637

2738
if (err != 0) {
28-
printf("%08X ", err);
39+
LOG_FATAL_NON_FATAL_ERR(is_fatal, "%08"PRIx32" ", err);
2940
}
3041

3142
if (file != NULL) {
32-
printf("in file %s ", file);
43+
LOG_FATAL_NON_FATAL_ERR(is_fatal, "in file %s ", file);
3344
}
3445

3546
if (line != 0) {
36-
printf("at line %u ", line);
47+
LOG_FATAL_NON_FATAL_ERR(is_fatal, "at line %"PRIu32" ", line);
3748
}
3849

3950
if (sp != NULL) {
40-
printf("with SP=%p ", sp);
51+
LOG_FATAL_NON_FATAL_ERR(is_fatal, "with SP=0x%"PRIx32" ", (uint32_t)sp);
4152
}
4253

43-
printf("\r\n");
54+
LOG_FATAL_NON_FATAL_ERR(is_fatal, "\n");
4455
}
4556
}

0 commit comments

Comments
 (0)