📄 main.c
字号:
KITLOutputDebugString ( "D) Download image now\r\n");
KITLOutputDebugString ( "L) Launch existing flash resident image now\r\n");
KITLOutputDebugString ( "\r\n\r\nEnter your selection: ");
Selection = 0;
while (! ( ( (Selection >= '0') && (Selection <= '8') ) ||
( (Selection == 'D') || (Selection == 'd') ) ||
( (Selection == 'L') || (Selection == 'l') ) ))
{
Selection = OEMReadDebugByte();
}
KITLOutputDebugString ( "%c\r\n", Selection);
switch (Selection)
{
case '0':
SetIP(&g_EbootCFG);
bCFGChanged=TRUE;
break;
case '1':
SetMask(&g_EbootCFG);
bCFGChanged=TRUE;
break;
case '2':
SetDelay(&g_EbootCFG);
bCFGChanged=TRUE;
break;
case '3':
if (g_EbootCFG.DHCPEnable == TRUE)
g_EbootCFG.DHCPEnable = FALSE;
else
g_EbootCFG.DHCPEnable = TRUE;
bCFGChanged=TRUE;
break;
case '4':
ResetDefaultEBootCFG(&g_EbootCFG);
bCFGChanged=TRUE;
break;
case '5':
SetMAC(&rndis_mac[0]);
// Save the user enter RNDIS MAC address
g_EbootCFG.RNDISMac[0] = (rndis_mac[1] << 8) | rndis_mac[0];
g_EbootCFG.RNDISMac[1] = (rndis_mac[3] << 8) | rndis_mac[2];
g_EbootCFG.RNDISMac[2] = (rndis_mac[5] << 8) | rndis_mac[4];
bCFGChanged = TRUE;
break;
case '6':
if (g_EbootCFG.autoDownloadImage == TRUE)
g_EbootCFG.autoDownloadImage = FALSE;
else
g_EbootCFG.autoDownloadImage = TRUE;
bCFGChanged=TRUE;
break;
case '7':
g_EbootCFG.bootDeviceOrder++;
if (g_EbootCFG.bootDeviceOrder >= NUM_BOOT_ORDERS)
g_EbootCFG.bootDeviceOrder = 0;
bCFGChanged=TRUE;
break;
case '8':
if ((g_EbootCFG.dwDbgSerPhysAddr == 0) || (g_EbootCFG.dwDbgSerPhysAddr == BULVERDE_BASE_REG_PA_BTUART))
{
g_EbootCFG.dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_FFUART;
}
else
{
g_EbootCFG.dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_BTUART;
}
bCFGChanged=TRUE;
break;
case 'D':
case 'd':
if (bCFGChanged == TRUE)
{
StoreEBootCFG(&g_EbootCFG);
}
g_DownloadImage = TRUE;
goto CONTINUE;
case 'L':
case 'l':
if (bCFGChanged == TRUE)
{
StoreEBootCFG(&g_EbootCFG);
}
g_DownloadImage = FALSE;
goto CONTINUE;
default:
break;
}
}
}
}
CONTINUE:
// Provide the chosen debug serial port address to the OS image for debug output messages.
//
g_pBSPArgs->dbgSerPhysAddr = g_EbootCFG.dwDbgSerPhysAddr;
BootDevice = -1;
// Locate and initialize an Ethernet controller.
//
for(i = 0; (i < NUM_BOOT_DEVICES) && (BootDevice == -1) ; i++)
{
// Try each of the boot devices in the specified order (until one succeeds or they all fail).
//
BootDevice = InitSpecifiedEthDevice(&g_pBSPArgs->kitl, BootOrder[g_EbootCFG.bootDeviceOrder][i]);
}
if( BootDevice == SDBG_USB_SERIAL )
{
// Indicate to OEMPreDownload that serial will be used
g_SerialUSBDownload = TRUE;
if(!USBSerialInit())
{
KITLOutputDebugString("ERROR: Failed to detect and initialize USB Function controller.\r\n");
return(FALSE);
}
}
// No device was found ...
//
if (BootDevice == -1)
{
KITLOutputDebugString("ERROR: Failed to detect and initialize Ethernet controller.\r\n");
return(FALSE);
}
else
{
// Make sure MAC address has been programmed.
//
if (!g_pBSPArgs->kitl.mac[0] && !g_pBSPArgs->kitl.mac[1] && !g_pBSPArgs->kitl.mac[2])
{
KITLOutputDebugString("ERROR: Invalid Ethernet address read from Ethernet controller.\n");
return(FALSE);
}
else
{
KITLOutputDebugString("INFO: MAC address: %x-%x-%x-%x-%x-%x\r\n",
g_pBSPArgs->kitl.mac[0] & 0x00FF, g_pBSPArgs->kitl.mac[0] >> 8,
g_pBSPArgs->kitl.mac[1] & 0x00FF, g_pBSPArgs->kitl.mac[1] >> 8,
g_pBSPArgs->kitl.mac[2] & 0x00FF, g_pBSPArgs->kitl.mac[2] >> 8);
}
}
return(TRUE);
}
//------------------------------------------------------------------------------
//
// Function: OEMPreDownload
//
// Pre-download initialization routine.
//
DWORD OEMPreDownload(void)
{
UINT32 SubnetMask;
BOOL fGotJumpImg = FALSE, fGotIP = FALSE;
UINT32 DHCPLeaseTime = 0;
UINT32 *pDHCPLeaseTime = &DHCPLeaseTime;
UINT32 BootFlags = 0;
const char * platformString = "MAINSTN";
// Create device name based on Ethernet address (this is how Platform Builder identifies this device).
//
KITLOutputDebugString("+OEMPreDownload()\r\n");
OALKitlCreateName(BSP_DEVICE_PREFIX, g_pBSPArgs->kitl.mac, g_pBSPArgs->deviceId);
KITLOutputDebugString("INFO: Using device name: '%s'\n", g_pBSPArgs->deviceId);
// User doesn't want to get a DHCP address...
// If user wants to jump to existing image, we may still need to populate
// ARGS so that a KITL session can correctly start up.
//
if (g_EbootCFG.DHCPEnable == FALSE)
{
pDHCPLeaseTime = NULL;
g_pBSPArgs->kitl.ipAddress = g_EbootCFG.IP;
g_pBSPArgs->kitl.ipMask = g_EbootCFG.subnetMask;
g_pBSPArgs->kitl.flags &= ~OAL_KITL_FLAGS_DHCP;
}
// If user wants to jump to existing image - skip download...
//
if (!g_DownloadImage)
{
return(BL_JUMP);
}
if( g_SerialUSBDownload )
{
// Send boot requests indefinitely
do
{
KITLOutputDebugString("Sending boot request...\r\n");
if(!SerialSendBootRequest(platformString))
{
KITLOutputDebugString("Failed to send boot request\r\n");
return BL_ERROR;
}
}
while(!SerialWaitForBootAck(&fGotJumpImg));
// Ack block zero to start the download
SerialSendBlockAck(0);
if( fGotJumpImg )
{
KITLOutputDebugString("Received boot request ack... jumping to image\r\n");
}
else
{
KITLOutputDebugString("Received boot request ack... starting download\r\n");
}
return fGotJumpImg ? BL_JUMP : BL_DOWNLOAD;
}
// Initialize the TFTP transport.
memcpy(g_DeviceAddr.wMAC, g_pBSPArgs->kitl.mac, (sizeof(UINT16) * 3));
g_DeviceAddr.dwIP = g_pBSPArgs->kitl.ipAddress;
g_DeviceAddr.wPort = 0;
SubnetMask = g_pBSPArgs->kitl.ipMask;
if (!EbootInitEtherTransport(&g_DeviceAddr,
&SubnetMask,
&fGotJumpImg,
pDHCPLeaseTime,
EBOOT_VERSION_MAJOR,
EBOOT_VERSION_MINOR,
BSP_DEVICE_PREFIX,
g_pBSPArgs->deviceId,
EDBG_CPU_ARM720,
BootFlags))
{
return(BL_ERROR);
}
// If the user wanted a DHCP address, save the values obtained in the init call above.
//
if (g_EbootCFG.DHCPEnable == TRUE)
{
g_pBSPArgs->kitl.ipAddress = g_DeviceAddr.dwIP;
g_pBSPArgs->kitl.ipMask = SubnetMask;
g_pBSPArgs->kitl.flags |= OAL_KITL_FLAGS_DHCP;
}
return(fGotJumpImg? BL_JUMP : BL_DOWNLOAD);
}
//------------------------------------------------------------------------------
//
// Function: OEMLaunch
//
// Launch downloaded/stored image.
//
void OEMLaunch(DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr, const ROMHDR *pRomHdr)
{
EDBG_OS_CONFIG_DATA *pCfgData;
EDBG_ADDR EshellHostAddr;
UINT32 PhysAddress;
// If a launch address wasn't specified - use the last known good address.
//
if (!dwLaunchAddr)
{
dwLaunchAddr = g_EbootCFG.dwLaunchAddr;
}
else
{
if (g_EbootCFG.dwLaunchAddr != dwLaunchAddr ||
g_EbootCFG.dwPhysStart != dwImageStart ||
g_EbootCFG.dwPhysLen != dwImageLength)
{
g_EbootCFG.dwLaunchAddr = dwLaunchAddr;
g_EbootCFG.dwPhysStart = dwImageStart;
g_EbootCFG.dwPhysLen = dwImageLength;
g_EbootCFG.dwStoreAddr = 0;
StoreEBootCFG(&g_EbootCFG);
}
}
// Translate the image start address (virtual address) to a physical address.
//
PhysAddress = (UINT32) OALVAtoPA((VOID *)dwLaunchAddr);
KITLOutputDebugString("Download successful! Jumping to image at 0x%x (physical 0x%x)...\r\n", dwLaunchAddr, PhysAddress);
// Wait for PB connection...
//
if (g_DownloadImage)
{
if( g_SerialUSBDownload )
{
// Wait indefinately for a jump request.
// SerialWaitForJump() returns the debug transport requested by PB.
// However, we only support ethernet for debug so we ignore the
// return value.
SerialWaitForJump();
}
else
{
KITLOutputDebugString("Waiting for host to connect...\r\n");
if (!(pCfgData = EbootWaitForHostConnect(&g_DeviceAddr, &EshellHostAddr)))
{
KITLOutputDebugString("ERROR: EbootWaitForHostConnect failed!\r\n");
SpinForever();
}
// If the user selected "passive" KITL (i.e., don't connect to the target at boot time), set the
// flag in the args structure so the OS image can honor it when it boots.
//
if (pCfgData && (pCfgData->KitlTransport & KTS_PASSIVE_MODE))
{
g_pBSPArgs->kitl.flags |= OAL_KITL_FLAGS_PASSIVE;
}
}
}
// Jump to the image we just downloaded.
//
KITLOutputDebugString("\r\n\r\n\r\n");
Launch(PhysAddress);
// Should never get here...
//
SpinForever();
}
//------------------------------------------------------------------------------
//
// Function: StoreEBootCFG
//
// Stores bootloader configuration information (menu settings, etc.) in flash.
//
static BOOL StoreEBootCFG(EBOOT_CFG *EBootCFG)
{
if (!FlashWrite(EBOOT_FLASH_CFG_START, (PUCHAR)EBootCFG, sizeof(EBOOT_CFG)))
{
KITLOutputDebugString("ERROR: StoreEBootCFG: failed to write configuration.\r\n");
return(FALSE);
}
return(TRUE);
}
//------------------------------------------------------------------------------
//
// Function: ResetDefaultEBootCFG
//
// Resets the debug bootloader configuration information (menu settings, etc.).
//
static void ResetDefaultEBootCFG(EBOOT_CFG *pEbootCFG)
{
KITLOutputDebugString("\r\nResetting factory default configuration...\r\n");
pEbootCFG->autoDownloadImage = TRUE;
pEbootCFG->IP = inet_addr("0.0.0.0");
pEbootCFG->subnetMask = inet_addr("0.0.0.0");
pEbootCFG->numBootMe = 50;
pEbootCFG->delay = 3;
pEbootCFG->DHCPEnable = TRUE;
pEbootCFG->dwLaunchAddr = 0;
pEbootCFG->dwPhysStart = 0;
pEbootCFG->dwPhysLen = 0;
pEbootCFG->bootDeviceOrder = 0;
pEbootCFG->dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_BTUART;
pEbootCFG->dwStoreAddr = 0;
pEbootCFG->CheckSignatures = FALSE;
pEbootCFG->RNDISMac[0] = 0;
pEbootCFG->RNDISMac[1] = 0;
pEbootCFG->RNDISMac[2] = 0;
pEbootCFG->ConfigMagicNumber = EBOOT_CFG_MAGIC_NUMBER;
}
//------------------------------------------------------------------------------
//
// Function: LoadEBootCFG
//
// Retrieves bootloader configuration information (menu settings, etc.) from flash.
//
static BOOL LoadEBootCFG(EBOOT_CFG *EBootCFG)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -