linux flash驱动程序,linux之NOR FLASH驱动程序

使用UBOOT体验NOR FLASH的操作(开发板设为NOR启动,进入UBOOT)

先使用OpenJTAG烧写UBOOT到NOR FLASH

1. 读数据

md.b 0

2. 读ID

NOR手册上:

往地址555H写AAH

往地址2AAH写55H

往地址555H写90H

读0地址得到厂家ID: C2H

读1地址得到设备ID: 22DAH或225BH

退出读ID状态: 给任意地址写F0H

2440的A1接到NOR的A0,所以2440发出(555h<<1), NOR才能收到555h这个地址

UBOOT怎么操作?

往地址AAAH写AAH mw.w aaa aa

往地址554写55H mw.w 554 55

往地址AAAH写90H mw.w aaa 90

读0地址得到厂家ID: C2H md.w 0 1

读2地址得到设备ID: 22DAH或225BH md.w 2 1

退出读ID状态: mw.w 0 f0

3. NOR有两种规范, jedec, cfi(common flash interface)

读取CFI信息

NOR手册:

进入CFI模式 往55H写入98H

读数据: 读10H得到0051

读11H得到0052

读12H得到0059

读27H得到容量

2440的A1接到NOR的A0,所以2440发出(555h<<1), NOR才能收到555h这个地址

UBOOT怎么操作?

进入CFI模式 往AAH写入98H mw.w aa 98

读数据: 读20H得到0051 md.w 20 1

读22H得到0052 md.w 22 1

读24H得到0059 md.w 24 1

读4EH得到容量 md.w 4e 1

退出CFI模式 mw.w 0 f0

4. 写数据: 在地址0x100000写入0x1234

md.w 100000 1 // 得到ffff

mw.w 100000 1234

md.w 100000 1 // 还是ffff

NOR手册:

往地址555H写AAH

往地址2AAH写55H

往地址555H写A0H

往地址PA写PD

2440的A1接到NOR的A0,所以2440发出(555h<<1), NOR才能收到555h这个地址

UBOOT怎么操作?

往地址AAAH写AAH mw.w aaa aa

往地址554H写55H mw.w 554 55

往地址AAAH写A0H mw.w aaa a0

往地址0x100000写1234h mw.w 100000 1234

NOR FLASH驱动程序框架

测试1:通过配置内核支持NOR FLASH

1. make menuconfig

-> Device Drivers

-> Memory Technology Device (MTD) support

-> Mapping drivers for chip access

CFI Flash device in physical memory map

(0x0) Physical start address of flash mapping // 物理基地址

(0x1000000) Physical length of flash mapping // 长度

(2) Bank width in octets (NEW) // 位宽

2. make modules

cp drivers/mtd/maps/physmap.ko /work/nfs_root/first_fs

3. 启动开发板

ls /dev/mtd*

insmod physmap.ko

ls /dev/mtd*

cat /proc/mtd

测试2: 使用自己写的驱动程序:

1. ls /dev/mtd*

2. insmod s3c_nor.ko

3. ls /dev/mtd*

4. 格式化: flash_eraseall -j /dev/mtd1

5. mount -t jffs2 /dev/mtdblock1 /mnt

在/mnt目录下操作文件

NOR FLASH识别过程:

do_map_probe("cfi_probe", s3c_nor_map);

drv = get_mtd_chip_driver(name)

ret = drv->probe(map); // cfi_probe.c

cfi_probe

mtd_do_chip_probe(map, &cfi_chip_probe);

cfi = genprobe_ident_chips(map, cp);

genprobe_new_chip(map, cp, &cfi)

cp->probe_chip(map, 0, NULL, cfi)

cfi_probe_chip

// 进入CFI模式

cfi_send_gen_cmd(0x98, 0x55, base, map, cfi, cfi->device_type, NULL);

// 看是否能读出"QRY"

qry_present(map,base,cfi)

.....

do_map_probe("jedec_probe", s3c_nor_map);

drv = get_mtd_chip_driver(name)

ret = drv->probe(map); // jedec_probe

jedec_probe

mtd_do_chip_probe(map, &jedec_chip_probe);

genprobe_ident_chips(map, cp);

genprobe_new_chip(map, cp, &cfi)

cp->probe_chip(map, 0, NULL, cfi)

jedec_probe_chip

// 解锁

cfi_send_gen_cmd(0xaa, cfi->addr_unlock1, base, map, cfi, cfi->device_type, NULL);

cfi_send_gen_cmd(0x55, cfi->addr_unlock2, base, map, cfi, cfi->device_type, NULL);

// 读ID命令

cfi_send_gen_cmd(0x90, cfi->addr_unlock1, base, map, cfi, cfi->device_type, NULL);

// 得到厂家ID,设备ID

cfi->mfr = jedec_read_mfr(map, base, cfi);

cfi->id = jedec_read_id(map, base, cfi);

// 和数组比较

jedec_table

驱动程序源码:

/*

* 参考 drivers\mtd\maps\physmap.c

*/

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

static struct map_info *s3c_nor_map;

static struct mtd_info *s3c_nor_mtd;

static struct mtd_partition s3c_nor_parts[] = {

[0] = {

.name = "bootloader_nor",

.size = 0x00040000,

.offset= 0,

},

[1] = {

.name = "root_nor",

.offset = MTDPART_OFS_APPEND,

.size = MTDPART_SIZ_FULL,

}

};

static int s3c_nor_init(void)

{

/* 1. 分配map_info结构体 */

s3c_nor_map = kzalloc(sizeof(struct map_info), GFP_KERNEL);;

/* 2. 设置: 物理基地址(phys), 大小(size), 位宽(bankwidth), 虚拟基地址(virt) */

s3c_nor_map->name = "s3c_nor";

s3c_nor_map->phys = 0;

s3c_nor_map->size = 0x1000000; /* >= NOR的真正大小 */

s3c_nor_map->bankwidth = 2;

s3c_nor_map->virt = ioremap(s3c_nor_map->phys, s3c_nor_map->size);

simple_map_init(s3c_nor_map);

/* 3. 使用: 调用NOR FLASH协议层提供的函数来识别 */

printk("use cfi_probe\n");

s3c_nor_mtd = do_map_probe("cfi_probe", s3c_nor_map);

if (!s3c_nor_mtd)

{

printk("use jedec_probe\n");

s3c_nor_mtd = do_map_probe("jedec_probe", s3c_nor_map);

}

if (!s3c_nor_mtd)

{

iounmap(s3c_nor_map->virt);

kfree(s3c_nor_map);

return -EIO;

}

/* 4. add_mtd_partitions */

add_mtd_partitions(s3c_nor_mtd, s3c_nor_parts, 2);

return 0;

}

static void s3c_nor_exit(void)

{

del_mtd_partitions(s3c_nor_mtd);

iounmap(s3c_nor_map->virt);

kfree(s3c_nor_map);

}

module_init(s3c_nor_init);

module_exit(s3c_nor_exit);

MODULE_LICENSE("GPL");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值