Blame SOURCES/ovmf-OvmfPkg-introduce-4MB-flash-image-mainly-for-Windows.patch

eb7fe6
From b151979f34a0bf4b85569d3f8fa4e66034dbf741 Mon Sep 17 00:00:00 2001
eb7fe6
From: Laszlo Ersek <lersek@redhat.com>
eb7fe6
Date: Fri, 5 May 2017 20:24:17 +0200
eb7fe6
Subject: [PATCH 06/10] OvmfPkg: introduce 4MB flash image (mainly) for Windows
eb7fe6
 HCK
eb7fe6
eb7fe6
Message-id: <20170505182421.19670-7-lersek@redhat.com>
eb7fe6
Patchwork-id: 75037
eb7fe6
O-Subject:  [RHEL-7.4 ovmf PATCH v2 06/10] OvmfPkg: introduce 4MB flash image
eb7fe6
	(mainly) for Windows HCK
eb7fe6
Bugzilla: 1443351
eb7fe6
Acked-by: Paolo Bonzini <pbonzini@redhat.com>
eb7fe6
Acked-by: Vitaly Kuznetsov <vkuznets@redhat.com>
eb7fe6
Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
eb7fe6
eb7fe6
The "Confirm64KilobytesOfUnauthenticatedVariableStorage" test case of the
eb7fe6
Secure Boot Logo Test ("Microsoft.UefiSecureBootLogo.Tests") suite in the
eb7fe6
Microsoft Hardware Certification Kit expects to be able to populate the
eb7fe6
variable store up to roughly 64 KB, with a series of 1 KB sized,
eb7fe6
unauthenticated variables. OVMF's current live varstore area is too small
eb7fe6
for this: 56 KB.
eb7fe6
eb7fe6
Introduce the FD_SIZE_4MB build macro (equivalently, FD_SIZE_IN_KB=4096),
eb7fe6
which
eb7fe6
eb7fe6
- enlarges the full flash image to 4MB -- QEMU supports up to 8MB, see
eb7fe6
  FLASH_MAP_BASE_MIN in "hw/i386/pc_sysfw.c" --,
eb7fe6
eb7fe6
- inside that, grows the varstore area / pflash chip to 528 KB, and within
eb7fe6
  it, the live area from 56 KB to 256 KB.
eb7fe6
eb7fe6
Importantly, a firmware binary built with -D FD_SIZE_4MB will *not* be
eb7fe6
compatible with a variable store that originates from a variable store
eb7fe6
template built *without* -D FD_SIZE_4MB. This is the reason for the large
eb7fe6
increase, as every such change breaks compatibility between a new firmware
eb7fe6
binary and old varstore files.
eb7fe6
eb7fe6
Enlarging the varstore does not impact the performance of normal
eb7fe6
operations, as we keep the varstore block size 4KB. The performance of
eb7fe6
reclaim is affected, but that is expected (since reclaim has to rework the
eb7fe6
full live area). And, reclaim occurs proportionally less frequently.
eb7fe6
eb7fe6
While at it, the FVMAIN_COMPACT volume (with the compressed FFS file in
eb7fe6
it) is also enlarged significantly, so that we have plenty of room for
eb7fe6
future DXEFV (and perhaps PEIFV) increments -- DXEFV has been growing
eb7fe6
steadily, and that increase shows through compression too. Right now the
eb7fe6
PEIFV and DXEFV volumes need no resizing.
eb7fe6
eb7fe6
Here's a summary:
eb7fe6
eb7fe6
  Description                Compression type                Size [KB]
eb7fe6
  -------------------------  -----------------  ----------------------
eb7fe6
  Non-volatile data storage  open-coded binary    128 ->   528 ( +400)
eb7fe6
                               data
eb7fe6
    Variable store                                 56 ->   256 ( +200)
eb7fe6
    Event log                                       4 ->     4 (   +0)
eb7fe6
    Working block                                   4 ->     4 (   +0)
eb7fe6
    Spare area                                     64 ->   264 ( +200)
eb7fe6
eb7fe6
  FVMAIN_COMPACT             uncompressed        1712 ->  3360 (+1648)
eb7fe6
    FV FFS file              LZMA compressed
eb7fe6
      PEIFV                  uncompressed         896 ->   896 (   +0)
eb7fe6
        individual PEI       uncompressed
eb7fe6
          modules
eb7fe6
      DXEFV                  uncompressed       10240 -> 10240 (   +0)
eb7fe6
        individual DXE       uncompressed
eb7fe6
          modules
eb7fe6
eb7fe6
  SECFV                      uncompressed         208 ->   208 (   +0)
eb7fe6
    SEC driver
eb7fe6
    reset vector code
eb7fe6
eb7fe6
For now, the 2MB flash image remains the default.
eb7fe6
eb7fe6
Cc: Gary Ching-Pang Lin <glin@suse.com>
eb7fe6
Cc: Jordan Justen <jordan.l.justen@intel.com>
eb7fe6
Contributed-under: TianoCore Contribution Agreement 1.0
eb7fe6
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
eb7fe6
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
eb7fe6
(cherry picked from commit b24fca05751f8222acf264853709012e0ab7bf49)
eb7fe6
---
eb7fe6
 OvmfPkg/OvmfPkg.fdf.inc    | 28 ++++++++++++++++++++++++
eb7fe6
 OvmfPkg/OvmfPkgIa32.dsc    |  4 ++++
eb7fe6
 OvmfPkg/OvmfPkgIa32X64.dsc |  4 ++++
eb7fe6
 OvmfPkg/OvmfPkgX64.dsc     |  4 ++++
eb7fe6
 OvmfPkg/VarStore.fdf.inc   | 54 ++++++++++++++++++++++++++++++++++++++++++++--
eb7fe6
 5 files changed, 92 insertions(+), 2 deletions(-)
eb7fe6
eb7fe6
diff --git a/OvmfPkg/OvmfPkg.fdf.inc b/OvmfPkg/OvmfPkg.fdf.inc
eb7fe6
index 4e72e35..b3e0c47 100644
eb7fe6
--- a/OvmfPkg/OvmfPkg.fdf.inc
eb7fe6
+++ b/OvmfPkg/OvmfPkg.fdf.inc
eb7fe6
@@ -16,10 +16,21 @@
eb7fe6
 ##
eb7fe6
 
eb7fe6
 DEFINE BLOCK_SIZE        = 0x1000
eb7fe6
+
eb7fe6
+#
eb7fe6
+# A firmware binary built with FD_SIZE_IN_KB=1024, and a firmware binary built
eb7fe6
+# with FD_SIZE_IN_KB=2048, use the same variable store layout.
eb7fe6
+#
eb7fe6
+# Setting FD_SIZE_IN_KB to 4096 results in a different (much larger) variable
eb7fe6
+# store structure that is incompatible with both of the above-mentioned
eb7fe6
+# firmware binaries.
eb7fe6
+#
eb7fe6
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
eb7fe6
 DEFINE VARS_SIZE         = 0x20000
eb7fe6
 DEFINE VARS_BLOCKS       = 0x20
eb7fe6
 DEFINE VARS_LIVE_SIZE    = 0xE000
eb7fe6
 DEFINE VARS_SPARE_SIZE   = 0x10000
eb7fe6
+!endif
eb7fe6
 
eb7fe6
 !if $(FD_SIZE_IN_KB) == 1024
eb7fe6
 DEFINE FW_BASE_ADDRESS   = 0xFFF00000
eb7fe6
@@ -45,6 +56,23 @@ DEFINE SECFV_OFFSET      = 0x001CC000
eb7fe6
 DEFINE SECFV_SIZE        = 0x34000
eb7fe6
 !endif
eb7fe6
 
eb7fe6
+!if $(FD_SIZE_IN_KB) == 4096
eb7fe6
+DEFINE VARS_SIZE         = 0x84000
eb7fe6
+DEFINE VARS_BLOCKS       = 0x84
eb7fe6
+DEFINE VARS_LIVE_SIZE    = 0x40000
eb7fe6
+DEFINE VARS_SPARE_SIZE   = 0x42000
eb7fe6
+
eb7fe6
+DEFINE FW_BASE_ADDRESS   = 0xFFC00000
eb7fe6
+DEFINE FW_SIZE           = 0x00400000
eb7fe6
+DEFINE FW_BLOCKS         = 0x400
eb7fe6
+DEFINE CODE_BASE_ADDRESS = 0xFFC84000
eb7fe6
+DEFINE CODE_SIZE         = 0x0037C000
eb7fe6
+DEFINE CODE_BLOCKS       = 0x37C
eb7fe6
+DEFINE FVMAIN_SIZE       = 0x00348000
eb7fe6
+DEFINE SECFV_OFFSET      = 0x003CC000
eb7fe6
+DEFINE SECFV_SIZE        = 0x34000
eb7fe6
+!endif
eb7fe6
+
eb7fe6
 SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress     = $(FW_BASE_ADDRESS)
eb7fe6
 SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareFdSize    = $(FW_SIZE)
eb7fe6
 SET gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFirmwareBlockSize = $(BLOCK_SIZE)
eb7fe6
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
eb7fe6
index d329150..44bd86b 100644
eb7fe6
--- a/OvmfPkg/OvmfPkgIa32.dsc
eb7fe6
+++ b/OvmfPkg/OvmfPkgIa32.dsc
eb7fe6
@@ -51,9 +51,13 @@
eb7fe6
 !ifdef $(FD_SIZE_2MB)
eb7fe6
   DEFINE FD_SIZE_IN_KB           = 2048
eb7fe6
 !else
eb7fe6
+!ifdef $(FD_SIZE_4MB)
eb7fe6
+  DEFINE FD_SIZE_IN_KB           = 4096
eb7fe6
+!else
eb7fe6
   DEFINE FD_SIZE_IN_KB           = 2048
eb7fe6
 !endif
eb7fe6
 !endif
eb7fe6
+!endif
eb7fe6
 
eb7fe6
 [BuildOptions]
eb7fe6
   GCC:*_UNIXGCC_*_CC_FLAGS             = -DMDEPKG_NDEBUG
eb7fe6
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
eb7fe6
index 7b694d9..a8ae37c 100644
eb7fe6
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
eb7fe6
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
eb7fe6
@@ -51,9 +51,13 @@
eb7fe6
 !ifdef $(FD_SIZE_2MB)
eb7fe6
   DEFINE FD_SIZE_IN_KB           = 2048
eb7fe6
 !else
eb7fe6
+!ifdef $(FD_SIZE_4MB)
eb7fe6
+  DEFINE FD_SIZE_IN_KB           = 4096
eb7fe6
+!else
eb7fe6
   DEFINE FD_SIZE_IN_KB           = 2048
eb7fe6
 !endif
eb7fe6
 !endif
eb7fe6
+!endif
eb7fe6
 
eb7fe6
 [BuildOptions]
eb7fe6
   GCC:*_UNIXGCC_*_CC_FLAGS             = -DMDEPKG_NDEBUG
eb7fe6
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
eb7fe6
index 6bb0de2..35bdb85 100644
eb7fe6
--- a/OvmfPkg/OvmfPkgX64.dsc
eb7fe6
+++ b/OvmfPkg/OvmfPkgX64.dsc
eb7fe6
@@ -51,9 +51,13 @@
eb7fe6
 !ifdef $(FD_SIZE_2MB)
eb7fe6
   DEFINE FD_SIZE_IN_KB           = 2048
eb7fe6
 !else
eb7fe6
+!ifdef $(FD_SIZE_4MB)
eb7fe6
+  DEFINE FD_SIZE_IN_KB           = 4096
eb7fe6
+!else
eb7fe6
   DEFINE FD_SIZE_IN_KB           = 2048
eb7fe6
 !endif
eb7fe6
 !endif
eb7fe6
+!endif
eb7fe6
 
eb7fe6
 [BuildOptions]
eb7fe6
   GCC:*_UNIXGCC_*_CC_FLAGS             = -DMDEPKG_NDEBUG
eb7fe6
diff --git a/OvmfPkg/VarStore.fdf.inc b/OvmfPkg/VarStore.fdf.inc
eb7fe6
index ce901c0..742fed1 100644
eb7fe6
--- a/OvmfPkg/VarStore.fdf.inc
eb7fe6
+++ b/OvmfPkg/VarStore.fdf.inc
eb7fe6
@@ -15,7 +15,12 @@
eb7fe6
 #
eb7fe6
 ##
eb7fe6
 
eb7fe6
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
eb7fe6
 0x00000000|0x0000e000
eb7fe6
+!endif
eb7fe6
+!if $(FD_SIZE_IN_KB) == 4096
eb7fe6
+0x00000000|0x00040000
eb7fe6
+!endif
eb7fe6
 #NV_VARIABLE_STORE
eb7fe6
 DATA = {
eb7fe6
   ## This is the EFI_FIRMWARE_VOLUME_HEADER
eb7fe6
@@ -27,14 +32,36 @@ DATA = {
eb7fe6
   #     { 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50 }}
eb7fe6
   0x8D, 0x2B, 0xF1, 0xFF, 0x96, 0x76, 0x8B, 0x4C,
eb7fe6
   0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50,
eb7fe6
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
eb7fe6
   # FvLength: 0x20000
eb7fe6
   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
eb7fe6
+!endif
eb7fe6
+!if $(FD_SIZE_IN_KB) == 4096
eb7fe6
+  # FvLength: 0x84000
eb7fe6
+  0x00, 0x40, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
eb7fe6
+!endif
eb7fe6
   # Signature "_FVH"       # Attributes
eb7fe6
   0x5f, 0x46, 0x56, 0x48, 0xff, 0xfe, 0x04, 0x00,
eb7fe6
-  # HeaderLength # CheckSum # ExtHeaderOffset #Reserved #Revision
eb7fe6
-  0x48, 0x00, 0x19, 0xF9, 0x00, 0x00, 0x00, 0x02,
eb7fe6
+  # HeaderLength
eb7fe6
+  0x48, 0x00,
eb7fe6
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
eb7fe6
+  # CheckSum
eb7fe6
+  0x19, 0xF9,
eb7fe6
+!endif
eb7fe6
+!if $(FD_SIZE_IN_KB) == 4096
eb7fe6
+  # CheckSum
eb7fe6
+  0xAF, 0xB8,
eb7fe6
+!endif
eb7fe6
+  # ExtHeaderOffset #Reserved #Revision
eb7fe6
+  0x00, 0x00, 0x00, 0x02,
eb7fe6
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
eb7fe6
   # Blockmap[0]: 0x20 Blocks * 0x1000 Bytes / Block
eb7fe6
   0x20, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
eb7fe6
+!endif
eb7fe6
+!if $(FD_SIZE_IN_KB) == 4096
eb7fe6
+  # Blockmap[0]: 0x84 Blocks * 0x1000 Bytes / Block
eb7fe6
+  0x84, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
eb7fe6
+!endif
eb7fe6
   # Blockmap[1]: End
eb7fe6
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
eb7fe6
   ## This is the VARIABLE_STORE_HEADER
eb7fe6
@@ -44,18 +71,36 @@ DATA = {
eb7fe6
   #     { 0xa1, 0x80, 0x2e, 0x14, 0x4e, 0xc3, 0x77, 0x92 }}
eb7fe6
   0x78, 0x2c, 0xf3, 0xaa, 0x7b, 0x94, 0x9a, 0x43,
eb7fe6
   0xa1, 0x80, 0x2e, 0x14, 0x4e, 0xc3, 0x77, 0x92,
eb7fe6
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
eb7fe6
   # Size: 0xe000 (gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize) -
eb7fe6
   #         0x48 (size of EFI_FIRMWARE_VOLUME_HEADER) = 0xdfb8
eb7fe6
   # This can speed up the Variable Dispatch a bit.
eb7fe6
   0xB8, 0xDF, 0x00, 0x00,
eb7fe6
+!endif
eb7fe6
+!if $(FD_SIZE_IN_KB) == 4096
eb7fe6
+  # Size: 0x40000 (gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize) -
eb7fe6
+  #          0x48 (size of EFI_FIRMWARE_VOLUME_HEADER) = 0x3ffb8
eb7fe6
+  # This can speed up the Variable Dispatch a bit.
eb7fe6
+  0xB8, 0xFF, 0x03, 0x00,
eb7fe6
+!endif
eb7fe6
   # FORMATTED: 0x5A #HEALTHY: 0xFE #Reserved: UINT16 #Reserved1: UINT32
eb7fe6
   0x5A, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
eb7fe6
 }
eb7fe6
 
eb7fe6
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
eb7fe6
 0x0000e000|0x00001000
eb7fe6
+!endif
eb7fe6
+!if $(FD_SIZE_IN_KB) == 4096
eb7fe6
+0x00040000|0x00001000
eb7fe6
+!endif
eb7fe6
 #NV_EVENT_LOG
eb7fe6
 
eb7fe6
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
eb7fe6
 0x0000f000|0x00001000
eb7fe6
+!endif
eb7fe6
+!if $(FD_SIZE_IN_KB) == 4096
eb7fe6
+0x00041000|0x00001000
eb7fe6
+!endif
eb7fe6
 #NV_FTW_WORKING
eb7fe6
 DATA = {
eb7fe6
   # EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER->Signature = gEdkiiWorkingBlockSignatureGuid         =
eb7fe6
@@ -68,5 +113,10 @@ DATA = {
eb7fe6
   0xE0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
eb7fe6
 }
eb7fe6
 
eb7fe6
+!if ($(FD_SIZE_IN_KB) == 1024) || ($(FD_SIZE_IN_KB) == 2048)
eb7fe6
 0x00010000|0x00010000
eb7fe6
+!endif
eb7fe6
+!if $(FD_SIZE_IN_KB) == 4096
eb7fe6
+0x00042000|0x00042000
eb7fe6
+!endif
eb7fe6
 #NV_FTW_SPARE
eb7fe6
-- 
eb7fe6
1.8.3.1
eb7fe6