S5PV210:支持NAND启动u-boot

时间:2022-09-23 19:32:25

1、修改:u-boot\board\samsung\smdkv210\smdkv210.c中的copy_bl2_to _ram函数,增加对SD/NAND启动的判断

void copy_bl2_to_ram(void)
{
/*
** ch: 通道
** sb: 起始块
** bs: 块大小
** dst: 目的地
** i: 是否初始化
*/
#define CopySDMMCtoMem(ch, sb, bs, dst, i) \
(((u8(*)(int, u32, unsigned short, u32*, u8))\
(*((u32 *)0xD0037F98)))(ch, sb, bs, dst, i))

#define MP0_1CON (*(volatile u32 *)0xE02002E0)
#defineMP0_3CON (*(volatile u32 *)0xE0200320)
#defineMP0_6CON (*(volatile u32 *)0xE0200380)

#define NF8_ReadPage_Adv(a,b,c) (((int(*)(u32, u32, u8*))(*((u32 *)0xD0037F90)))(a,b,c))

u32 bl2Size = 250 * 1024;// 250K

u32 OM = *(volatile u32 *)(0xE0000004);// OM Register
OM &= 0x1F;// 取低5位

if (OM == 0x2)// NAND 2 KB, 5cycle 8-bit ECC
{
u32 cfg = 0;
struct s5pv210_nand *nand_reg = (struct s5pv210_nand *)(struct s5pv210_nand *)samsung_get_base_nand();

/* initialize hardware */
/* HCLK_PSYS=133MHz(7.5ns) */
cfg =(0x1 << 23) |/* Disable 1-bit and 4-bit ECC */
/* 下面3个时间参数稍微比计算出的值大些(我这里依次加1),否则读写不稳定 */
(0x3 << 12) |/* 7.5ns * 2 > 12ns tALS tCLS */
(0x2 << 8) | /* (1+1) * 7.5ns > 12ns (tWP) */
(0x1 << 4) | /* (0+1) * 7.5 > 5ns (tCLH/tALH) */
(0x0 << 3) | /* SLC NAND Flash */
(0x0 << 2) |/* 2KBytes/Page */
(0x1 << 1);/* 5 address cycle */

writel(cfg, &nand_reg->nfconf);

writel((0x1 << 1) | (0x1 << 0), &nand_reg->nfcont);
/* Disable chip select and Enable NAND Flash Controller */

/* Config GPIO */
MP0_1CON &= ~(0xFFFF << 8);
MP0_1CON |= (0x3333 << 8);
MP0_3CON = 0x22222222;
MP0_6CON = 0x22222222;

int i = 0;
int pages = bl2Size / 2048;// 多少页
int offset = 0x4000 / 2048;// u-boot.bin在NAND中的偏移地址(页地址)
u8 *p = (u8 *)CONFIG_SYS_SDRAM_BASE;
for (; i < pages; i++, p += 2048, offset += 1)
NF8_ReadPage_Adv(offset / 64, offset % 64, p);
}
else if (OM == 0xC)// SD/MMC
{
u32 V210_SDMMC_BASE = *(volatile u32 *)(0xD0037488);// V210_SDMMC_BASE
u8 ch = 0;

/* 参考S5PV210手册7.9.1 SD/MMC REGISTER MAP */
if (V210_SDMMC_BASE == 0xEB000000)// 通道0
ch = 0;
else if (V210_SDMMC_BASE == 0xEB200000)// 通道2
ch = 2;
CopySDMMCtoMem(ch, 32, bl2Size / 512, (u32 *)CONFIG_SYS_SDRAM_BASE, 0);
}
}

重新编译,烧写到SD卡启动,在通过TFTP烧写到NAND

A、

SMDKV210 # tftpboot 20000000 smdkv210-spl.bin
smc911x: detected LAN9220 controller
smc911x: phy initialized
smc911x: MAC 1a:2a:3a:4a:5a:6a
Using smc911x-0 device
TFTP from server 192.168.1.101; our IP address is 192.168.1.108
Filename 'smdkv210-spl.bin'.
Load address: 0x20000000
Loading: T #
0 Bytes/s
done
Bytes transferred = 1420 (58c hex)

B、
SMDKV210 # nand write 20000000 0 $filesize

NAND write: device 0 offset 0x0, size 0x58c
1420 bytes written: OK

C、
SMDKV210 # tftpboot 20000000 u-boot.bin
smc911x: detected LAN9220 controller
smc911x: phy initialized
smc911x: MAC 1a:2a:3a:4a:5a:6a
Using smc911x-0 device
TFTP from server 192.168.1.101; our IP address is 192.168.1.108
Filename 'u-boot.bin'.
Load address: 0x20000000
Loading: T ################
40 KiB/s
done
Bytes transferred = 231368 (387c8 hex)

D、
SMDKV210 # nand write 20000000 4000  $filesize

NAND write: device 0 offset 0x4000, size 0x387c8
231368 bytes written: OK

最后执行:saveenv  把环境变量都保存到NAND中!(就能消除环境参数错误)