📄 main.c
字号:
//
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);
break;
}
KITLOutputDebugString("Download successful! Jumping to image at 0x%x (physical 0x%x)...\r\n", dwLaunchAddr, PhysAddress);
// Wait for PB connection...
//
if (g_DownloadImage)
{
memset(&EshellHostAddr, 0, sizeof(EDBG_ADDR));
KITLOutputDebugString("INFO: EbootWaitForHostConnect (IP = %s, MAC = %x-%x-%x-%x-%x-%x, Port = 0x%x)\r\n",
inet_ntoa(g_DeviceAddr.dwIP), g_DeviceAddr.wMAC[0] & 0x00FF, g_DeviceAddr.wMAC[0] >> 8,
g_DeviceAddr.wMAC[1] & 0x00FF, g_DeviceAddr.wMAC[1] >> 8,
g_DeviceAddr.wMAC[2] & 0x00FF, g_DeviceAddr.wMAC[2] >> 8,
g_DeviceAddr.wPort);
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");
OEMWriteDebugLED(0, 0x00FF);
Launch(PhysAddress);
// Should never get here...
//
SpinForever();
}
//------------------------------------------------------------------------------
//
// Function: OEMMultiBINNotify
//
// Receives/processes download file manifest.
//
// Parameters:
// pInfo
// [in] Download manifiest provided by BLCOMMON framework.
//
// Returns:
// void
//------------------------------------------------------------------------------
void OEMMultiBINNotify(const PMultiBINInfo pInfo)
{
CHAR szFileName[MAX_PATH];
int i, key, fileExtPos;
if (!pInfo) return;
KITLOutputDebugString("INFO: OEMMultiBINNotify (dwNumRegions = %d, dwRegionStart = 0x%x).\r\n",
pInfo->dwNumRegions, pInfo->Region[0].dwRegionStart);
// Only inspect manifest if this is a monolithic .nb0 or diskimage file
if (pInfo->dwNumRegions != 1)
return;
// NBO and DIO files will have start address of zero
if (pInfo->Region[0].dwRegionStart == 0)
{
// Convert the file name to lower case
i = 0;
fileExtPos = 0;
while ((pInfo->Region[0].szFileName[i] != '\0') && (i < MAX_PATH))
{
szFileName[i] = tolower(pInfo->Region[0].szFileName[i]);
// Keep track of file extension position
if (szFileName[i] == '.')
{
fileExtPos = i;
}
i++;
}
// Check for NAND XLDR update
if (strncmp(szFileName, XLDR_NB0_FILE, XLDR_NB0_FILE_LEN) == 0)
{
// Remap the start address to the NAND XLDR region
pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_XLDRIMAGE_NAND_PA_START);
KITLOutputDebugString("INFO: XLDR NB0 remapped to 0x%x.\r\n", pInfo->Region[0].dwRegionStart);
}
// Check for EBOOT update
else if (strncmp(szFileName, EBOOT_NB0_FILE, EBOOT_NB0_FILE_LEN) == 0)
{
// Remap the start address to the region specified by the user
KITLOutputDebugString("Specify destination for EBOOT NB0 [1 = NOR, 2 = NAND]: ");
do {
key = OEMReadDebugByte();
} while ((key != '1') && (key != '2'));
KITLOutputDebugString("\r\n");
switch (key)
{
case '1':
pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_EBOOTIMAGE_NOR_PA_START);
break;
case '2':
pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_EBOOTIMAGE_NAND_PA_START);
break;
default:
return;
}
KITLOutputDebugString("\r\nINFO: EBOOT NB0 remapped to 0x%x.\r\n", pInfo->Region[0].dwRegionStart);
}
// If file to be downloaded has an NB0 extension, assume it is an NK NB0 image
else if (fileExtPos && (strncmp(&szFileName[fileExtPos], ".nb0", 4) == 0))
{
// Remap the start address to the region specified by the user
KITLOutputDebugString("Specify destination for NK NB0 [0 = RAM, 1 = NOR, 2 = NAND]: ");
do {
key = OEMReadDebugByte();
} while ((key != '0') && (key != '1') && (key != '2'));
KITLOutputDebugString("\r\n");
switch (key)
{
case '0':
pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_NKIMAGE_RAM_PA_START);
break;
case '1':
pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_NKIMAGE_NOR_PA_START);
break;
case '2':
pInfo->Region[0].dwRegionStart = (DWORD) OALPAtoCA(IMAGE_BOOT_NKIMAGE_NAND_PA_START);
break;
default:
return;
}
KITLOutputDebugString("\r\nINFO: NK NB0 remapped to 0x%x.\r\n", pInfo->Region[0].dwRegionStart);
}
// Notify user of unsupported format
else
{
KITLOutputDebugString("\r\nWARNING: Unsupported binary format. Image not remapped.\r\n");
}
}
// If this is a Windows Mobile disk image BIN, then dwRegionStart will
// be offset into NAND.
else if (pInfo->Region[0].dwRegionStart < IMAGE_BOOT_RAMDEV_RAM_PA_START)
{
g_ImageType = IMAGE_TYPE_BINDIO;
g_ImageMemory = IMAGE_MEMORY_NAND;
KITLOutputDebugString("\r\nINFO: DIO image with starting address 0x%x.\r\n", pInfo->Region[0].dwRegionStart);
}
return;
}
//-----------------------------------------------------------------------------
//
// Function: OEMVerifyMemory
//
// This function verifies that the address provided is in valid memory,
// and sets globals to describe the image region being updated.
//
// Parameters:
// dwStartAddr
// [in] Address to be verified.
//
// dwLength
// [in] Length of the address, in bytes.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//-----------------------------------------------------------------------------
BOOL OEMVerifyMemory(DWORD dwStartAddr, DWORD dwLength)
{
BOOL rc = TRUE;
DWORD dwPhysVerifyStart;
DWORD dwPhysVerifyEnd;
// First check for DIO image flagged by OEMMultiBINNotify
if (g_ImageType == IMAGE_TYPE_BINDIO)
{
KITLOutputDebugString("INFO: Downloading DIO NAND image.\r\n");
return (TRUE);
}
dwPhysVerifyStart = (DWORD) OALVAtoPA((void *)dwStartAddr);
dwPhysVerifyEnd = dwPhysVerifyStart + dwLength - 1;
KITLOutputDebugString("INFO: OEMVerifyMemory (CA = 0x%x, PA = 0x%x, length = 0x%x)\r\n",
dwStartAddr, dwPhysVerifyStart, dwLength);
if ((dwPhysVerifyStart >= IMAGE_BOOT_XLDRIMAGE_NAND_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_XLDRIMAGE_NAND_PA_END))
{
KITLOutputDebugString("INFO: Downloading XLDR NAND image.\r\n");
g_ImageType = IMAGE_TYPE_XLDR;
g_ImageMemory = IMAGE_MEMORY_NAND;
}
else if ((dwPhysVerifyStart >= IMAGE_BOOT_EBOOTIMAGE_NAND_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_EBOOTIMAGE_NAND_PA_END))
{
KITLOutputDebugString("INFO: Downloading EBOOT NAND image.\r\n");
g_ImageType = IMAGE_TYPE_EBOOT;
g_ImageMemory = IMAGE_MEMORY_NAND;
}
else if ((dwPhysVerifyStart >= IMAGE_BOOT_IPLIMAGE_NAND_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_IPLIMAGE_NAND_PA_END))
{
KITLOutputDebugString("INFO: Downloading IPL NAND image.\r\n");
g_ImageType = IMAGE_TYPE_IPL;
g_ImageMemory = IMAGE_MEMORY_NAND;
}
// DIO and NK share this start address
else if ((dwPhysVerifyStart >= IMAGE_BOOT_NKIMAGE_NAND_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_NKIMAGE_NAND_PA_END))
{
KITLOutputDebugString("INFO: Downloading NK NAND image.\r\n");
g_ImageType = IMAGE_TYPE_NK;
g_ImageMemory = IMAGE_MEMORY_NAND;
}
else if ((dwPhysVerifyStart >= IMAGE_BOOT_EBOOTIMAGE_NOR_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_EBOOTIMAGE_NOR_PA_END))
{
KITLOutputDebugString("INFO: Downloading EBOOT NOR image.\r\n");
g_ImageType = IMAGE_TYPE_EBOOT;
g_ImageMemory = IMAGE_MEMORY_NOR;
}
else if ((dwPhysVerifyStart >= IMAGE_BOOT_NKIMAGE_NOR_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_NKIMAGE_NOR_PA_END))
{
KITLOutputDebugString("INFO: Downloading NK NOR image.\r\n");
g_ImageType = IMAGE_TYPE_NK;
g_ImageMemory = IMAGE_MEMORY_NOR;
}
else if ((dwPhysVerifyStart >= IMAGE_BOOT_NORDEV_NOR_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_NORDEV_NOR_PA_END))
{
KITLOutputDebugString("INFO: Downloading NK NOR image.\r\n");
KITLOutputDebugString("WARNING: NK image will overwrite EBOOT reserved space \r\n");
g_ImageType = IMAGE_TYPE_NK;
g_ImageMemory = IMAGE_MEMORY_NOR;
}
else if ((dwPhysVerifyStart >= IMAGE_BOOT_RAMDEV_RAM_PA_START) && (dwPhysVerifyEnd <= IMAGE_BOOT_RAMDEV_RAM_PA_END))
{
KITLOutputDebugString("INFO: Downloading NK RAM image.\r\n");
g_ImageType = IMAGE_TYPE_NK;
g_ImageMemory = IMAGE_MEMORY_RAM;
}
else
{
KITLOutputDebugString("ERROR: Invalid address range.\r\n");
rc = FALSE;
}
return(rc);
}
//------------------------------------------------------------------------------
//
// Function: StoreEBootCFG
//
// Stores bootloader configuration information (menu settings, etc.) in flash.
//
// Parameters:
// eBootCFG
// [in] Points to bootloader configuration to be stored.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//-----------------------------------------------------------------------------
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.
//
// Parameters:
// eBootCFG
// [out] Points to bootloader configuration that will be filled with
// loaded data.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//-----------------------------------------------------------------------------
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);
}
g_DefaultRamAddress = (PUCHAR)g_EbootCFG.dwLaunchAddr;
return(TRUE);
}
//------------------------------------------------------------------------------
//
// Function: ResetDefaultEBootCFG
//
// Resets the debug bootloader configuration information (menu settings, etc.).
//
// Parameters:
// eBootCFG
// [out] Points to bootloader configuration that will be filled with
// default data.
//
// Returns:
// TRUE indicates success. FALSE indicates failure.
//
//-----------------------------------------------------------------------------
void ResetDefaultEBootCFG(EBOOT_CFG *pEbootCFG)
{
EBOOT_CFG eBootCFG = {0};
KITLOutputDebugString("\r\nResetting factory default configuration...\r\n");
pEbootCFG->autoDownloadImage = EBOOT_CFG_AUTODOWNLOAD_NONE;
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 = (DWORD)OALPAtoCA(IMAGE_BOOT_NKIMAGE_RAM_PA_START);
pEbootCFG->dwPhysStart = 0;
pEbootCFG->dwPhysLen = 0;
pEbootCFG->mac[0] = 0x0000;
pEbootCFG->mac[1] = 0x0000;
pEbootCFG->mac[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
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -