u-boot-2012.04.01移植到TQ2440(三):移植NOR FLASH

时间:2021-06-10 16:36:29

一、    移植NOR FLASH

去掉配置文件include\configs\tq2440.h中的宏并修改代码段基地址

#define CONFIG_SYS_TEXT_BASE 0x0

//#defineCONFIG_SKIP_LOWLEVEL_INIT

在board\tq2440\lowlevel_init.S修改SDRAM’刷新频率

#define REFCNT                     0x4f4

该文件中的这三条指令其实可以用一条指令替换adrl r0, SMRDATA

ldr     r0, =SMRDATA

ldr    r1, _TEXT_BASE

sub  r0, r0, r1

进入/drivers/mtd/cfi_flash.c中的flash_init()函数

在该文件开头定义宏DEBUG打开调试信息

#define DEBUG 1

#define _DEBUG     1

重新编译

用原先的u-boot从NOR FLASH启动,将新u-boot.bin烧到NOR FLASH

TQ2440 # tftp 32000000u-boot.bin

dm9000 i/o: 0x20000000, id:0x90000a46

DM9000: running in 16 bitmode

MAC: 00:0c:29:4d:e4:f4

Using dm9000 device

TFTP from server172.28.12.60; our IP address is 172.28.12.10

Filename 'u-boot.bin'.

Load address: 0x32000000

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

done

Bytes transferred = 180828(2c25c hex)

TQ2440 # protect off all

Un-Protect Flash Bank # 1

TQ2440 # erase 0 +30000

 

...... done

Erased 6 sectors

TQ2440 # cp.b 32000000 030000

Copy to Flash...9....8....7....6....5....4....3....2....1....done

TQ2440 #

重启开发板

U-Boot 2012.04.01 (Dec 292012 - 14:25:05)

 

CPUID: 32440001

FCLK:      400 MHz

HCLK:      100 MHz

PCLK:       50 MHz

DRAM:  64 MiB

WARNING: Caches not enabled

Flash: fwc addr (null) cmdf0 00f0 16bit x 16 bit

fwc addr 0000aaaa cmd aa00aa 16bit x 16 bit

fwc addr 00005554 cmd 550055 16bit x 16 bit

fwc addr 0000aaaa cmd 900090 16bit x 16 bit

fwc addr (null) cmd f0 00f016bit x 16 bit

JEDEC PROBE: ID 1c2249 0

fwc addr (null) cmd ff 00ff16bit x 16 bit

fwc addr (null) cmd 90 009016bit x 16 bit

fwc addr (null) cmd ff 00ff16bit x 16 bit

JEDEC PROBE: ID 13 ea00 0

*** failed ***

### ERROR ### Please RESETthe board ###

搜索“JEDEC PROBE:

  flash_read_jedec_ids(info);

                       debug("JEDECPROBE: ID %x %x %x\n",

                                     info->manufacturer_id,

                                     info->device_id,

                                     info->device_id2);

                       if (jedec_flash_match(info,info->start[0]))

                              break;

                       else

                              unmap_physmem((void*)info->start[0],

                                           MAP_NOCACHE);

drivers\mtd\jedec_flash.c中的jedec_flash_match()函数:

/*-----------------------------------------------------------------------

 * match jedec ids against table. If a match isfound, fill flash_info entry

 */

intjedec_flash_match(flash_info_t *info, ulong base)

{

  int ret = 0;

  int i;

  ulong mask = 0xFFFF;

  if (info->chipwidth == 1)

         mask = 0xFF;

 

  for (i = 0; i < ARRAY_SIZE(jedec_table); i++) {

         if ((jedec_table[i].mfr_id & mask) ==(info->manufacturer_id & mask) &&

            (jedec_table[i].dev_id & mask) == (info->device_id & mask)) {

                fill_info(info, &jedec_table[i], base);

                ret = 1;

                break;

         }

  }

  return ret;

}

flash_read_jedec_ids(info)读出了我们的开发板的NOR FLASH的厂商ID为0x1c,设备ID为0x2249

jedec_flash_match(info,info->start[0])将读出的信息与jedec_table[]数组进行匹配,如果有匹配成功则填充flashin信息并返回1,否则返回0。说明这里没有匹配成功,需要在jedec_table[]数组中添加我们自己开发板的NOR FLASH信息。

修改配置文件include\configs\tq2440.h

#defineCONFIG_SYS_FLASH_LEGACY_1024Kx16

在drivers\mtd\jedec_flash.c文件中jedec_table[]数组中增加EN29LV160AB的配置根据芯片手册。

#ifdefCONFIG_SYS_FLASH_LEGACY_1024Kx16

    /* TQ2440 EN29LV160AB */

    {  

            .mfr_id     = 0x1c,  /* 厂商ID */

            .dev_id     = 0x2249,  /* 设备ID */

            .name      = "EON EN29LV160AB",

            .uaddr      = {/* 因为NOR FLASH的ADDR0接到了S3C2440的ADDR1 */

                [1] = MTD_UADDR_0x0555_0x02AA/* x16 */

            }, 

            .DevSize    = SIZE_2MiB,

            .CmdSet     = P_ID_AMD_STD,

            .NumEraseRegions= 4,

            .regions    = {

                ERASEINFO(0x04000, 1),

                ERASEINFO(0x02000, 2), 

                ERASEINFO(0x08000, 1), 

                ERASEINFO(0x10000, 31),

            }  

        }, 

#endif

重新编译通过工具将u-boot.bin烧写到NOR FLASH

U-Boot 2012.04.01 (Dec 292012 - 15:26:09)

 

CPUID: 32440001

FCLK:      400 MHz

HCLK:      100 MHz

PCLK:       50 MHz

DRAM:  64 MiB

WARNING: Caches not enabled

Flash: fwc addr (null) cmdf0 00f0 16bit x 16 bit

fwc addr 0000aaaa cmd aa00aa 16bit x 16 bit

fwc addr 00005554 cmd 550055 16bit x 16 bit

fwc addr 0000aaaa cmd 900090 16bit x 16 bit

fwc addr (null) cmd f0 00f016bit x 16 bit

JEDEC PROBE: ID 1c 2249 0

ERROR: too manyflash sectors

2 MiB

*** Warning - bad CRC, usingdefault environment

 

In:    serial

Out:   serial

Err:   serial

Net:   No ethernet found.

TQ2440 #

出现一个错误ERROR: too many flash sectors

修改配置文件include\configs\tq2440.h

#defineCONFIG_SYS_MAX_FLASH_SECT (35)

取消调试信息drivers\mtd\cfi_flash.c

//#define DEBUG    1

//#define _DEBUG  1

重新编译

U-Boot 2012.04.01 (Dec 292012 - 15:33:09)

 

CPUID: 32440001

FCLK:      400 MHz

HCLK:      100 MHz

PCLK:       50 MHz

DRAM:  64 MiB

WARNING: Caches not enabled

Flash: 2 MiB

*** Warning - bad CRC, usingdefault environment

 

In:    serial

Out:   serial

Err:   serial

Net:   No ethernet found.

TQ2440 # fflinfo

 

Bank # 1: EON EN29LV160ABflash (16 x 16)  Size: 2 MB in 35 Sectors

  AMD Legacy command set, Manufacturer ID:0x1C, Device ID: 0x2249

  Erase timeout: 30000 ms, write timeout: 100ms

 

  Sector Start Addresses:

  00000000  RO   00004000   RO  00006000   RO   00008000  RO   00010000   RO

  00020000  RO   00030000        00040000        00050000        00060000     

  00070000  RO   00080000        00090000        000A0000        000B0000     

  000C0000        000D0000        000E0000        000F0000        00100000     

  00110000       00120000        00130000        00140000        00150000     

  00160000        00170000        00180000        00190000        001A0000     

  001B0000        001C0000        001D0000        001E0000        001F0000     

TQ2440 # md.b 32000000 a

32000000: 13 00 00 ea 14 f09f e5 14 f0    ..........

TQ2440 # erase 100000 +a

 

. done

Erased 1 sectors

TQ2440 # cp.b 32000000100000 a

Copy to Flash... done

TQ2440 # md.b 100000 a

00100000: 13 00 00 ea 14 f09f e5 14 f0    ..........