2 Provides services to display completion progress of a firmware update on a
5 Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
6 Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include <Library/DebugLib.h>
14 #include <Library/UefiBootServicesTableLib.h>
15 #include <Library/UefiLib.h>
18 // Control Style. Set to 100 so it is reset on first call.
20 UINTN mPreviousProgress
= 100;
23 // Text foreground color of progress bar
25 UINTN mProgressBarForegroundColor
;
28 Function indicates the current completion progress of a firmware update.
29 Platform may override with its own specific function.
31 @param[in] Completion A value between 0 and 100 indicating the current
32 completion progress of a firmware update. This
33 value must the the same or higher than previous
34 calls to this service. The first call of 0 or a
35 value of 0 after reaching a value of 100 resets
36 the progress indicator to 0.
37 @param[in] Color Color of the progress indicator. Only used when
38 Completion is 0 to set the color of the progress
39 indicator. If Color is NULL, then the default color
42 @retval EFI_SUCCESS Progress displayed successfully.
43 @retval EFI_INVALID_PARAMETER Completion is not in range 0..100.
44 @retval EFI_INVALID_PARAMETER Completion is less than Completion value from
45 a previous call to this service.
46 @retval EFI_NOT_READY The device used to indicate progress is not
51 DisplayUpdateProgress (
53 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION
*Color OPTIONAL
57 UINTN CurrentAttribute
;
62 if (Completion
> 100) {
63 return EFI_INVALID_PARAMETER
;
67 // Check to see if this Completion percentage has already been displayed
69 if (Completion
== mPreviousProgress
) {
74 // Do special init on first call of each progress session
76 if (mPreviousProgress
== 100) {
80 // Convert pixel color to text foreground color
83 mProgressBarForegroundColor
= EFI_WHITE
;
85 mProgressBarForegroundColor
= EFI_BLACK
;
86 if (Color
->Pixel
.Blue
>= 0x40) {
87 mProgressBarForegroundColor
|= EFI_BLUE
;
90 if (Color
->Pixel
.Green
>= 0x40) {
91 mProgressBarForegroundColor
|= EFI_GREEN
;
94 if (Color
->Pixel
.Red
>= 0x40) {
95 mProgressBarForegroundColor
|= EFI_RED
;
98 if ((Color
->Pixel
.Blue
>= 0xC0) || (Color
->Pixel
.Green
>= 0xC0) || (Color
->Pixel
.Red
>= 0xC0)) {
99 mProgressBarForegroundColor
|= EFI_BRIGHT
;
102 if (mProgressBarForegroundColor
== EFI_BLACK
) {
103 mProgressBarForegroundColor
= EFI_WHITE
;
110 mPreviousProgress
= 0;
114 // Can not update progress bar if Completion is less than previous
116 if (Completion
< mPreviousProgress
) {
117 DEBUG ((DEBUG_WARN
, "WARNING: Completion (%d) should not be lesss than Previous (%d)!!!\n", Completion
, mPreviousProgress
));
118 return EFI_INVALID_PARAMETER
;
122 // Save current text color
124 CurrentAttribute
= (UINTN
)gST
->ConOut
->Mode
->Attribute
;
127 // Print progress percentage
129 Print (L
"\rUpdate Progress - %3d%% ", Completion
);
132 // Set progress bar color
134 gST
->ConOut
->SetAttribute (
136 EFI_TEXT_ATTR (mProgressBarForegroundColor
, EFI_BLACK
)
140 // Print completed portion of progress bar
142 for (Index
= 0; Index
< Completion
/ 2; Index
++) {
143 Print (L
"%c", BLOCKELEMENT_FULL_BLOCK
);
147 // Restore text color
149 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
152 // Print remaining portion of progress bar
154 for ( ; Index
< 50; Index
++) {
155 Print (L
"%c", BLOCKELEMENT_LIGHT_SHADE
);
158 mPreviousProgress
= Completion
;