From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 150FA81EE4 for ; Tue, 15 Nov 2016 02:04:28 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP; 15 Nov 2016 02:04:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,494,1473145200"; d="scan'208";a="191573633" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by fmsmga004.fm.intel.com with ESMTP; 15 Nov 2016 02:04:31 -0800 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Jie Lin Date: Tue, 15 Nov 2016 18:04:25 +0800 Message-Id: <20161115100425.299856-4-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20161115100425.299856-1-ruiyu.ni@intel.com> References: <20161115100425.299856-1-ruiyu.ni@intel.com> Subject: [PATCH 3/3] MdeModulePkg/BdsDxe: Avoid overwriting PlatformRecovery#### X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Nov 2016 10:04:28 -0000 Current implementation always creates PlatformRecovery0000 pointing to \EFI\BOOT\BOOT$(ARCH).efi but it may overwrite PlatformRecovery#### created before (maybe by a DXE driver). The patch only uses the smallest unused option number for the \EFI\BOOT\BOOT$(ARCH).efi PlatformRecovery#### to avoid overwriting already-created PlatformRecovery####. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Jie Lin --- MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c index 48e5351..56034f5 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c @@ -834,7 +834,7 @@ BdsEntry ( FilePath = FileDevicePath (NULL, EFI_REMOVABLE_MEDIA_FILE_NAME); Status = EfiBootManagerInitializeLoadOption ( &LoadOption, - 0, + LoadOptionNumberUnassigned, LoadOptionTypePlatformRecovery, LOAD_OPTION_ACTIVE, L"Default PlatformRecovery", @@ -843,9 +843,24 @@ BdsEntry ( 0 ); ASSERT_EFI_ERROR (Status); - EfiBootManagerLoadOptionToVariable (&LoadOption); + LoadOptions = EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOptionTypePlatformRecovery); + if (EfiBootManagerFindLoadOption (&LoadOption, LoadOptions, LoadOptionCount) == -1) { + for (Index = 0; Index < LoadOptionCount; Index++) { + // + // The PlatformRecovery#### options are sorted by OptionNumber. + // Find the the smallest unused number as the new OptionNumber. + // + if (LoadOptions[Index].OptionNumber != Index) { + break; + } + } + LoadOption.OptionNumber = Index; + Status = EfiBootManagerLoadOptionToVariable (&LoadOption); + ASSERT_EFI_ERROR (Status); + } EfiBootManagerFreeLoadOption (&LoadOption); FreePool (FilePath); + EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); // // Report Status Code to indicate connecting drivers will happen -- 2.9.0.windows.1