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

📄 main.c

📁 Lido PXA270平台开发板的最新BSP,包括源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
//  Function:  OEMLaunch
//
//  Launch downloaded/stored image.
//
void OEMLaunch(DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr, const ROMHDR *pRomHdr)
{
    EDBG_OS_CONFIG_DATA *pCfgData;
    EDBG_ADDR EshellHostAddr;
    UINT32 PhysAddress;


    // If a launch address wasn't specified - use the last known good address.
    //
    if (!dwLaunchAddr)
    {
        dwLaunchAddr = g_EbootCFG.dwLaunchAddr;
    }
    else
    {
        if (g_EbootCFG.dwLaunchAddr != dwLaunchAddr ||
            g_EbootCFG.dwPhysStart  != dwImageStart ||
            g_EbootCFG.dwPhysLen    != dwImageLength)
        {
            g_EbootCFG.dwLaunchAddr = dwLaunchAddr;
            g_EbootCFG.dwPhysStart  = dwImageStart;
            g_EbootCFG.dwPhysLen    = dwImageLength;
            g_EbootCFG.dwStoreAddr  = 0;

	    if(OEMIsFlashAddr(dwLaunchAddr))
            	StoreEBootCFG(&g_EbootCFG);
        }
    }

    // Translate the image start address (virtual address) to a physical address.
    //
    PhysAddress = (UINT32) OALVAtoPA((VOID *)dwLaunchAddr);
    EdbgOutputDebugString("Download successful!  Jumping to image at 0x%x (physical 0x%x)...\r\n", dwLaunchAddr, PhysAddress);

    // Wait for PB connection...
    //
    if (g_DownloadImage)
    {
        if (!(pCfgData = EbootWaitForHostConnect(&g_DeviceAddr, &EshellHostAddr)))
        {
            EdbgOutputDebugString("ERROR: EbootWaitForHostConnect failed!\r\n");
            SpinForever();
        }

        // If the user selected "passive" KITL (i.e., don't connect to the target at boot time), set the
        // flag in the args structure so the OS image can honor it when it boots.
        //
        if (pCfgData && (pCfgData->KitlTransport & KTS_PASSIVE_MODE))
        {
            g_pBSPArgs->kitl.flags |= OAL_KITL_FLAGS_PASSIVE;
        }
    }


    // Jump to the image we just downloaded.
    //
    EdbgOutputDebugString("\r\n\r\n\r\n");
    Launch(PhysAddress);

    // Should never get here...
    //
    SpinForever();

}


//------------------------------------------------------------------------------
//
//  Function:  StoreEBootCFG
//
//  Stores bootloader configuration information (menu settings, etc.) in flash.
//
static BOOL StoreEBootCFG(EBOOT_CFG *EBootCFG)
{

    if (!FlashWrite(EBOOT_FLASH_CFG_START, (PUCHAR)EBootCFG, sizeof(EBOOT_CFG)))
    {
        EdbgOutputDebugString("ERROR: StoreEBootCFG: failed to write configuration.\r\n");
        return(FALSE);
    }

    return(TRUE);
}


//------------------------------------------------------------------------------
//
//  Function:  ResetDefaultEBootCFG
//
//  Resets the debug bootloader configuration information (menu settings, etc.).
//
static void ResetDefaultEBootCFG(EBOOT_CFG *pEbootCFG)
{

    EdbgOutputDebugString("\r\nResetting factory default configuration...\r\n");

    pEbootCFG->autoDownloadImage = TRUE;
    pEbootCFG->IP                = inet_addr("192.168.0.6"); 
    pEbootCFG->subnetMask        = inet_addr("255.255.255.0"); 
    pEbootCFG->numBootMe         = 50;
    pEbootCFG->delay             = 3;
    pEbootCFG->DHCPEnable        = FALSE;
    pEbootCFG->dwLaunchAddr      = 0;
    pEbootCFG->dwPhysStart       = 0;
    pEbootCFG->dwPhysLen         = 0;
    pEbootCFG->bootDeviceOrder   = 0;
    pEbootCFG->dwDbgSerPhysAddr  = BULVERDE_BASE_REG_PA_FFUART;
    pEbootCFG->dwStoreAddr       = 0;
    pEbootCFG->CheckSignatures   = FALSE;
    pEbootCFG->ConfigMagicNumber = EBOOT_CFG_MAGIC_NUMBER;

}


//------------------------------------------------------------------------------
//
//  Function:  LoadEBootCFG
//
//  Retrieves bootloader configuration information (menu settings, etc.) from flash.
//
static BOOL LoadEBootCFG(EBOOT_CFG *EBootCFG)
{

    if (!FlashRead(EBOOT_FLASH_CFG_START, (PUCHAR)EBootCFG, sizeof(EBOOT_CFG)))
    {
        EdbgOutputDebugString("ERROR: LoadEBootCFG: failed to load configuration.\r\n");
        return(FALSE);
    }

    // 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 != EBOOT_CFG_MAGIC_NUMBER)
    {
        ResetDefaultEBootCFG(EBootCFG);
    }

    // Make sure a valid debug serial port address (physical) was found.
    //
    if (g_EbootCFG.dwDbgSerPhysAddr == 0)
    {
        g_EbootCFG.dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_FFUART;
    }

    return(TRUE);
}


static void SetIP(EBOOT_CFG *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 );
    }
}

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

    EdbgOutputDebugString ( "\r\nEnter new MAC 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 < 23)
                {
                    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';
        CvtMAC( szDottedD );

        setMAC_Address(&g_pBSPArgs->kitl);
    }
}

static void CvtMAC(char *pszDottedD ) 
{
    DWORD cBytes;
    char *pszLastNum;
    int atoi (const char *s);
    int i=0;    
    BYTE *p = (BYTE *)g_pBSPArgs->kitl.mac;

    // Replace the dots with NULL terminators
    pszLastNum = pszDottedD;
    for( cBytes = 0; cBytes < 6; cBytes++ ) {
        while(*pszDottedD != '.' && *pszDottedD != '\0')
            pszDottedD++;
        if (pszDottedD == '\0' && cBytes != 5)
        {
            // zero out the rest of MAC address
            while(i++ < 6)
            {
                *p++ = 0;
            }
            break;
        }
        *pszDottedD = '\0';
        *p++ = (atoi(pszLastNum) & 0xFF);
        i++;
        pszLastNum = ++pszDottedD;
    }
}

static void SetMask(EBOOT_CFG *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 );
    }
}


static void SetBootMe(EBOOT_CFG *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;
        }
    }
}


static void SetDelay(EBOOT_CFG *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);
                }
            }
        }
    }

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


BOOL OEMVerifyMemory(DWORD dwStartAddr, DWORD dwLength)
{
    BOOL  rc;
    DWORD dwPhysVerifyStart = (DWORD) OALVAtoPA((void *)dwStartAddr); 
    DWORD dwPhysVerifyEnd   = (DWORD) OALVAtoPA((void *)(dwStartAddr + dwLength - 1));


    EdbgOutputDebugString("****** OEMVerifyMemory checking physical range [ 0x%x ==> 0x%x ]...\r\n", dwPhysVerifyStart, dwPhysVerifyEnd);


    if ((dwPhysVerifyStart >= IMAGE_BOOT_BLDRIMAGE_FLASH_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_BLDRIMAGE_FLASH_PA_END))
    {
        EdbgOutputDebugString("****** bootloader address ****** \r\n\r\n");

        g_ImageType = IMAGE_TYPE_BOOTLOADER;
        rc = TRUE;
    }
    else if ((dwPhysVerifyStart >= XSBASE270_G_BASE_PA_BOOT_FLASH) && (dwPhysVerifyEnd <= (XSBASE270_G_BASE_PA_BOOT_FLASH + XSBASE270_G_SIZE_BOOT_FLASH)))
    {
        EdbgOutputDebugString("****** FLASH address ****** \r\n\r\n");

        g_ImageType = IMAGE_TYPE_FLASHIMAGE;
        rc = TRUE;
    }
    else if ((dwPhysVerifyStart >= XSBASE270_G_BASE_PA_SDRAM) && (dwPhysVerifyEnd <= (XSBASE270_G_BASE_PA_SDRAM + XSBASE270_G_SIZE_SDRAM)))
    {
        EdbgOutputDebugString("****** RAM address ****** \r\n\r\n");

        g_ImageType = IMAGE_TYPE_RAMIMAGE;
        rc = TRUE;
    }
    else
    {
        EdbgOutputDebugString("****** OEMVerifyMemory FAILED - Invalid Memory Area ****** \r\n\r\n");

        rc = FALSE;
    }

    return(rc);

}

void Scrub_sdram(void)
{
    DWORD* ScrubStartAddr = (DWORD*) OALVAtoPA((void *)(XSBASE270_G_BASE_PA_SDRAM + 0x100000)); 
    DWORD i;

    EdbgOutputDebugString("\r\n\r\nBeginning SDRAM Scrub ...\r\n");

    for(i=0; i<0xFC0000; i++)
    {
        *ScrubStartAddr = 0;
        ScrubStartAddr++;
    }

    EdbgOutputDebugString("SDRAM Scrub Complete!\r\n\r\n");

}

⌨️ 快捷键说明

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