micro2440 u-boot-1.1.6移植全过程

来源:互联网 发布:c语言实现约瑟夫环 编辑:程序博客网 时间:2024/05/20 22:28

开发环境:

系统:ubuntu 10.04.4

单板:micro2440

NAND FLASH:K9F1216U0A 256MB

NOR Flash:AM29LV160DB 2MB

SDRAM:HY57V561620 x2 64MB

NET:DM9000AEP

编译器:arm-linux-gcc-4.3.2

搭建开发环境详见ubuntu 10.04.4开发环境配置。

目标:

1.串口正常输出

2.支持NOR Flash

3.支持DM9000网卡

 一、获取源代码

ftp://ftp.denx.de/pub/u-boot/

下载u-boot-1.1.6.tar.bz2,并解压到工作目录

change@change:~/Si$ tar -jxvf u-boot-1.1.6.tar.bz2 -C micro2440/

change@change:~/Si$ cd micro2440/u-boot-1.1.6/
change@change:~/Si/micro2440/u-boot-1.1.6$ ls
arm_config.mk                  COPYING   fs              lib_m68k        MAKEALL               nios_config.mk
avr32_config.mk                cpu       i386_config.mk  lib_microblaze  Makefile              post
blackfin_config.mk             CREDITS   include         lib_mips        microblaze_config.mk  ppc_config.mk
board                          disk      lib_arm         lib_nios        mips_config.mk        README
CHANGELOG                      doc       lib_avr32       lib_nios2       mkconfig              rtc
CHANGELOG-before-U-Boot-1.1.5  drivers   lib_blackfin    lib_ppc         nand_spl              rules.mk
common                         dtt       lib_generic     m68k_config.mk  net                   tools
config.mk                      examples  lib_i386        MAINTAINERS     nios2_config.mk
change@change:~/Si/micro2440/u-boot-1.1.6$

方便移植,新建Source Insighe工程,阅读源码,工程添加源码是,以下未用文件可以不添加

board/下除 smdk2410 以外的所有其它目标板文件夹不添加
cpu/下除 arm920t 以外的所有其它cpu目录不添加
根目录下lib_XXX  的库文件目录,只留下 lib_arm 和 lib_generic ,其它lib_XXX 不添加
include/目录下arm-XXX  的文件目录,只留下 asm-arm ,其它arm-XXX 不添加
include/configs 目录下除 smdk2410.h  以外的所有其它配置头文件不添加

二、新建单板

change@change:~/Si/micro2440/u-boot-1.1.6$ cp -rf board/smdk2410/ board/micro2440
change@change:~/Si/micro2440/u-boot-1.1.6$ mv board/micro2440/smdk2410.c board/micro2440/micro2440.c
change@change:~/Si/micro2440/u-boot-1.1.6$

修改board/micro2440/Makefile文件中28行的COBJS改为:
  COBJS   := micro2440.o flash.o

change@change:~/Si/micro2440/u-boot-1.1.6$ cp include/configs/smdk2410.h include/configs/micro2440.h
change@change:~/Si/micro2440/u-boot-1.1.6$

修改顶层(u-boot-1.1.6目录)Makefile 文件1882行,增加:
micro2440_config :  unconfig
                 @$(MKCONFIG) $(@:_config=) arm arm920t micro2440 NULL s3c24x0
 注释:各项的意思如下:
    arm: CPU  的架构(ARCH)
    arm920t: CPU  的类型(CPU),其对应于 cpu/arm920t 子目录。 
    micro2440:  开发板的型号(BOARD),对应于 board/micro2440 目录。
    NULL:  开发者/或经销商(vender)。(此处没加 vender,为 NULL。)
    s3c24x0: 片上系统(SOC)。

已配置默认交叉编译链,这里采用默认配置,不需配置。

三、配置、编译、测试

change@change:~/Si/micro2440/u-boot-1.1.6$ make distclean

change@change:~/Si/micro2440/u-boot-1.1.6$ make micro2440_config
Configuring for micro2440 board...
change@change:~/Si/micro2440/u-boot-1.1.6$ make

make[1]: Leaving directory `/home/change/Si/micro2440/u-boot-1.1.6/common'
UNDEF_SYM=`arm-linux-objdump -x lib_generic/libgeneric.a board/micro2440/libmicro2440.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/nand/libnand.a drivers/nand_legacy/libnand_legacy.a drivers/sk98lin/libsk98lin.a post/libpost.a post/cpu/libcpu.a common/libcommon.a |sed  -n -e 's/.*\(__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
                cd /home/change/Si/micro2440/u-boot-1.1.6 && arm-linux-ld -Bstatic -T /home/change/Si/micro2440/u-boot-1.1.6/board/micro2440/u-boot.lds -Ttext 0x33F80000  $UNDEF_SYM cpu/arm920t/start.o \
                        --start-group lib_generic/libgeneric.a board/micro2440/libmicro2440.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/nand/libnand.a drivers/nand_legacy/libnand_legacy.a drivers/sk98lin/libsk98lin.a post/libpost.a post/cpu/libcpu.a common/libcommon.a --end-group -L /home/change/tools/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/armv4t -lgcc \
                        -Map u-boot.map -o u-boot
arm-linux-objcopy --gap-fill=0xff -O srec u-boot u-boot.srec
arm-linux-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin
change@change:~/Si/micro2440/u-boot-1.1.6$ ls
arm_config.mk                  cpu             include         lib_nios              mkconfig         rules.mk
avr32_config.mk                CREDITS         lib_arm         lib_nios2             nand_spl         System.map
blackfin_config.mk             disk            lib_avr32       lib_ppc               net              tools
board                          doc             lib_blackfin    m68k_config.mk        nios2_config.mk  u-boot
CHANGELOG                      drivers         lib_generic     MAINTAINERS           nios_config.mk   u-boot.bin
CHANGELOG-before-U-Boot-1.1.5  dtt             lib_i386        MAKEALL               post             u-boot.map
common                         examples        lib_m68k        Makefile              ppc_config.mk    u-boot.srec
config.mk                      fs              lib_microblaze  microblaze_config.mk  README
COPYING                        i386_config.mk  lib_mips        mips_config.mk        rtc
change@change:~/Si/micro2440/u-boot-1.1.6$

可以看到编译顺利生成u-boot.bin,但是还不支持micro2440,烧到单板不会有任何输出。

四、修改源码支持单板串口输出

1.修改内存SDRM配置

  进入/board/micro2440目录修改 lowlevel_init.S文件54行如下:
#define B1_BWSCON   (DW16)   //(DW32) (IDE)
#define B2_BWSCON   (DW16)   //    (IDE)
#define B3_BWSCON   (DW16 + WAIT + UBLB) //CS8900
#define B4_BWSCON   (DW16)     //DM9000
#define B5_BWSCON   (DW8)    //(DW16)
#define B6_BWSCON   (DW32)
#define B7_BWSCON   (DW32)

  修改lowlevel_init.S文件126行如下:
#define REFCNT 0x4f4
/*period=7.8125us,HCLK=100Mhz,(2048+1-7.8125*100)=0x4F4 */
//1113  /* period=15.6us, HCLK=60Mhz, (2048+1-15.6*60) */

2.修改时钟

S3c2440 的时钟计算公式和 s3c2410 不一样,对于 s3c2440 开发板,将 PCLK 设为
400Mhz,分频比为FCLK:HCLK:PCLK=1:4:8。 首先屏蔽原来s3c2410的时钟设置,修改cpu/arm920t/目录下start.S文件148行如下:
#if 0
  /* FCLK:HCLK:PCLK = 1:2:4 */
  /* default FCLK is 120 MHz ! */
  ldr  r0, =CLKDIVN
  mov r1, #3
  str  r1, [r0]
#endif
 然后在board_init函数中重新配置时钟,修改board/micro2440/micro2440.c文件中的
68行的board_init函数,并增加一些声明:
/* S3C2440: Mpll = (2*m * Fin) / (p * 2^s), UPLL = (m * Fin) / (p * 2^s)
* m = M (the value for divider M)+ 8, p = P (the value for divider P) + 2
*/
/* Fin = 12.0000MHz */
#define S3C2440_MPLL_400MHZ  ((0x5c<<12)|(0x02<<4)|(0x01))    //HJ 400MHz
#define S3C2440_UPLL_48MHZ ((0x38<<12)|(0x02<<4)|(0x02))     //HJ 100MHz
#define S3C2440_CLKDIV   0x05    /* FCLK:HCLK:PCLK = 1:4:8, UCLK = UPLL */
 //HJ 100MHz
/* S3C2410: Mpll,Upll = (m * Fin) / (p * 2^s)
* m = M (the value for divider M)+ 8, p = P (the value for divider P) + 2
*/
#define S3C2410_MPLL_200MHZ     ((0x5c<<12)|(0x04<<4)|(0x00))
#define S3C2410_UPLL_48MHZ      ((0x28<<12)|(0x01<<4)|(0x02))
#define S3C2410_CLKDIV          0x03    /* FCLK:HCLK:PCLK = 1:2:4 */   
以上代码针对s3c2410、s3c2440分别定义了MPLL、UPLL寄存器的值。开发板输入时钟为 12Mhz(这在 include/configs/micro2440.h中的宏 CONFIG_SYS_CLK_FREQ 中定义),可以根据代码中的计算公式针对自己的开发板修改系统时钟。下面是针对 s3c2410、s3c2440分别使用不同的宏设置系统时钟,用下面替换以前的board_init
int board_init (void)
{
 S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
 
 S3C24X0_GPIO * const gpio = S3C24X0_GetBase_GPIO();
 
 /* set up the I/O ports */
 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;
 /* support both of S3C2410 and S3C2440 */
 if ((gpio->GSTATUS1 == 0x32410000) || (gpio->GSTATUS1 == 0x32410002))
 {
  /* FCLK:HCLK:PCLK = 1:2:4 */
  clk_power->CLKDIVN = S3C2410_CLKDIV;
  
  /* change to asynchronous bus mod */
  __asm__(    "mrc    p15, 0, r1, c1, c0, 0\n"    /* read ctrl register   */  
     "orr    r1, r1, #0xc0000000\n"      /* Asynchronous         */  
     "mcr    p15, 0, r1, c1, c0, 0\n"    /* write ctrl register  */  
     :::"r1"
    );
        
  /* to reduce PLL lock time, adjust the LOCKTIME register */
  clk_power->LOCKTIME = 0xFFFFFF;
  
  /* configure MPLL */
  clk_power->MPLLCON = S3C2410_MPLL_200MHZ;
  
  /* some delay between MPLL and UPLL */
  delay (4000);
  
  /* configure UPLL */
  clk_power->UPLLCON = S3C2410_UPLL_48MHZ;
  
  /* some delay between MPLL and UPLL */
  delay (8000);
  
  /* arch number of SMDK2410-Board */
  gd->bd->bi_arch_number = MACH_TYPE_SMDK2410;

 }
 else
 {
  clk_power->CLKDIVN = S3C2440_CLKDIV;    //HJ 1:4:8
 
  /* change to asynchronous bus mod */
  __asm__(    "mrc    p15, 0, r1, c1, c0, 0\n"    /* read ctrl register   */  
     "orr    r1, r1, #0xc0000000\n"      /* Asynchronous         */  
     "mcr    p15, 0, r1, c1, c0, 0\n"    /* write ctrl register  */  
     :::"r1"
    );
  
  /* to reduce PLL lock time, adjust the LOCKTIME register */
  clk_power->LOCKTIME = 0xFFFFFF;
  
  /* configure MPLL */
  clk_power->MPLLCON = S3C2440_MPLL_400MHZ;  //fin=12.000MHz
  
  /* some delay between MPLL and UPLL */
  delay (4000);
  
  /* configure UPLL */
  clk_power->UPLLCON = S3C2440_UPLL_48MHZ;   //fin=12.000MHz
  
  /* some delay between MPLL and UPLL */
  delay (8000);
  
  /* arch number of SMDK2440-Board */
  gd->bd->bi_arch_number = MACH_TYPE_S3C2440;
 }
 /* adress of boot parameters */
 gd->bd->bi_boot_params = 0x30000100;
 
 icache_enable();
 dcache_enable();
 return 0;
}

最后一步,获取系统时钟的函数需要针对s3c2410、s3c2440的不同进行修改。 在后面设置串口波特率时需要获得系统时钟, 就是在 U-Boot 的第二阶段,lib_arm/board.c
中start_armboot 函数调用 serial_init 函数初始化串口时,会调用 get_PCLK  函数。它在 cpu/arm920t/s3c24x0/speed.c 中定义,与它相关的还有 get_HCLK、get_PLLCLK 等函数。 前面的 board_init  函数在识别出 S3C2410  或 S3C2440  后,设置了机器类型 ID:gd?bd?bi_arch_number,后面的函数可以通过它来分辨是 S3C2410 还是 S3C2440。首先要在程序的开头增加如下一行,DECLARE_GLOBAL_DATA_PTR;这样才可以使用 gd 变量。 
  在 cpu/arm920t/s3c24x0/speed.c 中修改:
 在程序开头40行增加一行:DECLARE_GLOBAL_DATA_PTR;这样才可以使用 gd 变量
 修改54行:get_PPLCLK 函数:
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;
 /* support both of S3C2410 and S3C2440 */
    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));   /* S3C2440 */
}

由于分频系数的设置方法也不一样,get_HCLK、get_PCLK也需要修改。对于s3c2410,沿用原来的计算方法,else分支中是s3c2440的代码,如下所示:
//修改get_HCLK、get_PCLK:
/* for s3c2440 */
#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)
 
/* return HCLK frequency */
ulong get_HCLK(void)
{
 S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
    unsigned long clkdiv;
 unsigned long camdiv;
    int hdiv = 1;
 
 /* support both of S3C2410 and S3C2440 */
    if (gd->bd->bi_arch_number == MACH_TYPE_SMDK2410)
        return((clk_power->CLKDIVN & 0x2) ? get_FCLK()/2 : get_FCLK());
    else
    {
        clkdiv = clk_power->CLKDIVN;
        camdiv = clk_power->CAMDIVN;
 
        /* work out clock scalings */
 
        switch (clkdiv & S3C2440_CLKDIVN_HDIVN_MASK) {
        case S3C2440_CLKDIVN_HDIVN_1:
            hdiv = 1;
            break;
 
        case S3C2440_CLKDIVN_HDIVN_2:
            hdiv = 2;
            break;
 
        case S3C2440_CLKDIVN_HDIVN_4_8:
            hdiv = (camdiv & S3C2440_CAMDIVN_HCLK4_HALF) ? 8 : 4;
            break;
 
        case S3C2440_CLKDIVN_HDIVN_3_6:
            hdiv = (camdiv & S3C2440_CAMDIVN_HCLK3_HALF) ? 6 : 3;
            break;
        }
        return get_FCLK() / hdiv;
    }
}
 
/* return PCLK frequency */
ulong get_PCLK(void)
{
 S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
 unsigned long clkdiv;    
 unsigned long camdiv;
 int hdiv = 1;
 /* support both of S3C2410 and S3C2440 */

    if (gd->bd->bi_arch_number == MACH_TYPE_SMDK2410)
        return((clk_power->CLKDIVN & 0x1) ? get_HCLK()/2 : get_HCLK());
    else
    {   
        clkdiv = clk_power->CLKDIVN;
        camdiv = clk_power->CAMDIVN;
 
        /* work out clock scalings */
 
        switch (clkdiv & S3C2440_CLKDIVN_HDIVN_MASK) {
        case S3C2440_CLKDIVN_HDIVN_1:
            hdiv = 1;
            break;
 
        case S3C2440_CLKDIVN_HDIVN_2:
            hdiv = 2;
            break;
 
        case S3C2440_CLKDIVN_HDIVN_4_8:
            hdiv = (camdiv & S3C2440_CAMDIVN_HCLK4_HALF) ? 8 : 4;
            break;
 
        case S3C2440_CLKDIVN_HDIVN_3_6:
            hdiv = (camdiv & S3C2440_CAMDIVN_HCLK3_HALF) ? 6 : 3;
            break;
        }
        return get_FCLK() / hdiv / ((clkdiv & S3C2440_CLKDIVN_PDIVN)? 2:1);
    }
}

 在 include/s3c24x0.h  中重新定义 S3C24X0_CLOCK_POWER  结构体,在 include/s3c24x0.h  中,S3C24X0_CLOCK_POWER  结构体中增加:129 行
 S3C24X0_REG32    CAMDIVN; /* for s3c2440*/
 至此,对s3c2440的支持(时钟配置部分)就算做好了。下面重新配置、编译

change@change:~/Si/micro2440/u-boot-1.1.6$ make distclean

change@change:~/Si/micro2440/u-boot-1.1.6$ make micro2440_config
Configuring for micro2440 board...
change@change:~/Si/micro2440/u-boot-1.1.6$ make

make[1]: Leaving directory `/home/change/Si/micro2440/u-boot-1.1.6/common'
UNDEF_SYM=`arm-linux-objdump -x lib_generic/libgeneric.a board/micro2440/libmicro2440.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/nand/libnand.a drivers/nand_legacy/libnand_legacy.a drivers/sk98lin/libsk98lin.a post/libpost.a post/cpu/libcpu.a common/libcommon.a |sed  -n -e 's/.*\(__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
                cd /home/change/Si/micro2440/u-boot-1.1.6 && arm-linux-ld -Bstatic -T /home/change/Si/micro2440/u-boot-1.1.6/board/micro2440/u-boot.lds -Ttext 0x33F80000  $UNDEF_SYM cpu/arm920t/start.o \
                        --start-group lib_generic/libgeneric.a board/micro2440/libmicro2440.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/nand/libnand.a drivers/nand_legacy/libnand_legacy.a drivers/sk98lin/libsk98lin.a post/libpost.a post/cpu/libcpu.a common/libcommon.a --end-group -L /home/change/tools/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/armv4t -lgcc \
                        -Map u-boot.map -o u-boot
arm-linux-objcopy --gap-fill=0xff -O srec u-boot u-boot.srec
arm-linux-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin
change@change:~/Si/micro2440/u-boot-1.1.6$ 

编译成功,最终在u-boot-1.1.6目录下生成u-boot.bin,下载到单板NOR flash设置串口115200 8 n 1串口就有输出了。

 五、增加Nor Flash支持

 micro2440开发板使用2M的EN29LV160DB。
 由于AM29LV800与EN29LV160DB相似,修改配置文件/include/configs/micro2440.h 156:如下:
 /*----------------------------------------------------------------------- 
 * FLASH and environment organization 
  */ 
#if 0 
#define CONFIG_AMD_LV400  1  /* uncomment this if you have a LV400 flash */ 
#endif 
#define CONFIG_AMD_LV800  1  /* uncomment this if you have a LV800 flash */ 
 
#define CFG_MAX_FLASH_BANKS 1  /* max number of memory banks */ 
#ifdef CONFIG_AMD_LV800 
#define PHYS_FLASH_SIZE  0x00200000 /* 2MB */ 
#define CFG_MAX_FLASH_SECT  (19) /* max number of sectors on one chip */ 
#define CFG_ENV_ADDR   (CFG_FLASH_BASE + 0xF0000) /* addr of environment */ 
#endif 
#ifdef CONFIG_AMD_LV400 
#define PHYS_FLASH_SIZE  0x00080000 /* 512KB */ 
#define CFG_MAX_FLASH_SECT  (11) /* max number of sectors on one chip */ 
#define CFG_ENV_ADDR   (CFG_FLASH_BASE + 0x070000) /* addr of environment */ 
#endif 
 
/* timeout values are in ticks */ 
#define CFG_FLASH_ERASE_TOUT (5*CFG_HZ) /* Timeout for Flash Erase */ 
#define CFG_FLASH_WRITE_TOUT (5*CFG_HZ) /* Timeout for Flash Write */ 
 
#define  CFG_ENV_IS_IN_FLASH  1 
#define CFG_ENV_SIZE  0x10000 /* Total Size of Environment Sector */ 
最后make一下,没有错误,加载到内存中运行正常。

 六、增加对网卡的支持,micro2440开发板使用100M的DM9000。
 u-boot 自带网卡驱动,所以只要做些设置即可。
(1)DM9000网卡使用的片选信号是nGCS 4,也就说明DM9000使用了BANK4。修改lowlevel_init.S(路径:board/micro2440/lowlevel_init.S)。

/* BWSCON */
#define DW8      (0x0)
#define DW16    (0x1)
#define DW32    (0x2)
#define WAIT    (0x1<<2)
#define UBLB    (0x1<<3)
#define B1_BWSCON    (DW32)
#define B2_BWSCON    (DW16)
#if 0

#define B3_BWSCON    (DW16 + WAIT + UBLB)
#endif
#define B3_BWSCON    (DW16 + UBLB)
#define B4_BWSCON    (DW16 + WAIT + UBLB)
#define B5_BWSCON    (DW16)
#define B6_BWSCON    (DW32)
#define B7_BWSCON    (DW32)
    修改前BANK3外接的CS8900网卡,将BANK3注释掉,修改数据宽度为16位,设置BANK4数据宽度16位,使用WAIT和nBE信号。
#define B4_Tacs    0x0    /*0clk */
#define B4_Tcos    0x3    /*4clk */
#define B4_Tacc    0x7    /* 14clk */
#define B4_Tcoh    0x1    /*1clk */
#define B4_Tah      0x3    /*4clk */
#define B4_Tacp    0x6    /*6clk */
#define B4_PMC    0x0    /* normal */

    根据DM9000数据手册设置时序,具体见DM9000数据手册。
 (2)增加网卡的 DM9000 的配置,include/configs/micro2440.h  的56行和96行 
/* 
 * Hardware drivers 
 */ 
#define CONFIG_DRIVER_DM9000 1 //去掉了原来 CS8900 的配置 
#define CONFIG_DM9000_BASE    0x20000000 
#define DM9000_IO    CONFIG_DM9000_BASE 
#define DM9000_DATA      (CONFIG_DM9000_BASE + 4) 
#define CONFIG_DM9000_USE_16BIT 
 
#define CONFIG_ETHADDR      10:23:45:67:89:AB 
#define CONFIG_NETMASK      255.255.255.0 
#define CONFIG_IPADDR      10.21.17.110 
#define CONFIG_SERVERIP    10.21.17.85 
注释掉CS8900的信息,添加DM9000的配置信息。
    宏定义CONFIG_DRIVER_DM9000为1表示配置使用DM9000网卡,u-boot编译时会将DM9000相关的驱动编译进去。
    其中0x20000000是DM9000的基址(BANK4),由于DM9000只有一条地址线CMD(LADDR2)用于
    区别是数据还是地址(CMD为低时数据总线上传输的是地址信号,CMD为高时传输的是数据信号),
    所以DM9000_DATA为0x20000004,DM9000_IO为0x20000000。
    
我的PC和开发板使用路由器相连,PC IP地址为172.16.1.111,开发板设置为1172.16.1.133,保证在同一个网段就行。
增加ping命令:
#define CONFIG_COMMANDS \
               (CONFIG_CMD_DFL| \
                  CFG_CMD_CACHE| \
                /*CFG_CMD_NAND|*/ \
           /*CFG_CMD_EEPROM |*/ \
                     /*CFG_CMD_I2C|*/ \
                    /*CFG_CMD_USB|*/ \
                 FG_CMD_REGINFO| \
                     CFG_CMD_PING| \
                     CFG_CMD_DATE| \
                        CFG_CMD_ELF)
    仿照CMD命令格式,我们使用CFG_CMD_PING增加对ping的支持。

change@change:~/Si/micro2440/u-boot-1.1.6$ make distclean

change@change:~/Si/micro2440/u-boot-1.1.6$ make micro2440_config 

Configuring for micro2440 board...

change@change:~/Si/micro2440/u-boot-1.1.6$ make

make[1]: Leaving directory `/home/change/Si/micro2440/u-boot-1.1.6/common'
UNDEF_SYM=`arm-linux-objdump -x lib_generic/libgeneric.a board/micro2440/libmicro2440.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/nand/libnand.a drivers/nand_legacy/libnand_legacy.a drivers/sk98lin/libsk98lin.a post/libpost.a post/cpu/libcpu.a common/libcommon.a |sed  -n -e 's/.*\(__u_boot_cmd_.*\)/-u\1/p'|sort|uniq`;\
                cd /home/change/Si/micro2440/u-boot-1.1.6 && arm-linux-ld -Bstatic -T /home/change/Si/micro2440/u-boot-1.1.6/board/micro2440/u-boot.lds -Ttext 0x33F80000  $UNDEF_SYM cpu/arm920t/start.o \
                        --start-group lib_generic/libgeneric.a board/micro2440/libmicro2440.a cpu/arm920t/libarm920t.a cpu/arm920t/s3c24x0/libs3c24x0.a lib_arm/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a net/libnet.a disk/libdisk.a rtc/librtc.a dtt/libdtt.a drivers/libdrivers.a drivers/nand/libnand.a drivers/nand_legacy/libnand_legacy.a drivers/sk98lin/libsk98lin.a post/libpost.a post/cpu/libcpu.a common/libcommon.a --end-group -L /home/change/tools/usr/local/arm/4.3.2/bin/../lib/gcc/arm-none-linux-gnueabi/4.3.2/armv4t -lgcc \
                        -Map u-boot.map -o u-boot
arm-linux-objcopy --gap-fill=0xff -O srec u-boot u-boot.srec
arm-linux-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin

change@change:~/Si/micro2440/u-boot-1.1.6$ cp u-boot.bin /home/change/work/tftpboot/

七、烧写、测试

单板NOR Flash启动,通过u-boot烧写上面的程序到NOR Flash

U-Boot 2012.04.01 (Oct 25 2012 - 22:47:25)


CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0 
SMDK2410 # tftp 0x32000000 u-boot.bin
dm9000 i/o: 0x20000000, id: 0x90000a46 
DM9000: running in 16 bit mode
MAC: 00:0c:29:4d:e4:f4
could not establish link
Using dm9000 device
TFTP from server 172.16.1.133; our IP address is 172.16.1.111
Filename 'u-boot.bin'.
Load address: 0x32000000
Loading: #######
done
Bytes transferred = 92408 (168f8 hex)
SMDK2410 # flinfo


Bank # 1: MXIC S29AL016J70 flash (16 x 16)  Size: 2 MB in 35 Sectors
  AMD Legacy command set, Manufacturer ID: 0x01, Device ID: 0x2249
  Erase timeout: 30000 ms, write timeout: 100 ms


  Sector Start Addresses:
  00000000   RO   00004000   RO   00006000   RO   00008000   RO   00010000   RO 
  00020000   RO   00030000   RO   00040000        00050000        00060000      
  00070000        00080000        00090000        000A0000        000B0000      
  000C0000        000D0000        000E0000        000F0000        00100000      
  00110000        00120000        00130000        00140000        00150000      
  00160000        00170000        00180000        00190000        001A0000      
  001B0000        001C0000        001D0000        001E0000        001F0000      
SMDK2410 # protect off all
Un-Protect Flash Bank # 1
SMDK2410 # erase 0 0x40000
Error: end address not on sector boundary
SMDK2410 # erase 0 0x80000
Error: end address not on sector boundary
SMDK2410 # erase 0 0x7ffff

........... done
Erased 11 sectors
SMDK2410 # cp.b 0x32000000 0 0x80000
Copy to Flash... 9....8....7....6....5....4....3....2....1....done
SMDK2410 # 


烧写成功,重启单板,串口输出如下:
U-Boot 1.1.6 (Apr 27 2013 - 20:11:51)


DRAM:  64 MB
Flash:  2 MB
*** Warning - bad CRC, using default environment


In:    serial
Out:   serial
Err:   serial
micro2440 # printenv
bootdelay=3
baudrate=115200
ethaddr=10:23:45:67:89:AB
ipaddr=172.16.1.111
serverip=172.16.1.133
netmask=255.255.255.0
stdin=serial
stdout=serial
stderr=serial


Environment size: 159/65532 bytes
micro2440 # ping 172.16.1.133
dm9000 i/o: 0x20000000, id: 0x90000a46 
MAC: 00:80:00:80:00:80
could not establish link
host 172.16.1.133 is alive
micro2440 # tftp 0x32000000 u-boot_2012.04.01.bin
dm9000 i/o: 0x20000000, id: 0x90000a46 
MAC: 00:80:00:80:00:80
could not establish link
TFTP from server 172.16.1.133; our IP address is 172.16.1.111
Filename 'u-boot_2012.04.01.bin'.
Load address: 0x32000000
Loading: ###########################################
done
Bytes transferred = 217492 (35194 hex)
micro2440 # protect off all
Un-Protect Flash Bank # 1
micro2440 # erase 0 0x7ffff
Erasing sector  0 ... ok.
Erasing sector  1 ... ok.
Erasing sector  2 ... ok.
Erasing sector  3 ... ok.
Erasing sector  4 ... ok.
Erasing sector  5 ... ok.
Erasing sector  6 ... ok.
Erasing sector  7 ... ok.
Erasing sector  8 ... ok.
Erasing sector  9 ... ok.
Erasing sector 10 ... ok.
Erased 11 sectors
micro2440 # cp.b 0x32000000 0 0x80000
Copy to Flash... done
micro2440 # 
测试网卡,可以ping通。通过tftp命令将程序放到内存,再写到NOR Flash,其中这个版本u-boot写NOR Flash过程有点长,要耐心等待。上面又将

u-boot-2012.04.01烧到NOR Flash,重启u-boot-2012.04.01正常运行,测试OK

U-Boot 2012.04.01 (Oct 25 2012 - 22:47:25)


CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND:  256 MiB
In:    serial
Out:   serial
Err:   serial
Net:   dm9000
Hit any key to stop autoboot:  0 
SMDK2410 # 

这只是最简版的u-boot,很多功能还不支持,但基本上可以使用了。有兴趣可以在此基础上修改。

原创粉丝点击