嵌入式系统移植 2011-03-17 21:21:10
终于可以发布uboot的移植文档了,朋友们都已经等了N久了,深表歉意!
文档共有10个部分,我将会分几篇博文贴出来,这只是个初始版,仅记录了我当初移植的过程,仅供参考。文章中的内容随时会修改,请先不要转载。后期我会整理成完整的PDF文档做为XC2440的配套教材。
之前我发布过uboot2010.03移植后的源码,建议大家去uboot官方FTP上下载uboot2010.03的源码,然后用beyond compare软件和我提供的源码进行比较,再根据文档中的步骤,查看我修改的代码,我修改的代码一般都会有注释:
/*xiangguangchao add begin*/
/*xiangguangchao add end*/
交叉编译器:arm-linux-gcc 4.1.2 支持EABI
平台搭建好了,马上开整:
smdk2410_config : unconfig
@$(MKCONFIG)$ (@:_config=)arm arm920t smdk2410 samsung s3c24x0
@$(MKCONFIG) $(@:_config=) arm arm920t XC2440 xgc s3c24x0
在board目录下,新建自己的开发板目录XC2440,把smdk2410目录下的所有文件拷到XC2440目录下,把smdk2410.c改为XC2440.c。修改该目录下的Makefile,(第28行)把smdk2410.o改为XC2440.o。
#define B6_MT 0x3 /* SDRAM */
#define B6_Trcd 0x1
#define B6_SCAN 0x1 /* 9bit */
#define B7_MT 0x3 /* SDRAM */
#define B7_Trcd 0x1 /* 3clk */
#define B7_SCAN 0x1 /* 9bit */
/* REFRESH parameter */
#define REFEN 0x1 /* Refresh enable */
#define TREFMD 0x0 /* CBR(CAS before RAS)/Auto refresh */
#define Trc 0x3 /* 7clk */
#define Tchr 0x2 /* 3clk */
#if defined(CONFIG_S3C2440)
#define Trp 0x2 /* 4clk */
#define REFCNT 1012
#else
#define Trp 0x0 /* 2clk */
#define REFCNT 0x0459
#endif
在include/configs目录下创建开发板的配置头文件,把smdk2410.h改名为XC2440.h,再把所有的文件全部删除,只留XC2440.h
修改XC2440.h,取消S3C2410的定义,加入S3C2440定义:
//#define CONFIG_S3C2410 1 /* specifically a SAMSUNG S3C2410 SoC */
//#define CONFIG_SMDK2410 1 /* on a SAMSUNG SMDK2410 Board */
#define CONFIG_S3C2440 1 /* specifically a SAMSUNG S3C2440 SoC */
增加对S3C2440处理器的支持,首先要修改2440的时钟设置
对于2440开发板,将FCLK设为400MHz,分频比为FCLK:HCLK:PCLK=1:4:8
#if 0
#define FCLK_SPEED 1
#if FCLK_SPEED==0 /* Fout = 203MHz, Fin = 12MHz for Audio */
#elif FCLK_SPEED==1 /* Fout = 202.8MHz */
#endif
#define USB_CLOCK 1
#if USB_CLOCK==0
#elif USB_CLOCK==1
#endif
#endif
#if defined(CONFIG_S3C2440)
/* Fout = 405MHz */
#define M_PDIV 0x2
#define M_SDIV 0x1
#endif
#if defined(CONFIG_S3C2440)
#define U_M_MDIV 0x38
#define U_M_PDIV 0x2
#endif
指定MACH_TYPE,在board_init函数中,查看bi_arch_number:
/* arch number of S3C2440-Board */
gd->bd->bi_arch_number = MACH_TYPE_S3C2440;
MACH_TYPE在include/asm-arm/mach-types.h中定义,其中MACH_TYPE_S3C2440是362,这个要和内核中的mach-types一致
修改cpu/arm920t/s3c24X0/speed.c:
m = ((r & 0xFF000) >> 12) + 8;
p = ((r & 0x003F0) >> 4) + 2;
/*xiangguangchao add begin*/
#if defined(CONFIG_S3C2440)
return ((CONFIG_SYS_CLK_FREQ * m * 2) /(p << s));
else if (pllreg == UPLL)
#endif
/*xiangguangchao add end*/
return (CONFIG_SYS_CLK_FREQ * m) / (p << s);
/* return HCLK frequency */
ulong get_HCLK(void)
{
struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
// return (readl(&clk_power->CLKDIVN) & 2) ? get_FCLK() / 2 : get_FCLK();
/*xiangguangchao add begin*/
#if defined(CONFIG_S3C2440)
if (readl(&clk_power->CLKDIVN) & 0x6)
if ((readl(&clk_power->CLKDIVN) & 0x6)==2) return(get_FCLK()/2);
if ((readl(&clk_power->CLKDIVN) & 0x6)==6) return((readl(&clk_power->CAMDIVN) & 0x100) ? get_FCLK()/6 : get_FCLK()/3);
if ((readl(&clk_power->CLKDIVN) & 0x6)==4) return((readl(&clk_power->CAMDIVN) & 0x200) ? get_FCLK()/8 : get_FCLK()/4);
return(get_FCLK());
return(get_FCLK());
#else
return((readl(&clk_power->CLKDIVN) & 0x2) ? get_FCLK()/2 : get_FCLK());
#endif
/*xiangguangchao add end*/
}
修改include/asm-arm/arch-s3c24x0/s3c24x0_cpu.h:
/*xiangguangchao add begin*/
#elif defined CONFIG_S3C2440
#include <asm/arch/s3c2410.h>
/*xiangguangchao add end*/
修改s3c24x0的寄存器定义头文件include/asm-arm/arch-s3c24x0/s3c24x0.h:将该文件中所有的“#ifdef CONFIG_S3C2410”替换成
“#if defined(CONFIG_S3C2410) || defined (CONFIG_S3C2440)”
在struct s3c24x0_clock_power结构体中加入2440的CAMDIVN寄存器定义:
#if defined (CONFIG_S3C2440)
#endif
修改cpu/arm920t/s3c24x0/timer.c,在get_tbclk函数中加入:
#elif defined(CONFIG_SBC2410X) || \
defined(CONFIG_SMDK2410) || \
defined(CONFIG_S3C2440) || \
# if defined(CONFIG_S3C2400)
# define pWTCON 0x15300000
# define INTMSK 0x14400008 /* Interupt-Controller base addresses */
# define CLKDIVN 0x14800014 /* clock divisor register */
#else
# define pWTCON 0x53000000
# define INTMSK 0x4A000008 /* Interupt-Controller base addresses */
# define INTSUBMSK 0x4A00001C
# define CLKDIVN 0x4C000014 /* clock divisor register */
# endif
/*xiangguangchao add begin*/
#define CLK_CTL_BASE 0x4C000000
#define MDIV_405 0x7f << 12
#define PSDIV_405 0x21
#define MDIV_200 0xa1 << 12
#define PSDIV_200 0x31
/*xiangguangchao add end*/
/*xiangguangchao add begin*/
#if defined(CONFIG_S3C2440)
ldr r1, =0x7fff
#endif
#if defined(CONFIG_S3C2440)
/* FCLK:HCLK:PCLK = 1:4:8 */
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, #0x04]
#else
/*xiangguangchao add end*/
/* FCLK:HCLK:PCLK = 1:2:4 */
/* default FCLK is 120 MHz ! */
/*xiangguangchao add begin*/
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_200
add r2, r2, #PSDIV_200
str r2, [r1, #0x04]
#endif
/*xiangguangchao add end*/
到此,uboot在S3C2440平台的基础移植工作已完成,接下来就要编译u-boot,然后在开发板上运行一下,验证是否可以正常启动。
编译命令:#make all,生成u-boot.bin镜像文件,用JTAG工具将其烧入Nor Flash中,运行效果如下:
U-Boot 2010.03 ( 8??? 03 2010 - 08:30:42)
Flash: 512 kB
*** Warning - bad CRC, using default environment
SMDK2410 #
现在检测到的Flash容量是512kB的,因为uboot默认的NorFlash配置是AM29LV400,XC2440上使用的NorFlash型号为S29AL016J(容量2M),我们需要修改成2M NorFlash的配置
注意:以下仅仅是修改了NorFlash的Size和Sectors Number的定义,驱动都是一样的。我们可以定义NorFlash型号为AM29LV160。
注释掉AM29LV400和AM29LV800的定义,加入AM29LV160的定义:
#if 0
#define CONFIG_AMD_LV400 1 /* uncomment this if you have a LV400 flash */
#define CONFIG_AMD_LV800 1 /* uncomment this if you have a LV800 flash */
#endif
#define CONFIG_AMD_LV160 1
#ifdef CONFIG_AMD_LV160
#define PHYS_FLASH_SIZE 0x00200000 /* 2MB */
#define CONFIG_SYS_MAX_FLASH_SECT (35) /* max number of sectors on one chip */
#define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + CONFIG_ENV_OFFSET) /* addr of environment */
#endif
#if defined(CONFIG_AMD_LV400)
(AMD_MANUFACT & FLASH_VENDMASK) | (AMD_ID_LV400B & FLASH_TYPEMASK);
#elif defined(CONFIG_AMD_LV800)
(AMD_MANUFACT & FLASH_VENDMASK) | (AMD_ID_LV800B & FLASH_TYPEMASK);
#elif defined(CONFIG_AMD_LV160)
(AMD_MANUFACT & FLASH_VENDMASK) | (AMD_ID_LV160B & FLASH_TYPEMASK);
#else
case (AMD_ID_LV400B & FLASH_TYPEMASK):
printf ("1x Amd29LV400BB (4Mbit)\n");
case (AMD_ID_LV800B & FLASH_TYPEMASK):
printf ("1x Amd29LV800BB (8Mbit)\n");
case (AMD_ID_LV160B & FLASH_TYPEMASK):
printf ("1x Amd29LV160B (2M)\n");
printf ("Unknown Chip Type\n");
U-Boot 2010.03 ( 8??? 03 2010 - 08:41:52)
Flash: 2 MB
*** Warning - bad CRC, using default environment
SMDK2410 #
查看NorFlash信息,输入命令#flinfo,信息如下:
Bank # 1: AMD: 1x Amd29LV160B (2M)
00000000 (RO) 00004000 (RO) 00006000 (RO) 00008000 (RO) 00010000 (RO)
00020000 (RO)00030000 00040000 00050000 00060000
00070000 00080000 00090000 000A0000 000B0000
000C0000 000D0000 000E0000 000F0000 00100000 (RO)
00110000 (RO) 00120000 00130000 00140000 00150000
00160000 00170000 00180000 00190000 001A0000
001B0000 001C0000 001D0000 001E0000 001F0000
在对该扇区擦除、写入之前,要先解除写保护,命令为:
#erase all 擦除整片Flash
#erase start end 擦除如:#erase 0x20000 0x2ffff
#erase start +len 擦除指定大小 如:#erase 0x40000 +0x12345
如:#cp.b 0x30000000 0 0x12345