⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c.ori

📁 支持三星原产的S3C2413开发板
💻 ORI
📖 第 1 页 / 共 5 页
字号:
				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 'c':
		case 'C':
			// 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("Low-level format 0 Block\r\n")));
				FMD_EraseBlock(0);

				OALMSG(TRUE, (TEXT("...erase complete.\r\n")));
			} 
			break;
		case 'a':
		case 'A':
			// 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("Low-level format Blocks [0x%x - 0x%x] ...\r\n"), EBOOT_BLOCK, RESERVED_BOOT_BLOCKS-1));
				for (i = NBOOT_BLOCK; i < RESERVED_BOOT_BLOCKS-1; i++) {
					FMD_EraseBlock(i);
				}
				for (i = NBOOT_BLOCK; i < IMAGE_START_SECTOR; i++) {
					FMD_WriteSector(i, NULL, &si, 1);
				}
				OALMSG(TRUE, (TEXT("...erase complete.\r\n")));
			} 
			break;
			
		case 'D':		   // Download? Yes.
		case 'd':
			bDownload = TRUE;
			goto MENU_DONE;
		case 'N':		   // Download? Yes.
		case 'n':
			if ((FMD_GetBlockStatus (5) & (BLOCK_STATUS_BAD|BLOCK_STATUS_RESERVED | BLOCK_STATUS_UNKNOWN)) > 0)
			{
				//if ((FMD_GetBlockStatus (5) & (BLOCK_STATUS_BAD)))
				//	OALMSG(TRUE, (TEXT("0 block is BADBLOCK\r\n")));					
				if ((FMD_GetBlockStatus (5) & (BLOCK_STATUS_RESERVED)))
					OALMSG(TRUE, (TEXT("0 block is BLOCK_STATUS_RESERVED\r\n")));	
				if ((FMD_GetBlockStatus (5) & (BLOCK_STATUS_UNKNOWN)))
					OALMSG(TRUE, (TEXT("3 block is BLOCK_STATUS_UNKNOWN\r\n")));					
			}

			if ((FMD_GetBlockStatus (6) & (BLOCK_STATUS_BAD|BLOCK_STATUS_RESERVED| BLOCK_STATUS_UNKNOWN)) > 0)
			{
				//if ((FMD_GetBlockStatus (6) & (BLOCK_STATUS_BAD)))
				//	OALMSG(TRUE, (TEXT("1 block is BLOCK_STATUS_BAD\r\n")));					
				if ((FMD_GetBlockStatus (6) & (BLOCK_STATUS_RESERVED)))
					OALMSG(TRUE, (TEXT("1 block is BLOCK_STATUS_RESERVED\r\n")));					
				if ((FMD_GetBlockStatus (6) & (BLOCK_STATUS_UNKNOWN)))
					OALMSG(TRUE, (TEXT("3 block is BLOCK_STATUS_UNKNOWN\r\n")));					
			}

			if ((FMD_GetBlockStatus (2) & (BLOCK_STATUS_BAD|BLOCK_STATUS_RESERVED| BLOCK_STATUS_UNKNOWN)) > 0)
			{
				if ((FMD_GetBlockStatus (2) & (BLOCK_STATUS_BAD)))
					OALMSG(TRUE, (TEXT("2 block is BLOCK_STATUS_BAD\r\n")));					
				if ((FMD_GetBlockStatus (2) & (BLOCK_STATUS_RESERVED)))
					OALMSG(TRUE, (TEXT("2 block is BLOCK_STATUS_RESERVED\r\n")));
				if ((FMD_GetBlockStatus (2) & (BLOCK_STATUS_UNKNOWN)))
					OALMSG(TRUE, (TEXT("3 block is BLOCK_STATUS_UNKNOWN\r\n")));					
			}

			if ((FMD_GetBlockStatus (3) & (BLOCK_STATUS_BAD|BLOCK_STATUS_RESERVED| BLOCK_STATUS_UNKNOWN)) > 0)
			{
				if ((FMD_GetBlockStatus (3) & (BLOCK_STATUS_BAD)))
					OALMSG(TRUE, (TEXT("3 block is BLOCK_STATUS_BAD\r\n")));					
				if ((FMD_GetBlockStatus (3) & (BLOCK_STATUS_RESERVED)))
					OALMSG(TRUE, (TEXT("3 block is BLOCK_STATUS_RESERVED\r\n")));					
				if ((FMD_GetBlockStatus (3) & (BLOCK_STATUS_UNKNOWN)))
					OALMSG(TRUE, (TEXT("3 block is BLOCK_STATUS_UNKNOWN\r\n")));		
			}			
			NANDFlashTest();
			continue;
		case 'M':		   // Download? no
		case 'm':
			OALMSG(TRUE, (TEXT("Memory Clear from 0x3007800 to 0x34000000.\r\n")));
			MemClear();
			break;
		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")));
				Mark_BadBlock(TOC_BLOCK, TOC_BLOCK+TOC_BLOCK_SIZE-1);	// DonGo
				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 SMD2413 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;

	volatile S3C2413_IOPORT_REG *s2413IOP = (S3C2413_IOPORT_REG *)OALPAtoVA(S3C2413_BASE_REG_PA_IOPORT, FALSE);
	volatile S3C2413_CLKPWR_REG *s2413CLKPWR = (S3C2413_CLKPWR_REG *)OALPAtoVA(S3C2413_BASE_REG_PA_CLOCK_POWER, FALSE);



	//EdbgOutputDebugString(TRUE, (TEXT("+OEMPlatformInit.\r\n")));

	EdbgOutputDebugString("WinCE Bootloader for Samsung SMDK2413 Version %d.%d Built %s\r\n\r\n", 
						  EBOOT_VERSION_MAJOR, EBOOT_VERSION_MINOR, __DATE__);

	// Display PLL setting...
	OALMSG(TRUE, (L">> PLL Setting values in EBOOT.\r\n"));
	OALMSG(TRUE, (L">> FCLK=[%ld,%ld,%ld]Hz\r\n", S3C2413_FCLK, S3C2413_HCLK, S3C2413_PCLK));

	// Initialize the display.
	//
	
	OALMSG(TRUE, (TEXT("InitDisplay\r\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;

	// 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.
	//
	// For USB Download functon
	//


	#if 1
	if (!InitUSB())
	{
		RETAILMSG(1, (TEXT("OEMPlatformInit: Failed to initialize USB.\r\n")));
		return(FALSE);
	}
	
	Isr_Init();	// USB isr init.
	#endif

	RETAILMSG(1, (TEXT("MPLLCON[%xh]\n"), s2413CLKPWR->MPLLCON));
	RETAILMSG(1, (TEXT("UPLLCON[%xh]\n"), s2413CLKPWR->UPLLCON));
	RETAILMSG(1, (TEXT("CLKCON[%xh]\n"), s2413CLKPWR->CLKCON));
	RETAILMSG(1, (TEXT("CLKSRC[%xh]\n"), s2413CLKPWR->CLKSRC));
	RETAILMSG(1, (TEXT("CLKDIVN[%xh]\n"), s2413CLKPWR->CLKDIVN));

    // 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;
		//OALMSG(TRUE, (TEXT("BP_Init OK\r\n")));
	}

// hsjang 060614 for supporting both small and large block NAND
    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
	//
	//OALMSG(TRUE, (TEXT("TOC_Read\r\n")));
	if ( !TOC_Read( ) ) 
	{
		// use default settings
		TOC_Init(DEFAULT_IMAGE_DESCRIPTOR, (IMAGE_TYPE_NKBIN), 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--);
		}
		if(dwCurrTime>=g_pBootCfg->BootDelay) KeySelect=0x00;
		
	}

	// Boot or enter bootloader menu.
	//
	//KeySelect = 0x20;
	switch(KeySelect)
	{
	case 0x20: // Boot menu.
		g_bDownloadImage = MainMenu(g_pBootCfg);
	break;
	case 0x00:
	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_EBOOT:
				OALMSG(TRUE, (TEXT("Don't support launch EBOOT.bin\r\n")));
				break;

			case IMAGE_TYPE_NKBIN:
				OALMSG(TRUE, (TEXT("OEMPlatformInit: IMAGE_TYPE_NKBIN\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)
{
	BOOL  bGotJump = FALSE;
	DWORD dwDHCPLeaseTime = 0;
	PDWORD pdwDHCPLeaseTime = &dwDHCPLeaseTime;
	DWORD dwBootFlags = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -