From owner-svn-src-head@freebsd.org Fri Jul 27 18:18:21 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9C72A1052AF9; Fri, 27 Jul 2018 18:18:21 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 40D2080AF5; Fri, 27 Jul 2018 18:18:21 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1C4671B5BE; Fri, 27 Jul 2018 18:18:21 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6RIIKik008687; Fri, 27 Jul 2018 18:18:20 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6RIIKaA008684; Fri, 27 Jul 2018 18:18:20 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201807271818.w6RIIKaA008684@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Fri, 27 Jul 2018 18:18:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336768 - head/usr.sbin/efibootmgr X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: head/usr.sbin/efibootmgr X-SVN-Commit-Revision: 336768 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Jul 2018 18:18:21 -0000 Author: imp Date: Fri Jul 27 18:18:20 2018 New Revision: 336768 URL: https://svnweb.freebsd.org/changeset/base/336768 Log: Add -b bootnum to allow creation of a specific boot number (rather than the auotmatic selection). This is important in some scripting environments. Also, remove bogus checks for bootnum != 0. 0 is a valid bootnum. Sponsored by: Netflix Modified: head/usr.sbin/efibootmgr/efibootmgr.8 head/usr.sbin/efibootmgr/efibootmgr.c Modified: head/usr.sbin/efibootmgr/efibootmgr.8 ============================================================================== --- head/usr.sbin/efibootmgr/efibootmgr.8 Fri Jul 27 17:39:36 2018 (r336767) +++ head/usr.sbin/efibootmgr/efibootmgr.8 Fri Jul 27 18:18:20 2018 (r336768) @@ -36,7 +36,7 @@ .Op Fl T .Op Fl o Ar bootorder .Op Fl verbose -.Op Fl c -k Ar kernel -l Ar loader [-L Ar label] [--dry-run] +.Op Fl c -k Ar kernel -l Ar loader [-L Ar label] [--dry-run] [-b Bootvar] .Sh "DESCRIPTION" .Nm manipulates how UEFI Boot Managers boot the system. @@ -70,6 +70,9 @@ Create a new Boot Variable The path to and name of the loader. .It Fl k -kernel Ar kernel The path to and name of the kernel. +.It Fl b Bootvar +When creating an entry, use Bootvar as the index. +Fail if it already exists. .It Fl L -label Ar label An optional description for the entry. .It Fl D -dry-run Modified: head/usr.sbin/efibootmgr/efibootmgr.c ============================================================================== --- head/usr.sbin/efibootmgr/efibootmgr.c Fri Jul 27 17:39:36 2018 (r336767) +++ head/usr.sbin/efibootmgr/efibootmgr.c Fri Jul 27 18:18:20 2018 (r336768) @@ -82,6 +82,7 @@ typedef struct _bmgr_opts { bool delete_bootnext; bool del_timeout; bool dry_run; + bool has_bootnum; bool once; int cp_src; bool set_active; @@ -170,7 +171,7 @@ set_bootvar(const char *name, uint8_t *data, size_t si #define USAGE \ " [-aAnNB Bootvar] [-t timeout] [-T] [-o bootorder] [-O] [--verbose] [--help] \n\ - [-c -l loader [-k kernel ] [-L label] [--dry-run]]" + [-c -l loader [-k kernel ] [-L label] [--dry-run] [-b Bootvar]]" #define CREATE_USAGE \ " efibootmgr -c -l loader [-k kernel] [-L label] [--dry-run]" @@ -201,6 +202,10 @@ parse_args(int argc, char *argv[]) opts.set_active = true; opts.bootnum = strtoul(optarg, NULL, 16); break; + case 'b': + opts.has_bootnum = true; + opts.bootnum = strtoul(optarg, NULL, 16); + break; case 'B': opts.delete = true; opts.bootnum = strtoul(optarg, NULL, 16); @@ -266,12 +271,7 @@ parse_args(int argc, char *argv[]) errx(1, "%s",CREATE_USAGE); return; } - if (opts.set_bootnext && !(opts.bootnum)) - errx(1, "%s", BOOTNEXT_USAGE); - if ((opts.set_active || opts.set_inactive) && !(opts.bootnum)) - errx(1, "%s", ACTIVE_USAGE); - if (opts.order && !(opts.order)) errx(1, "%s", ORDER_USAGE); } @@ -557,7 +557,23 @@ make_next_boot_var_name(void) return name; } +static char * +make_boot_var_name(uint16_t bootnum) +{ + struct entry *v; + char *name; + LIST_FOREACH(v, &efivars, entries) { + if (v->idx == bootnum) + return NULL; + } + + asprintf(&name, "%s%04X", "Boot", bootnum); + if (name == NULL) + err(1, "asprintf"); + return name; +} + static size_t create_loadopt(uint8_t *buf, size_t bufmax, uint32_t attributes, efidp dp, size_t dp_size, const char *description, const uint8_t *optional_data, size_t optional_data_size) @@ -605,7 +621,8 @@ create_loadopt(uint8_t *buf, size_t bufmax, uint32_t a static int -make_boot_var(const char *label, const char *loader, const char *kernel, const char *env, bool dry_run) +make_boot_var(const char *label, const char *loader, const char *kernel, const char *env, bool dry_run, + int bootnum) { struct entry *new_ent; uint32_t load_attrs = 0; @@ -617,7 +634,10 @@ make_boot_var(const char *label, const char *loader, c assert(label != NULL); - bootvar = make_next_boot_var_name(); + if (bootnum == -1) + bootvar = make_next_boot_var_name(); + else + bootvar = make_boot_var_name((uint16_t)bootnum); if (bootvar == NULL) err(1, "bootvar creation"); if (loader == NULL) @@ -894,7 +914,8 @@ main(int argc, char *argv[]) * 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.loader, opts.kernel, opts.env, opts.dry_run, + opts.has_bootnum ? opts.bootnum : -1); else if (opts.set_active || opts.set_inactive ) handle_activity(opts.bootnum, opts.set_active); else if (opts.order != NULL)