软件环境:ubuntu 6.06 linux;arm-linux-gcc 2.95.3;u-boot1.1.4;Jflash
硬件环境:FriendArm nano2410a板,32M SDRAM HY57V561620CT-H地址范围0x30000000--0x32000000,64M Nand Flash K9S1208U0B地址范围0x00000000--0x04000000,其他的与三星的SMDK2410一样。
1、解压cross-2.95.3.tar.bz2到某个目录下,我是放在/usr/local/arm/下
#tar jxvf cross-2.95.3.tar.bz2 -C /usr/local/arm
将arm-liux-gcc 2.95.3的路径加入到环境变量中
#export /usr/local/arm/2.95.3/bin
为了在启动的时候也这么做,编辑.bashrc文件
#vi ~/.bashrc
将export /usr/local/arm/2.95.3/bin 加到最后一行。
2、测试一下make是否有错误。
#cd u-boot1.1.4
#make smdk2410_config
#make ARCH=arm
如果使用的linux版本是ubuntu6.06,或者更新了最新的ubuntu的make版本,版本号为 3.81beta4,编译时会出现
make[2]: *** No rule to make target `hello_world.srec', needed by `all'. Stop.
的错误,原因是make的版本有问题,可以用下面方法将make的版本降低到3.80
#make --version <==查看make版本
a. 首先将/etc/apt/source.list 里的 "dapper" 替换成 "breezy"
#cp /etc/apt/source.list /etc/apt/source.list.dapper
#vi /etc/apt/source.list
#apt-get update
替换的目的是使用ubuntu linux 5.10的source.list
b. 删除原来的make,使用新的仓库源安装旧版本make
#apt-get remove make <== 删除 "make 3.81beta4"
#apt-get install make <== 安装 "make 3.80" ubuntu linux 5.10的仓库源列表
#
c. 安装完之后,可以将/etc/apt/source.list 中的"breezy"换回 "dapper"
#cp /etc/apt/source.list /etc/apt/source.list.breezy
#cp /etc/apt/source.list /etc/apt/source.list
#apt-get update <== 更新apt-get
# make --version <==查看当前make版本
GNU Make 3.80
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
这样make就不会出现编译错误了。
3、在u-boot里加入我的板子。u-boot的board目录下包含了一些现有的板子,我的板子结构与SMDK2410接近,所以使用它来作模板来修改,取板子名字是random2410(可任意取)。
#mkdir board/random2410
#cp board/smdk2410/* board/random2410/
#mv board/random2410/smdk2410.c board/random2410/random2410.c
#cp include/configs/smdk2410.h include/configs/random2410.h
---修改board/random2410/Makefile,将其中的smdk2410.o为random2410.o
---修改config.mk:#define TEXT_BASE 0x33f80000 改为
#define TEXT_BASE 0x31f80000
因为SDRAM地址最大是0x32000000,这个意思是将bootloader程序写到最高地址范围0x80000的空间。
4、修改顶层Makefile,在smdk2410_config的附近添加
random2410_config : unconfig
@./mkconfig $(@:_config=) arm arm920t random2410 NULL s3c24x0
arm: CPU的架构(ARCH)
arm920t: PU的类型(CPU),其对应于cpu/arm920t子目录。
random2410: 开发板的型号(BOARD),对应于board/random2410目录。
NULL: 开发者/或经销商(vender)。
s3c24x0: 片上系统(SOC)
测试是否编译会错误,如果有错估计是那里改的有问题
#make random2410_config
#make all ARCH=arm
5、修改board/random2410/lowlevel_init.S
#define B1_BWSCON (DW32)
#define B2_BWSCON (DW16)
#define B3_BWSCON (DW16 + WAIT + UBLB)
#define B4_BWSCON (DW16)
#define B5_BWSCON (DW16)
#define B6_BWSCON (DW32) <==(DW32) 改为(DW16)
#define B7_BWSCON (DW32) <==(DW32) 改为(DW16)
这是因为我的SDRAM只有一片16位的,而不是32位的或者2片16位
其他的根据板子的结构相应修改,这个文件主要是设置几个BANK控制寄存器
6、u-boot好像没有nand flash启动的,即将程序自己复制到DRAM里面去,可以参考vivi的copy_myself代码。修改cpu/arm920t/start.S
---在 ldr pc, _start_armboot之前加入
#ifdef CONFIG_S3C2410_NAND_BOOT
bl copy_myself
@ jump to ram
ldr r1, =on_the_ram
add pc, r1, #0
nop
nop
1: b 1b @ infinite loop
on_the_ram:
#endif
--------------------------------------------------------------
---在 _start_armboot: .word 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
mov r1, #0x0
mov r2, #0x20000
bl nand_read_ll
tst r0, #0x0.align 2
DW_STACK_START:
.word STACK_BASE+STACK_SIZE-4
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
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
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_BOOTbl 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
---在最后面添加
.align 2
DW_STACK_START:
.word STACK_BASE+STACK_SIZE-4
7、上面的代码缺少nand_read_ll的实现,可以从vivi那里拷贝过来board/random2410/加入NAND Flash读函数,建立nand_read.c,加入如下内容(copy from vivi bootloader)
/*
* nand_read.c: Simple NAND read functions for booting from NAND
*
* Copyright (C) 2002 MIZI Research, Inc.
*
* Author: Hwang, Chideok
* Date : $Date: 2002/08/14 10:26:47 $
*
* $Revision: 1.6 $
* $Id: param.c,v 1.9 2002/07/11 06:17:20 nandy Exp
*
*
*/
#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;
.align 2
DW_STACK_START:
.word STACK_BASE+STACK_SIZE-4
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/random2410/Makefile,加入nand_read.o
8、修改include/configs/random2410.h文件,在前面添加如下内容
/*
* Nandflash Boot
*/
#define CONFIG_S3C2410_NAND_BOOT 1
#define STACK_BASE 0x31f00000
#define STACK_SIZE 0x8000
#define UBOOT_RAM_BASE 0x31f80000
/* 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
---该文件的其他跟内存有关的信息相应修改:
#define CFG_MEMTEST_END 0x31F00000 /* 32 MB in DRAM */
#define CFG_LOAD_ADDR 0x31000000 /* default load address */
#define PHYS_SDRAM_1_SIZE 0x02000000 /* 32 MB */
---更改启动后提示字母:
#define CFG_PROMPT "random2410 # " /* Monitor Command Prompt */
---更改网络设置
#define CONFIG_ETHADDR 08:00:3e:26:0a:5b
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_IPADDR 192.168.1.110
#define CONFIG_SERVERIP 192.168.1.1
9、重新编译
#make all ARCH=arm
如果出错,请重新认真读前面的每一个细节。
10、将生成的u-boot.bin文件,用Jflash通过JTAG下载到板子,运行minicom,复位,将显示下面的信息:
U-Boot 1.1.4 (Sep 12 2006 - 02:06:04)
U-Boot code: 31F80000 -> 31F98998 BSS: -> 31F9CA70
RAM Configuration:
Bank #0: 30000000 32 MB
Flash: 512 kB
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
random2410 #
就可以使用u-boot的命令了。
下一步是移植linux 2.6.16的内核......
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/random263/archive/2006/09/12/1214981.aspx