Chinaunix首页 | 论坛 | 博客
  • 博客访问: 620902
  • 博文数量: 75
  • 博客积分: 988
  • 博客等级: 准尉
  • 技术积分: 1269
  • 用 户 组: 普通用户
  • 注册时间: 2011-05-10 15:44
文章分类

全部博文(75)

文章存档

2022年(1)

2019年(1)

2018年(1)

2016年(9)

2015年(7)

2013年(6)

2012年(40)

2011年(10)

分类: LINUX

2012-03-30 16:36:25

    Nor和Nand可以说各有所长吧,但是随着现在工艺的提升,Nand出现坏块或位反转的情形已大有改观。所以如果对数据没有十分严格的要求,大部分情况下,一般人还是乐意用nand的。谁又会去和钱过不去呢?
    Nor支持XIP 直接从片内取指令执行。
Nor的电路连接如上所示,用到16条数据线和16条地址线。


点击(此处)折叠或打开

  1. /*
  2.  * 参考:drivers\mtd\maps\physmap.c
  3.  */

  4. #include <linux/module.h>
  5. #include <linux/types.h>
  6. #include <linux/kernel.h>
  7. #include <linux/init.h>
  8. #include <linux/slab.h>
  9. #include <linux/device.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/mtd/mtd.h>
  12. #include <linux/mtd/map.h>
  13. #include <linux/mtd/partitions.h>
  14. #include <asm/io.h>

  15. static struct map_info *s3c_nor_map;
  16. static struct mtd_info *s3c_nor_mtd;

  17. static struct mtd_partition s3c_nor_parts[] = {
  18.     [0] = {
  19.         .name = "bootloader_nor",
  20.         .size = 0x00040000,
  21.         .offset = 0,
  22.     },
  23.     [1] = {
  24.         .name = "root_nor",
  25.         .offset = MTDPART_OFS_APPEND,
  26.         .size = MTDPART_SIZ_FULL, /* 剩下的所有分区 */
  27.     },
  28. };


  29. static int s3c_nor_init(void)
  30. {
  31.     /* 1.分配一个map_info结构体 */
  32.     s3c_nor_map = kzalloc(sizeof(struct map_info), GFP_KERNEL);
  33.     
  34.     /* 2.设置:物理基地址(phys),大小(size),位宽(bankwidth)
  35.      * 虚拟基地址(virt)
  36.      */
  37.   // s3c_nor_map->name = dev->dev.bus_id;
  38.     s3c_nor_map->name = "s3c_nor"; /* 名字 */
  39.   // s3c_nor_map->phys = dev->resource->start;
  40.     s3c_nor_map->phys = 0; /* 物理地址 */
  41.   // s3c_nor_map->size = dev->resource->end - dev->resource->start + 1;
  42.     s3c_nor_map->size = 0x1000000; /* 大小 16M(一定要>=Nor的真正大小 */
  43.   // s3c_nor_map->bankwidth = physmap_data->width;
  44.     s3c_nor_map->bankwidth = 2; /* 位宽 16位 */
  45.   // s3c_nor_map->set_vpp = physmap_data->set_vpp;
  46.     s3c_nor_map->set_vpp = physmap_data->set_vpp; /* */
  47.   // s3c_nor_map->virt = ioremap(info->map.phys, info->map.size);
  48.     s3c_nor_map->virt = ioremap(s3c_nor_map->phys, s3c_nor_map->size ); /* 虚拟地址 */

  49.     simple_map_init(s3c_nor_map); /* 简单初始化 */

  50.     /* 3.使用:调用NOR FLASH协议层提供的函数来识别 */
  51.     printk("use cfi_probe\n");
  52.     s3c_nor_mtd = do_map_probe("cfi_probe", s3c_nor_map);
  53.     if (!s3c_nor_mtd)
  54.     {
  55.         printk("use jeded_probe\n");
  56.         s3c_nor_mtd = do_map_probe("jeded_probe", s3c_nor_map);
  57.     }

  58.     if (!s3c_nor_mtd)
  59.     {
  60.         iounmap(s3c_nor_map->virt);
  61.         kfree(s3c_nor_map);
  62.         return -EIO;
  63.     }
  64.     
  65.     /* 4.add_mtd_partitions */
  66.    // add_mtd_partitions(struct mtd_info * master,const struct mtd_partition * parts,int nbparts)
  67.     add_mtd_partitions(s3c_nor_mtd, s3c_nor_parts, 2);
  68.     return 0;
  69. }

  70. static int s3c_nor_exit(void)
  71. {
  72.     del_mtd_partitions(s3c_nor_mtd);
  73.     iounmap(s3c_nor_map->virt);
  74.     kfree(s3c_nor_map);
  75. }


  76. module_init(s3c_nor_init);
  77. module_exit(s3c_nor_exit);


  78. MODULE_DESCRIPTION("nor_flash driver test for the s3c2440");
  79. MODULE_LICENSE("GPL");


阅读(4092) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~