From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 BA82281D6E for ; Thu, 3 Nov 2016 17:59:46 -0700 (PDT) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP; 03 Nov 2016 17:59:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,589,1473145200"; d="scan'208";a="187427164" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.25]) by fmsmga004.fm.intel.com with ESMTP; 03 Nov 2016 17:59:47 -0700 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Liming Gao , Chao B Zhang Date: Fri, 4 Nov 2016 08:59:41 +0800 Message-Id: <20161104005942.345832-4-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.9.0.windows.1 In-Reply-To: <20161104005942.345832-1-ruiyu.ni@intel.com> References: <20161104005942.345832-1-ruiyu.ni@intel.com> Subject: [PATCH 3/4] MdeModulePkg/BdsDxe: Check deferred images before booting to OS 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: Fri, 04 Nov 2016 00:59:46 -0000 The patch adds check of deferred images before booting to OS. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Cc: Liming Gao Cc: Chao B Zhang --- MdeModulePkg/Universal/BdsDxe/Bds.h | 4 +- MdeModulePkg/Universal/BdsDxe/BdsDxe.inf | 2 + MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 89 ++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Universal/BdsDxe/Bds.h b/MdeModulePkg/Universal/BdsDxe/Bds.h index d243932..1f8a192 100644 --- a/MdeModulePkg/Universal/BdsDxe/Bds.h +++ b/MdeModulePkg/Universal/BdsDxe/Bds.h @@ -1,7 +1,7 @@ /** @file Head file for BDS Architectural Protocol implementation -Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -20,10 +20,12 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include #include +#include #include #include diff --git a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf index e03cfde..a00b442 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf +++ b/MdeModulePkg/Universal/BdsDxe/BdsDxe.inf @@ -79,11 +79,13 @@ [Guids] gConnectConInEventGuid ## SOMETIMES_CONSUMES ## Event gEdkiiStatusCodeDataTypeVariableGuid ## SOMETIMES_CONSUMES ## GUID gPerformanceProtocolGuid ## SOMETIMES_PRODUCES ## Variable:L"PerfDataMemAddr" (The ACPI address of performance data) + gEfiEventReadyToBootGuid ## CONSUMES ## Event [Protocols] gEfiBdsArchProtocolGuid ## PRODUCES gEfiSimpleTextInputExProtocolGuid ## CONSUMES gEdkiiVariableLockProtocolGuid ## CONSUMES + gEfiDeferredImageLoadProtocolGuid ## CONSUMES [FeaturePcd] gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultLangDeprecate ## CONSUMES diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c index aacc4a6..ffa884a 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c @@ -86,7 +86,83 @@ BdsDxeOnConnectConInCallBack ( DEBUG ((EFI_D_WARN, "[Bds] Connect ConIn failed - %r!!!\n", Status)); } } +/** + Notify function for event group EFI_EVENT_GROUP_READY_TO_BOOT. This is used to + check whether there is remaining deferred load images. + + @param[in] Event The Event that is being processed. + @param[in] Context The Event Context. + +**/ +VOID +EFIAPI +CheckDeferredLoadImageOnReadyToBoot ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + EFI_DEFERRED_IMAGE_LOAD_PROTOCOL *DeferredImage; + UINTN HandleCount; + EFI_HANDLE *Handles; + UINTN Index; + UINTN ImageIndex; + EFI_DEVICE_PATH_PROTOCOL *ImageDevicePath; + VOID *Image; + UINTN ImageSize; + BOOLEAN BootOption; + + // + // Find all the deferred image load protocols. + // + HandleCount = 0; + Handles = NULL; + Status = gBS->LocateHandleBuffer ( + ByProtocol, + &gEfiDeferredImageLoadProtocolGuid, + NULL, + &HandleCount, + &Handles + ); + if (EFI_ERROR (Status)) { + return; + } + + for (Index = 0; Index < HandleCount; Index++) { + Status = gBS->HandleProtocol (Handles[Index], &gEfiDeferredImageLoadProtocolGuid, (VOID **) &DeferredImage); + if (EFI_ERROR (Status)) { + continue; + } + for (ImageIndex = 0; ; ImageIndex++) { + // + // Load all the deferred images in this protocol instance. + // + Status = DeferredImage->GetImageInfo ( + DeferredImage, + ImageIndex, + &ImageDevicePath, + (VOID **) &Image, + &ImageSize, + &BootOption + ); + if (EFI_ERROR (Status)) { + break; + } + DEBUG_CODE ( + CHAR16 *DevicePathStr; + DevicePathStr = ConvertDevicePathToText (ImageDevicePath, FALSE, FALSE); + DEBUG ((DEBUG_LOAD, "[Bds] Image was deferred but not loaded: %s.\n", DevicePathStr)); + if (DevicePathStr != NULL) { + FreePool (DevicePathStr); + } + ); + } + } + if (Handles != NULL) { + FreePool (Handles); + } +} /** Install Boot Device Selection Protocol @@ -108,6 +184,7 @@ BdsInitialize ( { EFI_STATUS Status; EFI_HANDLE Handle; + EFI_EVENT Event; // // Install protocol interface // @@ -119,6 +196,18 @@ BdsInitialize ( ); ASSERT_EFI_ERROR (Status); + // + // Register notify function to check deferred images on ReadyToBoot Event. + // + Status = gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + CheckDeferredLoadImageOnReadyToBoot, + NULL, + &gEfiEventReadyToBootGuid, + &Event + ); + ASSERT_EFI_ERROR (Status); return Status; } -- 2.9.0.windows.1