On 2015-01-15 13:43:43, James Bottomley wrote:
> [resend since the first seems to be lost in the list]

Frustrating...  :(

> From: James Bottomley <[email protected]>
> 
> I have a use case for inserting variables into the flash image, but it can't
> be verified on Ovmf since it throws away the variables section and builds a
> new pristine one.  Fix this by having Ovmf create it's in memory variable area
> initialised from the flash image store.
> 
> Signed-off-by: James Bottomley <[email protected]>

Please refer to OvmfPkg/Contributions.txt for how to contribute
patches. Also, can you send your patch from the same email address
that you are signing the contribution with?

Thanks,

-Jordan

> ---
>  OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c   | 169 
> +++++--------------------------
>  OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf |   1 +
>  2 files changed, 25 insertions(+), 145 deletions(-)
> 
> diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c 
> b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c
> index 7a8beb3..92fd95e 100644
> --- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c
> +++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c
> @@ -625,159 +625,38 @@ InitializeFvAndVariableStoreHeaders (
>    IN  VOID   *Ptr
>    )
>  {
> +  EFI_FIRMWARE_VOLUME_HEADER  *Fv;
> +  EFI_PHYSICAL_ADDRESS            NvStorageBase;
> +
>    //
> -  // Templates for standard (non-authenticated) variable FV header
> +  // Copy the variables structure from the firmware into the location
>    //
> -  STATIC FVB_FV_HDR_AND_VARS_TEMPLATE FvAndVarTemplate = {
> -    { // EFI_FIRMWARE_VOLUME_HEADER FvHdr;
> -      // UINT8                     ZeroVector[16];
> -      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
> -
> -      // EFI_GUID                  FileSystemGuid;
> -      EFI_SYSTEM_NV_DATA_FV_GUID,
> -
> -      // UINT64                    FvLength;
> -      EMU_FVB_SIZE,
> -
> -      // UINT32                    Signature;
> -      EFI_FVH_SIGNATURE,
> -
> -      // EFI_FVB_ATTRIBUTES_2      Attributes;
> -      0x4feff,
> -
> -      // UINT16                    HeaderLength;
> -      EMU_FV_HEADER_LENGTH,
> -
> -      // UINT16                    Checksum;
> -      0,
> -
> -      // UINT16                    ExtHeaderOffset;
> -      0,
> -
> -      // UINT8                     Reserved[1];
> -      {0},
> -
> -      // UINT8                     Revision;
> -      EFI_FVH_REVISION,
> -
> -      // EFI_FV_BLOCK_MAP_ENTRY    BlockMap[1];
> -      { 
> -        {
> -          2, // UINT32 NumBlocks;
> -          EMU_FVB_BLOCK_SIZE  // UINT32 Length;
> -        }
> -      }
> -    },
> -    // EFI_FV_BLOCK_MAP_ENTRY     EndBlockMap;
> -    { 0, 0 }, // End of block map
> -    { // VARIABLE_STORE_HEADER      VarHdr;
> -      // EFI_GUID  Signature;
> -      EFI_VARIABLE_GUID,
> -
> -      // UINT32  Size;
> -      (
> -        FixedPcdGet32 (PcdVariableStoreSize) -
> -        OFFSET_OF (FVB_FV_HDR_AND_VARS_TEMPLATE, VarHdr)
> -      ),
> -
> -      // UINT8   Format;
> -      VARIABLE_STORE_FORMATTED,
> -
> -      // UINT8   State;
> -      VARIABLE_STORE_HEALTHY,
> -
> -      // UINT16  Reserved;
> -      0,
> -
> -      // UINT32  Reserved1;
> -      0
> -    }
> -  };
> -
> +  NvStorageBase = (EFI_PHYSICAL_ADDRESS) PcdGet32 
> (PcdOvmfFlashNvStorageVariableBase);
> +  Fv = (EFI_FIRMWARE_VOLUME_HEADER *)NvStorageBase;
> +  ASSERT(Fv->FvLength == EMU_FVB_SIZE);
> +  ASSERT(Fv->HeaderLength == EMU_FV_HEADER_LENGTH);
> +  CopyMem(Ptr, (UINT8 *) (UINTN)NvStorageBase, Fv->FvLength);
>    //
> -  // Templates for authenticated variable FV header
> +  // Fix up the block Headers (Emu has a special block size which may differ
> +  // from other flash)
>    //
> -  STATIC FVB_FV_HDR_AND_VARS_TEMPLATE FvAndAuthenticatedVarTemplate = {
> -    { // EFI_FIRMWARE_VOLUME_HEADER FvHdr;
> -      // UINT8                     ZeroVector[16];
> -      { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
> -
> -      // EFI_GUID                  FileSystemGuid;
> -      EFI_SYSTEM_NV_DATA_FV_GUID,
> -
> -      // UINT64                    FvLength;
> -      EMU_FVB_SIZE,
> -
> -      // UINT32                    Signature;
> -      EFI_FVH_SIGNATURE,
> -
> -      // EFI_FVB_ATTRIBUTES_2      Attributes;
> -      0x4feff,
> -
> -      // UINT16                    HeaderLength;
> -      EMU_FV_HEADER_LENGTH,
> -
> -      // UINT16                    Checksum;
> -      0,
> -
> -      // UINT16                    ExtHeaderOffset;
> -      0,
> -
> -      // UINT8                     Reserved[1];
> -      {0},
> -
> -      // UINT8                     Revision;
> -      EFI_FVH_REVISION,
> -
> -      // EFI_FV_BLOCK_MAP_ENTRY    BlockMap[1];
> -      {
> -        {
> -          2, // UINT32 NumBlocks;
> -          EMU_FVB_BLOCK_SIZE  // UINT32 Length;
> -        }
> -      }
> -    },
> -    // EFI_FV_BLOCK_MAP_ENTRY     EndBlockMap;
> -    { 0, 0 }, // End of block map
> -    { // VARIABLE_STORE_HEADER      VarHdr;
> -        // EFI_GUID  Signature;     // need authenticated variables for 
> secure boot
> -        EFI_AUTHENTICATED_VARIABLE_GUID,
> -
> -      // UINT32  Size;
> -      (
> -        FixedPcdGet32 (PcdVariableStoreSize) -
> -        OFFSET_OF (FVB_FV_HDR_AND_VARS_TEMPLATE, VarHdr)
> -      ),
> -
> -      // UINT8   Format;
> -      VARIABLE_STORE_FORMATTED,
> -
> -      // UINT8   State;
> -      VARIABLE_STORE_HEALTHY,
> -
> -      // UINT16  Reserved;
> -      0,
> -
> -      // UINT32  Reserved1;
> -      0
> -    }
> -  };
> -
> -  EFI_FIRMWARE_VOLUME_HEADER  *Fv;
> -
> +  Fv = Ptr;
> +  Fv->BlockMap[0].NumBlocks = 2;
> +  Fv->BlockMap[0].Length = EMU_FVB_BLOCK_SIZE;
>    //
> -  // Copy the template structure into the location
> +  // fix up attributes (EFI_FVB2_ALIGNMENT_16 and
> +  // everything except EFI_FVB2_READ_DISABLED_CAP)
>    //
> -  if (FeaturePcdGet (PcdSecureBootEnable) == FALSE) {
> -    CopyMem (Ptr, (VOID*)&FvAndVarTemplate, sizeof (FvAndVarTemplate));
> -  } else {
> -    CopyMem (Ptr, (VOID*)&FvAndAuthenticatedVarTemplate, sizeof 
> (FvAndAuthenticatedVarTemplate));
> -  }
> -
> +  Fv->Attributes = 0x4fffe;
> +  //
> +  // We should only have a single entry in the block map
> +  //
> +  ASSERT(Fv->BlockMap[1].NumBlocks == 0);
> +  ASSERT(Fv->BlockMap[1].Length == 0);
>    //
> -  // Update the checksum for the FV header
> +  // Now that we mucked around with the FV header, redo its checksum
>    //
> -  Fv = (EFI_FIRMWARE_VOLUME_HEADER*) Ptr;
> +  Fv->Checksum = 0;
>    Fv->Checksum = CalculateCheckSum16 (Ptr, Fv->HeaderLength);
>  }
>  
> diff --git a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf 
> b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
> index 4d4827d..5c39f87 100644
> --- a/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
> +++ b/OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.inf
> @@ -60,6 +60,7 @@
>    gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
> +  gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFlashNvStorageVariableBase
>  
>  [Pcd]
>    gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
> 
> 
> 
> ------------------------------------------------------------------------------
> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
> GigeNET is offering a free month of service with a new server in Ashburn.
> Choose from 2 high performing configs, both with 100TB of bandwidth.
> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
> http://p.sf.net/sfu/gigenet
> _______________________________________________
> edk2-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/edk2-devel

------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to