ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_nsc_log.c File Reference

NSC veneer: secure-side logging. More...

#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_check.h"
#include "ra8_err.h"
#include "ra8_log.h"
#include "ra8_nsc.h"
#include "ra8_nsc_veneer.h"
Include dependency graph for ra8_nsc_log.c:

Go to the source code of this file.

Functions

static void internal_safe_strcpy (char *dst, const char *src, uint32_t cap)
 Length-bounded string copy with NUL terminator.
ra8_err_t ra8_nsc_log_emit (const char *tag, const char *message)
 NSC veneer: emit a log line from Non-Secure code.

Variables

static const char * s_tag = "NSCLOG"
static char s_tag_scratch [k_ra8_nsc_log_msg_max_len]
 Secure scratch for the (tag, message) copy.
static char s_msg_scratch [k_ra8_nsc_log_msg_max_len]

Detailed Description

NSC veneer: secure-side logging.

Tag
[Ring 4 / NSC] {World: NSC}

scaffold. Forwards the (tag, message) pair to ra8_log_info after copying both strings into a small secure-side scratch area to make sure the secure code never dereferences NS pointers directly.

Definition in file ra8_nsc_log.c.

Function Documentation

◆ internal_safe_strcpy()

void internal_safe_strcpy ( char * dst,
const char * src,
uint32_t cap )
static

Length-bounded string copy with NUL terminator.

Copies up to cap-1 bytes from src into dst and always writes a terminating NUL.

Parameters
[out]dstDestination buffer (must hold cap bytes).
[in]srcSource NUL-terminated string.
[in]capCapacity of dst in bytes; must be >= 1.
Precondition
dst and src non-NULL.
cap >= 1.
Postcondition
dst is NUL-terminated.
At most cap-1 source bytes are copied.
Note
Static helper; not thread-safe.
Since
0.1.0

Definition at line 60 of file ra8_nsc_log.c.

Referenced by ra8_nsc_log_emit().

◆ ra8_nsc_log_emit()

ra8_err_t ra8_nsc_log_emit ( const char * tag,
const char * message )
nodiscard

NSC veneer: emit a log line from Non-Secure code.

NSC veneer: emit a log line via the secure ITM channel.

Copies (tag,message) into secure scratch buffers and forwards to ra8_log_info.

Parameters
[in]tagNUL-terminated NS string (subsystem tag).
[in]messageNUL-terminated NS string (log message body).
Returns
ra8_err_t outcome.
Return values
k_ra8_okMessage handed to the secure logger.
k_ra8_err_null_ptrA pointer argument was NULL.
Precondition
TrustZone substrate has been initialized.
Both strings reside in the NS data region.
Postcondition
Tag/message copied into secure scratch and forwarded.
Strings truncated to k_ra8_nsc_log_msg_max_len-1 if longer.
Note
Thread-safe: no; the secure scratch is shared.
Since
0.1.0

Definition at line 94 of file ra8_nsc_log.c.

References internal_safe_strcpy(), k_ra8_nsc_log_msg_max_len, k_ra8_ok, RA8_CHECK_NULL_PTR, ra8_log_info, RA8_NSC_CHECK_NS_RANGE_R, RA8_NSC_VENEER, s_msg_scratch, s_tag, and s_tag_scratch.

Referenced by internal_sys_thread_entry(), internal_ui_thread_entry(), ns_reset_handler(), ui_thread_entry(), and work_thread_entry().

Variable Documentation

◆ s_msg_scratch

char s_msg_scratch[k_ra8_nsc_log_msg_max_len]
static

Definition at line 39 of file ra8_nsc_log.c.

Referenced by ra8_nsc_log_emit().

◆ s_tag

const char* s_tag = "NSCLOG"
static

Definition at line 27 of file ra8_nsc_log.c.

◆ s_tag_scratch

char s_tag_scratch[k_ra8_nsc_log_msg_max_len]
static

Secure scratch for the (tag, message) copy.

Living in the secure data section, this buffer is updated before each ra8_log_info call so the secure code never has to read from a Non-Secure pointer.

Definition at line 38 of file ra8_nsc_log.c.

Referenced by ra8_nsc_log_emit().