TianoCore EDK2 master
Loading...
Searching...
No Matches
CapsuleDump.c
Go to the documentation of this file.
1
9#include "CapsuleApp.h"
10
23BOOLEAN
25 IN EFI_CAPSULE_HEADER *CapsuleHeader,
26 IN UINT64 CapsuleSize
27 );
28
34VOID
36 IN EFI_CAPSULE_HEADER *CapsuleHeader
37 )
38{
39 EFI_DISPLAY_CAPSULE *DisplayCapsule;
40
41 DisplayCapsule = (EFI_DISPLAY_CAPSULE *)CapsuleHeader;
42 Print (L"[UxCapsule]\n");
43 Print (L"CapsuleHeader:\n");
44 Print (L" CapsuleGuid - %g\n", &DisplayCapsule->CapsuleHeader.CapsuleGuid);
45 Print (L" HeaderSize - 0x%x\n", DisplayCapsule->CapsuleHeader.HeaderSize);
46 Print (L" Flags - 0x%x\n", DisplayCapsule->CapsuleHeader.Flags);
47 Print (L" CapsuleImageSize - 0x%x\n", DisplayCapsule->CapsuleHeader.CapsuleImageSize);
48 Print (L"ImagePayload:\n");
49 Print (L" Version - 0x%x\n", DisplayCapsule->ImagePayload.Version);
50 Print (L" Checksum - 0x%x\n", DisplayCapsule->ImagePayload.Checksum);
51 Print (L" ImageType - 0x%x\n", DisplayCapsule->ImagePayload.ImageType);
52 Print (L" Mode - 0x%x\n", DisplayCapsule->ImagePayload.Mode);
53 Print (L" OffsetX - 0x%x\n", DisplayCapsule->ImagePayload.OffsetX);
54 Print (L" OffsetY - 0x%x\n", DisplayCapsule->ImagePayload.OffsetY);
55}
56
62VOID
64 IN EFI_CAPSULE_HEADER *CapsuleHeader
65 )
66{
68 UINT64 *ItemOffsetList;
69 UINTN Index;
70 UINTN Count;
72
73 Print (L"[FmpCapsule]\n");
74 Print (L"CapsuleHeader:\n");
75 Print (L" CapsuleGuid - %g\n", &CapsuleHeader->CapsuleGuid);
76 Print (L" HeaderSize - 0x%x\n", CapsuleHeader->HeaderSize);
77 Print (L" Flags - 0x%x\n", CapsuleHeader->Flags);
78 Print (L" CapsuleImageSize - 0x%x\n", CapsuleHeader->CapsuleImageSize);
79
80 FmpCapsuleHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_HEADER *)((UINT8 *)CapsuleHeader + CapsuleHeader->HeaderSize);
81 ItemOffsetList = (UINT64 *)(FmpCapsuleHeader + 1);
82 Print (L"FmpHeader:\n");
83 Print (L" Version - 0x%x\n", FmpCapsuleHeader->Version);
84 Print (L" EmbeddedDriverCount - 0x%x\n", FmpCapsuleHeader->EmbeddedDriverCount);
85 Print (L" PayloadItemCount - 0x%x\n", FmpCapsuleHeader->PayloadItemCount);
86 Count = FmpCapsuleHeader->EmbeddedDriverCount + FmpCapsuleHeader->PayloadItemCount;
87 for (Index = 0; Index < Count; Index++) {
88 Print (L" Offset[%d] - 0x%x\n", Index, ItemOffsetList[Index]);
89 }
90
91 for (Index = FmpCapsuleHeader->EmbeddedDriverCount; Index < Count; Index++) {
92 Print (L"FmpPayload[%d] ImageHeader:\n", Index);
93 FmpImageHeader = (EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER *)((UINT8 *)FmpCapsuleHeader + ItemOffsetList[Index]);
94 Print (L" Version - 0x%x\n", FmpImageHeader->Version);
95 Print (L" UpdateImageTypeId - %g\n", &FmpImageHeader->UpdateImageTypeId);
96 Print (L" UpdateImageIndex - 0x%x\n", FmpImageHeader->UpdateImageIndex);
97 Print (L" UpdateImageSize - 0x%x\n", FmpImageHeader->UpdateImageSize);
98 Print (L" UpdateVendorCodeSize - 0x%x\n", FmpImageHeader->UpdateVendorCodeSize);
99 if (FmpImageHeader->Version >= 2) {
100 Print (L" UpdateHardwareInstance - 0x%lx\n", FmpImageHeader->UpdateHardwareInstance);
101 if (FmpImageHeader->Version >= EFI_FIRMWARE_MANAGEMENT_CAPSULE_IMAGE_HEADER_INIT_VERSION) {
102 Print (L" ImageCapsuleSupport - 0x%lx\n", FmpImageHeader->ImageCapsuleSupport);
103 }
104 }
105 }
106}
107
116BOOLEAN
118 IN EFI_CAPSULE_HEADER *CapsuleHeader
119 )
120{
121 EFI_STATUS Status;
123 EFI_SYSTEM_RESOURCE_ENTRY *EsrtEntry;
124 UINTN Index;
125 BOOLEAN EsrtGuidFound;
126 EFI_CAPSULE_HEADER *NestedCapsuleHeader;
127 UINTN NestedCapsuleSize;
128
129 //
130 // Check ESRT
131 //
132 EsrtGuidFound = FALSE;
133 Status = EfiGetSystemConfigurationTable (&gEfiSystemResourceTableGuid, (VOID **)&Esrt);
134 if (!EFI_ERROR (Status)) {
135 ASSERT (Esrt != NULL);
136 EsrtEntry = (VOID *)(Esrt + 1);
137 for (Index = 0; Index < Esrt->FwResourceCount; Index++, EsrtEntry++) {
138 if (CompareGuid (&EsrtEntry->FwClass, &CapsuleHeader->CapsuleGuid)) {
139 EsrtGuidFound = TRUE;
140 break;
141 }
142 }
143 }
144
145 if (!EsrtGuidFound) {
146 return FALSE;
147 }
148
149 //
150 // Check nested capsule header
151 // FMP GUID after ESRT one
152 //
153 NestedCapsuleHeader = (EFI_CAPSULE_HEADER *)((UINT8 *)CapsuleHeader + CapsuleHeader->HeaderSize);
154 NestedCapsuleSize = (UINTN)CapsuleHeader + CapsuleHeader->CapsuleImageSize- (UINTN)NestedCapsuleHeader;
155 if (NestedCapsuleSize < sizeof (EFI_CAPSULE_HEADER)) {
156 return FALSE;
157 }
158
159 if (!CompareGuid (&NestedCapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) {
160 return FALSE;
161 }
162
163 return TRUE;
164}
165
176 IN CHAR16 *CapsuleName
177 )
178{
179 VOID *Buffer;
180 UINTN FileSize;
181 EFI_CAPSULE_HEADER *CapsuleHeader;
182 EFI_STATUS Status;
183
184 Buffer = NULL;
185 Status = ReadFileToBuffer (CapsuleName, &FileSize, &Buffer);
186 if (EFI_ERROR (Status)) {
187 Print (L"CapsuleApp: Capsule (%s) is not found.\n", CapsuleName);
188 goto Done;
189 }
190
191 if (!IsValidCapsuleHeader (Buffer, FileSize)) {
192 Print (L"CapsuleApp: Capsule image (%s) is not a valid capsule.\n", CapsuleName);
193 Status = EFI_INVALID_PARAMETER;
194 goto Done;
195 }
196
197 CapsuleHeader = Buffer;
198 if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gWindowsUxCapsuleGuid)) {
199 DumpUxCapsule (CapsuleHeader);
200 Status = EFI_SUCCESS;
201 goto Done;
202 }
203
204 if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) {
205 DumpFmpCapsule (CapsuleHeader);
206 }
207
208 if (IsNestedFmpCapsule (CapsuleHeader)) {
209 Print (L"[NestedCapsule]\n");
210 Print (L"CapsuleHeader:\n");
211 Print (L" CapsuleGuid - %g\n", &CapsuleHeader->CapsuleGuid);
212 Print (L" HeaderSize - 0x%x\n", CapsuleHeader->HeaderSize);
213 Print (L" Flags - 0x%x\n", CapsuleHeader->Flags);
214 Print (L" CapsuleImageSize - 0x%x\n", CapsuleHeader->CapsuleImageSize);
215 DumpFmpCapsule ((EFI_CAPSULE_HEADER *)((UINTN)CapsuleHeader + CapsuleHeader->HeaderSize));
216 }
217
218Done:
219 if (Buffer != NULL) {
220 FreePool (Buffer);
221 }
222
223 return Status;
224}
225
234 VOID
235 )
236{
237 EFI_STATUS Status;
238 UINT32 Index;
239 CHAR16 CapsuleVarName[20];
240 CHAR16 *TempVarName;
242 EFI_CAPSULE_RESULT_VARIABLE_FMP *CapsuleResultFmp;
243 UINTN CapsuleFileNameSize;
244 CHAR16 CapsuleIndexData[12];
245 CHAR16 *CapsuleIndex;
246 CHAR16 *CapsuleFileName;
247 CHAR16 *CapsuleTarget;
248
249 Status = GetVariable2 (
250 L"CapsuleMax",
251 &gEfiCapsuleReportGuid,
252 (VOID **)&CapsuleIndex,
253 NULL
254 );
255 if (!EFI_ERROR (Status)) {
256 ASSERT (CapsuleIndex != NULL);
257 CopyMem (CapsuleIndexData, CapsuleIndex, 11 * sizeof (CHAR16));
258 CapsuleIndexData[11] = 0;
259 Print (L"CapsuleMax - %s\n", CapsuleIndexData);
260 FreePool (CapsuleIndex);
261 }
262
263 Status = GetVariable2 (
264 L"CapsuleLast",
265 &gEfiCapsuleReportGuid,
266 (VOID **)&CapsuleIndex,
267 NULL
268 );
269 if (!EFI_ERROR (Status)) {
270 ASSERT (CapsuleIndex != NULL);
271 CopyMem (CapsuleIndexData, CapsuleIndex, 11 * sizeof (CHAR16));
272 CapsuleIndexData[11] = 0;
273 Print (L"CapsuleLast - %s\n", CapsuleIndexData);
274 FreePool (CapsuleIndex);
275 }
276
277 StrCpyS (CapsuleVarName, sizeof (CapsuleVarName)/sizeof (CapsuleVarName[0]), L"Capsule");
278 TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
279 Index = 0;
280
281 while (TRUE) {
282 UnicodeSPrint (TempVarName, 5 * sizeof (CHAR16), L"%04x", Index);
283
284 Status = GetVariable2 (
285 CapsuleVarName,
286 &gEfiCapsuleReportGuid,
287 (VOID **)&CapsuleResult,
288 NULL
289 );
290 if (Status == EFI_NOT_FOUND) {
291 break;
292 } else if (EFI_ERROR (Status)) {
293 continue;
294 }
295
296 ASSERT (CapsuleResult != NULL);
297
298 //
299 // display capsule process status
300 //
301 if (CapsuleResult->VariableTotalSize >= sizeof (EFI_CAPSULE_RESULT_VARIABLE_HEADER)) {
302 Print (L"CapsuleName: %s\n", CapsuleVarName);
303 Print (L" Capsule Guid: %g\n", &CapsuleResult->CapsuleGuid);
304 Print (L" Capsule ProcessedTime: %t\n", &CapsuleResult->CapsuleProcessed);
305 Print (L" Capsule Status: %r\n", CapsuleResult->CapsuleStatus);
306 }
307
308 if (CompareGuid (&CapsuleResult->CapsuleGuid, &gEfiFmpCapsuleGuid)) {
309 if (CapsuleResult->VariableTotalSize >= sizeof (EFI_CAPSULE_RESULT_VARIABLE_HEADER) + sizeof (EFI_CAPSULE_RESULT_VARIABLE_FMP) + sizeof (CHAR16) * 2) {
310 CapsuleResultFmp = (EFI_CAPSULE_RESULT_VARIABLE_FMP *)(CapsuleResult + 1);
311 Print (L" Capsule FMP Version: 0x%x\n", CapsuleResultFmp->Version);
312 Print (L" Capsule FMP PayloadIndex: 0x%x\n", CapsuleResultFmp->PayloadIndex);
313 Print (L" Capsule FMP UpdateImageIndex: 0x%x\n", CapsuleResultFmp->UpdateImageIndex);
314 Print (L" Capsule FMP UpdateImageTypeId: %g\n", &CapsuleResultFmp->UpdateImageTypeId);
315 CapsuleFileName = (CHAR16 *)(CapsuleResultFmp + 1);
316 Print (L" Capsule FMP CapsuleFileName: \"%s\"\n", CapsuleFileName);
317 CapsuleFileNameSize = StrSize (CapsuleFileName);
318 CapsuleTarget = (CHAR16 *)((UINTN)CapsuleFileName + CapsuleFileNameSize);
319 Print (L" Capsule FMP CapsuleTarget: \"%s\"\n", CapsuleTarget);
320 }
321 }
322
323 FreePool (CapsuleResult);
324
325 Index++;
326 if (Index > 0xFFFF) {
327 break;
328 }
329 }
330
331 return EFI_SUCCESS;
332}
333
334CHAR8 *mFwTypeString[] = {
335 "Unknown",
336 "SystemFirmware",
337 "DeviceFirmware",
338 "UefiDriver",
339};
340
341CHAR8 *mLastAttemptStatusString[] = {
342 "Success",
343 "Error: Unsuccessful",
344 "Error: Insufficient Resources",
345 "Error: Incorrect Version",
346 "Error: Invalid Format",
347 "Error: Auth Error",
348 "Error: Power Event AC",
349 "Error: Power Event Battery",
350 "Error: Unsatisfied Dependencies",
351};
352
360CHAR8 *
362 IN UINT32 FwType
363 )
364{
365 if (FwType < sizeof (mFwTypeString) / sizeof (mFwTypeString[0])) {
366 return mFwTypeString[FwType];
367 } else {
368 return "Invalid";
369 }
370}
371
379CHAR8 *
381 IN UINT32 LastAttemptStatus
382 )
383{
384 if (LastAttemptStatus < sizeof (mLastAttemptStatusString) / sizeof (mLastAttemptStatusString[0])) {
385 return mLastAttemptStatusString[LastAttemptStatus];
386 } else {
387 return "Error: Unknown";
388 }
389}
390
396VOID
399 )
400{
401 Print (L" FwClass - %g\n", &EsrtEntry->FwClass);
402 Print (L" FwType - 0x%x (%a)\n", EsrtEntry->FwType, FwTypeToString (EsrtEntry->FwType));
403 Print (L" FwVersion - 0x%x\n", EsrtEntry->FwVersion);
404 Print (L" LowestSupportedFwVersion - 0x%x\n", EsrtEntry->LowestSupportedFwVersion);
405 Print (L" CapsuleFlags - 0x%x\n", EsrtEntry->CapsuleFlags);
406 Print (L" LastAttemptVersion - 0x%x\n", EsrtEntry->LastAttemptVersion);
407 Print (L" LastAttemptStatus - 0x%x (%a)\n", EsrtEntry->LastAttemptStatus, LastAttemptStatusToString (EsrtEntry->LastAttemptStatus));
408}
409
415VOID
418 )
419{
420 UINTN Index;
421 EFI_SYSTEM_RESOURCE_ENTRY *EsrtEntry;
422
423 if (Esrt == NULL) {
424 return;
425 }
426
427 Print (L"EFI_SYSTEM_RESOURCE_TABLE:\n");
428 Print (L"FwResourceCount - 0x%x\n", Esrt->FwResourceCount);
429 Print (L"FwResourceCountMax - 0x%x\n", Esrt->FwResourceCountMax);
430 Print (L"FwResourceVersion - 0x%lx\n", Esrt->FwResourceVersion);
431
432 EsrtEntry = (VOID *)(Esrt + 1);
433 for (Index = 0; Index < Esrt->FwResourceCount; Index++) {
434 Print (L"EFI_SYSTEM_RESOURCE_ENTRY (%d):\n", Index);
435 DumpEsrtEntry (EsrtEntry);
436 EsrtEntry++;
437 }
438}
439
443VOID
445 VOID
446 )
447{
448 EFI_STATUS Status;
450
451 Print (L"##############\n");
452 Print (L"# ESRT TABLE #\n");
453 Print (L"##############\n");
454
455 Status = EfiGetSystemConfigurationTable (&gEfiSystemResourceTableGuid, (VOID **)&Esrt);
456 if (EFI_ERROR (Status)) {
457 Print (L"ESRT - %r\n", Status);
458 return;
459 }
460
461 DumpEsrt (Esrt);
462 Print (L"\n");
463}
464
475 IN EFI_CAPSULE_HEADER *CapsuleHeader
476 )
477{
478 if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gWindowsUxCapsuleGuid)) {
479 DumpUxCapsule (CapsuleHeader);
480 return EFI_SUCCESS;
481 }
482
483 if (CompareGuid (&CapsuleHeader->CapsuleGuid, &gEfiFmpCapsuleGuid)) {
484 DumpFmpCapsule (CapsuleHeader);
485 }
486
487 if (IsNestedFmpCapsule (CapsuleHeader)) {
488 Print (L"[NestedCapusule]\n");
489 Print (L"CapsuleHeader:\n");
490 Print (L" CapsuleGuid - %g\n", &CapsuleHeader->CapsuleGuid);
491 Print (L" HeaderSize - 0x%x\n", CapsuleHeader->HeaderSize);
492 Print (L" Flags - 0x%x\n", CapsuleHeader->Flags);
493 Print (L" CapsuleImageSize - 0x%x\n", CapsuleHeader->CapsuleImageSize);
494 DumpFmpCapsule ((EFI_CAPSULE_HEADER *)((UINTN)CapsuleHeader + CapsuleHeader->HeaderSize));
495 }
496
497 return EFI_SUCCESS;
498}
499
508STATIC
509CHAR16 *
511 IN CHAR16 *Str
512 )
513{
514 CHAR16 *Cptr;
515
516 for (Cptr = Str; *Cptr != L'\0'; Cptr++) {
517 if ((L'a' <= *Cptr) && (*Cptr <= L'z')) {
518 *Cptr = *Cptr - L'a' + L'A';
519 }
520 }
521
522 return Str;
523}
524
534STATIC
535VOID
537 IN CHAR16 *Str,
538 OUT CHAR16 *SubStr,
539 OUT UINTN *SubStrLen
540 )
541{
542 UINTN Index;
543
544 for (Index = 0; Str[Index] != L'.' && Str[Index] != L'\0'; Index++) {
545 SubStr[Index] = Str[Index];
546 }
547
548 SubStr[Index] = L'\0';
549 *SubStrLen = Index;
550}
551
560STATIC
561VOID
563 IN CHAR16 *StrBuf,
564 IN UINTN PadLen,
565 IN CHAR16 Character
566 )
567{
568 UINTN Index;
569
570 for (Index = 0; StrBuf[Index] != L'\0'; Index++) {
571 }
572
573 while (PadLen != 0) {
574 StrBuf[Index] = Character;
575 Index++;
576 PadLen--;
577 }
578
579 StrBuf[Index] = L'\0';
580}
581
591STATIC
592VOID
594 IN CHAR16 *FileName,
595 OUT CHAR16 *FileNameFirst,
596 OUT CHAR16 *FileNameExtension
597 )
598{
599 UINTN Index;
600 UINTN StringLen;
601
602 StringLen = StrLen (FileName);
603 for (Index = StringLen; Index > 0 && FileName[Index] != L'.'; Index--) {
604 }
605
606 //
607 // No period exists. No FileName Extension
608 //
609 if ((Index == 0) && (FileName[Index] != L'.')) {
610 FileNameExtension[0] = L'\0';
611 Index = StringLen;
612 } else {
613 StrCpyS (FileNameExtension, MAX_FILE_NAME_LEN, &FileName[Index+1]);
614 }
615
616 //
617 // Copy First file name
618 //
619 StrnCpyS (FileNameFirst, MAX_FILE_NAME_LEN, FileName, Index);
620 FileNameFirst[Index] = L'\0';
621}
622
634INTN
635EFIAPI
637 IN VOID *Left,
638 IN VOID *Right
639 )
640{
641 EFI_FILE_INFO *FileInfo1;
642 EFI_FILE_INFO *FileInfo2;
643 CHAR16 FileName1[MAX_FILE_NAME_SIZE];
644 CHAR16 FileExtension1[MAX_FILE_NAME_SIZE];
645 CHAR16 FileName2[MAX_FILE_NAME_SIZE];
646 CHAR16 FileExtension2[MAX_FILE_NAME_SIZE];
647 CHAR16 TempSubStr1[MAX_FILE_NAME_SIZE];
648 CHAR16 TempSubStr2[MAX_FILE_NAME_SIZE];
649 UINTN SubStrLen1;
650 UINTN SubStrLen2;
651 INTN SubStrCmpResult;
652
653 FileInfo1 = (EFI_FILE_INFO *)(*(UINTN *)Left);
654 FileInfo2 = (EFI_FILE_INFO *)(*(UINTN *)Right);
655
656 SplitFileNameExtension (FileInfo1->FileName, FileName1, FileExtension1);
657 SplitFileNameExtension (FileInfo2->FileName, FileName2, FileExtension2);
658
659 UpperCaseString (FileName1);
660 UpperCaseString (FileName2);
661
662 GetSubStringBeforePeriod (FileName1, TempSubStr1, &SubStrLen1);
663 GetSubStringBeforePeriod (FileName2, TempSubStr2, &SubStrLen2);
664
665 if (SubStrLen1 > SubStrLen2) {
666 //
667 // Substr in NewFileName is longer. Pad tail with SPACE
668 //
669 PadStrInTail (TempSubStr2, SubStrLen1 - SubStrLen2, L' ');
670 } else if (SubStrLen1 < SubStrLen2) {
671 //
672 // Substr in ListedFileName is longer. Pad tail with SPACE
673 //
674 PadStrInTail (TempSubStr1, SubStrLen2 - SubStrLen1, L' ');
675 }
676
677 SubStrCmpResult = StrnCmp (TempSubStr1, TempSubStr2, MAX_FILE_NAME_LEN);
678 if (SubStrCmpResult != 0) {
679 return SubStrCmpResult;
680 }
681
682 UpperCaseString (FileExtension1);
683 UpperCaseString (FileExtension2);
684
685 return StrnCmp (FileExtension1, FileExtension2, MAX_FILE_NAME_LEN);
686}
687
700 IN BOOLEAN DumpCapsuleInfo
701 )
702{
703 EFI_STATUS Status;
704 EFI_FILE *Root;
705 EFI_FILE *DirHandle;
706 EFI_FILE *FileHandle;
707 UINTN Index;
708 UINTN FileSize;
709 VOID *FileBuffer;
710 EFI_FILE_INFO **FileInfoBuffer;
712 UINTN FileCount;
713 BOOLEAN NoFile;
714
715 DirHandle = NULL;
716 FileHandle = NULL;
717 Index = 0;
718 FileInfoBuffer = NULL;
719 FileInfo = NULL;
720 FileCount = 0;
721 NoFile = FALSE;
722
723 Status = Fs->OpenVolume (Fs, &Root);
724 if (EFI_ERROR (Status)) {
725 Print (L"Cannot open volume. Status = %r\n", Status);
726 goto Done;
727 }
728
729 Status = Root->Open (Root, &DirHandle, EFI_CAPSULE_FILE_DIRECTORY, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
730 if (EFI_ERROR (Status)) {
731 Print (L"Cannot open %s. Status = %r\n", EFI_CAPSULE_FILE_DIRECTORY, Status);
732 goto Done;
733 }
734
735 //
736 // Get file count first
737 //
738 Status = FileHandleFindFirstFile (DirHandle, &FileInfo);
739 do {
740 if (EFI_ERROR (Status) || (FileInfo == NULL)) {
741 Print (L"Get File Info Fail. Status = %r\n", Status);
742 goto Done;
743 }
744
745 if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
746 FileCount++;
747 }
748
749 Status = FileHandleFindNextFile (DirHandle, FileInfo, &NoFile);
750 if (EFI_ERROR (Status)) {
751 Print (L"Get Next File Fail. Status = %r\n", Status);
752 goto Done;
753 }
754 } while (!NoFile);
755
756 if (FileCount == 0) {
757 Print (L"Error: No capsule file found!\n");
758 Status = EFI_NOT_FOUND;
759 goto Done;
760 }
761
762 FileInfoBuffer = AllocateZeroPool (sizeof (FileInfo) * FileCount);
763 if (FileInfoBuffer == NULL) {
764 Status = EFI_OUT_OF_RESOURCES;
765 goto Done;
766 }
767
768 NoFile = FALSE;
769
770 //
771 // Get all file info
772 //
773 Status = FileHandleFindFirstFile (DirHandle, &FileInfo);
774 do {
775 if (EFI_ERROR (Status) || (FileInfo == NULL)) {
776 Print (L"Get File Info Fail. Status = %r\n", Status);
777 goto Done;
778 }
779
780 if ((FileInfo->Attribute & (EFI_FILE_SYSTEM | EFI_FILE_ARCHIVE)) != 0) {
781 FileInfoBuffer[Index++] = AllocateCopyPool ((UINTN)FileInfo->Size, FileInfo);
782 }
783
784 Status = FileHandleFindNextFile (DirHandle, FileInfo, &NoFile);
785 if (EFI_ERROR (Status)) {
786 Print (L"Get Next File Fail. Status = %r\n", Status);
787 goto Done;
788 }
789 } while (!NoFile);
790
791 //
792 // Sort FileInfoBuffer by alphabet order
793 //
795 FileInfoBuffer,
796 FileCount,
797 sizeof (FileInfo),
798 (SORT_COMPARE)CompareFileNameInAlphabet
799 );
800
801 Print (L"The capsules will be performed by following order:\n");
802
803 for (Index = 0; Index < FileCount; Index++) {
804 Print (L" %d.%s\n", Index + 1, FileInfoBuffer[Index]->FileName);
805 }
806
807 if (!DumpCapsuleInfo) {
808 Status = EFI_SUCCESS;
809 goto Done;
810 }
811
812 Print (L"The infomation of the capsules:\n");
813
814 for (Index = 0; Index < FileCount; Index++) {
815 FileHandle = NULL;
816 Status = DirHandle->Open (DirHandle, &FileHandle, FileInfoBuffer[Index]->FileName, EFI_FILE_MODE_READ, 0);
817 if (EFI_ERROR (Status)) {
818 goto Done;
819 }
820
821 Status = FileHandleGetSize (FileHandle, (UINT64 *)&FileSize);
822 if (EFI_ERROR (Status)) {
823 Print (L"Cannot read file %s. Status = %r\n", FileInfoBuffer[Index]->FileName, Status);
824 FileHandleClose (FileHandle);
825 goto Done;
826 }
827
828 FileBuffer = AllocatePool (FileSize);
829 if (FileBuffer == NULL) {
830 Status = EFI_OUT_OF_RESOURCES;
831 goto Done;
832 }
833
834 Status = FileHandleRead (FileHandle, &FileSize, FileBuffer);
835 if (EFI_ERROR (Status)) {
836 Print (L"Cannot read file %s. Status = %r\n", FileInfoBuffer[Index]->FileName, Status);
837 FileHandleClose (FileHandle);
838 FreePool (FileBuffer);
839 goto Done;
840 }
841
842 Print (L"**************************\n");
843 Print (L" %d.%s:\n", Index + 1, FileInfoBuffer[Index]->FileName);
844 Print (L"**************************\n");
846 FileHandleClose (FileHandle);
847 FreePool (FileBuffer);
848 }
849
850Done:
851 if (FileInfoBuffer != NULL) {
852 for (Index = 0; Index < FileCount; Index++) {
853 if (FileInfoBuffer[Index] != NULL) {
854 FreePool (FileInfoBuffer[Index]);
855 }
856 }
857
858 FreePool (FileInfoBuffer);
859 }
860
861 return Status;
862}
863
871VOID
873 IN EFI_CAPSULE_BLOCK_DESCRIPTOR *BlockDescriptors,
874 IN BOOLEAN DumpCapsuleInfo
875 )
876{
877 EFI_CAPSULE_BLOCK_DESCRIPTOR *TempBlockPtr;
878
879 TempBlockPtr = BlockDescriptors;
880
881 while (TRUE) {
882 if (TempBlockPtr->Length != 0) {
883 if (DumpCapsuleInfo) {
884 Print (L"******************************************************\n");
885 }
886
887 Print (L"Capsule data starts at 0x%08x with size 0x%08x\n", TempBlockPtr->Union.DataBlock, TempBlockPtr->Length);
888 if (DumpCapsuleInfo) {
889 Print (L"******************************************************\n");
891 }
892
893 TempBlockPtr += 1;
894 } else {
895 if (TempBlockPtr->Union.ContinuationPointer == (UINTN)NULL) {
896 break;
897 } else {
898 TempBlockPtr = (EFI_CAPSULE_BLOCK_DESCRIPTOR *)(UINTN)TempBlockPtr->Union.ContinuationPointer;
899 }
900 }
901 }
902}
903
910VOID
912 IN BOOLEAN DumpCapsuleInfo
913 )
914{
915 EFI_STATUS Status;
916 CHAR16 CapsuleVarName[30];
917 CHAR16 *TempVarName;
918 UINTN Index;
919 EFI_PHYSICAL_ADDRESS *CapsuleDataPtr64;
920 UINT16 *BootNext;
921 CHAR16 BootOptionName[20];
922 EFI_BOOT_MANAGER_LOAD_OPTION BootNextOptionEntry;
923 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
925 EFI_SHELL_PROTOCOL *ShellProtocol;
926
927 Index = 0;
928 CapsuleDataPtr64 = NULL;
929 BootNext = NULL;
930
931 ShellProtocol = GetShellProtocol ();
932 if (ShellProtocol == NULL) {
933 Print (L"Get Shell Protocol Fail\n");
934 return;
935 }
936
937 //
938 // Dump capsule provisioned on Memory
939 //
940 Print (L"#########################\n");
941 Print (L"### Capsule on Memory ###\n");
942 Print (L"#########################\n");
943 StrCpyS (CapsuleVarName, sizeof (CapsuleVarName)/sizeof (CHAR16), EFI_CAPSULE_VARIABLE_NAME);
944 TempVarName = CapsuleVarName + StrLen (CapsuleVarName);
945 while (TRUE) {
946 if (Index > 0) {
948 TempVarName,
949 sizeof (CapsuleVarName) - ((UINTN)TempVarName - (UINTN)CapsuleVarName),
950 0,
951 Index,
952 0
953 );
954 }
955
956 Status = GetVariable2 (
957 CapsuleVarName,
958 &gEfiCapsuleVendorGuid,
959 (VOID **)&CapsuleDataPtr64,
960 NULL
961 );
962 if (EFI_ERROR (Status) || (CapsuleDataPtr64 == NULL)) {
963 if (Index == 0) {
964 Print (L"No data.\n");
965 }
966
967 break;
968 }
969
970 Index++;
971 Print (L"Capsule Description at 0x%08x\n", *CapsuleDataPtr64);
972 DumpBlockDescriptors ((EFI_CAPSULE_BLOCK_DESCRIPTOR *)(UINTN)*CapsuleDataPtr64, DumpCapsuleInfo);
973 }
974
975 //
976 // Dump capsule provisioned on Disk
977 //
978 Print (L"#########################\n");
979 Print (L"### Capsule on Disk #####\n");
980 Print (L"#########################\n");
981 Status = GetVariable2 (
982 L"BootNext",
983 &gEfiGlobalVariableGuid,
984 (VOID **)&BootNext,
985 NULL
986 );
987 if (EFI_ERROR (Status) || (BootNext == NULL)) {
988 Print (L"Get BootNext Variable Fail. Status = %r\n", Status);
989 } else {
990 UnicodeSPrint (BootOptionName, sizeof (BootOptionName), L"Boot%04x", *BootNext);
991 Status = EfiBootManagerVariableToLoadOption (BootOptionName, &BootNextOptionEntry);
992 if (!EFI_ERROR (Status)) {
993 //
994 // Display description and device path
995 //
996 GetEfiSysPartitionFromBootOptionFilePath (BootNextOptionEntry.FilePath, &DevicePath, &Fs);
997 if (!EFI_ERROR (Status)) {
998 Print (L"Capsules are provisioned on BootOption: %s\n", BootNextOptionEntry.Description);
999 Print (L" %s %s\n", ShellProtocol->GetMapFromDevicePath (&DevicePath), ConvertDevicePathToText (DevicePath, TRUE, TRUE));
1000 DumpCapsuleFromDisk (Fs, DumpCapsuleInfo);
1001 }
1002 }
1003 }
1004}
1005
1017VOID
1019 IN UINTN ImageInfoSize,
1021 IN UINT32 DescriptorVersion,
1022 IN UINT8 DescriptorCount,
1023 IN UINTN DescriptorSize,
1024 IN UINT32 PackageVersion,
1025 IN CHAR16 *PackageVersionName
1026 )
1027{
1028 EFI_FIRMWARE_IMAGE_DESCRIPTOR *CurrentImageInfo;
1029 UINTN Index;
1030 UINTN Index2;
1031
1032 Print (L" DescriptorVersion - 0x%x\n", DescriptorVersion);
1033 Print (L" DescriptorCount - 0x%x\n", DescriptorCount);
1034 Print (L" DescriptorSize - 0x%x\n", DescriptorSize);
1035 Print (L" PackageVersion - 0x%x\n", PackageVersion);
1036 Print (L" PackageVersionName - \"%s\"\n", PackageVersionName);
1037 CurrentImageInfo = ImageInfo;
1038 for (Index = 0; Index < DescriptorCount; Index++) {
1039 Print (L" ImageDescriptor (%d)\n", Index);
1040 Print (L" ImageIndex - 0x%x\n", CurrentImageInfo->ImageIndex);
1041 Print (L" ImageTypeId - %g\n", &CurrentImageInfo->ImageTypeId);
1042 Print (L" ImageId - 0x%lx\n", CurrentImageInfo->ImageId);
1043 Print (L" ImageIdName - \"%s\"\n", CurrentImageInfo->ImageIdName);
1044 Print (L" Version - 0x%x\n", CurrentImageInfo->Version);
1045 Print (L" VersionName - \"%s\"\n", CurrentImageInfo->VersionName);
1046 Print (L" Size - 0x%x\n", CurrentImageInfo->Size);
1047 Print (L" AttributesSupported - 0x%lx\n", CurrentImageInfo->AttributesSupported);
1048 Print (L" IMAGE_UPDATABLE - 0x%lx\n", CurrentImageInfo->AttributesSupported & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE);
1049 Print (L" RESET_REQUIRED - 0x%lx\n", CurrentImageInfo->AttributesSupported & IMAGE_ATTRIBUTE_RESET_REQUIRED);
1050 Print (L" AUTHENTICATION_REQUIRED - 0x%lx\n", CurrentImageInfo->AttributesSupported & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED);
1051 Print (L" IN_USE - 0x%lx\n", CurrentImageInfo->AttributesSupported & IMAGE_ATTRIBUTE_IN_USE);
1052 Print (L" UEFI_IMAGE - 0x%lx\n", CurrentImageInfo->AttributesSupported & IMAGE_ATTRIBUTE_UEFI_IMAGE);
1053 Print (L" AttributesSetting - 0x%lx\n", CurrentImageInfo->AttributesSetting);
1054 Print (L" IMAGE_UPDATABLE - 0x%lx\n", CurrentImageInfo->AttributesSetting & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE);
1055 Print (L" RESET_REQUIRED - 0x%lx\n", CurrentImageInfo->AttributesSetting & IMAGE_ATTRIBUTE_RESET_REQUIRED);
1056 Print (L" AUTHENTICATION_REQUIRED - 0x%lx\n", CurrentImageInfo->AttributesSetting & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED);
1057 Print (L" IN_USE - 0x%lx\n", CurrentImageInfo->AttributesSetting & IMAGE_ATTRIBUTE_IN_USE);
1058 Print (L" UEFI_IMAGE - 0x%lx\n", CurrentImageInfo->AttributesSetting & IMAGE_ATTRIBUTE_UEFI_IMAGE);
1059 Print (L" Compatibilities - 0x%lx\n", CurrentImageInfo->Compatibilities);
1060 Print (L" COMPATIB_CHECK_SUPPORTED - 0x%lx\n", CurrentImageInfo->Compatibilities & IMAGE_COMPATIBILITY_CHECK_SUPPORTED);
1061 if (DescriptorVersion > 1) {
1062 Print (L" LowestSupportedImageVersion - 0x%x\n", CurrentImageInfo->LowestSupportedImageVersion);
1063 if (DescriptorVersion > 2) {
1064 Print (L" LastAttemptVersion - 0x%x\n", CurrentImageInfo->LastAttemptVersion);
1065 Print (L" LastAttemptStatus - 0x%x (%a)\n", CurrentImageInfo->LastAttemptStatus, LastAttemptStatusToString (CurrentImageInfo->LastAttemptStatus));
1066 Print (L" HardwareInstance - 0x%lx\n", CurrentImageInfo->HardwareInstance);
1067 if (DescriptorVersion > 3) {
1068 Print (L" Dependencies - ");
1069 if (CurrentImageInfo->Dependencies == NULL) {
1070 Print (L"NULL\n");
1071 } else {
1072 Index2 = 0;
1073 do {
1074 Print (L"%02x ", CurrentImageInfo->Dependencies->Dependencies[Index2]);
1075 } while (CurrentImageInfo->Dependencies->Dependencies[Index2++] != EFI_FMP_DEP_END);
1076
1077 Print (L"\n");
1078 }
1079 }
1080 }
1081 }
1082
1083 //
1084 // Use DescriptorSize to move ImageInfo Pointer to stay compatible with different ImageInfo version
1085 //
1086 CurrentImageInfo = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)((UINT8 *)CurrentImageInfo + DescriptorSize);
1087 }
1088}
1089
1099VOID
1101 IN UINT32 PackageVersion,
1102 IN CHAR16 *PackageVersionName,
1103 IN UINT32 PackageVersionNameMaxLen,
1104 IN UINT64 AttributesSupported,
1105 IN UINT64 AttributesSetting
1106 )
1107{
1108 Print (L" PackageVersion - 0x%x\n", PackageVersion);
1109 Print (L" PackageVersionName - \"%s\"\n", PackageVersionName);
1110 Print (L" PackageVersionNameMaxLen - 0x%x\n", PackageVersionNameMaxLen);
1111 Print (L" AttributesSupported - 0x%lx\n", AttributesSupported);
1112 Print (L" IMAGE_UPDATABLE - 0x%lx\n", AttributesSupported & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE);
1113 Print (L" RESET_REQUIRED - 0x%lx\n", AttributesSupported & IMAGE_ATTRIBUTE_RESET_REQUIRED);
1114 Print (L" AUTHENTICATION_REQUIRED - 0x%lx\n", AttributesSupported & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED);
1115 Print (L" AttributesSetting - 0x%lx\n", AttributesSetting);
1116 Print (L" IMAGE_UPDATABLE - 0x%lx\n", AttributesSetting & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE);
1117 Print (L" RESET_REQUIRED - 0x%lx\n", AttributesSetting & IMAGE_ATTRIBUTE_RESET_REQUIRED);
1118 Print (L" AUTHENTICATION_REQUIRED - 0x%lx\n", AttributesSetting & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED);
1119}
1120
1124VOID
1126 VOID
1127 )
1128{
1129 EFI_STATUS Status;
1131 EFI_HANDLE *HandleBuffer;
1132 UINTN NumberOfHandles;
1133 UINTN Index;
1134 EFI_FIRMWARE_IMAGE_DESCRIPTOR *FmpImageInfoBuf;
1135 UINTN ImageInfoSize;
1136 UINT32 FmpImageInfoDescriptorVer;
1137 UINT8 FmpImageInfoCount;
1138 UINTN DescriptorSize;
1139 UINT32 PackageVersion;
1140 CHAR16 *PackageVersionName;
1141 UINT32 PackageVersionNameMaxLen;
1142 UINT64 AttributesSupported;
1143 UINT64 AttributesSetting;
1144
1145 Print (L"############\n");
1146 Print (L"# FMP DATA #\n");
1147 Print (L"############\n");
1148 Status = gBS->LocateHandleBuffer (
1149 ByProtocol,
1150 &gEfiFirmwareManagementProtocolGuid,
1151 NULL,
1152 &NumberOfHandles,
1153 &HandleBuffer
1154 );
1155 if (EFI_ERROR (Status)) {
1156 Print (L"FMP protocol - %r\n", EFI_NOT_FOUND);
1157 return;
1158 }
1159
1160 for (Index = 0; Index < NumberOfHandles; Index++) {
1161 Status = gBS->HandleProtocol (
1162 HandleBuffer[Index],
1163 &gEfiFirmwareManagementProtocolGuid,
1164 (VOID **)&Fmp
1165 );
1166 if (EFI_ERROR (Status)) {
1167 continue;
1168 }
1169
1170 ImageInfoSize = 0;
1171 Status = Fmp->GetImageInfo (
1172 Fmp,
1173 &ImageInfoSize,
1174 NULL,
1175 NULL,
1176 NULL,
1177 NULL,
1178 NULL,
1179 NULL
1180 );
1181 if (Status != EFI_BUFFER_TOO_SMALL) {
1182 continue;
1183 }
1184
1185 FmpImageInfoBuf = NULL;
1186 FmpImageInfoBuf = AllocateZeroPool (ImageInfoSize);
1187 if (FmpImageInfoBuf == NULL) {
1188 Status = EFI_OUT_OF_RESOURCES;
1189 goto EXIT;
1190 }
1191
1192 PackageVersionName = NULL;
1193 Status = Fmp->GetImageInfo (
1194 Fmp,
1195 &ImageInfoSize, // ImageInfoSize
1196 FmpImageInfoBuf, // ImageInfo
1197 &FmpImageInfoDescriptorVer, // DescriptorVersion
1198 &FmpImageInfoCount, // DescriptorCount
1199 &DescriptorSize, // DescriptorSize
1200 &PackageVersion, // PackageVersion
1201 &PackageVersionName // PackageVersionName
1202 );
1203
1204 //
1205 // If FMP GetInformation interface failed, skip this resource
1206 //
1207 if (EFI_ERROR (Status)) {
1208 Print (L"FMP (%d) ImageInfo - %r\n", Index, Status);
1209 FreePool (FmpImageInfoBuf);
1210 continue;
1211 }
1212
1213 Print (L"FMP (%d) ImageInfo:\n", Index);
1215 ImageInfoSize, // ImageInfoSize
1216 FmpImageInfoBuf, // ImageInfo
1217 FmpImageInfoDescriptorVer, // DescriptorVersion
1218 FmpImageInfoCount, // DescriptorCount
1219 DescriptorSize, // DescriptorSize
1220 PackageVersion, // PackageVersion
1221 PackageVersionName // PackageVersionName
1222 );
1223
1224 if (PackageVersionName != NULL) {
1225 FreePool (PackageVersionName);
1226 }
1227
1228 FreePool (FmpImageInfoBuf);
1229
1230 //
1231 // Get package info
1232 //
1233 PackageVersionName = NULL;
1234 Status = Fmp->GetPackageInfo (
1235 Fmp,
1236 &PackageVersion, // PackageVersion
1237 &PackageVersionName, // PackageVersionName
1238 &PackageVersionNameMaxLen, // PackageVersionNameMaxLen
1239 &AttributesSupported, // AttributesSupported
1240 &AttributesSetting // AttributesSetting
1241 );
1242 if (EFI_ERROR (Status)) {
1243 Print (L"FMP (%d) PackageInfo - %r\n", Index, Status);
1244 } else {
1245 Print (L"FMP (%d) ImageInfo:\n", Index);
1247 PackageVersion, // PackageVersion
1248 PackageVersionName, // PackageVersionName
1249 PackageVersionNameMaxLen, // PackageVersionNameMaxLen
1250 AttributesSupported, // AttributesSupported
1251 AttributesSetting // AttributesSetting
1252 );
1253
1254 if (PackageVersionName != NULL) {
1255 FreePool (PackageVersionName);
1256 }
1257 }
1258 }
1259
1260 Print (L"\n");
1261
1262EXIT:
1263 FreePool (HandleBuffer);
1264}
1265
1277BOOLEAN
1280 IN UINT8 DescriptorCount,
1281 IN UINTN DescriptorSize,
1282 IN EFI_GUID *ImageTypeId
1283 )
1284{
1285 EFI_FIRMWARE_IMAGE_DESCRIPTOR *CurrentImageInfo;
1286 UINTN Index;
1287
1288 CurrentImageInfo = ImageInfo;
1289 for (Index = 0; Index < DescriptorCount; Index++) {
1290 if (CompareGuid (&CurrentImageInfo->ImageTypeId, ImageTypeId)) {
1291 return TRUE;
1292 }
1293
1294 CurrentImageInfo = (EFI_FIRMWARE_IMAGE_DESCRIPTOR *)((UINT8 *)CurrentImageInfo + DescriptorSize);
1295 }
1296
1297 return FALSE;
1298}
1299
1309 IN EFI_GUID *ImageTypeId
1310 )
1311{
1312 EFI_STATUS Status;
1315 EFI_HANDLE *HandleBuffer;
1316 UINTN NumberOfHandles;
1317 UINTN Index;
1318 EFI_FIRMWARE_IMAGE_DESCRIPTOR *FmpImageInfoBuf;
1319 UINTN ImageInfoSize;
1320 UINT32 FmpImageInfoDescriptorVer;
1321 UINT8 FmpImageInfoCount;
1322 UINTN DescriptorSize;
1323 UINT32 PackageVersion;
1324 CHAR16 *PackageVersionName;
1325
1326 Status = gBS->LocateHandleBuffer (
1327 ByProtocol,
1328 &gEfiFirmwareManagementProtocolGuid,
1329 NULL,
1330 &NumberOfHandles,
1331 &HandleBuffer
1332 );
1333 if (EFI_ERROR (Status)) {
1334 Print (L"FMP protocol - %r\n", EFI_NOT_FOUND);
1335 return NULL;
1336 }
1337
1338 TargetFmp = NULL;
1339 for (Index = 0; Index < NumberOfHandles; Index++) {
1340 Status = gBS->HandleProtocol (
1341 HandleBuffer[Index],
1342 &gEfiFirmwareManagementProtocolGuid,
1343 (VOID **)&Fmp
1344 );
1345 if (EFI_ERROR (Status)) {
1346 continue;
1347 }
1348
1349 ImageInfoSize = 0;
1350 Status = Fmp->GetImageInfo (
1351 Fmp,
1352 &ImageInfoSize,
1353 NULL,
1354 NULL,
1355 NULL,
1356 NULL,
1357 NULL,
1358 NULL
1359 );
1360 if (Status != EFI_BUFFER_TOO_SMALL) {
1361 continue;
1362 }
1363
1364 FmpImageInfoBuf = NULL;
1365 FmpImageInfoBuf = AllocateZeroPool (ImageInfoSize);
1366 if (FmpImageInfoBuf == NULL) {
1367 FreePool (HandleBuffer);
1368 Print (L"Out of resource\n");
1369 return NULL;
1370 }
1371
1372 PackageVersionName = NULL;
1373 Status = Fmp->GetImageInfo (
1374 Fmp,
1375 &ImageInfoSize, // ImageInfoSize
1376 FmpImageInfoBuf, // ImageInfo
1377 &FmpImageInfoDescriptorVer, // DescriptorVersion
1378 &FmpImageInfoCount, // DescriptorCount
1379 &DescriptorSize, // DescriptorSize
1380 &PackageVersion, // PackageVersion
1381 &PackageVersionName // PackageVersionName
1382 );
1383
1384 //
1385 // If FMP GetInformation interface failed, skip this resource
1386 //
1387 if (EFI_ERROR (Status)) {
1388 FreePool (FmpImageInfoBuf);
1389 continue;
1390 }
1391
1392 if (PackageVersionName != NULL) {
1393 FreePool (PackageVersionName);
1394 }
1395
1396 if (IsThisFmpImageInfo (FmpImageInfoBuf, FmpImageInfoCount, DescriptorSize, ImageTypeId)) {
1397 TargetFmp = Fmp;
1398 }
1399
1400 FreePool (FmpImageInfoBuf);
1401 if (TargetFmp != NULL) {
1402 break;
1403 }
1404 }
1405
1406 FreePool (HandleBuffer);
1407 return TargetFmp;
1408}
1409
1419VOID
1421 IN EFI_GUID *ImageTypeId,
1422 IN UINTN ImageIndex,
1423 IN CHAR16 *ImageName
1424 )
1425{
1426 EFI_STATUS Status;
1428 VOID *Image;
1429 UINTN ImageSize;
1430
1431 Fmp = FindFmpFromImageTypeId (ImageTypeId);
1432 if (Fmp == NULL) {
1433 Print (L"No FMP include ImageTypeId %g\n", ImageTypeId);
1434 return;
1435 }
1436
1437 if (ImageIndex > 0xFF) {
1438 Print (L"ImageIndex 0x%x too big\n", ImageIndex);
1439 return;
1440 }
1441
1442 Image = Fmp;
1443 ImageSize = 0;
1444 Status = Fmp->GetImage (Fmp, (UINT8)ImageIndex, Image, &ImageSize);
1445 if (Status != EFI_BUFFER_TOO_SMALL) {
1446 Print (L"Fmp->GetImage - %r\n", Status);
1447 return;
1448 }
1449
1450 Image = AllocatePool (ImageSize);
1451 if (Image == NULL) {
1452 Print (L"Allocate FmpImage 0x%x - %r\n", ImageSize, EFI_OUT_OF_RESOURCES);
1453 return;
1454 }
1455
1456 Status = Fmp->GetImage (Fmp, (UINT8)ImageIndex, Image, &ImageSize);
1457 if (EFI_ERROR (Status)) {
1458 Print (L"Fmp->GetImage - %r\n", Status);
1459 return;
1460 }
1461
1462 Status = WriteFileFromBuffer (ImageName, ImageSize, Image);
1463 Print (L"CapsuleApp: Dump %g ImageIndex (0x%x) to %s %r\n", ImageTypeId, ImageIndex, ImageName, Status);
1464
1465 FreePool (Image);
1466
1467 return;
1468}
UINT64 UINTN
INT64 INTN
EFI_STATUS ReadFileToBuffer(IN CHAR16 *FileName, OUT UINTN *BufferSize, OUT VOID **Buffer)
Definition: AppSupport.c:81
EFI_STATUS WriteFileFromBuffer(IN CHAR16 *FileName, IN UINTN BufferSize, IN VOID *Buffer)
Definition: AppSupport.c:159
EFI_SHELL_PROTOCOL * GetShellProtocol(VOID)
Definition: AppSupport.c:49
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
Definition: SafeString.c:226
INTN EFIAPI StrnCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString, IN UINTN Length)
Definition: String.c:162
RETURN_STATUS EFIAPI StrnCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
Definition: SafeString.c:310
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
EFI_STATUS GetEfiSysPartitionFromBootOptionFilePath(IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT EFI_DEVICE_PATH_PROTOCOL **FullPath, OUT EFI_SIMPLE_FILE_SYSTEM_PROTOCOL **Fs)
EFI_FIRMWARE_MANAGEMENT_PROTOCOL * FindFmpFromImageTypeId(IN EFI_GUID *ImageTypeId)
Definition: CapsuleDump.c:1308
VOID DumpProvisionedCapsule(IN BOOLEAN DumpCapsuleInfo)
Definition: CapsuleDump.c:911
CHAR8 * LastAttemptStatusToString(IN UINT32 LastAttemptStatus)
Definition: CapsuleDump.c:380
VOID DumpFmpCapsule(IN EFI_CAPSULE_HEADER *CapsuleHeader)
Definition: CapsuleDump.c:63
VOID DumpEsrt(IN EFI_SYSTEM_RESOURCE_TABLE *Esrt)
Definition: CapsuleDump.c:416
VOID DumpBlockDescriptors(IN EFI_CAPSULE_BLOCK_DESCRIPTOR *BlockDescriptors, IN BOOLEAN DumpCapsuleInfo)
Definition: CapsuleDump.c:872
VOID DumpFmpPackageInfo(IN UINT32 PackageVersion, IN CHAR16 *PackageVersionName, IN UINT32 PackageVersionNameMaxLen, IN UINT64 AttributesSupported, IN UINT64 AttributesSetting)
Definition: CapsuleDump.c:1100
VOID DumpEsrtData(VOID)
Definition: CapsuleDump.c:444
CHAR8 * FwTypeToString(IN UINT32 FwType)
Definition: CapsuleDump.c:361
BOOLEAN IsThisFmpImageInfo(IN EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo, IN UINT8 DescriptorCount, IN UINTN DescriptorSize, IN EFI_GUID *ImageTypeId)
Definition: CapsuleDump.c:1278
EFI_STATUS DumpCapsuleStatusVariable(VOID)
Definition: CapsuleDump.c:233
STATIC CHAR16 * UpperCaseString(IN CHAR16 *Str)
Definition: CapsuleDump.c:510
STATIC VOID PadStrInTail(IN CHAR16 *StrBuf, IN UINTN PadLen, IN CHAR16 Character)
Definition: CapsuleDump.c:562
INTN EFIAPI CompareFileNameInAlphabet(IN VOID *Left, IN VOID *Right)
Definition: CapsuleDump.c:636
BOOLEAN IsNestedFmpCapsule(IN EFI_CAPSULE_HEADER *CapsuleHeader)
Definition: CapsuleDump.c:117
EFI_STATUS DumpCapsuleFromDisk(IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs, IN BOOLEAN DumpCapsuleInfo)
Definition: CapsuleDump.c:698
VOID DumpEsrtEntry(IN EFI_SYSTEM_RESOURCE_ENTRY *EsrtEntry)
Definition: CapsuleDump.c:397
EFI_STATUS DumpCapsule(IN CHAR16 *CapsuleName)
Definition: CapsuleDump.c:175
STATIC VOID GetSubStringBeforePeriod(IN CHAR16 *Str, OUT CHAR16 *SubStr, OUT UINTN *SubStrLen)
Definition: CapsuleDump.c:536
VOID DumpFmpImage(IN EFI_GUID *ImageTypeId, IN UINTN ImageIndex, IN CHAR16 *ImageName)
Definition: CapsuleDump.c:1420
VOID DumpUxCapsule(IN EFI_CAPSULE_HEADER *CapsuleHeader)
Definition: CapsuleDump.c:35
BOOLEAN IsValidCapsuleHeader(IN EFI_CAPSULE_HEADER *CapsuleHeader, IN UINT64 CapsuleSize)
Definition: CapsuleApp.c:247
EFI_STATUS DumpCapsuleFromBuffer(IN EFI_CAPSULE_HEADER *CapsuleHeader)
Definition: CapsuleDump.c:474
STATIC VOID SplitFileNameExtension(IN CHAR16 *FileName, OUT CHAR16 *FileNameFirst, OUT CHAR16 *FileNameExtension)
Definition: CapsuleDump.c:593
VOID DumpFmpData(VOID)
Definition: CapsuleDump.c:1125
VOID DumpFmpImageInfo(IN UINTN ImageInfoSize, IN EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo, IN UINT32 DescriptorVersion, IN UINT8 DescriptorCount, IN UINTN DescriptorSize, IN UINT32 PackageVersion, IN CHAR16 *PackageVersionName)
Definition: CapsuleDump.c:1018
#define EFI_CAPSULE_VARIABLE_NAME
Definition: CapsuleVendor.h:33
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_STATUS EFIAPI FileHandleFindNextFile(IN EFI_FILE_HANDLE DirHandle, OUT EFI_FILE_INFO *Buffer, OUT BOOLEAN *NoFile)
EFI_STATUS EFIAPI FileHandleClose(IN EFI_FILE_HANDLE FileHandle)
EFI_STATUS EFIAPI FileHandleGetSize(IN EFI_FILE_HANDLE FileHandle, OUT UINT64 *Size)
EFI_STATUS EFIAPI FileHandleFindFirstFile(IN EFI_FILE_HANDLE DirHandle, OUT EFI_FILE_INFO **Buffer)
EFI_STATUS EFIAPI FileHandleRead(IN EFI_FILE_HANDLE FileHandle, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
#define IMAGE_ATTRIBUTE_UEFI_IMAGE
#define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED
#define IMAGE_ATTRIBUTE_RESET_REQUIRED
#define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE
#define IMAGE_ATTRIBUTE_IN_USE
#define IMAGE_COMPATIBILITY_CHECK_SUPPORTED
RETURN_STATUS EFIAPI UnicodeValueToStringS(IN OUT CHAR16 *Buffer, IN UINTN BufferSize, IN UINTN Flags, IN INT64 Value, IN UINTN Width)
Definition: PrintLib.c:652
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_FILE_INFO * FileInfo(IN EFI_FILE_HANDLE FHand)
VOID EFIAPI PerformQuickSort(IN OUT VOID *BufferToSort, IN CONST UINTN Count, IN CONST UINTN ElementSize, IN SORT_COMPARE CompareFunction)
Definition: BaseSortLib.c:36
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI EfiBootManagerVariableToLoadOption(IN CHAR16 *VariableName, IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
Definition: BmLoadOption.c:998
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
Definition: UefiLib.c:82
EFI_STATUS EFIAPI GetVariable2(IN CONST CHAR16 *Name, IN CONST EFI_GUID *Guid, OUT VOID **Value, OUT UINTN *Size OPTIONAL)
Definition: UefiLib.c:1317
UINTN EFIAPI Print(IN CONST CHAR16 *Format,...)
Definition: UefiLibPrint.c:113
@ ByProtocol
Definition: UefiSpec.h:1518
EFI_PHYSICAL_ADDRESS DataBlock
Definition: UefiSpec.h:1664
EFI_PHYSICAL_ADDRESS ContinuationPointer
Definition: UefiSpec.h:1671
UINT32 CapsuleImageSize
Definition: UefiSpec.h:1698
EFI_GUID CapsuleGuid
Definition: UefiSpec.h:1682
UINT64 Size
Definition: FileInfo.h:23
UINT64 Attribute
Definition: FileInfo.h:47
CHAR16 FileName[1]
Definition: FileInfo.h:52
Definition: Base.h:213