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

📄 main.c

📁 WINDOWS CE BSP用于SBC2440开发板
💻 C
📖 第 1 页 / 共 4 页
字号:
    }

    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!

    /* thisway.diy, 2006.06.29 */
    PVIVI_WINCE_IMAGE_INFO pImageInfo = VIVI_WINCE_IMAGE_INFO_BASE;

#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);
    }


    /* thisway.diy, 2006.06.29 */
//    if (!memcmp(pImageInfo->puMagic, "X000FF\x0A", 7) || !memcmp(pImageInfo->puMagic, "B000FF\x0A", 7))
    EdbgOutputDebugString("g_pViviWinceInfo = 0x%X, g_pViviWinceInfo->dwViviWinceMagic = 0x%X\r\n", (DWORD)g_pViviWinceInfo, g_pViviWinceInfo->dwViviWinceMagic);
    if (g_pViviWinceInfo->dwViviWinceMagic == VIVI_DWONLOAD_WINCE_WITH_USB)
    {
        g_bHasLoadWithUSB = 1;
        g_bDownloadImage = AutoLoadByUSB( );
    }
    else
    {
        // 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;
    }

    /* thisway.diy, if have download with USB, not use eth */
    // Configure Ethernet controller.
	if ( g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DEBUGGER )
	{
		if (!g_bHasLoadWithUSB && !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);

    if (!g_bHasLoadWithUSB)
    {
        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);

    if (0) //(!g_bHasLoadWithUSB) // thisway.diy, 2007.01.27
    {
        // 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).
        //
#ifndef SIMULATOR
        if ( g_bDownloadImage && g_bWaitForConnect )
        {
            EdbgOutputDebugString ("EbootWaitForHostConenct\r\n");
            pCfgData = EbootWaitForHostConnect (&g_pBootCfg->EdbgAddr, &EshellHostAddr);
            if (!pCfgData) {
                EdbgOutputDebugString ("EbootWaitForHostConenct failed, spin forever\r\n");
                SPIN_FOREVER;
            }
            if (pCfgData->Flags & EDBG_FL_DBGMSG) {
                EdbgOutputDebugString("Enabling debug messages over Ethernet, IP: %s, port:%u\n",
                    inet_ntoa(pCfgData->DbgMsgIPAddr),ntohs(pCfgData->DbgMsgPort));
                memcpy(&pDriverGlobals->eth.DbgHostAddr.wMAC,&EshellHostAddr.wMAC,6);
                pDriverGlobals->eth.DbgHostAddr.dwIP  = pCfgData->DbgMsgIPAddr;
                pDriverGlobals->eth.DbgHostAddr.wPort = pCfgData->DbgMsgPort;
            }
            if (pCfgData->Flags & EDBG_FL_PPSH) {
                EdbgOutputDebugString("Enabling CESH over Ethernet,           IP: %s, port:%u\n",
                    inet_ntoa(pCfgData->PpshIPAddr),ntohs(pCfgData->PpshPort));
                memcpy(&pDriverGlobals->eth.PpshHostAddr.wMAC,&EshellHostAddr.wMAC,6);
                pDriverGlobals->eth.PpshHostAddr.dwIP  = pCfgData->PpshIPAddr;
                pDriverGlobals->eth.PpshHostAddr.wPort = pCfgData->PpshPort;
            }
            if (pCfgData->Flags & EDBG_FL_KDBG) {
                EdbgOutputDebugString("Enabling KDBG over Ethernet,           IP: %s, port:%u\n",
                    inet_ntoa(pCfgData->KdbgIPAddr),ntohs(pCfgData->KdbgPort));
                memcpy(&pDriverGlobals->eth.KdbgHostAddr.wMAC,&EshellHostAddr.wMAC,6);
                pDriverGlobals->eth.KdbgHostAddr.dwIP  = pCfgData->KdbgIPAddr;
                pDriverGlobals->eth.KdbgHostAddr.wPort = pCfgData->KdbgPort;
            }

            memcpy(&pDriverGlobals->eth.DownloadHostAddr,&EshellHostAddr,sizeof(EDBG_ADDR));
            pDriverGlobals->eth.etherFlags = pCfgData->Flags;
            pDriverGlobals->eth.KitlTransport = pCfgData->KitlTransport;
            EdbgOutputDebugString ("KitlTransport: 0x%x\r\n", pCfgData->KitlTransport);
            pDriverGlobals->eth.EbootMagicNum = EBOOT_MAGIC_NUM;
        }
        else if ( !g_bDownloadImage && g_bWaitForConnect)
        {
            EdbgOutputDebugString ("Eboot setup Kitl from media boot\r\n");
            pDriverGlobals->eth.KitlTransport = KTS_ETHER;
            pDriverGlobals->eth.EbootMagicNum = EBOOT_MAGIC_NUM;
        }
#endif

        // Update address info, in driver globals, and in EEPROM if necessary
        memcpy (&pDriverGlobals->eth.TargetAddr, &g_pBootCfg->EdbgAddr, sizeof(g_pBootCfg->EdbgAddr));
        pDriverGlobals->eth.SubnetMask = g_pBootCfg->SubnetMask;
    }

    // If the user requested an image be stored on media, do so now.  For multiple RAM BIN files, we need to map
    // its RAM address to a flash address - the image base address offset in RAM is maintained in flash.
    //

    // Remember kernel launch address or recall stored address if this download didn't provide one
    // (i.e., we didn't download the kernel region).
    if (g_bDownloadImage && (g_pBootCfg->ConfigFlags & TARGET_TYPE_NAND))
    {
		if (dwImageStart && dwImageLength)
		{

⌨️ 快捷键说明

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