Smart210学习记录------nor flash驱动
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Smart210学习记录------nor flash驱动,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2179字,纯文字阅读大概需要4分钟。
内容图文
![Smart210学习记录------nor flash驱动](/upload/InfoBanner/zyjiaocheng/1319/0348819de1b84c778d92ea5f8ee0d968.jpg)
nor flash驱动与nand flash驱动的差别不大,只是设置不同的结构体而已,,
nor flash驱动代码:
#include <linux/module.h> #include <linux/types.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/device.h> #include <linux/platform_device.h> #include <linux/mtd/mtd.h> #include <linux/mtd/map.h> #include <linux/mtd/partitions.h> #include <linux/mtd/physmap.h> #include <linux/mtd/concat.h> #include <linux/io.h> staticstruct map_info *nor_map; staticstruct mtd_info *nor_mtd; static unsigned char nr_parts = 2; staticstruct mtd_partition nor_mtd_partition[] = { [0] = { .name = "bootloader_nor", .size = 0x00040000, .offset = 0, }, [1] = { .name = "root_nor", .offset = MTDPART_OFS_APPEND, .size = MTDPART_SIZ_FULL, } }; staticint __init my_nor_flash_init(void) { /*分配一个mtd_info结构体*/int err; nor_map = kzalloc(sizeof(struct map_info), GFP_KERNEL); if(nor_map == NULL) { printk(KERN_ALERT"map_info kzalloc error\n"); return -ENOMEM; } /*设置: 物理基地址(phys), 大小(size), 位宽(bankwidth), 虚拟基地址(virt)*/ nor_map->name = "nor flash"; nor_map->phys = 0; nor_map->size = 0x100000; //大于真实nor flash的大小 nor_map->bankwidth = 2; //16位 nor_map->virt = ioremap(nor_map->phys,nor_map->size); if (nor_map->virt == NULL) { printk(KERN_ALERT"Failed to ioremap flash region\n"); err = -EIO; goto err_out; } simple_map_init(nor_map); printk(KERN_ALERT"do_map_probe cfi_probe\n"); nor_mtd = do_map_probe("cfi_probe", nor_map); if(nor_mtd = NULL) { printk(KERN_ALERT" do_map_probe jedec_probe\n"); nor_mtd = do_map_probe("jedec_probe", nor_map); } if(!nor_mtd) { iounmap(nor_map->virt); kfree(nor_map); return -EIO; } nor_mtd->owner = THIS_MODULE; /*添加分区*/if(mtd_device_register(nor_mtd, nor_mtd_partition, nr_parts) != 0) { printk(KERN_ALERT" mtd_device_register error\n"); return -EINVAL; } return0; err_out: kfree(nor_map); return err; } staticvoid __exit my_nor_flash_exit(void) { iounmap(nor_map->virt); kfree(nor_map); } module_init(my_nor_flash_init); module_exit(my_nor_flash_exit); MODULE_LICENSE("GPL");
原文:http://www.cnblogs.com/qigaohua/p/5509963.html
内容总结
以上是互联网集市为您收集整理的Smart210学习记录------nor flash驱动全部内容,希望文章能够帮你解决Smart210学习记录------nor flash驱动所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。