主题 : SPI外接spi flash後無法正常開機 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 35534
精华: 0
发帖: 15
金钱: 75 两
威望: 15 点
综合积分: 30 分
注册时间: 2011-01-03
最后登录: 2017-09-13
楼主  发表于: 2011-02-18 16:07

 SPI外接spi flash後無法正常開機

小弟使用的開發板為mini6410, kernel版本為2.6.36
外接spi flash為MXIC的mx25l3205d
爬文依照先前其他大大移植spi的方法,
也成功加入spidev並且使用spidev_test.c測試成功
但後來接上spi flash,且加入mtd partition,就無法開機了

小弟的修改步驟如下

先在mach-mini6410.c裡

加入標頭檔

#include <linux/spi/spi.h>
#include <linux/spi/flash.h>
#include <plat/s3c64xx-spi.h>

以及宣告下列spi所需結構並初始化

void set level(unsigned line_id,int lvl){}

static struct s3c64xx_spi_csinfo spi0_csinfo={
    .set_level = setlevel,    //指派function pointer
};

加入NOR flash MTD partition資訊
static struct mtd_partition spiflash_partition[]={
    {
    .name = "SPI flash partition 1",
    .offset = 0,
    .size = SZ_1M,
    },

    {
    .name = "SPI flash partition 1",
    .offset = MTDPART_OFS_APPEND,
    .size = MTDPART_SIZ_FULL,
    },
}

加入platfrom data
static struct flash_platform_data spiflash_pdata = {
    .name = "mx25l3205d",
    .parts = spiflash_partition,
    .nr_parts = ARRAY_SIZE(spiflash_partition),
    .type = "mx25l3205d",
}

宣告spi_board_info
static struct spi_board_info s3c64xx_spiflash_board[]={
[0] = {
        .modalias = "m25p80",
        .mode = SPI_MODE_0,
    .bus_num = 0,
        .chip_select = 0,
        .max_speed_hz = 4*1000*1000,
        .controller_data = &spi0_csinfo,
    .platform_data = &spiflash_pdata,
       },
};

接著在 platform_device *mini6410_devices[ ] __initdata裡加入
&s3c64xx_device_spi0,
這個device

最後在mini6410_machine_init中加入初始化及註冊的函式
s3c64xx_spi_set_info(0,0,1);       // (0,1,1)表示為spi "0" pdata, 使用clk["0"]=pclk, 以及num_cs =1
spi_register_board_info(s3c64xx_spiflash_board,ARRAY_SIZE(s3c64xx_spiflash_board));



重編kernel後測試,發現SPI flash有正常運作(read id正確)
mtd partition也如下顯示,看起來是ok

Creating 2 MTD partitions on "mx25l3205d":
0x000000000000-0x000000100000 : "SPI flash partition 1"
mtd: Giving out device 0 to SPI flash partition 1
0x000000100000-0x000000400000 : "SPI flash partition 2"
mtd: Giving out device 1 to SPI flash partition 2
S3C NAND Driver, (c) 2008 Samsung Electronics
S3C NAND Driver is using hardware ECC.
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND 256MiB 3,3V 8-bit)
Creating 3 MTD partitions on "NAND 256MiB 3,3V 8-bit":
0x000000000000-0x000000080000 : "Bootloader"
mtd: Giving out device 2 to Bootloader
0x000000080000-0x000000580000 : "Kernel"
mtd: Giving out device 3 to Kernel
0x000000580000-0x000010000000 : "File System"
mtd: Giving out device 4 to File System

但最後卻顯示
FAT: utf8 is not a recommended IO charset for FAT filesystems, filesystem will be case sensitive!
mmcblk0: mmc0:0001 SD512 489 MiB
mmcblk0: p1
FAT: utf8 is not a recommended IO charset for FAT filesystems, filesystem will be case sensitive!
yaffs: dev is 32505858 name is "mtdblock2" ro
yaffs: passed flags ""
s3c6400_setup_sdhci_cfg_card: CTRL 2=c0004120, 3=80808080
yaffs: dev is 32505858 name is "mtdblock2" ro
yaffs: passed flags ""
mount: mounting /dev/mtdblock2 on /r failed: Invalid argument
/init: line 102: can't open /r/dev/console: no such file

Kernel panic - not syncing: Attempted to kill init!
[<c0165464>] (unwind_backtrace+0x0/0xe4) from [<c033f0d4>] (panic+0x58/0x174)
[<c033f0d4>] (panic+0x58/0x174) from [<c017f680>] (do_exit+0x68/0x5cc)
[<c017f680>] (do_exit+0x68/0x5cc) from [<c017fea8>] (do_group_exit+0x90/0xc4)
[<c017fea8>] (do_group_exit+0x90/0xc4) from [<c017feec>] (sys_exit_group+0x10/0x18)
one_wire_status: 2
[<c017feec>] (sys_exit_group+0x10/0x18) from [<c015fe20>] (ret_fast_syscall+0x0/0x30)
one_wire_status: 4

後來測試時發現,如果nor flash不做add mtd partition的話 可以正常運作
不會有mounting failed
但加入mtd就會出現如上錯誤 不知道問題出在哪
不知道有沒有大大有相關經驗可以幫忙解答的
小弟感謝不盡