AuditLog: Non Secure interface
-- Add the NS API interface and related SVC functions
for the Audit Logging secure service.
-- Modify the example application to support the new
NS interface for the Audit Logging secure service.
Change-Id: I6158742585db19b58e45704f13a4e5b1b4557d69
Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
diff --git a/interface/include/tfm_log_api.h b/interface/include/tfm_log_api.h
new file mode 100644
index 0000000..24b73b4
--- /dev/null
+++ b/interface/include/tfm_log_api.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_LOG_API__
+#define __TFM_LOG_API__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "tfm_log_defs.h"
+
+/**
+ * \brief Retrieves the audit log
+ *
+ * \param[in] size Maximum number of bytes to retrieve from the log
+ * \param[out] buffer Pointer to the buffer that will hold the log
+ * \param[out] log_size Pointer to the actual size of the log retrieved
+ *
+ * \return Returns TFM_LOG_ERR_SUCCESS if retrieval has been completed,
+ * otherwise error as specified in \ref tfm_log_err
+ */
+enum tfm_log_err tfm_log_retrieve(uint32_t size,
+ uint8_t *buffer,
+ uint32_t *log_size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TFM_LOG_API__ */
diff --git a/interface/include/tfm_log_defs.h b/interface/include/tfm_log_defs.h
new file mode 100644
index 0000000..ccd779e
--- /dev/null
+++ b/interface/include/tfm_log_defs.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_LOG_DEFS_H__
+#define __TFM_LOG_DEFS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include "tfm_api.h"
+#include "limits.h"
+
+/* The return value is shared with the TFM partition status value. The LOG return
+ * codes shouldn't overlap with predefined TFM status values.
+ */
+#define TFM_LOG_ERR_OFFSET (TFM_PARTITION_SPECIFIC_ERROR_MIN)
+
+enum tfm_log_err {
+ TFM_LOG_ERR_SUCCESS = 0,
+ TFM_LOG_ERR_FAILURE = TFM_LOG_ERR_OFFSET,
+
+ /* Following entry is only to ensure the error code of int size */
+ TFM_LOG_ERR_FORCE_INT_SIZE = INT_MAX
+};
+
+/*!
+ * \struct tfm_log_line
+ *
+ * \brief The part of the log line which has to be
+ * provided by the secure service that wants
+ * to add information to the log
+ */
+struct tfm_log_line {
+ uint32_t size; /*!< Size in bytes of the three following fields */
+ uint32_t function_id; /*!< ID of the function requested */
+ uint32_t arg[4]; /*!< [r0,r1,r2,r3] arguments to the function */
+ uint8_t payload[]; /*!< Flexible array member for payload */
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TFM_LOG_DEFS_H__ */
diff --git a/interface/include/tfm_log_svc_handler.h b/interface/include/tfm_log_svc_handler.h
new file mode 100644
index 0000000..3e3b087
--- /dev/null
+++ b/interface/include/tfm_log_svc_handler.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_LOG_SVC_HANDLER_H__
+#define __TFM_LOG_SVC_HANDLER_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "tfm_log_defs.h"
+
+/**
+ * \brief Retrieves the audit log (SVC function)
+ *
+ * \param[in] size Maximum number of bytes to retrieve from the log
+ * \param[out] buffer Pointer to the buffer that will hold the log
+ * \param[out] log_size Pointer to the actual size of the log retrieved
+ *
+ * \return Returns TFM_LOG_ERR_SUCCESS if retrieval has been completed,
+ * otherwise error as specified in \ref tfm_log_err
+ */
+enum tfm_log_err tfm_log_svc_retrieve(uint32_t size,
+ uint8_t *buffer,
+ uint32_t *log_size);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TFM_LOG_SVC_HANDLER_H__ */
diff --git a/interface/include/tfm_log_veneers.h b/interface/include/tfm_log_veneers.h
new file mode 100644
index 0000000..f86f987
--- /dev/null
+++ b/interface/include/tfm_log_veneers.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __TFM_LOG_VENEERS_H__
+#define __TFM_LOG_VENEERS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include "tfm_log_defs.h"
+
+/**
+ * \brief Retrieves the audit log
+ *
+ * \param[in] size Maximum number of bytes to retrieve from the log
+ * \param[out] buffer Pointer to the buffer that will hold the log
+ * \param[out] log_size Pointer to the actual size of the log retrieved
+ *
+ * \return Returns TFM_LOG_ERR_SUCCESS if retrieval has been completed,
+ * otherwise error as specified in \ref tfm_log_err
+ */
+enum tfm_log_err tfm_log_veneer_retrieve(uint32_t size,
+ uint8_t *buffer,
+ uint32_t *log_size);
+/**
+ * \brief Adds a log entry
+ *
+ * \param[in] line Pointer to the line to be added. This memory must
+ * be accessible by the audit logging service.
+ *
+ * \return Returns TFM_LOG_ERR_SUCCESS if addition has been completed
+ * otherwise error as specified in \ref tfm_log_err
+ *
+ * \note This is a secure only callable API, NS calls will always
+ * return error
+ */
+enum tfm_log_err tfm_log_veneer_add_line(struct tfm_log_line *line);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TFM_LOG_VENEERS_H__ */
diff --git a/interface/include/tfm_ns_svc.h b/interface/include/tfm_ns_svc.h
index 4e4d731..b40b7c0 100644
--- a/interface/include/tfm_ns_svc.h
+++ b/interface/include/tfm_ns_svc.h
@@ -45,7 +45,8 @@
X(SVC_TFM_SST_GET_ATTRIBUTES, tfm_sst_svc_get_attributes) \
X(SVC_TFM_SST_READ, tfm_sst_svc_read) \
X(SVC_TFM_SST_WRITE, tfm_sst_svc_write) \
- X(SVC_TFM_SST_DELETE, tfm_sst_svc_delete)
+ X(SVC_TFM_SST_DELETE, tfm_sst_svc_delete) \
+ X(SVC_TFM_LOG_RETRIEVE, NULL)
/**
* \def LIST_SVC_CORE_TEST_INTERACTIVE
diff --git a/interface/src/tfm_log_api.c b/interface/src/tfm_log_api.c
new file mode 100644
index 0000000..de7a31b
--- /dev/null
+++ b/interface/src/tfm_log_api.c
@@ -0,0 +1,20 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "tfm_log_defs.h"
+#include "tfm_ns_lock.h"
+
+enum tfm_log_err tfm_log_retrieve(uint32_t size,
+ uint8_t *buffer,
+ uint32_t *log_size)
+{
+ return tfm_ns_lock_svc_dispatch(SVC_TFM_LOG_RETRIEVE,
+ (uint32_t)size,
+ (uint32_t)buffer,
+ (uint32_t)log_size,
+ 0);
+}
diff --git a/interface/src/tfm_log_svc_handler.c b/interface/src/tfm_log_svc_handler.c
new file mode 100644
index 0000000..0a67a78
--- /dev/null
+++ b/interface/src/tfm_log_svc_handler.c
@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2018, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "tfm_ns_svc.h"
+#include "tfm_log_veneers.h"
+
+/* SVC function implementations */
+enum tfm_log_err tfm_log_svc_retrieve(uint32_t size,
+ uint8_t* buffer,
+ uint32_t *log_size)
+{
+ return tfm_log_veneer_retrieve(size, buffer, log_size);
+}