引用 10 楼 codewarrior 的回复:
为什么要先格式化一遍?写的时候不就是每块先擦再写吗?
做好一个和你的NK分区一样大的文件,然后从头写到尾不就行了?
下面是我应用程序中操作NANDFLASH的代码 检查 擦 写 设置 操作 麻烦给指点下 ⊙﹏⊙ 谢谢
for(j=0 ;j
{
for(;;)//
{
if(pBufMsg1->blockID > 15) // CKECK NK BLOCK
{
if(DeviceIoControl(hFirm,
IOCTL_FMD_GET_STATUS,
(PBYTE)pBufMsg1,
sizeof(pBufMsg1),
NULL,
0,
(LPDWORD)firstcom,
NULL) == TRUE)
{
RETAILMSG(1, (L"~~~~~~~~~~~~~ bad block %d ~~~~~~~~~~\r\n",pBufMsg1->blockID));
pBufMsg1->blockID += 1;
continue;
}
// else
// break;
}
//.............. erase block ...............
if(DeviceIoControl(hFirm,
IOCTL_FMD_ERASE,
(PBYTE)pBufMsg1,
sizeof(pBufMsg1),
NULL,
0,
(LPDWORD)firstcom,
NULL) == FALSE)
{
RETAILMSG(1, (TEXT(" ERROR: EraseBlock[%d] \r\n"), pBufMsg1->blockID));
}
//............. get the flash status ...............
if(DeviceIoControl(hFirm,
IOCTL_FMD_GET_STATUS,
(PBYTE)pBufMsg1,
sizeof(pBufMsg1),
NULL,
0,
(LPDWORD)firstcom,
NULL) != TRUE)
{
break;
}
pBufMsg1->blockID += 1;
}
//..........................
pBufMsg1->startSectorAddr = (pBufMsg1->blockID)*64;
if(dwNumSector > 64)
{
dwSectorOFBlock = 64;
}
else
dwSectorOFBlock = dwNumSector;
//............operate a block 64 sector.................
for(i=0 ;i
{
memset(pBufMsg1->pSectorBuff ,0 ,2048);
memset(pBufMsg4->pSectorBuff ,0 ,2048);
BOOL ret = ReadFile(hFile ,(LPVOID)pBufMsg1->pSectorBuff ,2048 ,&k ,NULL);
if(!ret)
{
RETAILMSG(1, (L" read the file is failure !\r\n"));
break;
}
if(DeviceIoControl(hFirm,
IOCTL_FMD_WRITE,
(PBYTE)pBufMsg1,
sizeof(pBufMsg1),
(PBYTE)pBufMsg2,
sizeof(pBufMsg2),
(LPDWORD)firstcom,
NULL) == FALSE)
{
RETAILMSG(1, (L" write the file is failure .....%d !\r\n",pBufMsg1->startSectorAddr));
Sleep(3);
}
Sleep(1);
pBufMsg3->startSectorAddr = pBufMsg1->startSectorAddr;
if(DeviceIoControl(hFirm,
IOCTL_FMD_READ,
(PBYTE)pBufMsg3,
sizeof(pBufMsg3),
(PBYTE)pBufMsg4,
sizeof(pBufMsg4),
(LPDWORD)firstcom,
NULL) == FALSE)
{
RETAILMSG(1, (L"~~~~~~ read the file is failure %d !\r\n",pBufMsg1->startSectorAddr));
Sleep(3);
}
Sleep(1);
for(m=0 ;m<2048 ;m++)
{
if(pBufMsg1->pSectorBuff[m] != pBufMsg4->pSectorBuff[m])
{
RETAILMSG(1, (L" * \r\n"));
SetDlgItemText(IDC_EDIT2,_T("...operate Flash failure..."));
MessageBox(_T(" please write the file to flash once "),NULL,MB_YESNO);
return;
}
}
((CProgressCtrl *)GetDlgItem(IDC_PROGRESS1))->StepIt();
pBufMsg1->startSectorAddr += 1;
}
//...............set bad block....................
if(pBufMsg1->blockID < 8)
{
Ret = DeviceIoControl(hFirm,
IOCTL_FMD_SET_STATUS,
(PBYTE)pBufMsg1,
sizeof(pBufMsg1),
NULL,
0,
(LPDWORD)firstcom,
NULL);
if(Ret != TRUE)
{
RETAILMSG(1, (L"~~~~~~~~~~~~~bad block can not is set~~~~~~~~~~\r\n"));
return;
}
RETAILMSG(1, (L"~~~~~~~~~~~~~bad block %d is set~~~~~~~~~~\r\n",pBufMsg1->blockID));
}