Skip to content

Commit 16f2951

Browse files
jackson-cooperdstgloorious
authored andcommitted
LIB: Add with_marker argument to tfm_vprintf
The underlying tfm_vprintf function can now be called tfm_vprintf_unpriv, which is called from the runtime FW vprintf implementation. This function will be called without a marker character at the beginning of the string and therefore will cause an assertion to be triggered within the vprintf implementation. Add a new argument which specifies whether or not there is a marker character. Change-Id: I58bc8cfa44f348766408d6e1fcf3fa995c3f6131 Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com> (cherry picked from commit b59d3fb) Signed-off-by: Stefan Gloor <stefan.gloor@siemens.com>
1 parent 5205c3a commit 16f2951

File tree

4 files changed

+25
-16
lines changed

4 files changed

+25
-16
lines changed

lib/tfm_log/src/tfm_log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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
*
@@ -23,6 +23,6 @@ void tfm_log(const char *fmt, ...)
2323
va_list args;
2424

2525
va_start(args, fmt);
26-
tfm_vprintf(output_log, NULL, fmt, args);
26+
tfm_vprintf(output_log, NULL, fmt, args, true);
2727
va_end(args);
2828
}

lib/tfm_log_unpriv/src/tfm_log_unpriv.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,30 @@ static void output_string_to_buf(void *priv, const char *str, uint32_t len)
5353
data->buf_pos += len;
5454
}
5555

56-
int tfm_vprintf_unpriv(const char *fmt, va_list args)
56+
static int vprintf_output_buffer(const char *fmt, va_list args, bool with_marker)
5757
{
5858
struct tfm_log_unpriv_data data;
5959

6060
data.buf_pos = 0;
6161
data.total_output_chars = 0;
6262

63-
tfm_vprintf(output_string_to_buf, &data, fmt, args);
63+
tfm_vprintf(output_string_to_buf, &data, fmt, args, with_marker);
6464

6565
output_buf(&data, data.buf_pos);
6666

6767
return data.total_output_chars;
6868
}
6969

70+
int tfm_vprintf_unpriv(const char *fmt, va_list args)
71+
{
72+
return vprintf_output_buffer(fmt, args, false);
73+
}
74+
7075
void tfm_log_unpriv(const char *fmt, ...)
7176
{
7277
va_list args;
7378

7479
va_start(args, fmt);
75-
tfm_vprintf_unpriv(fmt, args);
80+
vprintf_output_buffer(fmt, args, true);
7681
va_end(args);
7782
}

lib/tfm_vprintf/inc/tfm_vprintf_priv.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <stdint.h>
1212
#include <stdarg.h>
13+
#include <stdbool.h>
1314

1415
/**
1516
* \typedef tfm_log_output_str
@@ -35,10 +36,12 @@ typedef void (*tfm_log_output_str)(void *priv, const char *str, uint32_t len);
3536
*
3637
* \param[in] output_func Pointer to the output function that handles the formatted string.
3738
* \param[in] priv Pointer to user-defined context, passed to the output function.
38-
* \param[in] fmt Format string specifying how to format the output. This is expected
39-
* to begin with a MARKER character.
39+
* \param[in] fmt Format string specifying how to format the output.
4040
* \param[in] args Variable argument list to match the format string.
41+
* \param[in] with_marker Whether or not the fmt string starts with a MARKER character.
42+
* This is expected to be used for standard logging use cases.
4143
*/
42-
void tfm_vprintf(tfm_log_output_str output_func, void *priv, const char *fmt, va_list args);
44+
void tfm_vprintf(tfm_log_output_str output_func, void *priv, const char *fmt, va_list args,
45+
bool with_marker);
4346

4447
#endif /* __TF_M_VPRINTF_PRIV_H__ */

lib/tfm_vprintf/src/tfm_vprintf.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,19 @@ static void tfm_vprintf_internal(tfm_log_output_str output_func,
214214
}
215215
}
216216

217-
void tfm_vprintf(tfm_log_output_str output_func, void *priv, const char *fmt, va_list args)
217+
void tfm_vprintf(tfm_log_output_str output_func, void *priv, const char *fmt, va_list args,
218+
bool with_marker)
218219
{
219220
uint8_t log_marker;
220221
const char spacer = ' ';
221222

222-
/* We expect the LOG_MARKER_* macro as the first character */
223-
log_marker = fmt[0];
224-
fmt++;
225-
226-
if (log_marker != LOG_RAW_VALUE) {
227-
output_str_not_formatted(output_func, priv, get_log_prefix(log_marker));
228-
output_char(output_func, priv, spacer);
223+
if (with_marker) {
224+
log_marker = fmt[0];
225+
fmt++;
226+
if (log_marker != LOG_RAW_VALUE) {
227+
output_str_not_formatted(output_func, priv, get_log_prefix(log_marker));
228+
output_char(output_func, priv, spacer);
229+
}
229230
}
230231

231232
tfm_vprintf_internal(output_func, priv, fmt, args);

0 commit comments

Comments
 (0)