📄 main.c
字号:
else
{
g_bBootMediaExist = TRUE;
}
// Get flash info
if (!FMD_GetInfo(&flashInfo))
{
OALMSG(OAL_ERROR, (L"ERROR: BLFlashDownload: FMD_GetInfo call failed\r\n"));
}
wNUM_BLOCKS = flashInfo.dwNumBlocks;
OALMSG(OAL_INFO, (TEXT("wNUM_BLOCKS : %d(0x%x) \r\n"), wNUM_BLOCKS, wNUM_BLOCKS));
stDeviceInfo = GetNandInfo();
// 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.
KeySelect = WaitForInitialSelection();
// Boot or enter bootloader menu.
//
switch(KeySelect)
{
case 0x20: // Boot menu.
// g_pBootCfg->ConfigFlags &= ~BOOT_OPTION_CLEAN; // Always clear CleanBoot Flags before 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)
{
EdbgOutputDebugString("\r\nLaunching image from boot media ... \r\n");
g_bDownloadImage = FALSE;
}
else
{
EdbgOutputDebugString("\r\nStarting auto-download ... \r\n");
g_bDownloadImage = TRUE;
}
break;
}
SetKITLConfigAndBootOptions();
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) )
{
EdbgOutputDebugString("OEMPlatformInit: ERROR_INVALID_TOC, can not autoboot.\r\n");
return FALSE;
}
switch (g_ImageType)
{
case IMAGE_TYPE_STEPLDR:
EdbgOutputDebugString("Don't support launch STEPLDR.bin\r\n");
break;
case IMAGE_TYPE_LOADER:
EdbgOutputDebugString("Don't support launch EBOOT.bin\r\n");
break;
case IMAGE_TYPE_RAMIMAGE:
OTGDEV_SetSoftDisconnect();
OALMSG(TRUE, (TEXT("OEMPlatformInit: IMAGE_TYPE_RAMIMAGE\r\n")));
if ( !ReadOSImageFromBootMedia( ) )
{
EdbgOutputDebugString("OEMPlatformInit ERROR: Failed to load kernel region into RAM.\r\n");
return FALSE;
}
break;
default:
EdbgOutputDebugString("OEMPlatformInit ERROR: unknown image type: 0x%x \r\n", g_ImageType);
return FALSE;
}
}
else // if ( g_bDownloadImage )
{
switch(g_pBootCfg->BootDevice)
{
case BOOT_DEVICE_ETHERNET:
// Configure Ethernet controller.
if (!InitEthDevice(g_pBootCfg))
{
EdbgOutputDebugString("ERROR: OEMPlatformInit: Failed to initialize Ethernet controller.\r\n");
goto CleanUp;
}
break;
case BOOT_DEVICE_USB_SERIAL:
{
// Configure Serial USB Download
KITL_SERIAL_INFO SerInfo;
SerInfo.pAddress = (UINT8 *)S3C6410_BASE_REG_PA_USBOTG_LINK;
EdbgOutputDebugString("OEMPlatformInit: BootDevice - USB Serial.\r\n");
EdbgOutputDebugString("Waiting for Platform Builder to connect...\r\n");
// Disconnect the device from the bus
OTGDEV_SetSoftDisconnect();
if (!InitializeUSB())
{
EdbgOutputDebugString("OEMPlatformInit: Failed to initialize USB.\r\n");
return(FALSE);
}
if (!Serial_Init(&SerInfo))
{
EdbgOutputDebugString("OEMPlatformInit: Failed to initialize USB for serial download.\r\n");
return(FALSE);
}
EdbgOutputDebugString("OEMPlatformInit: Initialized USB for serial download.\r\n");
}
break;
case BOOT_DEVICE_USB_RNDIS:
EdbgOutputDebugString("OEMPlatformInit: BootDevice - USB RNDIS.\r\n");
// Disconnect the device from the bus
OTGDEV_SetSoftDisconnect();
if (!InitializeUSB())
{
EdbgOutputDebugString("OEMPlatformInit: Failed to initialize USB.\r\n");
return(FALSE);
}
if (!Rndis_Init((UINT8 *)S3C6410_BASE_REG_PA_USBOTG_LINK, 0, g_KITLConfig->mac))
{
EdbgOutputDebugString("OEMPlatformInit: ERROR: Failed to initialize USB RNDIS for Download.\r\n");
return(FALSE);
}
EdbgOutputDebugString("OEMPlatformInit: Initialized USB for RNDIS download.\r\n");
break;
case BOOT_DEVICE_USB_DNW:
// Configure USB Download
InitializeInterrupt();
// Disconnect the device from the bus
OTGDEV_SetSoftDisconnect();
if (!InitializeUSB())
{
EdbgOutputDebugString("OEMPlatformInit: Failed to initialize USB.\r\n");
return(FALSE);
}
break;
default:
EdbgOutputDebugString("OEMPlatformInit: ERROR: unknown Boot device: 0x%x \r\n", g_pBootCfg->BootDevice);
return FALSE;
}
}
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);
EdbgOutputDebugString("INFO: *** Device Name '%s' ***\r\n", pBSPArgs->deviceId);
// We will skip download process, we want to jump to Kernel Address
if ( !g_bDownloadImage)
{
return(BL_JUMP);
}
switch(g_pBootCfg->BootDevice)
{
case BOOT_DEVICE_ETHERNET:
case BOOT_DEVICE_USB_RNDIS:
// 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;
}
// 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))
{
EdbgOutputDebugString("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;
}
break;
case BOOT_DEVICE_USB_SERIAL:
// Send boot requests indefinitely
do
{
OALMSG(TRUE, (TEXT("Sending boot request...\r\n")));
if(!SerialSendBootRequest(BSP_DEVICE_PREFIX))
{
OALMSG(TRUE, (TEXT("Failed to send boot request\r\n")));
return BL_ERROR;
}
}
while(!SerialWaitForBootAck(&bGotJump));
// Ack block zero to start the download
SerialSendBlockAck(0);
if( bGotJump )
{
OALMSG(TRUE, (TEXT("Received boot request ack... jumping to image\r\n")));
}
else
{
OALMSG(TRUE, (TEXT("Received boot request ack... starting download\r\n")));
}
break;
case BOOT_DEVICE_USB_DNW:
EdbgOutputDebugString("Please send the Image through USB.\r\n");
break;
}
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)
{
BOOL ret;
OALMSG(OAL_FUNC, (TEXT("+OEMReadData.\r\n")));
switch(g_pBootCfg->BootDevice)
{
case BOOT_DEVICE_ETHERNET:
case BOOT_DEVICE_USB_RNDIS:
ret = EbootEtherReadData(dwData, pData);
break;
case BOOT_DEVICE_USB_SERIAL:
ret = SerialReadData(dwData, pData);
break;
case BOOT_DEVICE_USB_DNW:
ret = UbootReadData(dwData, pData);
break;
}
return(ret);
}
void OEMReadDebugString(CHAR * szString)
{
USHORT cwNumChars = 0;
USHORT InChar = 0;
while(!((InChar == 0x0d) || (InChar == 0x0a)))
{
InChar = OEMReadDebugByte();
if (InChar != OEM_DEBUG_COM_ERROR && InChar != OEM_DEBUG_READ_NODATA)
{
if ((InChar >= 'a' && InChar <='z') || (InChar >= 'A' && InChar <= 'Z') || (InChar >= '0' && InChar <= '9'))
{
if (cwNumChars < 16)
{
szString[cwNumChars++] = (char)InChar;
OEMWriteDebugByte((BYTE)InChar);
}
}
// If it's a backspace, back up.
//
else if (InChar == 8)
{
if (cwNumChars > 0)
{
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars)
{
szString[cwNumChars] = '\0';
EdbgOutputDebugString("\r\n");
}
}
/*
@func void | OEMShowProgress | Displays download progress for the user.
@rdesc N/A.
@comm
@xref
*/
void OEMShowProgress(DWORD dwPacketNum)
{
// If user select USB_DNW(download thourhg USB using DNW)
// and program to NAND storage, This will be Programming Progress
// If not this is download progress
OALMSG(OAL_INFO&&OAL_FUNC, (TEXT("%d.\r\n"), dwPacketNum));
}
/*
@func void | OEMLaunch | Executes the stored/downloaded image.
@rdesc N/A.
@comm
@xref
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -