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

📄 main.c

📁 Windows CE 6.0 BSP for VOIP sample phone. Intel PXA270 platform.
💻 C
📖 第 1 页 / 共 2 页
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//------------------------------------------------------------------------------
//
//  File:  main.c
//
//  Core routines for the Plato bootloader.
//
#include <windows.h>
#include <nkintr.h>
#include <bulverde.h>
#include <plato.h>
#include <oal_memory.h>
#include <bsp.h>
#include "loader.h"
#include "flash.h"
#include "wait.h"

//------------------------------------------------------------------------------
// Global variables.
//
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.
IMAGE_TYPE g_ImageType;

EBOOT_CFG   g_EbootCFG;
BOOL        g_DownloadImage = TRUE;
UCHAR       *g_DefaultRamAddress;
BOOL        g_FormatFlash = FALSE;
BOOL        g_fChargerInitialized = FALSE;
BOOL         g_BootFromSD;

//------------------------------------------------------------------------------
// Local function prototypes.
//
BOOL LoadEBootCFG(EBOOT_CFG *EBootCFG);
BOOL StoreEBootCFG(EBOOT_CFG *EBootCFG);
void ResetDefaultEBootCFG(EBOOT_CFG *pEbootCFG);
BOOL OEMVerifyMemory(DWORD dwStartAddr, DWORD dwLength);
void OEMDownloadFileNotify(PDownloadManifest pInfo);
BOOL BLInitEthernet();

//------------------------------------------------------------------------------
// External function prorotypes.
//
extern BOOL GetMacAddress(UINT16 mac[3]);
extern void Launch(unsigned int uAddr);
extern BOOL BLMenu();
extern BOOL OALPowerInit();
extern void BLInitDisplay();
extern void DisplayDebugString();
extern void DisableLCDController();

//------------------------------------------------------------------------------
//
//  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)
{
    InitDebugSerial(BULVERDE_BASE_REG_PA_FFUART);

#ifdef DEBUG
    KITLOutputDebugString("\r\nINFO: Serial port initialized\r\n");
#endif

    OEMWriteDebugLED(0, 0xF00);

    return(TRUE);
}


//------------------------------------------------------------------------------
//
//  Function:  OEMPlatformInit
//
//  Initialize the Plato platform.
//
BOOL OEMPlatformInit(void)
{
    KITLOutputDebugString("Microsoft Windows CE Ethernet Bootloader %d.%d for Plato Platform Built %s\r\n\r\n", \
                          EBOOT_VERSION_MAJOR, EBOOT_VERSION_MINOR, __DATE__);

    // Load eboot configuration
    //
    if (!LoadEBootCFG(&g_EbootCFG)) 
    {

        // Load default bootloader configuration settings.
        KITLOutputDebugString("ERROR: flash initialization failed - loading bootloader defaults...\r\n");
        ResetDefaultEBootCFG(&g_EbootCFG);
    }

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

    // Initialize the BSP args structure.
    //
    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;
    g_pBSPArgs->dbgSerPhysAddr = g_EbootCFG.dwDbgSerPhysAddr;

    // Initialize the display controller
    //
    BLInitDisplay();

    // Initialize the power manager IC to start the battery charger and show LED status
    // if the charger is connected.
    //
    if (!OALPowerInit())
    {
        KITLOutputDebugString("WARNING: Battery Charger initialization failed. Battery may not charge properly.\r\n");
    }

    return(TRUE);
}



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

    g_BootFromSD = FALSE;

    // User menu code...
    //
    if (!BLMenu())
    {
        return (BL_ERROR);
    }

    // If the charger is not initialized yet, Initialize the power manager IC to start the 
    // battery charger and show LED status. The previous initialization would not have
    // taken place if the charger was not present at that time. The USB cable should
    // have been connected by now if it was going to be connected at any time.
    //
    if (!g_fChargerInitialized)
    {
        if (!OALPowerInit())
        {
            KITLOutputDebugString("WARNING: Battery Charger initialization failed. Battery may not charge properly.\r\n");
        }
    }

    // Setup KITL Config
    //

    // Validate IP Settings
    //
    if ((g_EbootCFG.IP == 0 || g_EbootCFG.subnetMask == 0) && !g_EbootCFG.DHCPEnable) {
        KITLOutputDebugString("ERROR: Invalid IP configuration - Static IP not set and DHCP Disabled.\r\n");
        return (BL_ERROR);
    }

    if (g_EbootCFG.KITLEnabled) 
        g_pBSPArgs->kitl.flags    |= OAL_KITL_FLAGS_ENABLED;
    else
        g_pBSPArgs->kitl.flags    &= ~OAL_KITL_FLAGS_ENABLED;
        
    if (g_EbootCFG.DHCPEnable) {
        g_pBSPArgs->kitl.flags    |= OAL_KITL_FLAGS_DHCP;
    } else {
        g_pBSPArgs->kitl.ipAddress = g_EbootCFG.IP;
        g_pBSPArgs->kitl.ipMask    = g_EbootCFG.subnetMask;
        g_pBSPArgs->kitl.flags    &= ~OAL_KITL_FLAGS_DHCP;
    }

    g_pBSPArgs->kitl.flags             |= OAL_KITL_FLAGS_VMINI;
    g_pBSPArgs->kitl.devLoc.IfcType     = InterfaceTypeUndefined;
    g_pBSPArgs->kitl.devLoc.BusNumber   = 0;
    g_pBSPArgs->kitl.devLoc.PhysicalLoc = 0;
    g_pBSPArgs->kitl.devLoc.LogicalLoc  = 0;
    g_pBSPArgs->kitl.devLoc.Pin         = IRQ_USBFN;

    // Inform KITL of our MAC address
    //
    memcpy(g_pBSPArgs->kitl.mac, g_EbootCFG.RNDISMac, 6);
    if (!g_pBSPArgs->kitl.mac[0] && !g_pBSPArgs->kitl.mac[1] && !g_pBSPArgs->kitl.mac[2])
    {
        KITLOutputDebugString("ERROR: Invalid RNDIS MAC address read from eboot config.\r\n");
        return (BL_ERROR);
    }

    if (g_DownloadImage)
    {
        // If the user selected the download option, locate and initialize an Ethernet controller.
        if (!BLInitEthernet())
            return BL_ERROR;

        // Create device name based on Ethernet address (this is how Platform Builder identifies this device).
        //
        OALKitlCreateName(BSP_DEVICE_PREFIX, g_pBSPArgs->kitl.mac, g_pBSPArgs->deviceId);
        KITLOutputDebugString("INFO: Using device name: '%s'\n", g_pBSPArgs->deviceId);

        // Check if the user wants to use DHCP
        //
        if (g_EbootCFG.DHCPEnable == FALSE)
            pDHCPLeaseTime             = NULL;

        // Initialize the TFTP transport.
        memcpy(g_DeviceAddr.wMAC, g_pBSPArgs->kitl.mac, (sizeof(UINT16) * 3));
        g_DeviceAddr.dwIP  = g_pBSPArgs->kitl.ipAddress;
        g_DeviceAddr.wPort = 0;
        SubnetMask         = g_pBSPArgs->kitl.ipMask;

        if (!EbootInitEtherTransport(&g_DeviceAddr,
                                     &SubnetMask,
                                     &fGotJumpImg,
                                     pDHCPLeaseTime,
                                     EBOOT_VERSION_MAJOR,
                                     EBOOT_VERSION_MINOR,
                                     BSP_DEVICE_PREFIX,
                                     g_pBSPArgs->deviceId,
                                     EDBG_CPU_ARM720,
                                     BootFlags))
        {
            return(BL_ERROR);
        }

        // If the user wanted a DHCP address, save the values obtained in the init call above.
        //
        if (g_EbootCFG.DHCPEnable == TRUE)
        {
            g_pBSPArgs->kitl.ipAddress  = g_DeviceAddr.dwIP;
            g_pBSPArgs->kitl.ipMask     = SubnetMask;
        }
    }

    // Set the clean boot flag so that OAL will let the kernel know that
    // it needs a clean boot (Filesys to initialize the memory structures)
    //
    g_pBSPArgs->bCleanBootFlag = TRUE;

    if (g_BootFromSD)
    {
        DisplayDebugString("Downloading image from SD...");
        rc = BL_DOWNLOAD;
    }
    else if (!g_DownloadImage || // this gets set in the BLMenu() function
        fGotJumpImg)        // this gets set in EbootInitEtherTransport
    {
        // Load image from Flash
        //
        DisplayDebugString("Reading image from flash...");
        rc = ReadFlashNK();
    }
    else if (g_DownloadImage)
    {
        DisplayDebugString("Downloading image from PB...");
        rc = BL_DOWNLOAD;
    }
    
    return(rc);
}


//------------------------------------------------------------------------------
//
//  Function:  OEMLaunch

⌨️ 快捷键说明

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