u-boot-2012.10移植到AT91RM9200(包括NAND FLASH)

基于中嵌SRM9204

目  录

1 配置-- 2

1.1修改顶层Makefile(可选)-- 2

1.2配置-- 2

1.3下载、运行、测试-- 3

2 修改内存配置参数(根据芯片手册修改)-- 4

2.1 修改配置参数-- 4

2.2 编译-- 4

2.3运行测试-- 4

3 配置网络参数-- 5

3.1 配置-- 5

3.2 编译-- 5

3.3运行测试-- 5

4 移植NAND Flash驱动-- 6

4.1 原理图-- 6

4.2配置-- 6

4.2添加代码-- 7

4.3 编译-- 8

4.4 运行测试-- 8

5 保存环境变量到NAND Flash和添加NAND 分区信息-- 9

5.1 配置环境变量保存到NAND- 9

5.2 配置支持NAND 分区信息-- 9

5.3编译-- 10

5.4 运行测试-- 10

6 支持烧写yaffs2文件系统-- 11

6.1配置-- 11

6.2修改drivers/mtd/nand/nand_util.c- 11

6.3 编译、运行测试-- 11

7 打印CPU时钟信息并添加自己的log- 11

7.1 配置-- 11

7.2 修改arch/arm/lib/board.c- 11

7.3 修改arch/arm/cpu/arm920t/at91/cpu.c- 12

7.4  编译-- 12

7.5运行测试-- 12

7 精简u-boot13

7.1注释掉include/config_cmd_default.h中一些不用的命令-- 13

7.2注释掉include/configs/at91rm9200ek.h中一些不用的命令-- 13

7.3编译-- 14

7.4运行测试-- 14

8 支持NORFlash启动-- 14

8.1配置:修改include/configs/at91rm9200ek.h- 14

8.2编译-- 14

8.3烧写u-boot.bin到NOR FLASH- 15

1 配置

1.1修改顶层Makefile(可选)

root@zjh:/home/work/u-boot-2012.10#vi Makefile

411 $(obj)u-boot.bin:   $(obj)u-boot

412        $(OBJCOPY) ${OBJCFLAGS} -O binary $< $@

413        $(BOARD_SIZE_CHECK)

414        cp u-boot.bin /home/tftpboot        根据自己的环境修改交叉编译器前缀

我的交叉编译器版本为4.4.3

1.2配置

root@zjh:/home/work/u-boot-2012.10#vi boards.cfg

搜索at91

60 at91rm9200ek                 arm         arm920t     at91rm9200ek        atmel          at91        at91rm9200ek

61 at91rm9200ek_ram             arm         arm920t     at91rm9200ek        atmel          at91        at91rm9200ek:RAMBOOT

可以看到有两行,一个是基于Flash启动,一个是基于RAM启动,我们先配置成基于RAM启动,编译后使用原有的u-boot将新的u-boot下载到RAM,通过go命令运行

root@zjh:/home/work/u-boot-2012.10#make at91rm9200ek_ram_config

root@zjh:/home/work/u-boot-2012.10#make

以上两步可合成一步

root@zjh:/home/work/u-boot-2012.10#make at91rm9200ek_ram

编译成功后,将生成u-boot.bin,如果进行了1.1,则会将u-boot.bin拷贝到tftp服务器目录/home/tftpboot

1.3下载、运行、测试

首先查看u-boot链接地址

root@zjh:/home/work/u-boot-2012.10#vi include/configs/at91rm9200ek.h

42 #ifdefCONFIG_RAMBOOT

43 #define CONFIG_SKIP_LOWLEVEL_INIT

44 #define CONFIG_SYS_TEXT_BASE 0x20100000

45 #else

46 #defineCONFIG_SYS_TEXT_BASE 0x10000000

47 #endif

我们配置为RAM启动,将会跳过底层初始化,这是链接地址为0x20100000

