]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Provides services to display completion progress of a firmware update on a\r | |
3 | text console.\r | |
4 | \r | |
5 | Copyright (c) 2016, Microsoft Corporation. All rights reserved.<BR>\r | |
6 | Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>\r | |
7 | \r | |
8 | Redistribution and use in source and binary forms, with or without\r | |
9 | modification, are permitted provided that the following conditions are met:\r | |
10 | 1. Redistributions of source code must retain the above copyright notice,\r | |
11 | this list of conditions and the following disclaimer.\r | |
12 | 2. Redistributions in binary form must reproduce the above copyright notice,\r | |
13 | this list of conditions and the following disclaimer in the documentation\r | |
14 | and/or other materials provided with the distribution.\r | |
15 | \r | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r | |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r | |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r | |
19 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\r | |
20 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r | |
21 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r | |
22 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r | |
23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\r | |
24 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF\r | |
25 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r | |
26 | \r | |
27 | **/\r | |
28 | \r | |
29 | #include <PiDxe.h>\r | |
30 | #include <Library/DebugLib.h>\r | |
31 | #include <Library/UefiBootServicesTableLib.h>\r | |
32 | #include <Library/UefiLib.h>\r | |
33 | \r | |
34 | //\r | |
35 | // Control Style. Set to 100 so it is reset on first call.\r | |
36 | //\r | |
37 | UINTN mPreviousProgress = 100;\r | |
38 | \r | |
39 | //\r | |
40 | // Text foreground color of progress bar\r | |
41 | //\r | |
42 | UINTN mProgressBarForegroundColor;\r | |
43 | \r | |
44 | /**\r | |
45 | Function indicates the current completion progress of a firmware update.\r | |
46 | Platform may override with its own specific function.\r | |
47 | \r | |
48 | @param[in] Completion A value between 0 and 100 indicating the current\r | |
49 | completion progress of a firmware update. This\r | |
50 | value must the the same or higher than previous\r | |
51 | calls to this service. The first call of 0 or a\r | |
52 | value of 0 after reaching a value of 100 resets\r | |
53 | the progress indicator to 0.\r | |
54 | @param[in] Color Color of the progress indicator. Only used when\r | |
55 | Completion is 0 to set the color of the progress\r | |
56 | indicator. If Color is NULL, then the default color\r | |
57 | is used.\r | |
58 | \r | |
59 | @retval EFI_SUCCESS Progress displayed successfully.\r | |
60 | @retval EFI_INVALID_PARAMETER Completion is not in range 0..100.\r | |
61 | @retval EFI_INVALID_PARAMETER Completion is less than Completion value from\r | |
62 | a previous call to this service.\r | |
63 | @retval EFI_NOT_READY The device used to indicate progress is not\r | |
64 | available.\r | |
65 | **/\r | |
66 | EFI_STATUS\r | |
67 | EFIAPI\r | |
68 | DisplayUpdateProgress (\r | |
69 | IN UINTN Completion,\r | |
70 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *Color OPTIONAL\r | |
71 | )\r | |
72 | {\r | |
73 | UINTN Index;\r | |
74 | UINTN CurrentAttribute;\r | |
75 | \r | |
76 | //\r | |
77 | // Check range\r | |
78 | //\r | |
79 | if (Completion > 100) {\r | |
80 | return EFI_INVALID_PARAMETER;\r | |
81 | }\r | |
82 | \r | |
83 | //\r | |
84 | // Check to see if this Completion percentage has already been displayed\r | |
85 | //\r | |
86 | if (Completion == mPreviousProgress) {\r | |
87 | return EFI_SUCCESS;\r | |
88 | }\r | |
89 | \r | |
90 | //\r | |
91 | // Do special init on first call of each progress session\r | |
92 | //\r | |
93 | if (mPreviousProgress == 100) {\r | |
94 | Print (L"\n");\r | |
95 | \r | |
96 | //\r | |
97 | // Convert pixel color to text foreground color\r | |
98 | //\r | |
99 | if (Color == NULL) {\r | |
100 | mProgressBarForegroundColor = EFI_WHITE;\r | |
101 | } else {\r | |
102 | mProgressBarForegroundColor = EFI_BLACK;\r | |
103 | if (Color->Pixel.Blue >= 0x40) {\r | |
104 | mProgressBarForegroundColor |= EFI_BLUE;\r | |
105 | }\r | |
106 | if (Color->Pixel.Green >= 0x40) {\r | |
107 | mProgressBarForegroundColor |= EFI_GREEN;\r | |
108 | }\r | |
109 | if (Color->Pixel.Red >= 0x40) {\r | |
110 | mProgressBarForegroundColor |= EFI_RED;\r | |
111 | }\r | |
112 | if (Color->Pixel.Blue >= 0xC0 || Color->Pixel.Green >= 0xC0 || Color->Pixel.Red >= 0xC0) {\r | |
113 | mProgressBarForegroundColor |= EFI_BRIGHT;\r | |
114 | }\r | |
115 | if (mProgressBarForegroundColor == EFI_BLACK) {\r | |
116 | mProgressBarForegroundColor = EFI_WHITE;\r | |
117 | }\r | |
118 | }\r | |
119 | \r | |
120 | //\r | |
121 | // Clear previous\r | |
122 | //\r | |
123 | mPreviousProgress = 0;\r | |
124 | }\r | |
125 | \r | |
126 | //\r | |
127 | // Can not update progress bar if Completion is less than previous\r | |
128 | //\r | |
129 | if (Completion < mPreviousProgress) {\r | |
130 | DEBUG ((DEBUG_WARN, "WARNING: Completion (%d) should not be lesss than Previous (%d)!!!\n", Completion, mPreviousProgress));\r | |
131 | return EFI_INVALID_PARAMETER;\r | |
132 | }\r | |
133 | \r | |
134 | //\r | |
135 | // Save current text color\r | |
136 | //\r | |
137 | CurrentAttribute = (UINTN)gST->ConOut->Mode->Attribute;\r | |
138 | \r | |
139 | //\r | |
140 | // Print progress percentage\r | |
141 | //\r | |
142 | Print (L"\rUpdate Progress - %3d%% ", Completion);\r | |
143 | \r | |
144 | //\r | |
145 | // Set progress bar color\r | |
146 | //\r | |
147 | gST->ConOut->SetAttribute (\r | |
148 | gST->ConOut,\r | |
149 | EFI_TEXT_ATTR (mProgressBarForegroundColor, EFI_BLACK)\r | |
150 | );\r | |
151 | \r | |
152 | //\r | |
153 | // Print completed portion of progress bar\r | |
154 | //\r | |
155 | for (Index = 0; Index < Completion / 2; Index++) {\r | |
156 | Print (L"%c", BLOCKELEMENT_FULL_BLOCK);\r | |
157 | }\r | |
158 | \r | |
159 | //\r | |
160 | // Restore text color\r | |
161 | //\r | |
162 | gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);\r | |
163 | \r | |
164 | //\r | |
165 | // Print remaining portion of progress bar\r | |
166 | //\r | |
167 | for (; Index < 50; Index++) {\r | |
168 | Print (L"%c", BLOCKELEMENT_LIGHT_SHADE);\r | |
169 | }\r | |
170 | \r | |
171 | mPreviousProgress = Completion;\r | |
172 | \r | |
173 | return EFI_SUCCESS;\r | |
174 | }\r |