Attest: Accept empty shared data area

Introduce the BOOT_DATA_AVAILABLE CMake variable to indicate whether
boot data is available in the shared data area (between the boot loader
and runtime firmware). If it's false the content of the shared data area
will be ignored and thus all the tests will pass for example when TF-M
is used with a boot loader that doesn't provide any boot data or when a
boot loader is not used at all.

Change-Id: Ic6d32cfdc8741018c6668692d64f81236006b593
Signed-off-by: David Vincze <david.vincze@arm.com>
diff --git a/secure_fw/CMakeLists.txt b/secure_fw/CMakeLists.txt
index e71971e..8721111 100644
--- a/secure_fw/CMakeLists.txt
+++ b/secure_fw/CMakeLists.txt
@@ -161,6 +161,10 @@
 	embedded_set_target_compile_defines(TARGET ${PROJECT_OBJ_LIB} LANGUAGE C DEFINES TFM_NVCOUNTERS_ENABLE APPEND)
 endif()
 
+if(BOOT_DATA_AVAILABLE)
+	embedded_set_target_compile_defines(TARGET ${PROJECT_OBJ_LIB} LANGUAGE C DEFINES BOOT_DATA_AVAILABLE APPEND)
+endif()
+
 if (NOT DEFINED CORE_TEST)
 	message(FATAL_ERROR "Incomplete build configuration: CORE_TEST is undefined.")
 elseif(CORE_TEST)
diff --git a/secure_fw/core/tfm_boot_data.c b/secure_fw/core/tfm_boot_data.c
index 7a3edc9..079e020 100644
--- a/secure_fw/core/tfm_boot_data.c
+++ b/secure_fw/core/tfm_boot_data.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -120,6 +120,7 @@
 
 void tfm_core_validate_boot_data(void)
 {
+#ifdef BOOT_DATA_AVAILABLE
     struct tfm_boot_data *boot_data;
 
     boot_data = (struct tfm_boot_data *)BOOT_TFM_SHARED_DATA_BASE;
@@ -127,6 +128,9 @@
     if (boot_data->header.tlv_magic == SHARED_DATA_TLV_INFO_MAGIC) {
         is_boot_data_valid = BOOT_DATA_VALID;
     }
+#else
+    is_boot_data_valid = BOOT_DATA_VALID;
+#endif /* BOOT_DATA_AVAILABLE */
 }
 
 void tfm_core_get_boot_data_handler(uint32_t args[])
@@ -136,8 +140,10 @@
     uint16_t buf_size  = (uint16_t)args[2];
     uint8_t *ptr;
     struct tfm_boot_data *boot_data;
+#ifdef BOOT_DATA_AVAILABLE
     struct shared_data_tlv_entry tlv_entry;
     uintptr_t tlv_end, offset;
+#endif /* BOOT_DATA_AVAILABLE */
 #ifndef TFM_PSA_API
     uint32_t running_partition_idx =
                 tfm_spm_partition_get_running_partition_idx();
@@ -188,10 +194,12 @@
         return;
     }
 
+#ifdef BOOT_DATA_AVAILABLE
     /* Get the boundaries of TLV section */
     boot_data = (struct tfm_boot_data *)BOOT_TFM_SHARED_DATA_BASE;
     tlv_end = BOOT_TFM_SHARED_DATA_BASE + boot_data->header.tlv_tot_len;
     offset  = BOOT_TFM_SHARED_DATA_BASE + SHARED_DATA_HEADER_SIZE;
+#endif /* BOOT_DATA_AVAILABLE */
 
     /* Add header to output buffer as well */
     if (buf_size < SHARED_DATA_HEADER_SIZE) {
@@ -204,6 +212,7 @@
         ptr = boot_data->data;
     }
 
+#ifdef BOOT_DATA_AVAILABLE
     /* Iterates over the TLV section and copy TLVs with requested major
      * type to the provided buffer.
      */
@@ -226,6 +235,8 @@
             boot_data->header.tlv_tot_len += tlv_entry.tlv_len;
         }
     }
+#endif /* BOOT_DATA_AVAILABLE */
+
     args[0] = (uint32_t)TFM_SUCCESS;
     return;
 }
diff --git a/secure_fw/services/initial_attestation/tfm_attestation.c b/secure_fw/services/initial_attestation/tfm_attestation.c
index 1b8757a..7e20b2e 100644
--- a/secure_fw/services/initial_attestation/tfm_attestation.c
+++ b/secure_fw/services/initial_attestation/tfm_attestation.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -57,22 +57,12 @@
                      uint32_t len)
 {
     enum psa_attest_err_t attest_res = PSA_ATTEST_ERR_SUCCESS;
-
-#ifndef BL2
-    /* Avoid compiler warning due to unused argument */
-    (void)len;
-    (void)major_type;
-
-    boot_data->header.tlv_magic   = SHARED_DATA_TLV_INFO_MAGIC;
-    boot_data->header.tlv_tot_len = SHARED_DATA_HEADER_SIZE;
-#else
     int32_t tfm_res;
 
     tfm_res = tfm_core_get_boot_data(major_type, boot_data, len);
     if (tfm_res != (int32_t)TFM_SUCCESS) {
         attest_res =  PSA_ATTEST_ERR_INIT_FAILED;
     }
-#endif /* BL2 */
 
     return attest_res;
 }