📄 menu.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 OR INDEMNITIES.
//
//------------------------------------------------------------------------------
//
// File: menu.c
//
// Menu routines for the Plato bootloader.
//
#include <windows.h>
#include <bsp.h>
#include "loader.h"
#include "Wait.h"
#include "KeyPad.h"
//------------------------------------------------------------------------------
// Global variables.
//
extern BSP_ARGS *g_pBSPArgs;
extern EBOOT_CFG g_EbootCFG;
extern BOOL g_DownloadImage;
extern BOOL g_FormatFlash;
extern BOOL g_DisplayMenu;
extern BOOL g_BootFromSD;
BOOL g_PauseBoot;
//------------------------------------------------------------------------------
// Local function prototypes.
//
static void SetMAC(unsigned char *mac);
static void SetIP(EBOOT_CFG *pEbootCFG);
static void SetMask(EBOOT_CFG *pEbootCFG);
static void SetBootMe(EBOOT_CFG *pEbootCFG);
static void SetDelay(EBOOT_CFG *pEbootCFG);
//------------------------------------------------------------------------------
// External function prorotypes.
//
extern void ResetDefaultEBootCFG(EBOOT_CFG *pEbootCFG);
extern BOOL StoreEBootCFG(EBOOT_CFG *EBootCFG);
extern VOID DisplayStartUpScreen();
extern VOID DisplayDebugString(char * str);
extern VOID DisplayString(int line, char * str);
extern UINT32 BLSDMMCDownload(CHAR *szBinFileName);
BOOL UseKeypadBootKeys(UINT8 Key)
{
BOOL fBootKeyFound = TRUE;
if (g_DisplayMenu == FALSE)
{
switch(Key)
{
case 0x23: /* 5, Show Menu */
g_DisplayMenu = TRUE;
g_PauseBoot = TRUE;
break;
default:
fBootKeyFound = FALSE;
}
}
else
{
switch(Key)
{
case 0x44: /* 1, Enable KITL */
KITLOutputDebugString ( "KITL at boot, Enabled.\r\n\n" );
g_EbootCFG.KITLEnabled = TRUE;
break;
case 0x11: /* 3, Disable KITL */
KITLOutputDebugString ( "KITL at boot, Disabled.\r\n\n" );
g_EbootCFG.KITLEnabled = FALSE;
break;
case 0x23: /* 5, Show Menu */
g_DisplayMenu = TRUE;
break;
case 0x42: /* 7, Boot Always from Flash */
KITLOutputDebugString ( "Launch existing flash resident image at startup.\r\n\n" );
g_DownloadImage = FALSE;
g_EbootCFG.autoDownloadImage = FALSE;
break;
case 0x33: /* 8, Format Flash */
KITLOutputDebugString ( "\r\nFormat user partition and clean system hive at boot.\r\n");
g_pBSPArgs->bFormatPartFlag = TRUE;
break;
case 0x21: /* 9, Boot Always from PB */
KITLOutputDebugString ( "Download new image at startup.\r\n\n" );
g_DownloadImage = TRUE;
g_EbootCFG.autoDownloadImage = TRUE;
break;
case 0x32: /* 0, Exit Menu and Boot */
g_PauseBoot = FALSE;
break;
default:
fBootKeyFound = FALSE;
}
}
if(fBootKeyFound)
{
DisplayStartUpScreen();
}
return fBootKeyFound;
}
BOOL BLDownloadFromSDCard()
{
BOOL retval = FALSE;
UINT32 StartTime, CurrTime, PrevTime;
UINT32 Selection;
UINT8 Key = NO_KEY;
if (BL_DOWNLOAD == BLSDMMCDownload("FLASH.BIN"))
{
KITLOutputDebugString ( "\r\nSD card image detected. \r\n");
KITLOutputDebugString ( "Press [SPACE] to load SD image.\r\n");
DisplayString(15, "SD card image detected.");
DisplayString(16, "Press 1 to load SD image.");
StartTime = OEMEthGetSecs();
PrevTime = StartTime;
CurrTime = StartTime;
Selection = 0;
// Allow the user 5 seconds to decide
//
while ((CurrTime - StartTime) < 5)
{
Selection = OEMReadDebugByte();
if ((Selection == 0x20))
{
retval = TRUE;
break;
}
ReadKeyPad(&Key);
if(NO_KEY != Key)
{
switch(Key)
{
case 0x44: // '1' key
retval = TRUE;
break;
default:
retval = FALSE;
}
break;
}
CurrTime = OEMEthGetSecs();
}
}
DisplayString(15, "");
if (!retval)
{
DisplayDebugString("Press 5 for boot menu.");
}
return retval;
}
//------------------------------------------------------------------------------
// This function delays the Automatic selection of boot option (download or launch) so
// that the user can change the behavior if needed.
//
UINT32 BLAutoBootDelay(BOOL *pfCFGChanged)
{
UINT32 AutoBootDelay = 0;
BOOLEAN bCFGChanged = FALSE;
UINT32 StartTime, CurrTime, PrevTime;
UINT32 Selection = 0;
UINT8 Key = NO_KEY;
static CHAR * BootIn = "Boot in XX seconds.";
g_PauseBoot = FALSE;
// Display Autoboot message
//
if (g_EbootCFG.autoDownloadImage)
{
g_DownloadImage = TRUE;
KITLOutputDebugString ( "\r\nPress [ENTER] to download now or [SPACE] to cancel.\r\n");
KITLOutputDebugString ( "\r\nInitiating image download in %d seconds. ", AutoBootDelay);
}
else
{
g_DownloadImage = FALSE;
KITLOutputDebugString ( "\r\nPress [ENTER] to launch image stored in flash or [SPACE] to cancel.\r\n");
KITLOutputDebugString ( "\r\nInitiating image launch in %d seconds. ", AutoBootDelay);
}
AutoBootDelay = g_EbootCFG.delay;
// Get a snapshot of the RTC seconds count.
//
StartTime = OEMEthGetSecs();
PrevTime = StartTime;
CurrTime = StartTime;
Selection = 0;
// Allow the user an amount of time to halt the auto boot/download process.
// Count down to 0 before proceeding with default operation.
//
while ((CurrTime - StartTime) < g_EbootCFG.delay)
{
UINT8 i=0;
UINT8 j;
Selection = OEMReadDebugByte();
if ((Selection == 0x20) || (Selection == 0x0d))
{
break;
}
ReadKeyPad(&Key);
if(NO_KEY != Key)
{
if(UseKeypadBootKeys(Key))
{
*pfCFGChanged = TRUE;
}
}
CurrTime = OEMEthGetSecs();
if (g_PauseBoot)
{
StartTime = CurrTime;
AutoBootDelay = g_EbootCFG.delay;
}
if (CurrTime > PrevTime)
{
AutoBootDelay--;
PrevTime = CurrTime;
if (AutoBootDelay < 9)
i = 11;
else if (AutoBootDelay < 99)
i = 12;
else if (AutoBootDelay < 999)
i = 13;
for (j = 0; j < i; j++)
{
OEMWriteDebugByte((BYTE)0x08); // print back space
}
KITLOutputDebugString ( "%d seconds. ", AutoBootDelay);
if (g_PauseBoot == FALSE)
{
if (g_DisplayMenu)
{
if (AutoBootDelay <= 99)
{
BootIn[8] = '0' + ((AutoBootDelay / 10) % 10);
BootIn[9] = '0' + (AutoBootDelay % 10);
DisplayString(16, BootIn);
}
else
{
DisplayString(16, "Boot in over 99 seconds.");
}
}
}
}
}
return Selection;
}
//------------------------------------------------------------------------------
// This function displays the boot menu on serial debug output and awaits user input
//
BOOL BLMenuSerial()
{
BOOLEAN bCFGChanged = FALSE;
UINT32 Selection = 0;
UCHAR rndis_mac[6] = {0,0,0,0,0,0};
g_FormatFlash = FALSE;
while (1)
{
// Show menu
KITLOutputDebugString ( "\r\n\r\nBoot Loader Configuration:\r\n\r\n");
KITLOutputDebugString ( "0) IP address: %s\r\n",inet_ntoa(g_EbootCFG.IP));
KITLOutputDebugString ( "1) Subnet Mask: %s\r\n", inet_ntoa(g_EbootCFG.subnetMask));
KITLOutputDebugString ( "2) Boot delay: %d seconds\r\n", g_EbootCFG.delay);
KITLOutputDebugString ( "3) %s DHCP\r\n", (g_EbootCFG.DHCPEnable == TRUE?"Disable":"Enable"));
KITLOutputDebugString ( "4) Reset to factory default configuration\r\n");
KITLOutputDebugString ( "5) RNDIS MAC address: %x-%x-%x-%x-%x-%x\r\n",(UCHAR) g_EbootCFG.RNDISMac[0],
(UCHAR) (g_EbootCFG.RNDISMac[0]>>8),
(UCHAR)g_EbootCFG.RNDISMac[1],
(UCHAR)(g_EbootCFG.RNDISMac[1]>>8),
(UCHAR)g_EbootCFG.RNDISMac[2],
(UCHAR)(g_EbootCFG.RNDISMac[2]>>8));
KITLOutputDebugString ( "6) %s image at startup\r\n", g_EbootCFG.autoDownloadImage?"Download new":"Launch existing flash resident");
KITLOutputDebugString ( "7) %s KITL at boot.\r\n", (g_EbootCFG.KITLEnabled == TRUE?"Disable":"Enable"));
KITLOutputDebugString ( "8) Format user partition and clean system hive at boot (%s).\r\n", g_pBSPArgs->bFormatPartFlag ? "Enabled" : "Disabled");
KITLOutputDebugString ( "9) Re-format physical flash layout.\r\n");
KITLOutputDebugString ( "D) Download image now\r\n");
KITLOutputDebugString ( "L) Launch existing flash resident image now\r\n");
KITLOutputDebugString ( "\r\n\r\nEnter your selection: ");
// Read user selection
Selection = 0;
while (! ( ( (Selection >= '0') && (Selection <= '9') ) ||
( (Selection == 'D') || (Selection == 'd') ) ||
( (Selection == 'L') || (Selection == 'l') ) ))
{
Selection = OEMReadDebugByte();
}
KITLOutputDebugString ( "%c\r\n", Selection);
// Process user selection
switch (Selection)
{
case '0':
SetIP(&g_EbootCFG);
bCFGChanged=TRUE;
break;
case '1':
SetMask(&g_EbootCFG);
bCFGChanged=TRUE;
break;
case '2':
SetDelay(&g_EbootCFG);
bCFGChanged=TRUE;
break;
case '3':
if (g_EbootCFG.DHCPEnable == TRUE)
g_EbootCFG.DHCPEnable = FALSE;
else
g_EbootCFG.DHCPEnable = TRUE;
bCFGChanged=TRUE;
break;
case '4':
ResetDefaultEBootCFG(&g_EbootCFG);
break;
case '5':
SetMAC(&rndis_mac[0]);
// Save the user enter RNDIS MAC address
g_EbootCFG.RNDISMac[0] = (rndis_mac[1] << 8) | rndis_mac[0];
g_EbootCFG.RNDISMac[1] = (rndis_mac[3] << 8) | rndis_mac[2];
g_EbootCFG.RNDISMac[2] = (rndis_mac[5] << 8) | rndis_mac[4];
bCFGChanged = TRUE;
break;
case '6':
if (g_EbootCFG.autoDownloadImage == TRUE)
g_EbootCFG.autoDownloadImage = FALSE;
else
g_EbootCFG.autoDownloadImage = TRUE;
bCFGChanged=TRUE;
break;
case '7':
if (g_EbootCFG.KITLEnabled == TRUE)
g_EbootCFG.KITLEnabled = FALSE;
else
g_EbootCFG.KITLEnabled = TRUE;
bCFGChanged=TRUE;
break;
case '8':
if (g_pBSPArgs->bFormatPartFlag == TRUE)
g_pBSPArgs->bFormatPartFlag = FALSE;
else
g_pBSPArgs->bFormatPartFlag = TRUE;
break;
case '9':
KITLOutputDebugString("\r\nFormatting flash requires a bootloader download. \r\n");
KITLOutputDebugString("Flash will be formatted before writing the new bootloader. \r\n");
KITLOutputDebugString("Preparing to download... \r\n\r\n");
g_FormatFlash = TRUE;
g_DownloadImage = TRUE;
goto exitMenu;
break;
case 'D':
case 'd':
g_DownloadImage = TRUE;
goto exitMenu;
break;
case 'L':
case 'l':
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -