@@ -22,6 +22,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
2222#include <Library/ReportStatusCodeLib.h>
2323
2424#define STACK_SIZE 0x20000
25+ extern EFI_GUID gEfiNonCcFvGuid ;
2526
2627/**
2728 Transfers control to DxeCore.
@@ -136,6 +137,117 @@ FindDxeCore (
136137 return Status ;
137138}
138139
140+ EFI_STATUS
141+ EFIAPI
142+ CheckSectionHookForDxeNonCc (
143+ IN EFI_COMMON_SECTION_HEADER * Section
144+ )
145+ {
146+ VOID * Buffer ;
147+ EFI_STATUS Status ;
148+ EFI_FV_INFO FvImageInfo ;
149+
150+ ASSERT (Section -> Type == EFI_SECTION_FIRMWARE_VOLUME_IMAGE );
151+
152+ if (IS_SECTION2 (Section )) {
153+ Buffer = (VOID * )((UINT8 * )Section + sizeof (EFI_COMMON_SECTION_HEADER2 ));
154+ } else {
155+ Buffer = (VOID * )((UINT8 * )Section + sizeof (EFI_COMMON_SECTION_HEADER ));
156+ }
157+
158+ ZeroMem (& FvImageInfo , sizeof (FvImageInfo ));
159+ Status = FfsGetVolumeInfo ((EFI_PEI_FV_HANDLE )(UINTN )Buffer , & FvImageInfo );
160+ if (EFI_ERROR (Status )) {
161+ DEBUG ((DEBUG_INFO , "Cannot get volume info! %r\n" , Status ));
162+ return Status ;
163+ }
164+
165+ return CompareGuid (& FvImageInfo .FvName , & gEfiNonCcFvGuid ) ? EFI_SUCCESS : EFI_NOT_FOUND ;
166+ }
167+
168+ EFI_STATUS
169+ EFIAPI
170+ FindDxeNonCc (
171+ IN INTN FvInstance
172+ )
173+ {
174+ EFI_STATUS Status ;
175+ EFI_PEI_FV_HANDLE VolumeHandle ;
176+ EFI_PEI_FILE_HANDLE FileHandle ;
177+ EFI_PEI_FV_HANDLE FvImageHandle ;
178+ EFI_FV_INFO FvImageInfo ;
179+ UINT32 FvAlignment ;
180+ VOID * FvBuffer ;
181+
182+ FileHandle = NULL ;
183+
184+ //
185+ // Caller passed in a specific FV to try, so only try that one
186+ //
187+ Status = FfsFindNextVolume (FvInstance , & VolumeHandle );
188+ ASSERT (Status == EFI_SUCCESS );
189+
190+ Status = FfsFindNextFile (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE , VolumeHandle , & FileHandle );
191+ ASSERT (FileHandle != NULL );
192+
193+ //
194+ // Find FvImage in FvFile
195+ //
196+ Status = FfsFindSectionData (EFI_SECTION_FIRMWARE_VOLUME_IMAGE , CheckSectionHookForDxeNonCc , FileHandle , (VOID * * )& FvImageHandle );
197+ if (EFI_ERROR (Status )) {
198+ return Status ;
199+ }
200+
201+ //
202+ // Collect FvImage Info.
203+ //
204+ ZeroMem (& FvImageInfo , sizeof (FvImageInfo ));
205+ Status = FfsGetVolumeInfo (FvImageHandle , & FvImageInfo );
206+ ASSERT_EFI_ERROR (Status );
207+
208+ //
209+ // FvAlignment must be more than 8 bytes required by FvHeader structure.
210+ //
211+ FvAlignment = 1 << ((FvImageInfo .FvAttributes & EFI_FVB2_ALIGNMENT ) >> 16 );
212+ if (FvAlignment < 8 ) {
213+ FvAlignment = 8 ;
214+ }
215+
216+ //
217+ // Check FvImage
218+ //
219+ if ((UINTN )FvImageInfo .FvStart % FvAlignment != 0 ) {
220+ FvBuffer = AllocateAlignedPages (EFI_SIZE_TO_PAGES ((UINT32 )FvImageInfo .FvSize ), FvAlignment );
221+ if (FvBuffer == NULL ) {
222+ return EFI_OUT_OF_RESOURCES ;
223+ }
224+
225+ CopyMem (FvBuffer , FvImageInfo .FvStart , (UINTN )FvImageInfo .FvSize );
226+ //
227+ // Update FvImageInfo after reload FvImage to new aligned memory
228+ //
229+ FfsGetVolumeInfo ((EFI_PEI_FV_HANDLE )FvBuffer , & FvImageInfo );
230+ }
231+
232+ //
233+ // Inform HOB consumer phase, i.e. DXE core, the existence of this FV
234+ //
235+ BuildFvHob ((EFI_PHYSICAL_ADDRESS )(UINTN )FvImageInfo .FvStart , FvImageInfo .FvSize );
236+
237+ //
238+ // Makes the encapsulated volume show up in DXE phase to skip processing of
239+ // encapsulated file again.
240+ //
241+ BuildFv2Hob (
242+ (EFI_PHYSICAL_ADDRESS )(UINTN )FvImageInfo .FvStart ,
243+ FvImageInfo .FvSize ,
244+ & FvImageInfo .FvName ,
245+ & (((EFI_FFS_FILE_HEADER * )FileHandle )-> Name )
246+ );
247+
248+ return Status ;
249+ }
250+
139251/**
140252 This function finds DXE Core in the firmware volume and transfer the control to
141253 DXE core.
@@ -168,10 +280,14 @@ DxeLoadCore (
168280 return Status ;
169281 }
170282
283+ if (!TdIsEnabled ()) {
284+ FindDxeNonCc (FvInstance );
285+ }
286+
171287 //
172288 // Load the DXE Core from a Firmware Volume.
173289 //
174- Status = FfsFindSectionData (EFI_SECTION_PE32 , FileHandle , & PeCoffImage );
290+ Status = FfsFindSectionData (EFI_SECTION_PE32 , NULL , FileHandle , & PeCoffImage );
175291 if (EFI_ERROR (Status )) {
176292 return Status ;
177293 }
0 commit comments