nand.cpp
来自「SAMSUNG S3C6410 CPU BSP for winmobile6」· C++ 代码 · 共 1,317 行 · 第 1/4 页
CPP
1,317 行
}
++dwBlock;
}
else
{
if (!WriteBlock(dwBlock, pbBuffer, g_pSectorInfoBuf))
{
OALMSG(OAL_ERROR, (TEXT("WriteData: failed to write block (0x%x).\r\n"), dwBlock));
return(FALSE);
}
++dwBlock;
pbBuffer += (EBOOT_WRITE_NAND_SECTORSIZE * g_FlashInfo.wSectorsPerBlock);
}
if (dwBlock%8 == 0) OALMSG(TRUE, (TEXT(".")));
}
if (g_ImageType == IMAGE_TYPE_LOADER)
{
g_pTOC->id[0].dwLoadAddress = dwImageStart;
g_pTOC->id[0].dwJumpAddress = 0;
g_pTOC->id[0].dwTtlSectors = FILE_TO_SECTOR_SIZE(dwImageLength);
g_pTOC->id[0].sgList[0].dwSector = BLOCK_TO_SECTOR(stBINPartE.n1stVbn);
g_pTOC->id[0].sgList[0].dwLength = g_pTOC->id[0].dwTtlSectors;
}
OALMSG(OAL_FUNC, (TEXT("_WriteRawImageToBootMedia\r\n")));
return TRUE;
}
#if EBOOT_ONENAND_RW_TEST
#include <ocld.h>
#include <InitialImage_rgb16_320x240.h>
UINT32 SetBlockPage(void)
{
CHAR szCount[16];
USHORT cwNumChars = 0;
USHORT InChar = 0;
UINT32 block=0, page=0;
UINT32 i;
EdbgOutputDebugString("\r\nEnter Block # to read : ");
while(!((InChar == 0x0d) || (InChar == 0x0a)))
{
InChar = OEMReadDebugByte();
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
// If it's a number or a period, add it to the string.
//
if ((InChar >= '0' && InChar <= '9'))
{
if (cwNumChars < 16)
{
szCount[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
// If it's a backspace, back up.
//
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars)
{
szCount[cwNumChars] = '\0';
block = atoi(szCount);
}
EdbgOutputDebugString("\r\nEnter Page # to read : ");
InChar = 0;
for (i=0; i<16; i++) szCount[i] = '0';
while(!((InChar == 0x0d) || (InChar == 0x0a)))
{
InChar = OEMReadDebugByte();
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
// If it's a number or a period, add it to the string.
//
if ((InChar >= '0' && InChar <= '9'))
{
if (cwNumChars < 16)
{
szCount[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
// If it's a backspace, back up.
//
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars)
{
szCount[cwNumChars] = '\0';
page = atoi(szCount);
}
return ((block<<6)|page);
}
#define TEST_PAGE_LENGTH (3)
#define TEST_SECTOR_LENGTH (512)
#define TEST_MAIN_LENGHT (2048)
#define TEST_SPARE_LENGTH (64)
#define TEST_MDATA_LENGTH (TEST_MAIN_LENGHT*TEST_PAGE_LENGTH)
#define TEST_SDATA_LENGTH (TEST_SPARE_LENGTH*TEST_PAGE_LENGTH)
#define TEST_DATA_LENGTH (TEST_MDATA_LENGTH+TEST_SDATA_LENGTH)
BOOL OneNAND_RWTest()
{
UINT8 cWriteBuf[TEST_DATA_LENGTH];
UINT8 cReadBuf[TEST_DATA_LENGTH];
UINT8 *pMBufw;
UINT8 *pSBufw;
UINT8 *pMBufr;
UINT8 *pSBufr;
UINT8 *pBuf;
UINT32 i;
SGL stSGLw, stSGLr;
UINT32 nErrPsn;
UINT32 nBlkPage;
UINT32 nPsn;
UINT32 nScts;
UINT32 nFlag;
// Write ///////////////////////////
//
pMBufw = cWriteBuf;
pSBufw = &(cWriteBuf[TEST_MDATA_LENGTH]);
pBuf = (UINT8 *)(&(InitialImage_rgb16_320x240_OND_RWData[0]));
for (i = 0; i < TEST_DATA_LENGTH; i++)
{
memcpy((void *)(cWriteBuf+i), (void *)(pBuf+i), sizeof(UINT8));
}
nBlkPage = SetBlockPage(); // nBlkPage = (block<<6) + page
nPsn = (nBlkPage << 2) + 1;
nScts = 9;
nFlag = 0x2;
stSGLw.nElements = 3;
stSGLw.stSGLEntry[0].pBuf = pMBufw;
stSGLw.stSGLEntry[0].nSectors = 3;
stSGLw.stSGLEntry[0].nFlag = SGL_ENTRY_USER_DATA;
stSGLw.stSGLEntry[1].pBuf = pMBufw+TEST_SECTOR_LENGTH*stSGLw.stSGLEntry[0].nSectors;
stSGLw.stSGLEntry[1].nSectors = 4;
stSGLw.stSGLEntry[1].nFlag = SGL_ENTRY_USER_DATA;
stSGLw.stSGLEntry[2].pBuf = pMBufw+TEST_SECTOR_LENGTH*(stSGLw.stSGLEntry[0].nSectors+stSGLw.stSGLEntry[1].nSectors);
stSGLw.stSGLEntry[2].nSectors = 2;
stSGLw.stSGLEntry[2].nFlag = SGL_ENTRY_USER_DATA;
ONLD_MWrite(0, nPsn, nScts, &stSGLw, pSBufw, nFlag, &nErrPsn);
// Read ///////////////////////////
//
memset((void *)cReadBuf, 0xff, TEST_DATA_LENGTH);
pMBufr = cReadBuf;
pSBufr = &(cReadBuf[TEST_MDATA_LENGTH]);
stSGLr.nElements = 3;
stSGLr.stSGLEntry[0].pBuf = pMBufr;
stSGLr.stSGLEntry[0].nSectors = 3;
stSGLr.stSGLEntry[0].nFlag = SGL_ENTRY_USER_DATA;
stSGLr.stSGLEntry[1].pBuf = pMBufr+TEST_SECTOR_LENGTH*stSGLw.stSGLEntry[0].nSectors;
stSGLr.stSGLEntry[1].nSectors = 4;
stSGLr.stSGLEntry[1].nFlag = SGL_ENTRY_USER_DATA;
stSGLr.stSGLEntry[2].pBuf = pMBufr+TEST_SECTOR_LENGTH*(stSGLw.stSGLEntry[0].nSectors+stSGLw.stSGLEntry[1].nSectors);
stSGLr.stSGLEntry[2].nSectors = 2;
stSGLr.stSGLEntry[2].nFlag = SGL_ENTRY_USER_DATA;
ONLD_MRead(0, nPsn, nScts, &stSGLr, pSBufr, nFlag);
// Print ///////////////////////////
//
{
int i;
RETAILMSG(1, (L"\r\n==Write==============================================\r\n"));
for (i = 0; i < TEST_DATA_LENGTH/*TEST_SECTOR_LENGTH*nScts*/; i++) {
if (i % 16 == 0)
RETAILMSG(1, (L"0x%x%x%x%x: ", (i>>12)&0xf,(i>>8)&0xf, (i>>4)&0xf, i&0xf));
RETAILMSG(1, (L"%x%x ", (cWriteBuf[i]>>4)&0xf, cWriteBuf[i]&0xf));
if ((i + 1) % 16 == 0)
RETAILMSG(1, (L"\r\n"));
if (i % 512 == 511)
RETAILMSG(1, (L"-----------------------------------------------------\r\n"));
}
RETAILMSG(1, (L"=====================================================\r\n"));
}
{
int i;
RETAILMSG(1, (L"==Read===============================================\r\n"));
for (i = 0; i < TEST_DATA_LENGTH/*TEST_SECTOR_LENGTH*nScts*/; i++) {
if (i % 16 == 0)
RETAILMSG(1, (L"0x%x%x%x%x: ", (i>>12)&0xf, (i>>8)&0xf, (i>>4)&0xf, i&0xf));
RETAILMSG(1, (L"%x%x ", (cReadBuf[i]>>4)&0xf, cReadBuf[i]&0xf));
if ((i + 1) % 16 == 0)
RETAILMSG(1, (L"\r\n"));
if (i % 512 == 511)
RETAILMSG(1, (L"-----------------------------------------------------\r\n"));
}
RETAILMSG(1, (L"=====================================================\r\n"));
}
return TRUE;
}
BOOL OneNAND_LLD_ReadAgingTest()
{
UINT8 cReadBuf[TEST_DATA_LENGTH];
UINT8 *pMBufr;
UINT8 *pSBufr;
SGL stSGLr;
UINT32 nBlkPage;
UINT32 nPsn;
UINT32 nScts;
UINT32 nFlag;
UINT32 nCnt = 0;
nBlkPage = SetBlockPage(); // nBlkPage = (block<<6) + page
nPsn = (nBlkPage << 2);
nScts = 252; // 63page * 4sector
nFlag = 0x2;
// Read ///////////////////////////
//
while (1)
{
nPsn = (nPsn & 0xff) | ((nCnt % 2048) << 8); // page No 1 of all block
memset((void *)cReadBuf, 0xff, TEST_DATA_LENGTH);
pMBufr = cReadBuf;
pSBufr = &(cReadBuf[TEST_MDATA_LENGTH]);
stSGLr.nElements = 1;
stSGLr.stSGLEntry[0].pBuf = pMBufr;
stSGLr.stSGLEntry[0].nSectors = nScts;
stSGLr.stSGLEntry[0].nFlag = SGL_ENTRY_USER_DATA;
ONLD_MRead(0, nPsn, nScts, &stSGLr, pSBufr, nFlag);
//ONLD_Read(0, nPsn, nScts, pMBufr, pSBufr, nFlag);
RETAILMSG(1, (L" Read %dth (B:%d,P:%d,0x%x)\r\n", nCnt, (nPsn&(~(0xff)))>>8, (nPsn>>2)&0x3f, cReadBuf[0])); // number of block and page
if (nCnt == 0xffffffff) break;
nCnt++;
}
// Print ///////////////////////////
//
RETAILMSG(1, (L"==End Test===========================================\r\n"));
return TRUE;
}
BOOL OneNAND_STL_ReadAgingTest()
{
UINT8 cReadBuf[TEST_MAIN_LENGHT*16];
UINT8 *pMBufr;
UINT32 nLsn;
UINT32 nScts;
UINT32 nCnt = 0;
nScts = 16; // 63page * 4sector
// Read ///////////////////////////
//
while (1)
{
for (nCnt = 0, nLsn = 0; nCnt < 1684; nCnt++, nLsn += nScts)
{
memset((void *)cReadBuf, 0xff, TEST_MAIN_LENGHT*nScts);
pMBufr = cReadBuf;
STL_Read(0, PARTITION_ID_COPIEDOS, nLsn<<2, nScts<<2, pMBufr);
//STL_Read(0, PARTITION_ID_FILESYSTEM, nLsn<<2, nScts<<2, cReadBuf);
RETAILMSG(1, (L" Read %dth (Lsn:%d,0x%x)\r\n", nCnt, nLsn, cReadBuf[0]));
}
}
// Print ///////////////////////////
//
RETAILMSG(1, (L"==End Test===========================================\r\n"));
return TRUE;
}
#endif // EBOOT_ONENAND_RW_TEST
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?