|
就是经常能见到的所谓的微软提供的代码里面:
比如:
- BOOL OEMWriteFlash(DWORD dwStartAddr, DWORD dwLength)
- {
- //EdbgOutputDebugString("OEMWriteFlash 0x%x 0x%x\r\n", dwStartAddr, dwLength);
- /* DWORD dwFlashAddr, dwExtraBytes = 0;
- LPBYTE pbCache = NULL;
- UCHAR nNumBlocks = 0;
- //确认起始地址和长度都在Flash区域内
- if(!OEMIsFlashAddr(dwStartAddr) || !OEMIsFlashAddr(dwStartAddr + dwLength - 1))
- {
- return(FALSE);
- }
- //确认起始地址是Block字节对齐的
- if (dwStartAddr % FLASH_BLOCK_SIZE)
- {
- return(FALSE);
- }
- //计算要写入的block数量
- nNumBlocks = (UCHAR) (dwLength/FLASH_BLOCK_SIZE);
- dwExtraBytes = (dwLength % FLASH_BLOCK_SIZE);
- dwFlashAddr = dwStartAddr;
- pbCache = OEMMapMemAddr (dwStartAddr, dwFlashAddr);
- //写Flash
- while(nNumBlocks)
- {
- if (CFI_Write_Block((DWORD*)dwFlashAddr, (DWORD*)pbCache, FLASH_BLOCK_SIZE, NULL) != PASS)
- {
- EdbgOutputDebugString("ERROR: OEMWriteFlash - unable to write to block (block address=0x%x).\r\n", dwFlashAddr);
- return(FALSE);
- }
- dwFlashAddr += FLASH_BLOCK_SIZE;
- pbCache = OEMMapMemAddr (dwStartAddr, dwFlashAddr);
- --nNumBlocks;
- }
- //将额外的数据写入Flash中
- if(dwExtraBytes)
- {
- if ([color=#FF0000]CFI_Write_Block[/color]((DWORD*)dwFlashAddr, (DWORD*)pbCache, dwExtraBytes, NULL) != PASS)
- {
- EdbgOutputDebugString("ERROR: OEMWriteFlash - unable to write to block (block address=0x%x).\r\n", dwFlashAddr);
- return(FALSE);
- }
- }
- */
- return TRUE;
- }
复制代码 |
|