📄 ebootmain.c
字号:
else
{
dwLaunchAddr= g_pTOC->id[g_dwTocEntry].dwJumpAddress;
EdbgOutputDebugString("INFO: using TOC[%d] dwJumpAddress: 0x%x\r\n", g_dwTocEntry, dwLaunchAddr);
}
// Our Launch function takes Physical address, so we need to convert it
// to physical address
dwLaunchAddr = ToPhysicalAddr(dwLaunchAddr);
EdbgOutputDebugString("\r\n::: Physical Launch Address: 0x%Xh\r\n",dwLaunchAddr);
rINTMSK=BIT_ALLMSK;
// OS_ENTER_CRITICAL();
if(memcmp(&output_decrypt[8+54],plaintext_b,54) != 0)
{
pBSPArgs->license_sig = 0;
pBSPArgs->license_crc = 0;
}
Launch(dwLaunchAddr);
// never returned
SPIN_FOREVER;
}
/*
@func BOOL | OEMReadData | Generically read download data (abstracts actual transport read call).
@rdesc TRUE = Success, FALSE = Failure.
@comm
@xref
*/
BOOL OEMReadData (DWORD cbData, LPBYTE pbData)
{
if ( g_bUSBDownload == FALSE )
{
if(g_bSERDownload == TRUE)
return SbootReadData(cbData, pbData);
if(NKFp)
{
//memcpy(pbData,(void*)readPtIndex,cbData);
FS_FRead((void*)pbData, cbData, 1, NKFp);
//readPtIndex += cbData;
return TRUE;
}
return FALSE;//EbootEtherReadData(cbData, pbData);
}
else
{
return UbootReadData(cbData, pbData);
}
}
/*
@func void | OEMShowProgress | Displays download progress for the user.
@rdesc N/A.
@comm
@xref
*/
void OEMShowProgress (DWORD dwPacketNum)
{
recv_length+=dwPacketNum;
if(hProgBar)
{
PROGBAR_SetValue(hProgBar, recv_length/1024);
GUI_Exec();
}
}
#define BACKSPACE 8
#define IPADDR_MAX 15
// Read IP from command line
static BOOL ReadIPLine (char *pbuf, DWORD dwTimeout)
{
DWORD dwCurrSec = OEMEthGetSecs ();
char ch;
int nLen = 0;
while (OEMEthGetSecs () - dwCurrSec < dwTimeout) {
ch = (CHAR)OEMReadDebugByte();
switch (ch) {
case OEM_DEBUG_COM_ERROR:
case OEM_DEBUG_READ_NODATA:
// no data or error, keep reading
break;
case BACKSPACE:
nLen --;
OEMWriteDebugByte (ch);
break;
case '\r':
case '\n':
OEMWriteDebugByte ('\n');
pbuf[nLen] = 0;
return TRUE;
default:
if ((ch == '.' || (ch >= '0' && ch <= '9')) && (nLen < IPADDR_MAX)) {
pbuf[nLen ++] = ch;
OEMWriteDebugByte (ch);
}
}
}
return FALSE; // timeout
}
// get users IP / SubnetMask
// return TRUE is changes made to either, else FALSE.
#if 0
static BOOL GetUserIPAddr (EDBG_ADDR *pMyAddr, DWORD *pdwSubnetMask)
{
char szbuf[IPADDR_MAX+1];
uchar changes = 0;
memset(szbuf, 0, sizeof(szbuf));
EdbgOutputDebugString ("\r\nEnter IP address, or CR for default (%s): ", inet_ntoa(pMyAddr->dwIP));
ReadIPLine (szbuf, INFINITE);
if (szbuf[0]) {
pMyAddr->dwIP = inet_addr(szbuf);
changes++;
memset(szbuf, 0, sizeof(szbuf));
}
EdbgOutputDebugString ("\r\nEnter Subnet Masks, or CR for default (%s): ", inet_ntoa(*pdwSubnetMask));
ReadIPLine (szbuf, INFINITE);
if (szbuf[0]) {
*pdwSubnetMask = inet_addr (szbuf);
changes++;
}
EdbgOutputDebugString ( "\r\nUsing IP Address %s, subnet mask %s\r\n",
inet_ntoa (pMyAddr->dwIP), inet_ntoa (*pdwSubnetMask));
return (changes ? TRUE : FALSE);
}
static ULONG mystrtoul(PUCHAR pStr, UCHAR nBase)
{
UCHAR nPos=0;
BYTE c;
ULONG nVal = 0;
UCHAR nCnt=0;
ULONG n=0;
// fulllibc doesn't implement isctype or iswctype, which are needed by
// strtoul, rather than including coredll code, here's our own simple strtoul.
if (pStr == NULL)
return(0);
for (nPos=0 ; nPos < strlen((char*)pStr) ; nPos++)
{
// c = tolower(*(pStr + strlen(pStr) - 1 - nPos));
c = (*(pStr + strlen((char*)pStr) - 1 - nPos));
if (c >= '0' && c <= '9')
c -= '0';
else if (c >= 'a' && c <= 'f')
{
c -= 'a';
c = (0xa + c);
}
for (nCnt = 0, n = 1 ; nCnt < nPos ; nCnt++)
{
n *= nBase;
}
nVal += (n * c);
}
return(nVal);
}
#endif
// since the startup code is in OAL and it branch to main, we'll just
// implement a pseudo 'main' instead of changing the startup code
void eboot_main (void)
{
// InitUSB();
// Isr_Init();
BootloaderMain ();
// SPIN_FOREVER;
}
VOID SC_WriteDebugLED(WORD wIndex, DWORD dwPattern)
{
OEMWriteDebugLED(wIndex,dwPattern);
}
/*
@func void | SetDelay | Accepts an autoboot delay value from user input.
@rdesc N/A.
@comm
@xref
*/
static void SetDelay()
{
CHAR szCount[16];
USHORT cwNumChars = 0;
USHORT InChar = 0;
EdbgOutputDebugString("\r\nEnter maximum number of seconds to delay [1-255]: ");
g_pBootCfg->BootDelay=Uart_GetIntNum();//GUI_EditDec(g_pBootCfg->BootDelay, 1, 255, 3, 40, 10, WM_CF_SHOW);
#if 0
while(!((InChar == 0x0d) || (InChar == 0x0a)))
{
InChar = GUI_WaitKey();
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);
Out2TerminalChar((char)InChar);
// GUI_DispChar(InChar);
}
}
// If it's a backspace, back up.
//
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
//OEMWriteDebugByte((BYTE)InChar);
Out2TerminalChar((char)InChar);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars)
{
szCount[cwNumChars] = '\0';
g_pBootCfg->BootDelay = atoi(szCount);
if (g_pBootCfg->BootDelay > 255)
{
g_pBootCfg->BootDelay = 255;
}
else if (g_pBootCfg->BootDelay < 1)
{
g_pBootCfg->BootDelay = 1;
}
}
#endif
if (g_pBootCfg->BootDelay > 255)
{
g_pBootCfg->BootDelay = 255;
}
else if (g_pBootCfg->BootDelay < 1)
{
g_pBootCfg->BootDelay = 1;
}
}
#if 0
static void CvtMAC(USHORT 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)(mystrtoul((PUCHAR)pszLastNum, 16) & 0xFF);
i++;
pszLastNum = ++pszDottedD;
}
}
static void SetCS8900MACAddress()
{
CHAR szDottedD[24];
USHORT cwNumChars = 0;
USHORT InChar = 0;
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';
CvtMAC((USHORT*)g_pBootCfg->EdbgAddr.wMAC, szDottedD);
EdbgOutputDebugString("INFO: MAC address set to: %x:%x:%x:%x:%x:%x\r\n",
g_pBootCfg->EdbgAddr.wMAC[0] & 0x00FF, g_pBootCfg->EdbgAddr.wMAC[0] >> 8,
g_pBootCfg->EdbgAddr.wMAC[1] & 0x00FF, g_pBootCfg->EdbgAddr.wMAC[1] >> 8,
g_pBootCfg->EdbgAddr.wMAC[2] & 0x00FF, g_pBootCfg->EdbgAddr.wMAC[2] >> 8);
}
else
{
EdbgOutputDebugString("WARNING: SetCS8900MACAddress: Invalid MAC address.\r\n");
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -