main.c
来自「SAMSUNG S3C6410 CPU BSP for winmobile6」· C语言 代码 · 共 1,638 行 · 第 1/4 页
C
1,638 行
}
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(1, (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(1, (L"INFO: *** Device Name '%hs' ***\r\n", pBSPArgs->deviceId));
if ( g_bUSBDownload == FALSE && g_bT32Download == FALSE ) // jylee
{
// 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(1, (TEXT("INFO: Using static IP address %s.\r\n"), OALKitlIPtoString(pBSPArgs->kitl.ipAddress)));
OALMSG(OAL_INFO, (TEXT("INFO: Using subnet mask %s.\r\n"), OALKitlIPtoString(pBSPArgs->kitl.ipMask)));
}
else
{
pBSPArgs->kitl.ipAddress = 0;
pBSPArgs->kitl.ipMask = 0;
}
if(g_pBootCfg->ConfigFlags & CONFIG_FLAGS_KITL)
pBSPArgs->kitl.flags |= OAL_KITL_FLAGS_ENABLED | OAL_KITL_FLAGS_VMINI;
else
pBSPArgs->kitl.flags &= ~(OAL_KITL_FLAGS_ENABLED | OAL_KITL_FLAGS_VMINI);
RETAILMSG(1,(TEXT("kitlenable= %d, flags= %x\r\n"),g_pBootCfg->ConfigFlags,pBSPArgs->kitl.flags));
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(1, (TEXT("_OEMPreDownload.\r\n")));
}
else if (g_bUSBDownload == TRUE) // jylee
{
// clear ram being downloading to 0xff because of initializing dummy data or downloaded data through usb
memset((void*)FILE_CACHE_START, 0xff, FILE_CACHE_LENGTH);
OALMSG(TRUE, (TEXT("Please send the Image through USB.\r\n")));
}
#if (USE_TRACE32_DOWNLOAD)
// jylee
else if (g_bT32Download == TRUE)
{
OALMSG(TRUE, (TEXT("Please send the Image through Trace32.\r\n")));
Trace32_Init();
}
#endif
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 = FALSE;
// int i;
if ( g_bUSBDownload == FALSE && g_bT32Download == FALSE) // jylee
//if ( g_bUSBDownload == FALSE )
{
// OALMSG(TRUE, (TEXT("\r\nINFO: dwData = %x, pData = %x\r\n"), dwData, pData));
ret = EbootEtherReadData(dwData, pData);
// OALMSG(TRUE, (TEXT("\r\n")));
// for ( i = 0; i < dwData; i++ )
// {
// OALMSG(TRUE, (TEXT("<%x>"), *(pData+i)));
// if ( i % 16 == 15 )
// OALMSG(TRUE, (TEXT("\r\n")));
// }
// OALMSG(TRUE, (TEXT("\r\n")));
}
else if ( g_bUSBDownload == TRUE ) // jylee
{
// OALMSG(TRUE, (TEXT("\r\nINFO: dwData = %x, pData = %x\r\n"), dwData, pData));
ret = UbootReadData(dwData, pData);
// OALMSG(TRUE, (TEXT("\r\n")));
// for ( i = 0; i < dwData; i++ )
// {
// OALMSG(TRUE, (TEXT("<%x>"), *(pData+i)));
// if ( i % 16 == 15 )
// OALMSG(TRUE, (TEXT("\r\n")));
// }
// OALMSG(TRUE, (TEXT("\r\n")));
}
#if (USE_TRACE32_DOWNLOAD)
else if ( g_bT32Download == TRUE) // jylee
{
ret = Trace32ReadData(dwData, pData);
}
#endif
/*
OALMSG(TRUE, (TEXT("\r\n")));
for ( i = 0; i < dwData; i++ )
{
OALMSG(TRUE, (TEXT("<%x>"), *(pData+i)));
if ( i % 16 == 15 )
OALMSG(TRUE, (TEXT("\r\n")));
}
OALMSG(TRUE, (TEXT("\r\n")));
*/
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)
{
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;
OALMSG(1, (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:
case IMAGE_TYPE_IPL:
case IMAGE_TYPE_SUPERIPL:
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_FLASHBIN:
case IMAGE_TYPE_DIO:
case IMAGE_TYPE_DIONB0:
PocketStoreII_STL_Format(PARTITION_ID_COPIEDOS);
if (!WriteRawImageToBootMedia(dwImageStart, dwImageLength, dwLaunchAddr))
{
OALMSG(OAL_ERROR, (TEXT("ERROR: OEMLaunch: Failed to store image to Smart Media.\r\n")));
goto CleanUp;
}
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;
default:
break;
}
}
if (BLFlashDownload() != BL_JUMP) {
OALMSG(OAL_ERROR, (L"ERROR: OEMLaunch: "
L"Image load from flash memory failed\r\n"
));
goto CleanUp;
}
OALMSG(1, (TEXT("waitforconnect\r\n")));
/*
// 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).
//
EDBG_ADDR EshellHostAddr;
EDBG_OS_CONFIG_DATA *pCfgData;
if (g_bDownloadImage)
{
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)))
{
OALMSG(OAL_ERROR, (TEXT("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;
}
}
*/
// 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));
}
// Jump to downloaded image (use the physical address since we'll be turning the MMU off)...
//
dwPhysLaunchAddr = (DWORD)OALVAtoPA((void *)dwLaunchAddr);
OALMSG(TRUE, (TEXT("INFO: OEMLaunch: Jumping to Physical Address 0x%Xh (Virtual Address 0x%Xh)...\r\n\r\n\r\n"), dwPhysLaunchAddr, dwLaunchAddr));
// Jump...
//
Launch(dwPhysLaunchAddr);
CleanUp:
OALMSG(TRUE, (TEXT("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
//
//------------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?