All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahisa Kojima <masahisa.kojima@linaro.org>
To: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Simon Glass <sjg@chromium.org>,
	 Takahiro Akashi <takahiro.akashi@linaro.org>,
	Francois Ozog <francois.ozog@linaro.org>,
	 Mark Kettenis <mark.kettenis@xs4all.nl>,
	u-boot@lists.denx.de
Subject: Re: [PATCH v6 3/6] efi_loader: menu-driven update of UEFI bootorder variable
Date: Thu, 26 May 2022 16:49:27 +0900	[thread overview]
Message-ID: <CADQ0-X_inPR7yGv+SkYO9KvJEiN=3Zgrv2oy7sJcUWvuqGL9rw@mail.gmail.com> (raw)
In-Reply-To: <cd98fdad-7f99-035c-1789-94e3b74af869@gmx.de>

On Tue, 24 May 2022 at 19:42, Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 5/16/22 13:00, Masahisa Kojima wrote:
> > This commit adds the menu-driven update of UEFI bootorder
> > variable.
> >
> > Signed-off-by: Masahisa Kojima <masahisa.kojima@linaro.org>
> > ---
> > (no update since v5)
> >
> > Changes in v5:
> > - split into the separate patch
> >
> >   lib/efi_loader/efi_bootmenu_maintenance.c | 102 ++++++++++++++++++++++
> >   1 file changed, 102 insertions(+)
> >
> > diff --git a/lib/efi_loader/efi_bootmenu_maintenance.c b/lib/efi_loader/efi_bootmenu_maintenance.c
> > index 96306cd2cc..be67fca95f 100644
> > --- a/lib/efi_loader/efi_bootmenu_maintenance.c
> > +++ b/lib/efi_loader/efi_bootmenu_maintenance.c
> > @@ -746,6 +746,56 @@ static efi_status_t efi_bootmenu_boot_add_enter_name(struct efi_bootmenu_boot_op
> >       return ret;
> >   }
> >
> > +static efi_status_t allow_decimal(struct efi_input_key *key)
> > +{
> > +     if (u'0' <= key->unicode_char && key->unicode_char <= u'9')
> > +             return EFI_SUCCESS;
> > +
> > +     return EFI_INVALID_PARAMETER;
> > +}
> > +
> > +static efi_status_t efi_bootmenu_change_boot_order(int selected, int max, int *new)
> > +{
> > +     efi_status_t ret;
> > +     u16 new_order[EFI_BOOT_ORDER_MAX_SIZE_IN_DECIMAL] = {0};
>
> After selecting an item why can we simply use the up and down key to
> move the selected item?

OK, I will use the up and down key, as Takahiro also
requested this before.

>
> > +
> > +     printf(ANSI_CURSOR_POSITION, 2, 1);
> > +     puts("  *** U-Boot EFI Boot Manager Menu ***");
> > +     printf(ANSI_CURSOR_POSITION, 4, 1);
> > +     printf("  current boot order      : %d", selected);
> > +
> > +     printf(ANSI_CURSOR_POSITION, 6, 1);
> > +     printf("  new boot order(0 - %4d): ", max);
> > +
> > +     printf(ANSI_CURSOR_POSITION, 8, 1);
> > +     puts("  ENTER to complete, ESC/CTRL+C to quit");
> > +
> > +     printf(ANSI_CURSOR_POSITION, 6, 29);
> > +     puts(ANSI_CURSOR_SHOW);
> > +
> > +     for (;;) {
> > +             memset(new_order, 0, sizeof(new_order));
> > +             ret = efi_console_get_u16_string(cin, cout, new_order, 6, allow_decimal, 6, 29);
> > +             if (ret == EFI_SUCCESS) {
> > +                     int i;
> > +                     int val = 0;
> > +
> > +                     for (i = 0;
> > +                          i < u16_strnlen(new_order, EFI_BOOT_ORDER_MAX_SIZE_IN_DECIMAL - 1);
> > +                          i++)
> > +                             val = (val * 10) + (new_order[i] - u'0');
> > +
> > +                     if (val > max)
> > +                             continue;
> > +
> > +                     *new = val;
> > +                     return EFI_SUCCESS;
> > +             } else {
> > +                     return ret;
> > +             }
> > +     }
> > +}
> > +
> >   static efi_status_t efi_bootmenu_select_file_handler(struct efi_bootmenu_boot_option *bo)
> >   {
> >       efi_status_t ret;
> > @@ -996,6 +1046,57 @@ static efi_status_t efi_bootmenu_process_delete_boot_option(void *data, bool *ex
> >       return ret;
> >   }
> >
> > +static efi_status_t efi_bootmenu_process_change_boot_order(void *data, bool *exit)
> > +{
> > +     int selected;
> > +     int new_order;
> > +     efi_status_t ret;
> > +     efi_uintn_t num, size;
> > +     u16 *bootorder = NULL;
> > +     u16 *new_bootorder = NULL;
> > +
> > +     bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size);
> > +     if (!bootorder)
> > +             return EFI_NOT_FOUND;
> > +
> > +     num = size / sizeof(u16);
> > +     ret = efi_bootmenu_show_boot_selection(bootorder, num, &selected);
> > +     if (ret != EFI_SUCCESS)
> > +             goto out;
> > +
> > +     ret = efi_bootmenu_change_boot_order(selected, num - 1, &new_order);
> > +     if (ret != EFI_SUCCESS)
> > +             goto out;
> > +
> > +     new_bootorder = calloc(1, size);
> > +     if (!new_bootorder)
> > +             goto out;
> > +
> > +     memcpy(new_bootorder, bootorder, size);
> > +     if (selected > new_order) {
> > +             new_bootorder[new_order] = bootorder[selected];
> > +             memcpy(&new_bootorder[new_order + 1], &bootorder[new_order],
> > +                    (selected - new_order) * sizeof(u16));
> > +     } else if (selected < new_order) {
> > +             new_bootorder[new_order] = bootorder[selected];
> > +             memcpy(&new_bootorder[selected], &bootorder[selected + 1],
> > +                    (new_order - selected) * sizeof(u16));
>
> After updating an item we should be in the
> efi_bootmenu_show_boot_selection() screen again.

OK.

Thanks,
Masahisa Kojima

>
> Best regards
>
> Heinrich
>
> > +     } else {
> > +             /* nothing to change */
> > +             goto out;
> > +     }
> > +     ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid,
> > +                                EFI_VARIABLE_NON_VOLATILE |
> > +                                EFI_VARIABLE_BOOTSERVICE_ACCESS |
> > +                                EFI_VARIABLE_RUNTIME_ACCESS,
> > +                                size, new_bootorder, false);
> > +out:
> > +     free(new_bootorder);
> > +     free(bootorder);
> > +
> > +     return ret;
> > +}
> > +
> >   static efi_status_t efi_bootmenu_init(void)
> >   {
> >       efi_status_t ret;
> > @@ -1025,6 +1126,7 @@ static efi_status_t efi_bootmenu_init(void)
> >   static const struct efi_bootmenu_item maintenance_menu_items[] = {
> >       {u"Add Boot Option", efi_bootmenu_process_add_boot_option},
> >       {u"Delete Boot Option", efi_bootmenu_process_delete_boot_option},
> > +     {u"Change Boot Order", efi_bootmenu_process_change_boot_order},
> >       {u"Quit", NULL},
> >   };
> >
>

  reply	other threads:[~2022-05-26  7:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-16 11:00 [PATCH v6 0/6] enable menu-driven boot device selection Masahisa Kojima
2022-05-16 11:00 ` [PATCH v6 1/6] efi_loader: menu-driven addition of UEFI boot option Masahisa Kojima
2022-05-25  1:38   ` Takahiro Akashi
2022-05-26  7:37     ` Heinrich Schuchardt
2022-06-06  0:45       ` Masahisa Kojima
2022-06-06  0:39     ` Masahisa Kojima
2022-06-13  9:44       ` Masahisa Kojima
2022-05-16 11:00 ` [PATCH v6 2/6] efi_loader: menu-driven deletion of UEFI boot variable Masahisa Kojima
2022-05-16 11:00 ` [PATCH v6 3/6] efi_loader: menu-driven update of UEFI bootorder variable Masahisa Kojima
2022-05-24 10:42   ` Heinrich Schuchardt
2022-05-26  7:49     ` Masahisa Kojima [this message]
2022-05-16 11:00 ` [PATCH v6 4/6] bootmenu: add removable media entries Masahisa Kojima
2022-05-16 11:00 ` [PATCH v6 5/6] doc:bootmenu: add description for UEFI boot support Masahisa Kojima
2022-05-18  1:31   ` Takahiro Akashi
2022-05-18  5:27     ` Masahisa Kojima
2022-05-16 11:00 ` [PATCH v6 6/6] lib/charset: fix compile warnings Masahisa Kojima
2022-06-04  6:33 ` [PATCH v6 0/6] enable menu-driven boot device selection Heinrich Schuchardt
2022-06-06  0:18   ` Masahisa Kojima

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADQ0-X_inPR7yGv+SkYO9KvJEiN=3Zgrv2oy7sJcUWvuqGL9rw@mail.gmail.com' \
    --to=masahisa.kojima@linaro.org \
    --cc=francois.ozog@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=mark.kettenis@xs4all.nl \
    --cc=sjg@chromium.org \
    --cc=takahiro.akashi@linaro.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.