From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web12.626.1648059142275419125 for ; Wed, 23 Mar 2022 11:12:23 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=n0aWih35; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: guo.dong@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1648059142; x=1679595142; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=Hqfstv5FrFu6fwLx1KN1AdHyWE7BrO1BPs5cVpLz9P0=; b=n0aWih35tnZdZxkzFn26W+eZFhDGYWIMD4thltDw+V2B1M2lMrKajd/n dJwuvMTL7vepAqIH2EtmInWNcYZ4LKPO0/Pt+7oCyh6W+hUa0xBSTuG/k Yz5fwQ3XWuMBRuw1A3nk83nyJ5BHrWnwRzJHeN4gArI8vO4zEGG9bSEYK kf2AO9yy0Rh/I3J9pbgoPpeM8sDi3vd69nPjYqbNDQNXnXNyEDoE1r+Go hNHI/flTIjANCqCByi7josSFnprEzTXZ6pdiDW53E4ouBA5PfVGl6VyV6 Qm50tD6JIezblS87b+pC0GHCU+Mg6eC7IBNSvvJ0BE1qnjiC8e7sF/IXH A==; X-IronPort-AV: E=McAfee;i="6200,9189,10295"; a="344627743" X-IronPort-AV: E=Sophos;i="5.90,204,1643702400"; d="scan'208";a="344627743" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Mar 2022 11:12:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,204,1643702400"; d="scan'208";a="717509886" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga005.jf.intel.com with ESMTP; 23 Mar 2022 11:12:20 -0700 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Wed, 23 Mar 2022 11:12:19 -0700 Received: from fmsmsx601.amr.corp.intel.com (10.18.126.81) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Wed, 23 Mar 2022 11:12:19 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Wed, 23 Mar 2022 11:12:19 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.101) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.21; Wed, 23 Mar 2022 11:12:19 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AJ/++1gaL+J2wHST0iHsmr1WxcTA9Z/DwZZmkJXF1JKQCatgjY0/P/R3/hySCcnMPrs4Pm9+HeSYyxJPzP/ha4uz9wdLfmrbrE2s8IC2rDiJJk0k4K3gx530st+93BU1rnA2TvJu2HliHHUDbYnEM//zXAxwFksBIJ3LjPID7YCzHa6nuowU7b0/fGFiH9gShgYJ7U/vCn0UN4W9K2eIMiUOHWH87+Hj/nxJjahnAmz3TmqnFvAClpWg/V1ntTuoyYqvzZoUEHEo7kHvmmiHe6ELZL6gmu5MYguOPSqtwDMClqU+umwFKWVNJPcRTRtXNf1YRJXiYCfiHKZIIaEwlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=3uZZ0TnGlWBxs75X5VDFRUyHtkBPalUsNbrB2YtBZLw=; b=C9yaOe0Oor+JWsvqGKMQe3is5j/KiA5DpWigsvd9RMRyYBqFNL/IFUcE7reY/kPJuokeUVpsiWqECqvcBseb1N7cwAXZiRFnvFYqOopGAvTPUwawr1pGEf2x5NGXLpuEFSyKD6Oy1Muv6zS/tyZ0xWTkVkfxEd/1K3OOcJeGVmm8zFmHkVXLWf/AONoCEDgJfEG5TsWMv/vKBWLpA2D27eqUgUDZUfeW+IiMNq5SgY+G/w2qOeYCfxfMnAM013cBZe1El+CasNwwSScLo0QfGIf4ipDkiVT8KICclO7OSCuASoCp+aJqpMwVbBxs0ISWalLT19PvNE3hwwBfbIJeLA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from BYAPR11MB3622.namprd11.prod.outlook.com (2603:10b6:a03:fe::30) by DM5PR11MB1564.namprd11.prod.outlook.com (2603:10b6:4:d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5081.14; Wed, 23 Mar 2022 18:12:15 +0000 Received: from BYAPR11MB3622.namprd11.prod.outlook.com ([fe80::b4d1:1ea2:e9c:f4ec]) by BYAPR11MB3622.namprd11.prod.outlook.com ([fe80::b4d1:1ea2:e9c:f4ec%7]) with mapi id 15.20.5081.023; Wed, 23 Mar 2022 18:12:15 +0000 From: "Guo Dong" To: "Rhodes, Sean" , "devel@edk2.groups.io" CC: "Rhodes, Sean" , "Ni, Ray" , "Ma, Maurice" , "You, Benjamin" , Patrick Rudolph Subject: Re: [PATCH 5/5] UefiPayloadPkg: Add support for Firmware Volume Block Protocol Thread-Topic: [PATCH 5/5] UefiPayloadPkg: Add support for Firmware Volume Block Protocol Thread-Index: AQHYPQOpVqMjXgVgIkiasvA5zAVnXKzNRs0A Date: Wed, 23 Mar 2022 18:12:15 +0000 Message-ID: References: <11ad7629288bc1e0e4f3b61333efe448cd81b5a4.1647853813.git.sean@starlabs.systems> In-Reply-To: <11ad7629288bc1e0e4f3b61333efe448cd81b5a4.1647853813.git.sean@starlabs.systems> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.6.401.20 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: b293119d-219d-4676-5f4d-08da0cf8a939 x-ms-traffictypediagnostic: DM5PR11MB1564:EE_ x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Z2pRdgZ/nmw5ECQSXFromrN+ieDQJ0fQQ/Fb/CFdj049HfNXoJdEjgXKHKNiIpSqcLIA2fOI9sjrn1ggyddM6QqTV/8JfRiKRcN3wsM2wOd9HgvhwfN5CXBAHjxt6/L6yBor+ZByZsVnX5bbzuRXPZU3TbxIjTa0rXNuX7cuKA7reGHEsS5tIOtHgDcjFafzfb2RkXHfu/xfFjgM5epvMuX6V40KzFoDvOUK34zjpfUgwq94kLI4Pekg4gaqKqFWJJWWhGeJHPG/09VxJNGN9vXuiyqWbTB9q/vz10tyc1oB4qvtBNzRf8ed5MdNYHCFiYZh6J9OiqdtVhAmpQVmDwS9F6tW+LluPelpvtFBpw5YdwRs4DjKn4vI5eByHFMF+PpOJnnyCsTO+s+3eXzB8AnBKsoPwldQ0wQCNa/c6HxbjuchrC70mL1sBqgngjxqR4K0mokOn72ox/arIl/XUAHX8snNgD1rNXTQ/f6GaQ88PzpGq0GIGm5bqF67mmRYKrtTMkwbQ485TUXvWxGTZ1KS76u3Is1PKqtG6Y2O2/Fisl6w+DJvz4jjpUbNINJwD4sR37HNio3I8yqEN++kQF/v7dFsDDpSgTvTziqQXHpLK+NlyL0RLDsSTH5sHdoL82a5dOU35aLLj4gq1wIXKBtooYDCpN226tt/ER7j2vneJOSJjXI5E4qUizE5u1fYr848GrVnYT7W3mCNx1g5Q+L3ACAqrQBhNDToUFZG7vM= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR11MB3622.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(82960400001)(38100700002)(6506007)(7696005)(76116006)(64756008)(66946007)(316002)(66556008)(4326008)(110136005)(66446008)(186003)(8676002)(66476007)(2906002)(55016003)(19627235002)(38070700005)(9686003)(26005)(86362001)(53546011)(33656002)(54906003)(508600001)(8936002)(122000001)(83380400001)(71200400001)(5660300002)(52536014)(30864003)(579004)(559001)(44824005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?PwaAgJ8EFNWQjEy10FFiNTtMYY3idasV0jpUjrTbRGtQ1GjgVL5FFHaEUCn2?= =?us-ascii?Q?YdpYZXp9TIRjlK8bjxnkFgBCpzcG0GDAql6mQ93/d3uxd9jwQ8+q7PScesT5?= =?us-ascii?Q?RJPKcjxDocRmSorpzje1pePsmVUCnsq1xfDmr34ncZAufqk+QY6oKbJeOcEF?= =?us-ascii?Q?+EMejBHdAjXqrVqdhXpeuwKJQS0loHZwYNXxRjBhvdaTFhLH9Gd1OM3klclv?= =?us-ascii?Q?elQXGtrEq4mUpEDK+f0x+Ll35Vi3DFoRA6Z3SMZnCncbkV2pLiCzqam5tmS3?= =?us-ascii?Q?FV8VtU2IA+nmZ4tXTheQH5kp0+9xjkb+8siofDEXECM3FIM7PJUzSk1adyPj?= =?us-ascii?Q?b9uF5Wo66NIqjOWNvoOuvq4TGTOFQ9BG5NrzAsnPvz8BDWMeywU+SDVKpgST?= =?us-ascii?Q?I3SSLYr8NkqTeQrXnLpt1hb4gdGAD5qqpwwM6A+ywjxLdL4oKrEhPeiumlpD?= =?us-ascii?Q?LvdoQXpQd5vC08iz3bJFUpGwi28gGmkw/bhSdwoW1dzS8e2tMXpXRdxWWxiw?= =?us-ascii?Q?xgyGfUc2JG9JdCmyjCqzdp/b6gzHRMb0W8yeQW1svrfEbF9z3NIuSua25Eni?= =?us-ascii?Q?jUcV0gg3Hx9H0kVwh2PMoODXmj5wrPUT93PLBRlXUa2BZ2vWltyqzRDDD+p9?= =?us-ascii?Q?Gpoh7uG86oYIL05kJ7gYClcsZLO5KQHMOD6UXKQ1mrRxSykt1YaRY/pZn66Z?= =?us-ascii?Q?PrBpWHUFkYO90o9TbEUv3eZF3It++sjXgku5HWHvmCQ6Tge4Kg6f7NxEE/Xg?= =?us-ascii?Q?L5nhvf04tQx5ejIEGOH8+/xd3tc9un1cPNqAeSvcIkQiTR4U3KxabsL7OLhu?= =?us-ascii?Q?UpMG+yrM1tkutkHP4q6Y/ftBG2nkEzzsd3cMS4LCh8NSY/lukTpNSuWrAH0j?= =?us-ascii?Q?19dVthJEl3k+UU6/t9b5EBtfR54tKfO2w3iltmEmIxkIo6ydfk32xRjbFbg5?= =?us-ascii?Q?KDtfvACgoXOXl2y52EdXLFCDbhKjQJKTEzqpLhTdmmnmnTlL8k1VAMuDhED3?= =?us-ascii?Q?Y3Sbd98WveNX+T6D3D07Lu4NBqBmF6TTeWI72mOqFkkxR8ADIK1PydjUrqgI?= =?us-ascii?Q?/PpnF/lc3oFxt1dCLgr0Wap2yWC2o/rizCTEM0WEFm/WJWxcsKv0jAmogN/Z?= =?us-ascii?Q?bGsVZ8PjoVyp/+xPsdW2Hnxxig9bfTCwuPw8PRivC01GHi6JmCtDmdwiqOJ2?= =?us-ascii?Q?JTAAQf0L5HDFs6j7BJdnm2LJwm3nOMkXdLX1YvtQuLjUbbd7kzpSHwLKCOLT?= =?us-ascii?Q?wz9xwFdJWgz7Adc4HqWsL6r5wgJMAIlc63HFlwClYfk6w+9YgvkQv/tYa562?= =?us-ascii?Q?fiFFpq0ENQewnqkRqLcjczKSiBENw/OFs8wqXZWA4AYKBqKs0o7uDyFCGPy3?= =?us-ascii?Q?giOamDtg8frgjMvfgfMV5eYJq2X2psk7+J4WPgT6fya8GnRetAdJpoyk5iPv?= =?us-ascii?Q?qFMI/5Zzr/I+OaBMaadJJxnrqj4GAF7b?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB3622.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b293119d-219d-4676-5f4d-08da0cf8a939 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Mar 2022 18:12:15.5003 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: E1UAb8WEA1RmnMI9UNqeTeAYz0YWm8RaaCt2mclzwxxCYgz62eQaq5lhEh+zsegDQUxLHPriaAGl6PtK+fCD8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1564 Return-Path: guo.dong@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Sean, SMMSTORE and this FVB module are specific for coreboot while UefiPayloadPkg= in Edk2 is targeting platform/bootloader independent. I just submitted an "add UEFI payload platform FV" patch to edk2-platforms = repo, in this patch it moves PCH specific modules from Edk2 UefiPayloadPkg to edk2-platforms Platform/Intel/PayloadPlatformPkg. Ma= ybe these coreboot specific modules could also target to edk2-platforms repo? Thanks, Guo -----Original Message----- From: Sean Rhodes =20 Sent: Monday, March 21, 2022 2:10 AM To: devel@edk2.groups.io Cc: Rhodes, Sean ; Dong, Guo ; N= i, Ray ; Ma, Maurice ; You, Benjami= n ; Patrick Rudolph Subject: [PATCH 5/5] UefiPayloadPkg: Add support for Firmware Volume Block = Protocol This adds support for FVB in order to support a platform independent and non-volatile variable store on UefiPayloadPkg. The variable store makes use the SmmStoreLib to provide an unauthenticed variable store. Since commit bc744f5893fc4d53275ed26dd8d968011c6a09c1 coreboot supports the SMMSTORE v2 feature. It implements a SMI handler that is able to write, read and erase pages in the boot media (SPI flash). The communication is done using a fixed communication buffer that is allocated in CBMEM. The existence of this optional feature is advertised by a coreboot table. When the SMMSTORE feature is not available the variable emulation is used by setting PcdEmuVariableNvModeEnable to TRUE. The DXE component provides runtime services and takes care of virtual to physical mapping the communication buffers between SMM and OS. The contents of the variable store can be accessed and modified by any priviledged application. As authentication is done by runtime services only the store shouldn't be used to store authenticated variables. Tested on Linux and Windows 10 on real hardware. Currently this cannot be tested on coreboot and qemu as it doesn't support the SMMSTORE on qemu. Cc: Guo Dong Cc: Ray Ni Cc: Maurice Ma Cc: Benjamin You Signed-off-by: Patrick Rudolph Signed-off-by: Sean Rhodes --- .../SmmStoreFvb/SmmStoreFvbRuntime.c | 282 ++++++ .../SmmStoreFvb/SmmStoreFvbRuntime.h | 111 +++ .../SmmStoreFvb/SmmStoreFvbRuntimeDxe.c | 849 ++++++++++++++++++ .../SmmStoreFvb/SmmStoreFvbRuntimeDxe.inf | 66 ++ UefiPayloadPkg/UefiPayloadPkg.dsc | 24 +- UefiPayloadPkg/UefiPayloadPkg.fdf | 4 + 6 files changed, 1330 insertions(+), 6 deletions(-) create mode 100644 UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntime.c create mode 100644 UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntime.h create mode 100644 UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntimeDxe.c create mode 100644 UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntimeDxe.inf diff --git a/UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntime.c b/UefiPayloadP= kg/SmmStoreFvb/SmmStoreFvbRuntime.c new file mode 100644 index 0000000000..08d5c408fb --- /dev/null +++ b/UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntime.c @@ -0,0 +1,282 @@ +/** @file SmmStoreFvbRuntime.c + + Copyright (c) 2022, 9elements GmbH
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "SmmStoreFvbRuntime.h" + +STATIC EFI_EVENT mSmmStoreVirtualAddrChangeEvent; + +// +// Global variable declarations +// +SMMSTORE_INSTANCE *mSmmStoreInstance; + +SMMSTORE_INSTANCE mSmmStoreInstanceTemplate =3D { + SMMSTORE_SIGNATURE, // Signature + NULL, // Handle ... NEED TO BE FILLED + { + FvbGetAttributes, // GetAttributes + FvbSetAttributes, // SetAttributes + FvbGetPhysicalAddress, // GetPhysicalAddress + FvbGetBlockSize, // GetBlockSize + FvbRead, // Read + FvbWrite, // Write + FvbEraseBlocks, // EraseBlocks + NULL, // ParentHandle + }, // FvbProtoccol + 0, // BlockSize ... NEED TO BE FILLED + 0, // LastBlock ... NEED TO BE FILLED + 0, // MmioAddress ... NEED TO BE FILLED + { + { + { + HARDWARE_DEVICE_PATH, + HW_MEMMAP_DP, + { + (UINT8)(sizeof (MEMMAP_DEVICE_PATH)), + (UINT8)(sizeof (MEMMAP_DEVICE_PATH) >> 8) + } + }, + EfiMemoryMappedIO, + (EFI_PHYSICAL_ADDRESS)0, // NEED TO BE FILLED + (EFI_PHYSICAL_ADDRESS)0, // NEED TO BE FILLED + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + END_DEVICE_PATH_LENGTH, + 0 + } + } + } // DevicePath +}; + +/** + Initialize the SmmStore instance. + + + @param[in] FvBase The physical MMIO base address of the FV = containing + the variable store. + + @param[in] NumberofBlocks Number of blocks within the FV. + @param[in] BlockSize The size in bytes of one block within the= FV. + @param[in, out] Instance The SmmStore instace to initialize + +**/ +STATIC +EFI_STATUS +SmmStoreInitInstance ( + IN EFI_PHYSICAL_ADDRESS FvBase, + IN UINTN NumberofBlocks, + IN UINTN BlockSize, + IN OUT SMMSTORE_INSTANCE *Instance + ) +{ + EFI_STATUS Status; + FV_MEMMAP_DEVICE_PATH *FvDevicePath; + + ASSERT (Instance !=3D NULL); + + Instance->BlockSize =3D BlockSize; + Instance->LastBlock =3D NumberofBlocks - 1; + Instance->MmioAddress =3D FvBase; + + FvDevicePath =3D &Instance->DevicePath; + FvDevicePath->MemMapDevPath.StartingAddress =3D FvBase; + FvDevicePath->MemMapDevPath.EndingAddress =3D FvBase + BlockSize * Num= berofBlocks - 1; + + Status =3D FvbInitialize (Instance); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &Instance->Handle, + &gEfiDevicePathProtocolGuid, + &Instance->DevicePath, + &gEfiFirmwareVolumeBlockProtocolGuid, + &Instance->FvbProtocol, + NULL + ); + if (EFI_ERROR (Status)) { + return Status; + } + + DEBUG ((DEBUG_INFO, "%a: Created a new instance\n", __FUNCTION__)); + + return Status; +} + +/** + Fixup internal data so that EFI can be call in virtual mode. + Call the passed in Child Notify event and convert any pointers in + lib to virtual mode. + + @param[in] Event The Event that is being processed + @param[in] Context Event Context +**/ +STATIC +VOID +EFIAPI +SmmStoreVirtualNotifyEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // Convert Fvb + EfiConvertPointer (0x0, (VOID **)&mSmmStoreInstance->FvbProtocol.EraseBl= ocks); + EfiConvertPointer (0x0, (VOID **)&mSmmStoreInstance->FvbProtocol.GetAttr= ibutes); + EfiConvertPointer (0x0, (VOID **)&mSmmStoreInstance->FvbProtocol.GetBloc= kSize); + EfiConvertPointer (0x0, (VOID **)&mSmmStoreInstance->FvbProtocol.GetPhys= icalAddress); + EfiConvertPointer (0x0, (VOID **)&mSmmStoreInstance->FvbProtocol.Read); + EfiConvertPointer (0x0, (VOID **)&mSmmStoreInstance->FvbProtocol.SetAttr= ibutes); + EfiConvertPointer (0x0, (VOID **)&mSmmStoreInstance->FvbProtocol.Write); + EfiConvertPointer (0x0, (VOID **)&mSmmStoreInstance->MmioAddress); + EfiConvertPointer (0x0, (VOID **)&mSmmStoreInstance); + + return; +} + +/** + The user Entry Point for module SmmStoreFvbRuntimeDxe. The user code sta= rts with this function. + + @param[in] ImageHandle The firmware allocated handle for the EFI imag= e. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval other Some error occurs when executing this entry po= int. + +**/ +EFI_STATUS +EFIAPI +SmmStoreInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS MmioAddress; + UINTN BlockSize; + UINTN BlockCount; + UINT32 NvStorageBase; + UINT32 NvStorageSize; + UINT32 NvVariableSize; + UINT32 FtwWorkingSize; + UINT32 FtwSpareSize; + + Status =3D SmmStoreLibInitialize (); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to initialize SmmStoreLib\n", __FUNCT= ION__)); + return Status; + } + + Status =3D SmmStoreLibGetMmioAddress (&MmioAddress); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get SmmStore MMIO address\n", __FU= NCTION__)); + SmmStoreLibDeinitialize (); + return Status; + } + + Status =3D SmmStoreLibGetNumBlocks (&BlockCount); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get SmmStore No. blocks\n", __FUNC= TION__)); + SmmStoreLibDeinitialize (); + return Status; + } + + Status =3D SmmStoreLibGetBlockSize (&BlockSize); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Failed to get SmmStore block size\n", __FUNC= TION__)); + SmmStoreLibDeinitialize (); + return Status; + } + + NvStorageSize =3D BlockCount * BlockSize; + NvStorageBase =3D MmioAddress; + + FtwSpareSize =3D (BlockCount / 2) * BlockSize; + FtwWorkingSize =3D BlockSize; + NvVariableSize =3D NvStorageSize - FtwSpareSize - FtwWorkingSize; + DEBUG ((DEBUG_INFO, "NvStorageBase:0x%x, NvStorageSize:0x%x\n", NvStorag= eBase, NvStorageSize)); + + if (NvVariableSize >=3D 0x80000000) { + SmmStoreLibDeinitialize (); + return EFI_INVALID_PARAMETER; + } + + Status =3D PcdSet32S (PcdFlashNvStorageVariableSize, NvVariableSize); + ASSERT_EFI_ERROR (Status); + Status =3D PcdSet32S (PcdFlashNvStorageVariableBase, NvStorageBase); + ASSERT_EFI_ERROR (Status); + Status =3D PcdSet64S (PcdFlashNvStorageVariableBase64, NvStorageBase); + ASSERT_EFI_ERROR (Status); + + Status =3D PcdSet32S (PcdFlashNvStorageFtwWorkingSize, FtwWorkingSize); + ASSERT_EFI_ERROR (Status); + Status =3D PcdSet32S (PcdFlashNvStorageFtwWorkingBase, NvStorageBase + N= vVariableSize); + ASSERT_EFI_ERROR (Status); + Status =3D PcdSet64S (PcdFlashNvStorageFtwWorkingBase64, NvStorageBase += NvVariableSize); + ASSERT_EFI_ERROR (Status); + + Status =3D PcdSet32S (PcdFlashNvStorageFtwSpareSize, FtwSpareSize); + ASSERT_EFI_ERROR (Status); + Status =3D PcdSet32S (PcdFlashNvStorageFtwSpareBase, NvStorageBase + NvV= ariableSize + FtwWorkingSize); + ASSERT_EFI_ERROR (Status); + Status =3D PcdSet64S (PcdFlashNvStorageFtwSpareBase64, NvStorageBase + N= vVariableSize + FtwWorkingSize); + ASSERT_EFI_ERROR (Status); + + mSmmStoreInstance =3D AllocateRuntimeCopyPool (sizeof (SMMSTORE_INSTANCE= ), &mSmmStoreInstanceTemplate); + if (mSmmStoreInstance =3D=3D NULL) { + SmmStoreLibDeinitialize (); + DEBUG ((DEBUG_ERROR, "%a: Out of resources\n", __FUNCTION__)); + return EFI_OUT_OF_RESOURCES; + } + + Status =3D SmmStoreInitInstance ( + MmioAddress, + BlockCount, + BlockSize, + mSmmStoreInstance + ); + if (EFI_ERROR (Status)) { + DEBUG ( + ( + DEBUG_ERROR, + "%a: Fail to create instance for SmmStore\n", + __FUNCTION__ + ) + ); + FreePool (mSmmStoreInstance); + SmmStoreLibDeinitialize (); + return Status; + } + + // + // Register for the virtual address change event + // + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_NOTIFY, + SmmStoreVirtualNotifyEvent, + NULL, + &gEfiEventVirtualAddressChangeGuid, + &mSmmStoreVirtualAddrChangeEvent + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntime.h b/UefiPayloadP= kg/SmmStoreFvb/SmmStoreFvbRuntime.h new file mode 100644 index 0000000000..8015d12d13 --- /dev/null +++ b/UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntime.h @@ -0,0 +1,111 @@ +/** @file SmmStoreFvbRuntime.h + + Copyright (c) 2022, 9elements GmbH
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef SMM_STORE_DXE_H_ +#define SMM_STORE_DXE_H_ + +#include +#include + +#include + +#include + +#include +#include +#include +#include + +#define SMMSTORE_SIGNATURE SIGNATURE_32('S', 'M', 'M', 'S') +#define INSTANCE_FROM_FVB_THIS(a) CR(a, SMMSTORE_INSTANCE, FvbProtocol, S= MMSTORE_SIGNATURE) + +typedef struct _SMMSTORE_INSTANCE SMMSTORE_INSTANCE; + +typedef struct { + MEMMAP_DEVICE_PATH MemMapDevPath; + EFI_DEVICE_PATH_PROTOCOL EndDevPath; +} FV_MEMMAP_DEVICE_PATH; + +struct _SMMSTORE_INSTANCE { + UINT32 Signature; + EFI_HANDLE Handle; + EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol; + UINTN BlockSize; + UINTN LastBlock; + EFI_PHYSICAL_ADDRESS MmioAddress; + FV_MEMMAP_DEVICE_PATH DevicePath; +}; + +// +// SmmStoreFvbRuntimeDxe.c +// + +EFI_STATUS +EFIAPI +FvbInitialize ( + IN SMMSTORE_INSTANCE *Instance + ); + +EFI_STATUS +EFIAPI +FvbGetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ); + +EFI_STATUS +EFIAPI +FvbSetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ); + +EFI_STATUS +EFIAPI +FvbGetPhysicalAddress ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + OUT EFI_PHYSICAL_ADDRESS *Address + ); + +EFI_STATUS +EFIAPI +FvbGetBlockSize ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + OUT UINTN *BlockSize, + OUT UINTN *NumberOfBlocks + ); + +EFI_STATUS +EFIAPI +FvbRead ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN OUT UINT8 *Buffer + ); + +EFI_STATUS +EFIAPI +FvbWrite ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ); + +EFI_STATUS +EFIAPI +FvbEraseBlocks ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + ... + ); + +#endif // SMM_STORE_DXE_H_ diff --git a/UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntimeDxe.c b/UefiPaylo= adPkg/SmmStoreFvb/SmmStoreFvbRuntimeDxe.c new file mode 100644 index 0000000000..14d4ec324d --- /dev/null +++ b/UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntimeDxe.c @@ -0,0 +1,849 @@ +/** @file SmmStoreFvbRuntimeDxe.c + + Copyright (c) 2022, 9elements GmbH
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "SmmStoreFvbRuntime.h" + +/// +/// The Firmware Volume Block Protocol is the low-level interface +/// to a firmware volume. File-level access to a firmware volume +/// should not be done using the Firmware Volume Block Protocol. +/// Normal access to a firmware volume must use the Firmware +/// Volume Protocol. Typically, only the file system driver that +/// produces the Firmware Volume Protocol will bind to the +/// Firmware Volume Block Protocol. +/// + +/** + Initialises the FV Header and Variable Store Header + to support variable operations. + + @param[in] Instance - Pointer to SmmStore instance + +**/ +EFI_STATUS +InitializeFvAndVariableStoreHeaders ( + IN SMMSTORE_INSTANCE *Instance + ) +{ + EFI_STATUS Status; + VOID *Headers; + UINTN HeadersLength; + EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumeHeader; + VARIABLE_STORE_HEADER *VariableStoreHeader; + UINT32 NvStorageFtwSpareSize; + UINT32 NvStorageFtwWorkingSize; + UINT32 NvStorageVariableSize; + UINT64 NvStorageFtwSpareBase; + UINT64 NvStorageFtwWorkingBase; + UINT64 NvStorageVariableBase; + + HeadersLength =3D sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_B= LOCK_MAP_ENTRY) + sizeof (VARIABLE_STORE_HEADER); + Headers =3D AllocateZeroPool (HeadersLength); + + NvStorageFtwWorkingSize =3D PcdGet32 (PcdFlashNvStorageFtwWorkingSize); + NvStorageFtwSpareSize =3D PcdGet32 (PcdFlashNvStorageFtwSpareSize); + NvStorageVariableSize =3D PcdGet32 (PcdFlashNvStorageVariableSize); + + NvStorageFtwSpareBase =3D (PcdGet64 (PcdFlashNvStorageFtwSpareBase64) != =3D 0) ? + PcdGet64 (PcdFlashNvStorageFtwSpareBase64) : Pcd= Get32 (PcdFlashNvStorageFtwSpareBase); + NvStorageFtwWorkingBase =3D (PcdGet64 (PcdFlashNvStorageFtwWorkingBase64= ) !=3D 0) ? + PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) := PcdGet32 (PcdFlashNvStorageFtwWorkingBase); + NvStorageVariableBase =3D (PcdGet64 (PcdFlashNvStorageVariableBase64) != =3D 0) ? + PcdGet64 (PcdFlashNvStorageVariableBase64) : Pcd= Get32 (PcdFlashNvStorageVariableBase); + + // FirmwareVolumeHeader->FvLength is declared to have the Variable area = AND the FTW working area AND the FTW Spare contiguous. + if ((NvStorageVariableBase + NvStorageVariableSize) !=3D NvStorageFtwWor= kingBase) { + DEBUG (( + DEBUG_ERROR, + "%a: NvStorageFtwWorkingBase is not contiguous with NvStorageVariabl= eBase region\n", + __FUNCTION__ + )); + return EFI_INVALID_PARAMETER; + } + + if ((NvStorageFtwWorkingBase + NvStorageFtwWorkingSize) !=3D NvStorageFt= wSpareBase) { + DEBUG (( + DEBUG_ERROR, + "%a: NvStorageFtwSpareBase is not contiguous with NvStorageFtwWorkin= gBase region\n", + __FUNCTION__ + )); + return EFI_INVALID_PARAMETER; + } + + // Check if the size of the area is at least one block size + if ((NvStorageVariableSize <=3D 0) || (NvStorageVariableSize / Instance-= >BlockSize <=3D 0)) { + DEBUG (( + DEBUG_ERROR, + "%a: NvStorageVariableSize is 0x%x, should be atleast one block size= \n", + __FUNCTION__, + NvStorageVariableSize + )); + return EFI_INVALID_PARAMETER; + } + + if ((NvStorageFtwWorkingSize <=3D 0) || (NvStorageFtwWorkingSize / Insta= nce->BlockSize <=3D 0)) { + DEBUG (( + DEBUG_ERROR, + "%a: NvStorageFtwWorkingSize is 0x%x, should be atleast one block si= ze\n", + __FUNCTION__, + NvStorageFtwWorkingSize + )); + return EFI_INVALID_PARAMETER; + } + + if ((NvStorageFtwSpareSize <=3D 0) || (NvStorageFtwSpareSize / Instance-= >BlockSize <=3D 0)) { + DEBUG (( + DEBUG_ERROR, + "%a: NvStorageFtwSpareSize is 0x%x, should be atleast one block size= \n", + __FUNCTION__, + NvStorageFtwSpareSize + )); + return EFI_INVALID_PARAMETER; + } + + // Ensure the Variable area Base Addresses are aligned on a block size b= oundaries + if ((NvStorageVariableBase % Instance->BlockSize !=3D 0) || + (NvStorageFtwWorkingBase % Instance->BlockSize !=3D 0) || + (NvStorageFtwSpareBase % Instance->BlockSize !=3D 0)) + { + DEBUG ((DEBUG_ERROR, "%a: NvStorage Base addresses must be aligned to = block size boundaries", __FUNCTION__)); + return EFI_INVALID_PARAMETER; + } + + // + // EFI_FIRMWARE_VOLUME_HEADER + // + FirmwareVolumeHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)Headers; + CopyGuid (&FirmwareVolumeHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid= ); + FirmwareVolumeHeader->FvLength =3D + PcdGet32 (PcdFlashNvStorageVariableSize) + + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) + + PcdGet32 (PcdFlashNvStorageFtwSpareSize); + FirmwareVolumeHeader->Signature =3D EFI_FVH_SIGNATURE; + FirmwareVolumeHeader->Attributes =3D (EFI_FVB_ATTRIBUTES_2)( + EFI_FVB2_READ_= ENABLED_CAP | // Reads may be enabled + EFI_FVB2_READ_= STATUS | // Reads are currently enabled + EFI_FVB2_STICK= Y_WRITE | // A block erase is required to flip bits into EFI_FVB2_ERA= SE_POLARITY + EFI_FVB2_MEMOR= Y_MAPPED | // It is memory mapped + EFI_FVB2_ERASE= _POLARITY | // After erasure all bits take this value (i.e. '1') + EFI_FVB2_WRITE= _STATUS | // Writes are currently enabled + EFI_FVB2_WRITE= _ENABLED_CAP // Writes may be enabled + ); + FirmwareVolumeHeader->HeaderLength =3D sizeof (EFI_FIRMWARE_VOL= UME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY); + FirmwareVolumeHeader->Revision =3D EFI_FVH_REVISION; + FirmwareVolumeHeader->BlockMap[0].NumBlocks =3D Instance->LastBlock + 1; + FirmwareVolumeHeader->BlockMap[0].Length =3D Instance->BlockSize; + FirmwareVolumeHeader->BlockMap[1].NumBlocks =3D 0; + FirmwareVolumeHeader->BlockMap[1].Length =3D 0; + FirmwareVolumeHeader->Checksum =3D CalculateCheckSum16 ((UI= NT16 *)FirmwareVolumeHeader, FirmwareVolumeHeader->HeaderLength); + + // + // VARIABLE_STORE_HEADER + // + VariableStoreHeader =3D (VARIABLE_STORE_HEADER *)((UINTN)Headers + Firmw= areVolumeHeader->HeaderLength); + CopyGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid); + VariableStoreHeader->Size =3D PcdGet32 (PcdFlashNvStorageVariableSize)= - FirmwareVolumeHeader->HeaderLength; + VariableStoreHeader->Format =3D VARIABLE_STORE_FORMATTED; + VariableStoreHeader->State =3D VARIABLE_STORE_HEALTHY; + + // Install the combined super-header in the NorFlash + Status =3D FvbWrite (&Instance->FvbProtocol, 0, 0, &HeadersLength, Heade= rs); + + FreePool (Headers); + return Status; +} + +/** + Check the integrity of firmware volume header. + + @retval EFI_SUCCESS - The firmware volume is consistent + @retval EFI_NOT_FOUND - The firmware volume has been corrupted. + +**/ +EFI_STATUS +ValidateFvHeader ( + VOID + ) +{ + UINT16 Checksum; + EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader; + VARIABLE_STORE_HEADER *VariableStoreHeader; + UINTN VariableStoreLength; + UINTN FvLength; + EFI_STATUS TempStatus; + UINTN BufferSize; + UINTN BufferSizeReqested; + + BufferSizeReqested =3D sizeof (EFI_FIRMWARE_VOLUME_HEADER); + FwVolHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)AllocatePool (Buffe= rSizeReqested); + if (!FwVolHeader) { + return EFI_OUT_OF_RESOURCES; + } + + BufferSize =3D BufferSizeReqested; + TempStatus =3D SmmStoreLibRead (0, 0, &BufferSize, (UINT8 *)FwVolHeader)= ; + if (EFI_ERROR (TempStatus) || (BufferSizeReqested !=3D BufferSize)) { + FreePool (FwVolHeader); + return EFI_DEVICE_ERROR; + } + + FvLength =3D PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFla= shNvStorageFtwWorkingSize) + + PcdGet32 (PcdFlashNvStorageFtwSpareSize); + + // + // 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 FvLength) + ) + { + DEBUG (( + DEBUG_INFO, + "%a: No Firmware Volume header present\n", + __FUNCTION__ + )); + FreePool (FwVolHeader); + return EFI_NOT_FOUND; + } + + // Check the Firmware Volume Guid + if ( CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid)= =3D=3D FALSE ) { + DEBUG (( + DEBUG_INFO, + "%a: Firmware Volume Guid non-compatible\n", + __FUNCTION__ + )); + FreePool (FwVolHeader); + return EFI_NOT_FOUND; + } + + BufferSizeReqested =3D FwVolHeader->HeaderLength; + FreePool (FwVolHeader); + FwVolHeader =3D (EFI_FIRMWARE_VOLUME_HEADER *)AllocatePool (BufferSizeRe= qested); + if (!FwVolHeader) { + return EFI_OUT_OF_RESOURCES; + } + + BufferSize =3D BufferSizeReqested; + TempStatus =3D SmmStoreLibRead (0, 0, &BufferSize, (UINT8 *)FwVolHeader)= ; + if (EFI_ERROR (TempStatus) || (BufferSizeReqested !=3D BufferSize)) { + FreePool (FwVolHeader); + return EFI_DEVICE_ERROR; + } + + // Verify the header checksum + Checksum =3D CalculateSum16 ((UINT16 *)FwVolHeader, FwVolHeader->HeaderL= ength); + if (Checksum !=3D 0) { + DEBUG (( + DEBUG_INFO, + "%a: FV checksum is invalid (Checksum:0x%X)\n", + __FUNCTION__, + Checksum + )); + FreePool (FwVolHeader); + return EFI_NOT_FOUND; + } + + BufferSizeReqested =3D sizeof (VARIABLE_STORE_HEADER); + VariableStoreHeader =3D (VARIABLE_STORE_HEADER *)AllocatePool (BufferSiz= eReqested); + if (!VariableStoreHeader) { + return EFI_OUT_OF_RESOURCES; + } + + BufferSize =3D BufferSizeReqested; + TempStatus =3D SmmStoreLibRead (0, FwVolHeader->HeaderLength, &BufferSiz= e, (UINT8 *)VariableStoreHeader); + if (EFI_ERROR (TempStatus) || (BufferSizeReqested !=3D BufferSize)) { + FreePool (VariableStoreHeader); + FreePool (FwVolHeader); + return EFI_DEVICE_ERROR; + } + + // Check the Variable Store Guid + if (!CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) && + !CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVar= iableGuid)) + { + DEBUG (( + DEBUG_INFO, + "%a: Variable Store Guid non-compatible\n", + __FUNCTION__ + )); + FreePool (FwVolHeader); + FreePool (VariableStoreHeader); + return EFI_NOT_FOUND; + } + + VariableStoreLength =3D PcdGet32 (PcdFlashNvStorageVariableSize) - FwVol= Header->HeaderLength; + if (VariableStoreHeader->Size !=3D VariableStoreLength) { + DEBUG (( + DEBUG_INFO, + "%a: Variable Store Length does not match\n", + __FUNCTION__ + )); + FreePool (FwVolHeader); + FreePool (VariableStoreHeader); + return EFI_NOT_FOUND; + } + + FreePool (FwVolHeader); + FreePool (VariableStoreHeader); + + return EFI_SUCCESS; +} + +/** + The GetAttributes() function retrieves the attributes and + current settings of the block. + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL ins= tance. + + @param Attributes Pointer to EFI_FVB_ATTRIBUTES_2 in which the attribut= es and + current settings are returned. + Type EFI_FVB_ATTRIBUTES_2 is defined in EFI_FIRMWARE_= VOLUME_HEADER. + + @retval EFI_SUCCESS The firmware volume attributes were returned. + + **/ +EFI_STATUS +EFIAPI +FvbGetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ) +{ + EFI_FVB_ATTRIBUTES_2 FlashFvbAttributes; + + FlashFvbAttributes =3D (EFI_FVB_ATTRIBUTES_2)( + EFI_FVB2_READ_STATUS | = // Reads are currently enabled + EFI_FVB2_WRITE_STATUS | = // Writes are enabled + EFI_FVB2_STICKY_WRITE | = // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY + EFI_FVB2_MEMORY_MAPPED | = // It is memory mapped + EFI_FVB2_ERASE_POLARITY = // After erasure all bits take this value (i.e. '1') + ); + + *Attributes =3D FlashFvbAttributes; + + DEBUG ((DEBUG_BLKIO, "FvbGetAttributes(0x%X)\n", *Attributes)); + + return EFI_SUCCESS; +} + +/** + The SetAttributes() function sets configurable firmware volume attributes + and returns the new settings of the firmware volume. + + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_= PROTOCOL instance. + + @param Attributes On input, Attributes is a pointer to EFI_= FVB_ATTRIBUTES_2 + that contains the desired firmware volume= settings. + On successful return, it contains the new= settings of + the firmware volume. + Type EFI_FVB_ATTRIBUTES_2 is defined in E= FI_FIRMWARE_VOLUME_HEADER. + + @retval EFI_SUCCESS The firmware volume attributes were retur= ned. + + @retval EFI_INVALID_PARAMETER The attributes requested are in conflict = with the capabilities + as declared in the firmware volume header= . + + **/ +EFI_STATUS +EFIAPI +FvbSetAttributes ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes + ) +{ + DEBUG ((DEBUG_ERROR, "FvbSetAttributes(0x%X) is not supported\n", *Attri= butes)); + return EFI_UNSUPPORTED; +} + +/** + The GetPhysicalAddress() function retrieves the base address of + a memory-mapped firmware volume. This function should be called + only for memory-mapped firmware volumes. + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROTOC= OL instance. + + @param Address Pointer to a caller-allocated + EFI_PHYSICAL_ADDRESS that, on successful + return from GetPhysicalAddress(), contains the + base address of the firmware volume. + + @retval EFI_SUCCESS The firmware volume base address was returned. + + @retval EFI_NOT_SUPPORTED The firmware volume is not memory mapped. + + **/ +EFI_STATUS +EFIAPI +FvbGetPhysicalAddress ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + OUT EFI_PHYSICAL_ADDRESS *Address + ) +{ + SMMSTORE_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_FVB_THIS (This); + + ASSERT (Address !=3D NULL); + *Address =3D Instance->MmioAddress; + + return EFI_SUCCESS; +} + +/** + The GetBlockSize() function retrieves the size of the requested + block. It also returns the number of additional blocks with + the identical size. The GetBlockSize() function is used to + retrieve the block map (see EFI_FIRMWARE_VOLUME_HEADER). + + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_= PROTOCOL instance. + + @param Lba Indicates the block for which to return t= he size. + + @param BlockSize Pointer to a caller-allocated UINTN in wh= ich + the size of the block is returned. + + @param NumberOfBlocks Pointer to a caller-allocated UINTN in + which the number of consecutive blocks, + starting with Lba, is returned. All + blocks in this range have a size of + BlockSize. + + + @retval EFI_SUCCESS The firmware volume base address was retu= rned. + + @retval EFI_INVALID_PARAMETER The requested LBA is out of range. + + **/ +EFI_STATUS +EFIAPI +FvbGetBlockSize ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + OUT UINTN *BlockSize, + OUT UINTN *NumberOfBlocks + ) +{ + EFI_STATUS Status; + SMMSTORE_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_FVB_THIS (This); + + DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=3D%ld, BlockSize=3D0x%x, LastB= lock=3D%ld)\n", Lba, Instance->BlockSize, Instance->LastBlock)); + + if (Lba > Instance->LastBlock) { + DEBUG ((DEBUG_ERROR, "FvbGetBlockSize: ERROR - Parameter LBA %ld is be= yond the last Lba (%ld).\n", Lba, Instance->LastBlock)); + Status =3D EFI_INVALID_PARAMETER; + } else { + *BlockSize =3D (UINTN)Instance->BlockSize; + *NumberOfBlocks =3D (UINTN)(Instance->LastBlock - Lba + 1); + + DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize: *BlockSize=3D0x%x, *NumberOfBlo= cks=3D0x%x.\n", *BlockSize, *NumberOfBlocks)); + + Status =3D EFI_SUCCESS; + } + + return Status; +} + +/** + Reads the specified number of bytes into a buffer from the specified bloc= k. + + The Read() function reads the requested number of bytes from the + requested block and stores them in the provided buffer. + Implementations should be mindful that the firmware volume + might be in the ReadDisabled state. If it is in this state, + the Read() function must return the status code + EFI_ACCESS_DENIED without modifying the contents of the + buffer. The Read() function must also prevent spanning block + boundaries. If a read is requested that would span a block + boundary, the read must read up to the boundary but not + beyond. The output parameter NumBytes must be set to correctly + indicate the number of bytes actually read. The caller must be + aware that a read may be partially completed. + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROT= OCOL instance. + + @param Lba The starting logical block index from which t= o read. + + @param Offset Offset into the block at which to begin readi= ng. + + @param NumBytes Pointer to a UINTN. + At entry, *NumBytes contains the total size o= f the buffer. + At exit, *NumBytes contains the total number = of bytes read. + + @param Buffer Pointer to a caller-allocated buffer that wil= l be used + to hold the data that is read. + + @retval EFI_SUCCESS The firmware volume was read successfully, a= nd contents are + in Buffer. + + @retval EFI_BAD_BUFFER_SIZE Read attempted across an LBA boundary. + On output, NumBytes contains the total number= of bytes + returned in Buffer. + + @retval EFI_ACCESS_DENIED The firmware volume is in the ReadDisabled st= ate. + + @retval EFI_DEVICE_ERROR The block device is not functioning correctly= and could not be read. + + **/ +EFI_STATUS +EFIAPI +FvbRead ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN OUT UINT8 *Buffer + ) +{ + UINTN BlockSize; + SMMSTORE_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_FVB_THIS (This); + + DEBUG ((DEBUG_BLKIO, "FvbRead(Parameters: Lba=3D%ld, Offset=3D0x%x, *Num= Bytes=3D0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes, Buffer)); + + // Cache the block size to avoid de-referencing pointers all the time + BlockSize =3D Instance->BlockSize; + + // The read must not span block boundaries. + // We need to check each variable individually because adding two large = values together overflows. + if ((Offset >=3D BlockSize) || + (*NumBytes > BlockSize) || + ((Offset + *NumBytes) > BlockSize)) + { + DEBUG ((DEBUG_ERROR, "FvbRead: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=3D= 0x%x + NumBytes=3D0x%x) > BlockSize=3D0x%x\n", Offset, *NumBytes, BlockSize= )); + return EFI_BAD_BUFFER_SIZE; + } + + // We must have some bytes to read + if (*NumBytes =3D=3D 0) { + return EFI_BAD_BUFFER_SIZE; + } + + return SmmStoreLibRead (Lba, Offset, NumBytes, Buffer); +} + +/** + Writes the specified number of bytes from the input buffer to the block. + + The Write() function writes the specified number of bytes from + the provided buffer to the specified block and offset. If the + firmware volume is sticky write, the caller must ensure that + all the bits of the specified range to write are in the + EFI_FVB_ERASE_POLARITY state before calling the Write() + function, or else the result will be unpredictable. This + unpredictability arises because, for a sticky-write firmware + volume, a write may negate a bit in the EFI_FVB_ERASE_POLARITY + state but cannot flip it back again. Before calling the + Write() function, it is recommended for the caller to first call + the EraseBlocks() function to erase the specified block to + write. A block erase cycle will transition bits from the + (NOT)EFI_FVB_ERASE_POLARITY state back to the + EFI_FVB_ERASE_POLARITY state. Implementations should be + mindful that the firmware volume might be in the WriteDisabled + state. If it is in this state, the Write() function must + return the status code EFI_ACCESS_DENIED without modifying the + contents of the firmware volume. The Write() function must + also prevent spanning block boundaries. If a write is + requested that spans a block boundary, the write must store up + to the boundary but not beyond. The output parameter NumBytes + must be set to correctly indicate the number of bytes actually + written. The caller must be aware that a write may be + partially completed. All writes, partial or otherwise, must be + fully flushed to the hardware before the Write() service + returns. + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_PROT= OCOL instance. + + @param Lba The starting logical block index to write to. + + @param Offset Offset into the block at which to begin writi= ng. + + @param NumBytes The pointer to a UINTN. + At entry, *NumBytes contains the total size o= f the buffer. + At exit, *NumBytes contains the total number = of bytes actually written. + + @param Buffer The pointer to a caller-allocated buffer that= contains the source for the write. + + @retval EFI_SUCCESS The firmware volume was written successfully. + + @retval EFI_BAD_BUFFER_SIZE The write was attempted across an LBA boundar= y. + On output, NumBytes contains the total number= of bytes + actually written. + + @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabled s= tate. + + @retval EFI_DEVICE_ERROR The block device is malfunctioning and could = not be written. + + + **/ +EFI_STATUS +EFIAPI +FvbWrite ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + IN EFI_LBA Lba, + IN UINTN Offset, + IN OUT UINTN *NumBytes, + IN UINT8 *Buffer + ) +{ + UINTN BlockSize; + SMMSTORE_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_FVB_THIS (This); + + DEBUG ((DEBUG_BLKIO, "FvbWrite(Parameters: Lba=3D%ld, Offset=3D0x%x, *Nu= mBytes=3D0x%x, Buffer @ 0x%08x)\n", Lba, Offset, *NumBytes, Buffer)); + + // Cache the block size to avoid de-referencing pointers all the time + BlockSize =3D Instance->BlockSize; + + // The read must not span block boundaries. + // We need to check each variable individually because adding two large = values together overflows. + if ((Offset >=3D BlockSize) || + (*NumBytes > BlockSize) || + ((Offset + *NumBytes) > BlockSize)) + { + DEBUG ((DEBUG_ERROR, "FvbRead: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=3D= 0x%x + NumBytes=3D0x%x) > BlockSize=3D0x%x\n", Offset, *NumBytes, BlockSize= )); + return EFI_BAD_BUFFER_SIZE; + } + + // We must have some bytes to read + if (*NumBytes =3D=3D 0) { + return EFI_BAD_BUFFER_SIZE; + } + + return SmmStoreLibWrite (Lba, Offset, NumBytes, Buffer); +} + +/** + Erases and initialises a firmware volume block. + + The EraseBlocks() function erases one or more blocks as denoted + by the variable argument list. The entire parameter list of + blocks must be verified before erasing any blocks. If a block is + requested that does not exist within the associated firmware + volume (it has a larger index than the last block of the + firmware volume), the EraseBlocks() function must return the + status code EFI_INVALID_PARAMETER without modifying the contents + of the firmware volume. Implementations should be mindful that + the firmware volume might be in the WriteDisabled state. If it + is in this state, the EraseBlocks() function must return the + status code EFI_ACCESS_DENIED without modifying the contents of + the firmware volume. All calls to EraseBlocks() must be fully + flushed to the hardware before the EraseBlocks() service + returns. + + @param This Indicates the EFI_FIRMWARE_VOLUME_BLOCK2_= PROTOCOL + instance. + + @param ... The variable argument list is a list of t= uples. + Each tuple describes a range of LBAs to e= rase + and consists of the following: + - An EFI_LBA that indicates the starting = LBA + - A UINTN that indicates the number of bl= ocks to erase. + + The list is terminated with an EFI_LBA_LI= ST_TERMINATOR. + For example, the following indicates that= two ranges of blocks + (5-7 and 10-11) are to be erased: + EraseBlocks (This, 5, 3, 10, 2, EFI_LBA_L= IST_TERMINATOR); + + @retval EFI_SUCCESS The erase request successfully completed. + + @retval EFI_ACCESS_DENIED The firmware volume is in the WriteDisabl= ed state. + + @retval EFI_DEVICE_ERROR The block device is not functioning corre= ctly and could not be written. + The firmware device may have been partial= ly erased. + + @retval EFI_INVALID_PARAMETER One or more of the LBAs listed in the var= iable argument list do + not exist in the firmware volume. + + **/ +EFI_STATUS +EFIAPI +FvbEraseBlocks ( + IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This, + ... + ) +{ + EFI_STATUS Status; + VA_LIST Args; + EFI_LBA StartingLba; // Lba from which we start erasing + UINTN NumOfLba; // Number of Lba blocks to erase + SMMSTORE_INSTANCE *Instance; + + Instance =3D INSTANCE_FROM_FVB_THIS (This); + + Status =3D EFI_SUCCESS; + + // Before erasing, check the entire list of parameters to ensure all spe= cified blocks are valid + + VA_START (Args, This); + do { + // Get the Lba from which we start erasing + StartingLba =3D VA_ARG (Args, EFI_LBA); + + // Have we reached the end of the list? + if (StartingLba =3D=3D EFI_LBA_LIST_TERMINATOR) { + // Exit the while loop + break; + } + + // How many Lba blocks are we requested to erase? + NumOfLba =3D VA_ARG (Args, UINTN); + + // All blocks must be within range + DEBUG (( + DEBUG_BLKIO, + "FvbEraseBlocks: Check if: ( StartingLba=3D%ld + NumOfLba=3D%Lu - 1 = ) > LastBlock=3D%ld.\n", + StartingLba, + (UINT64)NumOfLba, + Instance->LastBlock + )); + if ((NumOfLba =3D=3D 0) || ((StartingLba + NumOfLba - 1) > Instance->L= astBlock)) { + VA_END (Args); + DEBUG ((DEBUG_ERROR, "FvbEraseBlocks: ERROR - Lba range goes past th= e last Lba.\n")); + Status =3D EFI_INVALID_PARAMETER; + goto EXIT; + } + } while (TRUE); + + VA_END (Args); + + // + // To get here, all must be ok, so start erasing + // + VA_START (Args, This); + do { + // Get the Lba from which we start erasing + StartingLba =3D VA_ARG (Args, EFI_LBA); + + // Have we reached the end of the list? + if (StartingLba =3D=3D EFI_LBA_LIST_TERMINATOR) { + // Exit the while loop + break; + } + + // How many Lba blocks are we requested to erase? + NumOfLba =3D VA_ARG (Args, UINTN); + + // Go through each one and erase it + while (NumOfLba > 0) { + // Erase it + DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Erasing Lba=3D%ld\n", Starting= Lba)); + Status =3D SmmStoreLibEraseBlock (StartingLba); + if (EFI_ERROR (Status)) { + VA_END (Args); + Status =3D EFI_DEVICE_ERROR; + goto EXIT; + } + + // Move to the next Lba + StartingLba++; + NumOfLba--; + } + } while (TRUE); + + VA_END (Args); + +EXIT: + return Status; +} + +/** + Initialized the Firmware Volume if necessary and installs the + gEdkiiNvVarStoreFormattedGuid protocol. + + @param Instance Pointer to SmmStore instance + + **/ +EFI_STATUS +EFIAPI +FvbInitialize ( + IN SMMSTORE_INSTANCE *Instance + ) +{ + EFI_STATUS Status; + UINT32 FvbNumLba; + EFI_BOOT_MODE BootMode; + + ASSERT ((Instance !=3D NULL)); + + BootMode =3D GetBootModeHob (); + if (BootMode =3D=3D BOOT_WITH_DEFAULT_SETTINGS) { + Status =3D EFI_INVALID_PARAMETER; + } else { + // Determine if there is a valid header at the beginning of the NorFla= sh + Status =3D ValidateFvHeader (); + } + + // Install the Default FVB header if required + if (EFI_ERROR (Status)) { + // There is no valid header, so time to install one. + DEBUG ((DEBUG_INFO, "%a: The FVB Header is not valid.\n", __FUNCTION__= )); + DEBUG (( + DEBUG_INFO, + "%a: Installing a correct one for this volume.\n", + __FUNCTION__ + )); + + // Erase all the NorFlash that is reserved for variable storage + FvbNumLba =3D (PcdGet32 (PcdFlashNvStorageVariableSize) + + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) + + PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / Instance->Blo= ckSize; + + Status =3D FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumL= ba, EFI_LBA_LIST_TERMINATOR); + if (EFI_ERROR (Status)) { + return Status; + } + + // Install all appropriate headers + Status =3D InitializeFvAndVariableStoreHeaders (Instance); + if (EFI_ERROR (Status)) { + return Status; + } + } else { + DEBUG ((DEBUG_INFO, "%a: FVB header is valid\n", __FUNCTION__)); + } + + // + // The driver implementing the variable read service can now be dispatch= ed; + // the varstore headers are in place. + // + Status =3D gBS->InstallProtocolInterface ( + &gImageHandle, + &gEdkiiNvVarStoreFormattedGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + ASSERT_EFI_ERROR (Status); + + return Status; +} diff --git a/UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntimeDxe.inf b/UefiPay= loadPkg/SmmStoreFvb/SmmStoreFvbRuntimeDxe.inf new file mode 100644 index 0000000000..2bd8886bcc --- /dev/null +++ b/UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntimeDxe.inf @@ -0,0 +1,66 @@ +## @file +# Component description file for SmmStore module +# +# This module produces the FirmwareVolumeBlock protocol on top of the +# SmmStore provided by bootloader and installs the NvVarStoreFormatted pr= otocol. +# +# Copyright (c) 2022, 9elements GmbH
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D SmmStoreFvbRuntimeDxe + FILE_GUID =3D A0402FCA-6B25-4CEA-B7DD-C08F99714B29 + MODULE_TYPE =3D DXE_RUNTIME_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D SmmStoreInitialize + +[Sources.common] + SmmStoreFvbRuntimeDxe.c + SmmStoreFvbRuntime.h + SmmStoreFvbRuntime.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + UefiPayloadPkg/UefiPayloadPkg.dec + +[LibraryClasses] + BaseLib + DebugLib + HobLib + SmmStoreLib + UefiLib + UefiDriverEntryPoint + UefiBootServicesTableLib + UefiRuntimeLib + DxeServicesTableLib + +[Guids] + gEfiSystemNvDataFvGuid + gEfiVariableGuid ## PRODUCES ## PROTOCOL + gEfiAuthenticatedVariableGuid + gEfiEventVirtualAddressChangeGuid + gEdkiiNvVarStoreFormattedGuid ## PRODUCES ## PROTOCOL + +[Protocols] + gEfiDevicePathProtocolGuid ## BY_START + gEfiFirmwareVolumeBlockProtocolGuid ## BY_START + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 + +[Depex] + TRUE diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayload= Pkg.dsc index cf440fee58..0f6421612c 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.dsc +++ b/UefiPayloadPkg/UefiPayloadPkg.dsc @@ -97,6 +97,7 @@ # # EMU: UEFI payload with EMU variable # SPI: UEFI payload with SPI NV variable support + # SMMSTORE: UEFI payload with coreboot SMM NV variable support # NONE: UEFI payload with no variable modules # DEFINE VARIABLE_SUPPORT =3D EMU @@ -261,9 +262,11 @@ LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLib= Null.inf - SmmStoreLib|UefiPayloadPkg/Library/SmmStoreLib/SmmStoreLib.inf !if $(VARIABLE_SUPPORT) =3D=3D "EMU" TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf +!elseif $(VARIABLE_SUPPORT) =3D=3D "SMMSTORE" + SmmStoreLib|UefiPayloadPkg/Library/SmmStoreLib/SmmStoreLib.inf + TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurem= entLibNull.inf !elseif $(VARIABLE_SUPPORT) =3D=3D "SPI" PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecu= reLibNull.inf TpmMeasurementLib|SecurityPkg/Library/DxeTpmMeasurementLib/DxeTpmMeasure= mentLib.inf @@ -379,15 +382,13 @@ gUefiCpuPkgTokenSpaceGuid.PcdCpuSmmEnableBspElection|FALSE =20 [PcdsFixedAtBuild] - gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x10000 gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize|0x8000 gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x10000 !if $(VARIABLE_SUPPORT) =3D=3D "EMU" gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable |TRUE -!else +!elseif $(VARIABLE_SUPPORT) =3D=3D "SPI" || $(VARIABLE_SUPPORT) =3D=3D "SM= MSTORE" gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable |FALSE !endif - gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0 gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory|FALSE gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable|TRUE @@ -445,7 +446,6 @@ gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber|$(MAX_LOGICAL_= PROCESSORS) gUefiCpuPkgTokenSpaceGuid.PcdCpuNumberOfReservedVariableMtrrs|0 gUefiPayloadPkgTokenSpaceGuid.PcdBootloaderParameter|0 - ##########################################################################= ###### # # Pcd DynamicEx Section - list of all EDK II PCD Entries defined by this P= latform @@ -473,15 +473,19 @@ !endif gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FAL= SE gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0 gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|3 -!if $(VARIABLE_SUPPORT) =3D=3D "SPI" +!if $(VARIABLE_SUPPORT) =3D=3D "SPI" || $(VARIABLE_SUPPORT) =3D=3D "SMMSTO= RE" gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize |0 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize |0 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase |0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64|0 + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64|0 !endif # Disable SMM S3 script gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable|FALSE @@ -697,6 +701,14 @@ =20 !if $(VARIABLE_SUPPORT) =3D=3D "EMU" MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf +!elseif $(VARIABLE_SUPPORT) =3D=3D "SMMSTORE" + UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntimeDxe.inf + MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf { + + NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf + NULL|EmbeddedPkg/Library/NvVarStoreFormattedLib/NvVarStoreFormattedL= ib.inf + } !elseif $(VARIABLE_SUPPORT) =3D=3D "SPI" MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf { diff --git a/UefiPayloadPkg/UefiPayloadPkg.fdf b/UefiPayloadPkg/UefiPayload= Pkg.fdf index c7b04978ad..ca44f48f6d 100644 --- a/UefiPayloadPkg/UefiPayloadPkg.fdf +++ b/UefiPayloadPkg/UefiPayloadPkg.fdf @@ -140,6 +140,10 @@ INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRea= lTimeClockRuntimeDxe.inf =20 !if $(VARIABLE_SUPPORT) =3D=3D "EMU" INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf +!elseif $(VARIABLE_SUPPORT) =3D=3D "SMMSTORE" + INF UefiPayloadPkg/SmmStoreFvb/SmmStoreFvbRuntimeDxe.inf + INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.i= nf + INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf !elseif $(VARIABLE_SUPPORT) =3D=3D "SPI" INF UefiPayloadPkg/FvbRuntimeDxe/FvbSmm.inf INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.i= nf --=20 2.32.0