linux nand flash驅(qū)動編寫
很長一段時間,nand flash都是嵌入式的標(biāo)配產(chǎn)品。nand flash價格便宜,存儲量大,適用于很多的場景?,F(xiàn)在很普及的ssd,上面的存儲模塊其實也是由一塊一塊nand flash構(gòu)成的。對于linux嵌入式來說,開始uboot的加載是硬件完成的,中期的kernel加載是由uboot中的nand flash驅(qū)動完成的,而后期的rootfs加載,這就要靠kernel自己來完成了。當(dāng)然,這次還是以三星s3c芯片為例進行說明。
1、nand flash驅(qū)動在什么地方,可以從drviers/mtd/Makefile來看
obj-y += chips/ lpddr/ maps/ devices/ nand/ onenand/ tests/
2、nand在mtd下面,是作為一個單獨目錄保存的,這時應(yīng)該查看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、不難發(fā)現(xiàn),MTD_NAND_S3C2410才是那個真正的macro,嘗試在Makefile找文件
obj-$(CONFIG_MTD_NAND_S3C2410) += s3c2410.o
4、查看s3c2410.c文件,看看基本結(jié)構(gòu)構(gòu)成
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、繼續(xù)分析s3c24xx_nand_probe函數(shù)
s3c2410_nand_init_chip(info, nmtd, sets);
6、之所以從中摘出了s3c2410_nand_init_chip這個函數(shù),是因為里面進行了函數(shù)注冊
類似的函數(shù)還有s3c2410_nand_update_chip函數(shù)
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;
}
7、抓住了函數(shù)接口,就找到了基本邏輯。
對于框架來說,它不關(guān)心你的代碼如何實現(xiàn)。只要你按照它的接口寫,就能讓上層正常獲得數(shù)據(jù)。platform、usb、pci這都是一種接口形式,具體實現(xiàn)還要按照各個具體功能模塊來實現(xiàn)才行。
8、為什么我們都用s3c芯片進行舉例
因為它用的場景最多,學(xué)習(xí)資料最全,對于新手來說,這會少很多麻煩。
9、這個驅(qū)動依賴的kernel版本是什么
這里最有的代碼都是按照最新4.16的版本進行分析的,大家可以直接查看這里的地址。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
關(guān)注官方微信