?? main.c.bak
字號:
//
// 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.
//
/*++
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.
Portions Copyright (c) 2001 Intel Corporation
Module Name:
main.c
Abstract:
Ethernet boot loader main module. This file contains the C main
for the boot loader.
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.
Functions:
--*/
#include <windows.h>
#include <ethdbg.h>
#include "halether.h"
#include <nkintr.h>
#include <pehdr.h>
#include <romldr.h>
#include "ethdown.h"
#if defined ( RTECH_FLAG )
#include "monitor.h"
#endif
#define BIN_FILE_TYPE 1
#define NB0_FILE_TYPE 2
#define BOOTLOADER 4
#define NKBIN 8
#define FLASHTARGET 16
#define _Vertification_ 0
#define BOOT_LOADER // To avoid including debug ethernet support
#include "..\..\kernel\hal\debug.c"
extern BOOL SDdetect();
extern int sddownload;
extern void Launch(unsigned int uAddr);
extern void Launch2(unsigned int uAddr);
extern msWait(unsigned msVal);
extern DWORD dwPhysStart; // image physical starting address
extern DWORD dwPhysLen; // image physical length
#if defined ( RTECH_FLAG)
#define EBOOT_IMAGE_START 0x80078000
#define FLASH_START BOOT_FLASH_BASE_U_VIRTUAL
DWORD dwFlashCache;
extern DWORD dwEBOOT_OFFSET;
#endif
extern DWORD fileType;
extern DWORD v_PacketNum;
//
// Function pointers to the support library functions of the currently installed debug ethernet controller.
//
extern PFN_EDBG_INIT pfnEDbgInit;
extern PFN_EDBG_ENABLE_INTS pfnEDbgEnableInts;
extern PFN_EDBG_DISABLE_INTS pfnEDbgDisableInts;
extern PFN_EDBG_GET_PENDING_INTS pfnEDbgGetPendingInts;
extern PFN_EDBG_GET_FRAME pfnEDbgGetFrame;
extern PFN_EDBG_SEND_FRAME pfnEDbgSendFrame;
extern PFN_EDBG_READ_EEPROM pfnEDbgReadEEPROM;
extern PFN_EDBG_WRITE_EEPROM pfnEDbgWriteEEPROM;
extern PFN_EDBG_SET_OPTIONS pfnEDbgSetOptions;
#define pDriverGlobals ((PDRIVER_GLOBALS) DRIVER_GLOBALS_PHYSICAL_MEMORY_START)
// Constants that control operation of bootloader. All times in seconds
#define BOOTME_INTERVAL 3 // Interval between BOOTMEs
#define MAX_BOOTME_CNT 25
// Well known DHCP ports for use with UDP
#define DHCP_SERVER_PORT 0x4300
#define DHCP_CLIENT_PORT 0x4400
// Name of platform and base for device name in Eshell
#define PLATFORM_STRING "XSC1BD"
// CPU Id for Eshell
//#define EDBG_CPUID EDBG_CPU_XSC1
#define EDBG_CPUID EDBG_CPU_TYPE_ARM
#define EBOOT_VERSION_MAJOR 1
#define EBOOT_VERSION_MINOR 0
const unsigned char EBOOT_VERSION_EXT[] = {" v2.00-hjg"};
const unsigned char NKSignon[] = {
"\nMicrosoft Windows CE Ethernet Bootloader built "
__DATE__ " " __TIME__ "\n"
"Copyright (c) 2001 Microsoft Corporation\n"
"Portions copyright (c) 2001 Intel Corporation\n"};
ROMHDR RomHdr; // ROM Table of Contents
static BYTE FrameBuffer[ETHER_MTU];
extern DWORD dwLaunchAddr;
extern DWORD VerifyCheckSum(void);
DWORD EdbgDebugZone;
extern DWORD dwOffset;
ROMHDR * volatile const pTOC = (ROMHDR *)-1; // Gets replaced by RomLoader with real address
void KernelRelocate(ROMHDR *const pTOC);
extern UINT EdeviceInit(EDBG_ADDR *MyAddr);
extern int InitSpecifiedEthDevice(EDBG_ADDR *MyAddr, UINT EthDevice);
typedef volatile unsigned int *VPDWORD;
unsigned int ulRamBufStart; // starting address of available RAM
unsigned int ulRamBufEnd; // ending address of available RAM
extern void InitClock(void);
//
// Move all writeable data sections into RAM
//
// Relocate the kernel
void KernelRelocate(ROMHDR *const pTOC)
{
ULONG loop;
COPYentry *cptr;
//
//volatile BLR_REGS *BLR = (BLR_REGS *)FPGA_REGS_BASE_U_VIRTUAL;
#if _Vertification_
//BLR->hex_led = 0x90908080;
while ((OEMReadDebugByte() == OEM_DEBUG_READ_NODATA));
#endif
if (pTOC == (ROMHDR *const) 0xffffffff) {
while (1) ; // spin forever!
}
#if _Vertification_
//BLR->hex_led = 0x80808080;
while ((OEMReadDebugByte() == OEM_DEBUG_READ_NODATA));
//BLR->hex_led = pTOC->ulCopyEntries;
while ((OEMReadDebugByte() == OEM_DEBUG_READ_NODATA));
//BLR->hex_led = pTOC->ulCopyOffset;
while ((OEMReadDebugByte() == OEM_DEBUG_READ_NODATA));
#endif
// This is where the data sections become valid... don't read globals until after this
for (loop = 0; loop < pTOC->ulCopyEntries; loop++) {
cptr = (COPYentry *)(pTOC->ulCopyOffset + loop*sizeof(COPYentry));
//
#if _Vertification_
//BLR->hex_led = cptr->ulDest;
while ((OEMReadDebugByte() == OEM_DEBUG_READ_NODATA));
//BLR->hex_led = cptr->ulSource;
while ((OEMReadDebugByte() == OEM_DEBUG_READ_NODATA));
//BLR->hex_led = cptr->ulCopyLen;
while ((OEMReadDebugByte() == OEM_DEBUG_READ_NODATA));
#endif
//
if (cptr->ulCopyLen)
memcpy((LPVOID)cptr->ulDest,(LPVOID)cptr->ulSource,cptr->ulCopyLen);
if (cptr->ulCopyLen != cptr->ulDestLen)
memset((LPVOID)(cptr->ulDest+cptr->ulCopyLen),0,cptr->ulDestLen-cptr->ulCopyLen);
}
}
#define IPSTATE_NONE 0
#define IPSTATE_GOTIP 1
#define IPSTATE_ARP 2
#define IPSTATE_ARPED 3
#define IPSTATE_RETRY 4
#define MAX_DHCP_RETRY 3
#define NONE -1
#if defined ( ORGEBOOT_FLAG )
#define RAM_IMAGE_START 0x8008D000
#else
#define RAM_IMAGE_START 0x800C0000
#endif
#define FLASH_CFG_START (BOOT_FLASH_BASE_U_VIRTUAL+0x00040000)
#define EbootCFGMagicNumber 0x11232000
#define DEVICE_PCMCIA 0
#define DEVICE_CF 1
#define DEVICE_SMSC 2
typedef struct
{
DWORD autoDownloadImage;
DWORD IP;
DWORD subnetMask;
DWORD numBootMe;
DWORD delay;
DWORD DHCPEnable;
DWORD bootDeviceOrder;
DWORD dwLaunchAddr;
DWORD ConfigMagicNumber;
} EBOOTCFG;
int StoreEBootCFG(EBOOTCFG *EBootCFG);
int LoadEBootCFG(EBOOTCFG *EBootCFG);
void ResetFactoryDefaultCFG(EBOOTCFG *EBootCFG);
void SetIP(EBOOTCFG *pEbootCFG);
void SetMask(EBOOTCFG *pEbootCFG);
void SetBootMe(EBOOTCFG *pEbootCFG);
void SetDelay(EBOOTCFG *pEbootCFG);
#if defined ( PLAT_LUBBOCK )
void SetSMSCMACAddress();
void CvtMAC(USHORT MacAddr[3], char *pszDottedD );
extern void SMCSetMACAddress(USHORT MacAddr[3]);
extern void SMCGetMACAddress(USHORT MacAddr[3]);
#endif
extern void LCD_Initialize (void); // add hjg
BOOL CFGChanged=FALSE;
extern void ClearPromiscuousIP( void );
BOOL bLinkEstablished = FALSE;
#if defined ( RTECH_FLAG )
BOOL bEbootExternalDown = FALSE;
DWORD fWriteToFlash;
#endif
void main(void)
{
EDBG_ADDR MyAddr;
DWORD dwSubnetMask;
DWORD dwStartTime;
DWORD dwCurrTime;
DWORD dwPrevTime;
DWORD selection;
DWORD delay;
BOOL fGotJumpimg = FALSE, fGotIP = FALSE;
DWORD dwIPState = IPSTATE_NONE;
EDBG_ADDR EshellHostAddr = {0,0,0};
EDBG_OS_CONFIG_DATA *pCfgData;
DWORD dwNextBootme=0; // Time of next bootme
UCHAR BootmeCnt=0; // # of bootmes sent so far
int DHCPRetry=0;
DWORD DHCPLeaseTime;
DWORD EdbgFlags = 0;
UINT ethernet_device;
LPDWORD lpdwToc; // toc pointer
int i,j;
volatile GPIO_REGS *v_pGPIOReg;
volatile PWM_REGS *v_pPWM0Reg = NULL;//houjg add
volatile PWM_REGS *v_pPWM1Reg = NULL;//houjg add
volatile CLKMAN_REGS *v_pCLKReg = NULL;//houjg add
volatile SA2lcdregs *v_pLcdRegs = NULL;// houjg add
#if defined ( RTECH_FLAG )
DWORD dwFlashStart;
UINT16 MonitorFlag = 0;
#endif
SYSTEMTIME st;
SYSTEMTIME defst = {1998,1,0,1,12,0,0,0};
EBOOTCFG EbootCFG;
EBOOTCFG *pEbootCFG;
// This table describes the boot order for a given configuration
int bootOrder[] = {DEVICE_SMSC,DEVICE_PCMCIA,DEVICE_CF, //pEbootCFG->bootDeviceOrder = 0
DEVICE_SMSC,DEVICE_CF,DEVICE_PCMCIA, //pEbootCFG->bootDeviceOrder = 1
DEVICE_PCMCIA,DEVICE_CF,DEVICE_SMSC, //pEbootCFG->bootDeviceOrder = 2
DEVICE_PCMCIA,DEVICE_SMSC,DEVICE_CF, //pEbootCFG->bootDeviceOrder = 3
DEVICE_CF,DEVICE_SMSC,DEVICE_PCMCIA, //pEbootCFG->bootDeviceOrder = 4
DEVICE_CF,DEVICE_PCMCIA,DEVICE_SMSC}; //pEbootCFG->bootDeviceOrder = 5
#if defined ( PLAT_LUBBOCK )
//int x,y,z;
// volatile BLR_REGS *BLR = (BLR_REGS *)FPGA_REGS_BASE_U_VIRTUAL; //add by houjg ,wait for fpga registers
#endif
/* Copy kernel data to RAM & zero out BSS */
KernelRelocate(pTOC);
OEMInitDebugSerial(); //why no for xsacle 's init program
{
volatile PMEMC pMemCtrlRegs = (volatile PMEMC)MEMC_BASE_U_VIRTUAL;
EdbgOutputDebugString("MSC0=0x%x, MSC1=0x%x, MSC2=0x%x\r\n",
pMemCtrlRegs->msc0,
pMemCtrlRegs->msc1,
pMemCtrlRegs->msc2);
EdbgOutputDebugString("0x%x\r\n", *(volatile UINT16 *)(0xBF900300+14));
}
#if defined ( PLAT_LUBBOCK )
//BLR->hex_led = 0x80808080;
#endif
//EdbgOutputDebugString(NKSignon);
EdbgOutputDebugString("Test...\r\n");
EdbgOutputDebugString("Boot Loader, Version %s\r\n", EBOOT_VERSION_EXT);
#ifndef SABINAL
// Temporarily clear RAM here. fwxsc1.s will soon be modified to do this.
EdbgOutputDebugString("Clearing RAM ... \r\n");
memset((LPVOID)RAM_IMAGE_START, 0x0, 0x3eb5000);
EdbgOutputDebugString("Complete!\r\n");
#endif
v_pGPIOReg = (volatile GPIO_REGS *)GPIO_BASE_U_VIRTUAL;
v_pPWM1Reg = (volatile PPWM1_REGS)PWM1_BASE_U_VIRTUAL;
v_pPWM0Reg = (volatile PPWM0_REGS)PWM0_BASE_U_VIRTUAL;
v_pCLKReg = (volatile PCLKMAN_REGS)CLK_BASE_U_VIRTUAL;
v_pGPIOReg->GPCR_x |= GPIO_4;
v_pGPIOReg->GPDR_x |= GPIO_4; // set output mode
v_pGPIOReg->GPCR_x |= GPIO_5;
v_pGPIOReg->GPDR_x |= GPIO_5; // set output mode
for( i=0;i<20;i++) //add by houjg flash led 20 times
{
v_pGPIOReg->GPCR_x |= GPIO_4;
v_pGPIOReg->GPSR_x |= GPIO_5;
msWait(50);
v_pGPIOReg->GPSR_x |= GPIO_4;
v_pGPIOReg->GPCR_x |= GPIO_5;
msWait(50);
}
// v_pGPIOReg->GPSR_x |= GPIO_21;
// v_pGPIOReg->GPDR_x |= GPIO_21;
#if defined ( PLAT_LUBBOCK )
//BLR->hex_led = 0;
#endif
// init RomHdr
memset((LPVOID)&RomHdr,-1,sizeof(ROMHDR));
// Initialize driver globals area, so kernel knows we are present
memset((LPVOID)&pDriverGlobals->eth,0,DBG_ETH_GLOBALS_SIZE);
EdbgOutputDebugString("DriverGlobal address = 0x%X\r\n", pDriverGlobals);
pDriverGlobals->eth.EbootMagicNum = EBOOT_MAGIC_NUM;
pDriverGlobals->eth.EbootDevice = BOOT_DEVICE_NONE;
InitClock();
//add by houjg
EdbgOutputDebugString("LCD_Initialize... \r\n");
LCD_Initialize();
EdbgOutputDebugString ( "PWM1 CLOCK and LCD BACK On \r\n");
v_pCLKReg->cken |= 0x00000002; // PWM1 clock enabled // LCD BACK ON
v_pPWM0Reg->pwcr = 0x00;//64;
v_pPWM0Reg->pwdr = 0x9f;//20;
v_pPWM0Reg->pwpr = 0xff;//40;
OEMGetRealTime(&st);
#ifndef SABINAL
//
// Do not perform menu services for Sabinal
//
pEbootCFG = &EbootCFG;
LoadEBootCFG(pEbootCFG);
MyAddr.dwIP = pEbootCFG->IP;
dwSubnetMask = pEbootCFG->subnetMask;
delay = pEbootCFG->delay;
delay = 10;
EdbgOutputDebugString ( "Press On/Off button before reset to enter Boot Loader's Selection Menu,\r\n");
EdbgOutputDebugString ( "and please keep On/Off Button pressed at least 10 seconds...\r\n");
EdbgOutputDebugString ( "\r\nPress [ENTER] to download now or [SPACE] to cancel.\r\n");
EdbgOutputDebugString ( "Else, Boot Loader will launch OS image whinch exists in Flash.\r\n");
dwStartTime = OEMEthGetSecs();
dwPrevTime = dwStartTime;
dwCurrTime = dwStartTime;
//selection = 'L';
while((dwCurrTime - dwStartTime) <delay)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -