📄 amd.c
字号:
if ((ulDataWritten & CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ7_X16)) ==
(ulDataToWrite & CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ7_X16))) {
// DQ7 = valid data, do Read 2 and Read 3
ulDataWritten = bIsPaired ?
*((volatile ULONG *)(ulProgramAddress)) :
*((volatile USHORT *)(ulProgramAddress));
ulDataWritten = bIsPaired ?
*((volatile ULONG *)(ulProgramAddress)) :
*((volatile USHORT *)(ulProgramAddress));
// Spec indiates that D7 may be valid while other data lines are still invalid.
if (ulDataWritten != ulDataToWrite) {
// Try reading again before we report an error. We want to avoid
// reporting an error here because EBOOT has no recovery and
// will terminate the flashing procedure.
for (retry = 10; retry > 0 && !bDone; retry--) {
ulDataWritten = bIsPaired ?
*((volatile ULONG *)(ulProgramAddress)) :
*((volatile USHORT *)(ulProgramAddress));
if (ulDataWritten == ulDataToWrite) {
// Programmed properly
bDone = TRUE;
}
}
// Now report an error if the value we wanted did not get programmed
if (!bDone) {
// Programming failure
ERRORMSG(ZONE_HAL_ERROR,
(TEXT("Program failure [0x%x] 0x%x : expect 0x%x\r\n"),
ulProgramAddress, ulDataWritten, ulDataToWrite));
bSuccess = FALSE;
}
} else {
// Datum is programmed properly
bDone = TRUE;
}
} else {
if ((ulDataWritten & CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ5_X16)) ==
CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ5_X16)) {
// Read 2
ulDataWritten = bIsPaired ?
*((volatile ULONG *)(ulProgramAddress)) :
*((volatile USHORT *)(ulProgramAddress));
// Read 3
ulDataRead = bIsPaired ?
*((volatile ULONG *)(ulProgramAddress)) :
*((volatile USHORT *)(ulProgramAddress));
// To see if DQ6 is toggling
if ((ulDataWritten & CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ6_X16)) !=
(ulDataRead & CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ6_X16))) {
// DQ6 is toggling
ERRORMSG(ZONE_HAL_ERROR,
(TEXT("Program failure [0x%x] 0x%x : expect 0x%x\r\n"),
ulProgramAddress, ulDataWritten, ulDataToWrite));
// Probably due to an attempt to program a 0 to 1.
ERRORMSG(ZONE_HAL_ERROR,
(TEXT("DQ6 is toggling. Probably due to an attempt to program a 0 to 1!\r\n"))) ;
bSuccess = FALSE;
}
}
}
} // end poll for datum prog done
// Check for prog timeout.
if (!bDone && (j == g_FlashProgInfo.ulMaxDatumProgTOFactor))
bSuccess = FALSE;
if (!bSuccess)
break;
// Since the polling needs to occur on the last datum programmed
// to the buffer the math to advance the pointers
// for next datum is left until now
pulData = (ULONG *)((ULONG)pulData + dwBusWidth);
ulProgramAddress += dwBusWidth;
} // End prog datum loop
if (g_FlashProgInfo.bUnlockBypassSupport) {
// Exit bypass mode
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase,
CYCLE_1_ADDR_RESET_BYPASS, CYCLE_1_DATA_RESET_BYPASS);
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase,
CYCLE_2_ADDR_RESET_BYPASS, CYCLE_2_DATA_RESET_BYPASS);
}
}
// return to read array mode by issuing a soft reset
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase, CYCLE_1_ADDR_RESET, CYCLE_1_DATA_RESET);
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("AMDx16_Program-\r\n")));
return bSuccess;
}
//-----------------------------------------------------------------------------
//
// Function: AMDx16_EraseSector
//
// Erases a sector of flash.
// For 16bit mode flash devices.
//
// Flash programming notes:
// During the embedded erase algorithm, DQ7 is 0. When the erase is complete
// the polling produces a 1 on DQ7. Just prior to the completion of an
// embedded erase operation, DQ7 may change asynchronousl with DQ6-DQ0 while
// output enable is asserted. In other words, the device will switch from
// providing status to providing data.
// **************************************************************************
//
// Parameters:
// pFlashDesc
// [in] pointer to NOR flash descriptor
//
// ulAddr
// [in] start address of sector to start erase
//
// Returns:
// FALSE on failure
//
//-----------------------------------------------------------------------------
BOOL AMDx16_EraseSector(NOR_FLASH_DESC *pFlashDesc, ULONG ulAddr)
{
ULONG ulFlashBase;
BOOL bIsPaired;
ULONG i;
ULONG ulDataWritten;
BOOL bDone;
volatile ULONG ulSectorAddress = ulAddr;
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("AMDx16_EraseSector+ 0x%x 0x%x\r\n"),
pFlashDesc, ulSectorAddress));
if (!pFlashDesc) {
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("AMDx16_EraseSector: null param\r\n")));
return FALSE;
}
ulFlashBase = pFlashDesc->FlashBase;
bIsPaired = pFlashDesc->PairedFlash;
bDone = FALSE;
// Issue erase sector command
// **************************
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase, CYCLE_1_ADDR_UNLOCK_x16, CYCLE_1_DATA_UNLOCK);
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase, CYCLE_2_ADDR_UNLOCK_x16, CYCLE_2_DATA_UNLOCK);
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase, CYCLE_3_ADDR_CMD_x16, CYCLE_3_DATA_ERASE);
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase, CYCLE_4_ADDR_ERASE, CYCLE_4_DATA_ERASE);
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase, CYCLE_5_ADDR_ERASE, CYCLE_5_DATA_ERASE);
WR_FLASH_REG_INDEXED16(bIsPaired, ulSectorAddress, 0, CYCLE_6_DATA_SECTOR_ERASE);
#ifdef USE_OS_SERVICES
for (i = 0; i < g_FlashProgInfo.ulMaxSectorEraseTOFactor; i++) {
Sleep(g_FlashProgInfo.ulSectorEraseTO_ms);
#else
// Wait for erase command to be accepted
i = 0;
while (i++ < CHECK_STATUS_TIMEOUT) {
ulDataWritten = *((volatile USHORT *)(ulSectorAddress));
if (ulDataWritten & (1 << 3)) break;
}
// Wait for erase command complete
i = 0;
while (!bDone && i++ < CHECK_STATUS_TIMEOUT) {
#endif
ulDataWritten = bIsPaired ? *((volatile ULONG *)(ulSectorAddress)) :
*((volatile USHORT *)(ulSectorAddress));
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("[0x%x]->0x%x\r\n"),
ulSectorAddress, ulDataWritten));
if ((ulDataWritten & CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ7_X16))
== CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ7_X16)) {
// DQ7 on the high and low order devices is a 1,
// erase completed successfully.
// *********************************************
bDone = TRUE;
break;
} else {
// Test the device(s) to determine if a timeout has occurred.
// If the device was being erased (DQ7 -> 0) AND
// a timeout has occurred (DQ5 -> 1) then there is a failure.
// **********************************************************
if ((ulDataWritten & CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ5_X16))
== CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ5_X16)) {
ERRORMSG(ZONE_HAL_ERROR, (TEXT("ERROR: Erase timeout Poll cnt %d - [0x%x] rd value[0]:0x%x\r\n"),
i, ulSectorAddress, ulDataWritten));
break;
}
}
}
// Return to read array mode by issuing a soft reset
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase, CYCLE_1_ADDR_RESET, CYCLE_1_DATA_RESET);
DEBUGMSG(ZONE_HAL_FUNCTION, (TEXT("AMDx16_EraseSector-\r\n")));
return bDone;
}
//-----------------------------------------------------------------------------
//
// Function: AMDx16_EraseChip
//
// Function erases the entire flash chip
// For 16bit mode flash devices.
//
// Parameters:
// pFlashDesc
// [in] pointer to NOR flash descriptor
//
// Returns:
// FALSE on failure
//
//-----------------------------------------------------------------------------
BOOL AMDx16_EraseChip(NOR_FLASH_DESC *pFlashDesc)
{
ULONG ulFlashBase;
BOOL bIsPaired;
ULONG i;
ULONG ulDataWritten;
BOOL bDone;
DEBUGMSG(ZONE_HAL_FUNCTION,
(TEXT("AMDx16_EraseChip+ 0x%x\r\n"), pFlashDesc));
if( !pFlashDesc) {
DEBUGMSG(ZONE_HAL_ERROR, (TEXT("AMDx16_EraseChip: null param\r\n")));
return FALSE;
}
bIsPaired = pFlashDesc->PairedFlash;
ulFlashBase = pFlashDesc->FlashBase;
// Issue erase chip command
// **************************
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase,
CYCLE_1_ADDR_UNLOCK_x16, CYCLE_1_DATA_UNLOCK);
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase,
CYCLE_2_ADDR_UNLOCK_x16, CYCLE_2_DATA_UNLOCK);
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase,
CYCLE_3_ADDR_CMD_x16, CYCLE_3_DATA_ERASE);
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase,
CYCLE_4_ADDR_ERASE, CYCLE_4_DATA_ERASE);
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase,
CYCLE_5_ADDR_ERASE, CYCLE_5_DATA_ERASE);
WR_FLASH_REG_INDEXED16(bIsPaired, ulFlashBase,
CYCLE_6_ADDR_CHIP_ERASE, CYCLE_6_DATA_CHIP_ERASE);
bDone = FALSE;
#ifdef USE_OS_SERVICES
for (i = 0; i < g_FlashProgInfo.ulMaxChipEraseTOFactor; i++) {
Sleep(g_FlashProgInfo.ulChipEraseTO_ms);
#else
i = 0;
while (!bDone && i++ < CHECK_STATUS_TIMEOUT) {
#endif
ulDataWritten = bIsPaired ? *((volatile ULONG *)(ulFlashBase)) :
*((volatile USHORT *)(ulFlashBase));
DEBUGMSG(ZONE_HAL_FUNCTION,
(TEXT("[0x%x]->0x%x\r\n"), ulFlashBase, ulDataWritten));
if ((ulDataWritten & CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ7_X16))
== CREATE_MASK_16(bIsPaired, AMD_FLASH_DQ7_X16)) {
// DQ7 on the high and low order devices is a 1,
// erase completed successfully.
// *********************************************
bDone = TRUE;
break;
} else {
// Test the device(s) to determine if a timeout has occurred.
// If the device was being erased (DQ7 -> 0) AND
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -