開發環境:
系統:ubuntu 10.04.4
單板:tq2440
NAND FLASH:K9F1216U0A 256MB
NOR Flash:EN29LV160AB 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啓動。
http://blog.csdn.net/u010216127/article/details/8877182