From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by mx.groups.io with SMTP id smtpd.web08.7223.1613151306935318899 for ; Fri, 12 Feb 2021 09:35:07 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@linaro.org header.s=google header.b=u426ma9j; spf=pass (domain: linaro.org, ip: 209.85.221.41, mailfrom: ilias.apalodimas@linaro.org) Received: by mail-wr1-f41.google.com with SMTP id t15so43100wrx.13 for ; Fri, 12 Feb 2021 09:35:06 -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=KyWcFV1aBfJzsYHrGsgRoZOSW+oXidk8rkB1rK9m3gc=; b=u426ma9jlZMmp2LBL6RRoVIzOtXdeG2vQG2JcI0ks+c/98JMQ6n1jhspptLarK6IEJ YA/Y5ZVZJ/7Fr8Ae53+BRjsVzSv2WoecgdFLGmRQx4FD9n8Qpw+w3B8W+ysf+vUQnwrj ZqZXBvCogQq+snUDx5h/whWm/KSR6+fKsXZqg1PfoNR4fQJ9bjaLwv213riHVDiYj1RX 2hmIToTuX1rJf4xFFCaZkzCUQ83fFIDVfgHSPbFpDSrtyLKO3CvcjHbU0VV6eOsnsUqC rfQfFMVBqJMS4tsdqo2iOPH+WLsjPcrOxHbgV2RJEwFF1A54Hhvq4AO98JKHFsIrq1tJ JYVw== 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=KyWcFV1aBfJzsYHrGsgRoZOSW+oXidk8rkB1rK9m3gc=; b=X0K4Jh5tqo2DtfzXJCiXey1pSKe7NGcGjG0Vl029TaSDhK4OlNqc5BFp16joWZdN5X jCY8ccZtG/sKo4dCNF5Y62fWEkQg50aKu5Tojpl8OGjPf7bAPwsmRJKxsImUcC5cAz/E WsSN5cs6khDe5RIUxTDnrCdf9v1jEiQt8fnMGrQKoKVhqW+pU/2/8qzmRkaQlDd/EAB3 5oVU60+LQBjYWOfsitHtj6MiYUjq/5L7yzRBXvw5gJFvgrvI8ZpI9+DBkn8XU7Ubn/Ij 28U77/jrGrgykAY1sn+PMIXEZaF6y2jXnz56oLH/z+cCJdMayHEz0xbMat5XIXOYm1Y5 GguQ== X-Gm-Message-State: AOAM531rT1+2rvcsqkgsGUeeQhjVVE2dOB7k0DD+woa7P5Hg4/tlrjk1 SUI6Ij9Rg0wta8vjqAAXfbkIsNMV+hvjZ56N X-Google-Smtp-Source: ABdhPJz6Ievn1gN0nYsB91IWWQE4TaoVYma7PpfDBA+rX6q7Wk9ek7hfpX/tAIqoDlKhlBhHh1wxuA== X-Received: by 2002:a5d:47a2:: with SMTP id 2mr4721224wrb.393.1613151305458; Fri, 12 Feb 2021 09:35:05 -0800 (PST) Return-Path: Received: from apalos.home ([2a02:587:4647:e6c6:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id h13sm11535852wrv.20.2021.02.12.09.35.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Feb 2021 09:35:05 -0800 (PST) From: "Ilias Apalodimas" To: devel@edk2.groups.io, sami.mujawar@arm.com Cc: ardb+tianocore@kernel.org, sughosh.ganu@linaro.org, leif@nuviainc.com, Ilias Apalodimas Subject: [PATCH 2/2 v5] StMMRpmb: Add support for building StandaloneMm image for OP-TEE Date: Fri, 12 Feb 2021 19:34:59 +0200 Message-Id: <20210212173459.508205-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210212173459.508205-1-ilias.apalodimas@linaro.org> References: <20210212173459.508205-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable With some recent changes in OP-TEE [1] and U-Boot [2] we can compile StMM and launch it from an OP-TEE secure partition which is mimicking SPM. There's a number of advantages in this approach. In Arm world SPM, currently used for dispatching StMM, and SPD used for OP-TEE, are mutually exclusive. Since there's no application in OP-TEE for managing EFI variables, this means that one can have a secure OS or secure variable storage. By re-using StMM we have EDK2s approved application controlling variable storage and the ability to run a secure world OS. This also allows various firmware implementations to adopt EDK2 way of storing variables (including the FTW implementation), as long as OP-TEE is available on that given platform (or any other secure OS that can launch StMM and has a supplicant for handling the RPMB partition). Another advantage is that OP-TEE has the ability to access an eMMC RPMB partition to store those variables. This requires a normal world supplicant, which is implemented in U-Boot currently. The supplicant picks up the encrypted buffer from OP-TEE and wires it to the eMMC driver(s). Similar functionality can be added in EDK2 by porting the supplicant and adapt it to using the native eMMC drivers. There's is one drawback in using OP-TEE. The current SPM calls need to run to completion. This contradicts the current OP-TEE RPC call requirements, used to access the RPMB storage. Thats leads to two different SMC calls for entering secure world to access StMM. So let's add support for a platform that compiles StMM and an RPMB driver that communicates with OP-TEE to read/write the variables. For anyone interested in testing this there's repo that builds all the sources and works on QEMU [3]. [1] https://github.com/OP-TEE/optee_os/pull/3973 [2] http://u-boot.10912.n7.nabble.com/PATCH-0-7-v4-EFI-variable-support-via= -OP-TEE-td412499.html [3] https://git.linaro.org/people/ilias.apalodimas/efi_optee_variables.git/ Reviewed-by: Sami Mujawar Signed-off-by: Ilias Apalodimas --- Platform/StMMRpmb/PlatformStandaloneMm.dsc | 165 +++++++++++++++++++++ Platform/StMMRpmb/PlatformStandaloneMm.fdf | 111 ++++++++++++++ 2 files changed, 276 insertions(+) create mode 100644 Platform/StMMRpmb/PlatformStandaloneMm.dsc create mode 100644 Platform/StMMRpmb/PlatformStandaloneMm.fdf diff --git a/Platform/StMMRpmb/PlatformStandaloneMm.dsc b/Platform/StMMRpmb= /PlatformStandaloneMm.dsc new file mode 100644 index 000000000000..1f1ddf968c1f --- /dev/null +++ b/Platform/StMMRpmb/PlatformStandaloneMm.dsc @@ -0,0 +1,165 @@ +#=0D +# Copyright (c) 2018, ARM Limited. All rights reserved.=0D +# Copyright (c) 2020, Linaro Ltd. All rights reserved.=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +=0D +##########################################################################= ######=0D +#=0D +# Defines Section - statements that will be processed to create a Makefile= .=0D +#=0D +##########################################################################= ######=0D +[Defines]=0D + PLATFORM_NAME =3D MmStandaloneRpmb=0D + PLATFORM_GUID =3D A27A486E-D7B9-4D70-9F37-FED9ABE041A2= =0D + PLATFORM_VERSION =3D 1.0=0D + DSC_SPECIFICATION =3D 0x00010011=0D + OUTPUT_DIRECTORY =3D Build/$(PLATFORM_NAME)=0D + SUPPORTED_ARCHITECTURES =3D AARCH64=0D + BUILD_TARGETS =3D DEBUG|RELEASE|NOOPT=0D + SKUID_IDENTIFIER =3D DEFAULT=0D + FLASH_DEFINITION =3D Platform/StMMRpmb/PlatformStandaloneM= m.fdf=0D + DEFINE DEBUG_MESSAGE =3D TRUE=0D +=0D + # LzmaF86=0D + DEFINE COMPRESSION_TOOL_GUID =3D D42AE6BD-1352-4bfb-909A-CA72A6EAE889= =0D +=0D +##########################################################################= ######=0D +#=0D +# Library Class section - list of all Library Classes needed by this Platf= orm.=0D +#=0D +##########################################################################= ######=0D +[LibraryClasses]=0D + ArmSvcLib|ArmPkg/Library/ArmSvcLib/ArmSvcLib.inf=0D + ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf=0D + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf=0D + SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf=0D + VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/Var= iablePolicyHelperLib.inf=0D + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf=0D + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseD= ebugPrintErrorLevelLib.inf=0D + ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib= /PrePiExtractGuidedSectionLib.inf=0D + FvLib|StandaloneMmPkg/Library/FvLib/FvLib.inf=0D + HobLib|StandaloneMmPkg/Library/StandaloneMmCoreHobLib/StandaloneMmCoreHo= bLib.inf=0D + IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf=0D + MemLib|StandaloneMmPkg/Library/StandaloneMmMemLib/StandaloneMmMemLib.inf= =0D + MemoryAllocationLib|StandaloneMmPkg/Library/StandaloneMmCoreMemoryAlloca= tionLib/StandaloneMmCoreMemoryAllocationLib.inf=0D + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf=0D + PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf=0D + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf=0D + VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolicyL= ib.inf=0D + ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseRepor= tStatusCodeLibNull.inf=0D +=0D + #=0D + # Entry point=0D + #=0D + StandaloneMmCoreEntryPoint|StandaloneMmPkg/Library/StandaloneMmCoreEntry= Point/StandaloneMmCoreEntryPoint.inf=0D + StandaloneMmDriverEntryPoint|MdePkg/Library/StandaloneMmDriverEntryPoint= /StandaloneMmDriverEntryPoint.inf=0D +=0D + StandaloneMmMmuLib|ArmPkg/Library/StandaloneMmMmuLib/ArmMmuStandaloneMmL= ib.inf=0D + CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLibNull/BaseCache= MaintenanceLibNull.inf=0D + PeCoffExtraActionLib|StandaloneMmPkg/Library/StandaloneMmPeCoffExtraActi= onLib/StandaloneMmPeCoffExtraActionLib.inf=0D + RngLib|MdePkg/Library/BaseRngLibNull/BaseRngLibNull.inf=0D +=0D + SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull= .inf=0D + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf=0D +=0D + #=0D + # It is not possible to prevent the ARM compiler for generic intrinsic f= unctions.=0D + # This library provides the intrinsic functions generate by a given comp= iler.=0D + # NULL means link this library into all ARM images.=0D + #=0D + NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf=0D +=0D +[LibraryClasses.common.MM_STANDALONE]=0D + HobLib|StandaloneMmPkg/Library/StandaloneMmHobLib/StandaloneMmHobLib.inf= =0D + MmServicesTableLib|MdePkg/Library/StandaloneMmServicesTableLib/Standalon= eMmServicesTableLib.inf=0D + MemoryAllocationLib|StandaloneMmPkg/Library/StandaloneMmMemoryAllocation= Lib/StandaloneMmMemoryAllocationLib.inf=0D +=0D + IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf=0D + OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf=0D + PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecu= reLibNull.inf=0D + SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchroniza= tionLib.inf=0D + TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplat= e.inf=0D +##########################################################################= ######=0D +#=0D +# Pcd Section - list of all EDK II PCD Entries defined by this Platform=0D +#=0D +##########################################################################= ######=0D +=0D +[PcdsFeatureFlag.common]=0D + gArmTokenSpaceGuid.PcdFfaEnable|TRUE=0D +=0D +[PcdsFixedAtBuild]=0D + gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x800000CF=0D + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0xff=0D + gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x0f=0D +=0D + gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler|0x2=0D + # Secure Storage=0D + gEfiSecurityPkgTokenSpaceGuid.PcdUserPhysicalPresence|TRUE=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800=0D +=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00004000= =0D + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x0000400= 0=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x00004000= =0D + gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x00004000=0D +=0D +[PcdsPatchableInModule]=0D + # Allocated memory for EDK2 uppers layers=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64|0x0=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64|0x0=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64|0x0=0D +=0D +##########################################################################= #########################=0D +#=0D +# Components Section - list of the modules and components that will be pro= cessed by compilation=0D +# tools and the EDK II tools to generate PE32/PE32+/C= off image files.=0D +#=0D +# Note: The EDK II DSC file is not used to specify how compiled binary ima= ges get placed=0D +# into firmware volume images. This section is just a list of module= s to compile from=0D +# source into UEFI-compliant binaries.=0D +# It is the FDF file that contains information on combining binary f= iles into firmware=0D +# volume images, whose concept is beyond UEFI and is described in PI= specification.=0D +# Binary modules do not need to be listed in this section, as they s= hould be=0D +# specified in the FDF file. For example: Shell binary (Shell_Full.e= fi), FAT binary (Fat.efi),=0D +# Logo (Logo.bmp), and etc.=0D +# There may also be modules listed in this section that are not requ= ired in the FDF file,=0D +# When a module listed here is excluded from FDF file, then UEFI-com= pliant binary will be=0D +# generated for it, but the binary will not be put into any firmware= volume.=0D +#=0D +##########################################################################= #########################=0D +[Components.common]=0D + #=0D + # Standalone MM components=0D + #=0D + Drivers/OpTeeRpmb/OpTeeRpmbFv.inf=0D + StandaloneMmPkg/Core/StandaloneMmCore.inf=0D + StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.inf=0D + MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandalon= eMm.inf {=0D + =0D + NULL|Drivers/OpTeeRpmb/FixupPcd.inf=0D + }=0D + MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf {=0D + =0D + AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.= inf=0D + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf=0D + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf= =0D + VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf=0D + NULL|MdeModulePkg/Library/VarCheckUefiLib/VarCheckUefiLib.inf=0D + NULL|Drivers/OpTeeRpmb/FixupPcd.inf=0D + }=0D +=0D +##########################################################################= #########################=0D +#=0D +# BuildOptions Section - Define the module specific tool chain flags that = should be used as=0D +# the default flags for a module. These flags are a= ppended to any=0D +# standard flags that are defined by the build proc= ess. They can be=0D +# applied for any modules or only those modules wit= h the specific=0D +# module style (EDK or EDKII) specified in [Compone= nts] section.=0D +#=0D +##########################################################################= #########################=0D +[BuildOptions.AARCH64]=0D +GCC:*_*_*_DLINK_FLAGS =3D -z common-page-size=3D0x1000 -march=3Darmv8-a+no= fp=0D +GCC:*_*_*_CC_FLAGS =3D -mstrict-align=0D diff --git a/Platform/StMMRpmb/PlatformStandaloneMm.fdf b/Platform/StMMRpmb= /PlatformStandaloneMm.fdf new file mode 100644 index 000000000000..febc6d0d959b --- /dev/null +++ b/Platform/StMMRpmb/PlatformStandaloneMm.fdf @@ -0,0 +1,111 @@ +#=0D +# Copyright (c) 2018, ARM Limited. All rights reserved.=0D +# Copyright (c) 2020, Linaro Ltd. All rights reserved.=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +=0D +##########################################################################= ######=0D +#=0D +# FD Section=0D +# The [FD] Section is made up of the definition statements and a=0D +# description of what goes into the Flash Device Image. Each FD section= =0D +# defines one flash "device" image. A flash device image may be one of=0D +# the following: Removable media bootable image (like a boot floppy=0D +# image,) an Option ROM image (that would be "flashed" into an add-in=0D +# card,) a System "Flash" image (that would be burned into a system's=0D +# flash) or an Update ("Capsule") image that will be used to update and=0D +# existing system flash.=0D +#=0D +##########################################################################= ######=0D +=0D +[FD.BL32_AP_MM]=0D +BaseAddress =3D 0x1000 # any address apart from 0x0=0D +Size =3D 0x00300000=0D +ErasePolarity =3D 1=0D +=0D +BlockSize =3D 0x00001000=0D +NumBlocks =3D 0x0300=0D +=0D +##########################################################################= ######=0D +#=0D +# Following are lists of FD Region layout which correspond to the location= s of different=0D +# images within the flash device.=0D +#=0D +# Regions must be defined in ascending order and may not overlap.=0D +#=0D +# A Layout Region start with a eight digit hex offset (leading "0x" requir= ed) followed by=0D +# the pipe "|" character, followed by the size of the region, also in hex = with the leading=0D +# "0x" characters. Like:=0D +# Offset|Size=0D +# PcdOffsetCName|PcdSizeCName=0D +# RegionType =0D +#=0D +##########################################################################= ######=0D +=0D +0x00000000|0x00280000=0D +FV =3D FVMAIN_COMPACT=0D +=0D +[FV.FVMAIN_COMPACT]=0D +FvAlignment =3D 8=0D +ERASE_POLARITY =3D 1=0D +MEMORY_MAPPED =3D TRUE=0D +STICKY_WRITE =3D TRUE=0D +LOCK_CAP =3D TRUE=0D +LOCK_STATUS =3D TRUE=0D +WRITE_DISABLED_CAP =3D TRUE=0D +WRITE_ENABLED_CAP =3D TRUE=0D +WRITE_STATUS =3D TRUE=0D +WRITE_LOCK_CAP =3D TRUE=0D +WRITE_LOCK_STATUS =3D TRUE=0D +READ_DISABLED_CAP =3D TRUE=0D +READ_ENABLED_CAP =3D TRUE=0D +READ_STATUS =3D TRUE=0D +READ_LOCK_CAP =3D TRUE=0D +READ_LOCK_STATUS =3D TRUE=0D +=0D + INF StandaloneMmPkg/Core/StandaloneMmCore.inf=0D + INF Drivers/OpTeeRpmb/OpTeeRpmbFv.inf=0D + INF MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStand= aloneMm.inf=0D + INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf= =0D + INF StandaloneMmPkg/Drivers/StandaloneMmCpu/AArch64/StandaloneMmCpu.inf= =0D +##########################################################################= ######=0D +#=0D +# Rules are use with the [FV] section's module INF type to define=0D +# how an FFS file is created for a given INF file. The following Rule are = the default=0D +# rules for the different module type. User can add the customized rules t= o define the=0D +# content of the FFS file.=0D +#=0D +##########################################################################= ######=0D +=0D +=0D +##########################################################################= ##=0D +# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section = #=0D +##########################################################################= ##=0D +#=0D +#[Rule.Common.DXE_DRIVER]=0D +# FILE DRIVER =3D $(NAMED_GUID) {=0D +# DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_= NAME).depex=0D +# COMPRESS PI_STD {=0D +# GUIDED {=0D +# PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi= =0D +# UI STRING=3D"$(MODULE_NAME)" Optional=0D +# VERSION STRING=3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_N= UMBER)=0D +# }=0D +# }=0D +# }=0D +#=0D +##########################################################################= ##=0D +=0D +[Rule.Common.MM_CORE_STANDALONE]=0D + FILE SEC =3D $(NAMED_GUID) FIXED {=0D + PE32 PE32 Align =3D Auto $(INF_OUTPUT)/$(MODULE_NAME).efi= =0D + }=0D +=0D +[Rule.Common.MM_STANDALONE]=0D + FILE MM_STANDALONE =3D $(NAMED_GUID) {=0D + SMM_DEPEX SMM_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex= =0D + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi=0D + UI STRING=3D"$(MODULE_NAME)" Optional=0D + VERSION STRING=3D"$(INF_VERSION)" Optional BUILD_NUM=3D$(BUILD_NUMBE= R)=0D + }=0D --=20 2.30.0