📄 main.c
字号:
cwNumChars--;
OEMWriteDebugByte((BYTE)InChar);
}
}
}
}
EdbgOutputDebugString ( "\r\n");
// If it's a carriage return with an empty string, don't change anything.
//
if (cwNumChars)
{
szDottedD[cwNumChars] = '\0';
CvtMAC(pBootCfg->EdbgAddr.wMAC, szDottedD);
EdbgOutputDebugString("INFO: MAC address set to: %x:%x:%x:%x:%x:%x\r\n",
pBootCfg->EdbgAddr.wMAC[0] & 0x00FF, pBootCfg->EdbgAddr.wMAC[0] >> 8,
pBootCfg->EdbgAddr.wMAC[1] & 0x00FF, pBootCfg->EdbgAddr.wMAC[1] >> 8,
pBootCfg->EdbgAddr.wMAC[2] & 0x00FF, pBootCfg->EdbgAddr.wMAC[2] >> 8);
}
else
{
EdbgOutputDebugString("WARNING: SetCS8900MACAddress: Invalid MAC address.\r\n");
}
}
/*
@func BOOL | MainMenu | Manages the Samsung bootloader main menu.
@rdesc TRUE == Success and FALSE == Failure.
@comm
@xref
*/
static BOOL MainMenu(PBOOT_CFG pBootCfg)
{
volatile S3C2443_SSMC_REG *s2443SSMC = (S3C2443_SSMC_REG *)OALPAtoVA(S3C2443_BASE_REG_PA_SSMC, FALSE);
BYTE KeySelect = 0;
BOOL bConfigChanged = FALSE;
BOOLEAN bDownload = TRUE;
while(TRUE)
{
KeySelect = 0;
EdbgOutputDebugString ( "\r\nEthernet Boot Loader Configuration:\r\n\r\n");
EdbgOutputDebugString ( "0) IP address: %s\r\n",inet_ntoa(pBootCfg->EdbgAddr.dwIP));
EdbgOutputDebugString ( "1) Subnet mask: %s\r\n", inet_ntoa(pBootCfg->SubnetMask));
EdbgOutputDebugString ( "2) DHCP: %s\r\n", (pBootCfg->ConfigFlags & CONFIG_FLAGS_DHCP)?"Enabled":"Disabled");
EdbgOutputDebugString ( "3) Boot delay: %d seconds\r\n", pBootCfg->BootDelay);
EdbgOutputDebugString ( "4) Reset to factory default configuration\r\n");
EdbgOutputDebugString ( "5) Startup image: %s\r\n", (g_pBootCfg->ConfigFlags & BOOT_TYPE_DIRECT) ? "LAUNCH EXISTING" : "DOWNLOAD NEW");
EdbgOutputDebugString ( "6) Program disk image into SmartMedia card: %s\r\n", (pBootCfg->ConfigFlags & TARGET_TYPE_NAND)?"Enabled":"Disabled");
EdbgOutputDebugString ( "7) Program CS8900 MAC address (%B:%B:%B:%B:%B:%B)\r\n",
g_pBootCfg->EdbgAddr.wMAC[0] & 0x00FF, g_pBootCfg->EdbgAddr.wMAC[0] >> 8,
g_pBootCfg->EdbgAddr.wMAC[1] & 0x00FF, g_pBootCfg->EdbgAddr.wMAC[1] >> 8,
g_pBootCfg->EdbgAddr.wMAC[2] & 0x00FF, g_pBootCfg->EdbgAddr.wMAC[2] >> 8);
EdbgOutputDebugString ( "8) Kernel Debugger: %s\r\n", (g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DEBUGGER) ? "ENABLED" : "DISABLED");
EdbgOutputDebugString ( "9) Format Boot Media for BinFS\r\n");
// N.B: we need this option here since BinFS is really a RAM image, where you "format" the media
// with an MBR. There is no way to parse the image to say it's ment to be BinFS enabled.
EdbgOutputDebugString ( "E) Erase Reserved Block \r\n");
EdbgOutputDebugString ( "B) Mark Bad Block at Reserved Block \r\n");
EdbgOutputDebugString ( "F) Low-level format the Smart Media card\r\n");
EdbgOutputDebugString ( "D) Download image now\r\n");
EdbgOutputDebugString ( "L) LAUNCH existing Boot Media image\r\n");
EdbgOutputDebugString ( "R) Read Configuration \r\n");
EdbgOutputDebugString ( "U) DOWNLOAD image now(USB)\r\n");
EdbgOutputDebugString ( "W) Write Configuration Right Now\r\n");
EdbgOutputDebugString ( "\r\nEnter your selection: ");
while (! ( ( (KeySelect >= '0') && (KeySelect <= '9') ) ||
( (KeySelect == 'D') || (KeySelect == 'd') ) ||
( (KeySelect == 'B') || (KeySelect == 'b') ) ||
( (KeySelect == 'E') || (KeySelect == 'e') ) ||
( (KeySelect == 'F') || (KeySelect == 'f') ) ||
( (KeySelect == 'L') || (KeySelect == 'l') ) ||
( (KeySelect == 'R') || (KeySelect == 'r') ) ||
( (KeySelect == 'U') || (KeySelect == 'u') ) ||
( (KeySelect == 'W') || (KeySelect == 'w') ) ||
( (KeySelect == 'X') || (KeySelect == 'x') ) ))
{
KeySelect = OEMReadDebugByte();
}
EdbgOutputDebugString ( "%c\r\n", KeySelect);
switch(KeySelect)
{
case '0': // Change IP address.
SetIP(pBootCfg);
pBootCfg->ConfigFlags &= ~CONFIG_FLAGS_DHCP; // clear DHCP flag
bConfigChanged = TRUE;
break;
case '1': // Change subnet mask.
SetMask(pBootCfg);
bConfigChanged = TRUE;
break;
case '2': // Toggle static/DHCP mode.
pBootCfg->ConfigFlags = (pBootCfg->ConfigFlags ^ CONFIG_FLAGS_DHCP);
bConfigChanged = TRUE;
break;
case '3': // Change autoboot delay.
SetDelay(pBootCfg);
bConfigChanged = TRUE;
break;
case '4': // Reset the bootloader configuration to defaults.
OALMSG(TRUE, (TEXT("Resetting default TOC...\r\n")));
TOC_Init(DEFAULT_IMAGE_DESCRIPTOR, (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS), 0, 0, 0);
if ( !TOC_Write() ) {
OALMSG(OAL_WARN, (TEXT("TOC_Write Failed!\r\n")));
}
OALMSG(TRUE, (TEXT("...TOC complete\r\n")));
break;
case '5': // Toggle download/launch status.
pBootCfg->ConfigFlags = (pBootCfg->ConfigFlags ^ BOOT_TYPE_DIRECT);
bConfigChanged = TRUE;
break;
case '6': // Toggle image storage to Smart Media.
pBootCfg->ConfigFlags = (pBootCfg->ConfigFlags ^ TARGET_TYPE_NAND);
bConfigChanged = TRUE;
break;
case '7': // Configure Crystal CS8900 MAC address.
SetCS8900MACAddress(pBootCfg);
bConfigChanged = TRUE;
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 ) {
OALMSG(OAL_ERROR, (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,
wNUM_BLOCKS - g_dwImageStartBlock,
FORMAT_SKIP_BLOCK_CHECK) )
{
OALMSG(OAL_ERROR, (TEXT("ERROR: BootMonitor: Low-level boot media format failed.\r\n")));
continue;
}
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 ) {
OALMSG(OAL_ERROR, (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 = 0xffffffff;
si.wReserved2 = 0xffff;
OALMSG(TRUE, (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);
}
OALMSG(TRUE, (TEXT("...reserve complete.\r\n")));
OALMSG(TRUE, (TEXT("Low-level format Blocks [0x%x - 0x%x] ...\r\n"), IMAGE_START_BLOCK, wNUM_BLOCKS-1));
for (i = IMAGE_START_BLOCK; i < wNUM_BLOCKS; i++) {
FMD_EraseBlock(i);
}
OALMSG(TRUE, (TEXT("...erase complete.\r\n")));
} break;
case 'B':
case 'b':
// 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 ) {
OALMSG(OAL_ERROR, (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.bBadBlock = 0xff;
si.dwReserved1 = 0xffffffff;
si.wReserved2 = 0xffff;
OALMSG(TRUE, (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);
}
OALMSG(TRUE, (TEXT("...reserve complete.\r\n")));
} break;
case 'E':
case 'e':
// 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 ) {
OALMSG(OAL_ERROR, (TEXT("ERROR: BootMonitor: boot media does not exist.\r\n")));
continue;
} else {
UINT32 i;
OALMSG(TRUE, (TEXT("Low-level format Blocks [0x%x - 0x%x] ...\r\n"), 0, IMAGE_START_BLOCK-1));
for (i = NBOOT_BLOCK; i < (NBOOT_BLOCK+NBOOT_BLOCK_SIZE); i++) {
FMD_EraseBlock(i);
}
for (i = EBOOT_BLOCK; i < (EBOOT_BLOCK+EBOOT_BLOCK_SIZE); i++) {
FMD_EraseBlock(i);
}
OALMSG(TRUE, (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();
TOC_Print();
// TODO
break;
case 'U': // Download? No.
case 'u':
bConfigChanged = TRUE;
g_bUSBDownload = TRUE;
bDownload = TRUE;
goto MENU_DONE;
case 'W': // Configuration Write
case 'w':
if (!TOC_Write())
{
OALMSG(OAL_WARN, (TEXT("WARNING: MainMenu: Failed to store updated eboot configuration in flash.\r\n")));
}
else
{
OALMSG(OAL_INFO, (TEXT("Successfully Written\r\n")));
bConfigChanged = FALSE;
}
break;
default:
break;
}
}
MENU_DONE:
// If eboot settings were changed by user, save them to flash.
//
if (bConfigChanged && !TOC_Write())
{
OALMSG(OAL_WARN, (TEXT("WARNING: MainMenu: Failed to store updated bootloader configuration to flash.\r\n")));
}
return(bDownload);
}
/*
@func BOOL | OEMPlatformInit | Initialize the Samsung SMD2443 platform hardware.
@rdesc TRUE = Success, FALSE = Failure.
@comm
@xref
*/
BOOL OEMPlatformInit(void)
{
ULONG BootDelay;
UINT8 KeySelect;
UINT32 dwStartTime, dwPrevTime, dwCurrTime;
BOOLEAN bResult = FALSE;
FlashInfo flashInfo;
OALMSG(OAL_FUNC, (TEXT("+OEMPlatformInit.\r\n")));
EdbgOutputDebugString("Microsoft Windows CE Bootloader for the Samsung SMDK2443 Version %d.%d Built %s\r\n\r\n",
EBOOT_VERSION_MAJOR, EBOOT_VERSION_MINOR, __DATE__);
// Initialize the display.
//
RETAILMSG(1,(TEXT("InitDisplay\n")));
InitDisplay();
// Initialize the BSP args structure.
//
memset(pBSPArgs, 0, sizeof(BSP_ARGS));
pBSPArgs->header.signature = OAL_ARGS_SIGNATURE;
pBSPArgs->header.oalVersion = OAL_ARGS_VERSION;
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;
// For USB Download functon
//
if (!InitUSB())
{
DEBUGMSG(1, (TEXT("OEMPlatformInit: Failed to initialize USB.\r\n")));
return(FALSE);
}
Isr_Init();
// 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.
//
///*
OALMSG(TRUE, (TEXT("BP_Init\r\n")));
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;
// Get flash info
if (!FMD_GetInfo(&flashInfo)) {
OALMSG(OAL_ERROR, (L"ERROR: BLFlashDownload: "
L"FMD_GetInfo call failed\r\n"
));
}
wNUM_BLOCKS = flashInfo.dwNumBlocks;
RETAILMSG(1, (TEXT("wNUM_BLOCKS : %d(0x%x) \r\n"), wNUM_BLOCKS, wNUM_BLOCKS));
// 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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -