📄 nor.c
字号:
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("NORGetGeometry+\r\n")));
if (pGeometry == NULL) {
ERRORMSG(ZONE_ERROR, (TEXT("NORGetGeometry: NULL parameter!\r\n")));
return FALSE;
}
memcpy(pGeometry, &g_FlashDesc.Geometry, sizeof(CFI_FLASH_GEOMETRY_INFO));
DEBUGMSG(ZONE_FUNCTION, (TEXT("NORGetGeometry-\r\n")));
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: NORGetFlashID
//
// Returns manufacturer, device and unique SiID information.
//
// Parameters:
// pFlashID
// [out] pointer to flash ID struct
//
// Returns:
// None
//
//-----------------------------------------------------------------------------
BOOL NORGetFlashID(NOR_FLASH_ID_DESC *pFlashID)
{
DEBUGMSG(ZONE_FUNCTION, (TEXT("NORGetFlashID+\r\n")));
if (pFlashID == NULL) {
ERRORMSG(ZONE_ERROR, (TEXT("NORGetFlashID: NULL parameter!\r\n")));
return FALSE;
}
memcpy(pFlashID, &g_FlashDesc.FlashID, sizeof(NOR_FLASH_ID_DESC));
DEBUGMSG(ZONE_FUNCTION, (TEXT("NORGetFlashID-\r\n")));
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: NORShowProgress
//
// Turns on or off printing progress indicator to debug port.
//
// Parameters:
// bEnable
// [in] enable or not
//
// ulBytePerStep
// [in] number of bytes per indicator print.
// Returns:
//
//-----------------------------------------------------------------------------
void NORShowProgress(BOOL bEnable, ULONG ulBytePerStep)
{
g_bShowProgress = bEnable;
if (bEnable) {
if(g_ulBytePerStep == 0)
g_ulBytePerStep = 4096; // default to 4k per indicator step
else
g_ulBytePerStep = ulBytePerStep;
}
}
//-----------------------------------------------------------------------------
//
// Function: NORGetRelocateCodeSize
//
// Returns the number of bytes required to relocate the low level flash detect,
// program and erase functions.
//
// Parameters:
// None
//
// Returns:
// number of bytes
//
//-----------------------------------------------------------------------------
ULONG NORGetRelocateCodeSize(void)
{
ULONG i;
ULONG ulRelocateSize;
ulRelocateSize = 0;
for (i = 0; i < MAX_SUPPORTED_FLASH_DRIVERS; i++) {
ulRelocateSize = MAX(ulRelocateSize,
(ULONG)g_LowLevelDrivers[i].RelocateEnd - (ULONG)g_LowLevelDrivers[i].RelocateBegin);
DEBUGMSG(ZONE_FUNCTION,
(TEXT("ulRelocateSize 0x%x\r\n"), ulRelocateSize));
}
return ulRelocateSize;
}
//-----------------------------------------------------------------------------
//
// Function: NORVerifyData
//
// Compares the flash data with the contents of a given address.
//
// Parameters:
// ulStartAddress
// [in] flash address to compare with
//
// pData
// [in] ptr to data buffer to compare
//
// ulSize
// [in] size of data to compare
//
// Returns:
// FALSE on compare failure
//
//-----------------------------------------------------------------------------
BOOL NORVerifyData(ULONG ulStartAddress, UCHAR *pData, ULONG ulSize)
{
ULONG i;
if (g_bShowProgress) {
for (i = 0; i < (ulSize / g_ulBytePerStep); i++) {
if (memcmp((void *)ulStartAddress, pData, g_ulBytePerStep) != 0) {
ERRORMSG(ZONE_ERROR, (TEXT("[%08X] 0x%x Expected: 0x%x\r\n"),
ulStartAddress, *(ULONG *)ulStartAddress, *(ULONG *)pData));
return FALSE;
}
PROGRESSMSG(g_bShowProgress, (TEXT("V")));
ulStartAddress += g_ulBytePerStep;
pData += g_ulBytePerStep;
}
if (ulSize % g_ulBytePerStep) {
if (memcmp((void *)ulStartAddress, pData, ulSize % g_ulBytePerStep) != 0) {
ERRORMSG(ZONE_ERROR, (TEXT("[%08X] 0x%x Expected: 0x%x\r\n"),
ulStartAddress, *(ULONG *)ulStartAddress, *(ULONG *)pData));
return FALSE;
}
PROGRESSMSG(g_bShowProgress, (TEXT("V")));
}
PROGRESSMSG(g_bShowProgress, (TEXT("\r\n")));
} else {
if (memcmp((void *)ulStartAddress, pData, ulSize) != 0)
return FALSE;
}
return TRUE;
}
//-----------------------------------------------------------------------------
// PRIVATE FUNCTIONS
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//
// Function: NORFindSector
//
// Returns the sector start address of the input flash location.
//
// Parameters:
// pulFlashAddr
// [in/out] ptr to flash address
//
// pulEraseBlockSize
// [out] ptr to erase block size
//
// Returns:
// FALSE if input address is invalid flash address
//
//-----------------------------------------------------------------------------
static BOOL NORFindSector(ULONG *pulFlashAddr, ULONG *pulEraseBlockSize)
{
ULONG i;
ULONG j;
ULONG ulFlashSectorAddr;
ULONG ulEraseBlockSize;
ULONG ulFlashAddr;
ULONG ulSectorSize;
BOOL bIsPaired;
BOOL bDone;
DEBUGMSG(ZONE_FUNCTION, (TEXT("NORFindSector+\r\n")));
if (!pulFlashAddr) {
ERRORMSG(ZONE_ERROR,
(TEXT("NORFindSector: invalid input flash addr.\r\n")));
return FALSE;
}
bIsPaired = g_FlashDesc.PairedFlash;
ulFlashAddr = *pulFlashAddr;
// Check sector address alignment
ulFlashSectorAddr = g_FlashDesc.FlashBase;
bDone = FALSE;
for (i = 0; !bDone && i < g_FlashDesc.Geometry.NumEraseBlockRegions; i++) {
// Get erase block size
ulSectorSize = g_FlashDesc.Geometry.EraseBlockInfo[i].EraseBlockSize
* CFI_ERASE_BLOCK_SIZE_MULTP;
ulEraseBlockSize = bIsPaired ? 2 * ulSectorSize : ulSectorSize;
for (j = 0;
!bDone && j < (ULONG)(g_FlashDesc.Geometry.EraseBlockInfo[i].NumIdentEraseBlocks + 1);
j++) {
DEBUGMSG(ZONE_HAL_FUNCTION,
(TEXT("ulFlashSectorAddr 0x%x\r\n"), ulFlashSectorAddr));
if (ulFlashAddr >= ulFlashSectorAddr &&
ulFlashAddr < (ulFlashSectorAddr + ulEraseBlockSize)) {
// Found sector, break
bDone = TRUE;
} else {
// Increment flash walk address
ulFlashSectorAddr += ulEraseBlockSize;
}
}
}
DEBUGMSG(ZONE_FUNCTION,
(TEXT("NORFindSector- 0x%x\r\n"), ulFlashSectorAddr));
if (pulFlashAddr)
*pulFlashAddr = ulFlashAddr;
if (pulEraseBlockSize)
*pulEraseBlockSize = ulEraseBlockSize;
return bDone;
}
//-----------------------------------------------------------------------------
//
// Function: PrintCFIData
//
// Prints the CFI query ID string, system interface and geometry tables.
//
// Parameters:
// pFlashDesc
// [in] pointer to NOR flash descriptor
//
// Returns:
// None
//
//-----------------------------------------------------------------------------
static void PrintCFIData(NOR_FLASH_DESC *pFlashDesc)
{
ULONG i = 0;
// Print CFI query ID string
DEBUGMSG(ZONE_INFO, (TEXT("********CFI Query ID string********\r\n")));
DEBUGMSG(ZONE_INFO, (TEXT("CFI Unique ASCII string: %c%c%c\r\n"),
pFlashDesc->QryIDStr.ID[0], pFlashDesc->QryIDStr.ID[1], pFlashDesc->QryIDStr.ID[2]));
DEBUGMSG(ZONE_INFO, (TEXT("Primary OEM command set ID: 0x%x\r\n"), pFlashDesc->QryIDStr.PriOEMCmdSetID));
DEBUGMSG(ZONE_INFO, (TEXT("Address for primary extended table: 0x%x\r\n"), pFlashDesc->QryIDStr.PriExtTableAddr));
DEBUGMSG(ZONE_INFO, (TEXT("Alternate OEM command set ID: 0x%x\r\n"), pFlashDesc->QryIDStr.AltOEMCmdSetID));
DEBUGMSG(ZONE_INFO, (TEXT("Address for Alternate extended table: 0x%x\r\n"), pFlashDesc->QryIDStr.AltExtTableAddr));
// Print CFI System Interface
DEBUGMSG(ZONE_INFO, (TEXT("********CFI System Interface Data********\r\n")));
DEBUGMSG(ZONE_INFO, (TEXT("Vcc Minimum Write/Erase voltage: 0x%x\r\n"), pFlashDesc->SysInt.VccMinProgV));
DEBUGMSG(ZONE_INFO, (TEXT("Vcc Maximum Write/Erase voltage: 0x%x\r\n"), pFlashDesc->SysInt.VccMaxProgV));
DEBUGMSG(ZONE_INFO, (TEXT("Vpp Minimum Write/Erase voltage: 0x%x\r\n"), pFlashDesc->SysInt.VppMinProgV));
DEBUGMSG(ZONE_INFO, (TEXT("Vpp Maximum Write/Erase voltage: 0x%x\r\n"), pFlashDesc->SysInt.VppMaxProgV));
DEBUGMSG(ZONE_INFO, (TEXT("Typical timeout per single byte/word write: 0x%x\r\n"), pFlashDesc->SysInt.Typical.SnglWordProgTO_us));
DEBUGMSG(ZONE_INFO, (TEXT("Typical timeout for minimum-size buffer write: 0x%x\r\n"), pFlashDesc->SysInt.Typical.WriteBuffTO_us));
DEBUGMSG(ZONE_INFO, (TEXT("Typical timeout per individual block erase: 0x%x\r\n"), pFlashDesc->SysInt.Typical.BlockEraseTO_ms));
DEBUGMSG(ZONE_INFO, (TEXT("Typical timeout for full chip erase: 0x%x\r\n"), pFlashDesc->SysInt.Typical.ChipEraseTO_ms));
DEBUGMSG(ZONE_INFO, (TEXT("Maximum timeout per single byte/word write: 0x%x\r\n"), pFlashDesc->SysInt.Max.SnglWordProgTO_us));
DEBUGMSG(ZONE_INFO, (TEXT("Maximum timeout for minimum-size buffer write: 0x%x\r\n"), pFlashDesc->SysInt.Max.WriteBuffTO_us));
DEBUGMSG(ZONE_INFO, (TEXT("Maximum timeout per individual block erase: 0x%x\r\n"), pFlashDesc->SysInt.Max.BlockEraseTO_ms));
DEBUGMSG(ZONE_INFO, (TEXT("Maximum timeout for full chip erase: 0x%x\r\n"), pFlashDesc->SysInt.Max.ChipEraseTO_ms));
// Print device geometry definition
DEBUGMSG(ZONE_INFO, (TEXT("********CFI device Geometry Data********\r\n")));
DEBUGMSG(ZONE_INFO, (TEXT("Device Size: 0x%x\r\n"), pFlashDesc->Geometry.DevSize));
DEBUGMSG(ZONE_INFO, (TEXT("Flash Device Interface ID: 0x%x\r\n"), pFlashDesc->Geometry.DevInterface));
DEBUGMSG(ZONE_INFO, (TEXT("Maximum number of bytes in multi-byte write: 0x%x\r\n"), pFlashDesc->Geometry.WriteBuffSize));
DEBUGMSG(ZONE_INFO, (TEXT("Number of Erase Block Regions within device: 0x%x\r\n"), pFlashDesc->Geometry.NumEraseBlockRegions));
for (i = 0; i < pFlashDesc->Geometry.NumEraseBlockRegions; i++) {
DEBUGMSG(ZONE_INFO, (TEXT("Region %d - Number of Erase Blocks of identical size: 0x%x\r\n"),
i, pFlashDesc->Geometry.EraseBlockInfo[i].NumIdentEraseBlocks));
DEBUGMSG(ZONE_INFO, (TEXT("Region %d - Erase Block size: 0x%x\r\n"),
i, pFlashDesc->Geometry.EraseBlockInfo[i].EraseBlockSize));
}
}
//-----------------------------------------------------------------------------
//
// Function: PrintFlashID
//
// Prints the Flash ID information.
//
// Parameters:
// pFlashDesc
// [in] pointer to NOR flash descriptor
//
// Returns:
// None
//
//-----------------------------------------------------------------------------
static void PrintFlashID(NOR_FLASH_DESC *pFlashDesc)
{
ULONG i;
DEBUGMSG(ZONE_INFO, (TEXT("********Flash ID Info********\r\n")));
DEBUGMSG(ZONE_INFO, (TEXT("Manufacturer ID: 0x%x\r\n"),
pFlashDesc->FlashID.ManufacturerID));
for (i = 0; i < (sizeof(pFlashDesc->FlashID.DeviceID) / sizeof(ULONG)); i++) {
DEBUGMSG(ZONE_INFO, (TEXT("Device ID[%d]: 0x%x\r\n"),
i, pFlashDesc->FlashID.DeviceID[i]));
}
for (i = 0; i < (sizeof(pFlashDesc->FlashID.SiliconID) / sizeof(ULONG)); i++) {
DEBUGMSG(ZONE_INFO, (TEXT("Unique Silicon ID[%d]: 0x%x\r\n"),
i, pFlashDesc->FlashID.SiliconID[i]));
}
}
//-----------------------------------------------------------------------------
// END OF FILE
//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -