Build: Major warnings cleanup

This is a major type-mismatch cleanup and warnings elimination.

The IAR toolchain runs with more warnings enabled than ARMCLANG or
GNUARM, which has resulted in this effort.

This should make it easier to enable "pedantic" mode also for GNUARM.

There are still a few warnings about jumping past variable
initialization and falling off the end of non-void functions, but there
are comments in some of these parts that implies that this is done to
catch programming errors, like having case labels for all possible enum
values.

Reordered initializer in tfm_attestation_req_mngr.c to eliminate CI
warning.

Disabled "Pe940" warnings in CommonConfig.cmake to suppress warnings
about inline assembly functions declared to return value that doesn't
declare a return value in the __ASM() statement.

Disabled "Pe546" warnings to supress warnings about jumping over
unused initializers.

Fixed what appears to be a copy/paste bug in tfm_ss_core_test.c.

Removed unused variable "ret" in Driver_PPC.c for AN519 and AN521, to
make it similar to AN524.

Signed-off-by: TTornblom <thomas.tornblom@iar.com>
Change-Id: I2b729c73e4b004cff6b0530cc1350fcf900e4272
diff --git a/secure_fw/core/include/tfm_irq_list.h b/secure_fw/core/include/tfm_irq_list.h
index ab22ca7..fbad8f4 100644
--- a/secure_fw/core/include/tfm_irq_list.h
+++ b/secure_fw/core/include/tfm_irq_list.h
@@ -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
  *
@@ -15,7 +15,7 @@
 struct tfm_core_irq_signal_data_t {
     int32_t partition_id;
     psa_signal_t signal_value;
-    int32_t irq_line;
+    IRQn_Type irq_line;
     uint32_t irq_priority;
 };
 
diff --git a/secure_fw/core/ipc/tfm_multi_core.c b/secure_fw/core/ipc/tfm_multi_core.c
index 75db3be..0678509 100644
--- a/secure_fw/core/ipc/tfm_multi_core.c
+++ b/secure_fw/core/ipc/tfm_multi_core.c
@@ -42,7 +42,8 @@
     while (1) {
     }
 
-    /* Should not run here */
+
+    /* NOTREACHED */
     TFM_ASSERT(false);
 }
 
diff --git a/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc b/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc
index d44f7c6..0c86e72 100644
--- a/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc
+++ b/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc
@@ -29,7 +29,7 @@
 #ifdef TFM_ENABLE_IRQ_TEST
     { TFM_IRQ_TEST_1, SPM_CORE_IRQ_TEST_1_SIGNAL_TIMER_0_IRQ, TFM_TIMER0_IRQ, 64 },
 #endif /* TFM_ENABLE_IRQ_TEST */
-   {0, 0, 0, 0}                         /* add dummy element to avoid non-standard empty array */
+   {0, 0, (IRQn_Type) 0, 0}                         /* add dummy element to avoid non-standard empty array */
 };
 
 const size_t tfm_core_irq_signals_count = (sizeof(tfm_core_irq_signals) /
diff --git a/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc.template b/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc.template
index 5e9d44c..e5a7d6b 100644
--- a/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc.template
+++ b/secure_fw/core/ipc/tfm_secure_irq_handlers_ipc.inc.template
@@ -41,7 +41,7 @@
         {% endif %}
    {% endif %}
 {% endfor %}
-   {0, 0, 0, 0}                         /* add dummy element to avoid non-standard empty array */
+   {0, 0, (IRQn_Type) 0, 0}                         /* add dummy element to avoid non-standard empty array */
 };
 
 const size_t tfm_core_irq_signals_count = (sizeof(tfm_core_irq_signals) /
diff --git a/secure_fw/core/ipc/tfm_spe_mailbox.c b/secure_fw/core/ipc/tfm_spe_mailbox.c
index edc5eeb..baa02c7 100644
--- a/secure_fw/core/ipc/tfm_spe_mailbox.c
+++ b/secure_fw/core/ipc/tfm_spe_mailbox.c
@@ -19,7 +19,7 @@
 
 static int32_t tfm_mailbox_dispatch(uint32_t call_type,
                                     const struct psa_client_params_t *params,
-                                    int32_t client_id, uint32_t *psa_ret)
+                                    int32_t client_id, int32_t *psa_ret)
 {
     struct client_call_params_t spm_params = {0};
 
@@ -183,7 +183,7 @@
 {
     uint8_t idx;
     int32_t result;
-    uint32_t psa_ret = PSA_ERROR_GENERIC_ERROR;
+    int32_t psa_ret = PSA_ERROR_GENERIC_ERROR;
     mailbox_queue_status_t mask_bits, pend_slots, reply_slots = 0;
     struct ns_mailbox_queue_t *ns_queue = spe_mailbox_queue.ns_queue;
     struct mailbox_msg_t *msg_ptr;
diff --git a/secure_fw/core/tfm_boot_data.c b/secure_fw/core/tfm_boot_data.c
index 02bcc1f..84a7825 100644
--- a/secure_fw/core/tfm_boot_data.c
+++ b/secure_fw/core/tfm_boot_data.c
@@ -138,9 +138,9 @@
     uint8_t  tlv_major = (uint8_t)args[0];
     uint8_t *buf_start = (uint8_t *)args[1];
     uint16_t buf_size  = (uint16_t)args[2];
-    uint8_t *ptr;
     struct tfm_boot_data *boot_data;
 #ifdef BOOT_DATA_AVAILABLE
+    uint8_t *ptr;
     struct shared_data_tlv_entry tlv_entry;
     uintptr_t tlv_end, offset;
 #endif /* BOOT_DATA_AVAILABLE */
@@ -210,10 +210,10 @@
         boot_data = (struct tfm_boot_data *)buf_start;
         boot_data->header.tlv_magic   = SHARED_DATA_TLV_INFO_MAGIC;
         boot_data->header.tlv_tot_len = SHARED_DATA_HEADER_SIZE;
-        ptr = boot_data->data;
     }
 
 #ifdef BOOT_DATA_AVAILABLE
+    ptr = boot_data->data;
     /* Iterates over the TLV section and copy TLVs with requested major
      * type to the provided buffer.
      */
diff --git a/secure_fw/core/tfm_core_svcalls_ipc.c b/secure_fw/core/tfm_core_svcalls_ipc.c
index 202b5173..7cbf907 100644
--- a/secure_fw/core/tfm_core_svcalls_ipc.c
+++ b/secure_fw/core/tfm_core_svcalls_ipc.c
@@ -120,7 +120,7 @@
 
 uint32_t tfm_core_svc_handler(uint32_t *svc_args, uint32_t exc_return)
 {
-    uint8_t svc_number = 0;
+    tfm_svc_number_t svc_number = TFM_SVC_SFN_REQUEST;
     /*
      * Stack contains:
      * r0, r1, r2, r3, r12, r14 (lr), the return address and xPSR
@@ -130,7 +130,7 @@
         /* SV called directly from secure context. Check instruction for
          * svc_number
          */
-        svc_number = ((uint8_t *)svc_args[6])[-2];
+        svc_number = ((tfm_svc_number_t *)svc_args[6])[-2];
     } else {
         /* Secure SV executing with NS return.
          * NS cannot directly trigger S SVC so this should not happen. This is
diff --git a/secure_fw/services/crypto/crypto_init.c b/secure_fw/services/crypto/crypto_init.c
index b3acd55..743ce1d 100644
--- a/secure_fw/services/crypto/crypto_init.c
+++ b/secure_fw/services/crypto/crypto_init.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
  *
@@ -113,7 +113,7 @@
                                         const uint32_t sfn_id)
 {
     psa_status_t status = PSA_SUCCESS;
-    size_t in_len = PSA_MAX_IOVEC, out_len = PSA_MAX_IOVEC, i, read_size;
+    size_t in_len = PSA_MAX_IOVEC, out_len = PSA_MAX_IOVEC, i;
     psa_invec in_vec[PSA_MAX_IOVEC] = { {0} };
     psa_outvec out_vec[PSA_MAX_IOVEC] = { {0} };
     void *alloc_buf_ptr = NULL;
@@ -140,7 +140,7 @@
             return status;
         }
         /* Read from the IPC framework inputs into the scratch */
-        read_size = psa_read(msg->handle, i, alloc_buf_ptr, msg->in_size[i]);
+        (void) psa_read(msg->handle, i, alloc_buf_ptr, msg->in_size[i]);
         /* Populate the fields of the input to the secure function */
         in_vec[i].base = alloc_buf_ptr;
         in_vec[i].len = msg->in_size[i];
@@ -258,7 +258,7 @@
         }
     }
 
-    /* This is unreachable */
+    /* NOTREACHED */
     return;
 }
 #endif /* TFM_PSA_API */
diff --git a/secure_fw/services/crypto/crypto_key.c b/secure_fw/services/crypto/crypto_key.c
index e88040d..ef3b309 100644
--- a/secure_fw/services/crypto/crypto_key.c
+++ b/secure_fw/services/crypto/crypto_key.c
@@ -577,7 +577,6 @@
 
     return status;
 #endif /* TFM_CRYPTO_KEY_MODULE_DISABLED */
-    return PSA_ERROR_NOT_SUPPORTED;
 }
 
 psa_status_t tfm_crypto_generate_key(psa_invec in_vec[],
diff --git a/secure_fw/services/initial_attestation/tfm_attestation_req_mngr.c b/secure_fw/services/initial_attestation/tfm_attestation_req_mngr.c
index 07d9a80..8366bfb 100644
--- a/secure_fw/services/initial_attestation/tfm_attestation_req_mngr.c
+++ b/secure_fw/services/initial_attestation/tfm_attestation_req_mngr.c
@@ -171,13 +171,10 @@
 
 psa_status_t attest_partition_init(void)
 {
-    psa_status_t err = PSA_SUCCESS;
+    psa_status_t err = attest_init();
 #ifdef TFM_PSA_API
     psa_signal_t signals;
-#endif
 
-    err = attest_init();
-#ifdef TFM_PSA_API
     if (err != PSA_SUCCESS) {
         tfm_abort();
     }
@@ -197,6 +194,7 @@
             tfm_abort();
         }
     }
-#endif
+#else
     return err;
+#endif
 }
diff --git a/secure_fw/services/internal_trusted_storage/tfm_its_req_mngr.c b/secure_fw/services/internal_trusted_storage/tfm_its_req_mngr.c
index 518f877..eb634b8 100644
--- a/secure_fw/services/internal_trusted_storage/tfm_its_req_mngr.c
+++ b/secure_fw/services/internal_trusted_storage/tfm_its_req_mngr.c
@@ -349,8 +349,8 @@
         return PSA_ERROR_GENERIC_ERROR;
     }
     its_is_init = true;
-#endif
     return PSA_SUCCESS;
+#endif
 }
 
 size_t its_req_mngr_read(uint8_t *buf, size_t num_bytes)
diff --git a/secure_fw/services/platform/platform_sp.c b/secure_fw/services/platform/platform_sp.c
index f5d0973..b17e62e 100644
--- a/secure_fw/services/platform/platform_sp.c
+++ b/secure_fw/services/platform/platform_sp.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
  *
@@ -102,16 +102,16 @@
 
     num = psa_read(msg->handle, 0, &request, sizeof(request));
     if (num != sizeof(request)) {
-        return PSA_ERROR_PROGRAMMER_ERROR;
+        return (enum tfm_platform_err_t) PSA_ERROR_PROGRAMMER_ERROR;
     }
 
     if (in_len > 1) {
         if (msg->in_size[1] > INPUT_BUFFER_SIZE) {
-            return PSA_ERROR_PROGRAMMER_ERROR;
+            return (enum tfm_platform_err_t) PSA_ERROR_PROGRAMMER_ERROR;
         }
         num = psa_read(msg->handle, 1, &input_buffer, msg->in_size[1]);
         if (num != msg->in_size[1]) {
-            return PSA_ERROR_PROGRAMMER_ERROR;
+            return (enum tfm_platform_err_t) PSA_ERROR_PROGRAMMER_ERROR;
         }
         invec.base = input_buffer;
         invec.len = msg->in_size[1];
@@ -120,7 +120,7 @@
 
     if (out_len > 0) {
         if (msg->out_size[0] > OUTPUT_BUFFER_SIZE) {
-            return PSA_ERROR_PROGRAMMER_ERROR;
+            return (enum tfm_platform_err_t) PSA_ERROR_PROGRAMMER_ERROR;
         }
         outvec.base = output_buffer;
         outvec.len = msg->out_size[0];
@@ -188,7 +188,7 @@
         }
     }
 
-#endif /* TFM_PSA_API */
-
+#else
     return TFM_PLATFORM_ERR_SUCCESS;
+#endif /* TFM_PSA_API */
 }
diff --git a/secure_fw/services/secure_storage/tfm_sst_req_mngr.c b/secure_fw/services/secure_storage/tfm_sst_req_mngr.c
index ec9635d..94a0e78 100644
--- a/secure_fw/services/secure_storage/tfm_sst_req_mngr.c
+++ b/secure_fw/services/secure_storage/tfm_sst_req_mngr.c
@@ -418,12 +418,13 @@
             tfm_abort();
         }
     }
-#endif
+#else
     /* In library mode, initialisation is delayed until the first secure
      * function call, as calls to the Crypto service are required for
      * initialisation.
      */
     return PSA_SUCCESS;
+#endif
 }
 
 psa_status_t sst_req_mngr_read_asset_data(uint8_t *out_data, uint32_t size)
diff --git a/secure_fw/spm/spm_func.c b/secure_fw/spm/spm_func.c
index 6b9c46b..afb0479 100644
--- a/secure_fw/spm/spm_func.c
+++ b/secure_fw/spm/spm_func.c
@@ -411,7 +411,7 @@
     uint32_t handler_partition_id = svc_ctx->r0;
     sfn_t unpriv_handler = (sfn_t)svc_ctx->r1;
     uint32_t irq_signal = svc_ctx->r2;
-    uint32_t irq_line = svc_ctx->r3;
+    IRQn_Type irq_line = (IRQn_Type) svc_ctx->r3;
     enum tfm_status_e res;
     uint32_t psp = __get_PSP();
     uint32_t handler_partition_psp;
@@ -922,7 +922,7 @@
  * \retval >=0     The IRQ line number associated with a signal in the partition
  * \retval <0      error
  */
-static int32_t get_irq_line_for_signal(int32_t partition_id,
+static IRQn_Type get_irq_line_for_signal(int32_t partition_id,
                                        psa_signal_t signal)
 {
     size_t i;
@@ -933,7 +933,7 @@
             return tfm_core_irq_signals[i].irq_line;
         }
     }
-    return -1;
+    return (IRQn_Type) -1;
 }
 
 void tfm_spm_enable_irq_handler(uint32_t *svc_args)
@@ -945,7 +945,7 @@
                       tfm_spm_partition_get_running_partition_idx();
     uint32_t running_partition_id =
                       tfm_spm_partition_get_partition_id(running_partition_idx);
-    int32_t irq_line;
+    IRQn_Type irq_line;
 
     /* Only a single signal is allowed */
     if (!tfm_is_one_bit_set(irq_signal)) {
@@ -972,7 +972,7 @@
                       tfm_spm_partition_get_running_partition_idx();
     uint32_t running_partition_id =
                       tfm_spm_partition_get_partition_id(running_partition_idx);
-    int32_t irq_line;
+    IRQn_Type irq_line;
 
     /* Only a single signal is allowed */
     if (!tfm_is_one_bit_set(irq_signal)) {
@@ -1030,7 +1030,7 @@
     uint32_t running_partition_idx;
     uint32_t running_partition_id;
     const struct spm_partition_runtime_data_t *curr_part_data;
-    int32_t irq_line;
+    IRQn_Type irq_line;
 
     running_partition_idx = tfm_spm_partition_get_running_partition_idx();
     running_partition_id =
diff --git a/secure_fw/spm/spm_ipc.c b/secure_fw/spm/spm_ipc.c
index 90e688f..d6e707d 100644
--- a/secure_fw/spm/spm_ipc.c
+++ b/secure_fw/spm/spm_ipc.c
@@ -47,7 +47,7 @@
                  TFM_CONN_HANDLE_MAX_NUM);
 
 void tfm_irq_handler(uint32_t partition_id, psa_signal_t signal,
-                     int32_t irq_line);
+                     IRQn_Type irq_line);
 
 #include "tfm_secure_irq_handlers_ipc.inc"
 
@@ -1392,7 +1392,7 @@
  * \retval "Does not return"    Partition ID is invalid
  */
 void tfm_irq_handler(uint32_t partition_id, psa_signal_t signal,
-                     int32_t irq_line)
+                     IRQn_Type irq_line)
 {
     tfm_spm_hal_disable_irq(irq_line);
     notify_with_signal(partition_id, signal);
@@ -1441,7 +1441,7 @@
  */
 static int32_t get_irq_line_for_signal(int32_t partition_id,
                                        psa_signal_t signal,
-                                       int32_t *irq_line)
+                                       IRQn_Type *irq_line)
 {
     size_t i;
 
@@ -1458,7 +1458,7 @@
 void tfm_spm_psa_eoi(uint32_t *args)
 {
     psa_signal_t irq_signal;
-    int32_t irq_line = 0;
+    IRQn_Type irq_line = (IRQn_Type) 0;
     int32_t ret;
     struct spm_partition_desc_t *partition = NULL;
 
@@ -1497,7 +1497,7 @@
 {
     struct tfm_state_context_t *svc_ctx = (struct tfm_state_context_t *)args;
     psa_signal_t irq_signal = svc_ctx->r0;
-    int32_t irq_line = 0;
+    IRQn_Type irq_line = (IRQn_Type) 0;
     int32_t ret;
     struct spm_partition_desc_t *partition = NULL;
 
@@ -1525,7 +1525,7 @@
 {
     struct tfm_state_context_t *svc_ctx = (struct tfm_state_context_t *)args;
     psa_signal_t irq_signal = svc_ctx->r0;
-    int32_t irq_line = 0;
+    IRQn_Type irq_line = (IRQn_Type) 0;
     int32_t ret;
     struct spm_partition_desc_t *partition = NULL;