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

📄 main.c

📁 使用三星ARM2410的eboot程序
💻 C
📖 第 1 页 / 共 4 页
字号:
            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\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;
    }

    // Configure Ethernet controller.
    //
    if (!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;

    EdbgOutputDebugString("+OEMPreDownload: %d\r\n", g_bDownloadImage);

    // 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);
    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_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;

    EdbgOutputDebugString("-OEMPreDownload: %s\r\n",
        fGotJumpImg ? "BL_JUMP" : "BL_DOWNLOAD" );

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

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

	// Copy the uuid from nand toc to grobal memory area.
	memcpy(pDriverGlobals->baUDID, g_pTOC->udid, 8);

#if 0
// TBD: may need this for warm reset
    if (dwLaunchAddr == 0) {
TEST_TRAP;
        if (pDriverGlobals->dwLastLaunchAddrValid == LAST_LAUNCH_ADDR_VALID) {
            dwLaunchAddr = pDriverGlobals->dwLastLaunchAddr;
            EdbgOutputDebugString("Using previous launch address: 0x%x\n", dwLaunchAddr );
        } else {

            if (pRomHdr && pRomHdr->physfirst != -1) {
                dwLaunchAddr= pRomHdr->physfirst;
                EdbgOutputDebugString("Using RomHdr launch address: 0x%x\n", dwLaunchAddr );
            } else {
                dwLaunchAddr = DEFAULT_LAUNCHADDR;
                EdbgOutputDebugString("Using Default launch address: 0x%x\n", dwLaunchAddr );
            }
        }

    } else {
        pDriverGlobals->dwLastLaunchAddrValid = LAST_LAUNCH_ADDR_VALID;
        pDriverGlobals->dwLastLaunchAddr = dwLaunchAddr;
    };
#endif

    // 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)
		{
			g_pTOC->id[g_dwTocEntry].dwLoadAddress = dwImageStart;
			g_pTOC->id[g_dwTocEntry].dwTtlSectors = FILE_TO_SECTOR_SIZE(dwImageLength);
		}

        switch ( g_ImageType ) {
            case IMAGE_TYPE_LOADER:
                EdbgOutputDebugString("OEMLaunch: IMAGE_TYPE_LOADER\r\n");
                if ( !WriteRamImageToBootMedia(g_dwTocEntry) ) {
                    RETAILMSG(1, (TEXT("OEMLaunch ERROR: Failed to write image to boot media.\r\n")));
                    SPIN_FOREVER;
                }
                break;

            case IMAGE_TYPE_RAMIMAGE:
			case (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS):
//				EdbgOutputDebugString("OEMLaunch: IMAGE_TYPE_RAMIMAGE\r\n");
//				if ( !WriteRamImageToBootMedia(g_dwTocEntry) ) {
//					RETAILMSG(1, (TEXT("OEMLaunch ERROR: Failed to write image to boot media.\r\n")));
//					SPIN_FOREVER;
//				}
//				break;

            case (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS|IMAGE_TYPE_MXIP):
                EdbgOutputDebugString("OEMLaunch: (%s|IMAGE_TYPE_BINFS)\r\n",
                    (g_ImageType & IMAGE_TYPE_MXIP) ? "IMAGE_TYPE_MXIP" : "IMAGE_TYPE_RAMIMAGE");
                if ( !WriteRegionsToBootMedia(dwImageStart, dwImageLength, dwLaunchAddr) ) {
                    EdbgOutputDebugString("WARNING: OEMLaunch: Failed to store BinFS regions to boot media.\r\n");
                    SPIN_FOREVER;
                }
                break;

            default:
                EdbgOutputDebugString("OEMLaunch ERROR: unknown image type: 0x%x \r\n",
                    g_pTOC->id[g_dwTocEntry].dwImageType);
                SPIN_FOREVER;
        }
    }

	// 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 (dwLaunchAddr && (g_pTOC->id[g_dwTocEntry].dwJumpAddress != dwLaunchAddr))
	{
		g_pTOC->id[g_dwTocEntry].dwJumpAddress = dwLaunchAddr;
		if ( !TOC_Write() ) {
            EdbgOutputDebugString("*** OEMLaunch ERROR: TOC_Write failed! Next boot may not load from disk *** \r\n");
		}
        TOC_Print();
	}
	else
	{
		dwLaunchAddr= g_pTOC->id[g_dwTocEntry].dwJumpAddress;
		EdbgOutputDebugString("INFO: using TOC[%d] dwJumpAddress: 0x%x\r\n", g_dwTocEntry, dwLaunchAddr);
	}

#if 0
    // do we want to boot the image we just downloaded
    //
TEST_TRAP();
    if ( (g_pBootCfg->ConfigFlags & (BOOT_TYPE_DIRECT|TARGET_TYPE_NAND)) &&
         !ReadKernelRegionFromBootMedia() )
    {
        RETAILMSG(1, (TEXT("ERROR: OEMPlatformInit: Failed to load kernel region into RAM.\r\n")));
        SPIN_FOREVER;
    }
#endif 0

    EdbgOutputDebugString("\r\nJumping to image at virtual address 0x%Xh\r\n", dwLaunchAddr);

    //  Our Launch function takes Physical address, so we need to convert it
    //  to physical address

    dwLaunchAddr = ToPhysicalAddr(dwLaunchAddr);
    EdbgOutputDebugString("\r\n::: Physical Launch Address: 0x%Xh\r\n",dwLaunchAddr);

    Launch(dwLaunchAddr);

    // never returned
    SPIN_FOREVER;
}


/*
    @func   BOOL | OEMReadData | Generically read download data (abstracts actual transport read call).
    @rdesc  TRUE = Success, FALSE = Failure.
    @comm
    @xref
*/
BOOL OEMReadData (DWORD cbData, LPBYTE pbData)
{
    return EbootEtherReadData(cbData, pbData);
}


/*
    @func   void | OEMShowProgress | Displays download progress for the user.
    @rdesc  N/A.
    @comm
    @xref
*/
void OEMShowProgress (DWORD dwPacketNum)
{
}


#define BACKSPACE   8
#define IPADDR_MAX  15
// Read IP from command line
static BOOL ReadIPLine (char *pbuf, DWORD dwTimeout)
{
    DWORD dwCurrSec = OEMEthGetSecs ();
    char ch;
    int nLen = 0;
    while (OEMEthGetSecs () - dwCurrSec < dwTimeout) {
        ch = (CHAR)OEMReadDebugByte();
        switch (ch) {
        case OEM_DEBUG_COM_ERROR:
        case OEM_DEBUG_READ_NODATA:
            // no data or error, keep reading
            break;

⌨️ 快捷键说明

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