SPM: Implement SPM log functions.

Add source files about the implementation of SPM log functions.

Change-Id: I9be65e64fafd9b22e4134ece7e03527b6c5e567c
Signed-off-by: Shawn Shan <shawn.shan@arm.com>
diff --git a/platform/ext/common/tfm_hal_spm_logdev_peripheral.c b/platform/ext/common/tfm_hal_spm_logdev_peripheral.c
new file mode 100644
index 0000000..11e1398
--- /dev/null
+++ b/platform/ext/common/tfm_hal_spm_logdev_peripheral.c
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "tfm_hal_spm_logdev.h"
+#include "uart_stdout.h"
+
+int32_t tfm_hal_output_spm_log(const char *str, uint32_t len)
+{
+    /* Peripheral based log function call the stdio_output_string directly */
+    return stdio_output_string((const unsigned char *)str, len);
+}
diff --git a/secure_fw/spm/common/spm_log.c b/secure_fw/spm/common/spm_log.c
new file mode 100644
index 0000000..dc0e995
--- /dev/null
+++ b/secure_fw/spm/common/spm_log.c
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2020, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "tfm_spm_log.h"
+
+#define MAX_DIGIT_BITS 10  /* Max bits of uint32_t value 0xFFFFFFFF add '0x' */
+const static char HEX_TABLE[] = {'0', '1', '2', '3', '4', '5', '6', '7',
+                                 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+
+/**
+ * \brief Convert digit number into HEX format string, the string have '0x'
+ *        prefix and leading zeros are not stripped.
+ *
+ * \param[in]  value  A value need to be converted.
+ * \param[in]  msg    A string message that the value converted to.
+ *
+ */
+
+static void to_hex(uint32_t value, char msg[])
+{
+    int i;
+
+    msg[0] = '0';
+    msg[1] = 'x';
+    for (i = MAX_DIGIT_BITS - 1; i >= 2; i--, value >>= 4) {
+        msg[i] = HEX_TABLE[value & 0xF];
+    }
+}
+
+int32_t spm_log_msgval(const char *msg, size_t len, uint32_t value)
+{
+    int32_t result_msg = 0, result_val;
+    char value_str[MAX_DIGIT_BITS];
+
+    if (msg && len) {
+        result_msg = tfm_hal_output_spm_log(msg, len);
+        if (result_msg < TFM_HAL_SUCCESS) {
+            return result_msg;
+        }
+    }
+
+    to_hex(value, value_str);
+
+    result_val = tfm_hal_output_spm_log(value_str,
+                                        MAX_DIGIT_BITS);
+    if (result_val < TFM_HAL_SUCCESS) {
+        return result_val;
+    }
+    return (result_msg + result_val);
+}