📄 main.c
字号:
pBSPArgs->header.bspVersion = BSP_ARGS_VERSION;
pBSPArgs->kitl.flags = OAL_KITL_FLAGS_ENABLED | OAL_KITL_FLAGS_VMINI;
pBSPArgs->kitl.devLoc.IfcType = Internal;
pBSPArgs->kitl.devLoc.BusNumber = 0;
pBSPArgs->kitl.devLoc.LogicalLoc = BSP_BASE_REG_PA_CS8900A_IOBASE;
// This should not change unless reserved blocks are added/removed;
// made global to do the calc only once.
g_dwImageStartBlock = IMAGE_START_BLOCK;
// Try to initialize the boot media block driver and BinFS partition.
//
if ( !BP_Init((LPBYTE)BINFS_RAM_START, BINFS_RAM_LENGTH, NULL, NULL, NULL) )
{
OALMSG(OAL_WARN, (TEXT("WARNING: OEMPlatformInit failed to initialize Boot Media.\r\n")));
g_bBootMediaExist = FALSE;
}
else
g_bBootMediaExist = TRUE;
// Try to retrieve TOC (and Boot config) from boot media
//
if ( !TOC_Read( ) )
{
// use default settings
TOC_Init(DEFAULT_IMAGE_DESCRIPTOR, (IMAGE_TYPE_RAMIMAGE), 0, 0, 0);
}
// Display boot message - user can halt the autoboot by pressing any key on the serial terminal emulator.
//
BootDelay = g_pBootCfg->BootDelay;
if (g_pBootCfg->ConfigFlags & BOOT_TYPE_DIRECT)
{
OALMSG(TRUE, (TEXT("Press [ENTER] to launch image stored on boot media, or [SPACE] to enter boot monitor.\r\n")));
OALMSG(TRUE, (TEXT("\r\nInitiating image launch in %d seconds. "),BootDelay--));
}
else
{
OALMSG(TRUE, (TEXT("Press [ENTER] to download image stored on boot media, or [SPACE] to enter boot monitor.\r\n")));
OALMSG(TRUE, (TEXT("\r\nInitiating image download in %d seconds. "),BootDelay--));
}
dwStartTime = OEMEthGetSecs();
dwPrevTime = dwStartTime;
dwCurrTime = dwStartTime;
KeySelect = 0;
// Allow the user to break into the bootloader menu.
//
while((dwCurrTime - dwStartTime) < g_pBootCfg->BootDelay)
{
KeySelect = OEMReadDebugByte();
if ((KeySelect == 0x20) || (KeySelect == 0x0d))
break;
dwCurrTime = OEMEthGetSecs();
if (dwCurrTime > dwPrevTime)
{
int i, j;
// 1 Second has elapsed - update the countdown timer.
dwPrevTime = dwCurrTime;
if (BootDelay < 9)
i = 11;
else if (BootDelay < 99)
i = 12;
else if (BootDelay < 999)
i = 13;
for(j = 0; j < i; j++)
OEMWriteDebugByte((BYTE)0x08); // print back space
EdbgOutputDebugString ( "%d seconds. ", BootDelay--);
}
}
OALMSG(OAL_INFO, (TEXT("\r\n")));
// Boot or enter bootloader menu.
//
switch(KeySelect)
{
case 0x20: // Boot menu.
g_bDownloadImage = MainMenu(g_pBootCfg);
break;
case 0x00: // Fall through if no keys were pressed -or-
case 0x0d: // the user cancelled the countdown.
default:
if (g_pBootCfg->ConfigFlags & BOOT_TYPE_DIRECT)
{
OALMSG(TRUE, (TEXT("\r\nLaunching image from boot media ... \r\n")));
g_bDownloadImage = FALSE;
}
else
{
OALMSG(TRUE, (TEXT("\r\nStarting auto-download ... \r\n")));
g_bDownloadImage = TRUE;
}
break;
}
if ( !g_bDownloadImage )
{
// User doesn't want to download image - load it from the boot media.
// We could read an entire nk.bin or nk.nb0 into ram and jump.
if ( !VALID_TOC(g_pTOC) ) {
OALMSG(OAL_ERROR, (TEXT("OEMPlatformInit: ERROR_INVALID_TOC, can not autoboot.\r\n")));
return FALSE;
}
switch (g_ImageType) {
case IMAGE_TYPE_STEPLDR:
OALMSG(TRUE, (TEXT("Don't support launch STEPLDR.bin\r\n")));
break;
case IMAGE_TYPE_LOADER:
OALMSG(TRUE, (TEXT("Don't support launch EBOOT.bin\r\n")));
break;
case IMAGE_TYPE_RAMIMAGE:
OALMSG(TRUE, (TEXT("OEMPlatformInit: IMAGE_TYPE_RAMIMAGE\r\n")));
if ( !ReadOSImageFromBootMedia( ) )
{
OALMSG(OAL_ERROR, (TEXT("OEMPlatformInit ERROR: Failed to load kernel region into RAM.\r\n")));
return FALSE;
}
break;
default:
OALMSG(OAL_ERROR, (TEXT("OEMPlatformInit ERROR: unknown image type: 0x%x \r\n"), g_ImageType));
return FALSE;
}
}
// Configure Ethernet controller.
//
if (!InitEthDevice(g_pBootCfg))
{
OALMSG(OAL_ERROR, (TEXT("ERROR: OEMPlatformInit: Failed to initialize Ethernet controller.\r\n")));
goto CleanUp;
}
bResult = TRUE;
CleanUp:
OALMSG(OAL_FUNC, (TEXT("_OEMPlatformInit.\r\n")));
return(bResult);
}
/*
@func DWORD | OEMPreDownload | Complete pre-download tasks - get IP address, initialize TFTP, etc.
@rdesc BL_DOWNLOAD = Platform Builder is asking us to download an image, BL_JUMP = Platform Builder is requesting we jump to an existing image, BL_ERROR = Failure.
@comm
@xref
*/
DWORD OEMPreDownload(void)
{
BOOL bGotJump = FALSE;
DWORD dwDHCPLeaseTime = 0;
PDWORD pdwDHCPLeaseTime = &dwDHCPLeaseTime;
DWORD dwBootFlags = 0;
OALMSG(OAL_FUNC, (TEXT("+OEMPreDownload.\r\n")));
// Create device name based on Ethernet address (this is how Platform Builder identifies this device).
//
OALKitlCreateName(BSP_DEVICE_PREFIX, pBSPArgs->kitl.mac, pBSPArgs->deviceId);
OALMSG(OAL_INFO, (L"INFO: *** Device Name '%hs' ***\r\n", pBSPArgs->deviceId));
// If the user wants to use a static IP address, don't request an address
// from a DHCP server. This is done by passing in a NULL for the DHCP
// lease time variable. If user specified a static IP address, use it (don't use DHCP).
//
if (!(g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DHCP))
{
// Static IP address.
pBSPArgs->kitl.ipAddress = g_pBootCfg->EdbgAddr.dwIP;
pBSPArgs->kitl.ipMask = g_pBootCfg->SubnetMask;
pBSPArgs->kitl.flags &= ~OAL_KITL_FLAGS_DHCP;
pdwDHCPLeaseTime = NULL;
OALMSG(OAL_INFO, (TEXT("INFO: Using static IP address %s.\r\n"), inet_ntoa(pBSPArgs->kitl.ipAddress)));
OALMSG(OAL_INFO, (TEXT("INFO: Using subnet mask %s.\r\n"), inet_ntoa(pBSPArgs->kitl.ipMask)));
}
else
{
pBSPArgs->kitl.ipAddress = 0;
pBSPArgs->kitl.ipMask = 0;
}
if ( !g_bDownloadImage)
{
return(BL_JUMP);
}
// Initialize the the TFTP transport.
//
g_DeviceAddr.dwIP = pBSPArgs->kitl.ipAddress;
memcpy(g_DeviceAddr.wMAC, pBSPArgs->kitl.mac, (3 * sizeof(UINT16)));
g_DeviceAddr.wPort = 0;
if (!EbootInitEtherTransport(&g_DeviceAddr,
&pBSPArgs->kitl.ipMask,
&bGotJump,
pdwDHCPLeaseTime,
EBOOT_VERSION_MAJOR,
EBOOT_VERSION_MINOR,
BSP_DEVICE_PREFIX,
pBSPArgs->deviceId,
EDBG_CPU_ARM720,
dwBootFlags))
{
OALMSG(OAL_ERROR, (TEXT("ERROR: OEMPreDownload: Failed to initialize Ethernet connection.\r\n")));
return(BL_ERROR);
}
// If the user wanted a DHCP address, we presumably have it now - save it for the OS to use.
//
if (g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DHCP)
{
// DHCP address.
pBSPArgs->kitl.ipAddress = g_DeviceAddr.dwIP;
pBSPArgs->kitl.flags |= OAL_KITL_FLAGS_DHCP;
}
OALMSG(OAL_FUNC, (TEXT("_OEMPreDownload.\r\n")));
return(bGotJump ? BL_JUMP : BL_DOWNLOAD);
}
/*
@func BOOL | OEMReadData | Generically read download data (abstracts actual transport read call).
@rdesc TRUE = Success, FALSE = Failure.
@comm
@xref
*/
BOOL OEMReadData(DWORD dwData, PUCHAR pData)
{
OALMSG(OAL_FUNC, (TEXT("+OEMReadData.\r\n")));
return(EbootEtherReadData(dwData, pData));
}
/*
@func void | OEMShowProgress | Displays download progress for the user.
@rdesc N/A.
@comm
@xref
*/
void OEMShowProgress(DWORD dwPacketNum)
{
OALMSG(OAL_FUNC, (TEXT("+OEMShowProgress.\r\n")));
}
/*
@func void | OEMLaunch | Executes the stored/downloaded image.
@rdesc N/A.
@comm
@xref
*/
void OEMLaunch( DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr, const ROMHDR *pRomHdr )
{
DWORD dwPhysLaunchAddr;
EDBG_ADDR EshellHostAddr;
EDBG_OS_CONFIG_DATA *pCfgData;
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))
{
OALMSG(OAL_ERROR, (TEXT("ERROR: OEMLaunch: Failed to store image to Smart Media.\r\n")));
goto CleanUp;
}
OALMSG(TRUE, (TEXT("INFO: Step loader image stored to Smart Media. Please Reboot. Halting...\r\n")));
while(1)
{
// Wait...
}
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))
{
OALMSG(OAL_ERROR, (TEXT("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();
}
OALMSG(TRUE, (TEXT("INFO: Eboot image stored to Smart Media. Please Reboot. Halting...\r\n")));
while(1)
{
// Wait...
}
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))
{
OALMSG(OAL_ERROR, (TEXT("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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -