[PATCH 1/3] add-jtag-detection.patch

Andy Green andy at openmoko.com
Fri Aug 22 15:54:18 CEST 2008


This adds capability to use single qi image for JTAG load action as well
as execution from NAND.  It requires JTAG script to load the image at
0x0 and 0x33000000 addresses, then set data at 0x04 address to 0xffffffff.

This eliminates the lowlevel_foo stuff from U-Boot world.

Signed-off-by: Andy Green <andy at openmoko.com>
---

 src/start.S    |    3 +++
 src/start_qi.c |   42 ++++++++++++++++++++++++++++++------------
 2 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/src/start.S b/src/start.S
index 7e02ecf..43cfffd 100644
--- a/src/start.S
+++ b/src/start.S
@@ -24,6 +24,9 @@
 
 .globl _start
 _start:	b       start_code
+/* if we are injected by JTAG, the script sets _istag content to nonzero */
+_is_jtag:
+	.word	0
 
 _TEXT_BASE:
 	.word	TEXT_BASE
diff --git a/src/start_qi.c b/src/start_qi.c
index d4f4905..ac7d42e 100644
--- a/src/start_qi.c
+++ b/src/start_qi.c
@@ -47,21 +47,39 @@ void start_qi(void)
 	int n = 0;
 	int board = 0;
 	const struct board_variant * board_variant;
+	const u32 * p_is_jtag = (const u32 *)4;
+
 	/*
-	 * We got the first 4KBytes of the bootloader pulled into the
-	 * steppingstone SRAM for free.  Now we pull the whole bootloader
-	 * image into SDRAM.
+	 * well, we can be running on this CPU two different ways.
+	 *
+	 * 1) We were copied into steppingstone and TEXT_BASE already
+	 *    by JTAG.  We don't have to do anything else.  JTAG script
+	 *    then sets data at address 0x4 to 0xffffffff as a signal we
+	 *    are running by JTAG.
 	 *
-	 * This code and the .S files are arranged by the linker script to
-	 * expect to run from 0x0.  But the linker script has told everything
-	 * else to expect to run from 0x33000000+.  That's why we are going to
-	 * be able to copy this code and not have it crash when we run it from
-	 * there.
+	 * 2) We only got our first 4K into steppingstone, we need to copy
+	 *    the rest of ourselves into TEXT_BASE.
+	 *
+	 * So we do the copy out of NAND only if we see we did not come up
+	 * under control of JTAG.
 	 */
 
-	/* We randomly pull 24KBytes of bootloader */
-	if (nand_read_ll((unsigned char *)TEXT_BASE, 0, 24 * 1024 / 512) < 0)
-		goto unhappy;
+	if (!*p_is_jtag)
+		/*
+		* We got the first 4KBytes of the bootloader pulled into the
+		* steppingstone SRAM for free.  Now we pull the whole bootloader
+		* image into SDRAM.
+		*
+		* This code and the .S files are arranged by the linker script
+		* to expect to run from 0x0.  But the linker script has told
+		* everything else to expect to run from 0x33000000+.  That's
+		* why we are going to be able to copy this code and not have it
+		* crash when we run it from there.
+		*/
+
+		/* We randomly pull 32KBytes of bootloader */
+		if (nand_read_ll((u8 *)TEXT_BASE, 0, 32 * 1024 / 512) < 0)
+			goto unhappy;
 
 	/* ask all the boards we support in turn if they recognize this
 	 * hardware we are running on, accept the first positive answer
@@ -69,7 +87,7 @@ void start_qi(void)
 
 	this_board = boards[board];
 	while (!n) {
-		if (board >= ARRAY_SIZE(boards))
+		if (board > ARRAY_SIZE(boards))
 			/* can't put diagnostic on serial... too early */
 			goto unhappy;
 




More information about the openmoko-kernel mailing list