ITS: Move flash dev definitions to its_flash.c

Moves the ITS flash dev definitions from the its_flash.h header to the
source file, and declares them extern in the header, as the header
needs to be included by multiple files.

Change-Id: Ie03810801a53f0e504f8a0a7d9c0b545f1f3141a
Signed-off-by: Jamie Fox <jamie.fox@arm.com>
diff --git a/secure_fw/partitions/internal_trusted_storage/CMakeLists.txt b/secure_fw/partitions/internal_trusted_storage/CMakeLists.txt
index c4a96bb..2eb984e 100644
--- a/secure_fw/partitions/internal_trusted_storage/CMakeLists.txt
+++ b/secure_fw/partitions/internal_trusted_storage/CMakeLists.txt
@@ -28,6 +28,7 @@
         tfm_its_req_mngr.c
         tfm_internal_trusted_storage.c
         its_utils.c
+        flash/its_flash.c
         flash/its_flash_nand.c
         flash/its_flash_nor.c
         flash/its_flash_ram.c
diff --git a/secure_fw/partitions/internal_trusted_storage/flash/its_flash.c b/secure_fw/partitions/internal_trusted_storage/flash/its_flash.c
new file mode 100644
index 0000000..f2dd28f
--- /dev/null
+++ b/secure_fw/partitions/internal_trusted_storage/flash/its_flash.c
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "its_flash.h"
+
+#ifdef ITS_RAM_FS
+#ifndef ITS_RAM_FS_SIZE
+#error "ITS_RAM_FS_SIZE must be defined by the target in flash_layout.h"
+#endif
+uint8_t its_block_data[ITS_RAM_FS_SIZE];
+
+#elif (TFM_HAL_ITS_PROGRAM_UNIT > 16)
+#ifndef ITS_FLASH_NAND_BUF_SIZE
+#error "ITS_FLASH_NAND_BUF_SIZE must be defined by the target in flash_layout.h"
+#endif
+static uint8_t its_write_buf[ITS_FLASH_NAND_BUF_SIZE];
+struct its_flash_nand_dev_t its_flash_nand_dev = {
+    .driver = &TFM_HAL_ITS_FLASH_DRIVER,
+    .buf_block_id = ITS_BLOCK_INVALID_ID,
+    .write_buf = its_write_buf,
+    .buf_size = sizeof(its_write_buf),
+};
+#endif
+
+#ifdef TFM_PARTITION_PROTECTED_STORAGE
+#ifdef PS_RAM_FS
+#ifndef PS_RAM_FS_SIZE
+#error "PS_RAM_FS_SIZE must be defined by the target in flash_layout.h"
+#endif
+uint8_t ps_block_data[PS_RAM_FS_SIZE];
+
+#elif (TFM_HAL_PS_PROGRAM_UNIT > 16)
+#ifndef PS_FLASH_NAND_BUF_SIZE
+#error "PS_FLASH_NAND_BUF_SIZE must be defined by the target in flash_layout.h"
+#endif
+static uint8_t ps_write_buf[PS_FLASH_NAND_BUF_SIZE];
+struct its_flash_nand_dev_t ps_flash_nand_dev = {
+    .driver = &TFM_HAL_PS_FLASH_DRIVER,
+    .buf_block_id = ITS_BLOCK_INVALID_ID,
+    .write_buf = ps_write_buf,
+    .buf_size = sizeof(ps_write_buf),
+};
+#endif
+#endif /* TFM_PARTITION_PROTECTED_STORAGE */
diff --git a/secure_fw/partitions/internal_trusted_storage/flash/its_flash.h b/secure_fw/partitions/internal_trusted_storage/flash/its_flash.h
index dd021de..7b5ef5d 100644
--- a/secure_fw/partitions/internal_trusted_storage/flash/its_flash.h
+++ b/secure_fw/partitions/internal_trusted_storage/flash/its_flash.h
@@ -16,10 +16,7 @@
 #ifdef ITS_RAM_FS
 /* RAM FS: use a buffer to emulate storage in RAM */
 #include "its_flash_ram.h"
-#ifndef ITS_RAM_FS_SIZE
-#error "ITS_RAM_FS_SIZE must be defined by the target in flash_layout.h"
-#endif
-static uint8_t its_block_data[ITS_RAM_FS_SIZE];
+extern uint8_t its_block_data[];
 #define ITS_FLASH_DEV its_block_data
 #define ITS_FLASH_ALIGNMENT TFM_HAL_ITS_PROGRAM_UNIT
 #define ITS_FLASH_OPS its_flash_fs_ops_ram
@@ -29,16 +26,7 @@
  * shot, so no filesystem data alignment is required.
  */
 #include "its_flash_nand.h"
-#ifndef ITS_FLASH_NAND_BUF_SIZE
-#error "ITS_FLASH_NAND_BUF_SIZE must be defined by the target in flash_layout.h"
-#endif
-static uint8_t its_write_buf[ITS_FLASH_NAND_BUF_SIZE];
-static struct its_flash_nand_dev_t its_flash_nand_dev = {
-    .driver = &TFM_HAL_ITS_FLASH_DRIVER,
-    .buf_block_id = ITS_BLOCK_INVALID_ID,
-    .write_buf = its_write_buf,
-    .buf_size = sizeof(its_write_buf),
-};
+extern struct its_flash_nand_dev_t its_flash_nand_dev;
 #define ITS_FLASH_DEV its_flash_nand_dev
 #define ITS_FLASH_ALIGNMENT 1
 #define ITS_FLASH_OPS its_flash_fs_ops_nand
@@ -58,10 +46,7 @@
 #ifdef PS_RAM_FS
 /* RAM FS: use a buffer to emulate storage in RAM */
 #include "its_flash_ram.h"
-#ifndef PS_RAM_FS_SIZE
-#error "PS_RAM_FS_SIZE must be defined by the target in flash_layout.h"
-#endif
-static uint8_t ps_block_data[PS_RAM_FS_SIZE];
+extern uint8_t ps_block_data[];
 #define PS_FLASH_DEV ps_block_data
 #define PS_FLASH_ALIGNMENT TFM_HAL_PS_PROGRAM_UNIT
 #define PS_FLASH_OPS its_flash_fs_ops_ram
@@ -71,16 +56,7 @@
  * shot, so no filesystem data alignment is required.
  */
 #include "its_flash_nand.h"
-#ifndef PS_FLASH_NAND_BUF_SIZE
-#error "PS_FLASH_NAND_BUF_SIZE must be defined by the target in flash_layout.h"
-#endif
-static uint8_t ps_write_buf[PS_FLASH_NAND_BUF_SIZE];
-static struct its_flash_nand_dev_t ps_flash_nand_dev = {
-    .driver = &TFM_HAL_PS_FLASH_DRIVER,
-    .buf_block_id = ITS_BLOCK_INVALID_ID,
-    .write_buf = ps_write_buf,
-    .buf_size = sizeof(ps_write_buf),
-};
+extern struct its_flash_nand_dev_t ps_flash_nand_dev;
 #define PS_FLASH_DEV ps_flash_nand_dev
 #define PS_FLASH_ALIGNMENT 1
 #define PS_FLASH_OPS its_flash_fs_ops_nand