Add direct_fw_inspector
The direct_fw_inspector can be used on platforms where direct
access to fw storage volumes is possible from the update agent
security domain. The direct_fw_inspector uses the set of
registered installers to provide the information needed to
populate the fw_director to provide a fresh view of updatable
images.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: Iab6fe5d919a173a32c284dd5567e144692d58dba
diff --git a/components/service/fwu/inspector/direct/component.cmake b/components/service/fwu/inspector/direct/component.cmake
new file mode 100644
index 0000000..5faf786
--- /dev/null
+++ b/components/service/fwu/inspector/direct/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}/direct_fw_inspector.c"
+ )
diff --git a/components/service/fwu/inspector/direct/direct_fw_inspector.c b/components/service/fwu/inspector/direct/direct_fw_inspector.c
new file mode 100644
index 0000000..61ce670
--- /dev/null
+++ b/components/service/fwu/inspector/direct/direct_fw_inspector.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <trace.h>
+#include <protocols/service/fwu/packed-c/status.h>
+#include <media/volume/index/volume_index.h>
+#include <service/fwu/installer/installer.h>
+#include <service/fwu/installer/installer_index.h>
+#include <service/fwu/agent/fw_directory.h>
+#include <service/fwu/fw_store/banked/volume_id.h>
+#include "direct_fw_inspector.h"
+
+int direct_fw_inspector_inspect(
+ struct fw_directory *fw_dir,
+ unsigned int boot_index)
+{
+ int status = FWU_STATUS_SUCCESS;
+
+ /* The set of registered installers determines which fw components are
+ * updatable as individual units. Each installer is able to provide
+ * a view of the set of images [0..n] that it is capable of updating using
+ * its enumerate method. This view is based on the state of the firmware
+ * at the most recent boot. The set of updatable images may change after
+ * an update because:
+ * a) The set of images within the boot volume has changed
+ * b) The set of supported installers has changed
+ *
+ * By iterating over all registered installers, a complete and fresh view
+ * of updatable images is obtained.
+ */
+ unsigned int index = 0;
+
+ do {
+
+ struct installer *installer = installer_index_get(index);
+
+ if (!installer)
+ break;
+
+ /* To enable an installer to inspect the firmware volume that
+ * was booted from, determined the correct volume_id based on the
+ * most recent boot_index.
+ */
+ unsigned int volume_id = banked_volume_id(
+ installer->location_id,
+ banked_usage_id(boot_index));
+
+ /* Delegate volume inspection to the installer that will have
+ * the necessary package format knowledge to extract information
+ * about images that it is capable of updating. An installer
+ * will add 0..* image entries to the fw_directory.
+ */
+ status = installer_enumerate(installer, volume_id, fw_dir);
+
+ if (status != FWU_STATUS_SUCCESS) {
+
+ EMSG("Failed to enumerate contents of volume %d", volume_id);
+ break;
+ }
+
+ ++index;
+
+ } while (1);
+
+ return status;
+}
diff --git a/components/service/fwu/inspector/direct/direct_fw_inspector.h b/components/service/fwu/inspector/direct/direct_fw_inspector.h
new file mode 100644
index 0000000..e34d29f
--- /dev/null
+++ b/components/service/fwu/inspector/direct/direct_fw_inspector.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef DIRECT_FW_INSPECTOR_H
+#define DIRECT_FW_INSPECTOR_H
+
+#include <service/fwu/inspector/fw_inspector.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * \brief direct_fw_inspector inspect method
+ *
+ * The concrete inspect method for the direct_fw_inspector. The direct_fw_inspector
+ * is a fw_inspector that can be used when direct access to firmware storage volumes
+ * is possible e.g. when fw is loaded from Swd flash. The direct_fw_inspector delegates
+ * the enumeration of updatable images to the set of installers that were registered
+ * with the installer_index as part of the platform configuration.
+ *
+ * \param[in] fw_dir The firmware directory to refresh
+ * \param[in] boot_index The boot_index reported by the bootloader
+ *
+ * \return FWU status
+ */
+int direct_fw_inspector_inspect(
+ struct fw_directory *fw_dir,
+ unsigned int boot_index);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* DIRECT_FW_INSPECTOR_H */
diff --git a/deployments/component-test/component-test.cmake b/deployments/component-test/component-test.cmake
index cf43cf7..d9301e5 100644
--- a/deployments/component-test/component-test.cmake
+++ b/deployments/component-test/component-test.cmake
@@ -120,6 +120,7 @@
"components/service/fwu/installer/factory/default"
"components/service/fwu/installer/factory/default/test"
"components/service/fwu/inspector/mock"
+ "components/service/fwu/inspector/direct"
"components/service/crypto/client/cpp"
"components/service/crypto/client/cpp/protocol/protobuf"
"components/service/crypto/client/cpp/protocol/packed-c"