s3c2440 移值u-boot-2016.03 第4篇 支持NAND flash 识别

1, /include/configs/smdk2440.h
中添加
#define CONFIG_CMD_NAND
编译
drivers/mtd/nand/built-in.o: In function `nand_init_chip':
/u-boot-2016.03/drivers/mtd/nand/nand.c:76: undefined reference to `board_nand_init'
发现是少了文件
/drivers/mtd/nand/s3c2410_nand.c 复制为
/drivers/mtd/nand/s3c2440_nand.c 打开 里面的 所有 2410 换为 2440

drivers/mtd/nand/Makefile
添加一行
obj-$(CONFIG_NAND_S3C2440) += s3c2440_nand.o

2, 重新编辑
编译通过了,应该是用不上,烧写试机
NAND: 0 MiB 虽然没有报错,但是未实别出来。

3, 修改代码支持 NAND FLASH
2410 和 2440 控制寄存器有些不同,可能是这些原因。
在 nand_scan() 中扫 NAND FLASH ,实别出来容量大小。
/drivers/mtd/nand/nand_base.c
ret = nand_scan_ident(mtd, maxchips, NULL);
if (!ret)
ret = nand_scan_tail(mtd);
return ret;

原理和 NOR FLASH 差不多,实别出来ID 比较就知道大小了

应该是对应 s3c2440_nand.c 里面的
int board_nand_init(struct nand_chip *nand)
{
初始化修改,尽量使用定义的方式,方便 后期修改
//cfg = S3C2440_NFCONF_EN; 取消 15位 用不上 2440 中是保留位

smdk2440.h 中添加定义
#define CONFIG_S3C24XX_CUSTOM_NAND_TIMING
#define CONFIG_S3C24XX_TACLS 1
#define CONFIG_S3C24XX_TWRPH0 2
#define CONFIG_S3C24XX_TWRPH1 1
去掉 硬件 ECC
#define CONFIG_SYS_S3C2440_NAND_HWECC

4, 添加 #define DEBUG 打开调试信息
NAND: board_nand_init()
end of nand_init
hwcontrol(): 0xff 0x83
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0x90 0x83
hwcontrol(): 0x00 0x85
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0x90 0x83
hwcontrol(): 0x00 0x85
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0x90 0x83
hwcontrol(): 0x40 0x85
hwcontrol(): 0xffffffff 0x81
dev_ready
hwcontrol(): 0xffffffff 0x80
0 MiB

0x81 最后一位是1表示选中
0x83 ..选中
0x85 ..选中
0x80 最后一位是0就是不选中

board_nand_init() 还应该是有问题的。
加上 启用 nfcont 控制器
/* 4 ECC
* 1 CE 先不选中,用的时候在选中
* 0 启动 flash controller
*/
writel(1<<4 | 1<<1 | 1, &nand_reg->nfcont);

修改选中 及 命令 地址 寄存器定义, 注意这里是 ! NCLE
s3c24x0_hwcontrol()
if (!(ctrl & NAND_CLE))
IO_ADDR_W |= S3C2440_ADDR_NCLE;
if (!(ctrl & NAND_ALE))
IO_ADDR_W |= S3C2440_ADDR_NALE;
对比 2410 和 2440 选中控制位不同,进行修改。
if (ctrl & NAND_NCE)
writel(readl(&nand->nfconf) & ~S3C2440_NFCONF_nFCE,
&nand->nfconf);
else
writel(readl(&nand->nfconf) | S3C2440_NFCONF_nFCE,
&nand->nfconf);

修改
#define S3C2440_NFCONF_nFCE (1<<1)
其它的也修改下 参照手册
#define S3C2440_NFCONF_EN (1<<15)
#define S3C2440_NFCONF_512BYTE (1<<14)
#define S3C2440_NFCONF_4STEP (1<<13)
#define S3C2440_NFCONF_INITECC (1<<12)
#define S3C2440_NFCONF_nFCE (1<<1)
#define S3C2440_NFCONF_TACLS(x) ((x)<<12)
#define S3C2440_NFCONF_TWRPH0(x) ((x)<<8)
#define S3C2440_NFCONF_TWRPH1(x) ((x)<<4)
#define S3C2440_ADDR_NALE 8
#define S3C2440_ADDR_NCLE 0xc



nane_base.c
这里看下,默认的 nand_base 中的 取消选中的功能
static void nand_select_chip(struct mtd_info *mtd, int chipnr)
{
struct nand_chip *chip = mtd->priv;

switch (chipnr) {
case -1:
chip->cmd_ctrl(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE);
break;
case 0:
break;

default:
BUG();
}

对应的 s3c2440_nand 中的就是 调用这里
writel(readl(&nand->nfcont) | S3C2440_NFCONF_nFCE, &nand->nfcont);

ps: 经过后期 试验,发现,不能 nand write ,改进方法,见 u-boot 最后一篇的 补丁。 

posted @ 2016-05-18 10:03  宁次  阅读(1768)  评论(0编辑  收藏  举报