Skip to content

Conversation

@wxjstz
Copy link
Contributor

@wxjstz wxjstz commented Nov 20, 2025

When I explored the u540 code, I discovered that the PlatformSecLib library was missing the PeiServicesLib library.

@wxjstz
Copy link
Contributor Author

wxjstz commented Nov 20, 2025

Because RISCV_PEI_BOOTING is FALSE in u540, u540 is not actually using SecCore, so I tried the following test. Then the compilation failed, indicating a missing dependency.

diff --git a/UefiCpuPkg/SecCore/SecCoreNative.inf b/UefiCpuPkg/SecCore/SecCoreNative.inf
index 4d9f385e06..947d74756c 100644
--- a/UefiCpuPkg/SecCore/SecCoreNative.inf
+++ b/UefiCpuPkg/SecCore/SecCoreNative.inf
@@ -42,20 +42,20 @@
   UefiCpuPkg/UefiCpuPkg.dec
 
 [LibraryClasses]
-  BaseMemoryLib
-  DebugLib
+#  BaseMemoryLib^M
+#  DebugLib^M
   PlatformSecLib
-  PcdLib
-  DebugAgentLib
-  CpuLib
-  PeCoffGetEntryPointLib
-  PeCoffExtraActionLib
-  CpuExceptionHandlerLib
-  ReportStatusCodeLib
-  PeiServicesLib
-  PeiServicesTablePointerLib
-  HobLib
-  StackCheckLib
+#  PcdLib^M
+#  DebugAgentLib^M
+#  CpuLib^M
+#  PeCoffGetEntryPointLib^M
+#  PeCoffExtraActionLib^M
+#  CpuExceptionHandlerLib^M
+#  ReportStatusCodeLib^M
+#  PeiServicesLib^M
+#  PeiServicesTablePointerLib^M
+#  HobLib^M
+#  StackCheckLib^M
 
 [LibraryClasses.IA32, LibraryClasses.X64]
   CpuPageTableLib

When I explored the U540 code, I discovered that the PlatformSecLib
library was missing the PeiServicesLib library.

Signed-off-by: Xiang W <[email protected]>
PcdLib
PrePiLib
SerialPortLib
PeiServicesLib
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What services of PeiServicesLib used by PlatformSecLib?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff --git a/Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/RiscVPlatformSecLib.inf b/Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/RiscVPlatformSecLib.inf
index 213a43f7c6..6e6ca4695e 100644
--- a/Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/RiscVPlatformSecLib.inf
+++ b/Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/RiscVPlatformSecLib.inf
@@ -14,7 +14,6 @@
   FILE_GUID                      = b434fb89-87ce-475c-b8fd-919c74cc6780
   MODULE_TYPE                    = SEC
   VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = PlatformSecLib
 
 [Sources]
   Cpu.c
@@ -36,6 +35,7 @@
   PcdLib
   PrePiLib
   SerialPortLib
+#  PeiServicesLib
 
 [Packages]
   EmbeddedPkg/EmbeddedPkg.dec
diff --git a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.fdf b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.fdf
index a8f844586d..2ec77a4c00 100644
--- a/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.fdf
+++ b/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.fdf
@@ -84,7 +84,7 @@ READ_LOCK_CAP      = TRUE
 READ_LOCK_STATUS   = TRUE
 FvNameGuid         = 27A72E80-3118-4c0c-8673-AA5B4EFA9613
 
-INF  UefiCpuPkg/SecCore/SecCoreNative.inf
+INF  Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/RiscVPlatformSecLib.inf
 
 !if $(RISCV_PEI_BOOTING) == TRUE
   INF  Platform/RISC-V/PlatformPkg/PlatformPei/PlatformPeim.inf
diff --git a/Silicon/RISC-V/RiscV.dsc.inc b/Silicon/RISC-V/RiscV.dsc.inc
index 51b0d96988..6377b92067 100644
--- a/Silicon/RISC-V/RiscV.dsc.inc
+++ b/Silicon/RISC-V/RiscV.dsc.inc
@@ -192,7 +192,7 @@
   # SEC Phase modules
   #
 !if $(RISCV_PEI_BOOTING) == TRUE
