TianoCore EDK2 master
Loading...
Searching...
No Matches
SystemFirmwareReportDxe.c
Go to the documentation of this file.
1
16#include "SystemFirmwareDxe.h"
17
18//
19// SystemFmp driver private data
20//
21SYSTEM_FMP_PRIVATE_DATA *mSystemFmpPrivate = NULL;
22
40 IN VOID *Image,
41 IN UINTN ImageSize,
42 OUT UINT32 *LastAttemptVersion,
43 OUT UINT32 *LastAttemptStatus
44 )
45{
46 EFI_STATUS Status;
47 VOID *AuthenticatedImage;
48 UINTN AuthenticatedImageSize;
49 VOID *DispatchFvImage;
50 UINTN DispatchFvImageSize;
51 EFI_HANDLE FvProtocolHandle;
53 BOOLEAN Result;
54
55 AuthenticatedImage = NULL;
56 AuthenticatedImageSize = 0;
57
58 DEBUG ((DEBUG_INFO, "DispatchSystemFmpImages\n"));
59
60 //
61 // Verify
62 //
63 Status = CapsuleAuthenticateSystemFirmware (Image, ImageSize, FALSE, LastAttemptVersion, LastAttemptStatus, &AuthenticatedImage, &AuthenticatedImageSize);
64 if (EFI_ERROR (Status)) {
65 DEBUG ((DEBUG_INFO, "SystemFirmwareAuthenticateImage - %r\n", Status));
66 return Status;
67 }
68
69 //
70 // Get FV
71 //
72 Result = ExtractDriverFvImage (AuthenticatedImage, AuthenticatedImageSize, &DispatchFvImage, &DispatchFvImageSize);
73 if (Result) {
74 DEBUG ((DEBUG_INFO, "ExtractDriverFvImage\n"));
75 //
76 // Dispatch
77 //
78 if (((EFI_FIRMWARE_VOLUME_HEADER *)DispatchFvImage)->FvLength == DispatchFvImageSize) {
79 FvImage = AllocatePages (EFI_SIZE_TO_PAGES (DispatchFvImageSize));
80 if (FvImage != NULL) {
81 CopyMem (FvImage, DispatchFvImage, DispatchFvImageSize);
82 Status = gDS->ProcessFirmwareVolume (
83 (VOID *)FvImage,
84 (UINTN)FvImage->FvLength,
85 &FvProtocolHandle
86 );
87 DEBUG ((DEBUG_INFO, "ProcessFirmwareVolume - %r\n", Status));
88 if (!EFI_ERROR (Status)) {
89 gDS->Dispatch ();
90 DEBUG ((DEBUG_INFO, "Dispatch Done\n"));
91 }
92 }
93 }
94 }
95
96 return EFI_SUCCESS;
97}
98
146EFIAPI
149 IN UINT8 ImageIndex,
150 IN CONST VOID *Image,
151 IN UINTN ImageSize,
152 IN CONST VOID *VendorCode,
154 OUT CHAR16 **AbortReason
155 )
156{
157 SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate;
159 EFI_STATUS Status;
160 EFI_STATUS VarStatus;
161
162 if ((Image == NULL) || (ImageSize == 0) || (AbortReason == NULL)) {
163 return EFI_INVALID_PARAMETER;
164 }
165
166 SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP (This);
167 *AbortReason = NULL;
168
169 if ((ImageIndex == 0) || (ImageIndex > SystemFmpPrivate->DescriptorCount)) {
170 return EFI_INVALID_PARAMETER;
171 }
172
173 //
174 // Process FV
175 //
176 Status = DispatchSystemFmpImages ((VOID *)Image, ImageSize, &SystemFmpPrivate->LastAttempt.LastAttemptVersion, &SystemFmpPrivate->LastAttempt.LastAttemptStatus);
177 DEBUG ((DEBUG_INFO, "(Agent)SetImage - LastAttempt Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));
178 if (EFI_ERROR (Status)) {
179 VarStatus = gRT->SetVariable (
180 SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,
181 &gSystemFmpLastAttemptVariableGuid,
182 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
183 sizeof (SystemFmpPrivate->LastAttempt),
184 &SystemFmpPrivate->LastAttempt
185 );
186 DEBUG ((DEBUG_INFO, "(Agent)SetLastAttempt - %r\n", VarStatus));
187 return Status;
188 }
189
190 //
191 // Pass Thru to System FMP Protocol on same handle as FMP Protocol
192 //
193 Status = gBS->HandleProtocol (
194 SystemFmpPrivate->Handle,
195 &gSystemFmpProtocolGuid,
196 (VOID **)&SystemFmp
197 );
198 if (EFI_ERROR (Status)) {
199 Status = gBS->LocateProtocol (
200 &gSystemFmpProtocolGuid,
201 NULL,
202 (VOID **)&SystemFmp
203 );
204 if (EFI_ERROR (Status)) {
205 DEBUG ((DEBUG_INFO, "(Agent)SetImage - SystemFmpProtocol - %r\n", Status));
206 SystemFmpPrivate->LastAttempt.LastAttemptStatus = LAST_ATTEMPT_STATUS_ERROR_INVALID_FORMAT;
207 VarStatus = gRT->SetVariable (
208 SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,
209 &gSystemFmpLastAttemptVariableGuid,
210 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
211 sizeof (SystemFmpPrivate->LastAttempt),
212 &SystemFmpPrivate->LastAttempt
213 );
214 DEBUG ((DEBUG_INFO, "(Agent)SetLastAttempt - %r\n", VarStatus));
215 return Status;
216 }
217 }
218
219 return SystemFmp->SetImage (SystemFmp, ImageIndex, Image, ImageSize, VendorCode, Progress, AbortReason);
220}
221
231EFIAPI
233 IN EFI_HANDLE ImageHandle,
234 IN EFI_SYSTEM_TABLE *SystemTable
235 )
236{
237 EFI_STATUS Status;
238
239 //
240 // Initialize SystemFmpPrivateData
241 //
242 mSystemFmpPrivate = AllocateZeroPool (sizeof (SYSTEM_FMP_PRIVATE_DATA));
243 if (mSystemFmpPrivate == NULL) {
244 return EFI_OUT_OF_RESOURCES;
245 }
246
247 Status = InitializePrivateData (mSystemFmpPrivate);
248 if (EFI_ERROR (Status)) {
249 FreePool (mSystemFmpPrivate);
250 mSystemFmpPrivate = NULL;
251 return Status;
252 }
253
254 //
255 // Install FMP protocol.
256 //
257 Status = gBS->InstallProtocolInterface (
258 &mSystemFmpPrivate->Handle,
259 &gEfiFirmwareManagementProtocolGuid,
261 &mSystemFmpPrivate->Fmp
262 );
263 if (EFI_ERROR (Status)) {
264 FreePool (mSystemFmpPrivate);
265 mSystemFmpPrivate = NULL;
266 return Status;
267 }
268
269 return Status;
270}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_DXE_SERVICES * gDS
BOOLEAN EFIAPI ExtractDriverFvImage(IN VOID *AuthenticatedImage, IN UINTN AuthenticatedImageSize, OUT VOID **DriverFvImage, OUT UINTN *DriverFvImageSize)
EFI_STATUS EFIAPI CapsuleAuthenticateSystemFirmware(IN VOID *Image, IN UINTN ImageSize, IN BOOLEAN ForceVersionMatch, OUT UINT32 *LastAttemptVersion, OUT UINT32 *LastAttemptStatus, OUT VOID **AuthenticatedImage, OUT UINTN *AuthenticatedImageSize)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS(EFIAPI * EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS)(IN UINTN Completion)
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
VOID *EFIAPI AllocatePages(IN UINTN Pages)
EFI_STATUS InitializePrivateData(IN SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate)
#define SYSTEM_FMP_PRIVATE_DATA_FROM_FMP(a)
EFI_STATUS EFIAPI SystemFirmwareReportMainDxe(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS DispatchSystemFmpImages(IN VOID *Image, IN UINTN ImageSize, OUT UINT32 *LastAttemptVersion, OUT UINT32 *LastAttemptStatus)
EFI_STATUS EFIAPI FmpSetImage(IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This, IN UINT8 ImageIndex, IN CONST VOID *Image, IN UINTN ImageSize, IN CONST VOID *VendorCode, IN EFI_FIRMWARE_MANAGEMENT_UPDATE_IMAGE_PROGRESS Progress, OUT CHAR16 **AbortReason)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
#define EFI_VARIABLE_NON_VOLATILE
@ EFI_NATIVE_INTERFACE
Definition: UefiSpec.h:1193