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

📄 menu.c

📁 arm4 driver for freescale imx35
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES.
//
//------------------------------------------------------------------------------
//
//  File:  menu.c
//


#include <eboot.h>
#include <utilities.h>


extern BOOT_CFG g_bootCfg;
extern EBOOT_CONTEXT g_eboot;
extern OAL_KITL_DEVICE g_bootDevices[];
extern OAL_KITL_DEVICE g_kitlDevices[];

//------------------------------------------------------------------------------
//
//  Define:  dimof
//
#ifdef dimof
#undef dimof
#endif
#define dimof(x)                (sizeof(x)/sizeof(x[0]))

//------------------------------------------------------------------------------

static VOID ShowSettings(OAL_BLMENU_ITEM *pMenu);
static VOID ShowNetworkSettings(OAL_BLMENU_ITEM *pMenu);
static VOID SelectBootDevice(OAL_BLMENU_ITEM *pMenu);
static VOID SetKitlMode(OAL_BLMENU_ITEM *pMenu);
static VOID SaveSettings(OAL_BLMENU_ITEM *pMenu);
void ArubaboardBootShellMenuItem(OAL_BLMENU_ITEM *pMenu);


// Prototype so that we can jump to the bootloader shell code
void BootShell();

//------------------------------------------------------------------------------

static OAL_BLMENU_ITEM g_menuNetwork[] = {
    {
        L'1', L"Show Current Settings", ShowNetworkSettings,
        NULL, NULL, NULL
    }, {
        L'2', L"Enable/disable KITL", OALBLMenuEnable,
        L"KITL", &g_bootCfg.kitlFlags, (VOID*)OAL_KITL_FLAGS_ENABLED
    }, {
        L'3', L"KITL interrupt/poll mode", SetKitlMode,
        NULL, NULL, NULL
    }, {
        L'4', L"Enable/disable DHCP", OALBLMenuEnable,
        L"DHCP", &g_bootCfg.kitlFlags, (VOID*)OAL_KITL_FLAGS_DHCP
    }, {
        L'5', L"Set IP address", OALBLMenuSetIpAddress,
        L"Device", &g_bootCfg.ipAddress, NULL
    }, {
        L'6', L"Set IP mask", OALBLMenuSetIpMask,
        L"Device", &g_bootCfg.ipMask, NULL
    }, {
        L'7', L"Set default router", OALBLMenuSetIpAddress,
        L"Default router", &g_bootCfg.ipRoute, NULL
    }, {
        L'8', L"Enable/disable VMINI", OALBLMenuEnable,
        L"VMINI", &g_bootCfg.kitlFlags, (VOID*)OAL_KITL_FLAGS_VMINI
    }, {
        L'0', L"Exit and Continue", NULL,
        NULL, NULL, NULL
    }, {
        0, NULL, NULL,
        NULL, NULL, NULL
    }
};

static OAL_BLMENU_ITEM g_menuMain[] = {
    {
        L'1', L"Bootloader Shell", ArubaboardBootShellMenuItem,
        NULL, NULL, NULL
    }, {
        L'2', L"Show Current Settings", ShowSettings,
        NULL, NULL, NULL
    }, {
        L'3', L"Select Boot Device", SelectBootDevice,
        L"Boot", &g_bootCfg.bootDevLoc, g_bootDevices
    }, {
        L'4', L"Select Debug Device", OALBLMenuSelectDevice,
        L"Debug", &g_bootCfg.kitlDevLoc, g_kitlDevices
    }, {
        L'5', L"Network Settings", OALBLMenuShow,
        L"Network Settings", &g_menuNetwork, NULL
    }, {
        L'6', L"Save Settings", SaveSettings,
        NULL, NULL, NULL
    }, {
        L'0', L"Exit and Continue", NULL,
        NULL, NULL, NULL
    }, {
        0, NULL, NULL,
        NULL, NULL, NULL
    }
};

static OAL_BLMENU_ITEM g_menuRoot = {
    0, NULL, OALBLMenuShow,
    L"ArubaBoard Main Menu", g_menuMain, NULL
};

//------------------------------------------------------------------------------

VOID BLMenu()
{
    UINT32 time, delay = 5;
    WCHAR key = 0;

    // First let user break to menu
    OALLog(L"Hit space to enter ArubaBoard bootloader menu.");
    while (delay > 0 && key != L' ') 
	{
       OALLog(L".", delay);
       time = OALGetTickCount();
       while ((OALGetTickCount() - time) < 1000) {
          if ((key = OALBLMenuReadKey(FALSE)) == L' ') break;
       }
       delay--;
    }
    
    if (key == L' ') {
        OALBLMenuShow(&g_menuRoot);
    }        
    else {
        OALLog(L"\r\n");
    }        
}

//------------------------------------------------------------------------------

