Move platform_helpers.S to each platform's folder

In practice, all the functions in this file are platform-specific. It is
better to force all platforms to implement than having some sort of weak
function placeholder.

Porting guide updated.

Change-Id: I5beeeb10bec6fe5178b24503d6da8ca66074a8c6
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
diff --git a/docs/porting-guide.rst b/docs/porting-guide.rst
index 59d9dba..9c0812f 100644
--- a/docs/porting-guide.rst
+++ b/docs/porting-guide.rst
@@ -298,6 +298,47 @@
 
 This function initializes the ARM Generic Interrupt Controller (GIC).
 
+Function : platform_get_core_pos() [mandatory]
+``````````````````````````````````````````````
+
+::
+
+    Argument : u_register_t
+    Return   : unsigned int
+
+This function returns a linear core ID from a MPID.
+
+Function : plat_crash_console_init() [mandatory]
+````````````````````````````````````````````````
+
+::
+
+    Argument : void
+    Return   : int
+
+This function initializes a platform-specific console for crash reporting.
+
+Function : plat_crash_console_putc() [mandatory]
+````````````````````````````````````````````````
+
+::
+
+    Argument : int
+    Return   : int
+
+This function prints a character on the platform-specific crash console.
+
+Function : plat_crash_console_flush() [mandatory]
+`````````````````````````````````````````````````
+
+::
+
+    Argument : void
+    Return   : int
+
+This function waits until all the characters of the platform-specific crash
+console have been actually printed.
+
 Optional modifications
 ----------------------
 
@@ -350,17 +391,6 @@
 generate a watchdog timeout interrupt. This interrupt remains deliberately
 unserviced, which eventually asserts the reset signal.
 
-Function : tftf_platform_setup()
-````````````````````````````````
-
-::
-
-    Argument : void
-    Return   : void
-
-Setup code for platform hardware. The default implementation initializes the IO
-and GIC.
-
 Storage abstraction layer
 -------------------------
 
diff --git a/fwu/ns_bl1u/ns_bl1u.mk b/fwu/ns_bl1u/ns_bl1u.mk
index 430ff5e..0d7efcc 100644
--- a/fwu/ns_bl1u/ns_bl1u.mk
+++ b/fwu/ns_bl1u/ns_bl1u.mk
@@ -47,7 +47,6 @@
 			lib/utils/uuid.c				\
 			${XLAT_TABLES_LIB_SRCS}				\
 			plat/arm/common/arm_fwu_io_storage.c		\
-			plat/common/${ARCH}/platform_helpers.S		\
 			plat/common/${ARCH}/platform_up_stack.S 	\
 			plat/common/image_loader.c			\
 			plat/common/plat_common.c
diff --git a/fwu/ns_bl2u/ns_bl2u.mk b/fwu/ns_bl2u/ns_bl2u.mk
index e4c93a1..0605c3c 100644
--- a/fwu/ns_bl2u/ns_bl2u.mk
+++ b/fwu/ns_bl2u/ns_bl2u.mk
@@ -45,7 +45,6 @@
 			lib/utils/uuid.c				\
 			${XLAT_TABLES_LIB_SRCS}				\
 			plat/arm/common/arm_fwu_io_storage.c		\
-			plat/common/${ARCH}/platform_helpers.S		\
 			plat/common/${ARCH}/platform_up_stack.S 	\
 			plat/common/fwu_nvm_accessors.c			\
 			plat/common/plat_common.c			\
diff --git a/include/plat/common/platform.h b/include/plat/common/platform.h
index d3a486c..3f452ad 100644
--- a/include/plat/common/platform.h
+++ b/include/plat/common/platform.h
@@ -56,6 +56,14 @@
 void tftf_platform_watchdog_set(void);
 void tftf_platform_watchdog_reset(void);
 
+/* Helper that returns a linear core ID from a MPID */
+unsigned int platform_get_core_pos(u_register_t mpid);
+
+/* Crash console functions */
+int plat_crash_console_init(void);
+int plat_crash_console_putc(int c);
+int plat_crash_console_flush(void);
+
 /* Gets a handle for the initialised IO entity */
 void plat_get_nvm_handle(uintptr_t *handle);
 
@@ -153,11 +161,7 @@
  * Optional functions. A default, weak implementation of those functions is
  * provided, it may be overridden by platform code.
  ******************************************************************************/
-unsigned int platform_get_core_pos(unsigned long mpid);
 unsigned long platform_get_stack(unsigned long mpidr);
-int plat_crash_console_init(void);
-int plat_crash_console_putc(int c);
-int plat_crash_console_flush(void);
 /*
  * plat_get_prot_regions: It returns a pointer to a
  * set of regions used to test mem_protect_check.
diff --git a/plat/arm/board/fvp/aarch32/plat_helpers.S b/plat/arm/board/fvp/aarch32/plat_helpers.S
index 2dcc6e9..1d923ad 100644
--- a/plat/arm/board/fvp/aarch32/plat_helpers.S
+++ b/plat/arm/board/fvp/aarch32/plat_helpers.S
@@ -6,9 +6,13 @@
 
 #include <arch.h>
 #include <asm_macros.S>
+#include <pl011.h>
 #include "../fvp_def.h"
 
 	.globl	platform_get_core_pos
+	.globl	plat_crash_console_init
+	.globl	plat_crash_console_putc
+	.globl	plat_crash_console_flush
 
 /*----------------------------------------------------------------------
  * unsigned int platform_get_core_pos(unsigned long mpid)
@@ -47,3 +51,42 @@
 
 	bx	lr
 endfunc platform_get_core_pos
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_init(void)
+	 * Function to initialize the crash console
+	 * without a C Runtime to print crash report.
+	 * Clobber list : x0 - x4
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_init
+	ldr	r0, =PLAT_ARM_UART_BASE
+	ldr	r1, =PLAT_ARM_UART_CLK_IN_HZ
+	ldr	r2, =PL011_BAUDRATE
+	b	console_core_init
+endfunc plat_crash_console_init
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_putc(int c)
+	 * Function to print a character on the crash
+	 * console without a C Runtime.
+	 * Clobber list : x1, x2
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_putc
+	ldr	r1, =PLAT_ARM_UART_BASE
+	b	console_core_putc
+endfunc plat_crash_console_putc
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_flush()
+	 * Function to force a write of all buffered
+	 * data that hasn't been output.
+	 * Out : return -1 on error else return 0.
+	 * Clobber list : r0 - r1
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_flush
+	ldr	r1, =PLAT_ARM_UART_BASE
+	b	console_core_flush
+endfunc plat_crash_console_flush
diff --git a/plat/arm/board/fvp/aarch64/plat_helpers.S b/plat/arm/board/fvp/aarch64/plat_helpers.S
index bc9f60d..4bd9f3d 100644
--- a/plat/arm/board/fvp/aarch64/plat_helpers.S
+++ b/plat/arm/board/fvp/aarch64/plat_helpers.S
@@ -6,9 +6,13 @@
 
 #include <arch.h>
 #include <asm_macros.S>
+#include <pl011.h>
 #include "../fvp_def.h"
 
 	.globl	platform_get_core_pos
+	.globl	plat_crash_console_init
+	.globl	plat_crash_console_putc
+	.globl	plat_crash_console_flush
 
 /*----------------------------------------------------------------------
  * unsigned int platform_get_core_pos(unsigned long mpid)
@@ -46,3 +50,42 @@
 	madd	x0, x1, x3, x0
 	ret
 endfunc platform_get_core_pos
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_init(void)
+	 * Function to initialize the crash console
+	 * without a C Runtime to print crash report.
+	 * Clobber list : x0 - x4
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_init
+	mov_imm	x0, PLAT_ARM_UART_BASE
+	mov_imm	x1, PLAT_ARM_UART_CLK_IN_HZ
+	mov_imm	x2, PL011_BAUDRATE
+	b	console_core_init
+endfunc plat_crash_console_init
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_putc(int c)
+	 * Function to print a character on the crash
+	 * console without a C Runtime.
+	 * Clobber list : x1, x2
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_putc
+	mov_imm	x1, PLAT_ARM_UART_BASE
+	b	console_core_putc
+endfunc plat_crash_console_putc
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_flush()
+	 * Function to force a write of all buffered
+	 * data that hasn't been output.
+	 * Out : return -1 on error else return 0.
+	 * Clobber list : r0 - r1
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_flush
+	mov_imm	x1, PLAT_ARM_UART_BASE
+	b	console_core_flush
+endfunc plat_crash_console_flush
diff --git a/plat/arm/board/fvp/platform.mk b/plat/arm/board/fvp/platform.mk
index 281a5f3..2326bde 100644
--- a/plat/arm/board/fvp/platform.mk
+++ b/plat/arm/board/fvp/platform.mk
@@ -20,6 +20,8 @@
 			plat/arm/board/fvp/fvp_mem_prot.c		\
 			plat/arm/board/fvp/plat_setup.c
 
+CACTUS_SOURCES	+=	plat/arm/board/fvp/${ARCH}/plat_helpers.S
+
 # Firmware update is implemented on FVP.
 FIRMWARE_UPDATE := 1
 
diff --git a/plat/arm/board/juno/aarch32/plat_helpers.S b/plat/arm/board/juno/aarch32/plat_helpers.S
index 6f252c0..99fedb4 100644
--- a/plat/arm/board/juno/aarch32/plat_helpers.S
+++ b/plat/arm/board/juno/aarch32/plat_helpers.S
@@ -6,8 +6,13 @@
 
 #include <arch.h>
 #include <asm_macros.S>
+#include <pl011.h>
+#include "../juno_def.h"
 
 	.globl	platform_get_core_pos
+	.globl	plat_crash_console_init
+	.globl	plat_crash_console_putc
+	.globl	plat_crash_console_flush
 
 	/*
 	 * Return 0 to 3 for the Cortex-A53 cores and 4 to 5 for the Cortex-A57
@@ -21,3 +26,42 @@
 	add	r0, r1, r0, LSR #6
 	bx	lr
 endfunc platform_get_core_pos
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_init(void)
+	 * Function to initialize the crash console
+	 * without a C Runtime to print crash report.
+	 * Clobber list : x0 - x4
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_init
+	ldr	r0, =PLAT_ARM_UART_BASE
+	ldr	r1, =PLAT_ARM_UART_CLK_IN_HZ
+	ldr	r2, =PL011_BAUDRATE
+	b	console_core_init
+endfunc plat_crash_console_init
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_putc(int c)
+	 * Function to print a character on the crash
+	 * console without a C Runtime.
+	 * Clobber list : x1, x2
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_putc
+	ldr	r1, =PLAT_ARM_UART_BASE
+	b	console_core_putc
+endfunc plat_crash_console_putc
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_flush()
+	 * Function to force a write of all buffered
+	 * data that hasn't been output.
+	 * Out : return -1 on error else return 0.
+	 * Clobber list : r0 - r1
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_flush
+	ldr	r1, =PLAT_ARM_UART_BASE
+	b	console_core_flush
+endfunc plat_crash_console_flush
diff --git a/plat/arm/board/juno/aarch64/plat_helpers.S b/plat/arm/board/juno/aarch64/plat_helpers.S
index c51a4d9..1efee4f 100644
--- a/plat/arm/board/juno/aarch64/plat_helpers.S
+++ b/plat/arm/board/juno/aarch64/plat_helpers.S
@@ -6,8 +6,13 @@
 
 #include <arch.h>
 #include <asm_macros.S>
+#include <pl011.h>
+#include "../juno_def.h"
 
 	.globl	platform_get_core_pos
+	.globl	plat_crash_console_init
+	.globl	plat_crash_console_putc
+	.globl	plat_crash_console_flush
 
 	/*
 	 * Return 0 to 3 for the Cortex-A53 cores and 4 to 5 for the Cortex-A57
@@ -21,3 +26,42 @@
 	add	x0, x1, x0, LSR #6
 	ret
 endfunc platform_get_core_pos
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_init(void)
+	 * Function to initialize the crash console
+	 * without a C Runtime to print crash report.
+	 * Clobber list : x0 - x4
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_init
+	mov_imm	x0, PLAT_ARM_UART_BASE
+	mov_imm	x1, PLAT_ARM_UART_CLK_IN_HZ
+	mov_imm	x2, PL011_BAUDRATE
+	b	console_core_init
+endfunc plat_crash_console_init
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_putc(int c)
+	 * Function to print a character on the crash
+	 * console without a C Runtime.
+	 * Clobber list : x1, x2
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_putc
+	mov_imm	x1, PLAT_ARM_UART_BASE
+	b	console_core_putc
+endfunc plat_crash_console_putc
+
+	/* ---------------------------------------------
+	 * int plat_crash_console_flush()
+	 * Function to force a write of all buffered
+	 * data that hasn't been output.
+	 * Out : return -1 on error else return 0.
+	 * Clobber list : r0 - r1
+	 * ---------------------------------------------
+	 */
+func plat_crash_console_flush
+	mov_imm	x1, PLAT_ARM_UART_BASE
+	b	console_core_flush
+endfunc plat_crash_console_flush
diff --git a/plat/common/aarch32/platform_helpers.S b/plat/common/aarch32/platform_helpers.S
deleted file mode 100644
index 1a57418..0000000
--- a/plat/common/aarch32/platform_helpers.S
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2018, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <arch.h>
-#include <asm_macros.S>
-#include <pl011.h>
-#include <platform_def.h>
-
-	.weak	platform_get_core_pos
-	.weak	plat_crash_console_init
-	.weak	plat_crash_console_putc
-	.weak	plat_crash_console_flush
-
-	/* -----------------------------------------------------
-	 *  int platform_get_core_pos(u_register_t mpidr);
-	 *  With this function: CorePos = (ClusterId * 4) +
-	 *				  CoreId
-	 * -----------------------------------------------------
-	 */
-func platform_get_core_pos
-	and	r1, r0, #MPIDR_CPU_MASK
-	and	r0, r0, #MPIDR_CLUSTER_MASK
-	add	r0, r1, r0, LSR #6
-	bx	lr
-endfunc platform_get_core_pos
-
-	/* ---------------------------------------------
-	 * int plat_crash_console_init(void)
-	 * Function to initialize the crash console
-	 * without a C Runtime to print crash report.
-	 * Clobber list : x0 - x4
-	 * ---------------------------------------------
-	 */
-func plat_crash_console_init
-	ldr	r0, =PLAT_ARM_UART_BASE
-	ldr	r1, =PLAT_ARM_UART_CLK_IN_HZ
-	ldr	r2, =PL011_BAUDRATE
-	b	console_core_init
-endfunc plat_crash_console_init
-
-	/* ---------------------------------------------
-	 * int plat_crash_console_putc(int c)
-	 * Function to print a character on the crash
-	 * console without a C Runtime.
-	 * Clobber list : x1, x2
-	 * ---------------------------------------------
-	 */
-func plat_crash_console_putc
-	ldr	r1, =PLAT_ARM_UART_BASE
-	b	console_core_putc
-endfunc plat_crash_console_putc
-
-	/* ---------------------------------------------
-	 * int plat_crash_console_flush()
-	 * Function to force a write of all buffered
-	 * data that hasn't been output.
-	 * Out : return -1 on error else return 0.
-	 * Clobber list : r0 - r1
-	 * ---------------------------------------------
-	 */
-func plat_crash_console_flush
-	ldr	r1, =PLAT_ARM_UART_BASE
-	b	console_core_flush
-endfunc plat_crash_console_flush
diff --git a/plat/common/aarch64/platform_helpers.S b/plat/common/aarch64/platform_helpers.S
deleted file mode 100644
index 2161638..0000000
--- a/plat/common/aarch64/platform_helpers.S
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2018, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <arch.h>
-#include <asm_macros.S>
-#include <pl011.h>
-#include <platform_def.h>
-
-	.weak	platform_get_core_pos
-	.weak	plat_crash_console_init
-	.weak	plat_crash_console_putc
-	.weak	plat_crash_console_flush
-
-	/* -----------------------------------------------------
-	 *  int platform_get_core_pos(int mpidr);
-	 *  With this function: CorePos = (ClusterId * 4) +
-	 *  				  CoreId
-	 * -----------------------------------------------------
-	 */
-func platform_get_core_pos
-	and	x1, x0, #MPIDR_CPU_MASK
-	and	x0, x0, #MPIDR_CLUSTER_MASK
-	add	x0, x1, x0, LSR #6
-	ret
-endfunc platform_get_core_pos
-
-	/* ---------------------------------------------
-	 * int plat_crash_console_init(void)
-	 * Function to initialize the crash console
-	 * without a C Runtime to print crash report.
-	 * Clobber list : x0 - x4
-	 * ---------------------------------------------
-	 */
-func plat_crash_console_init
-	mov_imm	x0, PLAT_ARM_UART_BASE
-	mov_imm	x1, PLAT_ARM_UART_CLK_IN_HZ
-	mov_imm	x2, PL011_BAUDRATE
-	b	console_core_init
-endfunc plat_crash_console_init
-
-	/* ---------------------------------------------
-	 * int plat_crash_console_putc(int c)
-	 * Function to print a character on the crash
-	 * console without a C Runtime.
-	 * Clobber list : x1, x2
-	 * ---------------------------------------------
-	 */
-func plat_crash_console_putc
-	mov_imm	x1, PLAT_ARM_UART_BASE
-	b	console_core_putc
-endfunc plat_crash_console_putc
-
-	/* ---------------------------------------------
-	 * int plat_crash_console_flush()
-	 * Function to force a write of all buffered
-	 * data that hasn't been output.
-	 * Out : return -1 on error else return 0.
-	 * Clobber list : r0 - r1
-	 * ---------------------------------------------
-	 */
-func plat_crash_console_flush
-	mov_imm	x1, PLAT_ARM_UART_BASE
-	b	console_core_flush
-endfunc plat_crash_console_flush
diff --git a/spm/cactus/cactus.mk b/spm/cactus/cactus.mk
index f7794db..6f912e7 100644
--- a/spm/cactus/cactus.mk
+++ b/spm/cactus/cactus.mk
@@ -53,7 +53,6 @@
 CACTUS_SOURCES	+= 	drivers/arm/pl011/${ARCH}/pl011_console.S	\
 			lib/${ARCH}/cache_helpers.S			\
 			lib/${ARCH}/misc_helpers.S			\
-			plat/common/${ARCH}/platform_helpers.S		\
 			${STDLIB_SOURCES}
 
 CACTUS_LINKERFILE	:=	spm/cactus/cactus.ld.S
diff --git a/tftf/framework/framework.mk b/tftf/framework/framework.mk
index f6e1d7b..7d00704 100644
--- a/tftf/framework/framework.mk
+++ b/tftf/framework/framework.mk
@@ -80,7 +80,6 @@
 	lib/utils/mp_printf.c						\
 	lib/utils/uuid.c						\
 	${XLAT_TABLES_LIB_SRCS}						\
-	plat/common/${ARCH}/platform_helpers.S				\
 	plat/common/${ARCH}/platform_mp_stack.S 			\
 	plat/common/plat_common.c					\
 	plat/common/plat_state_id.c					\