Skip to contentSkip to conversation

qi_lb60: add nand spl support

PATCH Superseded xiangfu at openmobilefree.net 3 participants 6 messages Oct 27, 2012 – Jan 8, 2013

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

PATCH v7 1/1 qi_lb60: add nand spl support

From: Xiangfu <[email protected]>

Big thanks to Tom Rini, Daniel Schwierzeck and Marek Vasut for feedback.

For the usbboot code. I can not fast re-write them to u-boot USB sub-system. but I don't want wait. so let's finish the nand spl code first. :)

V7:
* fix typo

V6:
* remove usbboot code
* add u-boot-xburst.bin rule to main Makefile

V5:
* use puts instread of serial_puts (enable CONFIG_SPL_LIBCOMMON_SUPPORT)
* update my email address
* fix compiles warnings

V4:
* split to 2 patches (nand spl/usbbot)
* remove use define string.c using CONFIG_SPL_LIBGENERIC_SUPPORT
* fix checkputch.pl warnings

V3:
* add simpile string.c to mips/lib
* some cleanup on jz4740.c
* move to new spl/ structure
* support software usbboot mode

Xiangfu (1):
qi_lb60: add nand spl support

 Makefile                          |   12 +++
 arch/mips/cpu/xburst/Makefile     |    7 +-
 arch/mips/cpu/xburst/cpu.c        |    4 +
 arch/mips/cpu/xburst/jz4740.c     |   82 +++++++----------
 arch/mips/cpu/xburst/spl/Makefile |   47 ++++++++++
 arch/mips/cpu/xburst/spl/start.S  |   63 +++++++++++++
 board/qi/qi_lb60/Makefile         |    4 +
 board/qi/qi_lb60/qi_lb60-spl.c    |   30 +++++++
 board/qi/qi_lb60/qi_lb60.c        |    8 +-
 board/qi/qi_lb60/u-boot-spl.lds   |   61 +++++++++++++
 drivers/mtd/nand/jz4740_nand.c    |   39 ++++++++-
 include/configs/qi_lb60.h         |  175 ++++++++++++++++++-------------------
 12 files changed, 386 insertions(+), 146 deletions(-)
 create mode 100644 arch/mips/cpu/xburst/spl/Makefile
 create mode 100644 arch/mips/cpu/xburst/spl/start.S
 create mode 100644 board/qi/qi_lb60/qi_lb60-spl.c
 create mode 100644 board/qi/qi_lb60/u-boot-spl.lds
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v7 1/1 qi_lb60: add nand spl support

From: Xiangfu <[email protected]>

The JZ4740 CPU can load 8KB from two different addresses:
1. the normal area up to 8KB starting from NAND flash address 0x00000000
2. the backup area up to 8KB starting from NAND flash address 0x00002000

---
 Makefile                          |   12 +++
 arch/mips/cpu/xburst/Makefile     |    7 +-
 arch/mips/cpu/xburst/cpu.c        |    4 +
 arch/mips/cpu/xburst/jz4740.c     |   82 +++++++----------
 arch/mips/cpu/xburst/spl/Makefile |   47 ++++++++++
 arch/mips/cpu/xburst/spl/start.S  |   63 +++++++++++++
 board/qi/qi_lb60/Makefile         |    4 +
 board/qi/qi_lb60/qi_lb60-spl.c    |   30 +++++++
 board/qi/qi_lb60/qi_lb60.c        |    8 +-
 board/qi/qi_lb60/u-boot-spl.lds   |   61 +++++++++++++
 drivers/mtd/nand/jz4740_nand.c    |   39 ++++++++-
 include/configs/qi_lb60.h         |  175 ++++++++++++++++++-------------------
 12 files changed, 386 insertions(+), 146 deletions(-)
 create mode 100644 arch/mips/cpu/xburst/spl/Makefile
 create mode 100644 arch/mips/cpu/xburst/spl/start.S
 create mode 100644 board/qi/qi_lb60/qi_lb60-spl.c
 create mode 100644 board/qi/qi_lb60/u-boot-spl.lds
Makefile +12 -0
index 34d9075..a22778e 100644
@@ -393,6 +393,10 @@ ALL-y += $(obj)u-boot-nodtb-tegra.bin
 endif
 endif
 
+ifeq ($(CPU),xburst)
+ALL-y += $(obj)u-boot-xburst.bin
+endif
+
 all:		$(ALL-y) $(SUBDIR_EXAMPLES)
 
 $(obj)u-boot.dtb:	$(obj)u-boot
