Add platform specific TRNG driver
Adds platform specific TRNG driver to Crypto opteesp deployment.
Fetches and builds the TZ-TRNG driver from its external
repo and includes it when the crypto/opteesp is built for
the arm/fvp/fvp_base_revc-2xaemv8a platform. Device region
information provided as external configuration data is
not yet integrated to the TRNG hardware is not yet used.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I8a2946643a279dfcc3aff608427c85e674f0e084
diff --git a/components/config/ramstore/component.cmake b/components/config/ramstore/component.cmake
new file mode 100644
index 0000000..3fb8540
--- /dev/null
+++ b/components/config/ramstore/component.cmake
@@ -0,0 +1,14 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/config_ramstore.c"
+ )
+
diff --git a/components/config/ramstore/config_ramstore.c b/components/config/ramstore/config_ramstore.c
new file mode 100644
index 0000000..548ba4b
--- /dev/null
+++ b/components/config/ramstore/config_ramstore.c
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "config_ramstore.h"
+#include <config/interface/platform_config.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+/**
+ * Variable length container for a configuration object.
+ */
+struct config_container
+{
+ size_t size;
+ struct config_container *next;
+};
+
+static struct config_container *config_container_create(const void *data, size_t size)
+{
+ struct config_container *container = malloc(sizeof(struct config_container) + size);
+
+ if (container) {
+
+ container->size = size;
+ container->next = NULL;
+
+ memcpy((uint8_t*)container + sizeof(struct config_container), data, size);
+ }
+
+ return container;
+}
+
+static void config_container_destroy(struct config_container *container)
+{
+ free(container);
+}
+
+static const void *config_container_data(const struct config_container *container)
+{
+ return (const uint8_t*)container + sizeof(struct config_container);
+}
+
+/**
+ * Singleton config_ramstore instance
+ */
+static struct config_ramstore
+{
+ struct config_container *device_region_list;
+} ramstore = {0};
+
+
+void config_ramstore_init(void)
+{
+ ramstore.device_region_list = NULL;
+}
+
+void config_ramstore_deinit(void)
+{
+ while (ramstore.device_region_list) {
+
+ struct config_container *next = ramstore.device_region_list->next;
+ free(ramstore.device_region_list);
+ ramstore.device_region_list = next;
+ }
+}
+
+int platform_config_device_add(const struct device_region *device_region)
+{
+ struct config_container *container;
+
+ container = config_container_create(device_region, sizeof(struct device_region));
+ if (!container) return -1;
+
+ container->next = ramstore.device_region_list;
+ ramstore.device_region_list = container;
+
+ return 0;
+}
+
+struct device_region *platform_config_device_query(const char *dev_class,
+ int dev_instance)
+{
+ struct device_region *result = NULL;
+ const struct config_container *container = ramstore.device_region_list;
+
+ while (container) {
+
+ const struct device_region *candidate;
+ candidate = (const struct device_region*)config_container_data(container);
+
+ if ((candidate->dev_instance == dev_instance) &&
+ (strcmp(candidate->dev_class, dev_class) == 0)) {
+
+ result = malloc(container->size);
+ if (result) {
+
+ memcpy(result, candidate, container->size);
+ }
+
+ break;
+ }
+
+ container = container->next;
+ }
+
+ return result;
+}
+
+void platform_config_device_query_free(struct device_region *device_region)
+{
+ free(device_region);
+}
diff --git a/components/config/ramstore/config_ramstore.h b/components/config/ramstore/config_ramstore.h
new file mode 100644
index 0000000..5df1838
--- /dev/null
+++ b/components/config/ramstore/config_ramstore.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+/**
+ * A config store that implements the common config interface that
+ * saves configuration data in ram. This may be used in environments
+ * that are configured at run-time e.g. from device tree. The
+ * config_ramstore is a singleton.
+ */
+#ifndef CONFIG_RAMSTORE_H
+#define CONFIG_RAMSTORE_H
+
+#include <stddef.h>
+#include <platform/interface/device_region.h>
+#include <config/interface/platform_config.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * \brief Initializes the singleton store
+ *
+ */
+void config_ramstore_init(void);
+
+/**
+ * \brief Clean-up the config_ramstore after use
+ */
+void config_ramstore_deinit(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CONFIG_RAMSTORE_H */
diff --git a/components/config/ramstore/test/component.cmake b/components/config/ramstore/test/component.cmake
new file mode 100644
index 0000000..7f1df76
--- /dev/null
+++ b/components/config/ramstore/test/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/ramstore_tests.cpp"
+ )
diff --git a/components/config/ramstore/test/ramstore_tests.cpp b/components/config/ramstore/test/ramstore_tests.cpp
new file mode 100644
index 0000000..c597b57
--- /dev/null
+++ b/components/config/ramstore/test/ramstore_tests.cpp
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <cstring>
+#include <config/ramstore/config_ramstore.h>
+#include <CppUTest/TestHarness.h>
+
+TEST_GROUP(ConfigRamstoreTests)
+{
+ void setup()
+ {
+ config_ramstore_init();
+ }
+
+ void teardown()
+ {
+ config_ramstore_deinit();
+ }
+};
+
+TEST(ConfigRamstoreTests, checkEmptyConfig)
+{
+ /* Expect queries to an empty store to return gracefully */
+ struct device_region *query_result = platform_config_device_query("flash", 0);
+ CHECK(!query_result);
+
+ /* Expect freeing a null pointer to be harmless */
+ platform_config_device_query_free(query_result);
+}
+
+TEST(ConfigRamstoreTests, checkSingleConfig)
+{
+ struct device_region config;
+
+ /* This would be external configuration, obtained say from device tree */
+ strcpy(config.dev_class, "fs");
+ config.dev_instance = 2;
+ config.base_addr = (uint8_t*)0x0f000010;
+ config.io_region_size = 0x100;
+
+ /* Add the configuration object */
+ int status = platform_config_device_add(&config);
+ CHECK_EQUAL(0, status);
+
+ /* Expect query find the config object */
+ struct device_region *query_result = platform_config_device_query(config.dev_class, config.dev_instance);
+ CHECK(query_result);
+ CHECK(strcmp(config.dev_class, query_result->dev_class) == 0);
+ CHECK_EQUAL(config.dev_instance, query_result->dev_instance);
+ CHECK_EQUAL(config.base_addr, query_result->base_addr);
+ CHECK_EQUAL(config.io_region_size, query_result->io_region_size);
+
+ platform_config_device_query_free(query_result);
+}
+
+TEST(ConfigRamstoreTests, checkMultipleConfig)
+{
+ int status;
+
+ /* Add first config object */
+ struct device_region config1;
+
+ strcpy(config1.dev_class, "flash");
+ config1.dev_instance = 0;
+ config1.base_addr = (uint8_t*)0x0f000010;
+ config1.io_region_size = 0x100;
+
+ status = platform_config_device_add(&config1);
+ CHECK_EQUAL(0, status);
+
+ /* Add second config object */
+ struct device_region config2;
+
+ strcpy(config2.dev_class, "flash");
+ config2.dev_instance = 1;
+ config2.base_addr = (uint8_t*)0x0f000010;
+ config2.io_region_size = 0x100;
+
+ status = platform_config_device_add(&config2);
+ CHECK_EQUAL(0, status);
+
+ /* Expect queries for both objects to work */
+ struct device_region *query1_result = platform_config_device_query(config1.dev_class, config1.dev_instance);
+ CHECK(query1_result);
+
+ struct device_region *query2_result = platform_config_device_query(config2.dev_class, config2.dev_instance);
+ CHECK(query2_result);
+
+ platform_config_device_query_free(query2_result);
+}
\ No newline at end of file