-  UefiCpuPkg/SecCore/SecCoreNative.inf
+  Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/RiscVPlatformSecLib.inf
   Platform/RISC-V/PlatformPkg/PlatformPei/PlatformPeim.inf
   MdeModulePkg/Core/Pei/PeiMain.inf
   MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {
@@ -205,7 +205,7 @@
       NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
   }
 !else
-  UefiCpuPkg/SecCore/SecCoreNative.inf {
+  Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/RiscVPlatformSecLib.inf {
     <LibraryClasses>
       ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf
       NULL|MdeModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
$ build -a RISCV64 -t GCC5 -p edk2-platforms/Platform/SiFive/U5SeriesPkg/FreedomU540HiFiveUnleashedBoard/U540.dsc
.
.
.
/opt/riscv-gnu-toolchain/lib/gcc/riscv64-unknown-elf/15.1.0/../../../../riscv64-unknown-elf/bin/ld: /home/merle/workspaces/tianocore/Build/FreedomU540HiFiveUnleashed/DEBUG_GCC5/RISCV64/Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/RiscVPlatformSecLib/OUTPUT/PlatformSecLib.lib(Platform.obj): in function `PlatformInitialization':
/home/merle/workspaces/tianocore/edk2-platforms/Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/Platform.c:102:(.text.PlatformInitialization+0xe2): undefined reference to `AllocatePages'
/opt/riscv-gnu-toolchain/lib/gcc/riscv64-unknown-elf/15.1.0/../../../../riscv64-unknown-elf/bin/ld: /home/merle/workspaces/tianocore/Build/FreedomU540HiFiveUnleashed/DEBUG_GCC5/RISCV64/EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib/OUTPUT/PrePiExtractGuidedSectionLib.lib(PrePiExtractGuidedSectionLib.obj): in function `ExtractGuidedSectionLibConstructor':
/home/merle/workspaces/tianocore/edk2/EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.c:233:(.text.ExtractGuidedSectionLibConstructor+0x2e): undefined reference to `AllocatePool'
/opt/riscv-gnu-toolchain/lib/gcc/riscv64-unknown-elf/15.1.0/../../../../riscv64-unknown-elf/bin/ld: /home/merle/workspaces/tianocore/edk2/EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.c:238:(.text.ExtractGuidedSectionLibConstructor+0x5c): undefined reference to `AllocatePool'
/opt/riscv-gnu-toolchain/lib/gcc/riscv64-unknown-elf/15.1.0/../../../../riscv64-unknown-elf/bin/ld: /home/merle/workspaces/tianocore/edk2/EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.c:243:(.text.ExtractGuidedSectionLibConstructor+0x8a): undefined reference to `AllocatePool'
/opt/riscv-gnu-toolchain/lib/gcc/riscv64-unknown-elf/15.1.0/../../../../riscv64-unknown-elf/bin/ld: /home/merle/workspaces/tianocore/Build/FreedomU540HiFiveUnleashed/DEBUG_GCC5/RISCV64/EmbeddedPkg/Library/PrePiLib/PrePiLib/OUTPUT/PrePiLib.lib(FwVol.obj): in function `FfsProcessSection':
/home/merle/workspaces/tianocore/edk2/EmbeddedPkg/Library/PrePiLib/FwVol.c:444:(.text.FfsProcessSection+0x1bc): undefined reference to `AllocatePages'
/opt/riscv-gnu-toolchain/lib/gcc/riscv64-unknown-elf/15.1.0/../../../../riscv64-unknown-elf/bin/ld: /home/merle/workspaces/tianocore/edk2/EmbeddedPkg/Library/PrePiLib/FwVol.c:452:(.text.FfsProcessSection+0x206): undefined reference to `AllocatePages'
/opt/riscv-gnu-toolchain/lib/gcc/riscv64-unknown-elf/15.1.0/../../../../riscv64-unknown-elf/bin/ld: /home/merle/workspaces/tianocore/Build/FreedomU540HiFiveUnleashed/DEBUG_GCC5/RISCV64/EmbeddedPkg/Library/PrePiLib/PrePiLib/OUTPUT/PrePiLib.lib(FwVol.obj): in function `FfsProcessFvFile':
/home/merle/workspaces/tianocore/edk2/EmbeddedPkg/Library/PrePiLib/FwVol.c:927:(.text.FfsProcessFvFile+0x19c): undefined reference to `AllocateAlignedPages'
/opt/riscv-gnu-toolchain/lib/gcc/riscv64-unknown-elf/15.1.0/../../../../riscv64-unknown-elf/bin/ld: /home/merle/workspaces/tianocore/Build/FreedomU540HiFiveUnleashed/DEBUG_GCC5/RISCV64/EmbeddedPkg/Library/PrePiLib/PrePiLib/OUTPUT/PrePiLib.lib(PrePiLib.obj): in function `AllocateCodePages':
/home/merle/workspaces/tianocore/edk2/EmbeddedPkg/Library/PrePiLib/PrePiLib.c:35:(.text.AllocateCodePages+0x10): undefined reference to `AllocatePages'
/opt/riscv-gnu-toolchain/lib/gcc/riscv64-unknown-elf/15.1.0/../../../../riscv64-unknown-elf/bin/ld: /home/merle/workspaces/tianocore/edk2/EmbeddedPkg/Library/PrePiLib/PrePiLib.c:53:(.text.AllocateCodePages+0xaa): undefined reference to `FreePages'
/opt/riscv-gnu-toolchain/lib/gcc/riscv64-unknown-elf/15.1.0/../../../../riscv64-unknown-elf/bin/ld: /home/merle/workspaces/tianocore/Build/FreedomU540HiFiveUnleashed/DEBUG_GCC5/RISCV64/EmbeddedPkg/Library/PrePiLib/PrePiLib/OUTPUT/PrePiLib.lib(PrePiLib.obj): in function `LoadDxeCoreFromFfsFile':
/home/merle/workspaces/tianocore/edk2/EmbeddedPkg/Library/PrePiLib/PrePiLib.c:162:(.text.LoadDxeCoreFromFfsFile+0x206): undefined reference to `AllocatePages'
Building ... /home/merle/workspaces/tianocore/edk2/MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf [RISCV64]
make: 对“tbuild”无需做任何事。
make: 对“tbuild”无需做任何事。
collect2: error: ld returned 1 exit status
Building ... /home/merle/workspaces/tianocore/edk2/MdeModulePkg/Universal/SerialDxe/SerialDxe.inf [RISCV64]
make: *** [GNUmakefile:410:/home/merle/workspaces/tianocore/Build/FreedomU540HiFiveUnleashed/DEBUG_GCC5/RISCV64/Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/RiscVPlatformSecLib/DEBUG/PlatformSecLib.dll] 错误 1


build.py...
 : error 7000: Failed to execute command
	make tbuild [/home/merle/workspaces/tianocore/Build/FreedomU540HiFiveUnleashed/DEBUG_GCC5/RISCV64/Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/RiscVPlatformSecLib]


build.py...
 : error F002: Failed to build module
	/home/merle/workspaces/tianocore/edk2-platforms/Platform/RISC-V/PlatformPkg/Library/RiscVPlatformSecLib/RiscVPlatformSecLib.inf [RISCV64, GCC5, DEBUG]

- Failed -
Build end time: 14:52:30, Dec.01 2025
Build total time: 00:00:04

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what do you mean by above diff and error. If you need to enable PEI booting, just set the RISCV_PEI_BOOTING to TRUE, no? SecCoreNative is used in both PEI and PEIless cases. So, I don't know what exactly is the issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants