blob: b4cc72a68bfef8f8bc265574be6700a806d165b8 [file] [log] [blame]
Chris Brandc47d7102020-02-20 11:12:18 -08001/*
2 * Copyright (c) 2020, Cypress Semiconductor Corporation. All rights reserved.
Jamie Fox6a3946a2020-12-07 21:50:31 +00003 * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
Chris Brandc47d7102020-02-20 11:12:18 -08004 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 */
8
9#ifndef __TFM_HAL_PS_H__
10#define __TFM_HAL_PS_H__
11
Chris Brand8a6b5c52020-10-30 16:49:56 -070012#include <stddef.h>
Jamie Fox6a3946a2020-12-07 21:50:31 +000013#include <stdint.h>
14
15#include "Driver_Flash.h"
16#include "flash_layout.h"
17#include "tfm_hal_defs.h"
Chris Brand8a6b5c52020-10-30 16:49:56 -070018
Chris Brandc47d7102020-02-20 11:12:18 -080019#ifdef __cplusplus
20extern "C" {
21#endif
22
Jamie Fox6a3946a2020-12-07 21:50:31 +000023/* The name of the ARM_DRIVER_FLASH to use for PS */
24#ifndef TFM_HAL_PS_FLASH_DRIVER
25#error "TFM_HAL_PS_FLASH_DRIVER must be defined by the target in flash_layout.h"
26#endif
27
28/* The size of the PS flash device's physical program unit. Must be equal to
29 * TFM_HAL_PS_FLASH_DRIVER.GetInfo()->program_unit, but required at compile
30 * time.
31 */
32#ifndef TFM_HAL_PS_PROGRAM_UNIT
33#error "TFM_HAL_PS_PROGRAM_UNIT must be defined by the target in flash_layout.h"
34#elif (TFM_HAL_PS_PROGRAM_UNIT < 1)
35#error "TFM_HAL_PS_PROGRAM_UNIT must be greater than 1"
36#elif (TFM_HAL_PS_PROGRAM_UNIT & (TFM_HAL_PS_PROGRAM_UNIT - 1) != 0)
37#error "TFM_HAL_PS_PROGRAM_UNIT must be a power of two"
38#endif
39
40/**
41 * \brief Struct containing information required from the platform at runtime
42 * to configure the PS filesystem.
43 */
44struct tfm_hal_ps_fs_info_t {
45 uint32_t flash_area_addr; /**< Location of the block of flash to use for PS
46 */
47 size_t flash_area_size; /**< Number of bytes of flash to use for PS */
48 uint8_t sectors_per_block; /**< Number of erase sectors per logical FS block
49 */
50};
51
52/**
53 * \brief The flash driver to use for PS.
54 */
55extern ARM_DRIVER_FLASH TFM_HAL_PS_FLASH_DRIVER;
56
Chris Brandc47d7102020-02-20 11:12:18 -080057/**
58 * \brief Retrieve the filesystem config for PS.
59 *
60 * Note that this function should ensure that the values returned do
61 * not result in a security compromise.
62 *
Jamie Fox6a3946a2020-12-07 21:50:31 +000063 * \param [out] fs_info Filesystem config information
Chris Brandc47d7102020-02-20 11:12:18 -080064 *
Jamie Fox6a3946a2020-12-07 21:50:31 +000065 * \return A status code as specified in \ref tfm_hal_status_t
Chris Brandc47d7102020-02-20 11:12:18 -080066 * If an error is detected within this function, is should leave the
67 * content of the parameters unchanged.
Jamie Fox6a3946a2020-12-07 21:50:31 +000068 *
69 * \retval TFM_HAL_SUCCESS The operation completed successfully
70 * \retval TFM_HAL_ERROR_INVALID_INPUT Invalid parameter
Chris Brandc47d7102020-02-20 11:12:18 -080071 */
Jamie Fox6a3946a2020-12-07 21:50:31 +000072enum tfm_hal_status_t tfm_hal_ps_fs_info(struct tfm_hal_ps_fs_info_t *fs_info);
Chris Brandc47d7102020-02-20 11:12:18 -080073
74#ifdef __cplusplus
75}
76#endif
77
78#endif /* __TFM_HAL_PS_H__ */