TianoCore EDK2 master
Loading...
Searching...
No Matches
EdkiiSystemCapsuleLib.c
Go to the documentation of this file.
1
14#include <PiDxe.h>
15
18#include <Guid/WinCertificate.h>
20#include <Guid/WinCertificate.h>
22
23#include <Library/BaseLib.h>
25#include <Library/DebugLib.h>
26#include <Library/PcdLib.h>
30
32
34UINTN mImageFmpInfoSize;
35EFI_GUID mEdkiiSystemFirmwareFileGuid;
36
47BOOLEAN
49 IN UINT8 ErasePolarity,
50 IN VOID *InBuffer,
51 IN UINTN BufferSize
52 )
53{
54 UINTN Count;
55 UINT8 EraseByte;
56 UINT8 *Buffer;
57
58 if (ErasePolarity == 1) {
59 EraseByte = 0xFF;
60 } else {
61 EraseByte = 0;
62 }
63
64 Buffer = InBuffer;
65 for (Count = 0; Count < BufferSize; Count++) {
66 if (Buffer[Count] != EraseByte) {
67 return FALSE;
68 }
69 }
70
71 return TRUE;
72}
73
87BOOLEAN
89 IN VOID *SectionBuffer,
90 IN UINT32 SectionBufferSize,
91 IN EFI_SECTION_TYPE SectionType,
92 IN UINTN SectionInstance,
93 OUT VOID **OutSectionBuffer,
94 OUT UINTN *OutSectionSize
95 )
96{
97 EFI_COMMON_SECTION_HEADER *SectionHeader;
98 UINTN SectionSize;
99 UINTN Instance;
100
101 DEBUG ((DEBUG_INFO, "GetSectionByType - Buffer: 0x%08x - 0x%08x\n", SectionBuffer, SectionBufferSize));
102
103 //
104 // Find Section
105 //
106 SectionHeader = SectionBuffer;
107
108 Instance = 0;
109 while ((UINTN)SectionHeader < (UINTN)SectionBuffer + SectionBufferSize) {
110 DEBUG ((DEBUG_INFO, "GetSectionByType - Section: 0x%08x\n", SectionHeader));
111 if (IS_SECTION2 (SectionHeader)) {
112 SectionSize = SECTION2_SIZE (SectionHeader);
113 } else {
114 SectionSize = SECTION_SIZE (SectionHeader);
115 }
116
117 if (SectionHeader->Type == SectionType) {
118 if (Instance == SectionInstance) {
119 *OutSectionBuffer = (UINT8 *)SectionHeader;
120 *OutSectionSize = SectionSize;
121 DEBUG ((DEBUG_INFO, "GetSectionByType - 0x%x - 0x%x\n", *OutSectionBuffer, *OutSectionSize));
122 return TRUE;
123 } else {
124 DEBUG ((DEBUG_INFO, "GetSectionByType - find section instance %x\n", Instance));
125 Instance++;
126 }
127 } else {
128 //
129 // Skip other section type
130 //
131 DEBUG ((DEBUG_INFO, "GetSectionByType - other section type 0x%x\n", SectionHeader->Type));
132 }
133
134 //
135 // Next Section
136 //
137 SectionHeader = (EFI_COMMON_SECTION_HEADER *)((UINTN)SectionHeader + ALIGN_VALUE (SectionSize, 4));
138 }
139
140 return FALSE;
141}
142
156BOOLEAN
158 IN VOID *FdStart,
159 IN UINTN FdSize,
160 IN EFI_GUID *FileName,
161 IN EFI_FV_FILETYPE Type,
162 OUT VOID **OutFfsBuffer,
163 OUT UINTN *OutFfsBufferSize
164 )
165{
166 UINTN FvSize;
169 EFI_FFS_FILE_HEADER *FfsHeader;
170 UINT32 FfsSize;
171 UINTN TestLength;
172 BOOLEAN FvFound;
173
174 DEBUG ((DEBUG_INFO, "GetFfsByName - FV: 0x%08x - 0x%08x\n", (UINTN)FdStart, (UINTN)FdSize));
175
176 FvFound = FALSE;
177 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)FdStart;
178 while ((UINTN)FvHeader < (UINTN)FdStart + FdSize - 1) {
179 FvSize = (UINTN)FdStart + FdSize - (UINTN)FvHeader;
180
181 if (FvHeader->Signature != EFI_FVH_SIGNATURE) {
182 FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *)((UINTN)FvHeader + SIZE_4KB);
183 continue;
184 }
185
186 DEBUG ((DEBUG_INFO, "checking FV....0x%08x - 0x%x\n", FvHeader, FvHeader->FvLength));
187 FvFound = TRUE;
188 if (FvHeader->FvLength > FvSize) {
189 DEBUG ((DEBUG_ERROR, "GetFfsByName - FvSize: 0x%08x, MaxSize - 0x%08x\n", (UINTN)FvHeader->FvLength, (UINTN)FvSize));
190 return FALSE;
191 }
192
193 FvSize = (UINTN)FvHeader->FvLength;
194
195 //
196 // Find FFS
197 //
198 if (FvHeader->ExtHeaderOffset != 0) {
199 FvExtHeader = (EFI_FIRMWARE_VOLUME_EXT_HEADER *)((UINT8 *)FvHeader + FvHeader->ExtHeaderOffset);
200 FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FvExtHeader + FvExtHeader->ExtHeaderSize);
201 } else {
202 FfsHeader = (EFI_FFS_FILE_HEADER *)((UINT8 *)FvHeader + FvHeader->HeaderLength);
203 }
204
205 FfsHeader = (EFI_FFS_FILE_HEADER *)((UINTN)FvHeader + ALIGN_VALUE ((UINTN)FfsHeader - (UINTN)FvHeader, 8));
206
207 while ((UINTN)FfsHeader < (UINTN)FvHeader + FvSize - 1) {
208 DEBUG ((DEBUG_INFO, "GetFfsByName - FFS: 0x%08x\n", FfsHeader));
209 TestLength = (UINTN)((UINTN)FvHeader + FvSize - (UINTN)FfsHeader);
210 if (TestLength > sizeof (EFI_FFS_FILE_HEADER)) {
211 TestLength = sizeof (EFI_FFS_FILE_HEADER);
212 }
213
214 if (IsBufferErased (1, FfsHeader, TestLength)) {
215 break;
216 }
217
218 if (IS_FFS_FILE2 (FfsHeader)) {
219 FfsSize = FFS_FILE2_SIZE (FfsHeader);
220 } else {
221 FfsSize = FFS_FILE_SIZE (FfsHeader);
222 }
223
224 if (CompareGuid (FileName, &FfsHeader->Name) &&
225 ((Type == EFI_FV_FILETYPE_ALL) || (FfsHeader->Type == Type)))
226 {
227 *OutFfsBuffer = FfsHeader;
228 *OutFfsBufferSize = FfsSize;
229 return TRUE;
230 } else {
231 //
232 // Any other type is not allowed
233 //
234 DEBUG ((DEBUG_INFO, "GetFfsByName - other FFS type 0x%x, name %g\n", FfsHeader->Type, &FfsHeader->Name));
235 }
236
237 //
238 // Next File
239 //
240 FfsHeader = (EFI_FFS_FILE_HEADER *)((UINTN)FfsHeader + ALIGN_VALUE (FfsSize, 8));
241 }
242
243 //
244 // Next FV
245 //
246 FvHeader = (VOID *)(UINTN)((UINTN)FvHeader + FvHeader->FvLength);
247 }
248
249 if (!FvFound) {
250 DEBUG ((DEBUG_ERROR, "GetFfsByName - NO FV Found\n"));
251 }
252
253 return FALSE;
254}
255
267BOOLEAN
268EFIAPI
270 IN VOID *AuthenticatedImage,
271 IN UINTN AuthenticatedImageSize,
272 OUT VOID **DriverFvImage,
273 OUT UINTN *DriverFvImageSize
274 )
275{
276 BOOLEAN Result;
277 UINT32 FileHeaderSize;
278
279 *DriverFvImage = NULL;
280 *DriverFvImageSize = 0;
281
282 Result = GetFfsByName (AuthenticatedImage, AuthenticatedImageSize, &gEdkiiSystemFmpCapsuleDriverFvFileGuid, EFI_FV_FILETYPE_RAW, DriverFvImage, DriverFvImageSize);
283 if (!Result) {
284 return FALSE;
285 }
286
287 if (IS_FFS_FILE2 (*DriverFvImage)) {
288 FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
289 } else {
290 FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
291 }
292
293 *DriverFvImage = (UINT8 *)*DriverFvImage + FileHeaderSize;
294 *DriverFvImageSize = *DriverFvImageSize - FileHeaderSize;
295
296 return Result;
297}
298
310BOOLEAN
311EFIAPI
313 IN VOID *AuthenticatedImage,
314 IN UINTN AuthenticatedImageSize,
315 OUT VOID **ConfigImage,
316 OUT UINTN *ConfigImageSize
317 )
318{
319 BOOLEAN Result;
320 UINT32 FileHeaderSize;
321
322 *ConfigImage = NULL;
323 *ConfigImageSize = 0;
324
325 Result = GetFfsByName (AuthenticatedImage, AuthenticatedImageSize, &gEdkiiSystemFmpCapsuleConfigFileGuid, EFI_FV_FILETYPE_RAW, ConfigImage, ConfigImageSize);
326 if (!Result) {
327 return FALSE;
328 }
329
330 if (IS_FFS_FILE2 (*ConfigImage)) {
331 FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
332 } else {
333 FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
334 }
335
336 *ConfigImage = (UINT8 *)*ConfigImage + FileHeaderSize;
337 *ConfigImageSize = *ConfigImageSize - FileHeaderSize;
338
339 return Result;
340}
341
356BOOLEAN
357EFIAPI
359 IN VOID *Image,
360 IN UINTN ImageSize,
361 OUT UINT32 *LastAttemptStatus,
362 OUT VOID **AuthenticatedImage,
363 OUT UINTN *AuthenticatedImageSize
364 )
365{
367 EFI_STATUS Status;
368 GUID *CertType;
369 VOID *PublicKeyData;
370 UINTN PublicKeyDataLength;
371
372 DEBUG ((DEBUG_INFO, "ExtractAuthenticatedImage - Image: 0x%08x - 0x%08x\n", (UINTN)Image, (UINTN)ImageSize));
373
374 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
375 if ((Image == NULL) || (ImageSize == 0)) {
376 return FALSE;
377 }
378
379 ImageAuth = (EFI_FIRMWARE_IMAGE_AUTHENTICATION *)Image;
380 if (ImageSize < sizeof (EFI_FIRMWARE_IMAGE_AUTHENTICATION)) {
381 DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - ImageSize too small\n"));
382 return FALSE;
383 }
384
385 if (ImageAuth->AuthInfo.Hdr.dwLength <= OFFSET_OF (WIN_CERTIFICATE_UEFI_GUID, CertData)) {
386 DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - dwLength too small\n"));
387 return FALSE;
388 }
389
390 if ((UINTN)ImageAuth->AuthInfo.Hdr.dwLength > MAX_UINTN - sizeof (UINT64)) {
391 DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - dwLength too big\n"));
392 return FALSE;
393 }
394
395 if (ImageSize <= sizeof (ImageAuth->MonotonicCount) + ImageAuth->AuthInfo.Hdr.dwLength) {
396 DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - ImageSize too small\n"));
397 return FALSE;
398 }
399
400 if (ImageAuth->AuthInfo.Hdr.wRevision != 0x0200) {
401 DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - wRevision: 0x%02x, expect - 0x%02x\n", (UINTN)ImageAuth->AuthInfo.Hdr.wRevision, (UINTN)0x0200));
402 return FALSE;
403 }
404
405 if (ImageAuth->AuthInfo.Hdr.wCertificateType != WIN_CERT_TYPE_EFI_GUID) {
406 DEBUG ((DEBUG_ERROR, "ExtractAuthenticatedImage - wCertificateType: 0x%02x, expect - 0x%02x\n", (UINTN)ImageAuth->AuthInfo.Hdr.wCertificateType, (UINTN)WIN_CERT_TYPE_EFI_GUID));
407 return FALSE;
408 }
409
410 CertType = &ImageAuth->AuthInfo.CertType;
411 DEBUG ((DEBUG_INFO, "ExtractAuthenticatedImage - CertType: %g\n", CertType));
412
413 if (CompareGuid (&gEfiCertPkcs7Guid, CertType)) {
414 PublicKeyData = PcdGetPtr (PcdPkcs7CertBuffer);
415 PublicKeyDataLength = PcdGetSize (PcdPkcs7CertBuffer);
416 } else if (CompareGuid (&gEfiCertTypeRsa2048Sha256Guid, CertType)) {
417 PublicKeyData = PcdGetPtr (PcdRsa2048Sha256PublicKeyBuffer);
418 PublicKeyDataLength = PcdGetSize (PcdRsa2048Sha256PublicKeyBuffer);
419 } else {
420 return FALSE;
421 }
422
423 ASSERT (PublicKeyData != NULL);
424 ASSERT (PublicKeyDataLength != 0);
425
426 Status = AuthenticateFmpImage (
427 ImageAuth,
428 ImageSize,
429 PublicKeyData,
430 PublicKeyDataLength
431 );
432 switch (Status) {
433 case RETURN_SUCCESS:
434 *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;
435 break;
437 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_AUTH_ERROR;
438 break;
440 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
441 break;
443 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
444 break;
446 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INSUFFICIENT_RESOURCES;
447 break;
448 default:
449 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_UNSUCCESSFUL;
450 break;
451 }
452
453 if (EFI_ERROR (Status)) {
454 return FALSE;
455 }
456
457 if (AuthenticatedImage != NULL) {
458 *AuthenticatedImage = (UINT8 *)ImageAuth + ImageAuth->AuthInfo.Hdr.dwLength + sizeof (ImageAuth->MonotonicCount);
459 }
460
461 if (AuthenticatedImageSize != NULL) {
462 *AuthenticatedImageSize = ImageSize - ImageAuth->AuthInfo.Hdr.dwLength - sizeof (ImageAuth->MonotonicCount);
463 }
464
465 return TRUE;
466}
467
479BOOLEAN
480EFIAPI
482 IN VOID *SystemFirmwareImage,
483 IN UINTN SystemFirmwareImageSize,
485 OUT UINTN *ImageFmpInfoSize
486 )
487{
488 BOOLEAN Result;
489 UINT32 SectionHeaderSize;
490 UINT32 FileHeaderSize;
491
492 *ImageFmpInfo = NULL;
493 *ImageFmpInfoSize = 0;
494
495 Result = GetFfsByName (SystemFirmwareImage, SystemFirmwareImageSize, &gEdkiiSystemFirmwareImageDescriptorFileGuid, EFI_FV_FILETYPE_ALL, (VOID **)ImageFmpInfo, ImageFmpInfoSize);
496 if (!Result) {
497 return FALSE;
498 }
499
500 if (IS_FFS_FILE2 (*ImageFmpInfo)) {
501 FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
502 } else {
503 FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
504 }
505
506 *ImageFmpInfo = (VOID *)((UINT8 *)*ImageFmpInfo + FileHeaderSize);
507 *ImageFmpInfoSize = *ImageFmpInfoSize - FileHeaderSize;
508
509 Result = GetSectionByType (*ImageFmpInfo, (UINT32)*ImageFmpInfoSize, EFI_SECTION_RAW, 0, (VOID **)ImageFmpInfo, ImageFmpInfoSize);
510 if (!Result) {
511 return FALSE;
512 }
513
514 if (IS_SECTION2 (*ImageFmpInfo)) {
515 SectionHeaderSize = sizeof (EFI_RAW_SECTION2);
516 } else {
517 SectionHeaderSize = sizeof (EFI_RAW_SECTION);
518 }
519
520 *ImageFmpInfo = (VOID *)((UINT8 *)*ImageFmpInfo + SectionHeaderSize);
521 *ImageFmpInfoSize = *ImageFmpInfoSize - SectionHeaderSize;
522
523 return TRUE;
524}
525
537BOOLEAN
538EFIAPI
540 IN VOID *AuthenticatedImage,
541 IN UINTN AuthenticatedImageSize,
542 OUT VOID **SystemFirmwareImage,
543 OUT UINTN *SystemFirmwareImageSize
544 )
545{
546 BOOLEAN Result;
547 UINT32 FileHeaderSize;
548
549 *SystemFirmwareImage = NULL;
550 *SystemFirmwareImageSize = 0;
551
552 Result = GetFfsByName (AuthenticatedImage, AuthenticatedImageSize, &mEdkiiSystemFirmwareFileGuid, EFI_FV_FILETYPE_RAW, SystemFirmwareImage, SystemFirmwareImageSize);
553 if (!Result) {
554 // no nested FV, just return all data.
555 *SystemFirmwareImage = AuthenticatedImage;
556 *SystemFirmwareImageSize = AuthenticatedImageSize;
557
558 return TRUE;
559 }
560
561 if (IS_FFS_FILE2 (*SystemFirmwareImage)) {
562 FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER2);
563 } else {
564 FileHeaderSize = sizeof (EFI_FFS_FILE_HEADER);
565 }
566
567 *SystemFirmwareImage = (UINT8 *)*SystemFirmwareImage + FileHeaderSize;
568 *SystemFirmwareImageSize = *SystemFirmwareImageSize - FileHeaderSize;
569
570 return Result;
571}
572
592EFIAPI
594 IN VOID *Image,
595 IN UINTN ImageSize,
596 IN BOOLEAN ForceVersionMatch,
597 OUT UINT32 *LastAttemptVersion,
598 OUT UINT32 *LastAttemptStatus,
599 OUT VOID **AuthenticatedImage,
600 OUT UINTN *AuthenticatedImageSize
601 )
602{
603 BOOLEAN Result;
605 UINTN ImageFmpInfoSize;
606 EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *CurrentImageFmpInfo;
607 UINTN CurrentImageFmpInfoSize;
608 VOID *SystemFirmwareImage;
609 UINTN SystemFirmwareImageSize;
610
611 *LastAttemptVersion = 0;
612
613 //
614 // NOTE: This function need run in an isolated environment.
615 // Do not touch FMP protocol and its private structure.
616 //
617 if (mImageFmpInfo == NULL) {
618 DEBUG ((DEBUG_INFO, "ImageFmpInfo is not set\n"));
619 return EFI_SECURITY_VIOLATION;
620 }
621
622 Result = ExtractAuthenticatedImage ((VOID *)Image, ImageSize, LastAttemptStatus, AuthenticatedImage, AuthenticatedImageSize);
623 if (!Result) {
624 DEBUG ((DEBUG_INFO, "ExtractAuthenticatedImage - fail\n"));
625 return EFI_SECURITY_VIOLATION;
626 }
627
628 DEBUG ((DEBUG_INFO, "AuthenticatedImage - 0x%x - 0x%x\n", *AuthenticatedImage, *AuthenticatedImageSize));
629
630 Result = ExtractSystemFirmwareImage (*AuthenticatedImage, *AuthenticatedImageSize, &SystemFirmwareImage, &SystemFirmwareImageSize);
631 if (!Result) {
632 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
633 DEBUG ((DEBUG_INFO, "ExtractSystemFirmwareImage - fail\n"));
634 return EFI_SECURITY_VIOLATION;
635 }
636
637 DEBUG ((DEBUG_INFO, "SystemFirmwareImage - 0x%x - 0x%x\n", SystemFirmwareImage, SystemFirmwareImageSize));
638
639 Result = ExtractSystemFirmwareImageFmpInfo (SystemFirmwareImage, SystemFirmwareImageSize, &ImageFmpInfo, &ImageFmpInfoSize);
640 if (!Result) {
641 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
642 DEBUG ((DEBUG_INFO, "ExtractSystemFirmwareImageFmpInfo - fail\n"));
643 return EFI_SECURITY_VIOLATION;
644 }
645
646 *LastAttemptVersion = ImageFmpInfo->Version;
647 DEBUG ((DEBUG_INFO, "ImageFmpInfo - 0x%x - 0x%x\n", ImageFmpInfo, ImageFmpInfoSize));
648 DEBUG ((DEBUG_INFO, "NewImage Version - 0x%x\n", ImageFmpInfo->Version));
649 DEBUG ((DEBUG_INFO, "NewImage LowestSupportedImageVersion - 0x%x\n", ImageFmpInfo->LowestSupportedImageVersion));
650
651 CurrentImageFmpInfo = mImageFmpInfo;
652 CurrentImageFmpInfoSize = mImageFmpInfoSize;
653
654 DEBUG ((DEBUG_INFO, "ImageFmpInfo - 0x%x - 0x%x\n", CurrentImageFmpInfo, CurrentImageFmpInfoSize));
655 DEBUG ((DEBUG_INFO, "Current Version - 0x%x\n", CurrentImageFmpInfo->Version));
656 DEBUG ((DEBUG_INFO, "Current LowestSupportedImageVersion - 0x%x\n", CurrentImageFmpInfo->LowestSupportedImageVersion));
657
658 if (ForceVersionMatch) {
659 if (CurrentImageFmpInfo->Version != ImageFmpInfo->Version) {
660 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION;
661 DEBUG ((DEBUG_INFO, "ForceVersionMatch check - fail\n"));
662 return EFI_SECURITY_VIOLATION;
663 }
664 } else {
665 if (ImageFmpInfo->Version < CurrentImageFmpInfo->LowestSupportedImageVersion) {
666 *LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INCORRECT_VERSION;
667 DEBUG ((DEBUG_INFO, "LowestSupportedImageVersion check - fail\n"));
668 return EFI_SECURITY_VIOLATION;
669 }
670 }
671
672 *LastAttemptStatus = LAST_ATTEMPT_STATUS_SUCCESS;
673 return EFI_SUCCESS;
674}
675
685VOID
686EFIAPI
688 IN CONST GUID *CallBackGuid OPTIONAL,
689 IN UINTN CallBackToken,
690 IN OUT VOID *TokenData,
691 IN UINTN TokenDataSize
692 )
693{
694 if (CompareGuid (CallBackGuid, &gEfiSignedCapsulePkgTokenSpaceGuid) &&
695 (CallBackToken == PcdToken (PcdEdkiiSystemFirmwareImageDescriptor)))
696 {
697 mImageFmpInfoSize = TokenDataSize;
698 mImageFmpInfo = AllocateCopyPool (mImageFmpInfoSize, TokenData);
699 ASSERT (mImageFmpInfo != NULL);
700 //
701 // Cancel Callback after get the real set value
702 //
704 &gEfiSignedCapsulePkgTokenSpaceGuid,
705 PcdToken (PcdEdkiiSystemFirmwareImageDescriptor),
707 );
708 }
709
710 if (CompareGuid (CallBackGuid, &gEfiSignedCapsulePkgTokenSpaceGuid) &&
711 (CallBackToken == PcdToken (PcdEdkiiSystemFirmwareFileGuid)))
712 {
713 CopyGuid (&mEdkiiSystemFirmwareFileGuid, TokenData);
714 //
715 // Cancel Callback after get the real set value
716 //
718 &gEfiSignedCapsulePkgTokenSpaceGuid,
719 PcdToken (PcdEdkiiSystemFirmwareFileGuid),
721 );
722 }
723}
724
731EFIAPI
733 VOID
734 )
735{
736 mImageFmpInfoSize = PcdGetSize (PcdEdkiiSystemFirmwareImageDescriptor);
737 mImageFmpInfo = PcdGetPtr (PcdEdkiiSystemFirmwareImageDescriptor);
738 //
739 // Verify Firmware Image Descriptor first
740 //
741 if ((mImageFmpInfoSize < sizeof (EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR)) ||
742 (mImageFmpInfo->Signature != EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE))
743 {
744 //
745 // SystemFirmwareImageDescriptor is not set.
746 // Register PCD set callback to hook PCD value set.
747 //
748 mImageFmpInfo = NULL;
749 mImageFmpInfoSize = 0;
751 &gEfiSignedCapsulePkgTokenSpaceGuid,
752 PcdToken (PcdEdkiiSystemFirmwareImageDescriptor),
754 );
755 } else {
756 mImageFmpInfo = AllocateCopyPool (mImageFmpInfoSize, mImageFmpInfo);
757 ASSERT (mImageFmpInfo != NULL);
758 }
759
760 CopyGuid (&mEdkiiSystemFirmwareFileGuid, PcdGetPtr (PcdEdkiiSystemFirmwareFileGuid));
761 //
762 // Verify GUID value first
763 //
764 if (CompareGuid (&mEdkiiSystemFirmwareFileGuid, &gZeroGuid)) {
766 &gEfiSignedCapsulePkgTokenSpaceGuid,
767 PcdToken (PcdEdkiiSystemFirmwareFileGuid),
769 );
770 }
771
772 return EFI_SUCCESS;
773}
UINT64 UINTN
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
BOOLEAN EFIAPI ExtractDriverFvImage(IN VOID *AuthenticatedImage, IN UINTN AuthenticatedImageSize, OUT VOID **DriverFvImage, OUT UINTN *DriverFvImageSize)
BOOLEAN EFIAPI ExtractSystemFirmwareImage(IN VOID *AuthenticatedImage, IN UINTN AuthenticatedImageSize, OUT VOID **SystemFirmwareImage, OUT UINTN *SystemFirmwareImageSize)
EFI_STATUS EFIAPI EdkiiSystemCapsuleLibConstructor(VOID)
VOID EFIAPI EdkiiSystemCapsuleLibPcdCallBack(IN CONST GUID *CallBackGuid OPTIONAL, IN UINTN CallBackToken, IN OUT VOID *TokenData, IN UINTN TokenDataSize)
BOOLEAN EFIAPI ExtractSystemFirmwareImageFmpInfo(IN VOID *SystemFirmwareImage, IN UINTN SystemFirmwareImageSize, OUT EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR **ImageFmpInfo, OUT UINTN *ImageFmpInfoSize)
BOOLEAN EFIAPI ExtractAuthenticatedImage(IN VOID *Image, IN UINTN ImageSize, OUT UINT32 *LastAttemptStatus, OUT VOID **AuthenticatedImage, OUT UINTN *AuthenticatedImageSize)
EFI_STATUS EFIAPI CapsuleAuthenticateSystemFirmware(IN VOID *Image, IN UINTN ImageSize, IN BOOLEAN ForceVersionMatch, OUT UINT32 *LastAttemptVersion, OUT UINT32 *LastAttemptStatus, OUT VOID **AuthenticatedImage, OUT UINTN *AuthenticatedImageSize)
BOOLEAN IsBufferErased(IN UINT8 ErasePolarity, IN VOID *InBuffer, IN UINTN BufferSize)
BOOLEAN EFIAPI ExtractConfigImage(IN VOID *AuthenticatedImage, IN UINTN AuthenticatedImageSize, OUT VOID **ConfigImage, OUT UINTN *ConfigImageSize)
BOOLEAN GetFfsByName(IN VOID *FdStart, IN UINTN FdSize, IN EFI_GUID *FileName, IN EFI_FV_FILETYPE Type, OUT VOID **OutFfsBuffer, OUT UINTN *OutFfsBufferSize)
BOOLEAN GetSectionByType(IN VOID *SectionBuffer, IN UINT32 SectionBufferSize, IN EFI_SECTION_TYPE SectionType, IN UINTN SectionInstance, OUT VOID **OutSectionBuffer, OUT UINTN *OutSectionSize)
#define EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE
EFI_GUID gEdkiiSystemFirmwareImageDescriptorFileGuid
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
RETURN_STATUS EFIAPI AuthenticateFmpImage(IN EFI_FIRMWARE_IMAGE_AUTHENTICATION *Image, IN UINTN ImageSize, IN CONST UINT8 *PublicKeyData, IN UINTN PublicKeyDataLength)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define RETURN_UNSUPPORTED
Definition: Base.h:1081
#define RETURN_OUT_OF_RESOURCES
Definition: Base.h:1114
#define RETURN_SECURITY_VIOLATION
Definition: Base.h:1203
#define ALIGN_VALUE(Value, Alignment)
Definition: Base.h:948
#define RETURN_SUCCESS
Definition: Base.h:1066
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OFFSET_OF(TYPE, Field)
Definition: Base.h:758
#define OUT
Definition: Base.h:284
#define RETURN_INVALID_PARAMETER
Definition: Base.h:1076
#define DEBUG(Expression)
Definition: DebugLib.h:434
VOID EFIAPI LibPcdCallbackOnSet(IN CONST GUID *Guid OPTIONAL, IN UINTN TokenNumber, IN PCD_CALLBACK NotificationFunction)
Definition: PcdLib.c:716
#define PcdGetSize(TokenName)
Definition: PcdLib.h:440
#define PcdToken(TokenName)
Definition: PcdLib.h:36
VOID EFIAPI LibPcdCancelCallback(IN CONST GUID *Guid OPTIONAL, IN UINTN TokenNumber, IN PCD_CALLBACK NotificationFunction)
Definition: PcdLib.c:741
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
#define EFI_FV_FILETYPE_ALL
EFI_COMMON_SECTION_HEADER EFI_RAW_SECTION
#define FFS_FILE_SIZE(FfsFileHeaderPtr)
#define SECTION_SIZE(SectionHeaderPtr)
#define LAST_ATTEMPT_STATUS_SUCCESS
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
WIN_CERTIFICATE_UEFI_GUID AuthInfo
Definition: Base.h:213
UINT16 wCertificateType