]>
Commit | Line | Data |
---|---|---|
3cbfba02 DW |
1 | /*++\r |
2 | \r | |
3 | Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved\r | |
4 | \r\r | |
9dc8036d MK |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
6 | \r | |
3cbfba02 DW |
7 | \r\r |
8 | \r | |
9 | Module Name:\r | |
10 | \r | |
11 | BiosIdLib.c\r | |
12 | \r | |
13 | Abstract:\r | |
14 | \r | |
15 | Boot service DXE BIOS ID library implementation.\r | |
16 | \r | |
17 | These functions in this file can be called during DXE and cannot be called during runtime\r | |
18 | or in SMM which should use a RT or SMM library.\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | #include <PiDxe.h>\r | |
23 | #include <Library/BaseLib.h>\r | |
24 | #include <Library/HobLib.h>\r | |
25 | #include <Library/UefiBootServicesTableLib.h>\r | |
26 | #include <Library/BaseMemoryLib.h>\r | |
27 | #include <Library/DebugLib.h>\r | |
28 | \r | |
29 | #include <Library/BiosIdLib.h>\r | |
30 | #include <Guid/BiosId.h>\r | |
31 | #include <Protocol/FirmwareVolume2.h>\r | |
32 | #include <Protocol/LoadedImage.h>\r | |
33 | \r | |
34 | \r | |
35 | EFI_STATUS\r | |
36 | GetImageFromFv (\r | |
37 | IN EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv,\r | |
38 | IN EFI_GUID *NameGuid,\r | |
39 | IN EFI_SECTION_TYPE SectionType,\r | |
40 | OUT VOID **Buffer,\r | |
41 | OUT UINTN *Size\r | |
42 | )\r | |
43 | {\r | |
44 | EFI_STATUS Status;\r | |
45 | EFI_FV_FILETYPE FileType;\r | |
46 | EFI_FV_FILE_ATTRIBUTES Attributes;\r | |
47 | UINT32 AuthenticationStatus;\r | |
48 | \r | |
49 | //\r | |
50 | // Read desired section content in NameGuid file\r | |
51 | //\r | |
52 | *Buffer = NULL;\r | |
53 | *Size = 0;\r | |
54 | Status = Fv->ReadSection (\r | |
55 | Fv,\r | |
56 | NameGuid,\r | |
57 | SectionType,\r | |
58 | 0,\r | |
59 | Buffer,\r | |
60 | Size,\r | |
61 | &AuthenticationStatus\r | |
62 | );\r | |
63 | \r | |
64 | if (EFI_ERROR (Status) && (SectionType == EFI_SECTION_TE)) {\r | |
65 | //\r | |
66 | // Try reading PE32 section, since the TE section does not exist\r | |
67 | //\r | |
68 | *Buffer = NULL;\r | |
69 | *Size = 0;\r | |
70 | Status = Fv->ReadSection (\r | |
71 | Fv,\r | |
72 | NameGuid,\r | |
73 | EFI_SECTION_PE32,\r | |
74 | 0,\r | |
75 | Buffer,\r | |
76 | Size,\r | |
77 | &AuthenticationStatus\r | |
78 | );\r | |
79 | }\r | |
80 | \r | |
81 | if (EFI_ERROR (Status) &&\r | |
82 | ((SectionType == EFI_SECTION_TE) || (SectionType == EFI_SECTION_PE32))) {\r | |
83 | //\r | |
84 | // Try reading raw file, since the desired section does not exist\r | |
85 | //\r | |
86 | *Buffer = NULL;\r | |
87 | *Size = 0;\r | |
88 | Status = Fv->ReadFile (\r | |
89 | Fv,\r | |
90 | NameGuid,\r | |
91 | Buffer,\r | |
92 | Size,\r | |
93 | &FileType,\r | |
94 | &Attributes,\r | |
95 | &AuthenticationStatus\r | |
96 | );\r | |
97 | }\r | |
98 | \r | |
99 | return Status;\r | |
100 | }\r | |
101 | \r | |
102 | \r | |
103 | EFI_STATUS\r | |
104 | GetImageEx (\r | |
105 | IN EFI_HANDLE ImageHandle,\r | |
106 | IN EFI_GUID *NameGuid,\r | |
107 | IN EFI_SECTION_TYPE SectionType,\r | |
108 | OUT VOID **Buffer,\r | |
109 | OUT UINTN *Size,\r | |
110 | BOOLEAN WithinImageFv\r | |
111 | )\r | |
112 | {\r | |
113 | EFI_STATUS Status;\r | |
114 | EFI_HANDLE *HandleBuffer;\r | |
115 | UINTN HandleCount;\r | |
116 | UINTN Index;\r | |
117 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
118 | \r | |
119 | EFI_FIRMWARE_VOLUME2_PROTOCOL *ImageFv;\r | |
120 | EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r | |
121 | \r | |
122 | \r | |
123 | if (ImageHandle == NULL && WithinImageFv) {\r | |
124 | return EFI_INVALID_PARAMETER;\r | |
125 | }\r | |
126 | \r | |
127 | Status = EFI_NOT_FOUND;\r | |
128 | ImageFv = NULL;\r | |
129 | if (ImageHandle != NULL) {\r | |
130 | Status = gBS->HandleProtocol (\r | |
131 | ImageHandle,\r | |
132 | &gEfiLoadedImageProtocolGuid,\r | |
133 | (VOID **) &LoadedImage\r | |
134 | );\r | |
135 | if (EFI_ERROR (Status)) {\r | |
136 | return Status;\r | |
137 | }\r | |
138 | Status = gBS->HandleProtocol (\r | |
139 | LoadedImage->DeviceHandle,\r | |
140 | &gEfiFirmwareVolume2ProtocolGuid,\r | |
141 | (VOID **) &ImageFv\r | |
142 | );\r | |
143 | if (!EFI_ERROR (Status)) {\r | |
144 | Status = GetImageFromFv (ImageFv, NameGuid, SectionType, Buffer, Size);\r | |
145 | }\r | |
146 | }\r | |
147 | \r | |
148 | if (Status == EFI_SUCCESS || WithinImageFv) {\r | |
149 | return Status;\r | |
150 | }\r | |
151 | \r | |
152 | Status = gBS->LocateHandleBuffer (\r | |
153 | ByProtocol,\r | |
154 | &gEfiFirmwareVolume2ProtocolGuid,\r | |
155 | NULL,\r | |
156 | &HandleCount,\r | |
157 | &HandleBuffer\r | |
158 | );\r | |
159 | if (EFI_ERROR (Status)) {\r | |
160 | return Status;\r | |
161 | }\r | |
162 | \r | |
163 | //\r | |
164 | // Find desired image in all Fvs\r | |
165 | //\r | |
166 | for (Index = 0; Index < HandleCount; ++Index) {\r | |
167 | Status = gBS->HandleProtocol (\r | |
168 | HandleBuffer[Index],\r | |
169 | &gEfiFirmwareVolume2ProtocolGuid,\r | |
170 | (VOID**)&Fv\r | |
171 | );\r | |
172 | \r | |
173 | if (EFI_ERROR (Status)) {\r | |
174 | gBS->FreePool(HandleBuffer);\r | |
175 | return Status;\r | |
176 | }\r | |
177 | \r | |
178 | if (ImageFv != NULL && Fv == ImageFv) {\r | |
179 | continue;\r | |
180 | }\r | |
181 | \r | |
182 | Status = GetImageFromFv (Fv, NameGuid, SectionType, Buffer, Size);\r | |
183 | \r | |
184 | if (!EFI_ERROR (Status)) {\r | |
185 | break;\r | |
186 | }\r | |
187 | }\r | |
188 | gBS->FreePool(HandleBuffer);\r | |
189 | \r | |
190 | //\r | |
191 | // Not found image\r | |
192 | //\r | |
193 | if (Index == HandleCount) {\r | |
194 | return EFI_NOT_FOUND;\r | |
195 | }\r | |
196 | \r | |
197 | return EFI_SUCCESS;\r | |
198 | }\r | |
199 | \r | |
200 | /**\r | |
201 | This function returns BIOS ID by searching HOB or FV.\r | |
202 | \r | |
203 | @param BiosIdImage The BIOS ID got from HOB or FV.\r | |
204 | \r | |
205 | @retval EFI_SUCCESS All parameters were valid and BIOS ID has been got.\r | |
206 | @retval EFI_NOT_FOUND BiosId image is not found, and no parameter will be modified.\r | |
207 | @retval EFI_INVALID_PARAMETER The parameter is NULL.\r | |
208 | \r | |
209 | **/\r | |
210 | EFI_STATUS\r | |
211 | GetBiosId (\r | |
212 | OUT BIOS_ID_IMAGE *BiosIdImage\r | |
213 | )\r | |
214 | \r | |
215 | {\r | |
216 | EFI_STATUS Status;\r | |
217 | VOID *Address = NULL;\r | |
218 | UINTN Size = 0;\r | |
219 | \r | |
220 | DEBUG ((EFI_D_INFO, "Get BIOS ID from FV\n"));\r | |
221 | \r | |
222 | Status = GetImageEx (\r | |
223 | NULL,\r | |
224 | &gEfiBiosIdGuid,\r | |
225 | EFI_SECTION_RAW,\r | |
226 | &Address,\r | |
227 | &Size,\r | |
228 | FALSE\r | |
229 | );\r | |
230 | \r | |
231 | if (Status == EFI_SUCCESS) {\r | |
232 | //\r | |
233 | // BiosId image is present in FV\r | |
234 | //\r | |
235 | if (Address != NULL) {\r | |
236 | Size = sizeof (BIOS_ID_IMAGE);\r | |
237 | gBS->CopyMem (\r | |
238 | (void *) BiosIdImage,\r | |
239 | Address,\r | |
240 | Size\r | |
241 | );\r | |
242 | //\r | |
243 | // GetImage () allocated buffer for Address, now clear it.\r | |
244 | //\r | |
245 | gBS->FreePool (Address);\r | |
246 | \r | |
247 | DEBUG ((EFI_D_INFO, "Get BIOS ID from FV successfully\n"));\r | |
248 | DEBUG ((EFI_D_INFO, "BIOS ID: %s\n", (CHAR16 *) (&(BiosIdImage->BiosIdString))));\r | |
249 | \r | |
250 | return EFI_SUCCESS;\r | |
251 | }\r | |
252 | }\r | |
253 | return EFI_NOT_FOUND;\r | |
254 | }\r | |
255 | \r | |
256 | /**\r | |
257 | This function returns the Version & Release Date and Time by getting and converting\r | |
258 | BIOS ID.\r | |
259 | \r | |
260 | @param BiosVersion The Bios Version out of the conversion.\r | |
261 | @param BiosReleaseDate The Bios Release Date out of the conversion.\r | |
262 | @param BiosReleaseTime - The Bios Release Time out of the conversion.\r | |
263 | \r | |
264 | @retval EFI_SUCCESS - BIOS Version & Release Date and Time have been got successfully.\r | |
265 | @retval EFI_NOT_FOUND - BiosId image is not found, and no parameter will be modified.\r | |
266 | @retval EFI_INVALID_PARAMETER - All the parameters are NULL.\r | |
267 | \r | |
268 | **/\r | |
269 | EFI_STATUS\r | |
270 | GetBiosVersionDateTime (\r | |
271 | OUT CHAR16 *BiosVersion, OPTIONAL\r | |
272 | OUT CHAR16 *BiosReleaseDate, OPTIONAL\r | |
273 | OUT CHAR16 *BiosReleaseTime OPTIONAL\r | |
274 | )\r | |
275 | {\r | |
276 | EFI_STATUS Status;\r | |
277 | BIOS_ID_IMAGE BiosIdImage;\r | |
278 | \r | |
279 | if ((BiosVersion == NULL) && (BiosReleaseDate == NULL) && (BiosReleaseTime == NULL)) {\r | |
280 | return EFI_INVALID_PARAMETER;\r | |
281 | }\r | |
282 | \r | |
283 | Status = GetBiosId (&BiosIdImage);\r | |
284 | if (EFI_ERROR (Status)) {\r | |
285 | return EFI_NOT_FOUND;\r | |
286 | }\r | |
287 | \r | |
288 | if (BiosVersion != NULL) {\r | |
289 | //\r | |
290 | // Fill the BiosVersion data from the BIOS ID.\r | |
291 | //\r | |
292 | StrCpy (BiosVersion, (CHAR16 *) (&(BiosIdImage.BiosIdString)));\r | |
293 | }\r | |
294 | \r | |
295 | if (BiosReleaseDate != NULL) {\r | |
296 | //\r | |
297 | // Fill the build timestamp date from the BIOS ID in the "MM/DD/YY" format.\r | |
298 | //\r | |
299 | BiosReleaseDate[0] = BiosIdImage.BiosIdString.TimeStamp[2];\r | |
300 | BiosReleaseDate[1] = BiosIdImage.BiosIdString.TimeStamp[3];\r | |
301 | BiosReleaseDate[2] = (CHAR16) ((UINT8) ('/'));\r | |
302 | \r | |
303 | BiosReleaseDate[3] = BiosIdImage.BiosIdString.TimeStamp[4];\r | |
304 | BiosReleaseDate[4] = BiosIdImage.BiosIdString.TimeStamp[5];\r | |
305 | BiosReleaseDate[5] = (CHAR16) ((UINT8) ('/'));\r | |
306 | \r | |
307 | //\r | |
308 | // Add 20 for SMBIOS table\r | |
309 | // Current Linux kernel will misjudge 09 as year 0, so using 2009 for SMBIOS table\r | |
310 | //\r | |
311 | BiosReleaseDate[6] = '2';\r | |
312 | BiosReleaseDate[7] = '0';\r | |
313 | BiosReleaseDate[8] = BiosIdImage.BiosIdString.TimeStamp[0];\r | |
314 | BiosReleaseDate[9] = BiosIdImage.BiosIdString.TimeStamp[1];\r | |
315 | \r | |
316 | BiosReleaseDate[10] = (CHAR16) ((UINT8) ('\0'));\r | |
317 | }\r | |
318 | \r | |
319 | if (BiosReleaseTime != NULL) {\r | |
320 | \r | |
321 | //\r | |
322 | // Fill the build timestamp time from the BIOS ID in the "HH:MM" format.\r | |
323 | //\r | |
324 | \r | |
325 | BiosReleaseTime[0] = BiosIdImage.BiosIdString.TimeStamp[6];\r | |
326 | BiosReleaseTime[1] = BiosIdImage.BiosIdString.TimeStamp[7];\r | |
327 | BiosReleaseTime[2] = (CHAR16) ((UINT8) (':'));\r | |
328 | \r | |
329 | BiosReleaseTime[3] = BiosIdImage.BiosIdString.TimeStamp[8];\r | |
330 | BiosReleaseTime[4] = BiosIdImage.BiosIdString.TimeStamp[9];\r | |
331 | \r | |
332 | BiosReleaseTime[5] = (CHAR16) ((UINT8) ('\0'));\r | |
333 | }\r | |
334 | \r | |
335 | return EFI_SUCCESS;\r | |
336 | }\r | |
337 | \r |