--- /dev/null
+## @file\r
+# This FDF include file computes the end of the scratch buffer used in\r
+# DecompressMemFvs() [OvmfPkg/Sec/SecMain.c]. It is based on the decompressed\r
+# (ie. original) size of the LZMA-compressed section of the one FFS file in\r
+# the FVMAIN_COMPACT firmware volume.\r
+#\r
+# Copyright (C) 2015, Red Hat, Inc.\r
+#\r
+# This program and the accompanying materials are licensed and made available\r
+# under the terms and conditions of the BSD License which accompanies this\r
+# 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\r
+# IMPLIED.\r
+##\r
+\r
+# The GUID EE4E5898-3914-4259-9D6E-DC7BD79403CF means "LzmaCustomDecompress".\r
+# The decompressed output will have the following structure (see the file\r
+# "9E21FD93-9C72-4c15-8C4B-E77F1DB2D792SEC1.guided.dummy" in the\r
+# Build/Ovmf*/*/FV/Ffs/9E21FD93-9C72-4c15-8C4B-E77F1DB2D792/ directory):\r
+#\r
+# Size Contents\r
+# ------------------- --------------------------------------------------------\r
+# 4 EFI_COMMON_SECTION_HEADER, stating size 124 (0x7C) and\r
+# type 0x19 (EFI_SECTION_RAW). The purpose of this section\r
+# is to pad the start of PEIFV to 128 bytes.\r
+# 120 Zero bytes (padding).\r
+#\r
+# 4 EFI_COMMON_SECTION_HEADER, stating size\r
+# (PcdOvmfPeiMemFvSize + 4), and type 0x17\r
+# (EFI_SECTION_FIRMWARE_VOLUME_IMAGE).\r
+# PcdOvmfPeiMemFvSize PEIFV. Note that the above sizes pad the offset of this\r
+# object to 128 bytes. See also the "guided.dummy.txt"\r
+# file in the same directory.\r
+#\r
+# 4 EFI_COMMON_SECTION_HEADER, stating size 12 (0xC) and\r
+# type 0x19 (EFI_SECTION_RAW). The purpose of this section\r
+# is to pad the start of DXEFV to 16 bytes.\r
+# 8 Zero bytes (padding).\r
+#\r
+# 4 EFI_COMMON_SECTION_HEADER, stating size\r
+# (PcdOvmfDxeMemFvSize + 4), and type 0x17\r
+# (EFI_SECTION_FIRMWARE_VOLUME_IMAGE).\r
+# PcdOvmfDxeMemFvSize DXEFV. Note that the above sizes pad the offset of this\r
+# object to 16 bytes. See also the "guided.dummy.txt" file\r
+# in the same directory.\r
+#\r
+# The total size after decompression is (128 + PcdOvmfPeiMemFvSize + 16 +\r
+# PcdOvmfDxeMemFvSize).\r
+\r
+DEFINE OUTPUT_SIZE = (128 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfPeiMemFvSize + 16 + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvSize)\r
+\r
+# LzmaCustomDecompressLib uses a constant scratch buffer size of 64KB; see\r
+# SCRATCH_BUFFER_REQUEST_SIZE in\r
+# "MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaDecompress.c".\r
+\r
+DEFINE DECOMP_SCRATCH_SIZE = 0x00010000\r
+\r
+# Note: when we use PcdOvmfDxeMemFvBase in this context, BaseTools have not yet\r
+# offset it with MEMFD's base address. For that reason we have to do it manually.\r
+#\r
+# The calculation below mirrors DecompressMemFvs() [OvmfPkg/Sec/SecMain.c].\r
+\r
+DEFINE OUTPUT_BASE = ($(MEMFD_BASE_ADDRESS) + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDxeMemFvBase + 0x00100000)\r
+DEFINE DECOMP_SCRATCH_BASE_UNALIGNED = ($(OUTPUT_BASE) + $(OUTPUT_SIZE))\r
+DEFINE DECOMP_SCRATCH_BASE_ALIGNMENT = 0x000FFFFF\r
+DEFINE DECOMP_SCRATCH_BASE_MASK = 0xFFF00000\r
+DEFINE DECOMP_SCRATCH_BASE = (($(DECOMP_SCRATCH_BASE_UNALIGNED) + $(DECOMP_SCRATCH_BASE_ALIGNMENT)) & $(DECOMP_SCRATCH_BASE_MASK))\r
+\r
+SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfDecompressionScratchEnd = $(DECOMP_SCRATCH_BASE) + $(DECOMP_SCRATCH_SIZE)\r
\r
OutputBuffer = (VOID*) ((UINT8*)(UINTN) PcdGet32 (PcdOvmfDxeMemFvBase) + SIZE_1MB);\r
ScratchBuffer = ALIGN_POINTER ((UINT8*) OutputBuffer + OutputBufferSize, SIZE_1MB);\r
+\r
+ DEBUG ((EFI_D_VERBOSE, "%a: OutputBuffer@%p+0x%x ScratchBuffer@%p+0x%x "\r
+ "PcdOvmfDecompressionScratchEnd=0x%x\n", __FUNCTION__, OutputBuffer,\r
+ OutputBufferSize, ScratchBuffer, ScratchBufferSize,\r
+ PcdGet32 (PcdOvmfDecompressionScratchEnd)));\r
+ ASSERT ((UINTN)ScratchBuffer + ScratchBufferSize ==\r
+ PcdGet32 (PcdOvmfDecompressionScratchEnd));\r
+\r
Status = ExtractGuidedSectionDecode (\r
Section,\r
&OutputBuffer,\r