20.1 -- Nor flash 驱动(开发步骤)

开发环境:

1. 开发主机: Ubuntu 9.10
2. 交叉编译器: gcc version 3.4.5
3. 开发板: JZ2440-V3

背景: Nor驱动开发,测试.

1. 重启开发板(从nand启动).

2. 编写驱动程序nor_drv.c.

3. 编译驱动模块.
# make

4. 复制驱动模块到NFS文件系统.
# cp nor_drv.ko /work/nfs_root/first_fs

5. 配置内核,将内核自带的Nor驱动编译为模块[M].
# make menuconfig
  -> Device Drivers
    -> Memory Technology Device (MTD) support
      -> Mapping drivers for chip access
        <M> CFI Flash device in physical memory map
          (0x0) Physical start address of flash mapping
          (0x200000) Physical length of flash mapping
          (2)   Bank width in octets

6. 编译驱动模块.
# make modules

7. 复制内核自带的Nor驱动模块到NFS文件系统.
# cp drivers/mtd/maps/physmap.ko /work/nfs_root/first_fs

8. 开发板启动开关拨至nor.

9. 装载内核自带的Nor驱动模块.
# ls /dev/mtd* -la

# insmod physmap.ko
physmap platform flash device: 00200000 at 00000000
physmap-flash.0: Found 1 x16 devices at 0x0 in 16-bit bank
 Amd/Fujitsu Extended Query Table at 0x0040
number of CFI chips: 1
cfi_cmdset_0002: Disabling erase-suspend-program due to code brokenness.
cmdlinepart partition parsing not available
RedBoot partition parsing not available

# ls /dev/mtd* -la
crw-rw----    1 0        0         90,   8 Jan  1 00:00 /dev/mtd4
crw-rw----    1 0        0         90,   9 Jan  1 00:00 /dev/mtd4ro
brw-rw----    1 0        0         31,   4 Jan  1 00:00 /dev/mtdblock4

# cat /proc/mtd
dev:    size   erasesize  name
mtd4: 00200000 00010000 "physmap-flash.0"

# rmmod physmap

10. 装载自己编写的Nor驱动模块.
# ls /dev/mtd* -la

# insmod nor_drv.ko
s3c_nor: Found 1 x16 devices at 0x0 in 16-bit bank
 Amd/Fujitsu Extended Query Table at 0x0040
number of CFI chips: 1
cfi_cmdset_0002: Disabling erase-suspend-program due to code brokenness.
Creating 2 MTD partitions on "s3c_nor":
0x00000000-0x00100000 : "bootloader_nor"
0x00100000-0x00200000 : "root_nor"

# ls /dev/mtd* -la
crw-rw----    1 0        0          90,   8 Jan  1 00:00 /dev/mtd4
crw-rw----    1 0        0          90,   9 Jan  1 00:00 /dev/mtd4ro
crw-rw----    1 0        0          90,  10 Jan  1 00:00 /dev/mtd5
crw-rw----    1 0        0          90,  11 Jan  1 00:00 /dev/mtd5ro
brw-rw----    1 0        0          31,   4 Jan  1 00:00 /dev/mtdblock4
brw-rw----    1 0        0          31,   5 Jan  1 00:00 /dev/mtdblock5

# cat /proc/mtd
dev:    size   erasesize  name
mtd4: 00100000 00010000 "bootloader_nor"
mtd5: 00100000 00010000 "root_nor"

11. 测试自己编写的Nor驱动模块.
# flash_eraseall --help
BusyBox v1.20.0 (2018-07-15 14:40:53 CST) multi-call binary.

Usage: flash_eraseall [-jq] MTD_DEVICE

Erase an MTD device

        -j      Format the device for jffs2
        -q      Don't display progress messages

# flash_eraseall -j /dev/mtd4 //格式化为jffs2格式(nor: jffs2;nand: yaffs2)
Erasing 64 Kibyte @ 100000 - 100% complete.leanmarker written at f0000.

# mount -t jffs2 /dev/mtdblock4 /mnt
# cd /mnt

# ls -la
total 4
drwxr-xr-x    3 0        0                0 Jan  1 00:00 .
drwxrwxr-x   12 1000     1000          4096 Jul 15  2018 ..

# touch test.txt
# vi test.txt
hello world!
I'm bwg!

# cat test.txt
hello world!
I'm bwg!

12. 重启开发板(从nand启动).

13. 开发板启动开关拨至nor.
# insmod nor_drv.ko
s3c_nor: Found 1 x16 devices at 0x0 in 16-bit bank
 Amd/Fujitsu Extended Query Table at 0x0040
number of CFI chips: 1
cfi_cmdset_0002: Disabling erase-suspend-program due to code brokenness.
Creating 2 MTD partitions on "s3c_nor":
0x00000000-0x00100000 : "bootloader_nor"
0x00100000-0x00200000 : "root_nor"

# mount -t jffs2 /dev/mtdblock4 /mnt

# ls -la
total 5
drwxr-xr-x    3 0        0                0 Jan  1 00:00 .
drwxrwxr-x   12 1000     1000          4096 Jul 15  2018 ..
-rw-r--r--    1 0        0               22 Jan  1 00:11 test.txt

# cat test.txt
hello world!
I'm bwg!


猜你喜欢

转载自blog.csdn.net/xsbh0310/article/details/81054988