启动原有的u-boot,执行如下操作

U-Boot@zjh> tftpboot 20100000u-boot.bin

emac: Starting autonegotiation...

emac: Autonegotiation complete

emac: link up, 100Mbps full-duplex

Using emac device

TFTP from server 192.168.1.100; our IP address is 192.168.1.105

Filename 'u-boot.bin'.

Load address: 0x20100000

Loading: T ###############

done

Bytes transferred = 206924 (3284c hex)

U-Boot@zjh> go 20100000

## Starting application at 0x20100000 ...

 

 

U-Boot 2012.10 (Aug 02 2013 - 10:50:07)

 

DRAM:  32 MiB

WARNING: Caches not enabled

Flash: 8 MiB

In:    serial

Out:   serial

Err:   serial

Net:   emac

Hit any key to stop autoboot:  0

U-Boot>

2 修改内存配置参数(根据芯片手册修改)

2.1 修改配置参数

root@zjh:/home/work/u-boot-2012.10#vi include/configs/at91rm9200ek.h

83 #defineCONFIG_SYS_SDRAM_SIZE       SZ_64M

09 #defineCONFIG_SYS_SDRC_CR_VAL  0x2188c159 /* set up the CONFIG_SYS_SDRAM */

2.2 编译

root@zjh:/home/work/u-boot-2012.10#make distclean && make at91rm9200ek_ram

注:最后先make distclean,再编译,否则有时可能会有问题

2.3运行测试

启动原有的u-boot,执行如下操作

U-Boot@zjh> tftpboot 20100000u-boot.bin

emac:Starting autonegotiation...

emac:Autonegotiation complete

emac: linkup, 100Mbps full-duplex

Using emacdevice

TFTP fromserver 192.168.1.100; our IP address is 192.168.1.105

Filename'u-boot.bin'.

Load address:0x20100000

Loading: T###############

done

Bytestransferred = 206924 (3284c hex)

U-Boot@zjh>go 20100000

## Startingapplication at 0x20100000 ...

 

 

U-Boot2012.10 (Aug 02 2013 - 11:24:55)

 

DRAM:  64 MiB

WARNING:Caches not enabled

Flash: 8 MiB

In:    serial

Out:   serial

Err:   serial

Net:   emac

Hit any keyto stop autoboot:  0

U-Boot>

3 配置网络参数

3.1 配置

root@zjh:/home/work/u-boot-2012.10#vi include/configs/at91rm9200ek.h

146 /*

147  * Network Driver Setting

148  */

149 #defineCONFIG_DRIVER_AT91EMAC

150 #defineCONFIG_SYS_RX_ETH_BUFFER    16

151 #defineCONFIG_RMII

152 #defineCONFIG_MII

153

154 #define CONFIG_NETMASK     255.255.255.0

155 #define CONFIG_IPADDR      192.168.1.105

156 #define CONFIG_SERVERIP    192.168.1.100

157 #define CONFIG_ETHADDR     00:0c:29:4d:e4:f4

也可以不用配置,启动u-boot后跳过命令设置

3.2 编译

root@zjh:/home/work/u-boot-2012.10#make distclean && make at91rm9200ek_ram

3.3运行测试

启动原有的u-boot,执行如下操作

U-Boot@zjh> tftpboot 20100000u-boot.bin

emac:Starting autonegotiation...

emac:Autonegotiation complete

emac: linkup, 100Mbps full-duplex

Using emacdevice

TFTP fromserver 192.168.1.100; our IP address is 192.168.1.105

Filename'u-boot.bin'.

Load address:0x20100000

Loading:###############

done

Bytestransferred = 207016 (328a8 hex)

U-Boot@zjh>go 20100000

## Startingapplication at 0x20100000 ...

 

 

U-Boot2012.10 (Aug 02 2013 - 11:33:02)

 

DRAM:  64 MiB

WARNING:Caches not enabled

Flash: 8 MiB

In:    serial

Out:   serial

Err:   serial

Net:   emac

Hit any keyto stop autoboot:  0

U-Boot>ping 192.168.1.100

emac: linkup, 100Mbps full-duplex

Using emacdevice

host192.168.1.100 is alive

4 移植NANDFlash驱动

4.1 原理图

 

4.2配置

root@zjh:/home/work/u-boot-2012.10#vi include/configs/at91rm9200ek.h

70 #define CONFIG_ATMEL_LEGACY

 

137 #include<config_cmd_default.h>

138

140 #defineCONFIG_CMD_DHCP

141 #defineCONFIG_CMD_FAT

142 #defineCONFIG_CMD_MII

143 #defineCONFIG_CMD_PING

144 #defineCONFIG_CMD_USB

145 #undefCONFIG_CMD_FPGA

146 #define CONFIG_CMD_NAND

 

148 /* NAND flash */

149 #ifdef CONFIG_CMD_NAND

150 #define CONFIG_NAND_ATMEL

151 #define CONFIG_SYS_MAX_NAND_DEVICE  1

152 #define CONFIG_SYS_NAND_BASE    0x40000000 // CS3

153 #define CONFIG_SYS_NAND_DBW_8

154 #define CONFIG_SYS_NAND_MASK_ALE    (1 << 22)

154 #define CONFIG_SYS_NAND_MASK_CLE    (1 << 21)

155 #define CONFIG_SYS_NAND_ENABLE_PIN  AT91_PIN_PC0

156 #define CONFIG_SYS_NAND_READY_PIN   AT91_PIN_PC2

157 #endif

4.2添加代码

root@zjh:/home/work/u-boot-2012.10#vi drivers/mtd/nand/atmel_nand.c

34 #include <asm/arch/at91_pmc.h>

34 #include <asm/arch/at91_mc.h>

 

void nand_init_f(void)

{

    at91_mc_t *mc = (at91_mc_t *)ATMEL_BASE_MC;

    at91_pmc_t *pmc = (at91_pmc_t*)ATMEL_BASE_PMC;

    u32 csa;

 

    csa = readl(&mc->ebi.csa);

    writel(csa | AT91_EBI_CSA_CS3A,&mc->ebi.csa);

        writel(AT91_SMC_CSR_ACSS_STANDARD |AT91_SMC_CSR_DBW_8 | AT91_SMC_CSR_WSEN | \

        AT91_SMC_CSR_NWS(5) | AT91_SMC_CSR_TDF(1)| AT91_SMC_CSR_RWSETUP(1) | \

        AT91_SMC_CSR_RWHOLD(2),&mc->smc.csr[3]);

 

    /* Enable PIOC clock */

    writel(1 << ATMEL_ID_PIOC,&pmc->pcer);

    at91_set_A_periph(AT91_PIN_PC1, 0);     /* SMOE */

    at91_set_A_periph(AT91_PIN_PC3, 0);     /* SMWE */

 

   at91_set_gpio_output(CONFIG_SYS_NAND_ENABLE_PIN, 1);

   at91_set_gpio_input(CONFIG_SYS_NAND_READY_PIN, 0);

}

 

ntatmel_nand_chip_init(int devnum, ulong base_addr)

{

    int ret;

    struct mtd_info *mtd =&nand_info[devnum];

    struct nand_chip *nand =&nand_chip[devnum];

 

nand_init_f();

}

 

static voidat91_nand_hwcontrol(struct mtd_info *mtd,

                     int cmd, unsigned intctrl)

{

   struct nand_chip *this = mtd->priv;

 

   if (ctrl& NAND_CLE)

        writeb(cmd, this->IO_ADDR_W +  CONFIG_SYS_NAND_MASK_CLE);

    else

        writeb(cmd, this->IO_ADDR_W +CONFIG_SYS_NAND_MASK_ALE);

}

 

root@zjh:/home/work/u-boot-2012.10#vi drivers/mtd/nand/nand_base.c

#include<asm/arch/gpio.h>

#include<asm/arch/at91_pio.h>

 

static voidnand_select_chip(struct mtd_info *mtd, int chipnr)

{    

   switch (chipnr) {

    case -1:

       at91_set_gpio_value(CONFIG_SYS_NAND_ENABLE_PIN, 1);

        break;

    case 0:

       at91_set_gpio_value(CONFIG_SYS_NAND_ENABLE_PIN, 0);

        break;

        default:

        BUG();

    }   

}

4.3 编译

4.4 运行测试

启动原有的u-boot,执行如下操作

U-Boot@zjh> tftpboot 20100000u-boot.bin

emac:Starting autonegotiation...

emac:Autonegotiation complete

emac: linkup, 100Mbps full-duplex

Using emacdevice

TFTP fromserver 192.168.1.100; our IP address is 192.168.1.105

Filename'u-boot.bin'.

Load address:0x20100000

Loading: T##################

done

Bytestransferred = 250916 (3d424 hex)

U-Boot@zjh>go 20100000

## Startingapplication at 0x20100000 ...

 

 

U-Boot 2012.10(Aug 05 2013 - 15:05:34)

 

DRAM:  64 MiB

WARNING:Caches not enabled

Flash: 8 MiB

NAND:  128 MiB

In:    serial

Out:   serial

Err:   serial

Net:   emac

Hit any keyto stop autoboot:  0

U-Boot>

5 保存环境变量到NAND Flash和添加NAND 分区信息

5.1 配置环境变量保存到NAND

root@zjh:/home/work/u-boot-2012.10#vi include/configs/at91rm9200ek.h

//#define CONFIG_ENV_IS_IN_FLASH

#define CONFIG_ENV_IS_IN_NAND

#define CONFIG_ENV_OFFSET 0x0

 

#defineCONFIG_ENV_SIZE                    SZ_128K

5.2 配置支持NAND 分区信息

#define CONFIG_CMD_MTDPARTS

#define CONFIG_MTD_DEVICE

 

#define MTDIDS_DEFAULT              "nand0=at91rm9200-0"

/* writeable partitions require their size and offset beerasesize aligned  */

#define MTDPARTS_DEFAULT   "mtdparts=at91rm9200-0:128k(params),"\

                                                 "4m(kernel),"\

                                                 "-(rootfs)"

5.3编译

5.4 运行测试

启动原有的u-boot,执行如下操作

U-Boot@zjh> tftpboot 20100000u-boot.bin

……

U-Boot2012.10 (Aug 05 2013 - 15:22:35)

 

DRAM:  64 MiB

WARNING:Caches not enabled

Flash: 8 MiB

NAND:  128 MiB

In:    serial

Out:   serial

Err:   serial

Net:   emac

Hit any keyto stop autoboot:  0

U-Boot>save

SavingEnvironment to NAND...

ErasingNand...

Erasing at0x0 -- 100% complete.

Writing toNand... done

U-Boot>mtd default

U-Boot>save

SavingEnvironment to NAND...

ErasingNand...

Erasing at0x0 -- 100% complete.

Writing toNand... done

U-Boot>mtd

 

device nand0<at91rm9200-0>, # parts = 3

 #: name                size            offset          mask_flags

 0: params              0x00020000      0x00000000      0

 1: kernel              0x00400000      0x00020000      0

 2: rootfs              0x07be0000      0x00420000      0

 

activepartition: nand0,0 - (params) 0x00020000 @ 0x00000000

 

defaults:

mtdids  : nand0=at91rm9200-0

mtdparts:mtdparts=at91rm9200-0:128k(params),4m(kernel),-(rootfs)

U-Boot>

6 支持烧写yaffs2文件系统

6.1配置

root@zjh:/home/work/u-boot-2012.10#vi include/configs/at91rm9200ek.h

#define CONFIG_CMD_NAND_YAFFS

6.2修改drivers/mtd/nand/nand_util.c

if (!need_skip && !(flags& WITH_DROP_FFS) && !(flags &WITH_YAFFS_OOB)) {

              rval= nand_write (nand, offset, length, buffer);

              if(rval == 0)

                     return0;

 

              *length= 0;

              printf("NAND write to offset %llx failed %d\n",

                     offset,rval);

              returnrval;

       }

……

       if(flags & WITH_YAFFS_OOB) {

                     intpage, pages;

                     size_tpagesize = nand->writesize;

                     size_tpagesize_oob = pagesize + nand->oobsize;

                     structmtd_oob_ops ops;

 

                     ops.len= pagesize;

                     ops.ooblen= nand->oobsize;

                     ops.mode= MTD_OOB_RAW;

                     ops.ooboffs = 0;

……

6.3 编译、运行测试

7 打印CPU时钟信息并添加自己的log

7.1 配置

root@zjh:/home/work/u-boot-2012.10#vi include/configs/at91rm9200ek.h

#define CONFIG_DISPLAY_CPUINFO

7.2 修改arch/arm/lib/board.c

static int display_banner(void)

{

       printf("\n\n%s\n\n",version_string);

       printf("----成都思晗科技有限公司-----赵建辉\n\n");

       debug("U-Bootcode: %08lX -> %08lX  BSS: ->%08lX\n",

              _TEXT_BASE,

              _bss_start_ofs + _TEXT_BASE,_bss_end_ofs + _TEXT_BASE);

#ifdef CONFIG_MODEM_SUPPORT

       debug("ModemSupport enabled\n");

#endif

#ifdef CONFIG_USE_IRQ

       debug("IRQStack: %08lx\n", IRQ_STACK_START);

       debug("FIQStack: %08lx\n", FIQ_STACK_START);

#endif

 

       return(0);

}

7.3 修改arch/arm/cpu/arm920t/at91/cpu.c

#ifdefined(CONFIG_DISPLAY_CPUINFO)

intprint_cpuinfo(void)

{

       char buf[32];

 

       printf("CPU: %s\n",CONFIG_SYS_ATMEL_CPU_NAME);

       printf("Crystal frequency: %8sMHz\n",

                                   strmhz(buf,get_main_clk_rate()));

       printf("CPU clock        : %8s MHz\n",

                                   strmhz(buf,get_cpu_clk_rate()));

       printf("Master clock     : %8s MHz\n",

                                   strmhz(buf,get_mck_clk_rate()));

 

       return 0;

}

#endif

7.4  编译

7.5运行测试

## Startingapplication at 0x20100000 ...

 

 

U-Boot2012.10 (Aug 05 2013 - 15:54:35)

 

----成都思晗科技有限公司-----赵建辉

 

CPU: AT91RM9200

Crystal frequency:  18.432 MHz

CPU clock       :  179.712 MHz

Master clock    :   59.904 MHz

DRAM:  64 MiB

WARNING:Caches not enabled

Flash: 8 MiB

NAND:  128 MiB

In:    serial

Out:   serial

Err:   serial

Net:   emac

Hit any keyto stop autoboot:  0

U-Boot>

7 精简u-boot

7.1注释掉include/config_cmd_default.h中一些不用的命令

//#define CONFIG_CMD_CONSOLE  /* coninfo                     */

//#define CONFIG_CMD_EDITENV   /* editenv                     */

//#define CONFIG_CMD_FPGA         /* FPGA configuration Support    */

//#define CONFIG_CMD_IMI             /* iminfo               */

//#define CONFIG_CMD_ITEST  /* Integer (and string) test     */

//#define CONFIG_CMD_LOADS       /* loads                 */

//#define CONFIG_CMD_MISC          /* Misc functions like sleep etc*/

//#define CONFIG_CMD_NFS            /* NFS support                    */

//#define CONFIG_CMD_SETGETDCR     /* DCR support on 4xx         */

//#define CONFIG_CMD_SOURCE     /* "source" command support       */

//#define CONFIG_CMD_XIMG         /* Load part of Multi Image  */

7.2注释掉include/configs/at91rm9200ek.h中一些不用的命令

//#define CONFIG_CMD_DHCP

//#define CONFIG_CMD_FAT

//#define CONFIG_CMD_USB

//#undef CONFIG_CMD_FPGA

 

……

/*

 * USB Config

 */

#ifdef CONFIG_CMD_USB

#defineCONFIG_USB_ATMEL                 1

#defineCONFIG_USB_OHCI_NEW                 1

#defineCONFIG_USB_KEYBOARD                1

#defineCONFIG_USB_STORAGE                   1

#defineCONFIG_DOS_PARTITION                 1

 

#defineCONFIG_SYS_USB_OHCI_CPU_INIT        1

#defineCONFIG_SYS_USB_OHCI_REGS_BASE           ATMEL_USB_HOST_BASE

#defineCONFIG_SYS_USB_OHCI_SLOT_NAME          "at91rm9200"

#defineCONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS       15

#endif

7.3编译

root@zjh:/home/work/u-boot-2012.10#make distclean && make at91rm9200ek_ram

查看u-boot.bin大小

root@zjh:/home/work/u-boot-2012.10#ll -h u-boot.bin

-rw-r--r-- 1root root 203K 2013-08-05 16:25 u-boot.bin

之前是260k

7.4运行测试

启动原有的u-boot,执行如下操作

 

U-Boot2012.10 (Aug 05 2013 - 16:24:26)

 

----成都思晗科技有限公司-----赵建辉

 

CPU:AT91RM9200

Crystalfrequency:   18.432 MHz

CPUclock        :  179.712 MHz

Masterclock     :   59.904 MHz

DRAM:  64 MiB

有点问题

8 支持NOR Flash启动

8.1配置:修改include/configs/at91rm9200ek.h

#ifdefCONFIG_RAMBOOT

#defineCONFIG_SKIP_LOWLEVEL_INIT

#defineCONFIG_SYS_TEXT_BASE 0x20100000

#else

#defineCONFIG_SYS_TEXT_BASE 0x00000000

#endif

 

8.2编译

root@zjh:/home/work/u-boot-2012.10#make distclean && make at91rm9200ek

8.3烧写u-boot.bin到NOR FLASH

U-Boot@zjh>tftp 21000000 u-boot.bin

emac:Starting autonegotiation...

emac:Autonegotiation complete

emac: linkup, 100Mbps full-duplex

Using emacdevice

TFTP fromserver 192.168.1.100; our IP address is 192.168.1.105

Filename'u-boot.bin'.

Load address:0x21000000

Loading: T###############

done

Bytestransferred = 207836 (32bdc hex)

U-Boot@zjh>protect off all

Un-ProtectFlash Bank # 1

.......................................................................................................................................done

U-Boot@zjh>erase 10000000 +3ffff

 

...........done

Erased 11sectors

U-Boot@zjh>cp.b 21000000 10000000 3ffff

Copy toFlash... done

U-Boot@zjh>reset

resetting ...

 

 

U-Boot2012.10 (Aug 05 2013 - 16:32:02)

 

----成都思晗科技有限公司-----赵建辉

 

CPU: AT91RM9200

Crystalfrequency:   18.430 MHz

CPUclock        :  179.692 MHz

Masterclock     :   59.897 MHz

DRAM:  64 MiB

WARNING:Caches not enabled

Flash: 8 MiB

NAND:  128 MiB

In:    serial

Out:   serial

Err:   serial

Net:   emac

Hit any keyto stop autoboot:  0

U-Boot>

你可能感兴趣的:(Flash)