From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: zhiguang.liu@intel.com) Received: from mga11.intel.com (mga11.intel.com []) by groups.io with SMTP; Sun, 28 Apr 2019 22:25:40 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Apr 2019 22:25:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,408,1549958400"; d="scan'208";a="341695427" Received: from fieedk002.ccr.corp.intel.com ([10.239.157.133]) by fmsmga006.fm.intel.com with ESMTP; 28 Apr 2019 22:25:39 -0700 From: "Zhiguang Liu" To: devel@edk2.groups.io Cc: Jordan Justen , Andrew Fish , Ray Ni Subject: [PATCH 2/2] EmulatorPkg: Save the modified order after rebooting Date: Mon, 29 Apr 2019 13:24:43 +0800 Message-Id: <20190429052443.2908-3-zhiguang.liu@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190429052443.2908-1-zhiguang.liu@intel.com> References: <20190429052443.2908-1-zhiguang.liu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit REF:https://bugzilla.tianocore.org/show_bug.cgi?id=1650 The reason why boot order changed is that everytime Emulator restarts, the memory mapped address will change. This patch correct the device path to the right one. Signed-off-by: Zhiguang Liu Cc: Jordan Justen Cc: Andrew Fish Cc: Ray Ni --- EmulatorPkg/Library/PlatformBmLib/PlatformBm.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/EmulatorPkg/Library/PlatformBmLib/PlatformBm.c b/EmulatorPkg/Library/PlatformBmLib/PlatformBm.c index 191ce58cfb..28329e4f52 100644 --- a/EmulatorPkg/Library/PlatformBmLib/PlatformBm.c +++ b/EmulatorPkg/Library/PlatformBmLib/PlatformBm.c @@ -332,6 +332,63 @@ PlatformBdsRegisterStaticBootOptions ( PrintXY (10, 50, &White, &Black, L"Enter to boot directly."); } +/** + Change the device path of the boot options to the correct one. + and return whether it is the first time to start up emulator since last build. + @param FirstBoot Return 1 if it is the first time to start up emulator since last build. +**/ +VOID +EFIAPI +PlatformBootManagerChangeDevicePath ( + OUT UINTN *FirstBoot + ) +{ + UINTN BootOptionCount; + EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; + UINTN Index,LastIndex; + UINTN Flag=0; + *FirstBoot=1; + BootOptions = EfiBootManagerGetLoadOptions (&BootOptionCount, LoadOptionTypeBoot); + for (Index = 0; Index < BootOptionCount; Index++) + { + if ((!StrCmp(L"UEFI Enter Setup", BootOptions[Index].Description)) || + (!StrCmp(L"UEFI BootManagerMenuApp", BootOptions[Index].Description)) || + (!StrCmp(L"UEFI Shell", BootOptions[Index].Description))) + { + EFI_DEVICE_PATH_PROTOCOL *mypath; + EFI_DEVICE_PATH_PROTOCOL *mynextnode; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + gBS->HandleProtocol( + gImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **)&LoadedImage); + mynextnode = NextDevicePathNode(BootOptions[Index].FilePath); + mypath = DevicePathFromHandle(LoadedImage->DeviceHandle); + while (!IsDevicePathEndType(mynextnode)) + { + mypath = AppendDevicePathNode( + mypath, + mynextnode); + mynextnode = NextDevicePathNode(mynextnode); + } + BootOptions[Index].FilePath = DuplicateDevicePath(mypath); + FreePool(mypath); + EfiBootManagerLoadOptionToVariable(&BootOptions[Index]); + if(!StrCmp(L"UEFI Enter Setup", BootOptions[Index].Description)){ + if (Flag!=0){ + EfiBootManagerDeleteLoadOptionVariable(BootOptions[LastIndex].OptionNumber, LoadOptionTypeBoot); + } + Flag++; + LastIndex=Index; + } + if(!StrCmp(L"UEFI Shell", BootOptions[Index].Description)){ + *FirstBoot=0; + } + + } + } +} + /** Do the platform specific action after the console is connected. @@ -348,7 +405,7 @@ PlatformBootManagerAfterConsole ( VOID ) { - + UINTN FirstBoot=1; // // Go the different platform policy with different boot mode // Notes: this part code can be change with the table policy @@ -374,9 +431,10 @@ PlatformBootManagerAfterConsole ( case BOOT_WITH_DEFAULT_SETTINGS: default: PlatformBdsDiagnostics (IGNORE, TRUE); - PlatformBdsRegisterStaticBootOptions (); + PlatformBootManagerChangeDevicePath(&FirstBoot); PlatformBdsConnectSequence (); EfiBootManagerRefreshAllBootOption (); + PlatformBdsRegisterStaticBootOptions (); break; } } -- 2.21.0.windows.1