MdeModulePkg: Add DisplayUpdateProgressLib instances
https://bugzilla.tianocore.org/show_bug.cgi?id=801 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 consoles. Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Star Zeng <star.zeng@intel.com> Cc: Eric Dong <eric.dong@intel.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Contributed-under: TianoCore Contribution Agreement 1.1 Reviewed-by: Star Zeng <star.zeng@intel.com> Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
This commit is contained in:
@ -0,0 +1,174 @@
|
||||
/** @file
|
||||
Provides services to display completion progress of a firmware update on a
|
||||
text console.
|
||||
|
||||
Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 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 ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
**/
|
||||
|
||||
#include <PiDxe.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
#include <Library/UefiLib.h>
|
||||
|
||||
//
|
||||
// Control Style. Set to 100 so it is reset on first call.
|
||||
//
|
||||
UINTN mPreviousProgress = 100;
|
||||
|
||||
//
|
||||
// Text foreground color of progress bar
|
||||
//
|
||||
UINTN 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 color
|
||||
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 not
|
||||
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 displayed
|
||||
//
|
||||
if (Completion == mPreviousProgress) {
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
//
|
||||
// Do special init on first call of each progress session
|
||||
//
|
||||
if (mPreviousProgress == 100) {
|
||||
Print (L"\n");
|
||||
|
||||
//
|
||||
// Convert pixel color to text foreground color
|
||||
//
|
||||
if (Color == NULL) {
|
||||
mProgressBarForegroundColor = EFI_WHITE;
|
||||
} else {
|
||||
mProgressBarForegroundColor = EFI_BLACK;
|
||||
if (Color->Pixel.Blue >= 0x40) {
|
||||
mProgressBarForegroundColor |= EFI_BLUE;
|
||||
}
|
||||
if (Color->Pixel.Green >= 0x40) {
|
||||
mProgressBarForegroundColor |= EFI_GREEN;
|
||||
}
|
||||
if (Color->Pixel.Red >= 0x40) {
|
||||
mProgressBarForegroundColor |= EFI_RED;
|
||||
}
|
||||
if (Color->Pixel.Blue >= 0xC0 || Color->Pixel.Green >= 0xC0 || Color->Pixel.Red >= 0xC0) {
|
||||
mProgressBarForegroundColor |= EFI_BRIGHT;
|
||||
}
|
||||
if (mProgressBarForegroundColor == EFI_BLACK) {
|
||||
mProgressBarForegroundColor = EFI_WHITE;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Clear previous
|
||||
//
|
||||
mPreviousProgress = 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Can not update progress bar if Completion is less than previous
|
||||
//
|
||||
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 = (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 = 0; Index < 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; Index++) {
|
||||
Print (L"%c", BLOCKELEMENT_LIGHT_SHADE);
|
||||
}
|
||||
|
||||
mPreviousProgress = Completion;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
## @file
|
||||
# Provides services to display completion progress of a firmware update on a
|
||||
# text console.
|
||||
#
|
||||
# Copyright (c) 2016, Microsoft Corporation, All rights reserved.<BR>
|
||||
# Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
# 1. Redistributions of source code must retain the above copyright notice,
|
||||
# this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
# this list of conditions and the following disclaimer in the documentation
|
||||
# and/or other materials provided with the distribution.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 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 ANY DIRECT,
|
||||
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = DisplayUpdateProgressLibText
|
||||
MODULE_UNI_FILE = DisplayUpdateProgressLibText.uni
|
||||
FILE_GUID = CDEF83AE-1900-4B41-BF47-AAE9BD729CA5
|
||||
MODULE_TYPE = DXE_DRIVER
|
||||
VERSION_STRING = 1.0
|
||||
LIBRARY_CLASS = DisplayUpdateProgressLib|DXE_DRIVER UEFI_DRIVER UEFI_APPLICATION
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||
#
|
||||
|
||||
[Sources]
|
||||
DisplayUpdateProgressLibText.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
DebugLib
|
||||
UefiBootServicesTableLib
|
||||
UefiLib
|
@ -0,0 +1,18 @@
|
||||
// /** @file
|
||||
// Provides services to display completion progress of a firmware update on a
|
||||
// text console.
|
||||
//
|
||||
// Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
|
||||
//
|
||||
// This program and the accompanying materials
|
||||
// are licensed and made available under the terms and conditions of the BSD License
|
||||
// which accompanies this distribution. The full text of the license may be found at
|
||||
// http://opensource.org/licenses/bsd-license.php
|
||||
// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
//
|
||||
// **/
|
||||
|
||||
#string STR_MODULE_ABSTRACT #language en-US "Provides services to display completion progress of a firmware update on a text console."
|
||||
|
||||
#string STR_MODULE_DESCRIPTION #language en-US "Provides services to display completion progress of a firmware update on a text console."
|
Reference in New Issue
Block a user