]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
Update comments for NULL PlatformSecureLib instance.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / BdsBoot.c
CommitLineData
5c08e117 1/** @file\r
2 BDS Lib functions which relate with create or process the boot option.\r
3\r
2df686c6 4Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
180a5a35 5This program and the accompanying materials\r
5c08e117 6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "InternalBdsLib.h"\r
9aa7ba01 16#include "String.h"\r
5c08e117 17\r
18BOOLEAN mEnumBootDevice = FALSE;\r
9aa7ba01 19EFI_HII_HANDLE gBdsLibStringPackHandle = NULL;\r
5c08e117 20\r
9aa7ba01 21/**\r
22 The constructor function register UNI strings into imageHandle.\r
23 \r
24 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
25\r
26 @param ImageHandle The firmware allocated handle for the EFI image.\r
27 @param SystemTable A pointer to the EFI System Table.\r
28 \r
29 @retval EFI_SUCCESS The constructor successfully added string package.\r
30 @retval Other value The constructor can't add string package.\r
31\r
32**/\r
33EFI_STATUS\r
34EFIAPI\r
35GenericBdsLibConstructor (\r
36 IN EFI_HANDLE ImageHandle,\r
37 IN EFI_SYSTEM_TABLE *SystemTable\r
38 )\r
39{\r
40\r
41 gBdsLibStringPackHandle = HiiAddPackages (\r
e24fc103 42 &gBdsLibStringPackageGuid,\r
9aa7ba01 43 &ImageHandle,\r
44 GenericBdsLibStrings,\r
45 NULL\r
46 );\r
47\r
48 ASSERT (gBdsLibStringPackHandle != NULL);\r
49\r
50 return EFI_SUCCESS;\r
51}\r
52\r
5c08e117 53\r
54\r
55/**\r
56 Boot the legacy system with the boot option\r
57\r
58 @param Option The legacy boot option which have BBS device path\r
59\r
60 @retval EFI_UNSUPPORTED There is no legacybios protocol, do not support\r
61 legacy boot.\r
62 @retval EFI_STATUS Return the status of LegacyBios->LegacyBoot ().\r
63\r
64**/\r
65EFI_STATUS\r
66BdsLibDoLegacyBoot (\r
67 IN BDS_COMMON_OPTION *Option\r
68 )\r
69{\r
70 EFI_STATUS Status;\r
71 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;\r
72\r
73 Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);\r
74 if (EFI_ERROR (Status)) {\r
75 //\r
76 // If no LegacyBios protocol we do not support legacy boot\r
77 //\r
78 return EFI_UNSUPPORTED;\r
79 }\r
80 //\r
81 // Notes: if we separate the int 19, then we don't need to refresh BBS\r
82 //\r
83 BdsRefreshBbsTableForBoot (Option);\r
84\r
85 //\r
cd6a3b15 86 // Write boot to OS performance data for legacy boot.\r
5c08e117 87 //\r
88 PERF_CODE (\r
89 WriteBootToOsPerformanceData ();\r
90 );\r
91\r
92 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Legacy Boot: %S\n", Option->Description));\r
93 return LegacyBios->LegacyBoot (\r
94 LegacyBios,\r
95 (BBS_BBS_DEVICE_PATH *) Option->DevicePath,\r
96 Option->LoadOptionsSize,\r
97 Option->LoadOptions\r
98 );\r
99}\r
100\r
3d7decbc 101/**\r
102 Internal function to check if the input boot option is a valid EFI NV Boot####.\r
103\r
104 @param OptionToCheck Boot option to be checked.\r
105\r
106 @retval TRUE This boot option matches a valid EFI NV Boot####.\r
107 @retval FALSE If not.\r
128efbbc 108\r
3d7decbc 109**/\r
3d7decbc 110BOOLEAN\r
111IsBootOptionValidNVVarialbe (\r
112 IN BDS_COMMON_OPTION *OptionToCheck\r
113 )\r
114{\r
115 LIST_ENTRY TempList;\r
116 BDS_COMMON_OPTION *BootOption;\r
117 BOOLEAN Valid;\r
118 CHAR16 OptionName[20];\r
119\r
120 Valid = FALSE;\r
121\r
122 InitializeListHead (&TempList);\r
123 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionToCheck->BootCurrent);\r
5c08e117 124\r
3d7decbc 125 BootOption = BdsLibVariableToOption (&TempList, OptionName);\r
126 if (BootOption == NULL) {\r
127 return FALSE;\r
128 }\r
129\r
130 //\r
128efbbc 131 // If the Boot Option Number and Device Path matches, OptionToCheck matches a\r
3d7decbc 132 // valid EFI NV Boot####.\r
133 //\r
134 if ((OptionToCheck->BootCurrent == BootOption->BootCurrent) &&\r
135 (CompareMem (OptionToCheck->DevicePath, BootOption->DevicePath, GetDevicePathSize (OptionToCheck->DevicePath)) == 0))\r
136 {\r
137 Valid = TRUE;\r
138 }\r
139\r
140 FreePool (BootOption);\r
128efbbc 141\r
3d7decbc 142 return Valid;\r
143}\r
7389fdd0 144\r
145/**\r
146 Check whether a USB device match the specified USB Class device path. This\r
147 function follows "Load Option Processing" behavior in UEFI specification.\r
148\r
149 @param UsbIo USB I/O protocol associated with the USB device.\r
150 @param UsbClass The USB Class device path to match.\r
151\r
152 @retval TRUE The USB device match the USB Class device path.\r
153 @retval FALSE The USB device does not match the USB Class device path.\r
154\r
155**/\r
156BOOLEAN\r
157BdsMatchUsbClass (\r
158 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
159 IN USB_CLASS_DEVICE_PATH *UsbClass\r
160 )\r
161{\r
162 EFI_STATUS Status;\r
163 EFI_USB_DEVICE_DESCRIPTOR DevDesc;\r
164 EFI_USB_INTERFACE_DESCRIPTOR IfDesc;\r
165 UINT8 DeviceClass;\r
166 UINT8 DeviceSubClass;\r
167 UINT8 DeviceProtocol;\r
168\r
169 if ((DevicePathType (UsbClass) != MESSAGING_DEVICE_PATH) ||\r
170 (DevicePathSubType (UsbClass) != MSG_USB_CLASS_DP)){\r
171 return FALSE;\r
172 }\r
173\r
174 //\r
175 // Check Vendor Id and Product Id.\r
176 //\r
177 Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);\r
178 if (EFI_ERROR (Status)) {\r
179 return FALSE;\r
180 }\r
181\r
182 if ((UsbClass->VendorId != 0xffff) &&\r
183 (UsbClass->VendorId != DevDesc.IdVendor)) {\r
184 return FALSE;\r
185 }\r
186\r
187 if ((UsbClass->ProductId != 0xffff) &&\r
188 (UsbClass->ProductId != DevDesc.IdProduct)) {\r
189 return FALSE;\r
190 }\r
191\r
192 DeviceClass = DevDesc.DeviceClass;\r
193 DeviceSubClass = DevDesc.DeviceSubClass;\r
194 DeviceProtocol = DevDesc.DeviceProtocol;\r
195 if (DeviceClass == 0) {\r
196 //\r
197 // If Class in Device Descriptor is set to 0, use the Class, SubClass and\r
198 // Protocol in Interface Descriptor instead.\r
199 //\r
200 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);\r
201 if (EFI_ERROR (Status)) {\r
202 return FALSE;\r
203 }\r
204\r
205 DeviceClass = IfDesc.InterfaceClass;\r
206 DeviceSubClass = IfDesc.InterfaceSubClass;\r
207 DeviceProtocol = IfDesc.InterfaceProtocol;\r
208 }\r
209\r
210 //\r
211 // Check Class, SubClass and Protocol.\r
212 //\r
213 if ((UsbClass->DeviceClass != 0xff) &&\r
214 (UsbClass->DeviceClass != DeviceClass)) {\r
215 return FALSE;\r
216 }\r
217\r
218 if ((UsbClass->DeviceSubClass != 0xff) &&\r
219 (UsbClass->DeviceSubClass != DeviceSubClass)) {\r
220 return FALSE;\r
221 }\r
222\r
223 if ((UsbClass->DeviceProtocol != 0xff) &&\r
224 (UsbClass->DeviceProtocol != DeviceProtocol)) {\r
225 return FALSE;\r
226 }\r
227\r
228 return TRUE;\r
229}\r
230\r
231/**\r
232 Check whether a USB device match the specified USB WWID device path. This\r
233 function follows "Load Option Processing" behavior in UEFI specification.\r
234\r
235 @param UsbIo USB I/O protocol associated with the USB device.\r
236 @param UsbWwid The USB WWID device path to match.\r
237\r
238 @retval TRUE The USB device match the USB WWID device path.\r
239 @retval FALSE The USB device does not match the USB WWID device path.\r
240\r
241**/\r
242BOOLEAN\r
243BdsMatchUsbWwid (\r
244 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
245 IN USB_WWID_DEVICE_PATH *UsbWwid\r
246 )\r
247{\r
248 EFI_STATUS Status;\r
249 EFI_USB_DEVICE_DESCRIPTOR DevDesc;\r
250 EFI_USB_INTERFACE_DESCRIPTOR IfDesc;\r
251 UINT16 *LangIdTable;\r
252 UINT16 TableSize;\r
253 UINT16 Index;\r
254 CHAR16 *CompareStr;\r
255 UINTN CompareLen;\r
256 CHAR16 *SerialNumberStr;\r
257 UINTN Length;\r
258\r
259 if ((DevicePathType (UsbWwid) != MESSAGING_DEVICE_PATH) ||\r
260 (DevicePathSubType (UsbWwid) != MSG_USB_WWID_DP )){\r
261 return FALSE;\r
262 }\r
263\r
264 //\r
265 // Check Vendor Id and Product Id.\r
266 //\r
267 Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);\r
268 if (EFI_ERROR (Status)) {\r
269 return FALSE;\r
270 }\r
271 if ((DevDesc.IdVendor != UsbWwid->VendorId) ||\r
272 (DevDesc.IdProduct != UsbWwid->ProductId)) {\r
273 return FALSE;\r
274 }\r
275\r
276 //\r
277 // Check Interface Number.\r
278 //\r
279 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);\r
280 if (EFI_ERROR (Status)) {\r
281 return FALSE;\r
282 }\r
283 if (IfDesc.InterfaceNumber != UsbWwid->InterfaceNumber) {\r
284 return FALSE;\r
285 }\r
286\r
287 //\r
288 // Check Serial Number.\r
289 //\r
290 if (DevDesc.StrSerialNumber == 0) {\r
291 return FALSE;\r
292 }\r
293\r
294 //\r
295 // Get all supported languages.\r
296 //\r
297 TableSize = 0;\r
298 LangIdTable = NULL;\r
299 Status = UsbIo->UsbGetSupportedLanguages (UsbIo, &LangIdTable, &TableSize);\r
300 if (EFI_ERROR (Status) || (TableSize == 0) || (LangIdTable == NULL)) {\r
301 return FALSE;\r
302 }\r
303\r
304 //\r
305 // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.\r
306 //\r
307 CompareStr = (CHAR16 *) (UINTN) (UsbWwid + 1);\r
308 CompareLen = (DevicePathNodeLength (UsbWwid) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16);\r
309 if (CompareStr[CompareLen - 1] == L'\0') {\r
310 CompareLen--;\r
311 }\r
312\r
313 //\r
314 // Compare serial number in each supported language.\r
315 //\r
316 for (Index = 0; Index < TableSize / sizeof (UINT16); Index++) {\r
317 SerialNumberStr = NULL;\r
318 Status = UsbIo->UsbGetStringDescriptor (\r
319 UsbIo,\r
320 LangIdTable[Index],\r
321 DevDesc.StrSerialNumber,\r
322 &SerialNumberStr\r
323 );\r
324 if (EFI_ERROR (Status) || (SerialNumberStr == NULL)) {\r
325 continue;\r
326 }\r
327\r
328 Length = StrLen (SerialNumberStr);\r
329 if ((Length >= CompareLen) &&\r
330 (CompareMem (SerialNumberStr + Length - CompareLen, CompareStr, CompareLen * sizeof (CHAR16)) == 0)) {\r
331 FreePool (SerialNumberStr);\r
332 return TRUE;\r
333 }\r
334\r
335 FreePool (SerialNumberStr);\r
336 }\r
337\r
338 return FALSE;\r
339}\r
340\r
341/**\r
9972247d 342 Find a USB device path which match the specified short-form device path start\r
343 with USB Class or USB WWID device path and load the boot file then return the \r
344 image handle. If ParentDevicePath is NULL, this function will search in all USB\r
345 devices of the platform. If ParentDevicePath is not NULL,this function will only\r
346 search in its child devices.\r
7389fdd0 347\r
348 @param ParentDevicePath The device path of the parent.\r
349 @param ShortFormDevicePath The USB Class or USB WWID device path to match.\r
350\r
9972247d 351 @return The image Handle if find load file from specified short-form device path\r
352 or NULL if not found.\r
7389fdd0 353\r
354**/\r
355EFI_HANDLE *\r
356BdsFindUsbDevice (\r
357 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,\r
358 IN EFI_DEVICE_PATH_PROTOCOL *ShortFormDevicePath\r
359 )\r
360{\r
361 EFI_STATUS Status;\r
362 UINTN UsbIoHandleCount;\r
363 EFI_HANDLE *UsbIoHandleBuffer;\r
364 EFI_DEVICE_PATH_PROTOCOL *UsbIoDevicePath;\r
365 EFI_USB_IO_PROTOCOL *UsbIo;\r
366 UINTN Index;\r
367 UINTN ParentSize;\r
368 UINTN Size;\r
9972247d 369 EFI_HANDLE ImageHandle;\r
370 EFI_HANDLE Handle;\r
371 EFI_DEVICE_PATH_PROTOCOL *FullDevicePath;\r
372 EFI_DEVICE_PATH_PROTOCOL *NextDevicePath;\r
373\r
374 FullDevicePath = NULL;\r
375 ImageHandle = NULL;\r
7389fdd0 376\r
377 //\r
378 // Get all UsbIo Handles.\r
379 //\r
380 UsbIoHandleCount = 0;\r
381 UsbIoHandleBuffer = NULL;\r
382 Status = gBS->LocateHandleBuffer (\r
383 ByProtocol,\r
384 &gEfiUsbIoProtocolGuid,\r
385 NULL,\r
386 &UsbIoHandleCount,\r
387 &UsbIoHandleBuffer\r
388 );\r
389 if (EFI_ERROR (Status) || (UsbIoHandleCount == 0) || (UsbIoHandleBuffer == NULL)) {\r
390 return NULL;\r
391 }\r
392\r
7389fdd0 393 ParentSize = (ParentDevicePath == NULL) ? 0 : GetDevicePathSize (ParentDevicePath);\r
394 for (Index = 0; Index < UsbIoHandleCount; Index++) {\r
395 //\r
396 // Get the Usb IO interface.\r
397 //\r
398 Status = gBS->HandleProtocol(\r
399 UsbIoHandleBuffer[Index],\r
400 &gEfiUsbIoProtocolGuid,\r
401 (VOID **) &UsbIo\r
402 );\r
403 if (EFI_ERROR (Status)) {\r
404 continue;\r
405 }\r
406\r
9972247d 407 UsbIoDevicePath = DevicePathFromHandle (UsbIoHandleBuffer[Index]);\r
408 if (UsbIoDevicePath == NULL) {\r
409 continue;\r
410 }\r
411\r
7389fdd0 412 if (ParentDevicePath != NULL) {\r
413 //\r
414 // Compare starting part of UsbIoHandle's device path with ParentDevicePath.\r
415 //\r
7389fdd0 416 Size = GetDevicePathSize (UsbIoDevicePath);\r
417 if ((Size < ParentSize) ||\r
418 (CompareMem (UsbIoDevicePath, ParentDevicePath, ParentSize - END_DEVICE_PATH_LENGTH) != 0)) {\r
419 continue;\r
420 }\r
421 }\r
422\r
423 if (BdsMatchUsbClass (UsbIo, (USB_CLASS_DEVICE_PATH *) ShortFormDevicePath) ||\r
424 BdsMatchUsbWwid (UsbIo, (USB_WWID_DEVICE_PATH *) ShortFormDevicePath)) {\r
9972247d 425 //\r
426 // Try to find if there is the boot file in this DevicePath\r
427 //\r
428 NextDevicePath = NextDevicePathNode (ShortFormDevicePath);\r
429 if (!IsDevicePathEnd (NextDevicePath)) {\r
430 FullDevicePath = AppendDevicePath (UsbIoDevicePath, NextDevicePath);\r
431 //\r
432 // Connect the full device path, so that Simple File System protocol\r
433 // could be installed for this USB device.\r
434 //\r
435 BdsLibConnectDevicePath (FullDevicePath);\r
79b7a6a1 436 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));\r
9972247d 437 Status = gBS->LoadImage (\r
438 TRUE,\r
439 gImageHandle,\r
440 FullDevicePath,\r
441 NULL,\r
442 0,\r
443 &ImageHandle\r
444 );\r
445 FreePool (FullDevicePath);\r
446 } else {\r
447 FullDevicePath = UsbIoDevicePath;\r
448 Status = EFI_NOT_FOUND;\r
449 }\r
450\r
451 //\r
452 // If we didn't find an image directly, we need to try as if it is a removable device boot option\r
453 // and load the image according to the default boot behavior for removable device.\r
454 //\r
455 if (EFI_ERROR (Status)) {\r
456 //\r
457 // check if there is a bootable removable media could be found in this device path ,\r
458 // and get the bootable media handle\r
459 //\r
460 Handle = BdsLibGetBootableHandle(UsbIoDevicePath);\r
461 if (Handle == NULL) {\r
462 continue;\r
463 }\r
464 //\r
465 // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media\r
466 // machinename is ia32, ia64, x64, ...\r
467 //\r
468 FullDevicePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);\r
469 if (FullDevicePath != NULL) {\r
79b7a6a1 470 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));\r
9972247d 471 Status = gBS->LoadImage (\r
472 TRUE,\r
473 gImageHandle,\r
474 FullDevicePath,\r
475 NULL,\r
476 0,\r
477 &ImageHandle\r
478 );\r
479 if (EFI_ERROR (Status)) {\r
480 //\r
481 // The DevicePath failed, and it's not a valid\r
482 // removable media device.\r
483 //\r
484 continue;\r
485 }\r
486 } else {\r
487 continue;\r
488 }\r
489 }\r
7389fdd0 490 break;\r
491 }\r
492 }\r
493\r
494 FreePool (UsbIoHandleBuffer);\r
9972247d 495 return ImageHandle;\r
7389fdd0 496}\r
497\r
498/**\r
499 Expand USB Class or USB WWID device path node to be full device path of a USB\r
9972247d 500 device in platform then load the boot file on this full device path and return the \r
501 image handle.\r
7389fdd0 502\r
503 This function support following 4 cases:\r
504 1) Boot Option device path starts with a USB Class or USB WWID device path,\r
505 and there is no Media FilePath device path in the end.\r
506 In this case, it will follow Removable Media Boot Behavior.\r
507 2) Boot Option device path starts with a USB Class or USB WWID device path,\r
508 and ended with Media FilePath device path.\r
509 3) Boot Option device path starts with a full device path to a USB Host Controller,\r
510 contains a USB Class or USB WWID device path node, while not ended with Media\r
511 FilePath device path. In this case, it will follow Removable Media Boot Behavior.\r
512 4) Boot Option device path starts with a full device path to a USB Host Controller,\r
513 contains a USB Class or USB WWID device path node, and ended with Media\r
514 FilePath device path.\r
515\r
516 @param DevicePath The Boot Option device path.\r
517\r
9972247d 518 @return The image handle of boot file, or NULL if there is no boot file found in\r
519 the specified USB Class or USB WWID device path.\r
7389fdd0 520\r
521**/\r
9972247d 522EFI_HANDLE *\r
7389fdd0 523BdsExpandUsbShortFormDevicePath (\r
524 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
525 )\r
526{\r
9972247d 527 EFI_HANDLE *ImageHandle;\r
7389fdd0 528 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
7389fdd0 529 EFI_DEVICE_PATH_PROTOCOL *ShortFormDevicePath;\r
530\r
531 //\r
532 // Search for USB Class or USB WWID device path node.\r
533 //\r
534 ShortFormDevicePath = NULL;\r
9972247d 535 ImageHandle = NULL;\r
536 TempDevicePath = DevicePath;\r
7389fdd0 537 while (!IsDevicePathEnd (TempDevicePath)) {\r
538 if ((DevicePathType (TempDevicePath) == MESSAGING_DEVICE_PATH) &&\r
539 ((DevicePathSubType (TempDevicePath) == MSG_USB_CLASS_DP) ||\r
540 (DevicePathSubType (TempDevicePath) == MSG_USB_WWID_DP))) {\r
541 ShortFormDevicePath = TempDevicePath;\r
542 break;\r
543 }\r
7389fdd0 544 TempDevicePath = NextDevicePathNode (TempDevicePath);\r
545 }\r
546\r
547 if (ShortFormDevicePath == NULL) {\r
548 //\r
549 // No USB Class or USB WWID device path node found, do nothing.\r
550 //\r
551 return NULL;\r
552 }\r
553\r
554 if (ShortFormDevicePath == DevicePath) {\r
555 //\r
556 // Boot Option device path starts with USB Class or USB WWID device path.\r
557 //\r
9972247d 558 ImageHandle = BdsFindUsbDevice (NULL, ShortFormDevicePath);\r
559 if (ImageHandle == NULL) {\r
7389fdd0 560 //\r
561 // Failed to find a match in existing devices, connect the short form USB\r
562 // device path and try again.\r
563 //\r
564 BdsLibConnectUsbDevByShortFormDP (0xff, ShortFormDevicePath);\r
9972247d 565 ImageHandle = BdsFindUsbDevice (NULL, ShortFormDevicePath);\r
7389fdd0 566 }\r
567 } else {\r
568 //\r
569 // Boot Option device path contains USB Class or USB WWID device path node.\r
570 //\r
571\r
572 //\r
573 // Prepare the parent device path for search.\r
574 //\r
575 TempDevicePath = DuplicateDevicePath (DevicePath);\r
576 ASSERT (TempDevicePath != NULL);\r
577 SetDevicePathEndNode (((UINT8 *) TempDevicePath) + ((UINTN) ShortFormDevicePath - (UINTN) DevicePath));\r
578\r
579 //\r
9972247d 580 // The USB Host Controller device path is already in Boot Option device path\r
7389fdd0 581 // and USB Bus driver already support RemainingDevicePath starts with USB\r
582 // Class or USB WWID device path, so just search in existing USB devices and\r
583 // doesn't perform ConnectController here.\r
584 //\r
9972247d 585 ImageHandle = BdsFindUsbDevice (TempDevicePath, ShortFormDevicePath);\r
7389fdd0 586 FreePool (TempDevicePath);\r
587 }\r
588\r
9972247d 589 return ImageHandle;\r
7389fdd0 590}\r
591\r
5c08e117 592/**\r
593 Process the boot option follow the UEFI specification and\r
594 special treat the legacy boot option with BBS_DEVICE_PATH.\r
595\r
596 @param Option The boot option need to be processed\r
597 @param DevicePath The device path which describe where to load the\r
598 boot image or the legacy BBS device path to boot\r
599 the legacy OS\r
600 @param ExitDataSize The size of exit data.\r
601 @param ExitData Data returned when Boot image failed.\r
602\r
603 @retval EFI_SUCCESS Boot from the input boot option successfully.\r
604 @retval EFI_NOT_FOUND If the Device Path is not found in the system\r
605\r
606**/\r
607EFI_STATUS\r
608EFIAPI\r
609BdsLibBootViaBootOption (\r
610 IN BDS_COMMON_OPTION *Option,\r
611 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
612 OUT UINTN *ExitDataSize,\r
613 OUT CHAR16 **ExitData OPTIONAL\r
614 )\r
615{\r
616 EFI_STATUS Status;\r
2df686c6 617 EFI_STATUS StatusLogo;\r
5c08e117 618 EFI_HANDLE Handle;\r
619 EFI_HANDLE ImageHandle;\r
620 EFI_DEVICE_PATH_PROTOCOL *FilePath;\r
621 EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;\r
622 EFI_DEVICE_PATH_PROTOCOL *WorkingDevicePath;\r
623 EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;\r
624 LIST_ENTRY TempBootLists;\r
2df686c6 625 EFI_BOOT_LOGO_PROTOCOL *BootLogo;\r
5c08e117 626\r
627 //\r
628 // Record the performance data for End of BDS\r
629 //\r
128efbbc 630 PERF_END(NULL, "BDS", NULL, 0);\r
5c08e117 631\r
632 *ExitDataSize = 0;\r
633 *ExitData = NULL;\r
634\r
5c08e117 635 //\r
636 // Notes: this code can be remove after the s3 script table\r
637 // hook on the event EVT_SIGNAL_READY_TO_BOOT or\r
638 // EVT_SIGNAL_LEGACY_BOOT\r
639 //\r
640 Status = gBS->LocateProtocol (&gEfiAcpiS3SaveProtocolGuid, NULL, (VOID **) &AcpiS3Save);\r
641 if (!EFI_ERROR (Status)) {\r
642 AcpiS3Save->S3Save (AcpiS3Save, NULL);\r
643 }\r
644 //\r
645 // If it's Device Path that starts with a hard drive path, append it with the front part to compose a\r
646 // full device path\r
647 //\r
648 WorkingDevicePath = NULL;\r
649 if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&\r
650 (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)) {\r
651 WorkingDevicePath = BdsExpandPartitionPartialDevicePathToFull (\r
652 (HARDDRIVE_DEVICE_PATH *)DevicePath\r
653 );\r
654 if (WorkingDevicePath != NULL) {\r
655 DevicePath = WorkingDevicePath;\r
656 }\r
657 }\r
7389fdd0 658\r
5c08e117 659 //\r
660 // Set Boot Current\r
661 //\r
3d7decbc 662 if (IsBootOptionValidNVVarialbe (Option)) {\r
663 //\r
664 // For a temporary boot (i.e. a boot by selected a EFI Shell using "Boot From File"), Boot Current is actually not valid.\r
665 // In this case, "BootCurrent" is not created.\r
666 // Only create the BootCurrent variable when it points to a valid Boot#### variable.\r
667 //\r
668 gRT->SetVariable (\r
669 L"BootCurrent",\r
670 &gEfiGlobalVariableGuid,\r
671 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
672 sizeof (UINT16),\r
673 &Option->BootCurrent\r
674 );\r
675 }\r
5c08e117 676\r
72861c22 677 //\r
678 // Signal the EVT_SIGNAL_READY_TO_BOOT event\r
679 //\r
680 EfiSignalEventReadyToBoot();\r
681\r
682 //\r
683 // Expand USB Class or USB WWID device path node to be full device path of a USB\r
684 // device in platform then load the boot file on this full device path and get the\r
685 // image handle.\r
686 //\r
687 ImageHandle = BdsExpandUsbShortFormDevicePath (DevicePath);\r
688\r
689 //\r
690 // Adjust the different type memory page number just before booting\r
691 // and save the updated info into the variable for next boot to use\r
692 //\r
693 BdsSetMemoryTypeInformationVariable ();\r
694\r
5c08e117 695 //\r
9972247d 696 // By expanding the USB Class or WWID device path, the ImageHandle has returnned.\r
697 // Here get the ImageHandle for the non USB class or WWID device path.\r
5c08e117 698 //\r
9972247d 699 if (ImageHandle == NULL) {\r
700 ASSERT (Option->DevicePath != NULL);\r
701 if ((DevicePathType (Option->DevicePath) == BBS_DEVICE_PATH) &&\r
702 (DevicePathSubType (Option->DevicePath) == BBS_BBS_DP)\r
703 ) {\r
704 //\r
705 // Check to see if we should legacy BOOT. If yes then do the legacy boot\r
706 //\r
707 return BdsLibDoLegacyBoot (Option);\r
5c08e117 708 }\r
128efbbc 709\r
5c08e117 710 //\r
9972247d 711 // If the boot option point to Internal FV shell, make sure it is valid\r
5c08e117 712 //\r
9972247d 713 Status = BdsLibUpdateFvFileDevicePath (&DevicePath, PcdGetPtr(PcdShellFile));\r
714 if (!EFI_ERROR(Status)) {\r
715 if (Option->DevicePath != NULL) {\r
716 FreePool(Option->DevicePath);\r
717 }\r
718 Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));\r
719 ASSERT(Option->DevicePath != NULL);\r
720 CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));\r
721 //\r
722 // Update the shell boot option\r
723 //\r
724 InitializeListHead (&TempBootLists);\r
725 BdsLibRegisterNewOption (&TempBootLists, DevicePath, L"EFI Internal Shell", L"BootOrder");\r
726\r
727 //\r
728 // free the temporary device path created by BdsLibUpdateFvFileDevicePath()\r
729 //\r
730 FreePool (DevicePath);\r
731 DevicePath = Option->DevicePath;\r
732 }\r
5c08e117 733\r
9972247d 734 DEBUG_CODE_BEGIN();\r
5c08e117 735\r
9aa7ba01 736 if (Option->Description == NULL) {\r
737 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting from unknown device path\n"));\r
738 } else {\r
739 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting %S\n", Option->Description));\r
ab8cc80b 740 }\r
9aa7ba01 741 \r
9972247d 742 DEBUG_CODE_END();\r
ab8cc80b 743 \r
79b7a6a1 744 //\r
745 // Report status code for OS Loader LoadImage.\r
746 //\r
747 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));\r
9972247d 748 Status = gBS->LoadImage (\r
749 TRUE,\r
750 gImageHandle,\r
751 DevicePath,\r
752 NULL,\r
753 0,\r
754 &ImageHandle\r
755 );\r
5c08e117 756\r
5c08e117 757 //\r
9972247d 758 // If we didn't find an image directly, we need to try as if it is a removable device boot option\r
759 // and load the image according to the default boot behavior for removable device.\r
5c08e117 760 //\r
9972247d 761 if (EFI_ERROR (Status)) {\r
762 //\r
763 // check if there is a bootable removable media could be found in this device path ,\r
764 // and get the bootable media handle\r
765 //\r
766 Handle = BdsLibGetBootableHandle(DevicePath);\r
767 if (Handle == NULL) {\r
5c08e117 768 goto Done;\r
769 }\r
9972247d 770 //\r
771 // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media\r
772 // machinename is ia32, ia64, x64, ...\r
773 //\r
774 FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);\r
775 if (FilePath != NULL) {\r
79b7a6a1 776 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));\r
9972247d 777 Status = gBS->LoadImage (\r
778 TRUE,\r
779 gImageHandle,\r
780 FilePath,\r
781 NULL,\r
782 0,\r
783 &ImageHandle\r
784 );\r
785 if (EFI_ERROR (Status)) {\r
786 //\r
787 // The DevicePath failed, and it's not a valid\r
788 // removable media device.\r
789 //\r
790 goto Done;\r
791 }\r
792 }\r
5c08e117 793 }\r
5c08e117 794\r
9972247d 795 if (EFI_ERROR (Status)) {\r
796 //\r
797 // It there is any error from the Boot attempt exit now.\r
798 //\r
799 goto Done;\r
800 }\r
5c08e117 801 }\r
802 //\r
803 // Provide the image with it's load options\r
804 //\r
9972247d 805 if (ImageHandle == NULL) {\r
806 goto Done;\r
807 }\r
5c08e117 808 Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);\r
809 ASSERT_EFI_ERROR (Status);\r
810\r
811 if (Option->LoadOptionsSize != 0) {\r
812 ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;\r
813 ImageInfo->LoadOptions = Option->LoadOptions;\r
814 }\r
815 //\r
816 // Before calling the image, enable the Watchdog Timer for\r
817 // the 5 Minute period\r
818 //\r
819 gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);\r
820\r
cd6a3b15 821 //\r
822 // Write boot to OS performance data for UEFI boot\r
823 //\r
824 PERF_CODE (\r
825 WriteBootToOsPerformanceData ();\r
826 );\r
827\r
79b7a6a1 828 //\r
829 // Report status code for OS Loader StartImage.\r
830 //\r
831 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderStart));\r
832\r
5c08e117 833 Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);\r
834 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status = %r\n", Status));\r
835\r
836 //\r
837 // Clear the Watchdog Timer after the image returns\r
838 //\r
839 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);\r
840\r
841Done:\r
2df686c6 842 //\r
843 // Set Logo status invalid after trying one boot option\r
844 //\r
845 BootLogo = NULL;\r
846 StatusLogo = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);\r
847 if (!EFI_ERROR (StatusLogo) && (BootLogo != NULL)) {\r
848 BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);\r
849 }\r
850\r
5c08e117 851 //\r
852 // Clear Boot Current\r
853 //\r
854 gRT->SetVariable (\r
855 L"BootCurrent",\r
856 &gEfiGlobalVariableGuid,\r
857 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
858 0,\r
859 &Option->BootCurrent\r
860 );\r
861\r
862 return Status;\r
863}\r
864\r
865\r
866/**\r
867 Expand a device path that starts with a hard drive media device path node to be a\r
868 full device path that includes the full hardware path to the device. We need\r
869 to do this so it can be booted. As an optimization the front match (the part point\r
870 to the partition node. E.g. ACPI() /PCI()/ATA()/Partition() ) is saved in a variable\r
871 so a connect all is not required on every boot. All successful history device path\r
872 which point to partition node (the front part) will be saved.\r
873\r
874 @param HardDriveDevicePath EFI Device Path to boot, if it starts with a hard\r
875 drive media device path.\r
876 @return A Pointer to the full device path or NULL if a valid Hard Drive devic path\r
877 cannot be found.\r
878\r
879**/\r
880EFI_DEVICE_PATH_PROTOCOL *\r
881EFIAPI\r
882BdsExpandPartitionPartialDevicePathToFull (\r
883 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath\r
884 )\r
885{\r
886 EFI_STATUS Status;\r
887 UINTN BlockIoHandleCount;\r
888 EFI_HANDLE *BlockIoBuffer;\r
889 EFI_DEVICE_PATH_PROTOCOL *FullDevicePath;\r
890 EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath;\r
891 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
892 UINTN Index;\r
893 UINTN InstanceNum;\r
894 EFI_DEVICE_PATH_PROTOCOL *CachedDevicePath;\r
895 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;\r
896 UINTN CachedDevicePathSize;\r
897 BOOLEAN DeviceExist;\r
898 BOOLEAN NeedAdjust;\r
899 EFI_DEVICE_PATH_PROTOCOL *Instance;\r
900 UINTN Size;\r
901\r
902 FullDevicePath = NULL;\r
903 //\r
e24fc103 904 // Check if there is prestore HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable.\r
5c08e117 905 // If exist, search the front path which point to partition node in the variable instants.\r
e24fc103 906 // If fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, reconnect all and search in all system\r
5c08e117 907 //\r
908 CachedDevicePath = BdsLibGetVariableAndSize (\r
e24fc103
LG
909 HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
910 &gHdBootDevicePathVariablGuid,\r
5c08e117 911 &CachedDevicePathSize\r
912 );\r
128efbbc 913\r
5c08e117 914 if (CachedDevicePath != NULL) {\r
915 TempNewDevicePath = CachedDevicePath;\r
916 DeviceExist = FALSE;\r
917 NeedAdjust = FALSE;\r
918 do {\r
919 //\r
920 // Check every instance of the variable\r
921 // First, check whether the instance contain the partition node, which is needed for distinguishing multi\r
922 // partial partition boot option. Second, check whether the instance could be connected.\r
923 //\r
924 Instance = GetNextDevicePathInstance (&TempNewDevicePath, &Size);\r
925 if (MatchPartitionDevicePathNode (Instance, HardDriveDevicePath)) {\r
926 //\r
927 // Connect the device path instance, the device path point to hard drive media device path node\r
928 // e.g. ACPI() /PCI()/ATA()/Partition()\r
929 //\r
930 Status = BdsLibConnectDevicePath (Instance);\r
931 if (!EFI_ERROR (Status)) {\r
932 DeviceExist = TRUE;\r
933 break;\r
934 }\r
935 }\r
936 //\r
937 // Come here means the first instance is not matched\r
938 //\r
939 NeedAdjust = TRUE;\r
940 FreePool(Instance);\r
941 } while (TempNewDevicePath != NULL);\r
942\r
943 if (DeviceExist) {\r
944 //\r
945 // Find the matched device path.\r
946 // Append the file path information from the boot option and return the fully expanded device path.\r
947 //\r
948 DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);\r
949 FullDevicePath = AppendDevicePath (Instance, DevicePath);\r
950\r
951 //\r
e24fc103 952 // Adjust the HD_BOOT_DEVICE_PATH_VARIABLE_NAME instances sequence if the matched one is not first one.\r
5c08e117 953 //\r
954 if (NeedAdjust) {\r
955 //\r
956 // First delete the matched instance.\r
957 //\r
958 TempNewDevicePath = CachedDevicePath;\r
959 CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, Instance );\r
960 FreePool (TempNewDevicePath);\r
128efbbc 961\r
5c08e117 962 //\r
963 // Second, append the remaining path after the matched instance\r
964 //\r
965 TempNewDevicePath = CachedDevicePath;\r
966 CachedDevicePath = AppendDevicePathInstance (Instance, CachedDevicePath );\r
967 FreePool (TempNewDevicePath);\r
968 //\r
969 // Save the matching Device Path so we don't need to do a connect all next time\r
970 //\r
971 Status = gRT->SetVariable (\r
e24fc103
LG
972 HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
973 &gHdBootDevicePathVariablGuid,\r
5c08e117 974 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
975 GetDevicePathSize (CachedDevicePath),\r
976 CachedDevicePath\r
977 );\r
978 }\r
128efbbc 979\r
5c08e117 980 FreePool (Instance);\r
981 FreePool (CachedDevicePath);\r
982 return FullDevicePath;\r
983 }\r
984 }\r
985\r
986 //\r
e24fc103 987 // If we get here we fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, and now we need\r
5c08e117 988 // to search all devices in the system for a matched partition\r
989 //\r
990 BdsLibConnectAllDriversToAllControllers ();\r
991 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &BlockIoHandleCount, &BlockIoBuffer);\r
992 if (EFI_ERROR (Status) || BlockIoHandleCount == 0 || BlockIoBuffer == NULL) {\r
993 //\r
994 // If there was an error or there are no device handles that support\r
995 // the BLOCK_IO Protocol, then return.\r
996 //\r
997 return NULL;\r
998 }\r
999 //\r
1000 // Loop through all the device handles that support the BLOCK_IO Protocol\r
1001 //\r
1002 for (Index = 0; Index < BlockIoHandleCount; Index++) {\r
1003\r
1004 Status = gBS->HandleProtocol (BlockIoBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID *) &BlockIoDevicePath);\r
1005 if (EFI_ERROR (Status) || BlockIoDevicePath == NULL) {\r
1006 continue;\r
1007 }\r
1008\r
1009 if (MatchPartitionDevicePathNode (BlockIoDevicePath, HardDriveDevicePath)) {\r
1010 //\r
1011 // Find the matched partition device path\r
1012 //\r
1013 DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);\r
1014 FullDevicePath = AppendDevicePath (BlockIoDevicePath, DevicePath);\r
1015\r
1016 //\r
e24fc103 1017 // Save the matched partition device path in HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable\r
5c08e117 1018 //\r
1019 if (CachedDevicePath != NULL) {\r
1020 //\r
e24fc103 1021 // Save the matched partition device path as first instance of HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable\r
5c08e117 1022 //\r
1023 if (BdsLibMatchDevicePaths (CachedDevicePath, BlockIoDevicePath)) {\r
1024 TempNewDevicePath = CachedDevicePath;\r
1025 CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, BlockIoDevicePath);\r
1026 FreePool(TempNewDevicePath);\r
1027\r
1028 TempNewDevicePath = CachedDevicePath;\r
1029 CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);\r
cd730ec0 1030 if (TempNewDevicePath != NULL) {\r
1031 FreePool(TempNewDevicePath);\r
1032 }\r
5c08e117 1033 } else {\r
1034 TempNewDevicePath = CachedDevicePath;\r
1035 CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);\r
1036 FreePool(TempNewDevicePath);\r
1037 }\r
1038 //\r
1039 // Here limit the device path instance number to 12, which is max number for a system support 3 IDE controller\r
e24fc103
LG
1040 // If the user try to boot many OS in different HDs or partitions, in theory, \r
1041 // the HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable maybe become larger and larger.\r
5c08e117 1042 //\r
1043 InstanceNum = 0;\r
1044 ASSERT (CachedDevicePath != NULL);\r
1045 TempNewDevicePath = CachedDevicePath;\r
1046 while (!IsDevicePathEnd (TempNewDevicePath)) {\r
1047 TempNewDevicePath = NextDevicePathNode (TempNewDevicePath);\r
1048 //\r
1049 // Parse one instance\r
1050 //\r
1051 while (!IsDevicePathEndType (TempNewDevicePath)) {\r
1052 TempNewDevicePath = NextDevicePathNode (TempNewDevicePath);\r
1053 }\r
1054 InstanceNum++;\r
1055 //\r
1056 // If the CachedDevicePath variable contain too much instance, only remain 12 instances.\r
1057 //\r
1058 if (InstanceNum >= 12) {\r
1059 SetDevicePathEndNode (TempNewDevicePath);\r
1060 break;\r
1061 }\r
1062 }\r
1063 } else {\r
1064 CachedDevicePath = DuplicateDevicePath (BlockIoDevicePath);\r
1065 }\r
1066\r
1067 //\r
1068 // Save the matching Device Path so we don't need to do a connect all next time\r
1069 //\r
1070 Status = gRT->SetVariable (\r
e24fc103
LG
1071 HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
1072 &gHdBootDevicePathVariablGuid,\r
5c08e117 1073 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1074 GetDevicePathSize (CachedDevicePath),\r
1075 CachedDevicePath\r
1076 );\r
1077\r
1078 break;\r
1079 }\r
1080 }\r
128efbbc 1081\r
cd730ec0 1082 if (CachedDevicePath != NULL) {\r
1083 FreePool (CachedDevicePath);\r
1084 }\r
5c08e117 1085 if (BlockIoBuffer != NULL) {\r
1086 FreePool (BlockIoBuffer);\r
1087 }\r
1088 return FullDevicePath;\r
1089}\r
1090\r
1091/**\r
1092 Check whether there is a instance in BlockIoDevicePath, which contain multi device path\r
1093 instances, has the same partition node with HardDriveDevicePath device path\r
1094\r
1095 @param BlockIoDevicePath Multi device path instances which need to check\r
1096 @param HardDriveDevicePath A device path which starts with a hard drive media\r
1097 device path.\r
1098\r
1099 @retval TRUE There is a matched device path instance.\r
1100 @retval FALSE There is no matched device path instance.\r
1101\r
1102**/\r
1103BOOLEAN\r
1104EFIAPI\r
1105MatchPartitionDevicePathNode (\r
1106 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,\r
1107 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath\r
1108 )\r
1109{\r
1110 HARDDRIVE_DEVICE_PATH *TmpHdPath;\r
1111 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
1112 BOOLEAN Match;\r
1113 EFI_DEVICE_PATH_PROTOCOL *BlockIoHdDevicePathNode;\r
1114\r
1115 if ((BlockIoDevicePath == NULL) || (HardDriveDevicePath == NULL)) {\r
1116 return FALSE;\r
1117 }\r
128efbbc 1118\r
5c08e117 1119 //\r
1120 // Make PreviousDevicePath == the device path node before the end node\r
1121 //\r
1122 DevicePath = BlockIoDevicePath;\r
1123 BlockIoHdDevicePathNode = NULL;\r
1124\r
1125 //\r
1126 // find the partition device path node\r
1127 //\r
1128 while (!IsDevicePathEnd (DevicePath)) {\r
1129 if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&\r
1130 (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)\r
1131 ) {\r
1132 BlockIoHdDevicePathNode = DevicePath;\r
1133 break;\r
1134 }\r
1135\r
1136 DevicePath = NextDevicePathNode (DevicePath);\r
1137 }\r
1138\r
1139 if (BlockIoHdDevicePathNode == NULL) {\r
1140 return FALSE;\r
1141 }\r
1142 //\r
1143 // See if the harddrive device path in blockio matches the orig Hard Drive Node\r
1144 //\r
1145 TmpHdPath = (HARDDRIVE_DEVICE_PATH *) BlockIoHdDevicePathNode;\r
1146 Match = FALSE;\r
128efbbc 1147\r
5c08e117 1148 //\r
1149 // Check for the match\r
1150 //\r
1151 if ((TmpHdPath->MBRType == HardDriveDevicePath->MBRType) &&\r
1152 (TmpHdPath->SignatureType == HardDriveDevicePath->SignatureType)) {\r
1153 switch (TmpHdPath->SignatureType) {\r
1154 case SIGNATURE_TYPE_GUID:\r
1155 Match = CompareGuid ((EFI_GUID *)TmpHdPath->Signature, (EFI_GUID *)HardDriveDevicePath->Signature);\r
1156 break;\r
1157 case SIGNATURE_TYPE_MBR:\r
1158 Match = (BOOLEAN)(*((UINT32 *)(&(TmpHdPath->Signature[0]))) == ReadUnaligned32((UINT32 *)(&(HardDriveDevicePath->Signature[0]))));\r
1159 break;\r
1160 default:\r
1161 Match = FALSE;\r
1162 break;\r
1163 }\r
1164 }\r
1165\r
1166 return Match;\r
1167}\r
1168\r
1169/**\r
1170 Delete the boot option associated with the handle passed in.\r
1171\r
1172 @param Handle The handle which present the device path to create\r
1173 boot option\r
1174\r
1175 @retval EFI_SUCCESS Delete the boot option success\r
1176 @retval EFI_NOT_FOUND If the Device Path is not found in the system\r
1177 @retval EFI_OUT_OF_RESOURCES Lack of memory resource\r
1178 @retval Other Error return value from SetVariable()\r
1179\r
1180**/\r
1181EFI_STATUS\r
1182BdsLibDeleteOptionFromHandle (\r
1183 IN EFI_HANDLE Handle\r
1184 )\r
1185{\r
1186 UINT16 *BootOrder;\r
1187 UINT8 *BootOptionVar;\r
1188 UINTN BootOrderSize;\r
1189 UINTN BootOptionSize;\r
1190 EFI_STATUS Status;\r
1191 UINTN Index;\r
1192 UINT16 BootOption[BOOT_OPTION_MAX_CHAR];\r
1193 UINTN DevicePathSize;\r
1194 UINTN OptionDevicePathSize;\r
1195 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
1196 EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;\r
1197 UINT8 *TempPtr;\r
1198\r
1199 Status = EFI_SUCCESS;\r
1200 BootOrder = NULL;\r
1201 BootOrderSize = 0;\r
1202\r
1203 //\r
1204 // Check "BootOrder" variable, if no, means there is no any boot order.\r
1205 //\r
1206 BootOrder = BdsLibGetVariableAndSize (\r
1207 L"BootOrder",\r
1208 &gEfiGlobalVariableGuid,\r
1209 &BootOrderSize\r
1210 );\r
1211 if (BootOrder == NULL) {\r
1212 return EFI_NOT_FOUND;\r
1213 }\r
1214\r
1215 //\r
1216 // Convert device handle to device path protocol instance\r
1217 //\r
1218 DevicePath = DevicePathFromHandle (Handle);\r
1219 if (DevicePath == NULL) {\r
1220 return EFI_NOT_FOUND;\r
1221 }\r
1222 DevicePathSize = GetDevicePathSize (DevicePath);\r
1223\r
1224 //\r
1225 // Loop all boot order variable and find the matching device path\r
1226 //\r
1227 Index = 0;\r
1228 while (Index < BootOrderSize / sizeof (UINT16)) {\r
1229 UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);\r
1230 BootOptionVar = BdsLibGetVariableAndSize (\r
1231 BootOption,\r
1232 &gEfiGlobalVariableGuid,\r
1233 &BootOptionSize\r
1234 );\r
128efbbc 1235\r
5c08e117 1236 if (BootOptionVar == NULL) {\r
1237 FreePool (BootOrder);\r
1238 return EFI_OUT_OF_RESOURCES;\r
1239 }\r
1240\r
1241 TempPtr = BootOptionVar;\r
1242 TempPtr += sizeof (UINT32) + sizeof (UINT16);\r
1243 TempPtr += StrSize ((CHAR16 *) TempPtr);\r
1244 OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
1245 OptionDevicePathSize = GetDevicePathSize (OptionDevicePath);\r
1246\r
1247 //\r
1248 // Check whether the device path match\r
1249 //\r
1250 if ((OptionDevicePathSize == DevicePathSize) &&\r
1251 (CompareMem (DevicePath, OptionDevicePath, DevicePathSize) == 0)) {\r
1252 BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize);\r
1253 FreePool (BootOptionVar);\r
1254 break;\r
1255 }\r
1256\r
1257 FreePool (BootOptionVar);\r
1258 Index++;\r
1259 }\r
1260\r
1261 //\r
1262 // Adjust number of boot option for "BootOrder" variable.\r
1263 //\r
1264 Status = gRT->SetVariable (\r
1265 L"BootOrder",\r
1266 &gEfiGlobalVariableGuid,\r
1267 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1268 BootOrderSize,\r
1269 BootOrder\r
1270 );\r
1271\r
1272 FreePool (BootOrder);\r
1273\r
1274 return Status;\r
1275}\r
1276\r
1277\r
1278/**\r
3384a9bc 1279 Delete all invalid EFI boot options.\r
5c08e117 1280\r
1281 @retval EFI_SUCCESS Delete all invalid boot option success\r
1282 @retval EFI_NOT_FOUND Variable "BootOrder" is not found\r
1283 @retval EFI_OUT_OF_RESOURCES Lack of memory resource\r
1284 @retval Other Error return value from SetVariable()\r
1285\r
1286**/\r
1287EFI_STATUS\r
1288BdsDeleteAllInvalidEfiBootOption (\r
1289 VOID\r
1290 )\r
1291{\r
1292 UINT16 *BootOrder;\r
1293 UINT8 *BootOptionVar;\r
1294 UINTN BootOrderSize;\r
1295 UINTN BootOptionSize;\r
1296 EFI_STATUS Status;\r
1297 UINTN Index;\r
1298 UINTN Index2;\r
1299 UINT16 BootOption[BOOT_OPTION_MAX_CHAR];\r
1300 EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;\r
1301 UINT8 *TempPtr;\r
3384a9bc 1302 CHAR16 *Description;\r
5c08e117 1303\r
1304 Status = EFI_SUCCESS;\r
1305 BootOrder = NULL;\r
1306 BootOrderSize = 0;\r
1307\r
1308 //\r
1309 // Check "BootOrder" variable firstly, this variable hold the number of boot options\r
1310 //\r
1311 BootOrder = BdsLibGetVariableAndSize (\r
1312 L"BootOrder",\r
1313 &gEfiGlobalVariableGuid,\r
1314 &BootOrderSize\r
1315 );\r
1316 if (NULL == BootOrder) {\r
1317 return EFI_NOT_FOUND;\r
1318 }\r
1319\r
1320 Index = 0;\r
1321 while (Index < BootOrderSize / sizeof (UINT16)) {\r
1322 UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);\r
1323 BootOptionVar = BdsLibGetVariableAndSize (\r
1324 BootOption,\r
1325 &gEfiGlobalVariableGuid,\r
1326 &BootOptionSize\r
1327 );\r
1328 if (NULL == BootOptionVar) {\r
1329 FreePool (BootOrder);\r
1330 return EFI_OUT_OF_RESOURCES;\r
1331 }\r
1332\r
1333 TempPtr = BootOptionVar;\r
1334 TempPtr += sizeof (UINT32) + sizeof (UINT16);\r
3384a9bc 1335 Description = (CHAR16 *) TempPtr;\r
5c08e117 1336 TempPtr += StrSize ((CHAR16 *) TempPtr);\r
1337 OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
1338\r
1339 //\r
1340 // Skip legacy boot option (BBS boot device)\r
1341 //\r
1342 if ((DevicePathType (OptionDevicePath) == BBS_DEVICE_PATH) &&\r
1343 (DevicePathSubType (OptionDevicePath) == BBS_BBS_DP)) {\r
1344 FreePool (BootOptionVar);\r
1345 Index++;\r
1346 continue;\r
1347 }\r
1348\r
3384a9bc 1349 if (!BdsLibIsValidEFIBootOptDevicePathExt (OptionDevicePath, FALSE, Description)) {\r
5c08e117 1350 //\r
1351 // Delete this invalid boot option "Boot####"\r
1352 //\r
1353 Status = gRT->SetVariable (\r
1354 BootOption,\r
1355 &gEfiGlobalVariableGuid,\r
1356 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1357 0,\r
1358 NULL\r
1359 );\r
1360 //\r
1361 // Mark this boot option in boot order as deleted\r
1362 //\r
1363 BootOrder[Index] = 0xffff;\r
1364 }\r
1365\r
1366 FreePool (BootOptionVar);\r
1367 Index++;\r
1368 }\r
1369\r
1370 //\r
1371 // Adjust boot order array\r
1372 //\r
1373 Index2 = 0;\r
1374 for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {\r
1375 if (BootOrder[Index] != 0xffff) {\r
1376 BootOrder[Index2] = BootOrder[Index];\r
1377 Index2 ++;\r
1378 }\r
1379 }\r
1380 Status = gRT->SetVariable (\r
1381 L"BootOrder",\r
1382 &gEfiGlobalVariableGuid,\r
1383 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1384 Index2 * sizeof (UINT16),\r
1385 BootOrder\r
1386 );\r
1387\r
1388 FreePool (BootOrder);\r
1389\r
1390 return Status;\r
1391}\r
1392\r
1393\r
1394/**\r
3384a9bc 1395 For EFI boot option, BDS separate them as six types:\r
128efbbc 1396 1. Network - The boot option points to the SimpleNetworkProtocol device.\r
3384a9bc 1397 Bds will try to automatically create this type boot option when enumerate.\r
128efbbc 1398 2. Shell - The boot option points to internal flash shell.\r
3384a9bc 1399 Bds will try to automatically create this type boot option when enumerate.\r
1400 3. Removable BlockIo - The boot option only points to the removable media\r
1401 device, like USB flash disk, DVD, Floppy etc.\r
1402 These device should contain a *removable* blockIo\r
1403 protocol in their device handle.\r
128efbbc 1404 Bds will try to automatically create this type boot option\r
3384a9bc 1405 when enumerate.\r
128efbbc 1406 4. Fixed BlockIo - The boot option only points to a Fixed blockIo device,\r
3384a9bc 1407 like HardDisk.\r
1408 These device should contain a *fixed* blockIo\r
1409 protocol in their device handle.\r
1410 BDS will skip fixed blockIo devices, and NOT\r
128efbbc 1411 automatically create boot option for them. But BDS\r
1412 will help to delete those fixed blockIo boot option,\r
3384a9bc 1413 whose description rule conflict with other auto-created\r
1414 boot options.\r
128efbbc 1415 5. Non-BlockIo Simplefile - The boot option points to a device whose handle\r
3384a9bc 1416 has SimpleFileSystem Protocol, but has no blockio\r
1417 protocol. These devices do not offer blockIo\r
128efbbc 1418 protocol, but BDS still can get the\r
3384a9bc 1419 \EFI\BOOT\boot{machinename}.EFI by SimpleFileSystem\r
1420 Protocol.\r
128efbbc 1421 6. File - The boot option points to a file. These boot options are usually\r
3384a9bc 1422 created by user manually or OS loader. BDS will not delete or modify\r
128efbbc 1423 these boot options.\r
1424\r
3384a9bc 1425 This function will enumerate all possible boot device in the system, and\r
128efbbc 1426 automatically create boot options for Network, Shell, Removable BlockIo,\r
3384a9bc 1427 and Non-BlockIo Simplefile devices.\r
8d3b5aff 1428 It will only execute once of every boot.\r
128efbbc 1429\r
5c08e117 1430 @param BdsBootOptionList The header of the link list which indexed all\r
1431 current boot options\r
1432\r
1433 @retval EFI_SUCCESS Finished all the boot device enumerate and create\r
1434 the boot option base on that boot device\r
1435\r
e83c9064 1436 @retval EFI_OUT_OF_RESOURCES Failed to enumerate the boot device and create the boot option list\r
5c08e117 1437**/\r
1438EFI_STATUS\r
1439EFIAPI\r
1440BdsLibEnumerateAllBootOption (\r
1441 IN OUT LIST_ENTRY *BdsBootOptionList\r
1442 )\r
1443{\r
1444 EFI_STATUS Status;\r
1445 UINT16 FloppyNumber;\r
889a4bc2 1446 UINT16 HarddriveNumber;\r
5c08e117 1447 UINT16 CdromNumber;\r
1448 UINT16 UsbNumber;\r
1449 UINT16 MiscNumber;\r
8d3b5aff 1450 UINT16 ScsiNumber;\r
5c08e117 1451 UINT16 NonBlockNumber;\r
1452 UINTN NumberBlockIoHandles;\r
1453 EFI_HANDLE *BlockIoHandles;\r
1454 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
35bc0e9f
RN
1455 BOOLEAN Removable[2];\r
1456 UINTN RemovableIndex;\r
5c08e117 1457 UINTN Index;\r
a7a523e0 1458 UINTN NumOfLoadFileHandles;\r
1459 EFI_HANDLE *LoadFileHandles;\r
5c08e117 1460 UINTN FvHandleCount;\r
1461 EFI_HANDLE *FvHandleBuffer;\r
1462 EFI_FV_FILETYPE Type;\r
1463 UINTN Size;\r
1464 EFI_FV_FILE_ATTRIBUTES Attributes;\r
1465 UINT32 AuthenticationStatus;\r
8d3b5aff 1466 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
1467 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
5c08e117 1468 UINTN DevicePathType;\r
1469 CHAR16 Buffer[40];\r
1470 EFI_HANDLE *FileSystemHandles;\r
1471 UINTN NumberFileSystemHandles;\r
1472 BOOLEAN NeedDelete;\r
1473 EFI_IMAGE_DOS_HEADER DosHeader;\r
9aa7ba01 1474 CHAR8 *PlatLang;\r
1475 CHAR8 *LastLang;\r
5c08e117 1476 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;\r
1477 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
1478\r
889a4bc2
RN
1479 FloppyNumber = 0;\r
1480 HarddriveNumber = 0;\r
1481 CdromNumber = 0;\r
1482 UsbNumber = 0;\r
1483 MiscNumber = 0;\r
1484 ScsiNumber = 0;\r
1485 PlatLang = NULL;\r
1486 LastLang = NULL;\r
5c08e117 1487 ZeroMem (Buffer, sizeof (Buffer));\r
128efbbc 1488\r
5c08e117 1489 //\r
1490 // If the boot device enumerate happened, just get the boot\r
1491 // device from the boot order variable\r
1492 //\r
1493 if (mEnumBootDevice) {\r
e24fc103 1494 LastLang = GetVariable (LAST_ENUM_LANGUAGE_VARIABLE_NAME, &gLastEnumLangGuid);\r
9aa7ba01 1495 PlatLang = GetEfiGlobalVariable (L"PlatformLang");\r
0fa3ac1b
RN
1496 ASSERT (PlatLang != NULL);\r
1497 if ((LastLang != NULL) && (AsciiStrCmp (LastLang, PlatLang) == 0)) {\r
9aa7ba01 1498 Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");\r
0fa3ac1b
RN
1499 FreePool (LastLang);\r
1500 FreePool (PlatLang);\r
9aa7ba01 1501 return Status;\r
1502 } else {\r
1503 Status = gRT->SetVariable (\r
e24fc103
LG
1504 LAST_ENUM_LANGUAGE_VARIABLE_NAME,\r
1505 &gLastEnumLangGuid,\r
9aa7ba01 1506 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
0fa3ac1b 1507 AsciiStrSize (PlatLang),\r
9aa7ba01 1508 PlatLang\r
1509 );\r
1510 ASSERT_EFI_ERROR (Status);\r
0fa3ac1b
RN
1511\r
1512 if (LastLang != NULL) {\r
1513 FreePool (LastLang);\r
1514 }\r
1515 FreePool (PlatLang);\r
9aa7ba01 1516 }\r
5c08e117 1517 }\r
128efbbc 1518\r
5c08e117 1519 //\r
1520 // Notes: this dirty code is to get the legacy boot option from the\r
1521 // BBS table and create to variable as the EFI boot option, it should\r
1522 // be removed after the CSM can provide legacy boot option directly\r
1523 //\r
1524 REFRESH_LEGACY_BOOT_OPTIONS;\r
1525\r
1526 //\r
1527 // Delete invalid boot option\r
1528 //\r
1529 BdsDeleteAllInvalidEfiBootOption ();\r
128efbbc 1530\r
5c08e117 1531 //\r
701e17e5
RN
1532 // Parse removable media followed by fixed media.\r
1533 // The Removable[] array is used by the for-loop below to create removable media boot options \r
1534 // at first, and then to create fixed media boot options.\r
5c08e117 1535 //\r
701e17e5
RN
1536 Removable[0] = FALSE;\r
1537 Removable[1] = TRUE;\r
1538\r
5c08e117 1539 gBS->LocateHandleBuffer (\r
1540 ByProtocol,\r
1541 &gEfiBlockIoProtocolGuid,\r
1542 NULL,\r
1543 &NumberBlockIoHandles,\r
1544 &BlockIoHandles\r
1545 );\r
128efbbc 1546\r
35bc0e9f
RN
1547 for (RemovableIndex = 0; RemovableIndex < 2; RemovableIndex++) {\r
1548 for (Index = 0; Index < NumberBlockIoHandles; Index++) {\r
1549 Status = gBS->HandleProtocol (\r
1550 BlockIoHandles[Index],\r
1551 &gEfiBlockIoProtocolGuid,\r
1552 (VOID **) &BlkIo\r
1553 );\r
1554 //\r
1555 // skip the fixed block io then the removable block io\r
1556 //\r
1557 if (EFI_ERROR (Status) || (BlkIo->Media->RemovableMedia == Removable[RemovableIndex])) {\r
5c08e117 1558 continue;\r
1559 }\r
35bc0e9f
RN
1560 DevicePath = DevicePathFromHandle (BlockIoHandles[Index]);\r
1561 DevicePathType = BdsGetBootTypeFromDevicePath (DevicePath);\r
5c08e117 1562\r
35bc0e9f
RN
1563 switch (DevicePathType) {\r
1564 case BDS_EFI_ACPI_FLOPPY_BOOT:\r
1565 if (FloppyNumber != 0) {\r
1566 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)), FloppyNumber);\r
1567 } else {\r
1568 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)));\r
1569 }\r
1570 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
1571 FloppyNumber++;\r
1572 break;\r
128efbbc 1573\r
35bc0e9f 1574 //\r
889a4bc2 1575 // Assume a removable SATA device should be the DVD/CD device, a fixed SATA device should be the Hard Drive device.\r
35bc0e9f
RN
1576 //\r
1577 case BDS_EFI_MESSAGE_ATAPI_BOOT:\r
1578 case BDS_EFI_MESSAGE_SATA_BOOT:\r
889a4bc2
RN
1579 if (BlkIo->Media->RemovableMedia) {\r
1580 if (CdromNumber != 0) {\r
1581 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)), CdromNumber);\r
1582 } else {\r
1583 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)));\r
1584 }\r
1585 CdromNumber++;\r
35bc0e9f 1586 } else {\r
889a4bc2
RN
1587 if (HarddriveNumber != 0) {\r
1588 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)), HarddriveNumber);\r
1589 } else {\r
1590 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)));\r
1591 }\r
1592 HarddriveNumber++;\r
35bc0e9f
RN
1593 }\r
1594 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Buffer: %S\n", Buffer));\r
1595 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
35bc0e9f
RN
1596 break;\r
1597\r
1598 case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:\r
1599 if (UsbNumber != 0) {\r
1600 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)), UsbNumber);\r
1601 } else {\r
1602 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)));\r
1603 }\r
1604 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
1605 UsbNumber++;\r
1606 break;\r
5c08e117 1607\r
35bc0e9f
RN
1608 case BDS_EFI_MESSAGE_SCSI_BOOT:\r
1609 if (ScsiNumber != 0) {\r
1610 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)), ScsiNumber);\r
1611 } else {\r
1612 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)));\r
1613 }\r
1614 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
1615 ScsiNumber++;\r
1616 break;\r
5c08e117 1617\r
35bc0e9f
RN
1618 case BDS_EFI_MESSAGE_MISC_BOOT:\r
1619 if (MiscNumber != 0) {\r
1620 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber);\r
1621 } else {\r
1622 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)));\r
1623 }\r
1624 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
1625 MiscNumber++;\r
1626 break;\r
5c08e117 1627\r
35bc0e9f
RN
1628 default:\r
1629 break;\r
9aa7ba01 1630 }\r
5c08e117 1631 }\r
1632 }\r
1633\r
1634 if (NumberBlockIoHandles != 0) {\r
1635 FreePool (BlockIoHandles);\r
1636 }\r
1637\r
1638 //\r
1639 // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.\r
1640 //\r
1641 NonBlockNumber = 0;\r
1642 gBS->LocateHandleBuffer (\r
1643 ByProtocol,\r
1644 &gEfiSimpleFileSystemProtocolGuid,\r
1645 NULL,\r
1646 &NumberFileSystemHandles,\r
1647 &FileSystemHandles\r
1648 );\r
1649 for (Index = 0; Index < NumberFileSystemHandles; Index++) {\r
1650 Status = gBS->HandleProtocol (\r
1651 FileSystemHandles[Index],\r
1652 &gEfiBlockIoProtocolGuid,\r
1653 (VOID **) &BlkIo\r
1654 );\r
1655 if (!EFI_ERROR (Status)) {\r
1656 //\r
1657 // Skip if the file system handle supports a BlkIo protocol,\r
1658 //\r
1659 continue;\r
1660 }\r
1661\r
1662 //\r
1663 // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI\r
1664 // machinename is ia32, ia64, x64, ...\r
1665 //\r
35bc0e9f 1666 Hdr.Union = &HdrData;\r
5c08e117 1667 NeedDelete = TRUE;\r
1668 Status = BdsLibGetImageHeader (\r
1669 FileSystemHandles[Index],\r
c62dbf31 1670 EFI_REMOVABLE_MEDIA_FILE_NAME,\r
5c08e117 1671 &DosHeader,\r
1672 Hdr\r
1673 );\r
1674 if (!EFI_ERROR (Status) &&\r
1675 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&\r
1676 Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {\r
1677 NeedDelete = FALSE;\r
1678 }\r
1679\r
1680 if (NeedDelete) {\r
1681 //\r
1682 // No such file or the file is not a EFI application, delete this boot option\r
1683 //\r
1684 BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]);\r
1685 } else {\r
9aa7ba01 1686 if (NonBlockNumber != 0) {\r
1687 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)), NonBlockNumber);\r
1688 } else {\r
1689 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)));\r
1690 }\r
5c08e117 1691 BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOptionList, Buffer);\r
1692 NonBlockNumber++;\r
1693 }\r
1694 }\r
1695\r
1696 if (NumberFileSystemHandles != 0) {\r
1697 FreePool (FileSystemHandles);\r
1698 }\r
1699\r
1700 //\r
1701 // Parse Network Boot Device\r
1702 //\r
a7a523e0 1703 NumOfLoadFileHandles = 0;\r
ff482c56 1704 //\r
a7a523e0 1705 // Search Load File protocol for PXE boot option.\r
ff482c56 1706 //\r
5c08e117 1707 gBS->LocateHandleBuffer (\r
1708 ByProtocol,\r
a7a523e0 1709 &gEfiLoadFileProtocolGuid,\r
5c08e117 1710 NULL,\r
a7a523e0 1711 &NumOfLoadFileHandles,\r
1712 &LoadFileHandles\r
5c08e117 1713 );\r
8d3b5aff 1714\r
a7a523e0 1715 for (Index = 0; Index < NumOfLoadFileHandles; Index++) {\r
9aa7ba01 1716 if (Index != 0) {\r
1717 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)), Index);\r
1718 } else {\r
1719 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)));\r
1720 }\r
a7a523e0 1721 BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList, Buffer);\r
5c08e117 1722 }\r
1723\r
a7a523e0 1724 if (NumOfLoadFileHandles != 0) {\r
1725 FreePool (LoadFileHandles);\r
5c08e117 1726 }\r
1727\r
1728 //\r
1729 // Check if we have on flash shell\r
1730 //\r
1731 gBS->LocateHandleBuffer (\r
1732 ByProtocol,\r
1733 &gEfiFirmwareVolume2ProtocolGuid,\r
1734 NULL,\r
1735 &FvHandleCount,\r
1736 &FvHandleBuffer\r
1737 );\r
1738 for (Index = 0; Index < FvHandleCount; Index++) {\r
5c08e117 1739 gBS->HandleProtocol (\r
1740 FvHandleBuffer[Index],\r
1741 &gEfiFirmwareVolume2ProtocolGuid,\r
1742 (VOID **) &Fv\r
1743 );\r
1744\r
1745 Status = Fv->ReadFile (\r
1746 Fv,\r
d46f3632 1747 PcdGetPtr(PcdShellFile),\r
5c08e117 1748 NULL,\r
1749 &Size,\r
1750 &Type,\r
1751 &Attributes,\r
1752 &AuthenticationStatus\r
1753 );\r
1754 if (EFI_ERROR (Status)) {\r
1755 //\r
1756 // Skip if no shell file in the FV\r
1757 //\r
1758 continue;\r
1759 }\r
1760 //\r
1761 // Build the shell boot option\r
1762 //\r
1763 BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);\r
1764 }\r
1765\r
1766 if (FvHandleCount != 0) {\r
1767 FreePool (FvHandleBuffer);\r
1768 }\r
1769 //\r
1770 // Make sure every boot only have one time\r
1771 // boot device enumerate\r
1772 //\r
e83c9064 1773 Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");\r
5c08e117 1774 mEnumBootDevice = TRUE;\r
1775\r
e83c9064 1776 return Status;\r
5c08e117 1777}\r
1778\r
1779/**\r
1780 Build the boot option with the handle parsed in\r
1781\r
1782 @param Handle The handle which present the device path to create\r
1783 boot option\r
1784 @param BdsBootOptionList The header of the link list which indexed all\r
1785 current boot options\r
1786 @param String The description of the boot option.\r
1787\r
1788**/\r
1789VOID\r
1790EFIAPI\r
1791BdsLibBuildOptionFromHandle (\r
1792 IN EFI_HANDLE Handle,\r
1793 IN LIST_ENTRY *BdsBootOptionList,\r
1794 IN CHAR16 *String\r
1795 )\r
1796{\r
1797 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
128efbbc 1798\r
8d3b5aff 1799 DevicePath = DevicePathFromHandle (Handle);\r
5c08e117 1800\r
1801 //\r
1802 // Create and register new boot option\r
1803 //\r
1804 BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, String, L"BootOrder");\r
1805}\r
1806\r
1807\r
1808/**\r
1809 Build the on flash shell boot option with the handle parsed in.\r
1810\r
1811 @param Handle The handle which present the device path to create\r
1812 on flash shell boot option\r
1813 @param BdsBootOptionList The header of the link list which indexed all\r
1814 current boot options\r
1815\r
1816**/\r
1817VOID\r
1818EFIAPI\r
1819BdsLibBuildOptionFromShell (\r
1820 IN EFI_HANDLE Handle,\r
1821 IN OUT LIST_ENTRY *BdsBootOptionList\r
1822 )\r
1823{\r
1824 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
1825 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH ShellNode;\r
1826\r
1827 DevicePath = DevicePathFromHandle (Handle);\r
1828\r
1829 //\r
1830 // Build the shell device path\r
1831 //\r
d46f3632 1832 EfiInitializeFwVolDevicepathNode (&ShellNode, PcdGetPtr(PcdShellFile));\r
5c08e117 1833\r
1834 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &ShellNode);\r
1835\r
1836 //\r
1837 // Create and register the shell boot option\r
1838 //\r
1839 BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, L"EFI Internal Shell", L"BootOrder");\r
1840\r
1841}\r
1842\r
1843/**\r
1844 Boot from the UEFI spec defined "BootNext" variable.\r
1845\r
1846**/\r
1847VOID\r
1848EFIAPI\r
1849BdsLibBootNext (\r
1850 VOID\r
1851 )\r
1852{\r
1853 UINT16 *BootNext;\r
1854 UINTN BootNextSize;\r
1855 CHAR16 Buffer[20];\r
1856 BDS_COMMON_OPTION *BootOption;\r
1857 LIST_ENTRY TempList;\r
1858 UINTN ExitDataSize;\r
1859 CHAR16 *ExitData;\r
1860\r
1861 //\r
1862 // Init the boot option name buffer and temp link list\r
1863 //\r
1864 InitializeListHead (&TempList);\r
1865 ZeroMem (Buffer, sizeof (Buffer));\r
1866\r
1867 BootNext = BdsLibGetVariableAndSize (\r
1868 L"BootNext",\r
1869 &gEfiGlobalVariableGuid,\r
1870 &BootNextSize\r
1871 );\r
1872\r
1873 //\r
1874 // Clear the boot next variable first\r
1875 //\r
1876 if (BootNext != NULL) {\r
1877 gRT->SetVariable (\r
1878 L"BootNext",\r
1879 &gEfiGlobalVariableGuid,\r
1880 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1881 0,\r
1882 BootNext\r
1883 );\r
1884\r
1885 //\r
1886 // Start to build the boot option and try to boot\r
1887 //\r
1888 UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *BootNext);\r
1889 BootOption = BdsLibVariableToOption (&TempList, Buffer);\r
1890 ASSERT (BootOption != NULL);\r
1891 BdsLibConnectDevicePath (BootOption->DevicePath);\r
1892 BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);\r
1893 }\r
1894\r
1895}\r
1896\r
1897/**\r
1898 Return the bootable media handle.\r
1899 First, check the device is connected\r
1900 Second, check whether the device path point to a device which support SimpleFileSystemProtocol,\r
1901 Third, detect the the default boot file in the Media, and return the removable Media handle.\r
1902\r
e83c9064 1903 @param DevicePath Device Path to a bootable device\r
5c08e117 1904\r
e83c9064 1905 @return The bootable media handle. If the media on the DevicePath is not bootable, NULL will return.\r
5c08e117 1906\r
1907**/\r
1908EFI_HANDLE\r
1909EFIAPI\r
1910BdsLibGetBootableHandle (\r
1911 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
1912 )\r
1913{\r
1914 EFI_STATUS Status;\r
ef949581 1915 EFI_TPL OldTpl;\r
5c08e117 1916 EFI_DEVICE_PATH_PROTOCOL *UpdatedDevicePath;\r
1917 EFI_DEVICE_PATH_PROTOCOL *DupDevicePath;\r
1918 EFI_HANDLE Handle;\r
1919 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
1920 VOID *Buffer;\r
1921 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
1922 UINTN Size;\r
1923 UINTN TempSize;\r
1924 EFI_HANDLE ReturnHandle;\r
1925 EFI_HANDLE *SimpleFileSystemHandles;\r
1926\r
1927 UINTN NumberSimpleFileSystemHandles;\r
1928 UINTN Index;\r
1929 EFI_IMAGE_DOS_HEADER DosHeader;\r
1930 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;\r
1931 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
1932\r
1933 UpdatedDevicePath = DevicePath;\r
128efbbc 1934\r
ef949581
RN
1935 //\r
1936 // Enter to critical section to protect the acquired BlockIo instance \r
1937 // from getting released due to the USB mass storage hotplug event\r
1938 //\r
1939 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
1940\r
5c08e117 1941 //\r
1942 // Check whether the device is connected\r
1943 //\r
1944 Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &UpdatedDevicePath, &Handle);\r
1945 if (EFI_ERROR (Status)) {\r
1946 //\r
1947 // Skip the case that the boot option point to a simple file protocol which does not consume block Io protocol,\r
1948 //\r
1949 Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &UpdatedDevicePath, &Handle);\r
1950 if (EFI_ERROR (Status)) {\r
1951 //\r
1952 // Fail to find the proper BlockIo and simple file protocol, maybe because device not present, we need to connect it firstly\r
1953 //\r
1954 UpdatedDevicePath = DevicePath;\r
1955 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);\r
1956 gBS->ConnectController (Handle, NULL, NULL, TRUE);\r
1957 }\r
1958 } else {\r
e74f510b
RN
1959 //\r
1960 // For removable device boot option, its contained device path only point to the removable device handle, \r
1961 // should make sure all its children handles (its child partion or media handles) are created and connected. \r
1962 //\r
1963 gBS->ConnectController (Handle, NULL, NULL, TRUE); \r
5c08e117 1964 //\r
1965 // Get BlockIo protocol and check removable attribute\r
1966 //\r
1967 Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);\r
ef949581
RN
1968 ASSERT_EFI_ERROR (Status);\r
1969\r
5c08e117 1970 //\r
1971 // Issue a dummy read to the device to check for media change.\r
1972 // When the removable media is changed, any Block IO read/write will\r
1973 // cause the BlockIo protocol be reinstalled and EFI_MEDIA_CHANGED is\r
1974 // returned. After the Block IO protocol is reinstalled, subsequent\r
1975 // Block IO read/write will success.\r
1976 //\r
1977 Buffer = AllocatePool (BlockIo->Media->BlockSize);\r
1978 if (Buffer != NULL) {\r
1979 BlockIo->ReadBlocks (\r
1980 BlockIo,\r
1981 BlockIo->Media->MediaId,\r
1982 0,\r
1983 BlockIo->Media->BlockSize,\r
1984 Buffer\r
1985 );\r
1986 FreePool(Buffer);\r
1987 }\r
1988 }\r
1989\r
1990 //\r
1991 // Detect the the default boot file from removable Media\r
1992 //\r
1993\r
1994 //\r
1995 // If fail to get bootable handle specified by a USB boot option, the BDS should try to find other bootable device in the same USB bus\r
1996 // Try to locate the USB node device path first, if fail then use its previous PCI node to search\r
1997 //\r
1998 DupDevicePath = DuplicateDevicePath (DevicePath);\r
1999 ASSERT (DupDevicePath != NULL);\r
128efbbc 2000\r
5c08e117 2001 UpdatedDevicePath = DupDevicePath;\r
2002 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);\r
2003 //\r
2004 // if the resulting device path point to a usb node, and the usb node is a dummy node, should only let device path only point to the previous Pci node\r
2005 // Acpi()/Pci()/Usb() --> Acpi()/Pci()\r
2006 //\r
2007 if ((DevicePathType (UpdatedDevicePath) == MESSAGING_DEVICE_PATH) &&\r
2008 (DevicePathSubType (UpdatedDevicePath) == MSG_USB_DP)) {\r
2009 //\r
2010 // Remove the usb node, let the device path only point to PCI node\r
2011 //\r
2012 SetDevicePathEndNode (UpdatedDevicePath);\r
2013 UpdatedDevicePath = DupDevicePath;\r
2014 } else {\r
2015 UpdatedDevicePath = DevicePath;\r
2016 }\r
2017\r
2018 //\r
2019 // Get the device path size of boot option\r
2020 //\r
2021 Size = GetDevicePathSize(UpdatedDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL); // minus the end node\r
2022 ReturnHandle = NULL;\r
2023 gBS->LocateHandleBuffer (\r
2024 ByProtocol,\r
2025 &gEfiSimpleFileSystemProtocolGuid,\r
2026 NULL,\r
2027 &NumberSimpleFileSystemHandles,\r
2028 &SimpleFileSystemHandles\r
2029 );\r
2030 for (Index = 0; Index < NumberSimpleFileSystemHandles; Index++) {\r
2031 //\r
2032 // Get the device path size of SimpleFileSystem handle\r
2033 //\r
2034 TempDevicePath = DevicePathFromHandle (SimpleFileSystemHandles[Index]);\r
2035 TempSize = GetDevicePathSize (TempDevicePath)- sizeof (EFI_DEVICE_PATH_PROTOCOL); // minus the end node\r
2036 //\r
2037 // Check whether the device path of boot option is part of the SimpleFileSystem handle's device path\r
2038 //\r
2039 if (Size <= TempSize && CompareMem (TempDevicePath, UpdatedDevicePath, Size)==0) {\r
2040 //\r
2041 // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media\r
2042 // machinename is ia32, ia64, x64, ...\r
2043 //\r
2044 Hdr.Union = &HdrData;\r
2045 Status = BdsLibGetImageHeader (\r
2046 SimpleFileSystemHandles[Index],\r
c62dbf31 2047 EFI_REMOVABLE_MEDIA_FILE_NAME,\r
5c08e117 2048 &DosHeader,\r
2049 Hdr\r
2050 );\r
2051 if (!EFI_ERROR (Status) &&\r
2052 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&\r
2053 Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {\r
2054 ReturnHandle = SimpleFileSystemHandles[Index];\r
2055 break;\r
2056 }\r
2057 }\r
2058 }\r
2059\r
2060 FreePool(DupDevicePath);\r
2061\r
2062 if (SimpleFileSystemHandles != NULL) {\r
2063 FreePool(SimpleFileSystemHandles);\r
2064 }\r
2065\r
ef949581
RN
2066 gBS->RestoreTPL (OldTpl);\r
2067\r
5c08e117 2068 return ReturnHandle;\r
2069}\r
2070\r
2071/**\r
2072 Check to see if the network cable is plugged in. If the DevicePath is not\r
2073 connected it will be connected.\r
2074\r
2075 @param DevicePath Device Path to check\r
2076\r
2077 @retval TRUE DevicePath points to an Network that is connected\r
2078 @retval FALSE DevicePath does not point to a bootable network\r
2079\r
2080**/\r
2081BOOLEAN\r
2082BdsLibNetworkBootWithMediaPresent (\r
2083 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
2084 )\r
2085{\r
2086 EFI_STATUS Status;\r
2087 EFI_DEVICE_PATH_PROTOCOL *UpdatedDevicePath;\r
2088 EFI_HANDLE Handle;\r
2089 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
2090 BOOLEAN MediaPresent;\r
e51e619e 2091 UINT32 InterruptStatus;\r
5c08e117 2092\r
2093 MediaPresent = FALSE;\r
2094\r
2095 UpdatedDevicePath = DevicePath;\r
ff482c56 2096 //\r
a7a523e0 2097 // Locate Load File Protocol for PXE boot option first\r
ff482c56 2098 //\r
a7a523e0 2099 Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &UpdatedDevicePath, &Handle);\r
5c08e117 2100 if (EFI_ERROR (Status)) {\r
2101 //\r
2102 // Device not present so see if we need to connect it\r
2103 //\r
2104 Status = BdsLibConnectDevicePath (DevicePath);\r
2105 if (!EFI_ERROR (Status)) {\r
2106 //\r
2107 // This one should work after we did the connect\r
2108 //\r
a7a523e0 2109 Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &UpdatedDevicePath, &Handle);\r
5c08e117 2110 }\r
2111 }\r
2112\r
2113 if (!EFI_ERROR (Status)) {\r
2114 Status = gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);\r
ff482c56 2115 if (EFI_ERROR (Status)) {\r
2116 //\r
2117 // Failed to open SNP from this handle, try to get SNP from parent handle\r
2118 //\r
2119 UpdatedDevicePath = DevicePathFromHandle (Handle);\r
2120 if (UpdatedDevicePath != NULL) {\r
2121 Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);\r
2122 if (!EFI_ERROR (Status)) {\r
2123 //\r
2124 // SNP handle found, get SNP from it\r
2125 //\r
2126 Status = gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtocolGuid, (VOID **) &Snp);\r
2127 }\r
2128 }\r
2129 }\r
2130\r
5c08e117 2131 if (!EFI_ERROR (Status)) {\r
2132 if (Snp->Mode->MediaPresentSupported) {\r
2133 if (Snp->Mode->State == EfiSimpleNetworkInitialized) {\r
e51e619e 2134 //\r
2135 // Invoke Snp->GetStatus() to refresh the media status\r
2136 //\r
2137 Snp->GetStatus (Snp, &InterruptStatus, NULL);\r
2138\r
5c08e117 2139 //\r
2140 // In case some one else is using the SNP check to see if it's connected\r
2141 //\r
2142 MediaPresent = Snp->Mode->MediaPresent;\r
2143 } else {\r
2144 //\r
2145 // No one is using SNP so we need to Start and Initialize so\r
2146 // MediaPresent will be valid.\r
2147 //\r
2148 Status = Snp->Start (Snp);\r
2149 if (!EFI_ERROR (Status)) {\r
2150 Status = Snp->Initialize (Snp, 0, 0);\r
2151 if (!EFI_ERROR (Status)) {\r
2152 MediaPresent = Snp->Mode->MediaPresent;\r
2153 Snp->Shutdown (Snp);\r
2154 }\r
2155 Snp->Stop (Snp);\r
2156 }\r
2157 }\r
2158 } else {\r
2159 MediaPresent = TRUE;\r
2160 }\r
2161 }\r
2162 }\r
2163\r
2164 return MediaPresent;\r
2165}\r
2166\r
2167/**\r
2168 For a bootable Device path, return its boot type.\r
2169\r
2170 @param DevicePath The bootable device Path to check\r
2171\r
128efbbc 2172 @retval BDS_EFI_MEDIA_HD_BOOT If given device path contains MEDIA_DEVICE_PATH type device path node\r
11c5022d 2173 which subtype is MEDIA_HARDDRIVE_DP\r
2174 @retval BDS_EFI_MEDIA_CDROM_BOOT If given device path contains MEDIA_DEVICE_PATH type device path node\r
2175 which subtype is MEDIA_CDROM_DP\r
2176 @retval BDS_EFI_ACPI_FLOPPY_BOOT If given device path contains ACPI_DEVICE_PATH type device path node\r
2177 which HID is floppy device.\r
2178 @retval BDS_EFI_MESSAGE_ATAPI_BOOT If given device path contains MESSAGING_DEVICE_PATH type device path node\r
2179 and its last device path node's subtype is MSG_ATAPI_DP.\r
2180 @retval BDS_EFI_MESSAGE_SCSI_BOOT If given device path contains MESSAGING_DEVICE_PATH type device path node\r
2181 and its last device path node's subtype is MSG_SCSI_DP.\r
2182 @retval BDS_EFI_MESSAGE_USB_DEVICE_BOOT If given device path contains MESSAGING_DEVICE_PATH type device path node\r
2183 and its last device path node's subtype is MSG_USB_DP.\r
5c08e117 2184 @retval BDS_EFI_MESSAGE_MISC_BOOT If the device path not contains any media device path node, and\r
11c5022d 2185 its last device path node point to a message device path node.\r
2186 @retval BDS_LEGACY_BBS_BOOT If given device path contains BBS_DEVICE_PATH type device path node.\r
128efbbc 2187 @retval BDS_EFI_UNSUPPORT An EFI Removable BlockIO device path not point to a media and message device,\r
5c08e117 2188\r
2189**/\r
2190UINT32\r
2191EFIAPI\r
2192BdsGetBootTypeFromDevicePath (\r
2193 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
2194 )\r
2195{\r
2196 ACPI_HID_DEVICE_PATH *Acpi;\r
2197 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
2198 EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;\r
ff482c56 2199 UINT32 BootType;\r
5c08e117 2200\r
2201 if (NULL == DevicePath) {\r
2202 return BDS_EFI_UNSUPPORT;\r
2203 }\r
2204\r
2205 TempDevicePath = DevicePath;\r
2206\r
2207 while (!IsDevicePathEndType (TempDevicePath)) {\r
2208 switch (DevicePathType (TempDevicePath)) {\r
2209 case BBS_DEVICE_PATH:\r
2210 return BDS_LEGACY_BBS_BOOT;\r
2211 case MEDIA_DEVICE_PATH:\r
2212 if (DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP) {\r
2213 return BDS_EFI_MEDIA_HD_BOOT;\r
2214 } else if (DevicePathSubType (TempDevicePath) == MEDIA_CDROM_DP) {\r
2215 return BDS_EFI_MEDIA_CDROM_BOOT;\r
128efbbc 2216 }\r
5c08e117 2217 break;\r
2218 case ACPI_DEVICE_PATH:\r
2219 Acpi = (ACPI_HID_DEVICE_PATH *) TempDevicePath;\r
2220 if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {\r
2221 return BDS_EFI_ACPI_FLOPPY_BOOT;\r
2222 }\r
2223 break;\r
2224 case MESSAGING_DEVICE_PATH:\r
2225 //\r
2226 // Get the last device path node\r
2227 //\r
2228 LastDeviceNode = NextDevicePathNode (TempDevicePath);\r
2229 if (DevicePathSubType(LastDeviceNode) == MSG_DEVICE_LOGICAL_UNIT_DP) {\r
2230 //\r
2231 // if the next node type is Device Logical Unit, which specify the Logical Unit Number (LUN),\r
ff482c56 2232 // skip it\r
5c08e117 2233 //\r
2234 LastDeviceNode = NextDevicePathNode (LastDeviceNode);\r
2235 }\r
2236 //\r
2237 // if the device path not only point to driver device, it is not a messaging device path,\r
2238 //\r
2239 if (!IsDevicePathEndType (LastDeviceNode)) {\r
128efbbc 2240 break;\r
5c08e117 2241 }\r
2242\r
ff482c56 2243 switch (DevicePathSubType (TempDevicePath)) {\r
2244 case MSG_ATAPI_DP:\r
2245 BootType = BDS_EFI_MESSAGE_ATAPI_BOOT;\r
2246 break;\r
2247\r
2248 case MSG_USB_DP:\r
2249 BootType = BDS_EFI_MESSAGE_USB_DEVICE_BOOT;\r
2250 break;\r
2251\r
2252 case MSG_SCSI_DP:\r
2253 BootType = BDS_EFI_MESSAGE_SCSI_BOOT;\r
2254 break;\r
2255\r
2256 case MSG_SATA_DP:\r
2257 BootType = BDS_EFI_MESSAGE_SATA_BOOT;\r
2258 break;\r
2259\r
2260 case MSG_MAC_ADDR_DP:\r
2261 case MSG_VLAN_DP:\r
a7a523e0 2262 case MSG_IPv4_DP:\r
2263 case MSG_IPv6_DP:\r
ff482c56 2264 BootType = BDS_EFI_MESSAGE_MAC_BOOT;\r
2265 break;\r
2266\r
2267 default:\r
2268 BootType = BDS_EFI_MESSAGE_MISC_BOOT;\r
2269 break;\r
5c08e117 2270 }\r
ff482c56 2271 return BootType;\r
2272\r
5c08e117 2273 default:\r
2274 break;\r
2275 }\r
2276 TempDevicePath = NextDevicePathNode (TempDevicePath);\r
2277 }\r
2278\r
2279 return BDS_EFI_UNSUPPORT;\r
2280}\r
2281\r
2282/**\r
2283 Check whether the Device path in a boot option point to a valid bootable device,\r
2284 And if CheckMedia is true, check the device is ready to boot now.\r
2285\r
2286 @param DevPath the Device path in a boot option\r
2287 @param CheckMedia if true, check the device is ready to boot now.\r
2288\r
2289 @retval TRUE the Device path is valid\r
2290 @retval FALSE the Device path is invalid .\r
2291\r
2292**/\r
2293BOOLEAN\r
2294EFIAPI\r
2295BdsLibIsValidEFIBootOptDevicePath (\r
2296 IN EFI_DEVICE_PATH_PROTOCOL *DevPath,\r
2297 IN BOOLEAN CheckMedia\r
2298 )\r
3384a9bc 2299{\r
2300 return BdsLibIsValidEFIBootOptDevicePathExt (DevPath, CheckMedia, NULL);\r
2301}\r
2302\r
2303/**\r
2304 Check whether the Device path in a boot option point to a valid bootable device,\r
2305 And if CheckMedia is true, check the device is ready to boot now.\r
2306 If Description is not NULL and the device path point to a fixed BlockIo\r
2307 device, check the description whether conflict with other auto-created\r
2308 boot options.\r
2309\r
2310 @param DevPath the Device path in a boot option\r
2311 @param CheckMedia if true, check the device is ready to boot now.\r
2312 @param Description the description in a boot option\r
2313\r
2314 @retval TRUE the Device path is valid\r
2315 @retval FALSE the Device path is invalid .\r
2316\r
2317**/\r
2318BOOLEAN\r
2319EFIAPI\r
2320BdsLibIsValidEFIBootOptDevicePathExt (\r
2321 IN EFI_DEVICE_PATH_PROTOCOL *DevPath,\r
2322 IN BOOLEAN CheckMedia,\r
2323 IN CHAR16 *Description\r
2324 )\r
5c08e117 2325{\r
2326 EFI_STATUS Status;\r
2327 EFI_HANDLE Handle;\r
2328 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
2329 EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;\r
2330 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
2331\r
2332 TempDevicePath = DevPath;\r
2333 LastDeviceNode = DevPath;\r
128efbbc 2334\r
5c08e117 2335 //\r
a7a523e0 2336 // Check if it's a valid boot option for network boot device.\r
2337 // Check if there is EfiLoadFileProtocol installed. \r
2338 // If yes, that means there is a boot option for network.\r
5c08e117 2339 //\r
2340 Status = gBS->LocateDevicePath (\r
a7a523e0 2341 &gEfiLoadFileProtocolGuid,\r
5c08e117 2342 &TempDevicePath,\r
2343 &Handle\r
2344 );\r
2345 if (EFI_ERROR (Status)) {\r
2346 //\r
2347 // Device not present so see if we need to connect it\r
2348 //\r
2349 TempDevicePath = DevPath;\r
2350 BdsLibConnectDevicePath (TempDevicePath);\r
2351 Status = gBS->LocateDevicePath (\r
a7a523e0 2352 &gEfiLoadFileProtocolGuid,\r
5c08e117 2353 &TempDevicePath,\r
2354 &Handle\r
2355 );\r
2356 }\r
128efbbc 2357\r
5c08e117 2358 if (!EFI_ERROR (Status)) {\r
a7a523e0 2359 if (!IsDevicePathEnd (TempDevicePath)) {\r
2360 //\r
2361 // LoadFile protocol is not installed on handle with exactly the same DevPath\r
2362 //\r
2363 return FALSE;\r
2364 }\r
ff482c56 2365\r
a7a523e0 2366 if (CheckMedia) {\r
2367 //\r
2368 // Test if it is ready to boot now\r
2369 //\r
2370 if (BdsLibNetworkBootWithMediaPresent(DevPath)) {\r
5c08e117 2371 return TRUE;\r
2372 }\r
a7a523e0 2373 } else {\r
2374 return TRUE;\r
2375 } \r
5c08e117 2376 }\r
2377\r
2378 //\r
2379 // If the boot option point to a file, it is a valid EFI boot option,\r
2380 // and assume it is ready to boot now\r
2381 //\r
2382 while (!IsDevicePathEnd (TempDevicePath)) {\r
7389fdd0 2383 //\r
2384 // If there is USB Class or USB WWID device path node, treat it as valid EFI\r
2385 // Boot Option. BdsExpandUsbShortFormDevicePath () will be used to expand it\r
2386 // to full device path.\r
2387 //\r
2388 if ((DevicePathType (TempDevicePath) == MESSAGING_DEVICE_PATH) &&\r
2389 ((DevicePathSubType (TempDevicePath) == MSG_USB_CLASS_DP) ||\r
2390 (DevicePathSubType (TempDevicePath) == MSG_USB_WWID_DP))) {\r
2391 return TRUE;\r
2392 }\r
2393\r
2394 LastDeviceNode = TempDevicePath;\r
2395 TempDevicePath = NextDevicePathNode (TempDevicePath);\r
5c08e117 2396 }\r
2397 if ((DevicePathType (LastDeviceNode) == MEDIA_DEVICE_PATH) &&\r
2398 (DevicePathSubType (LastDeviceNode) == MEDIA_FILEPATH_DP)) {\r
2399 return TRUE;\r
2400 }\r
2401\r
2402 //\r
6617d838 2403 // Check if it's a valid boot option for internal FV application\r
5c08e117 2404 //\r
2405 if (EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode) != NULL) {\r
2406 //\r
6617d838 2407 // If the boot option point to internal FV application, make sure it is valid\r
5c08e117 2408 //\r
128efbbc 2409 TempDevicePath = DevPath;\r
6617d838
RN
2410 Status = BdsLibUpdateFvFileDevicePath (\r
2411 &TempDevicePath,\r
2412 EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode)\r
2413 );\r
5c08e117 2414 if (Status == EFI_ALREADY_STARTED) {\r
2415 return TRUE;\r
2416 } else {\r
2417 if (Status == EFI_SUCCESS) {\r
128efbbc 2418 FreePool (TempDevicePath);\r
5c08e117 2419 }\r
2420 return FALSE;\r
2421 }\r
2422 }\r
128efbbc 2423\r
5c08e117 2424 //\r
3384a9bc 2425 // If the boot option point to a blockIO device:\r
8d3b5aff 2426 // if it is a removable blockIo device, it is valid.\r
128efbbc 2427 // if it is a fixed blockIo device, check its description confliction.\r
5c08e117 2428 //\r
2429 TempDevicePath = DevPath;\r
2430 Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);\r
2431 if (EFI_ERROR (Status)) {\r
2432 //\r
2433 // Device not present so see if we need to connect it\r
2434 //\r
2435 Status = BdsLibConnectDevicePath (DevPath);\r
2436 if (!EFI_ERROR (Status)) {\r
2437 //\r
2438 // Try again to get the Block Io protocol after we did the connect\r
2439 //\r
2440 TempDevicePath = DevPath;\r
2441 Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);\r
2442 }\r
2443 }\r
128efbbc 2444\r
5c08e117 2445 if (!EFI_ERROR (Status)) {\r
2446 Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);\r
2447 if (!EFI_ERROR (Status)) {\r
2448 if (CheckMedia) {\r
2449 //\r
2450 // Test if it is ready to boot now\r
2451 //\r
2452 if (BdsLibGetBootableHandle (DevPath) != NULL) {\r
2453 return TRUE;\r
2454 }\r
2455 } else {\r
2456 return TRUE;\r
2457 }\r
2458 }\r
2459 } else {\r
2460 //\r
2461 // if the boot option point to a simple file protocol which does not consume block Io protocol, it is also a valid EFI boot option,\r
2462 //\r
2463 Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &TempDevicePath, &Handle);\r
2464 if (!EFI_ERROR (Status)) {\r
2465 if (CheckMedia) {\r
2466 //\r
2467 // Test if it is ready to boot now\r
2468 //\r
2469 if (BdsLibGetBootableHandle (DevPath) != NULL) {\r
2470 return TRUE;\r
2471 }\r
2472 } else {\r
2473 return TRUE;\r
2474 }\r
2475 }\r
2476 }\r
2477\r
2478 return FALSE;\r
2479}\r
2480\r
2481\r
2482/**\r
2483 According to a file guild, check a Fv file device path is valid. If it is invalid,\r
2484 try to return the valid device path.\r
2485 FV address maybe changes for memory layout adjust from time to time, use this function\r
2486 could promise the Fv file device path is right.\r
2487\r
2488 @param DevicePath on input, the Fv file device path need to check on\r
2489 output, the updated valid Fv file device path\r
2490 @param FileGuid the Fv file guild\r
2491\r
2492 @retval EFI_INVALID_PARAMETER the input DevicePath or FileGuid is invalid\r
2493 parameter\r
2494 @retval EFI_UNSUPPORTED the input DevicePath does not contain Fv file\r
2495 guild at all\r
2496 @retval EFI_ALREADY_STARTED the input DevicePath has pointed to Fv file, it is\r
2497 valid\r
2498 @retval EFI_SUCCESS has successfully updated the invalid DevicePath,\r
2499 and return the updated device path in DevicePath\r
2500\r
2501**/\r
2502EFI_STATUS\r
2503EFIAPI\r
2504BdsLibUpdateFvFileDevicePath (\r
2505 IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,\r
2506 IN EFI_GUID *FileGuid\r
2507 )\r
2508{\r
2509 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
2510 EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;\r
2511 EFI_STATUS Status;\r
2512 EFI_GUID *GuidPoint;\r
2513 UINTN Index;\r
2514 UINTN FvHandleCount;\r
2515 EFI_HANDLE *FvHandleBuffer;\r
2516 EFI_FV_FILETYPE Type;\r
2517 UINTN Size;\r
2518 EFI_FV_FILE_ATTRIBUTES Attributes;\r
2519 UINT32 AuthenticationStatus;\r
2520 BOOLEAN FindFvFile;\r
2521 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
2522 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
2523 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FvFileNode;\r
2524 EFI_HANDLE FoundFvHandle;\r
2525 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
2526\r
2527 if ((DevicePath == NULL) || (*DevicePath == NULL)) {\r
2528 return EFI_INVALID_PARAMETER;\r
2529 }\r
2530 if (FileGuid == NULL) {\r
2531 return EFI_INVALID_PARAMETER;\r
2532 }\r
128efbbc 2533\r
5c08e117 2534 //\r
2535 // Check whether the device path point to the default the input Fv file\r
2536 //\r
2537 TempDevicePath = *DevicePath;\r
2538 LastDeviceNode = TempDevicePath;\r
2539 while (!IsDevicePathEnd (TempDevicePath)) {\r
2540 LastDeviceNode = TempDevicePath;\r
2541 TempDevicePath = NextDevicePathNode (TempDevicePath);\r
2542 }\r
2543 GuidPoint = EfiGetNameGuidFromFwVolDevicePathNode (\r
2544 (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode\r
2545 );\r
2546 if (GuidPoint == NULL) {\r
2547 //\r
2548 // if this option does not points to a Fv file, just return EFI_UNSUPPORTED\r
2549 //\r
2550 return EFI_UNSUPPORTED;\r
2551 }\r
2552 if (!CompareGuid (GuidPoint, FileGuid)) {\r
2553 //\r
2554 // If the Fv file is not the input file guid, just return EFI_UNSUPPORTED\r
2555 //\r
2556 return EFI_UNSUPPORTED;\r
2557 }\r
2558\r
2559 //\r
2560 // Check whether the input Fv file device path is valid\r
2561 //\r
2562 TempDevicePath = *DevicePath;\r
2563 FoundFvHandle = NULL;\r
2564 Status = gBS->LocateDevicePath (\r
2565 &gEfiFirmwareVolume2ProtocolGuid,\r
2566 &TempDevicePath,\r
2567 &FoundFvHandle\r
2568 );\r
2569 if (!EFI_ERROR (Status)) {\r
2570 Status = gBS->HandleProtocol (\r
2571 FoundFvHandle,\r
2572 &gEfiFirmwareVolume2ProtocolGuid,\r
2573 (VOID **) &Fv\r
2574 );\r
2575 if (!EFI_ERROR (Status)) {\r
2576 //\r
2577 // Set FV ReadFile Buffer as NULL, only need to check whether input Fv file exist there\r
2578 //\r
2579 Status = Fv->ReadFile (\r
2580 Fv,\r
2581 FileGuid,\r
2582 NULL,\r
2583 &Size,\r
2584 &Type,\r
2585 &Attributes,\r
2586 &AuthenticationStatus\r
2587 );\r
2588 if (!EFI_ERROR (Status)) {\r
2589 return EFI_ALREADY_STARTED;\r
2590 }\r
2591 }\r
2592 }\r
2593\r
2594 //\r
2595 // Look for the input wanted FV file in current FV\r
2596 // First, try to look for in Bds own FV. Bds and input wanted FV file usually are in the same FV\r
2597 //\r
2598 FindFvFile = FALSE;\r
2599 FoundFvHandle = NULL;\r
2600 Status = gBS->HandleProtocol (\r
fefefa4c 2601 gImageHandle,\r
5c08e117 2602 &gEfiLoadedImageProtocolGuid,\r
2603 (VOID **) &LoadedImage\r
2604 );\r
2605 if (!EFI_ERROR (Status)) {\r
2606 Status = gBS->HandleProtocol (\r
2607 LoadedImage->DeviceHandle,\r
2608 &gEfiFirmwareVolume2ProtocolGuid,\r
2609 (VOID **) &Fv\r
2610 );\r
2611 if (!EFI_ERROR (Status)) {\r
2612 Status = Fv->ReadFile (\r
2613 Fv,\r
2614 FileGuid,\r
2615 NULL,\r
2616 &Size,\r
2617 &Type,\r
2618 &Attributes,\r
2619 &AuthenticationStatus\r
2620 );\r
2621 if (!EFI_ERROR (Status)) {\r
2622 FindFvFile = TRUE;\r
2623 FoundFvHandle = LoadedImage->DeviceHandle;\r
2624 }\r
2625 }\r
2626 }\r
2627 //\r
2628 // Second, if fail to find, try to enumerate all FV\r
2629 //\r
2630 if (!FindFvFile) {\r
2631 FvHandleBuffer = NULL;\r
2632 gBS->LocateHandleBuffer (\r
2633 ByProtocol,\r
2634 &gEfiFirmwareVolume2ProtocolGuid,\r
2635 NULL,\r
2636 &FvHandleCount,\r
2637 &FvHandleBuffer\r
2638 );\r
2639 for (Index = 0; Index < FvHandleCount; Index++) {\r
2640 gBS->HandleProtocol (\r
2641 FvHandleBuffer[Index],\r
2642 &gEfiFirmwareVolume2ProtocolGuid,\r
2643 (VOID **) &Fv\r
2644 );\r
2645\r
2646 Status = Fv->ReadFile (\r
2647 Fv,\r
2648 FileGuid,\r
2649 NULL,\r
2650 &Size,\r
2651 &Type,\r
2652 &Attributes,\r
2653 &AuthenticationStatus\r
2654 );\r
2655 if (EFI_ERROR (Status)) {\r
2656 //\r
2657 // Skip if input Fv file not in the FV\r
2658 //\r
2659 continue;\r
2660 }\r
2661 FindFvFile = TRUE;\r
2662 FoundFvHandle = FvHandleBuffer[Index];\r
2663 break;\r
2664 }\r
2665\r
2666 if (FvHandleBuffer != NULL) {\r
128efbbc 2667 FreePool (FvHandleBuffer);\r
5c08e117 2668 }\r
2669 }\r
2670\r
2671 if (FindFvFile) {\r
2672 //\r
2673 // Build the shell device path\r
2674 //\r
2675 NewDevicePath = DevicePathFromHandle (FoundFvHandle);\r
2676 EfiInitializeFwVolDevicepathNode (&FvFileNode, FileGuid);\r
2677 NewDevicePath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &FvFileNode);\r
2678 *DevicePath = NewDevicePath;\r
2679 return EFI_SUCCESS;\r
2680 }\r
2681 return EFI_NOT_FOUND;\r
2682}\r