From patchwork Thu May 24 08:04:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 136714 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp1881823lji; Thu, 24 May 2018 01:05:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr31SAgchUM0SwH9poAUbugqVoaCgoONU7wJdQ6z1Vi1GshBQ9niO9nL6dRen9TUwtqmJli X-Received: by 2002:a50:a94d:: with SMTP id m13-v6mr11044238edc.180.1527149138864; Thu, 24 May 2018 01:05:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527149138; cv=none; d=google.com; s=arc-20160816; b=sybYjUE77SD/S4N4/ABHb2/wPJkdlIizsopfwmWosa5q+hVPwdg4o86qudofttlpPR mQ1ncOfT3bfBU+xIzqMJ1seg1wIcHqL6NgsitELQizHJop4obqRNLuUnUVH/zk6rJ08Y JCcwN+5ZjFrsNSOffxwozDghw+4WHJHbiUit9Ci5yVKr7fDJ6pJRg3pwCPGy0dxnduzi T/KZ0ZyiqMMQRuQKlL3ZURfxbHcqtK0PEy68LQ50QN0vCdgpYr1mEGIu/pOP/evA1MJ6 YAPzA26Qawhi4zMiiNa9iNrcTWWkxp+Gk7oZx0iWYhiETQIlGVa5ENCZzTV1IaJm1mOl Wxog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=Tv0s3DKNKwZBvBviKay5QhFBWRngI3z/ZyyxsFw+elI=; b=V6982LmX1DZVQ/Z3xE0zWIzw0u2pMBqPsIrsWNXI9JsltAtZEWlMV+DLB6mLrYvQq+ Wl+EJzwDBFTybqsfMBL4rKlCq3VTZNa9cbm42Sw5mg3p6t9/EMu4SmXncIzEWGlIWAfg TBUkQNzrqUa/cMH+F+Wd/Mt1LCxH8cqo2AX1elQNxFbxVsAzR0tZYiNDET767gD6GgB8 CUXqOszHXZCABaOLzVfOnxOGIqJWSRo/cR8wGkmWoho5B/kDGRXuuwoqSuP22BNs6AOz 6ZYItEnA3kf1cQzZB8ar6q8JcdxdFCEH8PvLKoOWyuIuz2WPWz00HKf32V9Ya6vVbQlI l9Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=1BAtDbPo; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id b99-v6si4590781edf.140.2018.05.24.01.05.38; Thu, 24 May 2018 01:05:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=1BAtDbPo; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 6F18AC21DFA; Thu, 24 May 2018 08:05:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 2C7C3C21C2F; Thu, 24 May 2018 08:05:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4E6EBC21C2F; Thu, 24 May 2018 08:05:32 +0000 (UTC) Received: from conuserg-10.nifty.com (conuserg-10.nifty.com [210.131.2.77]) by lists.denx.de (Postfix) with ESMTPS id 45CF0C21C29 for ; Thu, 24 May 2018 08:05:31 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-10.nifty.com with ESMTP id w4O851Vv016588; Thu, 24 May 2018 17:05:02 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-10.nifty.com w4O851Vv016588 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1527149102; bh=ppPPLKK821sjp7XrJfDGwUWxIEevduFTijLcJN2GOs8=; h=From:To:Cc:Subject:Date:From; b=1BAtDbPojuLv/OeBQyKeHN4EYpGjaOvb7mimq1Dan+VQxxYJQciLFhZpBocg/Zh5V 7n/JBC50fWNnfy6PWTIsNxLgEa9zlIhiVOI3PcttnuWrhBWa0YWhZVYwUCGf7DcSib 8RP+RW46o8b60Z+TImwbjxBwqqWL877VpD85gq6/759N5CwsndsPgX+dYtV8F5ETHT rf2lL6Eal0DmxmrrU104LHIEvZC0XzF4ql72ibgqbvXNaQTTRCs440NzU36R4/Ab55 ANFzXtUwaKoKlm4kUrSfuJBMvBjbbPtbGUKDwACvOowpAtlbxYKJ4oBYBmU2Rx8zre SBGpKc6dEOAOQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Thu, 24 May 2018 17:04:57 +0900 Message-Id: <1527149097-28783-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Cc: Tom Rini , Alexander Graf , Masami Hiramatsu Subject: [U-Boot] [PATCH v2] menu: fix timeout duration X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" For distro-boot, the TIMEOUT directive in the boot script specifies how long to pause in units of 1/10 sec. [1] Commit 8594753ba0a7 ("menu: only timeout when menu is displayed") corrected this by simply dividing the timeout value by 10 in menu_interactive_choice(). I see two problems: - For example, "TIMEOUT 5" should wait for 0.5 sec, but the current implementation cannot handle the granularity of 1/10 sec. In fact, it never breaks because "m->timeout / 10" is zero, which means no timeout. - The menu API is used not only by cmd/pxe.c but also by common/autoboot.c . For the latter case, the unit of the timeout value is _second_ because its default is associated with CONFIG_BOOTDELAY. To fix the first issue, use DIV_ROUND_UP() so that the timeout value is rounded up to the closest integer. For the second issue, move the division to the boundary between cmd/pxe.c and common/menu.c . This is a more desirable place because the comment of struct pxe_menu says: * timeout - time in tenths of a second to wait for a user key-press before * booting the default label. Then, the comment of menu_create() says: * timeout - A delay in seconds to wait for user input. If 0, timeout is * disabled, and the default choice will be returned unless prompt is 1. [1] https://www.syslinux.org/wiki/index.php?title=SYSLINUX#TIMEOUT_timeout Signed-off-by: Masahiro Yamada --- Changes in v2: - In v1, I was misunderstanding. I thought the unit of TIMEOUT was second, but it is actually 1/10 second. Use round up to fix the "never timeout" problem. Also, move the division to the correct place to fix CONFIG_MENU_SHOW. cmd/pxe.c | 4 ++-- common/menu.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/cmd/pxe.c b/cmd/pxe.c index 7649d92..5609545 100644 --- a/cmd/pxe.c +++ b/cmd/pxe.c @@ -1453,8 +1453,8 @@ static struct menu *pxe_menu_to_menu(struct pxe_menu *cfg) /* * Create a menu and add items for all the labels. */ - m = menu_create(cfg->title, cfg->timeout, cfg->prompt, label_print, - NULL, NULL); + m = menu_create(cfg->title, DIV_ROUND_UP(cfg->timeout, 10), + cfg->prompt, label_print, NULL, NULL); if (!m) return NULL; diff --git a/common/menu.c b/common/menu.c index bf2b471..0f0a29a 100644 --- a/common/menu.c +++ b/common/menu.c @@ -194,8 +194,7 @@ static inline int menu_interactive_choice(struct menu *m, void **choice) if (!m->item_choice) { readret = cli_readline_into_buffer("Enter choice: ", - cbuf, - m->timeout / 10); + cbuf, m->timeout); if (readret >= 0) { choice_item = menu_item_by_key(m, cbuf);