Skip to contentSkip to conversation

Non-functional zboot implementation for KZM9G

RFC In review Ulrich Hecht 2 participants 3 messages Jul 30, 2013 – Aug 1, 2013

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Non-functional zboot implementation for KZM9G

Hi!

This is an attempt to implement zboot on the KZM9G board. It is based on the setup code from u-boot and is intended to be loaded to MERAM via USB and booted by the mask ROM boot loader.

The problem is that the DRAM setup appears to be wrong somehow. Even though it slavishly follows the example set by u-boot it fails to set the DRAM up in a stable manner for some reason. The effect observed is that many consecutive writes to DRAM in most cases cause the system to hang. In the few cases it doesn't the data written cannot be read back correctly.

I have tried yanking every bit in the SBSC back and forth (see the commented-out lines in head-kzm9g.txt for details), but the DRAM stays flaky in exactly the same way. I suspect that the mask ROM boot loader does something to the hardware that interferes with DRAM operation. The sh73a0 documentation details what the loader is supposed to be doing, and I have tried to revert the few things that are not overridden by the u-boot setup anyway, but that didn't to anything either.

If you want to give it a try, apply the patches and configure your kernel with CONFIG_ZBOOT_ROM_BSS=0xe5580000 and CONFIG_ZBOOT_ROM=y. You will have to disable a lot of features because MERAM is only 1.5 MB, and the entire image will have to fit in there. Don't forget to append the DTB. Set the mode switch (SW1) positions 1, 2, and 8 to OFF, all others to ON. Then upload the zImage using Magnus' r_usb_tool. If LEDs 1-4 light up and then turn off one by one, your board works better than mine. If only LED 1 turns off or the LEDs start blinking crazy bit patterns, it exhibits the same behavior as mine.

Ideas what could be wrong here are most welcome.

CU
Uli

Ulrich Hecht (5):
USB boot tool for SH-Mobile ARM SoCs
arm: boot: allow zboot with appended DTB
arm: shmobile: KZM9G zboot support (not working)
arm: boot: kzm9g: blink LEDs and check if DRAM works
arm: boot: kzm9g: raise core voltage

 Documentation/arm/SH-Mobile/r_usb_boot.c           |  544 ++++++++++++++++
 arch/arm/Kconfig                                   |    2 +-
 arch/arm/boot/compressed/misc.c                    |  327 +++++++++-
 arch/arm/mach-shmobile/include/mach/head-kzm9g.txt |  680 ++++++++++++++++++++
 arch/arm/mach-shmobile/include/mach/zboot.h        |    6 +
 5 files changed, 1556 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/arm/SH-Mobile/r_usb_boot.c
 create mode 100644 arch/arm/mach-shmobile/include/mach/head-kzm9g.txt
Signature · 1 line
1.7.10.4
maintainer
#1 lore raw

Hi Ulrich,

Quoted 30 lines · Ulrich Hecht

Hi!

This is an attempt to implement zboot on the KZM9G board. It is based on the setup code from u-boot and is intended to be loaded to MERAM via USB and booted by the mask ROM boot loader.

The problem is that the DRAM setup appears to be wrong somehow. Even though it slavishly follows the example set by u-boot it fails to set the DRAM up in a stable manner for some reason. The effect observed is that many consecutive writes to DRAM in most cases cause the system to hang. In the few cases it doesn't the data written cannot be read back correctly.

I have tried yanking every bit in the SBSC back and forth (see the commented-out lines in head-kzm9g.txt for details), but the DRAM stays flaky in exactly the same way. I suspect that the mask ROM boot loader does something to the hardware that interferes with DRAM operation. The sh73a0 documentation details what the loader is supposed to be doing, and I have tried to revert the few things that are not overridden by the u-boot setup anyway, but that didn't to anything either.

If you want to give it a try, apply the patches and configure your kernel with CONFIG_ZBOOT_ROM_BSS=0xe5580000 and CONFIG_ZBOOT_ROM=y. You will have to disable a lot of features because MERAM is only 1.5 MB, and the entire image will have to fit in there. Don't forget to append the DTB. Set the mode switch (SW1) positions 1, 2, and 8 to OFF, all others to ON. Then upload the zImage using Magnus' r_usb_tool. If LEDs 1-4 light up and then turn off one by one, your board works better than mine. If only LED 1 turns off or the LEDs start blinking crazy bit patterns, it exhibits the same behavior as mine.

Quoted 1 line

Ideas what could be wrong here are most welcome.

Thanks for posting your code. I will give your code a go when I find time later on.

Until then, may I suggest that you try adding SCIF debug printouts by yourself? LEDs are great, but it is hard to beat serial console...

For your convenience I've searched my pile of prototype patches and I've attached 3 different examples of random SCIF output code for various boards. For most of them you will need to hack them to change base address and perhaps also location of TX FIFO register depending on target SoC and board. Also, they assume that the boot loader actually set up the SCIF and PFC for you already - this seems to be the case with your zboot code but you may want to double check.

I think you should be able to use 3 instruction hack included in "linux-3.12-pre-arm-shmobile-smp-mpidr-dbg-sh73a0-20130731b.patch" on KZM9G more or less as-is.

Cheers,

/ magnus

From: Magnus Damm <[email protected]>

---

 arch/arm/mach-shmobile/include/mach/debug-macro.S |   47 +++++++++++++++++++++
 1 file changed, 47 insertions(+)
