TQ2440 u-boot-2012.04.01移植三支持NOR Flash

时间:2022-10-17 16:35:56
继 u-boot-2012.04.01移植二支持NAND启动,继续修改代码支持NAND Flash、NOR Flash。最后直接用NOR Flash里的u-boot烧写自己移植的u-boot到NAND,方便电脑没有并口或手上没有openjtag,照样能移植u-boot,当然有openjtag更方便。

开发环境:
系统:ubuntu 10.04.4
单板:tq2440
NAND FLASH:K9F1216U0A 256MB
NOR Flash:EN29LV160AB 2MB
SDRAM:HY57V561620 x2 64MB
NET:DM9000AEP
编译器:arm-linux-gcc-4.3.2

搭建开发环境详见ubuntu 10.04.4开发环境配置。
目标:
1.支持NOR Flash启动,串口正常输出
2.支持NAND启动
3.支持DM9000网卡
4.添加u-boot菜单
5.裁剪u-boot及制作补丁

虽然单板现在支持NAND Flash、NOR Flash启动,但u-boot还不支持读写NAND Flash、NOR Flash,继续完善u-boot.修改u-boot支持NOR Flash

1.定义DEBUG,输出调试信息

drivers/mtd/cfi_flash.c:增加宏定义

#define _DEBUG 1//*add print message

#define  DEBUG 1//*add print message

change@change:~$ cd Si/TQ2440/u-boot-2012.04.01/
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make distclean 
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make TQ2440_config 
Configuring for TQ2440 board...
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make

编译成功,烧写到NAND启动串口输出

U-Boot 2012.04.01 (May 03 2013 - 10:25:00)


CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: fwc addr (null) cmd f0 00f0 16bit x 16 bit
fwc addr 0000aaaa cmd aa 00aa 16bit x 16 bit
fwc addr 00005554 cmd 55 0055 16bit x 16 bit
fwc addr 0000aaaa cmd 90 0090 16bit x 16 bit
fwc addr (null) cmd f0 00f0 16bit x 16 bit
JEDEC PROBE: ID f0 ea00 0
fwc addr (null) cmd ff 00ff 16bit x 16 bit
fwc addr (null) cmd 90 0090 16bit x 16 bit
fwc addr (null) cmd ff 00ff 16bit x 16 bit
JEDEC PROBE: ID 90 ea00 0
0 KB
*** Warning - bad CRC, using default environment


In:    serial
Out:   serial
Err:   serial
Net:   no support
TQ2440 # 
上面是NOR Flash发出的各种命令,识别出JEDEC PROBE: ID f0 ea00 0

2.修改代码

change@change:~/Si/TQ2440/u-boot-2012.04.01$ grep "JEDEC PROBE" * -nR
drivers/mtd/cfi_flash.c:1699:                           debug("JEDEC PROBE: ID %x %x %x\n",
Binary file drivers/mtd/libmtd.o matches
Binary file drivers/mtd/cfi_flash.o matches
Binary file u-boot matches
Binary file u-boot.bin matches
change@change:~/Si/TQ2440/u-boot-2012.04.01$ 

进入drivers/mtd/cfi_flash.c:1699,看到打印ID后会跟jedec_flash_mach匹配,找到数组jedec_table[],去找与之匹配的id f0 ea00 0,找不到就增加该设备ID

结合NOR Flash手册修改代码drivers/mtd/jedec_flash.c370:

{
.mfr_id = 0xf0,//nanufaction id
.dev_id = 0xea00,//device id
.name = "TQ2440 NOR",
.uaddr = {/*Nor flash */
[1] = MTD_UADDR_0x0555_0x02AA /* x16 */
},
.DevSize = SIZE_2MiB,
.CmdSet = P_ID_AMD_STD,
.NumEraseRegions= 4,
.regions = {
ERASEINFO(0x4000, 1),
ERASEINFO(0x2000, 2),
ERASEINFO(0x8000, 1),
ERASEINFO(0x10000, 31),
}
},

change@change:~/Si/TQ2440/u-boot-2012.04.01$ make distclean 
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make TQ2440_config 
Configuring for TQ2440 board...
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make

烧写测试,NAND启动串口输出

U-Boot 2012.04.01 (May 03 2013 - 11:21:29)


CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: fwc addr (null) cmd f0 00f0 16bit x 16 bit
fwc addr 0000aaaa cmd aa 00aa 16bit x 16 bit
fwc addr 00005554 cmd 55 0055 16bit x 16 bit
fwc addr 0000aaaa cmd 90 0090 16bit x 16 bit
fwc addr (null) cmd f0 00f0 16bit x 16 bit
JEDEC PROBE: ID f0 ea00 0
ERROR: too many flash sectors
1 MiB
*** Warning - bad CRC, using default environment


In:    serial
Out:   serial
Err:   serial
Net:   no support
TQ2440 # 

change@change:~/Si/TQ2440/u-boot-2012.04.01$ grep "too many flash sectors" * -nR
drivers/mtd/cfi_flash.c:2020:                                   printf("ERROR: too many flash sectors\n");
Binary file drivers/mtd/libmtd.o matches
drivers/mtd/jedec_flash.c:444:                          printf("ERROR: too many flash sectors\n");
Binary file drivers/mtd/jedec_flash.o matches
Binary file drivers/mtd/cfi_flash.o matches
Binary file u-boot matches
Binary file u-boot.bin matches
change@change:~/Si/TQ2440/u-boot-2012.04.01$ 

修改include/configs/TQ2440.h191:

//#define CONFIG_SYS_MAX_FLASH_SECT (19)
#define CONFIG_SYS_MAX_FLASH_SECT (128)

change@change:~/Si/TQ2440/u-boot-2012.04.01$ make distclean 
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make TQ2440_config 
Configuring for TQ2440 board...
change@change:~/Si/TQ2440/u-boot-2012.04.01$ make

烧写测试,NAND启动串口输出

U-Boot 2012.04.01 (May 03 2013 - 11:33:35)


CPUID: 32440001
FCLK:      400 MHz
HCLK:      100 MHz
PCLK:       50 MHz
DRAM:  64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
*** Warning - bad CRC, using default environment


In:    serial
Out:   serial
Err:   serial
Net:   no support
TQ2440 # flinfo


Bank # 1: TQ2440 NOR Flash flash (16 x 16)  Size: 2 MB in 35 Sectors
  AMD Legacy command set, Manufacturer ID: 0xF0, Device ID: 0xEA00
  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   RO   00050000   RO   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 # 

基本正常,可以看到单板支持NOR Flash