Add PCD PcdMemoryMappedBootMedia to indiciate if Boot Media is memory mapped.
If set to true, don't check for Block Alignment as it is not necessary.

Cc: Hao A Wu <hao.a...@intel.com>
Cc: Liming Gao <gaolim...@byosoft.com.cn>
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
---
 MdeModulePkg/MdeModulePkg.dec                            | 7 +++++++
 MdeModulePkg/MdeModulePkg.uni                            | 4 ++++
 .../FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf      | 1 +
 MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c   | 9 ++++++---
 4 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec
index 463e889e9a..e181a5216b 100644
--- a/MdeModulePkg/MdeModulePkg.dec
+++ b/MdeModulePkg/MdeModulePkg.dec
@@ -1077,6 +1077,13 @@
   # @Prompt Enable UEFI Stack Guard.
   gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard|FALSE|BOOLEAN|0x30001055
 
+  ## Indicates if the Boot Media is memory mapped.
+  #  If enabled, don't check for block alignent as it is not necessary.
+  #   TRUE  - Do not check for block aligment.
+  #   FALSE - Check for block alignment.
+  # @Prompt Boot Media Memory Mapped.
+  
gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryMappedBootMedia|FALSE|BOOLEAN|0x30001058
+
 [PcdsFixedAtBuild, PcdsPatchableInModule]
   ## Dynamic type PCD can be registered callback function for Pcd setting 
action.
   #  PcdMaxPeiPcdCallBackNumberPerPcdEntry indicates the maximum number of 
callback function
diff --git a/MdeModulePkg/MdeModulePkg.uni b/MdeModulePkg/MdeModulePkg.uni
index 27889a7280..deafee3d5a 100644
--- a/MdeModulePkg/MdeModulePkg.uni
+++ b/MdeModulePkg/MdeModulePkg.uni
@@ -1173,6 +1173,10 @@
                                                                                
           " TRUE  - Capsule In Ram is supported.<BR>"
                                                                                
           " FALSE - Capsule In Ram is not supported."
 
+#string STR_gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryMappedBootMedia_PROMPT 
#language en-US "Boot Media is memory mapped."
+
+#string STR_gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryMappedBootMedia_HELP   
#language en-US "Indicates if the Boot Media is memory mapped."
+
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdCodRelocationDevPath_PROMPT  
#language en-US "Capsule On Disk relocation device path."
 
 #string STR_gEfiMdeModulePkgTokenSpaceGuid_PcdCodRelocationDevPath_HELP  
#language en-US   "Full device path of platform specific device to store 
Capsule On Disk temp relocation file.<BR>"
diff --git 
a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf 
b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
index 96165614d1..b3209567d9 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FaultTolerantWriteDxe.inf
@@ -72,6 +72,7 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase      ## 
SOMETIMES_CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase64    ## CONSUMES
   gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize      ## CONSUMES
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMemoryMappedBootMedia           ## CONSUMES
 
 #
 # gBS->CalculateCrc32() is consumed in EntryPoint.
diff --git a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c 
b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
index 661e148767..4c3fcbec6b 100644
--- a/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
+++ b/MdeModulePkg/Universal/FaultTolerantWriteDxe/FtwMisc.c
@@ -1119,7 +1119,9 @@ FindFvbForFtw (
           FtwDevice->WorkBlockSize          = BlockSize;
           FtwDevice->FtwWorkSpaceBase       = 
(UINTN)(FtwDevice->WorkSpaceAddress - (FvbBaseAddress + 
FtwDevice->WorkBlockSize * (LbaIndex - 1)));
           FtwDevice->NumberOfWorkSpaceBlock = FTW_BLOCKS 
(FtwDevice->FtwWorkSpaceBase + FtwDevice->FtwWorkSpaceSize, 
FtwDevice->WorkBlockSize);
-          if (FtwDevice->FtwWorkSpaceSize >= FtwDevice->WorkBlockSize) {
+          if ((!PcdGetBool (PcdMemoryMappedBootMedia)) &&
+              (FtwDevice->FtwWorkSpaceSize >= FtwDevice->WorkBlockSize))
+          {
             //
             // Check the alignment of work space address and length, they 
should be block size aligned when work space size is larger than one block size.
             //
@@ -1173,8 +1175,9 @@ FindFvbForFtw (
           //
           // Check the alignment of spare area address and length, they should 
be block size aligned
           //
-          if (((FtwDevice->SpareAreaAddress & (FtwDevice->SpareBlockSize - 1)) 
!= 0) ||
-              ((FtwDevice->SpareAreaLength & (FtwDevice->SpareBlockSize - 1)) 
!= 0))
+          if ((!PcdGetBool (PcdMemoryMappedBootMedia)) &&
+              (((FtwDevice->SpareAreaAddress & (FtwDevice->SpareBlockSize - 
1)) != 0) ||
+               ((FtwDevice->SpareAreaLength & (FtwDevice->SpareBlockSize - 1)) 
!= 0)))
           {
             DEBUG ((DEBUG_ERROR, "Ftw: Spare area address or length is not 
block size aligned\n"));
             FreePool (HandleBuffer);
-- 
2.32.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#87036): https://edk2.groups.io/g/devel/message/87036
Mute This Topic: https://groups.io/mt/89419637/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to