/proc/mtd 下看不到分区信息

zhouyiwu 2010-10-13 06:34:06
用的芯片为lpc313x,flash为AT45xxx DataFlash。
系统能够跑起来,但在/proc/mtd下看不到分区信息。

分区表添加在 arch/arm/mach-lpc313x/ea313x.c

#if defined(CONFIG_MTD_DATAFLASH)

#if 1 //定义SPI FLASH的分区表
#define SIZE_1PAGE 528
#define SIZE_1M (unsigned long)(1024*1024)
static struct mtd_partition lpc31xx_dataflash_partition[] = {
{
.name = "U-boot",
.offset = 0,
.size = 496*SIZE_1PAGE,
},
{
.name = "U-BOOT Env",
.offset = 496*SIZE_1PAGE,
.size = 248*SIZE_1PAGE,
},
{
.name ="Kernel",
.offset=744*SIZE_1PAGE,
.size = 2979*SIZE_1PAGE,
},
{
.name ="Root fs",
.offset=3724*SIZE_1PAGE,
.size = 3045*SIZE_1PAGE,
},
{
.name ="User Config",
.offset=6780*SIZE_1PAGE,
.size = 200*SIZE_1PAGE,
},
};


struct flash_platform_data dataflash_atmel_netled = {
.name="AT45DB321",
.parts=lpc31xx_dataflash_partition,
.nr_parts=ARRAY_SIZE(lpc31xx_dataflash_partition),
};

#endif


/* MTD Data FLASH driver registration */
static int __init lpc313x_spimtd_register(void)
{
struct spi_board_info info =
{
.modalias = "mtd_dataflash",
.max_speed_hz = 8000000,
.bus_num = 0,
.chip_select = 0, //原值为0
.platform_data=&dataflash_atmel_netled, //添加

};

return spi_register_board_info(&info, 1);
}


driver/mtd/device/mtd_dataflash.c

static int __devinit dataflash_probe(struct spi_device *spi)
{
int status;
struct flash_info *info;

printk(" dataflash_probe\n");

/*
* Try to detect dataflash by JEDEC ID.
* If it succeeds we know we have either a C or D part.
* D will support power of 2 pagesize option.
* Both support the security register, though with different
* write procedures.
*/
info = jedec_probe(spi);
if (IS_ERR(info))
return PTR_ERR(info);
if (info != NULL)
return add_dataflash_otp(spi, info->name, info->nr_pages,
info->pagesize, info->pageoffset,
(info->flags & SUP_POW2PS) ? 'd' : 'c');

/*
* Older chips support only legacy commands, identifing
* capacity using bits in the status byte.
*/
status = dataflash_status(spi);

printk(" status = %02X\n", status & 0x3c);

if (status <= 0 || status == 0xff) {
DEBUG(MTD_DEBUG_LEVEL1, "%s: status error %d\n",
spi->dev.bus_id, status);
if (status == 0 || status == 0xff)
status = -ENODEV;
return status; //status = 0xff,导致后面的代码未被执行,mtd_dataflash未被添加
}

/* if there's a device there, assume it's dataflash.
* board setup should have set spi->max_speed_max to
* match f(car) for continuous reads, mode 0 or 3.
*/

switch (status & 0x3c) {
case 0x0c: /* 0 0 1 1 x x */
status = add_dataflash(spi, "AT45DB011B", 512, 264, 9);
break;
case 0x14: /* 0 1 0 1 x x */
status = add_dataflash(spi, "AT45DB021B", 1024, 264, 9);
break;
case 0x1c: /* 0 1 1 1 x x */
status = add_dataflash(spi, "AT45DB041x", 2048, 264, 9);
break;
case 0x24: /* 1 0 0 1 x x */
status = add_dataflash(spi, "AT45DB081B", 4096, 264, 9);
break;
case 0x2c: /* 1 0 1 1 x x */
status = add_dataflash(spi, "AT45DB161x", 4096, 528, 10);
break;
case 0x34: /* 1 1 0 1 x x */
printk("m.j.y 0x34\n");
status = add_dataflash(spi, "AT45DB321x", 8192, 528, 10);
break;
case 0x38: /* 1 1 1 x x x */
case 0x3c:
printk(" 0x3C\n");
status = add_dataflash(spi, "AT45DB642x", 8192, 1056, 11);
break;
/* obsolete AT45DB1282 not (yet?) supported */
default:
DEBUG(MTD_DEBUG_LEVEL1, "%s: unsupported device (%x)\n",
spi->dev.bus_id, status & 0x3c);
status = -ENODEV;
}

if (status < 0)
DEBUG(MTD_DEBUG_LEVEL1, "%s: add_dataflash --> %d\n",
spi->dev.bus_id, status);

return status;
}

如何改代码,求高人指教!
...全文
566 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zhouyiwu 2010-10-15
[root@nxp block]# cd /sys/block
[root@nxp block]# ls
mtdblock0 mtdblock3 ram1 ram12 ram15 ram4 ram7
mtdblock1 mtdblock4 ram10 ram13 ram2 ram5 ram8
mtdblock2 ram0 ram11 ram14 ram3 ram6 ram9
回复
zhouyiwu 2010-10-15
/*
* Older chips support only legacy commands, identifing
* capacity using bits in the status byte.
*/
status = dataflash_status(spi);

printk(" status = %02X\n", status & 0x3c);

add_dataflash(spi, "AT45DB321x", 8192, 528, 10);

if (status <= 0 || status == 0xff) {
DEBUG(MTD_DEBUG_LEVEL1, "%s: status error %d\n",
spi->dev.bus_id, status);
if (status == 0 || status == 0xff)
status = -ENODEV;
return status; //status = 0xff,导致后面的代码未被执行,mtd_dataflash未被添加
}


添加红色那行代码
分区信息可以见
但又出现另外的问题

往flash写文件时出错了
例如写文件a
内容为12345
Write verify error (ECC OK or unused) at 00016b00. Wrote:
00000000: 85 19 01 e0 29 00 00 00 6d a6 2f d7 01 00 00 00
00000010: 01 00 00 00 02 00 00 00 d1 01 00 00 01 08 00 00
00000020: a3 7f 5b fd ce 51 b5 3a 61 ff ff ff 85 19 02 e0
00000030: 4a 00 00 00 2e 8c 28 78 02 00 00 00 02 00 00 00
00000040: a4 81 00 00 00 00 00 00 06 00 00 00 d1 01 00 00
00000050: d1 01 00 00 d1 01 00 00 00 00 00 00 06 00 00 00
00000060: 06 00 00 00 00 00 00 00 45 0e df 97 b6 d2 54 ae
00000070: 31 32 33 34 35 0a ff ff 85 19 02 e0 44 00 00 00
00000080: 1d fb f7 98 02 00 00 00 03 00 00 00 a4 81 00 00
00000090: 00 00 00 00 06 00 00 00 d1 01 00 00 d1 01 00 00
000000a0: d1 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000000b0: 00 00 00 00 00 00 00 00 b3 46 2e ad 85 19 04 20
000000c0: 54 01 00 00 73 cd 60 f6 00 00 00 00 00 00 00 00
000000d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000000e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000000f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000110: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000120: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000130: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000140: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000150: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000160: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000170: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000180: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000190: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000001f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000200: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Read back:
00000000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000010: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000020: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000030: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000040: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000050: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000060: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000070: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000080: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000090: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000000a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000000b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000000c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000000d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000000e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000000f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000100: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000110: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000120: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000130: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000140: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000150: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000160: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000170: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000180: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000190: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000001a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000001b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000001c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000001d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000001e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
000001f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00000200: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
About to refile bad block at 00016b00
Refiling block at 00016b00 to bad_used_list
回复
zhouyiwu 2010-10-15
[root@nxp block]# ls /sys/block/
ram0 ram10 ram12 ram14 ram2 ram4 ram6 ram8
ram1 ram11 ram13 ram15 ram3 ram5 ram7 ram9
回复
dfysy 2010-10-15
[Quote=引用 3 楼 zhouyiwu 的回复:]
有下面这两个文件夹
/sys/bus/spi/drivers/mtd_dataflash
/sys/bus/spi/devices/spi0.0
[/Quote]
这个只是在bus上注册了驱动,并没有注册MTD驱动啊,你看看你的/sys/block下有你的mtdblock设备吗?关键你的代码里面似乎没有调用add_mtd_partitions的地方,这样也能出MTD设备?!
回复
dfysy 2010-10-14
为啥没有add_mtd_partitions的调用?
回复
zhouyiwu 2010-10-14
有下面这两个文件夹
/sys/bus/spi/drivers/mtd_dataflash
/sys/bus/spi/devices/spi0.0
回复
zhouyiwu 2010-10-14
补充

错误信息为

spi0.0: status error 255

spi_lpc313x spi_lpc313x.0: LPC313x SPI driver
回复
相关推荐
发帖
Linux_Kernel
创建于2007-08-27

4152

社区成员

Linux/Unix社区 内核源代码研究区
申请成为版主
帖子事件
创建了帖子
2010-10-13 06:34
社区公告
暂无公告