微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > minis3c2440移植之uboot移植

minis3c2440移植之uboot移植

时间:11-24 来源:互联网 点击:
U-boot移植
(以下步骤适用于s3c2440开发板)
1、修改Makefile文件:
a.修改交叉编译宏(CROSS_COMPILE?=)修改为(CROSS_COMPILE?=arm-linux-);
b.将._LIBS:后的两个变量交换位置(line289)
c.添加tocore2440_config Make文件(line2997)
tocore2440_config: unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t tocore2440 tocore s3c24x0
包含六个参数:$1. tocore2440 表示在include/configs/目录下必须包含tocore2440.h文件;$2. arm表示在主目录下包含lib_arm目录,在include/目录下包含asm_arm目录;$3.arm920t表示CPU型号,在cpu目录下包含arm920t目录;$4.tocore2440芯片型号;$5.厂商目录(if($5!=NULL),则在board目录下有$5/$4目录,else,则在board目录下有$4目录);$6. s3c24x0表示在include/asm_arm/包含arch_ s3c24x0目录;
d.以上部分表示在移植U-boot前首先要添加开发板自己的配置头文件,并在board目录下建立自己的开发板目录,修改s3c24x0(cpu/arm920t/s3c24x0,include/asm_arm/archs3c24x0)文件,改为支持2440开发板,修改过程如下:
1) 修改inperrupts.c文件,添加宏定义:#defined(CONFIG_S3C2440)( line36)。
2) 修改speed.c文件:a.添加宏定义:#defined (CONFIG_S3C2440) ( line33);b.在get_PLLCLK()函数中添加2440支持,具体修改方式如下:在return返回值前添加#if defined(CONFIG_S3C2440)
if (pllreg == MPLL)
return((CONFIG_SYS_CLK_FREQ * m * 2) / (p < s)); //得到2440开发板的频率
else if (pllreg == UPLL)
#endif
c.将get_HCLK()函数修改为2440支持,将原函数返回改为:
//该函数为读取当前系统时钟
#if defined(CONFIG_S3C2440)
if (clk_power->CLKdivN & 0x6)
{
if ((clk_power->CLKdivN & 0x6)==2) return(get_FCLK()/2);
if ((clk_power->CLKdivN & 0x6)==6) return((clk_power->CAMdivN & 0x100) ? get_FCLK()/6 : get_FCLK()/3);
if ((clk_power->CLKdivN & 0x6)==4) return((clk_power->CAMdivN & 0x200) ? get_FCLK()/8 : get_FCLK()/4);
return(get_FCLK());
}
else return(get_FCLK());
#else
return((clk_power->CLKdivN & 0x2) ? get_FCLK()/2 : get_FCLK());
#endif
d.修改time.c文件,添加宏定义#defined (CONFIG_S3C2440)(line33)
2、添加配置文件
a.将smdk2410.h复制为tocore2440.h,其文件修改如下:
1)添加宏#undef CONFIG_SKIP_LOWLEVEL_INIT (line40)
2)注释2410宏定义:
//#define CONFIG_S 3C2410 1
//#define CONFIG_SBC2410X 1
3)添加2440宏定义:
#define CONFIG_S3C2440 1
#define CONFIG_TOCORE2440 1
#define CONFIG_TOCORE2440_LED 1 //添加点灯宏定义
#define CONFIG_S3C2440_NAND_BOOT 1 //Nandflash启动
4)注释CS8900网卡宏定义(在line72添加#if 0,在line76 添加#endif),添加DM9000网卡宏定义:
#define CONFIG_DRIVER_DM9000 1
#define CONFIG_DM9000_USE_16BIT 1
#define CONFIG_DM9000_BASE 0x20000300
#define DM9000_IO 0x20000300
#define DM9000_DATA 0x20000304
#define CONFIG_DM9000_NO_SROM 1
#undef CONFIG_DM9000_DEBUG
#define CONFIG_NET_MULTI
5)在命令行宏定义中添加如下宏定义:
#define CONFIG_CMD_ASKENV
#define CONFIG_CMD_DHCP
#define CONFIG_CMD_PING
#define CONFIG_CMD_NAND
#define CONFIG_CMD_SAVEENV

#define CONFIG_BOOTDELAY 3 //设置系统启动等待时间
#define CONFIG_BOOTARGS "console=ttySAC0 root=/dev/nfs "
"nfsroot=192.168.2.199:/fs "
"ip=192.168.2.69:" //NFS支持
#define CONFIG_ETHADDR 08:00:3e:26:0a:5b //打开MAC
#define CONFIG_IPADDR 192.168.2.69 //定义自身IP
#define CONFIG_SERVERIP 192.168.2.105 //定义服务器IP
#define CONFIG_BOOTCOMMAND "dhcp; bootm" //打开DHCP
//line154之后添加如下宏定义
#define CONFIG_SYS_PROMPT "[tocore2440 ]# " //修改启动标识
#define CONFIG_SYS_LOAD_ADDR 0x31000000 //下载地址
#define CONFIG_ENV_ADDR 0x060000 //断电保存地址
#define CONFIG_ENV_IS_IN_NAND 1 //Nandflash
#define CONFIG_ENV_OFFSET 0X60000 //整个寄存器偏移地址
#define CONFIG_ENV_SIZE 0x20000 //ENV分区大小
#define MTDPARTS_DEFAULT "mtdparts=nandflash0:384k(bootloader),"
"128k(params),"
"5m(kernel),"
"-(root)" //Nandflash默认设置

#define NAND_MAX_CHIPS 1 //Nandflash最大个数
#define CONFIG_MTD_NAND_VERIFY_WRITE //校验
#if defined(CONFIG_TOCORE2440_LED) //点灯宏定义


#define GPIO_CTL_BASE 0x56000000
#define oGPIO_B 0x10
#define oGPIO_CON 0x0
#define oGPIO_DAT 0x4
#define oGPIO_UP 0x8
#endif
#define STACK_BASE 0x33f00000
#define STACK_SIZE 0x10000

6)对Nandflash的相关设置修改如下:
添加LV800支持宏定义,注释掉如下宏定义
//#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x0F0000)
//#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000)
//#define CONFIG_ENV_IS_IN_FLASH 1
//#define CONFIG_ENV_SIZE 0x10000
添加Nandflash设置:
#if defined(CONFIG_CMD_NAND)
#define CONFIG_NAND_S3C2410
#define CONFIG_SYS_MAX_NAND_DEVICE 1
#endif
#define CONFIG_SETUP_MEMORY_TAGS
#define CONFIG_INITRD_TAG
#define CONFIG_CMDLINE_TAG
#define CONFIG_SYS_HUSH_PARSER
#define CONFIG_SYS_PROMPT_HUSH_PS2 "> "
#define CONFIG_CMDLINE_EDITING
#ifdef CONFIG_CMDLINE_EDITING
#undef CONFIG_AUTO_COMPLETE
#else
#define CONFIG_AUTO_COMPLETE
#endif

#define CONFIG_SYS_NAND_BASE 0x4E000000
#define NAND_CTL_BASE 0x4E000000
#define bINT_CTL(Nb) __REG(INT_CTL_BASE + (Nb))


#define oNFCONF 0x00
#if defined(CONFIG_S3C2440)
#define CONFIG_S3C2440_NAND_BOOT 1

#define oNFCONT 0x04
#define oNFCMD 0x08
#define oNFADDR 0x0c
#define oNFDATA 0x10
#define oNFSTAT 0x20
#define oNFECC 0x2c
#define rNFCONF (*(volatile unsigned int *)0x4e000000)
#define rNFCONT (*(volatile unsigned int *)0x4e000004)
#define rNFCMD (*(volatile unsigned char *)0x4e000008)
#define rNFADDR (*(volatile unsigned char *)0x4e00000c)
#define rNFDATA (*(volatile unsigned char *)0x4e000010)
#define rNFSTAT (*(volatile unsigned int *)0x4e000020)
#define rNFECC (*(volatile unsigned int *)0x4e00002c)
#endif
#if defined(CONFIG_S3C2410)
#define CONFIG_S3C2410_NAND_BOOT 1

#define oNFCONF 0x00
#define oNFCMD 0x04
#define oNFADDR 0x08
#define oNFDATA 0x0c
#define oNFSTAT 0x10
#define oNFECC 0x14
#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)
#endif
至此tocore2440.h文件修改完毕
b.建立目录/board/tocore/tocore2440,将/board/samsung/smdk2440下的文件拷贝至/board/tocore/tocore2440下,拷贝nand_read.c(开发板自带)文件至该目录下。修改Makefile文件(line28)
COBJS :=tocore2440.o nand_read.o flash.o
c.修改lowlevel_init.S文件,添加如下支持2440代码:
#if defined(CONFIG_S3C2440)
#define Trp 0x2
#define REFCNT 1012
#else
#define Trp 0x0
#define REFCNT 0x0459
#endif
d.修改tocore2440.c文件:
在#elif FCLK_SPEED==1之后添加:
#if defined(CONFIG_S3C2440)
#define M_Mdiv 0x7f
#define M_Pdiv 0x2
#define M_Sdiv 0x1
#endif
#endif
在#elif USB_CLOCK==1之后修改为:
//#define U_M_Mdiv 0x48
//#define U_M_Pdiv 0x3

#if defined(CONFIG_S3C2440)
#define U_M_Mdiv 0x38
#define U_M_Pdiv 0x2
#endif
修改board_init()函数:
将gpio->GPGCON的值改为 0xFF95FF3A;
将gpio->GPHCON 的值改为 0x0016FAAA
在gpio->GPHUP = 0x000007FF之后添加一下宏定义:
gpio->EXTINT0=0x22222222;
gpio->EXTINT1=0x22222222;
gpio->EXTINT2=0x22222222;

在dcache_enable()函数之后添加以下低昂等操作代码:
#if defined(CONFIG_TOCORE2440_LED)
gpio->GPBDAT = 0x181;
#endif

在board_init()函数之后添加以下函数:
#ifdef CONFIG_DRIVER_DM9000
int board_eth_init(bd_t *bis)
{
return dm9000_initialize(bis);
}
#endif
至此tocore2440.c文件修改完毕
e.修改start.S文件:
1)注释掉以下代码:
//bl coloured_LED_init
//bl red_LED_on
在#if defined (CONFIG_S3C2400) || defined (CONFIG_S3C2410)之后添加2440的支持:|| defined(CONFIG_S3C2440)
2)在line146之后添加对时钟设置代码:
#define CLK_CTL_BASE 0x4C000000
#define Mdiv_405 0x7f<12
#define PSdiv_405 0x21
#define Mdiv_200 0xa1<12
#define PSdiv_200 0x31
#endif
在line163之后添加工作频率设置汇编代码
#if defined(CONFIG_S3C2440)


ldr r0, =CLKdivN
mov r1,#5
str r1,[r0]

mrc p15,0,r1,c1,c0,0
orr r1, r1,#0xc0000000
mcr p15,0,r1,c1,c0,0

