diff mbox

[U-Boot] powerpc: mpc83xx: Enable pre-relocation malloc

Message ID 20170106135640.9243-1-mario.six@gdsys.cc
State Superseded
Delegated to: York Sun
Headers show

Commit Message

Mario Six Jan. 6, 2017, 1:56 p.m. UTC
To enable DM on MPC83xx, we need pre-relocation malloc, which is
implemented in this patch.

Signed-off-by: Mario Six <mario.six@gdsys.cc>
---
 arch/powerpc/cpu/mpc83xx/cpu_init.c    |  3 +--
 arch/powerpc/cpu/mpc83xx/spl_minimal.c |  4 +---
 arch/powerpc/cpu/mpc83xx/start.S       | 23 +++++++++++++++++++++++
 3 files changed, 25 insertions(+), 5 deletions(-)

Comments

Joakim Tjernlund Jan. 6, 2017, 4:32 p.m. UTC | #1
On Fri, 2017-01-06 at 14:56 +0100, Mario Six wrote:
> To enable DM on MPC83xx, we need pre-relocation malloc, which is
> implemented in this patch.
> 

Would be nice if you could avoid using r1, each time you modify r1 gdb will be
upset/confused if you ever try to debug start.S with gdb.

I guess the whole file need a bit of trimming to avoid using r1 but one has to start somewhere.

 Jocke
York Sun Jan. 6, 2017, 4:56 p.m. UTC | #2
On 01/06/2017 05:57 AM, Mario Six wrote:
> To enable DM on MPC83xx, we need pre-relocation malloc, which is
> implemented in this patch.
>
> Signed-off-by: Mario Six <mario.six@gdsys.cc>
> ---
>  arch/powerpc/cpu/mpc83xx/cpu_init.c    |  3 +--
>  arch/powerpc/cpu/mpc83xx/spl_minimal.c |  4 +---
>  arch/powerpc/cpu/mpc83xx/start.S       | 23 +++++++++++++++++++++++
>  3 files changed, 25 insertions(+), 5 deletions(-)
>

Patch looks good.

Reviewed-by: York Sun <york.sun@nxp.com>
York Sun Jan. 16, 2017, 10 p.m. UTC | #3
On 01/06/2017 08:32 AM, Joakim Tjernlund wrote:
> On Fri, 2017-01-06 at 14:56 +0100, Mario Six wrote:
>> To enable DM on MPC83xx, we need pre-relocation malloc, which is
>> implemented in this patch.
>>
>
> Would be nice if you could avoid using r1, each time you modify r1 gdb will be
> upset/confused if you ever try to debug start.S with gdb.
>
> I guess the whole file need a bit of trimming to avoid using r1 but one has to start somewhere.
>
>  Jocke
>

Guys,

I am not a mpc83xx maintainer. If the patch is agreed, I can bring it in 
with mpc85xx. If r1 needs some rework, please continue.

York
Mario Six Jan. 17, 2017, 6:52 a.m. UTC | #4
I'll take a look at the places where r1 is modified and send a v2.

On Mon, Jan 16, 2017 at 11:00 PM, york sun <york.sun@nxp.com> wrote:
> On 01/06/2017 08:32 AM, Joakim Tjernlund wrote:
>> On Fri, 2017-01-06 at 14:56 +0100, Mario Six wrote:
>>> To enable DM on MPC83xx, we need pre-relocation malloc, which is
>>> implemented in this patch.
>>>
>>
>> Would be nice if you could avoid using r1, each time you modify r1 gdb will be
>> upset/confused if you ever try to debug start.S with gdb.
>>
>> I guess the whole file need a bit of trimming to avoid using r1 but one has to start somewhere.
>>
>>  Jocke
>>
>
> Guys,
>
> I am not a mpc83xx maintainer. If the patch is agreed, I can bring it in
> with mpc85xx. If r1 needs some rework, please continue.
>
> York
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
diff mbox

Patch

diff --git a/arch/powerpc/cpu/mpc83xx/cpu_init.c b/arch/powerpc/cpu/mpc83xx/cpu_init.c
index f911275..3a0916b 100644
--- a/arch/powerpc/cpu/mpc83xx/cpu_init.c
+++ b/arch/powerpc/cpu/mpc83xx/cpu_init.c
@@ -205,8 +205,7 @@  void cpu_init_f (volatile immap_t * im)
 	/* Pointer is writable since we allocated a register for it */
 	gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
 
-	/* Clear initial global data */
-	memset ((void *) gd, 0, sizeof (gd_t));
+	/* global data region was cleared in start.S */
 
 	/* system performance tweaking */
 	clrsetbits_be32(&im->arbiter.acr, acr_mask, acr_val);
diff --git a/arch/powerpc/cpu/mpc83xx/spl_minimal.c b/arch/powerpc/cpu/mpc83xx/spl_minimal.c
index 845861e..026da12 100644
--- a/arch/powerpc/cpu/mpc83xx/spl_minimal.c
+++ b/arch/powerpc/cpu/mpc83xx/spl_minimal.c
@@ -23,9 +23,7 @@  void cpu_init_f (volatile immap_t * im)
 	/* Pointer is writable since we allocated a register for it */
 	gd = (gd_t *) (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET);
 
-	/* Clear initial global data */
-	for (i = 0; i < sizeof(gd_t); i++)
-		((char *)gd)[i] = 0;
+	/* global data region was cleared in start.S */
 
 	/* system performance tweaking */
 
diff --git a/arch/powerpc/cpu/mpc83xx/start.S b/arch/powerpc/cpu/mpc83xx/start.S
index 9bd86d8..f8044ac 100644
--- a/arch/powerpc/cpu/mpc83xx/start.S
+++ b/arch/powerpc/cpu/mpc83xx/start.S
@@ -265,6 +265,29 @@  in_flash:
 	lis	r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@h
 	ori	r1, r1, (CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_GBL_DATA_OFFSET)@l
 
+	/* r3 = end of GD area */
+	addi r3,r1,GENERATED_GBL_DATA_SIZE
+
+	/* Zero GD area */
+	li	r0, 0
+1:
+	subi	r3, r3, 1
+	stb	r0, 0(r3)
+	cmplw	r1, r3
+	bne	1b
+
+#ifdef CONFIG_SYS_MALLOC_F_LEN
+
+#if CONFIG_SYS_MALLOC_F_LEN + GENERATED_GBL_DATA_SIZE > CONFIG_SYS_INIT_RAM_SIZE
+#error "CONFIG_SYS_MALLOC_F_LEN too large to fit into initial RAM."
+#endif
+
+	/* r1 = stack pointer / pre-reloc malloc area */
+	subi    r1, r1, CONFIG_SYS_MALLOC_F_LEN
+
+	/* Set pointer to pre-reloc malloc area in GD */
+	stw     r1, GD_MALLOC_BASE(r3)
+#endif
 	li	r0, 0		/* Make room for stack frame header and	*/
 	stwu	r0, -4(r1)	/* clear final stack frame so that	*/
 	stwu	r0, -4(r1)	/* stack backtraces terminate cleanly	*/