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

📄 main.c

📁 ebd9307开发板wince bsp源码,包括cs8900,lcd,nand,serial,touch,usb,gpio,wd等驱动
💻 C
字号:
//**********************************************************************
//                                                                      
// Filename: main.c 
//                                                                      
// Description: Ethernet boot loader main module.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Use of this source code is subject to the terms of the Cirrus 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 
// EULA.RTF on your install media.
//
// Copyright(c) Cirrus Logic Corporation 2005, All Rights Reserved                       
//                                                                      
//**********************************************************************

//
// 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 EULA.RTF on your
// install media.
//
//------------------------------------------------------------------------------
//
//  Module Name:
//      main.c
//
//  Abstract:
//      Ethernet boot loader main module. This file contains the C main
//      for the boot loader.    NOTE: The firmware "entry" point (the real
//      entry point is _EntryPoint in init assembler file.
//
//      The Windows CE boot loader is the code that is executed on a Windows CE
//      development system at power-on reset and loads the Windows CE
//      operating system. The boot loader also provides code that monitors
//      the behavior of a Windows CE platform between the time the boot loader
//      starts running and the time the full operating system debugger is
//      available. Windows CE OEMs are supplied with sample boot loader code
//      that runs on a particular development platform and CPU.
//
//  Functions:
//
//------------------------------------------------------------------------------
#include <windows.h>
#include <blcommon.h>
#include <halether.h>
#include <ceddk.h>
#include <ethdbg.h>
#include <hwdefs.h>
#include <drv_glob.h>
#include <debugtimer.h>
#include <options.h>
//#include "parallel.h"
//#include "harddrive.h"
#include "ether.h"
//#include "pcmciasupport.h"

//
// Type definitions.
//
typedef VOID (*PFN_LAUNCH)(VOID);
typedef enum        // Supported image load/download methods.
{
    BL_ENET = 0,    // Ethernet.
    BL_ATAHDD       // ATA/IDE hard drive.
} IMG_LOC_ID;
typedef BOOL  (*PFN_PLATFORM_INIT)(VOID);
typedef DWORD (*PFN_PRE_DOWNLOAD)(VOID);
typedef BOOL  (*PFN_READ_DATA)(DWORD cbData, LPBYTE pbData);

//
// Definitions 
//

//
// Function prototypes.
//
void OEMInitDebugSerial(void) ;


//
// Varaibles.
//
DWORD EdbgDebugZone;
static EDBG_ADDR MyAddr;
BOOL bEthLaunch =FALSE;
static PFN_PLATFORM_INIT         pfnPlatformInit2 = NULL;
static PFN_PRE_DOWNLOAD          pfnPreDownload   = NULL;
static PFN_READ_DATA             pfnReadData      = NULL;

extern void    OEMUartStop(void);

extern void OEMWriteDebugLED(WORD wIndex, DWORD dwPattern);





//****************************************************************************
// SpinForever
//****************************************************************************
// Spin forever.
// 
//
static void SpinForever(void)
{
    EdbgOutputDebugString("SpinForever...\r\n");

    while(1)
    {
        ;
    }
}

//****************************************************************************
// OEMLaunch
//****************************************************************************
// dwImage          - Image Start
// dwImageLength    - Image Length
// dwLaunchAddr     - Launch Address
// pRomHdr          - Pointer to the bin header.  Used to copy uninitialized
//                    data to ram.
//
void OEMLaunch
(
    DWORD dwImageStart, 
    DWORD dwImageLength, 
    DWORD dwLaunchAddr, 
    const ROMHDR *pRomHdr
)
{
    EDBG_OS_CONFIG_DATA *pCfgData;    
    EDBG_ADDR EshellHostAddr;

    if (bEthLaunch)	// Wait for host connection?
    {
        memset (&EshellHostAddr, 0, sizeof (EshellHostAddr));
        //pDriverGlobals->eth.EdbgAddr

        if (!(pCfgData = EbootWaitForHostConnect(&pDriverGlobals->eth.EdbgAddr, &EshellHostAddr)))
        {
            EdbgOutputDebugString("ERROR: EbootWaitForHostConenct failed, spin forever\r\n");
            SpinForever();
        }
        EdbgOutputDebugString
        (
            "EBOOT: pCfgData = 0x%x, pCfgData->Flags\n",
            (ULONG)pCfgData,
            (ULONG)pCfgData->Flags
        );

        if (pCfgData->Flags & EDBG_FL_DBGMSG)
        {
            EdbgOutputDebugString("Enabling debug messages over Ethernet, IP: %s, port:%u\n",
                              inet_ntoa(pCfgData->DbgMsgIPAddr),ntohs(pCfgData->DbgMsgPort));
            memcpy((void *)&pDriverGlobals->eth.DbgHostAddr.wMAC, (void *)&EshellHostAddr.wMAC,6);
            pDriverGlobals->eth.DbgHostAddr.dwIP  = pCfgData->DbgMsgIPAddr;
            pDriverGlobals->eth.DbgHostAddr.wPort = pCfgData->DbgMsgPort;
        }
        if (pCfgData->Flags & EDBG_FL_PPSH)
        {
            EdbgOutputDebugString("Enabling CESH over Ethernet,           IP: %s, port:%u\n",
                              inet_ntoa(pCfgData->PpshIPAddr),ntohs(pCfgData->PpshPort));
            memcpy((void *)&pDriverGlobals->eth.PpshHostAddr.wMAC, (void *)&EshellHostAddr.wMAC,6);
            pDriverGlobals->eth.PpshHostAddr.dwIP  = pCfgData->PpshIPAddr;
            pDriverGlobals->eth.PpshHostAddr.wPort = pCfgData->PpshPort;
        }
        if (pCfgData->Flags & EDBG_FL_KDBG)
        {
            EdbgOutputDebugString("Enabling KDBG over Ethernet,           IP: %s, port:%u\n",
                              inet_ntoa(pCfgData->KdbgIPAddr),ntohs(pCfgData->KdbgPort));
            memcpy((void *)&pDriverGlobals->eth.KdbgHostAddr.wMAC, (void *)&EshellHostAddr.wMAC,6);
            pDriverGlobals->eth.KdbgHostAddr.dwIP  = pCfgData->KdbgIPAddr;
            pDriverGlobals->eth.KdbgHostAddr.wPort = pCfgData->KdbgPort;
        }
        pDriverGlobals->eth.etherFlags = pCfgData->Flags;

        //
        // This is also referred to the "ODO" mac address.  Only the MAC is valid in this variable.
        //
        memcpy((void *)&pDriverGlobals->eth.EshellHostAddr, (void *)&EshellHostAddr,sizeof(EDBG_ADDR));
    }
    else
    {
        //
        // It is ether a parallel port or a hard driver download.
        //
        
    }

    // If no jump address is specified, choose the default (flash address).
    // 
    if (!dwLaunchAddr)
    {
        //dwLaunchAddr = DEFAULT_JUMP_ADDR;
        SpinForever();
    }


    EdbgOutputDebugString("INFO: Jumping to image at 0x%X...\r\n", dwLaunchAddr);

    //
    // Delay 1 Millisecond to flush the Uart fifo and stop the UART.
    //
    if(bEthLaunch)
    {
        DelayInuSec(1000);
        // OEMUartStop();
    }
    

    ((PFN_LAUNCH)(dwLaunchAddr))();

    // Should never be reached...
    SpinForever();
}


//****************************************************************************
// OEMShowProgress
//****************************************************************************
// Show download progress.
// 
// dwPacketNum - Shows the number of packets.  I don't know how to get
//               the total number of packets.
//
// TODO - show packet progress.
//
void OEMShowProgress(DWORD dwPacketNum)
{
    return;
}

//****************************************************************************
//  OEMReadData
//****************************************************************************
// cbData - Buffer size
// pbData - Pointer to buffer.
// 
// return - TRUE Success
//          FALSE Failure
BOOL OEMReadData(DWORD cbData, LPBYTE pbData)
{
    BOOL bReturnValue = FALSE;

    //
    // Read the data in from the device.
    //
    if(pfnReadData)
        bReturnValue = pfnReadData(cbData, pbData);

    return bReturnValue;    
}

//****************************************************************************
// EbootMain
//****************************************************************************
// Called from startup.  First C routine to be called.
// 
//
void EbootMain(void)
{

    //
    // Write protect the flash.
    //
#ifdef EP93XX_16BIT
    *SMC_SMCBCR6    = 0x1000FFFF;
#else
    *SMC_SMCBCR6    = 0x2000FFFF;
#endif

	//
	// Turn off the Green LED as recommended in the SDB 
	// documentation 3.2.4.
	// 
	OEMWriteDebugLED(0,0);

    //
    // Common bootloader main routine.
    //
    BootloaderMain();

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

//****************************************************************************
// OEMDebugInit
//****************************************************************************
// Callback to initialize serial debug hardware.
// 
//
BOOL OEMDebugInit(void)
{
    //
    // Initialize our debug UART.
    //
    OEMInitDebugSerial();

    //
    // Initialize the debug timer.
    //
    DebugTimerInit();

    //
    // Initialize a PCMCIA card. Temporarily comment out.
    //
//    OEMPCMCIAInitialize();


    return(TRUE);
}

//****************************************************************************
// OEMPlatformInit
//****************************************************************************
// Called to detect the download type and initialize the platform.
//
// TRUE indicates success. FALSE indicates failure.
//
// Callback to initialize the platform.
//
BOOL OEMPlatformInit(void)
{
    BOOL fRet = FALSE;
    UCHAR i = 0;

    EdbgOutputDebugString("\n============================================================\n"
                          "SBC9307 Windows CE Ethernet Bootloader \n"
                          "(Built on %s %s)"
                          "\n============================================================\n",
                          __DATE__, __TIME__);

    //
    // RLG temp.
    //

/*    #if 0

    //
    // Initiailize the parallel port
    //    
    OEMInitParallelPort();
    
    //
    // Check to see if the parallel port is ready.
    //
    if (OEMIsParallelReady()) 
    {
        EdbgOutputDebugString("Downloading BIN file using parallel port.\r\n");
        pfnPlatformInit2 = NULL;
        pfnPreDownload   = ParallelPreDownload;
        pfnReadData      = ParallelPortRead;
        bEthLaunch       = FALSE;
        fRet             = TRUE;
    } else
    #endif // 0
#ifndef  EDB9307A
    if(OEMHDDDetect())
    {
        EdbgOutputDebugString("Downloading BIN file using Hard Drive/CF card.\r\n");
        pfnPlatformInit2 = OEMHDDPlatformInit;
        pfnPreDownload   = OEMHDDPreDownload;
        pfnReadData      = OEMHDDReadData;
        bEthLaunch       = FALSE;
        fRet             = TRUE;
    }
    else  
#endif
    {
*/
        EdbgOutputDebugString("Downloading BIN file using Ethernet.\r\n");
        pfnPlatformInit2 = OEMEthHardwareInit;
        pfnPreDownload   = OEMEthPreDownload;
        pfnReadData      = EbootEtherReadData;

        //
        // This tells the kernel to connect to the ethernet debugger.
        //
        pDriverGlobals->eth.EbootMagicNum = EBOOT_MAGIC_NUM;
        bEthLaunch       = TRUE;
        fRet             = TRUE;
//    }


    //
    // Initialize ethernet.
    //
    if(pfnPlatformInit2)
        pfnPlatformInit2();


    return(fRet);
}

//****************************************************************************
// OEMPreDownload
//****************************************************************************
// Sets up a device before a download.
// 
// Return BL_ERROR, BL_JUMP,  BL_DOWNLOAD
// 
DWORD OEMPreDownload()
{
    DWORD   dwReturnValue = BL_ERROR;

    //
    // Read the data in from the device.
    //
    if(pfnReadData)
        dwReturnValue = pfnPreDownload();

    return dwReturnValue;    
}


⌨️ 快捷键说明

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