📄 fmd.cpp
字号:
RETAILMSG(1,(TEXT("ERROR: FMD_WriteSector: failed sector write.\r\n")));
#endif
return(FALSE);
}
// NF_nFCE_H(); // Deselect the flash chip.
++SectorAddr;
}
NF_nFCE_H(); // Deselect the flash chip.
SetKMode (bLastMode);
return(TRUE);
}
static BOOL IsBlockBad1208(BLOCK_ID blockID)
{
BYTE Data;
SECTOR_ADDR blockPage = (blockID * NAND_PAGE_CNT);
// if(blockID<0x12)
// return TRUE;
BOOL bLastMode = SetKMode(TRUE);
NF_nFCE_L(); // Select the flash chip.
// NF_CMD(CMD_RESET); // Send reset command.
// NF_WAITRB(); // Wait for flash to complete command.
NF_CLEAR_RB();
NF_CMD(CMD_READ2); // Send read confirm command.
NF_ADDR(0); // Column = 0.
NF_ADDR(blockPage & 0xff); /* The mark of bad block is in 0 page */
NF_ADDR((blockPage >> 8) & 0xff); /* For block number A[24:17] */
NF_ADDR((blockPage >> 16) & 0xff); /* For block number A[25] */
// Wait for Ready bit
NF_DETECT_RB(); // Wait tR(max 12us)
// TODO
Data = NF_RDDATA(); // Read command status.
Data = NF_RDDATA(); // Read command status.
Data = NF_RDDATA(); // Read command status.
Data = NF_RDDATA(); // Read command status.
Data = NF_RDDATA(); // Read command status.
Data = NF_RDDATA(); // Read command status.
NF_nFCE_H(); // Deassert the flash chip.
if(0xff != Data)
{
SetKMode (bLastMode);
#ifdef BOOT_LOADER
EdbgOutputDebugString("IsBlockBad(%X): TRUE\r\n",blockID);
#else
RETAILMSG(1,(TEXT("IsBlockBad(%X): TRUE\r\n"),blockID));
#endif
return(TRUE);
}
SetKMode (bLastMode);
return(FALSE);
}
static BOOL MarkBlockBad1208(BLOCK_ID blockID)
{
BYTE Status;
ULONG blockPage = (blockID * NAND_PAGE_CNT); // Convert block address to page address.
BOOL bLastMode = SetKMode(TRUE);
NF_nFCE_L(); // Select the flash chip.
NF_CLEAR_RB();
NF_CMD(CMD_READ2); // Send read confirm command.
NF_CMD(CMD_WRITE); // Send write command.
NF_ADDR(0); // Column = 0.
NF_ADDR(blockPage & 0xff); /* The mark of bad block is in 0 page */
NF_ADDR((blockPage >> 8) & 0xff); /* For block number A[24:17] */
NF_ADDR((blockPage >> 16) & 0xff); /* For block number A[25] */
// TODO
NF_WRDATA(0xFF); // Write bad block marker.
NF_WRDATA(0xFF); // Write bad block marker.
NF_WRDATA(0xFF); // Write bad block marker.
NF_WRDATA(0xFF); // Write bad block marker.
NF_WRDATA(0xFF); // Write bad block marker.
NF_WRDATA(0); // Write bad block marker.
NF_CLEAR_RB();
NF_CMD(CMD_WRITE2); // Send write confirm command.
// Wait for RB
NF_DETECT_RB(); // Wait tR(max 12us)
// Get the status
NF_CMD(CMD_STATUS);
Status = NF_RDDATA(); // Read command status.
NF_nFCE_H(); // Deassert the flash chip.
SetKMode (bLastMode);
return((Status & 1) ? FALSE : TRUE);
}
#if (K9F1G08_SUPPORT||K9F2G08_SUPPORT||K9F4G08_SUPPORT||K9F8G08_SUPPORT)
BOOL FMD_ReadSector1G08(SECTOR_ADDR startSectorAddr, LPBYTE pSectorBuff, PSectorInfo pSectorInfoBuff, DWORD dwNumSectors)
{
ULONG SectorAddr = (ULONG)startSectorAddr;
int i;
BOOL bLastMode = SetKMode(TRUE);
// EdbgOutputDebugString("FMD_ReadSector1G08(%d,%p,%p,%d)\n",startSectorAddr,pSectorBuff,pSectorInfoBuff,dwNumSectors);
NF_RSTECC(); // Initialize ECC.
NF_nFCE_L(); // Select the flash chip.
NF_CLEAR_RB();
NF_CMD(CMD_RESET); // Send reset command.
for(i=0;i<10;i++);
NF_DETECT_RB();
while (dwNumSectors--)
{
ULONG blockPage = SectorAddr;//(((SectorAddr / NAND_PAGE_CNT) * NAND_PAGE_CNT) | (SectorAddr % NAND_PAGE_CNT));
if(pSectorBuff)
{
NF_CLEAR_RB();
NF_CMD(CMD_READ); // Send read command.
NF_ADDR(0); // Column (A[7:0]) = 0
NF_ADDR(0); // A[11:8]
NF_ADDR((blockPage)&0xff); // A[19:12]
NF_ADDR((blockPage>>8)&0xff); // A[27:20]
#if (K9F2G08_SUPPORT||K9F4G08_SUPPORT||K9F8G08_SUPPORT)
if((g_pNandFlashChip->FlashID!=0xECF1)&&(g_pNandFlashChip->FlashID!=0xECA1))
NF_ADDR((blockPage>>16)&0xff);
#endif
NF_CLEAR_RB();
NF_CMD(0x30); // 2'nd command
NF_DETECT_RB();
if((DWORD) pSectorBuff&0x3)
{
RdPage2048Unalign (pSectorBuff,(PULONG)&s2440NAND->NFDATA);
}
else
{
RdPage2048(pSectorBuff,(PULONG)&s2440NAND->NFDATA); // Read page/sector data.
}
}
if(pSectorInfoBuff) {
if(!pSectorBuff)
{
NF_CLEAR_RB();
NF_CMD(0x00); // Read command
NF_ADDR((2048+0)&0xff); // 2060 = 0x080c
NF_ADDR(((2048+0)>>8)&0xff);
NF_ADDR((blockPage)&0xff); // A[19:12]
NF_ADDR((blockPage>>8)&0xff); // A[27:20]
#if (K9F2G08_SUPPORT||K9F4G08_SUPPORT||K9F8G08_SUPPORT)
if((g_pNandFlashChip->FlashID!=0xECF1)&&(g_pNandFlashChip->FlashID!=0xECA1))
NF_ADDR((blockPage>>16)&0xff);
#endif
NF_CLEAR_RB();
NF_CMD(0x30); // 2'nd command
NF_DETECT_RB();
}
// Read the bad block mark
pSectorInfoBuff->bBadBlock = (BYTE) NF_RDDATA();
// Read the SectorInfo data (we only need to read first 8 bytes)
pSectorInfoBuff->dwReserved1 = NF_DATA_R4();
// OEM byte
pSectorInfoBuff->bOEMReserved = (BYTE) NF_RDDATA();
// Second reserved field (WORD)
pSectorInfoBuff->wReserved2 = ((BYTE) NF_RDDATA() << 8);
pSectorInfoBuff->wReserved2 |= ((BYTE) NF_RDDATA());
}
// NF_nFCE_H(); // Deselect the flash chip.
++SectorAddr;
pSectorBuff += NAND_PAGE_SIZE;
}
NF_nFCE_H(); // Deselect the flash chip.
SetKMode (bLastMode);
return(TRUE);
}
/*
@func BOOL | FMD_EraseBlock | Erases the specified flash block.
@rdesc TRUE = Success, FALSE = Failure.
@comm
@xref
*/
BOOL FMD_EraseBlock1G08(BLOCK_ID blockID)
{
BYTE Status;
ULONG blockPage = (blockID * NAND_PAGE_CNT); // Convert block address to page address.
BOOL bLastMode = SetKMode(TRUE);
NF_nFCE_L(); // Select the flash chip.
NF_CLEAR_RB();
NF_CMD(CMD_ERASE); // Send block erase command.
// Address 2-cycle
NF_ADDR((blockPage)&0xff); // Page number=0
NF_ADDR((blockPage>>8)&0xff);
#if (K9F2G08_SUPPORT||K9F4G08_SUPPORT||K9F8G08_SUPPORT)
if((g_pNandFlashChip->FlashID!=0xECF1)&&(g_pNandFlashChip->FlashID!=0xECA1))
NF_ADDR((blockPage>>16)&0xff);
#endif
NF_CMD(CMD_ERASE2); // Send block erase confirm command.
//NF_WAITRB(); // Wait for flash to complete command.
NF_DETECT_RB();
// Check the status
NF_CMD(CMD_STATUS);
Status = NF_RDDATA(); // Read command status.
NF_nFCE_H(); // Deselect the flash chip.
SetKMode (bLastMode);
return((Status & 1) ? FALSE : TRUE);
}
/*
@func BOOL | FMD_WriteSector | Writes the specified data to the specified NAND flash sector/page.
@rdesc TRUE = Success, FALSE = Failure.
@comm
@xref
*/
BOOL FMD_WriteSector1G08(SECTOR_ADDR startSectorAddr, LPBYTE pSectorBuff, PSectorInfo pSectorInfoBuff, DWORD dwNumSectors)
{
BYTE Status;
ULONG SectorAddr = (ULONG)startSectorAddr;
DWORD i;
BOOL bLastMode = SetKMode(TRUE);
// DWORD Mecc;
if (!pSectorBuff && !pSectorInfoBuff)
return(FALSE);
NF_RSTECC(); // Initialize ECC.
NF_nFCE_L(); // Select the flash chip.
NF_CLEAR_RB();
NF_CMD(CMD_RESET); // Send reset command.
for(i=0;i<10;i++);
NF_DETECT_RB();
while (dwNumSectors--)
{
ULONG blockPage = SectorAddr;//(((SectorAddr / NAND_PAGE_CNT) * NAND_PAGE_CNT) | (SectorAddr % NAND_PAGE_CNT));
if (!pSectorBuff)
{
NF_CLEAR_RB();
NF_CMD(CMD_WRITE); // Write 1st command
NF_ADDR((2048+0)&0xff); // Column (A[7:0]) = 0
NF_ADDR(((2048+0)>>8)&0xff); // A[11:8]
NF_ADDR((blockPage)&0xff); // A[19:12]
NF_ADDR((blockPage>>8)&0xff); // A[27:20]
#if (K9F2G08_SUPPORT||K9F4G08_SUPPORT||K9F8G08_SUPPORT)
if((g_pNandFlashChip->FlashID!=0xECF1)&&(g_pNandFlashChip->FlashID!=0xECA1))
NF_ADDR((blockPage>>16)&0xff);
#endif
NF_WRDATA( (pSectorInfoBuff->bBadBlock) );
// Write the first reserved field (DWORD)
NF_DATA_W4(pSectorInfoBuff->dwReserved1);
// Write OEM reserved flag
NF_WRDATA( (pSectorInfoBuff->bOEMReserved) );
// Write the second reserved field
NF_WRDATA( (pSectorInfoBuff->wReserved2 >> 8) & 0xff );
NF_WRDATA( (pSectorInfoBuff->wReserved2) & 0xff );
pSectorInfoBuff++;
}
else
{
// NF_CMD(CMD_READ); // Send read command.
NF_CLEAR_RB();
NF_CMD(CMD_WRITE); // Write 1st command
NF_ADDR(0); // Column (A[7:0]) = 0
NF_ADDR(0); // A[11:8]
NF_ADDR((blockPage)&0xff); // A[19:12]
NF_ADDR((blockPage>>8)&0xff); // A[27:20]
#if (K9F2G08_SUPPORT||K9F4G08_SUPPORT||K9F8G08_SUPPORT)
if((g_pNandFlashChip->FlashID!=0xECF1)&&(g_pNandFlashChip->FlashID!=0xECA1))
NF_ADDR((blockPage>>16)&0xff);
#endif
if( ((DWORD) pSectorBuff) & 0x3) {
// Write the data
WrPage2048Unalign (pSectorBuff,(PULONG)&s2440NAND->NFDATA);
}
else
{
WrPage2048(pSectorBuff,(PULONG)&s2440NAND->NFDATA); // Write page/sector data.
}
if(pSectorInfoBuff)
{
// Write the bad block flag
NF_WRDATA( (pSectorInfoBuff->bBadBlock) );
// Write the first reserved field (DWORD)
NF_DATA_W4(pSectorInfoBuff->dwReserved1);
// Write OEM reserved flag
NF_WRDATA( (pSectorInfoBuff->bOEMReserved) );
// Write the second reserved field
NF_WRDATA( (pSectorInfoBuff->wReserved2 >> 8) & 0xff );
NF_WRDATA( (pSectorInfoBuff->wReserved2) & 0xff );
}
pSectorBuff += NAND_PAGE_SIZE;
}
NF_CLEAR_RB();
NF_CMD(CMD_WRITE2); // Send write confirm command.
// Wait for RB
NF_DETECT_RB(); // Wait tR(max 12us)
// Check the status
NF_CMD(CMD_STATUS);
Status = NF_RDDATA();
if (Status & 1)
{
NF_nFCE_H(); // Deselect the flash chip.
SetKMode (bLastMode);
#ifdef BOOT_LOADER
EdbgOutputDebugString("ERROR: FMD_WriteSector: failed sector write.\r\n");
#else
RETAILMSG(1,(TEXT("ERROR: FMD_WriteSector: failed sector write.\r\n")));
#endif
return(FALSE);
}
// NF_nFCE_H(); // Deselect the flash chip.
++SectorAddr;
}
NF_nFCE_H(); // Deselect the flash chip.
SetKMode (bLastMode);
return(TRUE);
}
static BOOL IsBlockBad1G08(BLOCK_ID blockID)
{
BYTE Data;
SECTOR_ADDR blockPage = (blockID * NAND_PAGE_CNT);
// if(blockID<0x12)
// return TRUE;
BOOL bLastMode = SetKMode(TRUE);
NF_nFCE_L();
NF_CLEAR_RB();
NF_CMD(0x00); // Read command
NF_ADDR((2048+0)&0xff); // 2060 = 0x080c
NF_ADDR(((2048+0)>>8)&0xff);
NF_ADDR((blockPage)&0xff); // A[19:12]
NF_ADDR((blockPage>>8)&0xff); // A[27:20]
#if (K9F2G08_SUPPORT||K9F4G08_SUPPORT||K9F8G08_SUPPORT)
if((g_pNandFlashChip->FlashID!=0xECF1)&&(g_pNandFlashChip->FlashID!=0xECA1))
NF_ADDR((blockPage>>16)&0xff);
#endif
NF_CLEAR_RB();
NF_CMD(0x30); // 2'nd command
NF_DETECT_RB();
Data=NF_RDDATA();
NF_nFCE_H(); // Deassert the flash chip.
if(0xff != Data)
{
SetKMode (bLastMode);
#ifdef BOOT_LOADER
EdbgOutputDebugString("IsBlockBad(%X): TRUE\r\n",blockID);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -