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

📄 eth.c

📁 Windows CE 6.0 BSP for the Beagle Board.
💻 C
字号:
//
// 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.
//
//------------------------------------------------------------------------------
//
//  File:  eth.c
//
//  This file implements bootloader functions related to ethernet download
//  
#include <eboot.h>

//------------------------------------------------------------------------------
//
//  Static: g_ethState
//
//  This structure contains local state variables.
//
static struct {
    EDBG_ADDR edbgAddress;
    OAL_KITL_ETH_DRIVER *pDriver;
    UINT8 buffer[OAL_KITL_BUFFER_SIZE];
} g_ethState;

//------------------------------------------------------------------------------
//
//  Function:  BLEthDownload
//
//  This function initialize ethernet adapter and call download function from
//  bootloader common library.
//
UINT32 BLEthDownload(BOOT_CFG *pConfig, OAL_KITL_DEVICE *pBootDevices, UINT16 *pMac)
{
    UINT32 rc = BL_ERROR;
//    CPLD_REGS *pCPLDRegs;
    OAL_KITL_DEVICE *pDevice;
    UINT32 subnetMask, *pLeaseTime, leaseTime = 0;
    BOOL jumpToImage = FALSE;
    UINT8 deviceId[OAL_KITL_ID_SIZE];

    // We have to do device initialization for some devices
    switch (pConfig->bootDevLoc.IfcType) {
    //case Internal:
    //    switch (pConfig->bootDevLoc.LogicalLoc) {
    //    case BSP_SMSC91C96_REGS_PA:
    //        // Reset network chip
    //        pCPLDRegs = OALPAtoUA(BSP_CPLD_REGS_PA);
    //        OUTREG8(&pCPLDRegs->LANCTL, 1);
    //        OALStall(500);
    //        OUTREG8(&pCPLDRegs->LANCTL, 0);
    //        OALStall(500);
    //        break;
    //    }
        break;
    }

    // Find boot/KITL device driver
    pDevice = OALKitlFindDevice(&pConfig->bootDevLoc, pBootDevices);        
    if (pDevice == NULL || pDevice->type != OAL_KITL_TYPE_ETH) {
        OALMSG(OAL_ERROR, (
            L"ERROR: Boot device doesn't exist or it is unsupported\r\n"
        ));
        goto cleanUp;
    }
    
    // Get device driver
    g_ethState.pDriver = (OAL_KITL_ETH_DRIVER*)pDevice->pDriver;
    
    // Call InitDmaBuffer if there is any
    if (g_ethState.pDriver->pfnInitDmaBuffer != NULL) {
        if (!g_ethState.pDriver->pfnInitDmaBuffer(
            (UINT32)g_ethState.buffer, sizeof(g_ethState.buffer)
        )) {
            OALMSG(OAL_ERROR, (L"ERROR: "
                L"Boot device driver InitDmaBuffer call failed\r\n"
            ));
            goto cleanUp;
        }
    }      

    // Call Init
    if (!g_ethState.pDriver->pfnInit(
        pConfig->bootDevLoc.PhysicalLoc, pConfig->bootDevLoc.LogicalLoc, pMac
    )) {
        OALMSG(OAL_ERROR, (L"ERROR: "
            L"Boot device driver Init call failed\r\n"
        ));
        goto cleanUp;
    }         

    OALMSG(OAL_INFO, (L"INFO: "
        L"Boot device uses MAC %s\r\n", OALKitlMACtoString(pMac)
    ));

    // Generate device name
    OALKitlCreateName(BSP_DEVICE_PREFIX, pMac, deviceId);
    OALMSG(OAL_INFO, (L"INFO: "
        L"*** Device Name %S ***\r\n", deviceId
    ));

    // Initialize ethernet
    memset(&g_ethState.edbgAddress, 0, sizeof(g_ethState.edbgAddress));

    // Set lease time pointer to activate DHCP or update global structure
    if ((pConfig->kitlFlags & OAL_KITL_FLAGS_DHCP) != 0) {
       pLeaseTime = &leaseTime;
    } else {
       pLeaseTime = NULL;
       g_ethState.edbgAddress.dwIP = pConfig->ipAddress;
    }
    memcpy(
        g_ethState.edbgAddress.wMAC, pMac, sizeof(g_ethState.edbgAddress.wMAC)
    );
    subnetMask = 0xFFFFFF;
       
    // Initialize TFTP transport
    // Note that first parameter must be pointer to global variable...
    if (!EbootInitEtherTransport(
       &g_ethState.edbgAddress, &subnetMask, &jumpToImage, pLeaseTime,
       EBOOT_VERSION_MAJOR, EBOOT_VERSION_MINOR, BSP_DEVICE_PREFIX, 
       deviceId, EDBG_CPU_TYPE_ARM|0x0F, 0
    )) {
       OALMSG(OAL_ERROR, (L"ERROR: EbootInitEtherTransport call failed\r\n"));
       goto cleanUp;
    }
    OALMSG(1, (L"EbootInitEtherTransport Done\r\n"));

    // If DHCP was used update lease time and address
    if (pLeaseTime != NULL) pConfig->ipAddress = g_ethState.edbgAddress.dwIP;

    // Depending on what we get from TFTP
    rc = jumpToImage ? BL_JUMP : BL_DOWNLOAD;

cleanUp:
    return rc;
}

