HAL: Rename platform init function

Align with HAL design document:
 - Rename 'tfm_spm_hal_post_init' to 'tfm_hal_platform_init'.
 - Set 'tfm_hal_platform_init' to weak, and platform with specific init
   operation needs to override it.
 - Remove 'tfm_spm_hal_post_init_platform' and move the operations to
   'tfm_hal_platform_init'.

Change-Id: Ia96b3a6bae716d154edab8709eb6e277bafcb45e
Signed-off-by: Summer Qin <summer.qin@arm.com>
diff --git a/platform/ext/common/tfm_platform.c b/platform/ext/common/tfm_platform.c
index fc9ecb7..fd13dc2 100644
--- a/platform/ext/common/tfm_platform.c
+++ b/platform/ext/common/tfm_platform.c
@@ -8,23 +8,14 @@
 #include "target_cfg.h"
 #include "tfm_spm_hal.h"
 #include "uart_stdout.h"
+#include "tfm_hal_platform.h"
 
-/* platform-specific hw initialization */
-__WEAK enum tfm_plat_err_t tfm_spm_hal_post_init_platform(void)
+__WEAK enum tfm_hal_status_t tfm_hal_platform_init(void)
 {
-    return TFM_PLAT_ERR_SUCCESS;
-}
-
-enum tfm_plat_err_t tfm_spm_hal_post_init(void)
-{
-    if (tfm_spm_hal_post_init_platform() != TFM_PLAT_ERR_SUCCESS) {
-        return TFM_PLAT_ERR_SYSTEM_ERR;
-    }
-
     __enable_irq();
     stdio_init();
 
-    return TFM_PLAT_ERR_SUCCESS;
+    return TFM_HAL_SUCCESS;
 }
 
 __WEAK void tfm_hal_system_reset(void)
diff --git a/platform/ext/target/cypress/psoc64/spm_hal.c b/platform/ext/target/cypress/psoc64/spm_hal.c
index 27c8ed0..4ddb869 100644
--- a/platform/ext/target/cypress/psoc64/spm_hal.c
+++ b/platform/ext/target/cypress/psoc64/spm_hal.c
@@ -11,6 +11,7 @@
 #include <string.h>
 
 #include "tfm_spm_hal.h"
+#include "tfm_hal_platform.h"
 
 #include "device_definition.h"
 #include "region_defs.h"
@@ -417,12 +418,15 @@
     memcpy(boot_data, mock_data, sizeof(mock_data));
 }
 
-enum tfm_plat_err_t tfm_spm_hal_post_init_platform(void)
+enum tfm_hal_status_t tfm_hal_platform_init(void)
 {
     platform_init();
 
     /* FIXME: Use the actual data from mcuboot */
     mock_tfm_shared_data();
 
-    return TFM_PLAT_ERR_SUCCESS;
+    __enable_irq();
+    stdio_init();
+
+    return TFM_HAL_SUCCESS;
 }
diff --git a/platform/ext/target/stm/stm32l5xx/secure/tfm_platform_system.c b/platform/ext/target/stm/stm32l5xx/secure/tfm_platform_system.c
index a13e5f8..06bd86a 100644
--- a/platform/ext/target/stm/stm32l5xx/secure/tfm_platform_system.c
+++ b/platform/ext/target/stm/stm32l5xx/secure/tfm_platform_system.c
@@ -10,6 +10,8 @@
 #include "tfm_spm_hal.h"
 #include "uart_stdout.h"
 #include "tfm_platform_system.h"
+#include "tfm_hal_platform.h"
+
 void tfm_platform_hal_system_reset(void)
 {
     /* Reset the system */
@@ -23,21 +25,12 @@
      return TFM_PLAT_ERR_SYSTEM_ERR;
 }
 
-__WEAK enum tfm_plat_err_t tfm_spm_hal_post_init_platform(void)
+enum tfm_hal_status_t tfm_hal_platform_init(void)
 {
-     return TFM_PLAT_ERR_SUCCESS;
-}
-
-enum tfm_plat_err_t tfm_spm_hal_post_init(void)
-{
-    if (tfm_spm_hal_post_init_platform() != TFM_PLAT_ERR_SUCCESS) {
-        return TFM_PLAT_ERR_SYSTEM_ERR;
-    }
-
     __enable_irq();
     stdio_init();
 
-    return TFM_PLAT_ERR_SUCCESS;
+    return TFM_HAL_SUCCESS;
 }
 
 __WEAK void tfm_hal_system_reset(void)
@@ -45,8 +38,6 @@
     NVIC_SystemReset();
 }
 
-
-
 enum tfm_platform_err_t tfm_platform_hal_ioctl(tfm_platform_ioctl_req_t request,
                                                psa_invec  *in_vec,
                                                psa_outvec *out_vec)
diff --git a/platform/include/tfm_hal_platform.h b/platform/include/tfm_hal_platform.h
index bf61a84..f8f7bae 100644
--- a/platform/include/tfm_hal_platform.h
+++ b/platform/include/tfm_hal_platform.h
@@ -8,6 +8,19 @@
 #ifndef __TFM_HAL_PLATFORM_H__
 #define __TFM_HAL_PLATFORM_H__
 
+#include "tfm_hal_defs.h"
+
+/**
+ * \brief This function performs the platform-specific initialization.
+ *
+ * This function is called after architecture and platform common initialization
+ * has finished during system early startup.
+ *
+ * \retval TFM_HAL_SUCCESS          Init success.
+ * \retval TFM_HAL_ERROR_GENERIC    Generic errors.
+ */
+enum tfm_hal_status_t tfm_hal_platform_init(void);
+
 /**
  * \brief System reset
  */
diff --git a/platform/include/tfm_spm_hal.h b/platform/include/tfm_spm_hal.h
index 82d297a..673fbc9 100644
--- a/platform/include/tfm_spm_hal.h
+++ b/platform/include/tfm_spm_hal.h
@@ -69,32 +69,6 @@
 #endif
 
 /**
- * \brief This function initializes peripherals common to all platforms.
- *
- * Contrarily to SystemInit() intended for a high-priority hw initialization
- * (for example clock and power subsystems), and called on a very early boot
- * stage from startup code, this function is called from C code, hence variables
- * and other drivers data are protected from being cleared up by the C library
- * init.
- * In addition to performing initialization common to all platforms, it also
- * calls tfm_spm_hal_post_init_platform() function which implements
- * initialization of platform-specific peripherals and other hw.
- *
- * \return Returns values as specified by the \ref tfm_plat_err_t
- */
-enum tfm_plat_err_t tfm_spm_hal_post_init(void);
-
-/**
- * \brief This function initializes platform-specific peripherals and hardware.
- *
- * Called from tfm_spm_hal_post_init(), this function is intended for
- * platform-specific portion of hardware initialization.
- *
- * \return Returns values as specified by the \ref tfm_plat_err_t
- */
-enum tfm_plat_err_t tfm_spm_hal_post_init_platform(void);
-
-/**
  * \brief This function initialises the HW used for isolation, and sets the
  *        default configuration for them.
  *
diff --git a/secure_fw/spm/cmsis_func/main.c b/secure_fw/spm/cmsis_func/main.c
index 0d6a23b..e070515 100644
--- a/secure_fw/spm/cmsis_func/main.c
+++ b/secure_fw/spm/cmsis_func/main.c
@@ -8,6 +8,7 @@
 #include "log/tfm_log.h"
 #include "region.h"
 #include "spm_func.h"
+#include "tfm_hal_platform.h"
 #include "tfm_internal.h"
 #include "tfm_irq_list.h"
 #include "tfm_nspm.h"
@@ -33,6 +34,7 @@
 static int32_t tfm_core_init(void)
 {
     size_t i;
+    enum tfm_hal_status_t hal_status = TFM_HAL_ERROR_GENERIC;
     enum tfm_plat_err_t plat_err = TFM_PLAT_ERR_SYSTEM_ERR;
     enum irq_target_state_t irq_target_state = TFM_IRQ_TARGET_STATE_SECURE;
 
@@ -64,8 +66,8 @@
     }
 
     /* Performs platform specific initialization */
-    plat_err = tfm_spm_hal_post_init();
-    if (plat_err != TFM_PLAT_ERR_SUCCESS) {
+    hal_status = tfm_hal_platform_init();
+    if (hal_status != TFM_HAL_SUCCESS) {
         return TFM_ERROR_GENERIC;
     }
 
diff --git a/secure_fw/spm/cmsis_psa/main.c b/secure_fw/spm/cmsis_psa/main.c
index 5e160d6..ba7c869 100644
--- a/secure_fw/spm/cmsis_psa/main.c
+++ b/secure_fw/spm/cmsis_psa/main.c
@@ -8,6 +8,7 @@
 #include "log/tfm_log.h"
 #include "region.h"
 #include "spm_ipc.h"
+#include "tfm_hal_platform.h"
 #include "tfm_internal.h"
 #include "tfm_irq_list.h"
 #include "tfm_nspm.h"
@@ -33,6 +34,7 @@
 static int32_t tfm_core_init(void)
 {
     size_t i;
+    enum tfm_hal_status_t hal_status = TFM_HAL_ERROR_GENERIC;
     enum tfm_plat_err_t plat_err = TFM_PLAT_ERR_SYSTEM_ERR;
     enum irq_target_state_t irq_target_state = TFM_IRQ_TARGET_STATE_SECURE;
 
@@ -64,8 +66,8 @@
     }
 
     /* Performs platform specific initialization */
-    plat_err = tfm_spm_hal_post_init();
-    if (plat_err != TFM_PLAT_ERR_SUCCESS) {
+    hal_status = tfm_hal_platform_init();
+    if (hal_status != TFM_HAL_SUCCESS) {
         return TFM_ERROR_GENERIC;
     }