Add mock_fw_inspector

The mock_fw_inspector provides an implementation of the
fw_inspector interface to populate the fw_directory with
mock information about images that can be updated. Intended
only for test.

Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I8706e76f3399f4a71fd2891982e2fcd0b1605a19
diff --git a/components/service/fwu/inspector/fw_inspector.h b/components/service/fwu/inspector/fw_inspector.h
new file mode 100644
index 0000000..037a20f
--- /dev/null
+++ b/components/service/fwu/inspector/fw_inspector.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef FW_INSPECTOR_H
+#define FW_INSPECTOR_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Interface dependencies
+ */
+struct fw_directory;
+
+/**
+ * \brief fw_inspector public interface definition
+ *
+ * A firmware inspector is responsible for retrieving information about the
+ * firmware associated with a fw store and refreshing the contents of the
+ * presented firmware directory. The information will reflect the state of
+ * the firmware at the most recent boot. The method used for discovering information
+ * may well vary between device classes and firmware store realizations. To
+ * give the necessary flexibility, the fw_inspector 'inspect' function may be
+ * realized by alternative implementations. To give the flexibility to
+ * combine multiple inspection strategies into a single build (for test or
+ * run-time configuration), the inspect method is called via a function pointer.
+ *
+ * \param[in]  fw_dir      The firmware directory to refresh
+ * \param[in]  boot_index  The boot_index reported by the bootloader
+ *
+ * \return FWU status
+ */
+typedef int (*fw_inspector_inspect)(
+	struct fw_directory *fw_dir,
+	unsigned int boot_index);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* FW_INSPECTOR_H */
diff --git a/components/service/fwu/inspector/mock/component.cmake b/components/service/fwu/inspector/mock/component.cmake
new file mode 100644
index 0000000..fce467d
--- /dev/null
+++ b/components/service/fwu/inspector/mock/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2022, 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}/mock_fw_inspector.c"
+	)
diff --git a/components/service/fwu/inspector/mock/mock_fw_inspector.c b/components/service/fwu/inspector/mock/mock_fw_inspector.c
new file mode 100644
index 0000000..da8945d
--- /dev/null
+++ b/components/service/fwu/inspector/mock/mock_fw_inspector.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2022-2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <common/uuid/uuid.h>
+#include <service/fwu/agent/fw_directory.h>
+#include "mock_fw_inspector.h"
+
+int mock_fw_inspector_inspect(
+	struct fw_directory *fw_dir,
+	unsigned int boot_index)
+{
+	(void)boot_index;
+
+	/* A mock fw inspector that populates the fw_directory with fixed entries.
+	 * Intended for test purposes.
+	 */
+
+	/* Add some mock image entries to represent updatable units. */
+	struct image_info image_info = {0};
+
+	/* Image 1 */
+	uuid_guid_octets_from_canonical(&image_info.img_type_uuid, MOCK_IMG_TYPE_UUID_1);
+	image_info.max_size = 100;
+	image_info.lowest_accepted_version = 1;
+	image_info.active_version = 2;
+	image_info.permissions = 1;
+	image_info.install_type = INSTALL_TYPE_WHOLE_VOLUME;
+
+	fw_directory_add_image_info(fw_dir, &image_info);
+
+	/* Image 2 */
+	uuid_guid_octets_from_canonical(&image_info.img_type_uuid, MOCK_IMG_TYPE_UUID_2);
+	image_info.max_size = 100;
+	image_info.lowest_accepted_version = 1;
+	image_info.active_version = 2;
+	image_info.permissions = 1;
+	image_info.install_type = INSTALL_TYPE_SUB_VOLUME;
+
+	fw_directory_add_image_info(fw_dir, &image_info);
+
+	/* Image 3 */
+	uuid_guid_octets_from_canonical(&image_info.img_type_uuid, MOCK_IMG_TYPE_UUID_3);
+	image_info.max_size = 100;
+	image_info.lowest_accepted_version = 1;
+	image_info.active_version = 2;
+	image_info.permissions = 1;
+	image_info.install_type = INSTALL_TYPE_SUB_VOLUME;
+
+	fw_directory_add_image_info(fw_dir, &image_info);
+
+	/* Image 4 */
+	uuid_guid_octets_from_canonical(&image_info.img_type_uuid, MOCK_IMG_TYPE_UUID_4);
+	image_info.max_size = 200;
+	image_info.lowest_accepted_version = 1;
+	image_info.active_version = 2;
+	image_info.permissions = 1;
+	image_info.install_type = INSTALL_TYPE_SUB_VOLUME;
+
+	fw_directory_add_image_info(fw_dir, &image_info);
+
+	return 0;
+}
+
+
diff --git a/components/service/fwu/inspector/mock/mock_fw_inspector.h b/components/service/fwu/inspector/mock/mock_fw_inspector.h
new file mode 100644
index 0000000..0eb91dd
--- /dev/null
+++ b/components/service/fwu/inspector/mock/mock_fw_inspector.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef MOCK_FW_INSPECTOR_H
+#define MOCK_FW_INSPECTOR_H
+
+#include <service/fwu/inspector/fw_inspector.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Mock image type UUIDs
+ */
+#define MOCK_IMG_TYPE_UUID_1    "7744b3ab-2672-4a36-b619-b9a3608c9973"
+#define MOCK_IMG_TYPE_UUID_2    "52b3b093-08c4-427e-8cfe-a4c3b804ed88"
+#define MOCK_IMG_TYPE_UUID_3    "14345e20-a0b6-46dd-8699-e89512596205"
+#define MOCK_IMG_TYPE_UUID_4    "420f26dc-0a91-436f-8420-f4372b88ae16"
+
+/**
+ * \brief mock_fw_inspector inspect method
+ *
+ * The concrete inspect method for the mock_fw_inspector. The mock_fw_inspector
+ * is a fw_inspector that populates the fw_directory with a fixed set of mock
+ * entries. Used for test only.
+ *
+ * \param[in]  fw_dir      The firmware directory to refresh
+ * \param[in]  boot_index  The boot_index reported by the bootloader
+ *
+ * \return FWU status
+ */
+int mock_fw_inspector_inspect(
+	struct fw_directory *fw_dir,
+	unsigned int boot_index);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MOCK_FW_INSPECTOR_H */
diff --git a/deployments/component-test/component-test.cmake b/deployments/component-test/component-test.cmake
index 4fd0009..bd9e2cb 100644
--- a/deployments/component-test/component-test.cmake
+++ b/deployments/component-test/component-test.cmake
@@ -110,6 +110,7 @@
 		"components/service/block_storage/factory/client"
 		"components/service/fwu/agent"
 		"components/service/fwu/installer"
+		"components/service/fwu/inspector/mock"
 		"components/service/crypto/client/cpp"
 		"components/service/crypto/client/cpp/protocol/protobuf"
 		"components/service/crypto/client/cpp/protocol/packed-c"