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 File Reference
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "flash/its_flash.h"
#include "its_utils.h"
#include "psa/error.h"
Include dependency graph for its_flash_fs_mblock.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  its_metadata_block_header_t
 Structure to store the metadata block header. More...
 
struct  its_block_meta_t
 Structure to store information about each physical flash memory block. More...
 
struct  its_file_meta_t
 Structure to store file metadata. More...
 
struct  its_flash_fs_ctx_t
 Structure to store the ITS flash file system context. More...
 

Macros

#define ITS_SUPPORTED_VERSION   0x01
 Defines the supported version. More...
 
#define ITS_METADATA_INVALID_INDEX   0xFFFF
 Defines the invalid index value when the metadata table is full. More...
 
#define ITS_LOGICAL_DBLOCK0   0
 Defines logical data block 0 ID. More...
 
#define _T1
 
#define _T2
 
#define _T3
 

Functions

psa_status_t its_flash_fs_mblock_init (struct its_flash_fs_ctx_t *fs_ctx)
 Initializes metadata block with the valid/active metablock. More...
 
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 metadata block. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Macro Definition Documentation

#define _T1
Value:
uint32_t scratch_dblock; \
uint8_t fs_version; \
uint8_t active_swap_count;

Physical block ID of the data

Definition at line 55 of file its_flash_fs_mblock.h.

#define _T2
Value:
uint32_t phy_id; \
size_t data_start; \
size_t free_size;

Number of bytes free at end of block (set during \ block compaction for gap reuse) \

Definition at line 79 of file its_flash_fs_mblock.h.

#define _T3
Value:
uint32_t lblock; \
size_t data_idx; \
size_t cur_size; \
size_t max_size; \
uint32_t flags; \
uint8_t id[ITS_FILE_ID_SIZE];
#define ITS_FILE_ID_SIZE
Definition: its_utils.h:20

ID of this file

Definition at line 107 of file its_flash_fs_mblock.h.

#define ITS_LOGICAL_DBLOCK0   0

Defines logical data block 0 ID.

Definition at line 42 of file its_flash_fs_mblock.h.

#define ITS_METADATA_INVALID_INDEX   0xFFFF

Defines the invalid index value when the metadata table is full.

Definition at line 35 of file its_flash_fs_mblock.h.

#define ITS_SUPPORTED_VERSION   0x01

Defines the supported version.

Definition at line 28 of file its_flash_fs_mblock.h.

Function Documentation

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 metadata block.

Parameters
[in,out]fs_ctxFilesystem context
[in]idx_startFile metadata entry index to start copy, inclusive
[in]idx_endFile metadata entry index to end copy, exclusive
Returns
Returns error code as specified in psa_status_t

Definition at line 716 of file its_flash_fs_mblock.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in,out]fs_ctxFilesystem context
[in]lblockLogical block number
Returns
current scratch data block

Definition at line 733 of file its_flash_fs_mblock.c.

Here is the caller graph for this function:

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.

Parameters
[in,out]fs_ctxFilesystem context
[in]fidID of the file
[out]idxIndex of the file metadata in the file system
Returns
Returns error code as specified in psa_status_t

Definition at line 745 of file its_flash_fs_mblock.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in,out]fs_ctxFilesystem context
[in]flagsFlags to search for
[out]idxIndex of the file metadata in the file system
Returns
Returns error code as specified in psa_status_t

Definition at line 770 of file its_flash_fs_mblock.c.

Here is the call graph for this function:

Here is the caller graph for this function:

psa_status_t its_flash_fs_mblock_init ( struct its_flash_fs_ctx_t fs_ctx)

Initializes metadata block with the valid/active metablock.

Parameters
[in,out]fs_ctxFilesystem context
Returns
Returns value as specified in psa_status_t

Definition at line 795 of file its_flash_fs_mblock.c.

Here is the caller graph for this function:

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.

Parameters
[in,out]fs_ctxFilesystem context
Returns
Returns offset value in metadata block

Definition at line 819 of file its_flash_fs_mblock.c.

Here is the caller graph for this function:

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.

Note
The files data in the logical block 0 is stored in same physical block where the metadata is stored. A change in the metadata requires a swap of physical blocks. So, the files data stored in the current medadata block needs to be copied in the scratch block, unless the data of the file processed is located in the logical block 0.
Parameters
[in,out]fs_ctxFilesystem context
Returns
Returns error code as specified in psa_status_t

Definition at line 843 of file its_flash_fs_mblock.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in,out]fs_ctxFilesystem context
[in]lblockLogical block number
[out]block_metaPointer to block meta structure
Returns
Returns error code as specified in psa_status_t

Definition at line 890 of file its_flash_fs_mblock.c.

Here is the caller graph for this function:

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.

Parameters
[in,out]fs_ctxFilesystem context
[in]idxFile metadata entry index
[out]file_metaPointer to file meta structure
Returns
Returns error code as specified in psa_status_t

Definition at line 868 of file its_flash_fs_mblock.c.

Here is the caller graph for this function:

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.

Parameters
[in,out]fs_ctxFilesystem context
[in]fidFile ID
[in]use_spareIf true then the spare file will be used, otherwise at least one file will be left free
[in]sizeSize of the file for which space is reserve
[in]flagsFlags set when the file was created
[out]file_meta_idxFile metadata entry index
[out]file_metaFile metadata entry
[out]block_metaBlock metadata entry
Returns
Returns error code as specified in psa_status_t

Definition at line 912 of file its_flash_fs_mblock.c.

Here is the caller graph for this function:

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.

Parameters
[in,out]fs_ctxFilesystem context
Returns
Returns value as specified in psa_status_t

Definition at line 936 of file its_flash_fs_mblock.c.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
[in,out]fs_ctxFilesystem context
[in]phy_idPhysical ID of scratch data block
[in]lblockLogical block number

Definition at line 1046 of file its_flash_fs_mblock.c.

Here is the caller graph for this function:

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.

Parameters
[in,out]fs_ctxFilesystem context
[in]lblockLogical block number
[in]block_metaPointer to block's metadata
Returns
Returns error code as specified in psa_status_t

Definition at line 1054 of file its_flash_fs_mblock.c.

Here is the caller graph for this function:

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.

Parameters
[in,out]fs_ctxFilesystem context
[in]idxFile's index in the metadata table
[in]file_metaMetadata pointer
Returns
Returns error code as specified in psa_status_t

Definition at line 1077 of file its_flash_fs_mblock.c.

Here is the caller graph for this function: