From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 059AB207E5403 for ; Fri, 25 May 2018 04:11:03 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 25 May 2018 04:11:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,439,1520924400"; d="scan'208";a="58436113" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by fmsmga001.fm.intel.com with ESMTP; 25 May 2018 04:11:03 -0700 Received: from fmsmsx122.amr.corp.intel.com (10.18.125.37) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 25 May 2018 04:11:02 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx122.amr.corp.intel.com (10.18.125.37) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 25 May 2018 04:11:02 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.79]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.96]) with mapi id 14.03.0319.002; Fri, 25 May 2018 19:11:00 +0800 From: "Zeng, Star" To: "Kinney, Michael D" , "edk2-devel@lists.01.org" CC: Sean Brogan , "Dong, Eric" , "Zeng, Star" Thread-Topic: [Patch v3 2/3] MdeModulePkg: Add DisplayUpdateProgressLib instances Thread-Index: AQHT8+/c3wZxG/A+6E+B3dxCYXNtdKRASUZw Date: Fri, 25 May 2018 11:10:59 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103BAF1143@shsmsx102.ccr.corp.intel.com> References: <20180525061552.19840-1-michael.d.kinney@intel.com> <20180525061552.19840-3-michael.d.kinney@intel.com> In-Reply-To: <20180525061552.19840-3-michael.d.kinney@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch v3 2/3] MdeModulePkg: Add DisplayUpdateProgressLib instances X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 May 2018 11:11:04 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Star Zeng Thanks, Star -----Original Message----- From: Kinney, Michael D=20 Sent: Friday, May 25, 2018 2:16 PM To: edk2-devel@lists.01.org Cc: Sean Brogan ; Zeng, Star ; Dong, Eric Subject: [Patch v3 2/3] MdeModulePkg: Add DisplayUpdateProgressLib instance= s https://bugzilla.tianocore.org/show_bug.cgi?id=3D801 Based on content from the following branch/commits: https://github.com/Microsoft/MS_UEFI/tree/share/MsCapsuleSupport Add DisplayUpdateProgressLib instances for text consoles and graphical cons= oles. Cc: Sean Brogan Cc: Star Zeng Cc: Eric Dong Signed-off-by: Michael D Kinney Contributed-under: TianoCore Contribution Agreement 1.1 --- .../DisplayUpdateProgressLibGraphics.c | 475 +++++++++++++++++= ++++ .../DisplayUpdateProgressLibGraphics.inf | 60 +++ .../DisplayUpdateProgressLibGraphics.uni | 18 + .../DisplayUpdateProgressLibText.c | 174 ++++++++ .../DisplayUpdateProgressLibText.inf | 53 +++ .../DisplayUpdateProgressLibText.uni | 18 + MdeModulePkg/MdeModulePkg.dsc | 3 + 7 files changed, 801 insertions(+) create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/D= isplayUpdateProgressLibGraphics.c create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/D= isplayUpdateProgressLibGraphics.inf create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/D= isplayUpdateProgressLibGraphics.uni create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressLibText/Displ= ayUpdateProgressLibText.c create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressLibText/Displ= ayUpdateProgressLibText.inf create mode 100644 MdeModulePkg/Library/DisplayUpdateProgressLibText/Displ= ayUpdateProgressLibText.uni diff --git a/MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayU= pdateProgressLibGraphics.c b/MdeModulePkg/Library/DisplayUpdateProgressLibG= raphics/DisplayUpdateProgressLibGraphics.c new file mode 100644 index 0000000000..007522cea0 --- /dev/null +++ b/MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdat +++ eProgressLibGraphics.c @@ -0,0 +1,475 @@ +/** @file + Provides services to display completion progress of a firmware update=20 +on a + graphical console that supports the Graphics Output Protocol. + + Copyright (c) 2016, Microsoft Corporation. All rights reserved.
=20 + Copyright (c) 2018, Intel Corporation. All rights reserved.
+ + Redistribution and use in source and binary forms, with or without =20 + modification, are permitted provided that the following conditions are me= t: + 1. Redistributions of source code must retain the above copyright=20 + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright=20 + notice, this list of conditions and the following disclaimer in the=20 + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=20 + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT=20 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A = PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR=20 + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR=20 + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF=20 + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR=20 + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,=20 + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE =20 + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF= ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include +#include +#include #include=20 + +#include +#include +#include + +#include +#include + +// +// Values in percent of of logo height. +// +#define LOGO_BOTTOM_PADDING 20 +#define PROGRESS_BLOCK_HEIGHT 10 + +// +// Graphics Output Protocol instance to display progress bar //=20 +EFI_GRAPHICS_OUTPUT_PROTOCOL *mGop =3D NULL; + +// +// Set to 100 percent so it is reset on first call. +// +UINTN mPreviousProgress =3D 100; + +// +// Display coordinates for the progress bar. +// +UINTN mStartX =3D 0; +UINTN mStartY =3D 0; + +// +// Width and height of the progress bar. +// +UINTN mBlockWidth =3D 0; +UINTN mBlockHeight =3D 0; + +// +// GOP bitmap of the progress bar. Initialized on every new progress of=20 +100% // EFI_GRAPHICS_OUTPUT_BLT_PIXEL *mBlockBitmap; + +// +// GOP bitmap of the progress bar backround. Initialized once. +// +EFI_GRAPHICS_OUTPUT_BLT_PIXEL *mProgressBarBackground; + +// +// Default mask used to detect the left, right , top, and bottom of=20 +logo. Only // green and blue pixels are used for logo detection. +// +const EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION mLogoDetectionColorMask =3D { + { + 0xFF, // Blue + 0xFF, // Green + 0x00, // Red + 0x00 // Reserved + } +}; + +// +// Background color of progress bar. Grey. +// +const EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION mProgressBarBackgroundColor=20 +=3D { + { + 0x80, // Blue + 0x80, // Green + 0x80, // Red + 0x00 // Reserved + } +}; + +// +// Default color of progress completion. White. +// +const EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION mProgressBarDefaultColor =3D { + { + 0xFF, // Blue + 0xFF, // Green + 0xFF, // Red + 0x00 // Reserved + } +}; + +// +// Set to TRUE if a valid Graphics Output Protocol is found and the=20 +progress // bar fits under the boot logo using the current graphics mode. +// +BOOLEAN mGraphicsGood =3D FALSE; + +/* + Internal function used to find the bounds of the white logo (on black=20 +or + red background). + + These bounds are then computed to find the block size, 0%, 100%, etc. + +*/ +VOID +FindDim ( + VOID + ) +{ + EFI_STATUS Status; + INTN LogoX; + INTN LogoStartX; + INTN LogoEndX; + INTN LogoY; + INTN LogoStartY; + INTN LogoEndY; + UINTN OffsetX; // Logo screen coordin= ate + UINTN OffsetY; // Logo screen coordin= ate + UINTN Width; // Width of logo in pi= xels + UINTN Height; // Height of logo in p= ixels + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Logo; + EDKII_BOOT_LOGO2_PROTOCOL *BootLogo; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *Pixel; + + Logo =3D NULL; + BootLogo =3D NULL; + + // + // Return if a Graphics Output Protocol ha snot been found. + // + if (mGop =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "No GOP found. No progress bar support. \n")); + return; + } + + // + // Get boot logo protocol so we know where on the screen to grab // =20 + Status =3D gBS->LocateProtocol ( + &gEdkiiBootLogo2ProtocolGuid, + NULL, + (VOID **)&BootLogo + ); + if ((BootLogo =3D=3D NULL) || (EFI_ERROR (Status))) { + DEBUG ((DEBUG_ERROR, "Failed to locate gEdkiiBootLogo2ProtocolGuid. N= o Progress bar support. \n", Status)); + return; + } + + // + // Get logo location and size + // + Status =3D BootLogo->GetBootLogo ( + BootLogo, + &Logo, + &OffsetX, + &OffsetY, + &Width, + &Height + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed to Get Boot Logo Status =3D %r. No Progr= ess bar support. \n", Status)); + return; + } + + // + // Within logo buffer find where the actual logo starts/ends // =20 + LogoEndX =3D 0; LogoEndY =3D 0; + + // + // Find left side of logo in logo coordinates // for (LogoX =3D 0,=20 + LogoStartX =3D Width; LogoX < LogoStartX; LogoX++) { + Pixel =3D (EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *)(Logo + LogoX); + for (LogoY =3D 0; LogoY < (INTN)Height; LogoY++) { + if ((Pixel->Raw & mLogoDetectionColorMask.Raw) !=3D 0x0) { + LogoStartX =3D LogoX; + // + // For loop searches from right side back to this column. + // + LogoEndX =3D LogoX; + DEBUG ((DEBUG_INFO, "StartX found at (%d, %d) Color is: 0x%X \n", = LogoX, LogoY, Pixel->Raw)); + break; + } + Pixel =3D Pixel + Width; + } + } + + // + // Find right side of logo + // + for (LogoX =3D Width - 1; LogoX >=3D LogoEndX; LogoX--) { + Pixel =3D (EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *)(Logo + LogoX); + for (LogoY =3D 0; LogoY < (INTN)Height; LogoY++) { + if ((Pixel->Raw & mLogoDetectionColorMask.Raw) !=3D 0x0) { + LogoEndX =3D LogoX; + DEBUG ((DEBUG_INFO, "EndX found at (%d, %d) Color is: 0x%X \n", Lo= goX, LogoY, Pixel->Raw)); + break; + } + Pixel =3D Pixel + Width; + } + } + + // + // Compute mBlockWidth + // + mBlockWidth =3D ((LogoEndX - LogoStartX) + 99) / 100; + + // + // Adjust mStartX based on block width so it is centered under logo =20 + // mStartX =3D LogoStartX + OffsetX - (((mBlockWidth * 100) - (LogoEndX= =20 + - LogoStartX)) / 2); DEBUG ((DEBUG_INFO, "mBlockWidth set to 0x%X\n",=20 + mBlockWidth)); DEBUG ((DEBUG_INFO, "mStartX set to 0x%X\n",=20 + mStartX)); + + // + // Find the top of the logo + // + for (LogoY =3D 0, LogoStartY =3D Height; LogoY < LogoStartY; LogoY++) { + Pixel =3D (EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *)(Logo + (Width * Logo= Y)); + for (LogoX =3D 0; LogoX < (INTN)Width; LogoX++) { + //not black or red + if ((Pixel->Raw & mLogoDetectionColorMask.Raw) !=3D 0x0) { + LogoStartY =3D LogoY; + LogoEndY =3D LogoY; //for next loop will search from bottom side b= ack to this row. + DEBUG ((DEBUG_INFO, "StartY found at (%d, %d) Color is: 0x%X \n", = LogoX, LogoY, Pixel->Raw)); + break; + } + Pixel++; + } + } + + // + // Find the bottom of the logo + // + for (LogoY =3D Height - 1; LogoY >=3D LogoEndY; LogoY--) { + Pixel =3D (EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *)(Logo + (Width * Logo= Y)); + for (LogoX =3D 0; LogoX < (INTN)Width; LogoX++) { + if ((Pixel->Raw & mLogoDetectionColorMask.Raw) !=3D 0x0) { + LogoEndY =3D LogoY; + DEBUG ((DEBUG_INFO, "EndY found at (%d, %d) Color is: 0x%X \n", Lo= goX, LogoY, Pixel->Raw)); + break; + } + Pixel++; + } + } + + // + // Compute bottom padding (distance between logo bottom and progress=20 + bar) // mStartY =3D (((LogoEndY - LogoStartY) * LOGO_BOTTOM_PADDING) /= =20 + 100) + LogoEndY + OffsetY; + + // + // Compute progress bar height + // + mBlockHeight =3D (((LogoEndY - LogoStartY) * PROGRESS_BLOCK_HEIGHT) /=20 + 100); + + DEBUG ((DEBUG_INFO, "mBlockHeight set to 0x%X\n", mBlockHeight)); + + // + // Create progress bar background (one time init). + // + mProgressBarBackground =3D AllocatePool (mBlockWidth * 100 *=20 + mBlockHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); if (mProgressBar= Background =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "Failed to allocate progress bar background\n")); + return; + } + + // + // Fill the progress bar with the background color // + SetMem32 ( + mProgressBarBackground, + (mBlockWidth * 100 * mBlockHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PI= XEL)), + mProgressBarBackgroundColor.Raw + ); + + // + // Allocate mBlockBitmap + // + mBlockBitmap =3D AllocatePool (mBlockWidth * mBlockHeight * sizeof=20 + (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); if (mBlockBitmap =3D=3D NULL) { + FreePool (mProgressBarBackground); + DEBUG ((DEBUG_ERROR, "Failed to allocate block\n")); + return; + } + + // + // Check screen width and height and make sure it fits. + // + if ((mBlockHeight > Height) || (mBlockWidth > Width) || (mBlockHeight < = 1) || (mBlockWidth < 1)) { + DEBUG ((DEBUG_ERROR, "DisplayUpdateProgressLib - Progress - Failed to = get valid width and height.\n")); + DEBUG ((DEBUG_ERROR, "DisplayUpdateProgressLib - Progress - mBlockHeig= ht: 0x%X mBlockWidth: 0x%X.\n", mBlockHeight, mBlockWidth)); + FreePool (mProgressBarBackground); + FreePool (mBlockBitmap); + return; + } + + mGraphicsGood =3D TRUE; +} + +/** + Function indicates the current completion progress of a firmware update. + Platform may override with its own specific function. + + @param[in] Completion A value between 0 and 100 indicating the current + completion progress of a firmware update. This + value must the the same or higher than previous + calls to this service. The first call of 0 or a + value of 0 after reaching a value of 100 resets + the progress indicator to 0. + @param[in] Color Color of the progress indicator. Only used when + Completion is 0 to set the color of the progress + indicator. If Color is NULL, then the default co= lor + is used. + + @retval EFI_SUCCESS Progress displayed successfully. + @retval EFI_INVALID_PARAMETER Completion is not in range 0..100. + @retval EFI_INVALID_PARAMETER Completion is less than Completion value = from + a previous call to this service. + @retval EFI_NOT_READY The device used to indicate progress is n= ot + available. +**/ +EFI_STATUS +EFIAPI +DisplayUpdateProgress ( + IN UINTN Completion, + IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *Color OPTIONAL + ) +{ + EFI_STATUS Status; + UINTN PreX; + UINTN Index; + + // + // Check range + // + if (Completion > 100) { + return EFI_INVALID_PARAMETER; + } + + // + // Check to see if this Completion percentage has already been=20 + displayed // if (Completion =3D=3D mPreviousProgress) { + return EFI_SUCCESS; + } + + // + // Find Graphics Output Protocol if not already set. 1 time. + // + if (mGop =3D=3D NULL) { + Status =3D gBS->HandleProtocol ( + gST->ConsoleOutHandle, + &gEfiGraphicsOutputProtocolGuid, + (VOID**)&mGop + ); + if (EFI_ERROR (Status)) { + Status =3D gBS->LocateProtocol (&gEfiGraphicsOutputProtocolGuid, NUL= L, (VOID **)&mGop); + if (EFI_ERROR (Status)) { + mGop =3D NULL; + DEBUG ((DEBUG_ERROR, "Show Progress Function could not locate GOP.= Status =3D %r\n", Status)); + return EFI_NOT_READY; + } + } + + // + // Run once + // + FindDim (); + } + + // + // Make sure a valid start, end, and size info are available (find=20 + the Logo) // if (!mGraphicsGood) { + DEBUG ((DEBUG_INFO, "Graphics Not Good. Not doing any onscreen visual= display\n")); + return EFI_NOT_READY; + } + + // + // Do special init on first call of each progress session // if=20 + (mPreviousProgress =3D=3D 100) { + // + // Draw progress bar background + // + mGop->Blt ( + mGop, + mProgressBarBackground, + EfiBltBufferToVideo, + 0, + 0, + mStartX, + mStartY, + (mBlockWidth * 100), + mBlockHeight, + 0 + ); + + DEBUG ((DEBUG_VERBOSE, "Color is 0x%X\n", + (Color =3D=3D NULL) ? mProgressBarDefaultColor.Raw : Color->Raw + )); + + // + // Update block bitmap with correct color + // + SetMem32 ( + mBlockBitmap, + (mBlockWidth * mBlockHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)= ), + (Color =3D=3D NULL) ? mProgressBarDefaultColor.Raw : Color->Raw + ); + + // + // Clear previous + // + mPreviousProgress =3D 0; + } + + // + // Can not update progress bar if Completion is less than previous =20 + // if (Completion < mPreviousProgress) { + DEBUG ((DEBUG_WARN, "WARNING: Completion (%d) should not be lesss than= Previous (%d)!!!\n", Completion, mPreviousProgress)); + return EFI_INVALID_PARAMETER; + } + + PreX =3D ((mPreviousProgress * mBlockWidth) + mStartX); for (Index =3D= =20 + 0; Index < (Completion - mPreviousProgress); Index++) { + // + // Show progress by coloring new area + // + mGop->Blt ( + mGop, + mBlockBitmap, + EfiBltBufferToVideo, + 0, + 0, + PreX, + mStartY, + mBlockWidth, + mBlockHeight, + 0 + ); + PreX +=3D mBlockWidth; + } + + mPreviousProgress =3D Completion; + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayU= pdateProgressLibGraphics.inf b/MdeModulePkg/Library/DisplayUpdateProgressLi= bGraphics/DisplayUpdateProgressLibGraphics.inf new file mode 100644 index 0000000000..ada6076770 --- /dev/null +++ b/MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdat +++ eProgressLibGraphics.inf @@ -0,0 +1,60 @@ +## @file +# Provides services to display completion progress of a firmware=20 +update on a # graphical console that supports the Graphics Output Protoco= l. +# +# Copyright (c) 2016, Microsoft Corporation, All rights reserved.
=20 +# Copyright (c) 2018, Intel Corporation. All rights reserved.
# # =20 +Redistribution and use in source and binary forms, with or without # =20 +modification, are permitted provided that the following conditions are met= : +# 1. Redistributions of source code must retain the above copyright=20 +notice, # this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright=20 +notice, # this list of conditions and the following disclaimer in the=20 +documentation # and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=20 +"AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT=20 +LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A= PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR=20 +ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR=20 +CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF=20 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR=20 +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # =20 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING=20 +NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFT= WARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DisplayUpdateProgressLibGraphics + MODULE_UNI_FILE =3D DisplayUpdateProgressLibGraphics.uni + FILE_GUID =3D 319E9E37-B2D6-4699-90F3-B8B72B6D4CBD + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D DisplayUpdateProgressLib|DXE_DRIVER UEFI_DRIVER UEFI= _APPLICATION + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 IPF EBC +# + +[Sources] + DisplayUpdateProgressLibGraphics.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + MemoryAllocationLib + UefiBootServicesTableLib + BaseLib + UefiLib + +[Protocols] + gEfiGraphicsOutputProtocolGuid # CONSUMES + gEdkiiBootLogo2ProtocolGuid # CONSUMES diff --git a/MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayU= pdateProgressLibGraphics.uni b/MdeModulePkg/Library/DisplayUpdateProgressLi= bGraphics/DisplayUpdateProgressLibGraphics.uni new file mode 100644 index 0000000000..d7da641338 --- /dev/null +++ b/MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdat +++ eProgressLibGraphics.uni @@ -0,0 +1,18 @@ +// /** @file +// Provides services to display completion progress of a firmware=20 +update on a // graphical console that supports the Graphics Output Protoc= ol. +// +// Copyright (c) 2018, Intel Corporation. All rights reserved.
//=20 +// This program and the accompanying materials // are licensed and made=20 +available under the terms and conditions of the BSD License // which=20 +accompanies this distribution. The full text of the license may be=20 +found at // http://opensource.org/licenses/bsd-license.php +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"=20 +BASIS, // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRES= S OR IMPLIED. +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "Provides services to dis= play completion progress of a firmware update on a graphical console that s= upports the Graphics Output Protocol." + +#string STR_MODULE_DESCRIPTION #language en-US "Provides services to dis= play completion progress of a firmware update on a graphical console that s= upports the Graphics Output Protocol." diff --git a/MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdat= eProgressLibText.c b/MdeModulePkg/Library/DisplayUpdateProgressLibText/Disp= layUpdateProgressLibText.c new file mode 100644 index 0000000000..7aca8b89d0 --- /dev/null +++ b/MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdatePro +++ gressLibText.c @@ -0,0 +1,174 @@ +/** @file + Provides services to display completion progress of a firmware update=20 +on a + text console. + + Copyright (c) 2016, Microsoft Corporation. All rights reserved.
=20 + Copyright (c) 2018, Intel Corporation. All rights reserved.
+ + Redistribution and use in source and binary forms, with or without =20 + modification, are permitted provided that the following conditions are me= t: + 1. Redistributions of source code must retain the above copyright=20 + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright=20 + notice, this list of conditions and the following disclaimer in the=20 + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=20 + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT=20 + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A = PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR=20 + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR=20 + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF=20 + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR=20 + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,=20 + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE =20 + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF= ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include +#include +#include +#include + +// +// Control Style. Set to 100 so it is reset on first call. +// +UINTN mPreviousProgress =3D 100; + +// +// Text foreground color of progress bar // UINTN =20 +mProgressBarForegroundColor; + +/** + Function indicates the current completion progress of a firmware update. + Platform may override with its own specific function. + + @param[in] Completion A value between 0 and 100 indicating the current + completion progress of a firmware update. This + value must the the same or higher than previous + calls to this service. The first call of 0 or a + value of 0 after reaching a value of 100 resets + the progress indicator to 0. + @param[in] Color Color of the progress indicator. Only used when + Completion is 0 to set the color of the progress + indicator. If Color is NULL, then the default co= lor + is used. + + @retval EFI_SUCCESS Progress displayed successfully. + @retval EFI_INVALID_PARAMETER Completion is not in range 0..100. + @retval EFI_INVALID_PARAMETER Completion is less than Completion value = from + a previous call to this service. + @retval EFI_NOT_READY The device used to indicate progress is n= ot + available. +**/ +EFI_STATUS +EFIAPI +DisplayUpdateProgress ( + IN UINTN Completion, + IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *Color OPTIONAL + ) +{ + UINTN Index; + UINTN CurrentAttribute; + + // + // Check range + // + if (Completion > 100) { + return EFI_INVALID_PARAMETER; + } + + // + // Check to see if this Completion percentage has already been=20 + displayed // if (Completion =3D=3D mPreviousProgress) { + return EFI_SUCCESS; + } + + // + // Do special init on first call of each progress session // if=20 + (mPreviousProgress =3D=3D 100) { + Print (L"\n"); + + // + // Convert pixel color to text foreground color + // + if (Color =3D=3D NULL) { + mProgressBarForegroundColor =3D EFI_WHITE; + } else { + mProgressBarForegroundColor =3D EFI_BLACK; + if (Color->Pixel.Blue >=3D 0x40) { + mProgressBarForegroundColor |=3D EFI_BLUE; + } + if (Color->Pixel.Green >=3D 0x40) { + mProgressBarForegroundColor |=3D EFI_GREEN; + } + if (Color->Pixel.Red >=3D 0x40) { + mProgressBarForegroundColor |=3D EFI_RED; + } + if (Color->Pixel.Blue >=3D 0xC0 || Color->Pixel.Green >=3D 0xC0 || C= olor->Pixel.Red >=3D 0xC0) { + mProgressBarForegroundColor |=3D EFI_BRIGHT; + } + if (mProgressBarForegroundColor =3D=3D EFI_BLACK) { + mProgressBarForegroundColor =3D EFI_WHITE; + } + } + + // + // Clear previous + // + mPreviousProgress =3D 0; + } + + // + // Can not update progress bar if Completion is less than previous =20 + // if (Completion < mPreviousProgress) { + DEBUG ((DEBUG_WARN, "WARNING: Completion (%d) should not be lesss than= Previous (%d)!!!\n", Completion, mPreviousProgress)); + return EFI_INVALID_PARAMETER; + } + + // + // Save current text color + // + CurrentAttribute =3D (UINTN)gST->ConOut->Mode->Attribute; + + // + // Print progress percentage + // + Print (L"\rUpdate Progress - %3d%% ", Completion); + + // + // Set progress bar color + // + gST->ConOut->SetAttribute ( + gST->ConOut, + EFI_TEXT_ATTR (mProgressBarForegroundColor, EFI_BLACK) + ); + + // + // Print completed portion of progress bar // for (Index =3D 0; Index= =20 + < Completion / 2; Index++) { + Print (L"%c", BLOCKELEMENT_FULL_BLOCK); } + + // + // Restore text color + // + gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute); + + // + // Print remaining portion of progress bar // for (; Index < 50;=20 + Index++) { + Print (L"%c", BLOCKELEMENT_LIGHT_SHADE); } + + mPreviousProgress =3D Completion; + + return EFI_SUCCESS; +} diff --git a/MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdat= eProgressLibText.inf b/MdeModulePkg/Library/DisplayUpdateProgressLibText/Di= splayUpdateProgressLibText.inf new file mode 100644 index 0000000000..c3134439e4 --- /dev/null +++ b/MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdatePro +++ gressLibText.inf @@ -0,0 +1,53 @@ +## @file +# Provides services to display completion progress of a firmware=20 +update on a # text console. +# +# Copyright (c) 2016, Microsoft Corporation, All rights reserved.
=20 +# Copyright (c) 2018, Intel Corporation. All rights reserved.
# # =20 +Redistribution and use in source and binary forms, with or without # =20 +modification, are permitted provided that the following conditions are met= : +# 1. Redistributions of source code must retain the above copyright=20 +notice, # this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright=20 +notice, # this list of conditions and the following disclaimer in the=20 +documentation # and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS=20 +"AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT=20 +LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A= PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR=20 +ANY DIRECT, # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR=20 +CONSEQUENTIAL DAMAGES (INCLUDING, # BUT NOT LIMITED TO, PROCUREMENT OF=20 +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR=20 +BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # =20 +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING=20 +NEGLIGENCE # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFT= WARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DisplayUpdateProgressLibText + MODULE_UNI_FILE =3D DisplayUpdateProgressLibText.uni + FILE_GUID =3D CDEF83AE-1900-4B41-BF47-AAE9BD729CA5 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D DisplayUpdateProgressLib|DXE_DRIVER UEFI_DRIVER UEFI= _APPLICATION + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 IPF EBC +# + +[Sources] + DisplayUpdateProgressLibText.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + DebugLib + UefiBootServicesTableLib + UefiLib diff --git a/MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdat= eProgressLibText.uni b/MdeModulePkg/Library/DisplayUpdateProgressLibText/Di= splayUpdateProgressLibText.uni new file mode 100644 index 0000000000..3c783722bc --- /dev/null +++ b/MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdatePro +++ gressLibText.uni @@ -0,0 +1,18 @@ +// /** @file +// Provides services to display completion progress of a firmware=20 +update on a // text console. +// +// Copyright (c) 2018, Intel Corporation. All rights reserved.
//=20 +// This program and the accompanying materials // are licensed and made=20 +available under the terms and conditions of the BSD License // which=20 +accompanies this distribution. The full text of the license may be=20 +found at // http://opensource.org/licenses/bsd-license.php +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"=20 +BASIS, // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRES= S OR IMPLIED. +// +// **/ + +#string STR_MODULE_ABSTRACT #language en-US "Provides services to dis= play completion progress of a firmware update on a text console." + +#string STR_MODULE_DESCRIPTION #language en-US "Provides services to dis= play completion progress of a firmware update on a text console." diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc = index ec24a50c7d..b4e8a703af 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -108,6 +108,7 @@ [LibraryClasses] CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf BmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.i= nf SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf + =20 + DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLib + Graphics/DisplayUpdateProgressLibGraphics.inf =20 [LibraryClasses.EBC.PEIM] IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf @@ -327,6 +328,8 @@ [Components] MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf MdeModulePkg/Library/NonDiscoverableDeviceRegistrationLib/NonDiscoverabl= eDeviceRegistrationLib.inf MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupportLib.inf + =20 + MdeModulePkg/Library/DisplayUpdateProgressLibGraphics/DisplayUpdatePro + gressLibGraphics.inf =20 + MdeModulePkg/Library/DisplayUpdateProgressLibText/DisplayUpdateProgres + sLibText.inf =20 MdeModulePkg/Universal/BdsDxe/BdsDxe.inf MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenuApp.inf -- 2.14.2.windows.3