Skip to content

Commit bc2d40c

Browse files
Prabhakar KushwahaYork Sun
authored andcommitted
board/p1_p2_rdb:Enable p1_p2_rdb boot from NAND/SD/SPI in SPL
In the earlier patches, the SPL/TPL fraamework was introduced. For SD/SPI flash booting way, we introduce the SPL to enable a loader stub. The SPL was loaded by the code from the internal on-chip ROM. The SPL initializes the DDR according to the SPD and loads the final uboot image into DDR, then jump to the DDR to begin execution. For NAND booting way, the nand SPL has size limitation on some board(e.g. P1010RDB), it can not be more than 4KB, we can call it "minimal SPL", So the dynamic DDR driver doesn't fit into this minimum SPL. We added the TPL that is loaded by the the minimal SPL. The TPL initializes the DDR according to the SPD and loads the final uboot image into DDR,then jump to the DDR to begin execution. This patch enabled SPL/TPL for P1_P2_RDB to support starting from NAND/SD/SPI flash with SPL framework and initializing the DDR according to SPD in the SPL/TPL. Because the minimal SPL load the TPL to L2 SRAM and the jump to the L2 SRAM to execute, so the section .resetvec is no longer needed. Signed-off-by: Prabhakar Kushwaha <[email protected]> Reviewed-by: York Sun <[email protected]>
1 parent 3051f3f commit bc2d40c

File tree

8 files changed

+450
-268
lines changed

8 files changed

+450
-268
lines changed

board/freescale/p1_p2_rdb/Makefile

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,27 @@
44
# SPDX-License-Identifier: GPL-2.0+
55
#
66

7+
MINIMAL=
8+
9+
ifdef CONFIG_SPL_BUILD
10+
ifdef CONFIG_SPL_INIT_MINIMAL
11+
MINIMAL=y
12+
endif
13+
endif
14+
15+
ifdef MINIMAL
16+
17+
obj-y += spl_minimal.o tlb.o law.o
18+
19+
else
20+
ifdef CONFIG_SPL_BUILD
21+
obj-y += spl.o
22+
else
723
obj-y += p1_p2_rdb.o
24+
obj-$(CONFIG_PCI) += pci.o
25+
endif
826
obj-y += ddr.o
927
obj-y += law.o
10-
obj-$(CONFIG_PCI) += pci.o
1128
obj-y += tlb.o
29+
30+
endif

board/freescale/p1_p2_rdb/ddr.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,27 +180,22 @@ fsl_ddr_cfg_regs_t ddr_cfg_regs_800 = {
180180

181181
phys_size_t fixed_sdram (void)
182182
{
183-
char buf[32];
184183
fsl_ddr_cfg_regs_t ddr_cfg_regs;
185184
size_t ddr_size;
186185
struct cpu_type *cpu;
187186
ulong ddr_freq, ddr_freq_mhz;
188187

189188
cpu = gd->arch.cpu;
190-
/* P1020 and it's derivatives support max 32bit DDR width */
191-
if (cpu->soc_ver == SVR_P1020 || cpu->soc_ver == SVR_P1011) {
192-
ddr_size = (CONFIG_SYS_SDRAM_SIZE * 1024 * 1024 / 2);
193-
} else {
194-
ddr_size = CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
195-
}
189+
190+
ddr_size = CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
191+
196192
#if defined(CONFIG_SYS_RAMBOOT)
197193
return ddr_size;
198194
#endif
199195
ddr_freq = get_ddr_freq(0);
200196
ddr_freq_mhz = ddr_freq / 1000000;
201197

202-
printf("Configuring DDR for %s MT/s data rate\n",
203-
strmhz(buf, ddr_freq));
198+
printf("Configuring DDR for %ld T/s data rate\n", ddr_freq);
204199

205200
if(ddr_freq_mhz <= 400)
206201
memcpy(&ddr_cfg_regs, &ddr_cfg_regs_400, sizeof(ddr_cfg_regs));
@@ -211,8 +206,7 @@ phys_size_t fixed_sdram (void)
211206
else if(ddr_freq_mhz <= 800)
212207
memcpy(&ddr_cfg_regs, &ddr_cfg_regs_800, sizeof(ddr_cfg_regs));
213208
else
214-
panic("Unsupported DDR data rate %s MT/s data rate\n",
215-
strmhz(buf, ddr_freq));
209+
panic("Unsupported DDR data rate %ld T/s\n", ddr_freq);
216210

217211
/* P1020 and it's derivatives support max 32bit DDR width */
218212
if (cpu->soc_ver == SVR_P1020 || cpu->soc_ver == SVR_P1011) {

board/freescale/p1_p2_rdb/spl.c

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* Copyright 2013 Freescale Semiconductor, Inc.
3+
*
4+
* SPDX-License-Identifier: GPL-2.0+
5+
*/
6+
7+
#include <common.h>
8+
#include <ns16550.h>
9+
#include <malloc.h>
10+
#include <mmc.h>
11+
#include <nand.h>
12+
#include <i2c.h>
13+
#include <fsl_esdhc.h>
14+
#include <spi_flash.h>
15+
16+
DECLARE_GLOBAL_DATA_PTR;
17+
18+
#define SYSCLK_MASK 0x00200000
19+
#define BOARDREV_MASK 0x10100000
20+
21+
#define SYSCLK_66 66666666
22+
#define SYSCLK_100 100000000
23+
24+
unsigned long get_board_sys_clk(ulong dummy)
25+
{
26+
ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
27+
u32 val_gpdat, sysclk_gpio;
28+
29+
val_gpdat = in_be32(&pgpio->gpdat);
30+
sysclk_gpio = val_gpdat & SYSCLK_MASK;
31+
32+
if (sysclk_gpio == 0)
33+
return SYSCLK_66;
34+
else
35+
return SYSCLK_100;
36+
37+
return 0;
38+
}
39+
40+
phys_size_t get_effective_memsize(void)
41+
{
42+
return CONFIG_SYS_L2_SIZE;
43+
}
44+
45+
void board_init_f(ulong bootflag)
46+
{
47+
u32 plat_ratio, bus_clk;
48+
ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
49+
50+
console_init_f();
51+
52+
/* Set pmuxcr to allow both i2c1 and i2c2 */
53+
setbits_be32(&gur->pmuxcr, in_be32(&gur->pmuxcr) | 0x1000);
54+
setbits_be32(&gur->pmuxcr,
55+
in_be32(&gur->pmuxcr) | MPC85xx_PMUXCR_SD_DATA);
56+
57+
/* Read back the register to synchronize the write. */
58+
in_be32(&gur->pmuxcr);
59+
60+
#ifdef CONFIG_SPL_SPI_BOOT
61+
clrbits_be32(&gur->pmuxcr, MPC85xx_PMUXCR_SD_DATA);
62+
#endif
63+
64+
/* initialize selected port with appropriate baud rate */
65+
plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
66+
plat_ratio >>= 1;
67+
bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
68+
gd->bus_clk = bus_clk;
69+
70+
NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
71+
bus_clk / 16 / CONFIG_BAUDRATE);
72+
#ifdef CONFIG_SPL_MMC_BOOT
73+
puts("\nSD boot...\n");
74+
#elif defined(CONFIG_SPL_SPI_BOOT)
75+
puts("\nSPI Flash boot...\n");
76+
#endif
77+
78+
/* copy code to RAM and jump to it - this should not return */
79+
/* NOTE - code has to be copied out of NAND buffer before
80+
* other blocks can be read.
81+
*/
82+
relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
83+
}
84+
85+
void board_init_r(gd_t *gd, ulong dest_addr)
86+
{
87+
/* Pointer is writable since we allocated a register for it */
88+
gd = (gd_t *)CONFIG_SPL_GD_ADDR;
89+
bd_t *bd;
90+
91+
memset(gd, 0, sizeof(gd_t));
92+
bd = (bd_t *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t));
93+
memset(bd, 0, sizeof(bd_t));
94+
gd->bd = bd;
95+
bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR;
96+
bd->bi_memsize = CONFIG_SYS_L2_SIZE;
97+
98+
probecpu();
99+
get_clocks();
100+
mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR,
101+
CONFIG_SPL_RELOC_MALLOC_SIZE);
102+
103+
#ifdef CONFIG_SPL_MMC_BOOT
104+
mmc_initialize(bd);
105+
#endif
106+
/* relocate environment function pointers etc. */
107+
#ifdef CONFIG_SPL_NAND_BOOT
108+
nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
109+
(uchar *)CONFIG_ENV_ADDR);
110+
#endif
111+
#ifdef CONFIG_SPL_NAND_BOOT
112+
nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
113+
(uchar *)CONFIG_ENV_ADDR);
114+
#endif
115+
#ifdef CONFIG_SPL_MMC_BOOT
116+
mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
117+
(uchar *)CONFIG_ENV_ADDR);
118+
#endif
119+
#ifdef CONFIG_SPL_SPI_BOOT
120+
spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
121+
(uchar *)CONFIG_ENV_ADDR);
122+
#endif
123+
124+
gd->env_addr = (ulong)(CONFIG_ENV_ADDR);
125+
gd->env_valid = 1;
126+
127+
gd->ram_size = initdram(0);
128+
#ifdef CONFIG_SPL_NAND_BOOT
129+
puts("Tertiary program loader running in sram...");
130+
#else
131+
puts("Second program loader running in sram...\n");
132+
#endif
133+
134+
#ifdef CONFIG_SPL_MMC_BOOT
135+
mmc_boot();
136+
#elif defined(CONFIG_SPL_SPI_BOOT)
137+
spi_boot();
138+
#elif defined(CONFIG_SPL_NAND_BOOT)
139+
nand_boot();
140+
#endif
141+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2011 Freescale Semiconductor, Inc.
3+
*
4+
* SPDX-License-Identifier: GPL-2.0+
5+
*/
6+
7+
#include <common.h>
8+
#include <ns16550.h>
9+
#include <asm/io.h>
10+
#include <nand.h>
11+
#include <linux/compiler.h>
12+
#include <asm/fsl_law.h>
13+
#include <fsl_ddr_sdram.h>
14+
#include <asm/global_data.h>
15+
16+
DECLARE_GLOBAL_DATA_PTR;
17+
#define SYSCLK_MASK 0x00200000
18+
#define BOARDREV_MASK 0x10100000
19+
20+
#define SYSCLK_66 66666666
21+
#define SYSCLK_100 100000000
22+
23+
unsigned long get_board_sys_clk(ulong dummy)
24+
{
25+
ccsr_gpio_t *pgpio = (void *)(CONFIG_SYS_MPC85xx_GPIO_ADDR);
26+
u32 val_gpdat, sysclk_gpio;
27+
28+
val_gpdat = in_be32(&pgpio->gpdat);
29+
sysclk_gpio = val_gpdat & SYSCLK_MASK;
30+
31+
if (sysclk_gpio == 0)
32+
return SYSCLK_66;
33+
else
34+
return SYSCLK_100;
35+
36+
return 0;
37+
}
38+
39+
void board_init_f(ulong bootflag)
40+
{
41+
u32 plat_ratio;
42+
ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
43+
44+
#if defined(CONFIG_SYS_NAND_BR_PRELIM) && defined(CONFIG_SYS_NAND_OR_PRELIM)
45+
set_lbc_br(0, CONFIG_SYS_NAND_BR_PRELIM);
46+
set_lbc_or(0, CONFIG_SYS_NAND_OR_PRELIM);
47+
#endif
48+
49+
/* initialize selected port with appropriate baud rate */
50+
plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO;
51+
plat_ratio >>= 1;
52+
gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio;
53+
54+
NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1,
55+
gd->bus_clk / 16 / CONFIG_BAUDRATE);
56+
57+
puts("\nNAND boot... ");
58+
59+
/* copy code to RAM and jump to it - this should not return */
60+
/* NOTE - code has to be copied out of NAND buffer before
61+
* other blocks can be read.
62+
*/
63+
relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE);
64+
}
65+
66+
void board_init_r(gd_t *gd, ulong dest_addr)
67+
{
68+
puts("\nSecond program loader running in sram...");
69+
nand_boot();
70+
}
71+
72+
void putc(char c)
73+
{
74+
if (c == '\n')
75+
NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, '\r');
76+
77+
NS16550_putc((NS16550_t)CONFIG_SYS_NS16550_COM1, c);
78+
}
79+
80+
void puts(const char *str)
81+
{
82+
while (*str)
83+
putc(*str++);
84+
}

