From 9f9363a7e71efe5a9ab34be32d15bc5e2a398e72 Mon Sep 17 00:00:00 2001 From: Kay Sievers Date: Wed, 20 Mar 2013 03:07:02 +0100 Subject: [PATCH] setup: print only boot loader entries with an actual loader binary --- src/setup/efivars.c | 5 ++++- src/setup/efivars.h | 2 +- src/setup/setup.c | 41 +++++++++++++++++++++-------------------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/setup/efivars.c b/src/setup/efivars.c index 3764d28..7123257 100644 --- a/src/setup/efivars.c +++ b/src/setup/efivars.c @@ -330,7 +330,7 @@ struct device_path { }; } __attribute__((packed)); -int efi_get_boot_option(uint16_t id, char **title, uint8_t part_uuid[16], char **path) { +int efi_get_boot_option(uint16_t id, char **title, uint8_t part_uuid[16], char **path, bool *active) { char boot_id[9]; uint8_t *buf = NULL; size_t l; @@ -418,6 +418,9 @@ int efi_get_boot_option(uint16_t id, char **title, uint8_t part_uuid[16], char * else free(p); + if (active) + *active = !!header->attr & LOAD_OPTION_ACTIVE; + free(buf); return 0; err: diff --git a/src/setup/efivars.h b/src/setup/efivars.h index 1ce1e0c..dfe7355 100644 --- a/src/setup/efivars.h +++ b/src/setup/efivars.h @@ -38,7 +38,7 @@ int is_efi_secure_boot_setup_mode(void); int efi_get_variable(const uint8_t vendor[16], const char *name, void **value, size_t *size); int efi_set_variable( const uint8_t vendor[16], const char *name, const void *value, size_t size); int efi_get_variable_string(const uint8_t vendor[16], const char *name, char **p); -int efi_get_boot_option(uint16_t id, char **title, uint8_t part_uuid[16], char **path); +int efi_get_boot_option(uint16_t id, char **title, uint8_t part_uuid[16], char **path, bool *active); int efi_get_boot_options(uint16_t **options); int efi_add_boot_option(uint16_t id, const char *title, diff --git a/src/setup/setup.c b/src/setup/setup.c index 53f86d2..b3bad40 100644 --- a/src/setup/setup.c +++ b/src/setup/setup.c @@ -397,30 +397,31 @@ static int status_binaries(const char *esp_path) { return 0; } -static int print_efi_option(uint16_t id) { +static int print_efi_option(uint16_t id, bool in_order) { char *title = NULL; char *path = NULL; uint8_t partition[16]; + bool active; int r = 0; - r = efi_get_boot_option(id, &title, partition, &path); - if (r < 0) { - fprintf(stderr, "Failed to read EFI boot entry Boot%04X: %s.\n", id, strerror(-r)); + r = efi_get_boot_option(id, &title, partition, &path, &active); + if (r < 0) goto finish; - } + + /* print only configured entries with partition information */ + if (!path || memcmp(partition, UUID_EMPTY, 16) == 0) + return 0; printf(" Title: %s\n", strna(title)); printf(" Number: %04X\n", id); - if (path) - printf(" Binary: %s\n", path); - - if (memcmp(partition, UUID_EMPTY, 16) != 0) - printf(" Partition: /dev/disk/by-partuuid/%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n", - partition[0], partition[1], partition[2], partition[3], partition[4], partition[5], partition[6], partition[7], - partition[8], partition[9], partition[10], partition[11], partition[12], partition[13], partition[14], partition[15]); + printf(" Flags: %sactive%s\n", active ? "" : "in", in_order ? ", in-order" : ""); + printf(" Binary: %s\n", path); + printf(" Partition: /dev/disk/by-partuuid/%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n", + partition[0], partition[1], partition[2], partition[3], partition[4], partition[5], partition[6], partition[7], + partition[8], partition[9], partition[10], partition[11], partition[12], partition[13], partition[14], partition[15]); + printf("\n"); finish: - printf("\n"); free(title); free(path); return r; @@ -452,7 +453,7 @@ static int status_variables(void) { r = efi_get_variable_string(EFI_VENDOR_LOADER, "LoaderImageIdentifier", &s); if (r == 0) { tilt_backslashes(s); - printf(" Binary: %s\n", s); + printf(" Loader: %s\n", s); free(s); } @@ -467,7 +468,6 @@ static int status_variables(void) { printf("\n"); } - printf("Boot entries found in EFI variables:\n"); n_options = efi_get_boot_options(&options); if (n_options < 0) { if (n_options == -ENOENT) @@ -479,9 +479,9 @@ static int status_variables(void) { goto finish; } + printf("Boot loader entries found in EFI variables:\n"); n_order = efi_get_boot_order(&order); if (n_order == -ENOENT) { - fprintf(stderr, "No boot entries registered in EFI variables.\n"); n_order = 0; } else if (n_order < 0) { fprintf(stderr, "Failed to read EFI boot order.\n"); @@ -489,10 +489,11 @@ static int status_variables(void) { goto finish; } + /* print entries in BootOrder first */ for (i = 0; i < n_order; i++) - print_efi_option(order[i]); + print_efi_option(order[i], true); - printf("Inactive boot entries found in EFI variables:\n"); + /* print remaining entries */ for (i = 0; i < n_options; i++) { int j; bool found = false; @@ -506,7 +507,7 @@ static int status_variables(void) { if (found) continue; - print_efi_option(options[i]); + print_efi_option(options[i], false); } r = 0; @@ -857,7 +858,7 @@ static bool same_entry(uint16_t id, const uint8_t uuid[16], const char *path) { int err; bool same = false; - err = efi_get_boot_option(id, NULL, ouuid, &opath); + err = efi_get_boot_option(id, NULL, ouuid, &opath, NULL); if (err < 0) return false; if (memcmp(uuid, ouuid, 16) != 0) -- 2.7.4