📄 ebootmain.c
字号:
dwPrevTime = dwStartTime;
dwCurrTime = dwStartTime;
// dwBootDelay = g_pBootCfg->BootDelay;
oldh=WM_SelectWindow(0);
// if(boot_picture_exist == TRUE)
// GUI_DrawBitmap (&bmbootpicture, 0, 0);
GUI_SetTextMode(GUI_TEXTMODE_TRANS);
GUI_SetFont(&GUI_Font16_1);
GUI_SetBkColor(GUI_BLUE);
GUI_DispStringAt("Press [+] and [-] to cancel the auto boot" , 10, 200);
GUI_DispStringAt("auto boot in ",10,216);
xpos=GUI_GetDispPosX();
GUI_DispDec(dwBootDelay--, 3);
GUI_DispString(" seconds. ");
// EdbgOutputDebugString ( "Press [ENTER] to launch image stored on boot media, or [SPACE] to enter usb monitor.\r\n");
// EdbgOutputDebugString ( "\r\nInitiating image launch in %d seconds. ", dwBootDelay--);
// allow the user to break into boot monitor
while(dwBootDelay)//(dwCurrTime - dwStartTime) < dwBootDelay*OS_TICKS_PER_SEC)
{
cKeySelect = GUI_GetKey();
//if ((cKeySelect == 0x20) || (cKeySelect == 0x0d))
if((cKeySelect == '+') || (cKeySelect == '-'))
{
int cnt=0;
int key2 = GUI_GetKey();
while((key2 == 0)&&(cnt<200))
{
OSTimeDly(1);
key2 = GUI_GetKey();
cnt++;
}
if(cnt>=200)
continue;
if(((key2 == '+')||(key2 == '-'))&&(key2 != cKeySelect))
{
cKeySelect = 0x20;//cKeySelect = GUI_GetKey();
break;
}
// cKeySelect = 0x20;
// break;
}
// break;
dwCurrTime = OSTimeGet();//OEMEthGetSecs();
GUI_Exec();
if (dwCurrTime - dwPrevTime>100)
{
int i=0, j;
// 1 Second has elapsed - update the countdown timer.
dwPrevTime = dwCurrTime;
if (dwBootDelay < 9)
i = 11;
else if (dwBootDelay < 99)
i = 12;
else if (dwBootDelay < 999)
i = 13;
// for(j = 0; j < i; j++)
// OEMWriteDebugByte((BYTE)0x08); // print back space
GUI_GotoX(xpos);//(i-10));
GUI_SetTextMode(GUI_TEXTMODE_NORMAL);
GUI_DispDec(dwBootDelay--, 3);
GUI_DispString(" seconds. ");
// EdbgOutputDebugString ( "%d seconds. ", dwBootDelay--);
}
}
WM_SelectWindow(oldh);
EdbgOutputDebugString ( "\r\n");
switch(cKeySelect)
{
case 0x20: // Boot monitor.
usbMain();//g_bDownloadImage = BootMonitor( );
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;
}
// usbMain();
if(/*ReadImageFromNand()*/ReadKernelRegionFromBootMedia( ) == FALSE)
{
#if 1
FS_FILE *fp;
if((NKFp=FS_FOpen("nk.bin","rb")) == NULL)
{
if((fp=FS_FOpen("nk.nb0","rb")) == NULL)
usbMain();
else
{
//FS_FRead((void *)0x30200000, fp->size, 1, fp);
FS_size_t block_size=1024*512;
recv_length=0;
WM_ShowWindow(hFrameWin);
PROGBAR_SetMinMax(hProgBar, 0, fp->size/1024);
for(;recv_length<fp->size;)
{
FS_FRead((void *)(0x30200000+recv_length), block_size, 1, fp);
recv_length+=512*1024;
if(hProgBar)
PROGBAR_SetValue(hProgBar, recv_length/1024);
if(recv_length+512*1024>fp->size)
block_size=fp->size-recv_length;
}
GUI_Exec();
Launch(0x30201000);
}
}
else
{
//FS_FRead((void *)0x32000000, NKFp->size, 1, NKFp);
readPtIndex = 0x32000000;
g_bDownloadImage = TRUE;
// FS_FRead((void *)0x32000000, fp->size, 1, fp);
recv_length = 0;
WM_ShowWindow(hFrameWin);
PROGBAR_SetMinMax(hProgBar, 0, NKFp->size/1024);
DownloadImage (&dwImageStart, &dwImageLength, &dwLaunchAddr);
OEMLaunch (dwImageStart, dwImageLength, dwLaunchAddr, (const ROMHDR *)0);
}
#else
usbMain();
#endif
}
dwLaunchAddr= g_pTOC->id[g_dwTocEntry].dwJumpAddress;
EdbgOutputDebugString("INFO: using TOC[%d] dwJumpAddress: 0x%x\r\n", g_dwTocEntry, dwLaunchAddr);
EdbgOutputDebugString("\r\nJumping to image at virtual address 0x%Xh\r\n", dwLaunchAddr);
// Our Launch function takes Physical address, so we need to convert it
// to physical address
dwLaunchAddr = ToPhysicalAddr(dwLaunchAddr);
EdbgOutputDebugString("\r\n::: Physical Launch Address: 0x%Xh\r\n",dwLaunchAddr);
// rLCDCON1=rLCDCON1& 0x3fffe; //turn off the LCD
// Delay(100);
Uart_TxEmpty(1);
rINTMSK=BIT_ALLMSK;
// OS_ENTER_CRITICAL();
if((license_valid != TRUE) || (memcmp(&output_decrypt[8+54],plaintext_b,54)!=0))
{
pBSPArgs->license_sig = 0;
// EdbgOutputDebugString("2 license is not valid\n");
}
Launch(dwLaunchAddr);
return 0;
}
BOOL OEMPlatformInit()
{
SYSTEMTIME st;
SYSTEMTIME defst = {2002, 1, 0, 1, 12, 0, 0, 0};
DWORD dwStartTime, dwPrevTime, dwCurrTime;
int cKeySelect = 0;
DWORD dwBootDelay = 10; // seconds. N.B: change for retail device!
#ifdef SIMULATOR
EdbgOutputDebugString("Microsoft Windows CE SMDK2440 Bootloader *** SIMULATOR *** \r\n");
#else
EdbgOutputDebugString("Microsoft Windows CE SMDK2440 Bootloader Version %d.%d Built %s %s \r\n",
EBOOT_VERSION_MAJOR, EBOOT_VERSION_MINOR, __DATE__, __TIME__);
#endif
// Initialize the globals
//
memset((LPVOID)pBSPArgs, 0, sizeof(BSP_ARGS));
if(license_valid == TRUE)
{
pBSPArgs->header.signature = OAL_ARGS_SIGNATURE;
pBSPArgs->header.oalVersion = OAL_ARGS_VERSION;
pBSPArgs->header.bspVersion = BSP_ARGS_VERSION;
pBSPArgs->kitl.flags = 0;
pBSPArgs->kitl.devLoc.IfcType = Internal;
pBSPArgs->kitl.devLoc.BusNumber = 0;
pBSPArgs->kitl.devLoc.LogicalLoc = 0;
memcpy((LPVOID)pBSPArgs->serialnum,serial_num,8);
memcpy((LPVOID)pBSPArgs->license_dat,(LPVOID)g_pTOC->license_dat,128);
pBSPArgs->license_sig = g_pTOC->license_signature;
pBSPArgs->license_crc = g_pTOC->license_crc;
memcpy((LPVOID)pBSPArgs->kitl.mac,serial_num,6);
}
// memset((LPVOID) &(pDriverGlobals->eth), 0, DBG_ETH_GLOBALS_SIZE);
// memset((LPVOID) &g_TOC, 0, sizeof(g_TOC));
// 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 retrieve TOC (and Boot config) from boot media
//
if ( !TOC_Read( ) ) {
// use default settings
TOC_Init(DEFAULT_IMAGE_DESCRIPTOR, (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS), 0, 0, 0);
}
// Show_ExecKeyboard(eboot_mainproc,1);
g_bDownloadImage = BootMonitor( );
// NOTE - right now, we assume that if we're downloading, it's done over Ethernet.
// In the future, this may include other transports (USB, etc.).
//
if(g_bDownloadImage == 2)
{
g_bDownloadImage = FALSE;
return FALSE;
}
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_LOADER:
EdbgOutputDebugString("OEMPlatformInit: IMAGE_TYPE_LOADER\r\n");
break;
case (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS):
case (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS|IMAGE_TYPE_MXIP):
EdbgOutputDebugString("OEMPlatformInit: IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS|IMAGE_TYPE_MXIP\r\n");
// N.B: this assumes the image is setup as multi-bin for BinFS.
if ( !ReadKernelRegionFromBootMedia( ) ) {
// RETAILMSG(1, (TEXT("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;
}
}
return TRUE;
}
/*
@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()
{
char szDeviceName[EDBG_MAX_DEV_NAMELEN];
BOOL fGotJumpImg = FALSE;
DWORD DHCPLeaseTime = 0, *pDHCPLeaseTime = &DHCPLeaseTime;
OALKitlCreateName(BSP_DEVICE_PREFIX, (UINT16*)&pBSPArgs->kitl.mac[0], (CHAR*)pBSPArgs->deviceId);
EdbgOutputDebugString("INFO: *** Device Name '%hs' ***\r\n", pBSPArgs->deviceId);
// If user wants to jump to existing image with no KD - skip download...
//
if ( !g_bDownloadImage && !g_bWaitForConnect)
{
return(BL_JUMP);
}
if ( !g_bDownloadImage && g_bWaitForConnect )
fGotJumpImg = TRUE;
//
//g_bUSBDownload = TRUE;
// SMCSetOptions(OPT_BROADCAST_FILTERING);
// update DHCP lease time
if ( g_bUSBDownload == TRUE )
EdbgOutputDebugString("Please send the Image through USB\r\n");
if(g_bSERDownload == TRUE)
EdbgOutputDebugString("Please send the Image through Serial\r\n");
return fGotJumpImg? BL_JUMP : BL_DOWNLOAD;
}
/*
@func void | OEMLaunch | Executes the stored/downloaded image.
@rdesc N/A.
@comm
@xref
*/
void (*cerun)(void);
#define rINTMSK (*(volatile unsigned *)0x4a000008)
void OEMLaunch(DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr, const ROMHDR *pRomHdr)
{
EDBG_OS_CONFIG_DATA *pCfgData;
_EDBG_ADDR_t EshellHostAddr = {0,0,0};
EdbgOutputDebugString("::OEMLaunch, ImageStart:0x%x, ImageLength:0x%x, LaunchAddr:0x%x\r\n",
dwImageStart, dwImageLength, dwLaunchAddr);
// 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 the user requested an image be stored on media, do so now. For multiple RAM BIN files, we need to map
// its RAM address to a flash address - the image base address offset in RAM is maintained in flash.
//
// Remember kernel launch address or recall stored address if this download didn't provide one
// (i.e., we didn't download the kernel region).
if (g_bDownloadImage && (g_pBootCfg->ConfigFlags & TARGET_TYPE_NAND))
{
if (dwImageStart && dwImageLength)
{
g_pTOC->id[g_dwTocEntry].dwLoadAddress = dwImageStart;
g_pTOC->id[g_dwTocEntry].dwTtlSectors = FILE_TO_SECTOR_SIZE(dwImageLength);
}
switch ( g_ImageType ) {
case (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS|IMAGE_TYPE_MXIP):
case (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS):
EdbgOutputDebugString("OEMLaunch: (%s|IMAGE_TYPE_BINFS)\r\n",
(g_ImageType & IMAGE_TYPE_MXIP) ? "IMAGE_TYPE_MXIP" : "IMAGE_TYPE_RAMIMAGE");
if(hProgBar)
PROGBAR_SetText(hProgBar,"Writing...");
if ( !WriteRegionsToBootMedia(dwImageStart, dwImageLength, dwLaunchAddr) ) {
EdbgOutputDebugString("WARNING: OEMLaunch: Failed to store BinFS regions to boot media.\r\n");
SPIN_FOREVER;
}
if(hFrameWin)
FRAMEWIN_Delete(hFrameWin);
break;
default:
EdbgOutputDebugString("OEMLaunch ERROR: unknown image type: 0x%x \r\n",
g_pTOC->id[g_dwTocEntry].dwImageType);
SPIN_FOREVER;
}
}
// Remember kernel launch address or recall stored address if this download didn't provide one (i.e., we didn't download the kernel region).
//
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();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -