From: Jagadeesh Ujja <jagadeesh.ujja@arm.com>
To: edk2-devel@lists.01.org
Subject: [RFC PATCH 2/9] ArmPlatformPkg/NorFlashDxe: allow reusability as a MM driver
Date: Wed, 31 Oct 2018 16:39:40 +0530 [thread overview]
Message-ID: <20181031110947.6305-3-jagadeesh.ujja@arm.com> (raw)
In-Reply-To: <20181031110947.6305-1-jagadeesh.ujja@arm.com>
Adapt the NorFlashDxe driver to be used as a MM_STANDALONE driver to
allow access to NOR flash for code executing in MM_STANDALONE mode.
This allows storing of EFI variables on NOR flash which is accessible
only via the MM STANDALONE mode software.
Change-Id: I289f439f6710cf53dfe073e1776dd4f438dff3d4
Signed-off-by: Jagadeesh Ujja <jagadeesh.ujja@arm.com>
---
.../Drivers/NorFlashDxe/NorFlashBlockIoDxe.c | 5 +-
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c | 116 ++++++++++++++++++---
ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h | 15 ++-
.../Drivers/NorFlashDxe/NorFlashFvbDxe.c | 26 +++--
.../Drivers/NorFlashDxe/NorFlashMmStandalone.inf | 76 ++++++++++++++
5 files changed, 214 insertions(+), 24 deletions(-)
create mode 100644 ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashMmStandalone.inf
diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c
index 279b77c..38363a4 100644
--- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c
+++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashBlockIoDxe.c
@@ -1,6 +1,6 @@
/** @file NorFlashBlockIoDxe.c
- Copyright (c) 2011-2013, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2011-2018, ARM Ltd. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -13,8 +13,9 @@
**/
#include <Library/BaseMemoryLib.h>
+#ifndef MM_STANDALONE
#include <Library/UefiBootServicesTableLib.h>
-
+#endif
#include "NorFlashDxe.h"
//
diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
index 46e815b..eb8ae4e 100644
--- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
+++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.c
@@ -1,6 +1,6 @@
/** @file NorFlashDxe.c
- Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2011 - 2018, ARM Ltd. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -15,12 +15,16 @@
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
#include <Library/PcdLib.h>
-
+#ifndef MM_STANDALONE
+#include <Library/UefiBootServicesTableLib.h>
+#endif
#include "NorFlashDxe.h"
-
+#ifndef MM_STANDALONE
STATIC EFI_EVENT mNorFlashVirtualAddrChangeEvent;
+#else
+EFI_MM_SYSTEM_TABLE *mMmst = NULL;
+#endif
//
// Global variable declarations
@@ -134,7 +138,7 @@ NorFlashCreateInstance (
if (SupportFvb) {
NorFlashFvbInitialize (Instance);
-
+#ifndef MM_STANDALONE
Status = gBS->InstallMultipleProtocolInterfaces (
&Instance->Handle,
&gEfiDevicePathProtocolGuid, &Instance->DevicePath,
@@ -146,7 +150,44 @@ NorFlashCreateInstance (
FreePool (Instance);
return Status;
}
+#else
+ //Install DevicePath Protocol
+ Status = mMmst->MmInstallProtocolInterface (
+ &Instance->Handle,
+ &gEfiDevicePathProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &Instance->DevicePath
+ );
+ if (EFI_ERROR(Status)) {
+ FreePool (Instance);
+ return Status;
+ }
+ //Install BlockIo Protocol
+ Status = mMmst->MmInstallProtocolInterface (
+ &Instance->Handle,
+ &gEfiBlockIoProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &Instance->BlockIoProtocol
+ );
+ if (EFI_ERROR(Status)) {
+ FreePool (Instance);
+ return Status;
+ }
+
+ //Install FirmwareVolumeBlock Protocol
+ Status = mMmst->MmInstallProtocolInterface (
+ &Instance->Handle,
+ &gEfiSmmFirmwareVolumeBlockProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &Instance->FvbProtocol
+ );
+ if (EFI_ERROR(Status)) {
+ FreePool (Instance);
+ return Status;
+ }
+#endif
} else {
+#ifndef MM_STANDALONE
Status = gBS->InstallMultipleProtocolInterfaces (
&Instance->Handle,
&gEfiDevicePathProtocolGuid, &Instance->DevicePath,
@@ -158,6 +199,42 @@ NorFlashCreateInstance (
FreePool (Instance);
return Status;
}
+#else
+ //Install DevicePath Protocol
+ Status = mMmst->MmInstallProtocolInterface (
+ &Instance->Handle,
+ &gEfiDevicePathProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &Instance->DevicePath
+ );
+ if (EFI_ERROR(Status)) {
+ FreePool (Instance);
+ return Status;
+ }
+ //Install BlockIo Protocol
+ Status = mMmst->MmInstallProtocolInterface (
+ &Instance->Handle,
+ &gEfiBlockIoProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &Instance->BlockIoProtocol
+ );
+ if (EFI_ERROR(Status)) {
+ FreePool (Instance);
+ return Status;
+ }
+
+ //Install DiskIO Protocol
+ Status = mMmst->MmInstallProtocolInterface (
+ &Instance->Handle,
+ &gEfiDiskIoProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &Instance->DiskIoProtocol
+ );
+ if (EFI_ERROR(Status)) {
+ FreePool (Instance);
+ return Status;
+ }
+#endif
}
*NorFlashInstance = Instance;
@@ -336,6 +413,7 @@ NorFlashUnlockAndEraseSingleBlock (
{
EFI_STATUS Status;
UINTN Index;
+#ifndef MM_STANDALONE
EFI_TPL OriginalTPL;
if (!EfiAtRuntime ()) {
@@ -346,7 +424,7 @@ NorFlashUnlockAndEraseSingleBlock (
// use of uninitialized variables
OriginalTPL = TPL_HIGH_LEVEL;
}
-
+#endif
Index = 0;
// The block erase might fail a first time (SW bug ?). Retry it ...
do {
@@ -363,11 +441,12 @@ NorFlashUnlockAndEraseSingleBlock (
DEBUG((EFI_D_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress,Index));
}
+#ifndef MM_STANDALONE
if (!EfiAtRuntime ()) {
// Interruptions can resume.
gBS->RestoreTPL (OriginalTPL);
}
-
+#endif
return Status;
}
@@ -580,7 +659,9 @@ NorFlashWriteFullBlock (
UINTN BlockAddress;
UINTN BuffersInBlock;
UINTN RemainingWords;
+#ifndef MM_STANDALONE
EFI_TPL OriginalTPL;
+#endif
UINTN Cnt;
Status = EFI_SUCCESS;
@@ -590,7 +671,7 @@ NorFlashWriteFullBlock (
// Start writing from the first address at the start of the block
WordAddress = BlockAddress;
-
+#ifndef MM_STANDALONE
if (!EfiAtRuntime ()) {
// Raise TPL to TPL_HIGH to stop anyone from interrupting us.
OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
@@ -599,7 +680,7 @@ NorFlashWriteFullBlock (
// use of uninitialized variables
OriginalTPL = TPL_HIGH_LEVEL;
}
-
+#endif
Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress));
@@ -657,11 +738,12 @@ NorFlashWriteFullBlock (
}
EXIT:
+#ifndef MM_STANDALONE
if (!EfiAtRuntime ()) {
// Interruptions can resume.
gBS->RestoreTPL (OriginalTPL);
}
-
+#endif
if (EFI_ERROR(Status)) {
DEBUG((EFI_D_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));
}
@@ -1243,6 +1325,7 @@ NorFlashVirtualNotifyEvent (
IN VOID *Context
)
{
+#ifndef MM_STANDALONE
UINTN Index;
for (Index = 0; Index < mNorFlashDeviceCount; Index++) {
@@ -1268,7 +1351,7 @@ NorFlashVirtualNotifyEvent (
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->ShadowBuffer);
}
}
-
+#endif
return;
}
@@ -1276,13 +1359,20 @@ EFI_STATUS
EFIAPI
NorFlashInitialise (
IN EFI_HANDLE ImageHandle,
+#ifndef MM_STANDALONE
IN EFI_SYSTEM_TABLE *SystemTable
+#else
+ IN EFI_MM_SYSTEM_TABLE *SystemTable
+#endif
)
{
EFI_STATUS Status;
UINT32 Index;
NOR_FLASH_DESCRIPTION* NorFlashDevices;
BOOLEAN ContainVariableStorage;
+#ifdef MM_STANDALONE
+ mMmst = SystemTable;
+#endif
Status = NorFlashPlatformInitialization ();
if (EFI_ERROR(Status)) {
@@ -1318,7 +1408,7 @@ NorFlashInitialise (
DEBUG((EFI_D_ERROR,"NorFlashInitialise: Fail to create instance for NorFlash[%d]\n",Index));
}
}
-
+#ifndef MM_STANDALONE
//
// Register for the virtual address change event
//
@@ -1331,6 +1421,6 @@ NorFlashInitialise (
&mNorFlashVirtualAddrChangeEvent
);
ASSERT_EFI_ERROR (Status);
-
+#endif
return Status;
}
diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h
index 5c07694..2dc19ad 100644
--- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h
+++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashDxe.h
@@ -1,6 +1,6 @@
/** @file NorFlashDxe.h
- Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2011 - 2018, ARM Ltd. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -17,8 +17,11 @@
#include <Base.h>
+#ifndef MM_STANDALONE
#include <PiDxe.h>
-
+#else
+#include <PiMm.h>
+#endif
#include <Guid/EventGroup.h>
#include <Protocol/BlockIo.h>
@@ -28,8 +31,16 @@
#include <Library/DebugLib.h>
#include <Library/IoLib.h>
#include <Library/NorFlashPlatformLib.h>
+#ifndef MM_STANDALONE
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeLib.h>
+#else
+#include <Library/StandaloneMmCoreEntryPoint.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/SmmMemLib.h>
+#endif
#define NOR_FLASH_ERASE_RETRY 10
diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
index e62ffbb..dae0e55 100644
--- a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
+++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashFvbDxe.c
@@ -1,6 +1,6 @@
/*++ @file NorFlashFvbDxe.c
- Copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2011 - 2018, ARM Ltd. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
@@ -12,7 +12,11 @@
--*/
+#ifndef MM_STANDALONE
#include <PiDxe.h>
+#else
+#include <PiMm.h>
+#endif
#include <Library/PcdLib.h>
#include <Library/BaseLib.h>
@@ -20,16 +24,21 @@
#include <Library/UefiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
+#ifndef MM_STANDALONE
#include <Library/DxeServicesTableLib.h>
#include <Library/UefiBootServicesTableLib.h>
-
+#else
+#include <Library/StandaloneMmCoreEntryPoint.h>
+#endif
#include <Guid/VariableFormat.h>
#include <Guid/SystemNvDataGuid.h>
#include <Guid/NvVarStoreFormatted.h>
#include "NorFlashDxe.h"
+#ifndef MM_STANDALONE
STATIC EFI_EVENT mFvbVirtualAddrChangeEvent;
+#endif
STATIC UINTN mFlashNvStorageVariableBase;
///
@@ -702,7 +711,9 @@ FvbVirtualNotifyEvent (
IN VOID *Context
)
{
+#ifndef MM_STANDALONE
EfiConvertPointer (0x0, (VOID**)&mFlashNvStorageVariableBase);
+#endif
return;
}
@@ -715,11 +726,12 @@ NorFlashFvbInitialize (
EFI_STATUS Status;
UINT32 FvbNumLba;
EFI_BOOT_MODE BootMode;
+#ifndef MM_STANDALONE
UINTN RuntimeMmioRegionSize;
-
+#endif
DEBUG((DEBUG_BLKIO,"NorFlashFvbInitialize\n"));
ASSERT((Instance != NULL));
-
+#ifndef MM_STANDALONE
//
// Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME
//
@@ -741,7 +753,7 @@ NorFlashFvbInitialize (
Instance->DeviceBaseAddress, RuntimeMmioRegionSize,
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);
ASSERT_EFI_ERROR (Status);
-
+#endif
mFlashNvStorageVariableBase = FixedPcdGet32 (PcdFlashNvStorageVariableBase);
// Set the index of the first LBA for the FVB
@@ -776,7 +788,7 @@ NorFlashFvbInitialize (
return Status;
}
}
-
+#ifndef MM_STANDALONE
//
// The driver implementing the variable read service can now be dispatched;
// the varstore headers are in place.
@@ -801,6 +813,6 @@ NorFlashFvbInitialize (
&mFvbVirtualAddrChangeEvent
);
ASSERT_EFI_ERROR (Status);
-
+#endif
return Status;
}
diff --git a/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashMmStandalone.inf b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashMmStandalone.inf
new file mode 100644
index 0000000..abf221c
--- /dev/null
+++ b/ArmPlatformPkg/Drivers/NorFlashDxe/NorFlashMmStandalone.inf
@@ -0,0 +1,76 @@
+#/** @file
+#
+# Component description file for NorFlashDxe module
+#
+# Copyright (c) 2018, ARM Limited. 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 = 0x00010005
+ BASE_NAME = StandaloneMmNorFlash
+ FILE_GUID = 166F677B-DAC9-4AE4-AD34-2FF2504B0637
+ MODULE_TYPE = MM_STANDALONE
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x00010032
+ ENTRY_POINT = NorFlashInitialise
+
+[Sources.common]
+ NorFlashDxe.c
+ NorFlashFvbDxe.c
+ NorFlashBlockIoDxe.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ ArmPlatformPkg/ArmPlatformPkg.dec
+ EmbeddedPkg/EmbeddedPkg.dec
+ ArmPkg/ArmPkg.dec
+ edk2-platforms/Platform/ARM/ARM.dec
+ StandaloneMmPkg/StandaloneMmPkg.dec
+
+[LibraryClasses]
+ StandaloneMmDriverEntryPoint
+ BaseMemoryLib
+ ArmSvcLib
+ ArmLib
+ IoLib
+ BaseLib
+ DebugLib
+ HobLib
+ MemoryAllocationLib
+ NorFlashPlatformLib
+
+[Guids]
+ gEfiSystemNvDataFvGuid
+ gEfiVariableGuid
+ gEfiAuthenticatedVariableGuid
+ gEfiEventVirtualAddressChangeGuid
+ gEdkiiNvVarStoreFormattedGuid ## PRODUCES ## PROTOCOL
+
+[Protocols]
+ gEfiBlockIoProtocolGuid
+ gEfiDevicePathProtocolGuid
+ gEfiSmmFirmwareVolumeBlockProtocolGuid
+ gEfiDiskIoProtocolGuid
+
+[Pcd.common]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
+
+ gArmPlatformTokenSpaceGuid.PcdNorFlashCheckBlockLocked
+
+[Depex]
+ TRUE
--
1.9.1
next prev parent reply other threads:[~2018-10-31 11:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-31 11:09 [RFC PATCH 0/9] Extend secure variable service to be usable from Standalone MM Jagadeesh Ujja
2018-10-31 11:09 ` [RFC PATCH 1/9] StandaloneMmPkg: Pull in additonal libraries from staging branch Jagadeesh Ujja
2018-10-31 11:09 ` Jagadeesh Ujja [this message]
2018-10-31 11:09 ` [RFC PATCH 3/9] MdeModulePkg/FaultTolerantWriteDxe: allow reusability as a MM driver Jagadeesh Ujja
2018-10-31 11:09 ` [RFC PATCH 4/9] MdeModulePkg/Variable/RuntimeDxe: adapt for usability with MM Standalone Jagadeesh Ujja
2018-10-31 11:09 ` [RFC PATCH 5/9] MdeModulePkg/Variable/RuntimeDxe: adapt as a MM Standalone driver Jagadeesh Ujja
2018-10-31 11:09 ` [RFC PATCH 6/9] CryptoPkg/BaseCryptLib: Hack to get time in MM Standalone mode Jagadeesh Ujja
2018-10-31 11:09 ` [RFC PATCH 7/9] SecurityPkg/AuthVariableLib:allow reusability as MM_STANDALONE Jagadeesh Ujja
2018-11-09 6:04 ` Zhang, Chao B
2018-10-31 11:09 ` [RFC PATCH 8/9] MdeModulePkg VarCheckLib: allow " Jagadeesh Ujja
2018-10-31 11:09 ` [RFC PATCH 9/9] CryptoPkg/BaseCryptLib: allow MM_STANDALONE drivers to use this library Jagadeesh Ujja
2018-10-31 13:58 ` [RFC PATCH 0/9] Extend secure variable service to be usable from Standalone MM Gao, Liming
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181031110947.6305-3-jagadeesh.ujja@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox