📄 nand.cpp
字号:
OALMSG(TRUE, (TEXT("Update Other TOC Last TOC[%d] Entry to TOC cache in memory!\r\n"), g_pTOC->id[nCount]));
}
*/
}
TOC_Print();
// create extended partition in whatever is left
//
hPartEx = BP_OpenPartition( NEXT_FREE_LOC,
USE_REMAINING_SPACE,
PART_DOS32,
TRUE,
PART_OPEN_ALWAYS);
if (hPartEx == INVALID_HANDLE_VALUE )
{
OALMSG(OAL_WARN, (TEXT("*** WARN: StoreImageToBootMedia: Failed to open/create Extended partition ***\r\n")));
}
OALMSG(OAL_FUNC, (TEXT("-WriteOSImageToBootMedia\r\n")));
return(TRUE);
}
/*
@func BOOL | ReadKernelRegionFromBootMedia |
BinFS support. Reads the kernel region from Boot Media into RAM. The kernel region is fixed up
to run from RAM and this is done just before jumping to the kernel entry point.
@rdesc TRUE = Success, FALSE = Failure.
@comm
@xref
*/
BOOL ReadOSImageFromBootMedia()
{
HANDLE hPart;
SectorInfo si;
DWORD chainaddr, flashaddr;
DWORD i;
OALMSG(OAL_FUNC, (TEXT("+ReadOSImageFromBootMedia\r\n")));
if (!g_bBootMediaExist)
{
OALMSG(OAL_ERROR, (TEXT("ERROR: ReadOSImageFromBootMedia: device doesn't exist.\r\n")));
return(FALSE);
}
if ( !VALID_TOC(g_pTOC) )
{
OALMSG(OAL_ERROR, (TEXT("ERROR: ReadOSImageFromBootMedia: INVALID_TOC\r\n")));
return(FALSE);
}
if ( !VALID_IMAGE_DESCRIPTOR(&g_pTOC->id[g_dwTocEntry]) )
{
OALMSG(OAL_ERROR, (TEXT("ReadOSImageFromBootMedia: ERROR_INVALID_IMAGE_DESCRIPTOR: 0x%x\r\n"),
g_pTOC->id[g_dwTocEntry].dwSignature));
return FALSE;
}
if ( !OEMVerifyMemory(g_pTOC->id[g_dwTocEntry].dwLoadAddress, sizeof(DWORD)) ||
!OEMVerifyMemory(g_pTOC->id[g_dwTocEntry].dwJumpAddress, sizeof(DWORD)) ||
!g_pTOC->id[g_dwTocEntry].dwTtlSectors )
{
OALMSG(OAL_ERROR, (TEXT("ReadOSImageFromBootMedia: ERROR_INVALID_ADDRESS: (address=0x%x, sectors=0x%x, launch address=0x%x)...\r\n"),
g_pTOC->id[g_dwTocEntry].dwLoadAddress, g_pTOC->id[g_dwTocEntry].dwTtlSectors, g_pTOC->id[g_dwTocEntry].dwJumpAddress));
return FALSE;
}
// Open the BINFS partition (it must exist).
//
hPart = BP_OpenPartition( NEXT_FREE_LOC,
USE_REMAINING_SPACE,
PART_BINFS,
TRUE,
PART_OPEN_EXISTING);
if (hPart == INVALID_HANDLE_VALUE )
{
OALMSG(OAL_ERROR, (TEXT("ERROR: ReadOSImageFromBootMedia: Failed to open existing partition.\r\n")));
return(FALSE);
}
// Set the partition file pointer to the correct offset for the kernel region.
//
if ( !BP_SetDataPointer(hPart, g_pTOC->id[g_dwTocEntry].dwStoreOffset) )
{
OALMSG(OAL_ERROR, (TEXT("ERROR: ReadOSImageFromBootMedia: Failed to set data pointer in partition (offset=0x%x).\r\n"),
g_pTOC->id[g_dwTocEntry].dwStoreOffset));
return(FALSE);
}
// Read the kernel region from the Boot Media into RAM.
//
if ( !BP_ReadData( hPart,
(LPBYTE)(g_pTOC->id[g_dwTocEntry].dwLoadAddress),
SECTOR_TO_FILE_SIZE(g_pTOC->id[g_dwTocEntry].dwTtlSectors)) )
{
OALMSG(OAL_ERROR, (TEXT("ERROR: ReadOSImageFromBootMedia: Failed to read kernel region from partition.\r\n")));
return(FALSE);
}
if (!g_pTOC->chainInfo.dwLoadAddress)
{
chainaddr = g_pTOC->chainInfo.dwLoadAddress;
flashaddr = g_pTOC->chainInfo.dwFlashAddress;
for ( i = 0; i < (g_pTOC->chainInfo.dwLength); i++ )
{
OALMSG(TRUE, (TEXT("chainaddr=0x%x, flashaddr=0x%x\r\n"), chainaddr, flashaddr+i));
if ( !FMD_ReadSector(flashaddr+i, (PUCHAR)(chainaddr), &si, 1) ) {
OALMSG(OAL_ERROR, (TEXT("TOC ERROR: Unable to read/verify TOC\r\n")));
return FALSE;
}
chainaddr += 512;
}
}
OALMSG(OAL_FUNC, (TEXT("_ReadOSImageFromBootMedia\r\n")));
return(TRUE);
}
BOOL ReadBlock(DWORD dwBlock, LPBYTE pbBlock, PSectorInfo pSectorInfoTable)
{
for (int iSector = 0; iSector < g_FlashInfo.wSectorsPerBlock; iSector++) {
if (!FMD_ReadSector(dwBlock * g_FlashInfo.wSectorsPerBlock + iSector, pbBlock, pSectorInfoTable, 1))
return FALSE;
if (pbBlock)
pbBlock += g_FlashInfo.wDataBytesPerSector;
if (pSectorInfoTable)
pSectorInfoTable++;
}
return TRUE;
}
BOOL WriteBlock(DWORD dwBlock, LPBYTE pbBlock, PSectorInfo pSectorInfoTable)
{
for (int iSector = 0; iSector < g_FlashInfo.wSectorsPerBlock; iSector++) {
#ifdef _IROMBOOT_
if((dwBlock==0) && (iSector<(IMAGE_STEPLOADER_SIZE/SECTOR_SIZE))){
if (!FMD_WriteSector_Stepldr(dwBlock * g_FlashInfo.wSectorsPerBlock + iSector, pbBlock, pSectorInfoTable, 1))
return FALSE;
} else
#endif
if (!FMD_WriteSector(dwBlock * g_FlashInfo.wSectorsPerBlock + iSector, pbBlock, pSectorInfoTable, 1))
return FALSE;
//#endif // !_IROMBOOT_
if (pbBlock)
pbBlock += g_FlashInfo.wDataBytesPerSector;
if (pSectorInfoTable)
pSectorInfoTable++;
}
return TRUE;
}
BOOL WriteRawImageToBootMedia(DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr)
{
DWORD dwBlock,dwNumBlocks;
LPBYTE pbBuffer;
SectorInfo si;
OALMSG(OAL_FUNC, (TEXT("+WriteRawImageToBootMedia\r\n")));
if ( !g_bBootMediaExist )
{
OALMSG(OAL_ERROR, (TEXT("ERROR: WriteRawImageToBootMedia: device doesn't exist.\r\n")));
return(FALSE);
}
if (g_ImageType == IMAGE_TYPE_LOADER)
{
dwBlock = EBOOT_BLOCK;
if ( !VALID_TOC(g_pTOC) )
{
OALMSG(OAL_WARN, (TEXT("WARN: WriteRawImageToBootMedia: INVALID_TOC\r\n")));
if ( !TOC_Init(g_dwTocEntry, g_ImageType, dwImageStart, dwImageLength, dwLaunchAddr) )
{
OALMSG(OAL_ERROR, (TEXT("ERROR: INVALID_TOC\r\n")));
return(FALSE);
}
}
}
else if (g_ImageType == IMAGE_TYPE_STEPLDR)
{
dwBlock = NBOOT_BLOCK;
dwImageStart += dwLaunchAddr;
dwImageLength = STEPPINGSTONE_SIZE; //step loader can support 8k bytes.
}
pbBuffer = OEMMapMemAddr(dwImageStart, dwImageStart);
// Compute number of blocks.
//dwNumBlocks = (dwImageLength / 0x4000) + 1;
dwNumBlocks = (dwImageLength / (g_FlashInfo.wDataBytesPerSector*g_FlashInfo.wSectorsPerBlock)) + (dwImageLength%(g_FlashInfo.wDataBytesPerSector*g_FlashInfo.wSectorsPerBlock) ? 1: 0);
OALMSG(TRUE, (TEXT("dwImageLength = 0x%x \r\n"), dwImageLength));
OALMSG(TRUE, (TEXT("dwNumBlocks = 0x%x \r\n"), dwNumBlocks));
while (dwNumBlocks--)
{
// If the block is marked bad, skip to next block. Note that the assumption in our error checking
// is that any truely bad block will be marked either by the factory during production or will be marked
// during the erase and write verification phases. If anything other than a bad block fails ECC correction
// in this routine, it's fatal.
OALMSG(TRUE, (TEXT("dwBlock(0x%x) X "), dwBlock));
OALMSG(TRUE, (TEXT("g_FlashInfo.wSectorsPerBlock(0x%x)"), g_FlashInfo.wSectorsPerBlock));
OALMSG(TRUE, (TEXT(" = 0x%x \r\n"), dwBlock*g_FlashInfo.wSectorsPerBlock));
if(g_ImageType != IMAGE_TYPE_STEPLDR && g_ImageType != IMAGE_TYPE_LOADER)
{
// This will skip BadBlock for OS Images
if((FMD_GetBlockStatus(dwBlock) & (BLOCK_STATUS_BAD | BLOCK_STATUS_RESERVED)))
{
OALMSG(TRUE, (TEXT("FMD_GetBlockStatus Error \r\n")));
++dwBlock;
++dwNumBlocks;
continue;
}
if (!FMD_ReadSector(dwBlock*g_FlashInfo.wSectorsPerBlock, NULL, &si, 1))
{
OALMSG(TRUE, (TEXT("%s: Failed to get block(0x%x)'s sector info.\r\n"), _T(__FUNCTION__), dwBlock));
++dwBlock;
++dwNumBlocks;
}
}
else
{
OALMSG(TRUE, (TEXT("Ignore BadBlock Checking for Step loader and eboot\r\n")));
FMD_ReadSector(dwBlock*g_FlashInfo.wSectorsPerBlock, NULL, &si, 1);
}
#ifdef _IROMBOOT_
if(dwBlock != NBOOT_BLOCK)
{
#endif
// Stepldr & Eboot image in nand flash
// block mark as BLOCK_STATUS_RESERVED & BLOCK_STATUS_READONLY & BLOCK_STATUS_BAD
if ((si.bBadBlock == BADBLOCKMARK) && (si.bOEMReserved != 0xFC ))
{
++dwBlock;
++dwNumBlocks; // Compensate for fact that we didn't write any blocks.
continue;
}
if (!ReadBlock(dwBlock, NULL, g_pSectorInfoBuf))
{
OALMSG(OAL_ERROR, (TEXT("WriteData: failed to read block (0x%x).\r\n"), dwBlock));
return(FALSE);
}
#ifdef _IROMBOOT_
}
#endif
if (!FMD_EraseBlock(dwBlock))
{
OALMSG(OAL_ERROR, (TEXT("WriteData: failed to erase block (0x%x).\r\n"), dwBlock));
return FALSE;
}
if (!WriteBlock(dwBlock, pbBuffer, g_pSectorInfoBuf))
{
OALMSG(OAL_ERROR, (TEXT("WriteData: failed to write block (0x%x).\r\n"), dwBlock));
return(FALSE);
}
++dwBlock;
pbBuffer += g_FlashInfo.dwBytesPerBlock; //c ksk 20060311
OALMSG(TRUE, (TEXT("dwBytesPerBlock : %d\r\n"), g_FlashInfo.dwBytesPerBlock));
}
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(EBOOT_BLOCK);
g_pTOC->id[0].sgList[0].dwLength = g_pTOC->id[0].dwTtlSectors;
}
OALMSG(OAL_FUNC, (TEXT("_WriteRawImageToBootMedia\r\n")));
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -