难得五一没安排,闲着无聊,移植u-boot-2012.10到TQ2440,与大家分享。往往移植u-boot或做裸板开发,有诸多不便,电脑没有并口也没有openjtag,大多数人都望而止步,也不忍心破坏新买板子的系统。我想到一种方法,电脑没有并口,没有openjtag照样能做裸板开发,也能移植u-boot。一般新买的s3c2440开发板,出厂前NOR Flash已烧好u-boot,并且支持NAND、NOR Flash、DM9000等外设。可以这样做,NOR Falsh启动将出厂u-boot也烧到NAND,确保擦除一个还有一个u-boot。裸板开发时,NOR Flash启动,烧写裸板程序到NAND,再NAND启动调试自己的裸板程序;移植u-boot 时,NOR Flash启动,烧写移植的u-boot到NAND调试,最后调试OK后,再用NOR Flash启动u-boot烧到NOR Flash。言归正传,开始移植u-boot-2012.10
开发环境:
系统:ubuntu 10.04.4
单板:tq2440
NAND FLASH:K9F1216U0A 256MB
NOR Flash:AM29LV160A 2MB
SDRAM:HY57V561620 x2 64MB
NET:DM9000AEP
编译器:arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
搭建开发环境详见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.10.tar.bz2,解压到工作目录即可。
获取交叉编译链 http://code.google.com/p/smp-on-qemu/downloads/list 选择arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2并下载。然后在ubuntu下直接解压即可,还要配置环境变量
sudo gedit /etc/environment// 修改PATH,在最后再加“:/.../arm-2009q3/bin”,其中“...”是上面arm-2009q3-67-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2解压的路径。接着Log Out ubuntu系统,就可以直接使用交叉编译链。
二、新建单板
change@change:~$ cd Si/TQ2440/u-boot-2012.10/
change@change:~/Si/TQ2440/u-boot-2012.10$ cp board/samsung/smdk2410 board/samsung/TQ2440 -rf
change@change:~/Si/TQ2440/u-boot-2012.10$ cp include/configs/smdk2410.h include/configs/TQ2440.h
change@change:~/Si/TQ2440/u-boot-2012.10$ vim boards.cfg
72:增加如下内容
TQ2440 arm arm920t - samsung s3c24x0
三、配置·、编译
change@change:~/Si/TQ2440/u-boot-2012.10$ make TQ2440 CROSS_COMPILE=arm-none-linux-gnueabi-
arm-none-linux-gnueabi-objcopy -O srec u-boot u-boot.srec
arm-none-linux-gnueabi-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin
最终生成u-boot.bin文件,但是现在还不能用,需要修改源码支持单板TQ2440
四、修改代码,支持串口正常输出
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/smdk2410.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.10$ make TQ2440 CROSS_COMPILE=arm-none-linux-gnueabi-
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[2]: *** [s3c2410_nand.o] Error 1
果然出现错误,这样先解决串口问题,把NAND部分屏蔽掉再说drivers/mtd/nand/Makefile:
COBJS-$(CONFIG_NAND_S3C2410) += s3c2410_nand.o //不定义宏CONFIG_NAND_S3C2410即可
接着找到include/configs/TQ2440.h:193
#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:100//#define CONFIG_CMD_NAND
include/config_cmd_all.j62://#define CONFIG_CMD_NAND /* NAND support */
我也是编译几次,发现nand还是编译进去了报错,修改完继续编译
change@change:~/Si/TQ2440/u-boot-2012.10$ make TQ2440 CROSS_COMPILE=arm-none-linux-gnueabi-
yaffs_uboot_glue.c: In function 'cmd_yaffs_devconfig':
yaffs_uboot_glue.c:181: error: 'CONFIG_SYS_MAX_NAND_DEVICE' undeclared (first use in this function)
yaffs_uboot_glue.c:181: error: (Each undeclared identifier is reported only once
yaffs_uboot_glue.c:181: error: for each function it appears in.)
make[2]: *** [yaffs_uboot_glue.o] Error 1
直接屏蔽掉yaffs
include/configs/TQ2440.h:210//#define CONFIG_YAFFS2
记得编译之前要make distclean下,不然修改没生效,还是报错,就这个小问题,害我重编译好多次。
change@change:~/Si/TQ2440/u-boot-2012.10$ make distclean
change@change:~/Si/TQ2440/u-boot-2012.10$ make TQ2440 CROSS_COMPILE=arm-none-linux-gnueabi-
arm-none-linux-gnueabi-objcopy -O srec u-boot u-boot.srec
arm-none-linux-gnueabi-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin
最终编译通过,此时生成的u-boot.bin,烧进NOR Flash,串口输出正常。下一阶段移植u-boot支持NAND启动。