TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
its_flash_nor.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-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_nor.h"
10 #include "Driver_Flash.h"
11 
21 static uint32_t get_phys_address(const struct its_flash_info_t *info,
22  uint32_t block_id, size_t offset)
23 {
24  return info->fs_info.flash_area_addr + (block_id * info->block_size)
25  + offset;
26 }
27 
29 {
30  int32_t err;
31 
32  err = ((ARM_DRIVER_FLASH *)info->flash_dev)->Initialize(NULL);
33  if (err != ARM_DRIVER_OK) {
35  }
36 
37  return PSA_SUCCESS;
38 }
39 
41  uint32_t block_id, uint8_t *buff, size_t offset,
42  size_t size)
43 {
44  int32_t err;
45  uint32_t addr = get_phys_address(info, block_id, offset);
46 
47  err = ((ARM_DRIVER_FLASH *)info->flash_dev)->ReadData(addr, buff, size);
48  if (err != ARM_DRIVER_OK) {
50  }
51 
52  return PSA_SUCCESS;
53 }
54 
56  uint32_t block_id, const uint8_t *buff,
57  size_t offset, size_t size)
58 {
59  int32_t err;
60  uint32_t addr = get_phys_address(info, block_id, offset);
61 
62  err = ((ARM_DRIVER_FLASH *)info->flash_dev)->ProgramData(addr, buff, size);
63  if (err != ARM_DRIVER_OK) {
65  }
66 
67  return PSA_SUCCESS;
68 }
69 
71 {
72  /* Nothing needs to be done for NOR flash, as writes are commited to flash
73  * immediately.
74  */
75  (void)info;
76  return PSA_SUCCESS;
77 }
78 
80  uint32_t block_id)
81 {
82  int32_t err;
83  uint32_t addr;
84  size_t offset;
85 
86  for (offset = 0; offset < info->block_size; offset += info->sector_size) {
87  addr = get_phys_address(info, block_id, offset);
88 
89  err = ((ARM_DRIVER_FLASH *)info->flash_dev)->EraseSector(addr);
90  if (err != ARM_DRIVER_OK) {
92  }
93  }
94 
95  return PSA_SUCCESS;
96 }
psa_status_t its_flash_nor_erase(const struct its_flash_info_t *info, uint32_t block_id)
Erases block ID data.
Definition: its_flash_nor.c:79
psa_status_t its_flash_nor_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_nor.c:55
uint32_t flash_area_addr
Definition: its_flash.h:63
#define PSA_ERROR_STORAGE_FAILURE
Implementations of the flash interface functions for a NOR flash device. See its_flash.h for full documentation of functions.
#define PSA_SUCCESS
Definition: crypto_values.h:35
psa_status_t its_flash_nor_flush(const struct its_flash_info_t *info)
Flushes modifications to a block to flash.
Definition: its_flash_nor.c:70
uint16_t block_size
Definition: its_flash.h:160
psa_status_t its_flash_nor_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_nor.c:40
psa_status_t its_flash_nor_init(const struct its_flash_info_t *info)
Initialize the Flash Interface.
Definition: its_flash_nor.c:28
void * flash_dev
Definition: its_flash.h:155
struct flash_fs_info_t fs_info
Definition: its_flash.h:156
uint16_t sector_size
Definition: its_flash.h:157
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