//
// 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
volatile unsigned long *eth_base_