main.c

来自「该BSP是基于PXA270+WINCE的BSP」· C语言 代码 · 共 1,654 行 · 第 1/4 页

C
1,654
字号
//
// 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 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"

#define NUM_BOOT_ETHDEV  4
#define NUM_BOOT_ORDERS  4

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

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

static char* BootOrderString[NUM_BOOT_ORDERS] =
{
    "PCMCIA0 -> PCMCIA1 -> SMSC -> USB",
    "SMSC -> USB-> PCMCIA0 -> PCMCIA1",
    "USB -> SMSC -> PCMCIA0 -> PCMCIA1",
    "PCMCIA1 -> PCMCIA0 -> SMSC -> USB",
};

//------------------------------------------------------------------------------
// Global variables.
//
DWORD     EdbgDebugZone;
FlashInfo g_FlashInfo;
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;

extern BSP_ARGS *g_pBSPArgs;

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

static void SetMAC(unsigned char *mac);
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);

//================================================================================
UINT16 aMacV[3];

BYTE string2Hex(char* pszInput)
{
    BYTE high;
    BYTE low;
    if( ((*pszInput) >= '0') && ((*pszInput) <= '9') )    {
        high = (*pszInput) - '0';
    } else if( ((*pszInput) >= 'a') && ((*pszInput) <= 'f') )    {
        high = (*pszInput) - 'a' + 0xa;
    } else if( ((*pszInput) >= 'A') && ((*pszInput) <= 'F') )    {
        high = (*pszInput) - 'A' + 0xa;
    } else    {
        high = 0xff;
    }
    pszInput++;

    if( ((*pszInput) >= '0') && ((*pszInput) <= '9') )    {
        low = (*pszInput) - '0';
    } else if( ((*pszInput) >= 'a') && ((*pszInput) <= 'f') )    {
        low = (*pszInput) - 'a' + 0xa;
    } else if( ((*pszInput) >= 'A') && ((*pszInput) <= 'F') )    {
        low = (*pszInput) - 'A' + 0xa;
    } else    {
        low = 0xff;
    }

    return ((high << 4) + (low & 0xf));
}

//-----------------------------------------------------------------------------------
void SetSMSCMACAddr2Flash(EBOOT_CFG* pEbootCFG)
{
    char szDottedD[13]; // The string used to collect the dotted masks
    WORD cwNumChars = 0;
    UINT16 InChar = 0;
    USHORT MacAddr[3];

    EdbgOutputDebugString ( "\r\nEnter new MAC address (AABBCCDDEEFF): ");

    while (!((InChar == 0x0d) || (InChar == 0x0a))) {
        InChar = OEMReadDebugByte();
        if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) {
            if ( (InChar >= '0' && InChar <= '9') || 
                 (InChar >= 'a' && InChar <= 'f') ||
                 (InChar >= 'A' && InChar <= 'F') ) {
                if (cwNumChars <= 12) {
                    szDottedD[cwNumChars++] = (char)InChar;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            } else if (InChar == 8)	{	// If it's a backspace, back up
                if (cwNumChars > 0) {
                    cwNumChars--;
                    OEMWriteDebugByte((BYTE)InChar);
                }
            }
        }
    }

    if (cwNumChars == 12) {
        char temp1[3], temp2[3];
        int i;
        temp1[2] = temp2[2] = 0;
        szDottedD[cwNumChars] = '\0';

        for(i = 0; i < 3; i++) {
            memcpy(temp1, &szDottedD[i * 4 + 0], 2);
            memcpy(temp2, &szDottedD[i * 4 + 2], 2);
            MacAddr[i] = string2Hex(temp1) + string2Hex(temp2) * 0x100;
        }

        pEbootCFG->RNDISMac[0] = MacAddr[0];    
        pEbootCFG->RNDISMac[1] = MacAddr[1];
        pEbootCFG->RNDISMac[2] = MacAddr[2];

        EdbgOutputDebugString ( "\r\nMAC address programming complete.\r\n");
    }

	//write to EEPROM
	EdbgOutputDebugString ( "\r\n +MacAddr[0-1-2] %x,%x,%x\r\n",MacAddr[0],MacAddr[1],MacAddr[2]);
	
	#define NetchipBaseU 0xBA700000
	DM9000AInit_WriteMac(NetchipBaseU);
	DM9000AStoreMACAddress_1(MacAddr[0],0);// msWait(2);
	DM9000AStoreMACAddress_1(MacAddr[1],1);// msWait(2);
	DM9000AStoreMACAddress_1(MacAddr[2],2);// msWait(2);

}
//================================================================================

//================================================================================
BOOL DispSeted = 0;

BOOL  GetLongFromDebug(unsigned long *pVal)
{
	CHAR szCount[32];
	USHORT cwNumChars = 0;
	USHORT InChar = 0;
	BOOL bSuccess=FALSE;
	
	_ltoa(*pVal,szCount,10);
	EdbgOutputDebugString("%s",szCount);
	cwNumChars=strlen(szCount);
	while(!((InChar == 0x0d) || (InChar == 0x0a)))	{
		InChar = OEMReadDebugByte();
		if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA) 	{
			if ((InChar >= '0' && InChar <= '9')) 	{
				if (cwNumChars < 16) 	{
					szCount[cwNumChars++] = (char)InChar;
					OEMWriteDebugByte((BYTE)InChar);
				}
			}else if (InChar == 8) 	{
				if (cwNumChars > 0) 	{
					cwNumChars--;
					OEMWriteDebugByte((BYTE)InChar);
				}
			}
		}
	}
	if (cwNumChars) {
		szCount[cwNumChars] = '\0';
		bSuccess=TRUE;
		*pVal=atol(szCount);
	}
	return bSuccess;
}

//===============================================================================
void SetDisplayArgs( EBOOT_CFG *pEbootCFG)
{
	unsigned long val;

	unsigned short	CxScreen;	
	unsigned short	CyScreen;	
	unsigned short	Bpp;
	unsigned long	LCCR0;
	unsigned char	HSW;
	unsigned char	BLW;
	unsigned char	ELW;	
	unsigned char	VSW;
	unsigned char	BFW;
	unsigned char	EFW;
	unsigned char	PCD;
	unsigned long	LCCR3_OTHER;	//LCCR3 - PCD -BPP
	unsigned char	DoRotation;

	unsigned long 	myselect;
	unsigned long 	myval;
    DWORD selection;
	BOOL bSuccess;
//---------------
//CR    ox0d 13 '\r'
//LF    0x0a 10 '\n'
//space 0x20 32
//'Enter' to set parameter, "123" to select display device
	EdbgOutputDebugString("\r\n ");
	EdbgOutputDebugString("Press 'Enter' to continue\r\n ");

	selection = 0;
	myselect = 0;
	while (! ( (myselect == '\r') || (myselect == '1')  ))
		 myselect = OEMReadDebugByte();
	
	if ( myselect == 0x0d ) 	//'enter'
		goto setparameter;
	else if( myselect == '1' ) {
		myval = 0;
		bSuccess = GetLongFromDebug(&myval);
	}

	if( bSuccess && (myval==23) )	goto selectdevice;
	else							goto nochange;

selectdevice:		

	EdbgOutputDebugString("\r\n Select display device:\r\n ");
	EdbgOutputDebugString("---------------------------------------\r\n ");
	EdbgOutputDebugString(" 0)CRT \r\n ");
	EdbgOutputDebugString(" 1)LCD LQ64D343       640x480\r\n ");
	EdbgOutputDebugString(" 2)LCD LQ104V1DG61    640x480\r\n ");
	EdbgOutputDebugString(" 3)LCD PD064VTS       640x480\r\n ");
	EdbgOutputDebugString(" 4)LCD LTM035A776C    240x320\r\n ");
	EdbgOutputDebugString(" 5)LCD LS037V7DD03    480x640\r\n ");
	EdbgOutputDebugString(" 6)LCD LTV350QV-F05   240x320\r\n ");
	EdbgOutputDebugString(" 7)LCD SVGA           800x600\r\n ");
	EdbgOutputDebugString(" 8)LCD EL320x240.36HB \r\n ");
	EdbgOutputDebugString(" 9)LCD EL320x256-fd6  \r\n ");
	EdbgOutputDebugString("---------------------------------------\r\n ");
	EdbgOutputDebugString("\r\nEnter your selection: ");

	while (! ( ( (selection >= '0') && (selection <= '9') ) || (selection == '\r') )) {
		selection = OEMReadDebugByte();
	}
	EdbgOutputDebugString ( "%c\r\n", selection);

	switch (selection)	{
		default :
		case '0':	//CRT
			CxScreen 	= 640;
			CyScreen 	= 480;
			Bpp 		= 16;
			LCCR0		= 3148024;
			HSW			= 48;
			BLW			= 100;
			ELW			= 63;
			VSW			= 7;
			BFW			= 26;
			EFW			= 35;
			PCD			= 1;
			LCCR3_OTHER	= 7340032;
			DoRotation	= 0;
		break;

		case '1':	//LQ64D343
		case '2':	//LQ104V1DG61
		case '3':	//PD064VTS
			CxScreen 	= 640;
			CyScreen 	= 480;
			Bpp 		= 16;
			LCCR0		= 3148024;
			HSW			= 63;
			BLW			= 104;
			ELW			= 56;
			VSW			= 1;
			BFW			= 32;
			EFW			= 0;
			PCD			= 1;
			LCCR3_OTHER	= 7340032;
			DoRotation	= 0;
		break;

		case '4':	//LTM035A776C
			CxScreen 	= 240;
			CyScreen 	= 320;
			Bpp 		= 16;
			LCCR0		= 128977144;
			HSW			= 4;
			BLW			= 5;
			ELW			= 4;
			VSW			= 2;
			BFW			= 5;
			EFW			= 3;
			PCD			= 10;
			LCCR3_OTHER	= 4194304;
			DoRotation	= 0;
		break;

		case '5':	//LS037V7DD03 
			CxScreen 	= 480;
			CyScreen 	= 640;
			Bpp 		= 16;
			LCCR0		= 3148024;
			HSW			= 63;
			BLW			= 78;
			ELW			= 30;
			VSW			= 1;
			BFW			= 2;
			EFW			= 0;
			PCD			= 1;
			LCCR3_OTHER	= 7340032;
			DoRotation	= 0;
		break;

		case '6':	//LTV350QV-F05
			CxScreen 	= 320;
			CyScreen 	= 240;
			Bpp 		= 16;
			LCCR0		= 128977144;
			HSW			= 15;
			BLW			= 16;
			ELW			= 2;
			VSW			= 10;
			BFW			= 1;
			EFW			= 20;
			PCD			= 6;
			LCCR3_OTHER	= 3145728;
			DoRotation	= 0;
		break;

		case '7':	//SVGA 800x600
			CxScreen 	= 800;
			CyScreen 	= 600;
			Bpp 		= 16;
			LCCR0		= 3148024;
			HSW			= 48;
			BLW			= 170;
			ELW			= 40;
			VSW			= 7;
			BFW			= 23;
			EFW			= 37;
			PCD			= 1;
			LCCR3_OTHER	= 67174144;
			DoRotation	= 0;
		break;

		case '8':	//EL320x240.36HB
			CxScreen 	= 640;
			CyScreen 	= 480;
			Bpp 		= 16;
			LCCR0		= 128977018;
			HSW			= 10;
			BLW			= 20;
			ELW			= 180;
			VSW			= 10;
			BFW			= 40;
			EFW			= 120;
			PCD			= 6;
			LCCR3_OTHER	= 6291456;
			DoRotation	= 0;
		break;

		case '9':	//EL320x256-fd6
			CxScreen 	= 320;
			CyScreen 	= 256;
			Bpp 		= 16;
			LCCR0		= 3148024;
			HSW			= 60;
			BLW			= 10;
			ELW			= 0;
			VSW			= 20;
			BFW			= 0;
			EFW			= 10;
			PCD			= 6;
			LCCR3_OTHER	= 7340032;
			DoRotation	= 0;
		break;
	}//end of switch		

⌨️ 快捷键说明

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