2 * Copyright (c) 2017-2018 Netflix, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer
9 * in this position and unchanged.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include <sys/cdefs.h>
28 #include <sys/param.h>
48 #include <geom/geom.h>
49 #include <geom/geom_ctl.h>
50 #include <geom/geom_int.h>
55 #include <efivar-dp.h>
57 #ifndef LOAD_OPTION_ACTIVE
58 #define LOAD_OPTION_ACTIVE 0x00000001
61 #ifndef LOAD_OPTION_CATEGORY_BOOT
62 #define LOAD_OPTION_CATEGORY_BOOT 0x00000000
65 #define BAD_LENGTH ((size_t)-1)
67 #define EFI_OS_INDICATIONS_BOOT_TO_FW_UI 0x0000000000000001
69 typedef struct _bmgr_opts {
101 static struct option lopts[] = {
102 {"activate", no_argument, NULL, 'a'},
103 {"bootnext", no_argument, NULL, 'n'}, /* set bootnext */
104 {"bootnum", required_argument, NULL, 'b'},
105 {"bootorder", required_argument, NULL, 'o'}, /* set order */
106 {"copy", required_argument, NULL, 'C'}, /* Copy boot method */
107 {"create", no_argument, NULL, 'c'},
108 {"deactivate", no_argument, NULL, 'A'},
109 {"del-timeout", no_argument, NULL, 'T'},
110 {"delete", no_argument, NULL, 'B'},
111 {"delete-bootnext", no_argument, NULL, 'N'},
112 {"device-path", no_argument, NULL, 'd'},
113 {"dry-run", no_argument, NULL, 'D'},
114 {"env", required_argument, NULL, 'e'},
115 {"esp", no_argument, NULL, 'E'},
116 {"efidev", required_argument, NULL, 'u'},
117 {"fw-ui", no_argument, NULL, 'f'},
118 {"no-fw-ui", no_argument, NULL, 'F'},
119 {"help", no_argument, NULL, 'h'},
120 {"kernel", required_argument, NULL, 'k'},
121 {"label", required_argument, NULL, 'L'},
122 {"loader", required_argument, NULL, 'l'},
123 {"once", no_argument, NULL, 'O'},
124 {"set-timeout", required_argument, NULL, 't'},
125 {"unix-path", no_argument, NULL, 'p'},
126 {"verbose", no_argument, NULL, 'v'},
130 /* global efibootmgr opts */
131 static bmgr_opts_t opts;
133 static LIST_HEAD(efivars_head, entry) efivars =
134 LIST_HEAD_INITIALIZER(efivars);
147 LIST_ENTRY(entry) entries;
150 #define MAX_DP_LEN 4096
151 #define MAX_LOADOPT_LEN 8192
155 mangle_loader(char *loader)
159 for (c = loader; *c; c++)
167 #define COMMON_ATTRS EFI_VARIABLE_NON_VOLATILE | \
168 EFI_VARIABLE_BOOTSERVICE_ACCESS | \
169 EFI_VARIABLE_RUNTIME_ACCESS
172 * We use global guid, and common var attrs and
173 * find it better to just delete and re-create a var.
176 set_bootvar(const char *name, uint8_t *data, size_t size)
179 return efi_set_variable(EFI_GLOBAL_GUID, name, data, size,
185 " [-aAnB -b bootnum] [-N] [-t timeout] [-T] [-o bootorder] [-O] [--verbose] [--help]\n\
186 [-c -l loader [-k kernel] [-L label] [--dry-run] [-b bootnum]]"
188 #define CREATE_USAGE \
189 " efibootmgr -c -l loader [-k kernel] [-L label] [--dry-run] [-b bootnum] [-a]"
190 #define ORDER_USAGE \
191 " efibootmgr -o bootvarnum1,bootvarnum2,..."
192 #define TIMEOUT_USAGE \
193 " efibootmgr -t seconds"
194 #define DELETE_USAGE \
195 " efibootmgr -B -b bootnum"
196 #define ACTIVE_USAGE \
197 " efibootmgr [-a | -A] -b bootnum"
198 #define BOOTNEXT_USAGE \
199 " efibootmgr [-n | -N] -b bootnum"
202 parse_args(int argc, char *argv[])
207 while ((ch = getopt_long(argc, argv, "AaBb:C:cdDe:EFfhk:L:l:NnOo:pTt:v",
208 lopts, NULL)) != -1) {
211 opts.set_inactive = true;
214 opts.set_active = true;
217 opts.has_bootnum = true;
219 if (strncasecmp(arg, "boot", 4) == 0)
221 opts.bootnum = strtoul(arg, NULL, 16);
228 opts.cp_src = strtoul(optarg, NULL, 16);
229 errx(1, "Copy not implemented");
234 case 'D': /* should be remove dups XXX */
238 opts.device_path = true;
242 opts.env = strdup(optarg);
245 opts.esp_device = true;
248 opts.no_fw_ui = true;
255 errx(1, "%s", USAGE);
259 opts.kernel = strdup(optarg);
263 opts.label = strdup(optarg);
267 opts.loader = strdup(optarg);
268 opts.loader = mangle_loader(opts.loader);
271 opts.delete_bootnext = true;
274 opts.set_bootnext = true;
281 opts.order = strdup(optarg);
284 opts.unix_path = true;
287 opts.del_timeout = true;
290 opts.set_timeout = true;
291 opts.timeout = strtoul(optarg, NULL, 10);
294 opts.find_dev = true;
295 opts.dev = strdup(optarg);
304 errx(1, "%s",CREATE_USAGE);
308 if (opts.order != NULL && *opts.order == '\0')
309 errx(1, "%s", ORDER_USAGE);
311 if ((opts.set_inactive || opts.set_active) && !opts.has_bootnum)
312 errx(1, "%s", ACTIVE_USAGE);
314 if (opts.delete && !opts.has_bootnum)
315 errx(1, "%s", DELETE_USAGE);
317 if (opts.set_bootnext && !opts.has_bootnum)
318 errx(1, "%s", BOOTNEXT_USAGE);
327 char *next_name = NULL;
333 while ((ret = efi_get_next_variable_name(&guid, &next_name)) > 0) {
335 * Only pay attention to EFI:BootXXXX variables to get the list.
337 if (efi_guid_cmp(guid, &EFI_GLOBAL_GUID) != 0 ||
338 strlen(next_name) != 8 ||
339 strncmp(next_name, "Boot", 4) != 0 ||
340 !isxdigit(next_name[4]) ||
341 !isxdigit(next_name[5]) ||
342 !isxdigit(next_name[6]) ||
343 !isxdigit(next_name[7]))
345 nent = malloc(sizeof(struct entry));
346 nent->name = strdup(next_name);
348 ret = efi_get_variable(*guid, next_name, &nent->data,
349 &nent->size, &nent->attrs);
351 err(1, "efi_get_variable");
353 nent->idx = strtoul(&next_name[4], NULL, 16);
354 LIST_INSERT_HEAD(&efivars, nent, entries);
360 set_boot_order(char *order)
374 size = sizeof(uint16_t) * cnt;
375 new_data = malloc(size);
379 while ((next = strsep(&cp, ",")) != NULL) {
380 new_data[i] = strtoul(next, NULL, 16);
381 if (new_data[i] == 0 && errno == EINVAL) {
382 warnx("can't parse %s as a numb", next);
383 errx(1, "%s", ORDER_USAGE);
388 if (set_bootvar("BootOrder", (uint8_t*)new_data, size) < 0)
389 err(1, "Unabke to set BootOrder to %s", order);
394 handle_activity(int bootnum, bool active)
396 uint32_t attrs, load_attrs;
401 asprintf(&name, "%s%04X", "Boot", bootnum);
404 if (efi_get_variable(EFI_GLOBAL_GUID, name, &data, &size, &attrs) < 0)
405 err(1, "No such bootvar %s\n", name);
407 load_attrs = le32dec(data);
410 load_attrs |= LOAD_OPTION_ACTIVE;
412 load_attrs &= ~LOAD_OPTION_ACTIVE;
414 le32enc(data, load_attrs);
416 if (set_bootvar(name, data, size) < 0)
417 err(1, "handle activity efi_set_variable");
422 * add boot var to boot order.
423 * called by create boot var. There is no option
424 * to add one independent of create.
426 * Note: we currently don't support where it goes
427 * so it goes on the front, inactive.
428 * use -o 2,3,7 etc to affect order, -a to activate.
431 add_to_boot_order(char *bootvar)
438 val = strtoul(&bootvar[4], NULL, 16);
440 if (efi_get_variable(EFI_GLOBAL_GUID, "BootOrder", &data, &size, &attrs) < 0) {
441 if (errno == ENOENT) { /* create it and set this bootvar to active */
445 err(1, "efi_get_variable BootOrder");
449 * We have BootOrder with the current order
450 * so grow the array by one, add the value
451 * and write the new variable value.
453 size += sizeof(uint16_t);
459 if (size > sizeof(uint16_t))
460 memcpy(new + sizeof(uint16_t), data, size - sizeof(uint16_t));
462 if (set_bootvar("BootOrder", new, size) < 0)
463 err(1, "set_bootvar");
469 remove_from_order(uint16_t bootnum)
475 if (efi_get_variable(EFI_GLOBAL_GUID, "BootOrder", &data, &size, &attrs) < 0)
482 for (j = i = 0; i < size; i += sizeof(uint16_t)) {
483 if (le16dec(data + i) == bootnum)
485 memcpy(new + j, data + i, sizeof(uint16_t));
486 j += sizeof(uint16_t);
489 warnx("Boot variable %04x not in BootOrder", bootnum);
490 else if (set_bootvar("BootOrder", new, j) < 0)
491 err(1, "Unable to update BootOrder with new value");
497 delete_bootvar(int bootnum)
503 * Try to delete the boot variable and remocve it
504 * from the boot order. We always do both actions
505 * to make it easy to clean up from oopses.
507 if (bootnum < 0 || bootnum > 0xffff)
508 errx(1, "Bad boot variable %#x", bootnum);
509 asprintf(&name, "%s%04X", "Boot", bootnum);
512 printf("Removing boot variable '%s'\n", name);
513 if (efi_del_variable(EFI_GLOBAL_GUID, name) < 0) {
515 warn("cannot delete variable %s", name);
517 printf("Removing 0x%x from BootOrder\n", bootnum);
518 remove_from_order(bootnum);
529 if (efi_del_variable(EFI_GLOBAL_GUID, "BootNext") < 0)
530 err(1, "efi_del_variable");
534 handle_bootnext(uint16_t bootnum)
538 le16enc(&num, bootnum);
539 if (set_bootvar("BootNext", (uint8_t*)&bootnum, sizeof(uint16_t)) < 0)
540 err(1, "set_bootvar");
545 compare(const void *a, const void *b)
550 memcpy(&c, a, sizeof(uint16_t));
551 memcpy(&d, b, sizeof(uint16_t));
561 make_next_boot_var_name(void)
564 uint16_t *vals, next_free = 0;
569 LIST_FOREACH(v, &efivars, entries) {
573 vals = malloc(sizeof(uint16_t) * cnt);
578 LIST_FOREACH(v, &efivars, entries) {
581 qsort(vals, cnt, sizeof(uint16_t), compare);
582 /* if the hole is at the beginning, just return zero */
586 /* now just run the list looking for the first hole */
587 for (i = 0; i < cnt - 1 && next_free == 0; i++)
588 if (vals[i] + 1 != vals[i + 1])
589 next_free = vals[i] + 1;
591 next_free = vals[cnt - 1] + 1;
592 /* In theory we could have used all 65k slots -- what to do? */
596 asprintf(&name, "%s%04X", "Boot", next_free);
603 make_boot_var_name(uint16_t bootnum)
608 LIST_FOREACH(v, &efivars, entries) {
609 if (v->idx == bootnum)
613 asprintf(&name, "%s%04X", "Boot", bootnum);
620 create_loadopt(uint8_t *buf, size_t bufmax, uint32_t attributes, efidp dp, size_t dp_size,
621 const char *description, const uint8_t *optional_data, size_t optional_data_size)
623 efi_char *bbuf = NULL;
628 if (optional_data == NULL && optional_data_size != 0)
630 if (dp == NULL && dp_size != 0)
634 * Compute the length to make sure the passed in buffer is long enough.
636 utf8_to_ucs2(description, &bbuf, &desc_len);
637 len = sizeof(uint32_t) + sizeof(uint16_t) + desc_len + dp_size + optional_data_size;
643 le32enc(pos, attributes);
644 pos += sizeof (attributes);
646 le16enc(pos, dp_size);
647 pos += sizeof (uint16_t);
649 memcpy(pos, bbuf, desc_len); /* NB:desc_len includes strailing NUL */
653 memcpy(pos, dp, dp_size);
656 if (optional_data && optional_data_size > 0) {
657 memcpy(pos, optional_data, optional_data_size);
658 pos += optional_data_size;
666 make_boot_var(const char *label, const char *loader, const char *kernel, const char *env, bool dry_run,
667 int bootnum, bool activate)
669 struct entry *new_ent;
670 uint32_t load_attrs = 0;
671 uint8_t *load_opt_buf;
672 size_t lopt_size, llen, klen;
673 efidp dp, loaderdp, kerneldp;
674 char *bootvar = NULL;
677 assert(label != NULL);
680 bootvar = make_next_boot_var_name();
682 bootvar = make_boot_var_name((uint16_t)bootnum);
684 err(1, "bootvar creation");
686 errx(1, "Must specify boot loader");
687 ret = efivar_unix_path_to_device_path(loader, &loaderdp);
689 errc(1, ret, "Cannot translate unix loader path '%s' to UEFI",
691 if (kernel != NULL) {
692 ret = efivar_unix_path_to_device_path(kernel, &kerneldp);
695 "Cannot translate unix kernel path '%s' to UEFI",
700 llen = efidp_size(loaderdp);
701 if (llen > MAX_DP_LEN)
702 errx(1, "Loader path too long.");
703 klen = efidp_size(kerneldp);
704 if (klen > MAX_DP_LEN)
705 errx(1, "Kernel path too long.");
706 dp = malloc(llen + klen);
708 errx(1, "Can't allocate memory for new device paths");
709 memcpy(dp, loaderdp, llen);
710 if (kerneldp != NULL)
711 memcpy((char *)dp + llen, kerneldp, klen);
713 /* don't make the new bootvar active by default, use the -a option later */
714 load_attrs = LOAD_OPTION_CATEGORY_BOOT;
716 load_attrs |= LOAD_OPTION_ACTIVE;
717 load_opt_buf = malloc(MAX_LOADOPT_LEN);
718 if (load_opt_buf == NULL)
721 lopt_size = create_loadopt(load_opt_buf, MAX_LOADOPT_LEN, load_attrs,
722 dp, llen + klen, label, env, env ? strlen(env) + 1 : 0);
723 if (lopt_size == BAD_LENGTH)
724 errx(1, "Can't create loadopt");
728 ret = efi_set_variable(EFI_GLOBAL_GUID, bootvar,
729 (uint8_t*)load_opt_buf, lopt_size, COMMON_ATTRS);
733 err(1, "efi_set_variable");
736 add_to_boot_order(bootvar); /* first, still not active */
737 new_ent = malloc(sizeof(struct entry));
740 memset(new_ent, 0, sizeof(struct entry));
741 new_ent->name = bootvar;
742 new_ent->guid = EFI_GLOBAL_GUID;
743 LIST_INSERT_HEAD(&efivars, new_ent, entries);
752 print_loadopt_str(uint8_t *data, size_t datalen)
754 char *dev, *relpath, *abspath;
758 uint8_t *ep = data + datalen;
759 uint8_t *walker = data;
766 if (datalen < sizeof(attr) + sizeof(fplen) + sizeof(efi_char))
768 // First 4 bytes are attribute flags
769 attr = le32dec(walker);
770 walker += sizeof(attr);
771 // Next two bytes are length of the file paths
772 fplen = le16dec(walker);
773 walker += sizeof(fplen);
774 // Next we have a 0 terminated UCS2 string that we know to be aligned
775 descr = (efi_char *)(intptr_t)(void *)walker;
776 len = ucs2len(descr); // XXX need to sanity check that len < (datalen - (ep - walker) / 2)
777 walker += (len + 1) * sizeof(efi_char);
780 // Now we have fplen bytes worth of file path stuff
787 * Everything left is the binary option args
789 * optlen = ep - walker;
793 efidp_format_device_path(buf, sizeof(buf), dp,
794 (intptr_t)(void *)edp - (intptr_t)(void *)dp);
795 printf("%*s%s\n", indent, "", buf);
796 indent = 10 + len + 1;
797 rv = efivar_device_path_to_unix_path(dp, &dev, &relpath, &abspath);
799 printf("%*s%s:%s %s\n", indent + 4, "", dev, relpath, abspath);
804 dp = (efidp)((char *)dp + efidp_size(dp));
809 get_descr(uint8_t *data)
817 pos += sizeof(uint32_t) + sizeof(uint16_t);
818 desc = (efi_char*)(intptr_t)(void *)pos;
820 buf = malloc(len + 1);
821 memset(buf, 0, len + 1);
831 print_boot_var(const char *name, bool verbose, bool curboot)
839 ret = efi_get_variable(EFI_GLOBAL_GUID, name, &data, &size, NULL);
842 load_attrs = le32dec(data);
844 printf("%c%s%c %s", curboot ? '+' : ' ', name,
845 ((load_attrs & LOAD_OPTION_ACTIVE) ? '*': ' '), d);
848 print_loadopt_str(data, size);
856 os_indication_supported(uint64_t indication)
863 ret = efi_get_variable(EFI_GLOBAL_GUID, "OsIndicationsSupported", &data,
867 return (le64dec(data) & indication) == indication;
878 ret = efi_get_variable(EFI_GLOBAL_GUID, "OsIndications", &data, &size,
882 return le64dec(data);
886 os_indications_set(uint64_t mask, uint64_t val)
888 uint8_t new[sizeof(uint64_t)];
890 le64enc(&new, (os_indications() & ~mask) | (val & mask));
891 return set_bootvar("OsIndications", new, sizeof(new));
894 /* Cmd epilogue, or just the default with no args.
895 * The order is [bootnext] bootcurrent, timeout, order, and the bootvars [-v]
898 print_boot_vars(bool verbose)
901 * just read and print the current values
902 * as a command epilogue
909 uint16_t *boot_order = NULL, current;
912 if (os_indication_supported(EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) {
914 (os_indications() & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) != 0;
915 printf("Boot to FW : %s\n", boot_to_fw_ui != 0 ?
919 ret = efi_get_variable(EFI_GLOBAL_GUID, "BootNext", &data, &size, &attrs);
921 printf("BootNext : %04x\n", le16dec(data));
924 ret = efi_get_variable(EFI_GLOBAL_GUID, "BootCurrent", &data, &size,&attrs);
925 current = le16dec(data);
926 printf("BootCurrent: %04x\n", current);
928 ret = efi_get_variable(EFI_GLOBAL_GUID, "Timeout", &data, &size, &attrs);
930 printf("Timeout : %d seconds\n", le16dec(data));
933 if (efi_get_variable(EFI_GLOBAL_GUID, "BootOrder", &data, &size, &attrs) > 0) {
935 warn("Bad BootOrder variable: odd length %d", (int)size);
936 boot_order = malloc(size);
938 printf("BootOrder : ");
939 for (size_t i = 0; i < size; i += 2) {
940 boot_order[i / 2] = le16dec(data + i);
941 printf("%04X%s", boot_order[i / 2], i == size - 2 ? "\n" : ", ");
945 if (boot_order == NULL) {
947 * now we want to fetch 'em all fresh again
948 * which possibly includes a newly created bootvar
950 LIST_FOREACH(v, &efivars, entries) {
951 print_boot_var(v->name, verbose, v->idx == current);
954 LIST_FOREACH(v, &efivars, entries) {
957 for (int i = 0; i < bolen; i++) {
960 snprintf(buffer, sizeof(buffer), "Boot%04X", boot_order[i]);
961 if (!print_boot_var(buffer, verbose, boot_order[i] == current))
962 printf("%s: MISSING!\n", buffer);
963 LIST_FOREACH(v, &efivars, entries) {
964 if (v->idx == boot_order[i]) {
971 printf("\n\nUnreferenced Variables:\n");
972 LIST_FOREACH(v, &efivars, entries) {
974 print_boot_var(v->name, verbose, v->idx == current);
985 efi_del_variable(EFI_GLOBAL_GUID,"Timeout");
989 handle_timeout(int to)
993 le16enc(&timeout, to);
994 if (set_bootvar("Timeout", (uint8_t *)&timeout, sizeof(timeout)) < 0)
995 errx(1, "Can't set Timeout for booting.");
999 report_esp_device(bool do_dp, bool do_unix)
1005 uint16_t current, fplen;
1006 char *name, *dev, *relpath, *abspath;
1007 uint8_t *walker, *ep;
1012 if (do_dp && do_unix)
1013 errx(1, "Can't report both UEFI device-path and Unix path together");
1015 ret = efi_get_variable(EFI_GLOBAL_GUID, "BootCurrent", &data, &size,&attrs);
1017 err(1, "Can't get BootCurrent");
1018 current = le16dec(data);
1019 if (asprintf(&name, "Boot%04X", current) < 0)
1020 err(1, "Can't format boot var\n");
1021 if (efi_get_variable(EFI_GLOBAL_GUID, name, &data, &size, NULL) < 0)
1022 err(1, "Can't retrieve EFI var %s", name);
1023 // First 4 bytes are attribute flags
1026 walker += sizeof(uint32_t);
1027 // Next two bytes are length of the file paths
1028 fplen = le16dec(walker);
1029 walker += sizeof(fplen);
1030 // Next we have a 0 terminated UCS2 string that we know to be aligned
1031 descr = (efi_char *)(intptr_t)(void *)walker;
1032 len = ucs2len(descr); // XXX need to sanity check that len < (datalen - (ep - walker) / 2)
1033 walker += (len + 1) * sizeof(efi_char);
1035 errx(1, "malformed boot variable %s", name);
1036 // Now we have fplen bytes worth of file path stuff
1040 errx(1, "malformed boot variable %s", name);
1042 efidp_format_device_path_node(buf, sizeof(buf), dp);
1043 printf("%s\n", buf);
1046 if (efivar_device_path_to_unix_path(dp, &dev, &relpath, &abspath) != 0)
1047 errx(1, "Can't convert to unix path");
1049 if (abspath == NULL)
1050 errx(1, "Can't find where %s:%s is mounted",
1052 abspath[strlen(abspath) - strlen(relpath) - 1] = '\0';
1053 printf("%s\n", abspath);
1055 printf("%s\n", dev);
1064 set_boot_to_fw_ui(bool to_fw)
1068 if (!os_indication_supported(EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) {
1070 errx(1, "boot to fw ui not supported");
1074 ret = os_indications_set(EFI_OS_INDICATIONS_BOOT_TO_FW_UI,
1077 errx(1, "failed to set boot to fw ui");
1081 find_efi_device(const char *path)
1088 ret = efivar_unix_path_to_device_path(path, &dp);
1091 "Cannot translate path '%s' to UEFI", path);
1092 len = efidp_size(dp);
1093 if (len > MAX_DP_LEN)
1094 errx(1, "Resulting device path too long.");
1095 efidp_format_device_path(buf, sizeof(buf), dp, len);
1096 printf("%s -> %s\n", path, buf);
1101 main(int argc, char *argv[])
1104 memset(&opts, 0, sizeof (bmgr_opts_t));
1105 parse_args(argc, argv);
1108 * find_dev can operate without any efi variables
1110 if (!efi_variables_supported() && !opts.find_dev) {
1111 if (errno == EACCES && geteuid() != 0)
1112 errx(1, "must be run as root");
1113 errx(1, "efi variables not supported on this system. kldload efirt?");
1120 * side effect, adds to boot order, but not yet active.
1122 make_boot_var(opts.label ? opts.label : "",
1123 opts.loader, opts.kernel, opts.env, opts.dry_run,
1124 opts.has_bootnum ? opts.bootnum : -1, opts.set_active);
1125 else if (opts.set_active || opts.set_inactive )
1126 handle_activity(opts.bootnum, opts.set_active);
1127 else if (opts.order != NULL)
1128 set_boot_order(opts.order); /* create a new bootorder with opts.order */
1129 else if (opts.set_bootnext)
1130 handle_bootnext(opts.bootnum);
1131 else if (opts.delete_bootnext)
1133 else if (opts.delete)
1134 delete_bootvar(opts.bootnum);
1135 else if (opts.del_timeout)
1137 else if (opts.set_timeout)
1138 handle_timeout(opts.timeout);
1139 else if (opts.esp_device)
1140 report_esp_device(opts.device_path, opts.unix_path);
1141 else if (opts.fw_ui)
1142 set_boot_to_fw_ui(true);
1143 else if (opts.no_fw_ui)
1144 set_boot_to_fw_ui(false);
1145 else if (opts.find_dev)
1146 find_efi_device(opts.dev);
1148 print_boot_vars(opts.verbose);