From nobody Sat Nov 2 12:24:39 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 149060215958728.582697656096002; Mon, 27 Mar 2017 01:09:19 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 697BF2008475D; Mon, 27 Mar 2017 01:08:59 -0700 (PDT) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 072D62007D1F8 for ; Mon, 27 Mar 2017 01:08:57 -0700 (PDT) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Mar 2017 01:08:56 -0700 Received: from junghyun-mobl.amr.corp.intel.com (HELO jljusten-skl.amr.corp.intel.com) ([10.252.131.12]) by fmsmga005.fm.intel.com with ESMTP; 27 Mar 2017 01:08:56 -0700 X-Original-To: edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490602136; x=1522138136; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=5n87uNo35MF/f57OTPdl4NE0a1XwSs8+58PuIel23Ik=; b=LLqrXgYEYczRmp13gQKE5XBi/pQAcsBanQlsVbsvmKiVl/VZFpT/mig1 xsqvjsz+20o1CaDPgVhJkeVKVjTyVg==; X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,229,1486454400"; d="scan'208";a="80948378" From: Jordan Justen To: edk2-devel@lists.01.org Date: Mon, 27 Mar 2017 01:05:42 -0700 Message-Id: <20170327080544.24748-11-jordan.l.justen@intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170327080544.24748-1-jordan.l.justen@intel.com> References: <20170327080544.24748-1-jordan.l.justen@intel.com> Subject: [edk2] [PATCH 10/12] OvmfPkg PlatformPei: Initialize memory based variable store buffer X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen , Laszlo Ersek MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This is similar to the initialization in OvmfPkg/EmuVariableFvbRuntimeDxe/Fvb.c. Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jordan Justen --- OvmfPkg/PlatformPei/PlatformPei.inf | 1 + OvmfPkg/PlatformPei/Vars.c | 161 ++++++++++++++++++++++++++++++++= ++++ 2 files changed, 162 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index 0eaf27e553..7a7f5c23b0 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -50,6 +50,7 @@ =20 [LibraryClasses] BaseLib + BaseMemoryLib DebugLib HobLib IoLib diff --git a/OvmfPkg/PlatformPei/Vars.c b/OvmfPkg/PlatformPei/Vars.c index 563f847a55..452b06e399 100644 --- a/OvmfPkg/PlatformPei/Vars.c +++ b/OvmfPkg/PlatformPei/Vars.c @@ -15,18 +15,172 @@ **/ =20 #include +#include +#include #include +#include #include #include #include =20 #include "Platform.h" =20 +typedef struct { + + EFI_FIRMWARE_VOLUME_HEADER FvHdr; + EFI_FV_BLOCK_MAP_ENTRY EndBlockMap; + VARIABLE_STORE_HEADER VarHdr; + +} FVB_FV_HDR_AND_VARS_TEMPLATE; + #define OVMF_FVB_BLOCK_SIZE (FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize)) #define OVMF_FVB_SIZE (2 * FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize)) #define OVMF_FV_HEADER_LENGTH OFFSET_OF (FVB_FV_HDR_AND_VARS_TEMPLATE, Var= Hdr) =20 =20 +/** + Check the integrity of firmware volume header. + + @param[in] FwVolHeader - A pointer to a firmware volume header + + @retval EFI_SUCCESS - The firmware volume is consistent + @retval EFI_NOT_FOUND - The firmware volume has been corrupted. + +**/ +STATIC EFI_STATUS +ValidateFvHeader ( + IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader + ) +{ + UINT16 Checksum; + + // + // Verify the header revision, header signature, length + // Length of FvBlock cannot be 2**64-1 + // HeaderLength cannot be an odd number + // + if ((FwVolHeader->Revision !=3D EFI_FVH_REVISION) || + (FwVolHeader->Signature !=3D EFI_FVH_SIGNATURE) || + (FwVolHeader->FvLength !=3D OVMF_FVB_SIZE) || + (FwVolHeader->HeaderLength !=3D OVMF_FV_HEADER_LENGTH) + ) { + DEBUG ((EFI_D_INFO, "EMU Variable FVB: Basic FV headers were invalid\n= ")); + return EFI_NOT_FOUND; + } + // + // Verify the header checksum + // + Checksum =3D CalculateSum16((VOID*) FwVolHeader, FwVolHeader->HeaderLeng= th); + + if (Checksum !=3D 0) { + DEBUG ((EFI_D_INFO, "EMU Variable FVB: FV checksum was invalid\n")); + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + + +/** + Initializes the FV Header and Variable Store Header + to support variable operations. + + @param[in] Ptr - Location to initialize the headers + +**/ +STATIC VOID +InitializeFvAndVariableStoreHeaders ( + IN VOID *Ptr + ) +{ + // + // Templates for authenticated variable FV header + // + STATIC FVB_FV_HDR_AND_VARS_TEMPLATE FvAndAuthenticatedVarTemplate =3D { + { // 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; + OVMF_FVB_SIZE, + + // UINT32 Signature; + EFI_FVH_SIGNATURE, + + // EFI_FVB_ATTRIBUTES_2 Attributes; + 0x4feff, + + // UINT16 HeaderLength; + OVMF_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; + OVMF_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 se= cure 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; + + // + // Copy the template structure into the location + // + CopyMem ( + Ptr, + (VOID*) &FvAndAuthenticatedVarTemplate, + sizeof (FvAndAuthenticatedVarTemplate) + ); + + // + // Update the checksum for the FV header + // + Fv =3D (EFI_FIRMWARE_VOLUME_HEADER*) Ptr; + Fv->Checksum =3D CalculateCheckSum16 (Ptr, Fv->HeaderLength); +} + + VOID ReserveEmuVariableNvStore ( ) @@ -57,6 +211,13 @@ ReserveEmuVariableNvStore ( PcdStatus =3D PcdSet64S (PcdEmuVariableNvStoreReserved, VariableStore); ASSERT_RETURN_ERROR (PcdStatus); =20 + VOID *Ptr =3D (VOID*)(UINTN) VariableStore; + + if (EFI_ERROR (ValidateFvHeader (Ptr))) { + SetMem (Ptr, OVMF_FVB_SIZE, 0xff); + InitializeFvAndVariableStoreHeaders (Ptr); + } + // // Initialize the main FV header and variable store header // --=20 2.11.0 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel