📄 main.c
字号:
{
selection = OEMReadDebugByte();
}
EdbgOutputDebugString ( "%c\r\n", selection);
switch(selection)
{
case '0':
SetMACAddr(g_MyAddr.wMAC);
memcpy(pBootCfg->CS8900MAC, g_MyAddr.wMAC, 6);
bConfigChanged = TRUE;
break;
case '1':
if (SetIPAndSubnet(pBootCfg, TRUE))
bConfigChanged = TRUE;
break;
case '2':
if (SetIPAndSubnet(pBootCfg, FALSE))
bConfigChanged = TRUE;
break;
case '3':
ToggleDHCP(pBootCfg);
bConfigChanged = TRUE;
break;
case '4':
OALResetBootCFG(pBootCfg);
bConfigChanged = TRUE;
break;
case '5':
OALWriteBootCFG(pBootCfg);
break;
case '6':
// Toggles autoboot enable and displays autoboot selection
AutobootMenu(pBootCfg);
bConfigChanged = TRUE;
break;
#if NAND_BOOT_SUPPORT
case '7':
if(NandFlashMenu(pBootCfg, &bConfigChanged) == TRUE)
{
bDownloadImage = FALSE;
goto MENU_DONE;
}
break;
#endif
case 'D':
case 'd':
bDownloadImage = TRUE;
goto MENU_DONE;
case 'L':
case 'l':
// Set Launch Address to Flash Address
pBootCfg->LaunchAddress = FLASH_CVBASE + EBOOT_IMAGE_SIZE + 0x1000;
bDownloadImage = FALSE;
goto MENU_DONE;
case 'R':
case 'r':
bDownloadImage = FALSE;
goto MENU_DONE;
default:
break;
}
}
MENU_DONE:
// If eboot settings were changed by user, save them to flash.
//
if(bConfigChanged)
{
OALWriteBootCFG(pBootCfg);
}
return bDownloadImage;
}
//------------------------------------------------------------------------------
//
// Function: SetIPAndSubnet
//
// This function is used to implement the IP/subnet change menu.
//
// Parameters:
// pBootCfg
// [in/out] ptr to bootloader configuration structure
//
// Returns:
// TRUE if new IP/Subnet Mask is entered. FALSE otherwise
//
//------------------------------------------------------------------------------
static BOOL SetIPAndSubnet(BOOT_CFG *pBootCfg, BOOL bSetIP)
{
CHAR szDottedD[16]; // The string used to collect the dotted decimal IP address
WORD cwNumChars = 0;
UINT16 InChar = 0;
BOOL bChanged = FALSE;
if(bSetIP)
EdbgOutputDebugString ( "\r\nEnter new IP address: ");
else
EdbgOutputDebugString ( "\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--;
DELETE_CHAR;
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
if (cwNumChars)
{
szDottedD[cwNumChars] = '\0';
if(bSetIP) {
pBootCfg->IPAddr = inet_addr( szDottedD );
} else {
pBootCfg->SubnetMask = inet_addr( szDottedD );
}
bChanged = TRUE;
}
if (bSetIP) {
ClearPromiscuousIP();
}
return bChanged;
}
//------------------------------------------------------------------------------
//
// Function: SetMACAddr
//
// This function implements the MAC Address change menu.
//
// PARAMETERS:
// pMacAddress
// [in/out] - MAC address
//
// RETURNS:
// NONE
//------------------------------------------------------------------------------
static void SetMACAddr(UINT16 *pMacAddress)
{
UINT8 szLocalMAC[6]; // Store new MAC Address
WORD cwNumChars = 0;
CHAR InChar = 0;
BOOL bValid = TRUE;
UINT8 cHiByte;
EdbgOutputDebugString ( "\r\nEnter New MAC Address [Format: XX:XX:XX:XX:XX]: ");
while(1)
{
InChar = OEMReadDebugByte();
if ((InChar == 0x0d) || (InChar == 0x0a)) break;
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
if (InChar == 0x08 && cwNumChars > 0) {
// it's backspace
if((cwNumChars < 12) && ((cwNumChars % 2) == 0)) {
// bypass ':' the separator
DELETE_CHAR;
}
DELETE_CHAR;
cwNumChars--;
}
else if(cwNumChars < 12) {
bValid=TRUE;
if (InChar >= '0' && InChar <= '9') {
OEMWriteDebugByte((BYTE)InChar);
InChar -= 0x30;
}
else if (InChar >= 'A' && InChar <= 'F') {
OEMWriteDebugByte((BYTE)InChar);
InChar -= 0x37;
}
else if (InChar >= 'a' && InChar <= 'f') {
OEMWriteDebugByte((BYTE)InChar);
InChar -= 0x57;
}
else {
bValid = FALSE;
}
if(bValid) {
// it's valid input
if(((cwNumChars+1) % 2) == 0) {
//szLocalMAC[cwNumChars/2] += InChar;
szLocalMAC[cwNumChars/2] = cHiByte + InChar;
if( (cwNumChars + 1) < 12) {
// Also write the byte separator field
OEMWriteDebugByte((BYTE)':');
}
}
else {
cHiByte = InChar << 4;
szLocalMAC[cwNumChars/2] = cHiByte;
}
cwNumChars++;
}
}
}
}
// Only store a valid MAC Address
if (cwNumChars == 12) // only valid MAC Address, we save it
{
// Return New MAC Address
memcpy(pMacAddress,szLocalMAC,sizeof(szLocalMAC));
}
}
//------------------------------------------------------------------------------
//
// Function: ToggleDHCP
//
// Implements the enable/disable DHCP menu.
//
// Parameters:
// pBootCfg
// [in/out] ptr to bootloader configuration structure
//
// Returns:
//
//------------------------------------------------------------------------------
static void ToggleDHCP(BOOT_CFG *pBootCfg)
{
if((pBootCfg->ConfigFlags & CONFIG_FLAGS_DHCP))
pBootCfg->ConfigFlags &= ~CONFIG_FLAGS_DHCP;
else
pBootCfg->ConfigFlags |= CONFIG_FLAGS_DHCP;
}
//-----------------------------------------------------------------------------
//
// Function: AutobootMenu
//
// Implements the autoboot feature menu. Toggles autoboot enable and displays
// selected autoboot option when autoboot is enabled.
//
// Parameters:
// pBootCfg
// [in/out] ptr to bootloader configuration structure
//
// Returns:
//
//-----------------------------------------------------------------------------
static void AutobootMenu(BOOT_CFG *pBootCfg)
{
BOOL bExitMenu;
char selection;
if((pBootCfg->ConfigFlags & CONFIG_FLAGS_AUTOBOOT))
{
// Clear all autoboot flags
pBootCfg->ConfigFlags &= ~CONFIG_FLAGS_AUTOBOOT;
}
else
{
// set autoboot flag
pBootCfg->ConfigFlags &= ~CONFIG_FLAGS_AUTOBOOT;
bExitMenu = FALSE;
do {
EdbgOutputDebugString("\r\nAutoboot Selection Menu\r\n");
EdbgOutputDebugString("1) Autoboot from NOR\r\n");
EdbgOutputDebugString("2) Autoboot from NAND\r\n");
EdbgOutputDebugString("Enter your selection: ");
while(1)
{
selection = OEMReadDebugByte();
if((selection >= '1' && selection <= '2'))
break;
}
EdbgOutputDebugString ("%c\r\n\r\n", selection);
switch(selection)
{
case '1':
pBootCfg->ConfigFlags |= CONFIG_FLAGS_AUTOBOOT;
pBootCfg->BootDevice = CONFIG_AUTOBOOT_DEVICE_NOR;
// Return To Main Menu.
bExitMenu = TRUE;
break;
case '2':
pBootCfg->ConfigFlags |= CONFIG_FLAGS_AUTOBOOT;
pBootCfg->BootDevice = CONFIG_AUTOBOOT_DEVICE_NAND;
// Return To Main Menu.
bExitMenu = TRUE;
break;
default:
break;
}
} while(bExitMenu == FALSE);
}
}
void SpinForever(void)
{
CSP_PBC_REGS *pPBC;
// On both on board leds
pPBC = (PCSP_PBC_REGS)OALPAtoVA((UINT32)BSP_BASE_REG_PA_PBC_BASE, FALSE);
OUTREG16(&pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_SET_LED0));
OUTREG16(&pPBC->BCTRL1_SET, CSP_BITFMASK(PBC_BCTRL1_SET_LED1));
OALMSG(OAL_ERROR, (TEXT("Halting system\r\n")));
while(1);
}
//------------------------------------------------------------------------------
// END OF FILE
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -