u-boot目录的源码结构如下:
board:开发板相关目录。
common:通用的命令函数。
cpu:特定CPU架构相关目录,如arm920t。
doc:uboot的开发、使用文档。
drivers:uboot支持的设备驱动程序,比如串口,nandflash,网卡。
fs: 支持的文件系统,Uboot现在支持cramfs、fat、fdos、jffs2和registerfs。
include:头文件和开发板配置文件,configs目录下是开发板的配置文件
lib_xxxx: 与体系结构相关的库文件。如与ARM相关的库放在lib_arm中。
lib_generic:通用的库函数。
net:各种网络协议,TFTP协议、NFS协议等。
tools:uboot自带的工具。
下面我们就针对S3C2410平台u-boot的移植步骤做一下简单介绍:
1、首先下载u-boot的源码包,然后解压,进入源码包目录。
2、修改源码让u-boot支持从Nand Flash启动。
具体如下:
一、修改“u-boot-1.3.2/cpu/arm920t/start.S”文件,执行以下命令:
#gedit cpu/arm920t/start.S
(1)181行和201行前加上//,注释掉
181 //#ifdef CONFIG_AT91RM9200
201 //#endif
(2)#ifndef CONFIG_SKIP_RELOCATE_UBOOT之后加入:
#ifdef CONFIG_S3C2410_NAND_BOOT
bl copy_myself
#else
(3)“ble copy_loop”语句之后加入:
#endif
(4)“_start_armboot: .word start_armboot”语句之后加入copy_loop子程序:
/*
*************************************************************************
*
* copy u-boot to ram
*
*************************************************************************
*/
#ifdef CONFIG_S3C2410_NAND_BOOT
copy_myself:
mov r10, lr @save return address to r10
ldr sp, DW_STACK_START
mov fp, #0
bl NF_Init
ldr r0, =UBOOT_RAM_BASE
mov r1, #0x0
mov r2, #0x30000
bl nand_read_whole
tst r0, #0x0
beq ok_nand_read
1: b 1b
ok_nand_read:
mov r0, #0x00000000
ldr r1, =UBOOT_RAM_BASE
mov r2, #0x400
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:
1: b 1b
done_nand_read:
mov pc, r10
#endif
DW_STACK_START:
.word STACK_BASE+STACK_SIZE-4
二、新建“u-boot-1.3.2/ board/smdk2410/nand.c”文件
执行命令:
#gedit board/up2410/nand.c
在打开的文件里添加如下内容:
#include
#include
#include
#define TACLS 0
#define TWRPH0 3
#define TWRPH1 0
#define U32 unsigned int
extern unsigned long nand_probe(unsigned long physadr);
static void NF_Reset(void)
{
int i;
NF_nFCE_L();
NF_CMD(0xFF);
for(i=0;i<10;i++);
NF_WAITRB();
NF_nFCE_H();
}
void NF_Init(void)
{
rNFCONF=(1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0);
NF_Reset();
}
int nand_read_whole(unsigned char *buf, unsigned long start_addr, int size)
{
int i, j;
if((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK))
return 1;
NF_nFCE_L();
for(i=0; i<10; i++);
i = start_addr;
while(i < start_addr + size) {
rNFCMD = 0;
rNFADDR = i & 0xff;
rNFADDR = (i >> 9) & 0xff;
rNFADDR = (i >> 17) & 0xff;
rNFADDR = (i >> 25) & 0xff;
NF_WAITRB();
for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {
*buf = (rNFDATA & 0xff);
buf++;
}
}
NF_nFCE_H();
return 0;
}
三、修改“u-boot-1.3.2/board/smdk2410/Makefile”文件
执行命令:
#gedit board/smdk2410/Makefile
将“COBJS:= smdk2410.o flash.o”改为“COBJS:=smdk2410.o flash.o nand.o”
四、修改“u-boot-1.3.2/include/configs/smdk2410.h”文件
执行命令:
#gedit include/configs/smdk2410.h
在文件的最后一个#endif的前面添加如下内容:
#define CONFIG_S3C2410_NAND_BOOT 1
#define STACK_BASE 0x33f00000
#define STACK_SIZE 0x8000
#define UBOOT_RAM_BASE 0x33f80000
#define CFG_NAND_BASE 0x4E000000
#define CFG_MAX_NAND_DEVICE 1
#define SECTORSIZE 512
#define NAND_SECTOR_SIZE SECTORSIZE
#define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)
#define ADDR_COLUMN 1
#define ADDR_PAGE 2
#define ADDR_COLUMN_PAGE 3
#define NAND_ChipID_UNKNOWN 0x00
#define NAND_MAX_FLOORS 1
#define NAND_MAX_CHIPS 1
#define WRITE_NAND_COMMAND(d, adr) do {rNFCMD = d;} while(0)
#define WRITE_NAND_ADDRESS(d, adr) do {rNFADDR = d;} while(0)
#define WRITE_NAND(d, adr) do {rNFDATA = d;} while(0)
#define READ_NAND(adr) (rNFDATA)
#define NAND_WAIT_READY(nand) {while(!(rNFSTAT&(1<<0)));}
#define NAND_DISABLE_CE(nand) {rNFCONF |= (1<<11);}
#define NAND_ENABLE_CE(nand) {rNFCONF &= ~(1<<11);}
#define NAND_CTL_CLRALE(nandptr)
#define NAND_CTL_SETALE(nandptr)
#define NAND_CTL_CLRCLE(nandptr)
#define NAND_CTL_SETCLE(nandptr)
#define CONFIG_MTD_NAND_VERIFY_WRITE 1
#define rNFCONF (*(volatile unsigned int *)0x4e000000)
#define rNFCMD (*(volatile unsigned char *)0x4e000004)
#define rNFADDR (*(volatile unsigned char *)0x4e000008)
#define rNFDATA (*(volatile unsigned char *)0x4e00000c)
#define rNFSTAT (*(volatile unsigned int *)0x4e000010)
#define rNFECC (*(volatile unsigned int *)0x4e000014)
#define rNFECC0 (*(volatile unsigned char *)0x4e000014)
#define rNFECC1 (*(volatile unsigned char *)0x4e000015)
#define rNFECC2 (*(volatile unsigned char *)0x4e000016)
#define NF_CMD(cmd) {rNFCMD=cmd;}
#define NF_ADDR(addr) {rNFADDR=addr;}
#define NF_nFCE_L() {rNFCONF&=~(1<<11);}
#define NF_nFCE_H() {rNFCONF|=(1<<11);}
#define NF_RSTECC() {rNFCONF|=(1<<12);}
#define NF_RDDATA() (rNFDATA)
#define NF_WRDATA(data) {rNFDATA=data;}
#define NF_WAITRB() {while(!(rNFSTAT&(1<<0)));}
3、使u-boot支持dm9000网卡
步骤如下:
一、将dm9000x.h和dm9000x.c两个文件拷贝到drivers/net/下。
二、2. 修改“u-boot-1.3.2/include/configs/smdk2410.h”文件
执行命令:
#gedit include/configs/smdk2410.h
(1)将原网卡“CS8900”改为“DM9000”
(2)添加网络命令
(3)修改IP地址
(4)修改命令提示符
(5)修改默认下载地址
(6)修改环境变量在Nand Flash中的存储地址
具体如下:
(1)将原网卡“CS8900”改为“DM9000”
注释掉:
// #define CONFIG_DRIVER_CS8900 1 /* we have a CS8900 on-board */
// #define CS8900_BASE 0x19000300
// #define CS8900_BUS16 1 /* the Linux driver does accesses as shorts */
这3行之后添加:
#define CONFIG_DRIVER_DM9000 1
#define CONFIG_DRIVER_DM9000_BASE 0x10000000
#define DM9000_IO CONFIG_DM9000_BASE
#define DM9000_DATA (DM9000_IO + 2)
#define CONFIG_DM9000_USE_16BIT
(2)添加网络命令
找到下面的几行:
#define CONFIG_CMD_CACHE
#define CONFIG_CMD_DATE
#define CONFIG_CMD_ELF
在其下面添加下面几行:
#define CONFIG_CMD_REGINFO
#define CONFIG_CMD_NAND
#define CONFIG_CMD_PING
#define CONFIG_CMD_DLF
#define CONFIG_CMD_ENV
#define CONFIG_CMD_NET
(3)修改IP地址
找到下面几行:
#define CONFIG_BOOTDELAY 3
/*#define CONFIG_BOOTARGS "root=ramfs devfs=mount console=ttySA0,9600" */
/*#define CONFIG_ETHADDR 08:00:3e:26:0a:5b */
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_IPADDR 10.0.0.110
#define CONFIG_SERVERIP 10.0.0.1
/*#define CONFIG_BOOTFILE "elinos-lart" */
/*#define CONFIG_BOOTCOMMAND "tftp; bootm" */
修改为:
#define CONFIG_BOOTDELAY 3
#define CONFIG_BOOTARGS "root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200"
#define CONFIG_ETHADDR 08:00:3e:26:0a:5b
#define CONFIG_NETMASK 255.255.255.0
#define CONFIG_IPADDR 192.168.1.13
#define CONFIG_SERVERIP 192.168.1.12
#define CONFIG_BOOTFILE "uImage"
#define CONFIG_BOOTCOMMAND "tftp; bootm"
#define CONFIG_CMDLINE_TAG 1
#define CONFIG_SETUP_MEMORY_TAGS 1
#define CONFIG_INITRD_TAG 1
(4)修改命令提示符
找到下面一行:
#define CFG_PROMPT "SMDK2410 # "
修改为:
#define CFG_PROMPT "[ smdk2410 #]"
(5)修改默认下载地址
找到下面一行:
#define CFG_LOAD_ADDR 0x33000000
修改为:
#define CFG_LOAD_ADDR 0x30008000
#define CFG_TFTP_LOAD_ADDR 0x30008000
(6)修改环境变量在Nand Flash中的存储地址
找到下面两行:
#define CFG_ENV_IS_IN_FLASH 1
#define CFG_ENV_SIZE 0x10000
修改为:
#define CFG_ENV_IS_IN_NAND 1
#define CFG_ENV_SIZE 0x4000
#define CFG_ENV_OFFSET (0x80000-0x4000)
4、编译生成u-boot
依次执行以下命令:
#make smdk2410_config
#make
编译完成之后就生成了u-boot.bin文件,这个文件就是我们要烧写到开发板上的文件。