TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
its_flash_fs.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
3  * Copyright (c) 2020, Cypress Semiconductor Corporation. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  */
8 
9 #include "its_flash_fs.h"
10 
11 #include <stdbool.h>
12 
13 #include "its_flash_fs_dblock.h"
14 #include "tfm_memory_utils.h"
15 #include "its_utils.h"
16 
17 /* Filesystem-internal flags, which cannot be passed by the caller */
18 #define ITS_FLASH_FS_INTERNAL_FLAGS_MASK (UINT32_MAX - ((1U << 24) - 1))
19 /* Flag that indicates the file is to be deleted in the next block update */
20 #define ITS_FLASH_FS_FLAG_DELETE (1U << 24)
21 
22 static psa_status_t its_flash_fs_delete_idx(struct its_flash_fs_ctx_t *fs_ctx,
23  uint32_t del_file_idx);
24 
25 static psa_status_t its_flash_fs_file_write_aligned_data(
26  struct its_flash_fs_ctx_t *fs_ctx,
27  const struct its_block_meta_t *block_meta,
28  const struct its_file_meta_t *file_meta,
29  size_t offset,
30  size_t size,
31  const uint8_t *data)
32 {
33 #if (ITS_FLASH_MAX_ALIGNMENT != 1)
34  /* Check that the offset is aligned with the flash program unit */
35  if (!ITS_UTILS_IS_ALIGNED(offset, fs_ctx->flash_info->program_unit)) {
37  }
38 
39  /* Set the size to be aligned with the flash program unit */
40  size = ITS_UTILS_ALIGN(size, fs_ctx->flash_info->program_unit);
41 #endif
42 
43  /* It is not permitted to create gaps in the file */
44  if (offset > file_meta->cur_size) {
46  }
47 
48  /* Check that the new data is contained within the file's max size */
49  if (its_utils_check_contained_in(file_meta->max_size, offset, size)
50  != PSA_SUCCESS) {
52  }
53 
54  return its_flash_fs_dblock_write_file(fs_ctx, block_meta, file_meta, offset,
55  size, data);
56 }
57 
59  const struct its_flash_info_t *flash_info)
60 {
61  psa_status_t err;
62  uint32_t idx;
63 
64  /* Check for valid flash_info */
65  if (!flash_info) {
67  }
68 
69  /* Associate the flash device info with the context */
70  fs_ctx->flash_info = flash_info;
71 
72  /* Initialize metadata block with the valid/active metablock */
73  err = its_flash_fs_mblock_init(fs_ctx);
74  if (err != PSA_SUCCESS) {
75  return err;
76  }
77 
78  /* Check if a file marked for deletion has been left behind by a power
79  * failure. If so, delete it.
80  */
83  if (err == PSA_SUCCESS) {
84  return its_flash_fs_delete_idx(fs_ctx, idx);
85  } else if (err != PSA_ERROR_DOES_NOT_EXIST) {
86  return err;
87  }
88 
89  return PSA_SUCCESS;
90 }
91 
93 {
94  /* Clean and initialize the metadata block */
96 }
97 
99  const uint8_t *fid)
100 {
101  psa_status_t err;
102  uint32_t idx;
103 
104  err = its_flash_fs_mblock_get_file_idx(fs_ctx, fid, &idx);
105  if (err != PSA_SUCCESS) {
107  }
108 
109  return PSA_SUCCESS;
110 }
111 
113  const uint8_t *fid,
114  struct its_file_info_t *info)
115 {
116  psa_status_t err;
117  uint32_t idx;
118  struct its_file_meta_t tmp_metadata;
119 
120  /* Get the meta data index */
121  err = its_flash_fs_mblock_get_file_idx(fs_ctx, fid, &idx);
122  if (err != PSA_SUCCESS) {
124  }
125 
126  /* Read file metadata */
127  err = its_flash_fs_mblock_read_file_meta(fs_ctx, idx, &tmp_metadata);
128  if (err != PSA_SUCCESS) {
129  return err;
130  }
131 
132  /* Check if index is still referring to same file */
133  if (tfm_memcmp(fid, tmp_metadata.id, ITS_FILE_ID_SIZE)) {
135  }
136 
137  info->size_max = tmp_metadata.max_size;
138  info->size_current = tmp_metadata.cur_size;
139  info->flags = tmp_metadata.flags & ITS_FLASH_FS_USER_FLAGS_MASK;
140 
141  return PSA_SUCCESS;
142 }
143 
145  const uint8_t *fid,
146  uint32_t flags,
147  size_t max_size,
148  size_t data_size,
149  size_t offset,
150  const uint8_t *data)
151 {
152  struct its_block_meta_t block_meta;
153  struct its_file_meta_t file_meta;
154  uint32_t cur_phys_block;
155  psa_status_t err;
156  uint32_t idx;
157  uint32_t old_idx = ITS_METADATA_INVALID_INDEX;
158  uint32_t new_idx = ITS_METADATA_INVALID_INDEX;
159  bool use_spare;
160 
161  /* Do not permit the user to pass filesystem-internal flags */
162  if (flags & ITS_FLASH_FS_INTERNAL_FLAGS_MASK) {
164  }
165 
166 #if (ITS_FLASH_MAX_ALIGNMENT != 1)
167  /* Set the max_size to be aligned with the flash program unit */
168  max_size = ITS_UTILS_ALIGN(max_size, fs_ctx->flash_info->program_unit);
169 #endif
170 
171  /* Check if the file already exists */
172  err = its_flash_fs_mblock_get_file_idx(fs_ctx, fid, &old_idx);
173  if (err == PSA_SUCCESS) {
174  /* Read existing file metadata */
175  err = its_flash_fs_mblock_read_file_meta(fs_ctx, old_idx, &file_meta);
176  if (err != PSA_SUCCESS) {
178  }
179 
180  if (flags & ITS_FLASH_FS_FLAG_TRUNCATE) {
181  if (file_meta.max_size == max_size) {
182  /* Truncate and reuse the existing file, which is already the
183  * correct size.
184  */
185  file_meta.cur_size = 0;
186  file_meta.flags = flags;
187  new_idx = old_idx;
188  } else {
189  /* Mark the existing file to be deleted in this block update. It
190  * will be deleted in a second block update, and if there is a
191  * power failure before that block update completes, then
192  * deletion will be re-attempted based on this flag.
193  */
194  file_meta.flags |= ITS_FLASH_FS_FLAG_DELETE;
196  old_idx,
197  &file_meta);
198  if (err != PSA_SUCCESS) {
200  }
201  }
202  } else {
203  /* Write to existing file */
204  new_idx = old_idx;
205  }
206  } else if (err == PSA_ERROR_DOES_NOT_EXIST) {
207  /* The create flag must be supplied to create a new file */
208  if (!(flags & ITS_FLASH_FS_FLAG_CREATE)) {
210  }
211  } else {
212  return err;
213  }
214 
215  /* If the existing file was not reused, then a new one must be reserved */
216  if (new_idx == ITS_METADATA_INVALID_INDEX) {
217  /* Check that the file's maximum size is valid */
218  if (max_size > fs_ctx->flash_info->max_file_size) {
220  }
221 
222  /* Only use the spare file if there is an old file to be deleted */
223  use_spare = (old_idx != ITS_METADATA_INVALID_INDEX);
224 
225  /* Try to reserve a new file based on the input parameters */
226  err = its_flash_fs_mblock_reserve_file(fs_ctx, fid, use_spare,
227  max_size, flags, &new_idx,
228  &file_meta, &block_meta);
229  if (err != PSA_SUCCESS) {
230  return err;
231  }
232  } else {
233  /* Read existing block metadata */
234  err = its_flash_fs_mblock_read_block_metadata(fs_ctx, file_meta.lblock,
235  &block_meta);
236  if (err != PSA_SUCCESS) {
238  }
239  }
240 
241  if (data_size != 0) {
242  /* Write the content into scratch data block */
243  err = its_flash_fs_file_write_aligned_data(fs_ctx, &block_meta,
244  &file_meta, offset,
245  data_size, data);
246  if (err != PSA_SUCCESS) {
248  }
249 
250  /* Update the file's current size if required */
251  if (offset + data_size > file_meta.cur_size) {
252  /* Update the file metadata */
253  file_meta.cur_size = offset + data_size;
254  }
255 
256  cur_phys_block = block_meta.phy_id;
257 
258  /* Cur scratch block become the active datablock */
259  block_meta.phy_id =
261 
262  /* Swap the scratch data block */
263  its_flash_fs_mblock_set_data_scratch(fs_ctx, cur_phys_block,
264  file_meta.lblock);
265  }
266 
267  /* Update block metadata in scratch metadata block */
269  file_meta.lblock,
270  &block_meta);
271  if (err != PSA_SUCCESS) {
273  }
274 
275  /* Write file metadata in the scratch metadata block */
276  err = its_flash_fs_mblock_update_scratch_file_meta(fs_ctx, new_idx,
277  &file_meta);
278  if (err != PSA_SUCCESS) {
280  }
281 
282  /* Copy the file metadata entries from the start to the smaller of the two
283  * indexes.
284  */
285  idx = ITS_UTILS_MIN(new_idx, old_idx);
286  err = its_flash_fs_mblock_cp_file_meta(fs_ctx, 0, idx);
287  if (err != PSA_SUCCESS) {
289  }
290 
291  /* Copy the file metadata entries between the two indexes, if necessary */
292  if (old_idx != ITS_METADATA_INVALID_INDEX && old_idx != new_idx) {
293  err = its_flash_fs_mblock_cp_file_meta(fs_ctx, idx + 1,
294  ITS_UTILS_MAX(new_idx, old_idx));
295  if (err != PSA_SUCCESS) {
297  }
298 
299  idx = ITS_UTILS_MAX(new_idx, old_idx);
300  }
301 
302  /* Copy rest of the file metadata entries */
303  err = its_flash_fs_mblock_cp_file_meta(fs_ctx, idx + 1,
304  fs_ctx->flash_info->max_num_files);
305  if (err != PSA_SUCCESS) {
307  }
308 
309  /* The file data in the logical block 0 is stored in same physical block
310  * where the metadata is stored. A change in the metadata requires a swap of
311  * physical blocks. So, the file data stored in the current metadata block
312  * needs to be copied to the scratch block, if the data of the file
313  * processed is not located in the logical block 0. When file data is
314  * located in the logical block 0, that copy has been done while processing
315  * the file data.
316  */
317  if ((file_meta.lblock != ITS_LOGICAL_DBLOCK0) || (data_size == 0)) {
319  if (err != PSA_SUCCESS) {
321  }
322  }
323 
324  /* Write metadata header, swap metadata blocks and erase scratch blocks */
326  if (err != PSA_SUCCESS) {
327  return err;
328  }
329 
330  /* Delete the old file in a second block update.
331  * Note: A power failure after this point, but before the deletion has
332  * completed, will leave the old file in the filesystem, so it is always
333  * necessary to check for files to be deleted at initialisation time.
334  */
335  if (old_idx != ITS_METADATA_INVALID_INDEX && old_idx != new_idx) {
336  err = its_flash_fs_delete_idx(fs_ctx, old_idx);
337  }
338 
339  return err;
340 }
341 
342 static psa_status_t its_flash_fs_delete_idx(struct its_flash_fs_ctx_t *fs_ctx,
343  uint32_t del_file_idx)
344 {
345  size_t del_file_data_idx;
346  uint32_t del_file_lblock;
347  size_t del_file_max_size;
348  psa_status_t err;
349  size_t src_offset = fs_ctx->flash_info->block_size;
350  size_t nbr_bytes_to_move = 0;
351  uint32_t idx;
352  struct its_file_meta_t file_meta;
353 
354  err = its_flash_fs_mblock_read_file_meta(fs_ctx, del_file_idx, &file_meta);
355  if (err != PSA_SUCCESS) {
356  return err;
357  }
358 
359  if (its_utils_validate_fid(file_meta.id) != PSA_SUCCESS) {
361  }
362 
363  /* Save logical block, data_index and max_size to be used later on */
364  del_file_lblock = file_meta.lblock;
365  del_file_data_idx = file_meta.data_idx;
366  del_file_max_size = file_meta.max_size;
367 
368  /* Remove file metadata */
369  file_meta = (struct its_file_meta_t){0};
370 
371  /* Update file metadata in to the scratch block */
372  err = its_flash_fs_mblock_update_scratch_file_meta(fs_ctx, del_file_idx,
373  &file_meta);
374  if (err != PSA_SUCCESS) {
375  return err;
376  }
377 
378  /* Read all file metadata */
379  for (idx = 0; idx < fs_ctx->flash_info->max_num_files; idx++) {
380  if (idx == del_file_idx) {
381  /* Skip deleted file */
382  continue;
383  }
384 
385  /* Read file meta for the given file index */
386  err = its_flash_fs_mblock_read_file_meta(fs_ctx, idx, &file_meta);
387  if (err != PSA_SUCCESS) {
388  return err;
389  }
390 
391  /* Check if the file is located in the same logical block and has a
392  * valid FID.
393  */
394  if ((file_meta.lblock == del_file_lblock) &&
395  (its_utils_validate_fid(file_meta.id) == PSA_SUCCESS)) {
396  /* If a file is located after the data to delete, this
397  * needs to be moved.
398  */
399  if (file_meta.data_idx > del_file_data_idx) {
400  /* Check if this is the position after the deleted
401  * data. This will be the first file data to move.
402  */
403  if (src_offset > file_meta.data_idx) {
404  src_offset = file_meta.data_idx;
405  }
406 
407  /* Set the new file data index location in the
408  * data block.
409  */
410  file_meta.data_idx -= del_file_max_size;
411 
412  /* Increase number of bytes to move */
413  nbr_bytes_to_move += file_meta.max_size;
414  }
415  }
416  /* Update file metadata in to the scratch block */
418  &file_meta);
419  if (err != PSA_SUCCESS) {
420  return err;
421  }
422  }
423 
424  /* Compact data block */
425  err = its_flash_fs_dblock_compact_block(fs_ctx, del_file_lblock,
426  del_file_max_size,
427  src_offset, del_file_data_idx,
428  nbr_bytes_to_move);
429  if (err != PSA_SUCCESS) {
430  return err;
431  }
432 
433  /* The file data in the logical block 0 is stored in same physical block
434  * where the metadata is stored. A change in the metadata requires a
435  * swap of physical blocks. So, the file data stored in the current
436  * metadata block needs to be copied in the scratch block, if the data
437  * of the file processed is not located in the logical block 0. When an
438  * file data is located in the logical block 0, that copy has been done
439  * while processing the file data.
440  */
441  if (del_file_lblock != ITS_LOGICAL_DBLOCK0) {
443  if (err != PSA_SUCCESS) {
445  }
446  }
447 
448  /* Update the metablock header, swap scratch and active blocks,
449  * erase scratch blocks.
450  */
452 }
453 
455  const uint8_t *fid)
456 {
457  psa_status_t err;
458  uint32_t del_file_idx;
459 
460  /* Get the file index */
461  err = its_flash_fs_mblock_get_file_idx(fs_ctx, fid, &del_file_idx);
462  if (err != PSA_SUCCESS) {
464  }
465 
466  return its_flash_fs_delete_idx(fs_ctx, del_file_idx);
467 }
468 
470  const uint8_t *fid,
471  size_t size,
472  size_t offset,
473  uint8_t *data)
474 {
475  psa_status_t err;
476  uint32_t idx;
477  struct its_file_meta_t tmp_metadata;
478 
479  /* Get the file index */
480  err = its_flash_fs_mblock_get_file_idx(fs_ctx, fid, &idx);
481  if (err != PSA_SUCCESS) {
483  }
484 
485  /* Read file metadata */
486  err = its_flash_fs_mblock_read_file_meta(fs_ctx, idx, &tmp_metadata);
487  if (err != PSA_SUCCESS) {
489  }
490 
491  /* Check if index is still referring to same file */
492  if (tfm_memcmp(fid, tmp_metadata.id, ITS_FILE_ID_SIZE)) {
494  }
495 
496  /* Boundary check the incoming request */
497  err = its_utils_check_contained_in(tmp_metadata.cur_size, offset, size);
498  if (err != PSA_SUCCESS) {
499  return err;
500  }
501 
502  /* Read the file from flash */
503  err = its_flash_fs_dblock_read_file(fs_ctx, &tmp_metadata, offset, size,
504  data);
505  if (err != PSA_SUCCESS) {
507  }
508 
509  return PSA_SUCCESS;
510 }
511 
512 /* TODO This is very similar to (static) its_num_active_dblocks() */
513 static uint32_t its_flash_fs_num_active_dblocks(const struct its_flash_info_t *info)
514 {
515  /* Total number of datablocks is the number of dedicated datablocks plus
516  * logical datablock 0 stored in the metadata block.
517  */
518  if (info->num_blocks == 2) {
519  /* Metadata and data are stored in the same physical block, and the other
520  * block is required for power failure safe operation.
521  */
522  /* There are no dedicated data blocks when only two blocks are available */
523  return 1;
524  }
525  else {
526  /* One metadata block and two scratch blocks are reserved. One scratch block
527  * for metadata operations and the other for files data operations.
528  */
529  return info->num_blocks - 2;
530  }
531 }
532 
533 static size_t its_flash_fs_all_metadata_size(const struct its_flash_info_t *info)
534 {
535  return (sizeof(struct its_metadata_block_header_t)
536  + (its_flash_fs_num_active_dblocks(info)
537  * sizeof(struct its_block_meta_t))
538  + (info->max_num_files * sizeof(struct its_file_meta_t)));
539 }
540 
542 {
544 
545  /* The minimum number of blocks is 2. In this case, metadata and data are
546  * stored in the same physical block, and the other block is required for
547  * power failure safe operation.
548  * If at least 1 data block is available, 1 data scratch block is required for
549  * power failure safe operation. So, in this case, the minimum number of
550  * blocks is 4 (2 metadata block + 2 data blocks).
551  */
552  if ((info->num_blocks < 2) || (info->num_blocks == 3)) {
554  }
555 
556  if (info->num_blocks == 2) {
557  /* Metadata and data are stored in the same physical block */
558  if (info->max_file_size > info->block_size
559  - its_flash_fs_all_metadata_size(info)) {
561  }
562  }
563 
564  /* It is not required that all files fit in ITS flash area at the same time.
565  * So, it is possible that a create action fails because flash is full.
566  * However, the larger file must have enough space in the ITS flash area to be
567  * created, at least, when the ITS flash area is empty.
568  */
569  if (info->max_file_size > info->block_size) {
571  }
572 
573  /* Metadata must fit in a flash block */
574  if (its_flash_fs_all_metadata_size(info) > info->block_size) {
576  }
577 
578  return ret;
579 }
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.
const struct its_flash_info_t * flash_info
#define ITS_LOGICAL_DBLOCK0
Defines logical data block 0 ID.
uint32_t flags
Definition: its_flash_fs.h:64
psa_status_t its_flash_fs_file_get_info(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid, struct its_file_info_t *info)
Gets the file information referenced by the file ID.
Definition: its_flash_fs.c:112
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.
uint16_t program_unit
Definition: its_flash.h:165
#define ITS_UTILS_IS_ALIGNED(x, a)
Checks that a value is aligned to the provided alignment.
Definition: its_utils.h:66
psa_status_t its_flash_fs_prepare(struct its_flash_fs_ctx_t *fs_ctx, const struct its_flash_info_t *flash_info)
Prepares the filesystem to accept operations on the files.
Definition: its_flash_fs.c:58
#define PSA_ERROR_STORAGE_FAILURE
#define PSA_SUCCESS
Definition: crypto_values.h:35
Internal Trusted Storage service filesystem abstraction APIs. The purpose of this abstraction is to h...
psa_status_t its_flash_fs_validate_params(const struct its_flash_info_t *info)
Validates the configuration of the flash filesystem.
Definition: its_flash_fs.c:541
size_t size_current
Definition: its_flash_fs.h:60
uint8_t id[ITS_FILE_ID_SIZE]
psa_status_t its_flash_fs_dblock_write_file(struct its_flash_fs_ctx_t *fs_ctx, const struct its_block_meta_t *block_meta, const struct its_file_meta_t *file_meta, size_t offset, size_t size, const uint8_t *data)
Writes scratch data block content with requested data and the rest of the data from the given logical...
psa_status_t its_utils_validate_fid(const uint8_t *fid)
Validates file ID.
Definition: its_utils.c:30
uint16_t block_size
Definition: its_flash.h:160
Structure to store information about each physical flash memory block.
#define ITS_FLASH_FS_FLAG_DELETE
Definition: its_flash_fs.c:20
#define ITS_FLASH_FS_USER_FLAGS_MASK
Definition: its_flash_fs.h:34
psa_status_t its_flash_fs_file_exist(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid)
Checks if a file exists in the filesystem.
Definition: its_flash_fs.c:98
#define ITS_UTILS_MAX(x, y)
Evaluates to the maximum of the two parameters.
Definition: its_utils.h:46
psa_status_t its_flash_fs_file_write(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid, uint32_t flags, size_t max_size, size_t data_size, size_t offset, const uint8_t *data)
Writes data to a file.
Definition: its_flash_fs.c:144
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.
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.
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 *idx, struct its_file_meta_t *file_meta, struct its_block_meta_t *block_meta)
Reserves space for a file.
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.
#define PSA_ERROR_GENERIC_ERROR
Definition: crypto_values.h:43
#define PSA_ERROR_INVALID_ARGUMENT
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.
Structure to store file metadata.
psa_status_t its_utils_check_contained_in(size_t superset_size, size_t subset_offset, size_t subset_size)
Checks if a subset region is fully contained within a superset region.
Definition: its_utils.c:10
uint16_t num_blocks
Definition: its_flash.h:164
psa_status_t its_flash_fs_file_read(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid, size_t size, size_t offset, uint8_t *data)
Reads data from an existing file.
Definition: its_flash_fs.c:469
uint16_t max_file_size
Definition: its_flash.h:166
#define ITS_FILE_ID_SIZE
Definition: its_utils.h:20
#define ITS_METADATA_INVALID_INDEX
Defines the invalid index value when the metadata table is full.
psa_status_t its_flash_fs_file_delete(struct its_flash_fs_ctx_t *fs_ctx, const uint8_t *fid)
Deletes file referenced by the file ID.
Definition: its_flash_fs.c:454
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. ...
#define ITS_FLASH_FS_INTERNAL_FLAGS_MASK
Definition: its_flash_fs.c:18
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.
psa_status_t its_flash_fs_dblock_read_file(struct its_flash_fs_ctx_t *fs_ctx, const struct its_file_meta_t *file_meta, size_t offset, size_t size, uint8_t *buf)
Reads the file content.
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.
Structure to store the metadata block header.
__STATIC_INLINE int tfm_memcmp(const void *ptr1, const void *ptr2, size_t num)
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_dblock_compact_block(struct its_flash_fs_ctx_t *fs_ctx, uint32_t lblock, size_t free_size, size_t src_offset, size_t dst_offset, size_t size)
Compacts block data for the given logical block.
#define ITS_FLASH_FS_FLAG_CREATE
Definition: its_flash_fs.h:39
psa_status_t its_flash_fs_wipe_all(struct its_flash_fs_ctx_t *fs_ctx)
Wipes all files from the filesystem.
Definition: its_flash_fs.c:92
Structure to store the file information.
Definition: its_flash_fs.h:59
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.
#define PSA_ERROR_DOES_NOT_EXIST
Definition: crypto_values.h:89
uint16_t max_num_files
Definition: its_flash.h:167
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.
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:43
#define ITS_UTILS_ALIGN(x, a)
Aligns a value up to the provided alignment.
Definition: its_utils.h:56
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_UTILS_MIN(x, y)
Evaluates to the minimum of the two parameters.
Definition: its_utils.h:41
#define ITS_FLASH_FS_FLAG_TRUNCATE
Definition: its_flash_fs.h:41
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.