📄 flash.c
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
Module Name:
flash.c
Abstract:
Functions for accessing flash device
On CEPC, "flash" is our RAM XIP area
Simulate a flash device
--*/
#include <windows.h>
#include "xipflash.h"
// simulated flash params
// these are fixup vars
DWORD dwFlashStart = (DWORD)-1;
DWORD dwFlashLen = (DWORD)-1;
DWORD dwFlashBlkSize= (DWORD)-1;
DWORD dwFlashBlkBits= (DWORD)-1;
// **************************************************************************
//
// Function Name: IsFlash
//
// Purpose: determines if address range is in flash
//
// Arguments:
// IN pvStartAddr starting address of range
// IN dwLength length, ie. pvStartAddr + dwLength = end address
//
// Return Values:
//
// TRUE if the whole range is in flash, FALSE if not
//
BOOL
WINAPI
IsFlash(
LPVOID pvStartAddr,
DWORD dwPhysLen
)
{
return FALSE;
}
// **************************************************************************
//
// Function Name: FlashInit
//
// Purpose: initializes or deinitializes resources for flash routines
//
// Arguments:
// IN bInit TRUE- initialize, FALSE- deinitialize
//
// Return Values:
//
// ERROR_SUCCESS
// ERROR_OUTOFMEMORY can't allocate memory for flash functions
//
// Side effects:
// On successful init, the global flash function pointers are set
// On successful deinit, they are NULL
//
// Description:
//
// When initializing, you MUST allocate memory in RAM and copy into it
// any functions that take the flash out of READ ARRAY mode, because
// eXecute In Place from flash when it is out of READ ARRAY mode is not allowed.
// When uninitializing, it is recommended that you release the memory.
//
// Any other init is platform dependent.
//
DWORD
WINAPI
FlashInit(
BOOL bInit
)
{
//
// this is a RAM-only platform, just verify our flash params
//
if ( dwFlashStart == (DWORD)-1 ||
dwFlashLen == (DWORD)-1 ||
dwFlashBlkSize == (DWORD)-1 )
{
return ERROR_NOT_SUPPORTED;
}
return ERROR_SUCCESS;
}
// **************************************************************************
//
// Function Name: FlashErase
//
// Purpose: erases blocks of flash memory
//
// Arguments:
// IN pvStartAddr start address to erase
// IN dwLength length of region to erase
//
// Return Values:
//
// ERROR_SUCCESS
// ERROR_NOT_READY FlashInit(TRUE) was not called
// non-zero error from flash XX
//
//
// Side effects:
// If the region is not flash block aligned, memory outside of the
// region will be erased because the erase operations on block granularity.
//
// Description:
//
// This function will calculate the blocks needed to be erased
// and call the function in RAM to erase them.
//
DWORD
WINAPI
FlashErase(
LPVOID pvStartAddr,
DWORD dwLength
)
{
DWORD dwStartBlock = ((DWORD)pvStartAddr / dwFlashBlkSize) * dwFlashBlkSize;
while ( dwStartBlock < (DWORD)pvStartAddr + dwLength )
{
memset((LPVOID)dwStartBlock, 0xFF, dwFlashBlkSize);
dwStartBlock += dwFlashBlkSize;
}
return ERROR_SUCCESS;
}
// **************************************************************************
//
// Function Name: FlashWrite
//
// Purpose: writes data to flash memory
//
// Arguments:
// IN pvDestAddr dest address in flash
// IN dwLength amount of data to write
// IN pvSrcAddr src address of data
//
// Return Values:
//
// ERROR_SUCCESS
// ERROR_NOT_READY FlashInit(TRUE) wasn't called
// ERROR_INVALID_PARAMETER data not aligned or bad pointer
// ERROR_INVALID_DATA data verification check failed
// non-zero error from flash device, indicates failure XX
//
// Description:
//
// Write the data write function in RAM. Data is in DWORD units.
//
// NOTE BENE: pvDestAddr and pvSrcAddr must be DWORD aligned
//
DWORD
WINAPI
FlashWrite(
LPVOID pvDestAddr,
LPVOID pvSrcAddr,
DWORD dwLength
)
{
memcpy(pvDestAddr, pvSrcAddr, dwLength);
return ERROR_SUCCESS;
}
DWORD
WINAPI
FlashGetBlockInfo(
LPVOID pvStartAddr,
DWORD * pdwBlockStart,
DWORD * pdwBlockLen
)
{
*pdwBlockStart = ((DWORD)pvStartAddr / dwFlashBlkSize) * dwFlashBlkSize;
*pdwBlockLen = dwFlashBlkSize;
return ERROR_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -