编写Nor map驱动
-rwxr-xr-x 1
enzo enzo 253K 5月 18 16:32 u-boot.bin
Nor flash前256K存放uboot,所以驱动中定义的mtd_partition 要把uboot的空间留出来,不要破坏uboot
-
/*
-
* mini2440 nor flash mappings of chips in physical memory
-
*
-
*/
-
#include <linux/module.h>
-
#include <linux/types.h>
-
#include <linux/kernel.h>
-
#include <linux/init.h>
-
#include <asm/io.h>
-
#include <linux/mtd/mtd.h>
-
#include <linux/mtd/map.h>
-
-
#ifdef CONFIG_MTD_PARTITIONS
-
#include <linux/mtd/partitions.h>
-
#endif
-
-
#define WINDOW_ADDR 0x00000000 /* physical properties of flash */
-
#define WINDOW_SIZE 0x0200000 /*2M*/
-
#define BUSWIDTH 2 /*16bit bus*/
-
#define FLASH_BLOCKSIZE_MAIN 0x20000
-
#define FLASH_NUMBLOCKS_MAIN 128
-
/* can be "cfi_probe", "jedec_probe", "map_rom", NULL }; */
-
#define PROBETYPES { "cfi_probe","jedec_probe", "map_rom",NULL } /*mini2440 nor is jedec*/
-
-
#define MSG_PREFIX "Mini2440-NOR:" /* prefix for our printk()'s */
-
#define MTDID "Mini2440-nor" /* for mtdparts= partitioning */
-
-
static struct mtd_info *mymtd;
-
-
struct map_info mini2440nor_map = {
-
.name = "NOR flash on mini2440",
-
.size = WINDOW_SIZE,
-
.bankwidth = BUSWIDTH,
-
.phys = WINDOW_ADDR,
-
};
-
-
#ifdef CONFIG_MTD_PARTITIONS
-
-
/*
-
* MTD partitioning stuff
-
*/
-
static struct mtd_partition static_partitions[] =
-
{
-
{
-
.name = "Bootloader",
-
.size = 256*1024,
-
.offset = 0
-
},
-
{
-
.name = "reserve",
-
.size = MTDPART_SIZ_FULL,
-
.offset = MTDPART_OFS_APPEND
-
},
-
-
};
-
-
static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
-
-
#endif
-
-
static int mtd_parts_nb = 0;
-
static struct mtd_partition *mtd_parts = 0;
-
-
static int __init init_mini2440nor(void)
-
{
-
static const char *rom_probe_types[] = PROBETYPES;
-
const char **type;
-
const char *part_type = 0;
-
-
printk(KERN_NOTICE MSG_PREFIX "0x%08x at 0x%08xn",
-
WINDOW_SIZE, WINDOW_ADDR);
-
mini2440nor_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
-
-
if (!mini2440nor_map.virt) {
-
printk(MSG_PREFIX "failed to ioremapn");
-
return -EIO;
-
}
-
-
simple_map_init(&mini2440nor_map);
-
-
mymtd = 0;
-
type = rom_probe_types;
-
for(; !mymtd && *type; type++) {
-
mymtd = do_map_probe(*type, &mini2440nor_map);
-
}
-
if (mymtd) {
-
mymtd->owner = THIS_MODULE;
-
-
#ifdef CONFIG_MTD_PARTITIONS
-
mtd_parts_nb = parse_mtd_partitions(mymtd, probes, &mtd_parts, MTDID);
-
if (mtd_parts_nb > 0)
-
part_type = "detected";
-
-
if (mtd_parts_nb == 0)
-
{
-
mtd_parts = static_partitions;
-
mtd_parts_nb = ARRAY_SIZE(static_partitions);
-
part_type = "static";
-
}
-
#endif
-
/* 注册设备 */
-
add_mtd_device(mymtd);
-
if (mtd_parts_nb == 0)
-
printk(KERN_NOTICE MSG_PREFIX "no partition info availablen");
-
else
-
{
-
printk(KERN_NOTICE MSG_PREFIX
-
"using %s partition definitionn", part_type);
-
add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb);
-
}
-
return 0;
-
}
-
-
iounmap((void *)mini2440nor_map.virt);
-
return -ENXIO;
-
}
-
-
static void __exit cleanup_mini2440nor(void)
-
{
-
if (mymtd) {
-
del_mtd_device(mymtd);
-
map_destroy(mymtd);
-
}
-
if (mini2440nor_map.virt) {
-
iounmap((void *)mini2440nor_map.virt);
-
mini2440nor_map.virt = 0;
-
}
-
}
-
-
module_init(init_mini2440nor);
-
module_exit(cleanup_mini2440nor);
-
-
MODULE_LICENSE("GPL");
-
MODULE_AUTHOR("Enzo Fang ");
-
MODULE_DESCRIPTION("Generic configurable MTD map driver");
修改内核Makefile,Kconfig
修改/driver/mtd/maps/Makeconfig
obj-$(CONFIG_MTD_EDB7312) += edb7312.o
obj-$(CONFIG_MTD_MINI2440) += mini2440flash.o
修改/drivers/mtd/maps/Kconfig
config MTD_EDB7312
tristate
"CFI Flash device mapped on EDB7312"
depends on
ARCH_EDB7312 && MTD_CFI
help
This enables access to the CFI Flash on the
Cogent EDB7312 board.
If you have such a board, say 'Y' here.
config MTD_MINI2440
tristate
"CFI Flash device mapped on MINI2440"
depends on
ARM && MTD_CFI
help
This enables access to the CFI Flash on the
MINI2440 board.
If you have such a board, say 'Y' here.
结果:
# cat /proc/mtd
dev: size erasesize name
mtd0: 00200000 00001000 "NOR flash on
mini2440"
mtd1: 00040000 00001000 "Bootloader"
mtd2: 001c0000 00001000 "reserve"
//todo 将nor加入平台驱动
格式化nor flash
//todo为文件系统添加mtd-utils
[*] mtd-utils
[*] erase
[*] eraseall
[*] mkfs.jff2
擦除相应的存放jffs2文件系统的块
# eraseall /dev/mtd2
把该块以jffs2格式挂载到mnt下,这样在mnt目录下面就能执行任何写操作了。
# mount -t jffs2 /dev/mtdblock3 /mnt/
6.掉电重启,需要重新执行一遍mount -t jffs2 /dev/mtdblock3 /mnt/
阅读(1806) | 评论(0) | 转发(0) |