⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash.c

📁 CIRRUS 93XX系列windows mobile 6.0 BSP
💻 C
📖 第 1 页 / 共 2 页
字号:
    //  
    // Hack hack hack.  Looks like eboot thinks that this is the wrong address.
    //
    else if((0x80000000  < dwAddr) &&  (dwAddr < 0x84000000 ))
    {
        pReturnValue = (LPBYTE)(dwAddr & 0x7FFFFFFF);
    }
    else
    {
		//SDRAM is mapped to 0x000, so just masking the highest byte to convert a physical address to virtual one.
		pReturnValue = (LPBYTE)(dwAddr & 0x0FFFFFFF);
    }
   
	return pReturnValue; 
}

//****************************************************************************
//  OEMStartEraseFlash
//****************************************************************************
//  dwStartAddr - Start address, in flash, to start erasing from. The 
//                platform loader code needs to ensure this is a flash 
//                block-aligned address or needs to handle it specially if 
//                it is not. 
//
//  dwLength    - Number of bytes of flash to be erased. 
//
//  return      TRUE indicates success. FALSE indicates failure.
//
BOOL OEMStartEraseFlash (DWORD dwStartAddr, DWORD dwLength)
{
    ULONG   i = 0;
    ULONG   nNumBlocks = 0;
    //
    // Make sure the start and end addresses are in flash.
    //
    if (!OEMIsFlashAddr(dwStartAddr) || !OEMIsFlashAddr(dwStartAddr + dwLength - 1))
    {
        EdbgOutputDebugString
        (
            "ERROR: OEMStartEraseFlash - not a flash address (0x%x or 0x%x).\r\n", 
            dwStartAddr, 
            (dwStartAddr + dwLength - 1)
        );
        return(FALSE);
    }
    if (dwLength & 0x03)
    {
        EdbgOutputDebugString
        (
            "ERROR: OEMStartEraseFlash - length isn't an integral number of longwords (0x%x).\r\n",
            dwLength
        );
        return(FALSE);
    }

    //
    // Make sure that the flash addresses are valid.
    //
    if(dwStartAddr + dwLength >FLASH_VIRTUAL_MEMORY + gdwFlashSize  || 
       dwStartAddr < FLASH_VIRTUAL_MEMORY )
    {
        EdbgOutputDebugString
        (
            "ERROR: No Flash located in the locations from %x (%x)len %x(%x)\r\n",
            dwStartAddr,
			FLASH_VIRTUAL_MEMORY,
            dwLength,
			gdwFlashSize
        );
        return FALSE;
    }

    EdbgOutputDebugString("Erasing flash blocks: start Addr = 0x%x  length = 0x%x\r\n", dwStartAddr, dwLength);

	if( !pfnStartErase ) {
		EdbgOutputDebugString("Error, NO Flash is defined,stop\r\n" );
		while(1);
	}
    return(pfnStartErase(dwStartAddr, dwLength));
}

//****************************************************************************
// OEMContinueEraseFlash
//****************************************************************************
// 
// 
//
void OEMContinueEraseFlash (void)
{

    if(pfnContinueErase)
        pfnContinueErase();
}

//****************************************************************************
//  OEMFinishEraseFlash
//****************************************************************************
// 
// 
//
BOOL OEMFinishEraseFlash (void)
{
    BOOL    bSuccess = FALSE;

    EdbgOutputDebugString("Continue to Erase the rest of Flash.\r\n" );

    //
    // Finish erasing the flash.
    //
    if(pfnFinishErase)
    {
       bSuccess = pfnFinishErase();
    }


    if(bSuccess)
    {
        EdbgOutputDebugString("\r\nFlash Erase Successfully Finished\r\n" );
    }
    else
    {
        EdbgOutputDebugString("\r\nERROR: Error while erasing flash\r\n" );
        
    }

    return bSuccess;
}

