oemmain.c
来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 346 行
C
346 行
/*++
Copyright (c) 1997 Microsoft Corporation
Module Name:
oemmain.c
Abstract:
Author:
Revision History:
--*/
#include <windows.h>
#include <halether.h>
#include <nkintr.h>
#include <alt_def.h>
#include <eglobal.h>
#include <oalio.h>
#include <romdef.h>
#include "bootldr.h"
#include <ether.h>
#include "pciinit.h"
#include "firmware.h"
#include "workitem.h"
#define BACKSPACE 0x08
// three function pointers for transports (pre-download, read-data, and launch)
DWORD (* pfnPreDownload) ();
void (* pfnLaunch) (DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr, const ROMHDR *pRomHdr);
BOOL (* pfnReadData) (DWORD cbData, LPBYTE pbData);
BOOL EbootEtherReadData(DWORD cbData, LPBYTE pbData);
void FwMonitor(DWORD* RegTblBase, DWORD Cause);
void GetStringFromSerial(PUCHAR pBuffer, USHORT nLen);
VOID UpdateFlashMACData(PUSHORT pMAC);
BOOL DoGetMac(PUSHORT pMAC);
BOOL WatchForBootHalt(void);
VOID WriteLED(UCHAR ucCode)
{
WRITE_PORT_UCHAR((PUCHAR)(KSEG1_BASE + LED_BASE), ucCode);
}
UCHAR ReadSwitches(VOID)
{
return READ_PORT_UCHAR((PUCHAR)(KSEG1_BASE + DIP_SWITCH_BASE));
}
VOID EnableFlash(VOID)
{
UCHAR uDips;
uDips = ReadSwitches();
if(!(uDips & 0x04)){
EdbgOutputDebugString("PUT S1-SW3 IN TO OFF POSITION TO WRITE TO FLASH!!!\r\n");
return;
}
WRITE_PORT_UCHAR((PUCHAR)(KSEG1_BASE + CONTROL_REG_BASE), 0x01);
}
VOID DisableFlash(VOID)
{
WRITE_PORT_UCHAR((PUCHAR)(KSEG1_BASE + CONTROL_REG_BASE), 0x00);
}
CHAR GetCharFromSerial(void)
{
CHAR ch;
while(1)
{
ch = OEMReadDebugByte();
if ((ch != OEM_DEBUG_COM_ERROR) && (ch != OEM_DEBUG_READ_NODATA))
break;
}
return ch;
}
void GetStringFromSerial(PUCHAR pBuff, USHORT nLen)
{
int nChar=0;
USHORT nCount=0;
do
{
while((nChar = OEMReadDebugByte()) == OEM_DEBUG_READ_NODATA)
{
;
}
if (nChar == OEM_DEBUG_COM_ERROR)
return;
if (nChar == BACKSPACE && nCount)
{
OEMWriteDebugByte((UCHAR)BACKSPACE);
OEMWriteDebugByte((UCHAR)' ');
OEMWriteDebugByte((UCHAR)BACKSPACE);
--nCount;
}
else if ((UCHAR)nChar != '\n' && (UCHAR)nChar != '\r')
{
*(pBuff + nCount) = (UCHAR)nChar;
++nCount;
OEMWriteDebugByte((UCHAR)nChar);
}
}
while(nCount < (nLen - 1) && (UCHAR)nChar != '\n' && (UCHAR)nChar != '\r');
*(pBuff + nCount) = '\0';
return;
}
BOOL OEMDebugInit (void)
{
OEMInitDebugSerial();
return TRUE;
}
BOOL OEMPlatformInit (void)
{
BOOL fInMenu = TRUE;
CHAR InChar;
if (!PciInit())
{
EdbgOutputDebugString ("PciInit Failed\r\n");
return FALSE;
}
// initialize clock
if (!InitCounter ()) {
EdbgOutputDebugString ("InitCounter Failed\r\n");
return FALSE;
}
// Initialize driver globals area, so kernel knows we are present
memset(pDriverGlobals, 0, MAX_ETHER_GLOBAL_SIZE);
// test flash
if (!FlashInit ()) {
SPIN_FOREVER;
}
// Countdown timer - allow user to halt boot and enter menu...
if (!WatchForBootHalt())
{
if(EthInit())
{
pfnPreDownload = EthPreDownload;
pfnLaunch = EthLaunch;
pfnReadData = EbootEtherReadData;
fInMenu = FALSE;
}
else
EdbgOutputDebugString("\r\nERROR: Unable to initialize ethernet controller.\r\n\r\n");
}
while(fInMenu)
{
EdbgOutputDebugString( "\r\n\r\n" );
EdbgOutputDebugString( "Select from menu:\r\n" );
EdbgOutputDebugString( "\r\n" );
EdbgOutputDebugString( "[1|C] Load Windows CE via Ethernet\r\n" );
EdbgOutputDebugString( "[2|F] Load firmware to flash via Serial Debug (xmodem)\r\n" );
EdbgOutputDebugString( "[3|R] Run firmware monitor program\r\n" );
EdbgOutputDebugString( "[4|W] List PCI devices\r\n" );
EdbgOutputDebugString( "\r\n" );
InChar = GetCharFromSerial();
switch(InChar)
{
case '1':
case 'C':
case 'c':
if(EthInit())
{
pfnPreDownload = EthPreDownload;
pfnLaunch = EthLaunch;
pfnReadData = EbootEtherReadData;
fInMenu = FALSE;
break;
}
EdbgOutputDebugString("\r\nERROR: Unable to initialize ethernet controller.\r\n\r\n");
break;
case '2':
case 'F':
case 'f':
EdbgOutputDebugString("Flash Write is disabled. Do you want to enable it? (Y/N)");
InChar = GetCharFromSerial();
if( InChar != 'Y' && InChar != 'y')
break;
EnableFlash();
LoadFirmware();
DisableFlash();
EdbgOutputDebugString("*** REBOOTING ***\r\n");
JumpTo(KSEG1_BASE | PROM_BASE, (DWORD)NULL);
break;
case '3':
case 'r':
case 'R':
FwMonitor(NULL, USER_SELECT);
break;
case '4':
case 'W':
case 'w':
PciInitListDevices();
break;
// Hidden menu options...
case '=':
{
// show network information stored in flash
PDEVICE_NETWORK_INFO pDevNetworkInfo;
pDevNetworkInfo = (PDEVICE_NETWORK_INFO)(DEVICE_NETWORK_INFO_LOCATION);
// show IP address and subnet mask
if (pDevNetworkInfo->dwSignature == VALID_INFO_SIGNATURE)
{
EdbgOutputDebugString("IP Address = %s\n", inet_ntoa(pDevNetworkInfo->dwIP));
EdbgOutputDebugString("Subnet Mask = %s\n", inet_ntoa(pDevNetworkInfo->dwSubnetMask));
}
else
{
EdbgOutputDebugString("*** No IP address assigned\n");
}
// show MAC address
if (pDevNetworkInfo->dwMACSignature == VALID_MAC_ADDRESS)
{
ShowMACAddress((PBYTE)(pDevNetworkInfo->wMAC));
}
else
{
EdbgOutputDebugString("*** No MAC address assigned\n");
}
break;
}
case '+':
{
CHAR ch;
USHORT nMAC[3];
EdbgOutputDebugString("Flash Write is disabled. Do you want to enable it?(Y/N)\r\n");
ch = GetCharFromSerial();
if (ch !='Y' && ch !='y')
break;
EnableFlash();
if (DoGetMac(&nMAC[0]))
{
UpdateFlashMACData(&nMAC[0]);
EdbgOutputDebugString("MAC address successfully stored.\r\n");
}
else
EdbgOutputDebugString("MAC address not stored.\r\n");
DisableFlash();
}
break;
default:
break;
}
}
return TRUE;
}
DWORD OEMPreDownload (void)
{
return pfnPreDownload();
}
void OEMLaunch (DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr, const ROMHDR *pRomHdr)
{
pfnLaunch(dwImageStart, dwImageLength, dwLaunchAddr, pRomHdr);
}
BOOL OEMReadData (DWORD cbData, LPBYTE pbData)
{
return pfnReadData(cbData, pbData);
}
void OEMShowProgress (DWORD dwPacketNum)
{
// write to LED about the packet number
WriteLED((UCHAR)dwPacketNum);
}
BOOL WatchForBootHalt(void)
{
UCHAR nCount = 5; // Wait for 5 seconds...
ULONG nWait = 0;
while(nCount)
{
EdbgOutputDebugString("\rPress any key to break into configuration menu %d ...", nCount);
// A crude but simple way to wait...
for (nWait = 0 ; nWait < 0x30000 ; nWait++)
{
if (OEMReadDebugByte() != OEM_DEBUG_READ_NODATA)
{
return(TRUE);
}
}
--nCount;
}
EdbgOutputDebugString("\r\n");
return(FALSE);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?