Date   

Re: [PATCH v1 6/6] UefiPayloadPkg: Add CpuLib to module INFs that depend on UefiCpuLib.

Guo Dong
 

Reviewed-by: Guo Dong <guo.dong@...>

-----Original Message-----
From: Pu, Yu <yu.pu@...>
Sent: Thursday, March 31, 2022 10:22 PM
To: devel@edk2.groups.io
Cc: Pu, Yu <yu.pu@...>; Dong, Guo <guo.dong@...>; Ni, Ray <ray.ni@...>; Ma, Maurice <maurice.ma@...>; You, Benjamin <benjamin.you@...>; Rhodes, Sean <sean@...>
Subject: [PATCH v1 6/6] UefiPayloadPkg: Add CpuLib to module INFs that depend on UefiCpuLib.

Step 1 to merge UefiCpuLib to CpuLib.

Cc: Guo Dong <guo.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Benjamin You <benjamin.you@...>
Cc: Sean Rhodes <sean@...>
Signed-off-by: Yu Pu <yu.pu@...>
---
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h | 1 +
UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf | 1 +
UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf | 1 +
3 files changed, 3 insertions(+)

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
index 56e0a4c639a0..d1c7425b28f2 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.h
@@ -23,6 +23,7 @@
#include <Library/PeCoffLib.h>

#include <Library/BlParseLib.h>

#include <Library/PlatformSupportLib.h>

+#include <Library/CpuLib.h>

#include <Library/UefiCpuLib.h>

#include <IndustryStandard/Acpi.h>

#include <IndustryStandard/MemoryMappedConfigurationSpaceAccessTable.h>

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
index c4e4339ede4b..95446dd99729 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
+++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.inf
@@ -54,6 +54,7 @@
HobLib

PeCoffLib

PlatformSupportLib

+ CpuLib

UefiCpuLib



[Guids]

diff --git a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf
index 80af5afe0a3f..3b4836042a06 100644
--- a/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf
+++ b/UefiPayloadPkg/UefiPayloadEntry/UniversalPayloadEntry.inf
@@ -52,6 +52,7 @@
IoLib

HobLib

PeCoffLib

+ CpuLib

UefiCpuLib



[Guids]

--
2.30.0.windows.2


Re: [PATCH v1 1/1] UefiPayloadPkg: Add dependency of VariableSmm driver.

Guo Dong
 

Reviewed-by: Guo Dong <guo.dong@...>

-----Original Message-----
From: Li, Zhihao <zhihao.li@...>
Sent: Tuesday, March 29, 2022 12:12 AM
To: devel@edk2.groups.io
Cc: Dong, Guo <guo.dong@...>; Ni, Ray <ray.ni@...>; You, Benjamin <benjamin.you@...>; Rhodes, Sean <sean@...>; Fu, Siyuan <siyuan.fu@...>
Subject: [PATCH v1 1/1] UefiPayloadPkg: Add dependency of VariableSmm driver.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3882

UefiCpuPkg define a new Protocol with the new services SmmWaitForAllProcessor(), which can be used by SMI handler to optionally wait for other APs to complete SMM rendezvous in relaxed AP mode.

VariableSmm driver need use SmmCpuRendezvousLib, So add SmmCpuRendezvousLib dependency in UefiPayloadPkg which use VariableSmm driver.

Cc: Guo Dong <guo.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Benjamin You <benjamin.you@...>
Cc: Sean Rhodes <sean@...>
Cc: Siyuan Fu <siyuan.fu@...>

Signed-off-by: Zhihao Li <zhihao.li@...>
---
UefiPayloadPkg/UefiPayloadPkg.dsc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPayloadPkg.dsc
index 14a8d157a292..a9feba47bbd9 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -3,7 +3,7 @@
# # Provides drivers and definitions to create uefi payload for bootloaders. #-# Copyright (c) 2014 - 2021, Intel Corporation. All rights reserved.<BR>+# Copyright (c) 2014 - 2022, Intel Corporation. All rights reserved.<BR> # Copyright (c) Microsoft Corporation. # SPDX-License-Identifier: BSD-2-Clause-Patent #@@ -352,6 +352,7 @@
SmmCpuFeaturesLib|UefiCpuPkg/Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/SmmCpuExceptionHandlerLib.inf ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf+ SmmCpuRendezvousLib|UefiCpuPkg/Library/SmmCpuRendezvousLib/SmmCpuRendezvousLib.inf !if $(PERFORMANCE_MEASUREMENT_ENABLE) PerformanceLib|MdeModulePkg/Library/SmmPerformanceLib/SmmPerformanceLib.inf !endif--
2.26.2.windows.1


Event: TianoCore Design Meeting - APAC/NAMO - 04/15/2022 #cal-reminder

devel@edk2.groups.io Calendar <noreply@...>
 

Reminder: TianoCore Design Meeting - APAC/NAMO

When:
04/15/2022
9:30am to 10:30am
(UTC+08:00) Asia/Shanghai

Where:
Microsoft Teams

Organizer: Ray Ni ray.ni@...

View Event

Description:

TOPIC

  1. NA

For more info, see here: https://www.tianocore.org/design-meeting/


Microsoft Teams meeting

Join on your computer or mobile app

Click here to join the meeting

Join with a video conferencing device

teams@...

Video Conference ID: 119 715 416 0

Alternate VTC dialing instructions

Learn More | Meeting options


Re: [staging/LoongArch RESEND PATCH v1 00/33] Add a new architecture called LoongArch in EDK II

Abner Chang
 

Hi Li,
I had went through the whole patch set and gave feedbacks to the patch respectively. Apart from those comments, I have no problems with this contribution. I think we can adopt LoongArch port in the mainstream edk2 repo after the comments are addressed and the corresponding spec defined in UEFI spec unless any objections from others.

Thanks
Abner

From: devel@edk2.groups.io <devel@edk2.groups.io> on behalf of Chao Li <lichao@...>
Sent: Wednesday, February 9, 2022 2:51 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: Ray Ni <ray.ni@...>; Liming Gao <gaoliming@...>; Michael D Kinney <michael.d.kinney@...>; Guomin Jiang <guomin.jiang@...>; Wei6 Xu <wei6.xu@...>; Maciej Rabeda <maciej.rabeda@...>; Jiaxin Wu <jiaxin.wu@...>; Siyuan Fu <siyuan.fu@...>; Jiewen Yao <jiewen.yao@...>; Jian J Wang <jian.j.wang@...>; Xiaoyu Lu <xiaoyu1.lu@...>; Zhiguang Liu <zhiguang.liu@...>; Zhichao Gao <zhichao.gao@...>; Bob Feng <bob.c.feng@...>; Yuwei Chen <yuwei.chen@...>
Subject: [edk2-devel] [staging/LoongArch RESEND PATCH v1 00/33] Add a new architecture called LoongArch in EDK II
 
This new Arch should go through the EDK II Code First Process and then
the USWG can review our ECR. This commit contains 34 patchs, patch 0 is
the cover, patch 33 is Readme modification, and the others are the new
Arch support.

Modified modules: FatPkg, FmpDevicePkg, NetworkPkg,
NetworkPkg/HttpBootDxe, CryptoPkg, MdePkg/Include, SecurityPkg,
ShellPkg, UnitTestFrameworkPkg, MdePkg/DxeServicesLib, MdeModulePkg,
.python/SpellCheck, BaseTools, .azurepipelines, .pytool, MdePkg,
MdeModulePkg.

Cc: Ray Ni <ray.ni@...>
Cc: Liming Gao <gaoliming@...>
Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Guomin Jiang <guomin.jiang@...>
Cc: Wei6 Xu <wei6.xu@...>
Cc: Maciej Rabeda <maciej.rabeda@...>
Cc: Jiaxin Wu <jiaxin.wu@...>
Cc: Siyuan Fu <siyuan.fu@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Xiaoyu Lu <xiaoyu1.lu@...>
Cc: Zhiguang Liu <zhiguang.liu@...>
Cc: Zhichao Gao <zhichao.gao@...>
Cc: Bob Feng <bob.c.feng@...>
Cc: Yuwei Chen <yuwei.chen@...>

Chao Li (33):
  FatPkg: Add LOONGARCH64 architecture for EDK2 CI.
  FmpDevicePkg: Add LOONGARCH64 architecture for EDK2 CI.
  NetworkPkg: Add LOONGARCH64 architecture for EDK2 CI.
  NetworkPkg/HttpBootDxe: Add LOONGARCH64 architecture for EDK2 CI.
  CryptoPkg: Add LOONGARCH64 architecture for EDK2 CI.
  MdePkg/Include: Add LOONGARCH related definitions EDK2 CI.
  SecurityPkg: Add LOONGARCH64 architecture for EDK2 CI.
  ShellPkg: Add LOONGARCH64 architecture for EDK2 CI.
  UnitTestFrameworkPkg: Add LOONGARCH64 architecture for EDK2 CI.
  MdePkg/DxeServicesLib: Add LOONGARCH64 architecture
  MdeModulePkg: Use LockBoxNullLib for LOONGARCH64
  .python/SpellCheck: Add "Loongson" and "LOONGARCH" to "words" section
  BaseTools: BaseTools changes for LoongArch platform.
  BaseTools: BaseTools changes for LoongArch platform.
  BaseTools: BaseTools changes for LoongArch platform.
  BaseTools: Enable LoongArch64 architecture for LoongArch64 EDK2 CI.
  .azurepipelines: Add LoongArch64 architecture on LoongArch64 EDK2 CI.
  .pytool: Add LoongArch64 architecture on LoongArch64 EDK2 CI.
  MdePkg: Add LoongArch LOONGARCH64 binding
  MdePkg/Include: LoongArch definitions.
  MdePkg/BaseLib: BaseLib for LOONGARCH64 architecture.
  MdePkg/BaseCacheMaintenanceLib: LoongArch cache maintenance
    implementation.
  MdePkg/BaseIoLibIntrinsic: IoLibNoIo for LoongArch architecture.
  MdePkg/BasePeCoff: Add LoongArch PE/Coff related code.
  MdePkg/BaseCpuLib: LoongArch Base CPU library implementation.
  MdePkg/BaseSynchronizationLib: LoongArch cache related code.
  MdePkg/BaseSafeIntLib: Add LoongArch64 architecture for
    BaseSafeIntLib.
  MdeModulePkg/Logo: Add LoongArch64 architecture.
  MdeModulePkg/CapsuleRuntimeDxe: Add LoongArch64 architecture.
  MdeModulePkg/DxeIplPeim : LoongArch DxeIPL implementation.
  NetworkPkg: Add LoongArch64 architecture.
  BaseTools: Add LoongArch64 binding.
  Readme: Update the readme

 .azurepipelines/Ubuntu-GCC5.yml               |   3 +-
 .pytool/CISettings.py                         |   5 +-
 .pytool/Plugin/SpellCheck/cspell.base.yaml    |   4 +-
 ...gcc_loongarch64_unknown_linux_ext_dep.yaml |  22 ++
 BaseTools/Conf/tools_def.template             |  43 ++-
 .../LinuxGcc5ToolChain/LinuxGcc5ToolChain.py  |  31 +++
 BaseTools/Source/C/Common/BasePeCoff.c        |  15 +-
 BaseTools/Source/C/Common/PeCoffLoaderEx.c    |  76 ++++++
 BaseTools/Source/C/GNUmakefile                |   3 +
 BaseTools/Source/C/GenFv/GenFvInternalLib.c   | 128 ++++++++-
 BaseTools/Source/C/GenFw/Elf64Convert.c       | 153 ++++++++++-
 BaseTools/Source/C/GenFw/elf_common.h         |  58 ++++
 .../C/Include/IndustryStandard/PeImage.h      |  57 ++--
 .../C/Include/LoongArch64/ProcessorBind.h     |  80 ++++++
 BaseTools/Source/Python/Common/DataType.py    |  21 +-
 .../Source/Python/UPT/Library/DataType.py     |  24 +-
 BaseTools/Source/Python/build/buildoptions.py |   3 +-
 CryptoPkg/CryptoPkg.dsc                       |   3 +-
 .../Library/BaseCryptLib/BaseCryptLib.inf     |   6 +-
 .../Library/BaseCryptLib/RuntimeCryptLib.inf  |   4 +
 .../BaseCryptLibNull/BaseCryptLibNull.inf     |   3 +-
 .../BaseCryptLibOnProtocolPpi/DxeCryptLib.inf |   3 +-
 .../BaseCryptLibOnProtocolPpi/PeiCryptLib.inf |   3 +-
 CryptoPkg/Library/Include/CrtLibSupport.h     |   3 +-
 CryptoPkg/Library/OpensslLib/OpensslLib.inf   |   2 +
 .../Library/OpensslLib/OpensslLibCrypto.inf   |   2 +
 CryptoPkg/Library/TlsLib/TlsLib.inf           |   3 +-
 CryptoPkg/Library/TlsLibNull/TlsLibNull.inf   |   3 +-
 FatPkg/FatPkg.dsc                             |   3 +-
 FmpDevicePkg/FmpDevicePkg.dsc                 |   3 +-
 MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf       |   6 +-
 .../Core/DxeIplPeim/LoongArch64/DxeLoadFunc.c |  61 +++++
 MdeModulePkg/Logo/Logo.inf                    |   3 +-
 MdeModulePkg/MdeModulePkg.dsc                 |   4 +-
 .../CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf   |   9 +-
 MdePkg/Include/IndustryStandard/Dhcp.h        |  41 +--
 MdePkg/Include/IndustryStandard/PeImage.h     |   9 +
 MdePkg/Include/Library/BaseLib.h              |  24 ++
 MdePkg/Include/LoongArch64/ProcessorBind.h    | 121 +++++++++
 MdePkg/Include/Protocol/DebugSupport.h        |  65 ++++-
 MdePkg/Include/Protocol/PxeBaseCode.h         |   3 +
 MdePkg/Include/Uefi/UefiBaseType.h            |  14 +
 MdePkg/Include/Uefi/UefiSpec.h                |  16 +-
 .../BaseCacheMaintenanceLib.inf               |   4 +
 .../BaseCacheMaintenanceLib/LoongArchCache.c  | 253 ++++++++++++++++++
 MdePkg/Library/BaseCpuLib/BaseCpuLib.inf      |   7 +-
 MdePkg/Library/BaseCpuLib/BaseCpuLib.uni      |   5 +-
 .../BaseCpuLib/LoongArch/CpuFlushTlb.S        |  15 ++
 .../Library/BaseCpuLib/LoongArch/CpuSleep.S   |  15 ++
 .../BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf |  10 +-
 MdePkg/Library/BaseIoLibIntrinsic/IoLibNoIo.c |   3 +-
 MdePkg/Library/BaseLib/BaseLib.inf            |  13 +
 .../BaseLib/LoongArch64/CpuBreakpoint.S       |  24 ++
 MdePkg/Library/BaseLib/LoongArch64/CpuPause.S |  31 +++
 .../BaseLib/LoongArch64/DisableInterrupts.S   |  21 ++
 .../BaseLib/LoongArch64/EnableInterrupts.S    |  21 ++
 .../BaseLib/LoongArch64/GetInterruptState.S   |  35 +++
 .../BaseLib/LoongArch64/InternalSwitchStack.c |  58 ++++
 .../Library/BaseLib/LoongArch64/MemoryFence.S |  19 ++
 .../BaseLib/LoongArch64/SetJumpLongJump.S     |  49 ++++
 .../Library/BaseLib/LoongArch64/SwitchStack.S |  39 +++
 .../Library/BaseLib/LoongArch64/Unaligned.c   | 244 +++++++++++++++++
 MdePkg/Library/BasePeCoffLib/BasePeCoff.c     |   3 +-
 .../Library/BasePeCoffLib/BasePeCoffLib.inf   |   5 +
 .../Library/BasePeCoffLib/BasePeCoffLib.uni   |   2 +
 .../BasePeCoffLib/LoongArch/PeCoffLoaderEx.c  | 132 +++++++++
 .../Library/BaseSafeIntLib/BaseSafeIntLib.inf |   9 +-
 .../BaseSynchronizationLib.inf                |   5 +
 .../LoongArch64/Synchronization.c             | 239 +++++++++++++++++
 .../Library/DxeServicesLib/DxeServicesLib.inf |   4 +-
 MdePkg/MdePkg.dec                             |   4 +
 MdePkg/MdePkg.dsc                             |   3 +-
 NetworkPkg/HttpBootDxe/HttpBootDhcp4.h        |   3 +
 NetworkPkg/Network.dsc.inc                    |   3 +-
 NetworkPkg/NetworkPkg.dsc                     |   3 +-
 ReadMe.md                                     |  17 ++
 SecurityPkg/SecurityPkg.dsc                   |   3 +-
 ShellPkg/ShellPkg.dsc                         |   3 +-
 UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc |   3 +-
 79 files changed, 2340 insertions(+), 110 deletions(-)
 create mode 100644 BaseTools/Bin/gcc_loongarch64_unknown_linux_ext_dep.yaml
 create mode 100644 BaseTools/Source/C/Include/LoongArch64/ProcessorBind.h
 create mode 100644 MdeModulePkg/Core/DxeIplPeim/LoongArch64/DxeLoadFunc.c
 create mode 100644 MdePkg/Include/LoongArch64/ProcessorBind.h
 create mode 100644 MdePkg/Library/BaseCacheMaintenanceLib/LoongArchCache.c
 create mode 100644 MdePkg/Library/BaseCpuLib/LoongArch/CpuFlushTlb.S
 create mode 100644 MdePkg/Library/BaseCpuLib/LoongArch/CpuSleep.S
 create mode 100644 MdePkg/Library/BaseLib/LoongArch64/CpuBreakpoint.S
 create mode 100644 MdePkg/Library/BaseLib/LoongArch64/CpuPause.S
 create mode 100644 MdePkg/Library/BaseLib/LoongArch64/DisableInterrupts.S
 create mode 100644 MdePkg/Library/BaseLib/LoongArch64/EnableInterrupts.S
 create mode 100644 MdePkg/Library/BaseLib/LoongArch64/GetInterruptState.S
 create mode 100644 MdePkg/Library/BaseLib/LoongArch64/InternalSwitchStack.c
 create mode 100644 MdePkg/Library/BaseLib/LoongArch64/MemoryFence.S
 create mode 100644 MdePkg/Library/BaseLib/LoongArch64/SetJumpLongJump.S
 create mode 100644 MdePkg/Library/BaseLib/LoongArch64/SwitchStack.S
 create mode 100644 MdePkg/Library/BaseLib/LoongArch64/Unaligned.c
 create mode 100644 MdePkg/Library/BasePeCoffLib/LoongArch/PeCoffLoaderEx.c
 create mode 100644 MdePkg/Library/BaseSynchronizationLib/LoongArch64/Synchronization.c
 create mode 100644 ReadMe.md

