📄 main.c
字号:
if (!FlashRead(EBOOT_FLASH_CFG_START, (PUCHAR)EBootCFG, sizeof(EBOOT_CFG)))
{
KITLOutputDebugString("ERROR: LoadEBootCFG: failed to load configuration.\r\n");
return(FALSE);
}
// Is the CFG data valid? Check for the magic number that was written the last time
// the CFG block was updated. If Eboot has never been run, there will be no configuration
// information, so the magic number will likely not be found. In this case, setup the
// factory defaults and store them into Flash.
//
if (EBootCFG->ConfigMagicNumber != EBOOT_CFG_MAGIC_NUMBER)
{
ResetDefaultEBootCFG(EBootCFG);
}
// Make sure a valid debug serial port address (physical) was found.
//
if (g_EbootCFG.dwDbgSerPhysAddr == 0)
{
g_EbootCFG.dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_BTUART;
}
return(TRUE);
}
//------------------------------------------------------------------------------
static void SetMAC(unsigned char macdata[6])
{
BOOLEAN bSuccess = TRUE;
int idx;
int macidx;
unsigned char val;
unsigned char cnt;
char szDottedD[20]; // The string used to collect the dotted decimal IP address
WORD cwNumChars = 0;
UINT16 InChar = 0;
KITLOutputDebugString ( "\r\nEnter RDNIS MAC address: ");
while (!((InChar == 0x0d) || (InChar == 0x0a)))
{
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') ||
(InChar >= 'a' && InChar <= 'f') ||
(InChar >= 'A' && InChar <= 'F'))
{
if (cwNumChars < 20)
{
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] = '-';
szDottedD[cwNumChars+1] = '\0';
idx = 0;
macidx = 0;
val = 0;
cnt = 0;
while ((szDottedD[idx] != 0) && (idx < 20))
{
if (szDottedD[idx] >= '0' && szDottedD[idx] <= '9')
{
val <<= 4;
val |= szDottedD[idx] - 0x30;
cnt++;
}
else if (szDottedD[idx] >= 'a' && szDottedD[idx] <= 'f')
{
val <<= 4;
val |= szDottedD[idx] - 0x57;
cnt++;
}
else if (szDottedD[idx] >= 'A' && szDottedD[idx] <= 'F')
{
val <<= 4;
val |= szDottedD[idx] - 0x37;
cnt++;
}
else
{
macdata[macidx] = val;
macidx++;
val = 0;
cnt = 0;
}
idx++;
if (cnt > 2)
{
KITLOutputDebugString("Invalid MAC Address format\r\n");
bSuccess = FALSE;
idx = 20;
}
} // endwhile
}
if (!bSuccess)
{
for (macidx = 0; macidx < 6; macidx++)
{
macdata[macidx] = 0;
}
}
}
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;
KITLOutputDebugString ( "\r\nEnter new IP address: ");
while (!((InChar == 0x0d) || (InChar == 0x0a)))
{
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;
KITLOutputDebugString ( "\r\nEnter new subnet mask: ");
while (!((InChar == 0x0d) || (InChar == 0x0a)))
{
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 SetBootMe(EBOOT_CFG *pEbootCFG)
{
char szCount[16];
WORD cwNumChars = 0;
UINT16 InChar = 0;
KITLOutputDebugString ( "\r\nUse 0 for continuous boot me packets. \r\n");
KITLOutputDebugString ( "Enter maximum number of boot me packets to send [0-255]: ");
while (!((InChar == 0x0d) || (InChar == 0x0a)))
{
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;
KITLOutputDebugString ( "\r\nEnter maximum number of seconds to delay [1-255]: ");
while (!((InChar == 0x0d) || (InChar == 0x0a)))
{
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 ULONG bstrtoul(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(pStr) ; nPos++)
{
c = tolower(*(pStr + strlen(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);
}
BOOL OEMVerifyMemory(DWORD dwStartAddr, DWORD dwLength)
{
BOOL rc;
DWORD dwPhysVerifyStart = (DWORD) OALVAtoPA((void *)dwStartAddr);
DWORD dwPhysVerifyEnd = (DWORD) OALVAtoPA((void *)(dwStartAddr + dwLength - 1));
KITLOutputDebugString("****** OEMVerifyMemory checking physical range [ 0x%x ==> 0x%x ]...\r\n", dwPhysVerifyStart, dwPhysVerifyEnd);
if ((dwPhysVerifyStart >= IMAGE_BOOT_BLDRIMAGE_FLASH_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_BLDRIMAGE_FLASH_PA_END))
{
KITLOutputDebugString("****** bootloader address ****** \r\n\r\n");
g_ImageType = IMAGE_TYPE_BOOTLOADER;
rc = TRUE;
}
else if ((dwPhysVerifyStart >= MAINSTONEII_BASE_PA_BOOT_FLASH) && (dwPhysVerifyEnd <= (MAINSTONEII_BASE_PA_BOOT_FLASH + MAINSTONEII_SIZE_BOOT_FLASH)))
{
KITLOutputDebugString("****** FLASH address ****** \r\n\r\n");
g_ImageType = IMAGE_TYPE_FLASHIMAGE;
rc = TRUE;
}
else if ((dwPhysVerifyStart >= MAINSTONEII_BASE_PA_SDRAM) && (dwPhysVerifyEnd <= (MAINSTONEII_BASE_PA_SDRAM + MAINSTONEII_SIZE_SDRAM)))
{
KITLOutputDebugString("****** RAM address ****** \r\n\r\n");
g_ImageType = IMAGE_TYPE_RAMIMAGE;
rc = TRUE;
}
else
{
KITLOutputDebugString("****** OEMVerifyMemory FAILED - Invalid Memory Area ****** \r\n\r\n");
rc = FALSE;
}
return(rc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -