Changeset 48749 in vbox for trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg
- Timestamp:
- Sep 28, 2013 3:22:32 AM (11 years ago)
- Location:
- trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/GenericBdsLib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsBoot.c
r48747 r48749 18 18 BOOLEAN mEnumBootDevice = FALSE; 19 19 EFI_HII_HANDLE gBdsLibStringPackHandle = NULL; 20 21 #ifdef VBOX 22 /** Array of EFI boot files. */ 23 CHAR16 CONST *maBdsLibBootFiles[] = { 24 VBOX_EFI_APPLE_MEDIA_FILE_NAME, 25 EFI_REMOVABLE_MEDIA_FILE_NAME, 26 }; 27 #endif 20 28 21 29 /** … … 473 481 // 474 482 VBoxLogFlowFuncMark(); 483 #ifdef VBOX /* We look for serveral files because of apple. */ 484 { 485 INT32 IdxFile; 486 for (IdxFile = 0; IdxFile < sizeof(maBdsLibBootFiles) / sizeof(maBdsLibBootFiles[0]); IdxFile++) { 487 FullDevicePath = FileDevicePath(Handle, maBdsLibBootFiles[IdxFile]); 488 if (FullDevicePath != NULL) { 489 Status = gBS->LoadImage(TRUE, gImageHandle, FullDevicePath, NULL, 0, &ImageHandle); 490 if (!EFI_ERROR(Status)) { 491 break; 492 } 493 } 494 } 495 if (!EFI_ERROR(Status)) { 496 continue; 497 } 498 } 499 #else /* !VBOX */ 475 500 FullDevicePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME); 476 501 if (FullDevicePath != NULL) { … … 494 519 continue; 495 520 } 521 #endif /* !VBOX */ 496 522 } 497 523 break; … … 637 663 PERF_END(NULL, "BDS", NULL, 0); 638 664 639 DEBUG((DEBUG_INFO,"BdsLibBootViaBootOption: BootCurrent=0x%x OptionName=%s Description=%s StatusString=%s Attribute=0x%x LoadOptionsSize=0x%x\n",640 Option->BootCurrent, Option->OptionName, Option->Description, Option->StatusString, Option->Attribute, Option->LoadOptionsSize));665 VBoxLog(("BdsLibBootViaBootOption: BootCurrent=0x%x OptionName=%s Description=%s StatusString=%s Attribute=0x%x LoadOptionsSize=0x%x\n", 666 Option->BootCurrent, Option->OptionName, Option->Description, Option->StatusString, Option->Attribute, Option->LoadOptionsSize)); 641 667 642 668 *ExitDataSize = 0; … … 780 806 goto Done; 781 807 } 808 #ifdef VBOX /* We have more options to try out because of apple. */ 809 // 810 // Try parse any config="folder-path/" stuff found in the optional 811 // section of the boot option and attempt to load boot.efi it. 812 // 813 if (Option->LoadOptionsSize) { 814 /* First, see the there is a config=stuff in the load options. */ 815 VBoxLogFlowFuncMarkVar(Option->LoadOptions, "%s"); 816 /** @todo Please past and example of this here! */ 817 if (StrnCmp(L"config=", (CHAR16 *)Option->LoadOptions, 7) == 0) { 818 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume; 819 CHAR16 *pszConfigValue = &((CHAR16 *)Option->LoadOptions)[7]; 820 CHAR16 *pszFolder = NULL; 821 CHAR16 *pszTemp0 = NULL; 822 CHAR16 *pszTemp1 = NULL; 823 BOOLEAN fQuoted = (pszConfigValue[0] == L'\"'); 824 pszTemp0 = &pszConfigValue[fQuoted ? 2 : 1]; 825 pszTemp1 = pszTemp0; 826 VBoxLogFlowFuncMarkVar(pszTemp0, "%s"); 827 VBoxLogFlowFuncMarkVar(pszTemp1, "%s"); 828 pszFolder = AllocateZeroPool((StrLen(pszConfigValue) + StrLen(L"\\boot.efi") + 1) * sizeof(UINT16)); 829 while (pszTemp0) { 830 VBoxLogFlowFuncMarkVar(pszTemp0, "%s"); 831 VBoxLogFlowFuncMarkVar(pszTemp1, "%s"); 832 pszFolder = StrnCat(pszFolder, pszTemp1, StrLen(pszTemp1) - StrLen(pszTemp0)); 833 pszTemp1 = pszTemp0; 834 pszFolder = StrCat(pszFolder, L"\\"); 835 VBoxLogFlowFuncMarkVar(pszFolder, "%s"); 836 VBoxLogFlowFuncMarkVar(pszTemp0, "%s"); 837 VBoxLogFlowFuncMarkVar(pszTemp1, "%s"); 838 pszTemp0 = StrStr(&pszTemp0[1], L"\\"); 839 VBoxLogFlowFuncMarkVar(pszTemp0, "%s"); 840 } 841 pszFolder = StrCat(pszFolder, L"boot.efi"); 842 VBoxLogFlowFuncMarkVar(pszFolder,"%s"); 843 844 Status = gBS->HandleProtocol(Handle, &gEfiSimpleFileSystemProtocolGuid, &Volume); 845 VBoxLogFlowFuncMarkRC(Status); 846 if (!EFI_ERROR(Status)) { 847 FilePath = FileDevicePath((EFI_HANDLE)Handle, pszFolder); 848 if (FilePath) { 849 VBoxLogFlowFuncMarkVar(DevicePathToStr(FilePath), "%s"); 850 REPORT_STATUS_CODE(EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad)); 851 Status = gBS->LoadImage(TRUE, gImageHandle, FilePath, NULL, 0, &ImageHandle ); 852 VBoxLogFlowFuncMarkRC(Status); 853 /** @todo Probably leaking memory here! */ 854 } 855 } 856 } 857 } 858 859 // 860 // Try load any of the default boot files. 861 // 862 if (EFI_ERROR(Status)) { 863 UINT32 IdxFile; 864 for (IdxFile = 0; IdxFile < sizeof(maBdsLibBootFiles) / sizeof(maBdsLibBootFiles[0]); IdxFile++) { 865 FilePath = FileDevicePath(Handle, maBdsLibBootFiles[IdxFile]); 866 if (FilePath) { 867 VBoxLog(("BdsLibBootViaBootOption: Trying to load '%s'...\n", DevicePathToStr(FilePath))); 868 REPORT_STATUS_CODE(EFI_PROGRESS_CODE, PcdGet32(PcdProgressCodeOsLoaderLoad)); 869 Status = gBS->LoadImage(TRUE, gImageHandle, FilePath, NULL, 0, &ImageHandle ); 870 if (!EFI_ERROR(Status)) { 871 VBoxLog(("BdsLibBootViaBootOption: Successfully loaded boot file: %s\n", DevicePathToStr(FilePath))); 872 break; 873 } 874 VBoxLog(("BdsLibBootViaBootOption: Failed loading '%s': 0x%x(%r)\n", DevicePathToStr(FilePath), Status, Status)); 875 FilePath = NULL; /** @todo Probably leaking memory here! */ 876 } 877 } 878 } 879 #else /* !VBOX */ 782 880 // 783 881 // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media 784 882 // machinename is ia32, ia64, x64, ... 785 883 // 786 #ifdef VBOX 787 /* @todo: improve Mac Detection */ 788 FilePath = NULL; 789 if ( Option->LoadOptionsSize 790 || StrnCmp(Option->OptionName, L"Boot0080", 8) == 0) 791 { 792 if (Option->LoadOptionsSize) 793 { 794 VBoxLogFlowFuncMarkVar(Option->LoadOptions, "%s"); 795 if (StrnCmp(L"config=", (CHAR16 *)Option->LoadOptions, 7) == 0) 796 { 797 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume; 798 CHAR16 *pszConfigValue = &((CHAR16 *)Option->LoadOptions)[7]; 799 CHAR16 *pszFolder = NULL; 800 CHAR16 *pszTemp0 = NULL; 801 CHAR16 *pszTemp1 = NULL; 802 BOOLEAN fQouted = (pszConfigValue[0] == L'\"'); 803 pszTemp0 = &pszConfigValue[fQouted ? 2 : 1]; 804 pszTemp1 = pszTemp0; 805 VBoxLogFlowFuncMarkVar(pszTemp0, "%s"); 806 VBoxLogFlowFuncMarkVar(pszTemp1, "%s"); 807 pszFolder = AllocateZeroPool((StrLen(pszConfigValue) + StrLen(L"\\boot.efi") + 1) * sizeof(UINT16)); 808 while (pszTemp0) 809 { 810 VBoxLogFlowFuncMarkVar(pszTemp0, "%s"); 811 VBoxLogFlowFuncMarkVar(pszTemp1, "%s"); 812 pszFolder = StrnCat(pszFolder, pszTemp1, StrLen(pszTemp1) - StrLen(pszTemp0)); 813 pszTemp1 = pszTemp0; 814 pszFolder = StrCat(pszFolder, L"\\"); 815 VBoxLogFlowFuncMarkVar(pszFolder, "%s"); 816 VBoxLogFlowFuncMarkVar(pszTemp0, "%s"); 817 VBoxLogFlowFuncMarkVar(pszTemp1, "%s"); 818 pszTemp0 = StrStr(&pszTemp0[1], L"\\"); 819 VBoxLogFlowFuncMarkVar(pszTemp0, "%s"); 820 } 821 pszFolder = StrCat(pszFolder, L"boot.efi"); 822 VBoxLogFlowFuncMarkVar(pszFolder,"%s"); 823 824 Status = gBS->HandleProtocol ( 825 Handle, 826 &gEfiSimpleFileSystemProtocolGuid, 827 (VOID *) &Volume); 828 VBoxLogFlowFuncMarkRC(Status); 829 if (!EFI_ERROR(Status)) 830 { 831 FilePath = FileDevicePath ((EFI_HANDLE)Handle, pszFolder); 832 VBoxLogFlowFuncMarkVar(DevicePathToStr(FilePath), "%s"); 833 } 834 } 835 } 836 else 837 { 838 /* Boot0080 hasn't got hint how detect file path */ 839 VBoxLogFlowFuncMarkVar(Handle, "%p"); 840 FilePath = FileDevicePath (Handle, L"\\System\\Library\\CoreServices\\boot.efi"); 841 if (FilePath) 842 { 843 VBoxLogFlowFuncMarkVar(DevicePathToStr(FilePath), "%s"); 844 } 845 } 846 } 847 if (!FilePath) 848 FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME); 849 #else 850 FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME); 851 #endif 884 FilePath = FileDevicePath (Handle, EFI_REMOVABLE_MEDIA_FILE_NAME); 852 885 if (FilePath != NULL) { 853 886 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, PcdGet32 (PcdProgressCodeOsLoaderLoad)); … … 860 893 &ImageHandle 861 894 ); 862 VBoxLogFlowFuncMarkRC(Status);863 895 if (EFI_ERROR (Status)) { 864 896 // … … 869 901 } 870 902 } 903 #endif /* !VBOX */ 871 904 } 872 905 … … 1573 1606 EFI_HANDLE *FileSystemHandles; 1574 1607 UINTN NumberFileSystemHandles; 1575 BOOLEAN NeedDelete = TRUE;1608 BOOLEAN NeedDelete; 1576 1609 EFI_IMAGE_DOS_HEADER DosHeader; 1577 1610 CHAR8 *PlatLang; … … 1753 1786 ); 1754 1787 for (Index = 0; Index < NumberFileSystemHandles; Index++) { 1755 #ifdef VBOX1756 BOOLEAN fLoaded = FALSE;1757 #endif1758 1788 Status = gBS->HandleProtocol ( 1759 1789 FileSystemHandles[Index], … … 1761 1791 (VOID **) &BlkIo 1762 1792 ); 1763 1793 if (!EFI_ERROR (Status)) { 1764 1794 // 1765 1795 // Skip if the file system handle supports a BlkIo protocol, 1766 1796 // 1767 #if 0 /* VBox */1768 NeedDelete = TRUE;1769 Hdr.Union = &HdrData;1770 Status = BdsLibGetImageHeader (1771 FileSystemHandles[Index],1772 L"\\System\\Library\\CoreServices\\boot.efi",1773 NULL,1774 Hdr);1775 LogFlowFuncMarkRC(Status);1776 if (EFI_ERROR(Status))1777 continue;1778 else1779 {1780 fLoaded = TRUE;1781 }1782 #else1783 1797 continue; 1784 #endif1785 1798 } 1786 1799 … … 1789 1802 // machinename is ia32, ia64, x64, ... 1790 1803 // 1791 #ifdef VBOX 1792 VBoxLogFlowFuncMark(); 1793 if (!fLoaded) 1794 #endif 1804 #ifdef VBOX /* We try serveral variants because of apple. */ 1795 1805 { 1806 UINT32 IdxFile; 1807 NeedDelete = TRUE; 1808 for (IdxFile = 0; IdxFile < sizeof(maBdsLibBootFiles) / sizeof(maBdsLibBootFiles[0]); IdxFile++) { 1796 1809 Hdr.Union = &HdrData; 1797 NeedDelete = TRUE; 1798 Status = BdsLibGetImageHeader ( 1799 FileSystemHandles[Index], 1800 EFI_REMOVABLE_MEDIA_FILE_NAME, 1801 &DosHeader, 1802 Hdr 1803 ); 1804 } 1805 if ( !EFI_ERROR (Status) 1806 && ( ( EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) 1807 && Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) 1808 || !fLoaded)) { /* VBox */ 1810 Status = BdsLibGetImageHeader(FileSystemHandles[Index], (CHAR16 *)maBdsLibBootFiles[IdxFile], &DosHeader, Hdr); 1811 if (!EFI_ERROR(Status)) { 1812 break; 1813 } 1814 } 1815 } 1816 #else /* !VBOX */ 1817 Hdr.Union = &HdrData; 1818 NeedDelete = TRUE; 1819 Status = BdsLibGetImageHeader ( 1820 FileSystemHandles[Index], 1821 EFI_REMOVABLE_MEDIA_FILE_NAME, 1822 &DosHeader, 1823 Hdr 1824 ); 1825 #endif /* !VBOX */ 1826 if (!EFI_ERROR (Status) && 1827 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) && 1828 Hdr.Pe32->OptionalHeader.Subsystem == EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION) { 1809 1829 NeedDelete = FALSE; 1810 1830 } … … 2182 2202 // 2183 2203 if (Size <= TempSize && CompareMem (TempDevicePath, UpdatedDevicePath, Size)==0) { 2204 #ifdef VBOX 2205 // 2206 // Try detect image headers for one of the standard boot files. 2207 // 2208 UINT32 IdxFile; 2209 Hdr.Union = &HdrData; 2210 for (IdxFile = 0; IdxFile < sizeof(maBdsLibBootFiles) / sizeof(maBdsLibBootFiles[0]); IdxFile++) { 2211 Status = BdsLibGetImageHeader(SimpleFileSystemHandles[Index], (CHAR16 *)maBdsLibBootFiles[IdxFile], &DosHeader, Hdr); 2212 VBoxLogFlowFuncMarkRC(Status); 2213 if (!EFI_ERROR(Status)) { 2214 break; 2215 } 2216 Hdr.Union = &HdrData; 2217 } 2218 #else /* !VBOX */ 2184 2219 // 2185 2220 // Load the default boot file \EFI\BOOT\boot{machinename}.EFI from removable Media … … 2187 2222 // 2188 2223 Hdr.Union = &HdrData; 2189 VBoxLogFlowFuncMark();2190 2224 Status = BdsLibGetImageHeader ( 2191 2225 SimpleFileSystemHandles[Index], … … 2194 2228 Hdr 2195 2229 ); 2196 VBoxLogFlowFuncMarkRC(Status); 2230 #endif /* !VBOX */ 2197 2231 if (!EFI_ERROR (Status) && 2198 2232 EFI_IMAGE_MACHINE_TYPE_SUPPORTED (Hdr.Pe32->FileHeader.Machine) && … … 2259 2293 # endif 2260 2294 } 2261 #endif 2295 #endif /* VBOX */ 2262 2296 } 2263 2297 … … 2536 2570 EFI_BLOCK_IO_PROTOCOL *BlockIo; 2537 2571 2572 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: DevPath=%s CheckMedia=%d Description=%s\n", 2573 DevicePathToStr(DevPath), CheckMedia, Description)); 2574 2538 2575 TempDevicePath = DevPath; 2539 2576 LastDeviceNode = DevPath; … … 2544 2581 // If yes, that means there is a boot option for network. 2545 2582 // 2546 VBoxLogFlowFuncEnter();2547 2583 Status = gBS->LocateDevicePath ( 2548 2584 &gEfiLoadFileProtocolGuid, … … 2570 2606 // LoadFile protocol is not installed on handle with exactly the same DevPath 2571 2607 // 2572 VBoxLog FlowFuncLeave();2608 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns FALSE (#1)\n")); 2573 2609 return FALSE; 2574 2610 } … … 2579 2615 // 2580 2616 if (BdsLibNetworkBootWithMediaPresent(DevPath)) { 2581 VBoxLog FlowFuncLeave();2617 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns TRUE (#2)\n")); 2582 2618 return TRUE; 2583 2619 } 2584 2620 } else { 2585 VBoxLog FlowFuncLeave();2621 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns TRUE (#3)\n")); 2586 2622 return TRUE; 2587 2623 } … … 2601 2637 ((DevicePathSubType (TempDevicePath) == MSG_USB_CLASS_DP) || 2602 2638 (DevicePathSubType (TempDevicePath) == MSG_USB_WWID_DP))) { 2603 VBoxLog FlowFuncLeave();2639 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns TRUE (#4)\n")); 2604 2640 return TRUE; 2605 2641 } … … 2610 2646 if ((DevicePathType (LastDeviceNode) == MEDIA_DEVICE_PATH) && 2611 2647 (DevicePathSubType (LastDeviceNode) == MEDIA_FILEPATH_DP)) { 2612 VBoxLog FlowFuncLeave();2648 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns TRUE (#5)\n")); 2613 2649 return TRUE; 2614 2650 } … … 2627 2663 ); 2628 2664 if (Status == EFI_ALREADY_STARTED) { 2629 VBoxLog FlowFuncLeave();2665 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns TRUE (#6)\n")); 2630 2666 return TRUE; 2631 2667 } else { … … 2633 2669 FreePool (TempDevicePath); 2634 2670 } 2635 VBoxLog FlowFuncLeave();2671 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns FALSE (#7)\n")); 2636 2672 return FALSE; 2637 2673 } … … 2672 2708 // 2673 2709 if (BdsLibGetBootableHandle (DevPath) != NULL) { 2674 VBoxLog FlowFuncLeave();2710 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns TRUE (#8)\n")); 2675 2711 return TRUE; 2676 2712 } 2677 2713 } else { 2678 VBoxLog FlowFuncLeave();2714 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns TRUE (#9)\n")); 2679 2715 return TRUE; 2680 2716 } … … 2692 2728 // 2693 2729 if (BdsLibGetBootableHandle (DevPath) != NULL) { 2694 VBoxLog FlowFuncLeave();2730 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns TRUE (#10)\n")); 2695 2731 return TRUE; 2696 2732 } 2697 2733 } else { 2698 VBoxLog FlowFuncLeave();2734 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns TRUE (#10)\n")); 2699 2735 return TRUE; 2700 2736 } … … 2705 2741 return FALSE; 2706 2742 #else 2707 VBoxLog FlowFuncLeave();2743 VBoxLog(("BdsLibIsValidEFIBootOptDevicePathExt: returns TRUE (#11) - Status 0x%x(%r)\n", Status, Status)); 2708 2744 return TRUE; 2709 2745 #endif -
trunk/src/VBox/Devices/EFI/Firmware/IntelFrameworkModulePkg/Library/GenericBdsLib/InternalBdsLib.h
r48674 r48749 85 85 #endif 86 86 87 #ifdef VBOX 88 /** 89 Apple seems to have a different EFI_REMOVABLE_MEDIA_FILE_NAME value, so it 90 seems we have to check for both the apple value and for the UEFI value if we 91 want to support both apple and non-apple systems. (Probably more to this.) 92 **/ 93 #define VBOX_EFI_APPLE_MEDIA_FILE_NAME L"\\System\\Library\\CoreServices\\boot.efi" 94 #endif 95 87 96 /** 88 97
Note:
See TracChangeset
for help on using the changeset viewer.