board_init_r
#if defined(CONFIG_CMD_NAND)
puts("NAND: ");
nand_init(); /* go init the NAND */
#endif
void nand_init(void) Nand.c (drivers\mtd\nand
nand_init_chip(i);
board_nand_init //设置nand_chip 结构体。提供底层函数
nand->select_chip = NULL;
nand->cmd_ctrl = s3c2440_hwcontrol;
nand->dev_ready = s3c2440_dev_ready;
nand_scan
nand_scan_ident
nand_set_defaults(chip, busw);
chip->select_chip = nand_select_chip;
chip->cmdfunc = nand_command;
nand_get_flash_type
chip->select_chip(mtd, 0);
chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
nand_command (struct mtd_info *mtd, unsigned int command, int column, int page_addr)// 发地址,发命令
chip->cmd_ctrl(mtd, command, ctrl);
s3c2440_hwcontrol
static void s3c2440_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
*maf_id = chip->read_byte(mtd);
*dev_id = chip->read_byte(mtd);
s3c2440_hwcontrol 自己重写
struct nand_chip *chip = mtd->priv;
struct s3c2440_nand *nand = s3c2440_get_base_nand();
if(ctrl & NAND_CLE)
{
/*发命令*/
writeb(dat,&nand->nfcmd);
}
else if(ctrl & NAND_ALE)
{
/*发地址*/
writeb(dat,&nand->nfaddr);// 地址
}
自己编写 s3c2440_nand_select 函数
struct s3c2440_nand *nand = s3c2440_get_base_nand();
switch (chipnr) {
case -1: /*不选*/
nand->nfcont |= (1 <<1);
break;
case 0: /*选中,没有进行操作*/
nand->nfcont &= ~(1 <<1);
break;
default:
BUG();
}
U-Boot 2012.04.01 (Jul 23 2016 - 13:18:18)
CPUID: 32440001
FCLK: 400 MHz
HCLK: 100 MHz
PCLK: 50 MHz
DRAM: 64 MiB
WARNING: Caches not enabled
Flash: 2 MiB
NAND: 256 MiB //能够识别出 nand
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
Net: CS8900-0
nand erease 0 80000
nand write 0 0 80000 0:nor 0 nand 80000 长度
nand read 30000000 0 80000//3000000 读到哪里 0 从nand 0 开始读 80000 读的长度
cmp.b 0 30000000
U-Boot 2012.04.01 (Jul 23 2016 - 13:18:18)
nand 启动
CPUID: 32440001
FCLK: 400 MHz
HCLK: 100 MHz
PCLK: 50 MHz
DRAM: 64 MiB
WARNING: Caches not enabled
Flash: 0 KB // nand 启动0 地址对应片内内存,无法读取 nor flash的值
NAND: 256 MiB
*** Warning - bad CRC, using default environment
In: serial
Out: serial
Err: serial
Net: CS8900-0
SMDK2410 #