]> code.delx.au - refind/blob - EfiLib/BdsHelper.c
Reconfigured new UEFI BIOS-boot support to use the Mac-style "scanfor"
[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
10 EFI_GUID gEfiLegacyBootProtocolGuid = { 0xdb9a1e3d, 0x45cb, 0x4abb, { 0x85, 0x3b, 0xe5, 0x38, 0x7f, 0xdb, 0x2e, 0x2d }};
11
12 /**
13 Internal helper function.
14
15 Update the BBS Table so that devices of DeviceType have their boot priority
16 updated to a high/bootable value.
17
18 See "DeviceType values" in
19 http://www.intel.com/content/dam/doc/reference-guide/efi-compatibility-support-module-specification-v097.pdf
20
21 NOTE: This function should probably be refactored! Currently, all devices of
22 type are enabled. This should be updated so that only a specific device is
23 enabled. The wrong device could boot if there are multiple targets of the same
24 type.
25
26 @param DeviceType The device type that we wish to enable
27 **/
28 VOID
29 UpdateBbsTable (
30 IN UINT16 DeviceType
31 )
32 {
33 UINT16 Idx;
34 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
35 // EFI_GUID EfiLegacyBootProtocolGuid = { 0xdb9a1e3d, 0x45cb, 0x4abb, { 0x85, 0x3b, 0xe5, 0x38, 0x7f, 0xdb, 0x2e, 0x2d }};
36 EFI_STATUS Status;
37 UINT16 HddCount = 0;
38 HDD_INFO *HddInfo = NULL;
39 UINT16 BbsCount = 0;
40 BBS_TABLE *LocalBbsTable = NULL;
41
42 Status = gBS->LocateProtocol (&gEfiLegacyBootProtocolGuid, NULL, (VOID **) &LegacyBios);
43 if (EFI_ERROR (Status)) {
44 return;
45 }
46
47 Status = LegacyBios->GetBbsInfo (LegacyBios, &HddCount, &HddInfo, &BbsCount, &LocalBbsTable);
48
49 //Print (L"\n");
50 //Print (L" NO Prio bb/dd/ff cl/sc Type Stat segm:offs\n");
51 //Print (L"=============================================\n");
52
53 for (Idx = 0; Idx < BbsCount; Idx++)
54 {
55 if(LocalBbsTable[Idx].DeviceType == 0){
56 continue;
57 }
58
59 // Set devices of a particular type to BootPriority of 0. I believe 0 is the highest priority
60 if(LocalBbsTable[Idx].DeviceType == DeviceType){
61 LocalBbsTable[Idx].BootPriority = 0;
62 }
63
64 /*
65 Print (
66 L" %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x\n",
67 (UINTN) Idx,
68 (UINTN) LocalBbsTable[Idx].BootPriority,
69 (UINTN) LocalBbsTable[Idx].Bus,
70 (UINTN) LocalBbsTable[Idx].Device,
71 (UINTN) LocalBbsTable[Idx].Function,
72 (UINTN) LocalBbsTable[Idx].Class,
73 (UINTN) LocalBbsTable[Idx].SubClass,
74 (UINTN) LocalBbsTable[Idx].DeviceType,
75 (UINTN) * (UINT16 *) &LocalBbsTable[Idx].StatusFlags,
76 (UINTN) LocalBbsTable[Idx].BootHandlerSegment,
77 (UINTN) LocalBbsTable[Idx].BootHandlerOffset,
78 (UINTN) ((LocalBbsTable[Idx].MfgStringSegment << 4) + LocalBbsTable[Idx].MfgStringOffset),
79 (UINTN) ((LocalBbsTable[Idx].DescStringSegment << 4) + LocalBbsTable[Idx].DescStringOffset)
80 );
81 */
82 }
83
84 //Print(L"\n");
85 }
86
87 // Internal helper function
88 BOOLEAN ArrayContains(UINT16* Arr, UINT8 ArrLen, UINT8 Target)
89 {
90 UINT8 i;
91 for(i = 0; i < ArrLen; i++)
92 {
93 if(Arr[i] == Target)
94 return TRUE;
95 }
96
97 return FALSE;
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 BBS_BBS_DEVICE_PATH *OptionBBS;
118
119 Status = gBS->LocateProtocol (&gEfiLegacyBootProtocolGuid, NULL, (VOID **) &LegacyBios);
120 if (EFI_ERROR (Status)) {
121 return EFI_UNSUPPORTED;
122 }
123 OptionBBS = (BBS_BBS_DEVICE_PATH *) Option->DevicePath;
124
125 //Print(L"\n\n");
126 //Print(L"Option->Name='%s'\n", Option->OptionName);
127 //Print(L"Option->Number='%d'\n", Option->OptionNumber);
128 //Print(L"Option->Description='%s'\n", Option->Description);
129 //Print(L"Option->LoadOptionsSize='%d'\n",Option->LoadOptionsSize);
130 //Print(L"Option->BootCurrent='%d'\n",Option->BootCurrent);
131 //Print(L"Option->DevicePath->Type= '%d'\n", Option->DevicePath->Type);
132 //Print(L"Option->DevicePath->SubType= '%d'\n", Option->DevicePath->SubType);
133 //Print(L"Option->DevicePath->Length[0]= '%d'\n", Option->DevicePath->Length[0]);
134 //Print(L"Option->DevicePath->Length[1]= '%d'\n", Option->DevicePath->Length[1]);
135 //Print(L"OptionBBS->DeviceType='%d'\n",OptionBBS->DeviceType);
136 //Print(L"OptionBBS->StatusFlag='%d'\n",OptionBBS->StatusFlag);
137 //Print(L"OptionBBS->String[0]='%c'\n",OptionBBS->String[0]);
138 //Print(L"About to legacy boot!\n");
139 //PauseForKey();
140
141 UpdateBbsTable(OptionBBS->DeviceType);
142
143 return LegacyBios->LegacyBoot (LegacyBios, (BBS_BBS_DEVICE_PATH *) Option->DevicePath, Option->LoadOptionsSize, Option->LoadOptions);
144 }
145