NOR Flash Driver

Publisher:WhisperingWindLatest update time:2024-07-31 Source: cnblogsKeywords:NOR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Drivers

1 /*
2 * 参考:
3 * .linux-2.6.22.6driversmtddevicesmtdram.c
4 * .linux-2.6.22.6driversmtdmapsphysmap.c
5 */
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
15 #include
16 #include
17 #include
18
19
20 static struct map_info * nor_map;
21 static struct mtd_info * nor_mtd;
22
23
24 //分区信息
25 static struct mtd_partition nor_parts[] = {
26         [ 0 ] = {
27                 .name = "bootloader_nor" ,
28                 .size = 0x00040000 ,
29                 .offset = 0 , /* offset within the master MTD space */
30         },
31
32         [ 1 ] = {
33                 .name = "root_nor" ,
34                 .offset = MTDPART_OFS_APPEND, //紧跟着上一个分区的大小
35                 .size = MTDPART_SIZ_FULL,
36         },
37 };
38
39
40
41 /* 1 出入口函数 */
42 static int __init nor_init ( void )
43 {
44 /* 2 Allocate map_info structure*/ 45 nor_map = kmalloc( sizeof ( struct map_info), GFP_KERNEL); 46 /******** 2 end ********/ 47 48 49 /* 3 Settings: physical base address (phys), size (size), bankwidth, virtual base address (virt) */ 50 nor_map -> name = "nor" ; 51 nor_map -> phys = 0 ; 52 nor_map -> size = 1000000 ; //16M, larger than the actual size of nor 53 nor_map -> bankwidth = 2 ; 54 nor_map -> virt = ioremap(nor_map -> phys, nor_map -> size); 55 56 simple_map_init(nor_map); 57 /******** 3 end ********/ 58 59 60 /* 4 Use: call the function provided by the Nor Flash protocol layer to identify*/ 61 printk( "use cfi_probe n " ); 62 nor_mtd = do_map_probe( "cfi_probe " , nor_map); 63 if ( ! nor_mtd) 64 { 65 printk( "use jedec_probe n " ); 66 nor_mtd = do_map_probe( "jedec_probe" , nor_map); 67 } 68 69 if ( ! nor_mtd) 70 { 71 printk( "fail n " ); 72 iounmap(nor_map -> virt); 73 kfree(nor_map); 74 kfree(nor_mtd); 75 return - EIO;































76         }
77 /******** 4 end ********/
78
79 /* 5 添加分区:add_mtd_partison */
80         add_mtd_partitions(nor_mtd, nor_parts, 2 );
81 /******** 5 end ********/
82 return 0 ;
83 }
84
85
86 static void __exit nor_exit ( void )
87 {
88         iounmap(nor_map -> virt);
89         kfree(nor_map);
90         kfree(nor_mtd);
91         del_mtd_partitions(nor_mtd);
92 return ;
93 }
94
95 module_init(nor_init);
96 module_exit(nor_exit);
97
98 MODULE_LICENSE( "GPL" );
99 /******** 1 end ********/

debug

Test 1: Configure the kernel to support NOR FLASH

1. make menuconfig

-> Device Drivers

-> Memory Technology Device (MTD) support

-> Mapping drivers for chip access

CFI Flash device in physical memory map

(0x0) Physical start address of flash mapping // Physical base address

(0x1000000) Physical length of flash mapping // length

(2) Bank width in octets (NEW) // bit width

2. make modules

cp drivers/mtd/maps/physmap.ko /work/nfs_root/first_fs

3. Start the development board

ls /dev/mtd*

insmod physmap.ko

ls /dev/mtd*

cat /proc/mtd

Test 2: Using a self-written driver:

1. ls /dev/mtd*

2. insmod s3c_nor.ko

3. ls /dev/mtd*

4. Format: flash_eraseall -j /dev/mtd1

5. mount -t jffs2 /dev/mtdblock1 /mnt

Operate files in the /mnt directory

NOR FLASH identification process:

do_map_probe("cfi_probe", s3c_nor_map);

drv = get_mtd_chip_driver(name)

ret = drv->probe(map); // cfi_probe.c

cfi_probe

mtd_do_chip_probe(map, &cfi_chip_probe);

cfi = genprobe_ident_chips(map, cp);

genprobe_new_chip(map, cp, &cfi)

cp->probe_chip(map, 0, NULL, cfi)

cfi_probe_chip

// Enter CFI mode

cfi_send_gen_cmd(0x98, 0x55, base, map, cfi, cfi->device_type, NULL);

// See if "QRY" can be read

qry_present(map,base,cfi)

.....

do_map_probe("jedec_probe", s3c_nor_map);

drv = get_mtd_chip_driver(name)

ret = drv->probe(map); // test_eater

eater_probe

mtd_do_chip_probe(map, &jedec_chip_probe);

genprobe_ident_chips(map, cp);

genprobe_new_chip(map, cp, &cfi)

cp->probe_chip(map, 0, NULL, cfi)

jedec_probe_chip

// Unlock

cfi_send_gen_cmd(0xaa, cfi->addr_unlock1, base, map, cfi, cfi->device_type, NULL);

cfi_send_gen_cmd(0x55, cfi->addr_unlock2, base, map, cfi, cfi->device_type, NULL);

// Read ID command

cfi_send_gen_cmd(0x90, cfi->addr_unlock1, base, map, cfi, cfi->device_type, NULL);

// Get the manufacturer ID and device ID

cfi->mfr = jedec_read_mfr(map, base, cfi);

cfi->id = jedec_read_id(map, base, cfi);

// Compare with array

jedec_table


Keywords:NOR Reference address:NOR Flash Driver

Previous article:NAND Flash Driver
Next article:About the use of 128M memory in ARM9 S3C2440 wince6.0

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号