zoukankan      html  css  js  c++  java
  • S3C2440 nor_flash驱动程序

    20150418 S3C2440 nor_flash驱动程序

    2015-04-18 Lover雪儿

    和前面的nandflash差不多,我们此处来重新学习一下norflash驱动。

      1 /*
      2  * 参考 driversmtdmapsPhysmap.c
      3  */
      4 
      5 #include <linux/module.h>
      6 #include <linux/types.h>
      7 #include <linux/kernel.h>
      8 #include <linux/init.h>
      9 #include <linux/slab.h>
     10 #include <linux/device.h>
     11 #include <linux/platform_device.h>
     12 #include <linux/mtd/mtd.h>
     13 #include <linux/mtd/map.h>
     14 #include <linux/mtd/partitions.h>
     15 #include <linux/mtd/physmap.h>
     16 #include <linux/mtd/concat.h>
     17 #include <linux/io.h>
     18 
     19 //定义nor flash的分区
     20 static struct mtd_partition lhy_nor_part[] = {
     21     [0] = {
     22         .name    = "nor bootloader",
     23         .size    = 0x40000,
     24         .offset    = 0,
     25     },
     26     [1] = {
     27         .name    = "nor root",
     28         .offset = MTDPART_OFS_APPEND,
     29         .size    = MTDPART_SIZ_FULL,        //剩余的所有大小
     30     },
     31 };
     32 
     33 static struct map_info *lhy_nor_map;
     34 static struct mtd_info *lhy_nor_mtd;  //动态创建
     35 
     36 static int lhy_nor_init(void)
     37 {
     38     /* 1.分配map_info结构体 */
     39     lhy_nor_map = kzalloc(&dev->dev, sizeof(struct map_info),GFP_KERNEL);
     40     /* 2.设置:物理基地址(phys),大小(size),位宽(bankwidth),虚拟基地址(virt) */
     41     lhy_nor_map->name = "lhy_nor";  //名字
     42     lhy_nor_map->phys = 0x0;        //基地址
     43     lhy_nor_map->size = 0x1000000;    //大小,>=nor的真正大小
     44     lhy_nor_map->bankwidth = 2;        //位宽16位
     45 
     46     lhy_nor_map->virt = ioremap(lhy_nor_map->phys,lhy_nor_map->size); //映射地址
     47     
     48     simple_map_init(lhy_nor_map);    //简单的初始化
     49     
     50     /* 3.使用: 调用nor flash协议层提供的函数来识别 */
     51     printk("<0>use cfi_probe
    ");
     52     lhy_nor_mtd = do_map_probe("cfi_probe",lhy_nor_map);
     53     if(!lhy_nor_mtd){
     54         printk("<0>use jedec_probe
    ");
     55         lhy_nor_mtd = do_map_probe("jedec_probe",lhy_nor_map);
     56     }
     57     if(!lhy_nor_mtd){
     58         iounmap(lhy_nor_map->virt);
     59         kfree(lhy_nor_map);
     60         return -EIO;
     61     }
     62         
     63     /* 4.添加分区: add_mtd_partitions */
     64     add_mtd_partitions(lhy_nor_mtd,lhy_nor_part,2); //总共两个分区
     65     return 0;
     66 }
     67 
     68 static void lhy_nor_exit(void)
     69 {
     70     if(lhy_nor_map){
     71         iounmap(lhy_nor_map->virt);
     72         kfree(lhy_nor_map);
     73         del_mtd_partitions(lhy_nor_mtd);
     74     }
     75 }
     76 
     77 module_init(lhy_nor_init);
     78 module_exit(lhy_nor_exit);
     79 MODULE_LICENSE("GPL");
     80 
     81 /*
     82 
     83 使用U-BOOT来体验NOR FLASH 的操作(开发板设为NOR启动,进入U-BOOT)
     84 使用OpenJTAG烧写U-BOOT到nor flash
     85 1.读数据
     86 md.b 0
     87 
     88 2.读ID
     89 往地址555H写入AAH
     90 往地址2AAH写入55H
     91 往地址555H写入90H
     92 读0地址得到厂家ID      C2H
     93 读1地址得到设备ID    22DAH/225DH
     94 退出读ID状态        往任意地址写入F0H
     95 
     96 由于2440的CPU的数据线和NOR的数据线相错开,所以UBOOT操作时,写的地址应该<<1得到
     97 往地址AAAH写入AAH                        mw.w aaa aa
     98 往地址554H写入55H                        mw.w 554 55
     99 往地址AAAH写入90H                        mw.w aaa 90H        
    100 读0地址得到厂家ID      C2H                    md.w 0 1
    101 读2地址得到设备ID    22DAH/225DH            md.w 2 1
    102 退出读ID状态        往任意地址写入F0H      mw.w 0 f0
    103 
    104 3.NOR 手册上有两种规范,jedec,cfi(common flash interface)
    105     读取CFI信息    
    106     进入CFI模式,往地址55H写入98H
    107     读数据:    读10H得到0051
    108                 读11H得到0052
    109                 读12H得到0059
    110                 读27H得到容量
    111 UBOOT操作时,写的地址应该左移一位
    112     进入CFI模式,往地址AAH写入98H        mw.w aa 98
    113     读数据:    读20H得到0051            md.w 20 1
    114                 读22H得到0052           md.w 22 1    
    115                 读24H得到0059           md.w 24 1
    116                 读4EH得到容量           md.w 4E 1    2^n
    117     退出CFI模式,往任意地址写入F0H      mw.w 0 f0
    118 4.写数据    在地址0x100000写入0x1234  发现无法写数据
    119 往地址555H写入AAH                        
    120 往地址2AAH写入55H                        
    121 往地址555H写入A0H                            
    122 往烧写地址写入要写的数据
    123 
    124 U-BOOT操作
    125 往地址AAAH写入AAH                        mw.w aaa aa
    126 往地址554H写入55H                        mw.w 554 55
    127 往地址AAAH写入A0H                        mw.w aaa A0H        
    128 往烧写地址写入要写的数据                mw.w 100000 1234h  往1M的地址写数据
    129 
    130 
    131 5.测试内核自带的驱动程序:
    132 1).通过配置内核支持NOR FLASH
    133 --> Device Drivers
    134     --> Memory Technology Device (MTD) support 
    135         --> Mapping drivers fro chip access
    136         <M> CFI Flash device in physical memory map
    137         (0x0) Physical start address of flash mapping     //起始地址
    138         (0x1000000) Physical length of flash mapping    //内存大小,16M,要大于实际的大小
    139         (2) Bank owidth in octets                        //位宽为16位
    140 2).make modules
    141 cp drivers/mtd/maps/physmap.ko  /home/study/nfs_home    
    142     
    143                 
    144 6.写驱动程序
    145 ①分配
    146 ②设置
    147 ③使用                
    148 驱动程序框架:
    149 
    150 7.测试   使用自己写的驱动程序
    151 2.保存以前的根文件系统的bootargs
    152 nfs 30000000 192.168.1.5:/work/nfs_root/uImage_nonand
    153 set bootargs console=ttySAC0 root=/dev/nfs nfsroot=192.168.1.105:/work/nfs_root/first_fs ip=192.168.1.17:192.168.1.5:192.168.1.1:255.255.255.0::eth0:off
    154 
    155 ls /dev/mtd*
    156 insmod lhy_nor.ko
    157 ls /dev/mtd*    
    158 格式化: flash_eraseall -j     /dev/mtd1        ;格式化为jffs2文件系统(一般nand(yaffs),nor(jffs2))        
    159 
    160 挂接: mount -t jffs2 /dev/mtdblock1 /mnt      ;格式化时用字符设备,挂接时用块设备
    161 在里面增加文件,重启之后,看看文件是否还在
    162 insmod lhy_nor.ko
    163 ls /dev/mtd*
    164 mount -t jffs2 /dev/mtdblock1 /mnt           ;读文件
    165 
    166 
    167 8.协议层追踪
    168 lhy_nor_mtd = do_map_probe("cfi_probe",lhy_nor_map);
    169 lhy_nor_mtd = do_map_probe("jedec_probe",lhy_nor_map);
    170 
    171                 
    172 */
  • 相关阅读:
    自动机
    C语言文法
    实验报告一:词法分析
    Python的基础综合练习
    Python基础综合练习
    turtle画五星红旗
    熟悉常用的Linux操作
    大数据概述
    对学习编译原理的看法
    LINUX
  • 原文地址:https://www.cnblogs.com/lihaiyan/p/4438168.html
Copyright © 2011-2022 走看看