Index: usr.sbin/bsdinstall/scripts/bootconfig =================================================================== --- usr.sbin/bsdinstall/scripts/bootconfig +++ usr.sbin/bsdinstall/scripts/bootconfig @@ -138,17 +138,11 @@ bootlabel="FreeBSD" fi - efibootmgr --create --label "$bootlabel" --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null + efibootmgr --create --activate --label "$bootlabel" \ + --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null umount "${mntpt}" rmdir "${mntpt}" - - # When creating new entries, efibootmgr doesn't mark them active, so we need to - # do so. It doesn't make it easy to find which entry it just added, so rely on - # the fact that it places the new entry first in BootOrder. - bootorder=$(efivar --name 8be4df61-93ca-11d2-aa0d-00e098032b8c-BootOrder --print --no-name --hex | head -1) - bootentry=$(echo "$bootorder" | cut -w -f 3)$(echo "$bootorder" | cut -w -f 2) - efibootmgr --activate "$bootentry" > /dev/null done fi Index: usr.sbin/efibootmgr/efibootmgr.c =================================================================== --- usr.sbin/efibootmgr/efibootmgr.c +++ usr.sbin/efibootmgr/efibootmgr.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2017 Netflix, Inc. + * Copyright (c) 2017-2018 Netflix, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -94,7 +94,7 @@ } bmgr_opts_t; static struct option lopts[] = { - {"activate", required_argument, NULL, 'a'}, + {"activate", no_argument, NULL, 'a'}, {"bootnext", required_argument, NULL, 'n'}, /* set bootnext */ {"bootnum", required_argument, NULL, 'b'}, {"bootorder", required_argument, NULL, 'o'}, /* set order */ @@ -171,37 +171,35 @@ #define USAGE \ - " [-aAnNB Bootvar] [-t timeout] [-T] [-o bootorder] [-O] [--verbose] [--help] \n\ - [-c -l loader [-k kernel ] [-L label] [--dry-run] [-b Bootvar]]" + " [-aAnB -b bootnum] [-N] [-t timeout] [-T] [-o bootorder] [-O] [--verbose] [--help]\n\ + [-c -l loader [-k kernel] [-L label] [--dry-run] [-b bootnum]]" #define CREATE_USAGE \ - " efibootmgr -c -l loader [-k kernel] [-L label] [--dry-run]" + " efibootmgr -c -l loader [-k kernel] [-L label] [--dry-run] [-b bootnum]" #define ORDER_USAGE \ " efibootmgr -o bootvarnum1,bootvarnum2,..." #define TIMEOUT_USAGE \ " efibootmgr -t seconds" #define DELETE_USAGE \ - " efibootmgr -B bootvarnum" + " efibootmgr -B -b bootnum" #define ACTIVE_USAGE \ - " efibootmgr [-a | -A] bootvarnum" + " efibootmgr [-a | -A] -b bootnum" #define BOOTNEXT_USAGE \ - " efibootmgr [-n | -N] bootvarnum" + " efibootmgr [-n | -N] -b bootnum" static void parse_args(int argc, char *argv[]) { int ch; - while ((ch = getopt_long(argc, argv, "A:a:B:b:C:cDe:hk:L:l:Nn:Oo:Tt:v", + while ((ch = getopt_long(argc, argv, "AaBb:C:cDe:hk:L:l:NnOo:Tt:v", lopts, NULL)) != -1) { switch (ch) { case 'A': opts.set_inactive = true; - opts.bootnum = strtoul(optarg, NULL, 16); break; case 'a': opts.set_active = true; - opts.bootnum = strtoul(optarg, NULL, 16); break; case 'b': opts.has_bootnum = true; @@ -209,7 +207,6 @@ break; case 'B': opts.delete = true; - opts.bootnum = strtoul(optarg, NULL, 16); break; case 'C': opts.copy = true; @@ -246,7 +243,6 @@ break; case 'n': opts.set_bootnext = true; - opts.bootnum = strtoul(optarg, NULL, 16); break; case 'O': opts.once = true; @@ -338,14 +334,14 @@ while ((next = strsep(&cp, ",")) != NULL) { new_data[i] = strtoul(next, NULL, 16); if (new_data[i] == 0 && errno == EINVAL) { - warnx("can't parse %s as a numb", next); + warnx("can't parse %s as a number", next); errx(1, "%s", ORDER_USAGE); } i++; } free(cp); if (set_bootvar("BootOrder", (uint8_t*)new_data, size) < 0) - err(1, "Unabke to set BootOrder to %s", order); + err(1, "Unable to set BootOrder to %s", order); free(new_data); } @@ -357,6 +353,9 @@ size_t size; char *name; + if (bootnum < 0 || bootnum > 0xffff) + errx(1, "Need to specify a valid bootnum between 0 and FFFF with -b parameter"); + asprintf(&name, "%s%04X", "Boot", bootnum); if (name == NULL) err(1, "asprintf"); @@ -490,10 +489,13 @@ } static void -handle_bootnext(uint16_t bootnum) +handle_bootnext(int bootnum) { uint16_t num; + if (bootnum < 0 || bootnum > 0xFFFF) + errx(1, "Need to specify a valid bootnum between 0 and FFFF with -b parameter."); + le16enc(&num, bootnum); if (set_bootvar("BootNext", (uint8_t*)&bootnum, sizeof(uint16_t)) < 0) err(1, "set_bootvar"); @@ -675,7 +677,7 @@ lopt_size = create_loadopt(load_opt_buf, MAX_LOADOPT_LEN, load_attrs, dp, llen + klen, label, env, env ? strlen(env) + 1 : 0); if (lopt_size == BAD_LENGTH) - errx(1, "Can't crate loadopt"); + errx(1, "Can't create loadopt"); ret = 0; if (!dry_run) { @@ -904,21 +906,22 @@ int main(int argc, char *argv[]) { - if (!efi_variables_supported()) - errx(1, "efi variables not supported on this system. root? kldload efirt?"); + err(1, "Unable to use EFI variables"); memset(&opts, 0, sizeof (bmgr_opts_t)); + opts.bootnum = -1; parse_args(argc, argv); read_vars(); - if (opts.create) + if (opts.create) { /* * side effect, adds to boot order, but not yet active. */ make_boot_var(opts.label ? opts.label : "", opts.loader, opts.kernel, opts.env, opts.dry_run, opts.has_bootnum ? opts.bootnum : -1, opts.set_active); + } else if (opts.set_active || opts.set_inactive ) handle_activity(opts.bootnum, opts.set_active); else if (opts.order != NULL)