📄 davohdr.c
字号:
/* Copyright (c) 1995-2004 Intel Corporation */
/* Intel Confidential */
/* ###########################################################################
### HEADER
###
### Module: davohdr.c - Object Header module
###
### $Workfile: davohdr.c $
### $Revision: 3 $
### $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 "davohdr.h"
/*### Local Declarations
#########################*/
static ERR_CODE OHDR_ReadObjectHeaderName(FDI_Handle aHandle,
HDR_ObjectHeaderPtr aHeaderPtr);
/*### Global Declarations
#########################*/
/*### Local Functions
#########################*/
#define ExitOnError(status) \
if (status != ERR_NONE) \
{ return status; }
/*#################################################################
### OHDR_ReadObjectHeaderName
###
### DESCRIPTION:
### This function will load "aName" with the object name.
### PARAMETERS:
### aHandle - Contains handle(address) of object in flash.
### aHeaderPtr - IN: Must point to an object header
### OUT: Object header is loaded with the name, if one
### exists.
###
### RETURNS:
### ERR_CODE.
###*/
static ERR_CODE OHDR_ReadObjectHeaderName(FDI_Handle aHandle,
HDR_ObjectHeaderPtr aHeaderPtr)
{
ERR_CODE status = ERR_NONE;
UINT16 i = 0;
/* Insure that we stay within the limits of the fixed size */
if(aHeaderPtr->NameSize <= FDI_MaxNameLength)
{
for(i=0; i<FDI_MaxNameLength; i++)
{
*((char*)(aHeaderPtr->Name)+i) = ' ';
}
/* Insure that we got a pointer */
if(aHeaderPtr->Name != 0)
{
/* Read in the name */
status = FLASH_ReadBuffer(aHandle, (UINT8*)(aHeaderPtr->Name), aHeaderPtr->NameSize);
ExitOnError(status);
}
}
else
{
status = ERR_PARAM;
ExitOnError(status);
}
return status;
}
/*### Global Functions
#########################*/
/*#################################################################
### OHDR_ReadObjectHeader
###
### DESCRIPTION:
### This function will load "aHeaderPtr" with the object leader
### header data, and optionally, the name
### PARAMETERS:
### aHandle - Contains handle(address) of object leader header
### to read from flash.
### aHeaderPtr - IN: Must point to a valid header structure.
### OUT: Header is loaded with object leader
### header information, and optionally, the
### name.
### aReadName - if true, read name
###
### RETURNS:
### ERR_CODE.
###*/
ERR_CODE OHDR_ReadObjectHeader(FDI_Handle aHandle,
HDR_ObjectHeaderPtr aHeaderPtr,
BOOLEAN aReadName)
{
ERR_CODE status = ERR_NOTEXISTS;
/* Read the object leader header from flash */
status = FLASH_ReadBuffer(aHandle,
(UINT8*)aHeaderPtr,
HDR_SizeOfObjectHeaderWithoutName);
ExitOnError(status);
/* Determine if this is an object header */
if(aHeaderPtr->UniqueId1 == 0xF0F0 &&
aHeaderPtr->UniqueId2 == 0xF0F0)
{
/* If requested, read the name in */
if(aReadName == TRUE)
{
/* Read the name */
status = OHDR_ReadObjectHeaderName(aHandle + HDR_SizeOfObjectHeaderWithoutName,
aHeaderPtr);
ExitOnError(status);
}
}
else
{
status = ERR_NOTEXISTS;
ExitOnError(status);
}
return status;
}
/*#################################################################
### OHDR_WriteObjectHeader
###
### DESCRIPTION:
### This function will write the fixed object header and name
### to the specified object location in page space.
###
### PARAMETERS:
### aHandle - Contains destination handle(address) for flash.
### aObjectHeaderPtr
### - Must point to a valid fixed object header structure
### aNamePtr - Name, must be specified; size must be set in
### aObjectHeaderPtr
###
### RETURNS:
### ERR_CODE.
###*/
ERR_CODE OHDR_WriteObjectHeader(FDI_Handle aHandle,
HDR_ObjectHeaderPtr aHeaderPtr)
{
ERR_CODE status = ERR_NONE;
UINT8 alignedNameSize;
/* Write fixed object header to flash */
status = FLASH_WriteBuffer(aHandle,
(UINT8*)aHeaderPtr,
HDR_SizeOfObjectHeaderWithoutName);
if (status)
{
return status;
}
/* Write name to flash */
if ((aHeaderPtr->NameSize > 0) && (aHeaderPtr->Name != 0))
{
alignedNameSize = (aHeaderPtr->NameSize % 2) ? aHeaderPtr->NameSize + 1 : aHeaderPtr->NameSize;
status = FLASH_WriteBuffer(aHandle + HDR_SizeOfObjectHeaderWithoutName,
(UINT8*)(aHeaderPtr->Name),
alignedNameSize);
}
return status;
}
#endif /* DIRECT_ACCESS_VOLUME */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -