--- /dev/null
+/** @file\r
+ System Firmware descriptor producer.\r
+\r
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
+ This program and the accompanying materials\r
+ are licensed and made available under the terms and conditions of the BSD License\r
+ which accompanies this distribution. The full text of the license may be found at\r
+ http://opensource.org/licenses/bsd-license.php\r
+\r
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Protocol/FirmwareManagement.h>\r
+#include <Guid/EdkiiSystemFmpCapsule.h>\r
+\r
+/**\r
+ Entrypoint for SystemFirmwareDescriptor PEIM.\r
+\r
+ @param[in] FileHandle Handle of the file being invoked.\r
+ @param[in] PeiServices Describes the list of possible PEI Services.\r
+\r
+ @retval EFI_SUCCESS PPI successfully installed.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SystemFirmwareDescriptorPeimEntry (\r
+ IN EFI_PEI_FILE_HANDLE FileHandle,\r
+ IN CONST EFI_PEI_SERVICES **PeiServices\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *Descriptor;\r
+ UINTN Size;\r
+ UINTN Index;\r
+ UINT32 AuthenticationStatus;\r
+\r
+ //\r
+ // Search RAW section.\r
+ //\r
+ Index = 0;\r
+ while (TRUE) {\r
+ Status = PeiServicesFfsFindSectionData3(EFI_SECTION_RAW, Index, FileHandle, (VOID **)&Descriptor, &AuthenticationStatus);\r
+ if (EFI_ERROR(Status)) {\r
+ // Should not happen, must something wrong in FDF.\r
+ ASSERT(FALSE);\r
+ return EFI_NOT_FOUND;\r
+ }\r
+ if (Descriptor->Signature == EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR_SIGNATURE) {\r
+ break;\r
+ }\r
+ Index++;\r
+ }\r
+\r
+ DEBUG((DEBUG_INFO, "EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR size - 0x%x\n", Descriptor->Length));\r
+\r
+ Size = Descriptor->Length;\r
+ PcdSetPtrS (PcdEdkiiSystemFirmwareImageDescriptor, &Size, Descriptor);\r
+\r
+ return EFI_SUCCESS;\r
+}\r