]>
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 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
9 | \r | |
10 | **/\r | |
11 | \r | |
12 | #include <PiDxe.h>\r | |
13 | #include <Library/DebugLib.h>\r | |
14 | #include <Library/UefiBootServicesTableLib.h>\r | |
15 | #include <Library/UefiLib.h>\r | |
16 | \r | |
17 | //\r | |
18 | // Control Style. Set to 100 so it is reset on first call.\r | |
19 | //\r | |
20 | UINTN mPreviousProgress = 100;\r | |
21 | \r | |
22 | //\r | |
23 | // Text foreground color of progress bar\r | |
24 | //\r | |
25 | UINTN mProgressBarForegroundColor;\r | |
26 | \r | |
27 | /**\r | |
28 | Function indicates the current completion progress of a firmware update.\r | |
29 | Platform may override with its own specific function.\r | |
30 | \r | |
31 | @param[in] Completion A value between 0 and 100 indicating the current\r | |
32 | completion progress of a firmware update. This\r | |
33 | value must the the same or higher than previous\r | |
34 | calls to this service. The first call of 0 or a\r | |
35 | value of 0 after reaching a value of 100 resets\r | |
36 | the progress indicator to 0.\r | |
37 | @param[in] Color Color of the progress indicator. Only used when\r | |
38 | Completion is 0 to set the color of the progress\r | |
39 | indicator. If Color is NULL, then the default color\r | |
40 | is used.\r | |
41 | \r | |
42 | @retval EFI_SUCCESS Progress displayed successfully.\r | |
43 | @retval EFI_INVALID_PARAMETER Completion is not in range 0..100.\r | |
44 | @retval EFI_INVALID_PARAMETER Completion is less than Completion value from\r | |
45 | a previous call to this service.\r | |
46 | @retval EFI_NOT_READY The device used to indicate progress is not\r | |
47 | available.\r | |
48 | **/\r | |
49 | EFI_STATUS\r | |
50 | EFIAPI\r | |
51 | DisplayUpdateProgress (\r | |
52 | IN UINTN Completion,\r | |
53 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL_UNION *Color OPTIONAL\r | |
54 | )\r | |
55 | {\r | |
56 | UINTN Index;\r | |
57 | UINTN CurrentAttribute;\r | |
58 | \r | |
59 | //\r | |
60 | // Check range\r | |
61 | //\r | |
62 | if (Completion > 100) {\r | |
63 | return EFI_INVALID_PARAMETER;\r | |
64 | }\r | |
65 | \r | |
66 | //\r | |
67 | // Check to see if this Completion percentage has already been displayed\r | |
68 | //\r | |
69 | if (Completion == mPreviousProgress) {\r | |
70 | return EFI_SUCCESS;\r | |
71 | }\r | |
72 | \r | |
73 | //\r | |
74 | // Do special init on first call of each progress session\r | |
75 | //\r | |
76 | if (mPreviousProgress == 100) {\r | |
77 | Print (L"\n");\r | |
78 | \r | |
79 | //\r | |
80 | // Convert pixel color to text foreground color\r | |
81 | //\r | |
82 | if (Color == NULL) {\r | |
83 | mProgressBarForegroundColor = EFI_WHITE;\r | |
84 | } else {\r | |
85 | mProgressBarForegroundColor = EFI_BLACK;\r | |
86 | if (Color->Pixel.Blue >= 0x40) {\r | |
87 | mProgressBarForegroundColor |= EFI_BLUE;\r | |
88 | }\r | |
89 | \r | |
90 | if (Color->Pixel.Green >= 0x40) {\r | |
91 | mProgressBarForegroundColor |= EFI_GREEN;\r | |
92 | }\r | |
93 | \r | |
94 | if (Color->Pixel.Red >= 0x40) {\r | |
95 | mProgressBarForegroundColor |= EFI_RED;\r | |
96 | }\r | |
97 | \r | |
98 | if ((Color->Pixel.Blue >= 0xC0) || (Color->Pixel.Green >= 0xC0) || (Color->Pixel.Red >= 0xC0)) {\r | |
99 | mProgressBarForegroundColor |= EFI_BRIGHT;\r | |
100 | }\r | |
101 | \r | |
102 | if (mProgressBarForegroundColor == EFI_BLACK) {\r | |
103 | mProgressBarForegroundColor = EFI_WHITE;\r | |
104 | }\r | |
105 | }\r | |
106 | \r | |
107 | //\r | |
108 | // Clear previous\r | |
109 | //\r | |
110 | mPreviousProgress = 0;\r | |
111 | }\r | |
112 | \r | |
113 | //\r | |
114 | // Can not update progress bar if Completion is less than previous\r | |
115 | //\r | |
116 | if (Completion < mPreviousProgress) {\r | |
117 | DEBUG ((DEBUG_WARN, "WARNING: Completion (%d) should not be lesss than Previous (%d)!!!\n", Completion, mPreviousProgress));\r | |
118 | return EFI_INVALID_PARAMETER;\r | |
119 | }\r | |
120 | \r | |
121 | //\r | |
122 | // Save current text color\r | |
123 | //\r | |
124 | CurrentAttribute = (UINTN)gST->ConOut->Mode->Attribute;\r | |
125 | \r | |
126 | //\r | |
127 | // Print progress percentage\r | |
128 | //\r | |
129 | Print (L"\rUpdate Progress - %3d%% ", Completion);\r | |
130 | \r | |
131 | //\r | |
132 | // Set progress bar color\r | |
133 | //\r | |
134 | gST->ConOut->SetAttribute (\r | |
135 | gST->ConOut,\r | |
136 | EFI_TEXT_ATTR (mProgressBarForegroundColor, EFI_BLACK)\r | |
137 | );\r | |
138 | \r | |
139 | //\r | |
140 | // Print completed portion of progress bar\r | |
141 | //\r | |
142 | for (Index = 0; Index < Completion / 2; Index++) {\r | |
143 | Print (L"%c", BLOCKELEMENT_FULL_BLOCK);\r | |
144 | }\r | |
145 | \r | |
146 | //\r | |
147 | // Restore text color\r | |
148 | //\r | |
149 | gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);\r | |
150 | \r | |
151 | //\r | |
152 | // Print remaining portion of progress bar\r | |
153 | //\r | |
154 | for ( ; Index < 50; Index++) {\r | |
155 | Print (L"%c", BLOCKELEMENT_LIGHT_SHADE);\r | |
156 | }\r | |
157 | \r | |
158 | mPreviousProgress = Completion;\r | |
159 | \r | |
160 | return EFI_SUCCESS;\r | |
161 | }\r |