📄 main.c
字号:
//
// 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;
UINT32 rc;
// If the launch address lies in the NAND flash, copy to RAM and adjust the launch address.
// This assumes that the image is properly setup to run from RAM, and ROMSTART and ROMOFFSET
// match the settings in config.bib
//
#define ROMSTART 0x80100000
#define ROMOFFSET 0x2A650800
if (dwLaunchAddr >= (ROMSTART + ROMOFFSET)) {
KITLOutputDebugString("Flash Launch Address (0x%x) requested. Copying to RAM and adjusting address.\r\n", dwLaunchAddr);
rc = ReadFlashNK();
if (rc != BL_JUMP) {
KITLOutputDebugString("ERROR: Couldn't copy image to RAM.\r\n");
SpinForever();
}
dwLaunchAddr -= ROMOFFSET;
}
// 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;
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);
// If we've downloaded a new image, wait for PB connection...
//
if (g_DownloadImage)
{
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
//
DisplayDebugString("Jumping to image...");
KITLOutputDebugString("\r\n\r\n\r\n");
OEMWriteDebugLED(0, 0x00FF);
Launch(PhysAddress);
// Should never get here...
//
SpinForever();
}
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_MDOCLDRIMAGE_FLASH_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_MDOCLDRIMAGE_FLASH_PA_END))
{
KITLOutputDebugString("****** MDOCLDR address ****** \r\n\r\n");
g_ImageType = IMAGE_TYPE_MDOCLDR;
rc = TRUE;
}
else 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 >= IMAGE_WINCE_OSIMAGE_FLASH_PA_START) && (dwPhysVerifyEnd <= (PLATO_BASE_PA_BOOT_FLASH + PLATO_SIZE_BOOT_FLASH)))
{
KITLOutputDebugString("****** FLASH address ****** \r\n\r\n");
g_ImageType = IMAGE_TYPE_FLASHIMAGE;
rc = TRUE;
}
else if ((dwPhysVerifyStart >= PLATO_BASE_PA_SDRAM) && (dwPhysVerifyEnd <= (PLATO_BASE_PA_SDRAM + PLATO_SIZE_SDRAM)))
{
KITLOutputDebugString("****** RAM address ****** \r\n\r\n");
g_ImageType = IMAGE_TYPE_RAMIMAGE;
rc = TRUE;
}
else
{
KITLOutputDebugString("****** OEMVerifyMemory FAILED - Invalid memory area or image too big ****** \r\n\r\n");
rc = FALSE;
}
return(rc);
}
//------------------------------------------------------------------------------
//
// Function: StoreEBootCFG
//
// Stores bootloader configuration information (menu settings, etc.) in flash.
//
BOOL StoreEBootCFG(EBOOT_CFG *eBootCFG)
{
if (!FlashStoreEBootCFG((BYTE*) eBootCFG, sizeof(EBOOT_CFG)))
{
KITLOutputDebugString("ERROR: StoreEBootCFG: failed to write configuration.\r\n");
return(FALSE);
}
return(TRUE);
}
//------------------------------------------------------------------------------
//
// Function: LoadEBootCFG
//
// Retrieves bootloader configuration information (menu settings, etc.) from flash.
//
BOOL LoadEBootCFG(EBOOT_CFG *eBootCFG)
{
if (!FlashLoadEBootCFG((BYTE*) 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)
{
KITLOutputDebugString("ERROR: LoadEBootCFG: ConfigMagicNumber not correct. Expected = 0x%x ; Actual = 0x%x.\r\n", EBOOT_CFG_MAGIC_NUMBER, eBootCFG->ConfigMagicNumber);
ResetDefaultEBootCFG(eBootCFG);
}
// Make sure a valid debug serial port address (physical) was found.
//
if (eBootCFG->dwDbgSerPhysAddr == 0)
{
eBootCFG->dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_FFUART;
}
g_DefaultRamAddress = (PUCHAR)eBootCFG->dwLaunchAddr;
if (GetMacAddress(eBootCFG->RNDISMac))
{
StoreEBootCFG(eBootCFG);
}
// If the RNDIS MAC address is not yet set, create one and save it for future use
if (!eBootCFG->RNDISMac[0] && !eBootCFG->RNDISMac[1] && !eBootCFG->RNDISMac[2])
{
if (GetMacAddress(eBootCFG->RNDISMac))
{
StoreEBootCFG(eBootCFG);
}
}
return(TRUE);
}
//------------------------------------------------------------------------------
//
// Function: ResetDefaultEBootCFG
//
// Resets the debug bootloader configuration information (menu settings, etc.).
//
void ResetDefaultEBootCFG(EBOOT_CFG *pEbootCFG)
{
EBOOT_CFG eBootCFG = {0};
KITLOutputDebugString("\r\nResetting factory default configuration...\r\n");
pEbootCFG->autoDownloadImage = FALSE; //Default, load from Flash
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->KITLEnabled = TRUE;
pEbootCFG->dwLaunchAddr = (DWORD)OALPAtoVA(PLATO_BASE_PA_SDRAM, FALSE) + EBOOT_TOTAL_RAM_SIZE;
pEbootCFG->dwPhysStart = 0;
pEbootCFG->dwPhysLen = 0;
pEbootCFG->dwDbgSerPhysAddr = BULVERDE_BASE_REG_PA_FFUART;
pEbootCFG->RNDISDefault = TRUE;
pEbootCFG->RNDISMac[0] = 0x0000;
pEbootCFG->RNDISMac[1] = 0x0000;
pEbootCFG->RNDISMac[2] = 0x0000;
pEbootCFG->ConfigMagicNumber = EBOOT_CFG_MAGIC_NUMBER;
// save it back to flash
if (!FlashStoreEBootCFG((BYTE*) pEbootCFG, sizeof(EBOOT_CFG)))
{
KITLOutputDebugString("ERROR: ResetDefaultEBootCFG: failed to store configuration to flash.\r\n");
}
#ifdef DEBUG
else
{
KITLOutputDebugString("INFO: ResetDefaultEBootCFG: factory default configuration saved to flash.\r\n");
// DEBUG
// read it back to verify
if (!FlashLoadEBootCFG((BYTE*) &eBootCFG, sizeof(EBOOT_CFG)))
{
KITLOutputDebugString("WARNING: ResetDefaultEBootCFG: failed to load configuration for double check.\r\n");
}
else
{
if (0 != memcmp((const void *)&eBootCFG, (const void*)pEbootCFG, sizeof(EBOOT_CFG)))
{
KITLOutputDebugString("WARNING: ResetDefaultEBootCFG: saved and retrieved data not equal.\r\n");
}
else
{
KITLOutputDebugString("INFO: ResetDefaultEBootCFG: factory default configuration verified in flash.\r\n");
}
}
// END DEBUG
}
#endif
}
BOOL BLInitEthernet()
{
UINT32 EthDevice;
ETH_DEVICE_TYPE BootDevice = ETH_DEVICE_USB; // USB is the only available ethernet boot device
DisplayDebugString("Initializing Ethernet...");
EthDevice = InitSpecifiedEthDevice(&g_pBSPArgs->kitl, BootDevice);
if (EthDevice == -1)
{
// No device was found ...
//
KITLOutputDebugString("ERROR: Failed to detect and initialize Ethernet controller.\r\n");
return(FALSE);
}
// 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");
memcpy(g_pBSPArgs->kitl.mac, g_EbootCFG.RNDISMac, 6);
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);
}
}
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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -