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