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

📄 main.c

📁 Xcale270Bsp包,wince平台
💻 C
📖 第 1 页 / 共 5 页
字号:
{
    int retries = 0;

    // Let's be persistant here
    while (retries++ < 4)
    {
        if (!pfnEDbgSendFrame(pData, dwLength))
            return TRUE;
        EdbgOutputDebugString("!OEMEthSendFrame failure, retry %u\n",retries);
    }
    return FALSE;
}

/* OEMEthGetSecs
 *
 *  Return a count of seconds from some arbitrary time (the absolute value is not important,
 *  so long as it increments appropriately).
 */
DWORD OEMEthGetSecs(  )
{

    SYSTEMTIME st;
    OEMGetRealTime( &st );

    return((60UL * (60UL * (24UL * (31UL * st.wMonth + st.wDay) + st.wHour) + st.wMinute)) + st.wSecond);
}


VOID SC_WriteDebugLED(WORD wIndex, DWORD dwPattern) 
{

}

void WINAPIV NKDbgPrintfW(LPCWSTR lpszFmt, ...)  
{

}

int StoreEBootCFG(EBOOTCFG *EBootCFG)
{
    volatile DWORD * pdwFlash;
    DWORD *pCFG;
    int i,j,k;

    j = sizeof(EBOOTCFG) / 4;

    pdwFlash    = (volatile DWORD *)(FLASH_CFG_START); 

    // Erase the EBootCFG block
    FlashErase((DWORD)pdwFlash, 128*1024);  

    pCFG = (DWORD *)EBootCFG;

    // Program the contents of EBOOTCFG one DWORD at a time.
    for (i = 0; i < j; i++)
    {

        *pdwFlash = 0x00400040;
        *pdwFlash = *(DWORD *)(pCFG+i);
        k = 0;
        while ((k & 0x00800080) != 0x00800080)
        {
            k = (*pdwFlash);
        }
        if (k & 0x00000008)
            EdbgOutputDebugString("Voltage Range Error ... \r\n");

        if (k & 0x00000002)
            EdbgOutputDebugString("Device Protect Error ... \r\n");

        if (k & 0x00000010)
            EdbgOutputDebugString("Programming Error ... \r\n");

        pdwFlash++;

    }
    // Put flash back into read mode.
    *pdwFlash = 0x00FF00FF;
    return 0;
}

int LoadEBootCFG(EBOOTCFG *EBootCFG)
{
    volatile DWORD * pdwFlash;
    DWORD *pCFG;
    DWORD i,j;

    j = sizeof(EBOOTCFG)/4;
    pdwFlash    = (volatile DWORD *)(FLASH_CFG_START);
    pCFG = (DWORD *)EBootCFG;

    // Read the contents of Flash into EBOOTCFG one DWORD at a time.
    *pdwFlash = 0x00FF00FF;
    for (i = 0; i < j; i++)
    {
        *(DWORD *)(pCFG+i) = *(pdwFlash+i);
    }

    // Is the CFG data valid?  Check for the magic number that was written the last time
    // the CFG block was updated.  If Eboot has never been run, there will be no configuration
    // information, so the magic number will likely not be found.  In this case, setup the 
    // factory defaults and store them into Flash.
    if (EBootCFG->ConfigMagicNumber != EbootCFGMagicNumber)
    {
        ResetFactoryDefaultCFG(EBootCFG);
    }

    return 0;
}


int LoadFlashImage(DWORD dwPhysStart, DWORD dwPhysLen, DWORD dwLaunchAddr, EBOOTCFG *pEbootCFG)
{
    volatile DWORD * pdwStartRAM;
    volatile DWORD * pdwFlash;
    DWORD i;
    DWORD CRC;

    pdwStartRAM = (volatile DWORD *)dwPhysStart;
    pdwFlash    = (volatile DWORD *)(FLASH_BIN_START);

    EdbgOutputDebugString("dwPhysStart = 0x%x dwPhysLen = 0x%x dwLaunchAddr = 0x%x\r\n", dwPhysStart, dwPhysLen, dwLaunchAddr);

    if ( *(pdwFlash+16) == 0x43454345 )
    {
        EdbgOutputDebugString("Found pTOC signature.\n");

        // Copy Flash image into RAM
        EdbgOutputDebugString("Copying FLASH image into RAM.\r\n");
        //memcpy((LPVOID)pdwStartRAM,(LPVOID)pdwFlash,dwPhysLen);
        pdwStartRAM = (volatile DWORD *)dwPhysStart;
        pdwFlash    = (volatile DWORD *)(FLASH_BIN_START);
        for (i = 0; i < dwPhysLen / 4; i++)
        {
            *pdwStartRAM = *pdwFlash;
            pdwStartRAM++;
            pdwFlash++;
        }

        EdbgOutputDebugString("Verifying RAM.\r\n");
        pdwStartRAM = (volatile DWORD *)dwPhysStart;
        pdwFlash    = (volatile DWORD *)(FLASH_BIN_START); 
        for (i = 0; i < dwPhysLen / 4; i++)
        {
            if (*pdwStartRAM++ != *pdwFlash++)
            {
                // We'd normally go ahead and download a new image at this point.
                EdbgOutputDebugString("Error verifying RAM.  Expected 0x%x got 0x%x.\r\n", *(pdwFlash-1), *(pdwStartRAM-1));
                return 1;
            }
        }


        EdbgOutputDebugString("Calculating CRC-32 on flash image... "); 
        CRC = crc32((unsigned char *)RAM_IMAGE_START, dwPhysLen);
        if (CRC != pEbootCFG->CRC)
        {
            EdbgOutputDebugString("CRC-32 comparison failure.\r\nCalculated CRC is 0x%x expected 0x%x\r\n",CRC, pEbootCFG->CRC);
            return 1;
        }

        EdbgOutputDebugString("CRC-32 matches stored value 0x%x.\r\n", CRC);
        EdbgOutputDebugString("RAM image is good.\r\n");

        return 0;
    }

    EdbgOutputDebugString("pTOC not found.. problem with RAM image.\r\n");
    return 1;
}


void ResetFactoryDefaultCFG(EBOOTCFG *pEbootCFG)
{
    EdbgOutputDebugString("\r\nResetting factory default configuration ... \r\n");
    pEbootCFG->autoDownloadImage = TRUE;
    pEbootCFG->IP = inet_addr("192.168.80.2"); 
    pEbootCFG->subnetMask = inet_addr("255.255.0.0"); 
    pEbootCFG->numBootMe = 25;
    pEbootCFG->delay = 5;
    pEbootCFG->DHCPEnable = TRUE;
    pEbootCFG->dwLaunchAddr = 0x98381000;
    pEbootCFG->dwPhysStart = 0;
    pEbootCFG->dwPhysLen = 0;
    pEbootCFG->bootDeviceOrder = 0;
    pEbootCFG->bWriteBINToFlash = FALSE;
    pEbootCFG->ConfigMagicNumber = EbootCFGMagicNumber;
    pEbootCFG->CRC = 0;
    memset((LPVOID)pDriverGlobals,0,sizeof(DRIVER_GLOBALS));
    pDriverGlobals->eth.EbootMagicNum = EBOOT_MAGIC_NUM;
    pDriverGlobals->uninit_misc.EbootDevice = BOOT_DEVICE_NONE;
    memcpy(&pEbootCFG->DriverGlobals, (LPVOID)pDriverGlobals, sizeof(DRIVER_GLOBALS));  
}

void SetIP(EBOOTCFG *pEbootCFG)
{
    char szDottedD[16]; // The string used to collect the dotted decimal IP address
    WORD cwNumChars = 0;
    UINT16 InChar = 0;

    EdbgOutputDebugString ( "\r\nEnter new IP address: ");

    while (!((InChar == 0x0d) || (InChar == 0x0a)))
    {
        InChar = OEMReadDebugByte();
        if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
        {
            // If it's a number or a period, add it to the string
            if (InChar == '.' || (InChar >= '0' && InChar <= '9'))
            {
                if (cwNumChars < 16)
                {
                    szDottedD[cwNumChars++] = (char)InChar;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
            // If it's a backspace, back up
            else if (InChar == 8)
            {
                if (cwNumChars > 0)
                {
                    cwNumChars--;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
        }
    }

    // If it's a carriage return with an empty string, don't change anything.
    if (cwNumChars)
    {
        szDottedD[cwNumChars] = '\0';
        pEbootCFG->IP = inet_addr( szDottedD );
    }
    ClearPromiscuousIP();                
}

void SetMask(EBOOTCFG *pEbootCFG)
{
    char szDottedD[16]; // The string used to collect the dotted masks
    WORD cwNumChars = 0;
    UINT16 InChar = 0;

    EdbgOutputDebugString ( "\r\nEnter new subnet mask: ");

    while (!((InChar == 0x0d) || (InChar == 0x0a)))
    {
        InChar = OEMReadDebugByte();
        if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
        {
            // If it's a number or a period, add it to the string
            if (InChar == '.' || (InChar >= '0' && InChar <= '9'))
            {
                if (cwNumChars < 16)
                {
                    szDottedD[cwNumChars++] = (char)InChar;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
            // If it's a backspace, back up
            else if (InChar == 8)
            {
                if (cwNumChars > 0)
                {
                    cwNumChars--;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
        }
    }

    // If it's a carriage return with an empty string, don't change anything.
    if (cwNumChars)
    {
        szDottedD[cwNumChars] = '\0';
        pEbootCFG->subnetMask = inet_addr( szDottedD );
    }
}
void SetBootMe(EBOOTCFG *pEbootCFG)
{
    char szCount[16];
    WORD cwNumChars = 0;
    UINT16 InChar = 0;

    EdbgOutputDebugString ( "\r\nUse 0 for continuous boot me packets. \r\n");
    EdbgOutputDebugString ( "Enter maximum number of boot me packets to send [0-255]: ");

    while (!((InChar == 0x0d) || (InChar == 0x0a)))
    {
        InChar = OEMReadDebugByte();
        if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
        {
            // If it's a number or a period, add it to the string
            if ((InChar >= '0' && InChar <= '9'))
            {
                if (cwNumChars < 16)
                {
                    szCount[cwNumChars++] = (char)InChar;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
            // If it's a backspace, back up
            else if (InChar == 8)
            {
                if (cwNumChars > 0)
                {
                    cwNumChars--;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
        }
    }

    // If it's a carriage return with an empty string, don't change anything.
    if (cwNumChars)
    {
        szCount[cwNumChars] = '\0';
        pEbootCFG->numBootMe = atoi(szCount);
        if (pEbootCFG->numBootMe > 255)
        {
            pEbootCFG->numBootMe = 255;
        }
        else if (pEbootCFG->numBootMe < 0)
        {
            pEbootCFG->numBootMe = 1;
        }
    }
}

void SetDelay(EBOOTCFG *pEbootCFG)
{
    char szCount[16];
    WORD cwNumChars = 0;
    UINT16 InChar = 0;

    EdbgOutputDebugString ( "\r\nEnter maximum number of seconds to delay [1-255]: ");

    while (!((InChar == 0x0d) || (InChar == 0x0a)))
    {
        InChar = OEMReadDebugByte();
        if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
        {
            // If it's a number or a period, add it to the string
            if ((InChar >= '0' && InChar <= '9'))
            {
                if (cwNumChars < 16)
                {
                    szCount[cwNumChars++] = (char)InChar;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
            // If it's a backspace, back up
            else if (InChar == 8)
            {
                if (cwNumChars > 0)
                {
                    cwNumChars--;
                    OEMWriteDebugByte((BYTE)InChar);

⌨️ 快捷键说明

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