📄 davinit.c
字号:
### TotalBlocks - Total number of blocks being managed.
### DeviceId - Flash JEDEC Id.
### DeviceType - Type of device (RAM_EMUL, FILE_EMUL, etc.)
### See davflash.h for enumerations.
### FlashBase - If virtual memory is used, then this
### will return a virtual address to the
### physical address specified on the way IN.
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
/* Added a flag to fix format error.*/
ERR_CODE DAV_SoftInit(FLASH_InfoPtr flash_info_ptr, BOOLEAN perform_plr_recovery)
{
ERR_CODE status;
/* Init global vars to 0 */
FDI_TotalBlocks = 0;
DAV_InitializationComplete = FALSE;
/**************************************************************************
* COMPATIBILITY MODULE * COMPATIBILITY MODULE * COMPATIBILITY MODULE
* DO NOT MODIFY * DO NOT MODIFY * DO NOT MODIFY * DO NOT MODIFY
**************************************************************************/
/**************************************************************************
* -*- Mode: C -*-
*
* Copyright (c) Intel Corp.
*
*
* Description : This routine contains the compatibility module for
* this software. It is a direct violation of the
* software license agreement to remove, modify, alter,
* or change this compatibility module.
* This compatibility module must be called during
* initialization to adhere to the software licensing
* agreement. If an error is returned by the compatibility
* module, it must cause the entire software product
* provided by Intel to fail. Any changes to this
* compatibility module require prior written consent of
* Intel's Flash Software Marketing Department.
*
**************************************************************************/
status = FLASH_CompatibilityCheck();
if (status)
{
return status;
}
/********************************************************************
* END OF COMPATIBILITY MODULE * END OF COMPATIBILITY MODULE *
*******************************************************************/
/* Initialize hardware and reset flash part */
status = FLASH_GetDeviceInfo(flash_info_ptr);
if (status != ERR_NONE)
{
/* Must indicate to format or other that there is a
* serious problem, we can't initialize the flash
* interface.
*/
return ERR_SYSTEM;
}
/* Store flash information globally to the dav rather
than use the flash module functions.
*/
FDI_BlockSize = flash_info_ptr->BlockSize;
FDI_StartAddress = flash_info_ptr->FlashBase;
FDI_TotalBlocks = flash_info_ptr->TotalBlocks;
FDI_TopOfMemory = (FDI_StartAddress - 1) +
(FDI_TotalBlocks * FDI_BlockSize);
/* Set up derived system parameters */
FDI_ReclaimBlockAddressTop =(FDI_TopOfMemory);
FDI_ReclaimBlockAddressBottom =(FDI_TopOfMemory - \
(FDI_BlockSize * (FDI_ReservedReclaimBlocks)) + 1);
FDI_ParaSpaceAddressTop =(FDI_ReclaimBlockAddressBottom - 1);
FDI_ParaSpaceAddressBottom =(FDI_ParaSpaceAddressTop - \
(FDI_BlockSize * (FDI_ReservedSystemBlocks)) + 1);
FDI_PageSpaceAddressTop =(FDI_ParaSpaceAddressBottom - 1);
FDI_PageSpaceAddressBottom =(DAV_START_ADDRESS);
FDI_LastObjectAddress =FDI_PageSpaceAddressTop;
FDI_FirstObjectAddress =FDI_PageSpaceAddressBottom;
FDI_TotalFlashSpace =((FDI_TopOfMemory - FDI_StartAddress) + 1) / FDI_PageSize;
FDI_TotalObjectSpace =((FDI_TotalFlashSpace*FDI_PageSize) - (FDI_BlockSize * (FDI_ReservedReclaimBlocks + FDI_ReservedSystemBlocks)));
DAV_MEM_FirstHeaderAddr =((FDI_ParaSpaceAddressTop - FHDR_CalcHeaderSize()) + 1);
/* Setup remaining global variables */
FDI_SystemState = 0;
FDI_ReclaimLevel = FDI_InitialReclaimLevel;
FDI_ReAllocateOverrideFlag = FALSE;
FDI_LockoutObjectAllocation = FALSE;
#ifdef __USE_OLD_DEFRAG__ /* ReclaimState */
ReclaimState.ReclaimInProgress = FALSE;
#endif
DAV_InitializationComplete = TRUE;
/* Check for major failures such as reclaim, reallocate, allocate
but don't remove WIP objects. We may only be switching to a new
database. */
if(perform_plr_recovery == TRUE)
{
/* If we are recovering, the pin list is lost */
GlbPinObjectListEntries = 0;
UTIL_ClearVariable((UINT8*)&GlbPinObjectList[0], sizeof(GlbPinObjectList), 0x00);
UTIL_ClearVariable((UINT8*)&GlbPinBlockTable[0], sizeof(GlbPinBlockTable), 0x00);
status = RECOVER_ValidateSystem(); /* DAV_SoftInit */
if (status != ERR_NONE)
{
if(status != ERR_NOTEXISTS)
{
return (status);
}
else
{
/* We want to know this happened */
status = status;
}
/* No sign of a CFGTBL Fixed Header or CFGTBL */
status = ERR_NONE;
}
}
if (status == ERR_SYSTEM)
{
DAV_InitializationComplete = FALSE;
}
return status;
}
/*########################################################################
### DAV_Format
###
### DESCRIPTION:
### This function function will initialize flash through the
### flash module, create a configuration header entry, and
### perform any initialization necessary to put the DAV into
### a pre-use state. Note that no initialization is required
### prior to calling this function.
###
### PARAMETERS:
### IN:
### flash_info_ptr - Pointer to a valid FLASH_Info structure.
###
### OUT:
### flash_info_ptr->
### BlockSize - number of bytes in the erase block.
### TotalBytes - total bytes being managed.
### FlashBase - Base address of region to manage.
### May or may not be virtual.
### TotalBlocks - Total number of blocks being managed.
### DeviceId - Flash JEDEC Id.
### DeviceType - Type of device (RAM_EMUL, FILE_EMUL, etc.)
### See davflash.h for enumerations.
### FlashBase - If virtual memory is used, then this
### will return a virtual address to the
### physical address specified on the way IN.
###
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
*/
ERR_CODE DAV_Format(FLASH_InfoPtr flash_info_ptr)
{
ERR_CODE status;
/* Since we are formatting, we do not want to attempt a recovery */
BOOLEAN performPlrRecovery = FALSE;
status = DAV_SoftInit(flash_info_ptr, performPlrRecovery); /* DAV_Format */
if (status == ERR_SYSTEM)
{
return status;
}
/* Corrupt location of cfg header so if a power loss
* occurs during a format, format will restart.
* Zero out the top 16 bytes of the configuration header.
*/
CFGTBL_CorruptFixedHeader();
/* Erase all of DAV Space, including the paragraph (system) block and reclaim block */
UTIL_Dav_Format();
/* Create the configuration header */
GlbPinObjectListEntries = 0;
UTIL_ClearVariable((UINT8*)&GlbPinObjectList[0], sizeof(GlbPinObjectList), 0x00);
UTIL_ClearVariable((UINT8*)&GlbPinBlockTable[0], sizeof(GlbPinBlockTable),0x00);
status = MEM_CalcMemoryStatistics(FALSE); /* FDI_DAVInit */
if(status != ERR_NONE)
{
return status;
}
status = CFGTBL_AllocateFlash();
if(status != ERR_NONE)
{
return status;
}
status = FDI_DAVInit(); /* DAV_Format */
if (status != ERR_NONE)
{
status = ERR_INIT;
}
return status;
}
/*########################################################################
### DAV_Terminate
###
### DESCRIPTION:
### This function function will terminate all the semaphoress used by DAV.
###
### PARAMETERS:
### IN:
### OUT:
*/
void DAV_Terminate(void)
{
DAV_InitializationComplete = FALSE;
/* Moved mutex semaphore destruction to FDI_Terminate */
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -