📄 main.c
字号:
case '3': // Toggle static/DHCP mode.
g_pBootCfg->ConfigFlags = (g_pBootCfg->ConfigFlags ^ CONFIG_FLAGS_DHCP);
bConfigChanged = TRUE;
continue;
break;
case '4': // Reset TOC configuration.
RETAILMSG(1, (TEXT("Resetting default TOC...\r\n")));
TOC_Init(DEFAULT_IMAGE_DESCRIPTOR, (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS), 0, 0, 0);
if ( !TOC_Write() ) {
RETAILMSG(1, (TEXT("TOC_Write Failed!\r\n")));
}
RETAILMSG(1, (TEXT("...TOC complete\r\n")));
continue;
break;
case '5': // Toggle download/launch status.
g_pBootCfg->ConfigFlags = (g_pBootCfg->ConfigFlags ^ BOOT_TYPE_DIRECT);
bConfigChanged = TRUE;
break;
case '6': // Toggle boot media image store.
g_pBootCfg->ConfigFlags = (g_pBootCfg->ConfigFlags ^ TARGET_TYPE_NAND);
bConfigChanged = TRUE;
break;
case '7': // Configure MAC address.
SetCS8900MACAddress();
bConfigChanged = TRUE;
continue;
break;
case '8': // Toggle KD
g_pBootCfg->ConfigFlags = (g_pBootCfg->ConfigFlags ^ CONFIG_FLAGS_DEBUGGER);
g_bWaitForConnect = (g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DEBUGGER) ? TRUE : FALSE;
bConfigChanged = TRUE;
continue;
break;
case '9':
// format the boot media for BinFS
// N.B: this does not destroy our OEM reserved sections (TOC, bootloaders, etc)
if ( !g_bBootMediaExist ) {
RETAILMSG(1, (TEXT("ERROR: BootMonitor: boot media does not exist.\r\n")));
continue;
}
// N.B: format offset by # of reserved blocks,
// decrease the ttl # blocks available by that amount.
if ( !BP_LowLevelFormat( g_dwImageStartBlock,
NUM_BLOCKS - g_dwImageStartBlock,
0) )
{
RETAILMSG(1, (TEXT("ERROR: BootMonitor: Low-level boot media format failed.\r\n")));
continue;
}
break;
case 'B':
case 'b':
g_pTOC->id[g_dwTocEntry].dwImageType = (g_pTOC->id[g_dwTocEntry].dwImageType ^ IMAGE_TYPE_BINFS);
g_ImageType = g_pTOC->id[g_dwTocEntry].dwImageType;
bConfigChanged = TRUE;
break;
case 'E':
case 'e':
// TODO
break;
case 'F':
case 'f':
// low-level format
// N.B: this erases images, BinFs, FATFS, user data, etc.
// However, we don't format Bootloaders & TOC bolcks; use JTAG for this.
if ( !g_bBootMediaExist ) {
RETAILMSG(1, (TEXT("ERROR: BootMonitor: boot media does not exist.\r\n")));
continue;
} else {
DWORD i;
SectorInfo si;
// to keep bootpart off of our reserved blocks we must mark it as bad, reserved & read-only
si.bOEMReserved = OEM_BLOCK_RESERVED | OEM_BLOCK_READONLY;
si.bBadBlock = BADBLOCKMARK;
si.dwReserved1 = 0;
si.wReserved2 = 0;
RETAILMSG(1, (TEXT("Reserving Blocks [0x%x - 0x%x] ...\r\n"), 0, IMAGE_START_BLOCK-1));
for (i = 0; i < IMAGE_START_SECTOR; i++) {
FMD_WriteSector(i, NULL, &si, 1);
}
RETAILMSG(1, (TEXT("...reserve complete.\r\n")));
RETAILMSG(1, (TEXT("Low-level format Blocks [0x%x - 0x%x] ...\r\n"), IMAGE_START_BLOCK, NUM_BLOCKS-1));
for (i = IMAGE_START_BLOCK; i < NUM_BLOCKS; i++) {
FMD_EraseBlock(i);
}
RETAILMSG(1, (TEXT("...erase complete.\r\n")));
} break;
case 'D': // Download? Yes.
case 'd':
bDownload = TRUE;
goto MENU_DONE;
case 'L': // Download? No.
case 'l':
bDownload = FALSE;
goto MENU_DONE;
case 'R':
case 'r':
TOC_Read();
continue;
// TODO
break;
case 'U': // Download? No.
case 'u':
g_bWaitForConnect = FALSE;
bConfigChanged = TRUE;
g_bUSBDownload = TRUE;
bDownload = TRUE;
goto MENU_DONE;
case 'W': // Configuration Write
case 'w':
if (!TOC_Write())
{
RETAILMSG(1, (TEXT("WARNING: MainMenu: Failed to store updated eboot configuration in flash.\r\n")));
}
else
{
RETAILMSG(1, (TEXT("Successfully Written\r\n")));
bConfigChanged = FALSE;
}
break;
case 'X': // Download to media, then launch that
case 'x':
bDownload = TRUE;
bConfigChanged = TRUE;
g_pBootCfg->ConfigFlags |= TARGET_TYPE_NAND | BOOT_TYPE_DIRECT;
goto MENU_DONE;
default:
break;
}
}
MENU_DONE:
// If eboot settings were changed by user, save them.
//
if (bConfigChanged && !TOC_Write( ) )
{
RETAILMSG(1, (TEXT("WARNING: BootMonitor: Failed to store updated eboot configuration in flash.\r\n")));
}
return(bDownload);
}
/*
@func BOOL | OEMPlatformInit | Initialize the platform hardware.
@rdesc TRUE = Success, FALSE = Failure.
@comm
@xref
*/
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) &(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;
// Check real time clock, initialize if necessary (used for polling in net routines)
//
OEMGetRealTime(&st);
if ((st.wYear < 2000) ||
(st.wMonth < 1) ||
(st.wMonth > 12) ||
(st.wDay < 1) ||
(st.wDay > 31) ||
(st.wHour > 23) ||
(st.wMinute > 59) ||
(st.wSecond > 59) ||
(st.wMilliseconds > 999)) {
OEMSetRealTime(&defst);
}
else {
OEMSetRealTime(&st);
}
if (!InitUSB())
{
DEBUGMSG(1, (TEXT("OEMPlatformInit: Failed to initialize USB.\r\n")));
return(FALSE);
}
Isr_Init();
// Try to initialize the boot media block driver and BinFS partition.
//
if ( !BP_Init((LPBYTE)BINFS_RAM_START, BINFS_RAM_LENGTH, NULL, NULL, NULL) )
{
EdbgOutputDebugString("WARNING: OEMPlatformInit failed to initialize Boot Media.\r\n\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|IMAGE_TYPE_BINFS), 0, 0, 0);
}
// Start boot monitor prompt
//
dwBootDelay = g_pBootCfg->BootDelay;
if (g_pBootCfg->ConfigFlags & BOOT_TYPE_DIRECT)
{
EdbgOutputDebugString ( "Press [ENTER] to launch image stored on boot media, or [SPACE] to enter boot monitor.\r\n");
EdbgOutputDebugString ( "\r\nInitiating image launch in %d seconds. ", dwBootDelay--);
} else
{
EdbgOutputDebugString ( "Press [ENTER] to download image now, or [SPACE] to enter boot monitor.\r\n");
EdbgOutputDebugString ( "\r\nInitiating image download in %d seconds. ", dwBootDelay--);
}
dwStartTime = OEMEthGetSecs();
dwPrevTime = dwStartTime;
dwCurrTime = dwStartTime;
// allow the user to break into boot monitor
while((dwCurrTime - dwStartTime) < dwBootDelay)
{
cKeySelect = OEMReadDebugByte();
if ((cKeySelect == 0x20) || (cKeySelect == 0x0d))
break;
dwCurrTime = OEMEthGetSecs();
if (dwCurrTime > dwPrevTime)
{
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
EdbgOutputDebugString ( "%d seconds. ", dwBootDelay--);
}
}
EdbgOutputDebugString ( "\r\n");
switch(cKeySelect)
{
case 0x20: // Boot monitor.
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;
}
// 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 )
{
// 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:
EdbgOutputDebugString("OEMPlatformInit: IMAGE_TYPE_RAMIMAGE\r\n");
if ( !ReadRamImageFromBootMedia( ) ) {
RETAILMSG(1, (TEXT("OEMPlatformInit ERROR: Failed to load kernel region into RAM.\r\n")));
return FALSE;
}
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;
}
}
// If user specified a static IP address, use it (don't use DHCP).
//
if (g_bDownloadImage && !(g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DHCP))
{
pDriverGlobals->eth.TargetAddr.dwIP = g_pBootCfg->EdbgAddr.dwIP;
pDriverGlobals->eth.SubnetMask = g_pBootCfg->SubnetMask;
}
// Configure Ethernet controller.
if ( g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DEBUGGER )
{
if (!InitEthDevice(g_pBootCfg))
{
DEBUGMSG(1, (TEXT("OEMPlatformInit: Failed to initialize Ethernet controller.\r\n")));
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;
// 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;
//
// Create device name based on MAC address.
//
memset(szDeviceName, 0, EDBG_MAX_DEV_NAMELEN);
CreateDeviceName(&g_pBootCfg->EdbgAddr, szDeviceName);
EdbgOutputDebugString("Using device name: '%s'\n", szDeviceName);
// initialize TFTP transport
//
if ( !(g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DHCP) ) {
pDHCPLeaseTime = NULL; // the pDHCPLeaseTime parameter is overloaded.
// NULL indicates static IP
pDriverGlobals->eth.EdbgFlags = EDBG_FLAGS_STATIC_IP;
}
#ifndef SIMULATOR
if ( g_bUSBDownload == FALSE )
{
if (g_bDownloadImage &&
!EbootInitEtherTransport (&g_pBootCfg->EdbgAddr, &g_pBootCfg->SubnetMask, &fGotJumpImg, pDHCPLeaseTime,
EBOOT_VERSION_MAJOR, EBOOT_VERSION_MINOR, PLATFORM_STRING, szDeviceName, EDBG_CPUID, 0)) {
return BL_ERROR;
}
}
#endif
// SMCSetOptions(OPT_BROADCAST_FILTERING);
// update DHCP lease time
pDriverGlobals->eth.DHCPLeaseTime = DHCPLeaseTime;
if ( g_bUSBDownload == TRUE )
EdbgOutputDebugString("Please send the Image through USB\r\n");
return fGotJumpImg? BL_JUMP : BL_DOWNLOAD;
}
/*
@func void | OEMLaunch | Executes the stored/downloaded image.
@rdesc N/A.
@comm
@xref
*/
void OEMLaunch(DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr, const ROMHDR *pRomHdr)
{
EDBG_OS_CONFIG_DATA *pCfgData;
EDBG_ADDR 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).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -