:: Re: [maemo-leste] [PATCH] bootmenu:…
Forside
Slet denne besked
Besvar denne besked
Skribent: Pali Rohár
Dato:  
Til: Heinrich Schuchardt
CC: Simon Glass, Thirupathaiah Annapureddy, u-boot, maemo-leste
Emne: Re: [maemo-leste] [PATCH] bootmenu: Allow to quit it via CTRL+C
On Saturday 26 December 2020 23:15:29 Heinrich Schuchardt wrote:
> On 12/26/20 8:50 PM, Pali Rohár wrote:
> > On Saturday 26 December 2020 20:44:45 Heinrich Schuchardt wrote:
> > > Am 26. Dezember 2020 20:15:40 MEZ schrieb "Pali Rohár" <pali@???>:
> > > > On Saturday 26 December 2020 20:10:10 Heinrich Schuchardt wrote:
> > > > > Am 26. Dezember 2020 20:03:56 MEZ schrieb "Pali Rohár"
> > > > <pali@???>:
> > > > > > On Saturday 26 December 2020 19:44:23 Heinrich Schuchardt wrote:
> > > > > > > Am 26. Dezember 2020 19:02:25 MEZ schrieb "Pali Rohár"
> > > > > > <pali@???>:
> > > > > > > > When CTRL+C is pressed interrupt bootmenu and jump into U-Boot
> > > > > > console.
> > > > > > > > As the last entry in bootmenu is always U-Boot console just
> > > > choose
> > > > > > the
> > > > > > > > last
> > > > > > > > entry when CTRL+C is pressed.
> > > > > > > >
> > > > > > > > It is useful when bootmenu is part of boot process and you want
> > > > to
> > > > > > > > interrupt boot process by scripts which control U-Boot (serial)
> > > > > > > > console.
> > > > > > >
> > > > > > > Wouldn't the escape key be a better choice?
> > > > > >
> > > > > > I can add also escape key. But has escape key stable ANSI sequence
> > > > > > which
> > > > > > is needed to catch? If you tell me which bytes to catch (for escape
> > > > > > key)
> > > > > > I will add it.
> > > > >
> > > > > 0x1b is Escape
> > > >
> > > > Does not work. 0x1b is not escape key. It is start of the ANSI escape
> > > > sequence which matches also existing keys up and down.
> > >
> > > On the serial console you have to hit the key twice.
> > >
> > > The device driver will tranlate it to a single 0x1b which is the char you want to react to.
> >
> > Which device driver? bootmenu code is already catching and reacting to
> > the byte 0x1b as part of the key up and key down matching. So single
> > 0x1b for sure cannot be caught in bootmenu code as then key up and key
> > down keys stops working. If it is really 0x1b byte then it needs to be
> > somehow escaped and therefore be part of some longer, not single byte
> > sequence.
> >
>
> diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c
> index 1ba7b622e5..26222ff8b7 100644
> --- a/cmd/bootmenu.c
> +++ b/cmd/bootmenu.c
> @@ -44,6 +44,7 @@ enum bootmenu_key {
>      KEY_NONE = 0,
>      KEY_UP,
>      KEY_DOWN,
> +    KEY_QUIT,
>      KEY_SELECT,
>  };

>
> @@ -153,11 +154,18 @@ static void bootmenu_loop(struct bootmenu_data *menu,
>          break;
>      case 1:
>          /* Second char of ANSI '[' */
> -        if (c == '[') {
> +        switch (c) {
> +        case '\e':
> +            *esc = 0;
> +            *key = KEY_QUIT;
> +            break;


Thanks! Now I see what you mean. Basically 0x1b is escaped by escape
(0x1b) character.

> +        case '[':
>              *esc = 2;
>              *key = KEY_NONE;
> -        } else {
> +            break;
> +        default:
>              *esc = 0;
> +            break;
>          }
>          break;
>      case 2:
> @@ -217,6 +225,12 @@ static char *bootmenu_choice_entry(void *data)
>                  ++menu->active;
>              /* no menu key selected, regenerate menu */
>              return NULL;
> +        case KEY_QUIT:
> +            /* Quit by choosing the last entry - U-Boot console */
> +            iter = menu->first;
> +            while (iter->next)
> +                iter = iter->next;
> +            return iter->key;
>          case KEY_SELECT:
>              iter = menu->first;
>              for (i = 0; i < menu->active; ++i)

>