1 添加网络命令
在include/configs/gec2410.h
只要在
#define CONFIG_COMMANDS
添加定义
CFG_CMD_NET |\
CFG_CMD_PING |\
就可以了
说明:include/configs/gec2410.h
文件是与开发板相关的配置头文件。
2 支持nand flash启动和读写
(1) 支持从nand flash 启动
a 添加nandflash寄存器的定义
修改include/configs/gec2410.h文件,
添加如下内容:
/* * Nandflash Boot */
#define CONFIG_S3C2410_NAND_BOOT 1
#define STACK_BASE 0x33f00000
#define STACK_SIZE 0x8000
#define UBOOT_RAM_BASE 0x33f80000
/* NAND Flash Controller */
#define NAND_CTL_BASE 0x4E000000
#define bINT_CTL(Nb) __REG(INT_CTL_BASE + (Nb))
/* Offset */
#define oNFCONF 0x00
#define oNFCMD 0x04
#define oNFADDR 0x08
#define oNFDATA 0x0c
#define oNFSTAT 0x10
#define oNFECC 0x14
***********************************************************************************************
b 在start.S加入搬运代码
修改cpu/arm920t/start.S文件
在ldr pc, _start_armboot之前加入:
************************************************************************************************
#ifdef CONFIG_S3C2410_NAND_BOOT
bl copy_myself
@ jump to ram
ldr r1, =on_the_ram
add pc, r1, #0
nop
nop
1: b 1b @ infinite loop on_the_ram:
#endif
************************************************************************************************
在_start_armboot: .word start_armboot之后加入:
************************************************************************************************
#ifdef CONFIG_S3C2410_NAND_BOOT
copy_myself: mov r10, lr
@ reset NAND
mov r1, #NAND_CTL_BASE
ldr r2, =0xf830 @ initial value
str r2, [r1, #oNFCONF]
ldr r2, [r1, #oNFCONF]
bic r2, r2, #0x800 @ enable chip
str r2, [r1, #oNFCONF]
mov r2, #0xff @ RESET command
strb r2, [r1, #oNFCMD]
mov r3, #0 @ wait
1:add r3, r3, #0x1
cmp r3, #0xa
blt 1b
2:ldr r2, [r1, #oNFSTAT] @ wait ready
tst r2, #0x1
beq 2b
ldr r2, [r1, #oNFCONF]
orr r2, r2, #0x800 @ disable chip
str r2, [r1, #oNFCONF]
@ get read to call C functions (for nand_read())
ldr sp, DW_STACK_START @ setup stack pointer
mov fp, #0 @ no previous frame, so fp=0
@ copy vivi to RAM
ldr r0, =UBOOT_RAM_BASE
mov r1, #0x0
mov r2, #0x20000
bl nand_read_ll
tst r0, #0x0
beq ok_nand_read
#ifdef CONFIG_DEBUG_LL
bad_nand_read:
ldr r0, STR_FAIL
ldr r1, SerBase
bl PrintWord1:b 1b @ infinite loop
#endif
ok_nand_read:
#ifdef CONFIG_DEBUG_LL
ldr r0, STR_OK
ldr r1, SerBase
bl PrintWord
#endif
@ verify
mov r0, #0
ldr r1, =UBOOT_RAM_BASE
mov r2, #0x400 @ 4 bytes * 1024 = 4K-bytesgo_next:
ldr r3, [r0], #4
ldr r4, [r1], #4
teq r3, r4
bne notmatch
subs r2, r2, #4
beq done_nand_read
bne go_next
notmatch:
#ifdef CONFIG_DEBUG_LL
sub r0, r0, #4
ldr r1, SerBase
bl PrintHexWord
ldr r0, STR_FAIL
ldr r1, SerBase
bl PrintWord
#endif
1:b 1bdone_nand_read:
#ifdef CONFIG_DEBUG_LL
ldr r0, STR_OK
ldr r1, SerBase
bl PrintWord
#endif
mov pc, r10
@ clear memory
@ r0: start address
@ r1: length mem_clear:
mov r2, #0
mov r3, r2
mov r4, r2
mov r5, r2
mov r6, r2
mov r7, r2
mov r8, r2
mov r9, r2
clear_loop:
stmia r0!, {r2-r9}
subs r1, r1, #(8 * 4)
bne clear_loop
mov pc, lr
#endif @ CONFIG_S3C2410_NAND_BOOT
*************************************************************************************************
在文件的最后加入如下,堆栈地址:
************************************************************************************************
.align 2
DW_STACK_START:
.word STACK_BASE+STACK_SIZE-4
*************************************************************************************************
c 添加nand_read_ll函数的实现在board/gec2410/建立nand_read.c,
加入如下内容(copy from vivi):
************************************************************************************************
#include <config.h>
#define __REGb(x) (*(volatile unsigned char *)(x))
#define __REGi(x) (*(volatile unsigned int *)(x))
#define NF_BASE 0x4e000000#define NFCONF __REGi(NF_BASE + 0x0)
#define NFCMD __REGb(NF_BASE + 0x4)
#define NFADDR __REGb(NF_BASE + 0x8)
#define NFDATA __REGb(NF_BASE + 0xc)
#define NFSTAT __REGb(NF_BASE + 0x10)
#define BUSY 1
inline void wait_idle(void)
{
int i;
while(!(NFSTAT & BUSY))
for(i=0; i<10; i++);
}
#define NAND_SECTOR_SIZE 512
#define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)
/* low level nand read function */
intnand_read_ll(unsigned char *buf, unsigned long start_addr, int size)
{
int i, j;
if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK))
{
return -1;
/* invalid alignment */
}
/* chip Enable */
NFCONF &= ~0x800;
for(i=0; i<10; i++);
for(i=start_addr;
i < (start_addr + size);)
{
/* READ0 */
NFCMD = 0;
/* Write Address */
NFADDR = i & 0xff;
NFADDR = (i >> 9) & 0xff;
NFADDR = (i >> 17) & 0xff;
NFADDR = (i >> 25) & 0xff;
wait_idle();
for(j=0; j < NAND_SECTOR_SIZE; j++, i++)
{
*buf = (NFDATA & 0xff);
buf++;
}
}
/* chip Disable */
NFCONF |= 0x800;
/* chip disable */
return 0;
}
修改board/gec2410/Makefile为
OBJS := gec2410.o flash.o nand_read.o
以上步骤就可以把u-boot烧写到nandflash上了
(2) 支持nand flash操作命令
a 在/include/configs/gec2410.h
文件中添加宏定义
#define CONFIG_COMMANDS添加定义
CFG_CMD_NAND
CFG_CMD_ENV
b 定义环境变量宏
#define CFG_ENV_IS_IN_FLASH 1
#define CFG_ENV_SIZE 0x10000
/* Total Size of Environment Sector */
改为
#define CFG_ENV_IS_IN_NAND 1
#define CFG_ENV_OFFSET 0x030000
#define CFG_NAND_BASE 0x4E000000
#define CMD_SAVEENV
#define CFG_NAND_LEGACY
#define CFG_ENV_SIZE 0x10000
/* Total Size of Environment Sector */
/*set env*/
#define CFG_MONITOR_BASE PHYS_SDRAM_1
c 修改common/cmd_nand.c文件,
添加nand flash初始化函数添加
#define rNFCONF (*(volatile unsigned *)0x4E000000)
#define rNFCMD (*(volatile unsigned *)0x4E000004)
#define rNFADDR (*(volatile unsigned *)0x4E000008)
#define rNFDATA (*(volatile unsigned *)0x4E00000C)
#define rNFSTAT (*(volatile unsigned *)0x4E000010)
#define rNFECC (*(volatile unsigned *)0x4E000014)
#define CFG_NAND_BASE 0x4E000000
#define CFG_MAX_NAND_DEVICE 1
/* Max number of NAND devices */
#define SECTORSIZE 512
#define ADDR_COLUMN 1
#define ADDR_PAGE 2
#define ADDR_COLUMN_PAGE 3
#define NAND_ChipID_UNKNOWN 0x00
#define NAND_MAX_FLOORS 1
#define NAND_MAX_CHIPS 1
#define NAND_WAIT_READY(nand) {while(!(rNFSTAT&(1<<0)));}
#define NAND_DISABLE_CE(nand) {rNFCONF|=(1<<11);}
#define NAND_ENABLE_CE(nand) {rNFCONF&=~(1<<11);}
#define WRITE_NAND_COMMAND(d , adr) {rNFCMD=d;}
#define WRITE_NAND_ADDRESS(d, adr) {rNFADDR=d;}
#define WRITE_NAND(d , adr) {rNFDATA=d;}
#define READ_NAND(adr) (rNFDATA)
/* the following functions are NOP's because S3C24X0 handles this in hardware */
#define NAND_CTL_CLRALE(nandptr)
#define NAND_CTL_SETALE(nandptr)
#define NAND_CTL_CLRCLE(nandptr)
#define NAND_CTL_SETCLE(nandptr)
#define CONFIG_MTD_NAND_VERIFY_WRITE 1
********************************************************************************************************
添加nand_init()函数的实现
************************************************************************************************
void nand_init(void)
{
int i;
unsigned long j;
rNFCONF=(1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(0<<8)|(3<<4)|(0<<0);
rNFCONF=rNFCONF&~(1<<11);
rNFCMD=0xff;
for(i=0;i<10;i++);
while(!(rNFSTAT&(1<<0)));
rNFCONF=rNFCONF|(1<<11);
j=nand_probe(0x4e000000);
printf(&quot;nand flash : %4lu MB\n&quot;,j>>20);
}
********************************************************************************************************
d 在nand_probe函数中添加一行
************************************************************************************************
#endif
oob_config.badblock_pos = 5;
nand_dev_desc[0].ChipID = 0x00;
uboot移植完成! |