From patchwork Thu Apr 28 08:09:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 567135 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp5233363map; Thu, 28 Apr 2022 01:12:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFxNEsyW2m7PQtzIUSwVsDisaEMReqympsKKizWAc/Bi5ZA1CF4cxLTDkQwew2h5Iyl3y0 X-Received: by 2002:a17:906:c114:b0:6f3:ad4c:c886 with SMTP id do20-20020a170906c11400b006f3ad4cc886mr13545227ejc.124.1651133578210; Thu, 28 Apr 2022 01:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651133578; cv=none; d=google.com; s=arc-20160816; b=xqGFmuaz0QhU5xA7lvA4kNCMsa8YCEadg1KRHYFDDWh1PEHR5lToLq0o3j8InUeBuJ aAoJTaPl1b2T/Oa9ZrcEwrF0CIirMNepMhMr7o4cq6SmTdin3Tm/w0uIAxQu3Z8eiFUu OafKui9PGW3uGJfi9GgZzWatmV92pddoj7uIXdZO+kx99OAts04Ciq2v3u5IB7UN6QRT H7sSzbcEOGOcvgldsdqSS5VRyqnKcgyRY4QRLq5lwlvzMtRDl069Ma6bWjRd/+RDXrG9 20OisuFlob16bLPyjHl7T7/G0h/HjsD+pnlrtQf1MuBs3NBHu6EUtYDXMORn+mN/hDJT PhFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=x6/5QQUKffmkn89OIbMNZWa+hTgla18bSqTlHz9+c/M=; b=HW63Wq5cHrceqFh6E+xAvPmIKfVjS+gTTf5HNUbKd3yBh0AGDS5M+LeNt8fyK5w7Ib 13pz5vA0/YHUu2IXYT5QwcOPCE4a+xdOeLnbz3KJt7kw60SSzZU5B2bZoQ4wZ+OFMRIL 0ui/FpjjYEq+Q7bqeAUfjJzDeffgEK5GzmfP1ctuJlzo+n/BZLmb9RKy5IHZJEybPtky BlsKYEJqXp64CRZVQPiPTvaXVxd2munuwiP+oKLbVgF0jaKUrw00BfHVg0wbcj4uj1gh ZEpnO9IIZmB2/YwUX14cAe06lihe3QTq/QIsK79NB1s6g3yjUtGS0wFO083Z95Oh7v4p ti1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NWEuT1kd; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id i15-20020a17090639cf00b006f3a813732dsi3423014eje.605.2022.04.28.01.12.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 01:12:58 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NWEuT1kd; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 046C983EF7; Thu, 28 Apr 2022 10:11:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="NWEuT1kd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AC32E834AD; Thu, 28 Apr 2022 10:11:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6978783ECB for ; Thu, 28 Apr 2022 10:11:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pj1-x1035.google.com with SMTP id cu23-20020a17090afa9700b001d98d8e53b7so5572736pjb.0 for ; Thu, 28 Apr 2022 01:11:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x6/5QQUKffmkn89OIbMNZWa+hTgla18bSqTlHz9+c/M=; b=NWEuT1kdZ77pK4Gxe5bmtw/DGl+OG4Z/6HP0W1vi7lhTgGbRKboqjJSXk9v8n3sRs7 o4guHjeVr7NmJUCIsX62UjAaNygGgdhwYVvMVGYVxWIIaHl1fGGQgXV0unX/EpR+aqll qUY2oKBfseoAvUjil2XXjp6bMqMxqhvvGc9xPouHi9lgwVQOigfe0hvB8TgteOk7ypmG 05bKf7eQ8XA2GU5D/lrmxlGwqTSc062nLxv3P4d36+gl8MNoqerqbHTo7C5gk/NJtkff rlOpCxVpBdog7CjMR+ndNlBFwpMdGd9eTBY/VzB5Fw6N50bveyr1qeGpgGnXysI9rhak a32Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x6/5QQUKffmkn89OIbMNZWa+hTgla18bSqTlHz9+c/M=; b=G1glI18yEFDnFjAr4W3LPR8dmjI2DdADX0pOlfHOSHCZ5q9OVQLqj8Bup9OL5sFsBg WoVGAah/qLJ0/HuX1CLPeoc1p30T0ajs1N7vh1lcbD2GfPRk6TeJhooOQJvP0DQ/vJYb OlMjfsOPiMjRj9TLOEcs1/lUulS4yoeBvVD8P/cJ1ezRBgZobKjBQGmQVygy6m9t9j4S 3xSeO3Y5UoHNQnH3UVaAnu8WKV1QlhWL2xxBa3Yd60sF0aSVfcPW2mXockNrIIoi49F3 Cv0F9efoxPhIodlaUGDQmOsaYQ2Mmy6FTucHo4De5ixHUbld0/LUx8+041LRaudoLgKU ENQw== X-Gm-Message-State: AOAM533tQYCA3knokLS7Zoc8/EWtGz2tytYrFA3wfgL5gGOjCUadku1z tYwwiPiGCnbyWzquawHwgAjBWRpOhQltPg== X-Received: by 2002:a17:90a:a090:b0:1cb:a443:f19c with SMTP id r16-20020a17090aa09000b001cba443f19cmr38058694pjp.135.1651133467613; Thu, 28 Apr 2022 01:11:07 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id b15-20020a17090a7acf00b001cd4989ff5fsm5684259pjl.38.2022.04.28.01.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 01:11:07 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Francois Ozog , Mark Kettenis , Masahisa Kojima , Michal Simek , Kory Maincent , Ovidiu Panait , Ashok Reddy Soma Subject: [PATCH v5 11/17] bootmenu: add Kconfig option not to enter U-Boot console Date: Thu, 28 Apr 2022 17:09:44 +0900 Message-Id: <20220428080950.23509-12-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220428080950.23509-1-masahisa.kojima@linaro.org> References: <20220428080950.23509-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean This commit adds the Kconfig option to disable to enter the U-Boot console from bootmenu. If CMD_BOOTMENU_ENTER_UBOOT_CONSOLE is enabled, "U-Boot console" entry is appeared as the last entry in the bootmenu, then user can enter U-Boot console. If CMD_BOOTMENU_ENTER_UBOOT_CONSOLE is disabled, "Quit" entry is appeared as the last entry instead of "U-Boot console". When user chooses "Quit" from bootmenu, the following default commands are invoked. - "bootefi bootmgr" (if efi bootmgr is enabled) - "run bootcmd" If the both commands are executed and returns to the bootmenu, the bootmenu will appears again. Signed-off-by: Masahisa Kojima --- Changes in v5: - split into the separate patch - clear the console when user select "U-Boot console" - if the console is disabled, the last entry title is "Quit" cmd/Kconfig | 10 ++++++++ cmd/bootmenu.c | 69 ++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 68 insertions(+), 11 deletions(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 2b575a2b42..99a1435467 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -356,6 +356,16 @@ config CMD_BOOTMENU help Add an ANSI terminal boot menu command. +config CMD_BOOTMENU_ENTER_UBOOT_CONSOLE + bool "Allow Bootmenu to enter the U-Boot console" + depends on CMD_BOOTMENU + default n + help + Add an entry to enter U-Boot console in bootmenu. + If this option is disabled, user can not enter + the U-Boot console from bootmenu. It increases + the system security. + config CMD_ADTIMG bool "adtimg" help diff --git a/cmd/bootmenu.c b/cmd/bootmenu.c index afe42b8041..bfbb1b5248 100644 --- a/cmd/bootmenu.c +++ b/cmd/bootmenu.c @@ -29,6 +29,13 @@ */ #define MAX_ENV_SIZE (9 + 2 + 1) +enum bootmenu_ret { + BOOTMENU_RET_SUCCESS = 0, + BOOTMENU_RET_FAIL, + BOOTMENU_RET_QUIT, + BOOTMENU_RET_UPDATED, +}; + enum boot_type { BOOTMENU_TYPE_NONE = 0, BOOTMENU_TYPE_BOOTMENU, @@ -681,7 +688,12 @@ static struct bootmenu_data *bootmenu_create(int delay) if (!entry) goto cleanup; - entry->title = u16_strdup(u"U-Boot console"); + /* Add Quit entry if entering U-Boot console is disabled */ + if (IS_ENABLED(CONFIG_CMD_BOOTMENU_ENTER_UBOOT_CONSOLE)) + entry->title = u16_strdup(u"U-Boot console"); + else + entry->title = u16_strdup(u"Quit"); + if (!entry->title) { free(entry); goto cleanup; @@ -777,15 +789,17 @@ static void handle_uefi_bootnext(void) run_command("bootefi bootmgr", 0); } -static void bootmenu_show(int delay) +static enum bootmenu_ret bootmenu_show(int delay) { + int cmd_ret; int init = 0; void *choice = NULL; u16 *title = NULL; char *command = NULL; struct menu *menu; - struct bootmenu_data *bootmenu; struct bootmenu_entry *iter; + int ret = BOOTMENU_RET_SUCCESS; + struct bootmenu_data *bootmenu; efi_status_t efi_ret = EFI_SUCCESS; char *option, *sep; @@ -797,27 +811,27 @@ static void bootmenu_show(int delay) option = bootmenu_getoption(0); if (!option) { puts("bootmenu option 0 was not found\n"); - return; + return BOOTMENU_RET_FAIL; } sep = strchr(option, '='); if (!sep) { puts("bootmenu option 0 is invalid\n"); - return; + return BOOTMENU_RET_FAIL; } - run_command(sep+1, 0); - return; + cmd_ret = run_command(sep + 1, 0); + return (cmd_ret == CMD_RET_SUCCESS ? BOOTMENU_RET_SUCCESS : BOOTMENU_RET_FAIL); } bootmenu = bootmenu_create(delay); if (!bootmenu) - return; + return BOOTMENU_RET_FAIL; menu = menu_create(NULL, bootmenu->delay, 1, menu_display_statusline, bootmenu_print_entry, bootmenu_choice_entry, bootmenu); if (!menu) { bootmenu_destroy(bootmenu); - return; + return BOOTMENU_RET_FAIL; } for (iter = bootmenu->first; iter; iter = iter->next) { @@ -838,6 +852,14 @@ static void bootmenu_show(int delay) iter = choice; title = u16_strdup(iter->title); command = strdup(iter->command); + + /* last entry is U-Boot console or Quit */ + if (iter->num == iter->menu->count - 1) { + ret = BOOTMENU_RET_QUIT; + goto cleanup; + } + } else { + goto cleanup; } /* @@ -875,19 +897,44 @@ cleanup: debug("Starting entry '%ls'\n", title); free(title); if (efi_ret == EFI_SUCCESS) - run_command(command, 0); + cmd_ret = run_command(command, 0); free(command); } #ifdef CONFIG_POSTBOOTMENU run_command(CONFIG_POSTBOOTMENU, 0); #endif + + if (efi_ret != EFI_SUCCESS || cmd_ret != CMD_RET_SUCCESS) + ret = BOOTMENU_RET_FAIL; + + return ret; } #ifdef CONFIG_AUTOBOOT_MENU_SHOW int menu_show(int bootdelay) { - bootmenu_show(bootdelay); + int ret; + + while (1) { + ret = bootmenu_show(bootdelay); + bootdelay = -1; + if (ret == BOOTMENU_RET_UPDATED) + continue; + + if (!IS_ENABLED(CONFIG_CMD_BOOTMENU_ENTER_UBOOT_CONSOLE)) { + if (ret == BOOTMENU_RET_QUIT) { + /* default boot process */ + if (IS_ENABLED(CONFIG_CMD_BOOTEFI_BOOTMGR)) + run_command("bootefi bootmgr", 0); + + run_command("run bootcmd", 0); + } + } else { + break; + } + } + return -1; /* -1 - abort boot and run monitor code */ } #endif