📄 main.c
字号:
*/
void OEMLaunch( DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr, const ROMHDR *pRomHdr )
{
DWORD dwPhysLaunchAddr;
EDBG_ADDR EshellHostAddr;
EDBG_OS_CONFIG_DATA *pCfgData;
UINT32 i;
OALMSG(OAL_FUNC, (TEXT("+OEMLaunch.\r\n")));
// If the user requested that a disk image (stored in RAM now) be written to the SmartMedia card, so it now.
//
if (g_bDownloadImage && (g_pBootCfg->ConfigFlags & TARGET_TYPE_NAND))
{
// Since this platform only supports RAM images, the image cache address is the same as the image RAM address.
//
switch (g_ImageType)
{
case IMAGE_TYPE_STEPLDR:
if (!WriteRawImageToBootMedia(dwImageStart, dwImageLength, dwLaunchAddr))
{
EdbgOutputDebugString("ERROR: OEMLaunch: Failed to store image to Smart Media.\r\n");
goto CleanUp;
}
EdbgOutputDebugString("INFO: Step loader image stored to Smart Media. Please Reboot. Halting...\r\n");
SpinForever();
break;
case IMAGE_TYPE_LOADER:
g_pTOC->id[0].dwLoadAddress = dwImageStart;
g_pTOC->id[0].dwTtlSectors = FILE_TO_SECTOR_SIZE(dwImageLength);
if (!WriteRawImageToBootMedia(dwImageStart, dwImageLength, dwLaunchAddr))
{
EdbgOutputDebugString("ERROR: OEMLaunch: Failed to store image to Smart Media.\r\n");
goto CleanUp;
}
if (dwLaunchAddr && (g_pTOC->id[0].dwJumpAddress != dwLaunchAddr))
{
g_pTOC->id[0].dwJumpAddress = dwLaunchAddr;
if ( !TOC_Write() ) {
EdbgOutputDebugString("*** OEMLaunch ERROR: TOC_Write failed! Next boot may not load from disk *** \r\n");
}
TOC_Print();
}
EdbgOutputDebugString("INFO: Eboot image stored to Smart Media. Please Reboot. Halting...\r\n");
SpinForever();
break;
case IMAGE_TYPE_RAMIMAGE:
g_pTOC->id[g_dwTocEntry].dwLoadAddress = dwImageStart;
g_pTOC->id[g_dwTocEntry].dwTtlSectors = FILE_TO_SECTOR_SIZE(dwImageLength);
if (!WriteOSImageToBootMedia(dwImageStart, dwImageLength, dwLaunchAddr))
{
EdbgOutputDebugString("ERROR: OEMLaunch: Failed to store image to Smart Media.\r\n");
goto CleanUp;
}
if (dwLaunchAddr && (g_pTOC->id[g_dwTocEntry].dwJumpAddress != dwLaunchAddr))
{
g_pTOC->id[g_dwTocEntry].dwJumpAddress = dwLaunchAddr;
if ( !TOC_Write() ) {
EdbgOutputDebugString("*** OEMLaunch ERROR: TOC_Write failed! Next boot may not load from disk *** \r\n");
}
TOC_Print();
}
else
{
dwLaunchAddr= g_pTOC->id[g_dwTocEntry].dwJumpAddress;
EdbgOutputDebugString("INFO: using TOC[%d] dwJumpAddress: 0x%x\r\n", g_dwTocEntry, dwLaunchAddr);
}
break;
}
}
else if(g_bDownloadImage)
{
switch (g_ImageType)
{
case IMAGE_TYPE_STEPLDR:
EdbgOutputDebugString("Stepldr image can't launch from ram.\r\n");
EdbgOutputDebugString("You should program it into flash.\r\n");
SpinForever();
break;
case IMAGE_TYPE_LOADER:
EdbgOutputDebugString("Eboot image can't launch from ram.\r\n");
EdbgOutputDebugString("You should program it into flash.\r\n");
SpinForever();
break;
default:
break;
}
}
// Wait for Platform Builder to connect after the download and send us IP and port settings for service
// connections - also sends us KITL flags. This information is used later by the OS (KITL).
//
if (g_bDownloadImage & g_bWaitForConnect)
{
EdbgOutputDebugString("Wait For Connect...\r\n");
switch(g_pBootCfg->BootDevice)
{
case BOOT_DEVICE_ETHERNET:
case BOOT_DEVICE_USB_RNDIS:
memset(&EshellHostAddr, 0, sizeof(EDBG_ADDR));
g_DeviceAddr.dwIP = pBSPArgs->kitl.ipAddress;
memcpy(g_DeviceAddr.wMAC, pBSPArgs->kitl.mac, (3 * sizeof(UINT16)));
g_DeviceAddr.wPort = 0;
if (!(pCfgData = EbootWaitForHostConnect(&g_DeviceAddr, &EshellHostAddr)))
{
EdbgOutputDebugString("ERROR: OEMLaunch: EbootWaitForHostConnect failed.\r\n");
goto CleanUp;
}
// 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->KitlTransport & KTS_PASSIVE_MODE)
{
pBSPArgs->kitl.flags |= OAL_KITL_FLAGS_PASSIVE;
}
// save ethernet address for ethernet kitl // added by jjg 06.09.18
SaveEthernetAddress();
break;
case BOOT_DEVICE_USB_SERIAL:
{
DWORD dwKitlTransport;
dwKitlTransport = SerialWaitForJump();
if ((dwKitlTransport & KTS_PASSIVE_MODE) != 0)
{
pBSPArgs->kitl.flags |= OAL_KITL_FLAGS_PASSIVE;
}
}
break;
case BOOT_DEVICE_USB_DNW:
break;
}
}
// If a launch address was provided, we must have downloaded the image, save the address in case we
// want to jump to this image next time. If no launch address was provided, retrieve the last one.
//
if (dwLaunchAddr && (g_pTOC->id[g_dwTocEntry].dwJumpAddress != dwLaunchAddr))
{
g_pTOC->id[g_dwTocEntry].dwJumpAddress = dwLaunchAddr;
}
else
{
dwLaunchAddr= g_pTOC->id[g_dwTocEntry].dwJumpAddress;
OALMSG(OAL_INFO, (TEXT("INFO: using TOC[%d] dwJumpAddress: 0x%x\r\n"), g_dwTocEntry, dwLaunchAddr));
}
OALMSG(OAL_VERBOSE, (TEXT("pBSPArgs :0x%x\r\n"), pBSPArgs));
for(i=0;i<sizeof(BSP_ARGS); i++)
{
OALMSG(OAL_VERBOSE, (TEXT("0x%02x "),*((UINT8*)pBSPArgs+i)));
}
// Jump to downloaded image (use the physical address since we'll be turning the MMU off)...
//
dwPhysLaunchAddr = (DWORD)OALVAtoPA((void *)dwLaunchAddr);
EdbgOutputDebugString("INFO: OEMLaunch: Jumping to Physical Address 0x%Xh (Virtual Address 0x%Xh)...\r\n\r\n\r\n", dwPhysLaunchAddr, dwLaunchAddr);
// Jump...
//
Launch(dwPhysLaunchAddr);
CleanUp:
EdbgOutputDebugString("ERROR: OEMLaunch: Halting...\r\n");
SpinForever();
}
//------------------------------------------------------------------------------
//
// Function Name: OEMVerifyMemory( DWORD dwStartAddr, DWORD dwLength )
// Description..: This function verifies the passed address range lies
// within a valid region of memory. Additionally this function
// sets the g_ImageType if the image is a boot loader.
// Inputs.......: DWORD Memory start address
// DWORD Memory length
// Outputs......: BOOL - true if verified, false otherwise
//
//------------------------------------------------------------------------------
BOOL OEMVerifyMemory( DWORD dwStartAddr, DWORD dwLength )
{
OALMSG(OAL_FUNC, (TEXT("+OEMVerifyMemory.\r\n")));
OALMSG(OAL_INFO, (TEXT("dwStartAddr:0x%x, dwLength:0x%x\r\n"), dwStartAddr, dwLength));
// Is the image being downloaded the stepldr?
if ((dwStartAddr >= STEPLDR_RAM_IMAGE_BASE) &&
((dwStartAddr + dwLength - 1) < (STEPLDR_RAM_IMAGE_BASE + STEPLDR_RAM_IMAGE_SIZE - STEPLDR_BIN_HEAD_CUT_OFFSET)))
{
EdbgOutputDebugString("OEMVerifyMemory: Stepldr image\r\n");
g_ImageType = IMAGE_TYPE_STEPLDR; // Stepldr image.
return TRUE;
}
// Is the image being downloaded the bootloader?
else if ((dwStartAddr >= EBOOT_STORE_ADDRESS) &&
((dwStartAddr + dwLength - 1) < (EBOOT_STORE_ADDRESS + EBOOT_STORE_MAX_LENGTH)))
{
EdbgOutputDebugString("OEMVerifyMemory: Eboot image\r\n");
g_ImageType = IMAGE_TYPE_LOADER; // Eboot image.
return TRUE;
}
// Is it a ram image?
else if ((dwStartAddr >= ROM_RAMIMAGE_START) &&
((dwStartAddr + dwLength - 1) < (ROM_RAMIMAGE_START + ROM_RAMIMAGE_SIZE)))
{
EdbgOutputDebugString("OEMVerifyMemory: RAM image\r\n");
g_ImageType = IMAGE_TYPE_RAMIMAGE;
return TRUE;
}
else if (!dwStartAddr && !dwLength)
{
EdbgOutputDebugString("OEMVerifyMemory: Don't support raw image\r\n");
g_ImageType = IMAGE_TYPE_RAWBIN;
return FALSE;
}
// HACKHACK: get around MXIP images with funky addresses
OALMSG(TRUE, (TEXT("BIN image type is unknown\r\n")));
OALMSG(OAL_FUNC, (TEXT("_OEMVerifyMemory.\r\n")));
return FALSE;
}
/*
@func void | OEMMultiBINNotify | Called by blcommon to nofity the OEM code of the number, size, and location of one or more BIN regions,
this routine collects the information and uses it when temporarily caching a flash image in RAM prior to final storage.
@rdesc N/A.
@comm
@xref
*/
void OEMMultiBINNotify(const PMultiBINInfo pInfo)
{
BYTE nCount;
OALMSG(OAL_FUNC, (TEXT("+OEMMultiBINNotify.\r\n")));
if (!pInfo || !pInfo->dwNumRegions)
{
EdbgOutputDebugString("WARNING: OEMMultiBINNotify: Invalid BIN region descriptor(s).\r\n");
return;
}
if (!pInfo->Region[0].dwRegionStart && !pInfo->Region[0].dwRegionLength)
{
return;
}
g_dwMinImageStart = pInfo->Region[0].dwRegionStart;
EdbgOutputDebugString("\r\nDownload BIN file information:\r\n");
EdbgOutputDebugString("-----------------------------------------------------\r\n");
for (nCount = 0 ; nCount < pInfo->dwNumRegions ; nCount++)
{
EdbgOutputDebugString("[%d]: Base Address=0x%x Length=0x%x\r\n",
nCount, pInfo->Region[nCount].dwRegionStart, pInfo->Region[nCount].dwRegionLength);
if (pInfo->Region[nCount].dwRegionStart < g_dwMinImageStart)
{
g_dwMinImageStart = pInfo->Region[nCount].dwRegionStart;
if (g_dwMinImageStart == 0)
{
EdbgOutputDebugString("WARNING: OEMMultiBINNotify: Bad start address for region (%d).\r\n", nCount);
return;
}
}
}
memcpy((LPBYTE)&g_BINRegionInfo, (LPBYTE)pInfo, sizeof(MultiBINInfo));
EdbgOutputDebugString("-----------------------------------------------------\r\n");
OALMSG(OAL_FUNC, (TEXT("_OEMMultiBINNotify.\r\n")));
}
/*
@func PVOID | GetKernelExtPointer | Locates the kernel region's extension area pointer.
@rdesc Pointer to the kernel's extension area.
@comm
@xref
*/
PVOID GetKernelExtPointer(DWORD dwRegionStart, DWORD dwRegionLength)
{
DWORD dwCacheAddress = 0;
ROMHDR *pROMHeader;
DWORD dwNumModules = 0;
TOCentry *pTOC;
if (dwRegionStart == 0 || dwRegionLength == 0)
return(NULL);
if (*(LPDWORD) OEMMapMemAddr (dwRegionStart, dwRegionStart + ROM_SIGNATURE_OFFSET) != ROM_SIGNATURE)
return NULL;
// A pointer to the ROMHDR structure lives just past the ROM_SIGNATURE (which is a longword value). Note that
// this pointer is remapped since it might be a flash address (image destined for flash), but is actually cached
// in RAM.
//
dwCacheAddress = *(LPDWORD) OEMMapMemAddr (dwRegionStart, dwRegionStart + ROM_SIGNATURE_OFFSET + sizeof(ULONG));
pROMHeader = (ROMHDR *) OEMMapMemAddr (dwRegionStart, dwCacheAddress);
// Make sure sure are some modules in the table of contents.
//
if ((dwNumModules = pROMHeader->nummods) == 0)
return NULL;
// Locate the table of contents and search for the kernel executable and the TOC immediately follows the ROMHDR.
//
pTOC = (TOCentry *)(pROMHeader + 1);
while(dwNumModules--) {
LPBYTE pFileName = OEMMapMemAddr(dwRegionStart, (DWORD)pTOC->lpszFileName);
EdbgOutputDebugString("[%d] Module Name: %s\r\n", dwNumModules, pFileName);
if (!strcmp((const char *)pFileName, "nk.exe")) {
return ((PVOID)(pROMHeader->pExtensions));
}
++pTOC;
}
return NULL;
}
/*
@func BOOL | OEMDebugInit | Initializes the serial port for debug output message.
@rdesc TRUE == Success and FALSE == Failure.
@comm
@xref
*/
BOOL OEMDebugInit(void)
{
// Set up function callbacks used by blcommon.
//
g_pOEMVerifyMemory = OEMVerifyMemory; // Verify RAM.
g_pOEMMultiBINNotify = OEMMultiBINNotify;
// Call serial initialization routine (shared with the OAL).
//
OEMInitDebugSerial();
return(TRUE);
}
/*
@func void | SaveEthernetAddress | Save Ethernet Address on IMAGE_SHARE_ARGS_UA_START for Ethernet KITL
@rdesc
@comm
@xref
*/
void SaveEthernetAddress()
{
memcpy(pBSPArgs->kitl.mac, g_pBootCfg->EdbgAddr.wMAC, 6);
if (!(g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DHCP))
{
// Static IP address.
pBSPArgs->kitl.ipAddress = g_pBootCfg->EdbgAddr.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -