ARM笔记: U-Boot移植
扫描二维码
随时随地手机看文章
U-Boot移植:
系统:Ubuntu 12.04
开发板:JZ2440
虚拟机:VM10.04
U-Boot:U-BOOT-1.1.6
步骤:
1、解压U-BOOT-1.1.6
tar jxvf U-BOOT-1.1.6.tar.bz2
2、同时支持S3C2410和S3C2440:
(1)、新建一个开发板的相应目录和文件
在board目录下将smdk2410复制为100ask24x0,并将board/100ask24x0/smdk2410.c改名为100ask24x0.c,再将include/configs/smdk2410.h复制为100ask24x0.h
修改两个Makefile:
1)、在顶层Makefile中增加如个两行:
100ask24x0_config :unconfig
@$(MKCONFIG) $(@:_config=) arm arm920t 100ask24x0 NULL s3c24x0
2)、在board/100ask24x0/Makefile中修改如下:
COBJS:= smdk2410.o flash.o
改为
COBJS:= 100ask24x0.o flash.o
3、修改SDRAM的配置
SDRAM的初始化在U-Boot的第一阶段完成,在board/100ask24x0/lowlevel_init.S中,由于开发板的HCLK都为100mhz,需该REFCNT寄存器的值。修改如下:
#define REFCNT0x1113
改为
#define REFCNT0x4f4
4、增加对S3C2440的支持
2440的时钟计算公式、NAND操作和2410不太一样。
对于2440开发板,将FCLK设为400MHz,分频比为FCLK:HCLK:PCLK=1:4:8。
首先修改board/100ask24x0/100ask24x0.c中的board_init函数:
#define S3C2440_MPLL_400MHZ((0x5c<<12)|(0x02<<4)|(0x01))
#define S3C2440_UPLL_48MHZ((0x38<<12)|(0x02<<4)|(0x02))
#define S3C2440_CLKDIV0x05
#define S3C2410_MPLL_200MHZ((0x5c<<12)|(0x04<<4)|(0x00))
#define S3C2410_UPLL_48MHZ((0x28<<12)|(0x01<<4)|(0x02))
#define S3C2410_CLKDIV0x03
int board_init (void)
{
S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
gpio->GPACON = 0x007FFFFF;
gpio->GPBCON = 0x00044555;
gpio->GPBUP = 0x000007FF;
gpio->GPCCON = 0xAAAAAAAA;
gpio->GPCUP = 0x0000FFFF;
gpio->GPDCON = 0xAAAAAAAA;
gpio->GPDUP = 0x0000FFFF;
gpio->GPECON = 0xAAAAAAAA;
gpio->GPEUP = 0x0000FFFF;
gpio->GPFCON = 0x000055AA;
gpio->GPFUP = 0x000000FF;
gpio->GPGCON = 0xFF95FFBA;
gpio->GPGUP = 0x0000FFFF;
gpio->GPHCON = 0x002AFAAA;
gpio->GPHUP = 0x000007FF;
if ((gpio->GSTATUS1 == 0x32410000) || (gpio->GSTATUS1 == 0x32410002))
{
clk_power->CLKDIVN = S3C2410_CLKDIV;
__asm__("mrcp15, 0, r1, c1, c0, 0n"
"orrr1, r1, #0xc0000000n"
"mcrp15, 0, r1, c1, c0, 0n"
:::"r1"
);
clk_power->LOCKTIME = 0xFFFFFF;
clk_power->MPLLCON = S3C2410_MPLL_200MHZ;
delay (4000);
clk_power->UPLLCON = S3C2410_UPLL_48MHZ;
delay (8000);
gd->bd->bi_arch_number = MACH_TYPE_SMDK2410;
}
else
{
clk_power->CLKDIVN = S3C2440_CLKDIV;
__asm__("mrcp15, 0, r1, c1, c0, 0n"
"orrr1, r1, #0xc0000000n"
"mcrp15, 0, r1, c1, c0, 0n"
:::"r1"
);
clk_power->LOCKTIME = 0xFFFFFF;
clk_power->MPLLCON = S3C2440_MPLL_400MHZ;
delay (4000);
clk_power->UPLLCON = S3C2440_UPLL_48MHZ;
delay (8000);
gd->bd->bi_arch_number = MACH_TYPE_S3C2440;
}
gd->bd->bi_boot_params = 0x30000100;
icache_enable();
dcache_enable();
return 0;
}
5、修改系统时钟
在U-Boot的第二阶段,设置串口波特率时需要获得系统时钟,lib_arm/board.c中,start_armboot函数调用serial_init函数初始化时会调用get_PCLK函数。
在cpu/arm920t/s3c24x0/speed.c中修改:
首先,在程序开头增加一行DECLARE_GLOBAL_DATA_PTR;,这样才可以使用gd变量。
S3C2410和S3C2440的MPLL,UPLL计算公式不一样,所以修改get_PLLCLK:
static ulong get_PLLCLK(int pllreg)
{
S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
ulong r, m, p, s;
if (pllreg == MPLL)
r = clk_power->MPLLCON;
else if (pllreg == UPLL)
r = clk_power->UPLLCON;
else
hang();
m = ((r & 0xFF000) >> 12) + 8;
p = ((r & 0x003F0) >> 4) + 2;
s = r & 0x3;
if (gd->bd->bi_arch_number == MACH_TYPE_SMDK2410)
return((CONFIG_SYS_CLK_FREQ * m) / (p << s));
else
return((CONFIG_SYS_CLK_FREQ * m * 2) / (p << s));
}
由于分频系数的设置方法也不一样,get_HCLK,get_PCLK也做如下修改:
#define S3C2440_CLKDIVN_PDIVN(1<<0)
#define S3C2440_CLKDIVN_HDIVN_MASK(3<<1)
#define S3C2440_CLKDIVN_HDIVN_1(0<<1)
#define S3C2440_CLKDIVN_HDIVN_2(1<<1)
#define S3C2440_CLKDIVN_HDIVN_4_8(2<<1)
#define S3C2440_CLKDIVN_HDIVN_3_6(3<<1)
#define S3C2440_CLKDIVN_UCLK(1<<3)
#define S3C2440_CAMDIVN_CAMCLK_MASK(0xf<<0)
#define S3C2440_CAMDIVN_CAMCLK_SEL(1<<4)
#define S3C2440_CAMDIVN_HCLK3_HALF(1<<8)
#define S3C2440_CAMDIVN_HCLK4_HALF(1<<9)
#define S3C2440_CAMDIVN_DVSEN(1<<12)
ulong get_HCLK(void)
{
S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
unsigned long clkdiv;
unsigned long camdiv;
int hdiv = 1;
if (gd-