]> git.proxmox.com Git - mirror_edk2.git/blame - SignedCapsulePkg/Universal/SystemFirmwareUpdate/SystemFirmwareCommonDxe.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / SignedCapsulePkg / Universal / SystemFirmwareUpdate / SystemFirmwareCommonDxe.c
CommitLineData
f6f91d38
JY
1/** @file\r
2 Produce FMP instance for system firmware.\r
3\r
c8dca871 4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
fbf06957 5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
f6f91d38
JY
6\r
7**/\r
8\r
9#include "SystemFirmwareDxe.h"\r
10\r
b8786489
MK
11EFI_GUID gSystemFmpLastAttemptVariableGuid = SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_GUID;\r
12EFI_GUID gSystemFmpProtocolGuid = SYSTEM_FMP_PROTOCOL_GUID;\r
f6f91d38 13\r
b8786489 14EFI_FIRMWARE_MANAGEMENT_PROTOCOL mFirmwareManagementProtocol = {\r
f6f91d38
JY
15 FmpGetImageInfo,\r
16 FmpGetImage,\r
17 FmpSetImage,\r
18 FmpCheckImage,\r
19 FmpGetPackageInfo,\r
20 FmpSetPackageInfo\r
21};\r
22\r
23/**\r
24 Returns information about the current firmware image(s) of the device.\r
25\r
26 This function allows a copy of the current firmware image to be created and saved.\r
27 The saved copy could later been used, for example, in firmware image recovery or rollback.\r
28\r
29 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
30 @param[in, out] ImageInfoSize A pointer to the size, in bytes, of the ImageInfo buffer.\r
31 On input, this is the size of the buffer allocated by the caller.\r
32 On output, it is the size of the buffer returned by the firmware\r
33 if the buffer was large enough, or the size of the buffer needed\r
34 to contain the image(s) information if the buffer was too small.\r
35 @param[in, out] ImageInfo A pointer to the buffer in which firmware places the current image(s)\r
36 information. The information is an array of EFI_FIRMWARE_IMAGE_DESCRIPTORs.\r
37 @param[out] DescriptorVersion A pointer to the location in which firmware returns the version number\r
38 associated with the EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
39 @param[out] DescriptorCount A pointer to the location in which firmware returns the number of\r
40 descriptors or firmware images within this device.\r
41 @param[out] DescriptorSize A pointer to the location in which firmware returns the size, in bytes,\r
42 of an individual EFI_FIRMWARE_IMAGE_DESCRIPTOR.\r
43 @param[out] PackageVersion A version number that represents all the firmware images in the device.\r
44 The format is vendor specific and new version must have a greater value\r
45 than the old version. If PackageVersion is not supported, the value is\r
46 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version comparison\r
47 is to be performed using PackageVersionName. A value of 0xFFFFFFFD indicates\r
48 that package version update is in progress.\r
49 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing the\r
50 package version name. The buffer is allocated by this function with\r
51 AllocatePool(), and it is the caller's responsibility to free it with a call\r
52 to FreePool().\r
53\r
54 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
55 @retval EFI_BUFFER_TOO_SMALL The ImageInfo buffer was too small. The current buffer size\r
56 needed to hold the image(s) information is returned in ImageInfoSize.\r
57 @retval EFI_INVALID_PARAMETER ImageInfoSize is NULL.\r
58 @retval EFI_DEVICE_ERROR Valid information could not be returned. Possible corrupted image.\r
59\r
60**/\r
61EFI_STATUS\r
62EFIAPI\r
63FmpGetImageInfo (\r
b8786489
MK
64 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
65 IN OUT UINTN *ImageInfoSize,\r
66 IN OUT EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo,\r
67 OUT UINT32 *DescriptorVersion,\r
68 OUT UINT8 *DescriptorCount,\r
69 OUT UINTN *DescriptorSize,\r
70 OUT UINT32 *PackageVersion,\r
71 OUT CHAR16 **PackageVersionName\r
f6f91d38
JY
72 )\r
73{\r
b8786489
MK
74 SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate;\r
75 EDKII_SYSTEM_FIRMWARE_IMAGE_DESCRIPTOR *ImageDescriptor;\r
f6f91d38 76\r
b8786489 77 SystemFmpPrivate = SYSTEM_FMP_PRIVATE_DATA_FROM_FMP (This);\r
f6f91d38 78\r
b8786489 79 if (ImageInfoSize == NULL) {\r
f6f91d38
JY
80 return EFI_INVALID_PARAMETER;\r
81 }\r
82\r
b8786489
MK
83 if (*ImageInfoSize < sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount) {\r
84 *ImageInfoSize = sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount;\r
f6f91d38
JY
85 return EFI_BUFFER_TOO_SMALL;\r
86 }\r
87\r
b8786489
MK
88 if ((ImageInfo == NULL) ||\r
89 (DescriptorVersion == NULL) ||\r
90 (DescriptorCount == NULL) ||\r
91 (DescriptorSize == NULL) ||\r
92 (PackageVersion == NULL) ||\r
93 (PackageVersionName == NULL))\r
94 {\r
f6f91d38
JY
95 return EFI_INVALID_PARAMETER;\r
96 }\r
97\r
b8786489
MK
98 *ImageInfoSize = sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR) * SystemFmpPrivate->DescriptorCount;\r
99 *DescriptorSize = sizeof (EFI_FIRMWARE_IMAGE_DESCRIPTOR);\r
100 *DescriptorCount = SystemFmpPrivate->DescriptorCount;\r
101 *DescriptorVersion = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION;\r
f6f91d38
JY
102\r
103 //\r
104 // supports 1 ImageInfo descriptor\r
105 //\r
b8786489 106 ImageDescriptor = SystemFmpPrivate->ImageDescriptor;\r
f6f91d38
JY
107 ImageInfo->ImageIndex = ImageDescriptor->ImageIndex;\r
108 CopyGuid (&ImageInfo->ImageTypeId, &ImageDescriptor->ImageTypeId);\r
109 ImageInfo->ImageId = ImageDescriptor->ImageId;\r
110 if (ImageDescriptor->ImageIdNameStringOffset != 0) {\r
111 ImageInfo->ImageIdName = (CHAR16 *)((UINTN)ImageDescriptor + ImageDescriptor->ImageIdNameStringOffset);\r
112 } else {\r
113 ImageInfo->ImageIdName = NULL;\r
114 }\r
b8786489 115\r
f6f91d38
JY
116 ImageInfo->Version = ImageDescriptor->Version;\r
117 if (ImageDescriptor->VersionNameStringOffset != 0) {\r
118 ImageInfo->VersionName = (CHAR16 *)((UINTN)ImageDescriptor + ImageDescriptor->VersionNameStringOffset);\r
119 } else {\r
120 ImageInfo->VersionName = NULL;\r
121 }\r
b8786489
MK
122\r
123 ImageInfo->Size = (UINTN)ImageDescriptor->Size;\r
124 ImageInfo->AttributesSupported = ImageDescriptor->AttributesSupported;\r
125 ImageInfo->AttributesSetting = ImageDescriptor->AttributesSetting;\r
126 ImageInfo->Compatibilities = ImageDescriptor->Compatibilities;\r
f6f91d38 127 ImageInfo->LowestSupportedImageVersion = ImageDescriptor->LowestSupportedImageVersion;\r
b8786489
MK
128 ImageInfo->LastAttemptVersion = SystemFmpPrivate->LastAttempt.LastAttemptVersion;\r
129 ImageInfo->LastAttemptStatus = SystemFmpPrivate->LastAttempt.LastAttemptStatus;\r
130 ImageInfo->HardwareInstance = ImageDescriptor->HardwareInstance;\r
f6f91d38
JY
131\r
132 //\r
133 // package version\r
134 //\r
135 *PackageVersion = ImageDescriptor->PackageVersion;\r
136 if (ImageDescriptor->PackageVersionNameStringOffset != 0) {\r
137 *PackageVersionName = (VOID *)((UINTN)ImageDescriptor + ImageDescriptor->PackageVersionNameStringOffset);\r
b8786489 138 *PackageVersionName = AllocateCopyPool (StrSize (*PackageVersionName), *PackageVersionName);\r
f6f91d38
JY
139 } else {\r
140 *PackageVersionName = NULL;\r
141 }\r
142\r
143 return EFI_SUCCESS;\r
144}\r
145\r
146/**\r
147 Retrieves a copy of the current firmware image of the device.\r
148\r
149 This function allows a copy of the current firmware image to be created and saved.\r
150 The saved copy could later been used, for example, in firmware image recovery or rollback.\r
151\r
152 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
153 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
154 The number is between 1 and DescriptorCount.\r
155 @param[in,out] Image Points to the buffer where the current image is copied to.\r
156 @param[in,out] ImageSize On entry, points to the size of the buffer pointed to by Image, in bytes.\r
157 On return, points to the length of the image, in bytes.\r
158\r
159 @retval EFI_SUCCESS The device was successfully updated with the new image.\r
160 @retval EFI_BUFFER_TOO_SMALL The buffer specified by ImageSize is too small to hold the\r
161 image. The current buffer size needed to hold the image is returned\r
162 in ImageSize.\r
163 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
164 @retval EFI_NOT_FOUND The current image is not copied to the buffer.\r
165 @retval EFI_UNSUPPORTED The operation is not supported.\r
c8dca871 166 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
f6f91d38
JY
167\r
168**/\r
169EFI_STATUS\r
170EFIAPI\r
171FmpGetImage (\r
172 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
173 IN UINT8 ImageIndex,\r
174 IN OUT VOID *Image,\r
175 IN OUT UINTN *ImageSize\r
176 )\r
177{\r
f6f91d38
JY
178 return EFI_UNSUPPORTED;\r
179}\r
180\r
181/**\r
182 Checks if the firmware image is valid for the device.\r
183\r
184 This function allows firmware update application to validate the firmware image without\r
185 invoking the SetImage() first.\r
186\r
187 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
188 @param[in] ImageIndex A unique number identifying the firmware image(s) within the device.\r
189 The number is between 1 and DescriptorCount.\r
190 @param[in] Image Points to the new image.\r
191 @param[in] ImageSize Size of the new image in bytes.\r
192 @param[out] ImageUpdatable Indicates if the new image is valid for update. It also provides,\r
193 if available, additional information if the image is invalid.\r
194\r
195 @retval EFI_SUCCESS The image was successfully checked.\r
196 @retval EFI_INVALID_PARAMETER The Image was NULL.\r
197 @retval EFI_UNSUPPORTED The operation is not supported.\r
c8dca871 198 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
f6f91d38
JY
199\r
200**/\r
201EFI_STATUS\r
202EFIAPI\r
203FmpCheckImage (\r
204 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
205 IN UINT8 ImageIndex,\r
206 IN CONST VOID *Image,\r
207 IN UINTN ImageSize,\r
208 OUT UINT32 *ImageUpdatable\r
209 )\r
210{\r
211 return EFI_UNSUPPORTED;\r
212}\r
213\r
214/**\r
215 Returns information about the firmware package.\r
216\r
217 This function returns package information.\r
218\r
219 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
220 @param[out] PackageVersion A version number that represents all the firmware images in the device.\r
221 The format is vendor specific and new version must have a greater value\r
222 than the old version. If PackageVersion is not supported, the value is\r
223 0xFFFFFFFF. A value of 0xFFFFFFFE indicates that package version\r
224 comparison is to be performed using PackageVersionName. A value of\r
225 0xFFFFFFFD indicates that package version update is in progress.\r
226 @param[out] PackageVersionName A pointer to a pointer to a null-terminated string representing\r
227 the package version name. The buffer is allocated by this function with\r
228 AllocatePool(), and it is the caller's responsibility to free it with a\r
229 call to FreePool().\r
230 @param[out] PackageVersionNameMaxLen The maximum length of package version name if device supports update of\r
231 package version name. A value of 0 indicates the device does not support\r
232 update of package version name. Length is the number of Unicode characters,\r
233 including the terminating null character.\r
234 @param[out] AttributesSupported Package attributes that are supported by this device. See 'Package Attribute\r
235 Definitions' for possible returned values of this parameter. A value of 1\r
236 indicates the attribute is supported and the current setting value is\r
237 indicated in AttributesSetting. A value of 0 indicates the attribute is not\r
238 supported and the current setting value in AttributesSetting is meaningless.\r
239 @param[out] AttributesSetting Package attributes. See 'Package Attribute Definitions' for possible returned\r
240 values of this parameter\r
241\r
242 @retval EFI_SUCCESS The package information was successfully returned.\r
243 @retval EFI_UNSUPPORTED The operation is not supported.\r
244\r
245**/\r
246EFI_STATUS\r
247EFIAPI\r
248FmpGetPackageInfo (\r
b8786489
MK
249 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
250 OUT UINT32 *PackageVersion,\r
251 OUT CHAR16 **PackageVersionName,\r
252 OUT UINT32 *PackageVersionNameMaxLen,\r
253 OUT UINT64 *AttributesSupported,\r
254 OUT UINT64 *AttributesSetting\r
f6f91d38
JY
255 )\r
256{\r
257 return EFI_UNSUPPORTED;\r
258}\r
259\r
260/**\r
261 Updates information about the firmware package.\r
262\r
263 This function updates package information.\r
264 This function returns EFI_UNSUPPORTED if the package information is not updatable.\r
265 VendorCode enables vendor to implement vendor-specific package information update policy.\r
266 Null if the caller did not specify this policy or use the default policy.\r
267\r
268 @param[in] This A pointer to the EFI_FIRMWARE_MANAGEMENT_PROTOCOL instance.\r
269 @param[in] Image Points to the authentication image.\r
270 Null if authentication is not required.\r
271 @param[in] ImageSize Size of the authentication image in bytes.\r
272 0 if authentication is not required.\r
273 @param[in] VendorCode This enables vendor to implement vendor-specific firmware\r
274 image update policy.\r
275 Null indicates the caller did not specify this policy or use\r
276 the default policy.\r
277 @param[in] PackageVersion The new package version.\r
278 @param[in] PackageVersionName A pointer to the new null-terminated Unicode string representing\r
279 the package version name.\r
280 The string length is equal to or less than the value returned in\r
281 PackageVersionNameMaxLen.\r
282\r
283 @retval EFI_SUCCESS The device was successfully updated with the new package\r
284 information.\r
285 @retval EFI_INVALID_PARAMETER The PackageVersionName length is longer than the value\r
286 returned in PackageVersionNameMaxLen.\r
287 @retval EFI_UNSUPPORTED The operation is not supported.\r
c8dca871 288 @retval EFI_SECURITY_VIOLATION The operation could not be performed due to an authentication failure.\r
f6f91d38
JY
289\r
290**/\r
291EFI_STATUS\r
292EFIAPI\r
293FmpSetPackageInfo (\r
b8786489
MK
294 IN EFI_FIRMWARE_MANAGEMENT_PROTOCOL *This,\r
295 IN CONST VOID *Image,\r
296 IN UINTN ImageSize,\r
297 IN CONST VOID *VendorCode,\r
298 IN UINT32 PackageVersion,\r
299 IN CONST CHAR16 *PackageVersionName\r
f6f91d38
JY
300 )\r
301{\r
302 return EFI_UNSUPPORTED;\r
303}\r
304\r
305/**\r
306 Initialize SystemFmpDriver private data structure.\r
307\r
308 @param[in] SystemFmpPrivate private data structure to be initialized.\r
309\r
310 @return EFI_SUCCESS private data is initialized.\r
311**/\r
312EFI_STATUS\r
313InitializePrivateData (\r
314 IN SYSTEM_FMP_PRIVATE_DATA *SystemFmpPrivate\r
315 )\r
316{\r
b8786489
MK
317 EFI_STATUS VarStatus;\r
318 UINTN VarSize;\r
f6f91d38
JY
319\r
320 SystemFmpPrivate->Signature = SYSTEM_FMP_PRIVATE_DATA_SIGNATURE;\r
321 SystemFmpPrivate->Handle = NULL;\r
322 SystemFmpPrivate->DescriptorCount = 1;\r
b8786489 323 CopyMem (&SystemFmpPrivate->Fmp, &mFirmwareManagementProtocol, sizeof (EFI_FIRMWARE_MANAGEMENT_PROTOCOL));\r
f6f91d38 324\r
b8786489 325 SystemFmpPrivate->ImageDescriptor = PcdGetPtr (PcdEdkiiSystemFirmwareImageDescriptor);\r
f6f91d38
JY
326\r
327 SystemFmpPrivate->LastAttempt.LastAttemptVersion = 0x0;\r
b8786489
MK
328 SystemFmpPrivate->LastAttempt.LastAttemptStatus = 0x0;\r
329 VarSize = sizeof (SystemFmpPrivate->LastAttempt);\r
330 VarStatus = gRT->GetVariable (\r
331 SYSTEM_FMP_LAST_ATTEMPT_VARIABLE_NAME,\r
332 &gSystemFmpLastAttemptVariableGuid,\r
333 NULL,\r
334 &VarSize,\r
335 &SystemFmpPrivate->LastAttempt\r
336 );\r
337 DEBUG ((DEBUG_INFO, "GetLastAttempt - %r\n", VarStatus));\r
338 DEBUG ((DEBUG_INFO, "GetLastAttempt Version - 0x%x, State - 0x%x\n", SystemFmpPrivate->LastAttempt.LastAttemptVersion, SystemFmpPrivate->LastAttempt.LastAttemptStatus));\r
f6f91d38
JY
339\r
340 return EFI_SUCCESS;\r
341}\r