|
creator [email protected]
我的2440开发板没有norflash,是从nand引导的,但是扬创不提供U-BOOT的源代码,
所以决定移植一个,但是一直因为没有一个很好的调试方法。一直没有完成。最近看到
skyeye支持nand启动,同时支持u-boot。随决定移植一下,目前初期阶段是移植2410的
版本,ok之后再移植2440的版本。
我上一篇《在cygwin下面用skyeye调试u-boot》有写u-boot需要下载1.1.4版本或
1.1.2版本的。我采用的是1.1.4版本。主要修改如下几个地方:
以下参考(U-BOOT FOR 阳初2410 v2.3 BY wmmwang 8/29/2007),我本来写了
,是直接copy 2440的,我以为一样的,结果吃了大亏,nand寄存器不一样,搞的我很烦,
怪自己啊。
1、 在cpu/arm920t/start.s中修改如下:
#define STACK_BASE 0x33f00000
#define STACK_SIZE 0x8000
DW_STACK_START:
.word STACK_BASE+STACK_SIZE-4
#ifndef CONFIG_SKIP_RELOCATE_UBOOT
relocate: /* relocate U-Boot to RAM */
adr r0, _start /* r0 <- current position of code */
ldr r1, _TEXT_BASE /* test if we run from flash or RAM */
cmp r0, r1 /* don't reloc during debug */
beq stack_setup
@ ldr r2, _armboot_start
@ ldr r3, _bss_start
@ sub r2, r3, r2 /* r2 <- size of armboot */
@ add r2, r0, r2 /* r2 <- source end address */
@copy_loop:
@ ldmia r0!, {r3-r10} /* copy from source address [r0] */
@ stmia r1!, {r3-r10} /* copy to target address [r1] */
@ cmp r0, r2 /* until source end addreee [r2] */
@ ble copy_loop
#ifdef CONFIG_S3C2410_NAND_BOOT
bl copy_myself
#endif /*CONFIG_S3C2410_NAND_BOOT*/
#endif /*CONFIG_SKIP_RELOCATE_UBOOT*/
……
……
……
/**************************************************************************
*
* copy u-boot to ram
*
*************************************************************************
*/
#ifdef CONFIG_S3C2410_NAND_BOOT
@
@ copy_myself: copy u-boot to ram
@
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
ldr sp, DW_STACK_START @ setup stack pointer
mov fp, #0 @ no previous frame, so fp=0
@ copy UBOOT to RAM
ldr r0, _TEXT_BASE
mov r1, #0x0
mov r2, #0x20000
bl nand_read_ll
teq r0, #0x0
beq ok_nand_read
bad_nand_read:
1: b 1b @ infinite loop
ok_nand_read:
@ verify
mov r0, #0
ldr r1, _TEXT_BASE
mov r2, #0x400 @ 4 bytes * 1024 = 4K-bytes
go_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:
1: b 1b
done_nand_read:
mov pc, r10
#endif
@ CONFIG_S3C2440_NAND_BOOT
3、 在board/smdk2410/中添加nand_read.c文件:
#include <config.h>
#include "linux/mtd/mtd.h"
#include "linux/mtd/nand.h"
//#define LARGEPAGE_FLASH
#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 + 0x
#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++);
}
#ifndef LARGEPAGE_FLASH
#define NAND_SECTOR_SIZE 512
#else
#define NAND_SECTOR_SIZE 2048
#endif
#define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)
/* low level nand read function */
int
nand_read_ll(unsigned char *buf, unsigned long start_addr, int size)
{
int i, j;
if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)){
//if ((start_addr & NAND_BLOCK_MASK) /*|| (size > SZ_1M)*/) {
return -1; /* invalid alignment */
}
/* chip Enable */
NFCONF &= ~0x800;
for(i=0; i<10; i++);
for(i=start_addr; i < (start_addr + size);) {
/* READ0 */
NFCMD = NAND_CMD_READ0;
/* Write Address */
#ifndef LARGEPAGE_FLASH
NFADDR = i & 0xff;
NFADDR = (i >> 9) & 0xff;
NFADDR = (i >> 17) & 0xff;
NFADDR = (i >> 25) & 0xff;
#else
NFADDR = i & 0xff;
NFADDR = (i >> & 0x07;
NFADDR = (i >> 11) & 0xff;
NFADDR = (i >> 19) & 0xff;
NFADDR = (i >> 27) & 0x3;
NFCMD = NAND_CMD_READSTART;
#endif
wait_idle();
for(j=0; j < NAND_SECTOR_SIZE; j++) {
*buf = (NFDATA & 0xff);
buf++;
}
i += NAND_SECTOR_SIZE;
}
/* chip Disable */
NFCONF |= 0x800; /* chip disable */
return 0;
}
4、 修改board/smdk2410/Makefile:
COBJS := smdk2410.o flash.o nand_read.o //添加nand_read.o
编译就可以了。
以下是采用skyeye进行调试。
首先是生成nand.dump文件。
在skyeye-1.2.4\device\nandflash\tools下面有个mknandflashdump.c。
在cygwin下面编译 gcc mknandflashdump.c 生成a.exe
copy 刚才生成的u-boot.bin
执行./a.exe u-boot.bin nand.dump 0x0
就生成了nand.dump了。
修改skyeye.conf文件:
# skyeye config file for S3C2410X
cpu: arm920t
mach: s3c2410x
# physical memory
mem_bank: map=M, type=RW, addr=0x00000000, size=0x00004000, file=./u-boot.bin,boot=yes
mem_bank: map=M, type=RW, addr=0x30000000, size=0x04000000
#mem_bank: map=M, type=RW, addr=0xC0000000, size=0x04000000,file=./vmlinux
#mem_bank: map=M, type=RW, addr=0x30000000, size=0x03F80000
#mem_bank: map=M, type=RW, addr=0x33F80000, size=0x00080000, file=./u-boot.bin,boot=yes
#mem_bank: map=M, type=RW, addr=0xc1000000, size=0x01000000
# all peripherals I/O mapping area
mem_bank: map=I, type=RW, addr=0x48000000, size=0x20000000
mem_bank: map=I, type=RW, addr=0x19000300, size=0x00000020
#net: type=cs8900a, base=0x19000300, size=0x20,int=9, mac=08:00:3E:26:0A:5B, ethmod=tuntap, hostip=10.0.0.1
nandflash: type=s3c2410x,name=K9F1208U0B,dump=./nand.dump
#lcd: type=s3c2410x, mod=gtk
dbct:state=on
cygwin下面输入:skyeye 就ok。
注:我在copy_myself之后有个验证一直不通过,目前还在测试中。
后续我再改改
下一步:
移植到2440中,目前好像skyeye不支持2440 nand启动,看是否可以修改一下skyeye。
再下一步:
移植ecos到2440,当然也是在skyeye模拟、
先用skyeye模拟。
发现skyeye真是个好软件,特别是在bootloader移植和操作系统移植。 |
|