--- /dev/null
+/** @file\r
+ The boot manager reference implementation\r
+\r
+ Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+ This software and associated documentation (if any) is furnished\r
+ under a license and may only be used or copied in accordance\r
+ with the terms of the license. Except as permitted by such\r
+ license, no part of this software or documentation may be\r
+ reproduced, stored in a retrieval system, or transmitted in any\r
+ form or by any means without the express written consent of\r
+ Intel Corporation.\r
+\r
+**/\r
+\r
+#include "BootManager.h"\r
+\r
+UINT16 mKeyInput;\r
+EFI_GUID mBootManagerGuid = BOOT_MANAGER_FORMSET_GUID;\r
+//\r
+// Boot video resolution and text mode.\r
+//\r
+UINT32 mBmBootHorizontalResolution = 0;\r
+UINT32 mBmBootVerticalResolution = 0;\r
+UINT32 mBmBootTextModeColumn = 0;\r
+UINT32 mBmBootTextModeRow = 0;\r
+//\r
+// BIOS setup video resolution and text mode.\r
+//\r
+UINT32 mBmSetupTextModeColumn = 0;\r
+UINT32 mBmSetupTextModeRow = 0;\r
+UINT32 mBmSetupHorizontalResolution = 0;\r
+UINT32 mBmSetupVerticalResolution = 0;\r
+\r
+CHAR16 *mDeviceTypeStr[] = {\r
+ L"Legacy BEV",\r
+ L"Legacy Floppy",\r
+ L"Legacy Hard Drive",\r
+ L"Legacy CD ROM",\r
+ L"Legacy PCMCIA",\r
+ L"Legacy USB",\r
+ L"Legacy Embedded Network",\r
+ L"Legacy Unknown Device"\r
+};\r
+\r
+HII_VENDOR_DEVICE_PATH mBootManagerHiiVendorDevicePath = {\r
+ {\r
+ {\r
+ HARDWARE_DEVICE_PATH,\r
+ HW_VENDOR_DP,\r
+ {\r
+ (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
+ (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
+ }\r
+ },\r
+ //\r
+ // {1DDDBE15-481D-4d2b-8277-B191EAF66525}\r
+ //\r
+ { 0x1dddbe15, 0x481d, 0x4d2b, { 0x82, 0x77, 0xb1, 0x91, 0xea, 0xf6, 0x65, 0x25 } }\r
+ },\r
+ {\r
+ END_DEVICE_PATH_TYPE,\r
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+ { \r
+ (UINT8) (END_DEVICE_PATH_LENGTH),\r
+ (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
+ }\r
+ }\r
+};\r
+\r
+BOOT_MANAGER_CALLBACK_DATA gBootManagerPrivate = {\r
+ BOOT_MANAGER_CALLBACK_DATA_SIGNATURE,\r
+ NULL,\r
+ NULL,\r
+ {\r
+ BootManagerExtractConfig,\r
+ BootManagerRouteConfig,\r
+ BootManagerCallback\r
+ }\r
+};\r
+\r
+/**\r
+ This function will change video resolution and text mode\r
+ according to defined setup mode or defined boot mode \r
+\r
+ @param IsSetupMode Indicate mode is changed to setup mode or boot mode. \r
+\r
+ @retval EFI_SUCCESS Mode is changed successfully.\r
+ @retval Others Mode failed to be changed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BmBdsSetConsoleMode (\r
+ BOOLEAN IsSetupMode\r
+ )\r
+{\r
+ EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;\r
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;\r
+ UINTN SizeOfInfo;\r
+ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;\r
+ UINT32 MaxGopMode;\r
+ UINT32 MaxTextMode;\r
+ UINT32 ModeNumber;\r
+ UINT32 NewHorizontalResolution;\r
+ UINT32 NewVerticalResolution;\r
+ UINT32 NewColumns;\r
+ UINT32 NewRows;\r
+ UINTN HandleCount;\r
+ EFI_HANDLE *HandleBuffer;\r
+ EFI_STATUS Status;\r
+ UINTN Index;\r
+ UINTN CurrentColumn;\r
+ UINTN CurrentRow; \r
+\r
+ MaxGopMode = 0;\r
+ MaxTextMode = 0;\r
+\r
+ //\r
+ // Get current video resolution and text mode \r
+ //\r
+ Status = gBS->HandleProtocol (\r
+ gST->ConsoleOutHandle,\r
+ &gEfiGraphicsOutputProtocolGuid,\r
+ (VOID**)&GraphicsOutput\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ GraphicsOutput = NULL;\r
+ }\r
+\r
+ Status = gBS->HandleProtocol (\r
+ gST->ConsoleOutHandle,\r
+ &gEfiSimpleTextOutProtocolGuid,\r
+ (VOID**)&SimpleTextOut\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ SimpleTextOut = NULL;\r
+ }\r
+\r
+ if ((GraphicsOutput == NULL) || (SimpleTextOut == NULL)) {\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ if (IsSetupMode) {\r
+ //\r
+ // The requried resolution and text mode is setup mode.\r
+ //\r
+ NewHorizontalResolution = mBmSetupHorizontalResolution;\r
+ NewVerticalResolution = mBmSetupVerticalResolution;\r
+ NewColumns = mBmSetupTextModeColumn;\r
+ NewRows = mBmSetupTextModeRow;\r
+ } else {\r
+ //\r
+ // The required resolution and text mode is boot mode.\r
+ //\r
+ NewHorizontalResolution = mBmBootHorizontalResolution;\r
+ NewVerticalResolution = mBmBootVerticalResolution;\r
+ NewColumns = mBmBootTextModeColumn;\r
+ NewRows = mBmBootTextModeRow; \r
+ }\r
+\r
+ if (GraphicsOutput != NULL) {\r
+ MaxGopMode = GraphicsOutput->Mode->MaxMode;\r
+ }\r
+\r
+ if (SimpleTextOut != NULL) {\r
+ MaxTextMode = SimpleTextOut->Mode->MaxMode;\r
+ }\r
+\r
+ //\r
+ // 1. If current video resolution is same with required video resolution,\r
+ // video resolution need not be changed.\r
+ // 1.1. If current text mode is same with required text mode, text mode need not be changed.\r
+ // 1.2. If current text mode is different from required text mode, text mode need be changed.\r
+ // 2. If current video resolution is different from required video resolution, we need restart whole console drivers.\r
+ //\r
+ for (ModeNumber = 0; ModeNumber < MaxGopMode; ModeNumber++) {\r
+ Status = GraphicsOutput->QueryMode (\r
+ GraphicsOutput,\r
+ ModeNumber,\r
+ &SizeOfInfo,\r
+ &Info\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ if ((Info->HorizontalResolution == NewHorizontalResolution) &&\r
+ (Info->VerticalResolution == NewVerticalResolution)) {\r
+ if ((GraphicsOutput->Mode->Info->HorizontalResolution == NewHorizontalResolution) &&\r
+ (GraphicsOutput->Mode->Info->VerticalResolution == NewVerticalResolution)) {\r
+ //\r
+ // Current resolution is same with required resolution, check if text mode need be set\r
+ //\r
+ Status = SimpleTextOut->QueryMode (SimpleTextOut, SimpleTextOut->Mode->Mode, &CurrentColumn, &CurrentRow);\r
+ ASSERT_EFI_ERROR (Status);\r
+ if (CurrentColumn == NewColumns && CurrentRow == NewRows) {\r
+ //\r
+ // If current text mode is same with required text mode. Do nothing\r
+ //\r
+ FreePool (Info);\r
+ return EFI_SUCCESS;\r
+ } else {\r
+ //\r
+ // If current text mode is different from requried text mode. Set new video mode\r
+ //\r
+ for (Index = 0; Index < MaxTextMode; Index++) {\r
+ Status = SimpleTextOut->QueryMode (SimpleTextOut, Index, &CurrentColumn, &CurrentRow);\r
+ if (!EFI_ERROR(Status)) {\r
+ if ((CurrentColumn == NewColumns) && (CurrentRow == NewRows)) {\r
+ //\r
+ // Required text mode is supported, set it.\r
+ //\r
+ Status = SimpleTextOut->SetMode (SimpleTextOut, Index);\r
+ ASSERT_EFI_ERROR (Status);\r
+ //\r
+ // Update text mode PCD.\r
+ //\r
+ PcdSet32 (PcdConOutColumn, mBmSetupTextModeColumn);\r
+ PcdSet32 (PcdConOutRow, mBmSetupTextModeRow);\r
+ FreePool (Info);\r
+ return EFI_SUCCESS;\r
+ }\r
+ }\r
+ }\r
+ if (Index == MaxTextMode) {\r
+ //\r
+ // If requried text mode is not supported, return error.\r
+ //\r
+ FreePool (Info);\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+ } else {\r
+ //\r
+ // If current video resolution is not same with the new one, set new video resolution.\r
+ // In this case, the driver which produces simple text out need be restarted.\r
+ //\r
+ Status = GraphicsOutput->SetMode (GraphicsOutput, ModeNumber);\r
+ if (!EFI_ERROR (Status)) {\r
+ FreePool (Info);\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ FreePool (Info);\r
+ }\r
+ }\r
+\r
+ if (ModeNumber == MaxGopMode) {\r
+ //\r
+ // If the resolution is not supported, return error.\r
+ //\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ //\r
+ // Set PCD to Inform GraphicsConsole to change video resolution.\r
+ // Set PCD to Inform Consplitter to change text mode.\r
+ //\r
+ PcdSet32 (PcdVideoHorizontalResolution, NewHorizontalResolution);\r
+ PcdSet32 (PcdVideoVerticalResolution, NewVerticalResolution);\r
+ PcdSet32 (PcdConOutColumn, NewColumns);\r
+ PcdSet32 (PcdConOutRow, NewRows);\r
+\r
+ //\r
+ // Video mode is changed, so restart graphics console driver and higher level driver.\r
+ // Reconnect graphics console driver and higher level driver.\r
+ // Locate all the handles with GOP protocol and reconnect it.\r
+ //\r
+ Status = gBS->LocateHandleBuffer (\r
+ ByProtocol,\r
+ &gEfiSimpleTextOutProtocolGuid,\r
+ NULL,\r
+ &HandleCount,\r
+ &HandleBuffer\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ for (Index = 0; Index < HandleCount; Index++) {\r
+ gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);\r
+ }\r
+ for (Index = 0; Index < HandleCount; Index++) {\r
+ gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);\r
+ }\r
+ if (HandleBuffer != NULL) {\r
+ FreePool (HandleBuffer);\r
+ }\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Group the legacy boot options in the BootOption.\r
+\r
+ The routine assumes the boot options in the beginning that covers all the device \r
+ types are ordered properly and re-position the following boot options just after\r
+ the corresponding boot options with the same device type.\r
+ For example:\r
+ 1. Input = [Harddisk1 CdRom2 Efi1 Harddisk0 CdRom0 CdRom1 Harddisk2 Efi0]\r
+ Assuming [Harddisk1 CdRom2 Efi1] is ordered properly\r
+ Output = [Harddisk1 Harddisk0 Harddisk2 CdRom2 CdRom0 CdRom1 Efi1 Efi0]\r
+\r
+ 2. Input = [Efi1 Efi0 CdRom1 Harddisk0 Harddisk1 Harddisk2 CdRom0 CdRom2]\r
+ Assuming [Efi1 Efi0 CdRom1 Harddisk0] is ordered properly\r
+ Output = [Efi1 Efi0 CdRom1 CdRom0 CdRom2 Harddisk0 Harddisk1 Harddisk2]\r
+\r
+**/\r
+VOID\r
+GroupMultipleLegacyBootOption4SameType (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ UINTN Index;\r
+ UINTN DeviceIndex;\r
+ UINTN DeviceTypeIndex[7];\r
+ UINTN *NextIndex;\r
+ UINT16 OptionNumber;\r
+ UINT16 *BootOrder;\r
+ UINTN BootOrderSize;\r
+ CHAR16 OptionName[sizeof ("Boot####")];\r
+ EFI_BOOT_MANAGER_LOAD_OPTION BootOption;\r
+\r
+ SetMem (DeviceTypeIndex, sizeof (DeviceTypeIndex), 0xff);\r
+\r
+ GetEfiGlobalVariable2 (L"BootOrder", (VOID **) &BootOrder, &BootOrderSize);\r
+\r
+ for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {\r
+ UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", BootOrder[Index]);\r
+ Status = EfiBootManagerVariableToLoadOption (OptionName, &BootOption);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ if ((DevicePathType (BootOption.FilePath) == BBS_DEVICE_PATH) &&\r
+ (DevicePathSubType (BootOption.FilePath) == BBS_BBS_DP)) {\r
+ //\r
+ // Legacy Boot Option\r
+ //\r
+ DEBUG ((EFI_D_ERROR, "[BootManagerDxe] ==== Find Legacy Boot Option 0x%x! ==== \n", Index));\r
+ ASSERT ((((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType & 0xF) < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0]));\r
+ NextIndex = &DeviceTypeIndex[((BBS_BBS_DEVICE_PATH *) BootOption.FilePath)->DeviceType & 0xF];\r
+\r
+ if (*NextIndex == (UINTN) -1) {\r
+ //\r
+ // *NextIndex is the Index in BootOrder to put the next Option Number for the same type\r
+ //\r
+ *NextIndex = Index + 1;\r
+ } else {\r
+ //\r
+ // insert the current boot option before *NextIndex, causing [*Next .. Index] shift right one position\r
+ //\r
+ OptionNumber = BootOrder[Index];\r
+ CopyMem (&BootOrder[*NextIndex + 1], &BootOrder[*NextIndex], (Index - *NextIndex) * sizeof (UINT16));\r
+ BootOrder[*NextIndex] = OptionNumber;\r
+\r
+ //\r
+ // Update the DeviceTypeIndex array to reflect the right shift operation\r
+ //\r
+ for (DeviceIndex = 0; DeviceIndex < sizeof (DeviceTypeIndex) / sizeof (DeviceTypeIndex[0]); DeviceIndex++) {\r
+ if (DeviceTypeIndex[DeviceIndex] != (UINTN) -1 && DeviceTypeIndex[DeviceIndex] >= *NextIndex) {\r
+ DeviceTypeIndex[DeviceIndex]++;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ EfiBootManagerFreeLoadOption (&BootOption);\r
+ }\r
+\r
+ gRT->SetVariable (\r
+ L"BootOrder",\r
+ &gEfiGlobalVariableGuid,\r
+ VAR_FLAG,\r
+ BootOrderSize,\r
+ BootOrder\r
+ );\r
+ FreePool (BootOrder);\r
+}\r
+\r
+/**\r
+ This function converts an input device structure to a Unicode string.\r
+\r
+ @param DevPath A pointer to the device path structure.\r
+\r
+ @return A new allocated Unicode string that represents the device path.\r
+\r
+**/\r
+CHAR16 *\r
+BmDevicePathToStr (\r
+ IN EFI_DEVICE_PATH_PROTOCOL *DevPath\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ CHAR16 *ToText;\r
+ EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevPathToText;\r
+\r
+ if (DevPath == NULL) {\r
+ return NULL;\r
+ }\r
+\r
+ Status = gBS->LocateProtocol (\r
+ &gEfiDevicePathToTextProtocolGuid,\r
+ NULL,\r
+ (VOID **) &DevPathToText\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ ToText = DevPathToText->ConvertDevicePathToText (\r
+ DevPath,\r
+ FALSE,\r
+ TRUE\r
+ );\r
+ ASSERT (ToText != NULL);\r
+ return ToText;\r
+}\r
+\r
+/**\r
+ This function invokes Boot Manager. If all devices have not a chance to be connected,\r
+ the connect all will be triggered. It then enumerate all boot options. If \r
+ a boot option from the Boot Manager page is selected, Boot Manager will boot\r
+ from this boot option.\r
+ \r
+**/\r
+VOID\r
+UpdateBootManager (\r
+ VOID\r
+ )\r
+{\r
+ UINTN Index;\r
+ EFI_BOOT_MANAGER_LOAD_OPTION *BootOption;\r
+ UINTN BootOptionCount;\r
+ EFI_STRING_ID Token;\r
+ CHAR16 *HelpString;\r
+ EFI_STRING_ID HelpToken;\r
+ UINT16 *TempStr;\r
+ EFI_HII_HANDLE HiiHandle;\r
+ UINTN TempSize;\r
+ VOID *StartOpCodeHandle;\r
+ VOID *EndOpCodeHandle;\r
+ EFI_IFR_GUID_LABEL *StartLabel;\r
+ EFI_IFR_GUID_LABEL *EndLabel;\r
+ UINT16 DeviceType;\r
+ BOOLEAN IsLegacyOption;\r
+ BOOLEAN NeedEndOp;\r
+ UINTN MaxLen;\r
+\r
+ DeviceType = (UINT16) -1;\r
+\r
+ EfiBootManagerConnectAll ();\r
+\r
+ //\r
+ // for better user experience\r
+ // 1. User changes HD configuration (e.g.: unplug HDD), here we have a chance to remove the HDD boot option\r
+ // 2. User enables/disables UEFI PXE, here we have a chance to add/remove EFI Network boot option\r
+ //\r
+ EfiBootManagerRefreshAllBootOption ();\r
+\r
+ //\r
+ // BdsDxe doesn't group the legacy boot options for the same device type\r
+ // It's UI's choice.\r
+ //\r
+ GroupMultipleLegacyBootOption4SameType ();\r
+\r
+ BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
+\r
+ HiiHandle = gBootManagerPrivate.HiiHandle;\r
+\r
+ //\r
+ // Allocate space for creation of UpdateData Buffer\r
+ //\r
+ StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
+ ASSERT (StartOpCodeHandle != NULL);\r
+\r
+ EndOpCodeHandle = HiiAllocateOpCodeHandle ();\r
+ ASSERT (EndOpCodeHandle != NULL);\r
+\r
+ //\r
+ // Create Hii Extend Label OpCode as the start opcode\r
+ //\r
+ StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
+ StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
+ StartLabel->Number = LABEL_BOOT_OPTION;\r
+\r
+ //\r
+ // Create Hii Extend Label OpCode as the end opcode\r
+ //\r
+ EndLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (EndOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
+ EndLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
+ EndLabel->Number = LABEL_BOOT_OPTION_END;\r
+ mKeyInput = 0;\r
+ NeedEndOp = FALSE;\r
+ for (Index = 0; Index < BootOptionCount; Index++) {\r
+ //\r
+ // At this stage we are creating a menu entry, thus the Keys are reproduceable\r
+ //\r
+ mKeyInput++;\r
+\r
+ //\r
+ // Don't display the hidden/inactive boot option\r
+ //\r
+ if (((BootOption[Index].Attributes & LOAD_OPTION_HIDDEN) != 0) || ((BootOption[Index].Attributes & LOAD_OPTION_ACTIVE) == 0)) {\r
+ continue;\r
+ }\r
+\r
+ //\r
+ // Group the legacy boot option in the sub title created dynamically\r
+ //\r
+ IsLegacyOption = (BOOLEAN) (\r
+ (DevicePathType (BootOption[Index].FilePath) == BBS_DEVICE_PATH) &&\r
+ (DevicePathSubType (BootOption[Index].FilePath) == BBS_BBS_DP)\r
+ );\r
+\r
+ if (!IsLegacyOption && NeedEndOp) {\r
+ NeedEndOp = FALSE;\r
+ HiiCreateEndOpCode (StartOpCodeHandle);\r
+ }\r
+ \r
+ if (IsLegacyOption && DeviceType != ((BBS_BBS_DEVICE_PATH *) BootOption[Index].FilePath)->DeviceType) {\r
+ if (NeedEndOp) {\r
+ HiiCreateEndOpCode (StartOpCodeHandle);\r
+ }\r
+\r
+ DeviceType = ((BBS_BBS_DEVICE_PATH *) BootOption[Index].FilePath)->DeviceType;\r
+ Token = HiiSetString (\r
+ HiiHandle,\r
+ 0,\r
+ mDeviceTypeStr[\r
+ MIN (DeviceType & 0xF, sizeof (mDeviceTypeStr) / sizeof (mDeviceTypeStr[0]) - 1)\r
+ ],\r
+ NULL\r
+ );\r
+ HiiCreateSubTitleOpCode (StartOpCodeHandle, Token, 0, 0, 1);\r
+ NeedEndOp = TRUE;\r
+ }\r
+\r
+ ASSERT (BootOption[Index].Description != NULL);\r
+\r
+ Token = HiiSetString (HiiHandle, 0, BootOption[Index].Description, NULL);\r
+\r
+ TempStr = BmDevicePathToStr (BootOption[Index].FilePath);\r
+ TempSize = StrSize (TempStr);\r
+ HelpString = AllocateZeroPool (TempSize + StrSize (L"Device Path : "));\r
+ MaxLen = (TempSize + StrSize (L"Device Path : "))/sizeof(CHAR16);\r
+ ASSERT (HelpString != NULL);\r
+ StrCatS (HelpString, MaxLen, L"Device Path : ");\r
+ StrCatS (HelpString, MaxLen, TempStr);\r
+\r
+ HelpToken = HiiSetString (HiiHandle, 0, HelpString, NULL);\r
+\r
+ HiiCreateActionOpCode (\r
+ StartOpCodeHandle,\r
+ mKeyInput,\r
+ Token,\r
+ HelpToken,\r
+ EFI_IFR_FLAG_CALLBACK,\r
+ 0\r
+ );\r
+ }\r
+\r
+ if (NeedEndOp) {\r
+ HiiCreateEndOpCode (StartOpCodeHandle);\r
+ }\r
+\r
+ HiiUpdateForm (\r
+ HiiHandle,\r
+ &mBootManagerGuid,\r
+ BOOT_MANAGER_FORM_ID,\r
+ StartOpCodeHandle,\r
+ EndOpCodeHandle\r
+ );\r
+\r
+ HiiFreeOpCodeHandle (StartOpCodeHandle);\r
+ HiiFreeOpCodeHandle (EndOpCodeHandle);\r
+\r
+ EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount);\r
+}\r
+\r
+/**\r
+ This function allows a caller to extract the current configuration for one\r
+ or more named elements from the target driver.\r
+\r
+\r
+ @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+ @param Request A null-terminated Unicode string in <ConfigRequest> format.\r
+ @param Progress On return, points to a character in the Request string.\r
+ Points to the string's null terminator if request was successful.\r
+ Points to the most recent '&' before the first failing name/value\r
+ pair (or the beginning of the string if the failure is in the\r
+ first name/value pair) if the request was not successful.\r
+ @param Results A null-terminated Unicode string in <ConfigAltResp> format which\r
+ has all values filled in for the names in the Request string.\r
+ String to be allocated by the called function.\r
+\r
+ @retval EFI_SUCCESS The Results is filled with the requested values.\r
+ @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
+ @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r
+ @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BootManagerExtractConfig (\r
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
+ IN CONST EFI_STRING Request,\r
+ OUT EFI_STRING *Progress,\r
+ OUT EFI_STRING *Results\r
+ )\r
+{\r
+ if (Progress == NULL || Results == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+ *Progress = Request;\r
+ return EFI_NOT_FOUND;\r
+}\r
+\r
+/**\r
+ This function processes the results of changes in configuration.\r
+\r
+\r
+ @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+ @param Configuration A null-terminated Unicode string in <ConfigResp> format.\r
+ @param Progress A pointer to a string filled in with the offset of the most\r
+ recent '&' before the first failing name/value pair (or the\r
+ beginning of the string if the failure is in the first\r
+ name/value pair) or the terminating NULL if all was successful.\r
+\r
+ @retval EFI_SUCCESS The Results is processed successfully.\r
+ @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
+ @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BootManagerRouteConfig (\r
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
+ IN CONST EFI_STRING Configuration,\r
+ OUT EFI_STRING *Progress\r
+ )\r
+{\r
+ if (Configuration == NULL || Progress == NULL) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ *Progress = Configuration;\r
+\r
+ return EFI_NOT_FOUND;\r
+}\r
+\r
+/**\r
+ This call back function is registered with Boot Manager formset.\r
+ When user selects a boot option, this call back function will\r
+ be triggered. The boot option is saved for later processing.\r
+\r
+\r
+ @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+ @param Action Specifies the type of action taken by the browser.\r
+ @param QuestionId A unique value which is sent to the original exporting driver\r
+ so that it can identify the type of data to expect.\r
+ @param Type The type of value for the question.\r
+ @param Value A pointer to the data being sent to the original exporting driver.\r
+ @param ActionRequest On return, points to the action requested by the callback function.\r
+\r
+ @retval EFI_SUCCESS The callback successfully handled the action.\r
+ @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BootManagerCallback (\r
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
+ IN EFI_BROWSER_ACTION Action,\r
+ IN EFI_QUESTION_ID QuestionId,\r
+ IN UINT8 Type,\r
+ IN EFI_IFR_TYPE_VALUE *Value,\r
+ OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
+ )\r
+{\r
+ EFI_BOOT_MANAGER_LOAD_OPTION *BootOption;\r
+ UINTN BootOptionCount;\r
+ EFI_INPUT_KEY Key;\r
+ if (Action != EFI_BROWSER_ACTION_CHANGED) {\r
+ //\r
+ // Do nothing for other UEFI Action. Only do call back when data is changed.\r
+ //\r
+ return EFI_UNSUPPORTED;\r
+ }\r
+\r
+ if ((Value == NULL) || (ActionRequest == NULL)) {\r
+ return EFI_INVALID_PARAMETER;\r
+ }\r
+\r
+ BootOption = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot);\r
+ //\r
+ // parse the selected option\r
+ //\r
+ BmBdsSetConsoleMode (FALSE);\r
+ EfiBootManagerBoot (&BootOption[QuestionId - 1]);\r
+ BmBdsSetConsoleMode (TRUE);\r
+\r
+ if (EFI_ERROR (BootOption[QuestionId - 1].Status)) {\r
+ gST->ConOut->OutputString (\r
+ gST->ConOut,\r
+ HiiGetString (gBootManagerPrivate.HiiHandle, STRING_TOKEN (STR_ANY_KEY_CONTINUE), NULL)\r
+ );\r
+ gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+ }\r
+\r
+ EfiBootManagerFreeLoadOptions (BootOption, BootOptionCount);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+\r
+ Install Boot Manager Menu driver.\r
+\r
+ @param ImageHandle The image handle.\r
+ @param SystemTable The system table.\r
+\r
+ @retval EFI_SUCEESS Install Boot manager menu success.\r
+ @retval Other Return error status.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BootManagerLibConstructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Install Device Path Protocol and Config Access protocol to driver handle\r
+ //\r
+ gBootManagerPrivate.DriverHandle = NULL;\r
+ Status = gBS->InstallMultipleProtocolInterfaces (\r
+ &gBootManagerPrivate.DriverHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ &mBootManagerHiiVendorDevicePath,\r
+ &gEfiHiiConfigAccessProtocolGuid,\r
+ &gBootManagerPrivate.ConfigAccess,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ //\r
+ // Publish our HII data\r
+ //\r
+ gBootManagerPrivate.HiiHandle = HiiAddPackages (\r
+ &mBootManagerGuid,\r
+ gBootManagerPrivate.DriverHandle,\r
+ BootManagerVfrBin,\r
+ BootManagerLibStrings,\r
+ NULL\r
+ );\r
+ ASSERT (gBootManagerPrivate.HiiHandle != NULL);\r
+\r
+ //\r
+ // Update boot manager page \r
+ //\r
+ UpdateBootManager ();\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+ Unloads the application and its installed protocol.\r
+\r
+ @param[in] ImageHandle Handle that identifies the image to be unloaded.\r
+ @param[in] SystemTable System Table\r
+\r
+ @retval EFI_SUCCESS The image has been unloaded.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BootManagerLibDestructor (\r
+ IN EFI_HANDLE ImageHandle,\r
+ IN EFI_SYSTEM_TABLE *SystemTable\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+\r
+ Status = gBS->UninstallMultipleProtocolInterfaces (\r
+ gBootManagerPrivate.DriverHandle,\r
+ &gEfiDevicePathProtocolGuid,\r
+ &mBootManagerHiiVendorDevicePath,\r
+ &gEfiHiiConfigAccessProtocolGuid,\r
+ &gBootManagerPrivate.ConfigAccess,\r
+ NULL\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ HiiRemovePackages (gBootManagerPrivate.HiiHandle);\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
--- /dev/null
+/** @file\r
+ The boot manager reference implement\r
+\r
+ Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.<BR>\r
+ This software and associated documentation (if any) is furnished\r
+ under a license and may only be used or copied in accordance\r
+ with the terms of the license. Except as permitted by such\r
+ license, no part of this software or documentation may be\r
+ reproduced, stored in a retrieval system, or transmitted in any\r
+ form or by any means without the express written consent of\r
+ Intel Corporation.\r
+\r
+**/\r
+\r
+#ifndef _EFI_BOOT_MANAGER_H_\r
+#define _EFI_BOOT_MANAGER_H_\r
+\r
+#include <Guid/MdeModuleHii.h>\r
+#include <Guid/GlobalVariable.h>\r
+\r
+#include <Protocol/HiiConfigAccess.h>\r
+#include <Protocol/DevicePathToText.h>\r
+\r
+#include <Library/PrintLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/UefiBootManagerLib.h>\r
+\r
+#pragma pack(1)\r
+\r
+///\r
+/// HII specific Vendor Device Path definition.\r
+///\r
+typedef struct {\r
+ VENDOR_DEVICE_PATH VendorDevicePath;\r
+ EFI_DEVICE_PATH_PROTOCOL End;\r
+} HII_VENDOR_DEVICE_PATH;\r
+#pragma pack()\r
+\r
+//\r
+// These are defined as the same with vfr file\r
+//\r
+#define BOOT_MANAGER_FORMSET_GUID \\r
+ { \\r
+ 0x847bc3fe, 0xb974, 0x446d, {0x94, 0x49, 0x5a, 0xd5, 0x41, 0x2e, 0x99, 0x3b} \\r
+ }\r
+\r
+#define BOOT_MANAGER_FORM_ID 0x1000\r
+\r
+#define LABEL_BOOT_OPTION 0x00\r
+#define LABEL_BOOT_OPTION_END 0x01\r
+\r
+//\r
+// Variable created with this flag will be "Efi:...."\r
+//\r
+#define VAR_FLAG EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE\r
+\r
+//\r
+// These are the VFR compiler generated data representing our VFR data.\r
+//\r
+extern UINT8 BootManagerVfrBin[];\r
+\r
+#define BOOT_MANAGER_CALLBACK_DATA_SIGNATURE SIGNATURE_32 ('B', 'M', 'C', 'B')\r
+\r
+typedef struct {\r
+ UINTN Signature;\r
+\r
+ //\r
+ // HII relative handles\r
+ //\r
+ EFI_HII_HANDLE HiiHandle;\r
+ EFI_HANDLE DriverHandle;\r
+\r
+ //\r
+ // Produced protocols\r
+ //\r
+ EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;\r
+} BOOT_MANAGER_CALLBACK_DATA;\r
+\r
+/**\r
+ This call back function is registered with Boot Manager formset.\r
+ When user selects a boot option, this call back function will\r
+ be triggered. The boot option is saved for later processing.\r
+\r
+\r
+ @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+ @param Action Specifies the type of action taken by the browser.\r
+ @param QuestionId A unique value which is sent to the original exporting driver\r
+ so that it can identify the type of data to expect.\r
+ @param Type The type of value for the question.\r
+ @param Value A pointer to the data being sent to the original exporting driver.\r
+ @param ActionRequest On return, points to the action requested by the callback function.\r
+\r
+ @retval EFI_SUCCESS The callback successfully handled the action.\r
+ @retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BootManagerCallback (\r
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
+ IN EFI_BROWSER_ACTION Action,\r
+ IN EFI_QUESTION_ID QuestionId,\r
+ IN UINT8 Type,\r
+ IN EFI_IFR_TYPE_VALUE *Value,\r
+ OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
+ );\r
+\r
+/**\r
+ This function allows a caller to extract the current configuration for one\r
+ or more named elements from the target driver.\r
+\r
+\r
+ @param This - Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+ @param Request - A null-terminated Unicode string in <ConfigRequest> format.\r
+ @param Progress - On return, points to a character in the Request string.\r
+ Points to the string's null terminator if request was successful.\r
+ Points to the most recent '&' before the first failing name/value\r
+ pair (or the beginning of the string if the failure is in the\r
+ first name/value pair) if the request was not successful.\r
+ @param Results - A null-terminated Unicode string in <ConfigAltResp> format which\r
+ has all values filled in for the names in the Request string.\r
+ String to be allocated by the called function.\r
+\r
+ @retval EFI_SUCCESS The Results is filled with the requested values.\r
+ @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
+ @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.\r
+ @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BootManagerExtractConfig (\r
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
+ IN CONST EFI_STRING Request,\r
+ OUT EFI_STRING *Progress,\r
+ OUT EFI_STRING *Results\r
+ );\r
+\r
+/**\r
+ This function processes the results of changes in configuration.\r
+\r
+\r
+ @param This - Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
+ @param Configuration - A null-terminated Unicode string in <ConfigResp> format.\r
+ @param Progress - A pointer to a string filled in with the offset of the most\r
+ recent '&' before the first failing name/value pair (or the\r
+ beginning of the string if the failure is in the first\r
+ name/value pair) or the terminating NULL if all was successful.\r
+\r
+ @retval EFI_SUCCESS The Results is processed successfully.\r
+ @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
+ @retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BootManagerRouteConfig (\r
+ IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
+ IN CONST EFI_STRING Configuration,\r
+ OUT EFI_STRING *Progress\r
+ );\r
+\r
+#endif\r