Skip to content

Commit 8070ad9

Browse files
jackson-cooperdstgloorious
authored andcommitted
LIB: Return total printed chars from vprintf
The vprintf implementation in crt_vprintf.c should return the number of characters printed (as that is the standard signature of vprintf). Rework the tfm_vprintf_unpriv implementation to count the number of characters printed to the UART and return them. Change-Id: I26f9f4efdede685c1e82294859ef3ce1fcf45fcd Signed-off-by: Jackson Cooper-Driver <jackson.cooper-driver@arm.com> (cherry picked from commit b311830) Signed-off-by: Stefan Gloor <stefan.gloor@siemens.com>
1 parent 854f7ec commit 8070ad9

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

lib/tfm_log_unpriv/inc/tfm_vprintf_unpriv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
#include <stdarg.h>
1212

13-
void tfm_vprintf_unpriv(const char *fmt, va_list args);
13+
int tfm_vprintf_unpriv(const char *fmt, va_list args);
1414

1515
#endif /* __TFM_VPRINTF_UNPRIV_H__ */

lib/tfm_log_unpriv/src/tfm_log_unpriv.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@
1717

1818
struct tfm_log_unpriv_data {
1919
uint8_t buf_pos;
20+
size_t total_output_chars;
2021
char buf[LOG_UNPRIV_BUFFER_SIZE];
2122
};
2223

23-
static void output_buf(const char *buf, uint32_t buf_len)
24+
static void output_buf(struct tfm_log_unpriv_data *data, uint32_t buf_len)
2425
{
25-
tfm_hal_output_sp_log(buf, buf_len);
26+
int32_t ret;
27+
28+
ret = tfm_hal_output_sp_log(data->buf, buf_len);
29+
if (ret > 0) {
30+
data->total_output_chars += ret;
31+
}
2632
}
2733

2834
static void output_string_to_buf(void *priv, const char *str, uint32_t len)
@@ -31,30 +37,33 @@ static void output_string_to_buf(void *priv, const char *str, uint32_t len)
3137

3238
if ((data->buf_pos + len) > LOG_UNPRIV_BUFFER_SIZE) {
3339
/* Flush current buffer and re-use */
34-
output_buf(data->buf, data->buf_pos);
40+
output_buf(data, data->buf_pos);
3541
data->buf_pos = 0;
3642

3743
/* Handle strings larger than buffer with multiple flushes */
3844
for (; len > LOG_UNPRIV_BUFFER_SIZE;
3945
len -= LOG_UNPRIV_BUFFER_SIZE, str += LOG_UNPRIV_BUFFER_SIZE) {
4046
memcpy(data->buf, str, LOG_UNPRIV_BUFFER_SIZE);
41-
output_buf(data->buf, LOG_UNPRIV_BUFFER_SIZE);
47+
output_buf(data, LOG_UNPRIV_BUFFER_SIZE);
4248
}
4349
}
4450

4551
memcpy(data->buf + data->buf_pos, str, len);
4652
data->buf_pos += len;
4753
}
4854

49-
void tfm_vprintf_unpriv(const char *fmt, va_list args)
55+
int tfm_vprintf_unpriv(const char *fmt, va_list args)
5056
{
5157
struct tfm_log_unpriv_data data;
5258

5359
data.buf_pos = 0;
60+
data.total_output_chars = 0;
5461

5562
tfm_vprintf(output_string_to_buf, &data, fmt, args);
5663

57-
output_buf(data.buf, data.buf_pos);
64+
output_buf(&data, data.buf_pos);
65+
66+
return data.total_output_chars;
5867
}
5968

6069
void tfm_log_unpriv(const char *fmt, ...)

secure_fw/partitions/lib/runtime/crt_vprintf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
int vprintf(const char *fmt, va_list args)
1212
{
13-
tfm_vprintf_unpriv(fmt, args);
13+
return tfm_vprintf_unpriv(fmt, args);
1414
}

0 commit comments

Comments
 (0)