作者:reille
本博客网址:http://blog.csdn.net/reille/
开发环境:主机:Window XP SP2;linux:VMware7.01+ubuntu9.10;目标板:扬创utu2440-F开发板
交叉编译器:arm-linux-gcc4.3.2(一开始用的是编译内核的版本arm-linux-gcc3.4.1,但出现了软浮点问题,于是换成了现在用的版本,当然本人编译内核的时候还是用3.4.1版本)
详细描述了本人移植u-boot-2011.03到S3C2440(utu2440)的方法与步骤,同时把移植过程中遇到的问题及其解决方法记录了下来,以供参考步骤
本节详细描述:移植NAND FLASH部分,使u-boot支持从NAND FLASH启动和读写
——————————————————————————————————————————————————————————————————
1. u-boot的NAND FLASH部分移植准备
移植u-boot的NAND FLASH部分特别是支持u-boot从NAND FLASH启动部分,需要做一些相关准备。主要是:
1.1 掌握u-boot启动第一阶段的调试方法
详见我的博客关于使用AXD和JLINK调试u-boot:http://blog.csdn.net/reille/archive/2011/06/26/6568756.aspx,以及参考 A.5所指的参考资料
1.2 挂机(即烧写自己移植的u-boot到NAND FLASH后启动不起来)了怎么办?
详见我的博客关于使用JLINK间接烧写u-boot的方法与步骤:http://blog.csdn.net/reille/archive/2011/06/26/6568656.aspx
1.3 从Nand Flash启动U-BOOT的基本原理
1.3.1 前4K的问题
如果S3C2440被配置成从Nand Flash启动(配置由硬件工程师在电路板设置), S3C2440的Nand Flash控制器有一个特殊的功能,在S3C2440上电后,Nand Flash控制器会自动的把Nand Flash上的前4K数据搬移到4K内部RAM中,并把0x00000000设置内部RAM的起始地址,CPU从内部RAM的0x00000000位置开 始启动。这个过程不需要程序干涉。程序员需要完成的工作,是把最核心的启动程序放在Nand Flash的前4K中。
1.3.2 启动程序的安排
由于Nand Flash控制器从Nand Flash中搬移到内部RAM的代码是有限的,所以在启动代码的前4K里,我们必须完成S3C2410的核心配置以及把启动代码(U-BOOT)剩余部分搬到RAM中运行。u-boot源码不支持从nand flash启动,可是s3c2410支持从nand flash启动,加电后s3c2440将nand flash的前4k(保存有u-boot的部分功能--拷贝功能--把nand flash中的内容拷贝到SDRAM)拷贝到sram(s3c2440芯片内的sram)。这就需要修改u-boot源码,增加u-boot的功能: 使u-boot在得到执行权后能够将其自身拷贝到开发板上SDRAM中,以便处理器能够执行u-boot
2. u-boot的NAND FLASH部分移植
以下的操作是经过整理的,详细过程见A.1.1所列出的网址
注意,如果u-boot要在SDRAM中调试,得把u-boot-2011.03/include/configs/reille2440.h文件中的宏定义CONFIG_SKIP_LOWLEVEL_INIT开启和关闭CONFIG_S3C2440_NAND_BOOT宏定义
2.1 修改u-boot-2011.03/include/configs/reille2440.h文件
2.1.1 注销如下定义:
/* del by guoyirong 2011.06.19
#define CONFIG_ENV_IS_IN_FLASH 1
#define CONFIG_ENV_SIZE 0x10000 // Total Size of Environment Sector
*/
2.1.2 reille2440.h文件末增加如下定义:
2.1.3 注释CONFIG_SKIP_LOWLEVEL_INIT
//#define CONFIG_SKIP_LOWLEVEL_INIT
2.2 增加从NAND FLASH读取数据到内存的函数,文件名为nand_read.c,放到board/samsung/reille2440/nand_read.c下
nand_read.c文件内容如下:
2.3 修改cmd_bootm.c文件
a)把81和82行注释掉,如下:
// abort NOR FLASH |del by guoyirong 2011.06.25
//#include <mtd/cfi_flash.h>
//extern flash_info_t flash_info[]; /* info for FLASH chips */
b)把函数int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])整体注释掉,改为如下:
int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]){return (0);}
做一步是因为要去掉NOR FLASH支持(如果不去掉,则arch/arm/lib/libarm.o被连接到了4K之外,4K之内没有这个程序libarm是不可能实现NAND启动的),但去掉后,在这里会出现编译错误,如下所示:
In file included from cmd_bootm.c:80:
/home/reille/work/u-boot-2011.03/include/mtd/cfi_flash.h:174: error: expected ')' before '*' token
cmd_bootm.c:81: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'flash_info'
cmd_bootm.c: In function 'do_imls':
cmd_bootm.c:1145: error: 'flash_info_t' undeclared (first use in this function)
cmd_bootm.c:1145: error: (Each undeclared identifier is reported only once
cmd_bootm.c:1145: error: for each function it appears in.)
cmd_bootm.c:1145: error: 'info' undeclared (first use in this function)
cmd_bootm.c:1149: error: 'flash_info' undeclared (first use in this function)
cmd_bootm.c:1152: error: 'FLASH_UNKNOWN' undeclared (first use in this function)
make[1]: *** [cmd_bootm.o] Error 1
make[1]: Leaving directory `/home/reille/work/u-boot-2011.03/common'
make: *** [common/libcommon.o] Error 2
reille@ubuntu:~/work/u-boot-2011.03$
注释掉后就不会出现了,按理来说在u-boot-2011.03/include/configs/reille2440.h文件中去掉了宏定义CONFIG_CMD_IMLS及加上宏定义CONFIG_SYS_NO_FLASH就不会出现编译错误了,但不知道为什么没能起作用。
2.4 修改board/samsung/reille2440/makefile
#del by guoyirong 2011.06.25
#COBJS := reille2440.o flash.o nand_read.o
# no nor flash |add by guoyirong 2011.06.25
COBJS := reille2440.o nand_read.o
注意,不再有NOR FLASH了,因此去掉flash.o
2.5 drivers/mtd/nand/目录下新建s3c2440_nand.c文件实现对NAND FLASH的操作
2.5.1 s3c2440_nand.c文件内容如下:
2.5.2 在drivers/mtd/nand/Makefile文件中添加s3c2440_nand.c的编译项
COBJS-$(CONFIG_NAND_S3C2440) += s3c2440_nand.o
2.6 修改start.S文件
2.7 修改arch/arm/cpu/arm920t/u-boot.lds
.text :
{
arch/arm/cpu/arm920t/start.o (.text)
board/samsung/reille2440/libreille2440.o (.text)
*(.text)
}
2.8 修改修改/arch/arm/lib/board.c
a)修改一:board_init_f()函数
bd_t *bd;
init_fnc_t **init_fnc_ptr;
gd_t *id;
ulong addr, addr_sp;
/* Pointer is writable since we allocated a register for it */
gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);
/* compiler optimization barrier needed for GCC >= 3.4 */
__asm__ __volatile__("": : :"memory");
memset ((void*)gd, 0, sizeof (gd_t));
// gd->mon_len = _bss_end_ofs; // del by guoyirong 2011.06.25
/* 增加此句以保证与配置的一致性add by guoyirong 2011.06.25
* 具体原因请查看代码中对此变量的使用即可明白,注意我们的 _TEXT_BASE=0x33f80000
*/
gd->mon_len = 0x700000;
b)修改二:board_init_f()函数
gd->relocaddr = addr;
gd->start_addr_sp = addr_sp;
gd->reloc_off = addr - _TEXT_BASE;
debug ("relocation Offset is: %08lx/n", gd->reloc_off);
memcpy (id, (void *)gd, sizeof (gd_t));
__asm__ __volatile__("mov sp,%0"::"r"(addr_sp):"sp"); // added by guoyirong 2011.06.25
// add by guoyirong 2011.06.25
#ifdef CONFIG_S3C2440_NAND_BOOT
board_init_r(id, addr);
#else
relocate_code (addr_sp, id, addr);
/* NOTREACHED - relocate_code() does not return */
#endif
c)修改三:board_init_r()函数
debug ("Now running in RAM - U-Boot at: %08lx/n", dest_addr);
// u-boot启动时的输出版本信息 added by guoyirong 2011.06.25
display_banner();
display_dram_config();
2.9 修改board/samsung/reille2440/config.mk
# tftp debug added by guoyirong 2011.06.11
#CONFIG_SYS_TEXT_BASE = 0x33000000
CONFIG_SYS_TEXT_BASE = 0x33F80000
至此,该修改该移植的部分都完成了,重新编译,然后下载到NAND FLASH
3. 调试问题
严格按照上述的修改或者按照A.1.1网址进行修改,一般不会有问题
我在调试过程中,由于在nand_read_ll()函数中加了一句打印信息,导致不能正常启动,实际上在nand_read_ll()函数中不能加打印信息,弄得我用AXD去单步调试。
启动信息如下:
U-Boot 2011.03 (Jun 26 2011 - 02:40:58)
DRAM: 64 MiB
NAND: NAND_ECC_NONE selected by board driver. This is not recommended !!
64 MiB
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
Net: CS8900-0
[reille2440]#
A. 参考资料
A.1 u-boot的NAND FLASH部分移植:
A.1.1 http://www.linuxidc.com/Linux/2011-02/32772p4.htm
A.1.2 http://womeikongya.blog.163.com/blog/static/58599220201121352920156/
A.1.3 http://blog.csdn.net/csuwzc/archive/2011/05/30/6454256.aspx
A.2 u-boot源码中start.S汇编指令含义的详细解释
http://os.it168.com/a2009/0629/994/000000994561.shtml
A.3 使用JLink间接烧写S3C2410、S3C2440开发板Nor、Nand Flash的方法
http://www.ourdev.cn/bbs/bbs_content_all.jsp?bbs_sn=3228953
A.4 U-Boot调试环境搭建请教~~如何实现u-boot和内核的源码级调试
http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=3521744&bbs_page_no=1&bbs_id=1032
A.5 如何调试uboot中NAND FLASH 启动部分
http://blog.csdn.net/qiaoliang328/archive/2011/03/07/6229389.aspx