From patchwork Mon Jan 14 13:27:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 155492 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3658727jaa; Mon, 14 Jan 2019 05:28:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN41hxYNFexMIY9upznWbYbECDDzRxyUzGifsjUnaRfk4a6kt8OVikAhl+6g0TOU18At29LN X-Received: by 2002:a62:6e07:: with SMTP id j7mr26078506pfc.135.1547472518517; Mon, 14 Jan 2019 05:28:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547472518; cv=none; d=google.com; s=arc-20160816; b=yp1etG9GhalPWXogs6GhCuYJkiNkoiI4AK0tSERHCEi9l0GzHViBGUvBnaNfPwlwsw aPbSyqyzarqOZ5mPtsOyjWif2qWGWwb4mlhPmQRbfWRzCEyQcin4KSIt0IsKdGKmKCLi Jk4MlJ7zrEpJQpnMbKEEAg3cDD3Au/59YcteXWDLGz847BqU3uj09YyneqDKGFsvL5cd B+UCDEpaT11ctv+sQdyF87RxKnE3QYmASKqD0R7Itf1G0ZrELjOsNRtn7Zg41yIsp7X2 MsjMaiYQls3Mi1ZqgkkU3hDtA5raM7DukC3xJN1GOwjYaaTV02G7RXN8UOc3L6MN1dkt iMVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=9YFqYELuICpFZ60KUt6+ntHvZkVAPksWShIZskH63rs=; b=naytetBrHg5tekxIaqx8xKShj46j1+xVzuY/1wSlJzr/Ejk46MwvVANNyPRurwfjAv /z8eLl03FrjgwQ4du62Sna6tnFfRBbydgkiR9XtBuZSbLRHX17o1+mX9Y24lqBF3nfG8 jVIf5nchqz1YOD7JGD8eyqsbNXPTiFeydv3TjqqP74VLjO3ipac/fwRNj2zg06UxtLp9 uFbrqRWRh0VfroJptu6FrWpzKqN2f76r0aqXt98aZZr3A0NMe4gm9AiMAErOIGJ+GQma 1Neu/QxvTE8AcIlrlXTGYIFOad6XB26sMdg3mZ2kMpp6j52AmH2+gMD/r63ANe0OzTmp 9wqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=G9OGHWqq; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id u25si344094pgm.532.2019.01.14.05.28.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jan 2019 05:28:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=G9OGHWqq; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 30625211B76C3; Mon, 14 Jan 2019 05:28:24 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::444; helo=mail-wr1-x444.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9541D211B739D for ; Mon, 14 Jan 2019 05:28:22 -0800 (PST) Received: by mail-wr1-x444.google.com with SMTP id j2so22926632wrw.1 for ; Mon, 14 Jan 2019 05:28:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sPvgL9rPfGGBUF7lXXzmGQjdT3XcD246PvswS/wpSDo=; b=G9OGHWqqN0ugI4/Gm7BOmXALW5B4n3ssD5h4XlcaaKcL2MRiXO5lJyVpw5/dD9AU2m cJP4J1RqssittdUlTh3nzdxfTkpjG/RE7SZZT0PX6d58KmOhLH0ZJd7VUkxFe8t835b0 9uNBT2RFQkVObf0304uAck80F9RyEhk0fLb7c= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sPvgL9rPfGGBUF7lXXzmGQjdT3XcD246PvswS/wpSDo=; b=BI9O8DrGQ0cqXyvHHpn3W+VnIh2vh/0car2RYxgXqTqjECEn6McXnKbR5cxinRZxoJ a9YA4HYFco39ExOdG+E5fNSKYKIokNrkjB3aLtUOGSOFvTAtcvCauAHmiCsOF+LIw5Zv UpnVL/bXXo9QNYRO28Wc2ALSqeuCmeDtisYsmxIsgUD15BnXLu3eO6rv83qpi/uvDUSl hjRkR9VW8VDWenOXcGzV725B5RlmE9/a1Bv1DpCGSxleiBV8qmMMA2SN5EpgSdeS5Z73 0VAa15lnR5QWkdGyX5C1BHvzX5A2g0p59IH4LvsLYVVTtVaowrSqI6o5y5kb8VKrDNwb Jc4g== X-Gm-Message-State: AJcUukcoMblbmEg/AEVWnt46us/KA+XbdC4C3Gxw3KKF9e8uQdlMRMcH hO4XALH3Zxcq3It0BRYCKsX7aL6ofE8= X-Received: by 2002:adf:8323:: with SMTP id 32mr23476975wrd.176.1547472500914; Mon, 14 Jan 2019 05:28:20 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-19-62.w90-86.abo.wanadoo.fr. [90.86.222.62]) by smtp.gmail.com with ESMTPSA id 202sm33446560wmt.8.2019.01.14.05.28.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jan 2019 05:28:19 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Mon, 14 Jan 2019 14:27:47 +0100 Message-Id: <20190114132758.24054-7-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190114132758.24054-1-ard.biesheuvel@linaro.org> References: <20190114132758.24054-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Subject: [edk2] [PATCH v2 06/17] MdeModulePkg/FaultTolerantWriteDxe: implement standalone MM version X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hao Wu , Liming Gao , Michael D Kinney , Laszlo Ersek , Star Zeng Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Implement a new version of the fault tolerant write driver that can be used in the context of a standalone MM implementation. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Reviewed-by: Jian J Wang --- MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf | 90 ++++++++++++++++++++ MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.c | 88 +++++++++++++++++++ 2 files changed, 178 insertions(+) -- 2.20.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf new file mode 100644 index 000000000000..c667d4c19bfa --- /dev/null +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.inf @@ -0,0 +1,90 @@ + ## @file +# Fault Tolerant Write Smm Driver. +# +# This driver installs SMM Fault Tolerant Write (FTW) protocol, which provides fault +# tolerant write capability in SMM environment for block devices. Its implementation +# depends on the full functionality SMM FVB protocol that support read, write/erase +# flash access. +# +# Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
+# Copyright (c) 2018, Linaro, Ltd. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = FaultTolerantWriteStandaloneMm + FILE_GUID = 3aade4ec-63cc-4a48-a928-5a374dd463eb + MODULE_TYPE = MM_STANDALONE + VERSION_STRING = 1.0 + PI_SPECIFICATION_VERSION = 0x00010032 + ENTRY_POINT = StandaloneMmFaultTolerantWriteInitialize + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64 +# + +[Sources] + FtwMisc.c + UpdateWorkingBlock.c + FaultTolerantWrite.c + FaultTolerantWriteStandaloneMm.c + FaultTolerantWriteSmm.c + FaultTolerantWrite.h + FaultTolerantWriteSmmCommon.h + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + StandaloneMmPkg/StandaloneMmPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + MmServicesTableLib + PcdLib + ReportStatusCodeLib + StandaloneMmDriverEntryPoint + +[Guids] + # + # Signature in EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER + # + ## CONSUMES ## GUID + ## PRODUCES ## GUID + gEdkiiWorkingBlockSignatureGuid + +[Protocols] + gEfiSmmSwapAddressRangeProtocolGuid | gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## SOMETIMES_CONSUMES + ## NOTIFY + ## CONSUMES + gEfiSmmFirmwareVolumeBlockProtocolGuid + ## PRODUCES + ## UNDEFINED # SmiHandlerRegister + gEfiSmmFaultTolerantWriteProtocolGuid + gEfiMmEndOfDxeProtocolGuid ## CONSUMES + +[FeaturePcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## CONSUMES + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## SOMETIMES_CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## CONSUMES + +[Depex] + TRUE diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.c new file mode 100644 index 000000000000..95effd6d75fa --- /dev/null +++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandaloneMm.c @@ -0,0 +1,88 @@ +/** @file + + Parts of the SMM/MM implementation that are specific to standalone MM + +Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
+Copyright (c) 2018, Linaro, Ltd. All rights reserved.
+This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include +#include +#include "FaultTolerantWrite.h" +#include "FaultTolerantWriteSmmCommon.h" + +/** + This function checks if the buffer is valid per processor architecture and + does not overlap with SMRAM. + + @param Buffer The buffer start address to be checked. + @param Length The buffer length to be checked. + + @retval TRUE This buffer is valid per processor architecture and does not + overlap with SMRAM. + @retval FALSE This buffer is not valid per processor architecture or overlaps + with SMRAM. +**/ +BOOLEAN +FtwSmmIsBufferOutsideSmmValid ( + IN EFI_PHYSICAL_ADDRESS Buffer, + IN UINT64 Length + ) +{ + return TRUE; +} + +/** + Internal implementation of CRC32. Depending on the execution context + (standalone SMM or DXE vs standalone MM), this function is implemented + via a call to the CalculateCrc32 () boot service, or via a library + call. + + If Buffer is NULL, then ASSERT(). + If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT(). + + @param[in] Buffer A pointer to the buffer on which the 32-bit CRC is to be computed. + @param[in] Length The number of bytes in the buffer Data. + + @retval Crc32 The 32-bit CRC was computed for the data buffer. + +**/ +UINT32 +FtwCalculateCrc32 ( + IN VOID *Buffer, + IN UINTN Length + ) +{ + return CalculateCrc32 (Buffer, Length); +} + +/** + Notify the system that the SMM FTW driver is ready +**/ +VOID +FtwNotifySmmReady ( + VOID + ) +{ +} + +/** + Entry point of the module +**/ +EFI_STATUS +EFIAPI +StandaloneMmFaultTolerantWriteInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_MM_SYSTEM_TABLE *MmSystemTable + ) +{ + return MmFaultTolerantWriteInitialize (); +}