arch/arm/mach-shmobile/include/mach/debug-macro.S new file +47 -0
@@ -0,0 +1,47 @@
+/*
+ * arch/arm/mach-shmobile/include/mach/debug-macro.S
+ *
+ * Debugging macro include header
+ *
+ * Copyright (C) 2012  Renesas Electronics Corporation
+ * Copyright (C) 1994-1999 Russell King
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#define SSR	0x14
+#define FTDR	0x20
+
+#define TDFE	(1 << 5)
+#define TEND	(1 << 6)
+
+//#ifdef CONFIG_MACH_APE6EVM
+#define SCIF_PHYS	0xe6c40000
+#define SCIF_VIRT	0xe6c40000
+//#endif
+
+	.macro	addruart, rp, rv, tmp
+	ldr	\rp, =SCIF_PHYS
+	ldr	\rv, =SCIF_VIRT
+	.endm
+
+	.macro	waituart, rd, rx
+1001:	ldrh	\rd, [\rx, #SSR]
+	tst	\rd, #TDFE
+	beq	1001b
+	.endm
+
+	.macro	senduart, rd, rx
+	strb	\rd, [\rx, #FTDR]
+	ldrh	\rd, [\rx, #SSR]
+	bic	\rd, \rd, #TEND
+	strh	\rd, [\rx, #SSR]
+	.endm
+
+	.macro	busyuart, rd, rx
+1001:	ldrh	\rd, [\rx, #SSR]
+	tst	\rd, #TEND
+	beq	1001b
+	.endm

From: Magnus Damm <[email protected]>

---

 arch/arm/boot/compressed/head.S                  |    8 ++++++++
 arch/arm/boot/compressed/misc.c                  |    4 +++-
 arch/arm/mach-shmobile/include/mach/uncompress.h |   11 +++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)
arch/arm/boot/compressed/head.S +8 -0
@@ -134,6 +134,14 @@ start:
 		.word	_edata			@ zImage end address
  THUMB(		.thumb			)
 1:
+#define SCIFTDR0 0xe6c40020
+
+		mov	r0, #0xe6000000
+		add	r0, r0, #0xc40000
+		add	r0, r0, #0x20
+		mov     r1, #'X'
+		strb    r1, [r0]
+	
 		mrs	r9, cpsr
 #ifdef CONFIG_ARM_VIRT_EXT
 		bl	__hyp_stub_install	@ get into SVC mode, reversibly
arch/arm/boot/compressed/misc.c +3 -1
@@ -30,7 +30,7 @@ static inline void putc(int c) {}
 static inline void flush(void) {}
 static inline void arch_decomp_setup(void) {}
 #else
-#include <../mach-versatile/include/mach/uncompress.h>
+#include <../mach-shmobile/include/mach/uncompress.h>
 #endif
 
 #ifdef CONFIG_DEBUG_ICEDCC
@@ -148,6 +148,8 @@ decompress_kernel(unsigned long output_s
 	free_mem_end_ptr	= free_mem_ptr_end_p;
 	__machine_arch_type	= arch_id;
 
+	putc('X');
+
 	arch_decomp_setup();
 
 	putstr("Uncompressing Linux...");
arch/arm/mach-shmobile/include/mach/uncompress.h +11 -0
@@ -1,11 +1,22 @@
 #ifndef __ASM_MACH_UNCOMPRESS_H
 #define __ASM_MACH_UNCOMPRESS_H
 
+#include <linux/io.h>
+
+#define SCIF0	0xe6c40000
+#define SCFSR	0x14
+#define SCFTDR	0x20
+#define FSR_TEND	(1<<6)
+
 /*
  * This does not append a newline
  */
 static void putc(int c)
 {
+	while(!(__raw_readw(SCIF0 + SCFSR) & FSR_TEND))
+		;
+	__raw_writeb(c, SCIF0 + SCFTDR);
+	__raw_writew(__raw_readw(SCIF0 + SCFSR) & ~FSR_TEND, SCIF0 + SCFSR);
 }
 
 static inline void flush(void)

From: Magnus Damm <[email protected]>

---

 arch/arm/mach-shmobile/headsmp.S |   10 ++++++++++
 1 file changed, 10 insertions(+)
arch/arm/mach-shmobile/headsmp.S +10 -0
@@ -44,6 +44,10 @@ shmobile_boot_arg:
  */
 
 ENTRY(shmobile_smp_boot)
+	ldr	r11, =0xe6c80000
+	mov	r12, #'@'
+	strb    r12, [r11, #0x20]
+	
 	mrc	p15, 0, r0, c0, c0, 5		@ r0 = MPIDR
 	mov	r1, #0				@ r1 = Per-CPU offset
 	adr	r5, 1f
@@ -73,7 +77,13 @@ shmobile_smp_boot_found:
 ENDPROC(shmobile_smp_boot)
 
 ENTRY(shmobile_smp_reset)
+	ldr	r11, =0xe6c80000
+	mov	r12, #'W'
+	strb    r12, [r11, #0x20]
 	wfi
+	ldr	r11, =0xe6c80000
+	mov	r12, #'!'
+	strb    r12, [r11, #0x20]
 	b	shmobile_smp_boot
 ENDPROC(shmobile_smp_reset)
 
#2 lore raw
In reply to Ulrich Hecht
Quoted 2 lines · Magnus Damm

Thanks for posting your code. I will give your code a go when I find time later on.

OK, thanks.

Quoted 3 lines

on target SoC and board. Also, they assume that the boot loader actually set up the SCIF and PFC for you already - this seems to be the case with your zboot code but you may want to double check.

PFC, (I think) yes; SCIF, no.

Quoted 3 lines

I think you should be able to use 3 instruction hack included in "linux-3.12-pre-arm-shmobile-smp-mpidr-dbg-sh73a0-20130731b.patch" on KZM9G more or less as-is.

I actually had something like that, but I didn't feel like working out the timings, so I stuck with the LEDs. (In hindsight, it probably would have been easier than writing down addresses digit by digit...)

CU
Uli