📄 davcghdr.c
字号:
/* Copyright (c) 1995-2002 Intel Corporation */
/* Intel Confidential */
/* ###########################################################################
### CFGHDR - Configuration Header
###
### Module: cfghdr.c - Configuration Header Module
###
### $Workfile: davcghdr.c $
### $Revision: 49 $
### $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 "dav.h"
#if (DIRECT_ACCESS_VOLUME == TRUE)
/*### Local Declarations
#########################*/
/*## Restart States for Configuration Header Reclaim */
/*## Note these states are based on the documentation */
typedef enum
{
NoRestart,
RecoverState1,
RecoverState2,
RecoverState3,
RecoverState4,
RecoverState5
} CFGHDR_RestartState;
/*## Code used to combine Header Id status for restart switch statement */
#define CFGHDR_GetInitialState(ht_header_id, rb_header_id) \
(CFGHDR_InitialState)(((ht_header_id) & 0xFF00) | \
((rb_header_id >> 8) & 0x00FF))
#define CFGHDR_ST_Normal (HDR_ST_Normal >> 8)
#define CFGHDR_ST_RIP (HDR_ST_ReclaimInProgress >> 8)
#define CFGHDR_ST_COC (HDR_ST_CopyOutComplete >> 8)
#define CFGHDR_ST_CIP (HDR_ST_CopyInProgress >> 8)
#define CFGHDR_ST_Garbage 0x00FF /*CIP is the same as this*/
typedef enum
{
Normal_Garbage = ((CFGHDR_ST_Normal << 8) | CFGHDR_ST_Garbage), /*3CFF*/
RIP_Garbage = ((CFGHDR_ST_RIP << 8) | CFGHDR_ST_Garbage), /*30FF---*/
Garbage_Normal = ((CFGHDR_ST_Garbage << 8) | CFGHDR_ST_Normal), /*FF3C*/
Garbage_RIP = ((CFGHDR_ST_Garbage << 8) | CFGHDR_ST_RIP), /*FF30-*/
COC_Normal = ((CFGHDR_ST_COC << 8) | CFGHDR_ST_Normal), /*003C*/
CIP_RIP = ((CFGHDR_ST_CIP << 8) | CFGHDR_ST_RIP), /*3F30-*/
Normal_COC = ((CFGHDR_ST_Normal << 8) | CFGHDR_ST_COC), /*3C00*/
CIP_COC = ((CFGHDR_ST_CIP << 8) | CFGHDR_ST_COC), /*3F00*/
RIP_CIP = ((CFGHDR_ST_RIP << 8) | CFGHDR_ST_CIP), /*303F---*/
COC_CIP = ((CFGHDR_ST_COC << 8) | CFGHDR_ST_CIP) /*003F*/
} CFGHDR_InitialState; /*for ISf this changes for 8 bits */
/* to 16 bits */
/*### Global Declarations
#########################*/
/*### Local Functions
#########################*/
ERR_CODE CFGHDR_WriteConfigurationEntry(UINT8 entry_index,
CFGHDR_ConfigurationEntry cfg_entry);
ERR_CODE CFGHDR_MoveHeader(FDI_Handle source_header,
FDI_Handle dest_header,
CFGHDR_RestartState restart_state,
BOOLEAN restart);
/*### Global Functions
#########################*/
/*########################################################################
### CFGHDR_ScanConfigurationEntry
###
### DESCRIPTION:
### This function scans the entries at the base address passed in,
### looking for the next free entry or entry that is not done.
### It will scan through the max possible entries, and if a free
### entry is not found then the next free index will be -1.
### Also if a header is found that is not done, then
### the search will stop and the config entry will be passed back.
###
### PARAMETERS:
### entry_index_ptr - On return, it will contain the index to the
### next free entry or an entry not done.
### cfg_entry_ptr - On return, it will contain the configuration
### entry if one is available.
### base_address_of_entry_array - The base handle of the config. entries
###
### RETURNS:
### None.
###*/
ERR_CODE CFGHDR_ScanConfigurationEntry(UINT8_PTR entry_index_ptr,
CFGHDR_ConfigurationEntryPtr cfg_entry_ptr,
FDI_Handle base_address_of_entry_array,
BOOLEAN restart)
{
ERR_CODE status = ERR_NONE;
/* Scan for a free entry */
for (*entry_index_ptr = 0;
*entry_index_ptr < CFGHDR_MaxConfigurationEntries;
(*entry_index_ptr)++)
{
/* Read State from flash */
FLASH_ReadBuffer(base_address_of_entry_array,
(MemBufferPtr)(cfg_entry_ptr),
CFGHDR_ConfigurationEntrySize);
status = UINT32_FixISF_PLR( &(cfg_entry_ptr->Status),
base_address_of_entry_array, restart);
if(status)
{
return (status);
}
/* if empty entry break loop */
if (CFGHDR_IsUnusedConfigurationEntry(*cfg_entry_ptr))
{
/* Found an empty state entry */
break;
}
else
{
if (CFGHDR_GetReclaimComplete(*cfg_entry_ptr) !=
CFGHDR_STATUS_ReclaimComplete)
{
/* Entry is still in use */
break;
}
else
{
/* Try Next entry */
base_address_of_entry_array += CFGHDR_ConfigurationEntrySize;
}
}
}
if (*entry_index_ptr == CFGHDR_MaxConfigurationEntries)
{
/* No entries available */
*entry_index_ptr = 0xFF;
}
return status;
}
/*########################################################################
### CFGHDR_AllocateConfigurationEntry
###
### DESCRIPTION:
### This function finds the next available reclaim state entry,
### and performs CfgHeader reclaim if no more are available.
### It is assumed that configuration header is always in the
### header table at the top of object space. This function also
### marks the allocated entry with the selected type of reclaim
### and the reclaim in progress bit.
###
### PARAMETERS:
### entry_index_ptr - On return, this is the index to the config.
### entry in use.
### cfg_entry_ptr - On return, this is the actual config. entry
### indicating the type and reclaim in progress.
### reclaim_table_type - On input, this is used to determine type
### of entry that should be allocated (reallocate
### or paragraph reclaim).
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_AllocateConfigurationEntry(UINT8_PTR entry_index_ptr,
CFGHDR_ConfigurationEntryPtr cfg_entry_ptr,
UINT32 reclaim_table_type,
BOOLEAN restart)
{
ERR_CODE status;
FDI_Handle config_entry_handle;
/* Set handle to point to entry array in header table block */
config_entry_handle = ((FDI_LastObjectAddress - CFGHDR_ConfigHeaderSize) +
CFGHDR_EntryArrayOffset) + 1;
/* This will point return the next free entry. */
status = CFGHDR_ScanConfigurationEntry(entry_index_ptr, cfg_entry_ptr,
config_entry_handle, restart);
if(status)
{
return status;
}
if (*entry_index_ptr == 0xFF)
{
/* No More free entries, need to do a config reclaim */
status = CFGHDR_ConfigurationHeaderReclaim(FALSE);
if (status != ERR_NONE)
{
return(status);
}
*entry_index_ptr = 0;
CFGHDR_SetUnusedConfigurationEntry(*cfg_entry_ptr);
}
if (!CFGHDR_IsUnusedConfigurationEntry(*cfg_entry_ptr))
{
/* There is an entry in use. */
return(ERR_SYSTEM);
}
/* Write Entry to Reclaim In Progress with specified type */
CFGHDR_SetReclaimTableType((*cfg_entry_ptr), reclaim_table_type);
status = CFGHDR_WriteConfigurationEntry(*entry_index_ptr,
*cfg_entry_ptr);
if (status)
{
return(status);
}
CFGHDR_SetReclaimInProgress((*cfg_entry_ptr),
CFGHDR_STATUS_ReclaimInProgress);
status = CFGHDR_WriteConfigurationEntry(*entry_index_ptr,
*cfg_entry_ptr);
return(status);
}
/*########################################################################
### CFGHDR_WriteReclaimComplete
###
### DESCRIPTION:
### This function uses entry_index to select the
### configuration entry to mark Reclaim Complete; therefore
### indicating reclaim completion.
###
### PARAMETERS:
### entry_index - Selects the entry that should be marked to
### reclaim entry. This should be the entry
### returned during allocation of the config. entry.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_WriteReclaimComplete(UINT8 entry_index)
{
CFGHDR_ConfigurationEntry cfg_entry;
ERR_CODE status;
CFGHDR_SetUnusedConfigurationEntry(cfg_entry);
CFGHDR_SetReclaimComplete(cfg_entry, CFGHDR_STATUS_ReclaimComplete);
status = CFGHDR_WriteConfigurationEntry(entry_index, cfg_entry);
return(status);
}
/*########################################################################
### CFGHDR_WriteTableOffset
###
### DESCRIPTION:
### This function writes the passed in offset to the selected
### config. entry and then marks the entry as having a valid offset.
###
### PARAMETERS:
### entry_index - Selects the entry that should be marked to
### reclaim entry. This should be the entry
### returned during allocation of the config. entry.
### offset - The offset to be stored into the configuration entry.
### This should be the offset from the top of paragraph
### space to the reclaim table header.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_WriteTableOffset(UINT8 entry_index, UINT32 offset)
{
CFGHDR_ConfigurationEntry cfg_entry;
ERR_CODE status;
CFGHDR_SetUnusedConfigurationEntry(cfg_entry);
CFGHDR_SetOffset(cfg_entry, offset);
status = CFGHDR_WriteConfigurationEntry(entry_index, cfg_entry);
if (status)
{
return(status);
}
CFGHDR_SetOffsetStatus(cfg_entry, CFGHDR_STATUS_ValidOffset);
status = CFGHDR_WriteConfigurationEntry(entry_index, cfg_entry);
return(status);
}
/*########################################################################
### CFGHDR_WriteConfigurationEntry
###
### DESCRIPTION:
### This function writes the reclaim entry to the config header entries
### at the specified index. This actually writes the entry to flash.
### Before writing the entry, it authenticates the configuration header
### to ensure it is writing to config. header's object space.
###
### PARAMETERS:
### entry_index - Selects the entry that should be marked to
### reclaim entry. This should be the entry
### returned during allocation of the config. entry.
### reclaim_entry - The actual entry to be written to flash. This
### includes the status and offset.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_WriteConfigurationEntry(UINT8 entry_index,
CFGHDR_ConfigurationEntry reclaim_entry)
{
ERR_CODE status;
FDI_Handle reclaim_entry_handle;
/* Calculate base handle of entries */
reclaim_entry_handle = ((FDI_LastObjectAddress - CFGHDR_ConfigHeaderSize) +
CFGHDR_EntryArrayOffset) + 1;
/* Increment handle to correct entry */
reclaim_entry_handle += CFGHDR_ConfigurationEntrySize * entry_index;
status = FLASH_WriteBuffer(reclaim_entry_handle,
(MemBufferPtr)&reclaim_entry,
CFGHDR_ConfigurationEntrySize);
return(status);
}
/*######################################################################*/
/*### CONFIGURATION HEADER RECLAIM ###*/
/*######################################################################*/
/*########################################################################
### CFGHDR_ConfigurationHeaderReclaim
###
### DESCRIPTION:
### This function will reclaim in place the first block,
### in order to make reclaim entries available.
###
### PARAMETERS:
### restart - Allows a configuration header reclaim to be restarted.
### based on the status of the header id of the config.
### header.
###
### RETURNS:
### Returns a status of type ERR_CODE.
###*/
ERR_CODE CFGHDR_ConfigurationHeaderReclaim(BOOLEAN restart)
{
FDI_Handle rb_header_handle,
ht_header_handle,
unique_id_handle1,
unique_id_handle2;
ERR_CODE status = ERR_NONE;
UINT16 unique_id = 0,
ht_header_id, rb_header_id;
CFGHDR_RestartState restart_state = NoRestart;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -