📄 flash.c
字号:
* INPUT PARAMETERS:
* PVOID param - Pointer the parameter (not used).
* PVOID arg - Extra parameter (not used).
*
* RETURNS:
* None.
*
* GLOBAL EFFECTS:
* Restarts the Flash device and shuts it down on exit.
*
* ASSUMPTIONS:
* The Flash driver's software initialized routine has been called
* by the platform initialization code.
*
* CALLS:
* DM framework services.
* Flash driver.
*
* CALLED BY:
* Menu system.
*
* PROTOTYPE:
* VOID Flash_WriteTest(PVOID param, PVOID arg);
*
*******************************************************************************
*/
VOID Flash_WriteTest(PVOID param, PVOID arg)
{
UINT status;
UINT start, ticks;
INT i, x;
UINT loggedError = 0;
CHAR sbuf[sizeof(buf)]; //hzh, for save contex in NOR FLASH
PostDisplayProgress(ERR_L_FLASH, ERR_TS_WRITE, 1);
// Get pointer to the Flash drivers DCS.
if (NULL == (flashCtxP = GetFlashParameters(arg, ERR_TS_WRITE)))
{
// Invalid parameter
LOGERROR(status, ERR_L_FLASH, ERR_TS_WRITE, ERR_T_ILLPARAM,
0, 0, 0);
XllpUtilityOutputError(status);
testFailed = TRUE;
return;
}
PostDisplayProgress(ERR_L_FLASH, ERR_TS_WRITE, 2);
// Call Flash hardware setup to initializae the device.
status = flashCtxP->FlashHWSetupFnP(flashCtxP);
if (status)
{
// Flash Setup failed
loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_WRITE, ERR_FLASH_INVALID_DEV);
XllpUtilityOutputError(loggedError);
testFailed = TRUE;
return;
}
PostDisplayProgress(ERR_L_FLASH, ERR_TS_WRITE, 3);
// Fill in the rotating bit pattern.
for (i=0; i < sizeof(buf); i++)
{
buf[i] = i;
}
// Make sure flash blocks are unlocked.
status = flashCtxP->FlashLockStateFnP(flashCtxP, 0, LOGICAL_TEST_BLOCK,
sizeof(buf)/512);
if (status)
{
// Flash Write failed
loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_LOCK, ERR_T_WRONG_VALUE);
XllpUtilityOutputError(loggedError);
testFailed = TRUE;
return;
}
PostDisplayProgress(ERR_L_FLASH, ERR_TS_WRITE, 4);
//===hzh
status = flashCtxP->FlashReadFnP(flashCtxP, LOGICAL_TEST_BLOCK,
sbuf, sizeof(sbuf)/512);
if (status != sizeof(sbuf))
{
printf("Save error!\r\n");
testFailed = TRUE;
return;
}
//===
do
{
// Start the timer.
start = ostCtxP->getTimer_fnp(ostCtxP);
DM_CwDbgPrintf(DM_CW_FLASH_0, " Writing %d bytes to flash 10 times", sizeof(buf));
// Write the block and read it back
for (i=0; i < 3/*10*/; i++) //hzh, just do 3 times
{
PostDisplayProgress(ERR_L_FLASH, ERR_TS_WRITE, 5);
status = flashCtxP->FlashWriteFnP(flashCtxP, LOGICAL_TEST_BLOCK,
buf, sizeof(buf)/512);
if (status != sizeof(buf))
{
// Flash Write failed
loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_WRITE, ERR_T_WRONG_VALUE);
XllpUtilityOutputError(loggedError);
testFailed = TRUE;
return;
}
PostDisplayProgress(ERR_L_FLASH, ERR_TS_WRITE, 6);
status = flashCtxP->FlashReadFnP(flashCtxP, LOGICAL_TEST_BLOCK,
rbuf, sizeof(rbuf)/512);
if (status != sizeof(rbuf))
{
// Flash Read failed
loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_WRITE, ERR_T_WRONG_VALUE);
XllpUtilityOutputError(loggedError);
testFailed = TRUE;
return;
}
PostDisplayProgress(ERR_L_FLASH, ERR_TS_WRITE, 7);
for (x = 0; x < sizeof(buf); x++)
{
if (buf[x] != rbuf[x])
{
DM_CwDbgPrintf(DM_CW_FLASH_0,
" Failed at offset %08x, wrote: %08x, read: %08x",
i, buf[i], rbuf[i]);
loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_WRITE, ERR_T_WRONG_VALUE);
XllpUtilityOutputError(loggedError);
testFailed = TRUE;
return;
}
}
}
// Take the timestamp.
ticks = ostCtxP->getDelta_fnp(ostCtxP, start);
if (RunOnce)
{
// Run only a single pass.
break;
}
}
while (! DM_StopTest (NULL));
//===hzh
status = flashCtxP->FlashWriteFnP(flashCtxP, LOGICAL_TEST_BLOCK,
sbuf, sizeof(sbuf)/512);
if (status != sizeof(sbuf))
{
printf("Restore error!\r\n");
testFailed = TRUE;
return;
}
//===
PostDisplayProgress(ERR_L_FLASH, ERR_TS_WRITE, 8);
// Call Flash hardware to initializae the device.
flashCtxP->FlashHWShutdownFnP(flashCtxP);
PostDisplayProgress(ERR_L_FLASH, ERR_TS_WRITE, 9);
printf (" Success!\r\n");
}
/*
*******************************************************************************
*
* FUNCTION:
* Flash_LockTest
*
* DESCRIPTION:
* Lock/Unlock 2 Flash blocks 10 times.
*
* INPUT PARAMETERS:
* PVOID param - Pointer the parameter (not used).
* PVOID arg - Extra parameter (not used).
*
* RETURNS:
* None.
*
* GLOBAL EFFECTS:
* Restarts the Flash device and shuts it down on exit.
*
* ASSUMPTIONS:
* The Flash driver's software initialized routine has been called
* by the platform initialization code.
*
* CALLS:
* DM framework services.
* Flash driver.
*
* CALLED BY:
* Menu system.
*
* PROTOTYPE:
* VOID Flash_LockTest(PVOID param, PVOID arg);
*
*******************************************************************************
*/
VOID Flash_LockTest(PVOID param, PVOID arg)
{
UINT status;
UINT start, ticks;
INT i;
UINT loggedError = 0;
PostDisplayProgress(ERR_L_FLASH, ERR_TS_LOCK, 1);
// Get pointer to the Flash drivers DCS.
if (NULL == (flashCtxP = GetFlashParameters(arg, ERR_TS_LOCK)))
{
// Invalid parameter
LOGERROR(status, ERR_L_FLASH, ERR_TS_LOCK, ERR_T_ILLPARAM,
0, 0, 0);
XllpUtilityOutputError(status);
testFailed = TRUE;
return;
}
PostDisplayProgress(ERR_L_FLASH, ERR_TS_LOCK, 2);
// Call Flash hardware setup to initializae the device.
status = flashCtxP->FlashHWSetupFnP(flashCtxP);
if (status)
{
// Flash Setup failed
loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_LOCK, ERR_FLASH_INVALID_DEV);
XllpUtilityOutputError(loggedError);
testFailed = TRUE;
return;
}
PostDisplayProgress(ERR_L_FLASH, ERR_TS_LOCK, 3);
// Fill in the rotating bit pattern.
for (i=0; i < sizeof(buf); i++)
{
buf[i] = i;
}
// Fill in the rotating bit pattern.
for (i=0; i < sizeof(rbuf); i++)
{
rbuf[i] = ~i;
}
PostDisplayProgress(ERR_L_FLASH, ERR_TS_LOCK, 4);
// Make sure flash blocks are unlocked.
status = flashCtxP->FlashLockStateFnP(flashCtxP, 0, LOGICAL_TEST_BLOCK,
sizeof(buf)/512);
if (status)
{
// Flash Write failed
loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_LOCK, ERR_T_WRONG_VALUE);
XllpUtilityOutputError(loggedError);
testFailed = TRUE;
return;
}
#if 0 //hzh, don't write
// Write a known pattern to flash.
status = flashCtxP->FlashWriteFnP(flashCtxP, LOGICAL_TEST_BLOCK, buf,
sizeof(buf)/512);
if (status != sizeof(buf))
{
// Flash Write failed
loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_LOCK, ERR_T_WRONG_VALUE);
XllpUtilityOutputError(loggedError);
testFailed = TRUE;
return;
}
#endif
do
{
DM_CwDbgPrintf(DM_CW_FLASH_0, "Locking/Unlocking block %d to %d 10 times",
LOGICAL_TEST_BLOCK, (LOGICAL_TEST_BLOCK + (sizeof(buf) / 512) - 1));
// Start the timer.
start = ostCtxP->getTimer_fnp(ostCtxP);
DM_CwDbgPrintf(DM_CW_FLASH_0, "Locking 2 blocks starting at offset 2 MB");
// Lock and Unlock 2 blocks 10 times.
for (i = 0; i < 10; i++) {
PostDisplayProgress(ERR_L_FLASH, ERR_TS_LOCK, 5);
// Lock the logical test block
status = flashCtxP->FlashLockStateFnP(flashCtxP, 1,
LOGICAL_TEST_BLOCK,
sizeof(buf)/512);
if (status)
{
// Flash lock failed
loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_LOCK, ERR_T_WRONG_VALUE);
XllpUtilityOutputError(loggedError);
testFailed = TRUE;
return;
}
DM_CwDbgPrintf(DM_CW_FLASH_0, "Attempting to write to locked blocks");
PostDisplayProgress(ERR_L_FLASH, ERR_TS_LOCK, 6);
// Attempt to write to the locked flash.
status = flashCtxP->FlashWriteFnP(flashCtxP, LOGICAL_TEST_BLOCK,
rbuf, sizeof(rbuf)/512);
if (status == sizeof(rbuf))
{
// Flash Write failed
loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_LOCK, ERR_T_WRONG_VALUE);
XllpUtilityOutputError(loggedError);
testFailed = TRUE;
return;
}
DM_CwDbgPrintf(DM_CW_FLASH_0, "Unlocking all blocks");
PostDisplayProgress(ERR_L_FLASH, ERR_TS_LOCK, 7);
// Unlock all blocks, block paramters are ignored.
status = flashCtxP->FlashLockStateFnP(flashCtxP, 0,
LOGICAL_TEST_BLOCK,
sizeof(buf)/512);
if (status)
{
// Flash lock failed
loggedError = ERRORCODE(ERR_L_FLASH, ERR_TS_LOCK, ERR_T_WRONG_VALUE);
XllpUtilityOutputError(loggedError);
testFailed = TRUE;
return;
}
}
// Take the timestamp.
ticks = ostCtxP->getDelta_fnp(ostCtxP, start);
if (RunOnce)
{
// Run only a single pass.
break;
}
}
while (! DM_StopTest (NULL));
PostDisplayProgress(ERR_L_FLASH, ERR_TS_LOCK, 8);
// Call Flash hardware to initializae the device.
flashCtxP->FlashHWShutdownFnP(flashCtxP);
PostDisplayProgress(ERR_L_FLASH, ERR_TS_LOCK, 9);
printf (" Success!\r\n");
}
/*
*******************************************************************************
*
* FUNCTION:
* PostStrataFlash()
*
* DESCRIPTION:
* This routine runs all the non-interactive Flash test.
*
* INPUT PARAMETERS:
* UINT device - device to test, Flash_Boot_Index and Flash_Alternate_Index
*
* RETURNS:
* None.
*
* GLOBAL EFFECTS:
* None.
*
* ASSUMPTIONS:
* None.
*
* CALLS:
* Flash_ShowStatus, Flash_ReadTest,
* ReadUserSwitches, Flash_WriteTest.
*
* CALLED BY:
* POST
*
* PROTOTYPE:
* INT PostStrataFlash(VOID);
*
*******************************************************************************
*/
INT PostStrataFlash(UINT device)
{
INT errorCount = 0;
CHAR deviceString[10];
switch (device)
{
case Flash_Default_Index:
strcpy(deviceString, "DEFAULT");
break;
case Flash_Alternate_Index:
strcpy(deviceString, "ALTERNATE");
break;
default:
strcpy(deviceString, "ALTERNATE");
break;
}
PostDisplayProgress(ERR_L_FLASH, ERR_TS_POSTFLASH, 1);
// Attempt to access the Alternate Flash.
Flash_ShowStatus(&contexts[device], deviceString);
if (testFailed) ++errorCount;
PostDisplayProgress(ERR_L_FLASH, ERR_TS_POSTFLASH, 2);
// Read from the Alternate Flash.
Flash_ReadTest(&contexts[device], deviceString);
if (testFailed) ++errorCount;
PostDisplayProgress(ERR_L_FLASH, ERR_TS_POSTFLASH, 3);
// Write to the Alternate Flash.
Flash_WriteTest(&contexts[device], deviceString);
if (testFailed) ++errorCount;
PostDisplayProgress(ERR_L_FLASH, ERR_TS_POSTFLASH, 4);
// Write to the Alternate Flash.
Flash_LockTest(&contexts[device], deviceString);
if (testFailed) ++errorCount;
PostDisplayProgress(ERR_L_FLASH, ERR_TS_POSTFLASH, 5);
return errorCount;
}
/*
*******************************************************************************
*
* FUNCTION:
* PostStrataFlashTest()
*
* DESCRIPTION:
* This routine runs all the non-interactive Flash test.
*
* INPUT PARAMETERS:
* PVOID ctxP, PCHAR param
*
* RETURNS:
* None.
*
* GLOBAL EFFECTS:
* None.
*
* ASSUMPTIONS:
* None.
*
* CALLS:
*
* CALLED BY:
* POST
*
* PROTOTYPE:
* VOID PostStrataFlash(PVOID ctxP, PCHAR param);
*
*******************************************************************************
*/
VOID PostStrataFlashTest(PVOID ctxP, PCHAR param)
{
PostStrataFlash (Flash_Default_Index);
PostStrataFlash (Flash_Alternate_Index);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -