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

📄 main.c

📁 使用三星ARM2410的eboot程序
💻 C
📖 第 1 页 / 共 4 页
字号:
    @rdesc  TRUE = user selected download image, FALSE = user selected launch stored image.
    @comm
    @xref
*/
static BOOLEAN BootMonitor( )
{
    int  KeySelect = 0;
    BOOLEAN bConfigChanged = FALSE;
    BOOLEAN bDownload = TRUE;

    while(1)
    {
        KeySelect = 0;

        EdbgOutputDebugString ( "\r\nEthernet Boot Loader Configuration:\r\n");
        EdbgOutputDebugString ( "---------------------------------------\r\n");
        EdbgOutputDebugString ( "1) IP address: %s\r\n", inet_ntoa(g_pBootCfg->EdbgAddr.dwIP));
        EdbgOutputDebugString ( "   Subnet mask: %s\r\n", inet_ntoa(g_pBootCfg->SubnetMask));
        EdbgOutputDebugString ( "2) Boot delay: %d seconds\r\n", g_pBootCfg->BootDelay);
        EdbgOutputDebugString ( "3) DHCP: %s\r\n", (g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DHCP) ? "ENABLED" : "DISABLED");
        EdbgOutputDebugString ( "4) Reset TOC to default\r\n");
        EdbgOutputDebugString ( "5) Startup image: %s\r\n", (g_pBootCfg->ConfigFlags & BOOT_TYPE_DIRECT) ? "LAUNCH EXISTING" : "DOWNLOAD NEW");
        EdbgOutputDebugString ( "6) Program RAM image into Boot Media: %s\r\n", (g_pBootCfg->ConfigFlags & TARGET_TYPE_NAND) ? "ENABLED" : "DISABLED");
        EdbgOutputDebugString ( "7) 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) Kernel Debugger: %s\r\n", (g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DEBUGGER) ? "ENABLED" : "DISABLED");
        EdbgOutputDebugString ( "9) Format Boot Media for BinFS\r\n");
        EdbgOutputDebugString ( "\r\n");

        // 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 ( "B) Support BinFS: %s\r\n", (g_pTOC->id[g_dwTocEntry].dwImageType & IMAGE_TYPE_BINFS) ? "ENABLED" : "DISABLED");

        EdbgOutputDebugString ( "D) DOWNLOAD image now\r\n");
//        EdbgOutputDebugString ( "E) Image descriptor Entry: %u \r\n", g_dwTocEntry);
        EdbgOutputDebugString ( "F) Low-level FORMAT Boot Media\r\n");
        EdbgOutputDebugString ( "L) LAUNCH existing Boot Media image\r\n");
		EdbgOutputDebugString ( "R) Read Configuration \r\n");
        EdbgOutputDebugString ( "U) Set UDID : %B:%B:%B:%B:%B:%B\r\n", g_pTOC->udid[0], g_pTOC->udid[1], g_pTOC->udid[2], g_pTOC->udid[3], g_pTOC->udid[4], g_pTOC->udid[5]);
		EdbgOutputDebugString ( "W) Write Configuration Right Now\r\n");
        EdbgOutputDebugString ( "X) DOWNLOAD image to boot media, then LAUNCH it off the media\r\n");
        EdbgOutputDebugString ( "---------------------------------------\r\n");

        EdbgOutputDebugString ( "\r\nEnter your selection: ");

        while (! ( ( (KeySelect >= '0') && (KeySelect <= '9') ) ||
                 ( (KeySelect == 'B') || (KeySelect == 'b') )   ||
                 ( (KeySelect == 'E') || (KeySelect == 'e') )   ||
                 ( (KeySelect == 'F') || (KeySelect == 'f') )   ||
                 ( (KeySelect == 'D') || (KeySelect == 'd') )   ||
                 ( (KeySelect == 'L') || (KeySelect == 'l') )   ||
                 ( (KeySelect == 'R') || (KeySelect == 'r') )   ||
                 ( (KeySelect == 'U') || (KeySelect == 'u') )   ||
                 ( (KeySelect == 'W') || (KeySelect == 'w') )   ||
                 ( (KeySelect == 'X') || (KeySelect == 'x') )
               ))
        {
            KeySelect = OEMReadDebugByte();
        }

        EdbgOutputDebugString ( "%c\r\n", KeySelect);
        switch(KeySelect)
        {
        case '1':           // Change IP/Subnet address.
            if ( GetUserIPAddr(&g_pBootCfg->EdbgAddr, &g_pBootCfg->SubnetMask) ) {
                g_pBootCfg->ConfigFlags &= ~CONFIG_FLAGS_DHCP;   // clear DHCP flag
                bConfigChanged = TRUE;
            }
            continue;
            break;
        case '2':           // Change autoboot delay.
            SetDelay(g_pBootCfg);
            bConfigChanged = TRUE;
            continue;
            break;
        case '3':           // Toggle static/DHCP mode.
            g_pBootCfg->ConfigFlags = (g_pBootCfg->ConfigFlags ^ CONFIG_FLAGS_DHCP);
            bConfigChanged = TRUE;
            continue;
            break;
        case '4':           // Reset TOC configuration.
            RETAILMSG(1, (TEXT("Resetting default TOC...\r\n")));
            TOC_Init(DEFAULT_IMAGE_DESCRIPTOR, (IMAGE_TYPE_RAMIMAGE|IMAGE_TYPE_BINFS), 0, 0, 0);
            if ( !TOC_Write() ) {
                RETAILMSG(1, (TEXT("TOC_Write Failed!\r\n")));
            }
            RETAILMSG(1, (TEXT("...TOC complete\r\n")));
            continue;
            break;
        case '5':           // Toggle download/launch status.
            g_pBootCfg->ConfigFlags = (g_pBootCfg->ConfigFlags ^ BOOT_TYPE_DIRECT);
            bConfigChanged = TRUE;
            break;
        case '6':           // Toggle boot media image store.
            g_pBootCfg->ConfigFlags = (g_pBootCfg->ConfigFlags ^ TARGET_TYPE_NAND);
            bConfigChanged = TRUE;
            break;
        case '7':           // Configure MAC address.
            SetCS8900MACAddress();
            bConfigChanged = TRUE;
            continue;
            break;
        case '8':           // Toggle KD
            g_pBootCfg->ConfigFlags = (g_pBootCfg->ConfigFlags ^ CONFIG_FLAGS_DEBUGGER);
            g_bWaitForConnect = (g_pBootCfg->ConfigFlags & CONFIG_FLAGS_DEBUGGER) ? TRUE : FALSE;
            bConfigChanged = TRUE;
            continue;
            break;
        case '9':
            // format the boot media for BinFS
            // N.B: this does not destroy our OEM reserved sections (TOC, bootloaders, etc)
            if ( !g_bBootMediaExist ) {
                RETAILMSG(1, (TEXT("ERROR: BootMonitor: boot media does not exist.\r\n")));
                continue;
            }
            // N.B: format offset by # of reserved blocks,
            // decrease the ttl # blocks available by that amount.
            if ( !BP_LowLevelFormat( g_dwImageStartBlock,
                                     NUM_BLOCKS - g_dwImageStartBlock,
                                     0) )
            {
                RETAILMSG(1, (TEXT("ERROR: BootMonitor: Low-level boot media format failed.\r\n")));
                continue;
            }
            break;
        case 'B':
        case 'b':
            g_pTOC->id[g_dwTocEntry].dwImageType = (g_pTOC->id[g_dwTocEntry].dwImageType ^ IMAGE_TYPE_BINFS);
            g_ImageType = g_pTOC->id[g_dwTocEntry].dwImageType;
            bConfigChanged = TRUE;
            break;
        case 'E':
        case 'e':
            // TODO
            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 ) {
                RETAILMSG(1, (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  = 0;
                si.wReserved2   = 0;

                RETAILMSG(1, (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);
                }
                RETAILMSG(1, (TEXT("...reserve complete.\r\n")));

                RETAILMSG(1, (TEXT("Low-level format Blocks [0x%x - 0x%x] ...\r\n"), IMAGE_START_BLOCK, NUM_BLOCKS-1));
                for (i = IMAGE_START_BLOCK; i < NUM_BLOCKS; i++) {
                    FMD_EraseBlock(i);
                }
                RETAILMSG(1, (TEXT("...erase complete.\r\n")));
            } 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();
			continue;
            // TODO
            break;
        case 'U':           // Download? No.
        case 'u':
            if ( SetUDID() ) {
                bConfigChanged = TRUE;
            }
            continue;
            goto MENU_DONE;
        case 'W':           // Configuration Write
        case 'w':
            if (!TOC_Write())
            {
                RETAILMSG(1, (TEXT("WARNING: MainMenu: Failed to store updated eboot configuration in flash.\r\n")));
            }
            else
            {
                RETAILMSG(1, (TEXT("Successfully Written\r\n")));
                bConfigChanged = FALSE;
            }
            break;
        case 'X':           // Download to media, then launch that
        case 'x':
            bDownload = TRUE;
            bConfigChanged = TRUE;
            g_pBootCfg->ConfigFlags |= TARGET_TYPE_NAND | BOOT_TYPE_DIRECT;
            goto MENU_DONE;
        default:
            break;
        }
    }

MENU_DONE:
    // If eboot settings were changed by user, save them.
    //
    if (bConfigChanged && !TOC_Write( ) )
    {
        RETAILMSG(1, (TEXT("WARNING: BootMonitor: Failed to store updated eboot configuration in flash.\r\n")));
    }

    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!

#ifdef SIMULATOR
    EdbgOutputDebugString("Microsoft Windows CE Catfish Bootloader *** SIMULATOR *** \r\n");
#else
    EdbgOutputDebugString("Microsoft Windows CE Catfish 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);
    }


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

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

⌨️ 快捷键说明

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