1 | /** @file
|
---|
2 | Provides services to display completion progress of a firmware update on a
|
---|
3 | text console.
|
---|
4 |
|
---|
5 | Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>
|
---|
6 | Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
|
---|
7 |
|
---|
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.
|
---|
15 |
|
---|
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.
|
---|
26 |
|
---|
27 | **/
|
---|
28 |
|
---|
29 | #include <PiDxe.h>
|
---|
30 | #include <Library/DebugLib.h>
|
---|
31 | #include <Library/UefiBootServicesTableLib.h>
|
---|
32 | #include <Library/UefiLib.h>
|
---|
33 |
|
---|
34 | //
|
---|
35 | // Control Style. Set to 100 so it is reset on first call.
|
---|
36 | //
|
---|
37 | UINTN mPreviousProgress = 100;
|
---|
38 |
|
---|
39 | //
|
---|
40 | // Text foreground color of progress bar
|
---|
41 | //
|
---|
42 | UINTN mProgressBarForegroundColor;
|
---|
43 |
|
---|
44 | /**
|
---|
45 | Function indicates the current completion progress of a firmware update.
|
---|
46 | Platform may override with its own specific function.
|
---|
47 |
|
---|
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
|
---|
57 | is used.
|
---|
58 |
|
---|
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
|
---|
64 | available.
|
---|
65 | **/
|
---|
66 | EFI_STATUS
|
---|
67 | EFIAPI
|
---|
68 | DisplayUpdateProgress (
|
---|
69 | IN UINTN Completion,
|
---|
70 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *Color OPTIONAL
|
---|
71 | )
|
---|
72 | {
|
---|
73 | UINTN Index;
|
---|
74 | UINTN CurrentAttribute;
|
---|
75 |
|
---|
76 | //
|
---|
77 | // Check range
|
---|
78 | //
|
---|
79 | if (Completion > 100) {
|
---|
80 | return EFI_INVALID_PARAMETER;
|
---|
81 | }
|
---|
82 |
|
---|
83 | //
|
---|
84 | // Check to see if this Completion percentage has already been displayed
|
---|
85 | //
|
---|
86 | if (Completion == mPreviousProgress) {
|
---|
87 | return EFI_SUCCESS;
|
---|
88 | }
|
---|
89 |
|
---|
90 | //
|
---|
91 | // Do special init on first call of each progress session
|
---|
92 | //
|
---|
93 | if (mPreviousProgress == 100) {
|
---|
94 | Print (L"\n");
|
---|
95 |
|
---|
96 | //
|
---|
97 | // Convert pixel color to text foreground color
|
---|
98 | //
|
---|
99 | if (Color == NULL) {
|
---|
100 | mProgressBarForegroundColor = EFI_WHITE;
|
---|
101 | } else {
|
---|
102 | mProgressBarForegroundColor = EFI_BLACK;
|
---|
103 | if (Color->Pixel.Blue >= 0x40) {
|
---|
104 | mProgressBarForegroundColor |= EFI_BLUE;
|
---|
105 | }
|
---|
106 | if (Color->Pixel.Green >= 0x40) {
|
---|
107 | mProgressBarForegroundColor |= EFI_GREEN;
|
---|
108 | }
|
---|
109 | if (Color->Pixel.Red >= 0x40) {
|
---|
110 | mProgressBarForegroundColor |= EFI_RED;
|
---|
111 | }
|
---|
112 | if (Color->Pixel.Blue >= 0xC0 || Color->Pixel.Green >= 0xC0 || Color->Pixel.Red >= 0xC0) {
|
---|
113 | mProgressBarForegroundColor |= EFI_BRIGHT;
|
---|
114 | }
|
---|
115 | if (mProgressBarForegroundColor == EFI_BLACK) {
|
---|
116 | mProgressBarForegroundColor = EFI_WHITE;
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | //
|
---|
121 | // Clear previous
|
---|
122 | //
|
---|
123 | mPreviousProgress = 0;
|
---|
124 | }
|
---|
125 |
|
---|
126 | //
|
---|
127 | // Can not update progress bar if Completion is less than previous
|
---|
128 | //
|
---|
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;
|
---|
132 | }
|
---|
133 |
|
---|
134 | //
|
---|
135 | // Save current text color
|
---|
136 | //
|
---|
137 | CurrentAttribute = (UINTN)gST->ConOut->Mode->Attribute;
|
---|
138 |
|
---|
139 | //
|
---|
140 | // Print progress percentage
|
---|
141 | //
|
---|
142 | Print (L"\rUpdate Progress - %3d%% ", Completion);
|
---|
143 |
|
---|
144 | //
|
---|
145 | // Set progress bar color
|
---|
146 | //
|
---|
147 | gST->ConOut->SetAttribute (
|
---|
148 | gST->ConOut,
|
---|
149 | EFI_TEXT_ATTR (mProgressBarForegroundColor, EFI_BLACK)
|
---|
150 | );
|
---|
151 |
|
---|
152 | //
|
---|
153 | // Print completed portion of progress bar
|
---|
154 | //
|
---|
155 | for (Index = 0; Index < Completion / 2; Index++) {
|
---|
156 | Print (L"%c", BLOCKELEMENT_FULL_BLOCK);
|
---|
157 | }
|
---|
158 |
|
---|
159 | //
|
---|
160 | // Restore text color
|
---|
161 | //
|
---|
162 | gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);
|
---|
163 |
|
---|
164 | //
|
---|
165 | // Print remaining portion of progress bar
|
---|
166 | //
|
---|
167 | for (; Index < 50; Index++) {
|
---|
168 | Print (L"%c", BLOCKELEMENT_LIGHT_SHADE);
|
---|
169 | }
|
---|
170 |
|
---|
171 | mPreviousProgress = Completion;
|
---|
172 |
|
---|
173 | return EFI_SUCCESS;
|
---|
174 | }
|
---|