📄 main.c
字号:
else if (delay < 99)
i = 12;
else if (delay < 999)
i = 13;
for (j = 0; j < i; j++)
{
OEMWriteDebugByte((BYTE)0x08); // print back space
}
x = delay / 100;
y = (delay % 100) / 10;
z = ((delay % 100) % 10);
BLR->hex_led = ((x << 8) | (y << 4) | (z));
EdbgOutputDebugString ( "%d seconds. ", delay--);
}
}
EdbgOutputDebugString ( "\r\n");
switch (selection)
{
case 0x00: // fall through if nothing typed
case 0x0d: // user canceled wait
{
if (pEbootCFG->autoDownloadImage)
{
EdbgOutputDebugString ( "\r\nStarting auto download ... \r\n");
}
else
{
EdbgOutputDebugString ( "\r\nLaunching flash image ... \r\n");
}
break;
}
case 0x20:
{
selection = 0;
while (1)
{
// Show menu
EdbgOutputDebugString ( "\r\n\r\nEthernet Boot Loader Configuration:\r\n\r\n");
EdbgOutputDebugString ( "0) IP address: %s\r\n",inet_ntoa(pEbootCFG->IP));
EdbgOutputDebugString ( "1) Subnet mask: %s\r\n", inet_ntoa(pEbootCFG->subnetMask));
EdbgOutputDebugString ( "2) # bootme's: %d\r\n", pEbootCFG->numBootMe);
EdbgOutputDebugString ( "3) Boot delay: %d seconds\r\n", pEbootCFG->delay);
EdbgOutputDebugString ( "4) DHCP: %s\r\n", (pEbootCFG->DHCPEnable == TRUE?"Enabled":"Disabled"));
EdbgOutputDebugString ( "5) Reset to factory default configuration\r\n");
EdbgOutputDebugString ( "6) %s image at startup\r\n", pEbootCFG->autoDownloadImage?"Download new":"Launch existing flash resident");
EdbgOutputDebugString ( "7) Program RAM image into FLASH (%s)\r\n", pEbootCFG->bWriteBINToFlash?"Enabled":"Disabled");
EdbgOutputDebugString ( "8) Program SMSC MAC address\r\n");
EdbgOutputDebugString ( "9) Boot device order: ");
switch (pEbootCFG->bootDeviceOrder)
{
case 0:
EdbgOutputDebugString ( "SMSC -> PCMCIA S0 -> PCMCIA S1\r\n");
break;
case 1:
EdbgOutputDebugString ( "SMSC -> PCMCIA S1 -> PCMCIA S0\r\n");
break;
case 2:
EdbgOutputDebugString ( "PCMCIA S0 -> PCMCIA S1 -> SMSC\r\n");
break;
case 3:
EdbgOutputDebugString ( "PCMCIA S0 -> SMSC -> PCMCIA S1\r\n");
break;
case 4:
EdbgOutputDebugString ( "PCMCIA S1 -> SMSC -> PCMCIA S0\r\n");
break;
case 5:
EdbgOutputDebugString ( "PCMCIA S1 -> PCMCIA S0 -> SMSC\r\n");
break;
default:
EdbgOutputDebugString ( "SMSC -> PCMCIA S0 -> PCMCIA S1\r\n");
pEbootCFG->bootDeviceOrder = 0;
break;
}
EdbgOutputDebugString ( "D) Download image now\r\n");
EdbgOutputDebugString ( "E) Erase flash image\r\n");
EdbgOutputDebugString ( "L) Launch existing flash resident image now\r\n");
EdbgOutputDebugString ( "\r\n\r\nEnter your selection: ");
selection = 0;
while (! ( ( (selection >= '0') && (selection <= '9') ) ||
( (selection == 'D') || (selection == 'd') ) ||
( (selection == 'E') || (selection == 'e') ) ||
( (selection == 'L') || (selection == 'l') ) ))
{
selection = OEMReadDebugByte();
}
EdbgOutputDebugString ( "%c\r\n", selection);
switch (selection)
{
case '0':
SetIP(pEbootCFG);
MyAddr.dwIP = pEbootCFG->IP;
CFGChanged=TRUE;
break;
case '1':
SetMask(pEbootCFG);
dwSubnetMask = pEbootCFG->subnetMask;
CFGChanged=TRUE;
break;
case '2':
SetBootMe(pEbootCFG);
CFGChanged=TRUE;
break;
case '3':
SetDelay(pEbootCFG);
CFGChanged=TRUE;
break;
case '4':
if (pEbootCFG->DHCPEnable == TRUE)
{
pEbootCFG->DHCPEnable = FALSE;
}
else
{
pEbootCFG->DHCPEnable = TRUE;
}
CFGChanged=TRUE;
break;
case '5':
ResetFactoryDefaultCFG(pEbootCFG);
CFGChanged=TRUE;
break;
case '6':
if (pEbootCFG->autoDownloadImage == TRUE)
{
pEbootCFG->autoDownloadImage = FALSE;
}
else
{
pEbootCFG->autoDownloadImage = TRUE;
}
CFGChanged=TRUE;
break;
case '7':
if (pEbootCFG->bWriteBINToFlash == TRUE)
{
pEbootCFG->bWriteBINToFlash = FALSE;
}
else
{
pEbootCFG->bWriteBINToFlash = TRUE;
}
CFGChanged=TRUE;
break;
case '8':
SetSMSCMACAddress();
break;
case '9':
pEbootCFG->bootDeviceOrder++;
if (pEbootCFG->bootDeviceOrder > 5)
pEbootCFG->bootDeviceOrder = 0;
CFGChanged=TRUE;
break;
case 'D':
case 'd':
if (pDriverGlobals->eth.EbootMagicNum != EBOOT_MAGIC_NUM)
{
memset((LPVOID)pDriverGlobals,0,sizeof(DRIVER_GLOBALS));
pDriverGlobals->eth.EbootMagicNum = EBOOT_MAGIC_NUM;
pDriverGlobals->uninit_misc.EbootDevice = BOOT_DEVICE_NONE;
memcpy(&pEbootCFG->DriverGlobals, (LPVOID)pDriverGlobals, sizeof(DRIVER_GLOBALS));
CFGChanged = TRUE;
}
if (CFGChanged == TRUE)
{
StoreEBootCFG(pEbootCFG);
}
goto DOWNLOAD;
break;
case 'E':
case 'e':
EraseFlashImage();
break;
case 'L':
case 'l':
if (pDriverGlobals->eth.EbootMagicNum != EBOOT_MAGIC_NUM)
{
memset((LPVOID)pDriverGlobals,0,sizeof(DRIVER_GLOBALS));
pDriverGlobals->eth.EbootMagicNum = EBOOT_MAGIC_NUM;
pDriverGlobals->uninit_misc.EbootDevice = BOOT_DEVICE_NONE;
memcpy(&pEbootCFG->DriverGlobals, (LPVOID)pDriverGlobals, sizeof(DRIVER_GLOBALS));
CFGChanged = TRUE;
}
if (CFGChanged == TRUE)
{
StoreEBootCFG(pEbootCFG);
}
goto LAUNCHIMAGE;
break;
default:
break;
}
}
}
}
LAUNCHIMAGE:
if ((pEbootCFG->autoDownloadImage == FALSE) || (selection == 'L') || (selection == 'l'))
{
// If the image is targetted to execute out of flash, we launch it in place.
// If the image is targetted to execute out of SDRAM, we first load it out of flash
// into SDRAM, then launch it.
#ifdef MMXIP_MEMMAP
if ((pEbootCFG->dwLaunchAddr & 0xF0000000) == 0x80000000)
#else
if ((pEbootCFG->dwLaunchAddr & 0xF0000000) == 0x90000000)
#endif
{
// Check for pTOC signature ("CECE") here, after image in place
if (*(DWORD*)(pEbootCFG->dwPhysStart + 64) == 0x43454345)
{
EdbgOutputDebugString("Launching image at 0x%x...\r\n",pEbootCFG->dwLaunchAddr);
msWait(500);
// Call Launch2 with the physical address of the image start
Launch2(pEbootCFG->dwLaunchAddr - BOOT_FLASH_BASE_C_VIRTUAL);
}
else
{
EdbgOutputDebugString("Image not found at 0x%x\r\n",pEbootCFG->dwLaunchAddr);
}
}
#ifdef MMXIP_MEMMAP
else if ((pEbootCFG->dwLaunchAddr & 0xF0000000) == 0x90000000)
#else
else if ((pEbootCFG->dwLaunchAddr & 0xF0000000) == 0x80000000)
#endif
{
if (LoadFlashImage(pEbootCFG->dwPhysStart, pEbootCFG->dwPhysLen, pEbootCFG->dwLaunchAddr, pEbootCFG) == 0)
{
if (VerifyCheckSum() == 0)
{
lpdwToc= (LPDWORD)(*(DWORD*)(pEbootCFG->dwPhysStart - dwOffset + 68));
memcpy((LPVOID)&RomHdr, (LPVOID)lpdwToc, sizeof(ROMHDR));
EdbgOutputDebugString("ROMHDR at Address 0x%x\r\n",lpdwToc);
EdbgOutputDebugString("RomHdr.ulRAMStart=0x%x RomHdr.physfirst=0x%x.\r\n",RomHdr.ulRAMStart,RomHdr.physfirst);
EdbgOutputDebugString( "CLEANBOOT Clearing RAM from 0x%x-0x%x.\r\n",RomHdr.ulRAMStart,RomHdr.ulRAMEnd);
memset((LPVOID)RomHdr.ulRAMStart,0,RomHdr.ulRAMEnd-RomHdr.ulRAMStart);
EdbgOutputDebugString("Launching image at 0x%x...\r\n",pEbootCFG->dwLaunchAddr);
msWait(500);
Launch(pEbootCFG->dwLaunchAddr);
}
}
// Either LoadFlashImage failed, or the checksum failed. Therefore, the image
// was not launched.
EdbgOutputDebugString("A valid image was not found at 0x%x\r\n",pEbootCFG->dwLaunchAddr);
}
}
DOWNLOAD:
// Initialize the boot device in driver globals only if we are not launching a flash resident image.
// This will preserve the value stored in flash when not downloading a new image.
pDriverGlobals->uninit_misc.EbootDevice = BOOT_DEVICE_NONE;
// Try each of the boot devices in the specified order
ethernet_device = InitSpecifiedEthDevice(&MyAddr, bootOrder[(pEbootCFG->bootDeviceOrder * 3)]);
if (ethernet_device == NONE)
{
ethernet_device = InitSpecifiedEthDevice(&MyAddr, bootOrder[(pEbootCFG->bootDeviceOrder * 3) + 1]);
if (ethernet_device == NONE)
{
ethernet_device = InitSpecifiedEthDevice(&MyAddr, bootOrder[(pEbootCFG->bootDeviceOrder * 3) + 2]);
}
}
// No device was found ...
if (ethernet_device == NONE)
{
EdbgOutputDebugString("Failed to detect and initialize Ethernet controller.\r\n");
EdbgOutputDebugString("NOTE: Onboard LAN91C111 Ethernet controller is not currently supported.\r\n");
EdbgOutputDebugString("Eboot has halted.\r\n");
while (1);
}
// Make sure MAC address has been programmed
if (!MyAddr.wMAC[0] && !MyAddr.wMAC[1] && !MyAddr.wMAC[2])
{
EdbgOutputDebugString("Invalid Ethernet address read from Ethernet controller.\n");
goto FatalError;
}
// Device name based on platform ID and last word of MAC address
EdbgOutputDebugString("\r\nDevice identification: XSC1BD%d\n\n",ntohs(MyAddr.wMAC[2]));
// Set up TFTP server. Note that internally, we store port numbers in network byte order.
EbootInitTFtp( htons(EDBG_DOWNLOAD_PORT), htons(EDBG_DOWNLOAD_PORT));
EbootInitTFtpd();
if (EbootTFtpdServerRegister( EDBG_DOWNLOAD_FILENAME, EthDown ))
EdbgOutputDebugString( "Server Registration Failed\r\n" );
// Initialize DHCP, and send out first request
if (pEbootCFG->DHCPEnable == TRUE)
{
if (EbootInitDHCP( &MyAddr ))
EdbgOutputDebugString( "Error On InitDHCP() Call\r\n" );
EdbgOutputDebugString ( "Waiting for DHCP assignment... ");
}
// Loop until we have an IP address and eshell tells us which services are
// configured for Ethernet
while (!fGotJumpimg)
{
USHORT wLen, wDestPort, wSrcPort, wUDPDataLen, *pwUDPData;
// Once we get our IP address, periodically send BOOTME commands to eshell.
switch (dwIPState)
{
case IPSTATE_NONE:
if (pEbootCFG->DHCPEnable == TRUE)
{
// We haven't gotten an IP address yet. Call into DHCP to see if we
// need to retransmit request.
EbootDHCPRetransmit(&MyAddr,NULL,NULL);
}
else
{
// Use the static IP already configured.
MyAddr.dwIP = pEbootCFG->IP;
dwSubnetMask = pEbootCFG->subnetMask;
dwIPState = IPSTATE_GOTIP;
EdbgFlags |= EDBG_FLAGS_STATIC_IP;
DHCPLeaseTime = DEFAULT_DHCP_LEASE;
}
break;
case IPSTATE_GOTIP:
// Send a gratuitous ARP (an ARP of our new IP address) to verify that no other
// station is using our IP address.
if (!EbootGratuitousARP(&MyAddr, FrameBuffer))
{
dwIPState = IPSTATE_ARP;
dwNextBootme = OEMEthGetSecs(); // use dwNextBootme for ARP timeout
}
else
{
EdbgOutputDebugString("EbootGratuitousARP failed\r\n");
}
break;
case IPSTATE_ARP:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -