Skip to content

Commit 9eca6e0

Browse files
committed
Bootmgr: report boot order
1 parent 4d58d1b commit 9eca6e0

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

src/detection/bootmgr/bootmgr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ typedef struct FFBootmgrResult
66
{
77
FFstrbuf name;
88
FFstrbuf firmware;
9+
uint16_t order;
910
bool secureBoot;
1011
} FFBootmgrResult;
1112

src/detection/bootmgr/bootmgr_bsd.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ const char* ffDetectBootmgr(FFBootmgrResult* result)
3535
if (ioctl(efifd, EFIIOC_VAR_GET, &ioc) < 0 || ioc.datasize != 2)
3636
return "ioctl(EFIIOC_VAR_GET, BootCurrent) failed";
3737

38+
result->order = *(uint16_t*)buffer;
39+
3840
unsigned char hex[5];
39-
snprintf((char*) hex, sizeof(hex), "%04X", *(uint16_t*)buffer);
41+
snprintf((char*) hex, sizeof(hex), "%04X", result->order);
4042
ioc.datasize = sizeof(buffer);
4143
ioc.name = (efi_char[]){ 'B', 'o', 'o', 't', hex[0], hex[1], hex[2], hex[3], '\0' };
4244
ioc.namesize = sizeof("Boot####") * 2;

src/detection/bootmgr/bootmgr_linux.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ const char* ffDetectBootmgr(FFBootmgrResult* result)
1111
if (ffReadFileData(FF_EFIVARS_PATH_PREFIX "BootCurrent-" FF_EFI_GLOBAL_GUID, sizeof(buffer), buffer) != 6)
1212
return "Failed to read efivar: BootCurrent";
1313

14-
uint16_t value = *(uint16_t *)&buffer[4];
15-
snprintf((char*) buffer, sizeof(buffer), FF_EFIVARS_PATH_PREFIX "Boot%04X-" FF_EFI_GLOBAL_GUID, value);
14+
15+
result->order = *(uint16_t *)&buffer[4];
16+
17+
snprintf((char*) buffer, sizeof(buffer), FF_EFIVARS_PATH_PREFIX "Boot%04X-" FF_EFI_GLOBAL_GUID, result->order);
1618

1719
ssize_t size = ffReadFileData((const char*) buffer, sizeof(buffer), buffer);
1820
if (size < 5 + (int) sizeof(FFEfiLoadOption) || size == (ssize_t) sizeof(buffer))

src/detection/bootmgr/bootmgr_windows.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ const char* ffDetectBootmgr(FFBootmgrResult* result)
3232
if (enablePrivilege(L"SeSystemEnvironmentPrivilege") != NULL)
3333
return "Failed to enable SeSystemEnvironmentPrivilege";
3434

35-
uint16_t value;
36-
if (GetFirmwareEnvironmentVariableW(L"BootCurrent", L"{" FF_EFI_GLOBAL_GUID L"}", &value, sizeof(value)) != 2)
35+
if (GetFirmwareEnvironmentVariableW(L"BootCurrent", L"{" FF_EFI_GLOBAL_GUID L"}", &result->order, sizeof(result->order)) != 2)
3736
return "GetFirmwareEnvironmentVariableW(BootCurrent) failed";
3837

3938
uint8_t buffer[2048];
4039
wchar_t key[16];
41-
swprintf(key, ARRAY_SIZE(key), L"Boot%04X", value);
40+
swprintf(key, ARRAY_SIZE(key), L"Boot%04X", result->order);
4241
uint32_t size = GetFirmwareEnvironmentVariableW(key, L"{" FF_EFI_GLOBAL_GUID L"}", buffer, sizeof(buffer));
4342
if (size < sizeof(FFEfiLoadOption) || size == ARRAY_SIZE(buffer))
4443
return "GetFirmwareEnvironmentVariableW(Boot####) failed";

src/modules/bootmgr/bootmgr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void ffPrintBootmgr(FFBootmgrOptions* options)
4242
FF_FORMAT_ARG(bootmgr.firmware, "firmware-path"),
4343
FF_FORMAT_ARG(firmwareName, "firmware-name"),
4444
FF_FORMAT_ARG(bootmgr.secureBoot, "secure-boot"),
45+
FF_FORMAT_ARG(bootmgr.order, "order"),
4546
}));
4647
}
4748

@@ -102,6 +103,7 @@ void ffGenerateBootmgrJsonResult(FF_MAYBE_UNUSED FFBootmgrOptions* options, yyjs
102103
yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result");
103104
yyjson_mut_obj_add_strbuf(doc, obj, "name", &bootmgr.name);
104105
yyjson_mut_obj_add_strbuf(doc, obj, "firmware", &bootmgr.firmware);
106+
yyjson_mut_obj_add_uint(doc, obj, "order", bootmgr.order);
105107
yyjson_mut_obj_add_bool(doc, obj, "secureBoot", bootmgr.secureBoot);
106108

107109
exit:
@@ -122,6 +124,7 @@ static FFModuleBaseInfo ffModuleInfo = {
122124
{"Firmware file path", "firmware-path"},
123125
{"Firmware file name", "firmware-name"},
124126
{"Is secure boot enabled", "secure-boot"},
127+
{"Boot order", "order"},
125128
}))
126129
};
127130

0 commit comments

Comments
 (0)