mirror of
https://github.com/Metabolix/HackBGRT.git
synced 2026-04-10 20:22:12 -07:00
Improve output and README for BootOrder problems
Report own entry status (missing, disabled, after windows, enabled). Also improve README instructions on the topic.
This commit is contained in:
@@ -264,13 +264,13 @@ public class Efi {
|
||||
try {
|
||||
var log = GetVariable("HackBGRTLog", EFI_HACKBGRT_GUID);
|
||||
if (log.Data == null) {
|
||||
return "Log is empty.";
|
||||
return "Boot log is empty.";
|
||||
}
|
||||
return new string(BytesToUInt16s(log.Data).Select(i => (char)i).ToArray());
|
||||
} catch (NotImplementedException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
return $"Log not found: {e.ToString()}";
|
||||
return $"Boot log not found: {e.ToString()}";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,16 @@ public class EfiBootEntries {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Status of the own boot entry.
|
||||
*/
|
||||
public enum OwnEntryStatus {
|
||||
NotFound,
|
||||
Disabled,
|
||||
EnabledAfterWindows,
|
||||
Enabled
|
||||
}
|
||||
|
||||
/**
|
||||
* Path to the Windows boot loader.
|
||||
*/
|
||||
@@ -173,6 +183,26 @@ public class EfiBootEntries {
|
||||
get { return FindEntry(null); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the own entry is enabled.
|
||||
*/
|
||||
public OwnEntryStatus GetOwnEntryStatus() {
|
||||
var (ownNum, ownVar, _) = OwnEntry;
|
||||
if (ownVar == null) {
|
||||
return OwnEntryStatus.NotFound;
|
||||
}
|
||||
var (msNum, _, _) = WindowsEntry;
|
||||
var msPos = BootOrderInts.IndexOf(msNum);
|
||||
var ownPos = BootOrderInts.IndexOf(ownNum);
|
||||
if (ownPos < 0) {
|
||||
return OwnEntryStatus.Disabled;
|
||||
}
|
||||
if (ownPos < msPos || msPos < 0) {
|
||||
return OwnEntryStatus.Enabled;
|
||||
}
|
||||
return OwnEntryStatus.EnabledAfterWindows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the said boot entry from BootOrder.
|
||||
*
|
||||
@@ -295,15 +325,4 @@ public class EfiBootEntries {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to log the boot entries.
|
||||
*/
|
||||
public static void TryLogEntries() {
|
||||
try {
|
||||
new EfiBootEntries().LogEntries();
|
||||
} catch (Exception e) {
|
||||
Setup.Log($"LogEntries failed: {e.ToString()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
36
src/Setup.cs
36
src/Setup.cs
@@ -482,13 +482,12 @@ public class Setup {
|
||||
var fwbootmgr = "{fwbootmgr}";
|
||||
Execute("bcdedit", $"/set {fwbootmgr} displayorder {guid} /addfirst", true);
|
||||
WriteLine("Enabled NVRAM entry for HackBGRT with BCDEdit.");
|
||||
// Verify that the entry was created.
|
||||
Execute("bcdedit", "/enum firmware", true);
|
||||
|
||||
Execute("bcdedit", $"/enum {guid}", true);
|
||||
var e = new EfiBootEntries();
|
||||
e.MakeOwnEntry(false, DryRun); // Fix load options for shim.
|
||||
e.EnableOwnEntry(DryRun);
|
||||
Execute("bcdedit", $"/enum {guid}", true);
|
||||
e.LogEntries();
|
||||
} catch (Exception e) {
|
||||
Log($"EnableBCDEdit failed: {e.ToString()}");
|
||||
throw new SetupException("Failed to enable HackBGRT with BCDEdit!");
|
||||
@@ -536,9 +535,6 @@ public class Setup {
|
||||
e.MakeOwnEntry(true, DryRun);
|
||||
e.EnableOwnEntry(DryRun);
|
||||
WriteLine("Enabled NVRAM entry for HackBGRT.");
|
||||
// Verify that the entry was created.
|
||||
e.LogEntries();
|
||||
Execute("bcdedit", "/enum firmware", true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -549,6 +545,27 @@ public class Setup {
|
||||
WriteLine("Disabled NVRAM entry for HackBGRT.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Log boot entries and report the status of HackBGRT boot entry.
|
||||
*/
|
||||
public void CheckEntries() {
|
||||
try {
|
||||
var efiBootEntries = new EfiBootEntries();
|
||||
efiBootEntries.LogEntries();
|
||||
var entryStatusText = efiBootEntries.GetOwnEntryStatus() switch {
|
||||
EfiBootEntries.OwnEntryStatus.NotFound => "missing",
|
||||
EfiBootEntries.OwnEntryStatus.Disabled => "disabled (not in BootOrder)",
|
||||
EfiBootEntries.OwnEntryStatus.EnabledAfterWindows => "disabled (after Windows in BootOrder)",
|
||||
EfiBootEntries.OwnEntryStatus.Enabled => "enabled correctly",
|
||||
_ => throw new SetupException("Unknown HackBGRT boot entry status!")
|
||||
};
|
||||
WriteLine($"HackBGRT boot entry is {entryStatusText}.");
|
||||
} catch (Exception e) {
|
||||
WriteLine($"Failed to check EFI boot entries: {e.Message}");
|
||||
Setup.Log(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get paths related to MS boot loader.
|
||||
*/
|
||||
@@ -975,8 +992,10 @@ public class Setup {
|
||||
};
|
||||
var bootLog = tryGetBootLog();
|
||||
Setup.Log(bootLog);
|
||||
|
||||
Efi.LogBGRT();
|
||||
EfiBootEntries.TryLogEntries();
|
||||
CheckEntries();
|
||||
|
||||
if (GetBootTime() is DateTime bootTime) {
|
||||
var configTime = new[] { File.GetCreationTime("config.txt"), File.GetLastWriteTime("config.txt") }.Max();
|
||||
Log($"Boot time = {bootTime}, config.txt changed = {configTime}");
|
||||
@@ -1008,6 +1027,8 @@ public class Setup {
|
||||
HandleBitLocker();
|
||||
enable();
|
||||
verify(revert);
|
||||
CheckEntries();
|
||||
Execute("bcdedit", "/enum firmware", true);
|
||||
};
|
||||
foreach (var arg in actions) {
|
||||
Log($"Running action '{arg}'.");
|
||||
@@ -1033,6 +1054,7 @@ public class Setup {
|
||||
BootToFW();
|
||||
} else if (arg == "show-boot-log") {
|
||||
WriteLine(bootLog);
|
||||
CheckEntries();
|
||||
} else {
|
||||
throw new SetupException($"Invalid action: '{arg}'!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user