Skip to content

Commit da1c6dd

Browse files
Sean-StarLabsmergify[bot]
authored andcommitted
UefiPayloadPkg: Add Secure Boot support
Introduce Secure Boot functionality within UefiPayloadPkg by adding necessary modules and configurations. A new build flag, `SECURE_BOOT_ENABLE`, is introduced to control the activation of Secure Boot. This patch also overrides values in SecurityPkg to enforce image verification from all sources. A new FV (`SECURITY_FV`) for security modules is added for components and the firmware volume sizes to accommodate additional Secure Boot components. Cc: Guo Dong <guo.dong@intel.com> Cc: Ray Ni <ray.ni@intel.com> Cc: James Lu <james.lu@intel.com> Cc: Gua Guo <gua.guo@intel.com> Signed-off-by: Sean Rhodes <sean@starlabs.systems>
1 parent 7bac0a9 commit da1c6dd

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

UefiPayloadPkg/UefiPayloadPkg.ci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@
9696
"BLD_*_DISABLE_RESET_SYSTEM": "TRUE",
9797
"BLD_*_SERIAL_DRIVER_ENABLE": "FALSE",
9898
"BLD_*_BUILD_ARCH": "",
99+
"BLD_*_SECURE_BOOT_ENABLE": "TRUE",
99100
}
100101
}

UefiPayloadPkg/UefiPayloadPkg.dsc

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,11 @@
154154

155155
DEFINE MULTIPLE_DEBUG_PORT_SUPPORT = FALSE
156156

157+
#
158+
# Security
159+
#
160+
DEFINE SECURE_BOOT_ENABLE = FALSE
161+
157162
[BuildOptions]
158163
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
159164
!if $(USE_CBMEM_FOR_CONSOLE) == FALSE
@@ -305,7 +310,17 @@
305310
LockBoxLib|MdeModulePkg/Library/LockBoxNullLib/LockBoxNullLib.inf
306311
!endif
307312
FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf
313+
314+
!if $(SECURE_BOOT_ENABLE) == TRUE
315+
PlatformSecureLib|SecurityPkg/Library/PlatformSecureLibNull/PlatformSecureLibNull.inf
316+
AuthVariableLib|SecurityPkg/Library/AuthVariableLib/AuthVariableLib.inf
317+
SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf
318+
PlatformPKProtectionLib|SecurityPkg/Library/PlatformPKProtectionLibVarPolicy/PlatformPKProtectionLibVarPolicy.inf
319+
SecureBootVariableProvisionLib|SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.inf
320+
!else
308321
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
322+
!endif
323+
309324
!if $(VARIABLE_SUPPORT) == "EMU"
310325
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
311326
!elseif $(VARIABLE_SUPPORT) == "SPI"
@@ -396,6 +411,9 @@
396411
!endif
397412

398413
[LibraryClasses.common.DXE_RUNTIME_DRIVER]
414+
!if $(SECURE_BOOT_ENABLE) == TRUE
415+
BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf
416+
!endif
399417
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
400418
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
401419
ReportStatusCodeLib|MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf
@@ -527,6 +545,13 @@
527545
!endif
528546

529547

548+
!if $(SECURE_BOOT_ENABLE) == TRUE
549+
# Override the default values from SecurityPkg to ensure images from all sources are verified in secure boot
550+
gEfiSecurityPkgTokenSpaceGuid.PcdOptionRomImageVerificationPolicy|0x04
551+
gEfiSecurityPkgTokenSpaceGuid.PcdFixedMediaImageVerificationPolicy|0x04
552+
gEfiSecurityPkgTokenSpaceGuid.PcdRemovableMediaImageVerificationPolicy|0x04
553+
!endif
554+
530555
[PcdsPatchableInModule.X64]
531556
!if $(NETWORK_DRIVER_ENABLE) == TRUE
532557
gEfiNetworkPkgTokenSpaceGuid.PcdAllowHttpConnections|TRUE
@@ -716,8 +741,18 @@
716741
# Components that produce the architectural protocols
717742
#
718743
!if $(SECURITY_STUB_ENABLE) == TRUE
719-
MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
744+
MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf {
745+
<LibraryClasses>
746+
!if $(SECURE_BOOT_ENABLE) == TRUE
747+
NULL|SecurityPkg/Library/DxeImageVerificationLib/DxeImageVerificationLib.inf
748+
!endif
749+
}
750+
!endif
751+
752+
!if $(SECURE_BOOT_ENABLE) == TRUE
753+
SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
720754
!endif
755+
721756
UefiCpuPkg/CpuDxe/CpuDxe.inf
722757
MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
723758
!if $(BOOTSPLASH_IMAGE)

UefiPayloadPkg/UefiPayloadPkg.fdf

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ DEFINE FD_SIZE = 0x00850000
1717
DEFINE NUM_BLOCKS = 0x850
1818
!else
1919

20-
DEFINE FD_SIZE = 0x00590000
21-
DEFINE NUM_BLOCKS = 0x590
20+
DEFINE FD_SIZE = 0x00700000
21+
DEFINE NUM_BLOCKS = 0x700
2222
!endif
2323

2424
################################################################################
@@ -208,6 +208,12 @@ INF PcAtChipsetPkg/PcatRealTimeClockRuntimeDxe/PcatRealTimeClockRuntimeDxe.inf
208208
INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableSmmRuntimeDxe.inf
209209
!endif
210210

211+
!if $(UNIVERSAL_PAYLOAD) == FALSE
212+
!if $(SECURE_BOOT_ENABLE) == TRUE
213+
INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
214+
!endif
215+
!endif
216+
211217
INF UefiCpuPkg/CpuIo2Dxe/CpuIo2Dxe.inf
212218
INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
213219
!if $(MEMORY_TEST) == "GENERIC"
@@ -333,6 +339,35 @@ INF ShellPkg/DynamicCommand/DpDynamicCommand/DpDynamicCommand.inf
333339
INF ShellPkg/Application/Shell/Shell.inf
334340
!endif
335341

342+
!if $(UNIVERSAL_PAYLOAD) == TRUE
343+
!if $(SECURE_BOOT_ENABLE) == TRUE
344+
345+
[FV.SECFV]
346+
FvNameGuid = 2700E2F3-19D2-4E2D-9F13-BC891B9FC62C
347+
BlockSize = $(FD_BLOCK_SIZE)
348+
FvForceRebase = FALSE
349+
FvAlignment = 16
350+
ERASE_POLARITY = 1
351+
MEMORY_MAPPED = TRUE
352+
STICKY_WRITE = TRUE
353+
LOCK_CAP = TRUE
354+
LOCK_STATUS = TRUE
355+
WRITE_DISABLED_CAP = TRUE
356+
WRITE_ENABLED_CAP = TRUE
357+
WRITE_STATUS = TRUE
358+
WRITE_LOCK_CAP = TRUE
359+
WRITE_LOCK_STATUS = TRUE
360+
READ_DISABLED_CAP = TRUE
361+
READ_ENABLED_CAP = TRUE
362+
READ_STATUS = TRUE
363+
READ_LOCK_CAP = TRUE
364+
READ_LOCK_STATUS = TRUE
365+
366+
INF SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
367+
368+
!endif
369+
!endif
370+
336371

337372
################################################################################
338373
#

UefiPayloadPkg/UniversalPayloadBuild.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def BuildUniversalPayload(Args):
144144
EntryModuleInf = os.path.normpath("UefiPayloadPkg/UefiPayloadEntry/{}.inf".format (UpldEntryFile))
145145
DxeFvOutputDir = os.path.join(BuildDir, "{}_{}".format (BuildTarget, ToolChain), os.path.normpath("FV/DXEFV.Fv"))
146146
BdsFvOutputDir = os.path.join(BuildDir, "{}_{}".format (BuildTarget, ToolChain), os.path.normpath("FV/BDSFV.Fv"))
147+
SecFvOutputDir = os.path.join(BuildDir, "{}_{}".format (BuildTarget, ToolChain), os.path.normpath("FV/SECFV.Fv"))
147148
NetworkFvOutputDir = os.path.join(BuildDir, "{}_{}".format (BuildTarget, ToolChain), os.path.normpath("FV/NETWORKFV.Fv"))
148149
PayloadReportPath = os.path.join(BuildDir, "UefiUniversalPayload.txt")
149150
ModuleReportPath = os.path.join(BuildDir, "UefiUniversalPayloadEntry.txt")
@@ -212,6 +213,7 @@ def BuildUniversalPayload(Args):
212213
MultiFvList = [
213214
['uefi_fv', os.path.join(BuildDir, "{}_{}".format (BuildTarget, ToolChain), os.path.normpath("FV/DXEFV.Fv")) ],
214215
['bds_fv', os.path.join(BuildDir, "{}_{}".format (BuildTarget, ToolChain), os.path.normpath("FV/BDSFV.Fv")) ],
216+
['sec_fv', os.path.join(BuildDir, "{}_{}".format (BuildTarget, ToolChain), os.path.normpath("FV/SECFV.Fv")) ],
215217
['network_fv', os.path.join(BuildDir, "{}_{}".format (BuildTarget, ToolChain), os.path.normpath("FV/NETWORKFV.Fv"))],
216218
]
217219

@@ -234,6 +236,7 @@ def BuildUniversalPayload(Args):
234236
fit_image_info_header.TargetPath = os.path.join(BuildDir, 'UniversalPayload.fit')
235237
fit_image_info_header.UefifvPath = DxeFvOutputDir
236238
fit_image_info_header.BdsfvPath = BdsFvOutputDir
239+
fit_image_info_header.SecfvPath = SecFvOutputDir
237240
fit_image_info_header.NetworkfvPath = NetworkFvOutputDir
238241
fit_image_info_header.DataOffset = 0x1000
239242
fit_image_info_header.LoadAddr = Args.LoadAddress

0 commit comments

Comments
 (0)