summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2018-07-27 18:18:20 +0000
committerWarner Losh <imp@FreeBSD.org>2018-07-27 18:18:20 +0000
commitde26ba4d82a253e89c8829b89bf8fc5a2d27f21d (patch)
tree7558c381291e5f57513cc58ce1ba24a1d8f2100d /usr.sbin
parentb51092c7ec2db8b52c50bafce4fd51e15e090560 (diff)
downloadsrc-test2-de26ba4d82a253e89c8829b89bf8fc5a2d27f21d.tar.gz
src-test2-de26ba4d82a253e89c8829b89bf8fc5a2d27f21d.zip
Notes
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/efibootmgr/efibootmgr.85
-rw-r--r--usr.sbin/efibootmgr/efibootmgr.c39
2 files changed, 34 insertions, 10 deletions
diff --git a/usr.sbin/efibootmgr/efibootmgr.8 b/usr.sbin/efibootmgr/efibootmgr.8
index 7d0b3fde1f0c..a169f29fc93a 100644
--- a/usr.sbin/efibootmgr/efibootmgr.8
+++ b/usr.sbin/efibootmgr/efibootmgr.8
@@ -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
diff --git a/usr.sbin/efibootmgr/efibootmgr.c b/usr.sbin/efibootmgr/efibootmgr.c
index bc36df00dcc9..eaf7a1c1903f 100644
--- a/usr.sbin/efibootmgr/efibootmgr.c
+++ b/usr.sbin/efibootmgr/efibootmgr.c
@@ -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 size)
#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,11 +271,6 @@ 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,6 +557,22 @@ 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,
@@ -605,7 +621,8 @@ create_loadopt(uint8_t *buf, size_t bufmax, uint32_t attributes, efidp dp, size_
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, const char *kernel, const 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)