📄 davflash.c
字号:
/*### Global Functions
//#########################*/
/**************************************************************************
* 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.
*
**************************************************************************/
/*#################################################################
### FLASH_CompatibilityCheck
###
### Purpose:
###
### Entry Environment:
###
### Exit Environment:
###
### Inputs:
###
### RETURNS:
###
*/
ERR_CODE FLASH_CompatibilityCheck(void)
{
if (CompatibilityCheckPassed)
{
return ERR_NONE;
}
return ERR_MEDIA_TYPE;
}
/********************************************************************
* END OF COMPATIBILITY MODULE * END OF COMPATIBILITY MODULE *
*******************************************************************/
/*#################################################################
### FLASH_IsAreaErased
###
### DESCRIPTION:
### This function checks the range specified by start_addr and
### end_addr to ensure that memory within the range is in an
### erased state.
###
### PARAMETERS:
### start_addr - The start address of the range to check
### end_addr - The end address of the range to check
###
### RETURNS:
### Returns a TRUE(1) if the range is in an erased state.
### otherwise a FALSE(0)
###
*/
BOOLEAN FLASH_IsAreaErased(UINT32 start_addr,
UINT32 end_addr)
{
UINT32 ii, jj;
UINT32 byte_count;
UINT32 read_count;
UINT32 remainder;
UINT32 dword_scan_buffer[64];
UINT8 byte_scan_buffer[256];
byte_count = (end_addr - start_addr);
read_count = byte_count / sizeof(dword_scan_buffer);
remainder = byte_count % sizeof(dword_scan_buffer);
/* Perform erase scan */
for (ii = 0; ii < read_count; ii++)
{
FLASH_ReadBuffer(start_addr + (ii * sizeof(dword_scan_buffer)),
(UINT8_PTR)(dword_scan_buffer),
sizeof(dword_scan_buffer));
for (jj = 0; jj < (sizeof(dword_scan_buffer) / 4); jj++)
{
if (dword_scan_buffer[jj] != 0xFFFFFFFF)
{
return FALSE;
}
}
}
if (remainder > 0)
{
FLASH_ReadBuffer(start_addr + (read_count * sizeof(dword_scan_buffer)),
(UINT8_PTR)(byte_scan_buffer), remainder);
for (jj = 0; jj < remainder; jj++)
{
if (byte_scan_buffer[jj] != 0xFF)
{
return FALSE;
}
}
}
return TRUE;
}
/*#################################################################
### FLASH_IsBlockErased
###
### Purpose:
### This function returns a true or false based on the status
### of the block at address. If the block is erased a true(1)
### will be returned, otherwise false(0)
###
### Entry Environment:
###
### Exit Environment:
###
### Inputs:
### addr32 - A virtual 32 bit address to flash.
###
### RETURNS:
### Returns a TRUE(1) if the block is in an erased state.
### otherwise a FALSE(0)
###
*/
BOOLEAN FLASH_IsBlockErased(UINT32 addr32)
{
/* Normalize the address to the bottom of the block */
addr32 = (addr32 / FLASH_InitInfo.BlockSize) *
FLASH_InitInfo.BlockSize;
return (FLASH_IsAreaErased((addr32),
(addr32 + FLASH_InitInfo.BlockSize - 1)));
}
/*#################################################################
### FLASH_InitRegion
###
### Purpose:
###
### Entry Environment:
###
### Exit Environment:
###
### Inputs:
###
### RETURNS:
###
*/
ERR_CODE FLASH_InitRegion(UINT32 total_bytes)
{
ERR_CODE status = ERR_NONE;
if (!InitializationComplete)
{
/* Initialize Flash info structure */
FLASH_InitInfo.FlashBase = FLASH_START_ADDRESS;
/* The total number of blocks, not the number of blocks used by DAV.
The number of blocks used by DAV is in FLASH_InitInfo.UserTotalBlocks */
/* This will take into account the situation where DAV blocks
are not adjacent to (or within the BOOT_BLOCKS) FDI blocks.
*/
FLASH_InitInfo.TotalBlocks = DAV_BLOCKCOUNT;
FLASH_InitInfo.BlockSize = DAV_BLOCK_SIZE;
/* These are not used */
FLASH_InitInfo.TotalChips = 1;
FLASH_InitInfo.ChipSize = DAV_BLOCK_SIZE * 32;
FLASH_InitInfo.DeviceId = 0x88C5;
/* User settings */
FLASH_InitInfo.UserFlashBase = DAV_START_ADDRESS;
FLASH_InitInfo.UserTotalBlocks = DAV_BLOCKCOUNT;
/* Calculate total_bytes, block aligned */
total_bytes = FLASH_InitInfo.TotalBlocks * FLASH_InitInfo.BlockSize;
}
/* Validate that the user has requested a valid range within
* the discovered flash memory space.
*/
if (!ValidSystemRange(FLASH_InitInfo.UserFlashBase, total_bytes))
{
status = ERR_PARAM;
}
/**************************************************************************
* 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.
*
**************************************************************************/
if (!status)
{
InitializationComplete = TRUE;
CompatibilityCheckPassed = TRUE;
return ERR_NONE;
}
/********************************************************************
* END OF COMPATIBILITY MODULE * END OF COMPATIBILITY MODULE *
*******************************************************************/
/* An error occured due to other circumstances,
* go ahead and close up the interface so we can
* start over.
*/
ZeroFlashInfo(&FLASH_InitInfo);
return status;
}
/*########################################################################
### FLASH_GetDeviceInfo
###
### Purpose:
### This function will load the appropriate default values into the
### user defined FLASH_Info structure.
###
### Entry Enviroment:
### N/A
###
### Exit Enviroment:
### N/A
###
### Input:
### none.
###
### Output:
### flash_info_ptr:
### FlashBase - default base address for the specific device.
###
### TotalBytes - default size of the flash device in bytes.
###
### BlockSize - default block size of the flash device.
###
### DeviceType - The device type that is defined during the
### build process.
###
*/
ERR_CODE FLASH_GetDeviceInfo(FLASH_InfoPtr flash_info_ptr)
{
UINT32 total_bytes = 0;
ERR_CODE status = ERR_NONE;
if (!InitializationComplete)
{
total_bytes = flash_info_ptr->TotalBlocks * FDV_BLOCK_SIZE;
status = FLASH_InitRegion(total_bytes);
if (status)
{
return status;
}
}
/* Copy the flash info to the users's structure. */
flash_info_ptr->UserFlashBase = FLASH_InitInfo.UserFlashBase;
flash_info_ptr->UserTotalBlocks = FLASH_InitInfo.UserTotalBlocks;
/* Note that the user does not see the actual flash base, only
* its requested.
*/
flash_info_ptr->FlashBase = FLASH_InitInfo.UserFlashBase;
flash_info_ptr->TotalBlocks = FLASH_InitInfo.UserTotalBlocks;
flash_info_ptr->TotalChips = FLASH_InitInfo.TotalChips;
flash_info_ptr->ChipSize = FLASH_InitInfo.ChipSize;
flash_info_ptr->BlockSize = FLASH_InitInfo.BlockSize;
flash_info_ptr->DeviceId = FLASH_InitInfo.DeviceId;
return ERR_NONE;
}
/*########################################################################
### FLASH_WriteBuffer
###
### Purpose:
### Copy information from a buffer in memory to a location in flash.
###
### Entry Enviroment:
### Flat32 Protected Mode, Memory Accessible
###
### Exit Enviroment:
### All flash must be in read array mode.
###
### Input:
### addr32 - Address of destination in flash.
###
### buffer_ptr - Pointer to a buffer in memory.
###
### byte_count - Number of bytes to write to flash from the buffer.
###
### Output:
### ERR_CODE - Upon completion of the function,
### Success - ERR_NONE
### Failure - Any of the following:
### ERR_SYSTEM, STD_InvalidParamater,
### FLASH_WriteFail, FLASH_VPPFail,
### FLASH_CmdSeqFail.
###
*/
ERR_CODE FLASH_WriteBuffer(UINT32 addr32,
UINT8_PTR buffer_ptr,
UINT32 byte_count)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -