--- /dev/null
+/*++\r
+\r
+Copyright (c) 2006 - 2008, Intel Corporation \r
+All rights reserved. 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
+Module Name:\r
+ UnixFwh.c\r
+ \r
+Abstract:\r
+ PEIM to abstract construction of firmware volume in an Unix environment.\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#include "PiPei.h"\r
+#include <Ppi/UnixFwh.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeUnixFwh (\r
+ IN EFI_FFS_FILE_HEADER *FfsHeader,\r
+ IN EFI_PEI_SERVICES **PeiServices\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Perform a call-back into the SEC simulator to get address of the Firmware Hub\r
+\r
+Arguments:\r
+ FfsHeader - Ffs Header availible to every PEIM\r
+ PeiServices - General purpose services available to every PEIM.\r
+ \r
+Returns:\r
+ None\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;\r
+ UNIX_FWH_PPI *FwhPpi;\r
+ EFI_PHYSICAL_ADDRESS FdBase;\r
+ EFI_FIRMWARE_VOLUME_HEADER *FvHeader;\r
+ UINT64 FdSize;\r
+ UINTN Index;\r
+\r
+ DEBUG ((EFI_D_ERROR, "Unix Firmware Volume PEIM Loaded\n"));\r
+\r
+ //\r
+ // Get the Fwh Information PPI\r
+ //\r
+ Status = (**PeiServices).LocatePpi (\r
+ PeiServices,\r
+ &gUnixFwhPpiGuid, // GUID\r
+ 0, // INSTANCE\r
+ &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR\r
+ (VOID **)&FwhPpi // PPI\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ Index = 0;\r
+ do {\r
+ //\r
+ // Get information about all the FD's in the system\r
+ //\r
+ Status = FwhPpi->UnixFwh (Index, &FdBase, &FdSize);\r
+ if (!EFI_ERROR (Status)) {\r
+ //\r
+ // Assume the FD starts with an FV header\r
+ //\r
+ FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FdBase;\r
+\r
+ //\r
+ // Make an FV Hob for the first FV in the FD\r
+ //\r
+ BuildFvHob (FdBase, FvHeader->FvLength);\r
+\r
+ if (Index == 0) {\r
+ //\r
+ // Assume the first FD was produced by the NT32.DSC\r
+ // All these strange offests are needed to keep in\r
+ // sync with the FlashMap and NT32.dsc file\r
+ //\r
+ BuildResourceDescriptorHob (\r
+ EFI_RESOURCE_FIRMWARE_DEVICE,\r
+ (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),\r
+ FdBase,\r
+ ( \r
+ FvHeader->FvLength + \r
+ PcdGet32 (PcdFlashNvStorageVariableSize) +\r
+ PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +\r
+ PcdGet32 (PcdFlashNvStorageFtwSpareSize) +\r
+ PcdGet32 (PcdUnixFlashNvStorageEventLogSize)\r
+ )\r
+ );\r
+\r
+ //\r
+ // Hard code the address of the spare block and variable services.\r
+ // Assume it's a hard coded offset from FV0 in FD0.\r
+ //\r
+ FdSize = \r
+ PcdGet32 (PcdFlashNvStorageVariableSize) +\r
+ PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +\r
+ PcdGet32 (PcdFlashNvStorageFtwSpareSize) +\r
+ PcdGet32 (PcdUnixFlashNvStorageEventLogSize);\r
+\r
+ BuildFvHob (FdBase + PcdGet32 (PcdUnixFlashNvStorageVariableBase), FdSize);\r
+ } else {\r
+ //\r
+ // For other FD's just map them in.\r
+ //\r
+ BuildResourceDescriptorHob (\r
+ EFI_RESOURCE_FIRMWARE_DEVICE,\r
+ (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),\r
+ FdBase,\r
+ FdSize\r
+ );\r
+ }\r
+ }\r
+\r
+ Index++;\r
+ } while (!EFI_ERROR (Status));\r
+\r
+ return Status;\r
+}\r