Skip to contentSkip to conversation

board/b4qds:Add support of 2 stage NAND boot-loader

PATCH Superseded Prabhakar Kushwaha 2 participants 4 messages Mar 31, 2014 – Apr 4, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 9/10 board/b4qds:Add support of 2 stage NAND boot-loader

Add support of 2 stage NAND boot loader using SPL framework.
here, PBL initialise the internal SRAM and copy SPL(160KB). This further initialise DDR using SPD and environment and copy u-boot(768 KB) from NAND to DDR. Finally SPL transer control to u-boot.

Initialise/create followings required for SPL framework
- Add spl.c which defines board_init_f, board_init_r
- update tlb and ddr accordingly

---
 board/freescale/b4860qds/Makefile |    9 ++-
 board/freescale/b4860qds/ddr.c    |    5 +-
 board/freescale/b4860qds/spl.c    |  115 +++++++++++++++++++++++++++++++++++++
 board/freescale/b4860qds/tlb.c    |   10 ++++
 boards.cfg                        |    4 +-
 doc/README.b4860qds               |   35 +++++++++++
 include/configs/B4860QDS.h        |   64 ++++++++++++++++++---
 7 files changed, 230 insertions(+), 12 deletions(-)
 create mode 100644 board/freescale/b4860qds/spl.c
board/freescale/b4860qds/Makefile +7 -2
index e5cc054..0acd2a9 100644
@@ -4,9 +4,14 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
+ifdef CONFIG_SPL_BUILD
+obj-y += spl.o
+else
 obj-y	+= b4860qds.o
-obj-y	+= ddr.o
 obj-$(CONFIG_B4860QDS)+= eth_b4860qds.o
-obj-$(CONFIG_PCI)	+= pci.o
+obj-$(CONFIG_PCI)      += pci.o
+endif
+
+obj-y	+= ddr.o
 obj-y	+= law.o
 obj-y	+= tlb.o
board/freescale/b4860qds/ddr.c +4 -1
index 187c3b3..2c17156 100644
@@ -179,6 +179,7 @@ phys_size_t initdram(int board_type)
 {
 	phys_size_t dram_size;
 
+#if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_RAMBOOT_PBL)
 	puts("Initializing....using SPD\n");
 
 	dram_size = fsl_ddr_sdram();
@@ -186,7 +187,9 @@ phys_size_t initdram(int board_type)
 	dram_size = setup_ddr_tlbs(dram_size / 0x100000);
 	dram_size *= 0x100000;
 
-	puts("    DDR: ");
+#else
+	dram_size =  fsl_ddr_sdram_size();
+#endif
 	return dram_size;
 }
 
board/freescale/b4860qds/spl.c new file +115 -0

115 lines not on this page · raw message

board/freescale/b4860qds/tlb.c +10 -0
index 00798a1..7b55b86 100644
@@ -62,6 +62,7 @@ struct fsl_e_tlb_entry tlb_table[] = {
 		      MAS3_SX|MAS3_SR, MAS2_W|MAS2_G,
 		      0, 2, BOOKE_PAGESZ_256M, 1),
 