mov r1,#CLK_CTL_BASE
mov r2,#Mdiv_405
add r2,r2,#PSdiv_405
str r2,[r1,#0x4]
#else
在#endif 之后添加以下Nandflash设置代码:
#endif
#define LENGTH_UBOOT 0x60000
#define NAND_CTL_BASE 0x4E000000
#ifdef CONFIG_S3C2440_NAND_BOOT

@reset NAND
//#define oNFCONF 0x00
//#define oNFCONT 0x04
//#define oNFSTAT 0x08
//#define oNFCMD 0x20
mov r1,#NAND_CTL_BASE
ldr r2,=( (7<12)|(7<8)|(7<4)|(0<0))
str r2,[r1,#oNFCONF]
ldr r2,[r1,#oNFCONF]
ldr r2,=((1<4)|(0<1)|(1<0))
str r2,[r1,#oNFCONT]
ldr r2,[r1,#oNFCONT]
ldr r2,=(0x6)
str r2,[r1,#oNFSTAT]
ldr r2,[r1,#oNFSTAT]
mov r2,#0xff
strb r2,[r1,#oNFCMD]
mov r3,#0
nand1:
add r3,r3,#0x1
cmp r3,#0xa
blt nand1
nand2:
ldr r2,[r1,#oNFSTAT]
tst r2,#0x4
beq nand2
ldr r2,[r1,#oNFCONT]
orr r2,r2,#0x2
str r2,[r1,#oNFCONT]
@get read to call C functions (for nand_read())
ldr sp,DW_STACK_START
mov fp,#0
@copy U-Boot to Ram
ldr r0,=TEXT_BASE
mov r1,#0x0
mov r2, #LENGTH_UBOOT //the u-boot¿s lenth
bl nand_read_ll
tst r0,#0x0
beq ok_nand_read
bad_nand_read:
loop2: b loop2
ok_nand_read:
@verify
mov r0,#0
ldr r1,=TEXT_BASE
mov r2,#0x400
go_next:
ldr r3,[r0],#4
ldr r4,[r1],#4
teq r3,r4
bne notmatch
subs r2,r2,#4
beq stack_setup
bne go_next

notmatch:
loop3: b loop3 @CONFIG_S3C2440_NAND_BOOT
#endif
在对BSS段清零操作代码之后添加以点灯操作代码:
#if defined(CONFIG_TOCORE2440_LED)
mov r1, #GPIO_CTL_BASE
add r1, r1, #oGPIO_B
ldr r2,=0x156aa
str r2, [r1, #oGPIO_CON]
mov r2, #0xff
str r2, [r1, #oGPIO_UP]
mov r2, #0x1c0
str r2, [r1, #oGPIO_DAT]
#endif
在_start_armboot: .word start_armboot跳转代码之后添加以下对堆栈段设置的代码:
#define STACK_BASE 0x33f00000
#define STACK_SIZE 0x10000
.align 2
DW_STACK_START: .word STACK_BASE+STACK_SIZE-4
至此start.S文件修改完毕,整个配置文件修改完成。
3.在u-boot根目录下执行清理配置文件命令make distclean,并执行命令make tocore2440_config命令,完成对u-boot的配置,添加交叉编译工具环境变量:export PATH=/armtools/bin:$PATH(交叉编译工具解压在更目录下),再执行make命令,完成U-boot编译。


Linux内核编译步骤(支持S3C2440)
1. 修改Makefile文件:
修改arch宏定义:ARCH?=arm (line176)
修改CROSS_COMPILE为CROSS_COMPILE?=arm-linux- (line177)
2.执行命令cp arch/arm/configs/smdk2410_defconfig .config,完成对smdk2410配置信息的拷贝。执行命令make menuconfig命令,实现对.config文件的配置信息的设置。
3. 对.config配置方法如下:
a.进入配置System Type --->项:
选择S3C24XX Implementations --->项,进入后选定SMDK2440项和其子项SMDK2440 with S3C2440 CPU module,推出到上级菜单,选定arm900T支持项Support ARM920T processor,至此完成对System Type项的设置。
b.进入配置Floating point emulation --->项:
进入后选定NWFPE math emulation和其子项Support extended precision,至此完成对Floating point emulation项的设置。
c.进入配置Device Drivers --->驱动项:
1)配置Memory Technology Devices (MTD) --->项,进入选定Memory Technology Device (MTD) support项和MTD partitioning support项,并进入配置NAND Flash Device Drivers --->项,进入后选定NAND Flash support for S3C2410/S3C2440 SoC项NAND Flash support for S3C2410/S3C2440 SoC和其子项S3C2410 NAND driver debug项,退出到Device Drivers二级菜单。
2)配置Block devices --->项,进入后选定Loopback device support项,修改Default RAM disk size (kbytes)项的值为65535,退到上级菜单
3)配置Network device support --->项,进入之后选定Network device support项,进入Ethernet (10 or 100Mbit) --->项选择网DM9000支持项DM9000 support,退出到Device Drivers二级菜单
4)进入Character devices --->项的子项Serial drivers --->检查是否选定Samsung S3C2410/S3C2440/S3C2442/S3C2412 Serial port support和其子项Support for console on S3C2410 serial port,若未选定,则选定退出到主菜单。
d.配置File systems --->项,进入之后选定Ext2 extended attributes项、Ext2 execute in place support、Ext3 journalling file system support项和ROM file system support项,进入Network File Systems --->项,选定NFS file system support项,退出到主菜单
e.退出,保存。
4.修改arch/arm/march_s3c2410/目录下的文件common-smdk.c文件:
将struct mtd_partition smdk_default_nand_part[]修改为:
static struct mtd_partition smdk_default_nand_part[] = {
[0] = {
.name = "Kernel",
.size = SZ_2M,
.offset = 0,
},
[1] = {
.name = "root partition",
.offset = SZ_2M,
.size = (64*SZ_1M-2* SZ_1M),
},
[2] = {
.name = "other2",
.offset = SZ_64M,
.size = (64*SZ_1M),
},
[3] = {
.name = "other3",
.offset = SZ_128M,
.size = (64*SZ_1M),
},
#if 0

[2] = {
.name = "S3C2410 flash partition 2",
.offset = SZ_4M,
.size = SZ_4M,
},
[3] = {
.name = "S3C2410 flash partition 3",
.offset = SZ_8M,
.size = SZ_2M,
},
[4] = {
.name = "S3C2410 flash partition 4",
.offset = SZ_1M * 10,
.size = SZ_4M,
},
[5] = {
.name = "S3C2410 flash partition 5",
.offset = SZ_1M * 14,
.size = SZ_1M * 10,
},
[6] = {
.name = "S3C2410 flash partition 6",
.offset = SZ_1M * 24,
.size = SZ_1M * 24,
},
[7] = {
.name = "S3C2410 flash partition 7",
.offset = SZ_1M * 48,
.size = SZ_16M,
}
#endif
};
5.修改arch/arm/march_s3c2410/目录下的march-smdk2410.c文件:
修改函数void __init smdk2440_map_io():将主频设置为12000000。 代码为s3c24xx_init_clocks(12000000);
6.执行make clean清除命令,再执行make uImage命令,完成make命令之后将在arch/arm/boot目录下产生uImage文件。至此整个内核的修改和编译全部完成。



Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top