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

📄 main.c

📁 WinCE 5.0的PXA270Bootloader
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  File:  main.c
//
//  Core routines for the Intel Mainstone II bootloader.
//
#include <windows.h>
#include <nkintr.h>
#include <bulverde.h>
#include <mainstoneii.h>
#include <oal_memory.h>
#include <pcireg.h>
#include <fmd.h>
#include <xllp_pccardsocket.h>
#include <bsp.h>
#include "loader.h"

//------------------------------------------------------------------------------
// Local variables.
//
static PCI_REG_INFO g_FlashAddress;
static EBOOT_CFG    g_EbootCFG;
static BOOLEAN      g_DownloadImage = TRUE;

//------------------------------------------------------------------------------
// Global variables.
//
DWORD     EdbgDebugZone;
FlashInfo g_FlashInfo;
BSP_ARGS *g_pBSPArgs = (BSP_ARGS *) IMAGE_SHARE_ARGS_UA_START;
EDBG_ADDR g_DeviceAddr; // NOTE: global used so it remains in scope throughout download process
                        // since eboot library code keeps a global pointer to the variable provided.
XLLP_PCCARDSOCKET_T strEbtPCCardSocketHandle;
IMAGE_TYPE g_ImageType;

//------------------------------------------------------------------------------
// Local function prototypes.
//
static BOOL LoadEBootCFG(EBOOT_CFG *EBootCFG);
static BOOL StoreEBootCFG(EBOOT_CFG *EBootCFG);
static void ResetDefaultEBootCFG(EBOOT_CFG *pEbootCFG);

static void SetIP(EBOOT_CFG *pEbootCFG);
static void SetMask(EBOOT_CFG *pEbootCFG);
static void SetBootMe(EBOOT_CFG *pEbootCFG);
static void SetDelay(EBOOT_CFG *pEbootCFG);

BOOL OEMVerifyMemory(DWORD dwStartAddr, DWORD dwLength);

//------------------------------------------------------------------------------
// External function prorotypes.
//
extern void Launch(unsigned int uAddr);


//------------------------------------------------------------------------------
//
//  Function:  main
//
//  Bootloader main routine.
//
void main(void)
{

    // Common boot loader (blcommon) main routine.
    //
    BootloaderMain();

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

}

//------------------------------------------------------------------------------
//
//  Function:  OEMDebugInit
//
//  Initialize debug serial UART.
//
BOOL OEMDebugInit(void)
{

    // Initialize the flash interface (needed so we can determine which serial
    // port to use for bootloader and OS debug message output).
    //
    if (!FlashInit((UINT32) OALPAtoVA(MAINSTONEII_BASE_PA_BOOT_FLASH, FALSE), MAINSTONEII_SIZE_BOOT_FLASH))
    {
        // Load default bootloader configuration settings.
        //
        EdbgOutputDebugString("ERROR: flash initialization failed - loading bootloader defaults...\r\n");
        ResetDefaultEBootCFG(&g_EbootCFG);
    }
    else
    {
        // Load the bootloader configuration from flash (menu settings).
        //
        LoadEBootCFG(&g_EbootCFG);
    }

    // Initialize the debug UART.
    //
    InitDebugSerial(g_EbootCFG.dwDbgSerPhysAddr);

    // Clear the hex LEDs.
    //
    OEMWriteDebugLED(0, 0);

    // Set up optional bootloader function pointers.
    //
    g_pOEMVerifyMemory = OEMVerifyMemory;

    return(TRUE);

}


//------------------------------------------------------------------------------
//
//  Function:  OEMPlatformInit
//
//  Initialize the Mainstone II platform.
//
BOOL OEMPlatformInit(void)
{
    UINT32 AutoBootDelay = 0;
    BOOLEAN bXIPMode     = TRUE;
    BOOLEAN bCFGChanged  = FALSE;
    SYSTEMTIME SysTime;
    UINT32 StartTime, CurrTime, PrevTime;
    UINT32 Selection;
    UINT32 EthDevice;


    // This table describes the boot order for a given configuration.
    //
    ETH_DEVICE_TYPE BootOrder[] = { ETH_DEVICE_SMSC, ETH_DEVICE_PCMCIA0, ETH_DEVICE_PCMCIA1,    // pEbootCFG->bootDeviceOrder = 0.
                                    ETH_DEVICE_SMSC, ETH_DEVICE_PCMCIA1, ETH_DEVICE_PCMCIA0,    // pEbootCFG->bootDeviceOrder = 1.
                                    ETH_DEVICE_PCMCIA0, ETH_DEVICE_PCMCIA1, ETH_DEVICE_SMSC,    // pEbootCFG->bootDeviceOrder = 2.
                                    ETH_DEVICE_PCMCIA0, ETH_DEVICE_SMSC, ETH_DEVICE_PCMCIA1,    // pEbootCFG->bootDeviceOrder = 3.
                                    ETH_DEVICE_PCMCIA1, ETH_DEVICE_SMSC, ETH_DEVICE_PCMCIA0,    // pEbootCFG->bootDeviceOrder = 4.
                                    ETH_DEVICE_PCMCIA1, ETH_DEVICE_PCMCIA0, ETH_DEVICE_SMSC };  // pEbootCFG->bootDeviceOrder = 5.


    EdbgOutputDebugString("Microsoft Windows CE Ethernet Bootloader %d.%d for the Intel MainstoneII Development Platform Built %s\r\n", \
                          EBOOT_VERSION_MAJOR, EBOOT_VERSION_MINOR, __DATE__);

    // 
    memset((LPVOID)g_pBSPArgs, 0, sizeof(BSP_ARGS));
    g_pBSPArgs->header.signature  = OAL_ARGS_SIGNATURE;
    g_pBSPArgs->header.oalVersion = OAL_ARGS_VERSION;
    g_pBSPArgs->header.bspVersion = BSP_ARGS_VERSION;

    // Initialize the global XLLP device handle for the PC Card interface.
    //
    memset((void *) &strEbtPCCardSocketHandle, 0, sizeof(XLLP_PCCARDSOCKET_T));
    strEbtPCCardSocketHandle.pstrGpioRegsHandle = (XLLP_GPIO_T *) OALPAtoVA(BULVERDE_BASE_REG_PA_GPIO, FALSE);
    XllpPCCardConfigureGPIOs(&strEbtPCCardSocketHandle);

    // Read the current wall-clock time.
    // NOTE: At reset, the RTC value is set to 1/1/1980 at 0:0:0.
    //
    OEMGetRealTime(&SysTime);

    // User menu code...
    //
    AutoBootDelay = g_EbootCFG.delay;
    if (g_EbootCFG.autoDownloadImage)
    {
        g_DownloadImage = TRUE;
        EdbgOutputDebugString ( "\r\nPress [ENTER] to download now or [SPACE] to cancel.\r\n");
        EdbgOutputDebugString ( "\r\nInitiating image download in %d seconds. ", AutoBootDelay--);
    }
    else
    {
        g_DownloadImage = FALSE;
        EdbgOutputDebugString ( "\r\nPress [ENTER] to launch image stored in flash or [SPACE] to cancel.\r\n");
        EdbgOutputDebugString ( "\r\nInitiating image launch in %d seconds. ", AutoBootDelay--);
    }

    // Get a snapshot of the RTC seconds count.
    //
    StartTime     = OEMEthGetSecs();
    PrevTime      = StartTime;
    CurrTime      = StartTime;
    Selection     = 0;

    // Allow the user an amount of time to halt the auto boot/download process.
    // Count down to 0 before proceeding with default operation.
    //
    while ((CurrTime - StartTime) < g_EbootCFG.delay)
    {
        UINT8 i=0;
        UINT8 j;
        UINT8 x,y,z;

        Selection = OEMReadDebugByte(); 
        if ((Selection == 0x20) || (Selection == 0x0d))
        {
            break;
        }
        CurrTime = OEMEthGetSecs();   
        if (CurrTime > PrevTime)
        {
            PrevTime = CurrTime;
            if (AutoBootDelay < 9)
                i = 11;
            else if (AutoBootDelay < 99)
                i = 12;
            else if (AutoBootDelay < 999)
                i = 13;

            for (j = 0; j < i; j++)
            {
                OEMWriteDebugByte((BYTE)0x08); // print back space
            }
            x = AutoBootDelay / 100;
            y = (AutoBootDelay % 100) / 10;
            z = ((AutoBootDelay % 100) % 10);
            OEMWriteDebugLED(0, ((x << 8) | (y << 4) | (z)));
            EdbgOutputDebugString ( "%d seconds. ", AutoBootDelay--);
        }

    }

    switch (Selection)
    {
    case 0x00: // fall through if nothing typed
    case 0x0d: // user canceled wait
        {
            if (g_EbootCFG.autoDownloadImage)
            {
                EdbgOutputDebugString ( "\r\nStarting auto download ... \r\n");
            }
            else
            {
                EdbgOutputDebugString ( "\r\nLaunching flash image  ... \r\n");
            }
            break;
        }
    case 0x20:
        {
            Selection = 0;
            while (1)
            {
                // Show menu
                EdbgOutputDebugString ( "\r\n\r\nEthernet Boot Loader Configuration:\r\n\r\n");
                EdbgOutputDebugString ( "0) IP address: %s\r\n",inet_ntoa(g_EbootCFG.IP));
                EdbgOutputDebugString ( "1) Subnet mask: %s\r\n", inet_ntoa(g_EbootCFG.subnetMask));
                EdbgOutputDebugString ( "2) Boot delay: %d seconds\r\n", g_EbootCFG.delay);
                EdbgOutputDebugString ( "3) DHCP: %s\r\n", (g_EbootCFG.DHCPEnable == TRUE?"(Enabled)":"(Disabled)"));
                EdbgOutputDebugString ( "4) Reset to factory default configuration\r\n");
                EdbgOutputDebugString ( "5) %s image at startup\r\n", g_EbootCFG.autoDownloadImage?"Download new":"Launch existing flash resident");
                EdbgOutputDebugString ( "6) Boot device order: ");

                switch (g_EbootCFG.bootDeviceOrder)
                {
                case 0:
                    EdbgOutputDebugString ( "SMSC -> PCMCIA0 -> PCMCIA1\r\n");
                    break;
                case 1:
                    EdbgOutputDebugString ( "SMSC -> PCMCIA1 -> PCMCIA0\r\n");
                    break;
                case 2:
                    EdbgOutputDebugString ( "PCMCIA0 -> PCMCIA1 -> SMSC\r\n");
                    break;
                case 3:
                    EdbgOutputDebugString ( "PCMCIA0 -> SMSC -> PCMCIA1\r\n");
                    break;
                case 4:
                    EdbgOutputDebugString ( "PCMCIA1 -> SMSC -> PCMCIA0\r\n");
                    break;
                case 5:
                    EdbgOutputDebugString ( "PCMCIA1 -> PCMCIA0 -> SMSC\r\n");
                    break;
                default:
                    EdbgOutputDebugString ( "SMSC -> PCMCIA0 -> PCMCIA1\r\n");
                    g_EbootCFG.bootDeviceOrder = 0;
                    break;
                }
                EdbgOutputDebugString ( "7) Debug serial port: ");
                switch (g_EbootCFG.dwDbgSerPhysAddr)
                {
                case BULVERDE_BASE_REG_PA_FFUART:
                    EdbgOutputDebugString ( "FFUART\r\n");
                    break;
                case BULVERDE_BASE_REG_PA_BTUART:
                default:
                    EdbgOutputDebugString ( "BTUART\r\n");
                    break;
                }
                EdbgOutputDebugString ( "D) Download image now\r\n");
                EdbgOutputDebugString ( "L) Launch existing flash resident image now\r\n");
                EdbgOutputDebugString ( "\r\n\r\nEnter your selection: ");
                Selection = 0;
                while (! ( ( (Selection >= '0') && (Selection <= '7') ) || 
                           ( (Selection == 'D') || (Selection == 'd') ) || 
                           ( (Selection == 'L') || (Selection == 'l') ) ))
                {
                    Selection = OEMReadDebugByte();
                }
                EdbgOutputDebugString ( "%c\r\n", Selection);
                switch (Selection)
                {
                case '0':
                    SetIP(&g_EbootCFG);
                    bCFGChanged=TRUE;
                    break;
                case '1':
                    SetMask(&g_EbootCFG);
                    bCFGChanged=TRUE;
                    break;
                case '2':
                    SetDelay(&g_EbootCFG);
                    bCFGChanged=TRUE;
                    break;
                case '3':
                    if (g_EbootCFG.DHCPEnable == TRUE)
                        g_EbootCFG.DHCPEnable = FALSE;
                    else
                        g_EbootCFG.DHCPEnable = TRUE;
                    bCFGChanged=TRUE;
                    break;
                case '4':
                    ResetDefaultEBootCFG(&g_EbootCFG);
                    bCFGChanged=TRUE;
                    break;
                case '5':
                    if (g_EbootCFG.autoDownloadImage == TRUE)
                        g_EbootCFG.autoDownloadImage = FALSE;
                    else
                        g_EbootCFG.autoDownloadImage = TRUE;
                    bCFGChanged=TRUE;
                    break;
                case '6':
                    g_EbootCFG.bootDeviceOrder++;
                    if (g_EbootCFG.bootDeviceOrder > 5)
                        g_EbootCFG.bootDeviceOrder = 0;
                    bCFGChanged=TRUE;
                    break;
                case '7':
                    if ((g_EbootCFG.dwDbgSerPhysAddr == 0) || (g_EbootCFG.dwDbgSerPhysAddr == BULVERDE_BASE_REG_PA_BTUART))
                    {
                        g_EbootCFG.dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_FFUART;
                    }
                    else
                    {
                        g_EbootCFG.dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_BTUART;
                    }
                    bCFGChanged=TRUE;
                    break;
                case 'D':
                case 'd':
                    if (bCFGChanged == TRUE)
                    {
                        StoreEBootCFG(&g_EbootCFG);
                    }
                    g_DownloadImage = TRUE;
                    goto CONTINUE;
                case 'L':
                case 'l':
                    if (bCFGChanged == TRUE)
                    {
                        StoreEBootCFG(&g_EbootCFG);
                    }
                    g_DownloadImage = FALSE;
                    goto CONTINUE;

                default:
                    break;
                }
            }
        }
    }

  CONTINUE:

    // Provide the chosen debug serial port address to the OS image for debug output messages.
    //
    g_pBSPArgs->dbgSerPhysAddr = g_EbootCFG.dwDbgSerPhysAddr;

    // If we need to download an image, locate and initialize an Ethernet controller.
    //
    if (g_DownloadImage)
    {
        // Try each of the boot devices in the specified order (until one succeeds or they all fail).
        //
        EthDevice = InitSpecifiedEthDevice(&g_pBSPArgs->kitl, BootOrder[(g_EbootCFG.bootDeviceOrder * 3)]);
        if (EthDevice == -1)
        {
            EthDevice = InitSpecifiedEthDevice(&g_pBSPArgs->kitl, BootOrder[(g_EbootCFG.bootDeviceOrder * 3) + 1]);
            if (EthDevice == -1)
            {
                EthDevice = InitSpecifiedEthDevice(&g_pBSPArgs->kitl, BootOrder[(g_EbootCFG.bootDeviceOrder * 3) + 2]);
            }
        }

        // No device was found ... 
        //
        if (EthDevice == -1)
        {
            EdbgOutputDebugString("ERROR: Failed to detect and initialize Ethernet controller.\r\n");
            return(FALSE);
        }

        // Make sure MAC address has been programmed.
        //
        if (!g_pBSPArgs->kitl.mac[0] && !g_pBSPArgs->kitl.mac[1] && !g_pBSPArgs->kitl.mac[2])
        {
            EdbgOutputDebugString("ERROR: Invalid Ethernet address read from Ethernet controller.\n");
            return(FALSE);
        }
        else
        {
            EdbgOutputDebugString("INFO: MAC address: %x-%x-%x-%x-%x-%x\r\n",
                  g_pBSPArgs->kitl.mac[0] & 0x00FF, g_pBSPArgs->kitl.mac[0] >> 8,
                  g_pBSPArgs->kitl.mac[1] & 0x00FF, g_pBSPArgs->kitl.mac[1] >> 8,
                  g_pBSPArgs->kitl.mac[2] & 0x00FF, g_pBSPArgs->kitl.mac[2] >> 8);
        }
    }

    return(TRUE);

}


//------------------------------------------------------------------------------
//
//  Function:  OEMPreDownload
//
//  Pre-download initialization routine.
//
DWORD OEMPreDownload(void)
{
    UINT32 SubnetMask;
    BOOL  fGotJumpImg = FALSE, fGotIP = FALSE;
    UINT32 DHCPLeaseTime = 0;

⌨️ 快捷键说明

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