首页 > 系统 > Linux > 正文

linux nand flash驱动编写

2024-08-28 00:00:33
字体:
来源:转载
供稿:网友
这篇文章主要介绍了linux nand flash驱动编写,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

很长一段时间,nand flash都是嵌入式的标配产品。nand flash价格便宜,存储量大,适用于很多的场景。现在很普及的ssd,上面的存储模块其实也是由一块一块nand flash构成的。对于linux嵌入式来说,开始uboot的加载是硬件完成的,中期的kernel加载是由uboot中的nand flash驱动完成的,而后期的rootfs加载,这就要靠kernel自己来完成了。当然,这次还是以三星s3c芯片为例进行说明。

1、nand flash驱动在什么地方,可以从drviers/mtd/Makefile来看

obj-y    += chips/ lpddr/ maps/ devices/ nand/ onenand/ tests/ 

2、nand在mtd下面,是作为一个单独目录保存的,这时应该查看nand下的Kconfig

config MTD_NAND_S3C2410   tristate "NAND Flash support for Samsung S3C SoCs"   depends on ARCH_S3C24XX || ARCH_S3C64XX   help    This enables the NAND flash controller on the S3C24xx and S3C64xx    SoCs     No board specific support is done by this driver, each board    must advertise a platform_device for the driver to attach.  config MTD_NAND_S3C2410_DEBUG   bool "Samsung S3C NAND driver debug"   depends on MTD_NAND_S3C2410   help    Enable debugging of the S3C NAND driver  config MTD_NAND_S3C2410_CLKSTOP   bool "Samsung S3C NAND IDLE clock stop"   depends on MTD_NAND_S3C2410   default n   help    Stop the clock to the NAND controller when there is no chip    selected to save power. This will mean there is a small delay    when the is NAND chip selected or released, but will save    approximately 5mA of power when there is nothing happening. 

3、不难发现,MTD_NAND_S3C2410才是那个真正的macro,尝试在Makefile找文件

obj-$(CONFIG_MTD_NAND_S3C2410)   += s3c2410.o 

4、查看s3c2410.c文件,看看基本结构构成

static struct platform_driver s3c24xx_nand_driver = {   .probe   = s3c24xx_nand_probe,   .remove   = s3c24xx_nand_remove,   .suspend  = s3c24xx_nand_suspend,   .resume   = s3c24xx_nand_resume,   .id_table  = s3c24xx_driver_ids,   .driver   = {     .name  = "s3c24xx-nand",     .of_match_table = s3c24xx_nand_dt_ids,   }, };  module_platform_driver(s3c24xx_nand_driver); 

5、继续分析s3c24xx_nand_probe函数

s3c2410_nand_init_chip(info, nmtd, sets); 

6、之所以从中摘出了s3c2410_nand_init_chip这个函数,是因为里面进行了函数注册

类似的函数还有s3c2410_nand_update_chip函数

chip->write_buf  = s3c2410_nand_write_buf; chip->read_buf   = s3c2410_nand_read_buf; chip->select_chip = s3c2410_nand_select_chip; chip->chip_delay  = 50; nand_set_controller_data(chip, nmtd); chip->options    = set->options; chip->controller  = &info->controller;  switch (info->cpu_type) { case TYPE_S3C2410:   chip->IO_ADDR_W = regs + S3C2410_NFDATA;   info->sel_reg  = regs + S3C2410_NFCONF;   info->sel_bit  = S3C2410_NFCONF_nFCE;   chip->cmd_ctrl = s3c2410_nand_hwcontrol;   chip->dev_ready = s3c2410_nand_devready;   break;  case TYPE_S3C2440:   chip->IO_ADDR_W = regs + S3C2440_NFDATA;   info->sel_reg  = regs + S3C2440_NFCONT;   info->sel_bit  = S3C2440_NFCONT_nFCE;   chip->cmd_ctrl = s3c2440_nand_hwcontrol;   chip->dev_ready = s3c2440_nand_devready;   chip->read_buf = s3c2440_nand_read_buf;   chip->write_buf = s3c2440_nand_write_buf;   break;  case TYPE_S3C2412:   chip->IO_ADDR_W = regs + S3C2440_NFDATA;   info->sel_reg  = regs + S3C2440_NFCONT;   info->sel_bit  = S3C2412_NFCONT_nFCE0;   chip->cmd_ctrl = s3c2440_nand_hwcontrol;   chip->dev_ready = s3c2412_nand_devready;    if (readl(regs + S3C2410_NFCONF) & S3C2412_NFCONF_NANDBOOT)     dev_info(info->device, "System booted from NAND/n");    break; } 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表