📄 davflash.c
字号:
/* Copyright (c) 1995-2002 Intel Corporation */
/* Intel Confidential */
/* ###########################################################################
### FLASH
###
### Module: flash.c - Flash module for daVinci BIOS
###
### $Workfile: davflash.c $
### $Revision: 78 $
### $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.
*****************************************************************
*/
#define CURRENT_FILE_BEING_COMPILED DAV_FLASH
/*### Include Files
//#########################*/
#include "davtpdef.h"
#include "davflash.h"
#include "fdi_mutx.h"
/* E.5.0.690 Begin */
/*add fdi_lowl.h */
#include "fdi_lowl.h"
/* E.5.0.690 End */
#if (DIRECT_ACCESS_VOLUME == TRUE)
/*### Local Declarations
//#########################*/
/**************************************************************************
* 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.
*
**************************************************************************/
static BOOLEAN CompatibilityCheckPassed = TRUE;
/********************************************************************
* END OF COMPATIBILITY MODULE * END OF COMPATIBILITY MODULE *
*******************************************************************/
/*### Global Declarations
//#########################*/
/* This struct will hold the correct environment
* values and can be reloaded into the users
* struct if their values become corrupted.
*/
FLASH_Info FLASH_InitInfo;
BOOLEAN InitializationComplete = FALSE;
extern SEM_MTX_ID SEM_FlashWrite;
/* Moved from DavInit.c */
SEM_MTX_ID SEM_DAVReclLock;
SEM_ID SEM_DAVReclRequest;
SEM_MTX_ID SEM_DAVAPILock;
/*### Local Functions
//#########################*/
void ZeroFlashInfo(FLASH_InfoPtr flash_info_ptr)
{
flash_info_ptr->FlashBase = 0;
flash_info_ptr->TotalBlocks = 0;
flash_info_ptr->UserFlashBase = 0;
flash_info_ptr->UserTotalBlocks = 0;
flash_info_ptr->TotalChips = 0;
flash_info_ptr->ChipSize = 0;
flash_info_ptr->BlockSize = 0;
flash_info_ptr->DeviceId = 0;
}
BOOLEAN ValidSystemRange(UINT32 address, UINT32 total_bytes)
{
/* Check for 32-bit roll-over */
if ((address + total_bytes - 1) < FLASH_InitInfo.FlashBase)
{
return FALSE;
}
return TRUE;
}
BOOLEAN ValidUserRange(UINT32 address, UINT32 total_bytes)
{
UINT32 total_system_bytes;
total_system_bytes = FLASH_InitInfo.UserTotalBlocks *
FLASH_InitInfo.BlockSize;
/* Make sure that the requested physical address is within range
* of the physical base address and total bytes returned by
* the interface.
*/
if ((address < FLASH_InitInfo.FlashBase) ||
(address > FLASH_InitInfo.UserFlashBase +
total_system_bytes - 1))
{
return FALSE;
}
/* Check for 32-bit roll-over */
if ((address + total_bytes - 1) < FLASH_InitInfo.UserFlashBase)
{
return FALSE;
}
return TRUE;
}
/*### 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -