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

📄 main.c

📁 freescale i.mx31 BSP CE5.0全部源码
💻 C
📖 第 1 页 / 共 3 页
字号:
//-----------------------------------------------------------------------------
//
//  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.
//
//-----------------------------------------------------------------------------
//
//  Copyright (C) 2004, Motorola Inc. All Rights Reserved
//
//-----------------------------------------------------------------------------
//
//  Copyright (C) 2004, Freescale Semiconductor, Inc. All Rights Reserved
//  THIS SOURCE CODE IS CONFIDENTIAL AND PROPRIETARY AND MAY NOT
//  BE USED OR DISTRIBUTED WITHOUT THE WRITTEN PERMISSION OF
//  FREESCALE SEMICONDUCTOR, INC.
//
//-----------------------------------------------------------------------------

//------------------------------------------------------------------------------
//
//  File:  main.c
//
//  Provides the implementation of EBOOT.
//
//-----------------------------------------------------------------------------

//------------------------------------------------------------------------------
// INCLUDE FILES
//------------------------------------------------------------------------------
#include <windows.h>
#include <nkintr.h>
#include <blcommon.h>
#include <ethdbg.h>
#include <halether.h>
#include <udp.h>

#include "bsp.h"

#include "loader.h"

//------------------------------------------------------------------------------
// GLOBAL DEFINITIONS
//------------------------------------------------------------------------------

// Microsoft Eboot.lib Required
DWORD EdbgDebugZone = 0x0800;

//------------------------------------------------------------------------------
// GLOBAL OR STATIC VARIABLES
//------------------------------------------------------------------------------
// Driver globals pointer (parameter sharing memory used by bootloader and OS).
//
BSP_ARGS *pBSPArgs;

static EDBG_ADDR g_MyAddr;        // IP address
static BOOT_CFG g_BootConfig;
static BOOT_CFG *pBootCfg = &g_BootConfig;
static BOOL g_DownloadImage = TRUE;
static BOOL g_bWaitForConnect = TRUE;

MultiBINInfo g_BINRegionInfo;
DWORD  g_dwMinImageStart;

extern SYSTEMTIME default_time;
extern PCSP_PBC_REGS g_pPBC;

//------------------------------------------------------------------------------
// STATIC FUNCTION PROTOTYPES
//------------------------------------------------------------------------------
static BOOL MainMenu(BOOT_CFG *pBootCfg);
static BOOL SetIPAndSubnet(BOOT_CFG *pBootCfg, BOOL bSetIP);
static void ToggleDHCP(BOOT_CFG *pBootCfg);
static void SetMACAddr(UINT16 *pMacAddress);

// For Real Time Clock Support
void InitRTC(void);

// For autoboot support
static void AutobootMenu(BOOT_CFG *pBootCfg);

extern void DisplaySplashScreen(void);

// For BLCOMMON library error callback
extern PFN_OEMREPORTERROR g_pOEMReportError; 

//------------------------------------------------------------------------------
// EXPORTED FUNCTIONS
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//
//  Function:        OEMReportError
//
//  Callback function from the BLCOMMON library on error before halting the 
//  system. Turns on all board LEDs and print BLCOMMON error code.
//
//  Parameters:
//            dwReason
//                [in] BLCOMMON library error code. See blcommon.h
//
//          dwReserved 
//              [in] not used
//
//  Returns:
//             TRUE
//------------------------------------------------------------------------------
BOOL OEMReportError(DWORD dwReason, DWORD dwReserved)
{
    CSP_PBC_REGS *pPBC;

    // On both on board leds
    pPBC = (PCSP_PBC_REGS)OALPAtoVA((UINT32)BSP_BASE_REG_PA_PBC_BASE, FALSE);
    OUTREG16(&pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_SET_LED0));
    OUTREG16(&pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_SET_LED1));

    OALMSG(OAL_ERROR, (TEXT("ERROR: System halting. BLCOMMON err code %d\r\n"), dwReason));
    return TRUE;
}

//------------------------------------------------------------------------------
//
//  Function:        OEMMultiBINNotify
//
//
//  Parameters:
//            pInfo
//                [in] ptr to info about multiple bin regions
//
//  Returns:
//             void
//------------------------------------------------------------------------------
void OEMMultiBINNotify(const PMultiBINInfo pInfo)
{
    BYTE nCount;

    if (!pInfo || !pInfo->dwNumRegions)
    {
        OALMSG(OAL_ERROR, (TEXT("WARNING: OEMMultiBINNotify - invalid BIN region descriptor(s).\r\n")));
        return;
    }

    g_dwMinImageStart = pInfo->Region[0].dwRegionStart;

    OALMSG(OAL_INFO, (TEXT("\r\nDownload BIN file information:\r\n")));
    OALMSG(OAL_INFO, (TEXT("-----------------------------------------------------\r\n")));
    for (nCount = 0 ; nCount < pInfo->dwNumRegions ; nCount++)
    {
        OALMSG(OAL_INFO, (TEXT("[%d]: Base Address=0x%x  Length=0x%x\r\n") , nCount, pInfo->Region[nCount].dwRegionStart, pInfo->Region[nCount].dwRegionLength));
        if (pInfo->Region[nCount].dwRegionStart < g_dwMinImageStart)
        {
            g_dwMinImageStart = pInfo->Region[nCount].dwRegionStart;
            if (g_dwMinImageStart == 0)
            {
                OALMSG(OAL_ERROR, (TEXT("WARNING: OEMMultiBINNotify - bad region start address for region (%d).\r\n"), nCount));
                return;
            }
        }
    }
    OALMSG(OAL_INFO, (TEXT("\r\n")));

    for (nCount = 1 ; nCount < pInfo->dwNumRegions ; nCount++)
    {
        if (pInfo->Region[nCount].dwRegionStart < g_dwMinImageStart)
        {
            g_dwMinImageStart = pInfo->Region[nCount].dwRegionStart;
            if (g_dwMinImageStart == 0)
            {
                OALMSG(OAL_ERROR, (TEXT("WARNING: OEMMultiBINNotify - bad region start address for region (%d).\r\n"), nCount));
                return;
            }
        }
    }

    OALMSG(OAL_INFO, (TEXT("OEMMultiBINNotify:  memcpy(0x%x, 0x%x, 0x%x)\r\n"), &g_BINRegionInfo, pInfo, sizeof(MultiBINInfo)));
    memcpy((LPBYTE)&g_BINRegionInfo, (LPBYTE)pInfo, sizeof(MultiBINInfo));
}

//------------------------------------------------------------------------------
//
//  Function:        OEMDebugInit
//
//  This function does a callback to OEMInitDebugSerial() to initiliaze
//    the debug transport over UART.
//
//  Parameters:
//
//  Returns:
//             TRUE
//------------------------------------------------------------------------------
BOOL OEMDebugInit (void)
{
    OEMInitDebugSerial();
    g_pOEMMultiBINNotify = OEMMultiBINNotify;
    g_pOEMReportError = OEMReportError;
    return TRUE;
}

//------------------------------------------------------------------------------
//
//  Function:        OEMPlatformInit
//
//  This function is used to initiliaze the rest of    the platform. First it will
//    print the Bootloader version number over the debug serial, then it
//    initialize and setup the RTC. It will then initialize ethernet debug.
//  Also setsup the BSP_ARGS structure.
//
//  Parameters:
//
//
//  Returns:
//             FALSE on failure
//------------------------------------------------------------------------------
BOOL OEMPlatformInit (void)
{
    SYSTEMTIME st;
    CHAR selection;   // Selection for user interface
    DWORD dwCurrSec;
    PCSP_CCM_REGS pCCM;

    OALMSG(OAL_INFO, (TEXT("Copyright 2004 Freescale Semiconductor, Inc. All Rights Reserved\r\n")));
    OALMSG(OAL_INFO, (TEXT("Copyright (C) 2004, Motorola Inc. All Rights Reserved\r\n")));
    OALMSG(OAL_INFO, (TEXT("Microsoft Windows CE Ethernet Bootloader %d.%d for MX31 ADS (%s %s)\r\n"),
                          EBOOT_VERSION_MAJOR, EBOOT_VERSION_MINOR, TEXT(__DATE__), TEXT(__TIME__)));

    // Check for image reflash flag from RVD
    pCCM = (PCSP_CCM_REGS) OALPAtoUA(CSP_BASE_REG_PA_CCM);
    if (EXTREG32BF(&pCCM->RCSR, CCM_RCSR_GPF) == 0xF)
    {        
        OALMSG(OAL_INFO, (TEXT("Reflash request detected!\r\n")));

        // Write out the image previously downloaded into SDRAM
        // by RVD
        OEMWriteFlash(FLASH_CVBASE, 32*1024*1024);

        // Don't connect before launching image
        g_bWaitForConnect = FALSE;
            
        // Jump to OS image
        OEMLaunch(0, 0, OS_FLASH_IMAGE_START, NULL);
    }


    // Initialize the BSP args structure.
    //
    pBSPArgs = ((BSP_ARGS *) IMAGE_SHARE_ARGS_CA_START);
    memset(pBSPArgs, 0, sizeof(BSP_ARGS));
    pBSPArgs->header.signature       = OAL_ARGS_SIGNATURE;
    pBSPArgs->header.oalVersion      = OAL_ARGS_VERSION;
    pBSPArgs->header.bspVersion      = BSP_ARGS_VERSION;
    pBSPArgs->kitl.flags             = (OAL_KITL_FLAGS_ENABLED | OAL_KITL_FLAGS_VMINI);
    pBSPArgs->kitl.devLoc.IfcType    = Internal;
    pBSPArgs->kitl.devLoc.BusNumber  = 0;
    pBSPArgs->kitl.devLoc.LogicalLoc = BSP_BASE_REG_PA_CS8900A_IOBASE;
    
    // Update global BSP args struct with user switches on ADS board
    OALBspArgsInit(pBSPArgs);
        
    // Init the Ethernet controller function pointers
    InitEthDevice();

    memset((LPVOID)&g_MyAddr, 0, sizeof(EDBG_ADDR));

    // Initialize the MAC addr to something in case OALReadBootCFG fails

    // Load BOOT_CFG
    if (!OALReadBootCFG(pBootCfg))
    {
        // If boot configuration cannot be loaded, set the MAC address to
        // a default value
        // pBootCfg->CS8900MAC[0] = (BSP_ARGS_DEFAULT_MAC_BYTE1 << 8) | BSP_ARGS_DEFAULT_MAC_BYTE0;
        // pBootCfg->CS8900MAC[1] = (BSP_ARGS_DEFAULT_MAC_BYTE3 << 8) | BSP_ARGS_DEFAULT_MAC_BYTE2;
        // pBootCfg->CS8900MAC[2] = (BSP_ARGS_DEFAULT_MAC_BYTE5 << 8) | BSP_ARGS_DEFAULT_MAC_BYTE4;
    }

    memcpy(g_MyAddr.wMAC, pBootCfg->CS8900MAC, 6);
    g_MyAddr.dwIP = pBootCfg->IPAddr;

    // Initialize the RTC
    InitRTC();

#if NAND_BOOT_SUPPORT
    // Initialise Boot Partition Manager
    InitPartitionMgr();
#endif
        
    // Check real time clock, initialize if necessary (used for polling in net routines)
    OEMGetRealTime(&st);
    if ((st.wYear < 1601) ||
        (st.wMonth < 1) ||
        (st.wMonth > 12) ||
        (st.wDay < 1) ||
        (st.wDay > 31) ||
        (st.wHour > 23) ||
        (st.wMinute > 59) ||
        (st.wSecond > 59) ||
        (st.wMilliseconds > 999)) {

            OALMSG(OAL_ERROR, (TEXT("ERROR: Invalid time returned from OEMGetRealTime: Year: %u, Month: %u, Day: %u, Hour: %u, Minute: %u, second: %u\n"),
                           st.wYear, st.wMonth,st.wDay, st.wHour, st.wMinute,st.wSecond));
            OALMSG(OAL_INFO, (TEXT("INFO: Resetting real time clock to default date\n")));

        OEMSetRealTime(&default_time);
    }
    else
    {
        OEMSetRealTime(&st);
    }

    dwCurrSec = OEMEthGetSecs();
    
    // User Interface for setting up IP, subnet, etc
    OALMSG(OAL_INFO, (TEXT ("Hit ENTER within 3 seconds to change boot setting!\r\n")));
    while (OEMEthGetSecs() - dwCurrSec < 3) {
        selection = OEMReadDebugByte();
        if ((selection == 0x20) || (selection == 0x0d))
        {
            OEMWriteDebugByte('\n');
            break;
        }
    }

    switch (selection)
    {
        case 0x20:
        case 0x0d:
            g_DownloadImage = MainMenu(pBootCfg);
            break;

        default:
            // Auto boot OS if enabled            
            if((pBootCfg->ConfigFlags & CONFIG_FLAGS_AUTOBOOT))
            {
                switch(pBootCfg->BootDevice)
                {
                    case CONFIG_AUTOBOOT_DEVICE_NOR:
                        pBootCfg->LaunchAddress = OS_FLASH_IMAGE_START + 0x1000;
                        g_DownloadImage = FALSE;
                        break;

#if NAND_BOOT_SUPPORT

⌨️ 快捷键说明

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