From nobody Thu May 2 07:57:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511395140618558.9807347833045; Wed, 22 Nov 2017 15:59:00 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 415412035A7C6; Wed, 22 Nov 2017 15:54:42 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 EF96C2034C5E7 for ; Wed, 22 Nov 2017 15:54:39 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 726EC5AFED; Wed, 22 Nov 2017 23:58:56 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-45.rdu2.redhat.com [10.10.120.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id EB7F14A1; Wed, 22 Nov 2017 23:58:54 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Nov 2017 00:58:45 +0100 Message-Id: <20171122235849.4177-2-lersek@redhat.com> In-Reply-To: <20171122235849.4177-1-lersek@redhat.com> References: <20171122235849.4177-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 22 Nov 2017 23:58:56 +0000 (UTC) Subject: [edk2] [PATCH 1/5] MdeModulePkg/BdsDxe: fall back to a Boot Manager Menu loop before hanging X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Jordan Justen , Eric Dong , Star Zeng , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Under the following scenario: - no UEFI bootable application available anywhere in the system, - ... not even for the default platform recovery option, - no shell is built into the firmware image, - but UiApp is available in the firmware image, we should preferably not just hang in BdsEntry() with: DEBUG ((EFI_D_ERROR, "[Bds] Unable to boot!\n")); CpuDeadLoop (); while the user sits at the TianoCore logo page, wondering what's going on. Print an informative message to the console, wait for a keypress, and then return to the Boot Manager Menu forever. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Ruiyu Ni Cc: Eric Dong Cc: Star Zeng Ref: https://bugzilla.redhat.com/show_bug.cgi?id=3D1515418 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D513 Suggested-by: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Ruiyu Ni --- MdeModulePkg/Universal/BdsDxe/BdsEntry.c | 60 ++++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c b/MdeModulePkg/Univer= sal/BdsDxe/BdsEntry.c index dccc49090219..2b24755ac368 100644 --- a/MdeModulePkg/Universal/BdsDxe/BdsEntry.c +++ b/MdeModulePkg/Universal/BdsDxe/BdsEntry.c @@ -676,24 +676,73 @@ BdsAllocateMemoryForPerformanceData ( // // Mark L"PerfDataMemAddr" variable to read-only if the Variable Lock = protocol exists // Still lock it even the variable cannot be saved to prevent it's set= by 3rd party code. // Status =3D gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL,= (VOID **) &VariableLock); if (!EFI_ERROR (Status)) { Status =3D VariableLock->RequestToLock (VariableLock, L"PerfDataMemA= ddr", &gPerformanceProtocolGuid); ASSERT_EFI_ERROR (Status); } } } =20 +/** + Enter an infinite loop of calling the Boot Manager Menu. + + This is a last resort alternative to BdsEntry() giving up for good. This + function never returns. + + @param[in] BootManagerMenu The EFI_BOOT_MANAGER_LOAD_OPTION located and= /or + created by the EfiBootManagerGetBootManagerM= enu() + call in BdsEntry(). +**/ +VOID +BdsBootManagerMenuLoop ( + IN EFI_BOOT_MANAGER_LOAD_OPTION *BootManagerMenu + ) +{ + EFI_INPUT_KEY Key; + + // + // Normally BdsDxe does not print anything to the system console, but th= is is + // a last resort -- the end-user will likely not see any DEBUG messages + // logged in this situation. + // + // AsciiPrint() will NULL-check gST->ConOut internally. We check gST->Co= nIn + // here to see if it makes sense to request and wait for a keypress. + // + if (gST->ConIn !=3D NULL) { + AsciiPrint ( + "%a: No bootable option or device was found.\n" + "%a: Press any key to enter the Boot Manager Menu.\n", + gEfiCallerBaseName, + gEfiCallerBaseName + ); + BdsWaitForSingleEvent (gST->ConIn->WaitForKey, 0); + + // + // Drain any queued keys. + // + while (!EFI_ERROR (gST->ConIn->ReadKeyStroke (gST->ConIn, &Key))) { + // + // just throw away Key + // + } + } + + for (;;) { + EfiBootManagerBoot (BootManagerMenu); + } +} + /** =20 Service routine for BdsInstance->Entry(). Devices are connected, the consoles are initialized, and the boot options are tried. =20 @param This Protocol Instance structure. =20 **/ VOID EFIAPI BdsEntry ( IN EFI_BDS_ARCH_PROTOCOL *This @@ -1079,34 +1128,37 @@ BdsEntry ( } =20 do { // // Retry to boot if any of the boot succeeds // LoadOptions =3D EfiBootManagerGetLoadOptions (&LoadOptionCount, Load= OptionTypeBoot); BootSuccess =3D BootBootOptions (LoadOptions, LoadOptionCount, (Boot= ManagerMenuStatus !=3D EFI_NOT_FOUND) ? &BootManagerMenu : NULL); EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); } while (BootSuccess); } =20 - if (BootManagerMenuStatus !=3D EFI_NOT_FOUND) { - EfiBootManagerFreeLoadOption (&BootManagerMenu); - } - if (!BootSuccess) { LoadOptions =3D EfiBootManagerGetLoadOptions (&LoadOptionCount, LoadOp= tionTypePlatformRecovery); ProcessLoadOptions (LoadOptions, LoadOptionCount); EfiBootManagerFreeLoadOptions (LoadOptions, LoadOptionCount); } =20 + // + // If BootManagerMenu is available, fall back to it indefinitely. + // + if (BootManagerMenuStatus !=3D EFI_NOT_FOUND) { + BdsBootManagerMenuLoop (&BootManagerMenu); + } + DEBUG ((EFI_D_ERROR, "[Bds] Unable to boot!\n")); CpuDeadLoop (); } =20 /** Set the variable and report the error through status code upon failure. =20 @param VariableName A Null-terminated string that is the name= of the vendor's variable. Each VariableName is unique for each Vend= orGuid. VariableName must contain 1 or more characters. If Variable= Name is an empty string, then EFI_INVALID_PARAMETER is returned. @param VendorGuid A unique identifier for the vendor. --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 07:57:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511395142359387.2733872252933; Wed, 22 Nov 2017 15:59:02 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 794B82035BB16; Wed, 22 Nov 2017 15:54:44 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 C90452035A7C1 for ; Wed, 22 Nov 2017 15:54:41 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4F9A0356EA; Wed, 22 Nov 2017 23:58:58 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-45.rdu2.redhat.com [10.10.120.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id C5BF24A1; Wed, 22 Nov 2017 23:58:56 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Nov 2017 00:58:46 +0100 Message-Id: <20171122235849.4177-3-lersek@redhat.com> In-Reply-To: <20171122235849.4177-1-lersek@redhat.com> References: <20171122235849.4177-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 22 Nov 2017 23:58:58 +0000 (UTC) Subject: [edk2] [PATCH 2/5] MdeModulePkg: introduce the EDKII_OS_LOADER_DETAIL status code payload X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Jordan Justen , Eric Dong , Star Zeng , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The EfiBootManagerBoot() function in UefiBootManagerLib is the central function for loading and starting Boot#### options. The library is built into multiple drivers and applications (such as BdsDxe and UiApp), therefore it is careful not to print anything to the system console. All progress information is reported via DEBUG messages and progress/status codes. Individual platforms can customize how they handle the status codes reported. However, the codes currently reported about LoadImage() and StartImage() invocations are simple constants. Even if a platform displays them on some end-user accessible device -- because end-users are generally clueless of debug log capturing --, the information contained is insufficient for even rudimentary bug reporting. Introduce: - a new, common debug code that is similar to: - PcdProgressCodeOsLoaderLoad (LoadImage() preparation), - EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERROR (LoadImage() error), - PcdProgressCodeOsLoaderStart (StartImage() preparation), - EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED (StartImage() error), under which more details will be possible to convey about the same set of events; - a new status code payload structure (somewhat similar to EDKII_SET_VARIABLE_STATUS from "Include/Guid/StatusCodeDataTypeVariable.h"), for defining the wire format of said details. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Ruiyu Ni Cc: Eric Dong Cc: Star Zeng Ref: https://bugzilla.redhat.com/show_bug.cgi?id=3D1515418 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- MdeModulePkg/MdeModulePkg.dec | 9 ++ MdeModulePkg/MdeModulePkg.uni | 7 ++ MdeModulePkg/Include/Guid/StatusCodeDataTypeOsLoaderDetail.h | 109 +++++++= +++++++++++++ 3 files changed, 125 insertions(+) diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 856d67aceb21..6ba95dedc20d 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -383,24 +383,27 @@ [Guids] gEdkiiNonDiscoverableAmbaDeviceGuid =3D { 0x94440339, 0xCC93, 0x4506, {0= xB4, 0xC6, 0xEE, 0x8D, 0x0F, 0x4C, 0xA1, 0x91 } } gEdkiiNonDiscoverableEhciDeviceGuid =3D { 0xEAEE5615, 0x0CFD, 0x45FC, {0= x87, 0x69, 0xA0, 0xD8, 0x56, 0x95, 0xAF, 0x85 } } gEdkiiNonDiscoverableNvmeDeviceGuid =3D { 0xC5F25542, 0x2A79, 0x4A26, {0= x81, 0xBB, 0x4E, 0xA6, 0x32, 0x33, 0xB3, 0x09 } } gEdkiiNonDiscoverableOhciDeviceGuid =3D { 0xB20005B0, 0xBB2D, 0x496F, {0= x86, 0x9C, 0x23, 0x0B, 0x44, 0x79, 0xE7, 0xD1 } } gEdkiiNonDiscoverableSdhciDeviceGuid =3D { 0x1DD1D619, 0xF9B8, 0x463E, {= 0x86, 0x81, 0xD1, 0xDC, 0x7C, 0x07, 0xB7, 0x2C } } gEdkiiNonDiscoverableUfsDeviceGuid =3D { 0x2EA77912, 0x80A8, 0x4947, {0x= BE, 0x69, 0xCD, 0xD0, 0x0A, 0xFB, 0xE5, 0x56 } } gEdkiiNonDiscoverableUhciDeviceGuid =3D { 0xA8CDA0A2, 0x4F37, 0x4A1B, {0= x8E, 0x10, 0x8E, 0xF3, 0xCC, 0x3B, 0xF3, 0xA8 } } gEdkiiNonDiscoverableXhciDeviceGuid =3D { 0xB1BE0BC5, 0x6C28, 0x442D, {0= xAA, 0x37, 0x15, 0x1B, 0x42, 0x57, 0xBD, 0x78 } } =20 ## Include/Guid/PlatformHasAcpi.h gEdkiiPlatformHasAcpiGuid =3D { 0xf0966b41, 0xc23f, 0x41b9, { 0x96, 0x04= , 0x0f, 0xf7, 0xe1, 0x11, 0x96, 0x5a } } =20 + ## Include/Guid/StatusCodeDataTypeOsLoaderDetail.h + gEdkiiStatusCodeDataTypeOsLoaderDetailGuid =3D { 0xBE4904DC, 0x7EC4, 0x4= 167, { 0x90, 0x52, 0x38, 0x4D, 0x0B, 0x81, 0x30, 0x0B } } + [Ppis] ## Include/Ppi/AtaController.h gPeiAtaControllerPpiGuid =3D { 0xa45e60d1, 0xc719, 0x44aa, { 0xb0,= 0x7a, 0xaa, 0x77, 0x7f, 0x85, 0x90, 0x6d }} =20 ## Include/Ppi/UsbHostController.h gPeiUsbHostControllerPpiGuid =3D { 0x652B38A9, 0x77F4, 0x453F, { 0x89,= 0xD5, 0xE7, 0xBD, 0xC3, 0x52, 0xFC, 0x53 }} =20 ## Include/Ppi/Usb2HostController.h gPeiUsb2HostControllerPpiGuid =3D { 0xfedd6305, 0xe2d7, 0x4ed5, { 0x9f,= 0xaa, 0xda, 0x8, 0xe, 0x33, 0x6c, 0x22 }} =20 ## Include/Ppi/UsbController.h gPeiUsbControllerPpiGuid =3D { 0x3BC1F6DE, 0x693E, 0x4547, { 0xA3,= 0x00, 0x21, 0x82, 0x3C, 0xA4, 0x20, 0xB2 }} @@ -846,24 +849,30 @@ [PcdsFixedAtBuild] ## Progress Code for OS Loader LoadImage start.

# PROGRESS_CODE_OS_LOADER_LOAD =3D (EFI_SOFTWARE_DXE_BS_DRIVER | (EFI= _OEM_SPECIFIC | 0x00000000)) =3D 0x03058000
# @Prompt Progress Code for OS Loader LoadImage start. # @ValidList 0x80000003 | 0x03058000 gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad|0x03058000|UI= NT32|0x30001030 =20 ## Progress Code for OS Loader StartImage start.

# PROGRESS_CODE_OS_LOADER_START =3D (EFI_SOFTWARE_DXE_BS_DRIVER | (EFI= _OEM_SPECIFIC | 0x00000001)) =3D 0x03058001
# @Prompt Progress Code for OS Loader StartImage start. # @ValidList 0x80000003 | 0x03058001 gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart|0x03058001|U= INT32|0x30001031 =20 + ## Debug Code for OS Loader Detail.

+ # DEBUG_CODE_OS_LOADER_DETAIL =3D (EFI_SOFTWARE_DXE_BS_DRIVER | (EFI_OE= M_SPECIFIC | 0x00000003)) =3D 0x03058003
+ # @Prompt Debug Code for OS Loader Detail. + # @ValidList 0x80000007 | 0x03058003 + gEfiMdeModulePkgTokenSpaceGuid.PcdDebugCodeOsLoaderDetail|0x03058003|UIN= T32|0x3000103B + ## Progress Code for S3 Suspend start.

# PROGRESS_CODE_S3_SUSPEND_START =3D (EFI_SOFTWARE_SMM_DRIVER | (EFI_OE= M_SPECIFIC | 0x00000000)) =3D 0x03078000
# @Prompt Progress Code for S3 Suspend start. # @ValidList 0x80000003 | 0x03078000 gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendStart|0x03078000|= UINT32|0x30001032 =20 ## Progress Code for S3 Suspend end.

# PROGRESS_CODE_S3_SUSPEND_END =3D (EFI_SOFTWARE_SMM_DRIVER | (EFI_OE= M_SPECIFIC | 0x00000001)) =3D 0x03078001
# @Prompt Progress Code for S3 Suspend end. # @ValidList 0x80000003 | 0x03078001 gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendEnd|0x03078001|UI= NT32|0x30001033 =20 diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni index 588905a9a1fa..b0872970325c 100644 --- a/MdeModulePkg/MdeModulePkg.uni +++ b/MdeModulePkg/MdeModulePkg.uni @@ -35,24 +35,31 @@ #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdProgressCodeOsLoaderLoad_PRO= MPT #language en-US "Progress Code for OS Loader LoadImage start." =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdProgressCodeOsLoaderLoad_HEL= P #language en-US "Progress Code for OS Loader LoadImage start.

\n" = "PROGRESS_CODE_OS_LOADER_LOAD =3D (EFI_SOFTWARE_DXE_BS= _DRIVER | (EFI_OEM_SPECIFIC | 0x00000000)) =3D 0x03058000
" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_ERR_80000003 #language en-US "I= ncorrect progress code provided." =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdProgressCodeOsLoaderStart_PR= OMPT #language en-US "Progress Code for OS Loader StartImage start" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdProgressCodeOsLoaderStart_HE= LP #language en-US "Progress Code for OS Loader StartImage start.

\= n" = "PROGRESS_CODE_OS_LOADER_START =3D (EFI_SOFTWARE_DXE_B= S_DRIVER | (EFI_OEM_SPECIFIC | 0x00000001)) =3D 0x03058001
" =20 +#string STR_gEfiMdeModulePkgTokenSpaceGuid_ERR_80000007 #language en-US "I= ncorrect debug code provided." + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdDebugCodeOsLoaderDetail_PROM= PT #language en-US "Debug Code for OS Loader Detail" + +#string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdDebugCodeOsLoaderDetail_HELP= #language en-US "Debug Code for OS Loader Detail.

\n" + = "DEBUG_CODE_OS_LOADER_DETAIL =3D (EFI_SOFTWARE_DXE_BS_DRI= VER | (EFI_OEM_SPECIFIC | 0x00000003)) =3D 0x03058003
" + #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdProgressCodeS3SuspendStart_P= ROMPT #language en-US "Progress Code for S3 Suspend start" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdProgressCodeS3SuspendStart_H= ELP #language en-US "Progress Code for S3 Suspend start.

\n" = "PROGRESS_CODE_S3_SUSPEND_START =3D (EFI_SOFTWARE_SMM_= DRIVER | (EFI_OEM_SPECIFIC | 0x00000000)) =3D 0x03078000
" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdProgressCodeS3SuspendEnd_PRO= MPT #language en-US "Progress Code for S3 Suspend end" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdProgressCodeS3SuspendEnd_HEL= P #language en-US "Progress Code for S3 Suspend end.

\n" = "PROGRESS_CODE_S3_SUSPEND_END =3D (EFI_SOFTWARE_SMM_DR= IVER | (EFI_OEM_SPECIFIC | 0x00000001)) =3D 0x03078001
" =20 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdErrorCodeSetVariable_PROMPT = #language en-US "Error Code for SetVariable failure" =20 diff --git a/MdeModulePkg/Include/Guid/StatusCodeDataTypeOsLoaderDetail.h b= /MdeModulePkg/Include/Guid/StatusCodeDataTypeOsLoaderDetail.h new file mode 100644 index 000000000000..061ecef0ad21 --- /dev/null +++ b/MdeModulePkg/Include/Guid/StatusCodeDataTypeOsLoaderDetail.h @@ -0,0 +1,109 @@ +/** @file + Define the GUID, macros, and the data structure for passing details of OS + Loading from the UEFI Boot Manager to the Platform, as debug codes. + + Copyright (C) 2017, Red Hat, Inc. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License that accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php. + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#ifndef _STATUS_CODE_DATA_TYPE_OS_LOADER_DETAIL_H_ +#define _STATUS_CODE_DATA_TYPE_OS_LOADER_DETAIL_H_ + +#include +#include + +// +// The GUID for EFI_STATUS_CODE_DATA.Type, in order to identify the traili= ng +// payload as EDKII_OS_LOADER_DETAIL. +// +// The EFI_STATUS_CODE_VALUE under which to report such data is +// PcdGet32(PcdDebugCodeOsLoaderDetail). +// +#define EDKII_STATUS_CODE_DATA_TYPE_OS_LOADER_DETAIL_GUID \ + { \ + 0xBE4904DC, \ + 0x7EC4, \ + 0x4167, \ + { 0x90, 0x52, 0x38, 0x4D, 0x0B, 0x81, 0x30, 0x0B } \ + } + +// +// The UEFI Boot Manager is about to call gBS->LoadImage() on the boot opt= ion. +// +#define EDKII_OS_LOADER_DETAIL_TYPE_LOAD 0x00000000 +// +// gBS->LoadImage() failed on the boot option. +// +#define EDKII_OS_LOADER_DETAIL_TYPE_LOAD_ERROR 0x00000001 +// +// The UEFI Boot Manager is about to call gBS->StartImage() on the boot op= tion. +// +#define EDKII_OS_LOADER_DETAIL_TYPE_START 0x00000002 +// +// gBS->StartImage() failed on the boot option. +// +#define EDKII_OS_LOADER_DETAIL_TYPE_START_ERROR 0x00000003 + +// +// Structure for passing details about the above actions and results. Curr= ently +// a common structure is used for all of them. +// +// The structure can be extended compatibly by adding fields at the end. T= he +// presence of such fields can be deduced from the containing +// EFI_STATUS_CODE_DATA.Size field. Incompatible extensions require a new = GUID +// for the containing EFI_STATUS_CODE_DATA.Type field. +// +#pragma pack (1) +typedef struct { + // + // EDKII_OS_LOADER_DETAIL_TYPE_* values. + // + UINT32 Type; + // + // The number of the Boot#### UEFI variable from which the OS is being + // loaded. + // + UINT16 BootOptionNumber; + // + // The size of Description in bytes, including the terminating L'\0' + // character. If DescriptionSize is 0, then Description is absent. The t= ype + // of this field is UINT16 because all of EDKII_OS_LOADER_DETAIL has to = fit + // into EFI_STATUS_CODE_DATA.Size, which has type UINT16. + // + UINT16 DescriptionSize; + // + // The size of DevicePath in bytes, including the terminating end node. = If + // DevicePathSize is 0, then DevicePath is absent. The type of this fiel= d is + // UINT16 because all of EDKII_OS_LOADER_DETAIL has to fit into + // EFI_STATUS_CODE_DATA.Size, which has type UINT16. + // + // + UINT16 DevicePathSize; + // + // Used only for EDKII_OS_LOADER_DETAIL_TYPE_*_ERROR, the following field + // reports the failure code. + // + EFI_STATUS Status; + // + // The human-readable description of the boot option for which the OS is + // being loaded. Populated from EFI_LOAD_OPTION.Description. + // + // CHAR16 Description[]; + // + // Describes the device and location of the OS image being loaded. Popul= ated + // from the first element of the packed EFI_LOAD_OPTION.FilePathList arr= ay. + // + // EFI_DEVICE_PATH_PROTOCOL DevicePath; +} EDKII_OS_LOADER_DETAIL; +#pragma pack () + +extern EFI_GUID gEdkiiStatusCodeDataTypeOsLoaderDetailGuid; + +#endif // _STATUS_CODE_DATA_TYPE_OS_LOADER_DETAIL_H_ --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 07:57:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511395144620221.05646062354026; Wed, 22 Nov 2017 15:59:04 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B67B62035BB21; Wed, 22 Nov 2017 15:54:46 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 D67CC2034C5D9 for ; Wed, 22 Nov 2017 15:54:43 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56EDA356EA; Wed, 22 Nov 2017 23:59:00 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-45.rdu2.redhat.com [10.10.120.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2FD44A1; Wed, 22 Nov 2017 23:58:58 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Nov 2017 00:58:47 +0100 Message-Id: <20171122235849.4177-4-lersek@redhat.com> In-Reply-To: <20171122235849.4177-1-lersek@redhat.com> References: <20171122235849.4177-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 22 Nov 2017 23:59:00 +0000 (UTC) Subject: [edk2] [PATCH 3/5] MdeModulePkg/UefiBootManagerLib: report EDKII_OS_LOADER_DETAIL status code X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Jordan Justen , Eric Dong , Star Zeng , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The EfiBootManagerBoot() function reports progress codes about LoadImage() preparation and failure, and StartImage() preparation and failure. These codes are flat (scalar) constants. Extend this by "broadcasting" the Boot#### option number, description, device path, and -- on load / start failure -- the error result at the same locations, through EFI_DEBUG_CODE reporting. Use the PcdDebugCodeOsLoaderDetail status code value and the EDKII_OS_LOADER_DETAIL status code structure introduced earlier in this series. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Ruiyu Ni Cc: Eric Dong Cc: Star Zeng Ref: https://bugzilla.redhat.com/show_bug.cgi?id=3D1515418 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf | 2 + MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h | 84 +++++= +++++ MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c | 51 +++++- MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c | 166 +++++= +++++++++++++++ 4 files changed, 301 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf= b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf index ad4901db5713..633906fc6ca4 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf +++ b/MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf @@ -79,24 +79,25 @@ [Guids] =20 ## SOMETIMES_PRODUCES ## Variable:L"BootCurrent" (The boot option of cur= rent boot) ## SOMETIMES_CONSUMES ## Variable:L"BootXX" (Boot option variable) ## SOMETIMES_CONSUMES ## Variable:L"BootOrder" (The boot option array) ## SOMETIMES_CONSUMES ## Variable:L"DriverOrder" (The driver order list) ## SOMETIMES_CONSUMES ## Variable:L"ConIn" (The device path of console i= n device) ## SOMETIMES_CONSUMES ## Variable:L"ConOut" (The device path of console = out device) ## SOMETIMES_CONSUMES ## Variable:L"ErrOut" (The device path of error ou= t device) gEfiGlobalVariableGuid =20 gPerformanceProtocolGuid ## SOMETIMES_CONSUMES ## V= ariable:L"PerfDataMemAddr" (The ACPI address of performance data) gEdkiiStatusCodeDataTypeVariableGuid ## SOMETIMES_CONSUMES ## G= UID + gEdkiiStatusCodeDataTypeOsLoaderDetailGuid ## SOMETIMES_CONSUMES ## G= UID gEfiDiskInfoAhciInterfaceGuid ## SOMETIMES_CONSUMES ## G= UID gEfiDiskInfoIdeInterfaceGuid ## SOMETIMES_CONSUMES ## G= UID gEfiDiskInfoScsiInterfaceGuid ## SOMETIMES_CONSUMES ## G= UID gEfiDiskInfoSdMmcInterfaceGuid ## SOMETIMES_CONSUMES ## G= UID =20 [Protocols] gEfiPciRootBridgeIoProtocolGuid ## CONSUMES gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES gEfiLoadFileProtocolGuid ## SOMETIMES_CONSUMES gEfiSimpleTextOutProtocolGuid ## SOMETIMES_CONSUMES gEfiPciIoProtocolGuid ## SOMETIMES_CONSUMES gEfiLoadedImageProtocolGuid ## CONSUMES @@ -112,16 +113,17 @@ [Protocols] gEfiUsbIoProtocolGuid ## SOMETIMES_CONSUMES gEfiNvmExpressPassThruProtocolGuid ## SOMETIMES_CONSUMES gEfiDiskInfoProtocolGuid ## SOMETIMES_CONSUMES gEfiDriverHealthProtocolGuid ## SOMETIMES_CONSUMES gEfiFormBrowser2ProtocolGuid ## SOMETIMES_CONSUMES gEfiRamDiskProtocolGuid ## SOMETIMES_CONSUMES gEfiDeferredImageLoadProtocolGuid ## SOMETIMES_CONSUMES =20 [Pcd] gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange = ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad = ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart = ## SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdDebugCodeOsLoaderDetail = ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdErrorCodeSetVariable = ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile = ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdDriverHealthConfigureForm = ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdMaxRepairCount = ## CONSUMES diff --git a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h b/MdeModu= lePkg/Library/UefiBootManagerLib/InternalBm.h index 0224bd34a9ed..ddcb0347aef6 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h +++ b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h @@ -44,24 +44,25 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITH= ER EXPRESS OR IMPLIED. #include #include #include #include #include #include =20 #include #include #include #include #include +#include =20 #include #include #include #include #include #include #include #include #include #include #include @@ -298,24 +299,107 @@ BmStopHotkeyService ( =20 @retval EFI_NOT_FOUND The variable trying to be updated or dele= ted was not found. **/ EFI_STATUS BmSetVariableAndReportStatusCodeOnError ( IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data ); =20 +/** + Dynamically allocate and initialize an EDKII_OS_LOADER_DETAIL status code + payload. + + @param[in] BootOption Capture the OptionNumber, FilePath and + Description fields of BootOption in the + EDKII_OS_LOADER_DETAIL payload. + + @param[out] OsLoaderDetail On successful return, set to the + EDKII_OS_LOADER_DETAIL object that has b= een + allocated and initialized. On failure, n= ot + modified. + + @param[out] OsLoaderDetailSize On successful return, set to the size of= the + EDKII_OS_LOADER_DETAIL object that has b= een + allocated and initialized. On failure, n= ot + modified. + + @retval EFI_UNSUPPORTED EFI_DEBUG_CODE reporting is disabled in t= he + platform. + + @retval EFI_INVALID_PARAMETER BootOption->OptionNumber is not in + 0x0000..0xFFFF, inclusive. + + @retval EFI_BAD_BUFFER_SIZE BootOption->FilePath and/or + BootOption->Description would exceed the + UINT16 size limits presented by + EDKII_OS_LOADER_DETAIL or + EFI_STATUS_CODE_DATA. + + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + + @retval EFI_SUCCESS The EDKII_OS_LOADER_DETAIL object has been + allocated and initialized. The caller is + responsible for freeing the object with + FreePool(). +**/ +EFI_STATUS +BmCreateOsLoaderDetail ( + IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption, + OUT EDKII_OS_LOADER_DETAIL **OsLoaderDetail, + OUT UINTN *OsLoaderDetailSize + ); + +/** + Report an EFI_DEBUG_CODE status code with EDKII_OS_LOADER_DETAIL as payl= oad + (i.e., extended data). + + @param[in,out] OsLoaderDetail The EDKII_OS_LOADER_DETAIL payload previo= usly + created with BmCreateOsLoaderDetail(), and + modified zero or more times by + BmReportOsLoaderDetail(). If OsLoaderDeta= il is + NULL, the function does nothing. Otherwis= e, + the Type and Status fields are overwritte= n in + OsLoaderDetail, and a status code is repo= rted. + + @param[in] OsLoaderDetailSize The size returned by BmCreateOsLoaderDeta= il(). + If OsLoaderDetail is NULL, OsLoaderDetail= Size + may be zero. + + @param[in] DetailType OsLoaderDetail->Type is set to DetailType + before reporting the status code. The cal= ler + is responsible for passing an + EDKII_OS_LOADER_DETAIL_TYPE_* value. + + @param[in] DetailStatus OsLoaderDetail->Status is set to DetailSt= atus + before reporting the status code. + + @retval EFI_UNSUPPORTED EFI_DEBUG_CODE reporting is disabled in the + platform. + + @retval EFI_ABORTED OsLoaderDetail is NULL. + + @return Values propagated from REPORT_STATUS_CODE_EX(). +**/ +EFI_STATUS +BmReportOsLoaderDetail ( + IN OUT EDKII_OS_LOADER_DETAIL *OsLoaderDetail OPTIONAL, + IN UINTN OsLoaderDetailSize, + IN UINT32 DetailType, + IN EFI_STATUS DetailStatus + ); + /** Function compares a device path data structure to that of all the nodes = of a second device path instance. =20 @param Multi A pointer to a multi-instance device path = data structure. @param Single A pointer to a single-instance device path= data structure. =20 @retval TRUE If the Single device path is contained wit= hin Multi device path. @retval FALSE The Single device path is not match within= Multi device path. =20 diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c b/MdeModulePk= g/Library/UefiBootManagerLib/BmBoot.c index d6844823aa55..049afbf7d1f9 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c @@ -1665,34 +1665,39 @@ EfiBootManagerBoot ( EFI_STATUS Status; EFI_HANDLE ImageHandle; EFI_LOADED_IMAGE_PROTOCOL *ImageInfo; UINT16 Uint16; UINTN OptionNumber; UINTN OriginalOptionNumber; EFI_DEVICE_PATH_PROTOCOL *FilePath; EFI_DEVICE_PATH_PROTOCOL *RamDiskDevicePath; VOID *FileBuffer; UINTN FileSize; EFI_BOOT_LOGO_PROTOCOL *BootLogo; EFI_EVENT LegacyBootEvent; + EDKII_OS_LOADER_DETAIL *OsLoaderDetail; + UINTN OsLoaderDetailSize; =20 if (BootOption =3D=3D NULL) { return; } =20 if (BootOption->FilePath =3D=3D NULL || BootOption->OptionType !=3D Load= OptionTypeBoot) { BootOption->Status =3D EFI_INVALID_PARAMETER; return; } =20 + OsLoaderDetail =3D NULL; + OsLoaderDetailSize =3D 0; + // // 1. Create Boot#### for a temporary boot if there is no match Boot####= (i.e. a boot by selected a EFI Shell using "Boot From File") // OptionNumber =3D BmFindBootOptionInVariable (BootOption); if (OptionNumber =3D=3D LoadOptionNumberUnassigned) { Status =3D BmGetFreeOptionNumber (LoadOptionTypeBoot, &Uint16); if (!EFI_ERROR (Status)) { // // Save the BootOption->OptionNumber to restore later // OptionNumber =3D Uint16; OriginalOptionNumber =3D BootOption->OptionNumber; @@ -1751,68 +1756,93 @@ EfiBootManagerBoot ( =20 // // 6. Load EFI boot option to ImageHandle // DEBUG_CODE_BEGIN (); if (BootOption->Description =3D=3D NULL) { DEBUG ((DEBUG_INFO | DEBUG_LOAD, "[Bds]Booting from unknown device pat= h\n")); } else { DEBUG ((DEBUG_INFO | DEBUG_LOAD, "[Bds]Booting %s\n", BootOption->Desc= ription)); } DEBUG_CODE_END (); =20 + // + // Try to create the status code payload structure for detailed debug + // reporting. + // + Status =3D BmCreateOsLoaderDetail (BootOption, &OsLoaderDetail, + &OsLoaderDetailSize); + if (EFI_ERROR (Status) && (Status !=3D EFI_UNSUPPORTED)) { + DEBUG ((DEBUG_WARN | DEBUG_LOAD, "[Bds]BmCreateOsLoaderDetail(): %r\n", + Status)); + } + ImageHandle =3D NULL; RamDiskDevicePath =3D NULL; if (DevicePathType (BootOption->FilePath) !=3D BBS_DEVICE_PATH) { Status =3D EFI_NOT_FOUND; FilePath =3D NULL; EfiBootManagerConnectDevicePath (BootOption->FilePath, NULL); FileBuffer =3D BmGetNextLoadOptionBuffer (LoadOptionTypeBoot, BootOpti= on->FilePath, &FilePath, &FileSize); if (FileBuffer !=3D NULL) { RamDiskDevicePath =3D BmGetRamDiskDevicePath (FilePath); =20 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLo= aderLoad)); + BmReportOsLoaderDetail ( + OsLoaderDetail, + OsLoaderDetailSize, + EDKII_OS_LOADER_DETAIL_TYPE_LOAD, + 0 // DetailStatus -- unused here + ); + Status =3D gBS->LoadImage ( TRUE, gImageHandle, FilePath, FileBuffer, FileSize, &ImageHandle ); } if (FileBuffer !=3D NULL) { FreePool (FileBuffer); } if (FilePath !=3D NULL) { FreePool (FilePath); } =20 if (EFI_ERROR (Status)) { // // Report Status Code to indicate that the failure to load boot opti= on // REPORT_STATUS_CODE ( EFI_ERROR_CODE | EFI_ERROR_MINOR, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ER= ROR) ); + BmReportOsLoaderDetail ( + OsLoaderDetail, + OsLoaderDetailSize, + EDKII_OS_LOADER_DETAIL_TYPE_LOAD_ERROR, + Status + ); + BootOption->Status =3D Status; // // Destroy the RAM disk // if (RamDiskDevicePath !=3D NULL) { BmDestroyRamDisk (RamDiskDevicePath); FreePool (RamDiskDevicePath); } - return; + goto FreeOsLoaderDetail; } } =20 // // Check to see if we should legacy BOOT. If yes then do the legacy boot // Write boot to OS performance data for Legacy boot // if ((DevicePathType (BootOption->FilePath) =3D=3D BBS_DEVICE_PATH) && (D= evicePathSubType (BootOption->FilePath) =3D=3D BBS_BBS_DP)) { if (mBmLegacyBoot !=3D NULL) { // // Write boot to OS performance data for legacy boot. // @@ -1826,25 +1856,25 @@ EfiBootManagerBoot ( NULL,=20 &LegacyBootEvent ); ASSERT_EFI_ERROR (Status); ); =20 mBmLegacyBoot (BootOption); } else { BootOption->Status =3D EFI_UNSUPPORTED; } =20 PERF_END_EX (gImageHandle, "BdsAttempt", NULL, 0, (UINT32) OptionNumbe= r); - return; + goto FreeOsLoaderDetail; } =20 // // Provide the image with its load options // Status =3D gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGui= d, (VOID **) &ImageInfo); ASSERT_EFI_ERROR (Status); =20 if (!BmIsAutoCreateBootOption (BootOption)) { ImageInfo->LoadOptionsSize =3D BootOption->OptionalDataSize; ImageInfo->LoadOptions =3D BootOption->OptionalData; } @@ -1858,36 +1888,48 @@ EfiBootManagerBoot ( // Before calling the image, enable the Watchdog Timer for 5 minutes per= iod // gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL); =20 // // Write boot to OS performance data for UEFI boot // PERF_CODE ( BmWriteBootToOsPerformanceData (NULL, NULL); ); =20 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoader= Start)); + BmReportOsLoaderDetail ( + OsLoaderDetail, + OsLoaderDetailSize, + EDKII_OS_LOADER_DETAIL_TYPE_START, + 0 // DetailStatus -- unused here + ); =20 Status =3D gBS->StartImage (ImageHandle, &BootOption->ExitDataSize, &Boo= tOption->ExitData); DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status =3D %r\n", Status)= ); BootOption->Status =3D Status; if (EFI_ERROR (Status)) { // // Report Status Code to indicate that boot failure // REPORT_STATUS_CODE ( EFI_ERROR_CODE | EFI_ERROR_MINOR, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED) ); + BmReportOsLoaderDetail ( + OsLoaderDetail, + OsLoaderDetailSize, + EDKII_OS_LOADER_DETAIL_TYPE_START_ERROR, + Status + ); } PERF_END_EX (gImageHandle, "BdsAttempt", NULL, 0, (UINT32) OptionNumber); =20 // // Destroy the RAM disk // if (RamDiskDevicePath !=3D NULL) { BmDestroyRamDisk (RamDiskDevicePath); FreePool (RamDiskDevicePath); } =20 // @@ -1912,24 +1954,29 @@ EfiBootManagerBoot ( L"BootCurrent", &gEfiGlobalVariableGuid, 0, 0, NULL ); // // Deleting variable with current variable implementation shouldn't fail. // When BootXXXX (e.g.: BootManagerMenu) boots BootYYYY, exiting BootYYY= Y causes BootCurrent deleted, // exiting BootXXXX causes deleting BootCurrent returns EFI_NOT_FOUND. // ASSERT (Status =3D=3D EFI_SUCCESS || Status =3D=3D EFI_NOT_FOUND); + +FreeOsLoaderDetail: + if (OsLoaderDetail !=3D NULL) { + FreePool (OsLoaderDetail); + } } =20 /** Check whether there is a instance in BlockIoDevicePath, which contain mu= lti device path instances, has the same partition node with HardDriveDevicePath device p= ath =20 @param BlockIoDevicePath Multi device path instances which need to= check @param HardDriveDevicePath A device path which starts with a hard dr= ive media device path. =20 @retval TRUE There is a matched device path instance. @retval FALSE There is no matched device path instance. diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c b/MdeModulePk= g/Library/UefiBootManagerLib/BmMisc.c index 81d365940043..29da896854b8 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c @@ -369,24 +369,190 @@ BmSetVariableAndReportStatusCodeOnError ( SetVariableStatus, sizeof (EDKII_SET_VARIABLE_STATUS) + NameSize + DataSize ); =20 FreePool (SetVariableStatus); } } =20 return Status; } =20 =20 +/** + Dynamically allocate and initialize an EDKII_OS_LOADER_DETAIL status code + payload. + + @param[in] BootOption Capture the OptionNumber, FilePath and + Description fields of BootOption in the + EDKII_OS_LOADER_DETAIL payload. + + @param[out] OsLoaderDetail On successful return, set to the + EDKII_OS_LOADER_DETAIL object that has b= een + allocated and initialized. On failure, n= ot + modified. + + @param[out] OsLoaderDetailSize On successful return, set to the size of= the + EDKII_OS_LOADER_DETAIL object that has b= een + allocated and initialized. On failure, n= ot + modified. + + @retval EFI_UNSUPPORTED EFI_DEBUG_CODE reporting is disabled in t= he + platform. + + @retval EFI_INVALID_PARAMETER BootOption->OptionNumber is not in + 0x0000..0xFFFF, inclusive. + + @retval EFI_BAD_BUFFER_SIZE BootOption->FilePath and/or + BootOption->Description would exceed the + UINT16 size limits presented by + EDKII_OS_LOADER_DETAIL or + EFI_STATUS_CODE_DATA. + + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + + @retval EFI_SUCCESS The EDKII_OS_LOADER_DETAIL object has been + allocated and initialized. The caller is + responsible for freeing the object with + FreePool(). +**/ +EFI_STATUS +BmCreateOsLoaderDetail ( + IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *BootOption, + OUT EDKII_OS_LOADER_DETAIL **OsLoaderDetail, + OUT UINTN *OsLoaderDetailSize + ) +{ + UINTN DescriptionSize; + UINTN DevicePathSize; + UINTN PayloadSize; + EDKII_OS_LOADER_DETAIL *Payload; + UINT8 *VariableSizeData; + + if (!ReportDebugCodeEnabled ()) { + return EFI_UNSUPPORTED; + } + + if (BootOption->OptionNumber >=3D LoadOptionNumberMax) { + return EFI_INVALID_PARAMETER; + } + + DescriptionSize =3D (BootOption->Description =3D=3D NULL) ? + 0 : + StrSize (BootOption->Description); + DevicePathSize =3D GetDevicePathSize (BootOption->FilePath); + PayloadSize =3D sizeof *Payload + DescriptionSize + DevicePathSize; + + if (DescriptionSize > MAX_UINT16 || + DevicePathSize > MAX_UINT16 || + PayloadSize > MAX_UINT16) { + return EFI_BAD_BUFFER_SIZE; + } + + Payload =3D AllocateZeroPool (PayloadSize); + if (Payload =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + VariableSizeData =3D (UINT8 *)(Payload + 1); + + // + // Populate the variable size fields at the end of the payload. + // + CopyMem (VariableSizeData, BootOption->Description, DescriptionSize); + VariableSizeData +=3D DescriptionSize; + + CopyMem (VariableSizeData, BootOption->FilePath, DevicePathSize); + VariableSizeData +=3D DevicePathSize; + + ASSERT (VariableSizeData - (UINT8 *)Payload =3D=3D PayloadSize); + + // + // Populate the fixed fields in the payload. Any members not listed below + // remain zero-filled at this point. + // + Payload->BootOptionNumber =3D (UINT16)BootOption->OptionNumber; + Payload->DescriptionSize =3D (UINT16)DescriptionSize; + Payload->DevicePathSize =3D (UINT16)DevicePathSize; + + *OsLoaderDetail =3D Payload; + *OsLoaderDetailSize =3D PayloadSize; + return EFI_SUCCESS; +} + + +/** + Report an EFI_DEBUG_CODE status code with EDKII_OS_LOADER_DETAIL as payl= oad + (i.e., extended data). + + @param[in,out] OsLoaderDetail The EDKII_OS_LOADER_DETAIL payload previo= usly + created with BmCreateOsLoaderDetail(), and + modified zero or more times by + BmReportOsLoaderDetail(). If OsLoaderDeta= il is + NULL, the function does nothing. Otherwis= e, + the Type and Status fields are overwritte= n in + OsLoaderDetail, and a status code is repo= rted. + + @param[in] OsLoaderDetailSize The size returned by BmCreateOsLoaderDeta= il(). + If OsLoaderDetail is NULL, OsLoaderDetail= Size + may be zero. + + @param[in] DetailType OsLoaderDetail->Type is set to DetailType + before reporting the status code. The cal= ler + is responsible for passing an + EDKII_OS_LOADER_DETAIL_TYPE_* value. + + @param[in] DetailStatus OsLoaderDetail->Status is set to DetailSt= atus + before reporting the status code. + + @retval EFI_UNSUPPORTED EFI_DEBUG_CODE reporting is disabled in the + platform. + + @retval EFI_ABORTED OsLoaderDetail is NULL. + + @return Values propagated from REPORT_STATUS_CODE_EX(). +**/ +EFI_STATUS +BmReportOsLoaderDetail ( + IN OUT EDKII_OS_LOADER_DETAIL *OsLoaderDetail OPTIONAL, + IN UINTN OsLoaderDetailSize, + IN UINT32 DetailType, + IN EFI_STATUS DetailStatus + ) +{ + EFI_STATUS Status; + + if (!ReportDebugCodeEnabled ()) { + return EFI_UNSUPPORTED; + } + + if (OsLoaderDetail =3D=3D NULL) { + return EFI_ABORTED; + } + + OsLoaderDetail->Type =3D DetailType; + OsLoaderDetail->Status =3D DetailStatus; + + Status =3D REPORT_STATUS_CODE_EX ( + EFI_DEBUG_CODE, // Type + PcdGet32 (PcdDebugCodeOsLoaderDetail), // Value + 0, // Instance + &gEfiCallerIdGuid, // CallerId + &gEdkiiStatusCodeDataTypeOsLoaderDetailGuid, // ExtendedDataG= uid + OsLoaderDetail, // ExtendedData + OsLoaderDetailSize // ExtendedDataS= ize + ); + return Status; +} + + /** Print the device path info. =20 @param DevicePath The device path need to print. **/ VOID BmPrintDp ( EFI_DEVICE_PATH_PROTOCOL *DevicePath ) { CHAR16 *Str; =20 --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 07:57:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511395147396145.08385115097735; Wed, 22 Nov 2017 15:59:07 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0466E2035BB2E; Wed, 22 Nov 2017 15:54:47 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 A8E2F2034C5F5 for ; Wed, 22 Nov 2017 15:54:45 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2EA685AFED; Wed, 22 Nov 2017 23:59:02 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-45.rdu2.redhat.com [10.10.120.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA0D36178B; Wed, 22 Nov 2017 23:59:00 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Nov 2017 00:58:48 +0100 Message-Id: <20171122235849.4177-5-lersek@redhat.com> In-Reply-To: <20171122235849.4177-1-lersek@redhat.com> References: <20171122235849.4177-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 22 Nov 2017 23:59:02 +0000 (UTC) Subject: [edk2] [PATCH 4/5] OvmfPkg/PlatformBootManagerLib: print EDKII_OS_LOADER_DETAIL to ConOut X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Jordan Justen , Anthony Perard , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Parse and print the EDKII_OS_LOADER_DETAIL debug codes from UefiBootManagerLib (when it acts as part of BdsDxe -- not as part of UiApp, for example). In effect this displays LoadImage() and StartImage() attempts and failures on the splash screen, visibly to end-users. While at it, print two other (earlier) console messages about boot option generation and boot option filtering / reordering. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Ruiyu Ni Cc: Anthony Perard Cc: Julien Grall Ref: https://bugzilla.redhat.com/show_bug.cgi?id=3D1515418 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- Notes: We can port this later to ArmVirtPkg. For that, first we'll have to replace commit 59541d41633c ("ArmVirtPkg: remove status code support", 2017-07-05) with a port of commit a6d594c5fabd ("OvmfPkg: use StatusCode Router and Handler from MdeModulePkg", 2016-08-03). OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 4 + OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h | 15 + OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c | 8 + OvmfPkg/Library/PlatformBootManagerLib/StatusCodeHandler.c | 298 ++= ++++++++++++++++++ 4 files changed, 325 insertions(+) diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.= inf b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index 27789b7377bc..36901fc39d95 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -21,24 +21,25 @@ [Defines] LIBRARY_CLASS =3D PlatformBootManagerLib|DXE_DRIVER =20 # # The following information is for reference only and not required by the = build tools. # # VALID_ARCHITECTURES =3D IA32 X64 IPF EBC # =20 [Sources] BdsPlatform.c PlatformData.c QemuKernel.c + StatusCodeHandler.c BdsPlatform.h =20 [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec SourceLevelDebugPkg/SourceLevelDebugPkg.dec OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] BaseLib MemoryAllocationLib @@ -54,28 +55,31 @@ [LibraryClasses] QemuFwCfgLib QemuFwCfgS3Lib LoadLinuxLib QemuBootOrderLib UefiLib =20 [Pcd] gUefiOvmfPkgTokenSpaceGuid.PcdEmuVariableEvent gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashVariablesEnable gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile + gEfiMdeModulePkgTokenSpaceGuid.PcdDebugCodeOsLoaderDetail =20 [Pcd.IA32, Pcd.X64] gEfiMdePkgTokenSpaceGuid.PcdFSBClock =20 [Protocols] gEfiDecompressProtocolGuid gEfiPciRootBridgeIoProtocolGuid gEfiS3SaveStateProtocolGuid # PROTOCOL SOMETIMES_CONSU= MED gEfiDxeSmmReadyToLockProtocolGuid # PROTOCOL SOMETIMES_PRODU= CED gEfiLoadedImageProtocolGuid # PROTOCOL SOMETIMES_PRODU= CED gEfiFirmwareVolume2ProtocolGuid # PROTOCOL SOMETIMES_CONSU= MED + gEfiRscHandlerProtocolGuid # PROTOCOL SOMETIMES_CONSU= MED =20 [Guids] gEfiXenInfoGuid gEfiEndOfDxeEventGroupGuid gRootBridgesConnectedEventGroupGuid + gEdkiiStatusCodeDataTypeOsLoaderDetailGuid diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h b/OvmfPkg= /Library/PlatformBootManagerLib/BdsPlatform.h index 97ffbb514825..493cfee85f54 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h +++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h @@ -183,13 +183,28 @@ PlatformInitializeConsole ( =20 /** Loads and boots UEFI Linux via the FwCfg interface. =20 @retval EFI_NOT_FOUND - The Linux kernel was not found =20 **/ EFI_STATUS TryRunningQemuKernel ( VOID ); =20 +/** + Register a status code handler for printing EDKII_OS_LOADER_DETAIL repor= ts to + the console. + + @retval EFI_SUCCESS The status code handler has been successfully + registered. + + @return Error codes propagated from boot services and from + EFI_RSC_HANDLER_PROTOCOL. +**/ +EFI_STATUS +RegisterStatusCodeHandler ( + VOID + ); + #endif // _PLATFORM_SPECIFIC_BDS_PLATFORM_H_ diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c b/OvmfPkg= /Library/PlatformBootManagerLib/BdsPlatform.c index 025252e72b39..429f2926d2af 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c +++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.c @@ -1454,35 +1454,43 @@ Routine Description: BootLogoEnableLogo (); =20 // // Perform some platform specific connect sequence // PlatformBdsConnectSequence (); =20 // // Process QEMU's -kernel command line option // TryRunningQemuKernel (); =20 + AsciiPrint ( + "%a: auto-generating trailing boot options for bootable devices\n", + gEfiCallerBaseName + ); EfiBootManagerRefreshAllBootOption (); =20 // // Register UEFI Shell // PlatformRegisterFvBootOption ( PcdGetPtr (PcdShellFile), L"EFI Internal Shell", LOAD_OPTION_ACTIVE ); =20 + AsciiPrint ("%a: filtering and reordering boot options\n", + gEfiCallerBaseName); RemoveStaleFvFileOptions (); SetBootOrderFromQemu (); + + RegisterStatusCodeHandler (); } =20 /** This notification function is invoked when an instance of the EFI_DEVICE_PATH_PROTOCOL is produced. =20 @param Event The event that occurred @param Context For EFI compatibility. Not used. =20 **/ VOID EFIAPI diff --git a/OvmfPkg/Library/PlatformBootManagerLib/StatusCodeHandler.c b/O= vmfPkg/Library/PlatformBootManagerLib/StatusCodeHandler.c new file mode 100644 index 000000000000..cec4fb6ed6ce --- /dev/null +++ b/OvmfPkg/Library/PlatformBootManagerLib/StatusCodeHandler.c @@ -0,0 +1,298 @@ +/** @file + Register a status code handler for printing EDKII_OS_LOADER_DETAIL repor= ts to + the console. + + This feature enables users that are not accustomed to analyzing the OVMF + debug log to glean some information about UEFI boot option processing + (loading and starting). + + Copyright (C) 2017, Red Hat, Inc. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#include +#include + +#include "BdsPlatform.h" + + +/** + Handle status codes reported through ReportStatusCodeLib / + EFI_STATUS_CODE_PROTOCOL.ReportStatusCode(). Format matching status code= s to + the system console. + + The highest TPL at which this handler can be registered with + EFI_RSC_HANDLER_PROTOCOL.Register() is TPL_NOTIFY. That's because + AsciiPrint() uses EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL internally. + + The parameter list of this function precisely matches that of + EFI_STATUS_CODE_PROTOCOL.ReportStatusCode(). + + The return status of this function is ignored by the caller, but the fun= ction + still returns sensible codes: + + @retval EFI_SUCCESS The status code has been processed; eithe= r as + a no-op, due to filtering, or by formatti= ng it + to the system console. + + @retval EFI_INVALID_PARAMETER Unknown or malformed contents have been + detected in EFI_STATUS_CODE_DATA, or in t= he + EDKII_OS_LOADER_DETAIL payload within + EFI_STATUS_CODE_DATA. +**/ +STATIC +EFI_STATUS +EFIAPI +HandleStatusCode ( + IN EFI_STATUS_CODE_TYPE CodeType, + IN EFI_STATUS_CODE_VALUE Value, + IN UINT32 Instance, + IN EFI_GUID *CallerId, + IN EFI_STATUS_CODE_DATA *Data + ) +{ + EDKII_OS_LOADER_DETAIL *OsLoaderDetail; + UINT8 *VariableSizeData; + CHAR16 *Description; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + BOOLEAN DevPathStringIsDynamic; + CHAR16 *DevPathString; + EFI_STATUS Status; + + // + // Ignore all status codes other than OsLoaderDetail. + // + if (Value !=3D PcdGet32 (PcdDebugCodeOsLoaderDetail)) { + return EFI_SUCCESS; + } + + // + // The status codes we are interested in are emitted by UefiBootManagerL= ib. + // UefiBootManagerLib is built into several drivers and applications, e.= g. + // BdsDxe and UiApp. Process (i.e., print to the console) only those sta= tus + // codes that come from BdsDxe; that is, from the driver module that this + // PlatformBootManagerLib instance is also built into. + // + if (!CompareGuid (CallerId, &gEfiCallerIdGuid)) { + return EFI_SUCCESS; + } + + // + // Sanity checks -- now that Value has been validated, we have expectati= ons + // to enforce. + // + if ((Data =3D=3D NULL) || + (Data->HeaderSize < sizeof *Data) || + (Data->Size < sizeof *OsLoaderDetail) || + (!CompareGuid (&Data->Type, + &gEdkiiStatusCodeDataTypeOsLoaderDetailGuid))) { + DEBUG (( + DEBUG_ERROR, + "%a: unknown or malformed data for status code 0x%x\n", + __FUNCTION__, + PcdGet32 (PcdDebugCodeOsLoaderDetail) + )); + return EFI_INVALID_PARAMETER; + } + + OsLoaderDetail =3D (EDKII_OS_LOADER_DETAIL *)( + (UINT8 *)Data + Data->HeaderSize + ); + + // + // More sanity checks. The additions on the RHS are carried out in UINTN= and + // cannot overflow. + // + if (Data->Size < (sizeof *OsLoaderDetail + + OsLoaderDetail->DescriptionSize + + OsLoaderDetail->DevicePathSize)) { + DEBUG ((DEBUG_ERROR, "%a: malformed EDKII_OS_LOADER_DETAIL\n", + __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + // + // Extract the known variable size fields from the payload. + // + VariableSizeData =3D (UINT8 *)(OsLoaderDetail + 1); + + Description =3D (CHAR16 *)VariableSizeData; + VariableSizeData +=3D OsLoaderDetail->DescriptionSize; + + DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *)VariableSizeData; + VariableSizeData +=3D OsLoaderDetail->DevicePathSize; + + ASSERT (VariableSizeData - (UINT8 *)OsLoaderDetail <=3D Data->Size); + + // + // Prepare the extracted variable size fields for printing. + // + if (OsLoaderDetail->DescriptionSize =3D=3D 0) { + Description =3D L""; + } + + DevPathStringIsDynamic =3D FALSE; + if (OsLoaderDetail->DevicePathSize =3D=3D 0) { + DevPathString =3D L""; + } else { + DevPathString =3D ConvertDevicePathToText ( + DevicePath, + FALSE, // DisplayOnly + FALSE // AllowShortcuts + ); + if (DevPathString =3D=3D NULL) { + DevPathString =3D L""; + } else { + DevPathStringIsDynamic =3D TRUE; + } + } + + // + // Print the message to the console. + // + switch (OsLoaderDetail->Type) { + case EDKII_OS_LOADER_DETAIL_TYPE_LOAD: + case EDKII_OS_LOADER_DETAIL_TYPE_START: + AsciiPrint ( + "%a: %a Boot%04x \"%s\" from %s\n", + gEfiCallerBaseName, + (OsLoaderDetail->Type =3D=3D EDKII_OS_LOADER_DETAIL_TYPE_LOAD ? + "loading" : + "starting"), + OsLoaderDetail->BootOptionNumber, + Description, + DevPathString + ); + break; + + case EDKII_OS_LOADER_DETAIL_TYPE_LOAD_ERROR: + case EDKII_OS_LOADER_DETAIL_TYPE_START_ERROR: + AsciiPrint ( + "%a: failed to %a Boot%04x \"%s\" from %s: %r\n", + gEfiCallerBaseName, + (OsLoaderDetail->Type =3D=3D EDKII_OS_LOADER_DETAIL_TYPE_LOAD_ERROR ? + "load" : + "start"), + OsLoaderDetail->BootOptionNumber, + Description, + DevPathString, + OsLoaderDetail->Status + ); + break; + + default: + DEBUG ((DEBUG_ERROR, "%a: unknown EDKII_OS_LOADER_DETAIL.Type 0x%x\n", + __FUNCTION__, OsLoaderDetail->Type)); + Status =3D EFI_INVALID_PARAMETER; + goto ReleaseDevPathString; + } + + Status =3D EFI_SUCCESS; + +ReleaseDevPathString: + if (DevPathStringIsDynamic) { + FreePool (DevPathString); + } + return Status; +} + + +/** + Unregister HandleStatusCode() at ExitBootServices(). + + (See EFI_RSC_HANDLER_PROTOCOL in Volume 3 of the Platform Init spec.) + + @param[in] Event Event whose notification function is being invoked. + + @param[in] Context Pointer to EFI_RSC_HANDLER_PROTOCOL, originally look= ed up + when HandleStatusCode() was registered. +**/ +STATIC +VOID +EFIAPI +UnregisterAtExitBootServices ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_RSC_HANDLER_PROTOCOL *StatusCodeRouter; + + StatusCodeRouter =3D Context; + StatusCodeRouter->Unregister (HandleStatusCode); +} + + +/** + Register a status code handler for printing EDKII_OS_LOADER_DETAIL repor= ts to + the console. + + @retval EFI_SUCCESS The status code handler has been successfully + registered. + + @return Error codes propagated from boot services and from + EFI_RSC_HANDLER_PROTOCOL. +**/ +EFI_STATUS +RegisterStatusCodeHandler ( + VOID + ) +{ + EFI_STATUS Status; + EFI_RSC_HANDLER_PROTOCOL *StatusCodeRouter; + EFI_EVENT ExitBootEvent; + + Status =3D gBS->LocateProtocol (&gEfiRscHandlerProtocolGuid, + NULL /* Registration */, (VOID **)&StatusCodeRouter); + // + // This protocol is provided by the ReportStatusCodeRouterRuntimeDxe dri= ver + // that we build into the firmware image. Given that PlatformBootManager= Lib + // is used as part of BdsDxe, and BDS Entry occurs after all DXE drivers= have + // been dispatched, the EFI_RSC_HANDLER_PROTOCOL is available at this po= int. + // + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Register the handler callback. + // + Status =3D StatusCodeRouter->Register (HandleStatusCode, TPL_CALLBACK); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: failed to register status code handler: %r\n= ", + __FUNCTION__, Status)); + return Status; + } + + // + // Status code reporting and routing/handling extend into OS runtime. Si= nce + // we don't want our handler to survive the BDS phase, we have to unregi= ster + // the callback at ExitBootServices(). (See EFI_RSC_HANDLER_PROTOCOL in + // Volume 3 of the Platform Init spec.) + // + Status =3D gBS->CreateEvent ( + EVT_SIGNAL_EXIT_BOOT_SERVICES, // Type + TPL_CALLBACK, // NotifyTpl + UnregisterAtExitBootServices, // NotifyFunction + StatusCodeRouter, // NotifyContext + &ExitBootEvent // Event + ); + if (EFI_ERROR (Status)) { + // + // We have to unregister the callback right now, and fail the function. + // + DEBUG ((DEBUG_ERROR, "%a: failed to create ExitBootServices() event: %= r\n", + __FUNCTION__, Status)); + StatusCodeRouter->Unregister (HandleStatusCode); + return Status; + } + + return EFI_SUCCESS; +} --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 07:57:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1511395150471559.5198699430019; Wed, 22 Nov 2017 15:59:10 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 41F962035BB20; Wed, 22 Nov 2017 15:54:50 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (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 892EF2035BB20 for ; Wed, 22 Nov 2017 15:54:47 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 099D74ACBB; Wed, 22 Nov 2017 23:59:04 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-45.rdu2.redhat.com [10.10.120.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id 840144A1; Wed, 22 Nov 2017 23:59:02 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Nov 2017 00:58:49 +0100 Message-Id: <20171122235849.4177-6-lersek@redhat.com> In-Reply-To: <20171122235849.4177-1-lersek@redhat.com> References: <20171122235849.4177-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 22 Nov 2017 23:59:04 +0000 (UTC) Subject: [edk2] [PATCH 5/5] OvmfPkg: disable EFI_DEBUG_CODE reporting in RELEASE builds X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Jordan Justen , Anthony Perard , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Ruiyu Ni Cc: Anthony Perard Cc: Julien Grall Ref: https://bugzilla.redhat.com/show_bug.cgi?id=3D1515418 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- OvmfPkg/OvmfPkgIa32.dsc | 7 +++++++ OvmfPkg/OvmfPkgIa32X64.dsc | 7 +++++++ OvmfPkg/OvmfPkgX64.dsc | 7 +++++++ 3 files changed, 21 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 7ccb61147f27..c5bd9aa4dc6c 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -420,25 +420,32 @@ [PcdsFixedAtBuild] gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0xe000 !endif !if $(FD_SIZE_IN_KB) =3D=3D 4096 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x40000 !endif =20 gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0 =20 + # REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED 0x01 + # REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED 0x02 + # REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED 0x04 +!if $(TARGET) =3D=3D RELEASE + gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x03 +!else gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07 +!endif =20 # DEBUG_INIT 0x00000001 // Initialization # DEBUG_WARN 0x00000002 // Warnings # DEBUG_LOAD 0x00000004 // Load events # DEBUG_FS 0x00000008 // EFI File system # DEBUG_POOL 0x00000010 // Alloc & Free (pool) # DEBUG_PAGE 0x00000020 // Alloc & Free (page) # DEBUG_INFO 0x00000040 // Informational debug messages # DEBUG_DISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers # DEBUG_VARIABLE 0x00000100 // Variable # DEBUG_BM 0x00000400 // Boot Manager # DEBUG_BLKIO 0x00001000 // BlkIo Driver diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 237ec71b5ec0..6e39896b318f 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -425,25 +425,32 @@ [PcdsFixedAtBuild] gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0xe000 !endif !if $(FD_SIZE_IN_KB) =3D=3D 4096 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x40000 !endif =20 gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0 =20 + # REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED 0x01 + # REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED 0x02 + # REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED 0x04 +!if $(TARGET) =3D=3D RELEASE + gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x03 +!else gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07 +!endif =20 # DEBUG_INIT 0x00000001 // Initialization # DEBUG_WARN 0x00000002 // Warnings # DEBUG_LOAD 0x00000004 // Load events # DEBUG_FS 0x00000008 // EFI File system # DEBUG_POOL 0x00000010 // Alloc & Free (pool) # DEBUG_PAGE 0x00000020 // Alloc & Free (page) # DEBUG_INFO 0x00000040 // Informational debug messages # DEBUG_DISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers # DEBUG_VARIABLE 0x00000100 // Variable # DEBUG_BM 0x00000400 // Boot Manager # DEBUG_BLKIO 0x00001000 // BlkIo Driver diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index a5047fa38e61..2e2d4d584429 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -425,25 +425,32 @@ [PcdsFixedAtBuild] gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0xe000 !endif !if $(FD_SIZE_IN_KB) =3D=3D 4096 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x8400 gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x40000 !endif =20 gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0 =20 + # REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED 0x01 + # REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED 0x02 + # REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED 0x04 +!if $(TARGET) =3D=3D RELEASE + gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x03 +!else gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07 +!endif =20 # DEBUG_INIT 0x00000001 // Initialization # DEBUG_WARN 0x00000002 // Warnings # DEBUG_LOAD 0x00000004 // Load events # DEBUG_FS 0x00000008 // EFI File system # DEBUG_POOL 0x00000010 // Alloc & Free (pool) # DEBUG_PAGE 0x00000020 // Alloc & Free (page) # DEBUG_INFO 0x00000040 // Informational debug messages # DEBUG_DISPATCH 0x00000080 // PEI/DXE/SMM Dispatchers # DEBUG_VARIABLE 0x00000100 // Variable # DEBUG_BM 0x00000400 // Boot Manager # DEBUG_BLKIO 0x00001000 // BlkIo Driver --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel