TianoCore EDK2 master
Loading...
Searching...
No Matches
VarCheckHiiGenFromHii.c
Go to the documentation of this file.
1
9#include "VarCheckHiiGen.h"
10
15VOID
17 VOID
18 )
19{
20 EFI_STATUS Status;
21 UINTN BufferSize;
22 VOID *Buffer;
23 EFI_PHYSICAL_ADDRESS BufferAddress;
24 EFI_HII_DATABASE_PROTOCOL *HiiDatabase;
25
26 //
27 // Locate HII Database protocol
28 //
29 Status = gBS->LocateProtocol (&gEfiHiiDatabaseProtocolGuid, NULL, (VOID **)&HiiDatabase);
30 if (EFI_ERROR (Status)) {
31 return;
32 }
33
34 //
35 // Call first time with zero buffer length.
36 // Should fail with EFI_BUFFER_TOO_SMALL.
37 //
38 BufferSize = 0;
39 Buffer = NULL;
40 Status = HiiDatabase->ExportPackageLists (HiiDatabase, 0, &BufferSize, Buffer);
41 if (Status == EFI_BUFFER_TOO_SMALL) {
42 //
43 // Allocate buffer to hold the HII Database.
44 //
45 Status = gBS->AllocatePages (AllocateAnyPages, EfiBootServicesData, EFI_SIZE_TO_PAGES (BufferSize), &BufferAddress);
46 ASSERT_EFI_ERROR (Status);
47 Buffer = (VOID *)(UINTN)BufferAddress;
48
49 //
50 // Export HII Database into the buffer.
51 //
52 Status = HiiDatabase->ExportPackageLists (HiiDatabase, 0, &BufferSize, Buffer);
53 ASSERT_EFI_ERROR (Status);
54
55 DEBUG ((DEBUG_INFO, "VarCheckHiiGenDxeFromHii - HII Database exported at 0x%x, size = 0x%x\n", Buffer, BufferSize));
56
57 #ifdef DUMP_HII_DATA
59 DumpHiiDatabase (Buffer, BufferSize);
60 );
61 #endif
62
63 VarCheckParseHiiDatabase (Buffer, BufferSize);
64
65 gBS->FreePages (BufferAddress, EFI_SIZE_TO_PAGES (BufferSize));
66 }
67}
68
69#ifdef DUMP_VAR_CHECK_HII
71 { EFI_IFR_VARSTORE_EFI_OP, "EfiVarStore" },
72 { EFI_IFR_ONE_OF_OP, "OneOf" },
73 { EFI_IFR_CHECKBOX_OP, "CheckBox" },
74 { EFI_IFR_NUMERIC_OP, "Numeric" },
75 { EFI_IFR_ORDERED_LIST_OP, "OrderedList" },
76};
77
86CHAR8 *
87HiiOpCodeToStr (
88 IN UINT8 HiiOpCode
89 )
90{
91 UINTN Index;
92
93 for (Index = 0; Index < ARRAY_SIZE (mHiiOpCodeStringTable); Index++) {
94 if (mHiiOpCodeStringTable[Index].HiiOpCode == HiiOpCode) {
95 return mHiiOpCodeStringTable[Index].HiiOpCodeStr;
96 }
97 }
98
99 return "<UnknownHiiOpCode>";
100}
101
108VOID
109DumpHiiQuestion (
111 )
112{
113 UINT64 Minimum;
114 UINT64 Maximum;
115 UINT64 OneValue;
116 UINT8 *Ptr;
117
118 DEBUG ((DEBUG_INFO, " VAR_CHECK_HII_QUESTION_HEADER\n"));
119 DEBUG ((DEBUG_INFO, " OpCode - 0x%02x (%a) (%a)\n", HiiQuestion->OpCode, HiiOpCodeToStr (HiiQuestion->OpCode), (HiiQuestion->BitFieldStore ? "bit level" : "byte level")));
120 DEBUG ((DEBUG_INFO, " Length - 0x%02x\n", HiiQuestion->Length));
121 DEBUG ((DEBUG_INFO, " VarOffset - 0x%04x (%a)\n", HiiQuestion->VarOffset, (HiiQuestion->BitFieldStore ? "bit level" : "byte level")));
122 DEBUG ((DEBUG_INFO, " StorageWidth - 0x%02x (%a)\n", HiiQuestion->StorageWidth, (HiiQuestion->BitFieldStore ? "bit level" : "byte level")));
123
124 switch (HiiQuestion->OpCode) {
125 case EFI_IFR_ONE_OF_OP:
126 Ptr = (UINT8 *)((VAR_CHECK_HII_QUESTION_ONEOF *)HiiQuestion + 1);
127 while ((UINTN)Ptr < ((UINTN)HiiQuestion + HiiQuestion->Length)) {
128 OneValue = 0;
129 if (HiiQuestion->BitFieldStore) {
130 //
131 // For OneOf stored in bit field, the value of options are saved as UINT32 type.
132 //
133 CopyMem (&OneValue, Ptr, sizeof (UINT32));
134 DEBUG ((DEBUG_INFO, " OneOfOption - 0x%08x\n", OneValue));
135 } else {
136 CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
137 switch (HiiQuestion->StorageWidth) {
138 case sizeof (UINT8):
139 DEBUG ((DEBUG_INFO, " OneOfOption - 0x%02x\n", OneValue));
140 break;
141 case sizeof (UINT16):
142 DEBUG ((DEBUG_INFO, " OneOfOption - 0x%04x\n", OneValue));
143 break;
144 case sizeof (UINT32):
145 DEBUG ((DEBUG_INFO, " OneOfOption - 0x%08x\n", OneValue));
146 break;
147 case sizeof (UINT64):
148 DEBUG ((DEBUG_INFO, " OneOfOption - 0x%016lx\n", OneValue));
149 break;
150 default:
151 ASSERT (FALSE);
152 break;
153 }
154 }
155
156 if (HiiQuestion->BitFieldStore) {
157 Ptr += sizeof (UINT32);
158 } else {
159 Ptr += HiiQuestion->StorageWidth;
160 }
161 }
162
163 break;
164
165 case EFI_IFR_CHECKBOX_OP:
166 break;
167
168 case EFI_IFR_NUMERIC_OP:
169 Minimum = 0;
170 Maximum = 0;
171 Ptr = (UINT8 *)((VAR_CHECK_HII_QUESTION_NUMERIC *)HiiQuestion + 1);
172 if (HiiQuestion->BitFieldStore) {
173 //
174 // For Numeric stored in bit field, the value of Maximum/Minimum are saved as UINT32 type.
175 //
176 CopyMem (&Minimum, Ptr, sizeof (UINT32));
177 Ptr += sizeof (UINT32);
178 CopyMem (&Maximum, Ptr, sizeof (UINT32));
179 Ptr += sizeof (UINT32);
180
181 DEBUG ((DEBUG_INFO, " Minimum - 0x%08x\n", Minimum));
182 DEBUG ((DEBUG_INFO, " Maximum - 0x%08x\n", Maximum));
183 } else {
184 CopyMem (&Minimum, Ptr, HiiQuestion->StorageWidth);
185 Ptr += HiiQuestion->StorageWidth;
186 CopyMem (&Maximum, Ptr, HiiQuestion->StorageWidth);
187 Ptr += HiiQuestion->StorageWidth;
188
189 switch (HiiQuestion->StorageWidth) {
190 case sizeof (UINT8):
191 DEBUG ((DEBUG_INFO, " Minimum - 0x%02x\n", Minimum));
192 DEBUG ((DEBUG_INFO, " Maximum - 0x%02x\n", Maximum));
193 break;
194 case sizeof (UINT16):
195 DEBUG ((DEBUG_INFO, " Minimum - 0x%04x\n", Minimum));
196 DEBUG ((DEBUG_INFO, " Maximum - 0x%04x\n", Maximum));
197 break;
198 case sizeof (UINT32):
199 DEBUG ((DEBUG_INFO, " Minimum - 0x%08x\n", Minimum));
200 DEBUG ((DEBUG_INFO, " Maximum - 0x%08x\n", Maximum));
201 break;
202 case sizeof (UINT64):
203 DEBUG ((DEBUG_INFO, " Minimum - 0x%016lx\n", Minimum));
204 DEBUG ((DEBUG_INFO, " Maximum - 0x%016lx\n", Maximum));
205 break;
206 default:
207 ASSERT (FALSE);
208 break;
209 }
210 }
211
212 break;
213
214 case EFI_IFR_ORDERED_LIST_OP:
215 DEBUG ((DEBUG_INFO, " MaxContainers - 0x%02x\n", ((VAR_CHECK_HII_QUESTION_ORDEREDLIST *)HiiQuestion)->MaxContainers));
216 Ptr = (UINT8 *)((VAR_CHECK_HII_QUESTION_ORDEREDLIST *)HiiQuestion + 1);
217 while ((UINTN)Ptr < ((UINTN)HiiQuestion + HiiQuestion->Length)) {
218 OneValue = 0;
219 CopyMem (&OneValue, Ptr, HiiQuestion->StorageWidth);
220 switch (HiiQuestion->StorageWidth) {
221 case sizeof (UINT8):
222 DEBUG ((DEBUG_INFO, " OneOfOption - 0x%02x\n", OneValue));
223 break;
224 case sizeof (UINT16):
225 DEBUG ((DEBUG_INFO, " OneOfOption - 0x%04x\n", OneValue));
226 break;
227 case sizeof (UINT32):
228 DEBUG ((DEBUG_INFO, " OneOfOption - 0x%08x\n", OneValue));
229 break;
230 case sizeof (UINT64):
231 DEBUG ((DEBUG_INFO, " OneOfOption - 0x%016lx\n", OneValue));
232 break;
233 default:
234 ASSERT (FALSE);
235 break;
236 }
237
238 Ptr += HiiQuestion->StorageWidth;
239 }
240
241 break;
242
243 default:
244 ASSERT (FALSE);
245 break;
246 }
247}
248
255VOID
256DumpHiiVariable (
258 )
259{
261
262 DEBUG ((DEBUG_INFO, "VAR_CHECK_HII_VARIABLE_HEADER\n"));
263 DEBUG ((DEBUG_INFO, " Revision - 0x%04x\n", HiiVariable->Revision));
264 DEBUG ((DEBUG_INFO, " HeaderLength - 0x%04x\n", HiiVariable->HeaderLength));
265 DEBUG ((DEBUG_INFO, " Length - 0x%08x\n", HiiVariable->Length));
266 DEBUG ((DEBUG_INFO, " OpCode - 0x%02x (%a)\n", HiiVariable->OpCode, HiiOpCodeToStr (HiiVariable->OpCode)));
267 DEBUG ((DEBUG_INFO, " Size - 0x%04x\n", HiiVariable->Size));
268 DEBUG ((DEBUG_INFO, " Attributes - 0x%08x\n", HiiVariable->Attributes));
269 DEBUG ((DEBUG_INFO, " Guid - %g\n", &HiiVariable->Guid));
270 DEBUG ((DEBUG_INFO, " Name - %s\n", HiiVariable + 1));
271
272 //
273 // For Hii Question header align.
274 //
275 HiiQuestion = (VAR_CHECK_HII_QUESTION_HEADER *)HEADER_ALIGN (((UINTN)HiiVariable + HiiVariable->HeaderLength));
276 while ((UINTN)HiiQuestion < ((UINTN)HiiVariable + HiiVariable->Length)) {
277 //
278 // Dump Hii Question related to the Hii Variable.
279 //
280 DumpHiiQuestion (HiiQuestion);
281 //
282 // For Hii Question header align.
283 //
284 HiiQuestion = (VAR_CHECK_HII_QUESTION_HEADER *)HEADER_ALIGN (((UINTN)HiiQuestion + HiiQuestion->Length));
285 }
286}
287
295VOID
297 IN VOID *VarCheckHiiBin,
298 IN UINTN VarCheckHiiBinSize
299 )
300{
302
303 DEBUG ((DEBUG_INFO, "DumpVarCheckHii\n"));
304
305 //
306 // For Hii Variable header align.
307 //
308 HiiVariable = (VAR_CHECK_HII_VARIABLE_HEADER *)HEADER_ALIGN (VarCheckHiiBin);
309 while ((UINTN)HiiVariable < ((UINTN)VarCheckHiiBin + VarCheckHiiBinSize)) {
310 DumpHiiVariable (HiiVariable);
311 //
312 // For Hii Variable header align.
313 //
314 HiiVariable = (VAR_CHECK_HII_VARIABLE_HEADER *)HEADER_ALIGN (((UINTN)HiiVariable + HiiVariable->Length));
315 }
316}
317
318#endif
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define FALSE
Definition: Base.h:307
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define GLOBAL_REMOVE_IF_UNREFERENCED
Definition: Base.h:48
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define DEBUG_CODE(Expression)
Definition: DebugLib.h:590
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
EFI_BOOT_SERVICES * gBS
@ EfiBootServicesData
@ AllocateAnyPages
Definition: UefiSpec.h:33
VOID DumpVarCheckHii(IN VOID *VarCheckHiiBin, IN UINTN VarCheckHiiBinSize)
VOID VarCheckParseHiiDatabase(IN VOID *HiiDatabase, IN UINTN HiiDatabaseSize)
VOID DumpHiiDatabase(IN VOID *HiiDatabase, IN UINTN HiiDatabaseSize)
VOID VarCheckHiiGenFromHiiDatabase(VOID)