Nor flash drive with NAND flash drive The difference is not small, just set up a different structure,
Nor flash driver code:
#include <linux/module.h>#include<linux/types.h>#include<linux/kernel.h>#include<linux/init.h>#include<linux/slab.h>#include<linux/device.h>#include<linux/platform_device.h>#include<linux/mtd/mtd.h>#include<linux/mtd/map.h>#include<linux/mtd/partitions.h>#include<linux/mtd/physmap.h>#include<linux/mtd/concat.h>#include<linux/io.h>Static structMap_info *Nor_map;Static structMtd_info *NOR_MTD;StaticUnsignedCharNr_parts =2;Static structMtd_partition nor_mtd_partition[] = { [0] ={. Name="Bootloader_nor",. Size=0x00040000,. Offset=0, }, [1] ={. Name="Root_nor",. Offset=mtdpart_ofs_append,. Size=Mtdpart_siz_full,}};Static int__init My_nor_flash_init (void){ /*Assigning a mtd_info structure*/ interr; Nor_map= Kzalloc (sizeof(structmap_info), Gfp_kernel); if(Nor_map = =NULL) {PRINTK (Kern_alert"map_info kzalloc error\n"); return-Enomem; } /*settings: Physical base Address (phys), size (sizes), bit width (bankwidth), virtual base address (virt)*/Nor_map->name ="NOR Flash"; Nor_map->phys =0; Nor_map->size =0x100000;//greater than the size of true NOR flashNor_map->bankwidth =2;//16 GuestsNor_map->virt = Ioremap (nor_map->phys,nor_map->size); if(Nor_map->virt = =NULL) {PRINTK (Kern_alert"Failed to Ioremap Flash region\n"); Err= -EIO; Gotoerr_out; } simple_map_init (Nor_map); PRINTK (Kern_alert"Do_map_probe cfi_probe\n"); NOR_MTD= Do_map_probe ("Cfi_probe", Nor_map); if(NOR_MTD =NULL) {PRINTK (Kern_alert"Do_map_probe jedec_probe\n"); NOR_MTD= Do_map_probe ("Jedec_probe", Nor_map); } if(!NOR_MTD) {Iounmap (Nor_map-virt); Kfree (NOR_MAP); return-EIO; } NOR_MTD->owner =This_module; /*Adding partitions*/ if(Mtd_device_register (NOR_MTD, nor_mtd_partition, nr_parts)! =0) {PRINTK (Kern_alert"Mtd_device_register error\n"); return-EINVAL; } return 0; Err_out:kfree (NOR_MAP); returnerr;}Static void__exit My_nor_flash_exit (void) {Iounmap (Nor_map-virt); Kfree (NOR_MAP);} Module_init (My_nor_flash_init); Module_exit (My_nor_flash_exit); Module_license ("GPL");
SMART210 Learning record------NOR flash drive