(1)测试原有的驱动:
make menuconfig修改physmap-flash驱动配置:起始0,大小0x100000,位宽2,make modules后拷贝过去测试:
# insmod physmap.ko
physmap platform flash device: 01000000 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*
/dev/mtd0 /dev/mtd0ro /dev/mtdblock0
# cat /proc/mtd
dev: size erasesize name
mtd0: 00200000 00010000 "physmap-flash.0"
# rmmod physmap.ko
Device 'physmap-flash.0' does not have a release() function, it is broken and must be fixed.
WARNING: at drivers/base/core.c:107 device_release()
不管它
(2)vi s3c_nor.c
#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 <asm/io.h>static struct map_info *s3c_nor_map;
static struct mtd_info *s3c_nor_mtd;static int s3c_nor_init(void)
{s3c_nor_map = kzalloc(sizeof(struct map_info), GFP_KERNEL);s3c_nor_map->name = "s3c_nor";s3c_nor_map->phys = 0;s3c_nor_map->size = 0x1000000;s3c_nor_map->bankwidth = 2;s3c_nor_map->virt = ioremap(s3c_nor_map->phys, s3c_nor_map->size);simple_map_init(s3c_nor_map);printk("use cfi_probe\n");s3c_nor_mtd = do_map_probe("cfi_probe", s3c_nor_map);if(!s3c_nor_mtd){printk("use jedec_probe\n");s3c_nor_mtd = do_map_probe("jedec_probe", s3c_nor_map);}if(!s3c_nor_mtd){iounmap(s3c_nor_map->virt);kfree(s3c_nor_map);return -EIO;}return 0;
}static void s3c_nor_exit(void)
{iounmap(s3c_nor_map->virt);kfree(s3c_nor_map);
}module_init(s3c_nor_init);
module_exit(s3c_nor_exit);
MODULE_LICENSE("GPL");
测试驱动:
# insmod s3c_nor.ko
use cfi_probe
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.
(3)vi s3c_nor.c(添加分区)
static struct map_info *s3c_nor_map;
static struct mtd_info *s3c_nor_mtd;static struct mtd_partition s3c_nor_parts[] = {[0] = {.name = "bootloader_nor",.size = 0x00040000,.offset = 0,},[1] = {.name = "root_nor",.offset = MTDPART_OFS_APPEND,.size = MTDPART_SIZ_FULL,}
};static int s3c_nor_init(void)
{s3c_nor_map = kzalloc(sizeof(struct map_info), GFP_KERNEL);s3c_nor_map->name = "s3c_nor";s3c_nor_map->phys = 0;s3c_nor_map->size = 0x1000000;s3c_nor_map->bankwidth = 2;s3c_nor_map->virt = ioremap(s3c_nor_map->phys, s3c_nor_map->size);simple_map_init(s3c_nor_map);printk("use cfi_probe\n");s3c_nor_mtd = do_map_probe("cfi_probe", s3c_nor_map);if(!s3c_nor_mtd){printk("use jedec_probe\n");s3c_nor_mtd = do_map_probe("jedec_probe", s3c_nor_map);}if(!s3c_nor_mtd){iounmap(s3c_nor_map->virt);kfree(s3c_nor_map);return -EIO;}add_mtd_partitions(s3c_nor_map, s3c_nor_parts, 2);return 0;
}static void s3c_nor_exit(void)
{del_mtd_partitions(s3c_nor_map);iounmap(s3c_nor_map->virt);kfree(s3c_nor_map);
}
测试驱动:
# insmod s3c_nor.ko
use cfi_probe
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-0x00040000 : "bootloader_nor"
0x00040000-0x00200000 : "root_nor"
# ls /dev/mtd*
/dev/mtd0 /dev/mtd1 /dev/mtdblock0
/dev/mtd0ro /dev/mtd1ro /dev/mtdblock1
Linux系统中/dev/mtd与/dev/mtdblock的区别 - hnrainll - 博客园 (cnblogs.com)
可以继续格式化、挂接、建立文件!