@@ -506,6 +510,14 @@ $(obj)u-boot-nodtb-tegra.bin:	$(obj)spl/u-boot-spl.bin $(obj)u-boot.bin
 endif
 endif
 
+ifeq ($(CPU),xburst)
+$(obj)u-boot-xburst.bin:	$(obj)spl/u-boot-spl.bin $(obj)u-boot.bin
+	        dd if=$(obj)spl/u-boot-spl.bin of=$(obj)spl/u-boot-pad.bin conv=sync bs=8192 count=1
+		dd if=$(obj)spl/u-boot-spl.bin of=$(obj)spl/u-boot-pad.bin conv=sync,notrunc oflag=append bs=8192 count=1
+	        tr '\0' '\377' < /dev/zero | dd of=$(obj)spl/u-boot-pad.bin conv=sync,notrunc oflag=append bs=16384 count=1
+	        cat $(obj)spl/u-boot-pad.bin u-boot.bin > $@
+endif
+
 ifeq ($(CONFIG_SANDBOX),y)
 GEN_UBOOT = \
 		cd $(LNDIR) && $(CC) $(SYMS) -T $(obj)u-boot.lds \
arch/mips/cpu/xburst/Makefile +5 -2
index b1f2ae4..ec35e55 100644
@@ -24,9 +24,12 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(CPU).o
 
+COBJS-y	= cpu.o jz_serial.o
+
+ifneq ($(CONFIG_SPL_BUILD),y)
 START	= start.o
-SOBJS-y	=
-COBJS-y	= cpu.o timer.o jz_serial.o
+COBJS-y += timer.o
+endif
 
 COBJS-$(CONFIG_JZ4740) += jz4740.o
 
arch/mips/cpu/xburst/cpu.c +4 -0
index ddcbfaa..1432838 100644
@@ -42,6 +42,8 @@
 		:			\
 		: "i" (op), "R" (*(unsigned char *)(addr)))
 
+#ifndef CONFIG_SPL_BUILD
+
 void __attribute__((weak)) _machine_restart(void)
 {
 	struct jz4740_wdt *wdt = (struct jz4740_wdt *)JZ4740_WDT_BASE;
@@ -109,6 +111,8 @@ void invalidate_dcache_range(ulong start_addr, ulong stop)
 		cache_op(Hit_Invalidate_D, addr);
 }
 
