* [PATCH v4 1/4] MdeModulePkg/CapsuleRuntimeDxe: clean the capsule payload to DRAM
2018-06-13 8:08 [PATCH v4 0/4] MdeModulePkg ArmPkg: support for persistent capsules and progress reporting Ard Biesheuvel
@ 2018-06-13 8:08 ` Ard Biesheuvel
2018-06-14 0:54 ` Zeng, Star
2018-06-13 8:08 ` [PATCH v4 2/4] MdeModulePkg/DxeCapsuleLibFmp: pass progress callback only if it works Ard Biesheuvel
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Ard Biesheuvel @ 2018-06-13 8:08 UTC (permalink / raw)
To: edk2-devel
Cc: leif.lindholm, star.zeng, jiewen.yao, michael.d.kinney,
Ard Biesheuvel
When capsule updates are staged for processing after a warm reboot,
they are copied into memory with the MMU and caches enabled. When
the capsule PEI gets around to coalescing the capsule, the MMU and
caches may still be disabled, and so on architectures where uncached
accesses are incoherent with the caches (such as ARM and AARCH64),
we need to ensure that the data passed into UpdateCapsule() is
written back to main memory before performing the warm reboot.
Unfortunately, on ARM, the only type of cache maintenance instructions
that are suitable for this purpose operate on virtual addresses only,
and given that the UpdateCapsule() prototype includes the physical
address of a linked list of scatter/gather data structures that are
mapped at an address that is unknown to the firmware (and may not even
be mapped at all when UpdateCapsule() is invoked), we can only perform
this cache maintenance at boot time. Fortunately, both Windows and Linux
only invoke UpdateCapsule() before calling ExitBootServices(), so this
is not a problem in practice.
In the future, we may propose adding a secure firmware service that
permits performing the cache maintenance at OS runtime, in which case
this code may be enhanced to call that service if available. For now,
we just fail any UpdateCapsule() calls performed at OS runtime on ARM.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c | 77 ++++++++++++++++++++
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c | 51 +++++++++++++
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf | 14 +++-
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c | 33 ++-------
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h | 73 +++++++++++++++++++
5 files changed, 219 insertions(+), 29 deletions(-)
diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c b/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c
new file mode 100644
index 000000000000..7e0ca06ce7d0
--- /dev/null
+++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c
@@ -0,0 +1,77 @@
+ /** @file
+ ARM implementation of architecture specific routines related to
+ PersistAcrossReset capsules
+
+ Copyright (c) 2018, Linaro, 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 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 "CapsuleService.h"
+
+#include <Library/CacheMaintenanceLib.h>
+
+/**
+ Whether the platform supports capsules that persist across reset. Note that
+ some platforms only support such capsules at boot time.
+
+ @return TRUE if a PersistAcrossReset capsule may be passed to UpdateCapsule()
+ at this time
+ FALSE otherwise
+**/
+BOOLEAN
+EFIAPI
+IsPersistAcrossResetCapsuleSupported (
+ VOID
+ )
+{
+ //
+ // ARM requires the capsule payload to be cleaned to the point of coherency
+ // (PoC), but only permits doing so using cache maintenance instructions that
+ // operate on virtual addresses. Since at runtime, we don't know the virtual
+ // addresses of the data structures that make up the scatter/gather list, we
+ // cannot perform the maintenance, and all we can do is give up.
+ //
+ return FeaturePcdGet (PcdSupportUpdateCapsuleReset) && !EfiAtRuntime ();
+}
+
+/**
+ Writes Back a range of data cache lines covering a set of capsules in memory.
+
+ Writes Back the data cache lines specified by ScatterGatherList.
+
+ @param ScatterGatherList Physical address of the data structure that
+ describes a set of capsules in memory
+
+**/
+VOID
+EFIAPI
+CapsuleCacheWriteBack (
+ IN EFI_PHYSICAL_ADDRESS ScatterGatherList
+ )
+{
+ EFI_CAPSULE_BLOCK_DESCRIPTOR *Desc;
+
+ Desc = (EFI_CAPSULE_BLOCK_DESCRIPTOR *)(UINTN)ScatterGatherList;
+ do {
+ WriteBackDataCacheRange (Desc, sizeof *Desc);
+
+ if (Desc->Length > 0) {
+ WriteBackDataCacheRange ((VOID *)(UINTN)Desc->Union.DataBlock,
+ Desc->Length
+ );
+ Desc++;
+ } else if (Desc->Union.ContinuationPointer > 0) {
+ Desc = (EFI_CAPSULE_BLOCK_DESCRIPTOR *)(UINTN)Desc->Union.ContinuationPointer;
+ }
+ } while (Desc->Length > 0 || Desc->Union.ContinuationPointer > 0);
+
+ WriteBackDataCacheRange (Desc, sizeof *Desc);
+}
diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c
new file mode 100644
index 000000000000..09616999e3f8
--- /dev/null
+++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c
@@ -0,0 +1,51 @@
+/** @file
+ Default implementation of architecture specific routines related to
+ PersistAcrossReset capsules
+
+ Copyright (c) 2018, Linaro, 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 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 "CapsuleService.h"
+
+/**
+ Whether the platform supports capsules that persist across reset. Note that
+ some platforms only support such capsules at boot time.
+
+ @return TRUE if a PersistAcrossReset capsule may be passed to UpdateCapsule()
+ at this time
+ FALSE otherwise
+**/
+BOOLEAN
+EFIAPI
+IsPersistAcrossResetCapsuleSupported (
+ VOID
+ )
+{
+ return FeaturePcdGet (PcdSupportUpdateCapsuleReset);
+}
+
+/**
+ Writes Back a range of data cache lines covering a set of capsules in memory.
+
+ Writes Back the data cache lines specified by ScatterGatherList.
+
+ @param ScatterGatherList Physical address of the data structure that
+ describes a set of capsules in memory
+
+**/
+VOID
+EFIAPI
+CapsuleCacheWriteBack (
+ IN EFI_PHYSICAL_ADDRESS ScatterGatherList
+ )
+{
+}
diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
index 9ab04ce1b301..43a29ee22948 100644
--- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
@@ -27,17 +27,24 @@ [Defines]
#
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC ARM AARCH64
#
[Sources]
CapsuleService.c
+ CapsuleService.h
-[Sources.Ia32, Sources.IPF, Sources.EBC, Sources.ARM, Sources.AARCH64]
+[Sources.Ia32, Sources.IPF, Sources.EBC]
SaveLongModeContext.c
+ CapsuleReset.c
[Sources.X64]
X64/SaveLongModeContext.c
+ CapsuleReset.c
+
+[Sources.ARM, Sources.AARCH64]
+ SaveLongModeContext.c
+ Arm/CapsuleReset.c
[Packages]
MdePkg/MdePkg.dec
@@ -59,6 +66,9 @@ [LibraryClasses.X64]
UefiLib
BaseMemoryLib
+[LibraryClasses.ARM, LibraryClasses.AARCH64]
+ CacheMaintenanceLib
+
[Guids]
## SOMETIMES_PRODUCES ## Variable:L"CapsuleUpdateData" # (Process across reset capsule image) for capsule updated data
## SOMETIMES_PRODUCES ## Variable:L"CapsuleLongModeBuffer" # The long mode buffer used by IA32 Capsule PEIM to call X64 CapsuleCoalesce code to handle >4GB capsule blocks
diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
index 216798d1617e..23fd6d59c59e 100644
--- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
+++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
@@ -15,22 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
-#include <Uefi.h>
-
-#include <Protocol/Capsule.h>
-#include <Guid/CapsuleVendor.h>
-#include <Guid/FmpCapsule.h>
-
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-#include <Library/CapsuleLib.h>
-#include <Library/UefiDriverEntryPoint.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/UefiRuntimeLib.h>
-#include <Library/BaseLib.h>
-#include <Library/PrintLib.h>
-#include <Library/BaseMemoryLib.h>
+#include "CapsuleService.h"
+
//
// Handle for the installation of Capsule Architecture Protocol.
//
@@ -44,15 +30,6 @@ UINTN mTimes = 0;
UINT32 mMaxSizePopulateCapsule = 0;
UINT32 mMaxSizeNonPopulateCapsule = 0;
-/**
- Create the variable to save the base address of page table and stack
- for transferring into long mode in IA32 PEI.
-**/
-VOID
-SaveLongModeContext (
- VOID
- );
-
/**
Passes capsules to the firmware with both virtual and physical mapping. Depending on the intended
consumption, the firmware may process the capsule immediately. If the payload should persist
@@ -194,10 +171,12 @@ UpdateCapsule (
//
// Check if the platform supports update capsule across a system reset
//
- if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {
+ if (!IsPersistAcrossResetCapsuleSupported ()) {
return EFI_UNSUPPORTED;
}
+ CapsuleCacheWriteBack (ScatterGatherList);
+
//
// Construct variable name CapsuleUpdateData, CapsuleUpdateData1, CapsuleUpdateData2...
// if user calls UpdateCapsule multiple times.
@@ -344,7 +323,7 @@ QueryCapsuleCapabilities (
//
//Check if the platform supports update capsule across a system reset
//
- if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {
+ if (!IsPersistAcrossResetCapsuleSupported ()) {
return EFI_UNSUPPORTED;
}
*ResetType = EfiResetWarm;
diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h
new file mode 100644
index 000000000000..85aafc144b41
--- /dev/null
+++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h
@@ -0,0 +1,73 @@
+/** @file
+ Capsule Runtime Driver produces two UEFI capsule runtime services.
+ (UpdateCapsule, QueryCapsuleCapabilities)
+ It installs the Capsule Architectural Protocol defined in PI1.0a to signify
+ the capsule runtime services are ready.
+
+ Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2018, Linaro, 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 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 <Uefi.h>
+
+#include <Protocol/Capsule.h>
+#include <Guid/CapsuleVendor.h>
+#include <Guid/FmpCapsule.h>
+
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <Library/CapsuleLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PrintLib.h>
+#include <Library/BaseMemoryLib.h>
+
+/**
+ Create the variable to save the base address of page table and stack
+ for transferring into long mode in IA32 PEI.
+**/
+VOID
+SaveLongModeContext (
+ VOID
+ );
+
+/**
+ Whether the platform supports capsules that persist across reset. Note that
+ some platforms only support such capsules at boot time.
+
+ @return TRUE if a PersistAcrossReset capsule may be passed to UpdateCapsule()
+ at this time
+ FALSE otherwise
+**/
+BOOLEAN
+EFIAPI
+IsPersistAcrossResetCapsuleSupported (
+ VOID
+ );
+
+/**
+ Writes Back a range of data cache lines covering a set of capsules in memory.
+
+ Writes Back the data cache lines specified by ScatterGatherList.
+
+ @param ScatterGatherList Physical address of the data structure that
+ describes a set of capsules in memory
+
+**/
+VOID
+EFIAPI
+CapsuleCacheWriteBack (
+ IN EFI_PHYSICAL_ADDRESS ScatterGatherList
+ );
--
2.17.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v4 1/4] MdeModulePkg/CapsuleRuntimeDxe: clean the capsule payload to DRAM
2018-06-13 8:08 ` [PATCH v4 1/4] MdeModulePkg/CapsuleRuntimeDxe: clean the capsule payload to DRAM Ard Biesheuvel
@ 2018-06-14 0:54 ` Zeng, Star
2018-06-15 10:52 ` Ard Biesheuvel
0 siblings, 1 reply; 10+ messages in thread
From: Zeng, Star @ 2018-06-14 0:54 UTC (permalink / raw)
To: Ard Biesheuvel, edk2-devel@lists.01.org
Cc: leif.lindholm@linaro.org, Yao, Jiewen, Kinney, Michael D,
Zeng, Star
With 'EFIAPI' removed from IsPersistAcrossResetCapsuleSupported and CapsuleCacheWriteBack definitions, Reviewed-by: Star Zeng <star.zeng@intel.com>.
You can wait a little more time in case Jiewen/Mike has comments.
Thanks,
Star
-----Original Message-----
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
Sent: Wednesday, June 13, 2018 4:09 PM
To: edk2-devel@lists.01.org
Cc: leif.lindholm@linaro.org; Zeng, Star <star.zeng@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH v4 1/4] MdeModulePkg/CapsuleRuntimeDxe: clean the capsule payload to DRAM
When capsule updates are staged for processing after a warm reboot, they are copied into memory with the MMU and caches enabled. When the capsule PEI gets around to coalescing the capsule, the MMU and caches may still be disabled, and so on architectures where uncached accesses are incoherent with the caches (such as ARM and AARCH64), we need to ensure that the data passed into UpdateCapsule() is written back to main memory before performing the warm reboot.
Unfortunately, on ARM, the only type of cache maintenance instructions that are suitable for this purpose operate on virtual addresses only, and given that the UpdateCapsule() prototype includes the physical address of a linked list of scatter/gather data structures that are mapped at an address that is unknown to the firmware (and may not even be mapped at all when UpdateCapsule() is invoked), we can only perform this cache maintenance at boot time. Fortunately, both Windows and Linux only invoke UpdateCapsule() before calling ExitBootServices(), so this is not a problem in practice.
In the future, we may propose adding a secure firmware service that permits performing the cache maintenance at OS runtime, in which case this code may be enhanced to call that service if available. For now, we just fail any UpdateCapsule() calls performed at OS runtime on ARM.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c | 77 ++++++++++++++++++++
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c | 51 +++++++++++++
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf | 14 +++-
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c | 33 ++-------
MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h | 73 +++++++++++++++++++
5 files changed, 219 insertions(+), 29 deletions(-)
diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c b/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c
new file mode 100644
index 000000000000..7e0ca06ce7d0
--- /dev/null
+++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c
@@ -0,0 +1,77 @@
+ /** @file
+ ARM implementation of architecture specific routines related to
+ PersistAcrossReset capsules
+
+ Copyright (c) 2018, Linaro, 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 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 "CapsuleService.h"
+
+#include <Library/CacheMaintenanceLib.h>
+
+/**
+ Whether the platform supports capsules that persist across reset.
+Note that
+ some platforms only support such capsules at boot time.
+
+ @return TRUE if a PersistAcrossReset capsule may be passed to UpdateCapsule()
+ at this time
+ FALSE otherwise
+**/
+BOOLEAN
+EFIAPI
+IsPersistAcrossResetCapsuleSupported (
+ VOID
+ )
+{
+ //
+ // ARM requires the capsule payload to be cleaned to the point of
+coherency
+ // (PoC), but only permits doing so using cache maintenance
+instructions that
+ // operate on virtual addresses. Since at runtime, we don't know the
+virtual
+ // addresses of the data structures that make up the scatter/gather
+list, we
+ // cannot perform the maintenance, and all we can do is give up.
+ //
+ return FeaturePcdGet (PcdSupportUpdateCapsuleReset) && !EfiAtRuntime
+(); }
+
+/**
+ Writes Back a range of data cache lines covering a set of capsules in memory.
+
+ Writes Back the data cache lines specified by ScatterGatherList.
+
+ @param ScatterGatherList Physical address of the data structure that
+ describes a set of capsules in memory
+
+**/
+VOID
+EFIAPI
+CapsuleCacheWriteBack (
+ IN EFI_PHYSICAL_ADDRESS ScatterGatherList
+ )
+{
+ EFI_CAPSULE_BLOCK_DESCRIPTOR *Desc;
+
+ Desc = (EFI_CAPSULE_BLOCK_DESCRIPTOR *)(UINTN)ScatterGatherList; do
+ {
+ WriteBackDataCacheRange (Desc, sizeof *Desc);
+
+ if (Desc->Length > 0) {
+ WriteBackDataCacheRange ((VOID *)(UINTN)Desc->Union.DataBlock,
+ Desc->Length
+ );
+ Desc++;
+ } else if (Desc->Union.ContinuationPointer > 0) {
+ Desc = (EFI_CAPSULE_BLOCK_DESCRIPTOR *)(UINTN)Desc->Union.ContinuationPointer;
+ }
+ } while (Desc->Length > 0 || Desc->Union.ContinuationPointer > 0);
+
+ WriteBackDataCacheRange (Desc, sizeof *Desc); }
diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c
new file mode 100644
index 000000000000..09616999e3f8
--- /dev/null
+++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c
@@ -0,0 +1,51 @@
+/** @file
+ Default implementation of architecture specific routines related to
+ PersistAcrossReset capsules
+
+ Copyright (c) 2018, Linaro, 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 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 "CapsuleService.h"
+
+/**
+ Whether the platform supports capsules that persist across reset.
+Note that
+ some platforms only support such capsules at boot time.
+
+ @return TRUE if a PersistAcrossReset capsule may be passed to UpdateCapsule()
+ at this time
+ FALSE otherwise
+**/
+BOOLEAN
+EFIAPI
+IsPersistAcrossResetCapsuleSupported (
+ VOID
+ )
+{
+ return FeaturePcdGet (PcdSupportUpdateCapsuleReset); }
+
+/**
+ Writes Back a range of data cache lines covering a set of capsules in memory.
+
+ Writes Back the data cache lines specified by ScatterGatherList.
+
+ @param ScatterGatherList Physical address of the data structure that
+ describes a set of capsules in memory
+
+**/
+VOID
+EFIAPI
+CapsuleCacheWriteBack (
+ IN EFI_PHYSICAL_ADDRESS ScatterGatherList
+ )
+{
+}
diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
index 9ab04ce1b301..43a29ee22948 100644
--- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
@@ -27,17 +27,24 @@ [Defines]
#
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC ARM AARCH64
#
[Sources]
CapsuleService.c
+ CapsuleService.h
-[Sources.Ia32, Sources.IPF, Sources.EBC, Sources.ARM, Sources.AARCH64]
+[Sources.Ia32, Sources.IPF, Sources.EBC]
SaveLongModeContext.c
+ CapsuleReset.c
[Sources.X64]
X64/SaveLongModeContext.c
+ CapsuleReset.c
+
+[Sources.ARM, Sources.AARCH64]
+ SaveLongModeContext.c
+ Arm/CapsuleReset.c
[Packages]
MdePkg/MdePkg.dec
@@ -59,6 +66,9 @@ [LibraryClasses.X64]
UefiLib
BaseMemoryLib
+[LibraryClasses.ARM, LibraryClasses.AARCH64]
+ CacheMaintenanceLib
+
[Guids]
## SOMETIMES_PRODUCES ## Variable:L"CapsuleUpdateData" # (Process across reset capsule image) for capsule updated data
## SOMETIMES_PRODUCES ## Variable:L"CapsuleLongModeBuffer" # The long mode buffer used by IA32 Capsule PEIM to call X64 CapsuleCoalesce code to handle >4GB capsule blocks
diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
index 216798d1617e..23fd6d59c59e 100644
--- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
+++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
@@ -15,22 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
-#include <Uefi.h>
-
-#include <Protocol/Capsule.h>
-#include <Guid/CapsuleVendor.h>
-#include <Guid/FmpCapsule.h>
-
-#include <Library/DebugLib.h>
-#include <Library/PcdLib.h>
-#include <Library/CapsuleLib.h>
-#include <Library/UefiDriverEntryPoint.h> -#include <Library/UefiBootServicesTableLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/UefiRuntimeLib.h>
-#include <Library/BaseLib.h>
-#include <Library/PrintLib.h>
-#include <Library/BaseMemoryLib.h>
+#include "CapsuleService.h"
+
//
// Handle for the installation of Capsule Architecture Protocol.
//
@@ -44,15 +30,6 @@ UINTN mTimes = 0;
UINT32 mMaxSizePopulateCapsule = 0;
UINT32 mMaxSizeNonPopulateCapsule = 0;
-/**
- Create the variable to save the base address of page table and stack
- for transferring into long mode in IA32 PEI.
-**/
-VOID
-SaveLongModeContext (
- VOID
- );
-
/**
Passes capsules to the firmware with both virtual and physical mapping. Depending on the intended
consumption, the firmware may process the capsule immediately. If the payload should persist @@ -194,10 +171,12 @@ UpdateCapsule (
//
// Check if the platform supports update capsule across a system reset
//
- if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {
+ if (!IsPersistAcrossResetCapsuleSupported ()) {
return EFI_UNSUPPORTED;
}
+ CapsuleCacheWriteBack (ScatterGatherList);
+
//
// Construct variable name CapsuleUpdateData, CapsuleUpdateData1, CapsuleUpdateData2...
// if user calls UpdateCapsule multiple times.
@@ -344,7 +323,7 @@ QueryCapsuleCapabilities (
//
//Check if the platform supports update capsule across a system reset
//
- if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {
+ if (!IsPersistAcrossResetCapsuleSupported ()) {
return EFI_UNSUPPORTED;
}
*ResetType = EfiResetWarm;
diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h
new file mode 100644
index 000000000000..85aafc144b41
--- /dev/null
+++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h
@@ -0,0 +1,73 @@
+/** @file
+ Capsule Runtime Driver produces two UEFI capsule runtime services.
+ (UpdateCapsule, QueryCapsuleCapabilities)
+ It installs the Capsule Architectural Protocol defined in PI1.0a to
+signify
+ the capsule runtime services are ready.
+
+ Copyright (c) 2006 - 2017, Intel Corporation. All rights
+ reserved.<BR> Copyright (c) 2018, Linaro, 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 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 <Uefi.h>
+
+#include <Protocol/Capsule.h>
+#include <Guid/CapsuleVendor.h>
+#include <Guid/FmpCapsule.h>
+
+#include <Library/DebugLib.h>
+#include <Library/PcdLib.h>
+#include <Library/CapsuleLib.h>
+#include <Library/UefiDriverEntryPoint.h> #include
+<Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PrintLib.h>
+#include <Library/BaseMemoryLib.h>
+
+/**
+ Create the variable to save the base address of page table and stack
+ for transferring into long mode in IA32 PEI.
+**/
+VOID
+SaveLongModeContext (
+ VOID
+ );
+
+/**
+ Whether the platform supports capsules that persist across reset.
+Note that
+ some platforms only support such capsules at boot time.
+
+ @return TRUE if a PersistAcrossReset capsule may be passed to UpdateCapsule()
+ at this time
+ FALSE otherwise
+**/
+BOOLEAN
+EFIAPI
+IsPersistAcrossResetCapsuleSupported (
+ VOID
+ );
+
+/**
+ Writes Back a range of data cache lines covering a set of capsules in memory.
+
+ Writes Back the data cache lines specified by ScatterGatherList.
+
+ @param ScatterGatherList Physical address of the data structure that
+ describes a set of capsules in memory
+
+**/
+VOID
+EFIAPI
+CapsuleCacheWriteBack (
+ IN EFI_PHYSICAL_ADDRESS ScatterGatherList
+ );
--
2.17.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v4 1/4] MdeModulePkg/CapsuleRuntimeDxe: clean the capsule payload to DRAM
2018-06-14 0:54 ` Zeng, Star
@ 2018-06-15 10:52 ` Ard Biesheuvel
2018-06-15 14:02 ` Yao, Jiewen
0 siblings, 1 reply; 10+ messages in thread
From: Ard Biesheuvel @ 2018-06-15 10:52 UTC (permalink / raw)
To: Zeng, Star
Cc: edk2-devel@lists.01.org, leif.lindholm@linaro.org, Yao, Jiewen,
Kinney, Michael D
On 14 June 2018 at 02:54, Zeng, Star <star.zeng@intel.com> wrote:
> With 'EFIAPI' removed from IsPersistAcrossResetCapsuleSupported and CapsuleCacheWriteBack definitions, Reviewed-by: Star Zeng <star.zeng@intel.com>.
>
> You can wait a little more time in case Jiewen/Mike has comments.
>
Thank you Star.
I will push these by the end of today unless anyone objects.
> -----Original Message-----
> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> Sent: Wednesday, June 13, 2018 4:09 PM
> To: edk2-devel@lists.01.org
> Cc: leif.lindholm@linaro.org; Zeng, Star <star.zeng@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Subject: [PATCH v4 1/4] MdeModulePkg/CapsuleRuntimeDxe: clean the capsule payload to DRAM
>
> When capsule updates are staged for processing after a warm reboot, they are copied into memory with the MMU and caches enabled. When the capsule PEI gets around to coalescing the capsule, the MMU and caches may still be disabled, and so on architectures where uncached accesses are incoherent with the caches (such as ARM and AARCH64), we need to ensure that the data passed into UpdateCapsule() is written back to main memory before performing the warm reboot.
>
> Unfortunately, on ARM, the only type of cache maintenance instructions that are suitable for this purpose operate on virtual addresses only, and given that the UpdateCapsule() prototype includes the physical address of a linked list of scatter/gather data structures that are mapped at an address that is unknown to the firmware (and may not even be mapped at all when UpdateCapsule() is invoked), we can only perform this cache maintenance at boot time. Fortunately, both Windows and Linux only invoke UpdateCapsule() before calling ExitBootServices(), so this is not a problem in practice.
>
> In the future, we may propose adding a secure firmware service that permits performing the cache maintenance at OS runtime, in which case this code may be enhanced to call that service if available. For now, we just fail any UpdateCapsule() calls performed at OS runtime on ARM.
>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
> MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c | 77 ++++++++++++++++++++
> MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c | 51 +++++++++++++
> MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf | 14 +++-
> MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c | 33 ++-------
> MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h | 73 +++++++++++++++++++
> 5 files changed, 219 insertions(+), 29 deletions(-)
>
> diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c b/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c
> new file mode 100644
> index 000000000000..7e0ca06ce7d0
> --- /dev/null
> +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c
> @@ -0,0 +1,77 @@
> + /** @file
> + ARM implementation of architecture specific routines related to
> + PersistAcrossReset capsules
> +
> + Copyright (c) 2018, Linaro, 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 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 "CapsuleService.h"
> +
> +#include <Library/CacheMaintenanceLib.h>
> +
> +/**
> + Whether the platform supports capsules that persist across reset.
> +Note that
> + some platforms only support such capsules at boot time.
> +
> + @return TRUE if a PersistAcrossReset capsule may be passed to UpdateCapsule()
> + at this time
> + FALSE otherwise
> +**/
> +BOOLEAN
> +EFIAPI
> +IsPersistAcrossResetCapsuleSupported (
> + VOID
> + )
> +{
> + //
> + // ARM requires the capsule payload to be cleaned to the point of
> +coherency
> + // (PoC), but only permits doing so using cache maintenance
> +instructions that
> + // operate on virtual addresses. Since at runtime, we don't know the
> +virtual
> + // addresses of the data structures that make up the scatter/gather
> +list, we
> + // cannot perform the maintenance, and all we can do is give up.
> + //
> + return FeaturePcdGet (PcdSupportUpdateCapsuleReset) && !EfiAtRuntime
> +(); }
> +
> +/**
> + Writes Back a range of data cache lines covering a set of capsules in memory.
> +
> + Writes Back the data cache lines specified by ScatterGatherList.
> +
> + @param ScatterGatherList Physical address of the data structure that
> + describes a set of capsules in memory
> +
> +**/
> +VOID
> +EFIAPI
> +CapsuleCacheWriteBack (
> + IN EFI_PHYSICAL_ADDRESS ScatterGatherList
> + )
> +{
> + EFI_CAPSULE_BLOCK_DESCRIPTOR *Desc;
> +
> + Desc = (EFI_CAPSULE_BLOCK_DESCRIPTOR *)(UINTN)ScatterGatherList; do
> + {
> + WriteBackDataCacheRange (Desc, sizeof *Desc);
> +
> + if (Desc->Length > 0) {
> + WriteBackDataCacheRange ((VOID *)(UINTN)Desc->Union.DataBlock,
> + Desc->Length
> + );
> + Desc++;
> + } else if (Desc->Union.ContinuationPointer > 0) {
> + Desc = (EFI_CAPSULE_BLOCK_DESCRIPTOR *)(UINTN)Desc->Union.ContinuationPointer;
> + }
> + } while (Desc->Length > 0 || Desc->Union.ContinuationPointer > 0);
> +
> + WriteBackDataCacheRange (Desc, sizeof *Desc); }
> diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c
> new file mode 100644
> index 000000000000..09616999e3f8
> --- /dev/null
> +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c
> @@ -0,0 +1,51 @@
> +/** @file
> + Default implementation of architecture specific routines related to
> + PersistAcrossReset capsules
> +
> + Copyright (c) 2018, Linaro, 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 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 "CapsuleService.h"
> +
> +/**
> + Whether the platform supports capsules that persist across reset.
> +Note that
> + some platforms only support such capsules at boot time.
> +
> + @return TRUE if a PersistAcrossReset capsule may be passed to UpdateCapsule()
> + at this time
> + FALSE otherwise
> +**/
> +BOOLEAN
> +EFIAPI
> +IsPersistAcrossResetCapsuleSupported (
> + VOID
> + )
> +{
> + return FeaturePcdGet (PcdSupportUpdateCapsuleReset); }
> +
> +/**
> + Writes Back a range of data cache lines covering a set of capsules in memory.
> +
> + Writes Back the data cache lines specified by ScatterGatherList.
> +
> + @param ScatterGatherList Physical address of the data structure that
> + describes a set of capsules in memory
> +
> +**/
> +VOID
> +EFIAPI
> +CapsuleCacheWriteBack (
> + IN EFI_PHYSICAL_ADDRESS ScatterGatherList
> + )
> +{
> +}
> diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
> index 9ab04ce1b301..43a29ee22948 100644
> --- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
> +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
> @@ -27,17 +27,24 @@ [Defines]
> #
> # The following information is for reference only and not required by the build tools.
> #
> -# VALID_ARCHITECTURES = IA32 X64 IPF EBC
> +# VALID_ARCHITECTURES = IA32 X64 IPF EBC ARM AARCH64
> #
>
> [Sources]
> CapsuleService.c
> + CapsuleService.h
>
> -[Sources.Ia32, Sources.IPF, Sources.EBC, Sources.ARM, Sources.AARCH64]
> +[Sources.Ia32, Sources.IPF, Sources.EBC]
> SaveLongModeContext.c
> + CapsuleReset.c
>
> [Sources.X64]
> X64/SaveLongModeContext.c
> + CapsuleReset.c
> +
> +[Sources.ARM, Sources.AARCH64]
> + SaveLongModeContext.c
> + Arm/CapsuleReset.c
>
> [Packages]
> MdePkg/MdePkg.dec
> @@ -59,6 +66,9 @@ [LibraryClasses.X64]
> UefiLib
> BaseMemoryLib
>
> +[LibraryClasses.ARM, LibraryClasses.AARCH64]
> + CacheMaintenanceLib
> +
> [Guids]
> ## SOMETIMES_PRODUCES ## Variable:L"CapsuleUpdateData" # (Process across reset capsule image) for capsule updated data
> ## SOMETIMES_PRODUCES ## Variable:L"CapsuleLongModeBuffer" # The long mode buffer used by IA32 Capsule PEIM to call X64 CapsuleCoalesce code to handle >4GB capsule blocks
> diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
> index 216798d1617e..23fd6d59c59e 100644
> --- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
> +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
> @@ -15,22 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
>
> **/
>
> -#include <Uefi.h>
> -
> -#include <Protocol/Capsule.h>
> -#include <Guid/CapsuleVendor.h>
> -#include <Guid/FmpCapsule.h>
> -
> -#include <Library/DebugLib.h>
> -#include <Library/PcdLib.h>
> -#include <Library/CapsuleLib.h>
> -#include <Library/UefiDriverEntryPoint.h> -#include <Library/UefiBootServicesTableLib.h>
> -#include <Library/UefiRuntimeServicesTableLib.h>
> -#include <Library/UefiRuntimeLib.h>
> -#include <Library/BaseLib.h>
> -#include <Library/PrintLib.h>
> -#include <Library/BaseMemoryLib.h>
> +#include "CapsuleService.h"
> +
> //
> // Handle for the installation of Capsule Architecture Protocol.
> //
> @@ -44,15 +30,6 @@ UINTN mTimes = 0;
> UINT32 mMaxSizePopulateCapsule = 0;
> UINT32 mMaxSizeNonPopulateCapsule = 0;
>
> -/**
> - Create the variable to save the base address of page table and stack
> - for transferring into long mode in IA32 PEI.
> -**/
> -VOID
> -SaveLongModeContext (
> - VOID
> - );
> -
> /**
> Passes capsules to the firmware with both virtual and physical mapping. Depending on the intended
> consumption, the firmware may process the capsule immediately. If the payload should persist @@ -194,10 +171,12 @@ UpdateCapsule (
> //
> // Check if the platform supports update capsule across a system reset
> //
> - if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {
> + if (!IsPersistAcrossResetCapsuleSupported ()) {
> return EFI_UNSUPPORTED;
> }
>
> + CapsuleCacheWriteBack (ScatterGatherList);
> +
> //
> // Construct variable name CapsuleUpdateData, CapsuleUpdateData1, CapsuleUpdateData2...
> // if user calls UpdateCapsule multiple times.
> @@ -344,7 +323,7 @@ QueryCapsuleCapabilities (
> //
> //Check if the platform supports update capsule across a system reset
> //
> - if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {
> + if (!IsPersistAcrossResetCapsuleSupported ()) {
> return EFI_UNSUPPORTED;
> }
> *ResetType = EfiResetWarm;
> diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h
> new file mode 100644
> index 000000000000..85aafc144b41
> --- /dev/null
> +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h
> @@ -0,0 +1,73 @@
> +/** @file
> + Capsule Runtime Driver produces two UEFI capsule runtime services.
> + (UpdateCapsule, QueryCapsuleCapabilities)
> + It installs the Capsule Architectural Protocol defined in PI1.0a to
> +signify
> + the capsule runtime services are ready.
> +
> + Copyright (c) 2006 - 2017, Intel Corporation. All rights
> + reserved.<BR> Copyright (c) 2018, Linaro, 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 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 <Uefi.h>
> +
> +#include <Protocol/Capsule.h>
> +#include <Guid/CapsuleVendor.h>
> +#include <Guid/FmpCapsule.h>
> +
> +#include <Library/DebugLib.h>
> +#include <Library/PcdLib.h>
> +#include <Library/CapsuleLib.h>
> +#include <Library/UefiDriverEntryPoint.h> #include
> +<Library/UefiBootServicesTableLib.h>
> +#include <Library/UefiRuntimeServicesTableLib.h>
> +#include <Library/UefiRuntimeLib.h>
> +#include <Library/BaseLib.h>
> +#include <Library/PrintLib.h>
> +#include <Library/BaseMemoryLib.h>
> +
> +/**
> + Create the variable to save the base address of page table and stack
> + for transferring into long mode in IA32 PEI.
> +**/
> +VOID
> +SaveLongModeContext (
> + VOID
> + );
> +
> +/**
> + Whether the platform supports capsules that persist across reset.
> +Note that
> + some platforms only support such capsules at boot time.
> +
> + @return TRUE if a PersistAcrossReset capsule may be passed to UpdateCapsule()
> + at this time
> + FALSE otherwise
> +**/
> +BOOLEAN
> +EFIAPI
> +IsPersistAcrossResetCapsuleSupported (
> + VOID
> + );
> +
> +/**
> + Writes Back a range of data cache lines covering a set of capsules in memory.
> +
> + Writes Back the data cache lines specified by ScatterGatherList.
> +
> + @param ScatterGatherList Physical address of the data structure that
> + describes a set of capsules in memory
> +
> +**/
> +VOID
> +EFIAPI
> +CapsuleCacheWriteBack (
> + IN EFI_PHYSICAL_ADDRESS ScatterGatherList
> + );
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v4 1/4] MdeModulePkg/CapsuleRuntimeDxe: clean the capsule payload to DRAM
2018-06-15 10:52 ` Ard Biesheuvel
@ 2018-06-15 14:02 ` Yao, Jiewen
0 siblings, 0 replies; 10+ messages in thread
From: Yao, Jiewen @ 2018-06-15 14:02 UTC (permalink / raw)
To: Ard Biesheuvel, Zeng, Star
Cc: edk2-devel@lists.01.org, leif.lindholm@linaro.org,
Kinney, Michael D
Reviewed-by: Jiewen.yao@intel.com
> -----Original Message-----
> From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> Sent: Friday, June 15, 2018 3:52 AM
> To: Zeng, Star <star.zeng@intel.com>
> Cc: edk2-devel@lists.01.org; leif.lindholm@linaro.org; Yao, Jiewen
> <jiewen.yao@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>
> Subject: Re: [PATCH v4 1/4] MdeModulePkg/CapsuleRuntimeDxe: clean the
> capsule payload to DRAM
>
> On 14 June 2018 at 02:54, Zeng, Star <star.zeng@intel.com> wrote:
> > With 'EFIAPI' removed from IsPersistAcrossResetCapsuleSupported and
> CapsuleCacheWriteBack definitions, Reviewed-by: Star Zeng
> <star.zeng@intel.com>.
> >
> > You can wait a little more time in case Jiewen/Mike has comments.
> >
>
> Thank you Star.
>
> I will push these by the end of today unless anyone objects.
>
>
> > -----Original Message-----
> > From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
> > Sent: Wednesday, June 13, 2018 4:09 PM
> > To: edk2-devel@lists.01.org
> > Cc: leif.lindholm@linaro.org; Zeng, Star <star.zeng@intel.com>; Yao, Jiewen
> <jiewen.yao@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Ard
> Biesheuvel <ard.biesheuvel@linaro.org>
> > Subject: [PATCH v4 1/4] MdeModulePkg/CapsuleRuntimeDxe: clean the
> capsule payload to DRAM
> >
> > When capsule updates are staged for processing after a warm reboot, they are
> copied into memory with the MMU and caches enabled. When the capsule PEI
> gets around to coalescing the capsule, the MMU and caches may still be disabled,
> and so on architectures where uncached accesses are incoherent with the caches
> (such as ARM and AARCH64), we need to ensure that the data passed into
> UpdateCapsule() is written back to main memory before performing the warm
> reboot.
> >
> > Unfortunately, on ARM, the only type of cache maintenance instructions that
> are suitable for this purpose operate on virtual addresses only, and given that the
> UpdateCapsule() prototype includes the physical address of a linked list of
> scatter/gather data structures that are mapped at an address that is unknown to
> the firmware (and may not even be mapped at all when UpdateCapsule() is
> invoked), we can only perform this cache maintenance at boot time. Fortunately,
> both Windows and Linux only invoke UpdateCapsule() before calling
> ExitBootServices(), so this is not a problem in practice.
> >
> > In the future, we may propose adding a secure firmware service that permits
> performing the cache maintenance at OS runtime, in which case this code may
> be enhanced to call that service if available. For now, we just fail any
> UpdateCapsule() calls performed at OS runtime on ARM.
> >
> > Contributed-under: TianoCore Contribution Agreement 1.1
> > Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> > ---
> > MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c | 77
> ++++++++++++++++++++
> > MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c | 51
> +++++++++++++
> > MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf | 14
> +++-
> > MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c | 33
> ++-------
> > MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h | 73
> +++++++++++++++++++
> > 5 files changed, 219 insertions(+), 29 deletions(-)
> >
> > diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c
> b/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c
> > new file mode 100644
> > index 000000000000..7e0ca06ce7d0
> > --- /dev/null
> > +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c
> > @@ -0,0 +1,77 @@
> > + /** @file
> > + ARM implementation of architecture specific routines related to
> > + PersistAcrossReset capsules
> > +
> > + Copyright (c) 2018, Linaro, 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 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 "CapsuleService.h"
> > +
> > +#include <Library/CacheMaintenanceLib.h>
> > +
> > +/**
> > + Whether the platform supports capsules that persist across reset.
> > +Note that
> > + some platforms only support such capsules at boot time.
> > +
> > + @return TRUE if a PersistAcrossReset capsule may be passed to
> UpdateCapsule()
> > + at this time
> > + FALSE otherwise
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +IsPersistAcrossResetCapsuleSupported (
> > + VOID
> > + )
> > +{
> > + //
> > + // ARM requires the capsule payload to be cleaned to the point of
> > +coherency
> > + // (PoC), but only permits doing so using cache maintenance
> > +instructions that
> > + // operate on virtual addresses. Since at runtime, we don't know the
> > +virtual
> > + // addresses of the data structures that make up the scatter/gather
> > +list, we
> > + // cannot perform the maintenance, and all we can do is give up.
> > + //
> > + return FeaturePcdGet (PcdSupportUpdateCapsuleReset) && !EfiAtRuntime
> > +(); }
> > +
> > +/**
> > + Writes Back a range of data cache lines covering a set of capsules in
> memory.
> > +
> > + Writes Back the data cache lines specified by ScatterGatherList.
> > +
> > + @param ScatterGatherList Physical address of the data structure that
> > + describes a set of capsules in memory
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +CapsuleCacheWriteBack (
> > + IN EFI_PHYSICAL_ADDRESS ScatterGatherList
> > + )
> > +{
> > + EFI_CAPSULE_BLOCK_DESCRIPTOR *Desc;
> > +
> > + Desc = (EFI_CAPSULE_BLOCK_DESCRIPTOR *)(UINTN)ScatterGatherList;
> do
> > + {
> > + WriteBackDataCacheRange (Desc, sizeof *Desc);
> > +
> > + if (Desc->Length > 0) {
> > + WriteBackDataCacheRange ((VOID *)(UINTN)Desc->Union.DataBlock,
> > + Desc->Length
> > + );
> > + Desc++;
> > + } else if (Desc->Union.ContinuationPointer > 0) {
> > + Desc = (EFI_CAPSULE_BLOCK_DESCRIPTOR
> *)(UINTN)Desc->Union.ContinuationPointer;
> > + }
> > + } while (Desc->Length > 0 || Desc->Union.ContinuationPointer > 0);
> > +
> > + WriteBackDataCacheRange (Desc, sizeof *Desc); }
> > diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c
> b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c
> > new file mode 100644
> > index 000000000000..09616999e3f8
> > --- /dev/null
> > +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c
> > @@ -0,0 +1,51 @@
> > +/** @file
> > + Default implementation of architecture specific routines related to
> > + PersistAcrossReset capsules
> > +
> > + Copyright (c) 2018, Linaro, 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 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 "CapsuleService.h"
> > +
> > +/**
> > + Whether the platform supports capsules that persist across reset.
> > +Note that
> > + some platforms only support such capsules at boot time.
> > +
> > + @return TRUE if a PersistAcrossReset capsule may be passed to
> UpdateCapsule()
> > + at this time
> > + FALSE otherwise
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +IsPersistAcrossResetCapsuleSupported (
> > + VOID
> > + )
> > +{
> > + return FeaturePcdGet (PcdSupportUpdateCapsuleReset); }
> > +
> > +/**
> > + Writes Back a range of data cache lines covering a set of capsules in
> memory.
> > +
> > + Writes Back the data cache lines specified by ScatterGatherList.
> > +
> > + @param ScatterGatherList Physical address of the data structure that
> > + describes a set of capsules in memory
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +CapsuleCacheWriteBack (
> > + IN EFI_PHYSICAL_ADDRESS ScatterGatherList
> > + )
> > +{
> > +}
> > diff --git
> a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
> b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
> > index 9ab04ce1b301..43a29ee22948 100644
> > --- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
> > +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
> > @@ -27,17 +27,24 @@ [Defines]
> > #
> > # The following information is for reference only and not required by the
> build tools.
> > #
> > -# VALID_ARCHITECTURES = IA32 X64 IPF EBC
> > +# VALID_ARCHITECTURES = IA32 X64 IPF EBC ARM AARCH64
> > #
> >
> > [Sources]
> > CapsuleService.c
> > + CapsuleService.h
> >
> > -[Sources.Ia32, Sources.IPF, Sources.EBC, Sources.ARM, Sources.AARCH64]
> > +[Sources.Ia32, Sources.IPF, Sources.EBC]
> > SaveLongModeContext.c
> > + CapsuleReset.c
> >
> > [Sources.X64]
> > X64/SaveLongModeContext.c
> > + CapsuleReset.c
> > +
> > +[Sources.ARM, Sources.AARCH64]
> > + SaveLongModeContext.c
> > + Arm/CapsuleReset.c
> >
> > [Packages]
> > MdePkg/MdePkg.dec
> > @@ -59,6 +66,9 @@ [LibraryClasses.X64]
> > UefiLib
> > BaseMemoryLib
> >
> > +[LibraryClasses.ARM, LibraryClasses.AARCH64]
> > + CacheMaintenanceLib
> > +
> > [Guids]
> > ## SOMETIMES_PRODUCES ## Variable:L"CapsuleUpdateData" #
> (Process across reset capsule image) for capsule updated data
> > ## SOMETIMES_PRODUCES ## Variable:L"CapsuleLongModeBuffer" #
> The long mode buffer used by IA32 Capsule PEIM to call X64 CapsuleCoalesce
> code to handle >4GB capsule blocks
> > diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
> b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
> > index 216798d1617e..23fd6d59c59e 100644
> > --- a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
> > +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.c
> > @@ -15,22 +15,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY
> KIND, EITHER EXPRESS OR IMPLIED.
> >
> > **/
> >
> > -#include <Uefi.h>
> > -
> > -#include <Protocol/Capsule.h>
> > -#include <Guid/CapsuleVendor.h>
> > -#include <Guid/FmpCapsule.h>
> > -
> > -#include <Library/DebugLib.h>
> > -#include <Library/PcdLib.h>
> > -#include <Library/CapsuleLib.h>
> > -#include <Library/UefiDriverEntryPoint.h> -#include
> <Library/UefiBootServicesTableLib.h>
> > -#include <Library/UefiRuntimeServicesTableLib.h>
> > -#include <Library/UefiRuntimeLib.h>
> > -#include <Library/BaseLib.h>
> > -#include <Library/PrintLib.h>
> > -#include <Library/BaseMemoryLib.h>
> > +#include "CapsuleService.h"
> > +
> > //
> > // Handle for the installation of Capsule Architecture Protocol.
> > //
> > @@ -44,15 +30,6 @@ UINTN mTimes = 0;
> > UINT32 mMaxSizePopulateCapsule = 0;
> > UINT32 mMaxSizeNonPopulateCapsule = 0;
> >
> > -/**
> > - Create the variable to save the base address of page table and stack
> > - for transferring into long mode in IA32 PEI.
> > -**/
> > -VOID
> > -SaveLongModeContext (
> > - VOID
> > - );
> > -
> > /**
> > Passes capsules to the firmware with both virtual and physical mapping.
> Depending on the intended
> > consumption, the firmware may process the capsule immediately. If the
> payload should persist @@ -194,10 +171,12 @@ UpdateCapsule (
> > //
> > // Check if the platform supports update capsule across a system reset
> > //
> > - if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {
> > + if (!IsPersistAcrossResetCapsuleSupported ()) {
> > return EFI_UNSUPPORTED;
> > }
> >
> > + CapsuleCacheWriteBack (ScatterGatherList);
> > +
> > //
> > // Construct variable name CapsuleUpdateData, CapsuleUpdateData1,
> CapsuleUpdateData2...
> > // if user calls UpdateCapsule multiple times.
> > @@ -344,7 +323,7 @@ QueryCapsuleCapabilities (
> > //
> > //Check if the platform supports update capsule across a system reset
> > //
> > - if (!FeaturePcdGet(PcdSupportUpdateCapsuleReset)) {
> > + if (!IsPersistAcrossResetCapsuleSupported ()) {
> > return EFI_UNSUPPORTED;
> > }
> > *ResetType = EfiResetWarm;
> > diff --git a/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h
> b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h
> > new file mode 100644
> > index 000000000000..85aafc144b41
> > --- /dev/null
> > +++ b/MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h
> > @@ -0,0 +1,73 @@
> > +/** @file
> > + Capsule Runtime Driver produces two UEFI capsule runtime services.
> > + (UpdateCapsule, QueryCapsuleCapabilities)
> > + It installs the Capsule Architectural Protocol defined in PI1.0a to
> > +signify
> > + the capsule runtime services are ready.
> > +
> > + Copyright (c) 2006 - 2017, Intel Corporation. All rights
> > + reserved.<BR> Copyright (c) 2018, Linaro, 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 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 <Uefi.h>
> > +
> > +#include <Protocol/Capsule.h>
> > +#include <Guid/CapsuleVendor.h>
> > +#include <Guid/FmpCapsule.h>
> > +
> > +#include <Library/DebugLib.h>
> > +#include <Library/PcdLib.h>
> > +#include <Library/CapsuleLib.h>
> > +#include <Library/UefiDriverEntryPoint.h> #include
> > +<Library/UefiBootServicesTableLib.h>
> > +#include <Library/UefiRuntimeServicesTableLib.h>
> > +#include <Library/UefiRuntimeLib.h>
> > +#include <Library/BaseLib.h>
> > +#include <Library/PrintLib.h>
> > +#include <Library/BaseMemoryLib.h>
> > +
> > +/**
> > + Create the variable to save the base address of page table and stack
> > + for transferring into long mode in IA32 PEI.
> > +**/
> > +VOID
> > +SaveLongModeContext (
> > + VOID
> > + );
> > +
> > +/**
> > + Whether the platform supports capsules that persist across reset.
> > +Note that
> > + some platforms only support such capsules at boot time.
> > +
> > + @return TRUE if a PersistAcrossReset capsule may be passed to
> UpdateCapsule()
> > + at this time
> > + FALSE otherwise
> > +**/
> > +BOOLEAN
> > +EFIAPI
> > +IsPersistAcrossResetCapsuleSupported (
> > + VOID
> > + );
> > +
> > +/**
> > + Writes Back a range of data cache lines covering a set of capsules in
> memory.
> > +
> > + Writes Back the data cache lines specified by ScatterGatherList.
> > +
> > + @param ScatterGatherList Physical address of the data structure that
> > + describes a set of capsules in memory
> > +
> > +**/
> > +VOID
> > +EFIAPI
> > +CapsuleCacheWriteBack (
> > + IN EFI_PHYSICAL_ADDRESS ScatterGatherList
> > + );
> > --
> > 2.17.1
> >
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v4 2/4] MdeModulePkg/DxeCapsuleLibFmp: pass progress callback only if it works
2018-06-13 8:08 [PATCH v4 0/4] MdeModulePkg ArmPkg: support for persistent capsules and progress reporting Ard Biesheuvel
2018-06-13 8:08 ` [PATCH v4 1/4] MdeModulePkg/CapsuleRuntimeDxe: clean the capsule payload to DRAM Ard Biesheuvel
@ 2018-06-13 8:08 ` Ard Biesheuvel
2018-06-14 0:54 ` Zeng, Star
2018-06-13 8:09 ` [PATCH v4 3/4] ArmPkg/PlatformBootManagerLib: call ProcessCapsules() only once Ard Biesheuvel
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Ard Biesheuvel @ 2018-06-13 8:08 UTC (permalink / raw)
To: edk2-devel
Cc: leif.lindholm, star.zeng, jiewen.yao, michael.d.kinney,
Ard Biesheuvel
If the first call to UpdateImageProgress() fails, there is no point
in passing a pointer to it to Fmp->SetImage(), since it is highly
unlikely to succeed on any subsequent calls.
This permits the FMP implementation to fall back to an alternate means
of providing feedback to the user, e.g., via the console.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
index f0226eafa576..ab41df0eb0a4 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
@@ -841,6 +841,7 @@ SetFmpImageData (
UINT8 *Image;
VOID *VendorCode;
CHAR16 *AbortReason;
+ EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS ProgressCallback;
Status = gBS->HandleProtocol(
Handle,
@@ -892,7 +893,11 @@ SetFmpImageData (
//
// Before calling SetImage(), reset the progress bar to 0%
//
- UpdateImageProgress (0);
+ ProgressCallback = UpdateImageProgress;
+ Status = UpdateImageProgress (0);
+ if (EFI_ERROR (Status)) {
+ ProgressCallback = NULL;
+ }
Status = Fmp->SetImage(
Fmp,
@@ -900,13 +905,15 @@ SetFmpImageData (
Image, // Image
ImageHeader->UpdateImageSize, // ImageSize
VendorCode, // VendorCode
- UpdateImageProgress, // Progress
+ ProgressCallback, // Progress
&AbortReason // AbortReason
);
//
// Set the progress bar to 100% after returning from SetImage()
//
- UpdateImageProgress (100);
+ if (ProgressCallback != NULL) {
+ UpdateImageProgress (100);
+ }
DEBUG((DEBUG_INFO, "Fmp->SetImage - %r\n", Status));
if (AbortReason != NULL) {
--
2.17.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v4 2/4] MdeModulePkg/DxeCapsuleLibFmp: pass progress callback only if it works
2018-06-13 8:08 ` [PATCH v4 2/4] MdeModulePkg/DxeCapsuleLibFmp: pass progress callback only if it works Ard Biesheuvel
@ 2018-06-14 0:54 ` Zeng, Star
0 siblings, 0 replies; 10+ messages in thread
From: Zeng, Star @ 2018-06-14 0:54 UTC (permalink / raw)
To: Ard Biesheuvel, edk2-devel@lists.01.org
Cc: leif.lindholm@linaro.org, Yao, Jiewen, Kinney, Michael D,
Zeng, Star
Reviewed-by: Star Zeng <star.zeng@intel.com>
-----Original Message-----
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org]
Sent: Wednesday, June 13, 2018 4:09 PM
To: edk2-devel@lists.01.org
Cc: leif.lindholm@linaro.org; Zeng, Star <star.zeng@intel.com>; Yao, Jiewen <jiewen.yao@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH v4 2/4] MdeModulePkg/DxeCapsuleLibFmp: pass progress callback only if it works
If the first call to UpdateImageProgress() fails, there is no point in passing a pointer to it to Fmp->SetImage(), since it is highly unlikely to succeed on any subsequent calls.
This permits the FMP implementation to fall back to an alternate means of providing feedback to the user, e.g., via the console.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
index f0226eafa576..ab41df0eb0a4 100644
--- a/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
+++ b/MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.c
@@ -841,6 +841,7 @@ SetFmpImageData (
UINT8 *Image;
VOID *VendorCode;
CHAR16 *AbortReason;
+ EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS ProgressCallback;
Status = gBS->HandleProtocol(
Handle,
@@ -892,7 +893,11 @@ SetFmpImageData (
//
// Before calling SetImage(), reset the progress bar to 0%
//
- UpdateImageProgress (0);
+ ProgressCallback = UpdateImageProgress; Status = UpdateImageProgress
+ (0); if (EFI_ERROR (Status)) {
+ ProgressCallback = NULL;
+ }
Status = Fmp->SetImage(
Fmp,
@@ -900,13 +905,15 @@ SetFmpImageData (
Image, // Image
ImageHeader->UpdateImageSize, // ImageSize
VendorCode, // VendorCode
- UpdateImageProgress, // Progress
+ ProgressCallback, // Progress
&AbortReason // AbortReason
);
//
// Set the progress bar to 100% after returning from SetImage()
//
- UpdateImageProgress (100);
+ if (ProgressCallback != NULL) {
+ UpdateImageProgress (100);
+ }
DEBUG((DEBUG_INFO, "Fmp->SetImage - %r\n", Status));
if (AbortReason != NULL) {
--
2.17.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v4 3/4] ArmPkg/PlatformBootManagerLib: call ProcessCapsules() only once
2018-06-13 8:08 [PATCH v4 0/4] MdeModulePkg ArmPkg: support for persistent capsules and progress reporting Ard Biesheuvel
2018-06-13 8:08 ` [PATCH v4 1/4] MdeModulePkg/CapsuleRuntimeDxe: clean the capsule payload to DRAM Ard Biesheuvel
2018-06-13 8:08 ` [PATCH v4 2/4] MdeModulePkg/DxeCapsuleLibFmp: pass progress callback only if it works Ard Biesheuvel
@ 2018-06-13 8:09 ` Ard Biesheuvel
2018-06-13 8:09 ` [PATCH v4 4/4] ArmPkg/ArmSmcPsciResetSystemLib: implement fallback for warm reboot Ard Biesheuvel
2018-06-15 16:19 ` [PATCH v4 0/4] MdeModulePkg ArmPkg: support for persistent capsules and progress reporting Ard Biesheuvel
4 siblings, 0 replies; 10+ messages in thread
From: Ard Biesheuvel @ 2018-06-13 8:09 UTC (permalink / raw)
To: edk2-devel
Cc: leif.lindholm, star.zeng, jiewen.yao, michael.d.kinney,
Ard Biesheuvel
ARM platforms have no restriction on when a system firmware update
capsule can be applied, and so it is not necessary to call
ProcessCapsules() twice. So let's drop the first invocation that
occurs before EndOfDxe, and rewrite the second call so that all
capsule updates will be applied when the console is up and able to
provide progress feedback.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
---
ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c | 86 ++++++++++++++------
ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 1 +
2 files changed, 60 insertions(+), 27 deletions(-)
diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
index 3456a71fbb9c..079f1552d5ea 100644
--- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
+++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c
@@ -24,6 +24,7 @@
#include <Library/PcdLib.h>
#include <Library/UefiBootManagerLib.h>
#include <Library/UefiLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
#include <Protocol/DevicePath.h>
#include <Protocol/EsrtManagement.h>
#include <Protocol/GraphicsOutput.h>
@@ -553,21 +554,6 @@ PlatformBootManagerBeforeConsole (
VOID
)
{
- EFI_STATUS Status;
- ESRT_MANAGEMENT_PROTOCOL *EsrtManagement;
-
- if (GetBootModeHob() == BOOT_ON_FLASH_UPDATE) {
- DEBUG ((DEBUG_INFO, "ProcessCapsules Before EndOfDxe ......\n"));
- Status = ProcessCapsules ();
- DEBUG ((DEBUG_INFO, "ProcessCapsules returned %r\n", Status));
- } else {
- Status = gBS->LocateProtocol (&gEsrtManagementProtocolGuid, NULL,
- (VOID **)&EsrtManagement);
- if (!EFI_ERROR (Status)) {
- EsrtManagement->SyncEsrtFmp ();
- }
- }
-
//
// Signal EndOfDxe PI Event
//
@@ -618,6 +604,56 @@ PlatformBootManagerBeforeConsole (
PlatformRegisterOptionsAndKeys ();
}
+STATIC
+VOID
+HandleCapsules (
+ VOID
+ )
+{
+ ESRT_MANAGEMENT_PROTOCOL *EsrtManagement;
+ EFI_PEI_HOB_POINTERS HobPointer;
+ EFI_CAPSULE_HEADER *CapsuleHeader;
+ BOOLEAN NeedReset;
+ EFI_STATUS Status;
+
+ DEBUG ((DEBUG_INFO, "%a: processing capsules ...\n", __FUNCTION__));
+
+ Status = gBS->LocateProtocol (&gEsrtManagementProtocolGuid, NULL,
+ (VOID **)&EsrtManagement);
+ if (!EFI_ERROR (Status)) {
+ EsrtManagement->SyncEsrtFmp ();
+ }
+
+ //
+ // Find all capsule images from hob
+ //
+ HobPointer.Raw = GetHobList ();
+ NeedReset = FALSE;
+ while ((HobPointer.Raw = GetNextHob (EFI_HOB_TYPE_UEFI_CAPSULE,
+ HobPointer.Raw)) != NULL) {
+ CapsuleHeader = (VOID *)(UINTN)HobPointer.Capsule->BaseAddress;
+
+ Status = ProcessCapsuleImage (CapsuleHeader);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: failed to process capsule %p - %r\n",
+ __FUNCTION__, CapsuleHeader, Status));
+ return;
+ }
+
+ NeedReset = TRUE;
+ HobPointer.Raw = GET_NEXT_HOB (HobPointer);
+ }
+
+ if (NeedReset) {
+ DEBUG ((DEBUG_WARN, "%a: capsule update successful, resetting ...\n",
+ __FUNCTION__));
+
+ gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
+ CpuDeadLoop();
+ }
+}
+
+
#define VERSION_STRING_PREFIX L"Tianocore/EDK2 firmware version "
/**
@@ -637,7 +673,6 @@ PlatformBootManagerAfterConsole (
VOID
)
{
- ESRT_MANAGEMENT_PROTOCOL *EsrtManagement;
EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
UINTN FirmwareVerLength;
@@ -675,17 +710,14 @@ PlatformBootManagerAfterConsole (
//
EfiBootManagerConnectAll ();
- Status = gBS->LocateProtocol (&gEsrtManagementProtocolGuid, NULL,
- (VOID **)&EsrtManagement);
- if (!EFI_ERROR (Status)) {
- EsrtManagement->SyncEsrtFmp ();
- }
-
- if (GetBootModeHob() == BOOT_ON_FLASH_UPDATE) {
- DEBUG((DEBUG_INFO, "ProcessCapsules After EndOfDxe ......\n"));
- Status = ProcessCapsules ();
- DEBUG((DEBUG_INFO, "ProcessCapsules returned %r\n", Status));
- }
+ //
+ // On ARM, there is currently no reason to use the phased capsule
+ // update approach where some capsules are dispatched before EndOfDxe
+ // and some are dispatched after. So just handle all capsules here,
+ // when the console is up and we can actually give the user some
+ // feedback about what is going on.
+ //
+ HandleCapsules ();
//
// Enumerate all possible boot options.
diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
index e8cbb10dabdd..28d606d5c329 100644
--- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
+++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
@@ -55,6 +55,7 @@ [LibraryClasses]
UefiBootManagerLib
UefiBootServicesTableLib
UefiLib
+ UefiRuntimeServicesTableLib
[FeaturePcd]
gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport
--
2.17.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v4 4/4] ArmPkg/ArmSmcPsciResetSystemLib: implement fallback for warm reboot
2018-06-13 8:08 [PATCH v4 0/4] MdeModulePkg ArmPkg: support for persistent capsules and progress reporting Ard Biesheuvel
` (2 preceding siblings ...)
2018-06-13 8:09 ` [PATCH v4 3/4] ArmPkg/PlatformBootManagerLib: call ProcessCapsules() only once Ard Biesheuvel
@ 2018-06-13 8:09 ` Ard Biesheuvel
2018-06-15 16:19 ` [PATCH v4 0/4] MdeModulePkg ArmPkg: support for persistent capsules and progress reporting Ard Biesheuvel
4 siblings, 0 replies; 10+ messages in thread
From: Ard Biesheuvel @ 2018-06-13 8:09 UTC (permalink / raw)
To: edk2-devel
Cc: leif.lindholm, star.zeng, jiewen.yao, michael.d.kinney,
Ard Biesheuvel
Implement ResetSystemLib's EnterS3WithImmediateWake() routine using
a jump back to the PEI entry point with interrupts and MMU+caches
disabled. This is only possible at boot time, when we are sure that
the current CPU is the only one up and running. Also, it depends on
the platform whether the PEI code is preserved in memory (it may be
copied to DRAM rather than execute in place), so also add a feature
PCD to selectively enable this feature.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
---
ArmPkg/ArmPkg.dec | 4 ++++
ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c | 21 ++++++++++++++++++--
ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf | 9 +++++++++
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec
index debe066b6f7b..3aa229fe2ec9 100644
--- a/ArmPkg/ArmPkg.dec
+++ b/ArmPkg/ArmPkg.dec
@@ -85,6 +85,10 @@ [PcdsFeatureFlag.common]
# Define if the GICv3 controller should use the GICv2 legacy
gArmTokenSpaceGuid.PcdArmGicV3WithV2Legacy|FALSE|BOOLEAN|0x00000042
+ # Whether to implement warm reboot for capsule update using a jump back to the
+ # PEI entry point with caches and interrupts disabled.
+ gArmTokenSpaceGuid.PcdArmReenterPeiForCapsuleWarmReboot|FALSE|BOOLEAN|0x0000001F
+
[PcdsFeatureFlag.ARM]
# Whether to map normal memory as non-shareable. FALSE is the safe choice, but
# TRUE may be appropriate to fix performance problems if you don't care about
diff --git a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c
index d6d26bce5009..10ceafd14d5d 100644
--- a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c
+++ b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c
@@ -15,10 +15,13 @@
#include <PiDxe.h>
+#include <Library/ArmMmuLib.h>
+#include <Library/ArmSmcLib.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/ResetSystemLib.h>
-#include <Library/ArmSmcLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
#include <IndustryStandard/ArmStdSmc.h>
@@ -89,7 +92,21 @@ EnterS3WithImmediateWake (
VOID
)
{
- // Not implemented
+ VOID (*Reset)(VOID);
+
+ if (FeaturePcdGet (PcdArmReenterPeiForCapsuleWarmReboot) &&
+ !EfiAtRuntime ()) {
+ //
+ // At boot time, we are the only core running, so we can implement the
+ // immediate wake (which is used by capsule update) by disabling the MMU
+ // and interrupts, and jumping to the PEI entry point.
+ //
+ Reset = (VOID (*)(VOID))(UINTN)FixedPcdGet64 (PcdFvBaseAddress);
+
+ gBS->RaiseTPL (TPL_HIGH_LEVEL);
+ ArmDisableMmu ();
+ Reset ();
+ }
}
/**
diff --git a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
index 5a1ee976e5bc..19021cd1e8b6 100644
--- a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
+++ b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
@@ -30,6 +30,15 @@ [Packages]
MdePkg/MdePkg.dec
[LibraryClasses]
+ ArmMmuLib
ArmSmcLib
BaseLib
DebugLib
+ UefiBootServicesTableLib
+ UefiRuntimeLib
+
+[FeaturePcd]
+ gArmTokenSpaceGuid.PcdArmReenterPeiForCapsuleWarmReboot
+
+[FixedPcd]
+ gArmTokenSpaceGuid.PcdFvBaseAddress
--
2.17.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v4 0/4] MdeModulePkg ArmPkg: support for persistent capsules and progress reporting
2018-06-13 8:08 [PATCH v4 0/4] MdeModulePkg ArmPkg: support for persistent capsules and progress reporting Ard Biesheuvel
` (3 preceding siblings ...)
2018-06-13 8:09 ` [PATCH v4 4/4] ArmPkg/ArmSmcPsciResetSystemLib: implement fallback for warm reboot Ard Biesheuvel
@ 2018-06-15 16:19 ` Ard Biesheuvel
4 siblings, 0 replies; 10+ messages in thread
From: Ard Biesheuvel @ 2018-06-15 16:19 UTC (permalink / raw)
To: edk2-devel@lists.01.org
Cc: Leif Lindholm, Zeng, Star, Yao, Jiewen, Kinney, Michael D,
Ard Biesheuvel
On 13 June 2018 at 10:08, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
> This is the delta of code required to implement PersistAcrossReset on ARM
> systems, and to wire up the capsule handling routines in a way that makes
> the new progress reporting code do something meaningful on such platforms.
>
> Changes since v3:
> - let both UpdateCapsule() and QueryCapsuleCapabilities() return EFI_UNSUPPORTED
> when called at OS runtime on an ARM system
> - reset the system unconditionally after having processed any capsules (#3)
> - re-add Leif's ack (#3)
>
> Changes since v2:
> - move cache handling from CapsulePei to CapsuleRuntimeDxe, and make it ARM only
> - drop patch to change ProcessCapsules() logic in DxeCapsuleLibFmp; instead,
> the platform BDS code is modified to perform the ProcessCapsuleImage()
> call directly
>
> Changes since v1:
> - incorporate Star's feedback (#1, #2)
> - add Leif's ack (#4)
>
> Patch #1 ensures that the capsule data which is preserved in DRAM across
> a reboot is written back to main memory before attempting to access it
> with the caches off.
>
> Patch #2 updates DxeCapsuleLibFmp so it does not pass down the progress
> indication callback if its own attempt to invoke it has already failed.
>
> Patch #3 updates ArmPkg's generic PlatformBootManagerLib implementation
> to only call ProcessCapsules() after the [potentially non-trusted]
> console is up and running, to ensure that firmware update progress can
> be reported to the user.
>
> Patch #4 modifies ArmSmcPsciResetSystemLib to emulate a proper warm reboot
> by reentering PEI with interrupts, MMU and caches enabled. This works
> around the lack of an architected warm reboot in most current implementations.
> (The PSCI spec does cover warm reboot, but it was added recently and most
> secure firmware implementations haven't caught up yet)
>
> Ard Biesheuvel (4):
> MdeModulePkg/CapsuleRuntimeDxe: clean the capsule payload to DRAM
> MdeModulePkg/DxeCapsuleLibFmp: pass progress callback only if it works
> ArmPkg/PlatformBootManagerLib: call ProcessCapsules() only once
> ArmPkg/ArmSmcPsciResetSystemLib: implement fallback for warm reboot
>
Pushed as 488aab257f70..dde2dd64f070
Thanks all
> ArmPkg/ArmPkg.dec | 4 +
> .../ArmSmcPsciResetSystemLib.c | 21 ++++-
> .../ArmSmcPsciResetSystemLib.inf | 9 ++
> .../PlatformBootManagerLib/PlatformBm.c | 86 +++++++++++++------
> .../PlatformBootManagerLib.inf | 1 +
> .../Library/DxeCapsuleLibFmp/DxeCapsuleLib.c | 13 ++-
> .../CapsuleRuntimeDxe/Arm/CapsuleReset.c | 77 +++++++++++++++++
> .../CapsuleRuntimeDxe/CapsuleReset.c | 51 +++++++++++
> .../CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf | 14 ++-
> .../CapsuleRuntimeDxe/CapsuleService.c | 33 ++-----
> .../CapsuleRuntimeDxe/CapsuleService.h | 73 ++++++++++++++++
> 11 files changed, 321 insertions(+), 61 deletions(-)
> create mode 100644 MdeModulePkg/Universal/CapsuleRuntimeDxe/Arm/CapsuleReset.c
> create mode 100644 MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleReset.c
> create mode 100644 MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleService.h
>
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 10+ messages in thread