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 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
20 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
24 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <Library/DebugLib.h>
31 #include <Library/UefiBootServicesTableLib.h>
32 #include <Library/UefiLib.h>
35 // Control Style. Set to 100 so it is reset on first call.
37 UINTN mPreviousProgress
= 100;
40 // Text foreground color of progress bar
42 UINTN mProgressBarForegroundColor
;
45 Function indicates the current completion progress of a firmware update.
46 Platform may override with its own specific function.
48 @param[in] Completion A value between 0 and 100 indicating the current
49 completion progress of a firmware update. This
50 value must the the same or higher than previous
51 calls to this service. The first call of 0 or a
52 value of 0 after reaching a value of 100 resets
53 the progress indicator to 0.
54 @param[in] Color Color of the progress indicator. Only used when
55 Completion is 0 to set the color of the progress
56 indicator. If Color is NULL, then the default color
59 @retval EFI_SUCCESS Progress displayed successfully.
60 @retval EFI_INVALID_PARAMETER Completion is not in range 0..100.
61 @retval EFI_INVALID_PARAMETER Completion is less than Completion value from
62 a previous call to this service.
63 @retval EFI_NOT_READY The device used to indicate progress is not
68 DisplayUpdateProgress (
70 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION
*Color OPTIONAL
74 UINTN CurrentAttribute
;
79 if (Completion
> 100) {
80 return EFI_INVALID_PARAMETER
;
84 // Check to see if this Completion percentage has already been displayed
86 if (Completion
== mPreviousProgress
) {
91 // Do special init on first call of each progress session
93 if (mPreviousProgress
== 100) {
97 // Convert pixel color to text foreground color
100 mProgressBarForegroundColor
= EFI_WHITE
;
102 mProgressBarForegroundColor
= EFI_BLACK
;
103 if (Color
->Pixel
.Blue
>= 0x40) {
104 mProgressBarForegroundColor
|= EFI_BLUE
;
106 if (Color
->Pixel
.Green
>= 0x40) {
107 mProgressBarForegroundColor
|= EFI_GREEN
;
109 if (Color
->Pixel
.Red
>= 0x40) {
110 mProgressBarForegroundColor
|= EFI_RED
;
112 if (Color
->Pixel
.Blue
>= 0xC0 || Color
->Pixel
.Green
>= 0xC0 || Color
->Pixel
.Red
>= 0xC0) {
113 mProgressBarForegroundColor
|= EFI_BRIGHT
;
115 if (mProgressBarForegroundColor
== EFI_BLACK
) {
116 mProgressBarForegroundColor
= EFI_WHITE
;
123 mPreviousProgress
= 0;
127 // Can not update progress bar if Completion is less than previous
129 if (Completion
< mPreviousProgress
) {
130 DEBUG ((DEBUG_WARN
, "WARNING: Completion (%d) should not be lesss than Previous (%d)!!!\n", Completion
, mPreviousProgress
));
131 return EFI_INVALID_PARAMETER
;
135 // Save current text color
137 CurrentAttribute
= (UINTN
)gST
->ConOut
->Mode
->Attribute
;
140 // Print progress percentage
142 Print (L
"\rUpdate Progress - %3d%% ", Completion
);
145 // Set progress bar color
147 gST
->ConOut
->SetAttribute (
149 EFI_TEXT_ATTR (mProgressBarForegroundColor
, EFI_BLACK
)
153 // Print completed portion of progress bar
155 for (Index
= 0; Index
< Completion
/ 2; Index
++) {
156 Print (L
"%c", BLOCKELEMENT_FULL_BLOCK
);
160 // Restore text color
162 gST
->ConOut
->SetAttribute (gST
->ConOut
, CurrentAttribute
);
165 // Print remaining portion of progress bar
167 for (; Index
< 50; Index
++) {
168 Print (L
"%c", BLOCKELEMENT_LIGHT_SHADE
);
171 mPreviousProgress
= Completion
;