davrecip.c
来自「FDI Intel开发的FLASH文件系统,功能很强大」· C语言 代码 · 共 955 行 · 第 1/3 页
C
955 行
return(status);
}
bottom_block = Handle2Block(RECINPLC_BottomSectionAddr);
/*lint -fallthrough*/
case RECINPLC_STEP_BottomSection_RecoveryState1:
case RECINPLC_STEP_BottomSection_RecoveryState2:
case RECINPLC_STEP_BottomSection_RecoveryState3:
case RECINPLC_STEP_BottomSection_RecoveryState4:
case RECINPLC_STEP_MiddleSection:
case RECINPLC_STEP_TopSection_RecoveryState1:
case RECINPLC_STEP_TopSection_RecoveryState2:
case RECINPLC_STEP_TopSection_RecoveryState3:
case RECINPLC_STEP_TopSection_RecoveryState4:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_ProcessBlocks);
#endif
top_block = Handle2Block(RECINPLC_TopSectionAddr);
for (block = bottom_block; block <= top_block; block++ )
{
start_addr_in_block = RECINPLC_BottomSectionAddr;
end_addr_in_block = RECINPLC_TopSectionAddr;
GetInBlockHiLoAddress(&start_addr_in_block,
&end_addr_in_block, block);
status = RECINPLC_ProcessBlock(
FDI_GlobalInfo.CurrObj.ObjectAddress,
start_addr_in_block,
end_addr_in_block,
rip_restart_state);
if (status)
{
return(status);
}
if (restart)
{
/* Continue processing blocks from normal restart state */
rip_restart_state = RECINPLC_STEP_NoRestart;
}
}
/*lint -fallthrough*/
case RECINPLC_STEP_DeallocateRAT:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_DeallocateRAT);
#endif
/* Init Attr to a Erased State */
/* Deallocate Table */
HDR_InitHeaderAttr16(FDI_GlobalInfo.HeaderPtr->Attr16);
HDR_InitHeaderAttr8(FDI_GlobalInfo.HeaderPtr->Attr8);
status = HDR_InvalidateHeader(FDI_GlobalInfo.CurrObj.HeaderAddress,
FDI_GlobalInfo.HeaderPtr);
if (status != ERR_NONE)
{
return(status);
}
/*lint -fallthrough*/
case RECINPLC_STEP_MarkCfgEntryDone:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_MarkCFGDone);
#endif
status = CFGHDR_WriteReclaimComplete(cfg_entry_index);
if (status)
{
return status;
}
}
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_ReclaimInPlace_End);
#endif
return(status);
}
/*#################################################################
### RECINPLC_AllocateRAT
###
### DESCRIPTION:
### This function will allocate a Reallocate table and
### return its header and data location within the obj_info
### structure.
###
### PARAMETERS:
### obj_info_ptr - IN: Nothing.
### - OUT: The location of the new RAT and its header.
###
### 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 RECINPLC_AllocateRAT(HDR_SearchInfoPtr obj_info_ptr, BOOLEAN restart)
{
ERR_CODE status;
/* Table uses reclaim space reserves, so there must be space available */
obj_info_ptr->HeaderPtr->Attr8 =
HDR_SetReliableAttr(obj_info_ptr->HeaderPtr->Attr8, HDR_HA_NonReliable);
obj_info_ptr->HeaderPtr->Attr8 =
HDR_SetReservesAttr(obj_info_ptr->HeaderPtr->Attr8, HDR_HA_NoReserves);
obj_info_ptr->HeaderPtr->Attr16 =
HDR_SetAlignmentAttr(obj_info_ptr->HeaderPtr->Attr16, HDR_HA_AlignPara);
obj_info_ptr->HeaderPtr->Attr16 = (UINT16)
HDR_SetPrivilegeAttr(obj_info_ptr->HeaderPtr->Attr16, 0);
obj_info_ptr->HeaderPtr->Attr16 =
HDR_SetStatusAttr(obj_info_ptr->HeaderPtr->Attr16, HDR_HA_Valid);
obj_info_ptr->HeaderPtr->Attr16 =
HDR_SetAbsorbedAttr(obj_info_ptr->HeaderPtr->Attr16, HDR_HA_Exists);
HDR_SetObjectSize(obj_info_ptr->HeaderPtr,
RECINPLC_ReAllocateTableSize/FDI_ParagraphLength);
obj_info_ptr->HeaderPtr->NameSize = 0;
obj_info_ptr->HeaderPtr->ObjectType = FDI_HT_ReAllocateTable;
obj_info_ptr->HeaderPtr->SecurityKey = 0;
/* Write the header to flash */
status = HDR_CreateHeaderEntry(&obj_info_ptr->CurrObj.HeaderAddress,
obj_info_ptr->HeaderPtr);
obj_info_ptr->CurrObj.ObjectSize = RECINPLC_ReAllocateTableSize;
obj_info_ptr->CurrObj.ObjectAddress = obj_info_ptr->CurrObj.HeaderAddress -
obj_info_ptr->CurrObj.ObjectSize;
if (status)
{
return(status);
}
status = HDR_CalcMemoryStatistics(restart);
return(status);
}
/*#################################################################
### RECINPLC_InitRAT
###
### DESCRIPTION:
### This function will initialize the RAT described by the
### table_info structure with data from obj_info structure.
###
### PARAMETERS:
### table_info_ptr - IN: Correct table_info object address.
### - OUT: No change.
### obj_info_ptr - IN: Correct object size and start address
### to be loaded into the RAT
###
### RETURNS:
### When this function passes with no errors a value of 0 is
### returned otherwise, it returns a status of type ERR_CODE.
###*/
/* E.5.0.652 Begin */
ERR_CODE RECINPLC_InitRAT(HDR_SearchInfo *table_info_ptr,
HDR_SearchInfo *obj_info_ptr )
/* E.5.0.652 End */
{
UINT16 unique_id = 0xF0F0;
ERR_CODE status;
FDI_Handle table_handle;
table_handle = table_info_ptr->CurrObj.ObjectAddress;
/* Write Bottom Entry */
RECINPLC_BottomSectionAddr = obj_info_ptr->CurrObj.ObjectAddress;
status = FLASH_WriteBuffer((table_handle + RECINPLC_OffsetToBottomAddress),
(MemBufferPtr)(& RECINPLC_BottomSectionAddr),
sizeof(RECINPLC_BottomSectionAddr));
if (status)
{
return(status);
}
/* Write Top Entry */
RECINPLC_TopSectionAddr = obj_info_ptr->CurrObj.ObjectAddress +
obj_info_ptr->CurrObj.ObjectSize;
status = FLASH_WriteBuffer((table_handle + RECINPLC_OffsetToTopAddress),
(MemBufferPtr)(&RECINPLC_TopSectionAddr),
sizeof(RECINPLC_TopSectionAddr));
if (status)
{
return(status);
}
/* Write Unique Id 2 */
status = FLASH_WriteBuffer((table_handle + RECINPLC_OffsetToUniqueId2),
(MemBufferPtr)(&unique_id), sizeof(unique_id));
if (status)
{
return(status);
}
/* Write Unique Id 1 */
status = FLASH_WriteBuffer((table_handle + RECINPLC_OffsetToUniqueId1),
(MemBufferPtr)(&unique_id), sizeof(unique_id));
return(status);
}
/*#################################################################
### RECINPLC_ProcessBlock
###
### DESCRIPTION:
### This function will process the blocks for reclaim in place,
### and mark each step within the RAT as necessary.
###
### PARAMETERS:
### table_base_addr - Handle to the RAT base address.
### start_addr_in_block - Handle to the start address within
### the block to be processed.
### end_addr_in_block - Handle to the end address within
### the block to be processed.
### rip_restart_state - The starting point to process the block
### for the purpose of restarting.
###
### 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 RECINPLC_ProcessBlock(FDI_Handle table_base_addr,
FDI_Handle start_addr_in_block,
FDI_Handle end_addr_in_block,
RECINPLC_RestartStates rip_restart_state)
{
UINT32 block; /*Block currently being processed */
BOOLEAN RAT_in_block = FALSE; /*Indicates if RAT in block */
BOOLEAN in_top_block = FALSE; /*Indicates if block is in top block */
BOOLEAN in_bottom_block = FALSE; /*Indicates if block is in bottom block */
BOOLEAN in_middle_block = FALSE; /*Indicates if block is a middle block */
FDI_Handle block_status_handle; /*Handle to the status in RAT */
ERR_CODE status; /*Return status */
FDI_Handle block_status_handle_rb, /*Handle to RAT status in reclaim block */
block_status_handle_ht, /*Handle to RAT status in header table */
top_data_size, /*Total bytes from top address to */
/* upper block boundary */
bottom_data_size, /*Total bytes from lower block boundary */
/* to the bottom address */
start_handle_ht, /*Base address for copying bottom section*/
/* in the header table block */
start_handle_rb, /*Base address for copying bottom section*/
/* in the reclaim block */
end_handle_ht, /*Base address for copying top section */
/* in header table block */
end_handle_rb; /*Base address for copying top section */
/* in reclaim block */
#ifdef ENABLE_EVENT_TESTS
#ifdef DISABLE_RECINPLC_FLASH_FAIL
EVT_EventElement tmp_event_value;
#endif
#endif
UINT16 unique_id = 0x0000; /*Invalid Id state */
UINT8 table_entry = 0xFF; /*Table entry for marking the status */
/* Determine Initial States of boolean variables */
block = Handle2Block(start_addr_in_block);
if (block == Handle2Block(table_base_addr))
{
RAT_in_block = TRUE;
}
if (block == Handle2Block(RECINPLC_BottomSectionAddr))
{
in_bottom_block = TRUE;
}
if (block == Handle2Block(RECINPLC_TopSectionAddr))
{
in_top_block = TRUE;
}
if (!in_bottom_block && !in_top_block)
{
in_middle_block = TRUE;
}
if (in_bottom_block)
{
block_status_handle_ht = table_base_addr +
RECINPLC_OffsetToBottomStatus;
}
else
{
block_status_handle_ht = table_base_addr + RECINPLC_OffsetToTopStatus;
}
block_status_handle_rb = (block_status_handle_ht -
BlockAlign(block_status_handle_ht)) +
FDI_ReclaimBlockAddress;
/* Determine initial values of address variables */
start_handle_ht = BlockAlign(start_addr_in_block);
start_handle_rb = FDI_ReclaimBlockAddress;
top_data_size = RoundUp(end_addr_in_block, FDI_BlockSize) -
end_addr_in_block;
bottom_data_size = start_addr_in_block - start_handle_ht;
end_handle_ht = end_addr_in_block;
end_handle_rb = FDI_ReclaimBlockAddress +
FDI_BlockSize - top_data_size;
if (RAT_in_block)
{
/* Use RAT in RB */
block_status_handle = block_status_handle_rb;
}
else
{
/* Use RAT in Header block */
block_status_handle = block_status_handle_ht;
}
switch (rip_restart_state)
{
case RECINPLC_STEP_NoRestart:
case RECINPLC_STEP_MiddleSection:
case RECINPLC_STEP_TopSection_RecoveryState1:
case RECINPLC_STEP_BottomSection_RecoveryState1:
#ifdef ENABLE_REALLOCATE_TESTS
EVT_TestEvent(EVT_RECINPLC_ProcessBlockState1);
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?