📄 davinit.c
字号:
### block size).
### FlashBase - Physical base address of region to manage.
### OUT:
### 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.
###*/
ERR_CODE DAV_PowerOnInit(FLASH_InfoPtr flash_info_ptr)
{
ERR_CODE status;
ERR_CODE page_object_status;
HDR_SearchInfo page_object_searchInfo;
/* Initialize the counter for number of page objects in flash */
FDI_PageObjectCounter = 0;
status = DAV_SoftInit(flash_info_ptr, FALSE);
if (status)
{
return status;
}
/* Performs redundant recovery scan but, since no recovery will
be necessary it won't take that much time.
*/
status = RECOVER_ValidateSystem();
/* Count the number of page objects in flash */
if (!status)
{
HDR_InitSearchInfo((&page_object_searchInfo), (&SearchHeader));
do
{
page_object_status = GetNextHeader(&page_object_searchInfo, HDR_ByNextPageObject, 0, TRUE);
if ((page_object_status != ERR_NONE) && (page_object_status != ERR_NO_MORE_ENTRIES) &&
(page_object_status != ERR_PARAM))
{
return(page_object_status);
}
if ((page_object_status == ERR_NONE) &&
(HDR_GetHdrState(page_object_searchInfo.HeaderPtr->Attr16) == HDR_HA_STATE_Valid))
{
FDI_PageObjectCounter++;
}
} while (!(page_object_status == ERR_NO_MORE_ENTRIES));
}
return(status);
}
/*#################################################################
### DAV_SoftInit
###
### DESCRIPTION:
### This function is responsible for performing an initialization
### of data structures and will recovery from power loss but,
### will not perform any WIP object removal.
###
### PARAMETERS:
### flash_info_ptr - pointer to a valid flash info structure
### that tells the DAV what to manage.
### IN: none
###
### OUT:
### 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.
###
### 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 flag)
{
ERR_CODE status;
/* Init global vars to 0 */
FDI_BlockSize = 0;
FDI_StartAddress = 0;
FDI_TotalBlocks = 0;
FDI_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);
/* Setup remaining global variables */
FDI_SystemState = 0;
FDI_ReclaimLevel = FDI_InitialRelclaimLevel;
FDI_ReAllocateOverrideFlag = FALSE;
FDI_LockoutObjectAllocation = FALSE;
ReclaimState.ReclaimInProgress = FALSE;
FDI_MemUsage.ParaSpace.ReservesInUse = 0;
FDI_MemUsage.PageSpace.ReservesInUse = 0;
FDI_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(!flag)
{
status = RECOVER_ValidateSystem();
}
if (status == ERR_SYSTEM)
{
FDI_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)
{
UINT32 ii, end_of_memory;
UINT8 kill_buffer[FDI_ParagraphLength];
ERR_CODE status;
status = DAV_SoftInit(flash_info_ptr, TRUE);
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.
*/
for (ii = 0; ii < sizeof(kill_buffer); ii++)
{
kill_buffer[ii] = 0;
}
/* don't forget to subtract the reclaim block */
end_of_memory = (flash_info_ptr->TotalBlocks - 1) *
flash_info_ptr->BlockSize;
status = FLASH_WriteBuffer(
ParagraphAlign(flash_info_ptr->FlashBase +
end_of_memory - sizeof(kill_buffer)),
(MemBufferPtr)(kill_buffer), sizeof(kill_buffer));
if (status != ERR_NONE)
{
return status;
}
/* Erase all of Object Space*/
for (ii = 0; ii < flash_info_ptr->TotalBlocks; ii++)
{
status = FLASH_EraseBlock(flash_info_ptr->FlashBase
+ (ii * flash_info_ptr->BlockSize), FALSE);
if (status != ERR_NONE)
{
return status;
}
}
/* Create the configuration header*/
HDR_CalcMemoryStatistics( FALSE );
status = CFGHDR_CreateConfigurationHeader();
if (status != ERR_NONE)
{
return status;
}
return status;
}
/*########################################################################
### DAV_Exit
###
### Purpose:
### This function function is to cleanup any operations performed
### during initialization. Such as, free allocated RAM resources
### for emulated flash memory.
###
### PARAMETERS:
### IN:
### none
###
### OUT:
### none
###
### RETURNS:
### ERR_NONE (0)
###
*/
ERR_CODE DAV_Exit(void)
{
FDI_InitializationComplete = FALSE;
return ERR_NONE;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -