Chinaunix首页 | 论坛 | 博客
  • 博客访问: 306516
  • 博文数量: 75
  • 博客积分: 2710
  • 博客等级: 少校
  • 技术积分: 706
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-21 14:19
文章分类

全部博文(75)

文章存档

2011年(10)

2010年(22)

2009年(43)

我的朋友

分类: 嵌入式

2009-09-06 23:44:29

软硬件配置:S3C2410ANANDK9F1208U0B 64MCS8900A redhat9skyeye-1.2.8rc2ELDK-4.1

移植过程:(参考《基于smdk2410 开发板u-boot-1.2.0 nand flash的支持》)

一、测试我们的开发板的名字是gyh2410

cd u-boot-1.2.0
cp -rf board/smdk2410 board/gyh2410
mv board/gyh2410/smdk2410.c board/gyh2410/gyh2410.c
board/gyh2410Makefilesmdk2410.o改为gyh2410.o
cp include/configs/smdk2410.h include/configs/gyh2410.h
Makefile中添加配置项: gyh2410_config : unconfig @$(MKCONFIG) $(@:_config=) arm arm920t gyh2410 NULL s3c24x0
然后执行make gyh2410_config
make CROSS_COMPILE=arm-none-linux-gnueabi-
若没有问题,则可继续进行下面的操作。

二、NAND启动
1
、修改cpu/arm920t/start.S,实现代码搬移
#ifdef CONFIG_SKIP_RELOCATE_UBOOT
......
#endif
代码段替换为
#ifdef CONFIG_S3C2410_NAND_BOOT
bl copy_myself @
将代码从nand flash搬移到RAM中后,进入启动的第二阶段
@ jump to ram
ldr r1, =on_the_ram
add pc, r1, #0
nop
nop
1: b 1b @ infinite loop
on_the_ram:
#endif
ldr pc, _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 @
设置第一个参数:u-bootRAM中的起始地址
mov r1, #0x0 @
设置第二个参数:nand flash的起始地址
mov r2, #0x20000 @
设置第三个参数:u-boot的长度(128k)
bl nand_read_ll @
调用nand_read_ll(),此函数定义在borad/smdk2410/nand_read.c
tst r0, #0x0
beq ok_nand_read
#ifdef CONFIG_DEBUG_LL
bad_nand_read:
ldr r0, STR_FAIL
ldr r1, SerBase
bl PrintWord
1:b 1b @ infinite loop
#endif
ok_nand_read:
#ifdef CONFIG_DEBUG_LL
ldr r0, STR_OK
ldr r1, SerBase
bl PrintWord
#endif @ verify
检查搬移后的数据,如果前4k完全相同,表示搬移成功
mov r0, #0
ldr r1, =UBOOT_RAM_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:
#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 1b
done_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
_start_armboot: .word start_armboot之后加入:
 .align 2
DW_STACK_START: .word STACK_BASE+STACK_SIZE-4
2
、实现nand_read_ll函数(添加board/gyh2410/nand_read.c
#include
#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 */
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))
{ 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/gyh2410/Makefile OBJS := gyh2410.o flash.o nand_read.o
3
、增加配置(修改include/configs/gyh2410.h
添加如下内容:
/* Nandflash Boot */
#define CONFIG_S3C2410_NAND_BOOT 1 @
支持从nand flash启动
#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
4
、修改lowlevel_init.S
#define B1_BWSCON (DW32)#define B1_BWSCON (DW16)
5
、测试
make distclean
make gyh2410_config
make CROSS_COMPILE=arm-none-linux-gnueabi-
生成u-bootu-boot.bin skyeye下测试。

三、NAND命令支持
1
、打开nand命令
CFG_CMD_NAND | \ /*
打开nand flash命令 */
2
、加入NAND闪存芯片型号

/include/linux/mtd/ nand_ids.h中对如下结构体赋值进行修改:
static struct nand_flash_dev nand_flash_ids[] = {
......
{"Samsung K9F1208U0B", NAND_MFR_SAMSUNG, 0x76, 26, 0, 3, 0x4000, 0},
.......
}
3
、添加nand驱动

/drivers/nand_legacy/nand_legacy.c中加入nand_init()函数。 /*----------------------------------------------------------------------- * NAND flash basic functions
* Added by Lu Xianzi 2006.5.27
* Copied from board/mpl/vcma9/vcma9.h & vcma9.c
*/
 #if (CONFIG_SMDK2410)
#include typedef enum {
 NFCE_LOW,
NFCE_HIGH } NFCE_STATE;
static inline void NF_Conf(u16 conf) /*
控制寄存器设置
*/
 { S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
 nand->NFCONF = conf; }
static inline void NF_Cmd(u8 cmd) /*
命令寄存器传递命令
*/
{ S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); nand->NFCMD = cmd; } static inline void NF_CmdW(u8 cmd) /*
命令寄存器写操作
*/
 { NF_Cmd(cmd); udelay(1); }
static inline void NF_Addr(u8 addr) /*
地址寄存器设置
*/
{ S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); nand->NFADDR = addr; } static inline void NF_SetCE(NFCE_STATE s) /*
设置nand flash的片选信号
*/ { S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
switch (s) {
case NFCE_LOW:
nand->NFCONF &= ~(1<<11);
break;
case NFCE_HIGH:
nand->NFCONF |= (1<<11);
break; }
}
static inline void NF_WaitRB(void) /*
等待 nand flash处于 Ready状态
*/ { S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
while (!(nand->NFSTAT & (1<<0)));
 }
static inline void NF_Write(u8 data) /*
写数据操作
*/
{ S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); nand->NFDATA = data; } static inline u8 NF_Read(void) /*
读数据操作
*/
{ S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); return(nand->NFDATA); }
static inline void NF_Init_ECC(void) /*
初始化
ECC */
{ S3C2410_NAND * const nand = S3C2410_GetBase_NAND();
 nand->NFCONF |= (1<<12); }
 static inline u32 NF_Read_ECC(void) /*
读取ECC
*/
{ S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); return(nand->NFECC); }
extern ulong nand_probe(ulong physadr);
static inline void NF_Reset(void)
{ int i;
NF_SetCE(NFCE_LOW);
 NF_Cmd(0xFF); /* reset command */
 for(i = 0; i < 10; i++); /* tWB = 100ns. */
NF_WaitRB(); /* wait 200~500us; */
 NF_SetCE(NFCE_HIGH);
}
static inline void NF_Init(void)
{ #if 0 /* a little bit too optimistic */
#define TACLS 0
#define TWRPH0 3
#define TWRPH1 0
#else
#define TACLS 0
#define TWRPH0 4
#define TWRPH1 2
#endif NF_Conf((1<<15)|(0<<14)|(0<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0)); /*nand->NFCONF = (1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0); */ /* 1 1 1 1, 1 xxx, r xxx, r xxx */ /* En 512B 4step ECCR nFCE=H tACLS tWRPH0 tWRPH1 */
NF_Reset(); }
void nand_init(void)
{ S3C2410_NAND * const nand = S3C2410_GetBase_NAND(); NF_Init();
#ifdef DEBUG
printf("NAND flash probing at 0x%.8lX\n", (ulong)nand);
#endif
printf ("%4lu MB\n", nand_probe((ulong)nand) >> 20); }
#endif /* (CONFIG_SMDK2410) */
4
、配置NAND命令
/*----------------------------------------------------------------------- * NAND flash settings */
#if (CONFIG_COMMANDS & CFG_CMD_NAND)
#define CFG_NAND_LEGACY
#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) NF_WaitRB()
#define NAND_DISABLE_CE(nand) NF_SetCE(NFCE_HIGH)
#define NAND_ENABLE_CE(nand) NF_SetCE(NFCE_LOW)
#define WRITE_NAND_COMMAND(d, adr) NF_Cmd(d)
#define WRITE_NAND_COMMANDW(d, adr) NF_CmdW(d)
#define WRITE_NAND_ADDRESS(d, adr) NF_Addr(d)
#define WRITE_NAND(d, adr) NF_Write(d)
#define READ_NAND(adr) NF_Read() /* 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
//#define CONFIG_MTD_NAND_ECC_JFFS2 1
#endif /* CONFIG_COMMANDS & CFG_CMD_NAND */
5
、修改nand命令实现

common/env_nand.c中加入
int nand_legacy_erase(struct nand_chip* nand, size_t ofs, size_t len, int clean);
int nand_legacy_rw (struct nand_chip* nand, int cmd,size_t start, size_t len,size_t * retlen, u_char * buf);

extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
/* info for NAND chips, defined in drivers/nand/nand.c */
//extern nand_info_t nand_info[];
修改

//if (nand_erase(&nand_info[0], CFG_ENV_OFFSET, CFG_ENV_SIZE))

if (nand_legacy_erase(nand_dev_desc+0, CFG_ENV_OFFSET, CFG_ENV_SIZE, 0))
//ret = nand_write(&nand_info[0], CFG_ENV_OFFSET, &total, (u_char*)env_ptr);
nand_legacy_rw(nand_dev_desc+0, 0x00 | 0x02, CFG_ENV_OFFSET, CFG_ENV_SIZE, &total, (u_char*)env_ptr);

将if(ret || total != CFG_ENV_SIZE)改为if(total != CFG_ENV_SIZE),否则会出现每次都使用默认环境变量的情况。

重新编译并模拟即可实现nand命令。

四、添加ping命令
CFG_CMK_PING |\ /*
打开ping命令*/
重新编译生成即可。

注意:skyeye模拟时的net会在系统里添加一个网卡,这个网卡为虚拟的,并非实际的,也非开发板的,而是对应系统的与开发板交流的网卡(如192.168.1.1),可设开发板ipaddr=192.168.1.211,serverip=192.168.1.1此时可与开发板通信。能ping通,tftp命令和nfs命令也可用。

五、保存环境变量到NAND
#define CMD_SAVEENV
#define CFG_ENV_SIZE 0x10000 //64kB
#define CFG_ENV_OFFSET 0x40000
重新编译,即可正常保存环境变量至nand了。

六、传递内核参数
添加以下配置:
#define CONFIG_CMDLINE_TAG 1
#define CONFIG_SETUP_MEMORY_TAGS 1
#define CONFIG_INITRD_TAG 1
可以设置参数如下:
#define CONFIG_BOOTARGS “noinitrd root=/dev/mtdblock/2 mem=64M console=ttySAC0,115200 init=/linuxrc”
#define CONFIG_BOOTFILE “uImage”
#define CONFIG_BOOTCOMMAND “tftp 30008000 uImage; bootm”
重新编译,即可正常启动内核了。

阅读(1029) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~