+#ifndef CONFIG_SPL_BUILD
 	/* *I*G* - PCI */
 	SET_TLB_ENTRY(1, CONFIG_SYS_PCIE1_MEM_VIRT, CONFIG_SYS_PCIE1_MEM_PHYS,
 		      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
@@ -96,6 +97,7 @@ struct fsl_e_tlb_entry tlb_table[] = {
 		      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
 		      0, 9, BOOKE_PAGESZ_16M, 1),
 #endif
+#endif
 #ifdef CONFIG_SYS_DCSRBAR_PHYS
 	SET_TLB_ENTRY(1, CONFIG_SYS_DCSRBAR, CONFIG_SYS_DCSRBAR_PHYS,
 		      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
@@ -118,6 +120,7 @@ struct fsl_e_tlb_entry tlb_table[] = {
 	 * entry 14 and 15 has been used hard coded, they will be disabled
 	 * in cpu_init_f, so we use entry 16 for SRIO2.
 	 */
+#ifndef CONFIG_SPL_BUILD
 #ifdef CONFIG_SYS_SRIO1_MEM_PHYS
 	/* *I*G* - SRIO1 */
 	SET_TLB_ENTRY(1, CONFIG_SYS_SRIO1_MEM_VIRT, CONFIG_SYS_SRIO1_MEM_PHYS,
@@ -140,6 +143,13 @@ struct fsl_e_tlb_entry tlb_table[] = {
 		      MAS3_SX|MAS3_SW|MAS3_SR, MAS2_G,
 		      0, 17, BOOKE_PAGESZ_1M, 1),
 #endif
+#endif
+
+#if defined(CONFIG_RAMBOOT_PBL) && !defined(CONFIG_SPL_BUILD)
+	SET_TLB_ENTRY(1, CONFIG_SYS_DDR_SDRAM_BASE, CONFIG_SYS_DDR_SDRAM_BASE,
+		      MAS3_SX|MAS3_SW|MAS3_SR, 0,
+		      0, 17, BOOKE_PAGESZ_2G, 1)
+#endif
 };
 
 int num_tlb_entries = ARRAY_SIZE(tlb_table);
boards.cfg +2 -2
index 5afca26..76f3aae 100644
@@ -740,10 +740,10 @@ Active  powerpc     mpc85xx        -           -               sbc8548
 Active  powerpc     mpc85xx        -           -               socrates            socrates                             -                                                                                                                                 -
 Active  powerpc     mpc85xx        -           exmeritus       hww1u1a             HWW1U1A                              -                                                                                                                                 Kyle Moffett <[email protected]>
 Active  powerpc     mpc85xx        -           freescale       b4860qds            B4420QDS                             B4860QDS:PPC_B4420                                                                                                                -
-Active  powerpc     mpc85xx        -           freescale       b4860qds            B4420QDS_NAND                        B4860QDS:PPC_B4420,RAMBOOT_PBL,NAND,SYS_TEXT_BASE=0xFFF40000                                                                      -
+Active  powerpc     mpc85xx        -           freescale       b4860qds            B4420QDS_NAND                        B4860QDS:PPC_B4420,RAMBOOT_PBL,RAMBOOT_SPLPBL,NAND                                                                      -
 Active  powerpc     mpc85xx        -           freescale       b4860qds            B4420QDS_SPIFLASH                    B4860QDS:PPC_B4420,RAMBOOT_PBL,SPIFLASH,SYS_TEXT_BASE=0xFFF40000                                                                  -
 Active  powerpc     mpc85xx        -           freescale       b4860qds            B4860QDS                             B4860QDS:PPC_B4860                                                                                                                -
-Active  powerpc     mpc85xx        -           freescale       b4860qds            B4860QDS_NAND                        B4860QDS:PPC_B4860,RAMBOOT_PBL,NAND,SYS_TEXT_BASE=0xFFF40000                                                                      -
+Active  powerpc     mpc85xx        -           freescale       b4860qds            B4860QDS_NAND                        B4860QDS:PPC_B4860,RAMBOOT_PBL,RAMBOOT_SPLPBL,NAND
 Active  powerpc     mpc85xx        -           freescale       b4860qds            B4860QDS_SPIFLASH                    B4860QDS:PPC_B4860,RAMBOOT_PBL,SPIFLASH,SYS_TEXT_BASE=0xFFF40000                                                                  -
 Active  powerpc     mpc85xx        -           freescale       b4860qds            B4860QDS_SRIO_PCIE_BOOT              B4860QDS:PPC_B4860,SRIO_PCIE_BOOT_SLAVE,SYS_TEXT_BASE=0xFFF40000                                                                  -
 Active  powerpc     mpc85xx        -           freescale       bsc9131rdb          BSC9131RDB_NAND                      BSC9131RDB:BSC9131RDB,NAND                                                                                                        Poonam Aggrwal <[email protected]>
doc/README.b4860qds +35 -0
index 3da77d9..44b46da 100644
@@ -328,3 +328,38 @@ The below commands apply to both B4860QDS and B4420QDS.
    On Linux the interfaces are renamed as:
 	. eth2 -> fm1-gb2
 	. eth3 -> fm1-gb3
+
+NAND boot with 2 Stage boot loader
+----------------------------------
+PBL initialise the internal SRAM and copy SPL(160KB) in SRAM.
+SPL further initialise DDR using SPD and environment variables and copy
+u-boot(768 KB) from flash to DDR.
+Finally SPL transer control to u-boot for futher booting.
+
+SPL has following features:
+ - Executes within 256K
+ - No relocation required
+
+ Run time view of SPL framework :-
+ -----------------------------------------------
+ Area        | Address                         |
+-----------------------------------------------
+ Reserve     | 0xFFFC0000 (32KB)               |
+ -----------------------------------------------
+ GD, BD      | 0xFFFC8000 (4KB)                |
+ -----------------------------------------------
+ ENV         | 0xFFFC9000 (6KB)                |
+ -----------------------------------------------
+ HEAP        | 0xFFFCA800 (30KB)               |
+ -----------------------------------------------
+ STACK       | 0xFFFD8000 (20KB)               |
+ -----------------------------------------------
+ U-boot SPL  | 0xFFFD8000 (160KB)              |
+ -----------------------------------------------
+
+NAND Flash memory Map on B4860 and B4420QDS
+------------------------------------------
+ Start		 End		Definition			Size
+0x000000	0x0FFFFF	u-boot                          1MB
+0x140000	0x15FFFF	u-boot env                      128KB
+0x160000	0x17FFFF	FMAN Ucode                      128KB
include/configs/B4860QDS.h +57 -7

110 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 9/10 board/b4qds:Add support of 2 stage NAND boot-loader

board/freescale/b4860qds/spl.c line 62

Quoted 11 lines · Prabhakar Kushwaha
board/freescale/b4860qds/spl.c new file +11 -0
+void board_init_f(ulong bootflag)
+{
+	u32 plat_ratio, sys_clk, uart_clk;
+	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
+
+	/* Memcpy existing GD at CONFIG_SPL_GD_ADDR */
+	memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
+
+	/* Update GD pointer */
+	gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
+	__asm__ __volatile__("" : : : "memory");

Explain why this barrier is needed.

board/freescale/b4860qds/spl.c line 104

Quoted 13 lines
board/freescale/b4860qds/spl.c new file +13 -0
+#ifndef CONFIG_SPL_NAND_BOOT
+	env_init();
+#endif
+
+	/* relocate environment function pointers etc. */
+#ifdef CONFIG_SPL_NAND_BOOT
+	nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
+			    (uchar *)CONFIG_ENV_ADDR);
+	gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
+	gd->env_valid = 1;
+#else
+	env_relocate();
+#endif

Move env_init() to be just before env_relocate(), rather than duplicating the ifdef.

board/freescale/b4860qds/spl.c line 110

Quoted 5 lines
board/freescale/b4860qds/spl.c new file +5 -0
+	i2c_init_all();
+
+	puts("\n\n");
+
+	gd->ram_size = initdram(0);

What is the 0?

Quoted 15 lines
doc/README.b4860qds +7 -0
index 3da77d9..44b46da 100644
@@ -328,3 +328,38 @@ The below commands apply to both B4860QDS and B4420QDS.
    On Linux the interfaces are renamed as:
 	. eth2 -> fm1-gb2
 	. eth3 -> fm1-gb3
+
+NAND boot with 2 Stage boot loader
+----------------------------------
+PBL initialise the internal SRAM and copy SPL(160KB) in SRAM.
+SPL further initialise DDR using SPD and environment variables and copy
+u-boot(768 KB) from flash to DDR.
+Finally SPL transer control to u-boot for futher booting.

doc/README.b4860qds The below commands apply to both B4860QDS and B4420QDS. · line 347

Quoted 10 lines
doc/README.b4860qds +10 -0
+
+SPL has following features:
+ - Executes within 256K
+ - No relocation required
+
+ Run time view of SPL framework :-
+ -----------------------------------------------
+ Area        | Address                         |
+-----------------------------------------------
+ Reserve     | 0xFFFC0000 (32KB)               |

s/Reserve/Reserved/

What is it reserved for/by? Something external? Or does U-Boot just not use that area currently? In that case just say "Unused".

doc/README.b4860qds The below commands apply to both B4860QDS and B4420QDS. · line 365

Quoted 6 lines
doc/README.b4860qds +6 -0
+NAND Flash memory Map on B4860 and B4420QDS
+------------------------------------------
+ Start		 End		Definition			Size
+0x000000	0x0FFFFF	u-boot                          1MB
+0x140000	0x15FFFF	u-boot env                      128KB
+0x160000	0x17FFFF	FMAN Ucode                      128KB

What goes at 0x100000?

What if 0x140000 or 0x160000 is a bad block?

-Scott

#2 lore raw

PATCH 9/10 board/b4qds:Add support of 2 stage NAND boot-loader

Quoted 14 lines · Scott Wood

board/freescale/b4860qds/spl.c line 62

Quoted 11 lines · Prabhakar Kushwaha
board/freescale/b4860qds/spl.c new file +11 -0
+void board_init_f(ulong bootflag)
+{
+	u32 plat_ratio, sys_clk, uart_clk;
+	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
+
+	/* Memcpy existing GD at CONFIG_SPL_GD_ADDR */
+	memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
+
+	/* Update GD pointer */
+	gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
+	__asm__ __volatile__("" : : : "memory");

Explain why this barrier is needed.

I followed similar to what is present in arch/powerpc/lib/board.c. There is is mentioned like

     /* compiler optimization barrier needed for GCC >= 3.4 */
     __asm__ __volatile__("":::"memory");

may i mention this comment here also.

Quoted 7 lines
Quoted 7 lines
board/freescale/b4860qds/spl.c new file +7 -0
+#ifndef CONFIG_SPL_NAND_BOOT
+	env_init();
+#endif
+
+	/* relocate environment function pointers etc. */
+#ifdef CONFIG_SPL_NAND_BOOT
+	nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
Quoted 8 lines

board/freescale/b4860qds/spl.c line 104

Quoted 6 lines
board/freescale/b4860qds/spl.c new file +6 -0
+			    (uchar *)CONFIG_ENV_ADDR);
+	gd->env_addr  = (ulong)(CONFIG_ENV_ADDR);
+	gd->env_valid = 1;
+#else
+	env_relocate();
+#endif

Move env_init() to be just before env_relocate(), rather than duplicating the ifdef.

sure, I will do it.

Quoted 6 lines

board/freescale/b4860qds/spl.c line 110

Quoted 5 lines
board/freescale/b4860qds/spl.c new file +5 -0
+	i2c_init_all();
+
+	puts("\n\n");
+
+	gd->ram_size = initdram(0);

What is the 0?

here 0 is board type.

in arch/powerpc/lib/board.c , we pass it as 0 "dummy arg". Same I am following here

Quoted 27 lines
Quoted 15 lines
doc/README.b4860qds +7 -0
index 3da77d9..44b46da 100644
@@ -328,3 +328,38 @@ The below commands apply to both B4860QDS and B4420QDS.
     On Linux the interfaces are renamed as:
  	. eth2 -> fm1-gb2
  	. eth3 -> fm1-gb3
+
+NAND boot with 2 Stage boot loader
+----------------------------------
+PBL initialise the internal SRAM and copy SPL(160KB) in SRAM.
+SPL further initialise DDR using SPD and environment variables and copy
+u-boot(768 KB) from flash to DDR.
+Finally SPL transer control to u-boot for futher booting.

doc/README.b4860qds The below commands apply to both B4860QDS and B4420QDS. · line 347

Quoted 10 lines
doc/README.b4860qds +10 -0
+
+SPL has following features:
+ - Executes within 256K
+ - No relocation required
+
+ Run time view of SPL framework :-
+ -----------------------------------------------
+ Area        | Address                         |
+-----------------------------------------------
+ Reserve     | 0xFFFC0000 (32KB)               |

s/Reserve/Reserved/

Quoted 2 lines

What is it reserved for/by? Something external? Or does U-Boot just not use that area currently? In that case just say "Unused".

Secure boot requires some memory in SRAM in order to put some headers etc. May be I mention in README also

Quoted 7 lines

doc/README.b4860qds The below commands apply to both B4860QDS and B4420QDS. · line 365

Quoted 6 lines
doc/README.b4860qds +6 -0
+NAND Flash memory Map on B4860 and B4420QDS
+------------------------------------------
+ Start		 End		Definition			Size
+0x000000	0x0FFFFF	u-boot                          1MB
+0x140000	0x15FFFF	u-boot env                      128KB
+0x160000	0x17FFFF	FMAN Ucode                      128KB

What goes at 0x100000?

I think, ENV can start from here.

Quoted 3 lines

What if 0x140000 or 0x160000 is a bad block?

it can be true for any region. I believe it will be taken care by MTD layer to read next good block.

are you suggesting to have a hole of 1 block between every regions.

Regards,
Prabhakar

#3 lore raw

PATCH 9/10 board/b4qds:Add support of 2 stage NAND boot-loader

Quoted 16 lines · Prabhakar Kushwaha
Quoted 14 lines · Scott Wood

board/freescale/b4860qds/spl.c line 62

Quoted 11 lines · Prabhakar Kushwaha
board/freescale/b4860qds/spl.c new file +11 -0
+void board_init_f(ulong bootflag)
+{
+	u32 plat_ratio, sys_clk, uart_clk;
+	ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
+
+	/* Memcpy existing GD at CONFIG_SPL_GD_ADDR */
+	memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t));
+
+	/* Update GD pointer */
+	gd = (gd_t *)(CONFIG_SPL_GD_ADDR);
+	__asm__ __volatile__("" : : : "memory");

Explain why this barrier is needed.

Quoted 6 lines

I followed similar to what is present in arch/powerpc/lib/board.c. There is is mentioned like

     /* compiler optimization barrier needed for GCC >= 3.4 */
     __asm__ __volatile__("":::"memory");

may i mention this comment here also.

Yes, at least retain the comment when you copy the code.

Quoted 11 lines
Quoted 6 lines

board/freescale/b4860qds/spl.c line 110

Quoted 5 lines
board/freescale/b4860qds/spl.c new file +5 -0
+	i2c_init_all();
+
+	puts("\n\n");
+
+	gd->ram_size = initdram(0);

What is the 0?

here 0 is board type.

in arch/powerpc/lib/board.c , we pass it as 0 "dummy arg". Same I am following here

Right, that comment was more for York -- why do we have this dummy argument?

Quoted 11 lines
Quoted 9 lines
Quoted 5 lines

+ Run time view of SPL framework :-
+ -----------------------------------------------
+ Area | Address |

+-----------------------------------------------
+ Reserve     | 0xFFFC0000 (32KB)               |

s/Reserve/Reserved/

What is it reserved for/by? Something external? Or does U-Boot just not use that area currently? In that case just say "Unused".

Secure boot requires some memory in SRAM in order to put some headers etc. May be I mention in README also

Secure boot is no longer running at this point, so why does it care?

Or do you mean that code in U-Boot uses this for validating the next image (in which case, it's not reserved, but rather used for that purpose)?

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines

+NAND Flash memory Map on B4860 and B4420QDS
+------------------------------------------
+ Start End Definition Size

+0x000000	0x0FFFFF	u-boot                          1MB
+0x140000	0x15FFFF	u-boot env                      128KB
+0x160000	0x17FFFF	FMAN Ucode                      128KB

What goes at 0x100000?

Quoted 7 lines

I think, ENV can start from here.

Quoted 3 lines

What if 0x140000 or 0x160000 is a bad block?

it can be true for any region. I believe it will be taken care by MTD layer to read next good block.

No, it won't. Imagine if it did, and 0x140000 were bad, and it used 0x160000 instead. Then where would FMAN Ucode go?

Quoted 1 line

are you suggesting to have a hole of 1 block between every regions.

There are a variety of options for dealing with this for the environment. One of them is leaving a range of blocks (more than two -- consecutive blocks can be bad) within which block skipping can be done. This can be fairly wasteful, especially if you'd extend it to other things like microcode.

Another way is to put the environment in UBI, but that means you can't load the environment during SPL or before relocation.

My suggestion would be to put non-environment things in UBI. For the environment, either use CONFIG_ENV_RANGE, or append the environment (block-aligned) to the U-Boot image so it can participate in its bad block skipping without having to reserve another large chunk.

Also consider having a redundant environment, IIRC this will need additional work to function with any of the bad block handling approaches.

-Scott