3 * Functions to call legacy BIOS API.
10 #include "../refind/screen.h"
11 #include "../include/refit_call_wrapper.h"
13 EFI_GUID gEfiLegacyBootProtocolGuid
= { 0xdb9a1e3d, 0x45cb, 0x4abb, { 0x85, 0x3b, 0xe5, 0x38, 0x7f, 0xdb, 0x2e, 0x2d }};
16 Internal helper function.
18 Update the BBS Table so that devices of DeviceType have their boot priority
19 updated to a high/bootable value.
21 See "DeviceType values" in
22 http://www.intel.com/content/dam/doc/reference-guide/efi-compatibility-support-module-specification-v097.pdf
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
29 @param DeviceType The device type that we wish to enable
31 VOID
UpdateBbsTable (BDS_COMMON_OPTION
*Option
) {
33 EFI_LEGACY_BIOS_PROTOCOL
*LegacyBios
;
36 HDD_INFO
*HddInfo
= NULL
;
38 BBS_TABLE
*LocalBbsTable
= NULL
;
39 BBS_BBS_DEVICE_PATH
*OptionBBS
;
42 Status
= refit_call3_wrapper(gBS
->LocateProtocol
, &gEfiLegacyBootProtocolGuid
, NULL
, (VOID
**) &LegacyBios
);
43 if (EFI_ERROR (Status
) || (Option
== NULL
)) {
47 OptionBBS
= (BBS_BBS_DEVICE_PATH
*) Option
->DevicePath
;
48 Status
= refit_call5_wrapper(LegacyBios
->GetBbsInfo
, LegacyBios
, &HddCount
, &HddInfo
, &BbsCount
, &LocalBbsTable
);
51 // Print (L" NO Prio bb/dd/ff cl/sc Type Stat segm:offs\n");
52 // Print (L"=============================================\n");
54 for (Idx
= 0; Idx
< BbsCount
; Idx
++) {
55 if(LocalBbsTable
[Idx
].DeviceType
== 0) {
59 BdsBuildLegacyDevNameString (&LocalBbsTable
[Idx
], Idx
, sizeof (Desc
), Desc
);
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;
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;
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;
78 // L" %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x\n",
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)
93 // Print(L"%s\n", Desc);
100 Boot the legacy system with the boot option
102 @param Option The legacy boot option which have BBS device path
104 @retval EFI_UNSUPPORTED There is no legacybios protocol, do not support
106 @retval EFI_STATUS Return the status of LegacyBios->LegacyBoot ().
111 IN BDS_COMMON_OPTION
*Option
115 EFI_LEGACY_BIOS_PROTOCOL
*LegacyBios
;
117 Status
= refit_call3_wrapper(gBS
->LocateProtocol
, &gEfiLegacyBootProtocolGuid
, NULL
, (VOID
**) &LegacyBios
);
118 if (EFI_ERROR (Status
)) {
119 return EFI_UNSUPPORTED
;
122 UpdateBbsTable(Option
);
124 return refit_call4_wrapper(LegacyBios
->LegacyBoot
, LegacyBios
, (BBS_BBS_DEVICE_PATH
*) Option
->DevicePath
,
125 Option
->LoadOptionsSize
, Option
->LoadOptions
);