--
2.27.0







Re: [PATCH v2 0/3] BaseTools: Add support for gdb and lldb

Bob Feng
 

-----Original Message-----
From: Rebecca Cran <quic_rcran@...>
Sent: Thursday, April 7, 2022 6:34 AM
To: devel@edk2.groups.io; Leif Lindholm <quic_llindhol@...>; Kinney, Michael D <michael.d.kinney@...>; Wu, Hao A <hao.a.wu@...>; Feng, Bob C <bob.c.feng@...>; Gao, Liming <gaoliming@...>; Chen, Christine <yuwei.chen@...>
Cc: Andrew Fish <afish@...>
Subject: Re: [PATCH v2 0/3] BaseTools: Add support for gdb and lldb

Could I have some more reviews on this please? I'd like to get this into the tree soon.

--
Rebecca Cran

On 3/21/22 14:20, Rebecca Cran wrote:
This patch set adds debugging support for gdb and lldb.
It also adds generic debugging classes that use a file like object to
make it easy to import into any debugger that supports Python.

Changes from v1 to v2:
- Moved scripts from the root of the repo into BaseTools/Scripts.
- Fixed typo of "RISCV" as "RISKV".

Testing:
- Tested gdb on Ubuntu and lldb on macOS for IA32 and X64.
- Tested gdb on openSUSE for AARCH64.

Rebecca Cran (3):
BaseTools: efi_debugging.py: Add debugger agnostic dbg Python Classes
BaseTools: Scripts/efi_gdb.py: Add gdb EFI commands and pretty Print
BaseTools: Scripts/efi_lldb.py: Add lldb EFI commands and pretty
Print

BaseTools/Scripts/efi_debugging.py | 2185 ++++++++++++++++++++
BaseTools/Scripts/efi_gdb.py | 918 ++++++++
BaseTools/Scripts/efi_lldb.py | 1044 ++++++++++
3 files changed, 4147 insertions(+)
create mode 100755 BaseTools/Scripts/efi_debugging.py
create mode 100755 BaseTools/Scripts/efi_gdb.py
create mode 100755 BaseTools/Scripts/efi_lldb.py


Re: [PATCH v2 3/3] BaseTools: Scripts/efi_lldb.py: Add lldb EFI commands and pretty Print

Bob Feng
 

Reviewed-by: Bob Feng <bob.c.feng@...>


On Tue, Mar 22, 2022 at 04:21 AM, Rebecca Cran wrote:
https://bugzilla.tianocore.org/show_bug.cgi?id=3500

Use efi_debugging.py Python Classes to implement EFI gdb commands:
efi_symbols, guid, table, hob, and devicepath

You can attach to any standard gdb or kdp remote server and get EFI
symbols. No modifications of EFI are required.

Example usage:
OvmfPkg/build.sh qemu -gdb tcp::9000
lldb -o "gdb-remote localhost:9000" -o "command script import efi_lldb.py"
Note you may also have to teach lldb about QEMU:
-o "settings set plugin.process.gdb-remote.target-definition-file
x86_64_target_definition.py"

Cc: Leif Lindholm <quic_llindhol@...>
Cc: Michael D Kinney <michael.d.kinney@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: Bob Feng <bob.c.feng@...>
Cc: Liming Gao <gaoliming@...>
Cc: Yuwei Chen <yuwei.chen@...>
Signed-off-by: Rebecca Cran <quic_rcran@...>
---
BaseTools/Scripts/efi_lldb.py | 1044 ++++++++++++++++++++
1 file changed, 1044 insertions(+)

diff --git a/BaseTools/Scripts/efi_lldb.py b/BaseTools/Scripts/efi_lldb.py
new file mode 100755
index 000000000000..089b6ba58ab8
--- /dev/null
+++ b/BaseTools/Scripts/efi_lldb.py
@@ -0,0 +1,1044 @@
+#!/usr/bin/python3
+'''
+Copyright (c) Apple Inc. 2021
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+Example usage:
+OvmfPkg/build.sh qemu -gdb tcp::9000
+lldb -o "gdb-remote localhost:9000" -o "command script import efi_lldb.py"
+'''
+
+import optparse
+import shlex
+import subprocess
+import uuid
+import sys
+import os
+from pathlib import Path
+from efi_debugging import EfiDevicePath, EfiConfigurationTable, EfiTpl
+from efi_debugging import EfiHob, GuidNames, EfiStatusClass, EfiBootMode
+from efi_debugging import PeTeImage, patch_ctypes
+
+try:
+ # Just try for LLDB in case PYTHONPATH is already correctly setup
+ import lldb
+except ImportError:
+ try:
+ env = os.environ.copy()
+ env['LLDB_DEFAULT_PYTHON_VERSION'] = str(sys.version_info.major)
+ lldb_python_path = subprocess.check_output(
+ ["xcrun", "lldb", "-P"], env=env).decode("utf-8").strip()
+ sys.path.append(lldb_python_path)
+ import lldb
+ except ValueError:
+ print("Couldn't find LLDB.framework from lldb -P")
+ print("PYTHONPATH should match the currently selected lldb")
+ sys.exit(-1)
+
+
+class LldbFileObject(object):
+ '''
+ Class that fakes out file object to abstract lldb from the generic code.
+ For lldb this is memory so we don't have a concept of the end of the file.
+ '''
+
+ def __init__(self, process):
+ # _exe_ctx is lldb.SBExecutionContext
+ self._process = process
+ self._offset = 0
+ self._SBError = lldb.SBError()
+
+ def tell(self):
+ return self._offset
+
+ def read(self, size=-1):
+ if size == -1:
+ # arbitrary default size
+ size = 0x1000000
+
+ data = self._process.ReadMemory(self._offset, size, self._SBError)
+ if self._SBError.fail:
+ raise MemoryError(
+ f'lldb could not read memory 0x{size:x} '
+ f' bytes from 0x{self._offset:08x}')
+ else:
+ return data
+
+ def readable(self):
+ return True
+
+ def seek(self, offset, whence=0):
+ if whence == 0:
+ self._offset = offset
+ elif whence == 1:
+ self._offset += offset
+ else:
+ # whence == 2 is seek from end
+ raise NotImplementedError
+
+ def seekable(self):
+ return True
+
+ def write(self, data):
+ result = self._process.WriteMemory(self._offset, data, self._SBError)
+ if self._SBError.fail:
+ raise MemoryError(
+ f'lldb could not write memory to 0x{self._offset:08x}')
+ return result
+
+ def writable(self):
+ return True
+
+ def truncate(self, size=None):
+ raise NotImplementedError
+
+ def flush(self):
+ raise NotImplementedError
+
+ def fileno(self):
+ raise NotImplementedError
+
+
+class EfiSymbols:
+ """
+ Class to manage EFI Symbols
+ You need to pass file, and exe_ctx to load symbols.
+ You can print(EfiSymbols()) to see the currently loaded symbols
+ """
+
+ loaded = {}
+ stride = None
+ range = None
+ verbose = False
+
+ def __init__(self, target=None):
+ if target:
+ EfiSymbols.target = target
+ EfiSymbols._file = LldbFileObject(target.process)
+
+ @ classmethod
+ def __str__(cls):
+ return ''.join(f'{pecoff}\n' for (pecoff, _) in cls.loaded.values())
+
+ @ classmethod
+ def configure_search(cls, stride, range, verbose=False):
+ cls.stride = stride
+ cls.range = range
+ cls.verbose = verbose
+
+ @ classmethod
+ def clear(cls):
+ cls.loaded = {}
+
+ @ classmethod
+ def add_symbols_for_pecoff(cls, pecoff):
+ '''Tell lldb the location of the .text and .data sections.'''
+
+ if pecoff.LoadAddress in cls.loaded:
+ return 'Already Loaded: '
+
+ module = cls.target.AddModule(None, None, str(pecoff.CodeViewUuid))
+ if not module:
+ module = cls.target.AddModule(pecoff.CodeViewPdb,
+ None,
+ str(pecoff.CodeViewUuid))
+ if module.IsValid():
+ SBError = cls.target.SetModuleLoadAddress(
+ module, pecoff.LoadAddress + pecoff.TeAdjust)
+ if SBError.success:
+ cls.loaded[pecoff.LoadAddress] = (pecoff, module)
+ return ''
+
+ return 'Symbols NOT FOUND: '
+
+ @ classmethod
+ def address_to_symbols(cls, address, reprobe=False):
+ '''
+ Given an address search backwards for a PE/COFF (or TE) header
+ and load symbols. Return a status string.
+ '''
+ if not isinstance(address, int):
+ address = int(address)
+
+ pecoff, _ = cls.address_in_loaded_pecoff(address)
+ if not reprobe and pecoff is not None:
+ # skip the probe of the remote
+ return f'{pecoff} is already loaded'
+
+ pecoff = PeTeImage(cls._file, None)
+ if pecoff.pcToPeCoff(address, cls.stride, cls.range):
+ res = cls.add_symbols_for_pecoff(pecoff)
+ return f'{res}{pecoff}'
+ else:
+ return f'0x{address:08x} not in a PE/COFF (or TE) image'
+
+ @ classmethod
+ def address_in_loaded_pecoff(cls, address):
+ if not isinstance(address, int):
+ address = int(address)
+
+ for (pecoff, module) in cls.loaded.values():
+ if (address >= pecoff.LoadAddress and
+ address <= pecoff.EndLoadAddress):
+
+ return pecoff, module
+
+ return None, None
+
+ @ classmethod
+ def unload_symbols(cls, address):
+ pecoff, module = cls.address_in_loaded_pecoff(address)
+ if module:
+ name = str(module)
+ cls.target.ClearModuleLoadAddress(module)
+ cls.target.RemoveModule(module)
+ del cls.loaded[pecoff.LoadAddress]
+ return f'{name:s} was unloaded'
+ return f'0x{address:x} was not in a loaded image'
+
+
+def arg_to_address(frame, arg):
+ ''' convert an lldb command arg into a memory address (addr_t)'''
+
+ if arg is None:
+ return None
+
+ arg_str = arg if isinstance(arg, str) else str(arg)
+ SBValue = frame.EvaluateExpression(arg_str)
+ if SBValue.error.fail:
+ return arg
+
+ if (SBValue.TypeIsPointerType() or
+ SBValue.value_type == lldb.eValueTypeRegister or
+ SBValue.value_type == lldb.eValueTypeRegisterSet or
+ SBValue.value_type == lldb.eValueTypeConstResult):
+ try:
+ addr = SBValue.GetValueAsAddress()
+ except ValueError:
+ addr = SBValue.unsigned
+ else:
+ try:
+ addr = SBValue.address_of.GetValueAsAddress()
+ except ValueError:
+ addr = SBValue.address_of.unsigned
+
+ return addr
+
+
+def arg_to_data(frame, arg):
+ ''' convert an lldb command arg into a data vale (uint32_t/uint64_t)'''
+ if not isinstance(arg, str):
+ arg_str = str(str)
+
+ SBValue = frame.EvaluateExpression(arg_str)
+ return SBValue.unsigned
+
+
+class EfiDevicePathCommand:
+
+ def create_options(self):
+ ''' standard lldb command help/options parser'''
+ usage = "usage: %prog [options]"
+ description = '''Command that can EFI Config Tables
+'''
+
+ # Pass add_help_option = False, since this keeps the command in line
+ # with lldb commands, and we wire up "help command" to work by
+ # providing the long & short help methods below.
+ self.parser = optparse.OptionParser(
+ description=description,
+ prog='devicepath',
+ usage=usage,
+ add_help_option=False)
+
+ self.parser.add_option(
+ '-v',
+ '--verbose',
+ action='store_true',
+ dest='verbose',
+ help='hex dump extra data',
+ default=False)
+
+ self.parser.add_option(
+ '-n',
+ '--node',
+ action='store_true',
+ dest='node',
+ help='dump a single device path node',
+ default=False)
+
+ self.parser.add_option(
+ '-h',
+ '--help',
+ action='store_true',
+ dest='help',
+ help='Show help for the command',
+ default=False)
+
+ def get_short_help(self):
+ '''standard lldb function method'''
+ return "Display EFI Tables"
+
+ def get_long_help(self):
+ '''standard lldb function method'''
+ return self.help_string
+
+ def __init__(self, debugger, internal_dict):
+ '''standard lldb function method'''
+ self.create_options()
+ self.help_string = self.parser.format_help()
+
+ def __call__(self, debugger, command, exe_ctx, result):
+ '''standard lldb function method'''
+ # Use the Shell Lexer to properly parse up command options just like a
+ # shell would
+ command_args = shlex.split(command)
+
+ try:
+ (options, args) = self.parser.parse_args(command_args)
+ dev_list = []
+ for arg in args:
+ dev_list.append(arg_to_address(exe_ctx.frame, arg))
+ except ValueError:
+ # if you don't handle exceptions, passing an incorrect argument
+ # to the OptionParser will cause LLDB to exit (courtesy of
+ # OptParse dealing with argument errors by throwing SystemExit)
+ result.SetError("option parsing failed")
+ return
+
+ if options.help:
+ self.parser.print_help()
+ return
+
+ file = LldbFileObject(exe_ctx.process)
+
+ for dev_addr in dev_list:
+ if options.node:
+ print(EfiDevicePath(file).device_path_node_str(
+ dev_addr, options.verbose))
+ else:
+ device_path = EfiDevicePath(file, dev_addr, options.verbose)
+ if device_path.valid():
+ print(device_path)
+
+
+class EfiHobCommand:
+ def create_options(self):
+ ''' standard lldb command help/options parser'''
+ usage = "usage: %prog [options]"
+ description = '''Command that can EFI dump EFI HOBs'''
+
+ # Pass add_help_option = False, since this keeps the command in line
+ # with lldb commands, and we wire up "help command" to work by
+ # providing the long & short help methods below.
+ self.parser = optparse.OptionParser(
+ description=description,
+ prog='table',
+ usage=usage,
+ add_help_option=False)
+
+ self.parser.add_option(
+ '-a',
+ '--address',
+ type="int",
+ dest='address',
+ help='Parse HOBs from address',
+ default=None)
+
+ self.parser.add_option(
+ '-t',
+ '--type',
+ type="int",
+ dest='type',
+ help='Only dump HOBS of his type',
+ default=None)
+
+ self.parser.add_option(
+ '-v',
+ '--verbose',
+ action='store_true',
+ dest='verbose',
+ help='hex dump extra data',
+ default=False)
+
+ self.parser.add_option(
+ '-h',
+ '--help',
+ action='store_true',
+ dest='help',
+ help='Show help for the command',
+ default=False)
+
+ def get_short_help(self):
+ '''standard lldb function method'''
+ return "Display EFI Hobs"
+
+ def get_long_help(self):
+ '''standard lldb function method'''
+ return self.help_string
+
+ def __init__(self, debugger, internal_dict):
+ '''standard lldb function method'''
+ self.create_options()
+ self.help_string = self.parser.format_help()
+
+ def __call__(self, debugger, command, exe_ctx, result):
+ '''standard lldb function method'''
+ # Use the Shell Lexer to properly parse up command options just like a
+ # shell would
+ command_args = shlex.split(command)
+
+ try:
+ (options, _) = self.parser.parse_args(command_args)
+ except ValueError:
+ # if you don't handle exceptions, passing an incorrect argument
+ # to the OptionParser will cause LLDB to exit (courtesy of
+ # OptParse dealing with argument errors by throwing SystemExit)
+ result.SetError("option parsing failed")
+ return
+
+ if options.help:
+ self.parser.print_help()
+ return
+
+ address = arg_to_address(exe_ctx.frame, options.address)
+
+ file = LldbFileObject(exe_ctx.process)
+ hob = EfiHob(file, address, options.verbose).get_hob_by_type(
+ options.type)
+ print(hob)
+
+
+class EfiTableCommand:
+
+ def create_options(self):
+ ''' standard lldb command help/options parser'''
+ usage = "usage: %prog [options]"
+ description = '''Command that can display EFI Config Tables
+'''
+
+ # Pass add_help_option = False, since this keeps the command in line
+ # with lldb commands, and we wire up "help command" to work by
+ # providing the long & short help methods below.
+ self.parser = optparse.OptionParser(
+ description=description,
+ prog='table',
+ usage=usage,
+ add_help_option=False)
+
+ self.parser.add_option(
+ '-h',
+ '--help',
+ action='store_true',
+ dest='help',
+ help='Show help for the command',
+ default=False)
+
+ def get_short_help(self):
+ '''standard lldb function method'''
+ return "Display EFI Tables"
+
+ def get_long_help(self):
+ '''standard lldb function method'''
+ return self.help_string
+
+ def __init__(self, debugger, internal_dict):
+ '''standard lldb function method'''
+ self.create_options()
+ self.help_string = self.parser.format_help()
+
+ def __call__(self, debugger, command, exe_ctx, result):
+ '''standard lldb function method'''
+ # Use the Shell Lexer to properly parse up command options just like a
+ # shell would
+ command_args = shlex.split(command)
+
+ try:
+ (options, _) = self.parser.parse_args(command_args)
+ except ValueError:
+ # if you don't handle exceptions, passing an incorrect argument
+ # to the OptionParser will cause LLDB to exit (courtesy of
+ # OptParse dealing with argument errors by throwing SystemExit)
+ result.SetError("option parsing failed")
+ return
+
+ if options.help:
+ self.parser.print_help()
+ return
+
+ gST = exe_ctx.target.FindFirstGlobalVariable('gST')
+ if gST.error.fail:
+ print('Error: This command requires symbols for gST to be loaded')
+ return
+
+ file = LldbFileObject(exe_ctx.process)
+ table = EfiConfigurationTable(file, gST.unsigned)
+ if table:
+ print(table, '\n')
+
+
+class EfiGuidCommand:
+
+ def create_options(self):
+ ''' standard lldb command help/options parser'''
+ usage = "usage: %prog [options]"
+ description = '''
+ Command that can display all EFI GUID's or give info on a
+ specific GUID's
+ '''
+ self.parser = optparse.OptionParser(
+ description=description,
+ prog='guid',
+ usage=usage,
+ add_help_option=False)
+
+ self.parser.add_option(
+ '-n',
+ '--new',
+ action='store_true',
+ dest='new',
+ help='Generate a new GUID',
+ default=False)
+
+ self.parser.add_option(
+ '-v',
+ '--verbose',
+ action='store_true',
+ dest='verbose',
+ help='Also display GUID C structure values',
+ default=False)
+
+ self.parser.add_option(
+ '-h',
+ '--help',
+ action='store_true',
+ dest='help',
+ help='Show help for the command',
+ default=False)
+
+ def get_short_help(self):
+ '''standard lldb function method'''
+ return "Display EFI GUID's"
+
+ def get_long_help(self):
+ '''standard lldb function method'''
+ return self.help_string
+
+ def __init__(self, debugger, internal_dict):
+ '''standard lldb function method'''
+ self.create_options()
+ self.help_string = self.parser.format_help()
+
+ def __call__(self, debugger, command, exe_ctx, result):
+ '''standard lldb function method'''
+ # Use the Shell Lexer to properly parse up command options just like a
+ # shell would
+ command_args = shlex.split(command)
+
+ try:
+ (options, args) = self.parser.parse_args(command_args)
+ if len(args) >= 1:
+ # guid { 0x414e6bdd, 0xe47b, 0x47cc,
+ # { 0xb2, 0x44, 0xbb, 0x61, 0x02, 0x0c,0xf5, 0x16 }}
+ # this generates multiple args
+ arg = ' '.join(args)
+ except ValueError:
+ # if you don't handle exceptions, passing an incorrect argument
+ # to the OptionParser will cause LLDB to exit (courtesy of
+ # OptParse dealing with argument errors by throwing SystemExit)
+ result.SetError("option parsing failed")
+ return
+
+ if options.help:
+ self.parser.print_help()
+ return
+
+ if options.new:
+ guid = uuid.uuid4()
+ print(str(guid).upper())
+ print(GuidNames.to_c_guid(guid))
+ return
+
+ if len(args) > 0:
+ if GuidNames.is_guid_str(arg):
+ # guid 05AD34BA-6F02-4214-952E-4DA0398E2BB9
+ key = arg.lower()
+ name = GuidNames.to_name(key)
+ elif GuidNames.is_c_guid(arg):
+ # guid { 0x414e6bdd, 0xe47b, 0x47cc,
+ # { 0xb2, 0x44, 0xbb, 0x61, 0x02, 0x0c,0xf5, 0x16 }}
+ key = GuidNames.from_c_guid(arg)
+ name = GuidNames.to_name(key)
+ else:
+ # guid gEfiDxeServicesTableGuid
+ name = arg
+ try:
+ key = GuidNames.to_guid(name)
+ name = GuidNames.to_name(key)
+ except ValueError:
+ return
+
+ extra = f'{GuidNames.to_c_guid(key)}: ' if options.verbose else ''
+ print(f'{key}: {extra}{name}')
+
+ else:
+ for key, value in GuidNames._dict_.items():
+ if options.verbose:
+ extra = f'{GuidNames.to_c_guid(key)}: '
+ else:
+ extra = ''
+ print(f'{key}: {extra}{value}')
+
+
+class EfiSymbolicateCommand(object):
+ '''Class to abstract an lldb command'''
+
+ def create_options(self):
+ ''' standard lldb command help/options parser'''
+ usage = "usage: %prog [options]"
+ description = '''Command that can load EFI PE/COFF and TE image
+ symbols. If you are having trouble in PEI try adding --pei.
+ '''
+
+ # Pass add_help_option = False, since this keeps the command in line
+ # with lldb commands, and we wire up "help command" to work by
+ # providing the long & short help methods below.
+ self.parser = optparse.OptionParser(
+ description=description,
+ prog='efi_symbols',
+ usage=usage,
+ add_help_option=False)
+
+ self.parser.add_option(
+ '-a',
+ '--address',
+ type="int",
+ dest='address',
+ help='Load symbols for image at address',
+ default=None)
+
+ self.parser.add_option(
+ '-f',
+ '--frame',
+ action='store_true',
+ dest='frame',
+ help='Load symbols for current stack frame',
+ default=False)
+
+ self.parser.add_option(
+ '-p',
+ '--pc',
+ action='store_true',
+ dest='pc',
+ help='Load symbols for pc',
+ default=False)
+
+ self.parser.add_option(
+ '--pei',
+ action='store_true',
+ dest='pei',
+ help='Load symbols for PEI (searches every 4 bytes)',
+ default=False)
+
+ self.parser.add_option(
+ '-e',
+ '--extended',
+ action='store_true',
+ dest='extended',
+ help='Try to load all symbols based on config tables.',
+ default=False)
+
+ self.parser.add_option(
+ '-r',
+ '--range',
+ type="long",
+ dest='range',
+ help='How far to search backward for start of PE/COFF Image',
+ default=None)
+
+ self.parser.add_option(
+ '-s',
+ '--stride',
+ type="long",
+ dest='stride',
+ help='Boundary to search for PE/COFF header',
+ default=None)
+
+ self.parser.add_option(
+ '-t',
+ '--thread',
+ action='store_true',
+ dest='thread',
+ help='Load symbols for the frames of all threads',
+ default=False)
+
+ self.parser.add_option(
+ '-h',
+ '--help',
+ action='store_true',
+ dest='help',
+ help='Show help for the command',
+ default=False)
+
+ def get_short_help(self):
+ '''standard lldb function method'''
+ return (
+ "Load symbols based on an address that is part of"
+ " a PE/COFF EFI image.")
+
+ def get_long_help(self):
+ '''standard lldb function method'''
+ return self.help_string
+
+ def __init__(self, debugger, unused):
+ '''standard lldb function method'''
+ self.create_options()
+ self.help_string = self.parser.format_help()
+
+ def lldb_print(self, lldb_str):
+ # capture command out like an lldb command
+ self.result.PutCString(lldb_str)
+ # flush the output right away
+ self.result.SetImmediateOutputFile(
+ self.exe_ctx.target.debugger.GetOutputFile())
+
+ def __call__(self, debugger, command, exe_ctx, result):
+ '''standard lldb function method'''
+ # Use the Shell Lexer to properly parse up command options just like a
+ # shell would
+ command_args = shlex.split(command)
+
+ try:
+ (options, _) = self.parser.parse_args(command_args)
+ except ValueError:
+ # if you don't handle exceptions, passing an incorrect argument
+ # to the OptionParser will cause LLDB to exit (courtesy of
+ # OptParse dealing with argument errors by throwing SystemExit)
+ result.SetError("option parsing failed")
+ return
+
+ if options.help:
+ self.parser.print_help()
+ return
+
+ file = LldbFileObject(exe_ctx.process)
+ efi_symbols = EfiSymbols(exe_ctx.target)
+ self.result = result
+ self.exe_ctx = exe_ctx
+
+ if options.pei:
+ # XIP code ends up on a 4 byte boundary.
+ options.stride = 4
+ options.range = 0x100000
+ efi_symbols.configure_search(options.stride, options.range)
+
+ if not options.pc and options.address is None:
+ # default to
+ options.frame = True
+
+ if options.frame:
+ if not exe_ctx.frame.IsValid():
+ result.SetError("invalid frame")
+ return
+
+ threads = exe_ctx.process.threads if options.thread else [
+ exe_ctx.thread]
+
+ for thread in threads:
+ for frame in thread:
+ res = efi_symbols.address_to_symbols(frame.pc)
+ self.lldb_print(res)
+
+ else:
+ if options.address is not None:
+ address = options.address
+ elif options.pc:
+ try:
+ address = exe_ctx.thread.GetSelectedFrame().pc
+ except ValueError:
+ result.SetError("invalid pc")
+ return
+ else:
+ address = 0
+
+ res = efi_symbols.address_to_symbols(address.pc)
+ print(res)
+
+ if options.extended:
+
+ gST = exe_ctx.target.FindFirstGlobalVariable('gST')
+ if gST.error.fail:
+ print('Error: This command requires symbols to be loaded')
+ else:
+ table = EfiConfigurationTable(file, gST.unsigned)
+ for address, _ in table.DebugImageInfo():
+ res = efi_symbols.address_to_symbols(address)
+ self.lldb_print(res)
+
+ # keep trying module file names until we find a GUID xref file
+ for m in exe_ctx.target.modules:
+ if GuidNames.add_build_guid_file(str(m.file)):
+ break
+
+
+def CHAR16_TypeSummary(valobj, internal_dict):
+ '''
+ Display CHAR16 as a String in the debugger.
+ Note: utf-8 is returned as that is the value for the debugger.
+ '''
+ SBError = lldb.SBError()
+ Str = ''
+ if valobj.TypeIsPointerType():
+ if valobj.GetValueAsUnsigned() == 0:
+ return "NULL"
+
+ # CHAR16 * max string size 1024
+ for i in range(1024):
+ Char = valobj.GetPointeeData(i, 1).GetUnsignedInt16(SBError, 0)
+ if SBError.fail or Char == 0:
+ break
+ Str += chr(Char)
+ return 'L"' + Str + '"'
+
+ if valobj.num_children == 0:
+ # CHAR16
+ return "L'" + chr(valobj.unsigned) + "'"
+
+ else:
+ # CHAR16 []
+ for i in range(valobj.num_children):
+ Char = valobj.GetChildAtIndex(i).data.GetUnsignedInt16(SBError, 0)
+ if Char == 0:
+ break
+ Str += chr(Char)
+ return 'L"' + Str + '"'
+
+ return Str
+
+
+def CHAR8_TypeSummary(valobj, internal_dict):
+ '''
+ Display CHAR8 as a String in the debugger.
+ Note: utf-8 is returned as that is the value for the debugger.
+ '''
+ SBError = lldb.SBError()
+ Str = ''
+ if valobj.TypeIsPointerType():
+ if valobj.GetValueAsUnsigned() == 0:
+ return "NULL"
+
+ # CHAR8 * max string size 1024
+ for i in range(1024):
+ Char = valobj.GetPointeeData(i, 1).GetUnsignedInt8(SBError, 0)
+ if SBError.fail or Char == 0:
+ break
+ Str += chr(Char)
+ Str = '"' + Str + '"'
+ return Str
+
+ if valobj.num_children == 0:
+ # CHAR8
+ return "'" + chr(valobj.unsigned) + "'"
+ else:
+ # CHAR8 []
+ for i in range(valobj.num_children):
+ Char = valobj.GetChildAtIndex(i).data.GetUnsignedInt8(SBError, 0)
+ if SBError.fail or Char == 0:
+ break
+ Str += chr(Char)
+ return '"' + Str + '"'
+
+ return Str
+
+
+def EFI_STATUS_TypeSummary(valobj, internal_dict):
+ if valobj.TypeIsPointerType():
+ return ''
+ return str(EfiStatusClass(valobj.unsigned))
+
+
+def EFI_TPL_TypeSummary(valobj, internal_dict):
+ if valobj.TypeIsPointerType():
+ return ''
+ return str(EfiTpl(valobj.unsigned))
+
+
+def EFI_GUID_TypeSummary(valobj, internal_dict):
+ if valobj.TypeIsPointerType():
+ return ''
+ return str(GuidNames(bytes(valobj.data.uint8)))
+
+
+def EFI_BOOT_MODE_TypeSummary(valobj, internal_dict):
+ if valobj.TypeIsPointerType():
+ return ''
+ '''Return #define name for EFI_BOOT_MODE'''
+ return str(EfiBootMode(valobj.unsigned))
+
+
+def lldb_type_formaters(debugger, mod_name):
+ '''Teach lldb about EFI types'''
+
+ category = debugger.GetDefaultCategory()
+ FormatBool = lldb.SBTypeFormat(lldb.eFormatBoolean)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("BOOLEAN"), FormatBool)
+
+ FormatHex = lldb.SBTypeFormat(lldb.eFormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT64"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT64"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT32"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT32"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT16"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT16"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINT8"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("INT8"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("UINTN"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("INTN"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("CHAR8"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("CHAR16"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier(
+ "EFI_PHYSICAL_ADDRESS"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier(
+ "PHYSICAL_ADDRESS"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier("EFI_LBA"), FormatHex)
+ category.AddTypeFormat(
+ lldb.SBTypeNameSpecifier("EFI_BOOT_MODE"), FormatHex)
+ category.AddTypeFormat(lldb.SBTypeNameSpecifier(
+ "EFI_FV_FILETYPE"), FormatHex)
+
+ #
+ # Smart type printing for EFI
+ #
+
+ debugger.HandleCommand(
+ f'type summary add GUID - -python-function '
+ f'{mod_name}.EFI_GUID_TypeSummary')
+ debugger.HandleCommand(
+ f'type summary add EFI_GUID --python-function '
+ f'{mod_name}.EFI_GUID_TypeSummary')
+ debugger.HandleCommand(
+ f'type summary add EFI_STATUS --python-function '
+ f'{mod_name}.EFI_STATUS_TypeSummary')
+ debugger.HandleCommand(
+ f'type summary add EFI_TPL - -python-function '
+ f'{mod_name}.EFI_TPL_TypeSummary')
+ debugger.HandleCommand(
+ f'type summary add EFI_BOOT_MODE --python-function '
+ f'{mod_name}.EFI_BOOT_MODE_TypeSummary')
+
+ debugger.HandleCommand(
+ f'type summary add CHAR16 --python-function '
+ f'{mod_name}.CHAR16_TypeSummary')
+
+ # W605 this is the correct escape sequence for the lldb command
+ debugger.HandleCommand(
+ f'type summary add --regex "CHAR16 \[[0-9]+\]" ' # noqa: W605
+ f'--python-function {mod_name}.CHAR16_TypeSummary')
+
+ debugger.HandleCommand(
+ f'type summary add CHAR8 --python-function '
+ f'{mod_name}.CHAR8_TypeSummary')
+
+ # W605 this is the correct escape sequence for the lldb command
+ debugger.HandleCommand(
+ f'type summary add --regex "CHAR8 \[[0-9]+\]" ' # noqa: W605
+ f'--python-function {mod_name}.CHAR8_TypeSummary')
+
+
+class LldbWorkaround:
+ needed = True
+
+ @classmethod
+ def activate(cls):
+ if cls.needed:
+ lldb.debugger.HandleCommand("process handle SIGALRM -n false")
+ cls.needed = False
+
+
+def LoadEmulatorEfiSymbols(frame, bp_loc, internal_dict):
+ #
+ # This is an lldb breakpoint script, and assumes the breakpoint is on a
+ # function with the same prototype as SecGdbScriptBreak(). The
+ # argument names are important as lldb looks them up.
+ #
+ # VOID
+ # SecGdbScriptBreak (
+ # char *FileName,
+ # int FileNameLength,
+ # long unsigned int LoadAddress,
+ # int AddSymbolFlag
+ # )
+ # {
+ # return;
+ # }
+ #
+ # When the emulator loads a PE/COFF image, it calls the stub function with
+ # the filename of the symbol file, the length of the FileName, the
+ # load address and a flag to indicate if this is a load or unload operation
+ #
+ LldbWorkaround().activate()
+
+ symbols = EfiSymbols(frame.thread.process.target)
+ LoadAddress = frame.FindVariable("LoadAddress").unsigned
+ if frame.FindVariable("AddSymbolFlag").unsigned == 1:
+ res = symbols.address_to_symbols(LoadAddress)
+ else:
+ res = symbols.unload_symbols(LoadAddress)
+ print(res)
+
+ # make breakpoint command continue
+ return False
+
+
+def __lldb_init_module(debugger, internal_dict):
+ '''
+ This initializer is being run from LLDB in the embedded command interpreter
+ '''
+
+ mod_name = Path(__file__).stem
+ lldb_type_formaters(debugger, mod_name)
+
+ # Add any commands contained in this module to LLDB
+ debugger.HandleCommand(
+ f'command script add -c {mod_name}.EfiSymbolicateCommand efi_symbols')
+ debugger.HandleCommand(
+ f'command script add -c {mod_name}.EfiGuidCommand guid')
+ debugger.HandleCommand(
+ f'command script add -c {mod_name}.EfiTableCommand table')
+ debugger.HandleCommand(
+ f'command script add -c {mod_name}.EfiHobCommand hob')
+ debugger.HandleCommand(
+ f'command script add -c {mod_name}.EfiDevicePathCommand devicepath')
+
+ print('EFI specific commands have been installed.')
+
+ # patch the ctypes c_void_p values if the debuggers OS and EFI have
+ # different ideas on the size of the debug.
+ try:
+ patch_ctypes(debugger.GetSelectedTarget().addr_size)
+ except ValueError:
+ # incase the script is imported and the debugger has not target
+ # defaults to sizeof(UINTN) == sizeof(UINT64)
+ patch_ctypes()
+
+ try:
+ target = debugger.GetSelectedTarget()
+ if target.FindFunctions('SecGdbScriptBreak').symbols:
+ breakpoint = target.BreakpointCreateByName('SecGdbScriptBreak')
+ # Set the emulator breakpoints, if we are in the emulator
+ cmd = 'breakpoint command add -s python -F '
+ cmd += f'efi_lldb.LoadEmulatorEfiSymbols {breakpoint.GetID()}'
+ debugger.HandleCommand(cmd)
+ print('Type r to run emulator.')
+ else:
+ raise ValueError("No Emulator Symbols")
+
+ except ValueError:
+ # default action when the script is imported
+ debugger.HandleCommand("efi_symbols --frame --extended")
+ debugger.HandleCommand("register read")
+ debugger.HandleCommand("bt all")
+
+
+if __name__ == '__main__':
+ pass
--
2.34.1


Re: [PATCH v3 0/3] BaseTools: fix gcc workaround

Bob Feng
 

Hi Gerd,

Your patches are great but I think we can't take them because of the incompatible license.
I think the new Toolchain definition, like GCC12, can not resolve this issue because Toolchain is not used for building BaseTools.
So I'd prefer the second option of using 'gcc -dumpversion'.

And also we have the task to convert the tools implemented by C to python implementation. After we have done that, there will be no BaseTools build issue.
https://github.com/tianocore/edk2-staging/tree/PyBaseTools

@Gao, Liming @Chen, Christine
Could you review the corresponding patch?

Thanks,
Bob

-----Original Message-----
From: Gerd Hoffmann <kraxel@...>
Sent: Thursday, April 7, 2022 6:12 PM
To: Pedro Falcato <pedro.falcato@...>
Cc: edk2-devel-groups-io <devel@edk2.groups.io>; Chen, Christine <yuwei.chen@...>; Gao, Liming <gaoliming@...>; Pawel Polawski <ppolawsk@...>; Feng, Bob C <bob.c.feng@...>; Oliver Steffen <osteffen@...>; Rebecca Cran <rebecca@...>
Subject: Re: [edk2-devel] [PATCH v3 0/3] BaseTools: fix gcc workaround

On Mon, Apr 04, 2022 at 04:18:56PM +0100, Pedro Falcato wrote:
Hi Gerd,

These patches are a great idea but I don't know if we can take GPLv2
code like that. Are they even mergeable into the main edk2 repo (as
it's not compatible with BSD-2-clause)?
It's build system, doesn't end up being linked into firmware code, so not sure license compatibility is actually a problem here.

In any case I strongly prefer to fix that in some automatic way which does *not* require a new GCC12 tool chain definition.

So, any comments how to move forward with this?
Can we take the series as-is?
If not, other suggestions?
Second-best idea I've seen on the list is using 'gcc -dumpversion'.

Is it an option to just raise the minimum required gcc version to something newer? gcc5 was released almost 7 years ago ...

take care,
Gerd


Re: [PATCH v1 0/3] Add Variable Flash Info HOB

Michael Kubacki
 

Hi Hao,

I addressed all of your feedback including abstraction of the information with a library API in v2. It did help clean up the consumption code quite a bit.

https://edk2.groups.io/g/devel/message/88649

Thanks,
Michael

On 4/7/2022 7:56 PM, Michael Kubacki wrote:
Yes, I considered that as well but I was not sure if it was worth adding a new library just for that. I agree though that the code should not be duplicated. I will look into it and include your other suggestions in a v2 series.
Thanks,
Michael
On 4/6/2022 11:31 PM, Wu, Hao A wrote:
Sorry for a question:
GetVariableFlashInfo() seems being defined multiple times across modules, do you see value in abstracting it as a library API?

Best Regards,
Hao Wu

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Michael
Kubacki
Sent: Thursday, April 7, 2022 12:27 AM
To: devel@edk2.groups.io
Cc: Wang, Jian J <jian.j.wang@...>; Wu, Hao A <hao.a.wu@...>;
Gao, Liming <gaoliming@...>
Subject: [edk2-devel] [PATCH v1 0/3] Add Variable Flash Info HOB

From: Michael Kubacki <michael.kubacki@...>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3479

The UEFI variable drivers such as VariableRuntimeDxe, VariableSmm,
VariableStandaloneMm, etc. (and their dependent protocol/library
stack), typically acquire UEFI variable store flash information
with PCDs declared in MdeModulePkg.

For example:
[Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize

These PCDs work as-is in the StandaloneMm driver if they are not
dynamic such as Dynamic or DynamicEx because PCD services are not
readily available in the Standalone MM environment. Platforms that
use Standalone MM today, must define these PCDs as FixedAtBuild in
their platform build. However, the PCDs do allow platforms to treat
the PCDs as Dynamic/DynamicEx and being able to support that is
currently a gap for Standalone MM.

This patch series introduces a HOB that can be produced by the
platform to provide the same information. The HOB list is
available to Standalone MM.

The PCD declarations are left as-is in MdeModulePkg for backward
compatibility. This means unless a platform wants to use the HOB,
their code will continue to work with no change (they do not need
to produce the HOB). Only if the HOB is found, is its value used
instead of the PCDs.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...

Michael Kubacki (3):
   MdeModulePkg: Add Variable Flash Info HOB
   MdeModulePkg/Variable: Consume Variable Info HOB
   MdeModulePkg/FaultTolerantWrite: Consume Variable Info HOB

MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c |
111 +++++++++++++++++---
  MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
|   7 +-
  MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c
|  92 ++++++++++++++--
MdeModulePkg/Universal/Variable/Pei/Variable.c |  66
+++++++++++-
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.c |  42
++++++++
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c |
25 ++++-
  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c
|  20 +++-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c |
20 +++-
MdeModulePkg/Include/Guid/VariableFlashInfo.h |  36
+++++++
MdeModulePkg/MdeModulePkg.dec |   4 +
  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
|   9 +-
  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
|  11 +-
  MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf
|  11 +-

MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandalon
eMm.inf |  11 +-
  MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf
|  10 +-
MdeModulePkg/Universal/Variable/Pei/Variable.h |   2 +
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf |   6 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h |  17
+++
  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
|   6 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf |
6 +-
  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
|   6 +-
  21 files changed, 455 insertions(+), 63 deletions(-)
  create mode 100644 MdeModulePkg/Include/Guid/VariableFlashInfo.h

--
2.28.0.windows.1



-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#88461): https://edk2.groups.io/g/devel/message/88461
Mute This Topic: https://groups.io/mt/90293658/1768737
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [hao.a.wu@...]
-=-=-=-=-=-=



[PATCH v2 8/8] UefiPayloadPkg: Add VariableFlashInfoLib

Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479

Adds an instance of VariableFlashInfoLib to the platform build as
it is a new library class introduced in MdeModulePkg.

Cc: Guo Dong <guo.dong@...>
Cc: Ray Ni <ray.ni@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Benjamin You <benjamin.you@...>
Cc: Sean Rhodes <sean@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
UefiPayloadPkg/UefiPayloadPkg.dsc | 1 +
1 file changed, 1 insertion(+)

diff --git a/UefiPayloadPkg/UefiPayloadPkg.dsc b/UefiPayloadPkg/UefiPaylo=
adPkg.dsc
index e2ea48348257..170c5a1db4b2 100644
--- a/UefiPayloadPkg/UefiPayloadPkg.dsc
+++ b/UefiPayloadPkg/UefiPayloadPkg.dsc
@@ -272,6 +272,7 @@ [LibraryClasses]
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
VmgExitLib|UefiCpuPkg/Library/VmgExitLibNull/VmgExitLibNull.inf
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeRep=
ortStatusCodeLib.inf
=20
--=20
2.28.0.windows.1


[PATCH v2 7/8] OvmfPkg: Add VariableFlashInfoLib

Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479

Adds an instance of VariableFlashInfoLib to the platform build as
it is a new library class introduced in MdeModulePkg.

Cc: Anthony Perard <anthony.perard@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Brijesh Singh <brijesh.singh@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: James Bottomley <jejb@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Julien Grall <julien@...>
Cc: Min Xu <min.m.xu@...>
Cc: Peter Grehan <grehan@...>
Cc: Rebecca Cran <rebecca@...>
Cc: Sebastien Boeuf <sebastien.boeuf@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
OvmfPkg/AmdSev/AmdSevX64.dsc | 1 +
OvmfPkg/Bhyve/BhyveX64.dsc | 1 +
OvmfPkg/CloudHv/CloudHvX64.dsc | 1 +
OvmfPkg/IntelTdx/IntelTdxX64.dsc | 1 +
OvmfPkg/Microvm/MicrovmX64.dsc | 1 +
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/OvmfXen.dsc | 1 +
9 files changed, 9 insertions(+)

diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index fcdc3efab204..3868c577fe39 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -195,6 +195,7 @@ [LibraryClasses]
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
=20
!if $(BUILD_SHELL) =3D=3D TRUE
ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index e1b6b8e15f36..3df49e54de8a 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -206,6 +206,7 @@ [LibraryClasses]
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
=20
#
# Network libraries
diff --git a/OvmfPkg/CloudHv/CloudHvX64.dsc b/OvmfPkg/CloudHv/CloudHvX64.=
dsc
index 20f3bc340807..19b84275eba3 100644
--- a/OvmfPkg/CloudHv/CloudHvX64.dsc
+++ b/OvmfPkg/CloudHv/CloudHvX64.dsc
@@ -216,6 +216,7 @@ [LibraryClasses]
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
=20
=20
#
diff --git a/OvmfPkg/IntelTdx/IntelTdxX64.dsc b/OvmfPkg/IntelTdx/IntelTdx=
X64.dsc
index 245155d41b30..f21a33ed6ba3 100644
--- a/OvmfPkg/IntelTdx/IntelTdxX64.dsc
+++ b/OvmfPkg/IntelTdx/IntelTdxX64.dsc
@@ -184,6 +184,7 @@ [LibraryClasses]
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
=20
ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.=
inf
diff --git a/OvmfPkg/Microvm/MicrovmX64.dsc b/OvmfPkg/Microvm/MicrovmX64.=
dsc
index 59580ccd4691..d8603f016a0c 100644
--- a/OvmfPkg/Microvm/MicrovmX64.dsc
+++ b/OvmfPkg/Microvm/MicrovmX64.dsc
@@ -206,6 +206,7 @@ [LibraryClasses]
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
=20
=20
#
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index e4218b01f0fc..c689d4707046 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -213,6 +213,7 @@ [LibraryClasses]
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
=20
=20
#
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index a80cdaacb8bc..44c75639aa5d 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -217,6 +217,7 @@ [LibraryClasses]
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
=20
=20
#
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index fb2899f8a1be..60e7e3724a6b 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -225,6 +225,7 @@ [LibraryClasses]
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
=20
=20
#
diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 7bd594c6e263..01d832323585 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -195,6 +195,7 @@ [LibraryClasses]
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
=20
=20
#
--=20
2.28.0.windows.1


[PATCH v2 6/8] EmulatorPkg: Add VariableFlashInfoLib

Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479

Adds an instance of VariableFlashInfoLib to the platform build as
it is a new library class introduced in MdeModulePkg.

Cc: Andrew Fish <afish@...>
Cc: Ray Ni <ray.ni@...>
Cc: Abner Chang <abner.chang@...>
Cc: Nickle Wang <nickle.wang@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
EmulatorPkg/EmulatorPkg.dsc | 1 +
1 file changed, 1 insertion(+)

diff --git a/EmulatorPkg/EmulatorPkg.dsc b/EmulatorPkg/EmulatorPkg.dsc
index 554c13ddb500..4cf886b9eac7 100644
--- a/EmulatorPkg/EmulatorPkg.dsc
+++ b/EmulatorPkg/EmulatorPkg.dsc
@@ -122,6 +122,7 @@ [LibraryClasses]
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLibRuntimeDxe.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
SortLib|MdeModulePkg/Library/BaseSortLib/BaseSortLib.inf
ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
--=20
2.28.0.windows.1


[PATCH v2 5/8] ArmVirtPkg/ArmVirt.dsc.inc: Add VariableFlashInfoLib

Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479

Adds an instance of VariableFlashInfoLib to the platform build as
it is a new library class introduced in MdeModulePkg.

Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Leif Lindholm <quic_llindhol@...>
Cc: Sami Mujawar <sami.mujawar@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Julien Grall <julien@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
ArmVirtPkg/ArmVirt.dsc.inc | 1 +
1 file changed, 1 insertion(+)

diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc
index ba711deac025..988c1eb75529 100644
--- a/ArmVirtPkg/ArmVirt.dsc.inc
+++ b/ArmVirtPkg/ArmVirt.dsc.inc
@@ -177,6 +177,7 @@ [LibraryClasses.common]
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableL=
ibNull.inf
!endif
VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
VariablePolicyLib|MdeModulePkg/Library/VariablePolicyLib/VariablePolic=
yLib.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootMan=
agerLib.inf
--=20
2.28.0.windows.1


[PATCH v2 4/8] MdeModulePkg/FaultTolerantWrite: Consume Variable Flash Info

Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479

Adds support to the UEFI variable fault tolerant write (FTW) drivers
to receive FTW base and size information dynamically via the Variable
Flash Information library.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c =
| 41 +++++++++++++-------
MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c =
| 7 +++-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c =
| 28 ++++++++-----
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h =
| 7 +++-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf =
| 10 +----
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf =
| 10 +----
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandalon=
eMm.inf | 10 +----
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf =
| 10 +----
8 files changed, 63 insertions(+), 60 deletions(-)

diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c b/Mde=
ModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
index 661e1487673b..f1335870e797 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
@@ -987,22 +987,43 @@ InitFtwDevice (
OUT EFI_FTW_DEVICE **FtwData
)
{
- EFI_FTW_DEVICE *FtwDevice;
+ EFI_STATUS Status;
+ EFI_PHYSICAL_ADDRESS WorkSpaceAddress;
+ UINT64 Size;
+ UINTN FtwWorkingSize;
+ EFI_FTW_DEVICE *FtwDevice;
+
+ FtwWorkingSize =3D 0;
+
+ Status =3D GetVariableFlashFtwWorkingInfo (&WorkSpaceAddress, &Size);
+ ASSERT_EFI_ERROR (Status);
+
+ Status =3D SafeUint64ToUintn (Size, &FtwWorkingSize);
+ // This driver currently assumes the size will be UINTN so assert the =
value is safe for now.
+ ASSERT_EFI_ERROR (Status);
=20
//
// Allocate private data of this driver,
// Including the FtwWorkSpace[FTW_WORK_SPACE_SIZE].
//
- FtwDevice =3D AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + PcdGet32 (Pc=
dFlashNvStorageFtwWorkingSize));
+ FtwDevice =3D AllocateZeroPool (sizeof (EFI_FTW_DEVICE) + FtwWorkingSi=
ze);
if (FtwDevice =3D=3D NULL) {
return EFI_OUT_OF_RESOURCES;
}
=20
+ FtwDevice->WorkSpaceAddress =3D WorkSpaceAddress;
+ FtwDevice->WorkSpaceLength =3D FtwWorkingSize;
+
+ Status =3D GetVariableFlashFtwSpareInfo (&FtwDevice->SpareAreaAddress,=
&Size);
+ ASSERT_EFI_ERROR (Status);
+
+ Status =3D SafeUint64ToUintn (Size, &FtwDevice->SpareAreaLength);
+ // This driver currently assumes the size will be UINTN so assert the =
value is safe for now.
+ ASSERT_EFI_ERROR (Status);
+
//
// Initialize other parameters, and set WorkSpace as FTW_ERASED_BYTE.
//
- FtwDevice->WorkSpaceLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwWo=
rkingSize);
- FtwDevice->SpareAreaLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwSp=
areSize);
if ((FtwDevice->WorkSpaceLength =3D=3D 0) || (FtwDevice->SpareAreaLeng=
th =3D=3D 0)) {
DEBUG ((DEBUG_ERROR, "Ftw: Workspace or Spare block does not exist!\=
n"));
FreePool (FtwDevice);
@@ -1015,16 +1036,6 @@ InitFtwDevice (
FtwDevice->FtwWorkSpaceLba =3D (EFI_LBA)(-1);
FtwDevice->FtwSpareLba =3D (EFI_LBA)(-1);
=20
- FtwDevice->WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFla=
shNvStorageFtwWorkingBase64);
- if (FtwDevice->WorkSpaceAddress =3D=3D 0) {
- FtwDevice->WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdF=
lashNvStorageFtwWorkingBase);
- }
-
- FtwDevice->SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFla=
shNvStorageFtwSpareBase64);
- if (FtwDevice->SpareAreaAddress =3D=3D 0) {
- FtwDevice->SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdF=
lashNvStorageFtwSpareBase);
- }
-
*FtwData =3D FtwDevice;
return EFI_SUCCESS;
}
@@ -1277,7 +1288,7 @@ InitFtwProtocol (
FtwDevice->FtwLastWriteHeader =3D NULL;
FtwDevice->FtwLastWriteRecord =3D NULL;
=20
- InitializeLocalWorkSpaceHeader ();
+ InitializeLocalWorkSpaceHeader (FtwDevice->WorkSpaceLength);
=20
//
// Refresh the working space data from working block
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBl=
ock.c b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
index 61e7a92ccea1..fd563643eb63 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c
@@ -16,10 +16,13 @@ EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER mWorkingBloc=
kHeader =3D { ZERO_GUID, 0, 0
=20
Since Signature and WriteQueueSize have been known, Crc can be calcula=
ted out,
then the work space header will be fixed.
+
+ @param[in] WorkSpaceLength Length in bytes of the FTW workspace a=
rea.
+
**/
VOID
InitializeLocalWorkSpaceHeader (
- VOID
+ IN UINTN WorkSpaceLength
)
{
//
@@ -46,7 +49,7 @@ InitializeLocalWorkSpaceHeader (
&gEdkiiWorkingBlockSignatureGuid,
sizeof (EFI_GUID)
);
- mWorkingBlockHeader.WriteQueueSize =3D PcdGet32 (PcdFlashNvStorageFtwW=
orkingSize) - sizeof (EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER);
+ mWorkingBlockHeader.WriteQueueSize =3D WorkSpaceLength - sizeof (EFI_F=
AULT_TOLERANT_WORKING_BLOCK_HEADER);
=20
//
// Crc is calculated with all the fields except Crc and STATE, so leav=
e them as FTW_ERASED_BYTE.
diff --git a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWr=
itePei.c b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWrit=
ePei.c
index 15543f12ed29..8c152dcbad98 100644
--- a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.=
c
+++ b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.=
c
@@ -16,6 +16,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/HobLib.h>
+#include <Library/SafeIntLib.h>
+#include <Library/VariableFlashInfoLib.h>
=20
EFI_PEI_PPI_DESCRIPTOR mPpiListVariable =3D {
(EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
@@ -212,25 +214,31 @@ PeimFaultTolerantWriteInitialize (
EFI_PHYSICAL_ADDRESS SpareAreaAddress;
UINTN SpareAreaLength;
EFI_PHYSICAL_ADDRESS WorkSpaceInSpareArea;
+ UINT64 Size;
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA FtwLastWrite;
=20
FtwWorkingBlockHeader =3D NULL;
FtwLastWriteHeader =3D NULL;
FtwLastWriteRecord =3D NULL;
=20
- WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorage=
FtwWorkingBase64);
- if (WorkSpaceAddress =3D=3D 0) {
- WorkSpaceAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStora=
geFtwWorkingBase);
- }
+ SpareAreaAddress =3D 0;
+ SpareAreaLength =3D 0;
+ WorkSpaceAddress =3D 0;
+ WorkSpaceLength =3D 0;
=20
- WorkSpaceLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
+ Status =3D GetVariableFlashFtwWorkingInfo (&WorkSpaceAddress, &Size);
+ ASSERT_EFI_ERROR (Status);
=20
- SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet64 (PcdFlashNvStorage=
FtwSpareBase64);
- if (SpareAreaAddress =3D=3D 0) {
- SpareAreaAddress =3D (EFI_PHYSICAL_ADDRESS)PcdGet32 (PcdFlashNvStora=
geFtwSpareBase);
- }
+ Status =3D SafeUint64ToUintn (Size, &WorkSpaceLength);
+ // This driver currently assumes the size will be UINTN so assert the =
value is safe for now.
+ ASSERT_EFI_ERROR (Status);
=20
- SpareAreaLength =3D (UINTN)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
+ Status =3D GetVariableFlashFtwSpareInfo (&SpareAreaAddress, &Size);
+ ASSERT_EFI_ERROR (Status);
+
+ Status =3D SafeUint64ToUintn (Size, &SpareAreaLength);
+ // This driver currently assumes the size will be UINTN so assert the =
value is safe for now.
+ ASSERT_EFI_ERROR (Status);
=20
//
// The address of FTW working base and spare base must not be 0.
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
ite.h b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
index c14e47b5c7b2..5b84d062c294 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h
@@ -26,6 +26,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/ReportStatusCodeLib.h>
+#include <Library/SafeIntLib.h>
+#include <Library/VariableFlashInfoLib.h>
=20
//
// Flash erase polarity is 1
@@ -708,10 +710,13 @@ InitFtwProtocol (
=20
Since Signature and WriteQueueSize have been known, Crc can be calcula=
ted out,
then the work space header will be fixed.
+
+ @param[in] WorkSpaceLength Length in bytes of the FTW workspace a=
rea.
+
**/
VOID
InitializeLocalWorkSpaceHeader (
- VOID
+ IN UINTN WorkSpaceLength
);
=20
/**
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
iteDxe.inf b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
iteDxe.inf
index 96165614d178..d524e1849a2e 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.=
inf
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.=
inf
@@ -46,6 +46,8 @@ [LibraryClasses]
UefiLib
PcdLib
ReportStatusCodeLib
+ SafeIntLib
+ VariableFlashInfoLib
=20
[Guids]
#
@@ -65,14 +67,6 @@ [Protocols]
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## CONSUMES
=20
-[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## C=
ONSUMES
-
#
# gBS->CalculateCrc32() is consumed in EntryPoint.
# PI spec said: When the DXE Foundation is notified that the EFI_RUNTIME=
_ARCH_PROTOCOL
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
iteSmm.inf b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
iteSmm.inf
index 8cc6028470d8..8a4b9ad24657 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.=
inf
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.=
inf
@@ -52,6 +52,8 @@ [LibraryClasses]
ReportStatusCodeLib
SmmMemLib
BaseLib
+ SafeIntLib
+ VariableFlashInfoLib
=20
[Guids]
#
@@ -74,14 +76,6 @@ [Protocols]
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## CONSUMES
=20
-[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## C=
ONSUMES
-
#
# gBS->CalculateCrc32() is consumed in EntryPoint.
# PI spec said: When the DXE Foundation is notified that the EFI_RUNTIME=
_ARCH_PROTOCOL
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWr=
iteStandaloneMm.inf b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultT=
olerantWriteStandaloneMm.inf
index d0fab7d9414f..0ac6edf771ab 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStan=
daloneMm.inf
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStan=
daloneMm.inf
@@ -50,7 +50,9 @@ [LibraryClasses]
MmServicesTableLib
PcdLib
ReportStatusCodeLib
+ SafeIntLib
StandaloneMmDriverEntryPoint
+ VariableFlashInfoLib
=20
[Guids]
#
@@ -73,13 +75,5 @@ [Protocols]
[FeaturePcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFullFtwServiceEnable ## CONSUMES
=20
-[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## C=
ONSUMES
-
[Depex]
TRUE
diff --git a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWr=
itePei.inf b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWr=
itePei.inf
index f90892ad4493..230138272c3a 100644
--- a/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.=
inf
+++ b/MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.=
inf
@@ -39,6 +39,8 @@ [LibraryClasses]
HobLib
BaseMemoryLib
PcdLib
+ SafeIntLib
+ VariableFlashInfoLib
=20
[Guids]
## SOMETIMES_PRODUCES ## HOB
@@ -47,14 +49,6 @@ [Guids]
gEdkiiWorkingBlockSignatureGuid ## SOMETIMES_CONSUMES =
## GUID
gEfiSystemNvDataFvGuid ## SOMETIMES_CONSUMES =
## GUID
=20
-[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## C=
ONSUMES
-
[Depex]
TRUE
=20
--=20
2.28.0.windows.1


[PATCH v2 3/8] MdeModulePkg/Variable: Consume Variable Flash Info

Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479

Updates VariableRuntimeDxe, VariableSmm, and VariableStandaloneMm
to acquire variable flash information from the Variable Flash
Information library.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
MdeModulePkg/Universal/Variable/Pei/Variable.c | 14=
+++++++++-----
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c | 16=
++++++++++++----
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c | 14=
++++++++++----
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c | 17=
+++++++++++++----
MdeModulePkg/Universal/Variable/Pei/Variable.h | 2=
++
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf | 5=
++---
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h | 7=
++-----
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf | 5=
++---
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf | 5=
++---
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf | 5=
++---
10 files changed, 56 insertions(+), 34 deletions(-)

diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.c b/MdeModulePk=
g/Universal/Variable/Pei/Variable.c
index b36dd0de67b2..26a4c73b45a5 100644
--- a/MdeModulePkg/Universal/Variable/Pei/Variable.c
+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.c
@@ -567,11 +567,13 @@ GetVariableStore (
OUT VARIABLE_STORE_INFO *StoreInfo
)
{
+ EFI_STATUS Status;
EFI_HOB_GUID_TYPE *GuidHob;
EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
VARIABLE_STORE_HEADER *VariableStoreHeader;
EFI_PHYSICAL_ADDRESS NvStorageBase;
UINT32 NvStorageSize;
+ UINT64 NvStorageSize64;
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
UINT32 BackUpOffset;
=20
@@ -591,11 +593,13 @@ GetVariableStore (
// Emulated non-volatile variable mode is not enabled.
//
=20
- NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize);
- NvStorageBase =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvSto=
rageVariableBase64) !=3D 0 ?
- PcdGet64 (PcdFlashNvStora=
geVariableBase64) :
- PcdGet32 (PcdFlashNvStora=
geVariableBase)
- );
+ Status =3D GetVariableFlashNvStorageInfo (&NvStorageBase, &NvSto=
rageSize64);
+ ASSERT_EFI_ERROR (Status);
+
+ Status =3D SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);
+ // This driver currently assumes the size will be UINT32 so asse=
rt the value is safe for now.
+ ASSERT_EFI_ERROR (Status);
+
ASSERT (NvStorageBase !=3D 0);
=20
//
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c b/M=
deModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
index 03fec3048dc4..d5c409c914d1 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c
@@ -423,6 +423,8 @@ FtwNotificationEvent (
EFI_PHYSICAL_ADDRESS VariableStoreBase;
UINT64 VariableStoreLength;
UINTN FtwMaxBlockSize;
+ UINT32 NvStorageVariableSize;
+ UINT64 NvStorageVariableSize64;
=20
//
// Ensure FTW protocol is installed.
@@ -432,14 +434,20 @@ FtwNotificationEvent (
return;
}
=20
+ Status =3D GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvS=
torageVariableSize64);
+ ASSERT_EFI_ERROR (Status);
+
+ Status =3D SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVari=
ableSize);
+ // This driver currently assumes the size will be UINT32 so assert the=
value is safe for now.
+ ASSERT_EFI_ERROR (Status);
+
+ VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache->Header=
Length;
+
Status =3D FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize=
);
if (!EFI_ERROR (Status)) {
- ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <=3D FtwMaxBlockSiz=
e);
+ ASSERT (NvStorageVariableSize <=3D FtwMaxBlockSize);
}
=20
- NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE;
- VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache->He=
aderLength;
-
//
// Let NonVolatileVariableBase point to flash variable store base dire=
ctly after FTW ready.
//
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolati=
le.c b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c
index 5e9d40b67ac2..9e2d8fe0fe0c 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c
@@ -142,6 +142,7 @@ InitRealNonVolatileVariableStore (
EFI_PHYSICAL_ADDRESS NvStorageBase;
UINT8 *NvStorageData;
UINT32 NvStorageSize;
+ UINT64 NvStorageSize64;
FAULT_TOLERANT_WRITE_LAST_WRITE_DATA *FtwLastWriteData;
UINT32 BackUpOffset;
UINT32 BackUpSize;
@@ -153,19 +154,24 @@ InitRealNonVolatileVariableStore (
=20
mVariableModuleGlobal->FvbInstance =3D NULL;
=20
+ Status =3D GetVariableFlashNvStorageInfo (&NvStorageBase, &NvStorageSi=
ze64);
+ ASSERT_EFI_ERROR (Status);
+
+ Status =3D SafeUint64ToUint32 (NvStorageSize64, &NvStorageSize);
+ // This driver currently assumes the size will be UINT32 so assert the=
value is safe for now.
+ ASSERT_EFI_ERROR (Status);
+
+ ASSERT (NvStorageBase !=3D 0);
+
//
// Allocate runtime memory used for a memory copy of the FLASH region.
// Keep the memory and the FLASH in sync as updates occur.
//
- NvStorageSize =3D PcdGet32 (PcdFlashNvStorageVariableSize);
NvStorageData =3D AllocateRuntimeZeroPool (NvStorageSize);
if (NvStorageData =3D=3D NULL) {
return EFI_OUT_OF_RESOURCES;
}
=20
- NvStorageBase =3D NV_STORAGE_VARIABLE_BASE;
- ASSERT (NvStorageBase !=3D 0);
-
//
// Copy NV storage data to the memory buffer.
//
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c b/M=
deModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
index 517cae7b00f8..5253c328dcd9 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c
@@ -1084,6 +1084,8 @@ SmmFtwNotificationEvent (
EFI_SMM_FAULT_TOLERANT_WRITE_PROTOCOL *FtwProtocol;
EFI_PHYSICAL_ADDRESS NvStorageVariableBase;
UINTN FtwMaxBlockSize;
+ UINT32 NvStorageVariableSize;
+ UINT64 NvStorageVariableSize64;
=20
if (mVariableModuleGlobal->FvbInstance !=3D NULL) {
return EFI_SUCCESS;
@@ -1097,14 +1099,21 @@ SmmFtwNotificationEvent (
return Status;
}
=20
+ Status =3D GetVariableFlashNvStorageInfo (&NvStorageVariableBase, &NvS=
torageVariableSize64);
+ ASSERT_EFI_ERROR (Status);
+
+ Status =3D SafeUint64ToUint32 (NvStorageVariableSize64, &NvStorageVari=
ableSize);
+ // This driver currently assumes the size will be UINT32 so assert the=
value is safe for now.
+ ASSERT_EFI_ERROR (Status);
+
+ ASSERT (NvStorageVariableBase !=3D 0);
+ VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache->Header=
Length;
+
Status =3D FtwProtocol->GetMaxBlockSize (FtwProtocol, &FtwMaxBlockSize=
);
if (!EFI_ERROR (Status)) {
- ASSERT (PcdGet32 (PcdFlashNvStorageVariableSize) <=3D FtwMaxBlockSiz=
e);
+ ASSERT (NvStorageVariableSize <=3D FtwMaxBlockSize);
}
=20
- NvStorageVariableBase =3D NV_STORAGE_VARIABLE_BASE;
- VariableStoreBase =3D NvStorageVariableBase + mNvFvHeaderCache->He=
aderLength;
-
//
// Let NonVolatileVariableBase point to flash variable store base dire=
ctly after FTW ready.
//
diff --git a/MdeModulePkg/Universal/Variable/Pei/Variable.h b/MdeModulePk=
g/Universal/Variable/Pei/Variable.h
index 7f9ad5bfc357..51effbf79987 100644
--- a/MdeModulePkg/Universal/Variable/Pei/Variable.h
+++ b/MdeModulePkg/Universal/Variable/Pei/Variable.h
@@ -20,6 +20,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/BaseMemoryLib.h>
#include <Library/PeiServicesTablePointerLib.h>
#include <Library/PeiServicesLib.h>
+#include <Library/SafeIntLib.h>
+#include <Library/VariableFlashInfoLib.h>
=20
#include <Guid/VariableFormat.h>
#include <Guid/VariableIndexTable.h>
diff --git a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf b/MdeMod=
ulePkg/Universal/Variable/Pei/VariablePei.inf
index 7cbdd2385e8f..7264a24bdf71 100644
--- a/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
+++ b/MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
@@ -39,6 +39,8 @@ [LibraryClasses]
DebugLib
PeiServicesTablePointerLib
PeiServicesLib
+ SafeIntLib
+ VariableFlashInfoLib
=20
[Guids]
## CONSUMES ## GUID # Variable store header
@@ -59,9 +61,6 @@ [Ppis]
gEfiPeiReadOnlyVariable2PpiGuid ## PRODUCES
=20
[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## C=
ONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable ## S=
OMETIMES_CONSUMES
=20
[Depex]
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h b/MdeM=
odulePkg/Universal/Variable/RuntimeDxe/Variable.h
index 31e408976a35..a668abb82b15 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h
@@ -31,6 +31,8 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/MemoryAllocationLib.h>
#include <Library/AuthVariableLib.h>
#include <Library/VarCheckLib.h>
+#include <Library/VariableFlashInfoLib.h>
+#include <Library/SafeIntLib.h>
#include <Guid/GlobalVariable.h>
#include <Guid/EventGroup.h>
#include <Guid/VariableFormat.h>
@@ -40,11 +42,6 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
=20
#include "PrivilegePolymorphic.h"
=20
-#define NV_STORAGE_VARIABLE_BASE (EFI_PHYSICAL_ADDRESS)\
- (PcdGet64 (PcdFlashNvStorageVariableB=
ase64) !=3D 0 ? \
- PcdGet64 (PcdFlashNvStorageVariableB=
ase64) : \
- PcdGet32 (PcdFlashNvStorageVariableB=
ase))
-
#define EFI_VARIABLE_ATTRIBUTES_MASK (EFI_VARIABLE_NON_VOLATILE |\
EFI_VARIABLE_BOOTSERVICE_ACCESS | =
\
EFI_VARIABLE_RUNTIME_ACCESS | \
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDx=
e.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
index c9434df631ee..3858adf6739d 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
@@ -71,8 +71,10 @@ [LibraryClasses]
TpmMeasurementLib
AuthVariableLib
VarCheckLib
+ VariableFlashInfoLib
VariablePolicyLib
VariablePolicyHelperLib
+ SafeIntLib
=20
[Protocols]
gEfiFirmwareVolumeBlockProtocolGuid ## CONSUMES
@@ -125,9 +127,6 @@ [Guids]
gEfiImageSecurityDatabaseGuid
=20
[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## C=
ONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## S=
OMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## C=
ONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## C=
ONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## C=
ONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## C=
ONSUMES
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf b=
/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
index eaa97a01c6e5..8c552b87e080 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf
@@ -80,8 +80,10 @@ [LibraryClasses]
AuthVariableLib
VarCheckLib
UefiBootServicesTableLib
+ VariableFlashInfoLib
VariablePolicyLib
VariablePolicyHelperLib
+ SafeIntLib
=20
[Protocols]
gEfiSmmFirmwareVolumeBlockProtocolGuid ## CONSUMES
@@ -127,9 +129,6 @@ [Guids]
gEdkiiVarErrorFlagGuid
=20
[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## =
CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## =
SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## =
CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## =
CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## =
CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## =
CONSUMES
diff --git a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandalon=
eMm.inf b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm=
.inf
index d8c4f77e7f1f..f09bed40cf51 100644
--- a/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
+++ b/MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf
@@ -73,9 +73,11 @@ [LibraryClasses]
HobLib
MemoryAllocationLib
MmServicesTableLib
+ SafeIntLib
StandaloneMmDriverEntryPoint
SynchronizationLib
VarCheckLib
+ VariableFlashInfoLib
VariablePolicyLib
VariablePolicyHelperLib
=20
@@ -120,9 +122,6 @@ [Guids]
gEdkiiVarErrorFlagGuid
=20
[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## =
SOMETIMES_CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## =
CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## =
CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize ## =
CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize ## =
CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVolatileVariableSize ## =
CONSUMES
--=20
2.28.0.windows.1


[PATCH v2 2/8] MdeModulePkg/VariableFlashInfoLib: Add initial library

Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479

Adds a new library class VariableFlashInfoLib that abstracts access
to variable flash information. The instance provided first attempts
to retrieve information from the Variable Flash Info HOB. If that
HOB is not present, it falls back to the PCDs defined in
MdeModulePkg.

This fall back behavior provides backward compatibility for platforms
that only provide PCDs but also allows platforms that need to
dynamically provide the information using the Variable Flash Info HOB
to do so at runtime.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c=
| 178 ++++++++++++++++++++
MdeModulePkg/Include/Library/VariableFlashInfoLib.h =
| 68 ++++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.i=
nf | 48 ++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.u=
ni | 12 ++
MdeModulePkg/MdeModulePkg.dec =
| 4 +
MdeModulePkg/MdeModulePkg.dsc =
| 2 +
6 files changed, 312 insertions(+)

diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFl=
ashInfoLib.c b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariable=
FlashInfoLib.c
new file mode 100644
index 000000000000..8e3c6e75c957
--- /dev/null
+++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfo=
Lib.c
@@ -0,0 +1,178 @@
+/** @file
+ Variable Flash Information Library
+
+ Copyright (c) Microsoft Corporation<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Pi/PiMultiPhase.h>
+#include <Guid/VariableFlashInfo.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/VariableFlashInfoLib.h>
+
+/**
+ Get the HOB that contains variable flash information.
+
+ @param[out] VariableFlashInfo Pointer to a pointer to set to the var=
iable flash information structure.
+
+ @retval EFI_SUCCESS Variable flash information was found s=
uccessfully.
+ @retval EFI_INVALID_PARAMETER The VariableFlashInfo pointer given is=
NULL.
+ @retval EFI_NOT_FOUND Variable flash information could not b=
e found.
+
+**/
+EFI_STATUS
+GetVariableFlashInfoFromHob (
+ OUT VARIABLE_FLASH_INFO **VariableFlashInfo
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ if (VariableFlashInfo =3D=3D NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ GuidHob =3D GetFirstGuidHob (&gVariableFlashInfoHobGuid);
+ if (GuidHob =3D=3D NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ *VariableFlashInfo =3D GET_GUID_HOB_DATA (GuidHob);
+
+ //
+ // Assert if more than one variable flash information HOB is present.
+ //
+ DEBUG_CODE (
+ if ((GetNextGuidHob (&gVariableFlashInfoHobGuid, GET_NEXT_HOB (GuidH=
ob)) !=3D NULL)) {
+ DEBUG ((DEBUG_ERROR, "ERROR: Found two variable flash information HO=
Bs\n"));
+ ASSERT (FALSE);
+ }
+
+ );
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Get the base address and size for the NV storage area used for UEFI va=
riable storage.
+
+ @param[out] BaseAddress The NV storage base address.
+ @param[out] Length The NV storage length in bytes.
+
+ @retval EFI_SUCCESS NV storage information was found succe=
ssfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashNvStorageInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ )
+{
+ EFI_STATUS Status;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
+
+ if ((BaseAddress =3D=3D NULL) || (Length =3D=3D NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status =3D GetVariableFlashInfoFromHob (&VariableFlashInfo);
+ if (!EFI_ERROR (Status)) {
+ *BaseAddress =3D VariableFlashInfo->NvStorageBaseAddress;
+ *Length =3D VariableFlashInfo->NvStorageLength;
+ } else {
+ *BaseAddress =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageV=
ariableBase64) !=3D 0 ?
+ PcdGet64 (PcdFlashNvStorageVar=
iableBase64) :
+ PcdGet32 (PcdFlashNvStorageVar=
iableBase)
+ );
+ *Length =3D (UINT64)PcdGet32 (PcdFlashNvStorageVariableSize);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Get the base address and size for the fault tolerant write (FTW) spare
+ area used for UEFI variable storage.
+
+ @param[out] BaseAddress The FTW spare base address.
+ @param[out] Length The FTW spare length in bytes.
+
+ @retval EFI_SUCCESS FTW spare information was found succes=
sfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+ @retval EFI_NOT_FOUND FTW spare information could not be fou=
nd.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashFtwSpareInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ )
+{
+ EFI_STATUS Status;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
+
+ if ((BaseAddress =3D=3D NULL) || (Length =3D=3D NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status =3D GetVariableFlashInfoFromHob (&VariableFlashInfo);
+ if (!EFI_ERROR (Status)) {
+ *BaseAddress =3D VariableFlashInfo->FtwSpareBaseAddress;
+ *Length =3D VariableFlashInfo->FtwSpareLength;
+ } else {
+ *BaseAddress =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageF=
twSpareBase64) !=3D 0 ?
+ PcdGet64 (PcdFlashNvStorageFtw=
SpareBase64) :
+ PcdGet32 (PcdFlashNvStorageFtw=
SpareBase)
+ );
+ *Length =3D (UINT64)PcdGet32 (PcdFlashNvStorageFtwSpareSize);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Get the base address and size for the fault tolerant write (FTW) worki=
ng
+ area used for UEFI variable storage.
+
+ @param[out] BaseAddress The FTW working area base address.
+ @param[out] Length The FTW working area length in bytes.
+
+ @retval EFI_SUCCESS FTW working information was found succ=
essfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+ @retval EFI_NOT_FOUND FTW working information could not be f=
ound.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashFtwWorkingInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ )
+{
+ EFI_STATUS Status;
+ VARIABLE_FLASH_INFO *VariableFlashInfo;
+
+ if ((BaseAddress =3D=3D NULL) || (Length =3D=3D NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status =3D GetVariableFlashInfoFromHob (&VariableFlashInfo);
+ if (!EFI_ERROR (Status)) {
+ *BaseAddress =3D VariableFlashInfo->FtwWorkingBaseAddress;
+ *Length =3D VariableFlashInfo->FtwWorkingLength;
+ } else {
+ *BaseAddress =3D (EFI_PHYSICAL_ADDRESS)(PcdGet64 (PcdFlashNvStorageF=
twWorkingBase64) !=3D 0 ?
+ PcdGet64 (PcdFlashNvStorageFtw=
WorkingBase64) :
+ PcdGet32 (PcdFlashNvStorageFtw=
WorkingBase)
+ );
+ *Length =3D (UINT64)PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Include/Library/VariableFlashInfoLib.h b/MdeMod=
ulePkg/Include/Library/VariableFlashInfoLib.h
new file mode 100644
index 000000000000..1367be9376ea
--- /dev/null
+++ b/MdeModulePkg/Include/Library/VariableFlashInfoLib.h
@@ -0,0 +1,68 @@
+/** @file
+ Variable Flash Information Library
+
+Copyright (c) Microsoft Corporation<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef VARIABLE_FLASH_INFO_LIB_H_
+#define VARIABLE_FLASH_INFO_LIB_H_
+
+/**
+ Get the base address and size for the NV storage area used for UEFI va=
riable storage.
+
+ @param[out] BaseAddress The NV storage base address.
+ @param[out] Length The NV storage length in bytes.
+
+ @retval EFI_SUCCESS NV storage information was found succe=
ssfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+ @retval EFI_NOT_FOUND NV storage information could not be fo=
und.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashNvStorageInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ );
+
+/**
+ Get the base address and size for the fault tolerant write (FTW) spare
+ area used for UEFI variable storage.
+
+ @param[out] BaseAddress The FTW spare base address.
+ @param[out] Length The FTW spare length in bytes.
+
+ @retval EFI_SUCCESS FTW spare information was found succes=
sfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+ @retval EFI_NOT_FOUND FTW spare information could not be fou=
nd.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashFtwSpareInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ );
+
+/**
+ Get the base address and size for the fault tolerant write (FTW) worki=
ng
+ area used for UEFI variable storage.
+
+ @param[out] BaseAddress The FTW working area base address.
+ @param[out] Length The FTW working area length in bytes.
+
+ @retval EFI_SUCCESS FTW working information was found succ=
essfully.
+ @retval EFI_INVALID_PARAMETER A required pointer parameter is NULL.
+ @retval EFI_NOT_FOUND FTW working information could not be f=
ound.
+
+**/
+EFI_STATUS
+EFIAPI
+GetVariableFlashFtwWorkingInfo (
+ OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
+ OUT UINT64 *Length
+ );
+
+#endif
diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFl=
ashInfoLib.inf b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariab=
leFlashInfoLib.inf
new file mode 100644
index 000000000000..70175e75f9b1
--- /dev/null
+++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfo=
Lib.inf
@@ -0,0 +1,48 @@
+## @file
+# Variable Flash Information Library
+#
+# Provides services to access UEFI variable flash information.
+#
+# Copyright (c) Microsoft Corporation<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION =3D 0x00010005
+ BASE_NAME =3D BaseVariableFlashInfoLib
+ MODULE_UNI_FILE =3D BaseVariableFlashInfoLib.uni
+ FILE_GUID =3D DEC426C9-C92E-4BAD-8E93-3F61C261118B
+ MODULE_TYPE =3D BASE
+ VERSION_STRING =3D 1.0
+ LIBRARY_CLASS =3D VariableFlashInfoLib
+
+#
+# The following information is for reference only and not required by th=
e build tools.
+#
+# VALID_ARCHITECTURES =3D ANY
+#
+
+[Sources]
+ BaseVariableFlashInfoLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ DebugLib
+ HobLib
+
+[Guids]
+ gVariableFlashInfoHobGuid ## CONSUMES ## HOB
+
+[Pcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase64 ## S=
OMETIMES_CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize ## S=
OMETIMES_CONSUMES
diff --git a/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFl=
ashInfoLib.uni b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariab=
leFlashInfoLib.uni
new file mode 100644
index 000000000000..9a5348fa02a0
--- /dev/null
+++ b/MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfo=
Lib.uni
@@ -0,0 +1,12 @@
+// /** @file
+// Variable Flash Information Library
+//
+// Copyright (c) Microsoft Corporation<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "UEFI variable flash inf=
ormation library"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Provides services to ac=
cess UEFI variable flash information."
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.de=
c
index 4e82f5836096..2bcb9f9453af 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -154,6 +154,10 @@ [LibraryClasses]
#
VariablePolicyHelperLib|Include/Library/VariablePolicyHelperLib.h
=20
+ ## @libraryclass Provides services to access UEFI variable flash inf=
ormation.
+ #
+ VariableFlashInfoLib|Include/Library/VariableFlashInfoLib.h
+
[Guids]
## MdeModule package token space guid
# Include/Guid/MdeModulePkgTokenSpace.h
diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.ds=
c
index b1d83461865e..90a0a7ec4a7c 100644
--- a/MdeModulePkg/MdeModulePkg.dsc
+++ b/MdeModulePkg/MdeModulePkg.dsc
@@ -103,6 +103,7 @@ [LibraryClasses]
DisplayUpdateProgressLib|MdeModulePkg/Library/DisplayUpdateProgressLib=
Graphics/DisplayUpdateProgressLibGraphics.inf
VariablePolicyHelperLib|MdeModulePkg/Library/VariablePolicyHelperLib/V=
ariablePolicyHelperLib.inf
MmUnblockMemoryLib|MdePkg/Library/MmUnblockMemoryLib/MmUnblockMemoryLi=
bNull.inf
+ VariableFlashInfoLib|MdeModulePkg/Library/BaseVariableFlashInfoLib/Bas=
eVariableFlashInfoLib.inf
=20
[LibraryClasses.EBC.PEIM]
IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf
@@ -440,6 +441,7 @@ [Components]
MdeModulePkg/Library/FmpAuthenticationLibNull/FmpAuthenticationLibNull=
.inf
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeCapsuleLib.inf
MdeModulePkg/Library/DxeCapsuleLibFmp/DxeRuntimeCapsuleLib.inf
+ MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib=
.inf
=20
[Components.IA32, Components.X64, Components.AARCH64]
MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
--=20
2.28.0.windows.1


[PATCH v2 1/8] MdeModulePkg: Add Variable Flash Info HOB

Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479

Adds a new GUID that is used to identify a HOB that passes variable
flash information to UEFI variable drivers in HOB consumption phases
such as DXE, Traditional MM, and Standalone MM.

This information was previously passed directly with PCDs such
as EfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
and gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize.

However, the Standalone MM variable driver instance does not have
direct access to the PCD database. Therefore, this HOB will first
be considered as the source for variable flash information and
if platforms do not produce the HOB, reading the information from
the PCDs directly will be a backup to provide backward
compatibility.

Cc: Jian J Wang <jian.j.wang@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: Liming Gao <gaoliming@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>
---
MdeModulePkg/Include/Guid/VariableFlashInfo.h | 39 ++++++++++++++++++++
MdeModulePkg/MdeModulePkg.dec | 4 ++
2 files changed, 43 insertions(+)

diff --git a/MdeModulePkg/Include/Guid/VariableFlashInfo.h b/MdeModulePkg=
/Include/Guid/VariableFlashInfo.h
new file mode 100644
index 000000000000..e526e362aab9
--- /dev/null
+++ b/MdeModulePkg/Include/Guid/VariableFlashInfo.h
@@ -0,0 +1,39 @@
+/** @file
+ This file defines the GUID and data structure used to pass information=
about
+ a variable store mapped on flash (i.e. a MMIO firmware volume) to the =
DXE and MM environment.
+
+ Copyright (c) Microsoft Corporation.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef VARIABLE_FLASH_INFO_H_
+#define VARIABLE_FLASH_INFO_H_
+
+#define VARIABLE_FLASH_INFO_HOB_GUID \
+ { 0x5d11c653, 0x8154, 0x4ac3, { 0xa8, 0xc2, 0xfb, 0xa2, 0x89, 0x20, 0x=
fc, 0x90 }}
+
+#define VARIABLE_FLASH_INFO_HOB_VERSION 1
+
+extern EFI_GUID gVariableFlashInfoHobGuid;
+
+#pragma pack (push, 1)
+
+///
+/// This structure can be used to describe UEFI variable
+/// flash information.
+///
+typedef struct {
+ UINT32 Version;
+ EFI_PHYSICAL_ADDRESS NvStorageBaseAddress;
+ UINT64 NvStorageLength;
+ EFI_PHYSICAL_ADDRESS FtwSpareBaseAddress;
+ UINT64 FtwSpareLength;
+ EFI_PHYSICAL_ADDRESS FtwWorkingBaseAddress;
+ UINT64 FtwWorkingLength;
+} VARIABLE_FLASH_INFO;
+
+#pragma pack (pop)
+
+#endif
diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.de=
c
index cf79292ec877..4e82f5836096 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -226,6 +226,10 @@ [Guids]
# Include/Guid/SmmVariableCommon.h
gSmmVariableWriteGuid =3D { 0x93ba1826, 0xdffb, 0x45dd, { 0x82, 0xa7,=
0xe7, 0xdc, 0xaa, 0x3b, 0xbd, 0xf3 }}
=20
+ ## Guid of the variable flash information HOB.
+ # Include/Guid/VariableFlashInfo.h
+ gVariableFlashInfoHobGuid =3D { 0x5d11c653, 0x8154, 0x4ac3, { 0xa8, 0x=
c2, 0xfb, 0xa2, 0x89, 0x20, 0xfc, 0x90 }}
+
## Performance protocol guid that also acts as the performance HOB gui=
d and performance variable GUID
# Include/Guid/Performance.h
gPerformanceProtocolGuid =3D { 0x76B6BDFA, 0x2ACD, 0x4462, { 0x9=
E, 0x3F, 0xCB, 0x58, 0xC9, 0x69, 0xD9, 0x37 } }
--=20
2.28.0.windows.1


[PATCH v2 0/8] Add Variable Flash Info HOB

Michael Kubacki
 

From: Michael Kubacki <michael.kubacki@...>

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D3479

The UEFI variable drivers such as VariableRuntimeDxe, VariableSmm,
VariableStandaloneMm, etc. (and their dependent protocol/library
stack), typically acquire UEFI variable store flash information
with PCDs declared in MdeModulePkg.

For example:
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase64
gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize

These PCDs work as-is in the StandaloneMm driver if they are not
dynamic such as Dynamic or DynamicEx because PCD services are not
readily available in the Standalone MM environment. Platforms that
use Standalone MM today, must define these PCDs as FixedAtBuild in
their platform build. However, the PCDs do allow platforms to treat
the PCDs as Dynamic/DynamicEx and being able to support that is
currently a gap for Standalone MM.

This patch series introduces a HOB that can be produced by the
platform to provide the same information. The HOB list is
available to Standalone MM.

The PCD declarations are left as-is in MdeModulePkg for backward
compatibility. This means unless a platform wants to use the HOB,
their code will continue to work with no change (they do not need
to produce the HOB). Only if the HOB is found, is its value used
instead of the PCDs.

Due to the large number of consumers of this information, access
to the base address and size values is abstracted in a new library
class (as requested in the v1 series) called VariableFlashInfoLib.

The API of VariableFlashInfoLib does not bind the underlying data
structure to the information returned to library users to allow
flexibility in the library implementation in the future.

V2 changes:
1. Abstracted flash info data access with VariableFlashInfoLib.
2. Updated package builds in the repo that build the variable and
FTW drivers to include VariableFlashInfoLib.
3. Removed a redundant variable assignment in VariableSmm.c.
4. Updated comments in FtwMisc.c and FaultTolerantWritePei.c to
indicate driver assumption is UINTN (not UINT32)
5. Added a version field to the VARIABLE_FLASH_INFO structure.

Cc: Abner Chang <abner.chang@...>
Cc: Andrew Fish <afish@...>
Cc: Anthony Perard <anthony.perard@...>
Cc: Ard Biesheuvel <ardb+tianocore@...>
Cc: Benjamin You <benjamin.you@...>
Cc: Brijesh Singh <brijesh.singh@...>
Cc: Erdem Aktas <erdemaktas@...>
Cc: Gerd Hoffmann <kraxel@...>
Cc: Guo Dong <guo.dong@...>
Cc: Hao A Wu <hao.a.wu@...>
Cc: James Bottomley <jejb@...>
Cc: Jian J Wang <jian.j.wang@...>
Cc: Jiewen Yao <jiewen.yao@...>
Cc: Jordan Justen <jordan.l.justen@...>
Cc: Julien Grall <julien@...>
Cc: Leif Lindholm <quic_llindhol@...>
Cc: Liming Gao <gaoliming@...>
Cc: Maurice Ma <maurice.ma@...>
Cc: Min Xu <min.m.xu@...>
Cc: Nickle Wang <nickle.wang@...>
Cc: Peter Grehan <grehan@...>
Cc: Ray Ni <ray.ni@...>
Cc: Rebecca Cran <rebecca@...>
Cc: Sami Mujawar <sami.mujawar@...>
Cc: Sean Rhodes <sean@...>
Cc: Sebastien Boeuf <sebastien.boeuf@...>
Cc: Tom Lendacky <thomas.lendacky@...>
Signed-off-by: Michael Kubacki <michael.kubacki@...>

Michael Kubacki (8):
MdeModulePkg: Add Variable Flash Info HOB
MdeModulePkg/VariableFlashInfoLib: Add initial library
MdeModulePkg/Variable: Consume Variable Flash Info
MdeModulePkg/FaultTolerantWrite: Consume Variable Flash Info
ArmVirtPkg/ArmVirt.dsc.inc: Add VariableFlashInfoLib
EmulatorPkg: Add VariableFlashInfoLib
OvmfPkg: Add VariableFlashInfoLib
UefiPayloadPkg: Add VariableFlashInfoLib

MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.c=
| 178 ++++++++++++++++++++
MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c =
| 41 +++--
MdeModulePkg/Universal/FaultTolerantWriteDxe/UpdateWorkingBlock.c =
| 7 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.c =
| 28 +--
MdeModulePkg/Universal/Variable/Pei/Variable.c =
| 14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableDxe.c =
| 16 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableNonVolatile.c =
| 14 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.c =
| 17 +-
ArmVirtPkg/ArmVirt.dsc.inc =
| 1 +
EmulatorPkg/EmulatorPkg.dsc =
| 1 +
MdeModulePkg/Include/Guid/VariableFlashInfo.h =
| 39 +++++
MdeModulePkg/Include/Library/VariableFlashInfoLib.h =
| 68 ++++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.i=
nf | 48 ++++++
MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVariableFlashInfoLib.u=
ni | 12 ++
MdeModulePkg/MdeModulePkg.dec =
| 8 +
MdeModulePkg/MdeModulePkg.dsc =
| 2 +
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWrite.h =
| 7 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf =
| 10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteSmm.inf =
| 10 +-
MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteStandalon=
eMm.inf | 10 +-
MdeModulePkg/Universal/FaultTolerantWritePei/FaultTolerantWritePei.inf =
| 10 +-
MdeModulePkg/Universal/Variable/Pei/Variable.h =
| 2 +
MdeModulePkg/Universal/Variable/Pei/VariablePei.inf =
| 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/Variable.h =
| 7 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf =
| 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmm.inf =
| 5 +-
MdeModulePkg/Universal/Variable/RuntimeDxe/VariableStandaloneMm.inf =
| 5 +-
OvmfPkg/AmdSev/AmdSevX64.dsc =
| 1 +
OvmfPkg/Bhyve/BhyveX64.dsc =
| 1 +
OvmfPkg/CloudHv/CloudHvX64.dsc =
| 1 +
OvmfPkg/IntelTdx/IntelTdxX64.dsc =
| 1 +
OvmfPkg/Microvm/MicrovmX64.dsc =
| 1 +
OvmfPkg/OvmfPkgIa32.dsc =
| 1 +
OvmfPkg/OvmfPkgIa32X64.dsc =
| 1 +
OvmfPkg/OvmfPkgX64.dsc =
| 1 +
OvmfPkg/OvmfXen.dsc =
| 1 +
UefiPayloadPkg/UefiPayloadPkg.dsc =
| 1 +
37 files changed, 486 insertions(+), 94 deletions(-)
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVar=
iableFlashInfoLib.c
create mode 100644 MdeModulePkg/Include/Guid/VariableFlashInfo.h
create mode 100644 MdeModulePkg/Include/Library/VariableFlashInfoLib.h
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVar=
iableFlashInfoLib.inf
create mode 100644 MdeModulePkg/Library/BaseVariableFlashInfoLib/BaseVar=
iableFlashInfoLib.uni

--=20
2.28.0.windows.1


Re: [PATCH v2] OvmfPkg/BhyveBhfPkg: add support for QemuFwCfg

Pedro Falcato
 

Is this a laptop? Things may not work there because video output is done through the Intel GPU, even when using the Nvidia GPU, although I'm not sure.

On Fri, Apr 8, 2022 at 6:49 PM Mario Marietto <marietto2008@...> wrote:
im trying to test the patch on my pc,that has two graphic cards,the intel coffee lake and the nvidia. i tried to start the pc from the nvidia card and ive configured the xorg.conf file giving the proper bus id value. in addition ive loaded the kernel.ko file from the boot loader.conf i have removed the intel and the drm drivers used by the Intel graphic card. unfortunately my pc wont boot from the nvidia card. my mouse and keyboard freezes just before the desktop manager (xfce and kde5) starts.

Il gio 7 apr 2022, 18:46 Rebecca Cran <rebecca@...> ha scritto:
I've just looked at the patch and it looks good, though I haven't tested it.

So yes, please add:


Acked-by: Rebecca Cran <rebecca@...>


On 4/6/22 23:24, Corvin Köhne wrote:
> Hi Peter and Rebecca,
>
> thanks for your feedback. This patch is backward compatible. It checks
> if QemuFwCfg is available and if QemuFwCfg is missing it falls
> back to BhyveFwCtl.
>
> So, should I add Reviewed-by (or Acked-by?) Peter and Rebecca to the
> commit message?
>
>
> Thanks
> Corvin
>
> Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Beckhoff
> Registered office: Verl, Germany | Register court: Guetersloh HRA 7075
>
>
>



--
Pedro Falcato


Re: GSoC 2022: Add S3 resume support to MinPlatform

Benjamin Doron
 

Hi Nate,
Thanks! I've looked at the basics of I2C, but I've seen from the iGFX PRM that GMBUS implements some registers and error handling the NAKs differently, but I guess that I'll be dealing with that later.

Yeah, I was thinking that if we wanted debug up as soon as possible, then the iGFX BAR and P2SB GPIOs would have to be programmed, so that sounds about right. Synchronising with the FSP's config is probably important too, but I suppose you implemented that/we'll see?

For now, I have a proposal at https://docs.google.com/document/d/1CyyerMfPwvZxkBjfE_-H1OlkZPxH98uqpmb9tBAV_ps.

Best regards,
Benjamin


Re: [edk2-libc Patch 1/1] AppPkg\Applications\Python\Python-3.6.8\Lib: uuid.py module port for UEFI environment

Michael D Kinney
 

Thanks JP.

That makes sense. Bypass all the OS specific services in UEFI environment and generate UUID using time and random number.

Reviewed-by: Michael D Kinney <michael.d.kinney@...>

Mike

-----Original Message-----
From: Jayaprakash, N <n.jayaprakash@...>
Sent: Friday, April 8, 2022 10:19 AM
To: devel@edk2.groups.io; Jayaprakash, N <n.jayaprakash@...>; Kinney, Michael D <michael.d.kinney@...>
Cc: Frinzell, Aaron <aaron.frinzell@...>
Subject: RE: [edk2-devel] [edk2-libc Patch 1/1] AppPkg\Applications\Python\Python-3.6.8\Lib: uuid.py module port for UEFI
environment

+ Aaron

Regards,
JP

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Jayaprakash, N
Sent: 08 April 2022 22:12
To: Kinney, Michael D <michael.d.kinney@...>; devel@edk2.groups.io
Subject: Re: [edk2-devel] [edk2-libc Patch 1/1] AppPkg\Applications\Python\Python-3.6.8\Lib: uuid.py module port for UEFI
environment

The UUID generation is done through the random number generation & time unix time stamp features available through the built-in
python modules 'random' and 'time' respectively.
The random number & time (unix time stamp or epoch) based method of generating the UUID is already there in uuid.py module,
with this patch request enabled this path to take effect for UEFI invocation of this module.

There are some OS specific ways to generate the UUID's such as by using the libuuid on Linux kind of OS, windll.rpcrt4 library
on windows.
These will not work for UEFI and hence added appropriate platform check to ensure that this path is not taken for UEFI
invocation.

Besides this there are MAC address based algorithms available in uuid.py module.
These algorism are based on reading MAC address through various OS supported methods such as ipconfig command processing,
NetBIOS calls on Windows, using netstat command in Linux, lanscan in Unix, from arp - address resolution protocol in Linux,
NetBSD and other flavours of Linux.
These are currently not enabled for UEFI invocation of the uuid module. This has been done through platform check added at
appropriate place in the uuid.py module code.

Regards,
JP
-----Original Message-----
From: Kinney, Michael D <michael.d.kinney@...>
Sent: 08 April 2022 21:14
To: devel@edk2.groups.io; Jayaprakash, N <n.jayaprakash@...>; Kinney, Michael D <michael.d.kinney@...>
Subject: RE: [edk2-devel] [edk2-libc Patch 1/1] AppPkg\Applications\Python\Python-3.6.8\Lib: uuid.py module port for UEFI
environment

How is a UUID generated in UEFI env? Is there a dependency on MAC address or random number generator?

Can you add a description of the technique to the BZ and the commit message?

Thanks,

Mike

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
Jayaprakash, N
Sent: Friday, April 8, 2022 4:52 AM
To: devel@edk2.groups.io
Subject: [edk2-devel] [edk2-libc Patch 1/1]
AppPkg\Applications\Python\Python-3.6.8\Lib: uuid.py module port for
UEFI environment

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3899

This is commit contains the UEFI port of uuid.py module. Made
necessary changes required to uuid.py module to support UEFI environment.
Porting of this module to UEFI is required for open source tools such
as Chipsec to function properly.

Cc: Rebecca Cran <rebecca@...>
Cc: Michael D Kinney <michael.d.kinney@...>
Signed-off-by: Jayaprakash N <n.jayaprakash@...>
---
.../Python/Python-3.6.8/Lib/uuid.py | 94 ++++++++++---------
1 file changed, 50 insertions(+), 44 deletions(-)

diff --git a/AppPkg/Applications/Python/Python-3.6.8/Lib/uuid.py
b/AppPkg/Applications/Python/Python-3.6.8/Lib/uuid.py
index db8b2ef..84ed0b8 100644
--- a/AppPkg/Applications/Python/Python-3.6.8/Lib/uuid.py
+++ b/AppPkg/Applications/Python/Python-3.6.8/Lib/uuid.py
@@ -471,57 +471,61 @@ def _netbios_getnode():
continue
return int.from_bytes(bytes, 'big')

+
# Thanks to Thomas Heller for ctypes and for his help with its use here.

# If ctypes is available, use it to find system routines for UUID generation.
# XXX This makes the module non-thread-safe!
_uuid_generate_time = _UuidCreate = None
-try:
- import ctypes, ctypes.util
- import sys
-
- # The uuid_generate_* routines are provided by libuuid on at least
- # Linux and FreeBSD, and provided by libc on Mac OS X.
- _libnames = ['uuid']
- if not sys.platform.startswith('win'):
- _libnames.append('c')
- for libname in _libnames:
- try:
- lib = ctypes.CDLL(ctypes.util.find_library(libname))
- except Exception:
- continue
- if hasattr(lib, 'uuid_generate_time'):
- _uuid_generate_time = lib.uuid_generate_time
- break
- del _libnames
-
- # The uuid_generate_* functions are broken on MacOS X 10.5, as noted
- # in issue #8621 the function generates the same sequence of values
- # in the parent process and all children created using fork (unless
- # those children use exec as well).
- #
- # Assume that the uuid_generate functions are broken from 10.5 onward,
- # the test can be adjusted when a later version is fixed.
- if sys.platform == 'darwin':
- if int(os.uname().release.split('.')[0]) >= 9:
- _uuid_generate_time = None
-
- # On Windows prior to 2000, UuidCreate gives a UUID containing the
- # hardware address. On Windows 2000 and later, UuidCreate makes a
- # random UUID and UuidCreateSequential gives a UUID containing the
- # hardware address. These routines are provided by the RPC runtime.
- # NOTE: at least on Tim's WinXP Pro SP2 desktop box, while the last
- # 6 bytes returned by UuidCreateSequential are fixed, they don't appear
- # to bear any relationship to the MAC address of any network device
- # on the box.
+if os.name != 'edk2':
+ # This code is not meant to run on UEFI environment
try:
- lib = ctypes.windll.rpcrt4
+ import ctypes, ctypes.util
+ import sys
+
+ # The uuid_generate_* routines are provided by libuuid on at least
+ # Linux and FreeBSD, and provided by libc on Mac OS X.
+ _libnames = ['uuid']
+ if not sys.platform.startswith('win'):
+ _libnames.append('c')
+ for libname in _libnames:
+ try:
+ lib = ctypes.CDLL(ctypes.util.find_library(libname))
+ except Exception:
+ continue
+ if hasattr(lib, 'uuid_generate_time'):
+ _uuid_generate_time = lib.uuid_generate_time
+ break
+ del _libnames
+
+ # The uuid_generate_* functions are broken on MacOS X 10.5, as noted
+ # in issue #8621 the function generates the same sequence of values
+ # in the parent process and all children created using fork (unless
+ # those children use exec as well).
+ #
+ # Assume that the uuid_generate functions are broken from 10.5 onward,
+ # the test can be adjusted when a later version is fixed.
+ if sys.platform == 'darwin':
+ if int(os.uname().release.split('.')[0]) >= 9:
+ _uuid_generate_time = None
+
+ # On Windows prior to 2000, UuidCreate gives a UUID containing the
+ # hardware address. On Windows 2000 and later, UuidCreate makes a
+ # random UUID and UuidCreateSequential gives a UUID containing the
+ # hardware address. These routines are provided by the RPC runtime.
+ # NOTE: at least on Tim's WinXP Pro SP2 desktop box, while the last
+ # 6 bytes returned by UuidCreateSequential are fixed, they don't appear
+ # to bear any relationship to the MAC address of any network device
+ # on the box.
+ try:
+ lib = ctypes.windll.rpcrt4
+ except:
+ lib = None
+ _UuidCreate = getattr(lib, 'UuidCreateSequential',
+ getattr(lib, 'UuidCreate', None))
except:
- lib = None
- _UuidCreate = getattr(lib, 'UuidCreateSequential',
- getattr(lib, 'UuidCreate', None))
-except:
- pass
+ pass
+

def _unixdll_getnode():
"""Get the hardware address on Unix using ctypes."""
@@ -563,6 +567,8 @@ def getnode():
import sys
if sys.platform == 'win32':
getters = _NODE_GETTERS_WIN32
+ elif sys.platform == 'uefi':
+ getters = []
else:
getters = _NODE_GETTERS_UNIX

--
2.32.0.windows.2







8261 - 8280 of 96835