3 * Functions to call legacy BIOS API.
10 #include "../refind/screen.h"
11 #include "../refind/lib.h"
12 #include "../include/refit_call_wrapper.h"
14 EFI_GUID gEfiLegacyBootProtocolGuid
= { 0xdb9a1e3d, 0x45cb, 0x4abb, { 0x85, 0x3b, 0xe5, 0x38, 0x7f, 0xdb, 0x2e, 0x2d }};
17 Internal helper function.
19 Update the BBS Table so that devices of DeviceType have their boot priority
20 updated to a high/bootable value.
22 See "DeviceType values" in
23 http://www.intel.com/content/dam/doc/reference-guide/efi-compatibility-support-module-specification-v097.pdf
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
30 @param DeviceType The device type that we wish to enable
32 VOID
UpdateBbsTable (BDS_COMMON_OPTION
*Option
) {
34 EFI_LEGACY_BIOS_PROTOCOL
*LegacyBios
;
37 HDD_INFO
*HddInfo
= NULL
;
39 BBS_TABLE
*LocalBbsTable
= NULL
;
40 BBS_BBS_DEVICE_PATH
*OptionBBS
;
43 Status
= refit_call3_wrapper(gBS
->LocateProtocol
, &gEfiLegacyBootProtocolGuid
, NULL
, (VOID
**) &LegacyBios
);
44 if (EFI_ERROR (Status
) || (Option
== NULL
)) {
48 OptionBBS
= (BBS_BBS_DEVICE_PATH
*) Option
->DevicePath
;
49 Status
= refit_call5_wrapper(LegacyBios
->GetBbsInfo
, LegacyBios
, &HddCount
, &HddInfo
, &BbsCount
, &LocalBbsTable
);
52 // Print (L" NO Prio bb/dd/ff cl/sc Type Stat segm:offs\n");
53 // Print (L"=============================================\n");
55 for (Idx
= 0; Idx
< BbsCount
; Idx
++) {
56 if(LocalBbsTable
[Idx
].DeviceType
== 0) {
60 BdsBuildLegacyDevNameString (&LocalBbsTable
[Idx
], Idx
, sizeof (Desc
), Desc
);
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;
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;
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;
79 // L" %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x\n",
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)
94 // Print(L"%s\n", Desc);
101 Boot the legacy system with the boot option
103 @param Option The legacy boot option which have BBS device path
105 @retval EFI_UNSUPPORTED There is no legacybios protocol, do not support
107 @retval EFI_STATUS Return the status of LegacyBios->LegacyBoot ().
112 IN BDS_COMMON_OPTION
*Option
116 EFI_LEGACY_BIOS_PROTOCOL
*LegacyBios
;
118 Status
= refit_call3_wrapper(gBS
->LocateProtocol
, &gEfiLegacyBootProtocolGuid
, NULL
, (VOID
**) &LegacyBios
);
119 if (EFI_ERROR (Status
)) {
120 return EFI_UNSUPPORTED
;
123 UpdateBbsTable(Option
);
125 return refit_call4_wrapper(LegacyBios
->LegacyBoot
, LegacyBios
, (BBS_BBS_DEVICE_PATH
*) Option
->DevicePath
,
126 Option
->LoadOptionsSize
, Option
->LoadOptions
);