Nand Flash 驱动框架
框架入口源文件:s3c_nand.c
(可根据入口源文件,再按着框架到内核走一遍)
内核版本:linux_2.6.22.6 硬件平台:JZ2440
以下是驱动框架:

以下是驱动代码 s3c_nand.c :
#include <linux/module.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/string.h>
#include <linux/ioport.h>
#include <linux/platform_device.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/clk.h> #include <linux/mtd/mtd.h>
#include <linux/mtd/nand.h>
#include <linux/mtd/nand_ecc.h>
#include <linux/mtd/partitions.h> #include <asm/io.h> #include <asm/arch/regs-nand.h>
#include <asm/arch/nand.h> //定义一个 nand_chip 结构体
static struct nand_chip *s3c_chip; //定义一个 mtd_info 结构体
static struct mtd_info *s3c_info; //定义寄存器结构体
static struct s3c_nand_regs
{
unsigned long nfconf ;
unsigned long nfcont ;
unsigned long nfcmd ;
unsigned long nfaddr ;
unsigned long nfdata ;
unsigned long nfeccd0 ;
unsigned long nfeccd1 ;
unsigned long nfeccd ;
unsigned long nfstat ;
unsigned long nfestat0;
unsigned long nfestat1;
unsigned long nfmecc0 ;
unsigned long nfmecc1 ;
unsigned long nfsecc ;
unsigned long nfsblk ;
unsigned long nfeblk ; }*s3c_nand_regs; //分区表
static struct mtd_partition s3c_partitions[] =
{
[] = {
.name = "bootloader",
.size = 0x00040000,
.offset = ,
},
[] = {
.name = "params",
.offset = MTDPART_OFS_APPEND,
.size = 0x00020000,
},
[] = {
.name = "kernel",
.offset = MTDPART_OFS_APPEND,
.size = 0x00200000,
},
[] = {
.name = "root",
.offset = MTDPART_OFS_APPEND,
.size = MTDPART_SIZ_FULL,
}
}; static void s3c_select_chip(struct mtd_info *mtd, int chip)
{
if (chip == -) s3c_nand_regs->nfcont |= (<<);
else s3c_nand_regs->nfcont &= ~(<<);
} int s3c_dev_ready(struct mtd_info *mtd)
{
return (s3c_nand_regs->nfstat & (<<));
} void s3c_cmd_ctrl(struct mtd_info *mtd, int dat,unsigned int ctrl)
{
if (ctrl & NAND_CLE) s3c_nand_regs->nfcmd = dat;
else s3c_nand_regs->nfaddr = dat;
} static int s3c_nand_init(void)
{
struct clk *clk;
//申请 nand_chip
s3c_chip = kzalloc(sizeof(struct nand_chip),GFP_KERNEL); //初始化 nand_chip 函数供扫描用 1.选中 2.状态 3.发地址和命令 5.发数据 6.读数据
s3c_nand_regs = ioremap(0x4E000000,sizeof(struct s3c_nand_regs));
s3c_chip->select_chip =s3c_select_chip;
s3c_chip->dev_ready =s3c_dev_ready;
s3c_chip->cmd_ctrl =s3c_cmd_ctrl;
s3c_chip->IO_ADDR_R =&s3c_nand_regs->nfdata;
s3c_chip->IO_ADDR_W =&s3c_nand_regs->nfdata;
s3c_chip->ecc.mode =NAND_ECC_SOFT; //初始化 读写时序NFCONF 开关FCONT NAND时钟
s3c_nand_regs->nfconf = (<<)|(<<)|(<<);
s3c_nand_regs->nfcont = (<<) | (<<);
clk =clk_get(NULL,"nand");
clk_enable(clk); //申请 初始化 mtd_info
s3c_info = kzalloc(sizeof(struct mtd_info), GFP_KERNEL);
s3c_info->priv = s3c_chip;
s3c_info->owner = THIS_MODULE; //nand_scan nand_chip --> mtd_info
nand_scan(s3c_info,); //add_mtd_partitions mtd_info --> gendisk
add_mtd_partitions(s3c_info, s3c_partitions,); return ;
} static void s3c_nand_exit(void)
{
iounmap(s3c_nand_regs);
kfree(s3c_chip);
kfree(s3c_info);
del_mtd_partitions(s3c_info); } module_init(s3c_nand_init);
module_exit(s3c_nand_exit);
MODULE_LICENSE("GPL");
以下是编译驱动的Makefile:
KER_DIR=/work/systems/kernel/linux-/linux-2.6.22.6
all:
make -C $(KER_DIR) M=`pwd` modules
clean:
make -C $(KER_DIR) M=`pwd` modules clean
rm -fr modules.order obj-m += s3c_nand.o
Nand Flash 驱动框架的更多相关文章
- NAND FLASH驱动框架以及程序实现
1.NAND FLASH的硬件连接: 实验用的NAND FLASH芯片为K9F2G08U0C,它是三星公司的存储芯片,它的大小为256M.它的接线图如下所示: 它的每个引脚的分别为LDATA0-LDA ...
- 15.1 linux操作系统下nand flash驱动框架2
当我们需要在操作系统上读写普通文件的时候,总是需要一层层往下,最终到达硬件相关操作,当然底层设备大多数都是块设备 NAND FLASH就作为一个最底层的块设备. 而写驱动,就是要构建硬件与操作系统之间 ...
- 【驱动】linux系统下nand flash驱动程序框架
linux操作系统下nand flash驱动框架 当我们需要在操作系统上读写普通文件的时候,总是需要一层层往下,最终到达硬件相关操作,当然底层设备大多数都是块设备 NAND FLASH就作为一个最底层 ...
- 如何编写linux下nand flash驱动-4
2. 软件方面 如果想要在Linux下编写Nand Flash驱动,那么就先要搞清楚Linux下,关于此部分的整个框架.弄明白,系统是如何管理你的nand flash的,以及,系统都帮你做 ...
- 15、NAND FLASH驱动程序框架
驱动可以参考At91_nand.c,这个比S3c2410.c (drivers\mtd\nand)简单多了 NAND FLASH是一个存储芯片那么: 这样的操作很合理"读地址A的数据,把数据 ...
- 十八、Nand Flash驱动和Nor Flash驱动
在读者学习本章之前,最好了解Nand Flash读写过程和操作,可以参考:Nand Flash裸机操作. 一开始想在本章写eMMC框架和设备驱动,但是没有找到关于eMMC设备驱动具体写法,所以本章仍继 ...
- Smart210学习记录----nand flash驱动
[详解]如何编写Linux下Nand Flash驱动 :http://www.cnblogs.com/linux-rookie/articles/3016990.html 当读写文件请求到来的时候, ...
- Nand Flash驱动(实现初始化以及读操作)
简单制作一个Nand Flash驱动(只需要初始化Flash以及读Flash) 打开2440芯片手册,K9F2G08U0M芯片手册(因为2440中Nand Flash是用的256MB(2Gb)内存,8 ...
- linux2.6.30.4内核移植(2)——Nand Flash驱动移植
内核源码:linux2.6.30.4 交叉编译工具:3.4.5 移植linux内核至:TQ2440 工作基础:http://www.cnblogs.com/nufangrensheng/p/36696 ...
随机推荐
- WPF 4.5 is here : check out the new features !
So what's New in WPF Version 4.5 Developer Preview ? Here is a list of the new features and their re ...
- ICMP timestamp 请求响应漏洞
ICMP timestamp请求响应漏洞 解决方案: * 在您的防火墙上过滤外来的ICMP timestamp(类型13)报文以及外出的ICMP timestamp回复报文. google之, ...
- mybatis xml 文件中like模糊查询
1.直接传参法 直接传参法,就是将要查询的关键字keyword,在代码中拼接好要查询的格式,如%keyword%,然后直接作为参数传入mapper.xml的映射文件中. 2.CONCAT()函数 My ...
- [Object Tracking] **Mask R-CNN
From: 如何评价 Kaiming He 最新的 Mask R-CNN? 如何跟进这些人,是个能力,要慢慢掌握. https://github.com/CharlesShang/FastMaskRC ...
- [Python] 02 - String
字符串 string 一.基本性质 不变性 Immutability 要变就 --> list --> string 二.功能函数 功能函数 S = 'Spam" S.find( ...
- WPF自定义路由事件(二)
WPF中的路由事件 as U know,和以前Windows消息事件区别不再多讲,这篇博文中,将首先回顾下WPF内置的路由事件的用法,然后在此基础上自定义一个路由事件. 1.WPF内置路由事件 WPF ...
- iOS开发-- TFHpple抓取GB-2312编码的html页面,页面返回编码错误
今天用TFHpple解析html,发现老报错encoding error : input conversion failed due to input error, bytes I/O error ...
- K - Super A^B mod C
Given A,B,C, You should quickly calculate the result of A^B mod C. (1<=A,C<=1000000000,1<=B ...
- postgresql----聚合函数
聚合函数是从一组输入中计算出一个结果的函数. 测试表 test=# \d tbl_test Table "public.tbl_test" Column | Type | Modi ...
- web.config/app.config敏感数据加/解密的二种方法
一 建立虚拟目录 http://localhost/EncryptWebConfig,并添加web.config,其中包含数据库连接字符串: <connectionStrings> ...