TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
its_flash_ram.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #include "its_flash_ram.h"
9 #include "tfm_memory_utils.h"
10 
20 static uint32_t get_phys_address(const struct its_flash_info_t *info,
21  uint32_t block_id, size_t offset)
22 {
23  return (block_id * info->block_size) + offset;
24 }
25 
27 {
28  /* Nothing needs to be done in case of flash emulated in RAM */
29  (void)info;
30  return PSA_SUCCESS;
31 }
32 
34  uint32_t block_id, uint8_t *buff, size_t offset,
35  size_t size)
36 {
37  uint32_t idx = get_phys_address(info, block_id, offset);
38 
39  (void)tfm_memcpy(buff, (uint8_t *)info->flash_dev + idx, size);
40 
41  return PSA_SUCCESS;
42 }
43 
45  uint32_t block_id, const uint8_t *buff,
46  size_t offset, size_t size)
47 {
48  uint32_t idx = get_phys_address(info, block_id, offset);
49 
50  (void)tfm_memcpy((uint8_t *)info->flash_dev + idx, buff, size);
51 
52  return PSA_SUCCESS;
53 }
54 
56 {
57  /* Nothing needs to be done for flash emulated in RAM, as writes are
58  * commited immediately.
59  */
60  (void)info;
61  return PSA_SUCCESS;
62 }
63 
65  uint32_t block_id)
66 {
67  uint32_t idx = get_phys_address(info, block_id, 0);
68 
69  (void)tfm_memset((uint8_t *)info->flash_dev + idx, info->erase_val,
70  info->block_size);
71 
72  return PSA_SUCCESS;
73 }
__STATIC_INLINE void * tfm_memset(void *ptr, int value, size_t num)
#define PSA_SUCCESS
Definition: crypto_values.h:35
psa_status_t its_flash_ram_write(const struct its_flash_info_t *info, uint32_t block_id, const uint8_t *buff, size_t offset, size_t size)
Writes block data to the position specified by block ID and offset.
Definition: its_flash_ram.c:44
uint16_t block_size
Definition: its_flash.h:160
psa_status_t its_flash_ram_read(const struct its_flash_info_t *info, uint32_t block_id, uint8_t *buff, size_t offset, size_t size)
Reads block data from the position specified by block ID and offset.
Definition: its_flash_ram.c:33
psa_status_t its_flash_ram_init(const struct its_flash_info_t *info)
Initialize the Flash Interface.
Definition: its_flash_ram.c:26
psa_status_t its_flash_ram_flush(const struct its_flash_info_t *info)
Flushes modifications to a block to flash.
Definition: its_flash_ram.c:55
Implementations of the flash interface functions for an emulated flash device using RAM...
psa_status_t its_flash_ram_erase(const struct its_flash_info_t *info, uint32_t block_id)
Erases block ID data.
Definition: its_flash_ram.c:64
void * flash_dev
Definition: its_flash.h:155
uint8_t erase_val
Definition: its_flash.h:168
__STATIC_INLINE void * tfm_memcpy(void *dest, const void *src, size_t num)
Structure containing the required information about a flash device to be used by the ITS Flash FS...
Definition: its_flash.h:73
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:43