linux下Flash进程,Linux下norflash驱动编写方法

Linux下norflash驱动编写步骤

1. 分配map_info结构体

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

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

4. add_mtd_partitions

如:

#include #include #include #include #include #include #include #include #include #include #include #include #include static struct map_info *nor_map; static struct mtd_info *nor_mtd; static struct mtd_partition nor_parts[]={ [0] = {         .name   = "bootloader_nor",         .size   = 0x00040000, .offset = 0, }, [1] = {         .name   = "root_nor",         .offset = MTDPART_OFS_APPEND,         .size   = MTDPART_SIZ_FULL, } }; static int norflash_driver_init() { nor_map=kzalloc(sizeof(struct map_info), GFP_KERNEL); nor_map->name="nor_drv"; nor_map->size=0x1000000; nor_map->phys=0; nor_map->bankwidth=2; nor_map->virt=ioremap(nor_map->phys, nor_map->size); simple_map_init(s3c_nor_map); printk("use cfi_probe\n"); nor_mtd=do_map_probe("cfi_probe", s3c_nor_map); if (!nor_mtd) { printk("use jedec_probe\n"); nor_mtd=do_map_probe("jedec_probe", s3c_nor_map); } if (!nor_mtd) { iounmap(s3c_nor_map->virt); kfree(s3c_nor_map); return -EIO; } nor_mtd->owner=THIS_MODULE; add_mtd_partitions(nor_mtd, nor_parts, 2); return 0; } static void norflash_driver_exit() { del_mtd_partitions(nor_mtd); map_destroy(nor_mtd); iounmap(nor_map->virt); kzfree(nor_map); } module_init(norflash_driver_init); module_exit(norflash_driver_exit); MODULE_LICENSE("GPL");

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值