board/freescale/p1_p2_rdb/tlb.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct fsl_e_tlb_entry tlb_table[] = {
3737
MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
3838
0, 1, BOOKE_PAGESZ_1M, 1),
3939

40+
#ifndef CONFIG_SPL_BUILD
4041
/* W**G* - Flash/promjet, localbus */
4142
/* This will be changed to *I*G* after relocation to RAM. */
4243
SET_TLB_ENTRY(1, CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_BASE_PHYS,
@@ -55,6 +56,7 @@ struct fsl_e_tlb_entry tlb_table[] = {
5556
0, 4, BOOKE_PAGESZ_256K, 1),
5657

5758
#endif /* #if defined(CONFIG_PCI) */
59+
#endif
5860
/* *I*G - NAND */
5961
SET_TLB_ENTRY(1, CONFIG_SYS_NAND_BASE, CONFIG_SYS_NAND_BASE_PHYS,
6062
MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
@@ -65,7 +67,21 @@ struct fsl_e_tlb_entry tlb_table[] = {
6567
MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
6668
0, 6, BOOKE_PAGESZ_1M, 1),
6769

68-
#if defined(CONFIG_SYS_RAMBOOT)
70+
#ifdef CONFIG_SYS_INIT_L2_ADDR
71+
/* *I*G - L2SRAM */
72+
SET_TLB_ENTRY(1, CONFIG_SYS_INIT_L2_ADDR, CONFIG_SYS_INIT_L2_ADDR_PHYS,
73+
MAS3_SX|MAS3_SW|MAS3_SR, MAS2_G,
74+
0, 11, BOOKE_PAGESZ_256K, 1),
75+
#if CONFIG_SYS_L2_SIZE >= (256 << 10)
76+
SET_TLB_ENTRY(1, CONFIG_SYS_INIT_L2_ADDR + 0x40000,
77+
CONFIG_SYS_INIT_L2_ADDR_PHYS + 0x40000,
78+
MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
79+
0, 12, BOOKE_PAGESZ_256K, 1),
80+
#endif
81+
#endif
82+
83+
#if defined(CONFIG_SYS_RAMBOOT) || \
84+
(defined(CONFIG_SPL) && !defined(CONFIG_SPL_COMMON_INIT_DDR))
6985
SET_TLB_ENTRY(1, CONFIG_SYS_DDR_SDRAM_BASE, CONFIG_SYS_DDR_SDRAM_BASE,
7086
MAS3_SX|MAS3_SW|MAS3_SR, 0,
7187
0, 7, BOOKE_PAGESZ_1G, 1)

0 commit comments

Comments
 (0)