From 7e105c98dabad88bb44fc8fefad2dbb2a8117c96 Mon Sep 17 00:00:00 2001 From: jief666 Date: Fri, 19 Jan 2024 04:14:17 +0100 Subject: [PATCH] Add "FirstAvailable" option for DefaultVolume. --- OpenCorePkg | 2 +- rEFIt_UEFI/Platform/Settings.h | 2 ++ rEFIt_UEFI/Settings/ConfigPlist/Config_Boot.h | 7 ++++++- rEFIt_UEFI/cpp_foundation/XObjArray.h | 8 ++++++++ rEFIt_UEFI/entry_scan/legacy.cpp | 2 +- rEFIt_UEFI/entry_scan/loader.cpp | 2 +- rEFIt_UEFI/entry_scan/tool.cpp | 2 +- rEFIt_UEFI/gui/REFIT_MAINMENU_SCREEN.cpp | 4 ++++ rEFIt_UEFI/refit/lib.cpp | 11 ++++------- rEFIt_UEFI/refit/main.cpp | 4 +++- 10 files changed, 31 insertions(+), 13 deletions(-) diff --git a/OpenCorePkg b/OpenCorePkg index 0fcc050a4..b29733000 160000 --- a/OpenCorePkg +++ b/OpenCorePkg @@ -1 +1 @@ -Subproject commit 0fcc050a44f6fa06788b349e65b4e10fcdabde67 +Subproject commit b297330007bb21302d9fce22d49786443a5750ee diff --git a/rEFIt_UEFI/Platform/Settings.h b/rEFIt_UEFI/Platform/Settings.h index f503c2e72..39f13bf50 100644 --- a/rEFIt_UEFI/Platform/Settings.h +++ b/rEFIt_UEFI/Platform/Settings.h @@ -670,6 +670,7 @@ public: XBool NeverDoRecovery = false; XBool LastBootedVolume = false; XStringW DefaultVolume = XStringW(); + bool BootFirstAvailable = false; XStringW DefaultLoader = XStringW(); XBool DebugLog = false; XBool FastBoot = false; @@ -736,6 +737,7 @@ public: NeverDoRecovery = other.dgetNeverDoRecovery(); LastBootedVolume = other.dgetLastBootedVolume(); DefaultVolume = other.dgetDefaultVolume(); + BootFirstAvailable = other.dgetBootFirstAvailable(); DefaultLoader = other.dgetDefaultLoader(); DebugLog = other.dgetDebugLog(); FastBoot = other.dgetFastBoot(); diff --git a/rEFIt_UEFI/Settings/ConfigPlist/Config_Boot.h b/rEFIt_UEFI/Settings/ConfigPlist/Config_Boot.h index 1c1c942c7..58e78bd04 100644 --- a/rEFIt_UEFI/Settings/ConfigPlist/Config_Boot.h +++ b/rEFIt_UEFI/Settings/ConfigPlist/Config_Boot.h @@ -141,7 +141,12 @@ public: const decltype(DefaultVolume)::ValueType& dgetDefaultVolume() const { if ( !DefaultVolume.isDefined() ) return DefaultVolume.nullValue; if ( DefaultVolume.value().isEqualIC("LastBootedVolume") ) return DefaultVolume.nullValue; - return DefaultVolume.isDefined() ? DefaultVolume.value() : DefaultVolume.nullValue; + if ( DefaultVolume.value().isEqualIC("FirstAvailable") ) return DefaultVolume.nullValue; + return DefaultVolume.value(); + }; + bool dgetBootFirstAvailable() const { + if ( !DefaultVolume.isDefined() ) return false; + return DefaultVolume.value().isEqualIC("FirstAvailable"); }; const XString8& dgetDefaultLoader() const { return DefaultLoader.isDefined() ? DefaultLoader.value() : NullXString8; }; XBool dgetDebugLog() const { return Debug.isDefined() ? Debug.value() : XBool(false); }; diff --git a/rEFIt_UEFI/cpp_foundation/XObjArray.h b/rEFIt_UEFI/cpp_foundation/XObjArray.h index 97ec97b35..71488bd71 100644 --- a/rEFIt_UEFI/cpp_foundation/XObjArray.h +++ b/rEFIt_UEFI/cpp_foundation/XObjArray.h @@ -110,6 +110,14 @@ class XObjArrayNC template TYPE &operator[](IntegralType nIndex) { return ElementAt(nIndex); } + size_t indexOf(TYPE& e) const { + size_t i; + for ( i=0 ; i& other) const { if ( size() != other.size() ) return false; diff --git a/rEFIt_UEFI/entry_scan/legacy.cpp b/rEFIt_UEFI/entry_scan/legacy.cpp index 1bae78300..995ab443f 100644 --- a/rEFIt_UEFI/entry_scan/legacy.cpp +++ b/rEFIt_UEFI/entry_scan/legacy.cpp @@ -310,7 +310,7 @@ void AddCustomLegacy(void) if (Custom.settings.VolumeType != 0) { if (((1ull<DiskKind) & Custom.settings.VolumeType) == 0) { - DBG("skipped because media is ignored\n"); + DBG("skipped because media is ignored (VolumeType=%d DiskKind=%d)\n", Custom.settings.VolumeType, Volume->DiskKind); continue; } } diff --git a/rEFIt_UEFI/entry_scan/loader.cpp b/rEFIt_UEFI/entry_scan/loader.cpp index 583ef1ab7..cd3640a6c 100644 --- a/rEFIt_UEFI/entry_scan/loader.cpp +++ b/rEFIt_UEFI/entry_scan/loader.cpp @@ -2406,7 +2406,7 @@ STATIC void AddCustomEntry(IN UINTN CustomIndex, } if (Custom.settings.VolumeType != 0 && ((1<DiskKind) & Custom.settings.VolumeType) == 0) { - DBG("skipped because media is ignored\n"); + DBG("skipped because media is ignored (VolumeType=%d DiskKind=%d)\n", Custom.settings.VolumeType, Volume->DiskKind); continue; } diff --git a/rEFIt_UEFI/entry_scan/tool.cpp b/rEFIt_UEFI/entry_scan/tool.cpp index 67e831a5e..5694abebf 100644 --- a/rEFIt_UEFI/entry_scan/tool.cpp +++ b/rEFIt_UEFI/entry_scan/tool.cpp @@ -278,7 +278,7 @@ void AddCustomTool(void) if (Custom.settings.VolumeType != 0) { if (((1ull<DiskKind) & Custom.settings.VolumeType) == 0) { - DBG("skipped because media is ignored\n"); + DBG("skipped because media is ignored (VolumeType=%d DiskKind=%d)\n", Custom.settings.VolumeType, Volume->DiskKind); continue; } } diff --git a/rEFIt_UEFI/gui/REFIT_MAINMENU_SCREEN.cpp b/rEFIt_UEFI/gui/REFIT_MAINMENU_SCREEN.cpp index 293606b7a..5fa5d9569 100644 --- a/rEFIt_UEFI/gui/REFIT_MAINMENU_SCREEN.cpp +++ b/rEFIt_UEFI/gui/REFIT_MAINMENU_SCREEN.cpp @@ -169,6 +169,10 @@ void REFIT_MENU_SCREEN::DrawTextCorner(UINTN TextC, UINT8 Align) // Display Clover boot volume if (SelfVolume->VolLabel.notEmpty() && SelfVolume->VolLabel[0] != L'#') { Text = SWPrintf("%ls, booted from %ls %ls", gFirmwareRevision, SelfVolume->VolLabel.wc_str(), self.getCloverDirFullPath().wc_str()); + }else{ + if ( SelfVolume->VolName.notEmpty() ) { + Text = SWPrintf("%ls %ls%ls", gFirmwareRevision, SelfVolume->VolName.wc_str(), self.getCloverDirFullPath().wc_str()); + } } if (Text.isEmpty()) { Text = SWPrintf("%ls %ls", gFirmwareRevision, /*SelfVolume->VolName.wc_str(),*/ self.getCloverDirFullPath().wc_str()); diff --git a/rEFIt_UEFI/refit/lib.cpp b/rEFIt_UEFI/refit/lib.cpp index 5725965ab..a357d8ba7 100644 --- a/rEFIt_UEFI/refit/lib.cpp +++ b/rEFIt_UEFI/refit/lib.cpp @@ -584,16 +584,9 @@ static EFI_STATUS ScanVolume(IN OUT REFIT_VOLUME *Volume) Volume->DevicePathString = FileDevicePathToXStringW(Volume->DevicePath); } -#if REFIT_DEBUG > 0 if (Volume->DevicePath != NULL) { DBG(" %ls\n", FileDevicePathToXStringW(Volume->DevicePath).wc_str()); - //#if REFIT_DEBUG >= 2 - // DumpHex(1, 0, GetDevicePathSize(Volume->DevicePath), Volume->DevicePath); - //#endif } -#else - DBG("\n"); -#endif Volume->ApfsFileSystemUUID = APFSPartitionUUIDExtract(Volume->DevicePath); // NullXString8 if it's not an APFS volume Volume->DiskKind = DISK_KIND_INTERNAL; // default @@ -996,6 +989,10 @@ void ScanVolumes(void) Volume->Hidden = false; // default to not hidden Status = ScanVolume(Volume); +#ifdef JIEF_DEBUG + DBG(" kind=%d\n", Volume->DiskKind); +#endif + if (!EFI_ERROR(Status)) { Volume->Index = HandleIndex; Volumes.AddReference(Volume, true); diff --git a/rEFIt_UEFI/refit/main.cpp b/rEFIt_UEFI/refit/main.cpp index dc50cbd25..c3fbfbd1c 100644 --- a/rEFIt_UEFI/refit/main.cpp +++ b/rEFIt_UEFI/refit/main.cpp @@ -2519,6 +2519,8 @@ INTN FindDefaultEntry(void) // DBG("FindDefaultEntry ...\n"); //DbgHeader("FindDefaultEntry"); + if ( gSettings.Boot.BootFirstAvailable ) return 0; + // // try to detect volume set by Startup Disk or previous Clover selection // with broken nvram this requires emulation to be installed. @@ -3379,7 +3381,7 @@ displayFreeMemory("Before RunMainMenu"_XS8); #endif MenuExit = MainMenu.RunMainMenu(DefaultIndex, &ChosenEntry); } - // DBG("exit from MainMenu %llu\n", MenuExit); //MENU_EXIT_ENTER=(1) MENU_EXIT_DETAILS=3 +// DBG("exit from MainMenu %llu ChosenEntry=%zu\n", MenuExit, MainMenu.Entries.indexOf(*ChosenEntry)); //MENU_EXIT_ENTER=(1) MENU_EXIT_DETAILS=3 // disable default boot - have sense only in the first run gSettings.Boot.Timeout = -1; if ((DefaultEntry != NULL) && (MenuExit == MENU_EXIT_TIMEOUT)) {