TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
its_flash_fs_mblock.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __ITS_FLASH_FS_MBLOCK_H__
9 #define __ITS_FLASH_FS_MBLOCK_H__
10 
11 #include <stdbool.h>
12 #include <stddef.h>
13 #include <stdint.h>
14 
15 #include "flash/its_flash.h"
16 #include "its_utils.h"
17 #include "psa/error.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
28 #define ITS_SUPPORTED_VERSION 0x01
29 
35 #define ITS_METADATA_INVALID_INDEX 0xFFFF
36 
42 #define ITS_LOGICAL_DBLOCK0 0
43 
55 #define _T1 \
56  uint32_t scratch_dblock; \
59  uint8_t fs_version; \
60  uint8_t active_swap_count;
62 struct its_metadata_block_header_t {
64 #if ((ITS_FLASH_MAX_ALIGNMENT) > 4)
65  uint8_t roundup[sizeof(struct __attribute__((__aligned__(ITS_FLASH_MAX_ALIGNMENT))) { _T1 }) -
66  sizeof(struct { _T1 })];
67 #endif
68 };
69 #undef _T1
70 
79 #define _T2 \
80  uint32_t phy_id; \
81  size_t data_start; \
84  size_t free_size;
88 struct its_block_meta_t {
89  _T2
90 #if ((ITS_FLASH_MAX_ALIGNMENT) > 4)
91  uint8_t roundup[sizeof(struct __attribute__((__aligned__(ITS_FLASH_MAX_ALIGNMENT))) { _T2 }) -
92  sizeof(struct { _T2 })];
93 #endif
94 };
95 #undef _T2
96 
105 #define _T3 \
106  uint32_t lblock; \
109  size_t data_idx; \
110  size_t cur_size; \
113  size_t max_size; \
114  uint32_t flags; \
115  uint8_t id[ITS_FILE_ID_SIZE];
117 struct its_file_meta_t {
118  _T3
119 #if ((ITS_FLASH_MAX_ALIGNMENT) > 4)
120  uint8_t roundup[sizeof(struct __attribute__((__aligned__(ITS_FLASH_MAX_ALIGNMENT))) { _T3 }) -
121  sizeof(struct { _T3 })];
122 #endif
123 };
124 #undef _T3
125 
131 struct its_flash_fs_ctx_t {
132  const struct its_flash_info_t *flash_info;
136  uint32_t active_metablock;
137  uint32_t scratch_metablock;
138 };
148 
160  uint32_t idx_start,
161  uint32_t idx_end);
162 
172  struct its_flash_fs_ctx_t *fs_ctx,
173  uint32_t lblock);
174 
185  const uint8_t *fid,
186  uint32_t *idx);
198  struct its_flash_fs_ctx_t *fs_ctx,
199  uint32_t flags,
200  uint32_t *idx);
201 
211  struct its_flash_fs_ctx_t *fs_ctx);
212 
228  struct its_flash_fs_ctx_t *fs_ctx);
229 
240  struct its_flash_fs_ctx_t *fs_ctx,
241  uint32_t idx,
242  struct its_file_meta_t *file_meta);
243 
254  struct its_flash_fs_ctx_t *fs_ctx,
255  uint32_t lblock,
256  struct its_block_meta_t *block_meta);
257 
274  struct its_flash_fs_ctx_t *fs_ctx,
275  const uint8_t *fid,
276  bool use_spare,
277  size_t size,
278  uint32_t flags,
279  uint32_t *file_meta_idx,
280  struct its_file_meta_t *file_meta,
281  struct its_block_meta_t *block_meta);
282 
291  struct its_flash_fs_ctx_t *fs_ctx);
292 
301  uint32_t phy_id, uint32_t lblock);
302 
313  struct its_flash_fs_ctx_t *fs_ctx,
314  uint32_t lblock,
315  struct its_block_meta_t *block_meta);
316 
327  struct its_flash_fs_ctx_t *fs_ctx,
328  uint32_t idx,
329  const struct its_file_meta_t *file_meta);
330 
331 #ifdef __cplusplus
332 }
333 #endif
334 
335 #endif /* __ITS_FLASH_FS_MBLOCK_H__ */
const struct its_flash_info_t * flash_info
psa_status_t its_flash_fs_mblock_reset_metablock(struct its_flash_fs_ctx_t *fs_ctx)
Resets metablock by cleaning and initializing the metadatablock.
psa_status_t its_flash_fs_mblock_reserve_file(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid, bool use_spare, size_t size, uint32_t flags, uint32_t *file_meta_idx, struct its_file_meta_t *file_meta, struct its_block_meta_t *block_meta)
Reserves space for a file.
uint32_t its_flash_fs_mblock_cur_data_scratch_id(struct its_flash_fs_ctx_t *fs_ctx, uint32_t lblock)
Gets current scratch datablock physical ID.
#define _T3
#define _T1
Structure to store information about each physical flash memory block.
psa_status_t its_flash_fs_mblock_get_file_idx(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid, uint32_t *idx)
Gets file metadata entry index.
Standard error codes for the SPM and RoT Services.
psa_status_t its_flash_fs_mblock_migrate_lb0_data_to_scratch(struct its_flash_fs_ctx_t *fs_ctx)
Writes the files data area of logical block 0 into the scratch block.
struct its_metadata_block_header_t meta_block_header
psa_status_t its_flash_fs_mblock_read_file_meta(struct its_flash_fs_ctx_t *fs_ctx, uint32_t idx, struct its_file_meta_t *file_meta)
Reads specified file metadata.
#define _T2
Structure to store file metadata.
psa_status_t its_flash_fs_mblock_get_file_idx_flag(struct its_flash_fs_ctx_t *fs_ctx, uint32_t flags, uint32_t *idx)
Gets file metadata entry index of the first file with one of the provided flags set.
psa_status_t its_flash_fs_mblock_update_scratch_file_meta(struct its_flash_fs_ctx_t *fs_ctx, uint32_t idx, const struct its_file_meta_t *file_meta)
Writes a file metadata entry into scratch metadata block.
psa_status_t its_flash_fs_mblock_init(struct its_flash_fs_ctx_t *fs_ctx)
Initializes metadata block with the valid/active metablock.
#define ITS_FLASH_MAX_ALIGNMENT
Provides a compile-time constant for the maximum program unit required by any flash device that can b...
Definition: its_flash.h:43
psa_status_t its_flash_fs_mblock_cp_file_meta(struct its_flash_fs_ctx_t *fs_ctx, uint32_t idx_start, uint32_t idx_end)
Copies the file metadata entries between two indexes from the active metadata block to the scratch me...
psa_status_t its_flash_fs_mblock_update_scratch_block_meta(struct its_flash_fs_ctx_t *fs_ctx, uint32_t lblock, struct its_block_meta_t *block_meta)
Puts logical block's metadata in scratch metadata block.
Structure to store the metadata block header.
void its_flash_fs_mblock_set_data_scratch(struct its_flash_fs_ctx_t *fs_ctx, uint32_t phy_id, uint32_t lblock)
Sets current data scratch block.
Structure containing the required information about a flash device to be used by the ITS Flash FS...
Definition: its_flash.h:73
Structure to store the ITS flash file system context.
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:43
psa_status_t its_flash_fs_mblock_read_block_metadata(struct its_flash_fs_ctx_t *fs_ctx, uint32_t lblock, struct its_block_meta_t *block_meta)
Reads specified logical block metadata.
psa_status_t its_flash_fs_mblock_meta_update_finalize(struct its_flash_fs_ctx_t *fs_ctx)
Finalizes an update operation. Last step when a create/write/delete is performed. ...