📄 main.c
字号:
pLowFuncTbl = FIL_GetFuncTbl();
OALMSG(TRUE, (TEXT("Initial Bad Block Check\r\n")));
for (nBlock=1; nBlock<SUBLKS_TOTAL; nBlock++)
{
IS_CHECK_SPARE_ECC = FALSE32;
pLowFuncTbl->Read(0, nBlock*PAGES_PER_BLOCK+(PAGES_PER_BLOCK-1), 0x0, enuBOTH_PLANE_BITMAP, NULL, pSBuf, TRUE32, FALSE32);
IS_CHECK_SPARE_ECC = TRUE32;
if (pSBuf[0] != 0xff)
{
OALMSG(TRUE, (TEXT("Initial Bad Block @ %d Block\r\n"), nBlock));
#if 0
pLowFuncTbl->Erase(0, nBlock, enuNONE_PLANE_BITMAP);
pLowFuncTbl->Sync(0, &nSyncRet);
memset((void *)pSBuf, 0x00, BYTES_PER_SPARE_PAGE);
IS_CHECK_SPARE_ECC = FALSE32;
pLowFuncTbl->Write(0, nBlock*PAGES_PER_BLOCK+(PAGES_PER_BLOCK-1), 0x0, enuNONE_PLANE_BITMAP, NULL, pSBuf);
IS_CHECK_SPARE_ECC = TRUE32;
if (pLowFuncTbl->Sync(0, &nSyncRet)) // Write Error
{
OALMSG(TRUE, (TEXT("Bad marking Write Error @ %d Block\r\n"), nBlock));
}
#endif
}
#if 1
else
{
pLowFuncTbl->Erase(0, nBlock, enuNONE_PLANE_BITMAP);
if (pLowFuncTbl->Sync(0, &nSyncRet)) // Erase Error
{
OALMSG(TRUE, (TEXT("Erase Error @ %d Block -> Bad Marking\r\n"), nBlock));
memset((void *)pSBuf, 0x00, BYTES_PER_SPARE_PAGE);
IS_CHECK_SPARE_ECC = FALSE32;
pLowFuncTbl->Write(0, nBlock*PAGES_PER_BLOCK+(PAGES_PER_BLOCK-1), 0x0, enuNONE_PLANE_BITMAP, NULL, pSBuf);
IS_CHECK_SPARE_ECC = TRUE32;
if (pLowFuncTbl->Sync(0, &nSyncRet)) // Write Error
{
OALMSG(TRUE, (TEXT("Bad marking Write Error @ %d Block\r\n"), nBlock));
}
}
else
{
for (nPage=0; nPage<PAGES_PER_BLOCK; nPage++) // Write and Read Test
{
// Write Page
memset((void *)pSBuf, 0xff, BYTES_PER_SPARE_PAGE);
pLowFuncTbl->Write(0, nBlock*PAGES_PER_BLOCK+nPage, LEFT_SECTOR_BITMAP_PAGE, enuNONE_PLANE_BITMAP, pTemp, pSBuf);
if (pLowFuncTbl->Sync(0, &nSyncRet)) // Write Error
{
OALMSG(TRUE, (TEXT("Write Error @ %d Block %d Page -> Bad Marking\r\n"), nBlock, nPage));
pLowFuncTbl->Erase(0, nBlock, enuNONE_PLANE_BITMAP);
pLowFuncTbl->Sync(0, &nSyncRet);
memset((void *)pSBuf, 0x00, BYTES_PER_SPARE_PAGE);
IS_CHECK_SPARE_ECC = FALSE32;
pLowFuncTbl->Write(0, nBlock*PAGES_PER_BLOCK+(PAGES_PER_BLOCK-1), 0x0, enuNONE_PLANE_BITMAP, NULL, pSBuf);
IS_CHECK_SPARE_ECC = TRUE32;
if (pLowFuncTbl->Sync(0, &nSyncRet)) // Write Error
{
OALMSG(TRUE, (TEXT("Bad marking Write Error @ %d Block\r\n"), nBlock));
}
break; // Bad Block
}
// Read Page
memset((void *)pSBuf, 0xff, BYTES_PER_SPARE_PAGE);
if (pLowFuncTbl->Read(0, nBlock*PAGES_PER_BLOCK+nPage, LEFT_SECTOR_BITMAP_PAGE, enuNONE_PLANE_BITMAP, pDBuf, pSBuf, 0, 0))
{
OALMSG(TRUE, (TEXT("Read Error @ %d Block %d Page -> Bad Marking\r\n"), nBlock, nPage));
pLowFuncTbl->Erase(0, nBlock, enuNONE_PLANE_BITMAP);
pLowFuncTbl->Sync(0, &nSyncRet);
memset((void *)pSBuf, 0x00, BYTES_PER_SPARE_PAGE);
IS_CHECK_SPARE_ECC = FALSE32;
pLowFuncTbl->Write(0, nBlock*PAGES_PER_BLOCK+(PAGES_PER_BLOCK-1), 0x0, enuNONE_PLANE_BITMAP, NULL, pSBuf);
IS_CHECK_SPARE_ECC = TRUE32;
if (pLowFuncTbl->Sync(0, &nSyncRet)) // Write Error
{
OALMSG(TRUE, (TEXT("Bad marking Write Error @ %d Block\r\n"), nBlock));
}
break; // Bad Block
}
}
}
}
#endif
OALMSG(TRUE, (TEXT(".")));
}
OALMSG(TRUE, (TEXT(" --Make Initial Bad Block Information (Warning)\r\n")));
#endif
}
break;
case 'T': // Download? Yes.
case 't':
MLC_LowLevelTest();
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; // mask for using MLC type NAND flash device because of writing TOC frequently
g_bUSBDownload = TRUE;
bDownload = TRUE;
goto MENU_DONE;
#ifdef _EBOOT_SLEEP_
case 'S':
case 's':
OALMSG(OAL_WARN, (TEXT("Now go into Sleep Mode!!\r\n\n")));
OEMPowerOff();
#endif
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 SMD2450 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 SMDK2450 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();
// while(1);
// 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);
}
#ifdef _EBOOT_SLEEP_
if (!InitPowerButton())
{
DEBUGMSG(1, (TEXT("OEMPlatformInit: Failed to initialize Power Button.\r\n")));
return(FALSE);
}
#endif
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;
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)
{
OALMSG(TRUE, (TEXT("\r\nLaunching image from boot media ... \r\n")));
g_bDownloadImage = FALSE;
}
else
{
OALMSG(TRUE, (TEXT("\r\nStarting auto-download ... \r\n")));
g_bDownloadImage = TRUE;
}
break;
}
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) ) {
OALMSG(OAL_ERROR, (TEXT("OEMPlatformInit: ERROR_INVALID_TOC, can not autoboot.\r\n")));
return FALSE;
}
switch (g_ImageType) {
case IMAGE_TYPE_STEPLDR:
OALMSG(TRUE, (TEXT("Don't support launch STEPLDR.bin\r\n")));
break;
case IMAGE_TYPE_LOADER:
OALMSG(TRUE, (TEXT("Don't support launch EBOOT.bin\r\n")));
break;
case IMAGE_TYPE_RAMIMAGE:
OALMSG(TRUE, (TEXT("OEMPlatformInit: IMAGE_TYPE_RAMIMAGE\r\n")));
if ( !ReadOSImageFromBootMedia( ) )
{
OALMSG(OAL_ERROR, (TEXT("OEMPlatformInit ERROR: Failed to load kernel region into RAM.\r\n")));
return FALSE;
}
break;
default:
OALMSG(OAL_ERROR, (TEXT("OEMPlatformInit ERROR: unknown image type: 0x%x \r\n"), g_ImageType));
return FALSE;
}
}
// Configure Ethernet controller.
//
if ( g_bDownloadImage && (g_bUSBDownload == FALSE) )
{
if (!InitEthDevice(g_pBootCfg))
{
OALMSG(OAL_ERROR, (TEXT("ERROR: OEMPlatformInit: Failed to initialize Ethernet controller.\r\n")));
goto CleanUp;
}
}
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)
{
volatile S3C2450_INTR_REG *s2450INT = (S3C2450_INTR_REG *)OALPAtoVA(S3C2450_BASE_REG_PA_INTR, FALSE);
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);
OALMSG(OAL_INFO, (L"INFO: *** Device Name '%hs' ***\r\n", pBSPArgs->deviceId));
if ( g_bUSBDownload == FALSE )
{
// 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;
}
if ( !g_bDownloadImage)
{
return(BL_JUMP);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -