]> code.delx.au - refind/blob - EfiLib/BdsHelper.c
Suppress messages about delays for scanning boot loaders when
[refind] / EfiLib / BdsHelper.c
1 /*
2 * EfiLib/BdsHelper.c
3 * Functions to call legacy BIOS API.
4 *
5 */
6
7
8 #include "BdsHelper.h"
9 #include "legacy.h"
10 #include "../refind/screen.h"
11 #include "refit_call_wrapper.h"
12
13 EFI_GUID gEfiLegacyBootProtocolGuid = { 0xdb9a1e3d, 0x45cb, 0x4abb, { 0x85, 0x3b, 0xe5, 0x38, 0x7f, 0xdb, 0x2e, 0x2d }};
14
15 /**
16 Internal helper function.
17
18 Update the BBS Table so that devices of DeviceType have their boot priority
19 updated to a high/bootable value.
20
21 See "DeviceType values" in
22 http://www.intel.com/content/dam/doc/reference-guide/efi-compatibility-support-module-specification-v097.pdf
23
24 NOTE: This function should probably be refactored! Currently, all devices of
25 type are enabled. This should be updated so that only a specific device is
26 enabled. The wrong device could boot if there are multiple targets of the same
27 type.
28
29 @param DeviceType The device type that we wish to enable
30 **/
31 VOID UpdateBbsTable (BDS_COMMON_OPTION *Option) {
32 UINT16 Idx;
33 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
34 EFI_STATUS Status;
35 UINT16 HddCount = 0;
36 HDD_INFO *HddInfo = NULL;
37 UINT16 BbsCount = 0;
38 BBS_TABLE *LocalBbsTable = NULL;
39 BBS_BBS_DEVICE_PATH *OptionBBS;
40 CHAR16 Desc[100];
41
42 Status = refit_call3_wrapper(gBS->LocateProtocol, &gEfiLegacyBootProtocolGuid, NULL, (VOID **) &LegacyBios);
43 if (EFI_ERROR (Status) || (Option == NULL)) {
44 return;
45 }
46
47 OptionBBS = (BBS_BBS_DEVICE_PATH *) Option->DevicePath;
48 Status = refit_call5_wrapper(LegacyBios->GetBbsInfo, LegacyBios, &HddCount, &HddInfo, &BbsCount, &LocalBbsTable);
49
50 // Print (L"\n");
51 // Print (L" NO Prio bb/dd/ff cl/sc Type Stat segm:offs\n");
52 // Print (L"=============================================\n");
53
54 for (Idx = 0; Idx < BbsCount; Idx++) {
55 if(LocalBbsTable[Idx].DeviceType == 0) {
56 continue;
57 }
58
59 BdsBuildLegacyDevNameString (&LocalBbsTable[Idx], Idx, sizeof (Desc), Desc);
60
61 // Set devices of a particular type to BootPriority of 0 or 1. 0 is the highest priority.
62 if (LocalBbsTable[Idx].DeviceType == OptionBBS->DeviceType) {
63 if (StriCmp(Desc, Option->Description) == 0) {
64 // This entry exactly matches what we're looking for; make it highest priority
65 LocalBbsTable[Idx].BootPriority = 0;
66 } else {
67 // This entry doesn't exactly match, but is the right disk type; make it a bit lower
68 // in priority. Done mainly as a fallback in case of string-matching weirdness.
69 LocalBbsTable[Idx].BootPriority = 1;
70 } // if/else
71 } else if (LocalBbsTable[Idx].BootPriority <= 1) {
72 // Something's got a high enough boot priority to interfere with booting
73 // our chosen entry, so bump it down a bit....
74 LocalBbsTable[Idx].BootPriority = 2;
75 } // if/else if
76
77 // Print (
78 // L" %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x\n",
79 // (UINTN) Idx,
80 // (UINTN) LocalBbsTable[Idx].BootPriority,
81 // (UINTN) LocalBbsTable[Idx].Bus,
82 // (UINTN) LocalBbsTable[Idx].Device,
83 // (UINTN) LocalBbsTable[Idx].Function,
84 // (UINTN) LocalBbsTable[Idx].Class,
85 // (UINTN) LocalBbsTable[Idx].SubClass,
86 // (UINTN) LocalBbsTable[Idx].DeviceType,
87 // (UINTN) * (UINT16 *) &LocalBbsTable[Idx].StatusFlags,
88 // (UINTN) LocalBbsTable[Idx].BootHandlerSegment,
89 // (UINTN) LocalBbsTable[Idx].BootHandlerOffset,
90 // (UINTN) ((LocalBbsTable[Idx].MfgStringSegment << 4) + LocalBbsTable[Idx].MfgStringOffset),
91 // (UINTN) ((LocalBbsTable[Idx].DescStringSegment << 4) + LocalBbsTable[Idx].DescStringOffset)
92 // );
93 // Print(L"%s\n", Desc);
94
95 } // for
96 // PauseForKey();
97 }
98
99 /**
100 Boot the legacy system with the boot option
101
102 @param Option The legacy boot option which have BBS device path
103
104 @retval EFI_UNSUPPORTED There is no legacybios protocol, do not support
105 legacy boot.
106 @retval EFI_STATUS Return the status of LegacyBios->LegacyBoot ().
107
108 **/
109 EFI_STATUS
110 BdsLibDoLegacyBoot (
111 IN BDS_COMMON_OPTION *Option
112 )
113 {
114 EFI_STATUS Status;
115 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
116
117 Status = refit_call3_wrapper(gBS->LocateProtocol, &gEfiLegacyBootProtocolGuid, NULL, (VOID **) &LegacyBios);
118 if (EFI_ERROR (Status)) {
119 return EFI_UNSUPPORTED;
120 }
121
122 UpdateBbsTable(Option);
123
124 return refit_call4_wrapper(LegacyBios->LegacyBoot, LegacyBios, (BBS_BBS_DEVICE_PATH *) Option->DevicePath,
125 Option->LoadOptionsSize, Option->LoadOptions);
126 }