+#endif
+
 void flush_icache_all(void)
 {
 	u32 addr, t = 0;
arch/mips/cpu/xburst/jz4740.c +32 -50

165 lines not on this page · raw message

arch/mips/cpu/xburst/spl/Makefile new file +47 -0

47 lines not on this page · raw message

arch/mips/cpu/xburst/spl/start.S new file +63 -0

63 lines not on this page · raw message

board/qi/qi_lb60/Makefile +4 -0
index 5dae11b..e399246 100644
@@ -22,7 +22,11 @@ include $(TOPDIR)/config.mk
 
 LIB	= $(obj)lib$(BOARD).o
 
+ifeq ($(CONFIG_SPL_BUILD),y)
+COBJS	:= $(BOARD)-spl.o
+else
 COBJS	:= $(BOARD).o
+endif
 
 SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
board/qi/qi_lb60/qi_lb60-spl.c new file +30 -0
new file mode 100644
index 0000000..3fe3fa3
@@ -0,0 +1,30 @@
+/*
+ * Authors: Xiangfu Liu <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 3 of the License, or (at your option) any later version.
+ */
+
+#include <common.h>
+#include <nand.h>
+#include <asm/io.h>
+#include <asm/jz4740.h>
+
+void nand_spl_boot(void)
+{
+	__gpio_as_sdram_16bit_4720();
+	__gpio_as_uart0();
+	__gpio_jtag_to_uart0();
+
+	serial_init();
+
+	pll_init();
+	sdram_init();
+
+	nand_init();
+
+	puts("\nQi LB60 SPL: Starting U-Boot ...\n");
+	nand_boot();
+}
board/qi/qi_lb60/qi_lb60.c +5 -3
index d975209..3bd4e2f 100644
@@ -1,5 +1,5 @@
 /*
- * Authors: Xiangfu Liu <[email protected]>
+ * Authors: Xiangfu Liu <[email protected]>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -97,8 +97,10 @@ int board_early_init_f(void)
 /* U-Boot common routines */
 int checkboard(void)
 {
-	printf("Board: Qi LB60 (Ingenic XBurst Jz4740 SoC, Speed %ld MHz)\n",
-	       gd->cpu_clk / 1000000);
+	printf("Board: Qi LB60 (Ingenic XBurst Jz4740 SoC)\n");
+	printf(" CPU: %ld\n", gd->cpu_clk);
+	printf(" MEM: %ld\n", gd->mem_clk);
+	printf(" DEV: %ld\n", gd->dev_clk);
 
 	return 0;
 }
board/qi/qi_lb60/u-boot-spl.lds new file +61 -0

61 lines not on this page · raw message

drivers/mtd/nand/jz4740_nand.c +36 -3
index 3ec34f3..24a4921 100644
@@ -15,6 +15,9 @@
 #include <asm/io.h>
 #include <asm/jz4740.h>
 
+#ifdef CONFIG_SPL_BUILD
+#define printf(s) puts(s)
+#endif
 #define JZ_NAND_DATA_ADDR ((void __iomem *)0xB8000000)
 #define JZ_NAND_CMD_ADDR (JZ_NAND_DATA_ADDR + 0x8000)
 #define JZ_NAND_ADDR_ADDR (JZ_NAND_DATA_ADDR + 0x10000)
@@ -176,7 +179,7 @@ static int jz_nand_rs_correct_data(struct mtd_info *mtd, u_char *dat,
 		for (k = 0; k < 9; k++)
 			writeb(read_ecc[k], &emc->nfpar[k]);
 	}
-	/* Set PRDY */
+
 	writel(readl(&emc->nfecr) | EMC_NFECR_PRDY, &emc->nfecr);
 
 	/* Wait for completion */
@@ -184,7 +187,7 @@ static int jz_nand_rs_correct_data(struct mtd_info *mtd, u_char *dat,
 		status = readl(&emc->nfints);
 	} while (!(status & EMC_NFINTS_DECF));
 
-	/* disable ecc */
+	/* Disable ECC */
 	writel(readl(&emc->nfecr) & ~EMC_NFECR_ECCE, &emc->nfecr);
 
 	/* Check decoding */
@@ -192,7 +195,7 @@ static int jz_nand_rs_correct_data(struct mtd_info *mtd, u_char *dat,
 		return 0;
 
 	if (status & EMC_NFINTS_UNCOR) {
-		printf("uncorrectable ecc\n");
+		printf("JZ4740 uncorrectable ECC\n");
 		return -1;
 	}
 
@@ -230,6 +233,32 @@ static int jz_nand_rs_correct_data(struct mtd_info *mtd, u_char *dat,
 	return errcnt;
 }
 
+#ifdef CONFIG_SPL_BUILD
+static void jz_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
+{
+	int i;
+	struct nand_chip *this = mtd->priv;
+
+#if (JZ4740_NANDBOOT_CFG == JZ4740_NANDBOOT_B16R3) || \
+	(JZ4740_NANDBOOT_CFG == JZ4740_NANDBOOT_B16R2)
+	for (i = 0; i < len; i += 2)
+		buf[i] = readw(this->IO_ADDR_R);
+#elif (JZ4740_NANDBOOT_CFG == JZ4740_NANDBOOT_B8R3) || \
+	(JZ4740_NANDBOOT_CFG == JZ4740_NANDBOOT_B8R2)
+	for (i = 0; i < len; i++)
+		buf[i] = readb(this->IO_ADDR_R);
+#else
+	#error JZ4740_NANDBOOT_CFG not defined or wrong
+#endif
+}
+
+static uint8_t jz_nand_read_byte(struct mtd_info *mtd)
+{
+	struct nand_chip *this = mtd->priv;
+	return readb(this->IO_ADDR_R);
+}
+#endif
+
 /*
  * Main initialization routine
  */
@@ -254,6 +283,10 @@ int board_nand_init(struct nand_chip *nand)
 	nand->ecc.size		= CONFIG_SYS_NAND_ECCSIZE;
 	nand->ecc.bytes		= CONFIG_SYS_NAND_ECCBYTES;
 	nand->ecc.layout	= &qi_lb60_ecclayout_2gb;
+#ifdef CONFIG_SPL_BUILD
+	nand->read_byte		= jz_nand_read_byte;
+	nand->read_buf		= jz_nand_read_buf;
+#endif
 	nand->chip_delay	= 50;
 	nand->options		= NAND_USE_FLASH_BBT;
 
include/configs/qi_lb60.h +87 -88

255 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v7 1/1 qi_lb60: add nand spl support

Quoted 20 lines · xiangfu at openmobilefree.net

From: Xiangfu <[email protected]>

The JZ4740 CPU can load 8KB from two different addresses:
1. the normal area up to 8KB starting from NAND flash address
0x00000000
2. the backup area up to 8KB starting from NAND flash address
0x00002000

---
 Makefile                          |   12 +++
 arch/mips/cpu/xburst/Makefile     |    7 +-
 arch/mips/cpu/xburst/cpu.c        |    4 +
 arch/mips/cpu/xburst/jz4740.c     |   82 +++++++----------
 arch/mips/cpu/xburst/spl/Makefile |   47 ++++++++++
 arch/mips/cpu/xburst/spl/start.S  |   63 +++++++++++++
 board/qi/qi_lb60/Makefile         |    4 +
 board/qi/qi_lb60/qi_lb60-spl.c    |   30 +++++++
 board/qi/qi_lb60/qi_lb60.c        |    8 +-
 board/qi/qi_lb60/u-boot-spl.lds   |   61 +++++++++++++
Quoted 8 lines
 drivers/mtd/nand/jz4740_nand.c    |   39 ++++++++-
 include/configs/qi_lb60.h         |  175  
++++++++++++++++++-------------------
 12 files changed, 386 insertions(+), 146 deletions(-)
 create mode 100644 arch/mips/cpu/xburst/spl/Makefile
 create mode 100644 arch/mips/cpu/xburst/spl/start.S
 create mode 100644 board/qi/qi_lb60/qi_lb60-spl.c
 create mode 100644 board/qi/qi_lb60/u-boot-spl.lds

For the drivers/mtd/nand part:

-Scott

#3 lore raw

PATCH v7 1/1 qi_lb60: add nand spl support

Hi

Any chance merge this commit to upstream. make it a new year gift for me. :) Thanks

Xiangfu

Quoted 31 lines · Scott Wood
Quoted 17 lines · xiangfu at openmobilefree.net

From: Xiangfu <[email protected]>

The JZ4740 CPU can load 8KB from two different addresses:
1. the normal area up to 8KB starting from NAND flash address 0x00000000
2. the backup area up to 8KB starting from NAND flash address 0x00002000

---
 Makefile                          |   12 +++
 arch/mips/cpu/xburst/Makefile     |    7 +-
 arch/mips/cpu/xburst/cpu.c        |    4 +
 arch/mips/cpu/xburst/jz4740.c     |   82 +++++++----------
 arch/mips/cpu/xburst/spl/Makefile |   47 ++++++++++
 arch/mips/cpu/xburst/spl/start.S  |   63 +++++++++++++
 board/qi/qi_lb60/Makefile         |    4 +
 board/qi/qi_lb60/qi_lb60-spl.c    |   30 +++++++
 board/qi/qi_lb60/qi_lb60.c        |    8 +-
Quoted 8 lines
 board/qi/qi_lb60/u-boot-spl.lds   |   61 +++++++++++++
 drivers/mtd/nand/jz4740_nand.c    |   39 ++++++++-
 include/configs/qi_lb60.h         |  175 ++++++++++++++++++-------------------
 12 files changed, 386 insertions(+), 146 deletions(-)
 create mode 100644 arch/mips/cpu/xburst/spl/Makefile
 create mode 100644 arch/mips/cpu/xburst/spl/start.S
 create mode 100644 board/qi/qi_lb60/qi_lb60-spl.c
 create mode 100644 board/qi/qi_lb60/u-boot-spl.lds

For the drivers/mtd/nand part:

-Scott

#4 lore raw

PATCH v7 1/1 qi_lb60: add nand spl support

2013/1/4 Xiangfu Liu <[email protected]>:

Quoted 7 lines

Hi

Any chance merge this commit to upstream. make it a new year gift for me. :) Thanks

Xiangfu

hm, somehow I missed that patch. Please prepend your patch subject with "MIPS:" and CC me next time to avoid this.
Also send a new patch which is rebased to current master and move the cosmetic changes not related to SPL into a
separate patch.

Signature · 2 lines
Best regards,
Daniel
#5 lore raw

PATCH v7 1/1 qi_lb60: add nand spl support

Hi Daniel

Thanks for reply. patches coming soon.

Xiangfu

Quoted 15 lines · Daniel Schwierzeck

2013/1/4 Xiangfu Liu <[email protected]>:

Quoted 7 lines

Hi

Any chance merge this commit to upstream. make it a new year gift for me. :) Thanks

Xiangfu

hm, somehow I missed that patch. Please prepend your patch subject with "MIPS:" and CC me next time to avoid this.
Also send a new patch which is rebased to current master and move the cosmetic changes not related to SPL into a
separate patch.