Index: usr.sbin/efibootmgr/efibootmgr.8 =================================================================== --- usr.sbin/efibootmgr/efibootmgr.8 +++ usr.sbin/efibootmgr/efibootmgr.8 @@ -24,20 +24,39 @@ .\" .\" $FreeBSD$ .\" -.Dd December 28, 2018 +.Dd January 1, 2019 .Dt EFIBOOTMGR 8 .Os .Sh NAME -.Nm efibootmgr +.Nm efibootmgr .Nd manipulate the EFI Boot Manager .Sh SYNOPSIS -.Op Fl aAnNB -.Op Fl b Ar bootnum -.Op Fl t Ar timeout -.Op Fl T -.Op Fl o Ar bootorder +.Nm .Op Fl v -.Op Fl c l Ar loader [ Fl k Ar kernel ] [ Fl L Ar label ] [ Fl -dry-run ] +.Nm +.Fl c +.Fl l Ar loader +.Op Fl aD +.Op Fl b Ar bootnum +.Op Fl k Ar kernel +.Op Fl L Ar label +.Nm +.Fl B +.Fl b Ar bootnum +.Nm +.Brq Fl a Ns | Ns Fl A +.Fl b Ar bootnum +.Nm +.Fl n +.Fl b Ar bootnum +.Nm +.Fl N +.Nm +.Fl o Ar bootnum1 Ns , Ns Ar bootnum2 Ns , Ns Ar ... +.Nm +.Fl t Ar seconds +.Nm +.Fl T .Sh "DESCRIPTION" .Nm manipulates how UEFI Boot Managers boot the system. @@ -86,9 +105,9 @@ Deactivate the given bootnum boot entry. .It Fl n -bootnext Set bootnum boot entry as the BootNext variable. -.It Fl N -delete-bootnext +.It Fl N -delete-bootnext Delete the BootNext optional variable. -.It Fl o -bootorder Ar bootorder +.It Fl o -bootorder Ar bootnum1 Ns , Ns Ar bootnum2 Ns , Ns Ar ... Set BootOrder variable to the given comma delimited set of bootnums. The numbers are in hex to match BootXXXX, but may omit leading zeros. .It Fl t -set-timeout Ar timeout Index: usr.sbin/efibootmgr/efibootmgr.c =================================================================== --- usr.sbin/efibootmgr/efibootmgr.c +++ usr.sbin/efibootmgr/efibootmgr.c @@ -169,23 +169,48 @@ COMMON_ATTRS); } +typedef enum { + EBM_USAGE, + EBM_LIST, + EBM_CREATE, + EBM_DELETE, + EBM_ACTIVE, + EBM_BOOTNEXT_SET, + EBM_BOOTNEXT_DELETE, + EBM_ORDER, + EBM_TIMEOUT_SET, + EBM_TIMEOUT_DELETE +} ebm_usage_t; +static const char * const ebm_usage[] = { + [EBM_LIST] = "[-v]", + [EBM_CREATE] = "-c -l loader [-aD] [-b bootnum] [-k kernel] [-L label]", + [EBM_DELETE] = "-B -b bootnum", + [EBM_ACTIVE] = "{-a|-A} -b bootnum", + [EBM_BOOTNEXT_SET] = "-n -b bootnum", + [EBM_BOOTNEXT_DELETE] = "-N", + [EBM_ORDER] = "-o bootnum1,bootnum2,...", + [EBM_TIMEOUT_SET] = "-t seconds", + [EBM_TIMEOUT_DELETE] = "-T" +}; + +static void +usage(ebm_usage_t unum) +{ + + fprintf(stderr, "Usage:\n"); -#define USAGE \ - " [-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] [-b bootnum] [-a]" -#define ORDER_USAGE \ - " efibootmgr -o bootvarnum1,bootvarnum2,..." -#define TIMEOUT_USAGE \ - " efibootmgr -t seconds" -#define DELETE_USAGE \ - " efibootmgr -B -b bootnum" -#define ACTIVE_USAGE \ - " efibootmgr [-a | -A] -b bootnum" -#define BOOTNEXT_USAGE \ - " efibootmgr [-n | -N] -b bootnum" + if (unum >= 1 && unum < nitems(ebm_usage)) + fprintf(stderr, "\t%s %s\n", getprogname(), ebm_usage[unum]); + else { + ebm_usage_t i; + + for (i = 1; i < nitems(ebm_usage); i++) + fprintf(stderr, "\t%s %s\n", getprogname(), + ebm_usage[i]); + } + + exit(1); +} static void parse_args(int argc, char *argv[]) @@ -223,7 +248,7 @@ break; case 'h': default: - errx(1, "%s", USAGE); + usage(EBM_USAGE); break; case 'k': free(opts.kernel); @@ -265,21 +290,21 @@ } if (opts.create) { if (!opts.loader) - errx(1, "%s",CREATE_USAGE); + usage(EBM_CREATE); return; } if (opts.order && !(opts.order)) - errx(1, "%s", ORDER_USAGE); + usage(EBM_ORDER); if ((opts.set_inactive || opts.set_active) && !opts.has_bootnum) - errx(1, "%s", ACTIVE_USAGE); + usage(EBM_ACTIVE); if (opts.delete && !opts.has_bootnum) - errx(1, "%s", DELETE_USAGE); + usage(EBM_DELETE); if (opts.set_bootnext && !opts.has_bootnum) - errx(1, "%s", BOOTNEXT_USAGE); + usage(EBM_BOOTNEXT_SET); } @@ -344,7 +369,7 @@ new_data[i] = strtoul(next, NULL, 16); if (new_data[i] == 0 && errno == EINVAL) { warnx("can't parse %s as a numb", next); - errx(1, "%s", ORDER_USAGE); + usage(EBM_ORDER); } i++; }