X-Git-Url: https://code.delx.au/refind/blobdiff_plain/d6882a1cf9f487600ccb2b57ba880b5f91ff0c10..4cfc89efc08cf488803e93b1356446ac4d34f181:/EfiLib/BdsHelper.c diff --git a/EfiLib/BdsHelper.c b/EfiLib/BdsHelper.c index 12a54a4..563993a 100644 --- a/EfiLib/BdsHelper.c +++ b/EfiLib/BdsHelper.c @@ -6,6 +6,9 @@ #include "BdsHelper.h" +#include "legacy.h" +#include "../refind/screen.h" +#include "refit_call_wrapper.h" EFI_GUID gEfiLegacyBootProtocolGuid = { 0xdb9a1e3d, 0x45cb, 0x4abb, { 0x85, 0x3b, 0xe5, 0x38, 0x7f, 0xdb, 0x2e, 0x2d }}; @@ -25,77 +28,74 @@ EFI_GUID gEfiLegacyBootProtocolGuid = { 0xdb9a1e3d, 0x45cb, 0x4abb, { 0x85, @param DeviceType The device type that we wish to enable **/ -VOID -UpdateBbsTable ( - IN UINT16 DeviceType - ) -{ - UINT16 Idx; - EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - EFI_STATUS Status; - UINT16 HddCount = 0; - HDD_INFO *HddInfo = NULL; - UINT16 BbsCount = 0; - BBS_TABLE *LocalBbsTable = NULL; - - Status = gBS->LocateProtocol (&gEfiLegacyBootProtocolGuid, NULL, (VOID **) &LegacyBios); - if (EFI_ERROR (Status)) { +VOID UpdateBbsTable (BDS_COMMON_OPTION *Option) { + UINT16 Idx; + EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; + EFI_STATUS Status; + UINT16 HddCount = 0; + HDD_INFO *HddInfo = NULL; + UINT16 BbsCount = 0; + BBS_TABLE *LocalBbsTable = NULL; + BBS_BBS_DEVICE_PATH *OptionBBS; + CHAR16 Desc[100]; + + Status = refit_call3_wrapper(gBS->LocateProtocol, &gEfiLegacyBootProtocolGuid, NULL, (VOID **) &LegacyBios); + if (EFI_ERROR (Status) || (Option == NULL)) { return; - } - - Status = LegacyBios->GetBbsInfo (LegacyBios, &HddCount, &HddInfo, &BbsCount, &LocalBbsTable); - - //Print (L"\n"); - //Print (L" NO Prio bb/dd/ff cl/sc Type Stat segm:offs\n"); - //Print (L"=============================================\n"); - - for (Idx = 0; Idx < BbsCount; Idx++) - { - if(LocalBbsTable[Idx].DeviceType == 0){ - continue; - } - - // Set devices of a particular type to BootPriority of 0. I believe 0 is the highest priority - if(LocalBbsTable[Idx].DeviceType == DeviceType){ - LocalBbsTable[Idx].BootPriority = 0; - } - -/* - Print ( - L" %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x\n", - (UINTN) Idx, - (UINTN) LocalBbsTable[Idx].BootPriority, - (UINTN) LocalBbsTable[Idx].Bus, - (UINTN) LocalBbsTable[Idx].Device, - (UINTN) LocalBbsTable[Idx].Function, - (UINTN) LocalBbsTable[Idx].Class, - (UINTN) LocalBbsTable[Idx].SubClass, - (UINTN) LocalBbsTable[Idx].DeviceType, - (UINTN) * (UINT16 *) &LocalBbsTable[Idx].StatusFlags, - (UINTN) LocalBbsTable[Idx].BootHandlerSegment, - (UINTN) LocalBbsTable[Idx].BootHandlerOffset, - (UINTN) ((LocalBbsTable[Idx].MfgStringSegment << 4) + LocalBbsTable[Idx].MfgStringOffset), - (UINTN) ((LocalBbsTable[Idx].DescStringSegment << 4) + LocalBbsTable[Idx].DescStringOffset) - ); -*/ - } - - //Print(L"\n"); + } + + OptionBBS = (BBS_BBS_DEVICE_PATH *) Option->DevicePath; + Status = refit_call5_wrapper(LegacyBios->GetBbsInfo, LegacyBios, &HddCount, &HddInfo, &BbsCount, &LocalBbsTable); + +// Print (L"\n"); +// Print (L" NO Prio bb/dd/ff cl/sc Type Stat segm:offs\n"); +// Print (L"=============================================\n"); + + for (Idx = 0; Idx < BbsCount; Idx++) { + if(LocalBbsTable[Idx].DeviceType == 0) { + continue; + } + + BdsBuildLegacyDevNameString (&LocalBbsTable[Idx], Idx, sizeof (Desc), Desc); + + // Set devices of a particular type to BootPriority of 0 or 1. 0 is the highest priority. + if (LocalBbsTable[Idx].DeviceType == OptionBBS->DeviceType) { + if (StriCmp(Desc, Option->Description) == 0) { + // This entry exactly matches what we're looking for; make it highest priority + LocalBbsTable[Idx].BootPriority = 0; + } else { + // This entry doesn't exactly match, but is the right disk type; make it a bit lower + // in priority. Done mainly as a fallback in case of string-matching weirdness. + LocalBbsTable[Idx].BootPriority = 1; + } // if/else + } else if (LocalBbsTable[Idx].BootPriority <= 1) { + // Something's got a high enough boot priority to interfere with booting + // our chosen entry, so bump it down a bit.... + LocalBbsTable[Idx].BootPriority = 2; + } // if/else if + +// Print ( +// L" %02x: %04x %02x/%02x/%02x %02x/%02x %04x %04x %04x:%04x\n", +// (UINTN) Idx, +// (UINTN) LocalBbsTable[Idx].BootPriority, +// (UINTN) LocalBbsTable[Idx].Bus, +// (UINTN) LocalBbsTable[Idx].Device, +// (UINTN) LocalBbsTable[Idx].Function, +// (UINTN) LocalBbsTable[Idx].Class, +// (UINTN) LocalBbsTable[Idx].SubClass, +// (UINTN) LocalBbsTable[Idx].DeviceType, +// (UINTN) * (UINT16 *) &LocalBbsTable[Idx].StatusFlags, +// (UINTN) LocalBbsTable[Idx].BootHandlerSegment, +// (UINTN) LocalBbsTable[Idx].BootHandlerOffset, +// (UINTN) ((LocalBbsTable[Idx].MfgStringSegment << 4) + LocalBbsTable[Idx].MfgStringOffset), +// (UINTN) ((LocalBbsTable[Idx].DescStringSegment << 4) + LocalBbsTable[Idx].DescStringOffset) +// ); +// Print(L"%s\n", Desc); + + } // for +// PauseForKey(); } -// Internal helper function -// BOOLEAN ArrayContains(UINT16* Arr, UINT8 ArrLen, UINT8 Target) -// { -// UINT8 i; -// for(i = 0; i < ArrLen; i++) -// { -// if(Arr[i] == Target) -// return TRUE; -// } -// -// return FALSE; -// } - /** Boot the legacy system with the boot option @@ -113,31 +113,14 @@ BdsLibDoLegacyBoot ( { EFI_STATUS Status; EFI_LEGACY_BIOS_PROTOCOL *LegacyBios; - BBS_BBS_DEVICE_PATH *OptionBBS; - Status = gBS->LocateProtocol (&gEfiLegacyBootProtocolGuid, NULL, (VOID **) &LegacyBios); + Status = refit_call3_wrapper(gBS->LocateProtocol, &gEfiLegacyBootProtocolGuid, NULL, (VOID **) &LegacyBios); if (EFI_ERROR (Status)) { return EFI_UNSUPPORTED; } - OptionBBS = (BBS_BBS_DEVICE_PATH *) Option->DevicePath; - - Print(L"\n\n"); - Print(L"Option->Name='%s'\n", Option->OptionName); - Print(L"Option->Number='%d'\n", Option->OptionNumber); - Print(L"Option->Description='%s'\n", Option->Description); - Print(L"Option->LoadOptionsSize='%d'\n",Option->LoadOptionsSize); - Print(L"Option->BootCurrent='%d'\n",Option->BootCurrent); - Print(L"Option->DevicePath->Type= '%d'\n", Option->DevicePath->Type); - Print(L"Option->DevicePath->SubType= '%d'\n", Option->DevicePath->SubType); - Print(L"Option->DevicePath->Length[0]= '%d'\n", Option->DevicePath->Length[0]); - Print(L"Option->DevicePath->Length[1]= '%d'\n", Option->DevicePath->Length[1]); - Print(L"OptionBBS->DeviceType='%d'\n",OptionBBS->DeviceType); - Print(L"OptionBBS->StatusFlag='%d'\n",OptionBBS->StatusFlag); - Print(L"OptionBBS->String[0]='%s'\n",OptionBBS->String); - Print(L"About to legacy boot!\n"); - PauseForKey(); - - UpdateBbsTable(OptionBBS->DeviceType); - - return LegacyBios->LegacyBoot (LegacyBios, (BBS_BBS_DEVICE_PATH *) Option->DevicePath, Option->LoadOptionsSize, Option->LoadOptions); -} \ No newline at end of file + + UpdateBbsTable(Option); + + return refit_call4_wrapper(LegacyBios->LegacyBoot, LegacyBios, (BBS_BBS_DEVICE_PATH *) Option->DevicePath, + Option->LoadOptionsSize, Option->LoadOptions); +}