]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
Early return when the "BootOrder" variable doesn't exist to avoid SetVariable() retur...
[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
69fc8f08 4Copyright (c) 2004 - 2014, 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
09363eca 43 ImageHandle,\r
9aa7ba01 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
16e5944a
RN
53/**\r
54 Deletete the Boot Option from EFI Variable. The Boot Order Arrray\r
55 is also updated.\r
56\r
57 @param OptionNumber The number of Boot option want to be deleted.\r
58 @param BootOrder The Boot Order array.\r
59 @param BootOrderSize The size of the Boot Order Array.\r
60\r
61 @retval EFI_SUCCESS The Boot Option Variable was found and removed\r
62 @retval EFI_UNSUPPORTED The Boot Option Variable store was inaccessible\r
63 @retval EFI_NOT_FOUND The Boot Option Variable was not found\r
64**/\r
65EFI_STATUS\r
66EFIAPI\r
67BdsDeleteBootOption (\r
68 IN UINTN OptionNumber,\r
69 IN OUT UINT16 *BootOrder,\r
70 IN OUT UINTN *BootOrderSize\r
71 )\r
72{\r
73 CHAR16 BootOption[9];\r
74 UINTN Index;\r
75 EFI_STATUS Status;\r
76\r
77 UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", OptionNumber);\r
78 Status = gRT->SetVariable (\r
79 BootOption,\r
80 &gEfiGlobalVariableGuid,\r
81 0,\r
82 0,\r
83 NULL\r
84 );\r
69fc8f08
RN
85 //\r
86 // Deleting variable with existing variable implementation shouldn't fail.\r
87 //\r
88 ASSERT_EFI_ERROR (Status);\r
16e5944a
RN
89\r
90 //\r
91 // adjust boot order array\r
92 //\r
93 for (Index = 0; Index < *BootOrderSize / sizeof (UINT16); Index++) {\r
94 if (BootOrder[Index] == OptionNumber) {\r
95 CopyMem (&BootOrder[Index], &BootOrder[Index+1], *BootOrderSize - (Index+1) * sizeof (UINT16));\r
96 *BootOrderSize -= sizeof (UINT16);\r
97 break;\r
98 }\r
99 }\r
100\r
101 return Status;\r
102}\r
103/**\r
104\r
105 Translate the first n characters of an Ascii string to\r
106 Unicode characters. The count n is indicated by parameter\r
107 Size. If Size is greater than the length of string, then\r
108 the entire string is translated.\r
109\r
110\r
111 @param AStr Pointer to input Ascii string.\r
112 @param Size The number of characters to translate.\r
113 @param UStr Pointer to output Unicode string buffer.\r
114\r
115**/\r
116VOID\r
117AsciiToUnicodeSize (\r
118 IN UINT8 *AStr,\r
119 IN UINTN Size,\r
120 OUT UINT16 *UStr\r
121 )\r
122{\r
123 UINTN Idx;\r
124\r
125 Idx = 0;\r
126 while (AStr[Idx] != 0) {\r
127 UStr[Idx] = (CHAR16) AStr[Idx];\r
128 if (Idx == Size) {\r
129 break;\r
130 }\r
131\r
132 Idx++;\r
133 }\r
134 UStr[Idx] = 0;\r
135}\r
136\r
137/**\r
138 Build Legacy Device Name String according.\r
139\r
140 @param CurBBSEntry BBS Table.\r
141 @param Index Index.\r
142 @param BufSize The buffer size.\r
143 @param BootString The output string.\r
144\r
145**/\r
146VOID\r
147BdsBuildLegacyDevNameString (\r
148 IN BBS_TABLE *CurBBSEntry,\r
149 IN UINTN Index,\r
150 IN UINTN BufSize,\r
151 OUT CHAR16 *BootString\r
152 )\r
153{\r
154 CHAR16 *Fmt;\r
155 CHAR16 *Type;\r
156 UINT8 *StringDesc;\r
157 CHAR16 Temp[80];\r
158\r
159 switch (Index) {\r
160 //\r
161 // Primary Master\r
162 //\r
163 case 1:\r
164 Fmt = L"Primary Master %s";\r
165 break;\r
166\r
167 //\r
168 // Primary Slave\r
169 //\r
170 case 2:\r
171 Fmt = L"Primary Slave %s";\r
172 break;\r
173\r
174 //\r
175 // Secondary Master\r
176 //\r
177 case 3:\r
178 Fmt = L"Secondary Master %s";\r
179 break;\r
180\r
181 //\r
182 // Secondary Slave\r
183 //\r
184 case 4:\r
185 Fmt = L"Secondary Slave %s";\r
186 break;\r
187\r
188 default:\r
189 Fmt = L"%s";\r
190 break;\r
191 }\r
192\r
193 switch (CurBBSEntry->DeviceType) {\r
194 case BBS_FLOPPY:\r
195 Type = L"Floppy";\r
196 break;\r
197\r
198 case BBS_HARDDISK:\r
199 Type = L"Harddisk";\r
200 break;\r
201\r
202 case BBS_CDROM:\r
203 Type = L"CDROM";\r
204 break;\r
205\r
206 case BBS_PCMCIA:\r
207 Type = L"PCMCIAe";\r
208 break;\r
209\r
210 case BBS_USB:\r
211 Type = L"USB";\r
212 break;\r
213\r
214 case BBS_EMBED_NETWORK:\r
215 Type = L"Network";\r
216 break;\r
217\r
218 case BBS_BEV_DEVICE:\r
219 Type = L"BEVe";\r
220 break;\r
221\r
222 case BBS_UNKNOWN:\r
223 default:\r
224 Type = L"Unknown";\r
225 break;\r
226 }\r
227 //\r
228 // If current BBS entry has its description then use it.\r
229 //\r
230 StringDesc = (UINT8 *) (UINTN) ((CurBBSEntry->DescStringSegment << 4) + CurBBSEntry->DescStringOffset);\r
231 if (NULL != StringDesc) {\r
232 //\r
233 // Only get fisrt 32 characters, this is suggested by BBS spec\r
234 //\r
235 AsciiToUnicodeSize (StringDesc, 32, Temp);\r
236 Fmt = L"%s";\r
237 Type = Temp;\r
238 }\r
239\r
240 //\r
241 // BbsTable 16 entries are for onboard IDE.\r
242 // Set description string for SATA harddisks, Harddisk 0 ~ Harddisk 11\r
243 //\r
244 if (Index >= 5 && Index <= 16 && (CurBBSEntry->DeviceType == BBS_HARDDISK || CurBBSEntry->DeviceType == BBS_CDROM)) {\r
245 Fmt = L"%s %d";\r
246 UnicodeSPrint (BootString, BufSize, Fmt, Type, Index - 5);\r
247 } else {\r
248 UnicodeSPrint (BootString, BufSize, Fmt, Type);\r
249 }\r
250}\r
251\r
252/**\r
253\r
254 Create a legacy boot option for the specified entry of\r
255 BBS table, save it as variable, and append it to the boot\r
256 order list.\r
257\r
258\r
259 @param CurrentBbsEntry Pointer to current BBS table.\r
260 @param CurrentBbsDevPath Pointer to the Device Path Protocol instance of BBS\r
261 @param Index Index of the specified entry in BBS table.\r
262 @param BootOrderList On input, the original boot order list.\r
263 On output, the new boot order list attached with the\r
264 created node.\r
265 @param BootOrderListSize On input, the original size of boot order list.\r
266 On output, the size of new boot order list.\r
267\r
268 @retval EFI_SUCCESS Boot Option successfully created.\r
269 @retval EFI_OUT_OF_RESOURCES Fail to allocate necessary memory.\r
270 @retval Other Error occurs while setting variable.\r
271\r
272**/\r
273EFI_STATUS\r
274BdsCreateLegacyBootOption (\r
275 IN BBS_TABLE *CurrentBbsEntry,\r
276 IN EFI_DEVICE_PATH_PROTOCOL *CurrentBbsDevPath,\r
277 IN UINTN Index,\r
278 IN OUT UINT16 **BootOrderList,\r
279 IN OUT UINTN *BootOrderListSize\r
280 )\r
281{\r
282 EFI_STATUS Status;\r
283 UINT16 CurrentBootOptionNo;\r
284 UINT16 BootString[10];\r
285 CHAR16 BootDesc[100];\r
286 CHAR8 HelpString[100];\r
287 UINT16 *NewBootOrderList;\r
288 UINTN BufferSize;\r
289 UINTN StringLen;\r
290 VOID *Buffer;\r
291 UINT8 *Ptr;\r
292 UINT16 CurrentBbsDevPathSize;\r
293 UINTN BootOrderIndex;\r
294 UINTN BootOrderLastIndex;\r
295 UINTN ArrayIndex;\r
296 BOOLEAN IndexNotFound;\r
297 BBS_BBS_DEVICE_PATH *NewBbsDevPathNode;\r
298\r
299 if ((*BootOrderList) == NULL) {\r
300 CurrentBootOptionNo = 0;\r
301 } else {\r
302 for (ArrayIndex = 0; ArrayIndex < (UINTN) (*BootOrderListSize / sizeof (UINT16)); ArrayIndex++) {\r
303 IndexNotFound = TRUE;\r
304 for (BootOrderIndex = 0; BootOrderIndex < (UINTN) (*BootOrderListSize / sizeof (UINT16)); BootOrderIndex++) {\r
305 if ((*BootOrderList)[BootOrderIndex] == ArrayIndex) {\r
306 IndexNotFound = FALSE;\r
307 break;\r
308 }\r
309 }\r
310\r
311 if (!IndexNotFound) {\r
312 continue;\r
313 } else {\r
314 break;\r
315 }\r
316 }\r
317\r
318 CurrentBootOptionNo = (UINT16) ArrayIndex;\r
319 }\r
320\r
321 UnicodeSPrint (\r
322 BootString,\r
323 sizeof (BootString),\r
324 L"Boot%04x",\r
325 CurrentBootOptionNo\r
326 );\r
327\r
328 BdsBuildLegacyDevNameString (CurrentBbsEntry, Index, sizeof (BootDesc), BootDesc);\r
329\r
330 //\r
331 // Create new BBS device path node with description string\r
332 //\r
333 UnicodeStrToAsciiStr (BootDesc, HelpString);\r
334\r
335 StringLen = AsciiStrLen (HelpString);\r
336 NewBbsDevPathNode = AllocateZeroPool (sizeof (BBS_BBS_DEVICE_PATH) + StringLen);\r
337 if (NewBbsDevPathNode == NULL) {\r
338 return EFI_OUT_OF_RESOURCES;\r
339 }\r
340 CopyMem (NewBbsDevPathNode, CurrentBbsDevPath, sizeof (BBS_BBS_DEVICE_PATH));\r
341 CopyMem (NewBbsDevPathNode->String, HelpString, StringLen + 1);\r
342 SetDevicePathNodeLength (&(NewBbsDevPathNode->Header), sizeof (BBS_BBS_DEVICE_PATH) + StringLen);\r
343\r
344 //\r
345 // Create entire new CurrentBbsDevPath with end node\r
346 //\r
347 CurrentBbsDevPath = AppendDevicePathNode (\r
348 NULL,\r
349 (EFI_DEVICE_PATH_PROTOCOL *) NewBbsDevPathNode\r
350 );\r
351 if (CurrentBbsDevPath == NULL) {\r
352 FreePool (NewBbsDevPathNode);\r
353 return EFI_OUT_OF_RESOURCES;\r
354 }\r
355\r
356 CurrentBbsDevPathSize = (UINT16) (GetDevicePathSize (CurrentBbsDevPath));\r
357\r
358 BufferSize = sizeof (UINT32) +\r
359 sizeof (UINT16) +\r
360 StrSize (BootDesc) +\r
361 CurrentBbsDevPathSize +\r
362 sizeof (BBS_TABLE) +\r
363 sizeof (UINT16);\r
364\r
365 Buffer = AllocateZeroPool (BufferSize);\r
366 if (Buffer == NULL) {\r
367 FreePool (NewBbsDevPathNode);\r
368 FreePool (CurrentBbsDevPath);\r
369 return EFI_OUT_OF_RESOURCES;\r
370 }\r
371\r
372 Ptr = (UINT8 *) Buffer;\r
373\r
374 *((UINT32 *) Ptr) = LOAD_OPTION_ACTIVE;\r
375 Ptr += sizeof (UINT32);\r
376\r
377 *((UINT16 *) Ptr) = CurrentBbsDevPathSize;\r
378 Ptr += sizeof (UINT16);\r
379\r
380 CopyMem (\r
381 Ptr,\r
382 BootDesc,\r
383 StrSize (BootDesc)\r
384 );\r
385 Ptr += StrSize (BootDesc);\r
386\r
387 CopyMem (\r
388 Ptr,\r
389 CurrentBbsDevPath,\r
390 CurrentBbsDevPathSize\r
391 );\r
392 Ptr += CurrentBbsDevPathSize;\r
393\r
394 CopyMem (\r
395 Ptr,\r
396 CurrentBbsEntry,\r
397 sizeof (BBS_TABLE)\r
398 );\r
399\r
400 Ptr += sizeof (BBS_TABLE);\r
401 *((UINT16 *) Ptr) = (UINT16) Index;\r
402\r
403 Status = gRT->SetVariable (\r
404 BootString,\r
405 &gEfiGlobalVariableGuid,\r
406 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
407 BufferSize,\r
408 Buffer\r
409 );\r
5c08e117 410\r
16e5944a
RN
411 FreePool (Buffer);\r
412 \r
413 Buffer = NULL;\r
414\r
415 NewBootOrderList = AllocateZeroPool (*BootOrderListSize + sizeof (UINT16));\r
416 if (NULL == NewBootOrderList) {\r
417 FreePool (NewBbsDevPathNode);\r
418 FreePool (CurrentBbsDevPath);\r
419 return EFI_OUT_OF_RESOURCES;\r
420 }\r
421\r
422 if (*BootOrderList != NULL) {\r
423 CopyMem (NewBootOrderList, *BootOrderList, *BootOrderListSize);\r
424 FreePool (*BootOrderList);\r
425 }\r
426\r
427 BootOrderLastIndex = (UINTN) (*BootOrderListSize / sizeof (UINT16));\r
428 NewBootOrderList[BootOrderLastIndex] = CurrentBootOptionNo;\r
429 *BootOrderListSize += sizeof (UINT16);\r
430 *BootOrderList = NewBootOrderList;\r
431\r
432 FreePool (NewBbsDevPathNode);\r
433 FreePool (CurrentBbsDevPath);\r
434 return Status;\r
435}\r
436\r
437/**\r
438 Check if the boot option is a legacy one.\r
439\r
440 @param BootOptionVar The boot option data payload.\r
441 @param BbsEntry The BBS Table.\r
442 @param BbsIndex The table index.\r
443\r
444 @retval TRUE It is a legacy boot option.\r
445 @retval FALSE It is not a legacy boot option.\r
446\r
447**/\r
448BOOLEAN\r
449BdsIsLegacyBootOption (\r
450 IN UINT8 *BootOptionVar,\r
451 OUT BBS_TABLE **BbsEntry,\r
452 OUT UINT16 *BbsIndex\r
453 )\r
454{\r
455 UINT8 *Ptr;\r
456 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
457 BOOLEAN Ret;\r
458 UINT16 DevPathLen;\r
459\r
460 Ptr = BootOptionVar;\r
461 Ptr += sizeof (UINT32);\r
462 DevPathLen = *(UINT16 *) Ptr;\r
463 Ptr += sizeof (UINT16);\r
464 Ptr += StrSize ((UINT16 *) Ptr);\r
465 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;\r
466 if ((BBS_DEVICE_PATH == DevicePath->Type) && (BBS_BBS_DP == DevicePath->SubType)) {\r
467 Ptr += DevPathLen;\r
468 *BbsEntry = (BBS_TABLE *) Ptr;\r
469 Ptr += sizeof (BBS_TABLE);\r
470 *BbsIndex = *(UINT16 *) Ptr;\r
471 Ret = TRUE;\r
472 } else {\r
473 *BbsEntry = NULL;\r
474 Ret = FALSE;\r
475 }\r
476\r
477 return Ret;\r
478}\r
479\r
480/**\r
481 Delete all the invalid legacy boot options.\r
482\r
483 @retval EFI_SUCCESS All invalide legacy boot options are deleted.\r
484 @retval EFI_OUT_OF_RESOURCES Fail to allocate necessary memory.\r
485 @retval EFI_NOT_FOUND Fail to retrive variable of boot order.\r
486**/\r
487EFI_STATUS\r
488EFIAPI\r
489BdsDeleteAllInvalidLegacyBootOptions (\r
490 VOID\r
491 )\r
492{\r
493 UINT16 *BootOrder;\r
494 UINT8 *BootOptionVar;\r
495 UINTN BootOrderSize;\r
496 UINTN BootOptionSize;\r
497 EFI_STATUS Status;\r
498 UINT16 HddCount;\r
499 UINT16 BbsCount;\r
500 HDD_INFO *LocalHddInfo;\r
501 BBS_TABLE *LocalBbsTable;\r
502 BBS_TABLE *BbsEntry;\r
503 UINT16 BbsIndex;\r
504 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;\r
505 UINTN Index;\r
506 UINT16 BootOption[10];\r
507 UINT16 BootDesc[100];\r
508 BOOLEAN DescStringMatch;\r
509\r
510 Status = EFI_SUCCESS;\r
511 BootOrder = NULL;\r
512 BootOrderSize = 0;\r
513 HddCount = 0;\r
514 BbsCount = 0;\r
515 LocalHddInfo = NULL;\r
516 LocalBbsTable = NULL;\r
517 BbsEntry = NULL;\r
518\r
519 Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);\r
520 if (EFI_ERROR (Status)) {\r
521 return Status;\r
522 }\r
523\r
16e5944a
RN
524 BootOrder = BdsLibGetVariableAndSize (\r
525 L"BootOrder",\r
526 &gEfiGlobalVariableGuid,\r
527 &BootOrderSize\r
528 );\r
529 if (BootOrder == NULL) {\r
1187b10f 530 return EFI_NOT_FOUND;\r
16e5944a
RN
531 }\r
532\r
1187b10f
RN
533 LegacyBios->GetBbsInfo (\r
534 LegacyBios,\r
535 &HddCount,\r
536 &LocalHddInfo,\r
537 &BbsCount,\r
538 &LocalBbsTable\r
539 );\r
540\r
16e5944a
RN
541 Index = 0;\r
542 while (Index < BootOrderSize / sizeof (UINT16)) {\r
543 UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);\r
544 BootOptionVar = BdsLibGetVariableAndSize (\r
545 BootOption,\r
546 &gEfiGlobalVariableGuid,\r
547 &BootOptionSize\r
548 );\r
549 if (NULL == BootOptionVar) {\r
550 BootOptionSize = 0;\r
551 Status = gRT->GetVariable (\r
552 BootOption,\r
553 &gEfiGlobalVariableGuid,\r
554 NULL,\r
555 &BootOptionSize,\r
556 BootOptionVar\r
557 );\r
558 if (Status == EFI_NOT_FOUND) {\r
559 //\r
560 // Update BootOrder\r
561 //\r
562 BdsDeleteBootOption (\r
563 BootOrder[Index],\r
564 BootOrder,\r
565 &BootOrderSize\r
566 );\r
567 continue;\r
568 } else {\r
569 FreePool (BootOrder);\r
570 return EFI_OUT_OF_RESOURCES;\r
571 }\r
572 }\r
573 \r
574 //\r
575 // Skip Non-Legacy boot option\r
576 // \r
577 if (!BdsIsLegacyBootOption (BootOptionVar, &BbsEntry, &BbsIndex)) {\r
578 if (BootOptionVar!= NULL) {\r
579 FreePool (BootOptionVar);\r
580 }\r
581 Index++;\r
582 continue;\r
583 }\r
584\r
585 if (BbsIndex < BbsCount) {\r
586 //\r
587 // Check if BBS Description String is changed\r
588 //\r
589 DescStringMatch = FALSE;\r
590 BdsBuildLegacyDevNameString (\r
591 &LocalBbsTable[BbsIndex],\r
592 BbsIndex,\r
593 sizeof (BootDesc),\r
594 BootDesc\r
595 );\r
596\r
597 if (StrCmp (BootDesc, (UINT16*)(BootOptionVar + sizeof (UINT32) + sizeof (UINT16))) == 0) {\r
598 DescStringMatch = TRUE;\r
599 }\r
600\r
601 if (!((LocalBbsTable[BbsIndex].BootPriority == BBS_IGNORE_ENTRY) ||\r
602 (LocalBbsTable[BbsIndex].BootPriority == BBS_DO_NOT_BOOT_FROM)) &&\r
603 (LocalBbsTable[BbsIndex].DeviceType == BbsEntry->DeviceType) &&\r
604 DescStringMatch) {\r
605 Index++;\r
606 continue;\r
607 }\r
608 }\r
609\r
610 if (BootOptionVar != NULL) {\r
611 FreePool (BootOptionVar);\r
612 }\r
613 //\r
614 // should delete\r
615 //\r
616 BdsDeleteBootOption (\r
617 BootOrder[Index],\r
618 BootOrder,\r
619 &BootOrderSize\r
620 );\r
621 }\r
622\r
623 //\r
624 // Adjust the number of boot options.\r
625 //\r
626 Status = gRT->SetVariable (\r
627 L"BootOrder",\r
628 &gEfiGlobalVariableGuid,\r
629 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
630 BootOrderSize,\r
631 BootOrder\r
632 );\r
69fc8f08
RN
633 //\r
634 // Shrinking variable with existing variable implementation shouldn't fail.\r
635 //\r
636 ASSERT_EFI_ERROR (Status);\r
1187b10f 637 FreePool (BootOrder);\r
16e5944a
RN
638\r
639 return Status;\r
640}\r
641\r
642/**\r
643 Find all legacy boot option by device type.\r
644\r
645 @param BootOrder The boot order array.\r
646 @param BootOptionNum The number of boot option.\r
647 @param DevType Device type.\r
648 @param DevName Device name.\r
649 @param Attribute The boot option attribute.\r
650 @param BbsIndex The BBS table index.\r
651 @param OptionNumber The boot option index.\r
652\r
653 @retval TRUE The Legacy boot option is found.\r
654 @retval FALSE The legacy boot option is not found.\r
655\r
656**/\r
657BOOLEAN\r
658BdsFindLegacyBootOptionByDevTypeAndName (\r
659 IN UINT16 *BootOrder,\r
660 IN UINTN BootOptionNum,\r
661 IN UINT16 DevType,\r
662 IN CHAR16 *DevName,\r
663 OUT UINT32 *Attribute,\r
664 OUT UINT16 *BbsIndex,\r
665 OUT UINT16 *OptionNumber\r
666 )\r
667{\r
668 UINTN Index;\r
669 CHAR16 BootOption[9];\r
670 UINTN BootOptionSize;\r
671 UINT8 *BootOptionVar;\r
672 BBS_TABLE *BbsEntry;\r
673 BOOLEAN Found;\r
674\r
675 BbsEntry = NULL;\r
676 Found = FALSE;\r
677\r
678 if (NULL == BootOrder) {\r
679 return Found;\r
680 }\r
681\r
682 //\r
683 // Loop all boot option from variable\r
684 //\r
685 for (Index = 0; Index < BootOptionNum; Index++) {\r
686 UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", (UINTN) BootOrder[Index]);\r
687 BootOptionVar = BdsLibGetVariableAndSize (\r
688 BootOption,\r
689 &gEfiGlobalVariableGuid,\r
690 &BootOptionSize\r
691 );\r
692 if (NULL == BootOptionVar) {\r
693 continue;\r
694 }\r
695\r
696 //\r
697 // Skip Non-legacy boot option\r
698 //\r
699 if (!BdsIsLegacyBootOption (BootOptionVar, &BbsEntry, BbsIndex)) {\r
700 FreePool (BootOptionVar);\r
701 continue;\r
702 }\r
703\r
704 if (\r
705 (BbsEntry->DeviceType != DevType) ||\r
706 (StrCmp (DevName, (CHAR16*)(BootOptionVar + sizeof (UINT32) + sizeof (UINT16))) != 0)\r
707 ) {\r
708 FreePool (BootOptionVar);\r
709 continue;\r
710 }\r
711\r
712 *Attribute = *(UINT32 *) BootOptionVar;\r
713 *OptionNumber = BootOrder[Index];\r
714 Found = TRUE;\r
715 FreePool (BootOptionVar);\r
716 break;\r
717 }\r
718\r
719 return Found;\r
720}\r
721\r
722/**\r
723 Create a legacy boot option.\r
724\r
725 @param BbsItem The BBS Table entry.\r
726 @param Index Index of the specified entry in BBS table.\r
727 @param BootOrderList The boot order list.\r
728 @param BootOrderListSize The size of boot order list.\r
729\r
730 @retval EFI_OUT_OF_RESOURCE No enough memory.\r
731 @retval EFI_SUCCESS The function complete successfully.\r
732 @return Other value if the legacy boot option is not created.\r
733\r
734**/\r
735EFI_STATUS\r
736BdsCreateOneLegacyBootOption (\r
737 IN BBS_TABLE *BbsItem,\r
738 IN UINTN Index,\r
739 IN OUT UINT16 **BootOrderList,\r
740 IN OUT UINTN *BootOrderListSize\r
741 )\r
742{\r
743 BBS_BBS_DEVICE_PATH BbsDevPathNode;\r
744 EFI_STATUS Status;\r
745 EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
746\r
747 DevPath = NULL;\r
748\r
749 //\r
750 // Create device path node.\r
751 //\r
752 BbsDevPathNode.Header.Type = BBS_DEVICE_PATH;\r
753 BbsDevPathNode.Header.SubType = BBS_BBS_DP;\r
754 SetDevicePathNodeLength (&BbsDevPathNode.Header, sizeof (BBS_BBS_DEVICE_PATH));\r
755 BbsDevPathNode.DeviceType = BbsItem->DeviceType;\r
756 CopyMem (&BbsDevPathNode.StatusFlag, &BbsItem->StatusFlags, sizeof (UINT16));\r
757\r
758 DevPath = AppendDevicePathNode (\r
759 NULL,\r
760 (EFI_DEVICE_PATH_PROTOCOL *) &BbsDevPathNode\r
761 );\r
762 if (NULL == DevPath) {\r
763 return EFI_OUT_OF_RESOURCES;\r
764 }\r
765\r
766 Status = BdsCreateLegacyBootOption (\r
767 BbsItem,\r
768 DevPath,\r
769 Index,\r
770 BootOrderList,\r
771 BootOrderListSize\r
772 );\r
773 BbsItem->BootPriority = 0x00;\r
774\r
775 FreePool (DevPath);\r
776\r
777 return Status;\r
778}\r
779\r
780/**\r
781 Add the legacy boot options from BBS table if they do not exist.\r
782\r
783 @retval EFI_SUCCESS The boot options are added successfully \r
784 or they are already in boot options.\r
785 @retval EFI_NOT_FOUND No legacy boot options is found.\r
786 @retval EFI_OUT_OF_RESOURCE No enough memory.\r
787 @return Other value LegacyBoot options are not added.\r
788**/\r
789EFI_STATUS\r
790EFIAPI\r
791BdsAddNonExistingLegacyBootOptions (\r
792 VOID\r
793 )\r
794{\r
795 UINT16 *BootOrder;\r
796 UINTN BootOrderSize;\r
797 EFI_STATUS Status;\r
798 CHAR16 Desc[100];\r
799 UINT16 HddCount;\r
800 UINT16 BbsCount;\r
801 HDD_INFO *LocalHddInfo;\r
802 BBS_TABLE *LocalBbsTable;\r
803 UINT16 BbsIndex;\r
804 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;\r
805 UINT16 Index;\r
806 UINT32 Attribute;\r
807 UINT16 OptionNumber;\r
808 BOOLEAN Exist;\r
809\r
810 HddCount = 0;\r
811 BbsCount = 0;\r
812 LocalHddInfo = NULL;\r
813 LocalBbsTable = NULL;\r
814\r
815 Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);\r
816 if (EFI_ERROR (Status)) {\r
817 return Status;\r
818 }\r
819\r
820 LegacyBios->GetBbsInfo (\r
821 LegacyBios,\r
822 &HddCount,\r
823 &LocalHddInfo,\r
824 &BbsCount,\r
825 &LocalBbsTable\r
826 );\r
827\r
828 BootOrder = BdsLibGetVariableAndSize (\r
829 L"BootOrder",\r
830 &gEfiGlobalVariableGuid,\r
831 &BootOrderSize\r
832 );\r
833 if (BootOrder == NULL) {\r
834 BootOrderSize = 0;\r
835 }\r
836\r
837 for (Index = 0; Index < BbsCount; Index++) {\r
838 if ((LocalBbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) ||\r
839 (LocalBbsTable[Index].BootPriority == BBS_DO_NOT_BOOT_FROM)\r
840 ) {\r
841 continue;\r
842 }\r
843\r
844 BdsBuildLegacyDevNameString (&LocalBbsTable[Index], Index, sizeof (Desc), Desc);\r
845\r
846 Exist = BdsFindLegacyBootOptionByDevTypeAndName (\r
847 BootOrder,\r
848 BootOrderSize / sizeof (UINT16),\r
849 LocalBbsTable[Index].DeviceType,\r
850 Desc,\r
851 &Attribute,\r
852 &BbsIndex,\r
853 &OptionNumber\r
854 );\r
855 if (!Exist) {\r
856 //\r
857 // Not found such type of legacy device in boot options or we found but it's disabled\r
858 // so we have to create one and put it to the tail of boot order list\r
859 //\r
860 Status = BdsCreateOneLegacyBootOption (\r
861 &LocalBbsTable[Index],\r
862 Index,\r
863 &BootOrder,\r
864 &BootOrderSize\r
865 );\r
69fc8f08
RN
866 if (!EFI_ERROR (Status)) {\r
867 BbsIndex = Index;\r
868 OptionNumber = BootOrder[BootOrderSize / sizeof (UINT16) - 1];\r
16e5944a 869 }\r
16e5944a
RN
870 }\r
871\r
872 ASSERT (BbsIndex == Index);\r
873 }\r
874\r
875 Status = gRT->SetVariable (\r
876 L"BootOrder",\r
877 &gEfiGlobalVariableGuid,\r
878 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
879 BootOrderSize,\r
880 BootOrder\r
881 );\r
882 if (BootOrder != NULL) {\r
883 FreePool (BootOrder);\r
884 }\r
885\r
886 return Status;\r
887}\r
888\r
889/**\r
890 Fill the device order buffer.\r
891\r
892 @param BbsTable The BBS table.\r
893 @param BbsType The BBS Type.\r
894 @param BbsCount The BBS Count.\r
895 @param Buf device order buffer.\r
896\r
897 @return The device order buffer.\r
898\r
899**/\r
900UINT16 *\r
901BdsFillDevOrderBuf (\r
902 IN BBS_TABLE *BbsTable,\r
903 IN BBS_TYPE BbsType,\r
904 IN UINTN BbsCount,\r
905 OUT UINT16 *Buf\r
906 )\r
907{\r
908 UINTN Index;\r
909\r
910 for (Index = 0; Index < BbsCount; Index++) {\r
911 if (BbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) {\r
912 continue;\r
913 }\r
914\r
915 if (BbsTable[Index].DeviceType != BbsType) {\r
916 continue;\r
917 }\r
918\r
919 *Buf = (UINT16) (Index & 0xFF);\r
920 Buf++;\r
921 }\r
922\r
923 return Buf;\r
924}\r
925\r
926/**\r
927 Create the device order buffer.\r
928\r
929 @param BbsTable The BBS table.\r
930 @param BbsCount The BBS Count.\r
931\r
932 @retval EFI_SUCCES The buffer is created and the EFI variable named \r
933 VAR_LEGACY_DEV_ORDER and gEfiLegacyDevOrderVariableGuid is\r
934 set correctly.\r
935 @retval EFI_OUT_OF_RESOURCES Memmory or storage is not enough.\r
936 @retval EFI_DEVICE_ERROR Fail to add the device order into EFI variable fail\r
937 because of hardware error.\r
938**/\r
939EFI_STATUS\r
940BdsCreateDevOrder (\r
941 IN BBS_TABLE *BbsTable,\r
942 IN UINT16 BbsCount\r
943 )\r
944{\r
945 UINTN Index;\r
946 UINTN FDCount;\r
947 UINTN HDCount;\r
948 UINTN CDCount;\r
949 UINTN NETCount;\r
950 UINTN BEVCount;\r
951 UINTN TotalSize;\r
952 UINTN HeaderSize;\r
953 LEGACY_DEV_ORDER_ENTRY *DevOrder;\r
954 LEGACY_DEV_ORDER_ENTRY *DevOrderPtr;\r
955 EFI_STATUS Status;\r
956\r
957 FDCount = 0;\r
958 HDCount = 0;\r
959 CDCount = 0;\r
960 NETCount = 0;\r
961 BEVCount = 0;\r
962 TotalSize = 0;\r
963 HeaderSize = sizeof (BBS_TYPE) + sizeof (UINT16);\r
964 DevOrder = NULL;\r
965 Status = EFI_SUCCESS;\r
966\r
967 //\r
968 // Count all boot devices\r
969 //\r
970 for (Index = 0; Index < BbsCount; Index++) {\r
971 if (BbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) {\r
972 continue;\r
973 }\r
974\r
975 switch (BbsTable[Index].DeviceType) {\r
976 case BBS_FLOPPY:\r
977 FDCount++;\r
978 break;\r
979\r
980 case BBS_HARDDISK:\r
981 HDCount++;\r
982 break;\r
983\r
984 case BBS_CDROM:\r
985 CDCount++;\r
986 break;\r
987\r
988 case BBS_EMBED_NETWORK:\r
989 NETCount++;\r
990 break;\r
991\r
992 case BBS_BEV_DEVICE:\r
993 BEVCount++;\r
994 break;\r
995\r
996 default:\r
997 break;\r
998 }\r
999 }\r
1000\r
1001 TotalSize += (HeaderSize + sizeof (UINT16) * FDCount);\r
1002 TotalSize += (HeaderSize + sizeof (UINT16) * HDCount);\r
1003 TotalSize += (HeaderSize + sizeof (UINT16) * CDCount);\r
1004 TotalSize += (HeaderSize + sizeof (UINT16) * NETCount);\r
1005 TotalSize += (HeaderSize + sizeof (UINT16) * BEVCount);\r
1006\r
1007 //\r
1008 // Create buffer to hold all boot device order\r
1009 //\r
1010 DevOrder = AllocateZeroPool (TotalSize);\r
1011 if (NULL == DevOrder) {\r
1012 return EFI_OUT_OF_RESOURCES;\r
1013 }\r
1014 DevOrderPtr = DevOrder;\r
1015\r
1016 DevOrderPtr->BbsType = BBS_FLOPPY;\r
1017 DevOrderPtr->Length = (UINT16) (sizeof (DevOrderPtr->Length) + FDCount * sizeof (UINT16));\r
1018 DevOrderPtr = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_FLOPPY, BbsCount, DevOrderPtr->Data);\r
1019\r
1020 DevOrderPtr->BbsType = BBS_HARDDISK;\r
1021 DevOrderPtr->Length = (UINT16) (sizeof (UINT16) + HDCount * sizeof (UINT16));\r
1022 DevOrderPtr = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_HARDDISK, BbsCount, DevOrderPtr->Data);\r
1023 \r
1024 DevOrderPtr->BbsType = BBS_CDROM;\r
1025 DevOrderPtr->Length = (UINT16) (sizeof (UINT16) + CDCount * sizeof (UINT16));\r
1026 DevOrderPtr = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_CDROM, BbsCount, DevOrderPtr->Data);\r
1027 \r
1028 DevOrderPtr->BbsType = BBS_EMBED_NETWORK;\r
1029 DevOrderPtr->Length = (UINT16) (sizeof (UINT16) + NETCount * sizeof (UINT16));\r
1030 DevOrderPtr = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_EMBED_NETWORK, BbsCount, DevOrderPtr->Data);\r
1031\r
1032 DevOrderPtr->BbsType = BBS_BEV_DEVICE;\r
1033 DevOrderPtr->Length = (UINT16) (sizeof (UINT16) + BEVCount * sizeof (UINT16));\r
1034 DevOrderPtr = (LEGACY_DEV_ORDER_ENTRY *) BdsFillDevOrderBuf (BbsTable, BBS_BEV_DEVICE, BbsCount, DevOrderPtr->Data);\r
1035\r
1036 ASSERT (TotalSize == (UINTN) ((UINT8 *) DevOrderPtr - (UINT8 *) DevOrder));\r
1037\r
1038 //\r
1039 // Save device order for legacy boot device to variable.\r
1040 //\r
1041 Status = gRT->SetVariable (\r
1042 VAR_LEGACY_DEV_ORDER,\r
1043 &gEfiLegacyDevOrderVariableGuid,\r
1044 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1045 TotalSize,\r
1046 DevOrder\r
1047 );\r
1048 FreePool (DevOrder);\r
1049\r
1050 return Status;\r
1051}\r
1052\r
1053/**\r
1054 Add the legacy boot devices from BBS table into \r
1055 the legacy device boot order.\r
1056\r
1057 @retval EFI_SUCCESS The boot devices are added successfully.\r
1058 @retval EFI_NOT_FOUND The legacy boot devices are not found.\r
1059 @retval EFI_OUT_OF_RESOURCES Memmory or storage is not enough.\r
1060 @retval EFI_DEVICE_ERROR Fail to add the legacy device boot order into EFI variable\r
1061 because of hardware error.\r
1062**/\r
1063EFI_STATUS\r
1064EFIAPI\r
1065BdsUpdateLegacyDevOrder (\r
1066 VOID\r
1067 )\r
1068{\r
1069 LEGACY_DEV_ORDER_ENTRY *DevOrder;\r
1070 LEGACY_DEV_ORDER_ENTRY *NewDevOrder;\r
1071 LEGACY_DEV_ORDER_ENTRY *Ptr;\r
1072 LEGACY_DEV_ORDER_ENTRY *NewPtr;\r
1073 UINTN DevOrderSize;\r
1074 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;\r
1075 EFI_STATUS Status;\r
1076 UINT16 HddCount;\r
1077 UINT16 BbsCount;\r
1078 HDD_INFO *LocalHddInfo;\r
1079 BBS_TABLE *LocalBbsTable;\r
1080 UINTN Index;\r
1081 UINTN Index2;\r
1082 UINTN *Idx;\r
1083 UINTN FDCount;\r
1084 UINTN HDCount;\r
1085 UINTN CDCount;\r
1086 UINTN NETCount;\r
1087 UINTN BEVCount;\r
1088 UINTN TotalSize;\r
1089 UINTN HeaderSize;\r
1090 UINT16 *NewFDPtr;\r
1091 UINT16 *NewHDPtr;\r
1092 UINT16 *NewCDPtr;\r
1093 UINT16 *NewNETPtr;\r
1094 UINT16 *NewBEVPtr;\r
1095 UINT16 *NewDevPtr;\r
1096 UINTN FDIndex;\r
1097 UINTN HDIndex;\r
1098 UINTN CDIndex;\r
1099 UINTN NETIndex;\r
1100 UINTN BEVIndex;\r
1101\r
1102 Idx = NULL;\r
1103 FDCount = 0;\r
1104 HDCount = 0;\r
1105 CDCount = 0;\r
1106 NETCount = 0;\r
1107 BEVCount = 0;\r
1108 TotalSize = 0;\r
1109 HeaderSize = sizeof (BBS_TYPE) + sizeof (UINT16);\r
1110 FDIndex = 0;\r
1111 HDIndex = 0;\r
1112 CDIndex = 0;\r
1113 NETIndex = 0;\r
1114 BEVIndex = 0;\r
1115 NewDevPtr = NULL;\r
1116\r
1117 Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);\r
1118 if (EFI_ERROR (Status)) {\r
1119 return Status;\r
1120 }\r
1121\r
1122 Status = LegacyBios->GetBbsInfo (\r
1123 LegacyBios,\r
1124 &HddCount,\r
1125 &LocalHddInfo,\r
1126 &BbsCount,\r
1127 &LocalBbsTable\r
1128 );\r
1129 if (EFI_ERROR (Status)) {\r
1130 return Status;\r
1131 }\r
1132\r
1133 DevOrder = BdsLibGetVariableAndSize (\r
1134 VAR_LEGACY_DEV_ORDER,\r
1135 &gEfiLegacyDevOrderVariableGuid,\r
1136 &DevOrderSize\r
1137 );\r
1138 if (NULL == DevOrder) {\r
1139 return BdsCreateDevOrder (LocalBbsTable, BbsCount);\r
1140 }\r
1141 //\r
1142 // First we figure out how many boot devices with same device type respectively\r
1143 //\r
1144 for (Index = 0; Index < BbsCount; Index++) {\r
1145 if ((LocalBbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) ||\r
1146 (LocalBbsTable[Index].BootPriority == BBS_DO_NOT_BOOT_FROM)\r
1147 ) {\r
1148 continue;\r
1149 }\r
1150\r
1151 switch (LocalBbsTable[Index].DeviceType) {\r
1152 case BBS_FLOPPY:\r
1153 FDCount++;\r
1154 break;\r
1155\r
1156 case BBS_HARDDISK:\r
1157 HDCount++;\r
1158 break;\r
1159\r
1160 case BBS_CDROM:\r
1161 CDCount++;\r
1162 break;\r
1163\r
1164 case BBS_EMBED_NETWORK:\r
1165 NETCount++;\r
1166 break;\r
1167\r
1168 case BBS_BEV_DEVICE:\r
1169 BEVCount++;\r
1170 break;\r
1171\r
1172 default:\r
1173 break;\r
1174 }\r
1175 }\r
1176\r
1177 TotalSize += (HeaderSize + FDCount * sizeof (UINT16));\r
1178 TotalSize += (HeaderSize + HDCount * sizeof (UINT16));\r
1179 TotalSize += (HeaderSize + CDCount * sizeof (UINT16));\r
1180 TotalSize += (HeaderSize + NETCount * sizeof (UINT16));\r
1181 TotalSize += (HeaderSize + BEVCount * sizeof (UINT16));\r
1182\r
1183 NewDevOrder = AllocateZeroPool (TotalSize);\r
1184 if (NULL == NewDevOrder) {\r
1185 return EFI_OUT_OF_RESOURCES;\r
1186 }\r
1187\r
1188\r
1189\r
1190 //\r
1191 // copy FD\r
1192 //\r
1193 Ptr = DevOrder;\r
1194 NewPtr = NewDevOrder;\r
1195 NewPtr->BbsType = Ptr->BbsType;\r
1196 NewPtr->Length = (UINT16) (sizeof (UINT16) + FDCount * sizeof (UINT16));\r
1197 for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {\r
1198 if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||\r
1199 LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||\r
1200 LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_FLOPPY\r
1201 ) {\r
1202 continue;\r
1203 }\r
1204\r
1205 NewPtr->Data[FDIndex] = Ptr->Data[Index];\r
1206 FDIndex++;\r
1207 }\r
1208 NewFDPtr = NewPtr->Data;\r
1209\r
1210 //\r
1211 // copy HD\r
1212 //\r
1213 Ptr = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);\r
1214 NewPtr = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);\r
1215 NewPtr->BbsType = Ptr->BbsType;\r
1216 NewPtr->Length = (UINT16) (sizeof (UINT16) + HDCount * sizeof (UINT16));\r
1217 for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {\r
1218 if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||\r
1219 LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||\r
1220 LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||\r
1221 LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_HARDDISK\r
1222 ) {\r
1223 continue;\r
1224 }\r
1225\r
1226 NewPtr->Data[HDIndex] = Ptr->Data[Index];\r
1227 HDIndex++;\r
1228 }\r
1229 NewHDPtr = NewPtr->Data;\r
1230\r
1231 //\r
1232 // copy CD\r
1233 //\r
1234 Ptr = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);\r
1235 NewPtr = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);\r
1236 NewPtr->BbsType = Ptr->BbsType;\r
1237 NewPtr->Length = (UINT16) (sizeof (UINT16) + CDCount * sizeof (UINT16));\r
1238 for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {\r
1239 if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||\r
1240 LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||\r
1241 LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||\r
1242 LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_CDROM\r
1243 ) {\r
1244 continue;\r
1245 }\r
1246\r
1247 NewPtr->Data[CDIndex] = Ptr->Data[Index];\r
1248 CDIndex++;\r
1249 }\r
1250 NewCDPtr = NewPtr->Data;\r
1251\r
1252 //\r
1253 // copy NET\r
1254 //\r
1255 Ptr = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);\r
1256 NewPtr = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);\r
1257 NewPtr->BbsType = Ptr->BbsType;\r
1258 NewPtr->Length = (UINT16) (sizeof (UINT16) + NETCount * sizeof (UINT16));\r
1259 for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {\r
1260 if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||\r
1261 LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||\r
1262 LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||\r
1263 LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_EMBED_NETWORK\r
1264 ) {\r
1265 continue;\r
1266 }\r
1267\r
1268 NewPtr->Data[NETIndex] = Ptr->Data[Index];\r
1269 NETIndex++;\r
1270 }\r
1271 NewNETPtr = NewPtr->Data;\r
1272 \r
1273 //\r
1274 // copy BEV\r
1275 //\r
1276 Ptr = (LEGACY_DEV_ORDER_ENTRY *) (&Ptr->Data[Ptr->Length / sizeof (UINT16) - 1]);\r
1277 NewPtr = (LEGACY_DEV_ORDER_ENTRY *) (&NewPtr->Data[NewPtr->Length / sizeof (UINT16) -1]);\r
1278 NewPtr->BbsType = Ptr->BbsType;\r
1279 NewPtr->Length = (UINT16) (sizeof (UINT16) + BEVCount * sizeof (UINT16));\r
1280 for (Index = 0; Index < Ptr->Length / sizeof (UINT16) - 1; Index++) {\r
1281 if (LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_IGNORE_ENTRY ||\r
1282 LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_DO_NOT_BOOT_FROM ||\r
1283 LocalBbsTable[Ptr->Data[Index] & 0xFF].BootPriority == BBS_LOWEST_PRIORITY ||\r
1284 LocalBbsTable[Ptr->Data[Index] & 0xFF].DeviceType != BBS_BEV_DEVICE\r
1285 ) {\r
1286 continue;\r
1287 }\r
1288\r
1289 NewPtr->Data[BEVIndex] = Ptr->Data[Index];\r
1290 BEVIndex++;\r
1291 }\r
1292 NewBEVPtr = NewPtr->Data;\r
1293\r
1294 for (Index = 0; Index < BbsCount; Index++) {\r
1295 if ((LocalBbsTable[Index].BootPriority == BBS_IGNORE_ENTRY) ||\r
1296 (LocalBbsTable[Index].BootPriority == BBS_DO_NOT_BOOT_FROM)\r
1297 ) {\r
1298 continue;\r
1299 }\r
1300\r
1301 switch (LocalBbsTable[Index].DeviceType) {\r
1302 case BBS_FLOPPY:\r
1303 Idx = &FDIndex;\r
1304 NewDevPtr = NewFDPtr;\r
1305 break;\r
1306\r
1307 case BBS_HARDDISK:\r
1308 Idx = &HDIndex;\r
1309 NewDevPtr = NewHDPtr;\r
1310 break;\r
1311\r
1312 case BBS_CDROM:\r
1313 Idx = &CDIndex;\r
1314 NewDevPtr = NewCDPtr;\r
1315 break;\r
1316\r
1317 case BBS_EMBED_NETWORK:\r
1318 Idx = &NETIndex;\r
1319 NewDevPtr = NewNETPtr;\r
1320 break;\r
1321\r
1322 case BBS_BEV_DEVICE:\r
1323 Idx = &BEVIndex;\r
1324 NewDevPtr = NewBEVPtr;\r
1325 break;\r
1326\r
1327 default:\r
1328 Idx = NULL;\r
1329 break;\r
1330 }\r
1331 //\r
1332 // at this point we have copied those valid indexes to new buffer\r
1333 // and we should check if there is any new appeared boot device\r
1334 //\r
1335 if (Idx != NULL) {\r
1336 for (Index2 = 0; Index2 < *Idx; Index2++) {\r
1337 if ((NewDevPtr[Index2] & 0xFF) == (UINT16) Index) {\r
1338 break;\r
1339 }\r
1340 }\r
1341\r
1342 if (Index2 == *Idx) {\r
1343 //\r
1344 // Index2 == *Idx means we didn't find Index\r
1345 // so Index is a new appeared device's index in BBS table\r
1346 // insert it before disabled indexes.\r
1347 //\r
1348 for (Index2 = 0; Index2 < *Idx; Index2++) {\r
1349 if ((NewDevPtr[Index2] & 0xFF00) == 0xFF00) {\r
1350 break;\r
1351 }\r
1352 }\r
1353 CopyMem (&NewDevPtr[Index2 + 1], &NewDevPtr[Index2], (*Idx - Index2) * sizeof (UINT16));\r
1354 NewDevPtr[Index2] = (UINT16) (Index & 0xFF);\r
1355 (*Idx)++;\r
1356 }\r
1357 }\r
1358 }\r
1359\r
1360 FreePool (DevOrder);\r
1361\r
1362 Status = gRT->SetVariable (\r
1363 VAR_LEGACY_DEV_ORDER,\r
1364 &gEfiLegacyDevOrderVariableGuid,\r
1365 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
1366 TotalSize,\r
1367 NewDevOrder\r
1368 );\r
1369 FreePool (NewDevOrder);\r
1370\r
1371 return Status;\r
1372}\r
1373\r
1374/**\r
1375 Set Boot Priority for specified device type.\r
1376\r
1377 @param DeviceType The device type.\r
1378 @param BbsIndex The BBS index to set the highest priority. Ignore when -1.\r
1379 @param LocalBbsTable The BBS table.\r
1380 @param Priority The prority table.\r
1381\r
1382 @retval EFI_SUCCESS The function completes successfully.\r
1383 @retval EFI_NOT_FOUND Failed to find device.\r
1384 @retval EFI_OUT_OF_RESOURCES Failed to get the efi variable of device order.\r
1385\r
1386**/\r
1387EFI_STATUS\r
1388BdsSetBootPriority4SameTypeDev (\r
1389 IN UINT16 DeviceType,\r
1390 IN UINTN BbsIndex,\r
1391 IN OUT BBS_TABLE *LocalBbsTable,\r
1392 IN OUT UINT16 *Priority\r
1393 )\r
1394{\r
1395 LEGACY_DEV_ORDER_ENTRY *DevOrder;\r
1396 LEGACY_DEV_ORDER_ENTRY *DevOrderPtr;\r
1397 UINTN DevOrderSize;\r
1398 UINTN Index;\r
1399\r
1400 DevOrder = BdsLibGetVariableAndSize (\r
1401 VAR_LEGACY_DEV_ORDER,\r
1402 &gEfiLegacyDevOrderVariableGuid,\r
1403 &DevOrderSize\r
1404 );\r
1405 if (NULL == DevOrder) {\r
1406 return EFI_OUT_OF_RESOURCES;\r
1407 }\r
1408\r
1409 DevOrderPtr = DevOrder;\r
1410 while ((UINT8 *) DevOrderPtr < (UINT8 *) DevOrder + DevOrderSize) {\r
1411 if (DevOrderPtr->BbsType == DeviceType) {\r
1412 break;\r
1413 }\r
1414\r
1415 DevOrderPtr = (LEGACY_DEV_ORDER_ENTRY *) ((UINT8 *) DevOrderPtr + sizeof (BBS_TYPE) + DevOrderPtr->Length);\r
1416 }\r
1417\r
1418 if ((UINT8 *) DevOrderPtr >= (UINT8 *) DevOrder + DevOrderSize) {\r
1419 FreePool (DevOrder);\r
1420 return EFI_NOT_FOUND;\r
1421 }\r
1422\r
1423 if (BbsIndex != (UINTN) -1) {\r
1424 LocalBbsTable[BbsIndex].BootPriority = *Priority;\r
1425 (*Priority)++;\r
1426 }\r
1427 //\r
1428 // If the high byte of the DevIndex is 0xFF, it indicates that this device has been disabled.\r
1429 //\r
1430 for (Index = 0; Index < DevOrderPtr->Length / sizeof (UINT16) - 1; Index++) {\r
1431 if ((DevOrderPtr->Data[Index] & 0xFF00) == 0xFF00) {\r
1432 //\r
1433 // LocalBbsTable[DevIndex[Index] & 0xFF].BootPriority = BBS_DISABLED_ENTRY;\r
1434 //\r
1435 } else if (DevOrderPtr->Data[Index] != BbsIndex) {\r
1436 LocalBbsTable[DevOrderPtr->Data[Index]].BootPriority = *Priority;\r
1437 (*Priority)++;\r
1438 }\r
1439 }\r
1440\r
1441 FreePool (DevOrder);\r
1442 return EFI_SUCCESS;\r
1443}\r
1444\r
1445/**\r
1446 Print the BBS Table.\r
1447\r
1448 @param LocalBbsTable The BBS table.\r
1449 @param BbsCount The count of entry in BBS table.\r
1450**/\r
1451VOID\r
1452PrintBbsTable (\r
1453 IN BBS_TABLE *LocalBbsTable,\r
1454 IN UINT16 BbsCount\r
1455 )\r
1456{\r
1457 UINT16 Idx;\r
1458\r
1459 DEBUG ((DEBUG_ERROR, "\n"));\r
1460 DEBUG ((DEBUG_ERROR, " NO Prio bb/dd/ff cl/sc Type Stat segm:offs\n"));\r
1461 DEBUG ((DEBUG_ERROR, "=============================================\n"));\r
1462 for (Idx = 0; Idx < BbsCount; Idx++) {\r
1463 if ((LocalBbsTable[Idx].BootPriority == BBS_IGNORE_ENTRY) ||\r
1464 (LocalBbsTable[Idx].BootPriority == BBS_DO_NOT_BOOT_FROM) ||\r
1465 (LocalBbsTable[Idx].BootPriority == BBS_LOWEST_PRIORITY)\r
1466 ) {\r
1467 continue;\r
1468 }\r
1469\r
1470 DEBUG (\r
1471 (DEBUG_ERROR,\r
1472 " %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x\n",\r
1473 (UINTN) Idx,\r
1474 (UINTN) LocalBbsTable[Idx].BootPriority,\r
1475 (UINTN) LocalBbsTable[Idx].Bus,\r
1476 (UINTN) LocalBbsTable[Idx].Device,\r
1477 (UINTN) LocalBbsTable[Idx].Function,\r
1478 (UINTN) LocalBbsTable[Idx].Class,\r
1479 (UINTN) LocalBbsTable[Idx].SubClass,\r
1480 (UINTN) LocalBbsTable[Idx].DeviceType,\r
1481 (UINTN) * (UINT16 *) &LocalBbsTable[Idx].StatusFlags,\r
1482 (UINTN) LocalBbsTable[Idx].BootHandlerSegment,\r
1483 (UINTN) LocalBbsTable[Idx].BootHandlerOffset,\r
1484 (UINTN) ((LocalBbsTable[Idx].MfgStringSegment << 4) + LocalBbsTable[Idx].MfgStringOffset),\r
1485 (UINTN) ((LocalBbsTable[Idx].DescStringSegment << 4) + LocalBbsTable[Idx].DescStringOffset))\r
1486 );\r
1487 }\r
1488\r
1489 DEBUG ((DEBUG_ERROR, "\n"));\r
1490}\r
1491\r
1492/**\r
1493 Set the boot priority for BBS entries based on boot option entry and boot order.\r
1494\r
1495 @param Entry The boot option is to be checked for refresh BBS table.\r
1496 \r
1497 @retval EFI_SUCCESS The boot priority for BBS entries is refreshed successfully.\r
1498 @retval EFI_NOT_FOUND BBS entries can't be found.\r
1499 @retval EFI_OUT_OF_RESOURCES Failed to get the legacy device boot order.\r
1500**/\r
1501EFI_STATUS\r
1502EFIAPI\r
1503BdsRefreshBbsTableForBoot (\r
1504 IN BDS_COMMON_OPTION *Entry\r
1505 )\r
1506{\r
1507 EFI_STATUS Status;\r
1508 UINT16 BbsIndex;\r
1509 UINT16 HddCount;\r
1510 UINT16 BbsCount;\r
1511 HDD_INFO *LocalHddInfo;\r
1512 BBS_TABLE *LocalBbsTable;\r
1513 UINT16 DevType;\r
1514 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;\r
1515 UINTN Index;\r
1516 UINT16 Priority;\r
1517 UINT16 *BootOrder;\r
1518 UINTN BootOrderSize;\r
1519 UINT8 *BootOptionVar;\r
1520 UINTN BootOptionSize;\r
1521 CHAR16 BootOption[9];\r
1522 UINT8 *Ptr;\r
1523 UINT16 DevPathLen;\r
1524 EFI_DEVICE_PATH_PROTOCOL *DevPath;\r
1525 UINT16 *DeviceType;\r
1526 UINTN DeviceTypeCount;\r
1527 UINTN DeviceTypeIndex;\r
1528\r
1529 HddCount = 0;\r
1530 BbsCount = 0;\r
1531 LocalHddInfo = NULL;\r
1532 LocalBbsTable = NULL;\r
1533 DevType = BBS_UNKNOWN;\r
1534\r
1535 Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);\r
1536 if (EFI_ERROR (Status)) {\r
1537 return Status;\r
1538 }\r
1539\r
1540 LegacyBios->GetBbsInfo (\r
1541 LegacyBios,\r
1542 &HddCount,\r
1543 &LocalHddInfo,\r
1544 &BbsCount,\r
1545 &LocalBbsTable\r
1546 );\r
1547 //\r
1548 // First, set all the present devices' boot priority to BBS_UNPRIORITIZED_ENTRY\r
1549 // We will set them according to the settings setup by user\r
1550 //\r
1551 for (Index = 0; Index < BbsCount; Index++) {\r
1552 if (!((BBS_IGNORE_ENTRY == LocalBbsTable[Index].BootPriority) ||\r
1553 (BBS_DO_NOT_BOOT_FROM == LocalBbsTable[Index].BootPriority) ||\r
1554 (BBS_LOWEST_PRIORITY == LocalBbsTable[Index].BootPriority))) {\r
1555 LocalBbsTable[Index].BootPriority = BBS_UNPRIORITIZED_ENTRY;\r
1556 }\r
1557 }\r
1558 //\r
1559 // boot priority always starts at 0\r
1560 //\r
1561 Priority = 0;\r
1562 if (Entry->LoadOptionsSize == sizeof (BBS_TABLE) + sizeof (UINT16)) {\r
1563 //\r
1564 // If Entry stands for a legacy boot option, we prioritize the devices with the same type first.\r
1565 //\r
1566 DevType = ((BBS_TABLE *) Entry->LoadOptions)->DeviceType;\r
1567 BbsIndex = *(UINT16 *) ((BBS_TABLE *) Entry->LoadOptions + 1);\r
1568 Status = BdsSetBootPriority4SameTypeDev (\r
1569 DevType,\r
1570 BbsIndex,\r
1571 LocalBbsTable,\r
1572 &Priority\r
1573 );\r
1574 if (EFI_ERROR (Status)) {\r
1575 return Status;\r
1576 }\r
1577 }\r
1578 //\r
1579 // we have to set the boot priority for other BBS entries with different device types\r
1580 //\r
1581 BootOrder = BdsLibGetVariableAndSize (\r
1582 L"BootOrder",\r
1583 &gEfiGlobalVariableGuid,\r
1584 &BootOrderSize\r
1585 );\r
1586 DeviceType = AllocatePool (BootOrderSize + sizeof (UINT16));\r
1587 ASSERT (DeviceType != NULL);\r
1588\r
1589 DeviceType[0] = DevType;\r
1590 DeviceTypeCount = 1;\r
1591 for (Index = 0; ((BootOrder != NULL) && (Index < BootOrderSize / sizeof (UINT16))); Index++) {\r
1592 UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);\r
1593 BootOptionVar = BdsLibGetVariableAndSize (\r
1594 BootOption,\r
1595 &gEfiGlobalVariableGuid,\r
1596 &BootOptionSize\r
1597 );\r
1598 if (NULL == BootOptionVar) {\r
1599 continue;\r
1600 }\r
1601\r
1602 Ptr = BootOptionVar;\r
1603\r
1604 Ptr += sizeof (UINT32);\r
1605 DevPathLen = *(UINT16 *) Ptr;\r
1606 Ptr += sizeof (UINT16);\r
1607 Ptr += StrSize ((UINT16 *) Ptr);\r
1608 DevPath = (EFI_DEVICE_PATH_PROTOCOL *) Ptr;\r
1609 if (BBS_DEVICE_PATH != DevPath->Type || BBS_BBS_DP != DevPath->SubType) {\r
1610 FreePool (BootOptionVar);\r
1611 continue;\r
1612 }\r
1613\r
1614 Ptr += DevPathLen;\r
1615 DevType = ((BBS_TABLE *) Ptr)->DeviceType;\r
1616 for (DeviceTypeIndex = 0; DeviceTypeIndex < DeviceTypeCount; DeviceTypeIndex++) {\r
1617 if (DeviceType[DeviceTypeIndex] == DevType) {\r
1618 break;\r
1619 }\r
1620 }\r
1621 if (DeviceTypeIndex < DeviceTypeCount) {\r
1622 //\r
1623 // We don't want to process twice for a device type\r
1624 //\r
1625 FreePool (BootOptionVar);\r
1626 continue;\r
1627 }\r
1628\r
1629 DeviceType[DeviceTypeCount] = DevType;\r
1630 DeviceTypeCount++;\r
1631\r
1632 Status = BdsSetBootPriority4SameTypeDev (\r
1633 DevType,\r
1634 (UINTN) -1,\r
1635 LocalBbsTable,\r
1636 &Priority\r
1637 );\r
1638 FreePool (BootOptionVar);\r
1639 if (EFI_ERROR (Status)) {\r
1640 break;\r
1641 }\r
1642 }\r
1643\r
1644 if (BootOrder != NULL) {\r
1645 FreePool (BootOrder);\r
1646 }\r
1647\r
1648 DEBUG_CODE_BEGIN();\r
1649 PrintBbsTable (LocalBbsTable, BbsCount);\r
1650 DEBUG_CODE_END();\r
1651\r
1652 return Status;\r
1653}\r
5c08e117 1654\r
1655/**\r
1656 Boot the legacy system with the boot option\r
1657\r
1658 @param Option The legacy boot option which have BBS device path\r
1659\r
1660 @retval EFI_UNSUPPORTED There is no legacybios protocol, do not support\r
1661 legacy boot.\r
1662 @retval EFI_STATUS Return the status of LegacyBios->LegacyBoot ().\r
1663\r
1664**/\r
1665EFI_STATUS\r
1666BdsLibDoLegacyBoot (\r
1667 IN BDS_COMMON_OPTION *Option\r
1668 )\r
1669{\r
1670 EFI_STATUS Status;\r
1671 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;\r
26c0ba77 1672 EFI_EVENT LegacyBootEvent;\r
5c08e117 1673\r
1674 Status = gBS->LocateProtocol (&gEfiLegacyBiosProtocolGuid, NULL, (VOID **) &LegacyBios);\r
1675 if (EFI_ERROR (Status)) {\r
1676 //\r
1677 // If no LegacyBios protocol we do not support legacy boot\r
1678 //\r
1679 return EFI_UNSUPPORTED;\r
1680 }\r
1681 //\r
1682 // Notes: if we separate the int 19, then we don't need to refresh BBS\r
1683 //\r
1684 BdsRefreshBbsTableForBoot (Option);\r
1685\r
1686 //\r
cd6a3b15 1687 // Write boot to OS performance data for legacy boot.\r
5c08e117 1688 //\r
1689 PERF_CODE (\r
26c0ba77
SZ
1690 //\r
1691 // Create an event to be signalled when Legacy Boot occurs to write performance data.\r
1692 //\r
1693 Status = EfiCreateEventLegacyBootEx(\r
1694 TPL_NOTIFY,\r
1695 WriteBootToOsPerformanceData,\r
1696 NULL, \r
1697 &LegacyBootEvent\r
1698 );\r
1699 ASSERT_EFI_ERROR (Status);\r
5c08e117 1700 );\r
1701\r
1702 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Legacy Boot: %S\n", Option->Description));\r
1703 return LegacyBios->LegacyBoot (\r
1704 LegacyBios,\r
1705 (BBS_BBS_DEVICE_PATH *) Option->DevicePath,\r
1706 Option->LoadOptionsSize,\r
1707 Option->LoadOptions\r
1708 );\r
1709}\r
1710\r
3d7decbc 1711/**\r
1712 Internal function to check if the input boot option is a valid EFI NV Boot####.\r
1713\r
1714 @param OptionToCheck Boot option to be checked.\r
1715\r
1716 @retval TRUE This boot option matches a valid EFI NV Boot####.\r
1717 @retval FALSE If not.\r
128efbbc 1718\r
3d7decbc 1719**/\r
3d7decbc 1720BOOLEAN\r
1721IsBootOptionValidNVVarialbe (\r
1722 IN BDS_COMMON_OPTION *OptionToCheck\r
1723 )\r
1724{\r
1725 LIST_ENTRY TempList;\r
1726 BDS_COMMON_OPTION *BootOption;\r
1727 BOOLEAN Valid;\r
1728 CHAR16 OptionName[20];\r
1729\r
1730 Valid = FALSE;\r
1731\r
1732 InitializeListHead (&TempList);\r
1733 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionToCheck->BootCurrent);\r
5c08e117 1734\r
3d7decbc 1735 BootOption = BdsLibVariableToOption (&TempList, OptionName);\r
1736 if (BootOption == NULL) {\r
1737 return FALSE;\r
1738 }\r
1739\r
1740 //\r
128efbbc 1741 // If the Boot Option Number and Device Path matches, OptionToCheck matches a\r
3d7decbc 1742 // valid EFI NV Boot####.\r
1743 //\r
1744 if ((OptionToCheck->BootCurrent == BootOption->BootCurrent) &&\r
1745 (CompareMem (OptionToCheck->DevicePath, BootOption->DevicePath, GetDevicePathSize (OptionToCheck->DevicePath)) == 0))\r
1746 {\r
1747 Valid = TRUE;\r
1748 }\r
1749\r
1750 FreePool (BootOption);\r
128efbbc 1751\r
3d7decbc 1752 return Valid;\r
1753}\r
7389fdd0 1754\r
1755/**\r
1756 Check whether a USB device match the specified USB Class device path. This\r
1757 function follows "Load Option Processing" behavior in UEFI specification.\r
1758\r
1759 @param UsbIo USB I/O protocol associated with the USB device.\r
1760 @param UsbClass The USB Class device path to match.\r
1761\r
1762 @retval TRUE The USB device match the USB Class device path.\r
1763 @retval FALSE The USB device does not match the USB Class device path.\r
1764\r
1765**/\r
1766BOOLEAN\r
1767BdsMatchUsbClass (\r
1768 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
1769 IN USB_CLASS_DEVICE_PATH *UsbClass\r
1770 )\r
1771{\r
1772 EFI_STATUS Status;\r
1773 EFI_USB_DEVICE_DESCRIPTOR DevDesc;\r
1774 EFI_USB_INTERFACE_DESCRIPTOR IfDesc;\r
1775 UINT8 DeviceClass;\r
1776 UINT8 DeviceSubClass;\r
1777 UINT8 DeviceProtocol;\r
1778\r
1779 if ((DevicePathType (UsbClass) != MESSAGING_DEVICE_PATH) ||\r
1780 (DevicePathSubType (UsbClass) != MSG_USB_CLASS_DP)){\r
1781 return FALSE;\r
1782 }\r
1783\r
1784 //\r
1785 // Check Vendor Id and Product Id.\r
1786 //\r
1787 Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);\r
1788 if (EFI_ERROR (Status)) {\r
1789 return FALSE;\r
1790 }\r
1791\r
1792 if ((UsbClass->VendorId != 0xffff) &&\r
1793 (UsbClass->VendorId != DevDesc.IdVendor)) {\r
1794 return FALSE;\r
1795 }\r
1796\r
1797 if ((UsbClass->ProductId != 0xffff) &&\r
1798 (UsbClass->ProductId != DevDesc.IdProduct)) {\r
1799 return FALSE;\r
1800 }\r
1801\r
1802 DeviceClass = DevDesc.DeviceClass;\r
1803 DeviceSubClass = DevDesc.DeviceSubClass;\r
1804 DeviceProtocol = DevDesc.DeviceProtocol;\r
1805 if (DeviceClass == 0) {\r
1806 //\r
1807 // If Class in Device Descriptor is set to 0, use the Class, SubClass and\r
1808 // Protocol in Interface Descriptor instead.\r
1809 //\r
1810 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);\r
1811 if (EFI_ERROR (Status)) {\r
1812 return FALSE;\r
1813 }\r
1814\r
1815 DeviceClass = IfDesc.InterfaceClass;\r
1816 DeviceSubClass = IfDesc.InterfaceSubClass;\r
1817 DeviceProtocol = IfDesc.InterfaceProtocol;\r
1818 }\r
1819\r
1820 //\r
1821 // Check Class, SubClass and Protocol.\r
1822 //\r
1823 if ((UsbClass->DeviceClass != 0xff) &&\r
1824 (UsbClass->DeviceClass != DeviceClass)) {\r
1825 return FALSE;\r
1826 }\r
1827\r
1828 if ((UsbClass->DeviceSubClass != 0xff) &&\r
1829 (UsbClass->DeviceSubClass != DeviceSubClass)) {\r
1830 return FALSE;\r
1831 }\r
1832\r
1833 if ((UsbClass->DeviceProtocol != 0xff) &&\r
1834 (UsbClass->DeviceProtocol != DeviceProtocol)) {\r
1835 return FALSE;\r
1836 }\r
1837\r
1838 return TRUE;\r
1839}\r
1840\r
1841/**\r
1842 Check whether a USB device match the specified USB WWID device path. This\r
1843 function follows "Load Option Processing" behavior in UEFI specification.\r
1844\r
1845 @param UsbIo USB I/O protocol associated with the USB device.\r
1846 @param UsbWwid The USB WWID device path to match.\r
1847\r
1848 @retval TRUE The USB device match the USB WWID device path.\r
1849 @retval FALSE The USB device does not match the USB WWID device path.\r
1850\r
1851**/\r
1852BOOLEAN\r
1853BdsMatchUsbWwid (\r
1854 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
1855 IN USB_WWID_DEVICE_PATH *UsbWwid\r
1856 )\r
1857{\r
1858 EFI_STATUS Status;\r
1859 EFI_USB_DEVICE_DESCRIPTOR DevDesc;\r
1860 EFI_USB_INTERFACE_DESCRIPTOR IfDesc;\r
1861 UINT16 *LangIdTable;\r
1862 UINT16 TableSize;\r
1863 UINT16 Index;\r
1864 CHAR16 *CompareStr;\r
1865 UINTN CompareLen;\r
1866 CHAR16 *SerialNumberStr;\r
1867 UINTN Length;\r
1868\r
1869 if ((DevicePathType (UsbWwid) != MESSAGING_DEVICE_PATH) ||\r
1870 (DevicePathSubType (UsbWwid) != MSG_USB_WWID_DP )){\r
1871 return FALSE;\r
1872 }\r
1873\r
1874 //\r
1875 // Check Vendor Id and Product Id.\r
1876 //\r
1877 Status = UsbIo->UsbGetDeviceDescriptor (UsbIo, &DevDesc);\r
1878 if (EFI_ERROR (Status)) {\r
1879 return FALSE;\r
1880 }\r
1881 if ((DevDesc.IdVendor != UsbWwid->VendorId) ||\r
1882 (DevDesc.IdProduct != UsbWwid->ProductId)) {\r
1883 return FALSE;\r
1884 }\r
1885\r
1886 //\r
1887 // Check Interface Number.\r
1888 //\r
1889 Status = UsbIo->UsbGetInterfaceDescriptor (UsbIo, &IfDesc);\r
1890 if (EFI_ERROR (Status)) {\r
1891 return FALSE;\r
1892 }\r
1893 if (IfDesc.InterfaceNumber != UsbWwid->InterfaceNumber) {\r
1894 return FALSE;\r
1895 }\r
1896\r
1897 //\r
1898 // Check Serial Number.\r
1899 //\r
1900 if (DevDesc.StrSerialNumber == 0) {\r
1901 return FALSE;\r
1902 }\r
1903\r
1904 //\r
1905 // Get all supported languages.\r
1906 //\r
1907 TableSize = 0;\r
1908 LangIdTable = NULL;\r
1909 Status = UsbIo->UsbGetSupportedLanguages (UsbIo, &LangIdTable, &TableSize);\r
1910 if (EFI_ERROR (Status) || (TableSize == 0) || (LangIdTable == NULL)) {\r
1911 return FALSE;\r
1912 }\r
1913\r
1914 //\r
1915 // Serial number in USB WWID device path is the last 64-or-less UTF-16 characters.\r
1916 //\r
1917 CompareStr = (CHAR16 *) (UINTN) (UsbWwid + 1);\r
1918 CompareLen = (DevicePathNodeLength (UsbWwid) - sizeof (USB_WWID_DEVICE_PATH)) / sizeof (CHAR16);\r
1919 if (CompareStr[CompareLen - 1] == L'\0') {\r
1920 CompareLen--;\r
1921 }\r
1922\r
1923 //\r
1924 // Compare serial number in each supported language.\r
1925 //\r
1926 for (Index = 0; Index < TableSize / sizeof (UINT16); Index++) {\r
1927 SerialNumberStr = NULL;\r
1928 Status = UsbIo->UsbGetStringDescriptor (\r
1929 UsbIo,\r
1930 LangIdTable[Index],\r
1931 DevDesc.StrSerialNumber,\r
1932 &SerialNumberStr\r
1933 );\r
1934 if (EFI_ERROR (Status) || (SerialNumberStr == NULL)) {\r
1935 continue;\r
1936 }\r
1937\r
1938 Length = StrLen (SerialNumberStr);\r
1939 if ((Length >= CompareLen) &&\r
1940 (CompareMem (SerialNumberStr + Length - CompareLen, CompareStr, CompareLen * sizeof (CHAR16)) == 0)) {\r
1941 FreePool (SerialNumberStr);\r
1942 return TRUE;\r
1943 }\r
1944\r
1945 FreePool (SerialNumberStr);\r
1946 }\r
1947\r
1948 return FALSE;\r
1949}\r
1950\r
1951/**\r
9972247d 1952 Find a USB device path which match the specified short-form device path start\r
1953 with USB Class or USB WWID device path and load the boot file then return the \r
1954 image handle. If ParentDevicePath is NULL, this function will search in all USB\r
1955 devices of the platform. If ParentDevicePath is not NULL,this function will only\r
1956 search in its child devices.\r
7389fdd0 1957\r
1958 @param ParentDevicePath The device path of the parent.\r
1959 @param ShortFormDevicePath The USB Class or USB WWID device path to match.\r
1960\r
9972247d 1961 @return The image Handle if find load file from specified short-form device path\r
1962 or NULL if not found.\r
7389fdd0 1963\r
1964**/\r
1965EFI_HANDLE *\r
1966BdsFindUsbDevice (\r
1967 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,\r
1968 IN EFI_DEVICE_PATH_PROTOCOL *ShortFormDevicePath\r
1969 )\r
1970{\r
1971 EFI_STATUS Status;\r
1972 UINTN UsbIoHandleCount;\r
1973 EFI_HANDLE *UsbIoHandleBuffer;\r
1974 EFI_DEVICE_PATH_PROTOCOL *UsbIoDevicePath;\r
1975 EFI_USB_IO_PROTOCOL *UsbIo;\r
1976 UINTN Index;\r
1977 UINTN ParentSize;\r
1978 UINTN Size;\r
9972247d 1979 EFI_HANDLE ImageHandle;\r
1980 EFI_HANDLE Handle;\r
1981 EFI_DEVICE_PATH_PROTOCOL *FullDevicePath;\r
1982 EFI_DEVICE_PATH_PROTOCOL *NextDevicePath;\r
1983\r
1984 FullDevicePath = NULL;\r
1985 ImageHandle = NULL;\r
7389fdd0 1986\r
1987 //\r
1988 // Get all UsbIo Handles.\r
1989 //\r
1990 UsbIoHandleCount = 0;\r
1991 UsbIoHandleBuffer = NULL;\r
1992 Status = gBS->LocateHandleBuffer (\r
1993 ByProtocol,\r
1994 &gEfiUsbIoProtocolGuid,\r
1995 NULL,\r
1996 &UsbIoHandleCount,\r
1997 &UsbIoHandleBuffer\r
1998 );\r
1999 if (EFI_ERROR (Status) || (UsbIoHandleCount == 0) || (UsbIoHandleBuffer == NULL)) {\r
2000 return NULL;\r
2001 }\r
2002\r
7389fdd0 2003 ParentSize = (ParentDevicePath == NULL) ? 0 : GetDevicePathSize (ParentDevicePath);\r
2004 for (Index = 0; Index < UsbIoHandleCount; Index++) {\r
2005 //\r
2006 // Get the Usb IO interface.\r
2007 //\r
2008 Status = gBS->HandleProtocol(\r
2009 UsbIoHandleBuffer[Index],\r
2010 &gEfiUsbIoProtocolGuid,\r
2011 (VOID **) &UsbIo\r
2012 );\r
2013 if (EFI_ERROR (Status)) {\r
2014 continue;\r
2015 }\r
2016\r
9972247d 2017 UsbIoDevicePath = DevicePathFromHandle (UsbIoHandleBuffer[Index]);\r
2018 if (UsbIoDevicePath == NULL) {\r
2019 continue;\r
2020 }\r
2021\r
7389fdd0 2022 if (ParentDevicePath != NULL) {\r
2023 //\r
2024 // Compare starting part of UsbIoHandle's device path with ParentDevicePath.\r
2025 //\r
7389fdd0 2026 Size = GetDevicePathSize (UsbIoDevicePath);\r
2027 if ((Size < ParentSize) ||\r
2028 (CompareMem (UsbIoDevicePath, ParentDevicePath, ParentSize - END_DEVICE_PATH_LENGTH) != 0)) {\r
2029 continue;\r
2030 }\r
2031 }\r
2032\r
2033 if (BdsMatchUsbClass (UsbIo, (USB_CLASS_DEVICE_PATH *) ShortFormDevicePath) ||\r
2034 BdsMatchUsbWwid (UsbIo, (USB_WWID_DEVICE_PATH *) ShortFormDevicePath)) {\r
9972247d 2035 //\r
2036 // Try to find if there is the boot file in this DevicePath\r
2037 //\r
2038 NextDevicePath = NextDevicePathNode (ShortFormDevicePath);\r
2039 if (!IsDevicePathEnd (NextDevicePath)) {\r
2040 FullDevicePath = AppendDevicePath (UsbIoDevicePath, NextDevicePath);\r
2041 //\r
2042 // Connect the full device path, so that Simple File System protocol\r
2043 // could be installed for this USB device.\r
2044 //\r
2045 BdsLibConnectDevicePath (FullDevicePath);\r
79b7a6a1 2046 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));\r
9972247d 2047 Status = gBS->LoadImage (\r
2048 TRUE,\r
2049 gImageHandle,\r
2050 FullDevicePath,\r
2051 NULL,\r
2052 0,\r
2053 &ImageHandle\r
2054 );\r
2055 FreePool (FullDevicePath);\r
2056 } else {\r
2057 FullDevicePath = UsbIoDevicePath;\r
2058 Status = EFI_NOT_FOUND;\r
2059 }\r
2060\r
2061 //\r
2062 // If we didn't find an image directly, we need to try as if it is a removable device boot option\r
2063 // and load the image according to the default boot behavior for removable device.\r
2064 //\r
2065 if (EFI_ERROR (Status)) {\r
2066 //\r
2067 // check if there is a bootable removable media could be found in this device path ,\r
2068 // and get the bootable media handle\r
2069 //\r
2070 Handle = BdsLibGetBootableHandle(UsbIoDevicePath);\r
2071 if (Handle == NULL) {\r
2072 continue;\r
2073 }\r
2074 //\r
2075 // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media\r
2076 // machinename is ia32, ia64, x64, ...\r
2077 //\r
2078 FullDevicePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);\r
2079 if (FullDevicePath != NULL) {\r
79b7a6a1 2080 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));\r
9972247d 2081 Status = gBS->LoadImage (\r
2082 TRUE,\r
2083 gImageHandle,\r
2084 FullDevicePath,\r
2085 NULL,\r
2086 0,\r
2087 &ImageHandle\r
2088 );\r
2089 if (EFI_ERROR (Status)) {\r
2090 //\r
2091 // The DevicePath failed, and it's not a valid\r
2092 // removable media device.\r
2093 //\r
2094 continue;\r
2095 }\r
2096 } else {\r
2097 continue;\r
2098 }\r
2099 }\r
7389fdd0 2100 break;\r
2101 }\r
2102 }\r
2103\r
2104 FreePool (UsbIoHandleBuffer);\r
9972247d 2105 return ImageHandle;\r
7389fdd0 2106}\r
2107\r
2108/**\r
2109 Expand USB Class or USB WWID device path node to be full device path of a USB\r
9972247d 2110 device in platform then load the boot file on this full device path and return the \r
2111 image handle.\r
7389fdd0 2112\r
2113 This function support following 4 cases:\r
2114 1) Boot Option device path starts with a USB Class or USB WWID device path,\r
2115 and there is no Media FilePath device path in the end.\r
2116 In this case, it will follow Removable Media Boot Behavior.\r
2117 2) Boot Option device path starts with a USB Class or USB WWID device path,\r
2118 and ended with Media FilePath device path.\r
2119 3) Boot Option device path starts with a full device path to a USB Host Controller,\r
2120 contains a USB Class or USB WWID device path node, while not ended with Media\r
2121 FilePath device path. In this case, it will follow Removable Media Boot Behavior.\r
2122 4) Boot Option device path starts with a full device path to a USB Host Controller,\r
2123 contains a USB Class or USB WWID device path node, and ended with Media\r
2124 FilePath device path.\r
2125\r
2126 @param DevicePath The Boot Option device path.\r
2127\r
9972247d 2128 @return The image handle of boot file, or NULL if there is no boot file found in\r
2129 the specified USB Class or USB WWID device path.\r
7389fdd0 2130\r
2131**/\r
9972247d 2132EFI_HANDLE *\r
7389fdd0 2133BdsExpandUsbShortFormDevicePath (\r
2134 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
2135 )\r
2136{\r
9972247d 2137 EFI_HANDLE *ImageHandle;\r
7389fdd0 2138 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
7389fdd0 2139 EFI_DEVICE_PATH_PROTOCOL *ShortFormDevicePath;\r
2140\r
2141 //\r
2142 // Search for USB Class or USB WWID device path node.\r
2143 //\r
2144 ShortFormDevicePath = NULL;\r
9972247d 2145 ImageHandle = NULL;\r
2146 TempDevicePath = DevicePath;\r
7389fdd0 2147 while (!IsDevicePathEnd (TempDevicePath)) {\r
2148 if ((DevicePathType (TempDevicePath) == MESSAGING_DEVICE_PATH) &&\r
2149 ((DevicePathSubType (TempDevicePath) == MSG_USB_CLASS_DP) ||\r
2150 (DevicePathSubType (TempDevicePath) == MSG_USB_WWID_DP))) {\r
2151 ShortFormDevicePath = TempDevicePath;\r
2152 break;\r
2153 }\r
7389fdd0 2154 TempDevicePath = NextDevicePathNode (TempDevicePath);\r
2155 }\r
2156\r
2157 if (ShortFormDevicePath == NULL) {\r
2158 //\r
2159 // No USB Class or USB WWID device path node found, do nothing.\r
2160 //\r
2161 return NULL;\r
2162 }\r
2163\r
2164 if (ShortFormDevicePath == DevicePath) {\r
2165 //\r
2166 // Boot Option device path starts with USB Class or USB WWID device path.\r
2167 //\r
9972247d 2168 ImageHandle = BdsFindUsbDevice (NULL, ShortFormDevicePath);\r
2169 if (ImageHandle == NULL) {\r
7389fdd0 2170 //\r
2171 // Failed to find a match in existing devices, connect the short form USB\r
2172 // device path and try again.\r
2173 //\r
2174 BdsLibConnectUsbDevByShortFormDP (0xff, ShortFormDevicePath);\r
9972247d 2175 ImageHandle = BdsFindUsbDevice (NULL, ShortFormDevicePath);\r
7389fdd0 2176 }\r
2177 } else {\r
2178 //\r
2179 // Boot Option device path contains USB Class or USB WWID device path node.\r
2180 //\r
2181\r
2182 //\r
2183 // Prepare the parent device path for search.\r
2184 //\r
2185 TempDevicePath = DuplicateDevicePath (DevicePath);\r
2186 ASSERT (TempDevicePath != NULL);\r
2187 SetDevicePathEndNode (((UINT8 *) TempDevicePath) + ((UINTN) ShortFormDevicePath - (UINTN) DevicePath));\r
2188\r
2189 //\r
9972247d 2190 // The USB Host Controller device path is already in Boot Option device path\r
7389fdd0 2191 // and USB Bus driver already support RemainingDevicePath starts with USB\r
2192 // Class or USB WWID device path, so just search in existing USB devices and\r
2193 // doesn't perform ConnectController here.\r
2194 //\r
9972247d 2195 ImageHandle = BdsFindUsbDevice (TempDevicePath, ShortFormDevicePath);\r
7389fdd0 2196 FreePool (TempDevicePath);\r
2197 }\r
2198\r
9972247d 2199 return ImageHandle;\r
7389fdd0 2200}\r
2201\r
5c08e117 2202/**\r
2203 Process the boot option follow the UEFI specification and\r
2204 special treat the legacy boot option with BBS_DEVICE_PATH.\r
2205\r
2206 @param Option The boot option need to be processed\r
2207 @param DevicePath The device path which describe where to load the\r
2208 boot image or the legacy BBS device path to boot\r
2209 the legacy OS\r
2210 @param ExitDataSize The size of exit data.\r
2211 @param ExitData Data returned when Boot image failed.\r
2212\r
2213 @retval EFI_SUCCESS Boot from the input boot option successfully.\r
2214 @retval EFI_NOT_FOUND If the Device Path is not found in the system\r
2215\r
2216**/\r
2217EFI_STATUS\r
2218EFIAPI\r
2219BdsLibBootViaBootOption (\r
2220 IN BDS_COMMON_OPTION *Option,\r
2221 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
2222 OUT UINTN *ExitDataSize,\r
2223 OUT CHAR16 **ExitData OPTIONAL\r
2224 )\r
2225{\r
2226 EFI_STATUS Status;\r
2df686c6 2227 EFI_STATUS StatusLogo;\r
5c08e117 2228 EFI_HANDLE Handle;\r
2229 EFI_HANDLE ImageHandle;\r
2230 EFI_DEVICE_PATH_PROTOCOL *FilePath;\r
2231 EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;\r
2232 EFI_DEVICE_PATH_PROTOCOL *WorkingDevicePath;\r
2233 EFI_ACPI_S3_SAVE_PROTOCOL *AcpiS3Save;\r
2234 LIST_ENTRY TempBootLists;\r
2df686c6 2235 EFI_BOOT_LOGO_PROTOCOL *BootLogo;\r
5c08e117 2236\r
5c08e117 2237 *ExitDataSize = 0;\r
2238 *ExitData = NULL;\r
2239\r
5c08e117 2240 //\r
2241 // Notes: this code can be remove after the s3 script table\r
2242 // hook on the event EVT_SIGNAL_READY_TO_BOOT or\r
2243 // EVT_SIGNAL_LEGACY_BOOT\r
2244 //\r
2245 Status = gBS->LocateProtocol (&gEfiAcpiS3SaveProtocolGuid, NULL, (VOID **) &AcpiS3Save);\r
2246 if (!EFI_ERROR (Status)) {\r
2247 AcpiS3Save->S3Save (AcpiS3Save, NULL);\r
2248 }\r
2249 //\r
2250 // If it's Device Path that starts with a hard drive path, append it with the front part to compose a\r
2251 // full device path\r
2252 //\r
2253 WorkingDevicePath = NULL;\r
2254 if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&\r
2255 (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)) {\r
2256 WorkingDevicePath = BdsExpandPartitionPartialDevicePathToFull (\r
2257 (HARDDRIVE_DEVICE_PATH *)DevicePath\r
2258 );\r
2259 if (WorkingDevicePath != NULL) {\r
2260 DevicePath = WorkingDevicePath;\r
2261 }\r
2262 }\r
7389fdd0 2263\r
5c08e117 2264 //\r
2265 // Set Boot Current\r
2266 //\r
3d7decbc 2267 if (IsBootOptionValidNVVarialbe (Option)) {\r
2268 //\r
2269 // For a temporary boot (i.e. a boot by selected a EFI Shell using "Boot From File"), Boot Current is actually not valid.\r
2270 // In this case, "BootCurrent" is not created.\r
2271 // Only create the BootCurrent variable when it points to a valid Boot#### variable.\r
2272 //\r
69fc8f08 2273 SetVariableAndReportStatusCodeOnError (\r
3d7decbc 2274 L"BootCurrent",\r
2275 &gEfiGlobalVariableGuid,\r
2276 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
2277 sizeof (UINT16),\r
2278 &Option->BootCurrent\r
2279 );\r
2280 }\r
5c08e117 2281\r
cb38c322 2282 //\r
2283 // Report Status Code to indicate ReadyToBoot event will be signalled\r
2284 //\r
2285 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_READY_TO_BOOT_EVENT));\r
2286\r
72861c22 2287 //\r
2288 // Signal the EVT_SIGNAL_READY_TO_BOOT event\r
2289 //\r
2290 EfiSignalEventReadyToBoot();\r
2291\r
2292 //\r
2293 // Expand USB Class or USB WWID device path node to be full device path of a USB\r
2294 // device in platform then load the boot file on this full device path and get the\r
2295 // image handle.\r
2296 //\r
2297 ImageHandle = BdsExpandUsbShortFormDevicePath (DevicePath);\r
2298\r
2299 //\r
2300 // Adjust the different type memory page number just before booting\r
2301 // and save the updated info into the variable for next boot to use\r
2302 //\r
2303 BdsSetMemoryTypeInformationVariable ();\r
2304\r
5c08e117 2305 //\r
9972247d 2306 // By expanding the USB Class or WWID device path, the ImageHandle has returnned.\r
2307 // Here get the ImageHandle for the non USB class or WWID device path.\r
5c08e117 2308 //\r
9972247d 2309 if (ImageHandle == NULL) {\r
2310 ASSERT (Option->DevicePath != NULL);\r
2311 if ((DevicePathType (Option->DevicePath) == BBS_DEVICE_PATH) &&\r
2312 (DevicePathSubType (Option->DevicePath) == BBS_BBS_DP)\r
2313 ) {\r
2314 //\r
2315 // Check to see if we should legacy BOOT. If yes then do the legacy boot\r
2316 //\r
2317 return BdsLibDoLegacyBoot (Option);\r
5c08e117 2318 }\r
128efbbc 2319\r
5c08e117 2320 //\r
9972247d 2321 // If the boot option point to Internal FV shell, make sure it is valid\r
5c08e117 2322 //\r
9972247d 2323 Status = BdsLibUpdateFvFileDevicePath (&DevicePath, PcdGetPtr(PcdShellFile));\r
2324 if (!EFI_ERROR(Status)) {\r
2325 if (Option->DevicePath != NULL) {\r
2326 FreePool(Option->DevicePath);\r
2327 }\r
2328 Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));\r
2329 ASSERT(Option->DevicePath != NULL);\r
2330 CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));\r
2331 //\r
2332 // Update the shell boot option\r
2333 //\r
2334 InitializeListHead (&TempBootLists);\r
2335 BdsLibRegisterNewOption (&TempBootLists, DevicePath, L"EFI Internal Shell", L"BootOrder");\r
2336\r
2337 //\r
2338 // free the temporary device path created by BdsLibUpdateFvFileDevicePath()\r
2339 //\r
2340 FreePool (DevicePath);\r
2341 DevicePath = Option->DevicePath;\r
2342 }\r
5c08e117 2343\r
9972247d 2344 DEBUG_CODE_BEGIN();\r
5c08e117 2345\r
9aa7ba01 2346 if (Option->Description == NULL) {\r
2347 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting from unknown device path\n"));\r
2348 } else {\r
2349 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Booting %S\n", Option->Description));\r
ab8cc80b 2350 }\r
9aa7ba01 2351 \r
9972247d 2352 DEBUG_CODE_END();\r
ab8cc80b 2353 \r
79b7a6a1 2354 //\r
2355 // Report status code for OS Loader LoadImage.\r
2356 //\r
2357 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));\r
9972247d 2358 Status = gBS->LoadImage (\r
2359 TRUE,\r
2360 gImageHandle,\r
2361 DevicePath,\r
2362 NULL,\r
2363 0,\r
2364 &ImageHandle\r
2365 );\r
5c08e117 2366\r
5c08e117 2367 //\r
9972247d 2368 // If we didn't find an image directly, we need to try as if it is a removable device boot option\r
2369 // and load the image according to the default boot behavior for removable device.\r
5c08e117 2370 //\r
9972247d 2371 if (EFI_ERROR (Status)) {\r
2372 //\r
2373 // check if there is a bootable removable media could be found in this device path ,\r
2374 // and get the bootable media handle\r
2375 //\r
2376 Handle = BdsLibGetBootableHandle(DevicePath);\r
cb38c322 2377 if (Handle != NULL) {\r
2378 //\r
2379 // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media\r
2380 // machinename is ia32, ia64, x64, ...\r
2381 //\r
2382 FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME);\r
2383 if (FilePath != NULL) {\r
2384 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad));\r
2385 Status = gBS->LoadImage (\r
2386 TRUE,\r
2387 gImageHandle,\r
2388 FilePath,\r
2389 NULL,\r
2390 0,\r
2391 &ImageHandle\r
2392 );\r
9972247d 2393 }\r
2394 }\r
5c08e117 2395 }\r
5c08e117 2396 }\r
2397 //\r
2398 // Provide the image with it's load options\r
2399 //\r
cb38c322 2400 if ((ImageHandle == NULL) || (EFI_ERROR(Status))) {\r
2401 //\r
2402 // Report Status Code to indicate that the failure to load boot option\r
2403 //\r
2404 REPORT_STATUS_CODE (\r
2405 EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
2406 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_LOAD_ERROR)\r
2407 ); \r
9972247d 2408 goto Done;\r
2409 }\r
cb38c322 2410\r
5c08e117 2411 Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);\r
2412 ASSERT_EFI_ERROR (Status);\r
2413\r
2414 if (Option->LoadOptionsSize != 0) {\r
2415 ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;\r
2416 ImageInfo->LoadOptions = Option->LoadOptions;\r
2417 }\r
bf0712ae
ED
2418\r
2419 //\r
2420 // Clean to NULL because the image is loaded directly from the firmwares boot manager.\r
2421 //\r
2422 ImageInfo->ParentHandle = NULL;\r
2423\r
5c08e117 2424 //\r
2425 // Before calling the image, enable the Watchdog Timer for\r
2426 // the 5 Minute period\r
2427 //\r
2428 gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);\r
2429\r
cd6a3b15 2430 //\r
2431 // Write boot to OS performance data for UEFI boot\r
2432 //\r
2433 PERF_CODE (\r
26c0ba77 2434 WriteBootToOsPerformanceData (NULL, NULL);\r
cd6a3b15 2435 );\r
2436\r
79b7a6a1 2437 //\r
2438 // Report status code for OS Loader StartImage.\r
2439 //\r
2440 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderStart));\r
2441\r
5c08e117 2442 Status = gBS->StartImage (ImageHandle, ExitDataSize, ExitData);\r
2443 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Image Return Status = %r\n", Status));\r
cb38c322 2444 if (EFI_ERROR (Status)) {\r
2445 //\r
2446 // Report Status Code to indicate that boot failure\r
2447 //\r
2448 REPORT_STATUS_CODE (\r
2449 EFI_ERROR_CODE | EFI_ERROR_MINOR,\r
2450 (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_EC_BOOT_OPTION_FAILED)\r
2451 );\r
2452 }\r
5c08e117 2453\r
2454 //\r
2455 // Clear the Watchdog Timer after the image returns\r
2456 //\r
2457 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);\r
2458\r
2459Done:\r
2df686c6 2460 //\r
2461 // Set Logo status invalid after trying one boot option\r
2462 //\r
2463 BootLogo = NULL;\r
2464 StatusLogo = gBS->LocateProtocol (&gEfiBootLogoProtocolGuid, NULL, (VOID **) &BootLogo);\r
2465 if (!EFI_ERROR (StatusLogo) && (BootLogo != NULL)) {\r
2466 BootLogo->SetBootLogo (BootLogo, NULL, 0, 0, 0, 0);\r
2467 }\r
2468\r
5c08e117 2469 //\r
2470 // Clear Boot Current\r
69fc8f08 2471 // Deleting variable with current implementation shouldn't fail.\r
5c08e117 2472 //\r
2473 gRT->SetVariable (\r
2474 L"BootCurrent",\r
2475 &gEfiGlobalVariableGuid,\r
2476 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
2477 0,\r
69fc8f08 2478 NULL\r
5c08e117 2479 );\r
2480\r
2481 return Status;\r
2482}\r
2483\r
2484\r
2485/**\r
2486 Expand a device path that starts with a hard drive media device path node to be a\r
2487 full device path that includes the full hardware path to the device. We need\r
2488 to do this so it can be booted. As an optimization the front match (the part point\r
2489 to the partition node. E.g. ACPI() /PCI()/ATA()/Partition() ) is saved in a variable\r
2490 so a connect all is not required on every boot. All successful history device path\r
2491 which point to partition node (the front part) will be saved.\r
2492\r
2493 @param HardDriveDevicePath EFI Device Path to boot, if it starts with a hard\r
2494 drive media device path.\r
2495 @return A Pointer to the full device path or NULL if a valid Hard Drive devic path\r
2496 cannot be found.\r
2497\r
2498**/\r
2499EFI_DEVICE_PATH_PROTOCOL *\r
2500EFIAPI\r
2501BdsExpandPartitionPartialDevicePathToFull (\r
2502 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath\r
2503 )\r
2504{\r
2505 EFI_STATUS Status;\r
2506 UINTN BlockIoHandleCount;\r
2507 EFI_HANDLE *BlockIoBuffer;\r
2508 EFI_DEVICE_PATH_PROTOCOL *FullDevicePath;\r
2509 EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath;\r
2510 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
2511 UINTN Index;\r
2512 UINTN InstanceNum;\r
2513 EFI_DEVICE_PATH_PROTOCOL *CachedDevicePath;\r
2514 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;\r
2515 UINTN CachedDevicePathSize;\r
2516 BOOLEAN DeviceExist;\r
2517 BOOLEAN NeedAdjust;\r
2518 EFI_DEVICE_PATH_PROTOCOL *Instance;\r
2519 UINTN Size;\r
2520\r
2521 FullDevicePath = NULL;\r
2522 //\r
e24fc103 2523 // Check if there is prestore HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable.\r
5c08e117 2524 // If exist, search the front path which point to partition node in the variable instants.\r
e24fc103 2525 // If fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, reconnect all and search in all system\r
5c08e117 2526 //\r
2527 CachedDevicePath = BdsLibGetVariableAndSize (\r
e24fc103
LG
2528 HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
2529 &gHdBootDevicePathVariablGuid,\r
5c08e117 2530 &CachedDevicePathSize\r
2531 );\r
128efbbc 2532\r
5c08e117 2533 if (CachedDevicePath != NULL) {\r
2534 TempNewDevicePath = CachedDevicePath;\r
2535 DeviceExist = FALSE;\r
2536 NeedAdjust = FALSE;\r
2537 do {\r
2538 //\r
2539 // Check every instance of the variable\r
2540 // First, check whether the instance contain the partition node, which is needed for distinguishing multi\r
2541 // partial partition boot option. Second, check whether the instance could be connected.\r
2542 //\r
2543 Instance = GetNextDevicePathInstance (&TempNewDevicePath, &Size);\r
2544 if (MatchPartitionDevicePathNode (Instance, HardDriveDevicePath)) {\r
2545 //\r
2546 // Connect the device path instance, the device path point to hard drive media device path node\r
2547 // e.g. ACPI() /PCI()/ATA()/Partition()\r
2548 //\r
2549 Status = BdsLibConnectDevicePath (Instance);\r
2550 if (!EFI_ERROR (Status)) {\r
2551 DeviceExist = TRUE;\r
2552 break;\r
2553 }\r
2554 }\r
2555 //\r
2556 // Come here means the first instance is not matched\r
2557 //\r
2558 NeedAdjust = TRUE;\r
2559 FreePool(Instance);\r
2560 } while (TempNewDevicePath != NULL);\r
2561\r
2562 if (DeviceExist) {\r
2563 //\r
2564 // Find the matched device path.\r
2565 // Append the file path information from the boot option and return the fully expanded device path.\r
2566 //\r
2567 DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);\r
2568 FullDevicePath = AppendDevicePath (Instance, DevicePath);\r
2569\r
2570 //\r
e24fc103 2571 // Adjust the HD_BOOT_DEVICE_PATH_VARIABLE_NAME instances sequence if the matched one is not first one.\r
5c08e117 2572 //\r
2573 if (NeedAdjust) {\r
2574 //\r
2575 // First delete the matched instance.\r
2576 //\r
2577 TempNewDevicePath = CachedDevicePath;\r
2578 CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, Instance );\r
2579 FreePool (TempNewDevicePath);\r
128efbbc 2580\r
5c08e117 2581 //\r
2582 // Second, append the remaining path after the matched instance\r
2583 //\r
2584 TempNewDevicePath = CachedDevicePath;\r
2585 CachedDevicePath = AppendDevicePathInstance (Instance, CachedDevicePath );\r
2586 FreePool (TempNewDevicePath);\r
2587 //\r
2588 // Save the matching Device Path so we don't need to do a connect all next time\r
69fc8f08 2589 // Failure to set the variable only impacts the performance when next time expanding the short-form device path.\r
5c08e117 2590 //\r
2591 Status = gRT->SetVariable (\r
e24fc103
LG
2592 HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
2593 &gHdBootDevicePathVariablGuid,\r
5c08e117 2594 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
2595 GetDevicePathSize (CachedDevicePath),\r
2596 CachedDevicePath\r
2597 );\r
2598 }\r
128efbbc 2599\r
5c08e117 2600 FreePool (Instance);\r
2601 FreePool (CachedDevicePath);\r
2602 return FullDevicePath;\r
2603 }\r
2604 }\r
2605\r
2606 //\r
e24fc103 2607 // If we get here we fail to find or HD_BOOT_DEVICE_PATH_VARIABLE_NAME not exist, and now we need\r
5c08e117 2608 // to search all devices in the system for a matched partition\r
2609 //\r
2610 BdsLibConnectAllDriversToAllControllers ();\r
2611 Status = gBS->LocateHandleBuffer (ByProtocol, &gEfiBlockIoProtocolGuid, NULL, &BlockIoHandleCount, &BlockIoBuffer);\r
2612 if (EFI_ERROR (Status) || BlockIoHandleCount == 0 || BlockIoBuffer == NULL) {\r
2613 //\r
2614 // If there was an error or there are no device handles that support\r
2615 // the BLOCK_IO Protocol, then return.\r
2616 //\r
2617 return NULL;\r
2618 }\r
2619 //\r
2620 // Loop through all the device handles that support the BLOCK_IO Protocol\r
2621 //\r
2622 for (Index = 0; Index < BlockIoHandleCount; Index++) {\r
2623\r
2624 Status = gBS->HandleProtocol (BlockIoBuffer[Index], &gEfiDevicePathProtocolGuid, (VOID *) &BlockIoDevicePath);\r
2625 if (EFI_ERROR (Status) || BlockIoDevicePath == NULL) {\r
2626 continue;\r
2627 }\r
2628\r
2629 if (MatchPartitionDevicePathNode (BlockIoDevicePath, HardDriveDevicePath)) {\r
2630 //\r
2631 // Find the matched partition device path\r
2632 //\r
2633 DevicePath = NextDevicePathNode ((EFI_DEVICE_PATH_PROTOCOL *) HardDriveDevicePath);\r
2634 FullDevicePath = AppendDevicePath (BlockIoDevicePath, DevicePath);\r
2635\r
2636 //\r
e24fc103 2637 // Save the matched partition device path in HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable\r
5c08e117 2638 //\r
2639 if (CachedDevicePath != NULL) {\r
2640 //\r
e24fc103 2641 // Save the matched partition device path as first instance of HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable\r
5c08e117 2642 //\r
2643 if (BdsLibMatchDevicePaths (CachedDevicePath, BlockIoDevicePath)) {\r
2644 TempNewDevicePath = CachedDevicePath;\r
2645 CachedDevicePath = BdsLibDelPartMatchInstance (CachedDevicePath, BlockIoDevicePath);\r
2646 FreePool(TempNewDevicePath);\r
e5a9b63c 2647 }\r
5c08e117 2648\r
e5a9b63c 2649 if (CachedDevicePath != NULL) {\r
5c08e117 2650 TempNewDevicePath = CachedDevicePath;\r
2651 CachedDevicePath = AppendDevicePathInstance (BlockIoDevicePath, CachedDevicePath);\r
2652 FreePool(TempNewDevicePath);\r
e5a9b63c
RN
2653 } else {\r
2654 CachedDevicePath = DuplicateDevicePath (BlockIoDevicePath);\r
5c08e117 2655 }\r
e5a9b63c 2656\r
5c08e117 2657 //\r
2658 // Here limit the device path instance number to 12, which is max number for a system support 3 IDE controller\r
e24fc103
LG
2659 // If the user try to boot many OS in different HDs or partitions, in theory, \r
2660 // the HD_BOOT_DEVICE_PATH_VARIABLE_NAME variable maybe become larger and larger.\r
5c08e117 2661 //\r
2662 InstanceNum = 0;\r
2663 ASSERT (CachedDevicePath != NULL);\r
2664 TempNewDevicePath = CachedDevicePath;\r
2665 while (!IsDevicePathEnd (TempNewDevicePath)) {\r
2666 TempNewDevicePath = NextDevicePathNode (TempNewDevicePath);\r
2667 //\r
2668 // Parse one instance\r
2669 //\r
2670 while (!IsDevicePathEndType (TempNewDevicePath)) {\r
2671 TempNewDevicePath = NextDevicePathNode (TempNewDevicePath);\r
2672 }\r
2673 InstanceNum++;\r
2674 //\r
2675 // If the CachedDevicePath variable contain too much instance, only remain 12 instances.\r
2676 //\r
2677 if (InstanceNum >= 12) {\r
2678 SetDevicePathEndNode (TempNewDevicePath);\r
2679 break;\r
2680 }\r
2681 }\r
2682 } else {\r
2683 CachedDevicePath = DuplicateDevicePath (BlockIoDevicePath);\r
2684 }\r
2685\r
2686 //\r
2687 // Save the matching Device Path so we don't need to do a connect all next time\r
69fc8f08 2688 // Failure to set the variable only impacts the performance when next time expanding the short-form device path.\r
5c08e117 2689 //\r
2690 Status = gRT->SetVariable (\r
e24fc103
LG
2691 HD_BOOT_DEVICE_PATH_VARIABLE_NAME,\r
2692 &gHdBootDevicePathVariablGuid,\r
5c08e117 2693 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
2694 GetDevicePathSize (CachedDevicePath),\r
2695 CachedDevicePath\r
2696 );\r
2697\r
2698 break;\r
2699 }\r
2700 }\r
128efbbc 2701\r
cd730ec0 2702 if (CachedDevicePath != NULL) {\r
2703 FreePool (CachedDevicePath);\r
2704 }\r
5c08e117 2705 if (BlockIoBuffer != NULL) {\r
2706 FreePool (BlockIoBuffer);\r
2707 }\r
2708 return FullDevicePath;\r
2709}\r
2710\r
2711/**\r
2712 Check whether there is a instance in BlockIoDevicePath, which contain multi device path\r
2713 instances, has the same partition node with HardDriveDevicePath device path\r
2714\r
2715 @param BlockIoDevicePath Multi device path instances which need to check\r
2716 @param HardDriveDevicePath A device path which starts with a hard drive media\r
2717 device path.\r
2718\r
2719 @retval TRUE There is a matched device path instance.\r
2720 @retval FALSE There is no matched device path instance.\r
2721\r
2722**/\r
2723BOOLEAN\r
2724EFIAPI\r
2725MatchPartitionDevicePathNode (\r
2726 IN EFI_DEVICE_PATH_PROTOCOL *BlockIoDevicePath,\r
2727 IN HARDDRIVE_DEVICE_PATH *HardDriveDevicePath\r
2728 )\r
2729{\r
2730 HARDDRIVE_DEVICE_PATH *TmpHdPath;\r
2731 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
2732 BOOLEAN Match;\r
2733 EFI_DEVICE_PATH_PROTOCOL *BlockIoHdDevicePathNode;\r
2734\r
2735 if ((BlockIoDevicePath == NULL) || (HardDriveDevicePath == NULL)) {\r
2736 return FALSE;\r
2737 }\r
128efbbc 2738\r
5c08e117 2739 //\r
2740 // Make PreviousDevicePath == the device path node before the end node\r
2741 //\r
2742 DevicePath = BlockIoDevicePath;\r
2743 BlockIoHdDevicePathNode = NULL;\r
2744\r
2745 //\r
2746 // find the partition device path node\r
2747 //\r
2748 while (!IsDevicePathEnd (DevicePath)) {\r
2749 if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&\r
2750 (DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)\r
2751 ) {\r
2752 BlockIoHdDevicePathNode = DevicePath;\r
2753 break;\r
2754 }\r
2755\r
2756 DevicePath = NextDevicePathNode (DevicePath);\r
2757 }\r
2758\r
2759 if (BlockIoHdDevicePathNode == NULL) {\r
2760 return FALSE;\r
2761 }\r
2762 //\r
2763 // See if the harddrive device path in blockio matches the orig Hard Drive Node\r
2764 //\r
2765 TmpHdPath = (HARDDRIVE_DEVICE_PATH *) BlockIoHdDevicePathNode;\r
2766 Match = FALSE;\r
128efbbc 2767\r
5c08e117 2768 //\r
2769 // Check for the match\r
2770 //\r
2771 if ((TmpHdPath->MBRType == HardDriveDevicePath->MBRType) &&\r
2772 (TmpHdPath->SignatureType == HardDriveDevicePath->SignatureType)) {\r
2773 switch (TmpHdPath->SignatureType) {\r
2774 case SIGNATURE_TYPE_GUID:\r
2775 Match = CompareGuid ((EFI_GUID *)TmpHdPath->Signature, (EFI_GUID *)HardDriveDevicePath->Signature);\r
2776 break;\r
2777 case SIGNATURE_TYPE_MBR:\r
2778 Match = (BOOLEAN)(*((UINT32 *)(&(TmpHdPath->Signature[0]))) == ReadUnaligned32((UINT32 *)(&(HardDriveDevicePath->Signature[0]))));\r
2779 break;\r
2780 default:\r
2781 Match = FALSE;\r
2782 break;\r
2783 }\r
2784 }\r
2785\r
2786 return Match;\r
2787}\r
2788\r
2789/**\r
2790 Delete the boot option associated with the handle passed in.\r
2791\r
2792 @param Handle The handle which present the device path to create\r
2793 boot option\r
2794\r
2795 @retval EFI_SUCCESS Delete the boot option success\r
2796 @retval EFI_NOT_FOUND If the Device Path is not found in the system\r
2797 @retval EFI_OUT_OF_RESOURCES Lack of memory resource\r
2798 @retval Other Error return value from SetVariable()\r
2799\r
2800**/\r
2801EFI_STATUS\r
2802BdsLibDeleteOptionFromHandle (\r
2803 IN EFI_HANDLE Handle\r
2804 )\r
2805{\r
2806 UINT16 *BootOrder;\r
2807 UINT8 *BootOptionVar;\r
2808 UINTN BootOrderSize;\r
2809 UINTN BootOptionSize;\r
2810 EFI_STATUS Status;\r
2811 UINTN Index;\r
2812 UINT16 BootOption[BOOT_OPTION_MAX_CHAR];\r
2813 UINTN DevicePathSize;\r
2814 UINTN OptionDevicePathSize;\r
2815 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
2816 EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;\r
2817 UINT8 *TempPtr;\r
2818\r
2819 Status = EFI_SUCCESS;\r
2820 BootOrder = NULL;\r
2821 BootOrderSize = 0;\r
2822\r
2823 //\r
2824 // Check "BootOrder" variable, if no, means there is no any boot order.\r
2825 //\r
2826 BootOrder = BdsLibGetVariableAndSize (\r
2827 L"BootOrder",\r
2828 &gEfiGlobalVariableGuid,\r
2829 &BootOrderSize\r
2830 );\r
2831 if (BootOrder == NULL) {\r
2832 return EFI_NOT_FOUND;\r
2833 }\r
2834\r
2835 //\r
2836 // Convert device handle to device path protocol instance\r
2837 //\r
2838 DevicePath = DevicePathFromHandle (Handle);\r
2839 if (DevicePath == NULL) {\r
2840 return EFI_NOT_FOUND;\r
2841 }\r
2842 DevicePathSize = GetDevicePathSize (DevicePath);\r
2843\r
2844 //\r
2845 // Loop all boot order variable and find the matching device path\r
2846 //\r
2847 Index = 0;\r
2848 while (Index < BootOrderSize / sizeof (UINT16)) {\r
2849 UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);\r
2850 BootOptionVar = BdsLibGetVariableAndSize (\r
2851 BootOption,\r
2852 &gEfiGlobalVariableGuid,\r
2853 &BootOptionSize\r
2854 );\r
128efbbc 2855\r
5c08e117 2856 if (BootOptionVar == NULL) {\r
2857 FreePool (BootOrder);\r
2858 return EFI_OUT_OF_RESOURCES;\r
2859 }\r
2860\r
8c08a567
ED
2861 if (!ValidateOption(BootOptionVar, BootOptionSize)) {\r
2862 BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize);\r
2863 FreePool (BootOptionVar);\r
2864 Index++;\r
2865 continue;\r
2866 }\r
2867\r
5c08e117 2868 TempPtr = BootOptionVar;\r
2869 TempPtr += sizeof (UINT32) + sizeof (UINT16);\r
2870 TempPtr += StrSize ((CHAR16 *) TempPtr);\r
2871 OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
2872 OptionDevicePathSize = GetDevicePathSize (OptionDevicePath);\r
2873\r
2874 //\r
2875 // Check whether the device path match\r
2876 //\r
2877 if ((OptionDevicePathSize == DevicePathSize) &&\r
2878 (CompareMem (DevicePath, OptionDevicePath, DevicePathSize) == 0)) {\r
2879 BdsDeleteBootOption (BootOrder[Index], BootOrder, &BootOrderSize);\r
2880 FreePool (BootOptionVar);\r
2881 break;\r
2882 }\r
2883\r
2884 FreePool (BootOptionVar);\r
2885 Index++;\r
2886 }\r
2887\r
2888 //\r
2889 // Adjust number of boot option for "BootOrder" variable.\r
2890 //\r
2891 Status = gRT->SetVariable (\r
2892 L"BootOrder",\r
2893 &gEfiGlobalVariableGuid,\r
2894 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
2895 BootOrderSize,\r
2896 BootOrder\r
2897 );\r
69fc8f08
RN
2898 //\r
2899 // Shrinking variable with existing variable implementation shouldn't fail.\r
2900 //\r
2901 ASSERT_EFI_ERROR (Status);\r
5c08e117 2902\r
2903 FreePool (BootOrder);\r
2904\r
2905 return Status;\r
2906}\r
2907\r
2908\r
2909/**\r
3384a9bc 2910 Delete all invalid EFI boot options.\r
5c08e117 2911\r
2912 @retval EFI_SUCCESS Delete all invalid boot option success\r
2913 @retval EFI_NOT_FOUND Variable "BootOrder" is not found\r
2914 @retval EFI_OUT_OF_RESOURCES Lack of memory resource\r
2915 @retval Other Error return value from SetVariable()\r
2916\r
2917**/\r
2918EFI_STATUS\r
2919BdsDeleteAllInvalidEfiBootOption (\r
2920 VOID\r
2921 )\r
2922{\r
2923 UINT16 *BootOrder;\r
2924 UINT8 *BootOptionVar;\r
2925 UINTN BootOrderSize;\r
2926 UINTN BootOptionSize;\r
2927 EFI_STATUS Status;\r
2928 UINTN Index;\r
2929 UINTN Index2;\r
2930 UINT16 BootOption[BOOT_OPTION_MAX_CHAR];\r
2931 EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;\r
2932 UINT8 *TempPtr;\r
3384a9bc 2933 CHAR16 *Description;\r
8c08a567 2934 BOOLEAN Corrupted;\r
5c08e117 2935\r
8c08a567
ED
2936 Status = EFI_SUCCESS;\r
2937 BootOrder = NULL;\r
2938 Description = NULL;\r
2939 OptionDevicePath = NULL;\r
2940 BootOrderSize = 0;\r
2941 Corrupted = FALSE;\r
5c08e117 2942\r
2943 //\r
2944 // Check "BootOrder" variable firstly, this variable hold the number of boot options\r
2945 //\r
2946 BootOrder = BdsLibGetVariableAndSize (\r
2947 L"BootOrder",\r
2948 &gEfiGlobalVariableGuid,\r
2949 &BootOrderSize\r
2950 );\r
2951 if (NULL == BootOrder) {\r
2952 return EFI_NOT_FOUND;\r
2953 }\r
2954\r
2955 Index = 0;\r
2956 while (Index < BootOrderSize / sizeof (UINT16)) {\r
2957 UnicodeSPrint (BootOption, sizeof (BootOption), L"Boot%04x", BootOrder[Index]);\r
2958 BootOptionVar = BdsLibGetVariableAndSize (\r
2959 BootOption,\r
2960 &gEfiGlobalVariableGuid,\r
2961 &BootOptionSize\r
2962 );\r
2963 if (NULL == BootOptionVar) {\r
2964 FreePool (BootOrder);\r
2965 return EFI_OUT_OF_RESOURCES;\r
2966 }\r
2967\r
8c08a567
ED
2968 if (!ValidateOption(BootOptionVar, BootOptionSize)) {\r
2969 Corrupted = TRUE;\r
2970 } else {\r
2971 TempPtr = BootOptionVar;\r
2972 TempPtr += sizeof (UINT32) + sizeof (UINT16);\r
2973 Description = (CHAR16 *) TempPtr;\r
2974 TempPtr += StrSize ((CHAR16 *) TempPtr);\r
2975 OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
5c08e117 2976\r
8c08a567
ED
2977 //\r
2978 // Skip legacy boot option (BBS boot device)\r
2979 //\r
2980 if ((DevicePathType (OptionDevicePath) == BBS_DEVICE_PATH) &&\r
2981 (DevicePathSubType (OptionDevicePath) == BBS_BBS_DP)) {\r
2982 FreePool (BootOptionVar);\r
2983 Index++;\r
2984 continue;\r
2985 }\r
5c08e117 2986 }\r
2987\r
8c08a567 2988 if (Corrupted || !BdsLibIsValidEFIBootOptDevicePathExt (OptionDevicePath, FALSE, Description)) {\r
5c08e117 2989 //\r
2990 // Delete this invalid boot option "Boot####"\r
2991 //\r
2992 Status = gRT->SetVariable (\r
2993 BootOption,\r
2994 &gEfiGlobalVariableGuid,\r
2995 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
2996 0,\r
2997 NULL\r
2998 );\r
2999 //\r
69fc8f08
RN
3000 // Deleting variable with current variable implementation shouldn't fail.\r
3001 //\r
3002 ASSERT_EFI_ERROR (Status);\r
3003 //\r
5c08e117 3004 // Mark this boot option in boot order as deleted\r
3005 //\r
3006 BootOrder[Index] = 0xffff;\r
8c08a567 3007 Corrupted = FALSE;\r
5c08e117 3008 }\r
3009\r
3010 FreePool (BootOptionVar);\r
3011 Index++;\r
3012 }\r
3013\r
3014 //\r
3015 // Adjust boot order array\r
3016 //\r
3017 Index2 = 0;\r
3018 for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {\r
3019 if (BootOrder[Index] != 0xffff) {\r
3020 BootOrder[Index2] = BootOrder[Index];\r
3021 Index2 ++;\r
3022 }\r
3023 }\r
3024 Status = gRT->SetVariable (\r
3025 L"BootOrder",\r
3026 &gEfiGlobalVariableGuid,\r
3027 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
3028 Index2 * sizeof (UINT16),\r
3029 BootOrder\r
3030 );\r
69fc8f08
RN
3031 //\r
3032 // Shrinking variable with current variable implementation shouldn't fail.\r
3033 //\r
3034 ASSERT_EFI_ERROR (Status);\r
5c08e117 3035\r
3036 FreePool (BootOrder);\r
3037\r
3038 return Status;\r
3039}\r
3040\r
3041\r
3042/**\r
3384a9bc 3043 For EFI boot option, BDS separate them as six types:\r
128efbbc 3044 1. Network - The boot option points to the SimpleNetworkProtocol device.\r
3384a9bc 3045 Bds will try to automatically create this type boot option when enumerate.\r
128efbbc 3046 2. Shell - The boot option points to internal flash shell.\r
3384a9bc 3047 Bds will try to automatically create this type boot option when enumerate.\r
3048 3. Removable BlockIo - The boot option only points to the removable media\r
3049 device, like USB flash disk, DVD, Floppy etc.\r
3050 These device should contain a *removable* blockIo\r
3051 protocol in their device handle.\r
128efbbc 3052 Bds will try to automatically create this type boot option\r
3384a9bc 3053 when enumerate.\r
128efbbc 3054 4. Fixed BlockIo - The boot option only points to a Fixed blockIo device,\r
3384a9bc 3055 like HardDisk.\r
3056 These device should contain a *fixed* blockIo\r
3057 protocol in their device handle.\r
3058 BDS will skip fixed blockIo devices, and NOT\r
128efbbc 3059 automatically create boot option for them. But BDS\r
3060 will help to delete those fixed blockIo boot option,\r
3384a9bc 3061 whose description rule conflict with other auto-created\r
3062 boot options.\r
128efbbc 3063 5. Non-BlockIo Simplefile - The boot option points to a device whose handle\r
3384a9bc 3064 has SimpleFileSystem Protocol, but has no blockio\r
3065 protocol. These devices do not offer blockIo\r
128efbbc 3066 protocol, but BDS still can get the\r
3384a9bc 3067 \EFI\BOOT\boot{machinename}.EFI by SimpleFileSystem\r
3068 Protocol.\r
128efbbc 3069 6. File - The boot option points to a file. These boot options are usually\r
3384a9bc 3070 created by user manually or OS loader. BDS will not delete or modify\r
128efbbc 3071 these boot options.\r
3072\r
3384a9bc 3073 This function will enumerate all possible boot device in the system, and\r
128efbbc 3074 automatically create boot options for Network, Shell, Removable BlockIo,\r
3384a9bc 3075 and Non-BlockIo Simplefile devices.\r
8d3b5aff 3076 It will only execute once of every boot.\r
128efbbc 3077\r
5c08e117 3078 @param BdsBootOptionList The header of the link list which indexed all\r
3079 current boot options\r
3080\r
3081 @retval EFI_SUCCESS Finished all the boot device enumerate and create\r
3082 the boot option base on that boot device\r
3083\r
e83c9064 3084 @retval EFI_OUT_OF_RESOURCES Failed to enumerate the boot device and create the boot option list\r
5c08e117 3085**/\r
3086EFI_STATUS\r
3087EFIAPI\r
3088BdsLibEnumerateAllBootOption (\r
3089 IN OUT LIST_ENTRY *BdsBootOptionList\r
3090 )\r
3091{\r
3092 EFI_STATUS Status;\r
3093 UINT16 FloppyNumber;\r
889a4bc2 3094 UINT16 HarddriveNumber;\r
5c08e117 3095 UINT16 CdromNumber;\r
3096 UINT16 UsbNumber;\r
3097 UINT16 MiscNumber;\r
8d3b5aff 3098 UINT16 ScsiNumber;\r
5c08e117 3099 UINT16 NonBlockNumber;\r
3100 UINTN NumberBlockIoHandles;\r
3101 EFI_HANDLE *BlockIoHandles;\r
3102 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
35bc0e9f
RN
3103 BOOLEAN Removable[2];\r
3104 UINTN RemovableIndex;\r
5c08e117 3105 UINTN Index;\r
a7a523e0 3106 UINTN NumOfLoadFileHandles;\r
3107 EFI_HANDLE *LoadFileHandles;\r
5c08e117 3108 UINTN FvHandleCount;\r
3109 EFI_HANDLE *FvHandleBuffer;\r
3110 EFI_FV_FILETYPE Type;\r
3111 UINTN Size;\r
3112 EFI_FV_FILE_ATTRIBUTES Attributes;\r
3113 UINT32 AuthenticationStatus;\r
8d3b5aff 3114 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
3115 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
5c08e117 3116 UINTN DevicePathType;\r
3117 CHAR16 Buffer[40];\r
3118 EFI_HANDLE *FileSystemHandles;\r
3119 UINTN NumberFileSystemHandles;\r
3120 BOOLEAN NeedDelete;\r
3121 EFI_IMAGE_DOS_HEADER DosHeader;\r
9aa7ba01 3122 CHAR8 *PlatLang;\r
3123 CHAR8 *LastLang;\r
5c08e117 3124 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;\r
3125 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
3126\r
889a4bc2
RN
3127 FloppyNumber = 0;\r
3128 HarddriveNumber = 0;\r
3129 CdromNumber = 0;\r
3130 UsbNumber = 0;\r
3131 MiscNumber = 0;\r
3132 ScsiNumber = 0;\r
3133 PlatLang = NULL;\r
3134 LastLang = NULL;\r
5c08e117 3135 ZeroMem (Buffer, sizeof (Buffer));\r
128efbbc 3136\r
5c08e117 3137 //\r
3138 // If the boot device enumerate happened, just get the boot\r
3139 // device from the boot order variable\r
3140 //\r
3141 if (mEnumBootDevice) {\r
f01b91ae
ED
3142 GetVariable2 (LAST_ENUM_LANGUAGE_VARIABLE_NAME, &gLastEnumLangGuid, (VOID**)&LastLang, NULL);\r
3143 GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&PlatLang, NULL);\r
0fa3ac1b
RN
3144 ASSERT (PlatLang != NULL);\r
3145 if ((LastLang != NULL) && (AsciiStrCmp (LastLang, PlatLang) == 0)) {\r
9aa7ba01 3146 Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");\r
0fa3ac1b
RN
3147 FreePool (LastLang);\r
3148 FreePool (PlatLang);\r
9aa7ba01 3149 return Status;\r
3150 } else {\r
3151 Status = gRT->SetVariable (\r
e24fc103
LG
3152 LAST_ENUM_LANGUAGE_VARIABLE_NAME,\r
3153 &gLastEnumLangGuid,\r
9aa7ba01 3154 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
0fa3ac1b 3155 AsciiStrSize (PlatLang),\r
9aa7ba01 3156 PlatLang\r
3157 );\r
69fc8f08
RN
3158 //\r
3159 // Failure to set the variable only impacts the performance next time enumerating the boot options.\r
3160 //\r
0fa3ac1b
RN
3161\r
3162 if (LastLang != NULL) {\r
3163 FreePool (LastLang);\r
3164 }\r
3165 FreePool (PlatLang);\r
9aa7ba01 3166 }\r
5c08e117 3167 }\r
128efbbc 3168\r
5c08e117 3169 //\r
3170 // Notes: this dirty code is to get the legacy boot option from the\r
3171 // BBS table and create to variable as the EFI boot option, it should\r
3172 // be removed after the CSM can provide legacy boot option directly\r
3173 //\r
3174 REFRESH_LEGACY_BOOT_OPTIONS;\r
3175\r
3176 //\r
3177 // Delete invalid boot option\r
3178 //\r
3179 BdsDeleteAllInvalidEfiBootOption ();\r
128efbbc 3180\r
5c08e117 3181 //\r
701e17e5
RN
3182 // Parse removable media followed by fixed media.\r
3183 // The Removable[] array is used by the for-loop below to create removable media boot options \r
3184 // at first, and then to create fixed media boot options.\r
5c08e117 3185 //\r
701e17e5
RN
3186 Removable[0] = FALSE;\r
3187 Removable[1] = TRUE;\r
3188\r
5c08e117 3189 gBS->LocateHandleBuffer (\r
3190 ByProtocol,\r
3191 &gEfiBlockIoProtocolGuid,\r
3192 NULL,\r
3193 &NumberBlockIoHandles,\r
3194 &BlockIoHandles\r
3195 );\r
128efbbc 3196\r
35bc0e9f
RN
3197 for (RemovableIndex = 0; RemovableIndex < 2; RemovableIndex++) {\r
3198 for (Index = 0; Index < NumberBlockIoHandles; Index++) {\r
3199 Status = gBS->HandleProtocol (\r
3200 BlockIoHandles[Index],\r
3201 &gEfiBlockIoProtocolGuid,\r
3202 (VOID **) &BlkIo\r
3203 );\r
3204 //\r
3205 // skip the fixed block io then the removable block io\r
3206 //\r
3207 if (EFI_ERROR (Status) || (BlkIo->Media->RemovableMedia == Removable[RemovableIndex])) {\r
5c08e117 3208 continue;\r
3209 }\r
35bc0e9f
RN
3210 DevicePath = DevicePathFromHandle (BlockIoHandles[Index]);\r
3211 DevicePathType = BdsGetBootTypeFromDevicePath (DevicePath);\r
5c08e117 3212\r
35bc0e9f
RN
3213 switch (DevicePathType) {\r
3214 case BDS_EFI_ACPI_FLOPPY_BOOT:\r
3215 if (FloppyNumber != 0) {\r
3216 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)), FloppyNumber);\r
3217 } else {\r
3218 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_FLOPPY)));\r
3219 }\r
3220 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
3221 FloppyNumber++;\r
3222 break;\r
128efbbc 3223\r
35bc0e9f 3224 //\r
889a4bc2 3225 // Assume a removable SATA device should be the DVD/CD device, a fixed SATA device should be the Hard Drive device.\r
35bc0e9f
RN
3226 //\r
3227 case BDS_EFI_MESSAGE_ATAPI_BOOT:\r
3228 case BDS_EFI_MESSAGE_SATA_BOOT:\r
889a4bc2
RN
3229 if (BlkIo->Media->RemovableMedia) {\r
3230 if (CdromNumber != 0) {\r
3231 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)), CdromNumber);\r
3232 } else {\r
3233 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_CD_DVD)));\r
3234 }\r
3235 CdromNumber++;\r
35bc0e9f 3236 } else {\r
889a4bc2
RN
3237 if (HarddriveNumber != 0) {\r
3238 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)), HarddriveNumber);\r
3239 } else {\r
3240 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_HARDDRIVE)));\r
3241 }\r
3242 HarddriveNumber++;\r
35bc0e9f
RN
3243 }\r
3244 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Buffer: %S\n", Buffer));\r
3245 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
35bc0e9f
RN
3246 break;\r
3247\r
3248 case BDS_EFI_MESSAGE_USB_DEVICE_BOOT:\r
3249 if (UsbNumber != 0) {\r
3250 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)), UsbNumber);\r
3251 } else {\r
3252 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_USB)));\r
3253 }\r
3254 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
3255 UsbNumber++;\r
3256 break;\r
5c08e117 3257\r
35bc0e9f
RN
3258 case BDS_EFI_MESSAGE_SCSI_BOOT:\r
3259 if (ScsiNumber != 0) {\r
3260 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)), ScsiNumber);\r
3261 } else {\r
3262 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_SCSI)));\r
3263 }\r
3264 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
3265 ScsiNumber++;\r
3266 break;\r
5c08e117 3267\r
35bc0e9f
RN
3268 case BDS_EFI_MESSAGE_MISC_BOOT:\r
3269 if (MiscNumber != 0) {\r
3270 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)), MiscNumber);\r
3271 } else {\r
3272 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_MISC)));\r
3273 }\r
3274 BdsLibBuildOptionFromHandle (BlockIoHandles[Index], BdsBootOptionList, Buffer);\r
3275 MiscNumber++;\r
3276 break;\r
5c08e117 3277\r
35bc0e9f
RN
3278 default:\r
3279 break;\r
9aa7ba01 3280 }\r
5c08e117 3281 }\r
3282 }\r
3283\r
3284 if (NumberBlockIoHandles != 0) {\r
3285 FreePool (BlockIoHandles);\r
3286 }\r
3287\r
3288 //\r
3289 // If there is simple file protocol which does not consume block Io protocol, create a boot option for it here.\r
3290 //\r
3291 NonBlockNumber = 0;\r
3292 gBS->LocateHandleBuffer (\r
3293 ByProtocol,\r
3294 &gEfiSimpleFileSystemProtocolGuid,\r
3295 NULL,\r
3296 &NumberFileSystemHandles,\r
3297 &FileSystemHandles\r
3298 );\r
3299 for (Index = 0; Index < NumberFileSystemHandles; Index++) {\r
3300 Status = gBS->HandleProtocol (\r
3301 FileSystemHandles[Index],\r
3302 &gEfiBlockIoProtocolGuid,\r
3303 (VOID **) &BlkIo\r
3304 );\r
3305 if (!EFI_ERROR (Status)) {\r
3306 //\r
3307 // Skip if the file system handle supports a BlkIo protocol,\r
3308 //\r
3309 continue;\r
3310 }\r
3311\r
3312 //\r
3313 // Do the removable Media thing. \EFI\BOOT\boot{machinename}.EFI\r
3314 // machinename is ia32, ia64, x64, ...\r
3315 //\r
35bc0e9f 3316 Hdr.Union = &HdrData;\r
5c08e117 3317 NeedDelete = TRUE;\r
3318 Status = BdsLibGetImageHeader (\r
3319 FileSystemHandles[Index],\r
c62dbf31 3320 EFI_REMOVABLE_MEDIA_FILE_NAME,\r
5c08e117 3321 &DosHeader,\r
3322 Hdr\r
3323 );\r
3324 if (!EFI_ERROR (Status) &&\r
3325 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&\r
3326 Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {\r
3327 NeedDelete = FALSE;\r
3328 }\r
3329\r
3330 if (NeedDelete) {\r
3331 //\r
3332 // No such file or the file is not a EFI application, delete this boot option\r
3333 //\r
3334 BdsLibDeleteOptionFromHandle (FileSystemHandles[Index]);\r
3335 } else {\r
9aa7ba01 3336 if (NonBlockNumber != 0) {\r
3337 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)), NonBlockNumber);\r
3338 } else {\r
3339 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NON_BLOCK)));\r
3340 }\r
5c08e117 3341 BdsLibBuildOptionFromHandle (FileSystemHandles[Index], BdsBootOptionList, Buffer);\r
3342 NonBlockNumber++;\r
3343 }\r
3344 }\r
3345\r
3346 if (NumberFileSystemHandles != 0) {\r
3347 FreePool (FileSystemHandles);\r
3348 }\r
3349\r
3350 //\r
3351 // Parse Network Boot Device\r
3352 //\r
a7a523e0 3353 NumOfLoadFileHandles = 0;\r
ff482c56 3354 //\r
a7a523e0 3355 // Search Load File protocol for PXE boot option.\r
ff482c56 3356 //\r
5c08e117 3357 gBS->LocateHandleBuffer (\r
3358 ByProtocol,\r
a7a523e0 3359 &gEfiLoadFileProtocolGuid,\r
5c08e117 3360 NULL,\r
a7a523e0 3361 &NumOfLoadFileHandles,\r
3362 &LoadFileHandles\r
5c08e117 3363 );\r
8d3b5aff 3364\r
a7a523e0 3365 for (Index = 0; Index < NumOfLoadFileHandles; Index++) {\r
9aa7ba01 3366 if (Index != 0) {\r
3367 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s %d", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)), Index);\r
3368 } else {\r
3369 UnicodeSPrint (Buffer, sizeof (Buffer), L"%s", BdsLibGetStringById (STRING_TOKEN (STR_DESCRIPTION_NETWORK)));\r
3370 }\r
a7a523e0 3371 BdsLibBuildOptionFromHandle (LoadFileHandles[Index], BdsBootOptionList, Buffer);\r
5c08e117 3372 }\r
3373\r
a7a523e0 3374 if (NumOfLoadFileHandles != 0) {\r
3375 FreePool (LoadFileHandles);\r
5c08e117 3376 }\r
3377\r
3378 //\r
3379 // Check if we have on flash shell\r
3380 //\r
3381 gBS->LocateHandleBuffer (\r
3382 ByProtocol,\r
3383 &gEfiFirmwareVolume2ProtocolGuid,\r
3384 NULL,\r
3385 &FvHandleCount,\r
3386 &FvHandleBuffer\r
3387 );\r
3388 for (Index = 0; Index < FvHandleCount; Index++) {\r
5c08e117 3389 gBS->HandleProtocol (\r
3390 FvHandleBuffer[Index],\r
3391 &gEfiFirmwareVolume2ProtocolGuid,\r
3392 (VOID **) &Fv\r
3393 );\r
3394\r
3395 Status = Fv->ReadFile (\r
3396 Fv,\r
d46f3632 3397 PcdGetPtr(PcdShellFile),\r
5c08e117 3398 NULL,\r
3399 &Size,\r
3400 &Type,\r
3401 &Attributes,\r
3402 &AuthenticationStatus\r
3403 );\r
3404 if (EFI_ERROR (Status)) {\r
3405 //\r
3406 // Skip if no shell file in the FV\r
3407 //\r
3408 continue;\r
3409 }\r
3410 //\r
3411 // Build the shell boot option\r
3412 //\r
3413 BdsLibBuildOptionFromShell (FvHandleBuffer[Index], BdsBootOptionList);\r
3414 }\r
3415\r
3416 if (FvHandleCount != 0) {\r
3417 FreePool (FvHandleBuffer);\r
3418 }\r
3419 //\r
3420 // Make sure every boot only have one time\r
3421 // boot device enumerate\r
3422 //\r
e83c9064 3423 Status = BdsLibBuildOptionFromVar (BdsBootOptionList, L"BootOrder");\r
5c08e117 3424 mEnumBootDevice = TRUE;\r
3425\r
e83c9064 3426 return Status;\r
5c08e117 3427}\r
3428\r
3429/**\r
3430 Build the boot option with the handle parsed in\r
3431\r
3432 @param Handle The handle which present the device path to create\r
3433 boot option\r
3434 @param BdsBootOptionList The header of the link list which indexed all\r
3435 current boot options\r
3436 @param String The description of the boot option.\r
3437\r
3438**/\r
3439VOID\r
3440EFIAPI\r
3441BdsLibBuildOptionFromHandle (\r
3442 IN EFI_HANDLE Handle,\r
3443 IN LIST_ENTRY *BdsBootOptionList,\r
3444 IN CHAR16 *String\r
3445 )\r
3446{\r
3447 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
128efbbc 3448\r
8d3b5aff 3449 DevicePath = DevicePathFromHandle (Handle);\r
5c08e117 3450\r
3451 //\r
3452 // Create and register new boot option\r
3453 //\r
3454 BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, String, L"BootOrder");\r
3455}\r
3456\r
3457\r
3458/**\r
3459 Build the on flash shell boot option with the handle parsed in.\r
3460\r
3461 @param Handle The handle which present the device path to create\r
3462 on flash shell boot option\r
3463 @param BdsBootOptionList The header of the link list which indexed all\r
3464 current boot options\r
3465\r
3466**/\r
3467VOID\r
3468EFIAPI\r
3469BdsLibBuildOptionFromShell (\r
3470 IN EFI_HANDLE Handle,\r
3471 IN OUT LIST_ENTRY *BdsBootOptionList\r
3472 )\r
3473{\r
3474 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
3475 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH ShellNode;\r
3476\r
3477 DevicePath = DevicePathFromHandle (Handle);\r
3478\r
3479 //\r
3480 // Build the shell device path\r
3481 //\r
d46f3632 3482 EfiInitializeFwVolDevicepathNode (&ShellNode, PcdGetPtr(PcdShellFile));\r
5c08e117 3483\r
3484 DevicePath = AppendDevicePathNode (DevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &ShellNode);\r
3485\r
3486 //\r
3487 // Create and register the shell boot option\r
3488 //\r
3489 BdsLibRegisterNewOption (BdsBootOptionList, DevicePath, L"EFI Internal Shell", L"BootOrder");\r
3490\r
3491}\r
3492\r
3493/**\r
3494 Boot from the UEFI spec defined "BootNext" variable.\r
3495\r
3496**/\r
3497VOID\r
3498EFIAPI\r
3499BdsLibBootNext (\r
3500 VOID\r
3501 )\r
3502{\r
69fc8f08 3503 EFI_STATUS Status;\r
5c08e117 3504 UINT16 *BootNext;\r
3505 UINTN BootNextSize;\r
3506 CHAR16 Buffer[20];\r
3507 BDS_COMMON_OPTION *BootOption;\r
3508 LIST_ENTRY TempList;\r
3509 UINTN ExitDataSize;\r
3510 CHAR16 *ExitData;\r
3511\r
3512 //\r
3513 // Init the boot option name buffer and temp link list\r
3514 //\r
3515 InitializeListHead (&TempList);\r
3516 ZeroMem (Buffer, sizeof (Buffer));\r
3517\r
3518 BootNext = BdsLibGetVariableAndSize (\r
3519 L"BootNext",\r
3520 &gEfiGlobalVariableGuid,\r
3521 &BootNextSize\r
3522 );\r
3523\r
3524 //\r
3525 // Clear the boot next variable first\r
3526 //\r
3527 if (BootNext != NULL) {\r
69fc8f08
RN
3528 Status = gRT->SetVariable (\r
3529 L"BootNext",\r
3530 &gEfiGlobalVariableGuid,\r
3531 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
3532 0,\r
3533 NULL\r
3534 );\r
3535 //\r
3536 // Deleting variable with current variable implementation shouldn't fail.\r
3537 //\r
3538 ASSERT_EFI_ERROR (Status);\r
5c08e117 3539\r
3540 //\r
3541 // Start to build the boot option and try to boot\r
3542 //\r
3543 UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *BootNext);\r
3544 BootOption = BdsLibVariableToOption (&TempList, Buffer);\r
3545 ASSERT (BootOption != NULL);\r
3546 BdsLibConnectDevicePath (BootOption->DevicePath);\r
3547 BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);\r
3548 }\r
3549\r
3550}\r
3551\r
3552/**\r
3553 Return the bootable media handle.\r
3554 First, check the device is connected\r
3555 Second, check whether the device path point to a device which support SimpleFileSystemProtocol,\r
3556 Third, detect the the default boot file in the Media, and return the removable Media handle.\r
3557\r
e83c9064 3558 @param DevicePath Device Path to a bootable device\r
5c08e117 3559\r
e83c9064 3560 @return The bootable media handle. If the media on the DevicePath is not bootable, NULL will return.\r
5c08e117 3561\r
3562**/\r
3563EFI_HANDLE\r
3564EFIAPI\r
3565BdsLibGetBootableHandle (\r
3566 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
3567 )\r
3568{\r
3569 EFI_STATUS Status;\r
ef949581 3570 EFI_TPL OldTpl;\r
5c08e117 3571 EFI_DEVICE_PATH_PROTOCOL *UpdatedDevicePath;\r
3572 EFI_DEVICE_PATH_PROTOCOL *DupDevicePath;\r
3573 EFI_HANDLE Handle;\r
3574 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
3575 VOID *Buffer;\r
3576 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
3577 UINTN Size;\r
3578 UINTN TempSize;\r
3579 EFI_HANDLE ReturnHandle;\r
3580 EFI_HANDLE *SimpleFileSystemHandles;\r
3581\r
3582 UINTN NumberSimpleFileSystemHandles;\r
3583 UINTN Index;\r
3584 EFI_IMAGE_DOS_HEADER DosHeader;\r
3585 EFI_IMAGE_OPTIONAL_HEADER_UNION HdrData;\r
3586 EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;\r
3587\r
3588 UpdatedDevicePath = DevicePath;\r
128efbbc 3589\r
ef949581
RN
3590 //\r
3591 // Enter to critical section to protect the acquired BlockIo instance \r
3592 // from getting released due to the USB mass storage hotplug event\r
3593 //\r
3594 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
3595\r
5c08e117 3596 //\r
3597 // Check whether the device is connected\r
3598 //\r
3599 Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &UpdatedDevicePath, &Handle);\r
3600 if (EFI_ERROR (Status)) {\r
3601 //\r
3602 // Skip the case that the boot option point to a simple file protocol which does not consume block Io protocol,\r
3603 //\r
3604 Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &UpdatedDevicePath, &Handle);\r
3605 if (EFI_ERROR (Status)) {\r
3606 //\r
3607 // Fail to find the proper BlockIo and simple file protocol, maybe because device not present, we need to connect it firstly\r
3608 //\r
3609 UpdatedDevicePath = DevicePath;\r
3610 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);\r
3611 gBS->ConnectController (Handle, NULL, NULL, TRUE);\r
3612 }\r
3613 } else {\r
e74f510b
RN
3614 //\r
3615 // For removable device boot option, its contained device path only point to the removable device handle, \r
3616 // should make sure all its children handles (its child partion or media handles) are created and connected. \r
3617 //\r
3618 gBS->ConnectController (Handle, NULL, NULL, TRUE); \r
5c08e117 3619 //\r
3620 // Get BlockIo protocol and check removable attribute\r
3621 //\r
3622 Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);\r
ef949581
RN
3623 ASSERT_EFI_ERROR (Status);\r
3624\r
5c08e117 3625 //\r
3626 // Issue a dummy read to the device to check for media change.\r
3627 // When the removable media is changed, any Block IO read/write will\r
3628 // cause the BlockIo protocol be reinstalled and EFI_MEDIA_CHANGED is\r
3629 // returned. After the Block IO protocol is reinstalled, subsequent\r
3630 // Block IO read/write will success.\r
3631 //\r
3632 Buffer = AllocatePool (BlockIo->Media->BlockSize);\r
3633 if (Buffer != NULL) {\r
3634 BlockIo->ReadBlocks (\r
3635 BlockIo,\r
3636 BlockIo->Media->MediaId,\r
3637 0,\r
3638 BlockIo->Media->BlockSize,\r
3639 Buffer\r
3640 );\r
3641 FreePool(Buffer);\r
3642 }\r
3643 }\r
3644\r
3645 //\r
3646 // Detect the the default boot file from removable Media\r
3647 //\r
3648\r
3649 //\r
3650 // 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
3651 // Try to locate the USB node device path first, if fail then use its previous PCI node to search\r
3652 //\r
3653 DupDevicePath = DuplicateDevicePath (DevicePath);\r
3654 ASSERT (DupDevicePath != NULL);\r
128efbbc 3655\r
5c08e117 3656 UpdatedDevicePath = DupDevicePath;\r
3657 Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &UpdatedDevicePath, &Handle);\r
3658 //\r
3659 // 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
3660 // Acpi()/Pci()/Usb() --> Acpi()/Pci()\r
3661 //\r
3662 if ((DevicePathType (UpdatedDevicePath) == MESSAGING_DEVICE_PATH) &&\r
3663 (DevicePathSubType (UpdatedDevicePath) == MSG_USB_DP)) {\r
3664 //\r
3665 // Remove the usb node, let the device path only point to PCI node\r
3666 //\r
3667 SetDevicePathEndNode (UpdatedDevicePath);\r
3668 UpdatedDevicePath = DupDevicePath;\r
3669 } else {\r
3670 UpdatedDevicePath = DevicePath;\r
3671 }\r
3672\r
3673 //\r
3674 // Get the device path size of boot option\r
3675 //\r
3676 Size = GetDevicePathSize(UpdatedDevicePath) - sizeof (EFI_DEVICE_PATH_PROTOCOL); // minus the end node\r
3677 ReturnHandle = NULL;\r
3678 gBS->LocateHandleBuffer (\r
3679 ByProtocol,\r
3680 &gEfiSimpleFileSystemProtocolGuid,\r
3681 NULL,\r
3682 &NumberSimpleFileSystemHandles,\r
3683 &SimpleFileSystemHandles\r
3684 );\r
3685 for (Index = 0; Index < NumberSimpleFileSystemHandles; Index++) {\r
3686 //\r
3687 // Get the device path size of SimpleFileSystem handle\r
3688 //\r
3689 TempDevicePath = DevicePathFromHandle (SimpleFileSystemHandles[Index]);\r
3690 TempSize = GetDevicePathSize (TempDevicePath)- sizeof (EFI_DEVICE_PATH_PROTOCOL); // minus the end node\r
3691 //\r
3692 // Check whether the device path of boot option is part of the SimpleFileSystem handle's device path\r
3693 //\r
3694 if (Size <= TempSize && CompareMem (TempDevicePath, UpdatedDevicePath, Size)==0) {\r
3695 //\r
3696 // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media\r
3697 // machinename is ia32, ia64, x64, ...\r
3698 //\r
3699 Hdr.Union = &HdrData;\r
3700 Status = BdsLibGetImageHeader (\r
3701 SimpleFileSystemHandles[Index],\r
c62dbf31 3702 EFI_REMOVABLE_MEDIA_FILE_NAME,\r
5c08e117 3703 &DosHeader,\r
3704 Hdr\r
3705 );\r
3706 if (!EFI_ERROR (Status) &&\r
3707 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) &&\r
3708 Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) {\r
3709 ReturnHandle = SimpleFileSystemHandles[Index];\r
3710 break;\r
3711 }\r
3712 }\r
3713 }\r
3714\r
3715 FreePool(DupDevicePath);\r
3716\r
3717 if (SimpleFileSystemHandles != NULL) {\r
3718 FreePool(SimpleFileSystemHandles);\r
3719 }\r
3720\r
ef949581
RN
3721 gBS->RestoreTPL (OldTpl);\r
3722\r
5c08e117 3723 return ReturnHandle;\r
3724}\r
3725\r
3726/**\r
3727 Check to see if the network cable is plugged in. If the DevicePath is not\r
3728 connected it will be connected.\r
3729\r
3730 @param DevicePath Device Path to check\r
3731\r
3732 @retval TRUE DevicePath points to an Network that is connected\r
3733 @retval FALSE DevicePath does not point to a bootable network\r
3734\r
3735**/\r
3736BOOLEAN\r
3737BdsLibNetworkBootWithMediaPresent (\r
3738 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
3739 )\r
3740{\r
3741 EFI_STATUS Status;\r
3742 EFI_DEVICE_PATH_PROTOCOL *UpdatedDevicePath;\r
3743 EFI_HANDLE Handle;\r
3744 EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r
3745 BOOLEAN MediaPresent;\r
e51e619e 3746 UINT32 InterruptStatus;\r
5c08e117 3747\r
3748 MediaPresent = FALSE;\r
3749\r
3750 UpdatedDevicePath = DevicePath;\r
ff482c56 3751 //\r
a7a523e0 3752 // Locate Load File Protocol for PXE boot option first\r
ff482c56 3753 //\r
a7a523e0 3754 Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &UpdatedDevicePath, &Handle);\r
5c08e117 3755 if (EFI_ERROR (Status)) {\r
3756 //\r
3757 // Device not present so see if we need to connect it\r
3758 //\r
3759 Status = BdsLibConnectDevicePath (DevicePath);\r
3760 if (!EFI_ERROR (Status)) {\r
3761 //\r
3762 // This one should work after we did the connect\r
3763 //\r
a7a523e0 3764 Status = gBS->LocateDevicePath (&gEfiLoadFileProtocolGuid, &UpdatedDevicePath, &Handle);\r
5c08e117 3765 }\r
3766 }\r
3767\r
3768 if (!EFI_ERROR (Status)) {\r
3769 Status = gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtocolGuid, (VOID **)&Snp);\r
ff482c56 3770 if (EFI_ERROR (Status)) {\r
3771 //\r
3772 // Failed to open SNP from this handle, try to get SNP from parent handle\r
3773 //\r
3774 UpdatedDevicePath = DevicePathFromHandle (Handle);\r
3775 if (UpdatedDevicePath != NULL) {\r
3776 Status = gBS->LocateDevicePath (&gEfiSimpleNetworkProtocolGuid, &UpdatedDevicePath, &Handle);\r
3777 if (!EFI_ERROR (Status)) {\r
3778 //\r
3779 // SNP handle found, get SNP from it\r
3780 //\r
3781 Status = gBS->HandleProtocol (Handle, &gEfiSimpleNetworkProtocolGuid, (VOID **) &Snp);\r
3782 }\r
3783 }\r
3784 }\r
3785\r
5c08e117 3786 if (!EFI_ERROR (Status)) {\r
3787 if (Snp->Mode->MediaPresentSupported) {\r
3788 if (Snp->Mode->State == EfiSimpleNetworkInitialized) {\r
e51e619e 3789 //\r
3790 // Invoke Snp->GetStatus() to refresh the media status\r
3791 //\r
3792 Snp->GetStatus (Snp, &InterruptStatus, NULL);\r
3793\r
5c08e117 3794 //\r
3795 // In case some one else is using the SNP check to see if it's connected\r
3796 //\r
3797 MediaPresent = Snp->Mode->MediaPresent;\r
3798 } else {\r
3799 //\r
3800 // No one is using SNP so we need to Start and Initialize so\r
3801 // MediaPresent will be valid.\r
3802 //\r
3803 Status = Snp->Start (Snp);\r
3804 if (!EFI_ERROR (Status)) {\r
3805 Status = Snp->Initialize (Snp, 0, 0);\r
3806 if (!EFI_ERROR (Status)) {\r
3807 MediaPresent = Snp->Mode->MediaPresent;\r
3808 Snp->Shutdown (Snp);\r
3809 }\r
3810 Snp->Stop (Snp);\r
3811 }\r
3812 }\r
3813 } else {\r
3814 MediaPresent = TRUE;\r
3815 }\r
3816 }\r
3817 }\r
3818\r
3819 return MediaPresent;\r
3820}\r
3821\r
3822/**\r
3823 For a bootable Device path, return its boot type.\r
3824\r
3825 @param DevicePath The bootable device Path to check\r
3826\r
128efbbc 3827 @retval BDS_EFI_MEDIA_HD_BOOT If given device path contains MEDIA_DEVICE_PATH type device path node\r
11c5022d 3828 which subtype is MEDIA_HARDDRIVE_DP\r
3829 @retval BDS_EFI_MEDIA_CDROM_BOOT If given device path contains MEDIA_DEVICE_PATH type device path node\r
3830 which subtype is MEDIA_CDROM_DP\r
3831 @retval BDS_EFI_ACPI_FLOPPY_BOOT If given device path contains ACPI_DEVICE_PATH type device path node\r
3832 which HID is floppy device.\r
3833 @retval BDS_EFI_MESSAGE_ATAPI_BOOT If given device path contains MESSAGING_DEVICE_PATH type device path node\r
3834 and its last device path node's subtype is MSG_ATAPI_DP.\r
3835 @retval BDS_EFI_MESSAGE_SCSI_BOOT If given device path contains MESSAGING_DEVICE_PATH type device path node\r
3836 and its last device path node's subtype is MSG_SCSI_DP.\r
3837 @retval BDS_EFI_MESSAGE_USB_DEVICE_BOOT If given device path contains MESSAGING_DEVICE_PATH type device path node\r
3838 and its last device path node's subtype is MSG_USB_DP.\r
5c08e117 3839 @retval BDS_EFI_MESSAGE_MISC_BOOT If the device path not contains any media device path node, and\r
11c5022d 3840 its last device path node point to a message device path node.\r
3841 @retval BDS_LEGACY_BBS_BOOT If given device path contains BBS_DEVICE_PATH type device path node.\r
128efbbc 3842 @retval BDS_EFI_UNSUPPORT An EFI Removable BlockIO device path not point to a media and message device,\r
5c08e117 3843\r
3844**/\r
3845UINT32\r
3846EFIAPI\r
3847BdsGetBootTypeFromDevicePath (\r
3848 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
3849 )\r
3850{\r
3851 ACPI_HID_DEVICE_PATH *Acpi;\r
3852 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
3853 EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;\r
ff482c56 3854 UINT32 BootType;\r
5c08e117 3855\r
3856 if (NULL == DevicePath) {\r
3857 return BDS_EFI_UNSUPPORT;\r
3858 }\r
3859\r
3860 TempDevicePath = DevicePath;\r
3861\r
3862 while (!IsDevicePathEndType (TempDevicePath)) {\r
3863 switch (DevicePathType (TempDevicePath)) {\r
3864 case BBS_DEVICE_PATH:\r
3865 return BDS_LEGACY_BBS_BOOT;\r
3866 case MEDIA_DEVICE_PATH:\r
3867 if (DevicePathSubType (TempDevicePath) == MEDIA_HARDDRIVE_DP) {\r
3868 return BDS_EFI_MEDIA_HD_BOOT;\r
3869 } else if (DevicePathSubType (TempDevicePath) == MEDIA_CDROM_DP) {\r
3870 return BDS_EFI_MEDIA_CDROM_BOOT;\r
128efbbc 3871 }\r
5c08e117 3872 break;\r
3873 case ACPI_DEVICE_PATH:\r
3874 Acpi = (ACPI_HID_DEVICE_PATH *) TempDevicePath;\r
3875 if (EISA_ID_TO_NUM (Acpi->HID) == 0x0604) {\r
3876 return BDS_EFI_ACPI_FLOPPY_BOOT;\r
3877 }\r
3878 break;\r
3879 case MESSAGING_DEVICE_PATH:\r
3880 //\r
3881 // Get the last device path node\r
3882 //\r
3883 LastDeviceNode = NextDevicePathNode (TempDevicePath);\r
3884 if (DevicePathSubType(LastDeviceNode) == MSG_DEVICE_LOGICAL_UNIT_DP) {\r
3885 //\r
3886 // if the next node type is Device Logical Unit, which specify the Logical Unit Number (LUN),\r
ff482c56 3887 // skip it\r
5c08e117 3888 //\r
3889 LastDeviceNode = NextDevicePathNode (LastDeviceNode);\r
3890 }\r
3891 //\r
3892 // if the device path not only point to driver device, it is not a messaging device path,\r
3893 //\r
3894 if (!IsDevicePathEndType (LastDeviceNode)) {\r
128efbbc 3895 break;\r
5c08e117 3896 }\r
3897\r
ff482c56 3898 switch (DevicePathSubType (TempDevicePath)) {\r
3899 case MSG_ATAPI_DP:\r
3900 BootType = BDS_EFI_MESSAGE_ATAPI_BOOT;\r
3901 break;\r
3902\r
3903 case MSG_USB_DP:\r
3904 BootType = BDS_EFI_MESSAGE_USB_DEVICE_BOOT;\r
3905 break;\r
3906\r
3907 case MSG_SCSI_DP:\r
3908 BootType = BDS_EFI_MESSAGE_SCSI_BOOT;\r
3909 break;\r
3910\r
3911 case MSG_SATA_DP:\r
3912 BootType = BDS_EFI_MESSAGE_SATA_BOOT;\r
3913 break;\r
3914\r
3915 case MSG_MAC_ADDR_DP:\r
3916 case MSG_VLAN_DP:\r
a7a523e0 3917 case MSG_IPv4_DP:\r
3918 case MSG_IPv6_DP:\r
ff482c56 3919 BootType = BDS_EFI_MESSAGE_MAC_BOOT;\r
3920 break;\r
3921\r
3922 default:\r
3923 BootType = BDS_EFI_MESSAGE_MISC_BOOT;\r
3924 break;\r
5c08e117 3925 }\r
ff482c56 3926 return BootType;\r
3927\r
5c08e117 3928 default:\r
3929 break;\r
3930 }\r
3931 TempDevicePath = NextDevicePathNode (TempDevicePath);\r
3932 }\r
3933\r
3934 return BDS_EFI_UNSUPPORT;\r
3935}\r
3936\r
3937/**\r
3938 Check whether the Device path in a boot option point to a valid bootable device,\r
3939 And if CheckMedia is true, check the device is ready to boot now.\r
3940\r
3941 @param DevPath the Device path in a boot option\r
3942 @param CheckMedia if true, check the device is ready to boot now.\r
3943\r
3944 @retval TRUE the Device path is valid\r
3945 @retval FALSE the Device path is invalid .\r
3946\r
3947**/\r
3948BOOLEAN\r
3949EFIAPI\r
3950BdsLibIsValidEFIBootOptDevicePath (\r
3951 IN EFI_DEVICE_PATH_PROTOCOL *DevPath,\r
3952 IN BOOLEAN CheckMedia\r
3953 )\r
3384a9bc 3954{\r
3955 return BdsLibIsValidEFIBootOptDevicePathExt (DevPath, CheckMedia, NULL);\r
3956}\r
3957\r
3958/**\r
3959 Check whether the Device path in a boot option point to a valid bootable device,\r
3960 And if CheckMedia is true, check the device is ready to boot now.\r
3961 If Description is not NULL and the device path point to a fixed BlockIo\r
3962 device, check the description whether conflict with other auto-created\r
3963 boot options.\r
3964\r
3965 @param DevPath the Device path in a boot option\r
3966 @param CheckMedia if true, check the device is ready to boot now.\r
3967 @param Description the description in a boot option\r
3968\r
3969 @retval TRUE the Device path is valid\r
3970 @retval FALSE the Device path is invalid .\r
3971\r
3972**/\r
3973BOOLEAN\r
3974EFIAPI\r
3975BdsLibIsValidEFIBootOptDevicePathExt (\r
3976 IN EFI_DEVICE_PATH_PROTOCOL *DevPath,\r
3977 IN BOOLEAN CheckMedia,\r
3978 IN CHAR16 *Description\r
3979 )\r
5c08e117 3980{\r
3981 EFI_STATUS Status;\r
3982 EFI_HANDLE Handle;\r
3983 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
3984 EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;\r
3985 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
3986\r
3987 TempDevicePath = DevPath;\r
3988 LastDeviceNode = DevPath;\r
128efbbc 3989\r
5c08e117 3990 //\r
a7a523e0 3991 // Check if it's a valid boot option for network boot device.\r
3992 // Check if there is EfiLoadFileProtocol installed. \r
3993 // If yes, that means there is a boot option for network.\r
5c08e117 3994 //\r
3995 Status = gBS->LocateDevicePath (\r
a7a523e0 3996 &gEfiLoadFileProtocolGuid,\r
5c08e117 3997 &TempDevicePath,\r
3998 &Handle\r
3999 );\r
4000 if (EFI_ERROR (Status)) {\r
4001 //\r
4002 // Device not present so see if we need to connect it\r
4003 //\r
4004 TempDevicePath = DevPath;\r
4005 BdsLibConnectDevicePath (TempDevicePath);\r
4006 Status = gBS->LocateDevicePath (\r
a7a523e0 4007 &gEfiLoadFileProtocolGuid,\r
5c08e117 4008 &TempDevicePath,\r
4009 &Handle\r
4010 );\r
4011 }\r
128efbbc 4012\r
5c08e117 4013 if (!EFI_ERROR (Status)) {\r
a7a523e0 4014 if (!IsDevicePathEnd (TempDevicePath)) {\r
4015 //\r
4016 // LoadFile protocol is not installed on handle with exactly the same DevPath\r
4017 //\r
4018 return FALSE;\r
4019 }\r
ff482c56 4020\r
a7a523e0 4021 if (CheckMedia) {\r
4022 //\r
4023 // Test if it is ready to boot now\r
4024 //\r
4025 if (BdsLibNetworkBootWithMediaPresent(DevPath)) {\r
5c08e117 4026 return TRUE;\r
4027 }\r
a7a523e0 4028 } else {\r
4029 return TRUE;\r
4030 } \r
5c08e117 4031 }\r
4032\r
4033 //\r
4034 // If the boot option point to a file, it is a valid EFI boot option,\r
4035 // and assume it is ready to boot now\r
4036 //\r
4037 while (!IsDevicePathEnd (TempDevicePath)) {\r
7389fdd0 4038 //\r
4039 // If there is USB Class or USB WWID device path node, treat it as valid EFI\r
4040 // Boot Option. BdsExpandUsbShortFormDevicePath () will be used to expand it\r
4041 // to full device path.\r
4042 //\r
4043 if ((DevicePathType (TempDevicePath) == MESSAGING_DEVICE_PATH) &&\r
4044 ((DevicePathSubType (TempDevicePath) == MSG_USB_CLASS_DP) ||\r
4045 (DevicePathSubType (TempDevicePath) == MSG_USB_WWID_DP))) {\r
4046 return TRUE;\r
4047 }\r
4048\r
4049 LastDeviceNode = TempDevicePath;\r
4050 TempDevicePath = NextDevicePathNode (TempDevicePath);\r
5c08e117 4051 }\r
4052 if ((DevicePathType (LastDeviceNode) == MEDIA_DEVICE_PATH) &&\r
4053 (DevicePathSubType (LastDeviceNode) == MEDIA_FILEPATH_DP)) {\r
4054 return TRUE;\r
4055 }\r
4056\r
4057 //\r
6617d838 4058 // Check if it's a valid boot option for internal FV application\r
5c08e117 4059 //\r
4060 if (EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode) != NULL) {\r
4061 //\r
6617d838 4062 // If the boot option point to internal FV application, make sure it is valid\r
5c08e117 4063 //\r
128efbbc 4064 TempDevicePath = DevPath;\r
6617d838
RN
4065 Status = BdsLibUpdateFvFileDevicePath (\r
4066 &TempDevicePath,\r
4067 EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode)\r
4068 );\r
5c08e117 4069 if (Status == EFI_ALREADY_STARTED) {\r
4070 return TRUE;\r
4071 } else {\r
4072 if (Status == EFI_SUCCESS) {\r
128efbbc 4073 FreePool (TempDevicePath);\r
5c08e117 4074 }\r
4075 return FALSE;\r
4076 }\r
4077 }\r
128efbbc 4078\r
5c08e117 4079 //\r
3384a9bc 4080 // If the boot option point to a blockIO device:\r
8d3b5aff 4081 // if it is a removable blockIo device, it is valid.\r
128efbbc 4082 // if it is a fixed blockIo device, check its description confliction.\r
5c08e117 4083 //\r
4084 TempDevicePath = DevPath;\r
4085 Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);\r
4086 if (EFI_ERROR (Status)) {\r
4087 //\r
4088 // Device not present so see if we need to connect it\r
4089 //\r
4090 Status = BdsLibConnectDevicePath (DevPath);\r
4091 if (!EFI_ERROR (Status)) {\r
4092 //\r
4093 // Try again to get the Block Io protocol after we did the connect\r
4094 //\r
4095 TempDevicePath = DevPath;\r
4096 Status = gBS->LocateDevicePath (&gEfiBlockIoProtocolGuid, &TempDevicePath, &Handle);\r
4097 }\r
4098 }\r
128efbbc 4099\r
5c08e117 4100 if (!EFI_ERROR (Status)) {\r
4101 Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);\r
4102 if (!EFI_ERROR (Status)) {\r
4103 if (CheckMedia) {\r
4104 //\r
4105 // Test if it is ready to boot now\r
4106 //\r
4107 if (BdsLibGetBootableHandle (DevPath) != NULL) {\r
4108 return TRUE;\r
4109 }\r
4110 } else {\r
4111 return TRUE;\r
4112 }\r
4113 }\r
4114 } else {\r
4115 //\r
4116 // 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
4117 //\r
4118 Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, &TempDevicePath, &Handle);\r
4119 if (!EFI_ERROR (Status)) {\r
4120 if (CheckMedia) {\r
4121 //\r
4122 // Test if it is ready to boot now\r
4123 //\r
4124 if (BdsLibGetBootableHandle (DevPath) != NULL) {\r
4125 return TRUE;\r
4126 }\r
4127 } else {\r
4128 return TRUE;\r
4129 }\r
4130 }\r
4131 }\r
4132\r
4133 return FALSE;\r
4134}\r
4135\r
4136\r
4137/**\r
4138 According to a file guild, check a Fv file device path is valid. If it is invalid,\r
4139 try to return the valid device path.\r
4140 FV address maybe changes for memory layout adjust from time to time, use this function\r
4141 could promise the Fv file device path is right.\r
4142\r
4143 @param DevicePath on input, the Fv file device path need to check on\r
4144 output, the updated valid Fv file device path\r
4145 @param FileGuid the Fv file guild\r
4146\r
4147 @retval EFI_INVALID_PARAMETER the input DevicePath or FileGuid is invalid\r
4148 parameter\r
4149 @retval EFI_UNSUPPORTED the input DevicePath does not contain Fv file\r
4150 guild at all\r
4151 @retval EFI_ALREADY_STARTED the input DevicePath has pointed to Fv file, it is\r
4152 valid\r
4153 @retval EFI_SUCCESS has successfully updated the invalid DevicePath,\r
4154 and return the updated device path in DevicePath\r
4155\r
4156**/\r
4157EFI_STATUS\r
4158EFIAPI\r
4159BdsLibUpdateFvFileDevicePath (\r
4160 IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,\r
4161 IN EFI_GUID *FileGuid\r
4162 )\r
4163{\r
4164 EFI_DEVICE_PATH_PROTOCOL *TempDevicePath;\r
4165 EFI_DEVICE_PATH_PROTOCOL *LastDeviceNode;\r
4166 EFI_STATUS Status;\r
4167 EFI_GUID *GuidPoint;\r
4168 UINTN Index;\r
4169 UINTN FvHandleCount;\r
4170 EFI_HANDLE *FvHandleBuffer;\r
4171 EFI_FV_FILETYPE Type;\r
4172 UINTN Size;\r
4173 EFI_FV_FILE_ATTRIBUTES Attributes;\r
4174 UINT32 AuthenticationStatus;\r
4175 BOOLEAN FindFvFile;\r
4176 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
4177 EFI_FIRMWARE_VOLUME2_PROTOCOL *Fv;\r
4178 MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FvFileNode;\r
4179 EFI_HANDLE FoundFvHandle;\r
4180 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
4181\r
4182 if ((DevicePath == NULL) || (*DevicePath == NULL)) {\r
4183 return EFI_INVALID_PARAMETER;\r
4184 }\r
4185 if (FileGuid == NULL) {\r
4186 return EFI_INVALID_PARAMETER;\r
4187 }\r
128efbbc 4188\r
5c08e117 4189 //\r
4190 // Check whether the device path point to the default the input Fv file\r
4191 //\r
4192 TempDevicePath = *DevicePath;\r
4193 LastDeviceNode = TempDevicePath;\r
4194 while (!IsDevicePathEnd (TempDevicePath)) {\r
4195 LastDeviceNode = TempDevicePath;\r
4196 TempDevicePath = NextDevicePathNode (TempDevicePath);\r
4197 }\r
4198 GuidPoint = EfiGetNameGuidFromFwVolDevicePathNode (\r
4199 (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) LastDeviceNode\r
4200 );\r
4201 if (GuidPoint == NULL) {\r
4202 //\r
4203 // if this option does not points to a Fv file, just return EFI_UNSUPPORTED\r
4204 //\r
4205 return EFI_UNSUPPORTED;\r
4206 }\r
4207 if (!CompareGuid (GuidPoint, FileGuid)) {\r
4208 //\r
4209 // If the Fv file is not the input file guid, just return EFI_UNSUPPORTED\r
4210 //\r
4211 return EFI_UNSUPPORTED;\r
4212 }\r
4213\r
4214 //\r
4215 // Check whether the input Fv file device path is valid\r
4216 //\r
4217 TempDevicePath = *DevicePath;\r
4218 FoundFvHandle = NULL;\r
4219 Status = gBS->LocateDevicePath (\r
4220 &gEfiFirmwareVolume2ProtocolGuid,\r
4221 &TempDevicePath,\r
4222 &FoundFvHandle\r
4223 );\r
4224 if (!EFI_ERROR (Status)) {\r
4225 Status = gBS->HandleProtocol (\r
4226 FoundFvHandle,\r
4227 &gEfiFirmwareVolume2ProtocolGuid,\r
4228 (VOID **) &Fv\r
4229 );\r
4230 if (!EFI_ERROR (Status)) {\r
4231 //\r
4232 // Set FV ReadFile Buffer as NULL, only need to check whether input Fv file exist there\r
4233 //\r
4234 Status = Fv->ReadFile (\r
4235 Fv,\r
4236 FileGuid,\r
4237 NULL,\r
4238 &Size,\r
4239 &Type,\r
4240 &Attributes,\r
4241 &AuthenticationStatus\r
4242 );\r
4243 if (!EFI_ERROR (Status)) {\r
4244 return EFI_ALREADY_STARTED;\r
4245 }\r
4246 }\r
4247 }\r
4248\r
4249 //\r
4250 // Look for the input wanted FV file in current FV\r
4251 // First, try to look for in Bds own FV. Bds and input wanted FV file usually are in the same FV\r
4252 //\r
4253 FindFvFile = FALSE;\r
4254 FoundFvHandle = NULL;\r
4255 Status = gBS->HandleProtocol (\r
fefefa4c 4256 gImageHandle,\r
5c08e117 4257 &gEfiLoadedImageProtocolGuid,\r
4258 (VOID **) &LoadedImage\r
4259 );\r
4260 if (!EFI_ERROR (Status)) {\r
4261 Status = gBS->HandleProtocol (\r
4262 LoadedImage->DeviceHandle,\r
4263 &gEfiFirmwareVolume2ProtocolGuid,\r
4264 (VOID **) &Fv\r
4265 );\r
4266 if (!EFI_ERROR (Status)) {\r
4267 Status = Fv->ReadFile (\r
4268 Fv,\r
4269 FileGuid,\r
4270 NULL,\r
4271 &Size,\r
4272 &Type,\r
4273 &Attributes,\r
4274 &AuthenticationStatus\r
4275 );\r
4276 if (!EFI_ERROR (Status)) {\r
4277 FindFvFile = TRUE;\r
4278 FoundFvHandle = LoadedImage->DeviceHandle;\r
4279 }\r
4280 }\r
4281 }\r
4282 //\r
4283 // Second, if fail to find, try to enumerate all FV\r
4284 //\r
4285 if (!FindFvFile) {\r
4286 FvHandleBuffer = NULL;\r
4287 gBS->LocateHandleBuffer (\r
4288 ByProtocol,\r
4289 &gEfiFirmwareVolume2ProtocolGuid,\r
4290 NULL,\r
4291 &FvHandleCount,\r
4292 &FvHandleBuffer\r
4293 );\r
4294 for (Index = 0; Index < FvHandleCount; Index++) {\r
4295 gBS->HandleProtocol (\r
4296 FvHandleBuffer[Index],\r
4297 &gEfiFirmwareVolume2ProtocolGuid,\r
4298 (VOID **) &Fv\r
4299 );\r
4300\r
4301 Status = Fv->ReadFile (\r
4302 Fv,\r
4303 FileGuid,\r
4304 NULL,\r
4305 &Size,\r
4306 &Type,\r
4307 &Attributes,\r
4308 &AuthenticationStatus\r
4309 );\r
4310 if (EFI_ERROR (Status)) {\r
4311 //\r
4312 // Skip if input Fv file not in the FV\r
4313 //\r
4314 continue;\r
4315 }\r
4316 FindFvFile = TRUE;\r
4317 FoundFvHandle = FvHandleBuffer[Index];\r
4318 break;\r
4319 }\r
4320\r
4321 if (FvHandleBuffer != NULL) {\r
128efbbc 4322 FreePool (FvHandleBuffer);\r
5c08e117 4323 }\r
4324 }\r
4325\r
4326 if (FindFvFile) {\r
4327 //\r
4328 // Build the shell device path\r
4329 //\r
4330 NewDevicePath = DevicePathFromHandle (FoundFvHandle);\r
4331 EfiInitializeFwVolDevicepathNode (&FvFileNode, FileGuid);\r
4332 NewDevicePath = AppendDevicePathNode (NewDevicePath, (EFI_DEVICE_PATH_PROTOCOL *) &FvFileNode);\r
4333 *DevicePath = NewDevicePath;\r
4334 return EFI_SUCCESS;\r
4335 }\r
4336 return EFI_NOT_FOUND;\r
4337}\r