我用的是MX9328的开发板,上面有16M的FLASH
我用的是MX9328的开发板,上面有两片共16MFLASH,芯片是mt28s4m16lc_6,我想用MTD来驱动他们,因此我在/linux/drivers/mtd/maps下写了自己的.c文件,内容如下:#include <linux/module.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <asm/io.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/map.h>
#include <linux/mtd/partitions.h>
#include <linux/config.h>
#define WINDOW_ADDR 0X0C000000
#define WINDOW_SIZE 0x01000000
#define BUSWIDTH 4
static struct mtd_info *mymtd;
__u8 mx9328_read8(struct map_info *map, unsigned long ofs)
{
return __raw_readb(map->map_priv_1 + ofs);
}
__u16 mx9328_read16(struct map_info *map, unsigned long ofs)
{
return __raw_readw(map->map_priv_1 + ofs);
}
__u32 mx9328_read32(struct map_info *map, unsigned long ofs)
{
return __raw_readl(map->map_priv_1 + ofs);
}
#ifdef CFI_WORD_64
__u64 mx9328_read64(struct map_info *map, unsigned long ofs)
{
return __raw_readll(map->map_priv_1 + ofs);
}
#endif
void mx9328_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
{
memcpy_fromio(to, map->map_priv_1 + from, len);
}
void mx9328_write8(struct map_info *map, __u8 d, unsigned long adr)
{
__raw_writeb(d, map->map_priv_1 + adr);
mb();
}
void mx9328_write16(struct map_info *map, __u16 d, unsigned long adr)
{
__raw_writew(d, map->map_priv_1 + adr);
mb();
}
void mx9328_write32(struct map_info *map, __u32 d, unsigned long adr)
{
__raw_writel(d, map->map_priv_1 + adr);
mb();
}
#ifdef CFI_WORD_64
void mx9328_write64(struct map_info *map, __u64 d, unsigned long adr)
{
__raw_writell(d, map->map_priv_1 + adr);
mb();
}
#endif
void mx9328_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
{
memcpy_toio(map->map_priv_1 + to, from, len);
}
struct map_info mx9328_map = {
name: "mx9328 flash device",
size: WINDOW_SIZE,
buswidth: BUSWIDTH,
read8: mx9328_read8,
read16: mx9328_read16,
read32: mx9328_read32,
#ifdef CFI_WORD_64
read64: mx9328_read64,
#endif
copy_from: mx9328_copy_from,
write8: mx9328_write8,
write16: mx9328_write16,
write32: mx9328_write32,
#ifdef CFI_WORD_64
write64: mx9328_write64,
#endif
copy_to: mx9328_copy_to
};
/*this is my important code#######################
* MTD 'PARTITIONING' STUFF
*/
static struct mtd_partition mx9328_partitions[]={
{
name: "bootloader (1M)",
size: 0x100000,
offset: 0x0
},
{
name: "kernel (2M)",
size: 0x200000,
offset: 0x100000
}
{
name: "filesystem (11M)",
size:0x0b00000,
offset:0x300000
}
{
name: "fdisk (2M)",
size:0x0200000,
offset:0xe00000
}
};
/*my partition is end */
int __init init_mx9328(void)
{
static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", 0 };
const char **type;
printk(KERN_NOTICE "mx9328 flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
mx9328_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
if (!mx9328_map.map_priv_1) {
printk("Failed to ioremap\n");
return -EIO;
}
mymtd = 0;
type = rom_probe_types;
for(; !mymtd && *type; type++) {
mymtd = do_map_probe(*type, &mx9328_map);
}
if (mymtd) {
mymtd->module = THIS_MODULE;
mymtd->erasesize=0x80000;
add_mtd_device(mymtd);
return 0;
}
iounmap((void *)mx9328_map.map_priv_1);
return -ENXIO;
}
static void __exit cleanup_mx9328(void)
{
if (mymtd) {
del_mtd_device(mymtd);
map_destroy(mymtd);
}
if (mx9328_map.map_priv_1) {
iounmap((void *)mx9328_map.map_priv_1);
mx9328_map.map_priv_1 = 0;
}
}
module_init(init_mx9328);
module_exit(cleanup_mx9328);
内核的.config文件mtd部分配置如下:
#
# Memory Technology Devices (MTD)
#
CONFIG_MTD=y
CONFIG_MTD_DEBUG=y
CONFIG_MTD_DEBUG_VERBOSE=3
CONFIG_MTD_PARTITIONS=y
# CONFIG_MTD_CONCAT is not set
# CONFIG_MTD_REDBOOT_PARTS is not set
# CONFIG_MTD_BOOTLDR_PARTS is not set
# CONFIG_MTD_AFS_PARTS is not set
CONFIG_MTD_CHAR=y
CONFIG_MTD_BLOCK=y
# CONFIG_FTL is not set
# CONFIG_NFTL is not set
#
# RAM/ROM/Flash chip drivers
#
CONFIG_MTD_CFI=y
CONFIG_MTD_JEDECPROBE=y
CONFIG_MTD_GEN_PROBE=y
CONFIG_MTD_CFI_ADV_OPTIONS=y
CONFIG_MTD_CFI_NOSWAP=y
# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
CONFIG_MTD_CFI_GEOMETRY=y
# CONFIG_MTD_CFI_B1 is not set
# CONFIG_MTD_CFI_B2 is not set
CONFIG_MTD_CFI_B4=y
# CONFIG_MTD_CFI_B8 is not set
# CONFIG_MTD_CFI_I1 is not set
CONFIG_MTD_CFI_I2=y
# CONFIG_MTD_CFI_I4 is not set
# CONFIG_MTD_CFI_I8 is not set
# CONFIG_MTD_CFI_INTELEXT is not set
# CONFIG_MTD_CFI_AMDSTD is not set
# CONFIG_MTD_RAM is not set
# CONFIG_MTD_ROM is not set
# CONFIG_MTD_ABSENT is not set
# CONFIG_MTD_OBSOLETE_CHIPS is not set
# CONFIG_MTD_AMDSTD is not set
# CONFIG_MTD_SHARP is not set
# CONFIG_MTD_JEDEC is not set
#
# Mapping drivers for chip access
CONFIG_MTD_M9328=y
但启动后不管CFI还是jedec都没有监测到FLASH,请问这是怎么回事呢? 我想,应该现查一查,这两片NOR FLASH的厂商,型号. 以便在.config确定flash chip driver.其次分区的格式有问题,因为你是两片FLASH, 所以应该有两个物理分区影射.如下
static struct mtd_patitions your_patitions ={
{
FLASH 1 PARTITIONS
},
{
FLASH 2 PARTITONS
}
}
应该注意在只设定一个PAYSMAP_START_ADDRESS 时,两片FLASH 地址应该连续, 并且每个FLASH的PARTITIONS 应该是0x2000的整数倍.
页:
[1]