开发环境:
系统:ubuntu 10.04.4
单板:tq2440
NAND FLASH:K9F1216U0A 256MB
NOR Flash:AM29LV160A 2MB
SDRAM:HY57V561620 x2 64MB
NET:DM9000AEP
编译器:arm-linux-gcc-4.3.2
搭建开发环境详见ubuntu 10.04.4开发环境配置。
目标:
1.支持NOR Flash启动,串口正常输出
2.支持NAND启动
3.支持DM9000网卡
4.添加u-boot菜单
5.u-boot裁剪及制作补丁
一、获取源代码
ftp://ftp.denx.de/pub/u-boot/ 下载u-boot-2012.04.01.tar.bz2,解压到工作目录即可。交叉编译链arm-linux-gcc-4.3.2.tar.bz2到处都是,配置见ubuntu 10.04.4开发环境配置。
change@change:~$ cd Si/
change@change:~/Si$ ls
A10 OK6410 u-boot-1.1.6.tar.bz2
A13 pcduino u-boot-2012.04.01.tar.bz2
gcc-linaro-arm-linux-gnueabihf-4.8-2013.04-20130417_linux.tar.bz2 s3c2440 u-boot-2012.10.tar.bz2
jz4755 s5pc100
micro2440 TQ2440
change@change:~/Si$ tar xjf u-boot-2012.04.01.tar.bz2 -C TQ2440/
change@change:~/Si$ cd TQ2440/u-boot-2012.04.01/
方便移植,新建Source Insighe工程,阅读源码,工程添加源码是,以下未用文件可以不添加
board/samsung下除 smdk2410 以外的所有其它目标板文件夹不添加
arch/arm/cpu/下除 arm920t 、u-boot.lds以外的所有其它cpu目录不添加
include/目录下arm-XXX 的文件目录,只留下 asm-arm ,其它arm-XXX 不添加
include/configs 目录下除 smdk2410.h 以外的所有其它配置头文件不添加
二、新建单板
change@change:~/Si/TQ2440/u-boot-2012.04.01$ cp -rf board/samsung/smdk2410/ board/samsung/TQ2440
change@change:~/Si/TQ2440/u-boot-2012.04.01$ mv board/samsung/TQ2440/smdk2410.c board/samsung/TQ2440/TQ2440.c
修改board/samsung/TQ2440/Makefile文件中28行的COBJS改为:
COBJS := TQ2440.o
change@change:~/Si/TQ2440/u-boot-2012.04.01$ cp include/configs/smdk2410.h include/configs/TQ2440.h
change@change:~/Si/TQ2440/u-boot-2012.04.01$ vim boards.cfg
72:增加如下内容
TQ2440 arm arm920t - samsung s3c24x0
三、配置、编译change@change:~/Si/TQ2440/u-boot-2012.04.01$ make TQ2440_config
Configuring for TQ2440 board...
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make
arm-linux-objcopy -O srec hello_world hello_world.srec 2>/dev/null
arm-linux-objcopy -O binary hello_world hello_world.bin 2>/dev/null
make[1]: Leaving directory `/home/change/Si/TQ2440/u-boot-2012.04.01/examples/standalone'
make -C examples/api all
make[1]: Entering directory `/home/change/Si/TQ2440/u-boot-2012.04.01/examples/api'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/change/Si/TQ2440/u-boot-2012.04.01/examples/api'
编译成功,此时还不支持单板,需要修改代码。
四、修改代码,支持串口正常输出
1.修改时钟配置
arch/arm/cpu/arm920t/start.S:170,去掉以前的时钟配置,参考update程序改成自己的代码
/* FCLK:HCLK:PCLK = 1:2:4 */
/* default FCLK is 120 MHz ! */
// ldr r0, =CLKDIVN
// mov r1, #3
// str r1, [r0]
增加如下代码175:
#define S3C2440_MPLL_400MHZ ((0x5c<<12)|(0x01<<4)|(0x01))
/* 2. 设置时钟 */
ldr r0, =0x4c000014
// mov r1, #0x03; // FCLK:HCLK:PCLK=1:2:4, HDIVN=1,PDIVN=1
mov r1, #0x05; // FCLK:HCLK:PCLK=1:4:8
str r1, [r0]
/* 如果HDIVN非0,CPU的总线模蔦u0153覾u0160\u017e肻u017d印癴ast bus mode”变为“asynchronous bus mode” */
mrc p15, 0, r1, c1, c0, 0 /* 读出控制\u0152腬u017d嫫?*/
orr r1, r1, #0xc0000000 /* 设置为“asynchronous bus mode” */
mcr p15, 0, r1, c1, c0, 0 /* 衆u017d入控制\u0152腬u017d嫫?*/
/* MPLLCON = S3C2440_MPLL_200MHZ */
ldr r0, =0x4c000004
ldr r1, =S3C2440_MPLL_400MHZ
str r1, [r0]
/* 启动ICACHE */
mrc p15, 0, r0, c1, c0, 0 @ read control reg
orr r0, r0, #(1<<12)
mcr p15, 0, r0, c1, c0, 0 @ write it back
在board/samsung/TQ2440/TQ2440.c去掉对时钟MPLL的配置76:
/* to reduce PLL lock time, adjust the LOCKTIME register */
//writel(0xFFFFFF, &clk_power->locktime);
/* configure MPLL */
//writel((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV,
// &clk_power->mpllcon);
2.修改SDRAM设置代码
同样参考update程序,改成自己的SDRAM初始化程序board/samsung/TQ2440/lowlevel_init.S:154的SMRDATA替换成如下代码:
SMRDATA:
.long 0x22011110 //BWSCON
.long 0x00000700 //BANKCON0
.long 0x00000700 //BANKCON1
.long 0x00000700 //BANKCON2
.long 0x00000700 //BANKCON3
//.long 0x00000700 //BANKCON4
.long 0x00000740 //BANKCON4
.long 0x00000700 //BANKCON5
.long 0x00018005 //BANKCON6
.long 0x00018005 //BANKCON7
.long 0x008C04F4 // REFRESH
.long 0x000000B1 //BANKSIZE
.long 0x00000030 //MRSRB6
.long 0x00000030 //MRSRB7
3.修改串口波特率设置
arch/arm/cpu/arm920t/s3c24x0/speed.c 发现82:get_HCLK(void)里支持CONFIG_S3C2440,解决方法如下:
include/configs/TQ2440.h:38
//#define CONFIG_S3C2410 /* specifically a SAMSUNG S3C2410 SoC */
#define CONFIG_S3C2440 /* specifically a SAMSUNG S3C2410 SoC */
再配置编译看看,有问题也可以及时修改
change@change:~/Si/TQ2440/u-boot-2012.04.01$make distclean
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make TQ2440_config
Configuring for TQ2440 board...
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make
s3c2410_nand.c: In function 's3c2410_hwcontrol':
s3c2410_nand.c:57: warning: implicit declaration of function 's3c2410_get_base_nand'
s3c2410_nand.c:57: warning: initialization makes pointer from integer without a cast
s3c2410_nand.c:72: error: dereferencing pointer to incomplete type
s3c2410_nand.c:72: error: dereferencing pointer to incomplete type
s3c2410_nand.c:75: error: dereferencing pointer to incomplete type
s3c2410_nand.c:75: error: dereferencing pointer to incomplete type
s3c2410_nand.c: In function 's3c2410_dev_ready':
s3c2410_nand.c:85: warning: initialization makes pointer from integer without a cast
s3c2410_nand.c:87: error: dereferencing pointer to incomplete type
s3c2410_nand.c: In function 'board_nand_init':
s3c2410_nand.c:129: warning: initialization makes pointer from integer without a cast
s3c2410_nand.c:150: error: dereferencing pointer to incomplete type
s3c2410_nand.c:153: error: dereferencing pointer to incomplete type
s3c2410_nand.c:154: error: dereferencing pointer to incomplete type
make[1]: *** [s3c2410_nand.o] Error 1
make[1]: Leaving directory `/home/change/Si/TQ2440/u-boot-2012.04.01/drivers/mtd/nand'
make: *** [drivers/mtd/nand/libnand.o] Error 2
果然出现错误,这样先解决串口问题,把NAND部分屏蔽掉再说drivers/mtd/nand/Makefile:42
COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o //不定义宏CONFIG_NAND_S3C2410即可
接着找到include/configs/TQ2440.h:210
#ifdef CONFIG_CMD_NAND
#define CONFIG_NAND_S3C2410
#define CONFIG_SYS_S3C2410_NAND_HWECC
#define CONFIG_SYS_MAX_NAND_DEVICE 1
#define CONFIG_SYS_NAND_BASE 0x4E000000
#endif
屏蔽CONFIG_CMD_NAND即可,注意去掉2处宏定义,
include/configs/TQ2440.h:102//#define CONFIG_CMD_NAND
include/config_cmd_all.j64://#define CONFIG_CMD_NAND /* NAND support */
我也是编译几次,发现nand还是编译进去了报错,修改完继续编译
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make distclean
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make TQ2440_config
Configuring for TQ2440 board...
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make
fs/yaffs2/libyaffs2.o: In function `yaffs_StartUp':
/home/change/Si/TQ2440/u-boot-2012.04.01/fs/yaffs2/yaffscfg.c:210: undefined reference to `nand_info'
make: *** [u-boot] Error 1
直接屏蔽掉yaffs
include/configs/TQ2440.h:227//#define CONFIG_YAFFS2
记得编译之前要make distclean下,不然修改没生效,还是报错,就这个小问题,害我重编译好多次。
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make distcleanGenerating include/autoconf.mk
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make TQ2440_config
Configuring for TQ2440 board...
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make
OK编译通过,此时生成的u-boot.bin,烧进NOR Flash,串口一个输出正常。下一阶段移植u-boot支持NAND启动。