VOID ShowSettings(OAL_BLMENU_ITEM *pMenu)
{
    OALLog(L"\r\n Main:\r\n");
    if(g_bootCfg.bootDevLoc.LogicalLoc == OMAP5912_MMCSD_REGS_PA){ // boot from SD/MMC
        OALLog(
            L"  Boot device:   %s(%S)\r\n",
            OALKitlDeviceName(&g_bootCfg.bootDevLoc, g_bootDevices), g_bootCfg.binName
            );
    }
    else{
        OALLog(
            L"  Boot device:   %s\r\n",
            OALKitlDeviceName(&g_bootCfg.bootDevLoc, g_bootDevices)
            );
    }
    OALLog(
        L"  Debug device:  %s\r\n",
        OALKitlDeviceName(&g_bootCfg.kitlDevLoc, g_kitlDevices)
    );
    ShowNetworkSettings(pMenu);
}

//------------------------------------------------------------------------------

VOID ShowNetworkSettings(OAL_BLMENU_ITEM *pMenu)
{
    OALLog(L"\r\n Network:\r\n");
    OALLog(
        L"  KITL state:    %s\r\n",
        (g_bootCfg.kitlFlags & OAL_KITL_FLAGS_ENABLED) ? L"enabled" : L"disabled"
    );
    OALLog(
        L"  KITL mode:     %s\r\n",
        (g_bootCfg.kitlFlags & OAL_KITL_FLAGS_POLL) ? L"poll" : L"interrupt"
    );
    OALLog(
        L"  DHCP:          %s\r\n",
        (g_bootCfg.kitlFlags & OAL_KITL_FLAGS_DHCP) ? L"enabled" : L"disabled"
    );
    OALLog(L"  IP address:    %s\r\n", OALKitlIPtoString(g_bootCfg.ipAddress));
    OALLog(L"  IP mask:       %s\r\n", OALKitlIPtoString(g_bootCfg.ipMask));
    OALLog(L"  IP router:     %s\r\n", OALKitlIPtoString(g_bootCfg.ipRoute));
    OALLog(
        L"  VMINI:         %s\r\n",
        (g_bootCfg.kitlFlags & OAL_KITL_FLAGS_VMINI) ? L"enabled" : L"disabled"
    );
}

//------------------------------------------------------------------------------

VOID SelectBootDevice(OAL_BLMENU_ITEM *pMenu){
    int i;
    WCHAR buf[MAX_PATH];

    OALBLMenuSelectDevice(pMenu);
    if(g_bootCfg.bootDevLoc.LogicalLoc == OMAP5912_MMCSD_REGS_PA){ // boot from SD/MMC
        // let user select image name
        OALLog(L"Enter image name(actual '%S'): ", g_bootCfg.binName);
        if(OALBLMenuReadLine(buf, dimof(buf))){
            for(i = 0; buf[i] != 0; ++i){
                g_bootCfg.binName[i] = (CHAR)buf[i];
            }
        }
    }
}

//------------------------------------------------------------------------------

VOID SetKitlMode(OAL_BLMENU_ITEM *pMenu)
{
    WCHAR key;

    if ((g_bootCfg.kitlFlags & OAL_KITL_FLAGS_POLL) != 0) {
        OALLog(L" Set KITL to interrupt mode [y/-]: ");
    } else {
        OALLog(L" Set KITL to poll mode [y/-]: ");
    }    

    // Get key
    key = OALBLMenuReadKey(TRUE);
    OALLog(L"%c\r\n", key);

    if (key == L'y' || key == L'Y') {
        if ((g_bootCfg.kitlFlags & OAL_KITL_FLAGS_POLL) != 0) {
            g_bootCfg.kitlFlags &= ~OAL_KITL_FLAGS_POLL;
            OALLog(L" KITL set to interrupt mode\r\n");
        } else {
            g_bootCfg.kitlFlags |= OAL_KITL_FLAGS_POLL;
            OALLog(L" KITL set to poll mode\r\n");
        }            
    }
}

//------------------------------------------------------------------------------

VOID SaveSettings(OAL_BLMENU_ITEM *pMenu)
{
    WCHAR key;

    OALLog(L" Do you want save current settings [-/y]? ");

    // Get key
    key = OALBLMenuReadKey(TRUE);
    OALLog(L"%c\r\n", key);

    // Depending on result
    if (key != L'y' && key != L'Y') goto cleanUp;

    if (BLWriteBootCfg(&g_bootCfg)) 
	{
        OALLog(L" Current settings has been saved\r\n");
    }
	else 
	{        
        OALLog(L"ERROR: Settings save failed!\r\n");
    }

cleanUp:
    return;
}

//------------------------------------------------------------------------------


void ArubaboardBootShellMenuItem(OAL_BLMENU_ITEM *pMenu)
{
    BootShell();
}


//------------------------------------------------------------------------------


⌨️ 快捷键说明

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