打印

k9f1208写Spare的问题, 帮忙看一下

[复制链接]
1963|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
amixice|  楼主 | 2007-10-30 21:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
下面是读写K9F1208一个page的程序.
在int Nand_WriteChunkToNAND(struct yaffs_DeviceStruct *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare){
函数中出错了.

当 data!=NULL, spare!=NULL(写整个页,包括Spare)时能够写正确.
但当date==NULL, spare!=NUL(只写SPare)L时会出错.


int Nand_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare)
{
    int i;
    
    NAND_ENABLE_CE(0);        //Enable Flash

    if(data)
    {    // read main data
        WRITE_NAND_COMMAND(0x00, 0);         // ponit to C eara
        WRITE_NAND_ADDRESS(0x00, 0);        // start from 0
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND), 0);
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND>>8), 0);
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND>>16), 0);
        for(i=0; i<10; i++);
        NAND_WAIT_READY(0);                    //wait
        for(i=0; i<BYTES_PER_PAGE; i++)
            *data++ = READ_NAND(0);
        
        if(spare)
        {// and spare
            data = (__u8 *)spare;
            for(i=0; i<BYTES_OF_SPARE; i++)
                *data++ = READ_NAND(0);
        }
    }
    else if(spare)
    { // only spare
        WRITE_NAND_COMMAND(0x50, 0);         // ponit to C eara
        WRITE_NAND_ADDRESS(0x00, 0);        // start from 0
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND), 0);
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND>>8), 0);
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND>>16), 0);
        for(i=0; i<10; i++);
        NAND_WAIT_READY(0);                    //wait
        data = (__u8 *)spare;
        for(i=0; i<BYTES_OF_SPARE; i++)
            *data++ = READ_NAND(0);
    }
    
    NAND_DISABLE_CE(0);        //Enable Flash

    return YAFFS_OK;
}

int Nand_WriteChunkToNAND(struct yaffs_DeviceStruct *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare){

    __u8 *readback, *pwrite;
    int i;
    int rc = YAFFS_OK;

    if((readback = malloc(BYTES_PER_PAGE + BYTES_OF_SPARE)) == NULL)
    {
        printf ("malloc return NULL ");
        return YAFFS_FAIL;
    }

    NAND_ENABLE_CE(0);        //Enable Flash
    if(data)
    {    // write data       
        WRITE_NAND_COMMAND(0x00, 0);         // ponit to A eara
        WRITE_NAND_COMMAND(0x80, 0);        // sequence command
        WRITE_NAND_ADDRESS(0x00, 0);        // start from 0
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND), 0);
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND>>8), 0);
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND>>16), 0);
        pwrite = data;
        for(i=0; i<BYTES_PER_PAGE; i++)
            WRITE_NAND(*pwrite++, 0);
        if(spare)
        { // and spare
            pwrite = (__u8 *)spare;
            for(i=0; i<BYTES_OF_SPARE; i++)
                WRITE_NAND(*pwrite++, 0);
        }
        WRITE_NAND_COMMAND(0x10, 0);        // program command
        for(i=0; i<10; i++);
        NAND_WAIT_READY(0);                    //wait
        WRITE_NAND_COMMAND(0x70, 0);        // read status command
        if(0x00 != (READ_NAND(0) & 0x01))
        {
            rc = YAFFS_FAIL;
        }
    }
    else if(spare)
    { // only spare
        WRITE_NAND_COMMAND(0x50, 0);         // ponit to C eara
        WRITE_NAND_COMMAND(0x80, 0);        // sequence command
        WRITE_NAND_ADDRESS(0x00, 0);        // start from 0
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND), 0);
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND>>8), 0);
        WRITE_NAND_ADDRESS(0xff&(chunkInNAND>>16), 0);
        pwrite = (__u8 *)spare;
        for(i=0; i<BYTES_OF_SPARE; i++)
            WRITE_NAND(*pwrite++, 0);
        WRITE_NAND_COMMAND(0x10, 0);        // program command
        for(i=0; i<10; i++);
        NAND_WAIT_READY(0);                    //wait
        WRITE_NAND_COMMAND(0x70, 0);        // read status command
        if(0x00 != (READ_NAND(0) & 0x01))
        {
            rc = YAFFS_FAIL;
        }
    
    }
    NAND_DISABLE_CE(0);        //Enable Flash

    Nand_ReadChunkFromNAND((struct yaffs_DeviceStruct *)0, chunkInNAND, readback, (yaffs_Spare *)&readback[BYTES_PER_PAGE]);
    if(data)
    {
        if(0 != memcmp(readback, data, BYTES_PER_PAGE))
        {
            printf("write Data error ");
            rc = YAFFS_FAIL;
        }
        else
            printf("write Data ok ");
    }
    if(spare)
    {
        if(0 != memcmp(readback+BYTES_PER_PAGE, (__u8 *)spare, BYTES_OF_SPARE))
        {
            printf("write Spare error ");
            rc = YAFFS_FAIL;
        }
        else
            printf("write Spare ok ");
    }
    free(readback);
    return rc;
}

相关帖子

沙发
amixice|  楼主 | 2007-10-30 21:41 | 只看该作者

运行时的输出

write Data ok
write Spare ok
write Data ok
write Spare ok
write Data ok
write Spare ok
write Data ok
write Spare ok
write Data ok
write Spare ok
write Data ok
write Spare ok
write Data ok
write Spare ok
write Data ok
write Spare ok
write Data ok
write Spare ok
write Data ok
write Spare ok
write Data ok
write Spare ok
**>>ecc error fix performed on chunk 768:0
**>>Block 24 marked for retirement
write Data ok
write Spare ok
write Spare error

前面都是data!=NULL spare!=NULL时 都是成功的
最后一次只写Spare时 是 Write Spare error. 还有很多, 只写Spare没有成功过

 # write /nand/u-boot 33000000 5000
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error
write Spare error



使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

13

主题

64

帖子

0

粉丝