From mboxrd@z Thu Jan 1 00:00:00 1970 From: Heinrich Schuchardt Date: Sat, 26 Dec 2020 23:15:29 +0100 Subject: [PATCH] bootmenu: Allow to quit it via CTRL+C In-Reply-To: <20201226195027.kksrqirn26qhkhel@pali> References: <20201226180225.17563-1-pali@kernel.org> <20201226190356.au3njchffwtf3poe@pali> <0B7EC0F9-9371-4741-9863-2CA2AE0E437A@gmx.de> <20201226191540.cuajfctqfrmcp5l7@pali> <344046A6-7044-4B29-9902-49D5FE784F0C@gmx.de> <20201226195027.kksrqirn26qhkhel@pali> Message-ID: <0edc6880-c63e-b171-7075-0e9bce9ee7eb@gmx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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" : >>> On Saturday 26 December 2020 20:10:10 Heinrich Schuchardt wrote: >>>> Am 26. Dezember 2020 20:03:56 MEZ schrieb "Pali Roh?r" >>> : >>>>> On Saturday 26 December 2020 19:44:23 Heinrich Schuchardt wrote: >>>>>> Am 26. Dezember 2020 19:02:25 MEZ schrieb "Pali Roh?r" >>>>> : >>>>>>> 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; + 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)