//*****************************************************************// //*****************************************************************// //*****************************************************************// //** **// //** (C)Copyright 2013, American Megatrends, Inc. **// //** **// //** All Rights Reserved. **// //** **// //** 5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093 **// //** **// //** Phone (770)-246-8600 **// //** **// //*****************************************************************// //*****************************************************************// //*****************************************************************// // $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseLite/AddBootOption.c $ // // $Author: Arunsb $ // // $Revision: 29 $ // // $Date: 5/21/14 6:28p $ // //*****************************************************************// //*****************************************************************// // Revision History // ---------------- // $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseLite/AddBootOption.c $ // // 29 5/21/14 6:28p Arunsb // [TAG] EIP170152 // [Category] Bug Fix // [Severity:] Normal // [Symptom:] Add boot option failed to add the boot option // [Root Cause] If boot order is not there then TSE not allowing to add // boot options // [Solution] If boot order not presents also allowing to add boot option // [Files] AddBootOption.c // // 28 5/02/14 12:56p Premkumara // [TAG] EIP131549 // [Category] Bug Fix // [Severity:] Important // [Symptom:] After adding boot/driver options and Loading defaults causes // crashing issue. // [Root Cause] While discarding boot/driver options the boot order get // corrupted by copying extra data because of wrong size. // [Solution] Handled proper size to copy boot/driver options while // loading defaults // [Files] AddBootOption.c, Special.c // // 27 2/11/14 8:46p Arunsb // // 26 1/30/14 10:58a Arunsb // [TAG] EIP132762 // [Category] Bug Fix // [Severity:] Normal // [Symptom:] Adding UEFI bootable RHEL OS(Bootx64.efi) from UEFI REHL6.4 // DVD disk causes setup hang // [Root Cause] The DevicePath is not created properly while adding boot // options // [Solution] Added '\' before file path name e.g \EFI\Boot\Bootx64.efi // instead of EFI\Boot\Bootx64.efi // [Files] AddBootOption.c // // 25 12/04/13 2:22p Premkumara // [TAG] EIP131549 // [Category] Bug Fix // [Severity:] Important // [Symptom:] After adding boot/driver options and Loading defaults causes // crashing issue. // [Root Cause] While discarding boot/driver options the boot order get // corrupted by copying extra data because of wrong size. // [Solution] Handled proper size to copy boot/driver options while // loading defaults // [Files] AddBootOption.c, Special.c // // 24 5/22/13 10:56a Premkumara // [TAG] EIP123432 // [Category] Bug Fix // [Issue Faced] Take print screen for save & Exit msg box. OK // of msg box is consumed by Save & Exit msg box. // - Cursor is missing after taking print screen of popupedit box in // string control // - Printscreen support is not given for Filebrowser feature // [RootCause] - When msg box for Save&Exit is popped and printscreen // event is called and displaying msg box over Save&Exit. Then msgbox // handleaction for printscreen event will change the result value in // _CallbackMsgbox() function so it will break the while loop in // _CallbackGetValue() function so destroy the next msg box in // CallbackShowMessageBox() function. // - DrawCursor variable is not set to TRUE after printscreen event // [Solution] - Returning EFI_UNSUPPORTED for printscreen event handling // function for messgebox and change the result value to 0xff // - Support given for file browser feature // [Files] Callback.c, MessageBox.c, Minisetupext.c, PopupString.c, // AddBootOption.c // AmiTSEStr.uni, FakeToken.c // // 23 5/22/13 10:51a Arunsb // EfiLibAllocateCopyPool leads to memory crash so changed it to // EfiLibAllocateZeroPool // // 22 4/16/13 12:59p Arunsb // [TAG] EIP113590 // [Category] Bug Fix // [Severity] Normal // [Symptom] Can't load default boot priorities if enable token // "SETUP_SUPPORT_ADD_BOOT_OPTION" // [RootCause] Size calculated wrongly // [Solution] Defaults will be formed only if size is 0, otherwise // current buffer will be overwritten. // [Files] AddBootOption.c // // 21 3/29/13 12:23p Premkumara // [TAG] EIP97611 // [Category] New Feature // [Description] PrintScreen Support in TSE // [Files] AMITSE.sdl, CommonHelper.c, HotKeyBin.h, AddBootOption.c, // Page.c, TseUefiHii.h, Uefi21Wapper.c // // 20 12/01/12 6:46a Premkumara // [TAG] EIP105725 // [Category] Bug Fix // [Severity] Important // [Symptom] Setup hangs on BBS Menu having string more than 200 // characters // [RootCause] File path string is not handled properly // [Solution] Handled FilePath strings based on length of string and // allocate memory based on length dynamically // [Files] AddBootOption.c, AMIVfr.h // // 19 10/18/12 6:02a Arunsb // Updated for 2.16.1235 QA submission // // 15 10/10/12 12:38p Arunsb // Synched the source for v2.16.1232, backup with Aptio // // 18 5/29/12 4:37a Arunsb // [TAG] EIP91109 // [Category] Improvement // [Description] Sync the Aptio IV source for AptioV // // 17 1/24/12 4:37a Arunsb // [TAG] EIP81581 // [Category] Improvement // [Description] Default driver order support // [Files] globals.c, addbootoption.c, callback.c, minisetupext.h and // variable.c // // 16 1/19/12 10:49a Arunsb // [TAG] EIP79956 // [Category] Bug Fix // [Severity] Important // [Symptom] Two boot option entries displayed with the single name // value // [RootCause] If defaults are loaded then boot order is trying to load // the improper boot order due to add boot option feature // [Solution] Boot order formed properly for add boot option case. // If no tsedefaultbootorder module present then gOptimalDefaults // [VARIABLE_ID_BOOT_ORDER] are saved properly in SaveAddDelBootOptions at // first time. // At first time optimal buffer is empty so it was filled with some junk // value so it is changed to fill the current variable list at first time // of saving with add boot option feature. // [Files] Addbootoption.c and callback.c // // 15 1/09/12 1:50a Arunsb // [TAG] EIP79952 // [Category] Bug Fix // [Severity] Normal // [Symptom] Add driver option displays select boot option as title // [RootCause] Title problem // [Solution] Title changes // [Files] Faketokens.c, amitsestr.uni, addbootoption.c, // uefi2.0\hiicallback.c and uefi21wapper.c // // 14 11/30/11 1:34p Premkumara // [TAG] EIP75352 // [Category] Improvement // [Description] Suppress the warnings from static code analyzer // [Files] Boot.c, bbs.c, TseAdvanced.c, Special.c, Variable.c, // TseLiteHelper.c, PopupSel.c, AddBootOption.c, Hii.c, FormBrowser2.c // // 13 11/13/11 12:54p Arunsb // [TAG] EIP70421 // [Category] New Feature // [Description] Support for driver order in TSE // [Files] AMITSE.SDL, CommonHelper.c, setup.ini, uefisetup.ini, // boot.c, // minisetup.h, bbs.c, special.c, special.h, tseadvanced.c, // addbootoption.c, // callback.c, minisetupext.c, minisetupext.h, popupsel.c, popupsel.h, // TseLitehelper.c, variable.c, Uefi21Wapper.c, AMIVfr.h, boot.h, // TseElink.h, variable.h, // setup.h, Boot.vfr and Setup.uni // // 12 1/10/11 3:55p Mallikarjunanv // Updated to work with respect to EDK Libraries // // 11 1/07/11 12:09a Mallikarjunanv // [TAG] EIP51378 // [Description] Global variable gHandleBuffer changed to // gSmplFileSysHndlBuf because of the conflict with HddSecurity module, // which already using gHandleBuffer. // // 10 1/06/11 11:14p Mallikarjunanv // [TAG] EIP41615 // [Description] Updated the files with respect to File Browser support. // // 9 12/28/10 6:20p Mallikarjunanv // [TAG] EIP41615 // [Description] Added the file browser support for the Add boot option // reated controls // [Files] AmiVfr.h, AmiTse.sdl, AmiTseStr.uni, CommonHelper.c, // Faketokens.c, TseElinks.h, EdkHelper.h, minisetup.h, TseAdvanced.c, // AddBootOption.c // // 8 3/26/10 5:25p Madhans // EIP 35562: Support To create Boot option in Capital letters. // // 7 2/26/10 8:54p Madhans // For TSE 2.01.1024. refer changelog.log for file checkin history . // // 11 2/25/10 8:04a Mallikarjunanv // Updated the memory corruptions in case of add delete boot options // // 10 2/19/10 8:19a Mallikarjunanv // updated year in copyright message // // 9 1/28/10 1:10p Mallikarjunanv // //EIP:34119 - Fix to solve issues, if the boot option name is set with // max number of characters allowed. // // 8 1/09/10 7:12a Mallikarjunanv // Updated TSE2.01 Release sources with coding standards // // 7 1/04/10 10:40a Mallikarjunanv // EIPs 27161/29095 - Added support for reserved boot option names and // added support not to create empty boot option names // // 6 12/18/09 2:27p Madhans // EIP: 32350/32445 To fix the Add/Delete Boot option issues with TSE 2.0. // // 5 8/18/09 5:34p Madhans // EIP 25367: To resolve the build issue and to avoid redefinition. // // 4 8/13/09 7:39a Mallikarjunanv // eip:24971 - supporting tse features without tse sources // // 3 6/23/09 6:52p Blaines // Coding standard update, // Remove spaces from file header to allow proper chm function list // creation. // // 2 6/12/09 7:44p Presannar // Initial implementation of coding standards for AMITSE2.0 // // 1 6/04/09 8:05p Madhans // // 2 4/29/09 9:02p Madhans // Bug Fixes after unit Testing.. // // 1 4/28/09 11:04p Madhans // Tse 2.0 Code complete Checkin. // // 1 4/28/09 9:39p Madhans // Tse 2.0 Code complete Checkin. // // 1 12/18/08 7:59p Madhans // Intial version of TSE Lite sources // // //*****************************************************************// //*****************************************************************// // //---------------------------------------------------------------------------- // // Name: AddBootOption.c // // Description: This file contains code to handle the Add boot option operation. // //---------------------------------------------------------------------------- // #include "minisetup.h" /////////////////////////////////////////////////////// /// MACRO DEFINITIONS /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// /// VARIABLE DECLARATIONS /////////////////////////////////////////////////////// typedef struct// EIP-41615: Start { UINT64 Type; UINTN Size; CHAR16 *Name; STRING_REF Token; } FILE_TYPE; EFI_FILE_PROTOCOL *gFs = NULL; EFI_GUID gSimpleFileSystemGuid = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID; AMI_POST_MANAGER_PROTOCOL *mPostMgr = NULL; static EFI_HANDLE *gSmplFileSysHndlBuf = NULL; //EIP:51378 Global variable gHandleBuffer changed to gSmplFileSysHndlBuf because of the conflict with HddSecurity module, which already using gHandleBuffer. BOOLEAN gValidOption = FALSE; UINT16 gSelIdx = 0;/// EIP-41615: End UINTN gDelOptionCount; BOOT_DATA *gDelBootData; UINTN gFsCount; FS_DATA *gFsList; UINTN gDriverDelOptionCount; //EIP70421 & 70422 Support for driver order BOOT_DATA *gDelDriverData; //EIP70421 & 70422 Support for driver order /////////////////////////////////////////////////////// /// EXTERN VARIABLES /////////////////////////////////////////////////////// extern UINTN gDelBootOptionReserved; extern UINTN gAddBootOptionEmpty; extern UINTN gAddDriverOptionEmpty; /////////////////////////////////////////////////////// /// FUNCTION DECLARATIONS /////////////////////////////////////////////////////// EFI_DEVICE_PATH_PROTOCOL *_BootBuildFileDevicePath( UINT32 *index, CHAR16 *fileName ); VOID BbsStrnCpy ( CHAR16 *Dst, CHAR16 *Src, UINTN Length ); VOID _GetFsLists (VOID); UINT16 *_DevicePathToStr(EFI_DEVICE_PATH_PROTOCOL *Path); VOID FixHiddenOptions (BOOLEAN, UINT16 **, UINTN); UINT16 _BootSetBootNowCount(VOID); EFI_STATUS ShowPostMsgBox(IN CHAR16 *MsgBoxTitle,IN CHAR16 *Message,IN UINT8 MsgBoxType, UINT8 *pSelection);//EIP:41615 EFI_STATUS FileBrowserLaunchFilePath(UINT32 Variable); // //---------------------------------------------------------------------------- // Procedure: TseUpdateAddDeleteBootVar // // Description: Function to update add and delete boot variables // // Input: None // // Output: None // //---------------------------------------------------------------------------- // void TseUpdateAddDeleteBootVar(void) { UINT16 u16DelOption; EFI_GUID DelBootOptionGuid = DEL_BOOT_OPTION_GUID; EFI_GUID AddBootOptionGuid = ADD_BOOT_OPTION_GUID; NEW_BOOT_OPTION AddBootOption; //Set del boot option var u16DelOption = DISABLED_BOOT_OPTION; VarSetNvramName( L"DelBootOption", &DelBootOptionGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS, &u16DelOption, sizeof(UINT16) ); //Set AddBootOption variable _GetFsLists (); MemSet(&AddBootOption, sizeof(NEW_BOOT_OPTION),0); AddBootOption.FsCount = (UINT16)gFsCount; VarSetNvramName( L"AddBootOption", &AddBootOptionGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS, &AddBootOption, sizeof(NEW_BOOT_OPTION) ); } //EIP70421 & 70422 Support for driver order // //---------------------------------------------------------------------------- // Procedure: TseUpdateAddDeleteDriverVar // // Description: Function to update add and delete driver variables // // Input: None // // Output: None // //---------------------------------------------------------------------------- // void TseUpdateAddDeleteDriverVar (void) { UINT16 u16DelOption; EFI_GUID DelDriverOptionGuid = DEL_DRIVER_OPTION_GUID; EFI_GUID AddDriverOptionGuid = ADD_DRIVER_OPTION_GUID; NEW_DRIVER_OPTION AddDriverOption; //Set del driver option var u16DelOption = DISABLED_DRIVER_OPTION; VarSetNvramName (L"DelDriverOption", &DelDriverOptionGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS, &u16DelOption, sizeof (UINT16)); //Set AddDriverOption variable _GetFsLists(); MemSet (&AddDriverOption, sizeof (NEW_DRIVER_OPTION), 0); AddDriverOption.FsCount = (UINT16)gFsCount; VarSetNvramName (L"AddDriverOption", &AddDriverOptionGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS, &AddDriverOption, sizeof (NEW_DRIVER_OPTION)); } // //---------------------------------------------------------------------------- // Procedure: _GetFsLists // // Description: function to get the file system details // // Input: None // // Output: None // //---------------------------------------------------------------------------- // VOID _GetFsLists (VOID) { UINTN Count,i; EFI_HANDLE *HandleBuffer; EFI_DEVICE_PATH_PROTOCOL *DevicePath; CHAR16 *Str; EFI_STATUS Status; //Find all handles supporting Simple File Sys Protocol if (0 == gFsCount) //EIP70421 Support for driver order; No need of calling continuously boot then driver, one call is enough to set gFsCount { Status = gBS->LocateHandleBuffer( ByProtocol, &gEfiSimpleFileSystemProtocolGuid, NULL, &Count, &HandleBuffer ); if(EFI_ERROR(Status)) return; for(i=0;iOpenProtocol ( HandleBuffer[i], &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath, NULL, HandleBuffer[i], EFI_OPEN_PROTOCOL_GET_PROTOCOL ); if(EFI_ERROR(Status)) continue; if(!DevicePath) continue; Str = NULL; Str = _DevicePathToStr(DevicePath); gFsList = MemReallocateZeroPool(gFsList, gFsCount * sizeof(FS_DATA), (gFsCount + 1) * sizeof(FS_DATA)); gFsList[gFsCount].FsId = Str ? Str : StrDup(L"Unknown"); gFsList[gFsCount].FsPath = DevicePath; gFsCount++; } } } static UINT16 DefaultDevicePath[]=L"DevicePath(Type %x, SubType %x)"; static UINT16 *HWDP[] = { L"PCI(%X|%X)\\", //HW_PCI_DP L"Pccard(Socket %x)\\", //HW_PCCARD_DP L"VenHw(%g)\\" //HW_VENDOR_DP }; /*Uncomment if ACPI details are necessary static UINT16 *ACPIDP[] = { L"Acpi(%x, %x)\\" //ACPI_DP };*/ static UINT16 *MSGDP[] = { L"ATA(%s,%s)\\", //MSG_ATAPI_DP L"SCSI(%x,%x)\\", //MSG_SCSI_DP L"VenMsg(%g)\\" //MSG_VENDOR_DP }; static UINT16 *MEDIADP[] = { L"CDROM(Entry%x)\\", //MEDIA_CDROM_DP L"VenMedia(%g)\\", //MEDIA_VENDOR_DP L"%g\\" //MEDIA_FILEPATH_DP }; // //---------------------------------------------------------------------------- // Procedure: _HWToStr // // Description: Convert Device Path of type to string. // // Input: // IN EFI_DEVICE_PATH_PROTOCOL *Path - Device Path // OUT UINT16 *Str - String form of device path. // // Output: // int - number of characters not including \0 or -1 if error. // // Notes: // //---------------------------------------------------------------------------- // UINTN _HWToStr( EFI_DEVICE_PATH_PROTOCOL *Path, UINT16 *Str ) { switch(Path->SubType) { case HW_PCI_DP: return SPrint(Str,0,HWDP[0],((PCI_DEVICE_PATH*)Path)->Device,((PCI_DEVICE_PATH*)Path)->Function); case HW_PCCARD_DP: return SPrint(Str,0,HWDP[1],((AMITSE_PCCARD_DEVICE_PATH*)Path)->FunctionNumber); case HW_VENDOR_DP: return SPrint(Str,0,HWDP[2],&((VENDOR_DEVICE_PATH*)Path)->Guid); } return SPrint(Str,0,DefaultDevicePath,Path->Type,Path->SubType); } // //---------------------------------------------------------------------------- // Procedure: ACPIToStr // // Description: Convert Device Path of type to string. // // Input: // IN EFI_DEVICE_PATH_PROTOCOL *Path - Device Path // OUT UINT16 *Str - String form of device path. // // Output: // int - number of characters not including \0 or -1 if error. // // Notes: // //---------------------------------------------------------------------------- // /* Uncomment below code if ACPI details are necessary. CAUTION: If ACPI details are included then the string becomes too big to display */ /* UINTN ACPIToStr( EFI_DEVICE_PATH_PROTOCOL *Path, UINT16 *Str ) { switch(Path->SubType) { case ACPI_DP: return SPrint(Str,0,ACPIDP[0], ((ACPI_HID_DEVICE_PATH*)Path)->HID, ((ACPI_HID_DEVICE_PATH*)Path)->UID); } return SPrint(Str,0,DefaultDevicePath,Path->Type,Path->SubType); } */ // //---------------------------------------------------------------------------- // Procedure: _MSGToStr // // Description: Convert Device Path of type to string. // // Input: // IN EFI_DEVICE_PATH_PROTOCOL *Path - Device Path // OUT UINT16 *Str - String form of device path. // // Output: // int - number of characters not including \0 or -1 if error. // // Notes: // //---------------------------------------------------------------------------- // UINTN _MSGToStr( EFI_DEVICE_PATH_PROTOCOL *Path, UINT16 *Str ) { switch(Path->SubType) { case MSG_ATAPI_DP: return SPrint(Str,0,MSGDP[0], ((ATAPI_DEVICE_PATH*)Path)->PrimarySecondary ? L"Sec" : L"Pri", ((ATAPI_DEVICE_PATH*)Path)->SlaveMaster ? L"Sl" :L"Ma"); case MSG_SCSI_DP: return SPrint(Str,0,MSGDP[1], ((SCSI_DEVICE_PATH*)Path)->Pun, ((SCSI_DEVICE_PATH*)Path)->Lun); case MSG_VENDOR_DP: return SPrint(Str,0,MSGDP[2], ((VENDOR_DEVICE_PATH*)Path)->Guid); case MSG_USB_DP: return SPrint(Str,0,L"USB(%x,%x)\\", ((USB_DEVICE_PATH*)Path)->ParentPortNumber,((USB_DEVICE_PATH*)Path)->InterfaceNumber); } return SPrint(Str,0,DefaultDevicePath,Path->Type,Path->SubType); } // //---------------------------------------------------------------------------- // Procedure: _MEDIAToStr // // Description: Convert Device Path of type to string. // // Input: // IN EFI_DEVICE_PATH_PROTOCOL *Path - Device Path // OUT UINT16 *Str - String form of device path. // // Output: // int - number of characters not including \0 or -1 if error. // // Notes: // //---------------------------------------------------------------------------- // UINTN _MEDIAToStr( EFI_DEVICE_PATH_PROTOCOL *Path, UINT16 *Str ) { switch(Path->SubType) { case MEDIA_HARDDRIVE_DP: { HARDDRIVE_DEVICE_PATH *Hd = (HARDDRIVE_DEVICE_PATH *)Path; switch(Hd->SignatureType) { case SIGNATURE_TYPE_MBR: return SPrint(Str,0,L"HD(Part%d,Sig%08X)", Hd->PartitionNumber, *((UINT32 *)(&(Hd->Signature[0])))); case SIGNATURE_TYPE_GUID: return SPrint(Str,0, L"HD(Part%d,Sig%g)", Hd->PartitionNumber, (EFI_GUID *) &(Hd->Signature[0])); default: return SPrint(Str,0,L"HD(Part%d,MBRType=%02x,SigType=%02x)", Hd->PartitionNumber, Hd->MBRType, Hd->SignatureType ); } } case MEDIA_CDROM_DP: return SPrint(Str,0,MEDIADP[0], ((CDROM_DEVICE_PATH*)Path)->BootEntry); case MEDIA_VENDOR_DP: return SPrint(Str,0,MEDIADP[1], ((VENDOR_DEVICE_PATH*)Path)->Guid); case MEDIA_FILEPATH_DP: return SPrint(Str,0,MEDIADP[2], &((AMITSE_MEDIA_FW_VOL_FILEPATH_DEVICE_PATH*)Path)->FvFileName); } return SPrint(Str,0,DefaultDevicePath,Path->Type,Path->SubType); } // //---------------------------------------------------------------------------- // Procedure: _UnknownToStr // // Description: Convert Device Path of type to string. // // Input: // IN EFI_DEVICE_PATH_PROTOCOL *Path - Device Path // OUT UINT16 *Str - String form of device path. // // Output: // int - number of characters not including \0 or -1 if error. // // Notes: // //---------------------------------------------------------------------------- // UINTN _UnknownToStr( EFI_DEVICE_PATH_PROTOCOL *Path, UINT16 *Str ) { return SPrint(Str,0,DefaultDevicePath,Path->Type,Path->SubType); } // //---------------------------------------------------------------------------- // Procedure: _DevicePathToStr // // Description: Convert Device Path of type to string. Str is allocated by // this routine. It must be freed by the caller. // // Input: // IN EFI_DEVICE_PATH_PROTOCOL *Path - Device Path // // // Output: // OUT UINT16 *Str - String form of device path. // // Notes: // //---------------------------------------------------------------------------- // UINT16 *_DevicePathToStr(EFI_DEVICE_PATH_PROTOCOL *Path) { CHAR16 Buffer[512]; CHAR16 *p = Buffer, *Str = NULL; UINTN Count = 0; UINTN Length; MemSet(Buffer,sizeof(Buffer),0); for(;;) { switch(Path->Type) { case HARDWARE_DEVICE_PATH: Count = _HWToStr(Path, p); break; case ACPI_DEVICE_PATH: /* Uncomment below code if ACPI details are necessary. CAUTION: If ACPI details are included then the string becomes too big to display */ /* Count = SPrint(p,0,L"Acpi\\"); ACPIToStr(Path, p); */ break; case MESSAGING_DEVICE_PATH: Count = _MSGToStr(Path, p); break; case MEDIA_DEVICE_PATH: Count = _MEDIAToStr(Path, p); break; case END_DEVICE_PATH_TYPE: Count = 0; break; case END_ENTIRE_DEVICE_PATH_SUBTYPE: *p = L'|'; *(p+1) = L'\0'; Count = 1; break; default: Count = _UnknownToStr(Path, p); } p += EfiStrLen(p); if (Count == -1) return NULL; if (IsDevicePathEnd(Path)) break; Path = NextDevicePathNode(Path); } Length = (UINTN)p - (UINTN)Buffer; Str = (UINT16 *)EfiLibAllocateZeroPool(Length+sizeof(UINT16)); MemCopy(Str, Buffer, Length); return Str; } //EIP70421 & 70422 Support for driver order // //-------------------------------------------------------------------------------------------- // Procedure: _DisableRestorePrevOptions // // Description: Function to make the boot/driver option as disable in bootorder/driverorder // if it is inactive and non hidden // // // Input: BOOLEAN , UINT16 **, UINTN // // Output: VOID // //------------------------------------------------------------------------------------------- // VOID _DisableRestorePrevOptions (BOOLEAN Option, UINT16 **Order, UINTN OptionCount) { UINTN iIndex = 0; BOOT_DATA *pBootData; if (0 == OptionCount) { return; } for (iIndex = 0; iIndex < OptionCount; iIndex ++) { if (BOOT_ORDER_OPTION == Option) { pBootData = BootGetBootData ((*Order) [iIndex]); } else { pBootData = DriverGetDriverData ((*Order) [iIndex]); } if (pBootData) { if ( (!(pBootData->Active & LOAD_OPTION_ACTIVE)) && (!(pBootData->Active & LOAD_OPTION_HIDDEN)) ) { (*Order) [iIndex] = DISABLED_BOOT_OPTION; } } } } // //---------------------------------------------------------------------------- // Procedure: BootAddBootOption // // Description: Function to add boot option // // Input: VOID // // Output: VOID // //---------------------------------------------------------------------------- // VOID BootAddBootOption( VOID ) { UINTN i,size; UINT16 u16Option; NEW_BOOT_OPTION *newBoot = NULL, *tmpPtr; CHAR16 *fileName; UINT32 index; EFI_DEVICE_PATH_PROTOCOL *devicePath; UINT16 *NewBootOrder = NULL, *CurrBootOrder = NULL; UINT16 BootCountVal; CHAR16 *BootNameBuf = NULL; //EIP:34119 EFI_STATUS Status; //Get input size = 0; Status = gBS->LocateProtocol(&gAmiPostManagerProtocolGuid, NULL,(void**) &mPostMgr); if(Status != EFI_SUCCESS) return; newBoot = VarGetVariable( VARIABLE_ID_ADD_BOOT_OPTION, &size ); //EIP-75352 Suppress the warnings from static code analyzer if (NULL == newBoot){ return; } //EIP:34119 - Start //Fix EIP:29095 - not to create boot option with out a name if (( EfiStrLen( newBoot->Path ) == 0 ) || ( EfiStrLen(newBoot->Label) == 0 )) { // CallbackShowMessageBox( (UINTN)gAddBootOptionEmpty, MSGBOX_TYPE_OK ); mPostMgr->DisplayMsgBox( L"WARNING", L"Please set Boot Option Name and File Path", MSGBOX_TYPE_OK,NULL); return; } BootNameBuf = EfiLibAllocateZeroPool( sizeof(newBoot->Label)+2 ); BbsStrnCpy( BootNameBuf, newBoot->Label, (sizeof(newBoot->Label))/2 ); //EIP:34119 - End // cleanup old data tmpPtr = EfiLibAllocateZeroPool( size ); tmpPtr->FsCount = (UINT16)gFsCount; VarSetValue( VARIABLE_ID_ADD_BOOT_OPTION, 0, size, tmpPtr ); MemFreePointer( (VOID **)&tmpPtr ); fileName = newBoot->Path; index = newBoot->SelFs; devicePath = _BootBuildFileDevicePath( &index, fileName ); if ( devicePath != NULL ) { EFI_DEVICE_PATH_PROTOCOL *TmpDevPath, *HddMediaPath; //Find a free option number for ( u16Option = 0; u16Option < MAX_BOOT_OPTIONS; u16Option++ ) { for(i=0;iLabel ); gBootData[gBootOptionCount].Name = BootNameBuf; //EIP:34119 - End //For a hard drive start the dev path from the partition for( TmpDevPath = devicePath; !IsDevicePathEndType(TmpDevPath); TmpDevPath=NextDevicePathNode(TmpDevPath) ) { if(TmpDevPath->Type==MEDIA_DEVICE_PATH && TmpDevPath->SubType==MEDIA_HARDDRIVE_DP) { HddMediaPath = EfiLibAllocateZeroPool(EfiDevicePathSize(TmpDevPath)); MemCopy(HddMediaPath, TmpDevPath, EfiDevicePathSize(TmpDevPath)); MemFreePointer((VOID **)&devicePath); devicePath = HddMediaPath; break; } } gBootData[gBootOptionCount].DevicePath = devicePath; gBootData[gBootOptionCount].bNewOption = TRUE; size = 0; CurrBootOrder = VarGetVariable(VARIABLE_ID_BOOT_ORDER, &size); //EIP-75352 Suppress the warnings from static code analyzer /* if (NULL == CurrBootOrder){ //If file system available and no boot option presents then add boot option always fails so commenting it. return; }*/ NewBootOrder = EfiLibAllocateZeroPool((gBootOptionCount+1) * sizeof(UINT16)); for(i=0;i