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