📄 main.c
字号:
{
UINT16 inChar;
EdbgOutputDebugString("\r\nDo you want to use DHCP? [Y/n] ");
do {
inChar = OEMReadDebugByte();
} while ((inChar!=0x0d) &&
(inChar!=0x0a) &&
(inChar!='y') &&
(inChar!='Y') &&
(inChar!='n') &&
(inChar!='N'));
if ((inChar==0x0d) || (inChar==0x0a))
inChar = 'Y';
else if (inChar == 'y')
inChar = 'Y';
if (inChar=='Y')
{
pEbootCFG->DHCPEnable = TRUE;
return;
}
pEbootCFG->DHCPEnable = FALSE;
EdbgOutputDebugString("\r\nCurrent IP Address is: %s\r\n",inet_ntoa(pEbootCFG->IP));
EdbgOutputDebugString("Current Subnet Mask is: %s\r\n",inet_ntoa(pEbootCFG->subnetMask));
SetIP(pEbootCFG);
SetMask(pEbootCFG);
}
static void SetIP(EBOOT_CFG *pEbootCFG)
{
char szDottedD[16]; // The string used to collect the dotted decimal IP address
WORD cwNumChars = 0;
UINT16 InChar = 0;
EdbgOutputDebugString ( "\r\nEnter new IP address: ");
while (!((InChar == 0x0d) || (InChar == 0x0a) || (InChar == 0x1b)))
{
InChar = OEMReadDebugByte();
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
// If it's a number or a period, add it to the string
if (InChar == '.' || (InChar >= '0' && InChar <= '9'))
{
if (cwNumChars < 16)
{
szDottedD[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
// If it's a backspace, back up
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
if (cwNumChars)
{
szDottedD[cwNumChars] = '\0';
pEbootCFG->IP = inet_addr( szDottedD );
}
}
static void SetMask(EBOOT_CFG *pEbootCFG)
{
char szDottedD[16]; // The string used to collect the dotted masks
WORD cwNumChars = 0;
UINT16 InChar = 0;
EdbgOutputDebugString ( "\r\nEnter new subnet mask: ");
while (!((InChar == 0x0d) || (InChar == 0x0a) || (InChar == 0x1b)))
{
InChar = OEMReadDebugByte();
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
// If it's a number or a period, add it to the string
if (InChar == '.' || (InChar >= '0' && InChar <= '9'))
{
if (cwNumChars < 16)
{
szDottedD[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
// If it's a backspace, back up
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
if (cwNumChars)
{
szDottedD[cwNumChars] = '\0';
pEbootCFG->subnetMask = inet_addr( szDottedD );
}
}
static void CvtMAC(UINT16 MacAddr[3], char *pszDottedD )
{
DWORD cBytes;
char *pszLastNum;
int atoi (const char *s);
int i=0;
BYTE *p = (BYTE *)MacAddr;
// Replace the dots with NULL terminators
pszLastNum = pszDottedD;
for(cBytes = 0 ; cBytes < 6 ; cBytes++)
{
while(*pszDottedD != '-' && *pszDottedD != '\0')
{
pszDottedD++;
}
if (pszDottedD == '\0' && cBytes != 5)
{
// zero out the rest of MAC address
while(i++ < 6)
{
*p++ = 0;
}
break;
}
*pszDottedD = '\0';
*p++ = (BYTE)(hexstrtoul(pszLastNum,8) & 0xFF);
i++;
pszLastNum = ++pszDottedD;
}
}
static void SetMACAddress(EBOOT_CFG *pEbootCFG, UINT32 GumEthDevice)
{
CHAR szDottedD[24];
USHORT cwNumChars = 0;
USHORT InChar = 0;
UINT32 i;
memset(szDottedD, '0', 24);
EdbgOutputDebugString ( "\r\nEnter new MAC address in hexadecimal (hh-hh-hh-hh-hh-hh): ");
while(!((InChar == 0x0d) || (InChar == 0x0a)))
{
InChar = OEMReadDebugByte();
InChar = tolower(InChar);
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
// If it's a hex number or a period, add it to the string.
//
if (InChar == '-' || (InChar >= '0' && InChar <= '9') || (InChar >= 'a' && InChar <= 'f'))
{
if (cwNumChars < 17)
{
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);
}
}
}
}
EdbgOutputDebugString ( "\r\n");
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars)
{
szDottedD[cwNumChars] = '\0';
for (i=cwNumChars;i<24;i++)
{
szDottedD[i] = '\0';
}
if (GumEthDevice == 1)
CvtMAC(pEbootCFG->Eth1mac, szDottedD);
else
CvtMAC(pEbootCFG->Eth2mac, szDottedD);
}
else
{
EdbgOutputDebugString("WARNING: Invalid MAC address.\r\n");
}
}
// not used!
static void SetBootMe(EBOOT_CFG *pEbootCFG)
{
char szCount[16];
WORD cwNumChars = 0;
UINT16 InChar = 0;
EdbgOutputDebugString ( "\r\nUse 0 for continuous boot me packets. \r\n");
EdbgOutputDebugString ( "Enter maximum number of boot me packets to send [0-255]: ");
while (!((InChar == 0x0d) || (InChar == 0x0a) || (InChar == 0x1b)))
{
InChar = OEMReadDebugByte();
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
// If it's a number or a period, add it to the string
if ((InChar >= '0' && InChar <= '9'))
{
if (cwNumChars < 16)
{
szCount[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
// If it's a backspace, back up
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
if (cwNumChars)
{
szCount[cwNumChars] = '\0';
pEbootCFG->numBootMe = atoi(szCount);
if (pEbootCFG->numBootMe > 255)
{
pEbootCFG->numBootMe = 255;
}
else if (pEbootCFG->numBootMe < 0)
{
pEbootCFG->numBootMe = 1;
}
}
}
static void SetDelay(EBOOT_CFG *pEbootCFG)
{
char szCount[16];
WORD cwNumChars = 0;
UINT16 InChar = 0;
EdbgOutputDebugString ( "\r\nEnter maximum number of seconds to delay [1-255]: ");
while (!((InChar == 0x0d) || (InChar == 0x0a) || (InChar == 0x1b)))
{
InChar = OEMReadDebugByte();
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
// If it's a number or a period, add it to the string
if ((InChar >= '0' && InChar <= '9'))
{
if (cwNumChars < 16)
{
szCount[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
// If it's a backspace, back up
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
if (cwNumChars)
{
szCount[cwNumChars] = '\0';
pEbootCFG->delay = atoi(szCount);
if (pEbootCFG->delay > 255)
{
pEbootCFG->delay = 255;
}
else if (pEbootCFG->delay < 1)
{
pEbootCFG->delay = 1;
}
}
}
static void SetHardwareCFG(void)
{
char szDword[9]; // The string used to collect the dword
WORD cwNumChars = 0;
UINT16 InChar = 0;
OALMSG(1, (L"\r\nEnter new hardware configuration: 0x%08X->0x",g_EbootCFG.dwPlatformHardware));
while (!((InChar == 0x0d) || (InChar == 0x0a) || (InChar == 0x1b)))
{
InChar = OEMReadDebugByte();
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
// If it's a number or hex alpha, add it to the string
if ((InChar >= 'a' && InChar <= 'f') || (InChar >= '0' && InChar <= '9'))
{
if (cwNumChars < 8)
{
szDword[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
// If it's a backspace, back up
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
if (cwNumChars)
{
szDword[cwNumChars] = '\0';
g_EbootCFG.dwPlatformHardware = hexstrtoul( szDword,8 );
}
}
static BOOL DetectXMFlashDevice(UINT32 FlashBaseAddress)
{
UINT32 nDeviceID = 0;
volatile UINT16 *pFlash = (volatile UINT16 *)(FlashBaseAddress);
// Get the flash part ID.
//
*pFlash = 0x0090;
nDeviceID = (*(pFlash + 1) & 0xFFFF);
// Put the flash part in read array mode.
//
*pFlash = 0x00FF;
if (nDeviceID == FLASH_DEVICE_ID_XM)
return TRUE;
else
return FALSE;
}
static DWORD hexstrtoul(char *str, UINT32 len)
{
DWORD val;
UINT32 i;
char c1;
val=0;
for(i=0;i<len;i++) {
if(*str=='\0') break;
c1=*str++;
if(c1>='A' && c1<='F') c1=(c1-'A')+0xA;
else if(c1>='a' && c1<='f') c1=(c1-'a')+0xA;
else if(c1>='0' && c1<='9') c1=(c1-'0');
val<<=4;
val|=c1;
}
return val;
}
static void printProgress(void)
{
static int printState = 0;
OEMWriteDebugByte((BYTE)0x08); // print back space
switch (printState) {
case 0:
OEMWriteDebugByte((BYTE)'/');
printState++;
break;
case 1:
OEMWriteDebugByte((BYTE)'-');
printState++;
break;
default:
OEMWriteDebugByte((BYTE)'\\');
printState = 0;
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -