Bootmgr: report boot order

This commit is contained in:
李通洲
2025-03-23 21:30:53 +08:00
parent 4d58d1be66
commit 9eca6e0b48
5 changed files with 13 additions and 6 deletions
+1
View File
@@ -6,6 +6,7 @@ typedef struct FFBootmgrResult
{
FFstrbuf name;
FFstrbuf firmware;
uint16_t order;
bool secureBoot;
} FFBootmgrResult;
+3 -1
View File
@@ -35,8 +35,10 @@ const char* ffDetectBootmgr(FFBootmgrResult* result)
if (ioctl(efifd, EFIIOC_VAR_GET, &ioc) < 0 || ioc.datasize != 2)
return "ioctl(EFIIOC_VAR_GET, BootCurrent) failed";
result->order = *(uint16_t*)buffer;
unsigned char hex[5];
snprintf((char*) hex, sizeof(hex), "%04X", *(uint16_t*)buffer);
snprintf((char*) hex, sizeof(hex), "%04X", result->order);
ioc.datasize = sizeof(buffer);
ioc.name = (efi_char[]){ 'B', 'o', 'o', 't', hex[0], hex[1], hex[2], hex[3], '\0' };
ioc.namesize = sizeof("Boot####") * 2;
+4 -2
View File
@@ -11,8 +11,10 @@ const char* ffDetectBootmgr(FFBootmgrResult* result)
if (ffReadFileData(FF_EFIVARS_PATH_PREFIX "BootCurrent-" FF_EFI_GLOBAL_GUID, sizeof(buffer), buffer) != 6)
return "Failed to read efivar: BootCurrent";
uint16_t value = *(uint16_t *)&buffer[4];
snprintf((char*) buffer, sizeof(buffer), FF_EFIVARS_PATH_PREFIX "Boot%04X-" FF_EFI_GLOBAL_GUID, value);
result->order = *(uint16_t *)&buffer[4];
snprintf((char*) buffer, sizeof(buffer), FF_EFIVARS_PATH_PREFIX "Boot%04X-" FF_EFI_GLOBAL_GUID, result->order);
ssize_t size = ffReadFileData((const char*) buffer, sizeof(buffer), buffer);
if (size < 5 + (int) sizeof(FFEfiLoadOption) || size == (ssize_t) sizeof(buffer))
+2 -3
View File
@@ -32,13 +32,12 @@ const char* ffDetectBootmgr(FFBootmgrResult* result)
if (enablePrivilege(L"SeSystemEnvironmentPrivilege") != NULL)
return "Failed to enable SeSystemEnvironmentPrivilege";
uint16_t value;
if (GetFirmwareEnvironmentVariableW(L"BootCurrent", L"{" FF_EFI_GLOBAL_GUID L"}", &value, sizeof(value)) != 2)
if (GetFirmwareEnvironmentVariableW(L"BootCurrent", L"{" FF_EFI_GLOBAL_GUID L"}", &result->order, sizeof(result->order)) != 2)
return "GetFirmwareEnvironmentVariableW(BootCurrent) failed";
uint8_t buffer[2048];
wchar_t key[16];
swprintf(key, ARRAY_SIZE(key), L"Boot%04X", value);
swprintf(key, ARRAY_SIZE(key), L"Boot%04X", result->order);
uint32_t size = GetFirmwareEnvironmentVariableW(key, L"{" FF_EFI_GLOBAL_GUID L"}", buffer, sizeof(buffer));
if (size < sizeof(FFEfiLoadOption) || size == ARRAY_SIZE(buffer))
return "GetFirmwareEnvironmentVariableW(Boot####) failed";
+3
View File
@@ -42,6 +42,7 @@ void ffPrintBootmgr(FFBootmgrOptions* options)
FF_FORMAT_ARG(bootmgr.firmware, "firmware-path"),
FF_FORMAT_ARG(firmwareName, "firmware-name"),
FF_FORMAT_ARG(bootmgr.secureBoot, "secure-boot"),
FF_FORMAT_ARG(bootmgr.order, "order"),
}));
}
@@ -102,6 +103,7 @@ void ffGenerateBootmgrJsonResult(FF_MAYBE_UNUSED FFBootmgrOptions* options, yyjs
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
yyjson_mut_obj_add_strbuf(doc, obj, "name", &bootmgr.name);
yyjson_mut_obj_add_strbuf(doc, obj, "firmware", &bootmgr.firmware);
yyjson_mut_obj_add_uint(doc, obj, "order", bootmgr.order);
yyjson_mut_obj_add_bool(doc, obj, "secureBoot", bootmgr.secureBoot);
exit:
@@ -122,6 +124,7 @@ static FFModuleBaseInfo ffModuleInfo = {
{"Firmware file path", "firmware-path"},
{"Firmware file name", "firmware-name"},
{"Is secure boot enabled", "secure-boot"},
{"Boot order", "order"},
}))
};