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
(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
Previous article:NAND Flash Driver
Next article:About the use of 128M memory in ARM9 S3C2440 wince6.0
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- [Help] In the design of lithium battery power modules, why is every 1V of lithium battery voltage very valuable?
- [DIY Bing Dun Dun] + Limited Edition Homemade Dun Dun is here
- EEWORLD University Hall----Live Replay: Unlocking New Possibilities of TI Sitara AM2x MCU in Motor Drive
- 02.USART routines and tests
- How to create and call schematic templates in AD?
- Learning: The most important components of the analog world - signal chain and power supply
- An article to understand the naming of electromagnetic wave bands
- Anlu SparkRoad Development Board Review (3) Official DEMO Test
- 20 "Million Miles" Raspberry Pi Car - Motor Control Learning (Control Speed)
- [RVB2601 debug record] The function in the c file is not declared in the header file