📄 davfhdr.c
字号:
/* Copyright (c) 1995-2004 Intel Corporation */
/* Intel Confidential */
/* ###########################################################################
### FIXED HEADER
###
### Module: davfhdr.c - Fixed Header module
###
### $Workfile: davfhdr.c $
### $Revision: 9 $
### $NoKeywords: $
########################################################################### */
/*
*****************************************************************
* NOTICE OF LICENSE AGREEMENT
*
* This code is provided by Intel Corp., and the use is governed
* under the terms of a license agreement. See license agreement
* for complete terms of license.
*
* YOU MAY ONLY USE THE SOFTWARE WITH INTEL FLASH PRODUCTS. YOUR
* USE OF THE SOFTWARE WITH ANY OTHER FLASH PRODUCTS IS EXPRESSLY
* PROHIBITED UNLESS AND UNTIL YOU APPLY FOR, AND ARE GRANTED IN
* INTEL'S SOLE DISCRETION, A SEPARATE WRITTEN SOFTWARE LICENSE
* FROM INTEL LICENSING ANY SUCH USE.
*****************************************************************
*/
/*### Include Files
#########################*/
#include "DavLib.h"
#if (DIRECT_ACCESS_VOLUME == TRUE)
#include "davfhdr.h"
/*### Local Declarations
#########################*/
/*### Global Declarations
#########################*/
/*### Local Functions
#########################*/
#define ExitOnError(status) \
if (status != ERR_NONE) \
{ return status; }
/*########################################################################
### FHDR_Attr1_FixISF_PLR
###
### DESCRIPTION:
### This function will fix the PLR bit's bits in the plr fields of the
### fixed header from the indeterminate state of 01 or 10 to
### either 00 or 11. for Attr1.
###
### PARAMETERS:
### 32-bit pointer to fixed header attribute in RAM
### flash address where Init' may need to be fixed in flash if required
### restart to know whether to fix in flash or not.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
/* E5.5.979 START */
ERR_CODE FHDR_Attr1_FixISF_PLR(UINT32* uint32_ptr,
UINT32 flash_address,
BOOLEAN restart)
{
/* NOTE: only the last ten bits of HDR_FixedHeader.Attr1 contains PLR bits. */
/* Hence, only it will be corrected, but the entire second half of Attr1 */
/* must be written to flash, since the minimum-sized write is one word, */
/* if the restart flag is set to TRUE. */
UINT16 temp_state;
UINT16 temp_attr1;
ERR_CODE status = ERR_NONE;
/* store into a word the lower 10 bits of the dword */
temp_attr1 = (UINT16)(*uint32_ptr & 0x000003ff);
if((temp_state = UTIL_GetUINT16HeaderQuasiState(temp_attr1)) != 0)
{
/*Fix bits to 00 or 11 depending on restart*/
if(restart)
{
/*fix quasi bits to zero*/
temp_attr1 = UTIL_FixUINT16QuasiStateTo00(temp_state, temp_attr1);
/* mask off the lower 10 bits by pushing them to all zeros */
*uint32_ptr = *uint32_ptr & 0xfffffc00;
/* combine the new lower 10 bits plus the upper 22 bits */
*uint32_ptr = *uint32_ptr | (UINT32)temp_attr1;
/*Write the state back to flash*/
status = FLASH_WriteBuffer(flash_address, (UINT8*)uint32_ptr,
sizeof(UINT32));
}
else
{
/*fix quasi bits in RAM to 11 of the read is 10, fix it to 00 if the read is a 01*/
if(temp_state & temp_attr1)
{ /*this is the 10 situation*/
temp_attr1 = UTIL_FixUINT16QuasiStateTo11(temp_state, temp_attr1);
}
else
{
/*this is the 01 situation*/
temp_attr1 = UTIL_FixUINT16QuasiStateTo00(temp_state, temp_attr1);
}
/* mask off the lower 10 bits by pushing them to all zeros */
*uint32_ptr = *uint32_ptr & 0xfffffc00;
/* combine the new lower 10 bits plus the upper 22 bits */
*uint32_ptr = *uint32_ptr | (UINT32)temp_attr1;
}
}
return (status);
}
/* E5.5.979 END */
/*########################################################################
### FHDR_Attr2_FixISF_PLR
###
### DESCRIPTION:
### This function will fix the PLR bit's bits in the plr fields of the
### fixed header from the indeterminate state of 01 or 10 to
### either 00 or 11. for Attr2.
###
### PARAMETERS:
### 32-bit pointer to fixed header attribute in RAM
### flash address where Init' may need to be fixed in flash if required
### restart to know whether to fix in flash or not.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
/* E5.5.979 START */
ERR_CODE FHDR_Attr2_FixISF_PLR(UINT32* uint32_ptr,
UINT32 flash_address,
BOOLEAN restart)
{
/* NOTE: only the last 8 bits of HDR_FixedHeader.Attr2 contains PLR bits. */
/* Hence, only it will be corrected, but the entire second half of Attr1 */
/* must be written to flash, since the minimum-sized write is one word, */
/* if the restart flag is set to TRUE. */
/* Because this is a little-endian system, the fourth byte is the first */
/* byte pointed to by the 32-bit pointer passed to this function. */
UINT8 temp_attr2;
UINT8 temp_state;
ERR_CODE status = ERR_NONE;
/* store into a temp byte the lower 8 bits from the passed-in dword */
temp_attr2 = (UINT8)(*uint32_ptr & 0x000000ff);
if((temp_state = UTIL_GetUINT8QuasiState(temp_attr2)) != 0)
{
/*Fix bits to 00 or 11 depending on restart*/
if(restart)
{
/*fix quasi bits to zero*/
temp_attr2 = UTIL_FixUINT8QuasiStateTo00(temp_state, temp_attr2);
/* mask off the lower 8 bits of the attr1 field */
*uint32_ptr = *uint32_ptr & 0xffffff00;
/* combine the fixed-up byte with the passed in dword */
*uint32_ptr = *uint32_ptr | (UINT32)temp_attr2;
/*Write the state back to flash*/
status = FLASH_WriteBuffer(flash_address, (UINT8*)uint32_ptr,
sizeof(UINT32));
}
else
{
/*fix quasi bits in RAM to 11 of the read is 10, fix it to 00 if the read is a 01*/
if(temp_state & temp_attr2)
{ /*this is the 10 situation*/
temp_attr2 = UTIL_FixUINT8QuasiStateTo11(temp_state, temp_attr2);
}
else
{
/*this is the 01 situation*/
temp_attr2 = UTIL_FixUINT16QuasiStateTo00(temp_state, temp_attr2);
}
/* mask off the lower 8 bits of the attr1 field */
*uint32_ptr = *uint32_ptr & 0xffffff00;
/* combine the fixed-up byte with the passed in dword */
*uint32_ptr = *uint32_ptr | (UINT32)temp_attr2;
}
}
return (status);
}
/* E5.5.979 END */
/*########################################################################
### FHDR_UINT8_FixISF_PLR
###
### DESCRIPTION:
### This function will fix the PLR bit's bits in the plr fields of the
### object header from the indeterminate state of 01 or 10 to
### either 00 or 11. for an 8 bit value
###
### PARAMETERS:
### 8 bit pointer to status in RAM
### flash address where Init' may need to be fixed in flash if required
### restart to know wheather to fix in flash or not.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE FHDR_UINT8_FixISF_PLR(UINT8 *uint8_ptr,
UINT32 flash_address,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
UINT8 temp_state;
if((temp_state = UTIL_GetUINT8QuasiState(*uint8_ptr)) != 0)
{
/*Fix bits to 00 or 11 depending on restart*/
if(restart)
{
/*fix quasi bits to zero*/
*uint8_ptr = UTIL_FixUINT8QuasiStateTo00(temp_state, *uint8_ptr);
/*Write the state back to flash*/
status = FLASH_WriteBuffer(flash_address, uint8_ptr,
sizeof(UINT8));
}
else
{
/*fix quasi bits in RAM to 11 of the read is 10, fix it to 00 if the read is a 01*/
if(temp_state & *uint8_ptr)
{ /*this is the 10 situation*/
*uint8_ptr = UTIL_FixUINT8QuasiStateTo11(temp_state, *uint8_ptr);
}
else
{
/*this is the 01 situation*/
*uint8_ptr = UTIL_FixUINT8QuasiStateTo00(temp_state, *uint8_ptr);
}
}
}
return (status);
}
/*### Global Functions
#########################*/
/*#################################################################
### FHDR_CreateFixedHeader
###
### DESCRIPTION:
### This function creates the fixed portion of a header to the
### handle in flash. It writes the header in the correct order
### and marks the fixed header complete bit after writing the
### fixed portion.
###
### PARAMETERS:
### aHandle - Address of where to create the fixed
### header.
### aHeaderPtr - IN: The header should be filled with the
### offset, type, and size information to be stored in the
### new entry.
### OUT: The offset, allocation status, and header status
### fields in the fixed header will be set. If this
### function completes with no errors, the
### allocation status should be WriteInProgress, and
### the header status should be HeaderValid.
###
### 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 FHDR_CreateFixedHeader(FDI_Handle aHandle,
HDR_FixedHeaderPtr aHeaderPtr)
{
ERR_CODE status = ERR_NONE;
/* initialize all header fields to unused (all 1's) except offset, size and type */
FHDR_SetReallocationStatus(aHeaderPtr, HDR_REALLOC_BACKUP_NOT_COMPLETE);
FHDR_SetAllocationStatus(aHeaderPtr, HDR_ALLOC_EMPTY);
FHDR_SetAbsorbStatus(aHeaderPtr, HDR_NOT_ABSORBED);
/* Set header status to HeaderAllocating */
FHDR_SetHeaderStatus(aHeaderPtr, HDR_HEADER_ALLOCATING);
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr2),
(UINT8*)&(aHeaderPtr->Attr2),
sizeof(aHeaderPtr->Attr2));
ExitOnError(status);
/* Set offset; size and type already set; size and type already written, */
/* so write offset only to flash */
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr1),
(UINT8*)&(aHeaderPtr->Attr1),
sizeof(aHeaderPtr->Attr1));
ExitOnError(status);
/* At this point, entire header has been written, so only write
the necessary bytes to flash */
/* Set header status to HeaderValid */
FHDR_SetHeaderStatus(aHeaderPtr, HDR_HEADER_VALID);
/* E5.5.979 START */
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr2),
(UINT8*)&(aHeaderPtr->Attr2),
sizeof(aHeaderPtr->Attr2));
/* E5.5.979 END */
ExitOnError(status);
/* Set allocation status to WriteInProgress */
FHDR_SetAllocationStatus(aHeaderPtr, HDR_ALLOC_WRITE_IN_PROGRESS);
/* E5.5.979 START */
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr1),
(UINT8*)&(aHeaderPtr->Attr1),
sizeof(aHeaderPtr->Attr1));
/* E5.5.979 END */
return(status);
}
/*#################################################################
### FHDR_CreateFixedHeaderBackup
###
### DESCRIPTION:
### This function creates the fixed portion of a header to the
### handle in flash for a backup object. It writes the header
### in the correct order and marks the fixed header complete
### bit after writing the fixed portion.
###
### PARAMETERS:
### aHandle - Address of where to create the fixed
### header for the backup object
### aHeaderPtr - IN: The header should be filled with the
### offset, type, and size information to be stored in the
### new entry.
### OUT: The offset, allocation status, and header status
### fields in the fixed header will be set. If this
### function completes with no errors, the
### allocation status should be WriteInProgress, and
### the header status should be HeaderValid.
###
### 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 FHDR_CreateFixedHeaderBackup(FDI_Handle aHandle,
HDR_FixedHeaderPtr aHeaderPtr)
{
ERR_CODE status = ERR_NONE;
/* initialize all header fields to unused (all 1's) except offset, size and type */
FHDR_SetReallocationStatus(aHeaderPtr, HDR_REALLOC_BACKUP_COMPLETE);
FHDR_SetAllocationStatus(aHeaderPtr, HDR_ALLOC_EMPTY);
FHDR_SetAbsorbStatus(aHeaderPtr, HDR_NOT_ABSORBED);
/* Set header status to HeaderAllocating */
FHDR_SetHeaderStatus(aHeaderPtr, HDR_HEADER_ALLOCATING);
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr2),
(UINT8*)&(aHeaderPtr->Attr2),
sizeof(aHeaderPtr->Attr2));
ExitOnError(status);
/* Set offset; size and type already set; size and type already written, */
/* so write offset only to flash */
status = FLASH_WriteBuffer((UINT32)&(((HDR_FixedHeaderPtr)aHandle)->Attr1),
(UINT8*)&(aHeaderPtr->Attr1),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -