fmd.c
来自「Windows CE 6.0 BSP for VOIP sample phone」· C语言 代码 · 共 850 行 · 第 1/2 页
C
850 行
pLayoutSector = pAddress;
break;
}
// Multiply by two
sectorSize <<= 1;
}
// Did we find flash layout sector?
if (pLayoutSector != NULL)
{
// Update sector size
s_fmd.sectorSize = sectorSize;
break;
}
// Move to next sector and check for region table
pAddress += s_fmd.sectorSize;
}
if (pLayoutSector == 0)
{
OALMSG(OAL_ERROR, (L"ERROR: FMD_Init: "
L"Failed find flash layout sector\r\n"
));
}
// Read flash layout sector and make local copy...
if (!BuildLayoutInfo(pLayoutSector))
{
OALMSG(OAL_ERROR, (L"ERROR: FMD_Init: "
L"Failed build flash layout info\r\n"
));
goto cleanUp;
}
// Done
hFMD = &s_fmd;
cleanUp:
if (hFMD == NULL) FMD_Deinit(&s_fmd);
return hFMD;
}
//------------------------------------------------------------------------------
//
// Function: FMD_Deinit
//
BOOL
FMD_Deinit(
VOID *pContext
)
{
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: FMD_GetInfo
//
BOOL
FMD_GetInfo(
FlashInfo *pInfo
)
{
pInfo->flashType = NOR;
pInfo->dwNumBlocks = s_fmd.blocks;
pInfo->dwBytesPerBlock = s_fmd.blockSize;
pInfo->wDataBytesPerSector = (WORD)s_fmd.sectorSize;
pInfo->wSectorsPerBlock = (WORD)s_fmd.region[0].dwSectorsPerBlock;
return TRUE;
}
//------------------------------------------------------------------------------
//
// Function: FMD_GetInfoEx
//
BOOL
FMD_GetInfoEx(
FlashInfoEx *pInfo,
DWORD *pRegions
)
{
BOOL rc = FALSE;
if (pRegions == NULL) goto cleanUp;
if (pInfo == NULL)
{
// Return required buffer size to caller
*pRegions = s_fmd.regions;
rc = TRUE;
goto cleanUp;
}
if (*pRegions < s_fmd.regions)
{
goto cleanUp;
}
// Copy region table
PREFAST_SUPPRESS(386, "Warning is result of API");
memcpy(pInfo->region, s_fmd.region, s_fmd.regions * sizeof(FlashRegion));
*pRegions = s_fmd.regions;
pInfo->cbSize = sizeof(FlashInfoEx);
pInfo->flashType = NOR;
pInfo->dwNumBlocks = s_fmd.blocks;
pInfo->dwDataBytesPerSector = (WORD)s_fmd.sectorSize;
pInfo->dwNumRegions = s_fmd.regions;
rc = TRUE;
cleanUp:
return rc;
}
//------------------------------------------------------------------------------
//
// Function: FMD_GetPhysSectorAddr
//
VOID
FMD_GetPhysSectorAddr(
SECTOR_ADDR sector,
DWORD *pSector
)
{
VOID *pInfo;
GetSectorAddresses(sector, &pSector, &pInfo);
}
//------------------------------------------------------------------------------
//
// Function: FMD_ReadSector
//
BOOL
FMD_ReadSector(
SECTOR_ADDR sector,
UCHAR *pBuffer,
SectorInfo *pSectorInfo,
DWORD sectors
)
{
BOOL rc = FALSE;
VOID *pSector;
VOID *pInfo;
if (sectors == 0 || ((pBuffer == NULL) && (pSectorInfo == NULL)))
{
OALMSG(OAL_ERROR, (L"ERROR: FMD_ReadSector: "
L"Invalid parameters (%d, 0x%08x, 0x%08x, %d)\r\n",
sector, pBuffer, pSectorInfo, sectors
));
goto cleanUp;
}
while (sectors-- > 0)
{
// Get sector and info location, NULL for sector means error
GetSectorAddresses(sector, &pSector, &pInfo);
if (pSector == NULL)
{
OALMSG(OAL_ERROR, (L"ERROR: FMD_ReadSector: "
L"Invalid sector number (%d)\r\n", sector
));
goto cleanUp;
}
// Read sector data
if (pBuffer != NULL)
{
memcpy(pBuffer, pSector, s_fmd.sectorSize);
pBuffer += s_fmd.sectorSize;
}
// Read sector info
if (pSectorInfo != NULL)
{
if (pInfo != NULL)
{
memcpy(pSectorInfo, pInfo, sizeof(SectorInfo));
}
else
{
memset(pSectorInfo, 0xff, sizeof(SectorInfo));
pSectorInfo->dwReserved1 = sector;
}
pSectorInfo++;
}
sector++;
}
rc = TRUE;
cleanUp:
ASSERT(rc);
return rc;
}
//------------------------------------------------------------------------------
//
// Function: FMD_WriteSector
//
BOOL
FMD_WriteSector(
SECTOR_ADDR sector,
UCHAR *pBuffer,
SectorInfo *pSectorInfo,
DWORD sectors
)
{
return FALSE;
}
//------------------------------------------------------------------------------
//
// Function: FMD_EraseBlock
//
BOOL
FMD_EraseBlock(
BLOCK_ID block
)
{
return FALSE;
}
//------------------------------------------------------------------------------
//
// Function: FMD_GetBlockStatus
//
DWORD FMD_GetBlockStatus(
BLOCK_ID block
)
{
DWORD status = 0;
ULONG region;
SECTOR_ADDR sector;
SectorInfo sectorInfo;
// First check for reserved block
for (region = 0; region < s_fmd.reservedRegions; region++)
{
ReservedEntry *pRegion = &s_fmd.reservedRegion[region];
if ( (block >= pRegion->dwStartBlock) &&
(block < (pRegion->dwStartBlock + pRegion->dwNumBlocks)) )
{
status = BLOCK_STATUS_RESERVED;
goto cleanUp;
}
}
// Now find block region
for (region = 0; region < s_fmd.regions; region++)
{
FlashRegion *pRegion = &s_fmd.region[region];
if ( (block >= pRegion->dwStartPhysBlock) &&
(block < (pRegion->dwStartPhysBlock + pRegion->dwNumPhysBlocks)) )
{
break;
}
}
// If we don't find it return error
if (region >= s_fmd.regions)
{
status = BLOCK_STATUS_UNKNOWN;
goto cleanUp;
}
// Get first block sector number
sector = s_fmd.firstSector[region] +
(block - s_fmd.region[region].dwStartPhysBlock) *
s_fmd.region[region].dwSectorsPerBlock;
// Read sector info
if (!FMD_ReadSector(sector, NULL, §orInfo, 1))
{
status = BLOCK_STATUS_UNKNOWN;
goto cleanUp;
}
// Note that we invert status bit
if ((sectorInfo.bOEMReserved & OEM_BLOCK_RESERVED) == 0)
{
status |= BLOCK_STATUS_RESERVED;
}
cleanUp:
return status;
}
//------------------------------------------------------------------------------
BOOL
FMD_SetBlockStatus(
BLOCK_ID block, DWORD status
)
{
return FALSE;
}
//------------------------------------------------------------------------------
//
// Function: FMD_PowerUp
//
VOID
FMD_PowerUp(
VOID
)
{
}
//------------------------------------------------------------------------------
//
// Function: FMD_PowerDown
//
VOID
FMD_PowerDown(
VOID
)
{
}
//------------------------------------------------------------------------------
BOOL
FMD_OEMIoControl(
DWORD code,
UCHAR *pInBuffer,
DWORD inSize,
UCHAR *pOutBuffer,
DWORD outSize,
DWORD *pOutSize
)
{
BOOL rc = TRUE;
switch(code)
{
case IOCTL_FMD_GET_INTERFACE:
{
FMDInterface *pInterface = (FMDInterface*)pOutBuffer;
if (pOutSize != NULL) *pOutSize = sizeof(FMDInterface);
if ((pOutBuffer == NULL) || (outSize < sizeof(FMDInterface)))
{
rc = FALSE;
break;
}
pInterface->cbSize = sizeof(FMDInterface);
pInterface->pInit = FMD_Init;
pInterface->pDeInit = FMD_Deinit;
pInterface->pGetInfo = FMD_GetInfo;
pInterface->pGetInfoEx = FMD_GetInfoEx;
pInterface->pGetBlockStatus = FMD_GetBlockStatus;
pInterface->pSetBlockStatus = FMD_SetBlockStatus;
pInterface->pReadSector = FMD_ReadSector;
pInterface->pWriteSector = FMD_WriteSector;
pInterface->pEraseBlock = FMD_EraseBlock;
pInterface->pPowerUp = FMD_PowerUp;
pInterface->pPowerDown = FMD_PowerDown;
pInterface->pGetPhysSectorAddr = FMD_GetPhysSectorAddr;
pInterface->pOEMIoControl = FMD_OEMIoControl;
}
break;
case IOCTL_FMD_GET_RESERVED_TABLE:
{
ULONG regions = s_fmd.reservedRegions;
ULONG size;
if (regions > dimof(s_fmd.reservedRegion))
{
regions = dimof(s_fmd.reservedRegion);
}
size = regions * sizeof(ReservedEntry);
if (pOutSize != NULL) *pOutSize = size;
if ((pOutBuffer == NULL) || (outSize < size))
{
rc = FALSE;
break;
}
memcpy(pOutBuffer, s_fmd.reservedRegion, size);
}
break;
case IOCTL_FMD_GET_RAW_BLOCK_SIZE:
if (pOutSize != NULL) *pOutSize = sizeof(DWORD);
if ((pOutBuffer == NULL) || (outSize < sizeof(DWORD)))
{
rc = FALSE;
break;
}
*((DWORD*)pOutBuffer) = s_fmd.blockSize;
break;
case IOCTL_FMD_GET_INFO:
{
FMDInfo *pInfo = (FMDInfo*)pOutBuffer;
if ((pOutBuffer == NULL) || (outSize < sizeof(FMDInfo)))
{
rc = FALSE;
break;
}
pInfo->flashType = NOR;
pInfo->dwBaseAddress = s_fmd.memBase;
pInfo->dwNumRegions = s_fmd.regions;
pInfo->dwNumReserved = s_fmd.reservedRegions;
}
break;
default:
rc = FALSE;
break;
}
return rc;
}
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?