NAND flash移植
开发板配置三星256M nand flash K9F2G08UA0。
u-boot源码中默认的nand配置参数也同样是256M,所以很多地方则无需修改。如果是512M或者更大2G的flash则需要对应修改。
256M Nand flash 框图:
总共2048 Blocks
1 Block = 64 Pages
1 Page = 2K Bytes
1 Block = 64 * 2K Bytes = 128K Bytes
1 Device = 2048 * 128K Bytes = 256M Bytes
1、修改单板配置 u-boot-2013.04-rc1/include/configs/smdk6410.h
默认为256M,所以以下参数不做修改
/* NAND chip page size */
#define CONFIG_SYS_NAND_PAGE_SIZE 2048
/* NAND chip block size */
#define CONFIG_SYS_NAND_BLOCK_SIZE (128 * 1024)
/* NAND chip page per block count */
#define CONFIG_SYS_NAND_PAGE_COUNT 64
/* Location of the bad-block */
#define CONFIG_SYS_NAND_BAD_BLOCK_POS 0
/* Extra address cycle for > 128MiB */
#define CONFIG_SYS_NAND_5_ADDR_CYCLE
如果是2G nand K9GAG08U0D,则修改为如下
/* NAND chip page size */
#define CONFIG_SYS_NAND_PAGE_SIZE 4096
/* NAND chip block size */
#define CONFIG_SYS_NAND_BLOCK_SIZE (128 * 4096)
/* NAND chip page per block count */
#define CONFIG_SYS_NAND_PAGE_COUNT 128
/* Location of the bad-block */
#define CONFIG_SYS_NAND_BAD_BLOCK_POS 0
/* Extra address cycle for > 128MiB */
#define CONFIG_SYS_NAND_5_ADDR_CYCLE
2、修改芯片类型定义;/home/eric/Documents/u-boot-2013.04-rc1-1104/drivers/mtd/nand/nand_ids.c
97行修改:将原有的替换掉,ID为0xDA,一个ID只能有一个条目。
{"NAND 256MiB 3,3V 8-bit", 0xDA, 2048, 256, (64*2048), LP_OPTIONS},//eric++2017-11-04
//{"NAND 256MiB 3,3V 8-bit", 0xDA, 0, 256, 0, LP_OPTIONS},
如果是2G的flash,则需要对应修改,ID为0xD5的条目为
{"NAND 2GiB 3,3V 8-bit", 0xD5, 4096, 2048, (128*4096), LP_OPTIONS},
3、编译,启动
NAND: nand_get_flash_type: second ID read did not match 00,04 against 00,00
No NAND device found!!!
0 MiB
*** Warning - bad CRC, using default environment
出现了错误,nand_get_flash_type: second ID read did not match 00,04 against 00,00。导致No NAND device found!!!
这是由于,nand 在初始化的时候,nand控制器时序配置不正确引起的。
为了在SD卡启动的时候就可以成功检测到NAND。
修改/home/eric/Documents/u-boot-2013.04-rc1-1104/drivers/mtd/nand/s3c64xx.c
262行添加:初始化nand 控制器主要的三个参数。TACLS:3,TWRPH0:7,TWRPH1:7
NFCONT_REG = (NFCONT_REG & ~NFCONT_WP) | NFCONT_ENABLE | 0x6;
NFCONF_REG = NFCONF_ECC_4BIT | (3<<12) | (7<<8) | (7<<4) ;//eric++ 2017-11-04
也可以在后续移植NAND_BOOT启动的时候,在lowleve_init.s中修改,
#ifdef CONFIG_BOOT_NAND
/*
* NAND Interface init for SMDK6410
*/
nand_asm_init:
ldr r0, =ELFIN_NAND_BASE
ldr r1, [r0, #NFCONF_OFFSET]
orr r1, r1, #0x70//TWRPH1 = 7
orr r1, r1, #0x3700//TWRPH0=7,TACLS=3
str r1, [r0, #NFCONF_OFFSET]
ldr r1, [r0, #NFCONT_OFFSET]
orr r1, r1, #0x07
str r1, [r0, #NFCONT_OFFSET]
mov pc, lr
#endif
4、重新编译,启动
U-Boot 2013.04-rc1 (Nov 04 2017 - 21:56:06) for SMDK6410
CPU: S3C6410@533MHz
Fclk = 533MHz, Hclk = 133MHz, Pclk = 66MHz (ASYNC Mode)
Board: SMDK6410
DRAM: 128 MiB
WARNING: Caches not enabled
Flash: *** failed ***
NAND: 256 MiB
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
Net: CS8900-0
Hit any key to stop autoboot: 0
NAND read: device 0 offset 0x60000, size 0x1c0000
1835008 bytes read: OK
至此,已经可以成功检测到256M的nand flash!,并自动执行了NAND read命令,读取flash成功。
5、注意到每次启动都会提示 * Warning - bad CRC, using default environment,这是由于smdk6410中,默认定义将环境数据ENV保存到nand Flash中,而上电后nand Flash中并没有有效的ENV数据,所以采用默认数值。
#define CONFIG_ENV_IS_IN_NAND
1、即便执行了saveenv,也会保存失败,原因是在/home/eric/Documents/u-boot-2013.04-rc1-1104/common/env_nend.c中,保存时判断条件。
#if defined(ENV_IS_EMBEDDED) || defined(CONFIG_NAND_ENV_DST)
由于并没有定义CONFIG_NAND_ENV_DST,所以无法保存成功!等后续u-boot从nandflash中启动的时候,便可顺利保存
2、可以修改#define CONFIG_ENV_IS_IN_NAND为#ENV_IS_IN_MMC,并执行saveenv指令就可以将ENV保存在SD卡中。每次上电将自动加载保存的数据。