main.c

来自「SAMSUNG S3C6410 CPU BSP for winmobile6」· C语言 代码 · 共 1,638 行 · 第 1/4 页

C
1,638
字号
    // 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)
{
    BYTE KeySelect = 0;
    BOOL bConfigChanged = FALSE;
    BOOLEAN bDownload = TRUE;
    DWORD i=0;

    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 NandFlash memory: %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) KITL Configuration: %s\r\n", (g_pBootCfg->ConfigFlags & CONFIG_FLAGS_KITL) ? "ENABLED" : "DISABLED");

        // 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 ( "A) Erase All Blocks\r\n");
//        EdbgOutputDebugString ( "D) Download image now\r\n");
        EdbgOutputDebugString ( "F) Format Storage Folder\r\n");
        EdbgOutputDebugString ( "L) LAUNCH existing Boot Media image\r\n");
#if EBOOT_ONENAND_RW_TEST
        EdbgOutputDebugString ( "M) Write/Read Test on OneNAND\r\n");
        EdbgOutputDebugString ( "N) Read Aging Test on OneNAND\r\n");
#endif
		EdbgOutputDebugString ( "R) Read Configuration \r\n");
#if (USE_TRACE32_DOWNLOAD)
        EdbgOutputDebugString ( "T) DOWNLOAD image now(Trace32)\r\n");
#endif
        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 <= '8') ) ||
                   ( (KeySelect == 'A') || (KeySelect == 'a') ) ||
                   ( (KeySelect == 'C') || (KeySelect == 'c') ) ||
//                   ( (KeySelect == 'D') || (KeySelect == 'd') ) ||
                   ( (KeySelect == 'F') || (KeySelect == 'f') ) ||
                   ( (KeySelect == 'L') || (KeySelect == 'l') ) ||
#if EBOOT_ONENAND_RW_TEST
                   ( (KeySelect == 'M') || (KeySelect == 'm') ) ||
                   ( (KeySelect == 'N') || (KeySelect == 'n') ) ||
#endif
                   ( (KeySelect == 'R') || (KeySelect == 'r') ) ||
#if (USE_TRACE32_DOWNLOAD)
                   ( (KeySelect == 'T') || (KeySelect == 't') ) ||
#endif
                   ( (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_KITL);
            bConfigChanged = TRUE;
            continue;
            break;
        case 'A':
        case 'a':
        	{
				LLDSpec stLLDSpec;
				UINT32 i;

				if (ONLD_GetDevInfo(0, &stLLDSpec))
				{
					OALMSG(TRUE, (TEXT("ONLD_GetDevInfo is failed.\r\n")));
					break;
				}

                OALMSG(TRUE, (TEXT("All block(%d) UnLock...\r\n"), stLLDSpec.nNumOfBlks));
                _SetRWBlock(0, 0, stLLDSpec.nNumOfBlks);
				
				OALMSG(TRUE, (TEXT("All block(%d) Erase...\r\n"), stLLDSpec.nNumOfBlks));
				for (i = 0; i < stLLDSpec.nNumOfBlks; i++) {
					//FMD_EraseBlock_BML(i);
					ONLD_Erase(0, i, (0<<0));
				}
				OALMSG(TRUE, (TEXT("Erase complete...\r\n")));
				OALMSG(TRUE, (TEXT("Reboot is recommended!!\r\n")));
            }
        	break;
        case 'D':           // Download? Yes.
        case 'd':
            bDownload = TRUE;
            goto MENU_DONE;
        case 'F':
        case 'f':
			OALMSG(TRUE, (TEXT(" Format PocketStore's FAT regions.\r\n")));
        	if (!PocketStoreII_STL_Format(PARTITION_ID_FILESYSTEM))
				OALMSG(TRUE, (TEXT(" PocketStore is not formatted.\r\n")));
        	else
				OALMSG(TRUE, (TEXT(" Format complete.\r\n")));
            break;
        case 'L':           // Download? No.
        case 'l':
            bDownload = FALSE;
            goto MENU_DONE;
#if EBOOT_ONENAND_RW_TEST
        case 'M':
        case 'm':
            OneNAND_RWTest();
            break;
        case 'N':
        case 'n':
            OneNAND_LLD_ReadAgingTest();
            //OneNAND_STL_ReadAgingTest();
            break;
#endif
        case 'R':
        case 'r':
			TOC_Read();
			TOC_Print();
            // TODO
            break;
#if (USE_TRACE32_DOWNLOAD)
        case 'T':           // Download? No.
        case 't':
            //bConfigChanged = TRUE;
			g_bUSBDownload = FALSE;
            bDownload = TRUE;
            g_bT32Download = TRUE;  // jylee
            goto MENU_DONE;
#endif
        case 'U':           // Download? No.
        case 'u':
			if (!InitUSB())
			{
				DEBUGMSG(1, (TEXT("OEMPlatformInit: Failed to initialize USB.\r\n")));
				return(FALSE);
			}
            //bConfigChanged = TRUE;
			g_bUSBDownload = TRUE;
            bDownload = TRUE;
            g_bT32Download = FALSE; // jylee
            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 SMD2440 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 SMDK6410 Version %d.%d Built %s\r\n\r\n",
                          EBOOT_VERSION_MAJOR, EBOOT_VERSION_MINOR, __DATE__);
	// Initialize the display.
	InitializeDisplay();

    // 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             = 0;
    pBSPArgs->kitl.devLoc.IfcType    = Internal;
    pBSPArgs->kitl.devLoc.BusNumber  = 0;
    pBSPArgs->kitl.devLoc.LogicalLoc = BSP_BASE_REG_PA_CS8900A_IOBASE;

	Isr_Init();

    /*------------------------------------*/
    /* PocketStore Nand System Initialize */
    /*------------------------------------*/
    if (PocketStoreInitialize() == FALSE)
    {
        EdbgOutputDebugString("[EBOOT:ERR] PocketStoreInitialize fail\r\n");
        return FALSE;
    }

    // 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));
	
//    OALMSG(TRUE, (TEXT("TOC_Read\r\n")));
    // 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 & CONFIG_FLAGS_KITL)
			pBSPArgs->kitl.flags = OAL_KITL_FLAGS_ENABLED | OAL_KITL_FLAGS_VMINI;
    RETAILMSG(1,(TEXT("\n\nFlags= %x, kitl.flags= %x \r\n"),g_pBootCfg->ConfigFlags,pBSPArgs->kitl.flags));
    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 = 0, j = 0;

            // 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;
        }
	}

    // Configure Ethernet controller.
    //
    // jylee
	if ( g_bDownloadImage && (g_bUSBDownload == FALSE) && (g_bT32Download == FALSE))
	{
		if (!InitEthDevice(g_pBootCfg))
    	{
        	OALMSG(OAL_ERROR, (TEXT("ERROR: OEMPlatformInit: Failed to initialize Ethernet controller.\r\n")));
        	goto CleanUp;
        }

⌨️ 快捷键说明

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