Platform: Move data_width_byte variable from RAM to Flash
If the const variable is defined as local variable, then it
is stored in Flash and loaded to RAM(stack) when it runs.
If it is defined as file static, its runtime address will be
allocated in Flash. So copy to RAM is avoided and Flash cost
remains the same.
Signed-off-by: Sherry Zhang <sherry.zhang2@arm.com>
Change-Id: I701a6cf01abc5a6d587aa7c263dec0a221487e5c
diff --git a/bl2/src/flash_map.c b/bl2/src/flash_map.c
index 51f3272..1197af5 100644
--- a/bl2/src/flash_map.c
+++ b/bl2/src/flash_map.c
@@ -30,6 +30,13 @@
extern const struct flash_area flash_map[];
extern const int flash_map_entry_num;
+/* Valid entries for data item width */
+static const uint32_t data_width_byte[] = {
+ sizeof(uint8_t),
+ sizeof(uint16_t),
+ sizeof(uint32_t),
+};
+
/*
* Check the target address in the flash_area_xxx operation.
*/
@@ -99,12 +106,6 @@
uint8_t data_width, i = 0, j;
int ret = 0;
- /* Valid entries for data item width */
- const uint32_t data_width_byte[] = {
- sizeof(uint8_t),
- sizeof(uint16_t),
- sizeof(uint32_t),
- };
ARM_FLASH_CAPABILITIES DriverCapabilities;
BOOT_LOG_DBG("read area=%d, off=%#x, len=%#x", area->fa_id, off, len);
@@ -191,12 +192,6 @@
#else
uint8_t len_padding[FLASH_PROGRAM_UNIT - 1];
#endif
- /* Valid entries for data item width */
- const uint32_t data_width_byte[] = {
- sizeof(uint8_t),
- sizeof(uint16_t),
- sizeof(uint32_t),
- };
ARM_FLASH_CAPABILITIES DriverCapabilities;
uint8_t data_width;
/* The PROGRAM_UNIT aligned value of `off` */
diff --git a/platform/ext/common/template/flash_otp_nv_counters_backend.c b/platform/ext/common/template/flash_otp_nv_counters_backend.c
index b0baba5..e9fdff6 100644
--- a/platform/ext/common/template/flash_otp_nv_counters_backend.c
+++ b/platform/ext/common/template/flash_otp_nv_counters_backend.c
@@ -61,6 +61,12 @@
#endif /* defined(OTP_WRITEABLE)*/
#else /* OTP_NV_COUNTERS_RAM_EMULATION */
+/* Valid entries for data item width */
+static const uint32_t data_width_byte[] = {
+ sizeof(uint8_t),
+ sizeof(uint16_t),
+ sizeof(uint32_t),
+};
#if defined(OTP_WRITEABLE)
static enum tfm_plat_err_t make_backup(void);
@@ -121,12 +127,6 @@
enum tfm_plat_err_t err = TFM_PLAT_ERR_SUCCESS;
ARM_FLASH_CAPABILITIES DriverCapabilities;
uint8_t data_width;
- /* Valid entries for data item width */
- uint32_t data_width_byte[] = {
- sizeof(uint8_t),
- sizeof(uint16_t),
- sizeof(uint32_t),
- };
uint32_t remaining_cnt, read_cnt;
uint8_t temp_buffer[sizeof(uint32_t)];
@@ -259,12 +259,6 @@
end = size;
ARM_FLASH_CAPABILITIES DriverCapabilities;
uint8_t data_width;
- /* Valid entries for data item width */
- uint32_t data_width_byte[] = {
- sizeof(uint8_t),
- sizeof(uint16_t),
- sizeof(uint32_t),
- };
DriverCapabilities = OTP_NV_COUNTERS_FLASH_DEV.GetCapabilities();
data_width = data_width_byte[DriverCapabilities.data_width];
@@ -316,12 +310,6 @@
end = round_up(offset + cnt, TFM_OTP_NV_COUNTERS_SECTOR_SIZE);
ARM_FLASH_CAPABILITIES DriverCapabilities;
uint8_t data_width;
- /* Valid entries for data item width */
- uint32_t data_width_byte[] = {
- sizeof(uint8_t),
- sizeof(uint16_t),
- sizeof(uint32_t),
- };
DriverCapabilities = OTP_NV_COUNTERS_FLASH_DEV.GetCapabilities();
data_width = data_width_byte[DriverCapabilities.data_width];
@@ -431,12 +419,6 @@
size_t copy_size;
ARM_FLASH_CAPABILITIES DriverCapabilities;
uint8_t data_width;
- /* Valid entries for data item width */
- uint32_t data_width_byte[] = {
- sizeof(uint8_t),
- sizeof(uint16_t),
- sizeof(uint32_t),
- };
DriverCapabilities = OTP_NV_COUNTERS_FLASH_DEV.GetCapabilities();
data_width = data_width_byte[DriverCapabilities.data_width];
diff --git a/secure_fw/partitions/internal_trusted_storage/flash/its_flash_nand.c b/secure_fw/partitions/internal_trusted_storage/flash/its_flash_nand.c
index d3108ad..2b3c62d 100644
--- a/secure_fw/partitions/internal_trusted_storage/flash/its_flash_nand.c
+++ b/secure_fw/partitions/internal_trusted_storage/flash/its_flash_nand.c
@@ -11,6 +11,13 @@
#include "flash_fs/its_flash_fs.h"
#include "tfm_memory_utils.h"
+/* Valid entries for data item width */
+static const uint32_t data_width_byte[] = {
+ sizeof(uint8_t),
+ sizeof(uint16_t),
+ sizeof(uint32_t),
+};
+
/**
* \brief Gets physical address of the given block ID.
*
@@ -58,13 +65,6 @@
/* The max size of flash data_width is 4 bytes. */
uint8_t temp_buffer[sizeof(uint32_t)];
ARM_FLASH_CAPABILITIES DriverCapabilities;
-
- /* Valid entries for data item width */
- const uint32_t data_width_byte[] = {
- sizeof(uint8_t),
- sizeof(uint16_t),
- sizeof(uint32_t),
- };
uint8_t data_width;
int ret;
@@ -178,13 +178,6 @@
(struct its_flash_nand_dev_t *)cfg->flash_dev;
uint32_t addr;
ARM_FLASH_CAPABILITIES DriverCapabilities;
-
- /* Valid entries for data item width */
- const uint32_t data_width_byte[] = {
- sizeof(uint8_t),
- sizeof(uint16_t),
- sizeof(uint32_t),
- };
uint8_t data_width;
DriverCapabilities = flash_dev->driver->GetCapabilities();
diff --git a/secure_fw/partitions/internal_trusted_storage/flash/its_flash_nor.c b/secure_fw/partitions/internal_trusted_storage/flash/its_flash_nor.c
index 3c5abe3..5e13683 100644
--- a/secure_fw/partitions/internal_trusted_storage/flash/its_flash_nor.c
+++ b/secure_fw/partitions/internal_trusted_storage/flash/its_flash_nor.c
@@ -12,6 +12,13 @@
#include "driver/Driver_Flash.h"
#include "tfm_memory_utils.h"
+/* Valid entries for data item width */
+static const uint32_t data_width_byte[] = {
+ sizeof(uint8_t),
+ sizeof(uint16_t),
+ sizeof(uint32_t),
+};
+
/**
* \brief Gets physical address of the given block ID.
*
@@ -50,13 +57,6 @@
/* The max size of flash data_width is 4 bytes. */
uint8_t temp_buffer[sizeof(uint32_t)];
ARM_FLASH_CAPABILITIES DriverCapabilities;
-
- /* Valid entries for data item width */
- const uint32_t data_width_byte[] = {
- sizeof(uint8_t),
- sizeof(uint16_t),
- sizeof(uint32_t),
- };
uint8_t data_width;
int ret;
@@ -142,13 +142,6 @@
int32_t err;
ARM_FLASH_CAPABILITIES DriverCapabilities;
uint32_t addr;
-
- /* Valid entries for data item width */
- const uint32_t data_width_byte[] = {
- sizeof(uint8_t),
- sizeof(uint16_t),
- sizeof(uint32_t),
- };
uint8_t data_width;
DriverCapabilities =