//------------------------------------------------------------------------------
//
//  Function:  BLEthConfig
//
//  This function receives connect message from host and it updates arguments
//  based on it. Most part of connect message isn't used by KITL anymore, but
//  we want set passive KITL mode when no-KITL is select on PB.
//
VOID BLEthConfig(BSP_ARGS *pArgs)
{
    EDBG_OS_CONFIG_DATA *pConfig;

    // Get host connect info
    pConfig = EbootWaitForHostConnect(&g_ethState.edbgAddress, NULL);

    pArgs->kitl.flags &= ~OAL_KITL_FLAGS_PASSIVE;
    if ((pConfig->KitlTransport & KTS_PASSIVE_MODE) != 0) {
        pArgs->kitl.flags |= OAL_KITL_FLAGS_PASSIVE;
    }        
}

//------------------------------------------------------------------------------
//
//  Function:  OEMEthGetFrame
//
//  Check to see if a frame has been received, and if so copy to buffer.
//  An optimization  which may be performed in the Ethernet driver is to 
//  filter out all received broadcast packets except for ARPs.
//
BOOL OEMEthGetFrame(BYTE *pData, UINT16 *pLength)
{
    return g_ethState.pDriver->pfnGetFrame(pData, pLength) > 0;
}


//------------------------------------------------------------------------------
//
//  Function:  OEMEthSendFrame
//
//  Send Ethernet frame.  
//
BOOL OEMEthSendFrame(BYTE *pData, DWORD length)
{
    return g_ethState.pDriver->pfnSendFrame(pData, length) == 0;
}


////------------------------------------------------------------------------------
////
////  Function:   OEMReadData
////
////  This function is called to read data from the transport during
////  the download process.
////
//BOOL OEMReadData(ULONG size, UCHAR *pData)
//{
//    // Save read data size and location. It is used in workaround
//    // for download BIN DIO images larger than RAM.
//    g_eboot.readSize = size;
//    g_eboot.pReadBuffer = pData;
//
//    return EbootEtherReadData(size, pData);
//}
//
////------------------------------------------------------------------------------

//VOID OALKitlCreateName(CHAR *pPrefix, UINT16 mac[3], CHAR *pBuffer)
//{
//    UINT32 code=0, count, d;
//    INT32 j;
//    OMAP3_DEVICE_DIEID_REGS *pDevIdRegs = OALPAtoUA(OMAP3_DEVICE_DIEID_REGS_PA);
//
//    OALMSG(OAL_KITL&&OAL_FUNC, (
//        L"+OALKitlCreateName('%hs', 0x%04x:0x%04x:0x%04x, 0x%08x)\r\n", pPrefix, mac[0],mac[1],mac[2], pBuffer
//    ));
//
//    // Copy prefix    
//    count = 0;
//    while (count < OAL_KITL_ID_SIZE - 1 && pPrefix[count] != '\0') {
//        pBuffer[count] = pPrefix[count];
//        count++;
//    }
//
//    // Create unique part of name from SoC ID
//    code  = INREG32(&pDevIdRegs->ulDIE_ID_0);
//    code ^= INREG32(&pDevIdRegs->ulDIE_ID_1);
//    code ^= INREG32(&pDevIdRegs->ulDIE_ID_2);
//    code ^= INREG32(&pDevIdRegs->ulDIE_ID_3);
//
//    // Convert it to hexa number    
//    for (j = 28; j >= 0 && count < OAL_KITL_ID_SIZE - 1; j -= 4) {
//        d = (code >> j) & 0xF;
//        pBuffer[count++] = d < 10 ? '0' + d : 'A' + d - 10;
//    }
//    pBuffer[count] = '\0';
//
//    OALMSG(OAL_KITL&&OAL_FUNC, (
//        L"-OALKitlCreateName(pBuffer = '%hs')\r\n", pBuffer
//    ));
//}
//
//------------------------------------------------------------------------------

⌨️ 快捷键说明

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