All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paul Menzel <pmenzel@molgen.mpg.de>
To: grub-devel@gnu.org
Cc: coreboot@coreboot.org
Subject: [PATCH] normal/menu: Do not treat error values as key presses
Date: Tue, 5 Feb 2019 17:29:13 +0100	[thread overview]
Message-ID: <fd5ecb16-3b3d-c875-0226-32624d8f8443@molgen.mpg.de> (raw)
In-Reply-To: <a8ca2d83-72ef-6eac-e1f4-7a2d39c78b48@molgen.mpg.de>

[-- Attachment #1: Type: text/plain, Size: 2391 bytes --]

Date: Sat, 4 Feb 2019 22:39:37 +0100

Some terminals, like `grub-core/term/at_keyboard.c`, return `-1` in case
they are not ready yet.

      if (! KEYBOARD_ISREADY (grub_inb (KEYBOARD_REG_STATUS)))
        return -1;

Currently, that is treated as a key press, and the menu time-out is
cancelled/cleared. This is unwanted, as the boot is stopped and the user
manually has to select a menu entry. Therefore, adapt the condition to
require the key value also to be greater than 0.

`GRUB_TERM_NO_KEY` is defined as 0, so the condition could be collapsed
to greater or equal than (≥) 0, but the compiler will probably do that
for us anyway, so keep the cases separate for clarity.

This is tested with coreboot, the GRUB default payload, and the
configuration file `grub.cfg` below.

For GRUB:

    $ ./autogen.sh
    $ ./configure --with-platform=coreboot
    $ make -j`nproc`
    $ make default_payload.elf

For coreboot:

    $ more grub.cfg
    serial --unit 0 --speed 115200
    set timeout=5

    menuentry 'halt' {
        halt
    }
    $ build/cbfstool build/coreboot.rom add-payload \
        -f /dev/shm/grub/default_payload.elf -n fallback/payload -c lzma
    $ build/cbfstool build/coreboot.rom add -f grub.cfg -n etc/grub.cfg -t raw
    $ qemu-system-x86_64 --version
    QEMU emulator version 3.1.0 (Debian 1:3.1+dfsg-2+b1)
    Copyright (c) 2003-2018 Fabrice Bellard and the QEMU Project developers
    $ qemu-system-x86_64 -M pc -bios build/coreboot.rom -serial stdio -nic none

Currently, the time-out is cancelled/cleared. With the commit, it is not.

With a small GRUB payload, this the problem is also reproducible on the
ASRock E350M1.

Link: http://lists.gnu.org/archive/html/grub-devel/2019-01/msg00037.html
Signed-off-by: Paul Menzel <pmenzel@molgen.mpg.de>
---
 grub-core/normal/menu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c
index e7a83c2d6..68159e771 100644
--- a/grub-core/normal/menu.c
+++ b/grub-core/normal/menu.c
@@ -698,7 +698,8 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
 
       c = grub_getkey_noblock ();
 
-      if (c != GRUB_TERM_NO_KEY)
+      /* Negative values are returned on error */
+      if ((c != GRUB_TERM_NO_KEY) && (c > 0))
 	{
 	  if (timeout >= 0)
 	    {
-- 
2.20.1


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 5174 bytes --]

  reply	other threads:[~2019-02-05 16:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-14 13:08 Menu time-out missing when GRUB is loaded quickly and `at_keyboard` Paul Menzel
2019-02-05 16:29 ` Paul Menzel [this message]
2019-02-06 11:49   ` [PATCH] normal/menu: Do not treat error values as key presses Daniel Kiper

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=fd5ecb16-3b3d-c875-0226-32624d8f8443@molgen.mpg.de \
    --to=pmenzel@molgen.mpg.de \
    --cc=coreboot@coreboot.org \
    --cc=grub-devel@gnu.org \
    /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.