TI中文支持网
TI专业的中文技术问题搜集分享网站

nandflash读写问题

自己做了一块板子,参考的是官方的原理图,把nand512r3r换成了s30ms01gp25tfw50,参数变成了有1024block,每块64page,每page2048bytes,然后我将mcsdk里的例程nand_write_evmc6678l里的相关参数做了更改,再向里面烧写数据,主函数里调用了两个flash_nand,第一个调用时没有报错,到了第二次调用时在执行flash_nand里的函数时到了块检测那一步就报错了,请各位大侠不吝赐教

void main ()
{
FILE *fp;
platform_init_flags init_flags;
platform_init_config init_config;
PLATFORM_DEVICE_info *p_device;
Bool ret;
uint32_t rCount;
p_device=(PLATFORM_DEVICE_info *)0x80000000;
printf("NAND Writer Utility Version %s\n\n", version);

fp = fopen(input_file, "r");
if (fp == NULL)
{
printf("Error in opening %s input file\n", input_file);
return;
}

ret = parse_input_file(fp);
fclose (fp);

if (ret == FALSE)
{
printf("Error in parsing %s input file\n", input_file);
return;
}

/* Initialize main Platform lib */
memset(&init_config, 0, sizeof(platform_init_config));
memset(&init_flags, 1, sizeof(platform_init_flags));
init_flags.pll = 0;
init_flags.ddr = 0;

p_device->manufacturer_id = 0x2C;
p_device->device_id = 0xA1;
p_device->type = PLATFORM_DEVICE_NAND;
p_device->width = 8;
p_device->block_count = 1024;
p_device->page_count = 64;
p_device->page_size = 2048;
p_device->spare_size = 64;
p_device->handle = 0x2CA1;
p_device->bboffset = 5;
p_device->column = 2048;
p_device->flags = 0;
p_device->internal = NULL;
p_device->bblist = NULL;

 if(flash_nand (p_device) == FALSE)                          第一个
{
printf ("NAND device open failed!\n");
 return;
 }
//#if !(defined(_EVMC6657L_))
// p_device = platform_device_open(PLATFORM_DEVID_NAND512R3A2D, 0);
//#else
// p_device = platform_device_open(0x2CA1, 0);
//#endif
if (p_device == NULL) {
printf ("NAND device open failed!\n");
print_platform_errno();
return;
}
nandWriterInfo.deviceTotalBytes = p_device->block_count * p_device->page_count * p_device->page_size;
nandWriterInfo.blockSizeBytes = p_device->page_count * p_device->page_size;
nandWriterInfo.startAddr = 131072;

if ((nandWriterInfo.startAddr % nandWriterInfo.blockSizeBytes) != 0)
{
printf ("The start programming address 0x%8x set in %s is not at the beginning of a block, block size = 0x%4x\n", nandWriterInfo.startAddr, nandWriterInfo.file_name,
nandWriterInfo.blockSizeBytes);
return;
}

/* Check if we need to erase the nand completely */
if (nand_erase_flag == 0x12345678)
{
if (nand_erase_all_blks(p_device) == FALSE)
{
printf ("Formatting all nand blocks – failed \n");
}
else
{
printf ("Formatting all nand blocks – Successful\n");
}
platform_device_close(p_device->handle);
/* Operation Complete */
return;
}

/* Open and find the length of the data file */
fp = fopen (nandWriterInfo.file_name, "rb");
if (fp == NULL)
{
printf ("Failed to open file %s\n", nandWriterInfo.file_name);
platform_device_close(p_device->handle);
return;
}

/* Parse the CCS format file */
ret = find_file_length(fp);
fclose (fp);
if (ret == FALSE)
{
printf("Error in parsing CCS file %s\n", nandWriterInfo.file_name);
platform_device_close(p_device->handle);
return;
}

/* Write the flash, verify the results. On read back failure mark
* the block as bad and try rewriting again */
rCount = 0;

do
{
if (flash_nand (p_device) == FALSE)        第二个
{
printf ("NAND write giving up\n");
return;
}

rCount += 1;

} while ((flash_verify (p_device) == FALSE) && (rCount < 5));
if (rCount >= 5) {
printf ("NAND write failed (maximum retries reached)\n");
}
else
{
printf ("NAND programming completed successfully\n");
}

platform_device_close(p_device->handle);
return;
}

flash_nand程序如下

flash_nand
(
PLATFORM_DEVICE_info *p_device
)
{
uint32_t wPos, wLen;
uint32_t block, start_block;
uint8_t *scrach_block;

if (swap_byte)
{
scrach_block = malloc(nandWriterInfo.blockSizeBytes);
if (scrach_block == NULL)
{
printf ("Can not allocate scratch block memory!\n");
return (FALSE);
}
}

start_block = nandWriterInfo.startAddr / nandWriterInfo.blockSizeBytes;

/* Program the NAND */
for (block = start_block, wPos = 0; wPos < nandWriterInfo.writeBytes; block++, wPos += nandWriterInfo.blockSizeBytes)
{
while(checkBadBlockMark(p_device, block))
{
printf ("Bad block # %d detected, skipping block … \n", block);                 这里报错
if (++block == p_device->block_count)
{
printf ("Flash failed: End of device reached\n");
if (swap_byte) free (scrach_block);
return (FALSE);
}
}

printf ("Flashing block %d (%d bytes of %d)\n", block, wPos, nandWriterInfo.writeBytes);

platform_device_erase_block(p_device->handle, block);

wLen = nandWriterInfo.blockSizeBytes;
if (nandWriterInfo.writeBytes – wPos < nandWriterInfo.blockSizeBytes)
{
wLen = nandWriterInfo.writeBytes – wPos;
}

if (swap_byte)
{
formBlock((uint32_t *)(&nandWriterInfo.writeData[wPos]), nandWriterInfo.blockSizeBytes, scrach_block);
}
else
{
scrach_block = &nandWriterInfo.writeData[wPos];
}
if (platform_device_write(p_device->handle, block*nandWriterInfo.blockSizeBytes, scrach_block, wLen) != Platform_EOK)
{
printf ("platform_device_write block # %d failed!\n", block);
print_platform_errno();
if (swap_byte) free (scrach_block);
return (FALSE);
}

}

if (swap_byte) free (scrach_block);
return (TRUE);
}

Shine:

如果你用flash参数不一样,可以改一下源码,然后重新编译一下再使用。

黑夜白羊:

回复 Shine:

Shine Zhang

如果你用flash参数不一样,可以改一下源码,然后重新编译一下再使用。

黑夜白羊:

mcsdk中自带例程中的的读写nandflash的例程,想问一下nandwriter_evmc6678l,想问一下这个工程里调用的库文件里是不是把nandflash的相关参数已经设定好了,如果换用其他的nandflash则无法使用这个库文件

赞(0)
未经允许不得转载:TI中文支持网 » nandflash读写问题
分享到: 更多 (0)