//****************************************************************************
// OEMWriteFlash
//****************************************************************************
//  dwStartAddr  -  Address in flash where the start of the downloaded image 
//                  is to be written. Note that if this is not a flash 
//                  block-aligned address, the platform code will need 
//                  to take this into account and handle it as a special
//                  case. 
//
//  dwLength     -  Length of the image, in bytes, to be written to flash. 
// 
//
BOOL OEMWriteFlash (DWORD dwStartAddr, DWORD dwLength)
{
    ULONG   ulSMC;
    ULONG   ulCount;
    BOOL    bSuccess = TRUE; 
#if EP93XX_FLASH_WIDTH==16
    PUSHORT  pulSource, pulDest;
#else
    PULONG  pulSource, pulDest;
#endif

    EdbgOutputDebugString("Writing to flash at Address= 0x%x, Length = 0x%x\r\n",dwStartAddr,dwLength  );
    //
    // Check to make sure that the flash routine exists.
    //
    if(!pfnWriteFlash)
    {
        bSuccess = FALSE;
    }

    //
    // Make sure the start and end addresses are in flash.
    //
    if(bSuccess)
    {
        if (!OEMIsFlashAddr(dwStartAddr) || !OEMIsFlashAddr(dwStartAddr + dwLength - 1))
        {
            EdbgOutputDebugString
            (
                "ERROR: OEMWriteFlash - not a flash address (0x%x or 0x%x).\r\n", 
                dwStartAddr, 
                (dwStartAddr + dwLength - 1)
            );
            bSuccess = FALSE;
        }
    }

    //
    // Perform a quick check to make sure that the flash is erased.
    //
if (1)
    {
#if EP93XX_FLASH_WIDTH==16
        pulDest    =(PUSHORT) dwStartAddr;
        for(ulCount = 0; ulCount < (dwLength>>1) ; ulCount++)
        {
            if(*pulDest != 0xFFFF)
            {
                EdbgOutputDebugString
                (
                    "ERROR: OEMWriteFlash - Flash not erased at location = 0x%x,  value = 0x%x \r\n",
                    (ULONG)pulDest,
                    *pulDest
                );
                bSuccess = FALSE;
                while(1);
                break;
            }
            pulDest++;
        } 
#else
        pulDest    =(PULONG) dwStartAddr;
        for(ulCount = 0; ulCount < (dwLength>>2) ; ulCount++)
        {
            if(*pulDest != 0xFFFFFFFF)
            {
                EdbgOutputDebugString
                (
                    "ERROR: OEMWriteFlash - Flash not erased at location = 0x%x,  value = 0x%x \r\n",
                    (ULONG)pulDest,
                    *pulDest
                );
                bSuccess = FALSE;
                while(1);
                break;
            }
            pulDest++;
        } 
#endif
    }


    //
    // Write the flash
    //
    if(pfnWriteFlash  && bSuccess)
    {
        bSuccess = pfnWriteFlash( dwStartAddr, FLASH_CACHE_VIRTUAL_MEMORY ,dwLength);
    }
    //
    // Clear the Flash write protect for chip select 6.
    //
//    ulSMC = *SMC_SMCBCR6;
//    *SMC_SMCBCR6 = ulSMC | SMCBCR_WP | SMCBCR_WPERR ;

    ulSMC = *FLASH_SMC;
    *FLASH_SMC = ulSMC | SMCBCR_WP | SMCBCR_WPERR ;
    //
    // Check to make sure that the image has been flashed correctly.
    //
    if(bSuccess)
    {
#if EP93XX_FLASH_WIDTH==16
        pulSource   = (PUSHORT) FLASH_CACHE_VIRTUAL_MEMORY;
        pulDest     = (PUSHORT) dwStartAddr;
        for(ulCount = 0; ulCount < (dwLength>>1) ; ulCount++)
        {
            if(*pulSource != *pulDest)
            {
                EdbgOutputDebugString
                (
                    "ERROR: OEMWriteFlash - Miscompare at pSource = 0x%x, pDest = 0x%x, 0x%x != 0x%x \r\n",
                    (ULONG)pulSource,
                    (ULONG)pulDest,
                    *pulSource,
                    *pulDest
                );
                bSuccess = FALSE;
                break;
            }
            pulSource++;
            pulDest++;
        } 
#else
        pulSource   = (PULONG) FLASH_CACHE_VIRTUAL_MEMORY;
        pulDest     = (PULONG) dwStartAddr;
        for(ulCount = 0; ulCount < (dwLength>>2) ; ulCount++)
        {
            if(*pulSource != *pulDest)
            {
                EdbgOutputDebugString
                (
                    "ERROR: OEMWriteFlash - Miscompare at pSource = 0x%x, pDest = 0x%x, 0x%x != 0x%x \r\n",
                    (ULONG)pulSource,
                    (ULONG)pulDest,
                    *pulSource,
                    *pulDest
                );
                bSuccess = FALSE;
                break;
            }
            pulSource++;
            pulDest++;
        } 
#endif
    }


    return bSuccess;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -