Platform: TF-M ITS and PS HAL
Expands the TF-M Internal Trusted Storage and Protected Storage HALs to
cover all flash and filesystem configuration parameters required from
the platform. The CMSIS Flash APIs are exposed to abstract the flash
device, along with a function and some definitions to expose further
parameters required by the filesystem.
Updates ITS to use the new HALs and removes its_flash_info_external.c,
its_flash_info_internal.c and its_flash.c. Also moves the
block_to_block_move() function from its_flash.c to the filesystem, as
its implementation is agnostic to the flash device. The its_flash.h
header is kept as a helper to abstract the different flash block device
wrappers (NOR, NAND, RAM).
The ITS filesystem is updated to take a configuration struct as an
initialisation parameter, which is filled using values from the HAL.
Change-Id: I95ae44795a59b1f36c9b95d057f44b4ae3ba2344
Signed-off-by: Jamie Fox <jamie.fox@arm.com>
diff --git a/platform/include/tfm_hal_its.h b/platform/include/tfm_hal_its.h
index 77698fe..a451485 100644
--- a/platform/include/tfm_hal_its.h
+++ b/platform/include/tfm_hal_its.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2020, Cypress Semiconductor Corporation. All rights reserved.
+ * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -9,25 +10,68 @@
#define __TFM_HAL_ITS_H__
#include <stddef.h>
+#include <stdint.h>
+
+#include "Driver_Flash.h"
+#include "flash_layout.h"
+#include "tfm_hal_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
+/* The name of the ARM_DRIVER_FLASH to use for ITS */
+#ifndef TFM_HAL_ITS_FLASH_DRIVER
+#error "TFM_HAL_ITS_FLASH_DRIVER must be defined by the target in flash_layout.h"
+#endif
+
+/* The size of the ITS flash device's physical program unit. Must be equal to
+ * TFM_HAL_ITS_FLASH_DRIVER.GetInfo()->program_unit, but required at compile
+ * time.
+ */
+#ifndef TFM_HAL_ITS_PROGRAM_UNIT
+#error "TFM_HAL_ITS_PROGRAM_UNIT must be defined by the target in flash_layout.h"
+#elif (TFM_HAL_ITS_PROGRAM_UNIT < 1)
+#error "TFM_HAL_ITS_PROGRAM_UNIT must be greater than 1"
+#elif (TFM_HAL_ITS_PROGRAM_UNIT & (TFM_HAL_ITS_PROGRAM_UNIT - 1) != 0)
+#error "TFM_HAL_ITS_PROGRAM_UNIT must be a power of two"
+#endif
+
+/**
+ * \brief Struct containing information required from the platform at runtime
+ * to configure the ITS filesystem.
+ */
+struct tfm_hal_its_fs_info_t {
+ uint32_t flash_area_addr; /**< Location of the block of flash to use for
+ * ITS
+ */
+ size_t flash_area_size; /**< Number of bytes of flash to use for ITS */
+ uint8_t sectors_per_block; /**< Number of erase sectors per logical FS block
+ */
+};
+
+/**
+ * \brief The flash driver to use for ITS.
+ */
+extern ARM_DRIVER_FLASH TFM_HAL_ITS_FLASH_DRIVER;
+
/**
* \brief Retrieve the filesystem config for ITS.
*
* Note that this function should ensure that the values returned do
* not result in a security compromise.
*
- * \param [out] flash_area_addr Location of the block of flash to use for ITS
- * \param [out] flash_area_size Number of bytes of flash to use for ITS
+ * \param [out] fs_info Filesystem config information
*
- * \return void
+ * \return A status code as specified in \ref tfm_hal_status_t
* If an error is detected within this function, is should leave the
* content of the parameters unchanged.
+ *
+ * \retval TFM_HAL_SUCCESS The operation completed successfully
+ * \retval TFM_HAL_ERROR_INVALID_INPUT Invalid parameter
*/
-void tfm_hal_its_fs_info(uint32_t *flash_area_addr, size_t *flash_area_size);
+enum tfm_hal_status_t
+tfm_hal_its_fs_info(struct tfm_hal_its_fs_info_t *fs_info);
#ifdef __cplusplus
}