📄 main.c
字号:
EdbgOutputDebugString ( "\r\n\r\nEnter your selection: ");
while (!(selection >= '0' && selection <= '8')
&& selection != 'K' && selection != 'k'
&& selection != 'P' && selection != 'p'
&& selection != 'C' && selection != 'c'
&& selection != 'H' && selection != 'h'
&& selection != 'A' && selection != 'a'
&& selection != 'T' && selection != 't'
&& selection != 'F' && selection != 'f'
&& selection != 'S' && selection != 's'
&& selection != 'D' && selection != 'd'
&& selection != 'L' && selection != 'l'
&& selection != 'R' && selection != 'r'
)
{
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);
UpdatePBCRam(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 'k':
case 'K':
pBootCfg->ConfigFlags ^= CONFIG_FLAGS_KITL_POLL;
if(pBootCfg->ConfigFlags & CONFIG_FLAGS_KITL_POLL){
pBSPArgs->kitl.flags |= OAL_KITL_FLAGS_POLL;
}else{
pBSPArgs->kitl.flags &= ~OAL_KITL_FLAGS_POLL;
}
bConfigChanged = TRUE;
break;
case 'p':
case 'P':
pBootCfg->ConfigFlags ^= CONFIG_FLAGS_KITL_PASSIVE;
if(pBootCfg->ConfigFlags & CONFIG_FLAGS_KITL_PASSIVE){
pBSPArgs->kitl.flags |= OAL_KITL_FLAGS_PASSIVE;
}else{
pBSPArgs->kitl.flags &= ~OAL_KITL_FLAGS_PASSIVE;
}
bConfigChanged = TRUE;
break;
case 'c':
case 'C':
pBootCfg->ConfigFlags ^= CONFIG_FLAGS_L2CACHE;
bConfigChanged = TRUE;
break;
case 'h':
case 'H':
pBootCfg->ConfigFlags ^= CONFIG_FLAGS_AHBCLK;
bConfigChanged = TRUE;
break;
case 'a':
case 'A':
pBootCfg->ConfigFlags ^= CONFIG_FLAGS_ARMCLK;
bConfigChanged = TRUE;
break;
case 't':
case 'T':
pBootCfg->ConfigFlags ^= CONFIG_FLAGS_DPTC;
bConfigChanged = TRUE;
break;
case 'f':
case 'F':
pBootCfg->ConfigFlags ^= CONFIG_FLAGS_DVFS;
bConfigChanged = TRUE;
break;
case 's':
case 'S':
pBootCfg->ConfigFlags ^= CONFIG_FLAGS_SW2A;
bConfigChanged = TRUE;
break;
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);
UpdatePBCRam(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))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -