TianoCore EDK2 master
Loading...
Searching...
No Matches
HobPrintLib.c
Go to the documentation of this file.
1
9#include <Uefi.h>
10#include <Pi/PiMultiPhase.h>
12#include <Library/DebugLib.h>
13#include <Library/HobLib.h>
14#include <Library/HobPrintLib.h>
17
18#define ROW_LIMITER 16
19
20typedef struct {
21 UINT16 Type;
22 CHAR8 *Name;
23 HOB_PRINT_HANDLER PrintHandler;
25
26CHAR8 *mMemoryTypeStr[] = {
27 "EfiReservedMemoryType",
28 "EfiLoaderCode",
29 "EfiLoaderData",
30 "EfiBootServicesCode",
31 "EfiBootServicesData",
32 "EfiRuntimeServicesCode",
33 "EfiRuntimeServicesData",
34 "EfiConventionalMemory",
35 "EfiUnusableMemory",
36 "EfiACPIReclaimMemory",
37 "EfiACPIMemoryNVS",
38 "EfiMemoryMappedIO",
39 "EfiMemoryMappedIOPortSpace",
40 "EfiPalCode",
41 "EfiPersistentMemory",
42 "EfiMaxMemoryType"
43};
44
45CHAR8 *mResource_Type_List[] = {
46 "EFI_RESOURCE_SYSTEM_MEMORY ", // 0x00000000
47 "EFI_RESOURCE_MEMORY_MAPPED_IO ", // 0x00000001
48 "EFI_RESOURCE_IO ", // 0x00000002
49 "EFI_RESOURCE_FIRMWARE_DEVICE ", // 0x00000003
50 "EFI_RESOURCE_MEMORY_MAPPED_IO_PORT ", // 0x00000004
51 "EFI_RESOURCE_MEMORY_RESERVED ", // 0x00000005
52 "EFI_RESOURCE_IO_RESERVED ", // 0x00000006
53 "EFI_RESOURCE_MAX_MEMORY_TYPE " // 0x00000007
54};
55
67 IN UINT32 ErrorLevel,
68 IN UINT8 *DataStart,
69 IN UINT16 DataSize
70 )
71{
72 UINTN Index1;
73 UINTN Index2;
74 UINT8 *StartAddr;
75
76 StartAddr = DataStart;
77 for (Index1 = 0; Index1 * ROW_LIMITER < DataSize; Index1++) {
78 DEBUG ((ErrorLevel, " 0x%04p:", (DataStart - StartAddr)));
79 for (Index2 = 0; (Index2 < ROW_LIMITER) && (Index1 * ROW_LIMITER + Index2 < DataSize); Index2++) {
80 DEBUG ((ErrorLevel, " %02x", *DataStart));
81 DataStart++;
82 }
83
84 DEBUG ((ErrorLevel, "\n"));
85 }
86
87 return EFI_SUCCESS;
88}
89
100 IN VOID *HobStart,
101 IN UINT16 HobLength
102 )
103{
104 DEBUG ((DEBUG_ERROR, " Invalid HOB. Full hex dump in below:\n"));
105 PrintHex (DEBUG_ERROR, HobStart, HobLength);
107}
108
118 IN VOID *HobStart,
119 IN UINT16 HobLength
120 )
121{
123
124 Hob.Raw = (UINT8 *)HobStart;
125 if (HobLength < sizeof (*Hob.HandoffInformationTable)) {
126 return PrintInvalidHob (HobStart, HobLength);
127 }
128
129 DEBUG ((DEBUG_INFO, " BootMode = 0x%x\n", Hob.HandoffInformationTable->BootMode));
130 DEBUG ((DEBUG_INFO, " EfiMemoryTop = 0x%lx\n", Hob.HandoffInformationTable->EfiMemoryTop));
131 DEBUG ((DEBUG_INFO, " EfiMemoryBottom = 0x%lx\n", Hob.HandoffInformationTable->EfiMemoryBottom));
132 DEBUG ((DEBUG_INFO, " EfiFreeMemoryTop = 0x%lx\n", Hob.HandoffInformationTable->EfiFreeMemoryTop));
133 DEBUG ((DEBUG_INFO, " EfiFreeMemoryBottom = 0x%lx\n", Hob.HandoffInformationTable->EfiFreeMemoryBottom));
134 DEBUG ((DEBUG_INFO, " EfiEndOfHobList = 0x%lx\n", Hob.HandoffInformationTable->EfiEndOfHobList));
135 return EFI_SUCCESS;
136}
137
146 IN VOID *HobStart,
147 IN UINT16 HobLength
148 )
149{
151
152 Hob.Raw = (UINT8 *)HobStart;
153
154 if (CompareGuid (&Hob.MemoryAllocation->AllocDescriptor.Name, &gEfiHobMemoryAllocStackGuid)) {
155 if (HobLength < sizeof (*Hob.MemoryAllocationStack)) {
156 return PrintInvalidHob (HobStart, HobLength);
157 }
158
159 DEBUG ((DEBUG_INFO, " Type = EFI_HOB_MEMORY_ALLOCATION_STACK\n"));
160 } else if (CompareGuid (&Hob.MemoryAllocation->AllocDescriptor.Name, &gEfiHobMemoryAllocBspStoreGuid)) {
161 if (HobLength < sizeof (*Hob.MemoryAllocationBspStore)) {
162 return PrintInvalidHob (HobStart, HobLength);
163 }
164
165 DEBUG ((DEBUG_INFO, " Type = EFI_HOB_MEMORY_ALLOCATION_BSP_STORE\n"));
166 } else if (CompareGuid (&Hob.MemoryAllocation->AllocDescriptor.Name, &gEfiHobMemoryAllocModuleGuid)) {
167 if (HobLength < sizeof (*Hob.MemoryAllocationModule)) {
168 return PrintInvalidHob (HobStart, HobLength);
169 }
170
171 DEBUG ((DEBUG_INFO, " Type = EFI_HOB_MEMORY_ALLOCATION_MODULE\n"));
172 DEBUG ((DEBUG_INFO, " ModuleName = %g\n", &Hob.MemoryAllocationModule->ModuleName));
173 DEBUG ((DEBUG_INFO, " EntryPoint = 0x%lx\n", Hob.MemoryAllocationModule->EntryPoint));
174 } else {
175 if (HobLength < sizeof (*Hob.MemoryAllocation)) {
176 return PrintInvalidHob (HobStart, HobLength);
177 }
178
179 DEBUG ((DEBUG_INFO, " Type = EFI_HOB_TYPE_MEMORY_ALLOCATION\n"));
180 }
181
182 DEBUG ((DEBUG_INFO, " Name = %g\n", &Hob.MemoryAllocationStack->AllocDescriptor.Name));
183 DEBUG ((DEBUG_INFO, " MemoryBaseAddress = 0x%lx\n", Hob.MemoryAllocationStack->AllocDescriptor.MemoryBaseAddress));
184 DEBUG ((DEBUG_INFO, " MemoryLength = 0x%lx\n", Hob.MemoryAllocationStack->AllocDescriptor.MemoryLength));
185 DEBUG ((DEBUG_INFO, " MemoryType = %a \n", mMemoryTypeStr[Hob.MemoryAllocationStack->AllocDescriptor.MemoryType]));
186 return EFI_SUCCESS;
187}
188
197 IN VOID *HobStart,
198 IN UINT16 HobLength
199 )
200{
202
203 Hob.Raw = (UINT8 *)HobStart;
204 ASSERT (HobLength >= sizeof (*Hob.ResourceDescriptor));
205
206 DEBUG ((DEBUG_INFO, " ResourceType = %a\n", mResource_Type_List[Hob.ResourceDescriptor->ResourceType]));
207 if (!IsZeroGuid (&Hob.ResourceDescriptor->Owner)) {
208 DEBUG ((DEBUG_INFO, " Owner = %g\n", &Hob.ResourceDescriptor->Owner));
209 }
210
211 DEBUG ((DEBUG_INFO, " ResourceAttribute = 0x%x\n", Hob.ResourceDescriptor->ResourceAttribute));
212 DEBUG ((DEBUG_INFO, " PhysicalStart = 0x%lx\n", Hob.ResourceDescriptor->PhysicalStart));
213 DEBUG ((DEBUG_INFO, " ResourceLength = 0x%lx\n", Hob.ResourceDescriptor->ResourceLength));
214 return EFI_SUCCESS;
215}
216
225 IN VOID *HobStart,
226 IN UINT16 HobLength
227 )
228{
230 UINT16 DataLength;
231
232 Hob.Raw = (UINT8 *)HobStart;
233 ASSERT (HobLength >= sizeof (*Hob.Guid));
234
235 DataLength = GET_GUID_HOB_DATA_SIZE (Hob.Raw);
236
237 DEBUG ((DEBUG_INFO, " Name = %g\n", &Hob.Guid->Name));
238 DEBUG ((DEBUG_INFO, " DataLength = 0x%x\n", DataLength));
239 PrintHex (DEBUG_VERBOSE, GET_GUID_HOB_DATA (Hob.Raw), DataLength);
240 return EFI_SUCCESS;
241}
242
251 IN VOID *HobStart,
252 IN UINT16 HobLength
253 )
254{
256
257 Hob.Raw = (UINT8 *)HobStart;
258 ASSERT (HobLength >= sizeof (*Hob.FirmwareVolume));
259
260 DEBUG ((DEBUG_INFO, " BaseAddress = 0x%lx\n", Hob.FirmwareVolume->BaseAddress));
261 DEBUG ((DEBUG_INFO, " Length = 0x%lx\n", Hob.FirmwareVolume->Length));
262 return EFI_SUCCESS;
263}
264
273 IN VOID *HobStart,
274 IN UINT16 HobLength
275 )
276{
278
279 Hob.Raw = (UINT8 *)HobStart;
280 ASSERT (HobLength >= sizeof (*Hob.Cpu));
281
282 DEBUG ((DEBUG_INFO, " SizeOfMemorySpace = 0x%lx\n", Hob.Cpu->SizeOfMemorySpace));
283 DEBUG ((DEBUG_INFO, " SizeOfIoSpace = 0x%lx\n", Hob.Cpu->SizeOfIoSpace));
284 return EFI_SUCCESS;
285}
286
295 IN VOID *HobStart,
296 IN UINT16 HobLength
297 )
298{
300 UINT16 AllocationSize;
301
302 Hob.Raw = (UINT8 *)HobStart;
303 ASSERT (HobLength >= sizeof (*Hob.Pool));
304
305 AllocationSize = HobLength - sizeof (EFI_HOB_GENERIC_HEADER);
306 DEBUG ((DEBUG_INFO, " AllocationSize = 0x%lx\n", AllocationSize));
307
308 PrintHex (DEBUG_VERBOSE, Hob.Raw + sizeof (EFI_HOB_GENERIC_HEADER), AllocationSize);
309
310 return EFI_SUCCESS;
311}
312
321 IN VOID *HobStart,
322 IN UINT16 HobLength
323 )
324{
326
327 Hob.Raw = (UINT8 *)HobStart;
328 ASSERT (HobLength >= sizeof (*Hob.FirmwareVolume2));
329
330 DEBUG ((DEBUG_INFO, " BaseAddress = 0x%lx\n", Hob.FirmwareVolume2->BaseAddress));
331 DEBUG ((DEBUG_INFO, " Length = 0x%lx\n", Hob.FirmwareVolume2->Length));
332 DEBUG ((DEBUG_INFO, " FvName = %g\n", &Hob.FirmwareVolume2->FvName));
333 DEBUG ((DEBUG_INFO, " FileName = %g\n", &Hob.FirmwareVolume2->FileName));
334 return EFI_SUCCESS;
335}
336
345 IN VOID *HobStart,
346 IN UINT16 HobLength
347 )
348{
350
351 Hob.Raw = (UINT8 *)HobStart;
352 ASSERT (HobLength >= sizeof (*Hob.Capsule));
353
354 DEBUG ((DEBUG_INFO, " BaseAddress = 0x%lx\n", Hob.Capsule->BaseAddress));
355 DEBUG ((DEBUG_INFO, " Length = 0x%lx\n", Hob.Capsule->Length));
356 return EFI_SUCCESS;
357}
358
367 IN VOID *HobStart,
368 IN UINT16 HobLength
369 )
370{
372
373 Hob.Raw = (UINT8 *)HobStart;
374 ASSERT (HobLength >= sizeof (*Hob.FirmwareVolume3));
375
376 DEBUG ((DEBUG_INFO, " BaseAddress = 0x%lx\n", Hob.FirmwareVolume3->BaseAddress));
377 DEBUG ((DEBUG_INFO, " Length = 0x%lx\n", Hob.FirmwareVolume3->Length));
378 DEBUG ((DEBUG_INFO, " AuthenticationStatus = 0x%x\n", Hob.FirmwareVolume3->AuthenticationStatus));
379 DEBUG ((DEBUG_INFO, " ExtractedFv = %a\n", (Hob.FirmwareVolume3->ExtractedFv ? "True" : "False")));
380 DEBUG ((DEBUG_INFO, " FvName = %g\n", &Hob.FirmwareVolume3->FvName));
381 DEBUG ((DEBUG_INFO, " FileName = %g\n", &Hob.FirmwareVolume3->FileName));
382 return EFI_SUCCESS;
383}
384
385//
386// Mapping table from Hob type to Hob print function.
387//
388HOB_PRINT_HANDLER_TABLE mHobHandles[] = {
389 { EFI_HOB_TYPE_HANDOFF, "EFI_HOB_TYPE_HANDOFF", PrintHandOffHob },
390 { EFI_HOB_TYPE_MEMORY_ALLOCATION, "EFI_HOB_TYPE_MEMORY_ALLOCATION", PrintMemoryAllocationHob },
391 { EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, "EFI_HOB_TYPE_RESOURCE_DESCRIPTOR", PrintResourceDiscriptorHob },
392 { EFI_HOB_TYPE_GUID_EXTENSION, "EFI_HOB_TYPE_GUID_EXTENSION", PrintGuidHob },
393 { EFI_HOB_TYPE_FV, "EFI_HOB_TYPE_FV", PrintFvHob },
394 { EFI_HOB_TYPE_CPU, "EFI_HOB_TYPE_CPU", PrintCpuHob },
395 { EFI_HOB_TYPE_MEMORY_POOL, "EFI_HOB_TYPE_MEMORY_POOL", PrintMemoryPoolHob },
396 { EFI_HOB_TYPE_FV2, "EFI_HOB_TYPE_FV2", PrintFv2Hob },
397 { EFI_HOB_TYPE_UEFI_CAPSULE, "EFI_HOB_TYPE_UEFI_CAPSULE", PrintCapsuleHob },
398 { EFI_HOB_TYPE_FV3, "EFI_HOB_TYPE_FV3", PrintFv3Hob }
399};
400
408VOID
409EFIAPI
411 IN CONST VOID *HobStart,
412 IN HOB_PRINT_HANDLER PrintHandler
413 )
414{
415 EFI_STATUS Status;
417 UINTN Count;
418 UINTN Index;
419
420 ASSERT (HobStart != NULL);
421
422 Hob.Raw = (UINT8 *)HobStart;
423 DEBUG ((DEBUG_INFO, "Print all Hob information from Hob 0x%p\n", Hob.Raw));
424
425 Status = EFI_SUCCESS;
426 Count = 0;
427 //
428 // Parse the HOB list to see which type it is, and print the information.
429 //
430 while (!END_OF_HOB_LIST (Hob)) {
431 //
432 // Print HOB generic information
433 //
434 for (Index = 0; Index < ARRAY_SIZE (mHobHandles); Index++) {
435 if (Hob.Header->HobType == mHobHandles[Index].Type) {
436 DEBUG ((DEBUG_INFO, "HOB[%d]: Type = %a, Offset = 0x%p, Length = 0x%x\n", Count, mHobHandles[Index].Name, (Hob.Raw - (UINT8 *)HobStart), Hob.Header->HobLength));
437 break;
438 }
439 }
440
441 if (Index == ARRAY_SIZE (mHobHandles)) {
442 DEBUG ((DEBUG_INFO, "HOB[%d]: Type = %d, Offset = 0x%p, Length = 0x%x\n", Count, Hob.Header->HobType, (Hob.Raw - (UINT8 *)HobStart), Hob.Header->HobLength));
443 }
444
445 //
446 // Process custom HOB print handler first
447 //
448 if (PrintHandler != NULL) {
449 Status = PrintHandler (Hob.Raw, Hob.Header->HobLength);
450 }
451
452 //
453 // Process internal HOB print handler
454 //
455 if ((PrintHandler == NULL) || EFI_ERROR (Status)) {
456 if (Index < ARRAY_SIZE (mHobHandles)) {
457 mHobHandles[Index].PrintHandler (Hob.Raw, Hob.Header->HobLength);
458 } else {
459 DEBUG ((DEBUG_INFO, " Unkown Hob type, full hex dump in below:\n"));
460 PrintHex (DEBUG_INFO, Hob.Raw, Hob.Header->HobLength);
461 }
462 }
463
464 Count++;
465 Hob.Raw = GET_NEXT_HOB (Hob);
466 }
467
468 DEBUG ((DEBUG_INFO, "There are totally %d Hobs, the End Hob address is %p\n", Count, Hob.Raw));
469}
UINT64 UINTN
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
BOOLEAN EFIAPI IsZeroGuid(IN CONST GUID *Guid)
Definition: MemLibGuid.c:156
EFI_STATUS PrintInvalidHob(IN VOID *HobStart, IN UINT16 HobLength)
Definition: HobPrintLib.c:99
VOID EFIAPI PrintHobList(IN CONST VOID *HobStart, IN HOB_PRINT_HANDLER PrintHandler)
Definition: HobPrintLib.c:410
EFI_STATUS PrintCapsuleHob(IN VOID *HobStart, IN UINT16 HobLength)
Definition: HobPrintLib.c:344
EFI_STATUS PrintMemoryAllocationHob(IN VOID *HobStart, IN UINT16 HobLength)
Definition: HobPrintLib.c:145
EFI_STATUS PrintCpuHob(IN VOID *HobStart, IN UINT16 HobLength)
Definition: HobPrintLib.c:272
EFI_STATUS PrintHex(IN UINT32 ErrorLevel, IN UINT8 *DataStart, IN UINT16 DataSize)
Definition: HobPrintLib.c:66
EFI_STATUS PrintGuidHob(IN VOID *HobStart, IN UINT16 HobLength)
Definition: HobPrintLib.c:224
EFI_STATUS PrintHandOffHob(IN VOID *HobStart, IN UINT16 HobLength)
Definition: HobPrintLib.c:117
EFI_STATUS PrintMemoryPoolHob(IN VOID *HobStart, IN UINT16 HobLength)
Definition: HobPrintLib.c:294
EFI_STATUS PrintFv2Hob(IN VOID *HobStart, IN UINT16 HobLength)
Definition: HobPrintLib.c:320
EFI_STATUS PrintFvHob(IN VOID *HobStart, IN UINT16 HobLength)
Definition: HobPrintLib.c:250
EFI_STATUS PrintResourceDiscriptorHob(IN VOID *HobStart, IN UINT16 HobLength)
Definition: HobPrintLib.c:196
EFI_STATUS PrintFv3Hob(IN VOID *HobStart, IN UINT16 HobLength)
Definition: HobPrintLib.c:366
EFI_STATUS(* HOB_PRINT_HANDLER)(IN VOID *Hob, IN UINT16 HobLength)
Definition: HobPrintLib.h:24
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define RETURN_INVALID_PARAMETER
Definition: Base.h:1076
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
UINT8 SizeOfIoSpace
Definition: PiHob.h:451
UINT8 SizeOfMemorySpace
Definition: PiHob.h:447
EFI_PHYSICAL_ADDRESS BaseAddress
Definition: PiHob.h:383
UINT32 AuthenticationStatus
Definition: PiHob.h:418
EFI_PHYSICAL_ADDRESS BaseAddress
Definition: PiHob.h:410
EFI_PHYSICAL_ADDRESS BaseAddress
Definition: PiHob.h:364
EFI_GUID Name
Definition: PiHob.h:347
EFI_BOOT_MODE BootMode
Definition: PiHob.h:74
EFI_PHYSICAL_ADDRESS EfiFreeMemoryBottom
Definition: PiHob.h:92
EFI_PHYSICAL_ADDRESS EfiMemoryTop
Definition: PiHob.h:79
EFI_PHYSICAL_ADDRESS EfiFreeMemoryTop
Definition: PiHob.h:88
EFI_PHYSICAL_ADDRESS EfiMemoryBottom
Definition: PiHob.h:83
EFI_PHYSICAL_ADDRESS EfiEndOfHobList
Definition: PiHob.h:96
EFI_PHYSICAL_ADDRESS MemoryBaseAddress
Definition: PiHob.h:119
EFI_MEMORY_TYPE MemoryType
Definition: PiHob.h:131
EFI_PHYSICAL_ADDRESS EntryPoint
Definition: PiHob.h:217
EFI_HOB_MEMORY_ALLOCATION_HEADER AllocDescriptor
Definition: PiHob.h:174
EFI_HOB_MEMORY_ALLOCATION_HEADER AllocDescriptor
Definition: PiHob.h:153
EFI_PHYSICAL_ADDRESS PhysicalStart
Definition: PiHob.h:328
EFI_RESOURCE_TYPE ResourceType
Definition: PiHob.h:320
EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
Definition: PiHob.h:324
EFI_PHYSICAL_ADDRESS BaseAddress
Definition: PiHob.h:486