From patchwork Mon Oct 24 04:47:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 617832 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2483008pvb; Sun, 23 Oct 2022 21:47:53 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4XxPIphX+95FBprZeHArsBgw317XamugkZJDUGWujlm3rWVIBoMzdAeL3QlYw6txE9rdIW X-Received: by 2002:a17:907:b0b:b0:78d:8877:9f9e with SMTP id h11-20020a1709070b0b00b0078d88779f9emr25520186ejl.693.1666586873575; Sun, 23 Oct 2022 21:47:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666586873; cv=none; d=google.com; s=arc-20160816; b=zUCVWuy3hfTrXgBfRkAGF97axR2pMGf1kv02Fcm7TxqiZYhAdUMRXDW7SggoyqYjJY 1lgUbA25vik0IN+VsTx2M5tThVk9Afdy6BADGImyFyqtnd8Xh2DQvcSGBKiU3ZAc1oCu MQzE0cGtjn9bBGpVQIQoaKuVbceHoD8Sbirg1SkEkJ41HE5rxqcFANyvvtld+pYvF8NF oEY/Lr7UUmJgsK1VARfadkJu/Lpl6fmiMjjHdUygWOOTZMwTBSw5VdTuxl37lAy171m1 1rhs688h0trMZPt0zE7LgWXxys7n0iRPqPZLTSjPX5r3rhFvXXyQIE/MdfPeSNuTJcLE pr5Q== 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=OMsh9Oc0CCknYUovkbuTqB+UsRMDQpThqpMPaS13aiY=; b=mIfVlRRFu6D0eE+mUG1oh6Bjw/TDS44Ge7rbQ8JMeEkrfDmzBS/Sww1CXT2eyGc/09 6Kt5OputZuu3A7ut2kbLQtaLUZZPLkDYh/EESBFYZJG4S9VaM1m7mEo4nA6COx9TBkSB ARKDeavAPeSrjK22WXXoARBQIpJzyddWG0wHd9RZWU574Asy+fPzg4XINY5CYcBdCWrz mUXT7ImruAVqELhTnGKpB0D7yUH/gGbkkt5GKbRlIvc3qSZUufdb/e9g2X444mtosLNS X5KJD18njYQ68zpy5o9gjTTrkeYRq2tEPK7dFBZ/P8vttnx1Ozygzd7+4JqNPq+mi4JY NGKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=X4NbSbX6; 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 i6-20020a0564020f0600b00454474269dbsi25140315eda.154.2022.10.23.21.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:47:53 -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=X4NbSbX6; 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 8CF8684F1A; Mon, 24 Oct 2022 06:47:42 +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="X4NbSbX6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C4F1484F0B; Mon, 24 Oct 2022 06:47:39 +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-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) (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 F003284EEA for ; Mon, 24 Oct 2022 06:47:36 +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-pl1-x632.google.com with SMTP id n7so7559467plp.1 for ; Sun, 23 Oct 2022 21:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=OMsh9Oc0CCknYUovkbuTqB+UsRMDQpThqpMPaS13aiY=; b=X4NbSbX6jT6LRKYcirGh4ZFYQH27cp8jAx8yv+AjmKzbnlU3VJWvULmCKNyQ6WvIjr 0wbaC6rGwwHEk3l+ZvNB6cYWuZ3sb9OnEW++/3jVt9qpJeYqJJ+PWXRwS4Hroc5VhcnA DH2vmReH13HxNpnSsMZRK4k7W6roZEHho2bA45gprg9DI9rvioJRpTCM9ivIEgcZUqIu lr9sqb2OCAJI1tEQqHquizUz9TQfwh2xf4u4LUmIzHriF+i2oDZoZ5hLjyTeNFMOiUED 8lh8Pqx294Xt7iRC0jYQXHs5wLMlwr1JT0JIy5Qoa9UGcIYQ09QVSW/Skac24JYVwQLh a4DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OMsh9Oc0CCknYUovkbuTqB+UsRMDQpThqpMPaS13aiY=; b=P+X0ikg1OVE5lk74WcpIW6syfSfw3egFGQWGr3pbD4AKw58nvID+dJicsSuFQ3MpKK 2Z6Q7otSN0wrOPU0FjNXXrOPRFS+h4o7mX2eokfUFnkl7snbLGUYThB6405g/f9dLzsN eVYQT0oo6nzFVdq0TpJQ0yX8tpVLmF/9tX8Hhpio4fBknWGvd1sbKttNFjy7OIXykVGN cEgya8R6gRN9Dhzcmuyw0+FRttXQGl5/xpUhkW/LECNP2GbodTMZzM4e6nZbsvzNAeME Fguop4U1qRkR48xpSvcIZYtmD1XrYMnZTlpuCs11L+PHF4gDr08++yZmaD9pax45nDUH Nz/g== X-Gm-Message-State: ACrzQf3/7GOt3nu6KWfyW6E7aS6axKE42HzTlVxL7EAzFxIr6cV8YIZX JaBf6/00OtA8cLkr4uKXgX/XXLgR9jom9w== X-Received: by 2002:a17:90a:e7c4:b0:20d:451f:a988 with SMTP id kb4-20020a17090ae7c400b0020d451fa988mr35622076pjb.57.1666586854970; Sun, 23 Oct 2022 21:47:34 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id i72-20020a62874b000000b0056b932f3280sm3213979pfe.103.2022.10.23.21.47.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:47:34 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v4 1/7] eficonfig: refactor eficonfig_select_file_handler() Date: Mon, 24 Oct 2022 13:47:58 +0900 Message-Id: <20221024044804.3351-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221024044804.3351-1-masahisa.kojima@linaro.org> References: <20221024044804.3351-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.6 at phobos.denx.de X-Virus-Status: Clean eficonfig_select_file_handler() is commonly used to select the file. eficonfig_display_select_file_option() intends to add the additional menu mainly to clear the selected file information. eficonfig_display_select_file_option() is not necessary for the file selection process, so it should be outside of eficonfig_select_file_handler(). Signed-off-by: Masahisa Kojima --- No change since v2 newly created in v2 cmd/eficonfig.c | 13 +++++-------- test/py/tests/test_eficonfig/test_eficonfig.py | 1 + 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 2595dd9563..f6a99bd01a 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -968,7 +968,7 @@ efi_status_t eficonfig_process_clear_file_selection(void *data) } static struct eficonfig_item select_file_menu_items[] = { - {"Select File", eficonfig_process_select_file}, + {"Select File", eficonfig_select_file_handler}, {"Clear", eficonfig_process_clear_file_selection}, {"Quit", eficonfig_process_quit}, }; @@ -980,12 +980,13 @@ static struct eficonfig_item select_file_menu_items[] = { * @file_info: pointer to the file information structure * Return: status code */ -efi_status_t eficonfig_display_select_file_option(struct eficonfig_select_file_info *file_info) +efi_status_t eficonfig_display_select_file_option(void *data) { efi_status_t ret; struct efimenu *efi_menu; - select_file_menu_items[1].data = file_info; + select_file_menu_items[0].data = data; + select_file_menu_items[1].data = data; efi_menu = eficonfig_create_fixed_menu(select_file_menu_items, ARRAY_SIZE(select_file_menu_items)); if (!efi_menu) @@ -1016,10 +1017,6 @@ efi_status_t eficonfig_select_file_handler(void *data) struct eficonfig_select_file_info *tmp = NULL; struct eficonfig_select_file_info *file_info = data; - ret = eficonfig_display_select_file_option(file_info); - if (ret != EFI_SUCCESS) - return ret; - tmp = calloc(1, sizeof(struct eficonfig_select_file_info)); if (!tmp) return EFI_OUT_OF_RESOURCES; @@ -1284,7 +1281,7 @@ static efi_status_t prepare_file_selection_entry(struct efimenu *efi_menu, char utf8_utf16_strcpy(&p, devname); u16_strlcat(file_name, file_info->current_path, len); ret = create_boot_option_entry(efi_menu, title, file_name, - eficonfig_select_file_handler, file_info); + eficonfig_display_select_file_option, file_info); out: free(devname); free(file_name); diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py b/test/py/tests/test_eficonfig/test_eficonfig.py index 99606d9c4b..102bfd7541 100644 --- a/test/py/tests/test_eficonfig/test_eficonfig.py +++ b/test/py/tests/test_eficonfig/test_eficonfig.py @@ -349,6 +349,7 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): press_up_down_enter_and_wait(0, 1, True, 'Quit') press_up_down_enter_and_wait(0, 0, True, 'No block device found!') press_escape_key(False) + press_escape_key(False) check_current_is_maintenance_menu() # Return to U-Boot console press_escape_key(True) From patchwork Mon Oct 24 04:47:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 617833 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2483082pvb; Sun, 23 Oct 2022 21:48:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6ooW+qZN3Sqyk6L1GVbWO2D5Jx0qBdPxaqV0MEUyUOzFu7/fQXLpjwMWvlHiRz+F4Rcuak X-Received: by 2002:aa7:c491:0:b0:461:7f0c:c573 with SMTP id m17-20020aa7c491000000b004617f0cc573mr9108982edq.8.1666586885510; Sun, 23 Oct 2022 21:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666586885; cv=none; d=google.com; s=arc-20160816; b=vegMtz6M2DoqTaWjc9J/2cXY5ECKkszV2Yib6ILPVXe90EGjQoOP8fykTfl2lghasU cKPLhcVUenE5IxCRZFkig5OHQX8ivG9LFRBdTagy3jJROj1GbkmPPwH+6rWhV0S197tP k+SwqHjNmaoRO/hPhoajUhj3+M7UU+O9lnEac+xNT+zWF4OaZ5nKaD9QZr7Y2T+KjOw/ +MS2a5y7mAAbjyzDnWPZH6Ccmva4I4yAsGRwvrGIDgy0+9CEn9tR7RpPmULdP6cmmaBr eheUnR9UXutYQiGndJWnRH2RqXcBEFmvRTvOgk7wAbScrgHqrhUpk0szpRsWLgli/Jmc 3K0g== 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=0ERyheRvFp8/wHvmYCSbRcxDgU68ioohlTrwboamaxo=; b=NIEK0ebn8qIwyWk3CGjbxfCbeIezU/TqA2PPunIS+vvi9UP95vq/bNaT9LswCWi1TR 7yUV1I/t5UCmXt7gVNSmewdRDD4ojv1NnZ3tWWsa/WdA+qNDTXv+XVdns9IBz9v+fw5U uvNK95fvyo5RHJdDtieXzzHDVyVB6kDCQRtXrIPWaaNa+8T9XNuhjxf76NR5V6FsqbAw QBFaMr3ouOlWFgt2b8y48/fQtfOjna5tgNNe3yz30tldEN8qtkr56i6ecHCJ1a3eqZZV L7VuxzBujzcyyUID9DXcDBnx+kwjKVajMPLcTF9aaooLr0cl/BO87U6RrRLkeiPg/icw wCDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z89oXIx7; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id e1-20020a17090618e100b00782af8d75fasi22452897ejf.252.2022.10.23.21.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:48:05 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Z89oXIx7; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 5D8B984F50; Mon, 24 Oct 2022 06:47:49 +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="Z89oXIx7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ECD7184F43; Mon, 24 Oct 2022 06:47:43 +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-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) (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 DAEC984DE8 for ; Mon, 24 Oct 2022 06:47:39 +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-pg1-x52d.google.com with SMTP id b5so7774243pgb.6 for ; Sun, 23 Oct 2022 21:47:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=0ERyheRvFp8/wHvmYCSbRcxDgU68ioohlTrwboamaxo=; b=Z89oXIx77x/Yvd0L9G4LlabhfimsnWxEflbHQ0zk5FZ0KRqDYCOHNVqle1dKbixzGf yhHS6zvCBLiPZLoaQtg6F36aelLc85vE3gS52PSDg3CBXVY2bygMjwl3LLv61qQHotZ/ mnw+0jOc0jWjz+oR0BTUl0fQ+FZVp/Gm0tR3aKW/jVUFRvkGEm6ONJZDTsmNpFLKjTms KayKk2GiRrCOATsji8EKpciKgbHj40X3NWm2Sfpg3E91LHYiWjtg3Pt3BKxTmLx2vC8g 87eBsyCO4mLAIO/wsNyT5eyNiugdKO/epxOx/5XeueU6RvAF57LQNdHRgJVxOi/5lR1m 0l+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0ERyheRvFp8/wHvmYCSbRcxDgU68ioohlTrwboamaxo=; b=WgdV8Wyt32Yxct2e3RBqzrKTFDOQdf2uy/YLw1WoaTfMhCvZ0QcBC+IqCJMX5pZinw WS+XybHHVKwKc+rJs8hPOsZI8V5JG15JAbtuyVsIW4dGawQb/byMr7O4rUTQSZKtiyOb g8t4JvMaajaRYhgoK6yT3oWtq6D5Is8a6DHUukdHgUr3nTwMoJ5MZ89XvH+wc7EdmBDI Kb2xYE74wLmqj605N3O+WyOPuJd+iMGr0K0GaQKQlyvMzvoygh5Fi/kksguLWLjc6ujW 7BHQoA0AqiZcvVmTb2AEmYAIGjhHiDHFKzwlih50Z+HWrlF1gCalsYKphdzUkvEjj3z/ 65Ew== X-Gm-Message-State: ACrzQf3+PBOQ3Zq/6vsPZIqUDc+sDyYo1iOLRB2hgAWj8yvj9M6ue5Tt 8SutaL7Gr7UVUSTSZs2Q8gZXCUBV8xNSiw== X-Received: by 2002:a05:6a00:23c5:b0:563:a0f0:e4d1 with SMTP id g5-20020a056a0023c500b00563a0f0e4d1mr31587351pfc.62.1666586857898; Sun, 23 Oct 2022 21:47:37 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id i72-20020a62874b000000b0056b932f3280sm3213979pfe.103.2022.10.23.21.47.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:47:37 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v4 2/7] eficonfig: expose append entry function Date: Mon, 24 Oct 2022 13:47:59 +0900 Message-Id: <20221024044804.3351-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221024044804.3351-1-masahisa.kojima@linaro.org> References: <20221024044804.3351-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.6 at phobos.denx.de X-Virus-Status: Clean This commit exposes the eficonfig menu entry append function. Signed-off-by: Masahisa Kojima --- No change since v2 newly created in v2 cmd/eficonfig.c | 32 +++++++++++++++++--------------- include/efi_config.h | 5 +++++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index f6a99bd01a..0cb0770ac3 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -263,7 +263,7 @@ efi_status_t eficonfig_process_quit(void *data) } /** - * append_entry() - append menu item + * eficonfig_append_menu_entry() - append menu item * * @efi_menu: pointer to the efimenu structure * @title: pointer to the entry title @@ -271,8 +271,9 @@ efi_status_t eficonfig_process_quit(void *data) * @data: pointer to the data to be passed to each entry callback * Return: status code */ -static efi_status_t append_entry(struct efimenu *efi_menu, - char *title, eficonfig_entry_func func, void *data) +efi_status_t eficonfig_append_menu_entry(struct efimenu *efi_menu, + char *title, eficonfig_entry_func func, + void *data) { struct eficonfig_entry *entry; @@ -295,12 +296,12 @@ static efi_status_t append_entry(struct efimenu *efi_menu, } /** - * append_quit_entry() - append quit entry + * eficonfig_append_quit_entry() - append quit entry * * @efi_menu: pointer to the efimenu structure * Return: status code */ -static efi_status_t append_quit_entry(struct efimenu *efi_menu) +efi_status_t eficonfig_append_quit_entry(struct efimenu *efi_menu) { char *title; efi_status_t ret; @@ -309,7 +310,7 @@ static efi_status_t append_quit_entry(struct efimenu *efi_menu) if (!title) return EFI_OUT_OF_RESOURCES; - ret = append_entry(efi_menu, title, eficonfig_process_quit, NULL); + ret = eficonfig_append_menu_entry(efi_menu, title, eficonfig_process_quit, NULL); if (ret != EFI_SUCCESS) free(title); @@ -341,7 +342,7 @@ void *eficonfig_create_fixed_menu(const struct eficonfig_item *items, int count) if (!title) goto out; - ret = append_entry(efi_menu, title, iter->func, iter->data); + ret = eficonfig_append_menu_entry(efi_menu, title, iter->func, iter->data); if (ret != EFI_SUCCESS) { free(title); goto out; @@ -634,14 +635,15 @@ static efi_status_t eficonfig_select_volume(struct eficonfig_select_file_info *f info->v = v; info->dp = device_path; info->file_info = file_info; - ret = append_entry(efi_menu, devname, eficonfig_volume_selected, info); + ret = eficonfig_append_menu_entry(efi_menu, devname, eficonfig_volume_selected, + info); if (ret != EFI_SUCCESS) { free(info); goto out; } } - ret = append_quit_entry(efi_menu); + ret = eficonfig_append_quit_entry(efi_menu); if (ret != EFI_SUCCESS) goto out; @@ -745,8 +747,8 @@ eficonfig_create_file_entry(struct efimenu *efi_menu, u32 count, (int (*)(const void *, const void *))sort_file); for (i = 0; i < entry_num; i++) { - ret = append_entry(efi_menu, tmp_infos[i]->file_name, - eficonfig_file_selected, tmp_infos[i]); + ret = eficonfig_append_menu_entry(efi_menu, tmp_infos[i]->file_name, + eficonfig_file_selected, tmp_infos[i]); if (ret != EFI_SUCCESS) goto out; } @@ -815,7 +817,7 @@ static efi_status_t eficonfig_select_file(struct eficonfig_select_file_info *fil if (ret != EFI_SUCCESS) goto err; - ret = append_quit_entry(efi_menu); + ret = eficonfig_append_quit_entry(efi_menu); if (ret != EFI_SUCCESS) goto err; @@ -1218,7 +1220,7 @@ static efi_status_t create_boot_option_entry(struct efimenu *efi_menu, char *tit utf16_utf8_strcpy(&p, val); } - return append_entry(efi_menu, buf, func, data); + return eficonfig_append_menu_entry(efi_menu, buf, func, data); } /** @@ -1677,7 +1679,7 @@ static efi_status_t eficonfig_add_boot_selection_entry(struct efimenu *efi_menu, utf16_utf8_strcpy(&p, lo.label); info->boot_index = boot_index; info->selected = selected; - ret = append_entry(efi_menu, buf, eficonfig_process_boot_selected, info); + ret = eficonfig_append_menu_entry(efi_menu, buf, eficonfig_process_boot_selected, info); if (ret != EFI_SUCCESS) { free(load_option); free(info); @@ -1736,7 +1738,7 @@ static efi_status_t eficonfig_show_boot_selection(unsigned int *selected) break; } - ret = append_quit_entry(efi_menu); + ret = eficonfig_append_quit_entry(efi_menu); if (ret != EFI_SUCCESS) goto out; diff --git a/include/efi_config.h b/include/efi_config.h index 098cac2115..86bc801211 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -95,4 +95,9 @@ efi_status_t eficonfig_get_unused_bootoption(u16 *buf, efi_status_t eficonfig_append_bootorder(u16 index); efi_status_t eficonfig_generate_media_device_boot_option(void); +efi_status_t eficonfig_append_menu_entry(struct efimenu *efi_menu, + char *title, eficonfig_entry_func func, + void *data); +efi_status_t eficonfig_append_quit_entry(struct efimenu *efi_menu); + #endif From patchwork Mon Oct 24 04:48:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 617834 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2483170pvb; Sun, 23 Oct 2022 21:48:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM72g7ulsFC17Th/QWstV99c1pvOol11XbEK4C2GiD3QOGMMpF7R4TTa6SJYD9hfvRzJWQrz X-Received: by 2002:a05:6402:42d0:b0:457:d16e:283d with SMTP id i16-20020a05640242d000b00457d16e283dmr28837441edc.395.1666586897566; Sun, 23 Oct 2022 21:48:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666586897; cv=none; d=google.com; s=arc-20160816; b=NptnIw8jUn2gyg9mzQuZIqWbQtSmGBTuSGDhTdP42Dd8Xgya+pXVwWzKpU5FfyUDFd 19PfxVzcsz4URrq3jH611DgPAXUO/LkEDT/ov575dDOE09zAHV5XHoQFUpTdJtcFB5JM TAkzSGmvqLsoMa1zHh4xTq47K1TwefBqzbo+MHVsM/d8DUPVYqQ1FnS5wunzoEcZe2Xj 3kmPptA9rA7ZmERQ71+MdX4jxqEi4boN0xgzmp6AF9eBCHWAgqb/aQOwgf/RnGkr39HI Nlu1ngRi3N6D0vldC1brLPx/02uTtq+fsfWKBhF45/BZrV9z6JVh291ZDipF0fbevmw5 7aTw== 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=/Q8/dYPpJGnZZJQmZU3M0r33BhFE3zOJjkBcvoc0k4A=; b=QaKp+DZM2FQWQL1Yfqi26ByqoBq/Ts+SPpT8BJcm1302p+RzhPXcrPlPLg6yTutzuG 00JG1junJ3b1fOAs5xH47fnlBhWQ5d2PAnkO3Ja35kvPuca6BuzGbHKlXtRaHNBdDL/x JkpZxCcahtDAostBYN7d2/0LOyywDJgTgfCZg2Jyr2mmKqPHrKK78OndwSNdPoPwC5Ir WAt9m+ZmC3oCO8ltLPvkfETyjrs0Y6nF8yEeV1ATqKX8coEVC95iyzjpNQmFBSw5UI/o WLwDkzRm+fh0Mk2KHT5druYnUo3x/7Sp48qHYjIazc97+1MkxI6nrLZyqBVoygI8hzsp G+zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fekqojZV; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id dd3-20020a1709069b8300b0073ffabc3352si27901535ejc.836.2022.10.23.21.48.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:48:17 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fekqojZV; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 1142584F52; Mon, 24 Oct 2022 06:47:55 +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="fekqojZV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9D7D584F49; Mon, 24 Oct 2022 06:47:48 +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-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) (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 3DFD884F3E for ; Mon, 24 Oct 2022 06:47:43 +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-x102f.google.com with SMTP id m6-20020a17090a5a4600b00212f8dffec9so2557843pji.0 for ; Sun, 23 Oct 2022 21:47:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=/Q8/dYPpJGnZZJQmZU3M0r33BhFE3zOJjkBcvoc0k4A=; b=fekqojZV1ZGmVCAoYP5KD09mirC4StCMf6/W80IBAok7E3A466EF58LM107F0stM16 vFBzcIG6A9a9wEacQQl2l35Dzws87Br/9MPKazdzJHSgM+I8yZ6TBsiCvNo6s96V32GY QvSxXWwNJrxxEhF3RV8MKIqwXDJ3YN5ZKVqm0kfgXz83ZSto9XhQW0J85QhjzfD4p/v2 XSeSNTstc3GpH0GyC6pUGPZ0645ixkW/k2+EuV3fA1GNLvWyYSq1dd71IcKVH0CX0mSL C60eTkOs+KMydZdxXBJraoOagCbNfgHAcVU1dCoW7C+jCcuei+okUasEcMolenTzC5EZ 3GyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/Q8/dYPpJGnZZJQmZU3M0r33BhFE3zOJjkBcvoc0k4A=; b=ubktLjK3kLQZgxWGBv4VT4qtzhtTrrzM47Hek5JhVAkDRnAgNUl4VXxw2m/1x2hgWC lEBpNzT2nTuYrzbw0Ur/60euxN1EHIMG8y7w51V/KJMRyMgQGNDZ8rFLMUeToe6XrGi4 WC7t9nz4W2vrozdF57fJZ0ncNsqAU8G9uxYpl1RF+GtssZOYs4Xp+DRXFUUUFtrsnR89 QE+s6w8IEIf8eYgVcrZp4HhIgL5ovsKR5CQ1mixiuepDfjXaTBKkXFaK2Kpz6vap9JUT Ak1CKCUJgZ4bImUSNvdwQIifjbq+0DdEDmL/4SGWmSRUKbIRnI7C+TNlSPYgThKCaQKx CMwA== X-Gm-Message-State: ACrzQf1zgQn6e1iixJ/NOcu5k5Vsb1HhjW+Dznp9ZF7f1dCv7bZCpxVb Tb6TCkkO2+vyvdS/agSQ4KA8xnh/SyZ/fQ== X-Received: by 2002:a17:903:2144:b0:182:42ce:5778 with SMTP id s4-20020a170903214400b0018242ce5778mr31258146ple.46.1666586861269; Sun, 23 Oct 2022 21:47:41 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id i72-20020a62874b000000b0056b932f3280sm3213979pfe.103.2022.10.23.21.47.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:47:40 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Stefan Roese Subject: [PATCH v4 3/7] eficonfig: add direct menu entry access mode Date: Mon, 24 Oct 2022 13:48:00 +0900 Message-Id: <20221024044804.3351-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221024044804.3351-1-masahisa.kojima@linaro.org> References: <20221024044804.3351-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.6 at phobos.denx.de X-Virus-Status: Clean This commit adds the direct menu entry access mode. User can select the menu entry by '&' key followed by the menu title name. User input is read in UTF-16, then UTF-16 string is converted into UTF-8 internally because string comparison relies on strncasecmp(). There is no equivalent string comparison function for UTF-16. Signed-off-by: Masahisa Kojima --- Newly added in v4 cmd/eficonfig.c | 120 ++++++++++++++++++++++++++++++++++++++++++- common/menu.c | 3 ++ include/efi_config.h | 3 ++ include/menu.h | 1 + 4 files changed, 126 insertions(+), 1 deletion(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 0cb0770ac3..56d9268f9f 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -22,6 +22,7 @@ static struct efi_simple_text_input_protocol *cin; +#define EFICONFIG_ACCESSOR_STR_MAX 16 #define EFICONFIG_DESCRIPTION_MAX 32 #define EFICONFIG_OPTIONAL_DATA_MAX 64 @@ -155,7 +156,28 @@ static void eficonfig_print_entry(void *data) if (reverse) puts(ANSI_COLOR_REVERSE); - printf("%s", entry->title); + if (reverse && entry->efi_menu->direct_access_mode) { + size_t len = u16_strlen(entry->efi_menu->accessor_str); + char *accessor_str, *p; + + accessor_str = calloc(1, utf16_utf8_strlen(entry->efi_menu->accessor_str) + 1); + if (!accessor_str) { + printf("%s", entry->title); + return; + } + p = accessor_str; + utf16_utf8_strncpy(&p, entry->efi_menu->accessor_str, EFICONFIG_ACCESSOR_STR_MAX); + len = strlen(accessor_str); + if (!strncasecmp(accessor_str, entry->title, len)) { + printf("%.*s" ANSI_COLOR_RESET "%s", (int)len, entry->title, + &entry->title[len]); + } else { + printf("%s", entry->title); + } + free(accessor_str); + } else { + printf("%s", entry->title); + } if (reverse) puts(ANSI_COLOR_RESET); @@ -182,6 +204,83 @@ static void eficonfig_display_statusline(struct menu *m) entry->efi_menu->count + 6, 1, entry->efi_menu->count + 7, 1); } +/** + * eficonfig_handle_direct_accessor() - handle direct access user input + * + * @efi_menu: pointer to the efimenu structure + * Return: key string to identify the selected entry + */ +static char *eficonfig_handle_direct_accessor(struct efimenu *efi_menu) +{ + efi_status_t ret; + char *accessor_str, *p; + struct efi_input_key key; + struct list_head *pos, *n; + struct eficonfig_entry *entry; + static int len; + + /* Read user input */ + do { + ret = EFI_CALL(cin->read_key_stroke(cin, &key)); + mdelay(10); + } while (ret == EFI_NOT_READY); + + /* If user presses Ctrl+C or ESC, exit direct access mode */ + if (key.unicode_char == 0x3 || key.scan_code == 23) + goto out; + + /* If user presses ENTER, exit direct access mode and return the active entry */ + if (key.unicode_char == u'\r') { + list_for_each_safe(pos, n, &efi_menu->list) { + entry = list_entry(pos, struct eficonfig_entry, list); + if (entry->num == efi_menu->active) { + efi_menu->direct_access_mode = false; + memset(efi_menu->accessor_str, 0, + EFICONFIG_ACCESSOR_STR_MAX * sizeof(u16)); + return entry->key; + } + } + + /* no matching entry */ + goto out; + } + + /* Ignore other control code and efi scan code */ + if (key.unicode_char < 0x20 || key.scan_code != 0) + return NULL; + + len = u16_strlen(efi_menu->accessor_str); + if (len < EFICONFIG_ACCESSOR_STR_MAX - 1) + efi_menu->accessor_str[len] = key.unicode_char; + + accessor_str = calloc(1, utf16_utf8_strlen(efi_menu->accessor_str) + 1); + if (!accessor_str) + return NULL; + + p = accessor_str; + utf16_utf8_strncpy(&p, efi_menu->accessor_str, EFICONFIG_ACCESSOR_STR_MAX); + + list_for_each_safe(pos, n, &efi_menu->list) { + entry = list_entry(pos, struct eficonfig_entry, list); + if (!strncasecmp(accessor_str, entry->title, strlen(accessor_str))) { + efi_menu->active = entry->num; + free(accessor_str); + return NULL; + } + } + + /* does not match any entries */ + free(accessor_str); + efi_menu->active = 0; + return NULL; + +out: + efi_menu->direct_access_mode = false; + memset(efi_menu->accessor_str, 0, EFICONFIG_ACCESSOR_STR_MAX * sizeof(u16)); + efi_menu->active = 0; + return NULL; +} + /** * eficonfig_choice_entry() - user key input handler * @@ -196,6 +295,9 @@ static char *eficonfig_choice_entry(void *data) enum bootmenu_key key = KEY_NONE; struct efimenu *efi_menu = data; + if (efi_menu->direct_access_mode) + return eficonfig_handle_direct_accessor(efi_menu); + while (1) { bootmenu_loop((struct bootmenu_data *)efi_menu, &key, &esc); @@ -221,6 +323,10 @@ static char *eficonfig_choice_entry(void *data) /* Quit by choosing the last entry */ entry = list_last_entry(&efi_menu->list, struct eficonfig_entry, list); return entry->key; + case KEY_AMPERSAND: + memset(efi_menu->accessor_str, 0, EFICONFIG_ACCESSOR_STR_MAX * sizeof(u16)); + efi_menu->direct_access_mode = true; + return NULL; default: /* Pressed key is not valid, no need to regenerate the menu */ break; @@ -248,6 +354,7 @@ void eficonfig_destroy(struct efimenu *efi_menu) free(entry); } free(efi_menu->menu_header); + free(efi_menu->accessor_str); free(efi_menu); } @@ -385,6 +492,9 @@ efi_status_t eficonfig_process_common(struct efimenu *efi_menu, char *menu_heade if (!efi_menu->menu_header) return EFI_OUT_OF_RESOURCES; } + efi_menu->accessor_str = calloc(1, EFICONFIG_ACCESSOR_STR_MAX * sizeof(u16)); + if (!efi_menu->accessor_str) + return EFI_OUT_OF_RESOURCES; menu = menu_create(NULL, 0, 1, eficonfig_display_statusline, eficonfig_print_entry, eficonfig_choice_entry, @@ -1866,6 +1976,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) enum bootmenu_key key = KEY_NONE; struct eficonfig_boot_order *entry; + if (efi_menu->direct_access_mode) { + eficonfig_handle_direct_accessor(efi_menu); + return EFI_NOT_READY; + } + while (1) { bootmenu_loop(NULL, &key, &esc); @@ -1931,6 +2046,9 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) break; case KEY_QUIT: return EFI_ABORTED; + case KEY_AMPERSAND: + efi_menu->direct_access_mode = true; + return EFI_NOT_READY; default: /* Pressed key is not valid, no need to regenerate the menu */ break; diff --git a/common/menu.c b/common/menu.c index 8fe00965c0..6ea9f5c9b8 100644 --- a/common/menu.c +++ b/common/menu.c @@ -557,4 +557,7 @@ void bootmenu_loop(struct bootmenu_data *menu, if (c == ' ') *key = KEY_SPACE; + + if (c == '&') + *key = KEY_AMPERSAND; } diff --git a/include/efi_config.h b/include/efi_config.h index 86bc801211..1b84e2d579 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -45,6 +45,7 @@ struct eficonfig_entry { * @active: active menu entry index * @count: total count of menu entry * @menu_header: menu header string + * @accessor_str: pointer to the accessor string for entry shortcut * @list: menu entry list structure */ struct efimenu { @@ -52,6 +53,8 @@ struct efimenu { int active; int count; char *menu_header; + bool direct_access_mode; + u16 *accessor_str; struct list_head list; }; diff --git a/include/menu.h b/include/menu.h index 702aacb170..03bf8dc4f5 100644 --- a/include/menu.h +++ b/include/menu.h @@ -51,6 +51,7 @@ enum bootmenu_key { KEY_PLUS, KEY_MINUS, KEY_SPACE, + KEY_AMPERSAND, }; void bootmenu_autoboot_loop(struct bootmenu_data *menu, From patchwork Mon Oct 24 04:48:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 617837 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2483463pvb; Sun, 23 Oct 2022 21:49:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM72+CBLopHCiJGJjMT+XpA8wC7N6IrfjXE8fQ0TKDl+XDhCTUCaS5vgVF56dZGAOm+jDw6k X-Received: by 2002:a17:906:1ec5:b0:78d:b3d1:183b with SMTP id m5-20020a1709061ec500b0078db3d1183bmr25615700ejj.709.1666586959141; Sun, 23 Oct 2022 21:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666586959; cv=none; d=google.com; s=arc-20160816; b=I1Dr+ool5NFduVMGKqkFLxTPyn6/8gezgZ7rxhxi+qh39RHcyOEnbnymWH6GYO0RVj E8/WbCB5PFPYQP7VIdsCpgo/HcELQLiBVlxrs9QURhRWEbTx55JMGMlE8OTy46bMC/6D m6YTnuHSbjIip1b39FHJfoW1mtaDf+aWgGz9aXh6rqdXgZ1O8b8cpngVMs4mmJZh+Kuc so6ybQKIUKdWnADSVFgz6uQm2gPhpW88QVkw+UFigvULfZva3Z2+F5R6uilh1mYqe6mj s/lVnBeN0iWDLSSWyphpS5C8ZMgg0B5UlMKwzpyFYjc5rt9KvRnam81kMs3vvRsGP8/0 0IMA== 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=rxT3K09tYUScZAERYfMbRRKxf21oBrXD283szGG3VYk=; b=Lvd2Tu7SYNCOns2Z3C5jjmRjOCOk6m7gIlHWevMFr80YEWwL4kkbaiDqo0bZQ04HYg sDc4kY1pV/57CGXKZdCENeMvnPmAG0z/HaHzdXJtxKIXg7TdPSIEMjiUEeRok5VgNTFE nGFUCztfcE6byiffvzFw7Wv47ULpIPJ/NCTnmH2Af1JMD04KWEUFleuUTPtc01+nU0/3 ap00xdhcipb2Ak0gNCPGaq+LktCjYnAIbzijXDnQnCmW+YLxY922lWey2ZGTgucb0S2s 7J7ylrjjHyQy1RlabrPoklKvrIIRQ/zk5zr1hpc15xbUVCuR1eWYEas64JeRSswgD8yx vD0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Po+bheMR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id bo17-20020a0564020b3100b00461c9edc3a5si1329513edb.77.2022.10.23.21.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:49:19 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Po+bheMR; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 3138084F48; Mon, 24 Oct 2022 06:48:14 +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="Po+bheMR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 638D084F49; Mon, 24 Oct 2022 06:48:06 +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-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (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 00E2684F58 for ; Mon, 24 Oct 2022 06:47:56 +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-x1030.google.com with SMTP id s22-20020a17090a075600b002130d2ad62aso1383696pje.2 for ; Sun, 23 Oct 2022 21:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=rxT3K09tYUScZAERYfMbRRKxf21oBrXD283szGG3VYk=; b=Po+bheMR/iXLOmAjRq8cwnHPG368YJ6QT8NYCc+jy8ky6lStEIvXXdXwJ/vHwjWuGa W10uxSKqS8rcgkcW/gVGGyRH9lFbrsS4Qfevkq6wCI8OTILhWicusqItG3HZSnL7IIPe 0uXwt48gXmEkWpdvspqfaHF99OJfOpBGKELVYVdiuEjhXXasS5W0dwtwcegPE3ckimek TpDKz3p3LV5xYp/cXSjWjzJHwRfg+VPCIzeuvZ7gQpfwcFF8pyetEXxaY25rysqJFisB +onLiIVxS3DB68fHRdAWDbYQZtPhWnLtLObZYehqUcl2lrE9EV/HNi7jGZskMoKx+Zta Oq9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rxT3K09tYUScZAERYfMbRRKxf21oBrXD283szGG3VYk=; b=PG3iSUlHUeblRbRaJUotEyhQbEnUcSepHn5eVQkztcJMa6CJRyOY1nSeF+FB+qltnc ZOLPbAyy/Qcmp1+GdWaAfG25jiememDr5UIDZBErkS26uS4YhfuKBMRDrsDTftNkMOXn 9v4cCIFGLSivG5EmdDYDPOH9oUnCSEpRNMeku95BRXW25MkC/BTRyasf/YTpheYqsco1 /YPeZXS9FIlj1M586qeexUXsIACeittaDD/X8MgQWWivDEFcN7bIc5l6lReR+DVU9r0t /IvWLmYu1CclvYXuiIu0MJ9znrKjXKhEDccTSY7grtGfMKeb8wfpjjTQS01BYMDjova3 0r7Q== X-Gm-Message-State: ACrzQf168mCOYC1hPeqOg896YGc9FIpUhlD5k7IrLT5bNxb0F08SE6IY al3yntO05QTBI+MqMznp8UQN74Xs5uMefQ== X-Received: by 2002:a17:902:9684:b0:17e:71b2:bd16 with SMTP id n4-20020a170902968400b0017e71b2bd16mr31560979plp.163.1666586864286; Sun, 23 Oct 2022 21:47:44 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id i72-20020a62874b000000b0056b932f3280sm3213979pfe.103.2022.10.23.21.47.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:47:43 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v4 4/7] eficonfig: add direct menu entry access in change boot order Date: Mon, 24 Oct 2022 13:48:01 +0900 Message-Id: <20221024044804.3351-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221024044804.3351-1-masahisa.kojima@linaro.org> References: <20221024044804.3351-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.6 at phobos.denx.de X-Virus-Status: Clean This commit adds the direct menu entry access in change boot order menu. To call eficonfig_handle_direct_accessor() from change boot order menu, refactoring is required to use 'eficonfig_entry' structure in change boot order menu processing. Signed-off-by: Masahisa Kojima --- Newly added in v4 cmd/eficonfig.c | 165 ++++++++++++++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 63 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 56d9268f9f..8c131849be 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -94,20 +94,14 @@ struct eficonfig_boot_selection_data { }; /** - * struct eficonfig_boot_order - structure to be used to update BootOrder variable + * struct eficonfig_boot_order_data - structure to be used to update BootOrder variable * - * @num: index in the menu entry - * @description: pointer to the description string * @boot_index: boot option index * @active: flag to include the boot option into BootOrder variable - * @list: list structure */ -struct eficonfig_boot_order { - u32 num; - u16 *description; +struct eficonfig_boot_order_data { u32 boot_index; bool active; - struct list_head list; }; /** @@ -1924,7 +1918,7 @@ static void eficonfig_display_change_boot_order(struct efimenu *efi_menu) { bool reverse; struct list_head *pos, *n; - struct eficonfig_boot_order *entry; + struct eficonfig_entry *entry; printf(ANSI_CLEAR_CONSOLE ANSI_CURSOR_POSITION "\n ** Change Boot Order **\n" @@ -1940,7 +1934,7 @@ static void eficonfig_display_change_boot_order(struct efimenu *efi_menu) /* draw boot option list */ list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list); reverse = (entry->num == efi_menu->active); printf(ANSI_CURSOR_POSITION, entry->num + 4, 7); @@ -1949,13 +1943,34 @@ static void eficonfig_display_change_boot_order(struct efimenu *efi_menu) puts(ANSI_COLOR_REVERSE); if (entry->num < efi_menu->count - 2) { - if (entry->active) + if (((struct eficonfig_boot_order_data *)entry->data)->active) printf("[*] "); else printf("[ ] "); } - printf("%ls", entry->description); + if (reverse && efi_menu->direct_access_mode) { + size_t len = u16_strlen(efi_menu->accessor_str); + char *accessor_str, *p; + + accessor_str = calloc(1, utf16_utf8_strlen(efi_menu->accessor_str) + 1); + if (!accessor_str) { + printf("%s", entry->title); + return; + } + p = accessor_str; + utf16_utf8_strncpy(&p, efi_menu->accessor_str, EFICONFIG_ACCESSOR_STR_MAX); + len = strlen(accessor_str); + if (!strncasecmp(accessor_str, entry->title, len)) { + printf("%.*s" ANSI_COLOR_RESET "%s", (int)len, entry->title, + &entry->title[len]); + } else { + printf("%s", entry->title); + } + free(accessor_str); + } else { + printf("%s", entry->title); + } if (reverse) puts(ANSI_COLOR_RESET); @@ -1972,12 +1987,18 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) { int esc = 0; struct list_head *pos, *n; - struct eficonfig_boot_order *tmp; enum bootmenu_key key = KEY_NONE; - struct eficonfig_boot_order *entry; + struct eficonfig_entry *entry, *tmp; if (efi_menu->direct_access_mode) { - eficonfig_handle_direct_accessor(efi_menu); + if (eficonfig_handle_direct_accessor(efi_menu)) { + /* If the selected entry is "Save" or "Quit", complete selection */ + if (efi_menu->active == efi_menu->count - 2) + return EFI_SUCCESS; + + if (efi_menu->active == efi_menu->count - 1) + return EFI_ABORTED; + } return EFI_NOT_READY; } @@ -1988,11 +2009,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) case KEY_PLUS: if (efi_menu->active > 0) { list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list); if (entry->num == efi_menu->active) break; } - tmp = list_entry(pos->prev, struct eficonfig_boot_order, list); + tmp = list_entry(pos->prev, struct eficonfig_entry, list); entry->num--; tmp->num++; list_del(&tmp->list); @@ -2006,11 +2027,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) case KEY_MINUS: if (efi_menu->active < efi_menu->count - 3) { list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list); if (entry->num == efi_menu->active) break; } - tmp = list_entry(pos->next, struct eficonfig_boot_order, list); + tmp = list_entry(pos->next, struct eficonfig_entry, list); entry->num++; tmp->num--; list_del(&entry->list); @@ -2036,9 +2057,11 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) case KEY_SPACE: if (efi_menu->active < efi_menu->count - 2) { list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); + entry = list_entry(pos, struct eficonfig_entry, list); if (entry->num == efi_menu->active) { - entry->active = entry->active ? false : true; + struct eficonfig_boot_order_data *data = entry->data; + + data->active = data->active ? false : true; return EFI_NOT_READY; } } @@ -2047,6 +2070,8 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) case KEY_QUIT: return EFI_ABORTED; case KEY_AMPERSAND: + memset(efi_menu->accessor_str, 0, + EFICONFIG_ACCESSOR_STR_MAX * sizeof(u16)); efi_menu->direct_access_mode = true; return EFI_NOT_READY; default: @@ -2067,12 +2092,13 @@ static efi_status_t eficonfig_choice_change_boot_order(struct efimenu *efi_menu) static efi_status_t eficonfig_add_change_boot_order_entry(struct efimenu *efi_menu, u32 boot_index, bool active) { + char *title, *p; efi_status_t ret; efi_uintn_t size; void *load_option; struct efi_load_option lo; u16 varname[] = u"Boot####"; - struct eficonfig_boot_order *entry; + struct eficonfig_boot_order_data *data; efi_create_indexed_name(varname, sizeof(varname), "Boot", boot_index); load_option = efi_get_var(varname, &efi_global_variable_guid, &size); @@ -2080,31 +2106,38 @@ static efi_status_t eficonfig_add_change_boot_order_entry(struct efimenu *efi_me return EFI_SUCCESS; ret = efi_deserialize_load_option(&lo, load_option, &size); - if (ret != EFI_SUCCESS) { - free(load_option); - return ret; + if (ret != EFI_SUCCESS) + goto out; + + data = calloc(1, sizeof(struct eficonfig_boot_order_data)); + if (!data) { + ret = EFI_OUT_OF_RESOURCES; + goto out; } - entry = calloc(1, sizeof(struct eficonfig_boot_order)); - if (!entry) { - free(load_option); - return EFI_OUT_OF_RESOURCES; + title = calloc(1, utf16_utf8_strlen(lo.label) + 1); + if (!title) { + free(data); + ret = EFI_OUT_OF_RESOURCES; + goto out; } + p = title; + utf16_utf8_strcpy(&p, lo.label); - entry->description = u16_strdup(lo.label); - if (!entry->description) { - free(load_option); - free(entry); - return EFI_OUT_OF_RESOURCES; + data->boot_index = boot_index; + data->active = active; + + ret = eficonfig_append_menu_entry(efi_menu, title, NULL, data); + if (ret != EFI_SUCCESS) { + free(data); + free(title); + goto out; } - entry->num = efi_menu->count++; - entry->boot_index = boot_index; - entry->active = active; - list_add_tail(&entry->list, &efi_menu->list); +out: free(load_option); - return EFI_SUCCESS; + return ret; } /** @@ -2119,8 +2152,8 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi u16 *bootorder, efi_uintn_t num) { u32 i; + char *title; efi_status_t ret; - struct eficonfig_boot_order *entry; /* list the load option in the order of BootOrder variable */ for (i = 0; i < num; i++) { @@ -2147,27 +2180,25 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi } /* add "Save" and "Quit" entries */ - entry = calloc(1, sizeof(struct eficonfig_boot_order)); - if (!entry) + title = strdup("Save"); + if (!title) { + ret = EFI_OUT_OF_RESOURCES; goto out; + } - entry->num = efi_menu->count++; - entry->description = u16_strdup(u"Save"); - list_add_tail(&entry->list, &efi_menu->list); - - entry = calloc(1, sizeof(struct eficonfig_boot_order)); - if (!entry) + ret = eficonfig_append_menu_entry(efi_menu, title, NULL, NULL); + if (ret != EFI_SUCCESS) goto out; - entry->num = efi_menu->count++; - entry->description = u16_strdup(u"Quit"); - list_add_tail(&entry->list, &efi_menu->list); + ret = eficonfig_append_quit_entry(efi_menu); + if (ret != EFI_SUCCESS) + goto out; efi_menu->active = 0; return EFI_SUCCESS; out: - return EFI_OUT_OF_RESOURCES; + return ret; } /** @@ -2183,13 +2214,17 @@ static efi_status_t eficonfig_process_change_boot_order(void *data) efi_status_t ret; efi_uintn_t num, size; struct list_head *pos, *n; - struct eficonfig_boot_order *entry; + struct eficonfig_entry *entry; struct efimenu *efi_menu; efi_menu = calloc(1, sizeof(struct efimenu)); if (!efi_menu) return EFI_OUT_OF_RESOURCES; + efi_menu->accessor_str = calloc(1, 32); + if (!efi_menu->accessor_str) + return EFI_OUT_OF_RESOURCES; + bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); INIT_LIST_HEAD(&efi_menu->list); @@ -2214,9 +2249,16 @@ static efi_status_t eficonfig_process_change_boot_order(void *data) /* create new BootOrder */ count = 0; list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); - if (entry->active) - new_bootorder[count++] = entry->boot_index; + struct eficonfig_boot_order_data *data; + + entry = list_entry(pos, struct eficonfig_entry, list); + /* exit the loop when iteration reaches "Save" */ + if (!strncmp(entry->title, "Save", strlen("Save"))) + break; + + data = entry->data; + if (data->active) + new_bootorder[count++] = data->boot_index; } size = count * sizeof(u16); @@ -2235,15 +2277,12 @@ static efi_status_t eficonfig_process_change_boot_order(void *data) } } out: + free(bootorder); list_for_each_safe(pos, n, &efi_menu->list) { - entry = list_entry(pos, struct eficonfig_boot_order, list); - list_del(&entry->list); - free(entry->description); - free(entry); + entry = list_entry(pos, struct eficonfig_entry, list); + free(entry->data); } - - free(bootorder); - free(efi_menu); + eficonfig_destroy(efi_menu); /* to stay the parent menu */ ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret; From patchwork Mon Oct 24 04:48:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 617835 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2483247pvb; Sun, 23 Oct 2022 21:48:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7R722CY016fws5CXrcOHf9vX+clStrCxnSr9GHNfYA+Ox+JZfy0ElW+9xgXpD2m98F9b+s X-Received: by 2002:a17:907:7d90:b0:78d:bc5a:913c with SMTP id oz16-20020a1709077d9000b0078dbc5a913cmr25487580ejc.390.1666586910423; Sun, 23 Oct 2022 21:48:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666586910; cv=none; d=google.com; s=arc-20160816; b=riRa/neoigHxwWgXypSX05BYF3J2v4zTNdDR/nDm+Hbj9goZPycSKnSZ8teGxNc8Ed CkPCi0EJuQ9uufnCVeieNQHqNPd8JFMcibVTC79nmgr6jDZVm70tIFVZbgBWK9F9sTYE A65liHFkNbi6SHZS1SJENs2XsP8egmA/t6DOcywhGcagocxDimikkOoKEifP0nBbYX9a kvRXyJKvinrIczJJBaba/yUOEEgfcuEAXr589oyfgjZLOvCxPbAKcD3kkJ7/mwrRxdND Fk4doWupOZM2VvpelGpTw1OWIxyMctIXzSWD0xgyPB9CzxYv82o5JnoO+N1zWaCMZDXt B8UA== 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=VoabyjqkIYYGuP9gf/yACEoQKu7iyUENZKYlTT+BLjE=; b=cOX7wZuEngW837CCjYjhleP8BZSMMEwBdc+DMOmuUBRUdbALD97f/AJlcDIlC4EjL9 UWgOh1ZQ069omDE+SeNs+Zx0c8UWLcjzzB3bH4SpK1ZqZo1ruTlNIGARteESo8hIbNBE vAsHlp9sjL9EIhlE1nuVfkIjAJh968axK58AAzLwu5c6y4GaXNonXKR6oPsKMwlsgVRR GjDPvCTsILsqInELePV7lFCWTJVgU13IVglKJwFNZqDu73CPmis/0e9JnPTVbIygfWOK zT9Zw8Ez9aOqwZ2A+V21h14O3rj2V9RGEtV+Q35Mi/9pZHaECnoHNUtSpK6ZXQOJQwNf KINA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bdWexGbZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id r7-20020aa7d587000000b00461e870df81si271752edq.620.2022.10.23.21.48.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:48:30 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bdWexGbZ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 3508A84F5B; Mon, 24 Oct 2022 06:48:00 +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="bdWexGbZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 92EBF84F5B; Mon, 24 Oct 2022 06:47:57 +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-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (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 49E1C84F44 for ; Mon, 24 Oct 2022 06:47:51 +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-x1033.google.com with SMTP id m14-20020a17090a3f8e00b00212dab39bcdso5481485pjc.0 for ; Sun, 23 Oct 2022 21:47:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=VoabyjqkIYYGuP9gf/yACEoQKu7iyUENZKYlTT+BLjE=; b=bdWexGbZ5OjdPIMExbrU4xgTV84Ol2iznOhZsvQgC/RnlHT1DKhuPEF77KaOT0OL0V wOmF5IzqCgtF6fCsepzTpOSPVZvVbWVQu02mAgS1XHetA+SN1eI73b31zGql41uSn5wQ r4lx5lKt04p6dCEQcZlvfdQhRZMhrBNKN/PKMbaL+Mi85D3TJwMcPpTSVAeZtJr73BVU 4R8P0VqpEuzbRgwbIny8PB9ZFzRM5E1rUI6+DahKSAXTtLVvoH/Igp+tDnH33gvPH1eb AIhmSl24vns5CKaJB4SkZhZOgj2Nnxsaj3vnDeoKLXgzCnoMjDox8io7dq+boixFeXyS i64Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VoabyjqkIYYGuP9gf/yACEoQKu7iyUENZKYlTT+BLjE=; b=jzqgKCLVMjcOgfK/EofX9xro7kWC9jP5ci3PMea3Vzyyo2cduKFsmKYz2SU/jMpyw9 3yefcs7C/8k0AclV8c4YzwhLsh1byMWhA4MQtbePD96q39b/koNZHxztUlgY5IQyvjTH QNe9QIz/E9XA5qPf14dRja/IJVqZMHIyjRO3fEdOSzUQWGNlCv9OxxEyg/kZeXMoMyAB /N8/oV5Ym0KRfDFHEB00Z0peSjf9DJZekBjCbKLU1WlbR1tHkqXUmbzJGyM+f3iGmt7j 7E8rRbLlqmQlBizSZpi/tEVmaUcGvE6TqW9VKGqlIzWH6YQZj+3vS6brBPBx/uRpY6dV kGIA== X-Gm-Message-State: ACrzQf1nOBgEnCDUuh0/dUigbu9Xeomu3CgnMgcOOXkQajxyXlv6ZCTq wpHn4GHBq+HD5Kf8VWtsHMSYeh7RwL/79g== X-Received: by 2002:a17:90b:4b42:b0:20d:954e:28d with SMTP id mi2-20020a17090b4b4200b0020d954e028dmr69852684pjb.93.1666586869249; Sun, 23 Oct 2022 21:47:49 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id i72-20020a62874b000000b0056b932f3280sm3213979pfe.103.2022.10.23.21.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:47:48 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima , Roger Knecht , Kever Yang , Chris Morgan , Samuel Dionne-Riel , Huang Jianan , Ashok Reddy Soma , Ovidiu Panait Subject: [PATCH v4 5/7] eficonfig: add UEFI Secure Boot Key enrollment interface Date: Mon, 24 Oct 2022 13:48:02 +0900 Message-Id: <20221024044804.3351-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221024044804.3351-1-masahisa.kojima@linaro.org> References: <20221024044804.3351-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.6 at phobos.denx.de X-Virus-Status: Clean This commit adds the menu-driven UEFI Secure Boot Key enrollment interface. User can enroll the PK, KEK, db and dbx by selecting EFI Signature Lists file. After the PK is enrolled, UEFI Secure Boot is enabled and EFI Signature Lists file must be signed by KEK or PK. Signed-off-by: Masahisa Kojima --- Changes in v4: - add CONFIG_EFI_MM_COMM_TEE dependency - fix error handling Changes in v3: - fix error handling Changes in v2: - allow to enroll .esl file - fix typos - add function comments cmd/Makefile | 5 + cmd/eficonfig.c | 3 + cmd/eficonfig_sbkey.c | 357 ++++++++++++++++++++++++++++++++++++++++++ include/efi_config.h | 5 + 4 files changed, 370 insertions(+) create mode 100644 cmd/eficonfig_sbkey.c diff --git a/cmd/Makefile b/cmd/Makefile index c95e09d058..e43ef22e98 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -66,6 +66,11 @@ obj-$(CONFIG_CMD_EEPROM) += eeprom.o obj-$(CONFIG_EFI) += efi.o obj-$(CONFIG_CMD_EFIDEBUG) += efidebug.o obj-$(CONFIG_CMD_EFICONFIG) += eficonfig.o +ifdef CONFIG_CMD_EFICONFIG +ifdef CONFIG_EFI_MM_COMM_TEE +obj-$(CONFIG_EFI_SECURE_BOOT) += eficonfig_sbkey.o +endif +endif obj-$(CONFIG_CMD_ELF) += elf.o obj-$(CONFIG_CMD_EROFS) += erofs.o obj-$(CONFIG_HUSH_PARSER) += exit.o diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 8c131849be..1ddf4c2180 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -2599,6 +2599,9 @@ static const struct eficonfig_item maintenance_menu_items[] = { {"Edit Boot Option", eficonfig_process_edit_boot_option}, {"Change Boot Order", eficonfig_process_change_boot_order}, {"Delete Boot Option", eficonfig_process_delete_boot_option}, +#if (CONFIG_IS_ENABLED(EFI_SECURE_BOOT) && CONFIG_IS_ENABLED(EFI_MM_COMM_TEE)) + {"Secure Boot Configuration", eficonfig_process_secure_boot_config}, +#endif {"Quit", eficonfig_process_quit}, }; diff --git a/cmd/eficonfig_sbkey.c b/cmd/eficonfig_sbkey.c new file mode 100644 index 0000000000..32a39eb7ba --- /dev/null +++ b/cmd/eficonfig_sbkey.c @@ -0,0 +1,357 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Menu-driven UEFI Secure Boot Key Maintenance + * + * Copyright (c) 2022 Masahisa Kojima, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +enum efi_sbkey_signature_type { + SIG_TYPE_X509 = 0, + SIG_TYPE_HASH, + SIG_TYPE_CRL, + SIG_TYPE_RSA2048, +}; + +struct eficonfig_sigtype_to_str { + efi_guid_t sig_type; + char *str; + enum efi_sbkey_signature_type type; +}; + +static const struct eficonfig_sigtype_to_str sigtype_to_str[] = { + {EFI_CERT_X509_GUID, "X509", SIG_TYPE_X509}, + {EFI_CERT_SHA256_GUID, "SHA256", SIG_TYPE_HASH}, + {EFI_CERT_X509_SHA256_GUID, "X509_SHA256 CRL", SIG_TYPE_CRL}, + {EFI_CERT_X509_SHA384_GUID, "X509_SHA384 CRL", SIG_TYPE_CRL}, + {EFI_CERT_X509_SHA512_GUID, "X509_SHA512 CRL", SIG_TYPE_CRL}, + /* U-Boot does not support the following signature types */ +/* {EFI_CERT_RSA2048_GUID, "RSA2048", SIG_TYPE_RSA2048}, */ +/* {EFI_CERT_RSA2048_SHA256_GUID, "RSA2048_SHA256", SIG_TYPE_RSA2048}, */ +/* {EFI_CERT_SHA1_GUID, "SHA1", SIG_TYPE_HASH}, */ +/* {EFI_CERT_RSA2048_SHA_GUID, "RSA2048_SHA", SIG_TYPE_RSA2048 }, */ +/* {EFI_CERT_SHA224_GUID, "SHA224", SIG_TYPE_HASH}, */ +/* {EFI_CERT_SHA384_GUID, "SHA384", SIG_TYPE_HASH}, */ +/* {EFI_CERT_SHA512_GUID, "SHA512", SIG_TYPE_HASH}, */ +}; + +/** + * is_secureboot_enabled() - check UEFI Secure Boot is enabled + * + * Return: true when UEFI Secure Boot is enabled, false otherwise + */ +static bool is_secureboot_enabled(void) +{ + efi_status_t ret; + u8 secure_boot; + efi_uintn_t size; + + size = sizeof(secure_boot); + ret = efi_get_variable_int(u"SecureBoot", &efi_global_variable_guid, + NULL, &size, &secure_boot, NULL); + + return secure_boot == 1; +} + +/** + * create_time_based_payload() - create payload for time based authenticate variable + * + * @db: pointer to the original signature database + * @new_db: pointer to the authenticated variable payload + * @size: pointer to payload size + * Return: status code + */ +static efi_status_t create_time_based_payload(void *db, void **new_db, efi_uintn_t *size) +{ + efi_status_t ret; + struct efi_time time; + efi_uintn_t total_size; + struct efi_variable_authentication_2 *auth; + + *new_db = NULL; + + /* + * SetVariable() call with EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS + * attribute requires EFI_VARIABLE_AUTHENTICATED_2 descriptor, prepare it + * without certificate data in it. + */ + total_size = sizeof(struct efi_variable_authentication_2) + *size; + + auth = calloc(1, total_size); + if (!auth) + return EFI_OUT_OF_RESOURCES; + + ret = EFI_CALL((*efi_runtime_services.get_time)(&time, NULL)); + if (ret != EFI_SUCCESS) { + free(auth); + return EFI_OUT_OF_RESOURCES; + } + time.pad1 = 0; + time.nanosecond = 0; + time.timezone = 0; + time.daylight = 0; + time.pad2 = 0; + memcpy(&auth->time_stamp, &time, sizeof(time)); + auth->auth_info.hdr.dwLength = sizeof(struct win_certificate_uefi_guid); + auth->auth_info.hdr.wRevision = 0x0200; + auth->auth_info.hdr.wCertificateType = WIN_CERT_TYPE_EFI_GUID; + guidcpy(&auth->auth_info.cert_type, &efi_guid_cert_type_pkcs7); + if (db) + memcpy((u8 *)auth + sizeof(struct efi_variable_authentication_2), db, *size); + + *new_db = auth; + *size = total_size; + + return EFI_SUCCESS; +} + +/** + * file_have_auth_header() - check file has EFI_VARIABLE_AUTHENTICATION_2 header + * @buf: pointer to file + * @size: file size + * Return: true if file has auth header, false otherwise + */ +static bool file_have_auth_header(void *buf, efi_uintn_t size) +{ + struct efi_variable_authentication_2 *auth = buf; + + if (auth->auth_info.hdr.wCertificateType != WIN_CERT_TYPE_EFI_GUID) + return false; + + if (guidcmp(&auth->auth_info.cert_type, &efi_guid_cert_type_pkcs7)) + return false; + + return true; +} + +/** + * file_is_efi_signature_list() - check the file is efi signature list + * @buf: pointer to file + * Return: true if file is efi signature list, false otherwise + */ +static bool file_is_efi_signature_list(void *buf) +{ + u32 i; + struct efi_signature_list *sig_list = buf; + + for (i = 0; i < ARRAY_SIZE(sigtype_to_str); i++) { + if (!guidcmp(&sig_list->signature_type, &sigtype_to_str[i].sig_type)) + return true; + } + + return false; +} + +/** + * eficonfig_process_enroll_key() - enroll key into signature database + * + * @data: pointer to the data for each entry + * Return: status code + */ +static efi_status_t eficonfig_process_enroll_key(void *data) +{ + u32 attr; + char *buf = NULL; + efi_uintn_t size; + efi_status_t ret; + void *new_db = NULL; + struct efi_file_handle *f; + struct efi_file_handle *root; + struct eficonfig_select_file_info file_info; + + file_info.current_path = calloc(1, EFICONFIG_FILE_PATH_BUF_SIZE); + if (!file_info.current_path) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + ret = eficonfig_select_file_handler(&file_info); + if (ret != EFI_SUCCESS) + goto out; + + ret = efi_open_volume_int(file_info.current_volume, &root); + if (ret != EFI_SUCCESS) + goto out; + + ret = efi_file_open_int(root, &f, file_info.current_path, EFI_FILE_MODE_READ, 0); + if (ret != EFI_SUCCESS) + goto out; + + size = 0; + ret = EFI_CALL(f->getinfo(f, &efi_file_info_guid, &size, NULL)); + if (ret != EFI_BUFFER_TOO_SMALL) + goto out; + + buf = calloc(1, size); + if (!buf) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + ret = EFI_CALL(f->getinfo(f, &efi_file_info_guid, &size, buf)); + if (ret != EFI_SUCCESS) + goto out; + + size = ((struct efi_file_info *)buf)->file_size; + free(buf); + + buf = calloc(1, size); + if (!buf) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + ret = efi_file_read_int(f, &size, buf); + if (ret != EFI_SUCCESS) { + eficonfig_print_msg("ERROR! Failed to read file."); + goto out; + } + if (size == 0) { + eficonfig_print_msg("ERROR! File is empty."); + goto out; + } + + /* We expect that file is EFI Signature Lists or signed EFI Signature Lists */ + if (!file_have_auth_header(buf, size)) { + if (!file_is_efi_signature_list(buf)) { + eficonfig_print_msg("ERROR! Invalid file format."); + ret = EFI_INVALID_PARAMETER; + goto out; + } + + ret = create_time_based_payload(buf, &new_db, &size); + if (ret != EFI_SUCCESS) { + eficonfig_print_msg("ERROR! Failed to create payload with timestamp."); + goto out; + } + + free(buf); + buf = new_db; + } + + attr = EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; + + /* PK can enroll only one certificate */ + if (u16_strcmp(data, u"PK")) { + efi_uintn_t db_size = 0; + + /* check the variable exists. If exists, add APPEND_WRITE attribute */ + ret = efi_get_variable_int(data, efi_auth_var_get_guid(data), NULL, + &db_size, NULL, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) + attr |= EFI_VARIABLE_APPEND_WRITE; + } + + ret = efi_set_variable_int((u16 *)data, efi_auth_var_get_guid((u16 *)data), + attr, size, buf, false); + if (ret != EFI_SUCCESS) + eficonfig_print_msg("ERROR! Failed to update signature database"); + +out: + free(file_info.current_path); + free(buf); + + /* to stay the parent menu */ + ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret; + + return ret; +} + +static struct eficonfig_item key_config_menu_items[] = { + {"Enroll New Key", eficonfig_process_enroll_key}, + {"Quit", eficonfig_process_quit}, +}; + +/** + * eficonfig_process_set_secure_boot_key() - display the key configuration menu + * + * @data: pointer to the data for each entry + * Return: status code + */ +static efi_status_t eficonfig_process_set_secure_boot_key(void *data) +{ + u32 i; + efi_status_t ret; + char header_str[32]; + struct efimenu *efi_menu; + + for (i = 0; i < ARRAY_SIZE(key_config_menu_items); i++) + key_config_menu_items[i].data = data; + + snprintf(header_str, sizeof(header_str), " ** Configure %ls **", (u16 *)data); + + while (1) { + efi_menu = eficonfig_create_fixed_menu(key_config_menu_items, + ARRAY_SIZE(key_config_menu_items)); + + ret = eficonfig_process_common(efi_menu, header_str); + eficonfig_destroy(efi_menu); + + if (ret == EFI_ABORTED) + break; + } + + /* to stay the parent menu */ + ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret; + + return ret; +} + +static const struct eficonfig_item secure_boot_menu_items[] = { + {"PK", eficonfig_process_set_secure_boot_key, u"PK"}, + {"KEK", eficonfig_process_set_secure_boot_key, u"KEK"}, + {"db", eficonfig_process_set_secure_boot_key, u"db"}, + {"dbx", eficonfig_process_set_secure_boot_key, u"dbx"}, + {"Quit", eficonfig_process_quit}, +}; + +/** + * eficonfig_process_secure_boot_config() - display the key list menu + * + * @data: pointer to the data for each entry + * Return: status code + */ +efi_status_t eficonfig_process_secure_boot_config(void *data) +{ + efi_status_t ret; + struct efimenu *efi_menu; + + while (1) { + char header_str[64]; + + snprintf(header_str, sizeof(header_str), + " ** UEFI Secure Boot Key Configuration (SecureBoot : %s) **", + (is_secureboot_enabled() ? "ON" : "OFF")); + + efi_menu = eficonfig_create_fixed_menu(secure_boot_menu_items, + ARRAY_SIZE(secure_boot_menu_items)); + if (!efi_menu) { + ret = EFI_OUT_OF_RESOURCES; + break; + } + + ret = eficonfig_process_common(efi_menu, header_str); + eficonfig_destroy(efi_menu); + + if (ret == EFI_ABORTED) + break; + } + + /* to stay the parent menu */ + ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret; + + return ret; +} diff --git a/include/efi_config.h b/include/efi_config.h index 1b84e2d579..5586e21e1e 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -102,5 +102,10 @@ efi_status_t eficonfig_append_menu_entry(struct efimenu *efi_menu, char *title, eficonfig_entry_func func, void *data); efi_status_t eficonfig_append_quit_entry(struct efimenu *efi_menu); +void *eficonfig_create_fixed_menu(const struct eficonfig_item *items, int count); + +#ifdef CONFIG_EFI_SECURE_BOOT +efi_status_t eficonfig_process_secure_boot_config(void *data); +#endif #endif From patchwork Mon Oct 24 04:48:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 617836 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2483348pvb; Sun, 23 Oct 2022 21:48:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Y+ZxjOe1V+EOdnl0Mv027rxSU3KImaGbJpJby1K9qJSPj5jUtVYN1BCZjVtWpVy0yh1Wn X-Received: by 2002:a17:906:8473:b0:77b:efa8:50e4 with SMTP id hx19-20020a170906847300b0077befa850e4mr25530442ejc.250.1666586933999; Sun, 23 Oct 2022 21:48:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666586933; cv=none; d=google.com; s=arc-20160816; b=hbaZuYLjobNLuuf6tz3hgI2W/fGYj8IJ9DI/RkqFPA6FpgzggoFTWE2vbG2cRzaKYN AAPhvXplx7KYL8pdrD8Jp9V19Nc5UMQQ1fYV6vr4D8GDgZIt4/5kEQEl87N3LdtX9B6a xioQDeCuqRmkyAQNGBdJpjNwXDj9jaq8T1zmaIf69D2YXSdl/ef9j3xfoDQqtxtVBaGg bk9d6OpwBVEL0qTBYMOnHHUd7B8Wvh6/OZjXdXfLv+682MmhI0x1qJ0QIMKvNX7aSUAf AIYPESIfIusxbT4ce4b2GJO7zArJzFs/+ARWYUjKhrt4E4n/E8VQbp3+nA6se+THM5ok A9pQ== 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=CRPt9IN85H648RSFMEnZhx++mZqyjCtw5Qf8WTOUQbw=; b=EaQ1OwBSSlZb4ftvZz5uuVQsuLxic8c1z8PD9tCp+35gcioFgAY/qLhYvY8zHrYJ/U 4m0T5ypt/vAPcY/BZc/Raq1bQzihWijuIkDa4pvWnEcEE88LJD1Rvo2Yv1DX1uxgxHdE v8o4ZRL8hqauCVCEKnHmG6wCDG5lKpyuYoN4m6h2K6s+MhMFrzM7hEOuP/ITgm+8YrRP 8TaK2QwRqo7LGY4BCP4gjL5Gc3GsHXFLLIC+Yn//vnO+as5wxAaheHGMVNXohy8fUmEB 9zdsEBhWmfHCBZV40jo/5Uu6/fhC6dUCuawN6DW/XpD1226k4wbCQBAhUS2883FKqVjF vwRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k1QoWcv1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id dz16-20020a0564021d5000b00461c74a07c8si2003628edb.343.2022.10.23.21.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:48:53 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=k1QoWcv1; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 B590B84F49; Mon, 24 Oct 2022 06:48:08 +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="k1QoWcv1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0D08F84F61; Mon, 24 Oct 2022 06:48:04 +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-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (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 49C7C84F48 for ; Mon, 24 Oct 2022 06:47:54 +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-pg1-x535.google.com with SMTP id h185so7757878pgc.10 for ; Sun, 23 Oct 2022 21:47:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=CRPt9IN85H648RSFMEnZhx++mZqyjCtw5Qf8WTOUQbw=; b=k1QoWcv1jktL87x0CFHxuNatWwAIaJ9k9qUtxjzCJR4vKE/lvDjpnR0TygFZpKCSgi St08QIFzWRDN6WvFRazohioai5am3AGtcGPbKOPUXRAKwF/hFhKbilxt3IzVp/zimvgZ R1uXdZi9/DCReSwiklLBktEHDRPecoAKko7V3RKw+LL2gGTIv8/gZN/XYdhO58pgTRva OFLhodGCucctC8iejcGg1wOBGyaECHsAciTftH2WFioDiKWJL9IPP5wqaCUKOzjfuLar LBYf+KVRK7sz66gZkTO0/mr+/iwveW/q7hNiDfIjK6w/dqtx1jmG5403uKK4wUT8OsmZ 1niw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=CRPt9IN85H648RSFMEnZhx++mZqyjCtw5Qf8WTOUQbw=; b=pc9pmOGJmvLP1XJtCwdTaNOafSWGGVS/I8QFVYC7GY5XYdY23whuO8QUrQaQGmnzmh p1eF64tJ3G6GS31ut/xeD7kfwuHWx1h8w2UpgVfhBJcL2fp2R5GATLwwaoX09YZJdv+5 cEzba8br8jUB0iPc6HXLVuPVjf65iOQkCxLsXfgLQBoPsdWIx6OsieVdXLb6bgkNjixB 9iUGWgNRdzPRUZQyKn0C3z6Zc4REDvCorbwpJDRSc0hcxx95Ur4k27vYMl+n+3rMEj+C qJbDJTTM+Hxon9h5TECsAWsWjmMQ6VJOOQkXI2YrTT87HXs3Jc69Mp/Go+ZFFyW2CX1d YywA== X-Gm-Message-State: ACrzQf27t4NyXEVkQoRn55gHlrq9fD48r2GM8Rwhs5LepxDAZQ9tAc7o GHzp/dVj7tdxsBsEeNFWONaqkiyy1+pbvg== X-Received: by 2002:aa7:9298:0:b0:56b:b6dc:988a with SMTP id j24-20020aa79298000000b0056bb6dc988amr5554574pfa.5.1666586872152; Sun, 23 Oct 2022 21:47:52 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id i72-20020a62874b000000b0056b932f3280sm3213979pfe.103.2022.10.23.21.47.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:47:51 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v4 6/7] eficonfig: add "Show/Delete Signature Database" menu entry Date: Mon, 24 Oct 2022 13:48:03 +0900 Message-Id: <20221024044804.3351-7-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221024044804.3351-1-masahisa.kojima@linaro.org> References: <20221024044804.3351-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.6 at phobos.denx.de X-Virus-Status: Clean This commit adds the menu-driven interface to show and delete the signature database. EFI Signature Lists can contain the multiple signature entries, this menu can delete the indivisual entry. If the PK is enrolled and UEFI Secure Boot is in User Mode or Deployed Mode, user can not delete the existing signature lists since the signature lists must be signed by KEK or PK but signing information is not stored in the signature database. To delete PK, user needs to enroll the new key with an empty value and this new key must be signed with the old PK. Signed-off-by: Masahisa Kojima --- No change since v2 Changes in v2: - integrate show and delete signature database menu - add confirmation message before delete - add function comment cmd/eficonfig_sbkey.c | 394 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 394 insertions(+) diff --git a/cmd/eficonfig_sbkey.c b/cmd/eficonfig_sbkey.c index 32a39eb7ba..44307ec12b 100644 --- a/cmd/eficonfig_sbkey.c +++ b/cmd/eficonfig_sbkey.c @@ -17,6 +17,14 @@ #include #include +struct eficonfig_sig_data { + struct efi_signature_list *esl; + struct efi_signature_data *esd; + struct list_head list; + struct eficonfig_sig_data **selected; + u16 *varname; +}; + enum efi_sbkey_signature_type { SIG_TYPE_X509 = 0, SIG_TYPE_HASH, @@ -46,6 +54,32 @@ static const struct eficonfig_sigtype_to_str sigtype_to_str[] = { /* {EFI_CERT_SHA512_GUID, "SHA512", SIG_TYPE_HASH}, */ }; +/** + * eficonfig_console_wait_enter() - wait ENTER key press + * + * Return: 1 if ENTER key is pressed, 0 if user selects to quit + */ +static int eficonfig_console_wait_enter(void) +{ + int esc = 0; + enum bootmenu_key key = KEY_NONE; + + puts(ANSI_CURSOR_HIDE); + + while (1) { + bootmenu_loop(NULL, &key, &esc); + + switch (key) { + case KEY_SELECT: + return 1; + case KEY_QUIT: + return 0; + default: + break; + } + } +} + /** * is_secureboot_enabled() - check UEFI Secure Boot is enabled * @@ -270,8 +304,368 @@ out: return ret; } +/** + * delete_selected_signature_data() - delete the signature data from signature list + * + * @db: pointer to the signature database + * @db_size: pointer to the signature database size + * @target: pointer to the signature data to be deleted + * Return: status code + */ +static void delete_selected_signature_data(void *db, efi_uintn_t *db_size, + struct eficonfig_sig_data *target) +{ + u32 remain; + u8 *dest, *start, *end; + efi_uintn_t total_size, esd_size, size; + struct efi_signature_list *esl; + struct efi_signature_data *esd; + + esl = db; + total_size = *db_size; + size = *db_size; + end = (u8 *)db + *db_size; + while (total_size > 0) { + esd = (struct efi_signature_data *)((u8 *)esl + + sizeof(struct efi_signature_list) + esl->signature_header_size); + esd_size = esl->signature_list_size - sizeof(struct efi_signature_list) - + esl->signature_header_size; + for (; esd_size > 0; esd_size -= esl->signature_size) { + if (esl == target->esl && esd == target->esd) { + remain = esl->signature_list_size - + (sizeof(struct efi_signature_list) - + esl->signature_header_size) - + esl->signature_size; + if (remain > 0) { + /* only delete the single signature data */ + esl->signature_list_size -= esl->signature_size; + size -= esl->signature_size; + dest = (u8 *)esd; + start = (u8 *)esd + esl->signature_size; + } else { + /* delete entire signature list */ + dest = (u8 *)esl; + start = (u8 *)esl + esl->signature_list_size; + size -= esl->signature_list_size; + } + memmove(dest, start, (end - start)); + goto out; + } + esd = (struct efi_signature_data *)((u8 *)esd + esl->signature_size); + } + total_size -= esl->signature_list_size; + esl = (struct efi_signature_list *)((u8 *)esl + esl->signature_list_size); + } +out: + *db_size = size; +} + +/** + * display_sigdata_info() - display signature data information + * + * @sg: pointer to the internal signature data structure + * Return: status code + */ +static void display_sigdata_info(struct eficonfig_sig_data *sg) +{ + u32 i; + + puts(ANSI_CURSOR_HIDE); + puts(ANSI_CLEAR_CONSOLE); + printf(ANSI_CURSOR_POSITION, 1, 1); + + *sg->selected = sg; + printf("\n ** Show/Delete Signature Database (%ls) **\n\n" + " Owner GUID:\n" + " %pUL\n", + sg->varname, sg->esd->signature_owner.b); + + for (i = 0; i < ARRAY_SIZE(sigtype_to_str); i++) { + if (!guidcmp(&sg->esl->signature_type, &sigtype_to_str[i].sig_type)) { + printf(" Signature Type:\n" + " %s\n", sigtype_to_str[i].str); + + switch (sigtype_to_str[i].type) { + case SIG_TYPE_X509: + { + struct x509_certificate *cert_tmp; + + cert_tmp = x509_cert_parse(sg->esd->signature_data, + sg->esl->signature_size); + printf(" Subject:\n" + " %s\n" + " Issuer:\n" + " %s\n", + cert_tmp->subject, cert_tmp->issuer); + break; + } + case SIG_TYPE_CRL: + { + u32 hash_size = sg->esl->signature_size - sizeof(efi_guid_t) - + sizeof(struct efi_time); + struct efi_time *time = + (struct efi_time *)((u8 *)sg->esd->signature_data + + hash_size); + + printf(" ToBeSignedHash:\n"); + print_hex_dump(" ", DUMP_PREFIX_NONE, 16, 1, + sg->esd->signature_data, hash_size, false); + printf(" TimeOfRevocation:\n" + " %d-%d-%d %02d:%02d:%02d\n", + time->year, time->month, time->day, + time->hour, time->minute, time->second); + break; + } + case SIG_TYPE_HASH: + { + u32 hash_size = sg->esl->signature_size - sizeof(efi_guid_t); + + printf(" Hash:\n"); + print_hex_dump(" ", DUMP_PREFIX_NONE, 16, 1, + sg->esd->signature_data, hash_size, false); + break; + } + default: + eficonfig_print_msg("ERROR! Unsupported format."); + break; + } + } + } +} + +/** + * eficonfig_process_sigdata_delete() - delete signature data + * + * @data: pointer to the data for each entry + * Return: status code + */ +static efi_status_t eficonfig_process_sigdata_delete(void *data) +{ + int delete; + efi_status_t ret; + efi_uintn_t size; + u8 setup_mode = 0; + u8 audit_mode = 0; + + struct eficonfig_sig_data *sg = data; + + display_sigdata_info(sg); + + if (!u16_strcmp(sg->varname, u"PK")) { + while (tstc()) + getchar(); + + printf("\n\n Can not delete PK, Press any key to continue"); + getchar(); + return EFI_NOT_READY; + } + + printf("\n\n Press ENTER to delete, ESC/CTRL+C to quit"); + delete = eficonfig_console_wait_enter(); + if (!delete) + return EFI_NOT_READY; + + size = sizeof(setup_mode); + ret = efi_get_variable_int(u"SetupMode", &efi_global_variable_guid, + NULL, &size, &setup_mode, NULL); + size = sizeof(audit_mode); + ret = efi_get_variable_int(u"AuditMode", &efi_global_variable_guid, + NULL, &size, &audit_mode, NULL); + + if (!setup_mode && !audit_mode) { + eficonfig_print_msg("Not in the SetupMode or AuditMode, can not delete."); + return EFI_NOT_READY; + } + + return EFI_SUCCESS; +} + +/** + * prepare_signature_db_list() - create the signature data menu entry + * + * @efimenu: pointer to the efimenu structure + * @varname: pointer to the variable name + * @db: pointer to the variable raw data + * @db_size: variable data size + * @func: callback of each entry + * @selected: pointer to selected signature data + * Return: status code + */ +static efi_status_t prepare_signature_db_list(struct efimenu *efi_menu, void *varname, + void *db, efi_uintn_t db_size, + eficonfig_entry_func func, + struct eficonfig_sig_data **selected) +{ + u32 num = 0; + efi_uintn_t size; + struct eficonfig_sig_data *sg; + struct efi_signature_list *esl; + struct efi_signature_data *esd; + efi_status_t ret = EFI_SUCCESS; + + INIT_LIST_HEAD(&efi_menu->list); + + esl = db; + size = db_size; + while (size > 0) { + u32 remain; + + esd = (struct efi_signature_data *)((u8 *)esl + + (sizeof(struct efi_signature_list) + + esl->signature_header_size)); + remain = esl->signature_list_size - sizeof(struct efi_signature_list) - + esl->signature_header_size; + for (; remain > 0; remain -= esl->signature_size) { + char buf[40]; + char *title; + + if (num >= EFICONFIG_ENTRY_NUM_MAX - 1) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + sg = calloc(1, sizeof(struct eficonfig_sig_data)); + if (!sg) { + ret = EFI_OUT_OF_RESOURCES; + goto err; + } + + snprintf(buf, sizeof(buf), "%pUL", &esd->signature_owner); + title = calloc(1, (strlen(buf) + 1)); + if (!title) { + free(sg); + ret = EFI_OUT_OF_RESOURCES; + goto err; + } + strlcpy(title, buf, strlen(buf) + 1); + + sg->esl = esl; + sg->esd = esd; + sg->selected = selected; + sg->varname = varname; + ret = eficonfig_append_menu_entry(efi_menu, title, func, sg); + if (ret != EFI_SUCCESS) { + free(sg); + free(title); + goto err; + } + esd = (struct efi_signature_data *)((u8 *)esd + esl->signature_size); + num++; + } + + size -= esl->signature_list_size; + esl = (struct efi_signature_list *)((u8 *)esl + esl->signature_list_size); + } +out: + ret = eficonfig_append_quit_entry(efi_menu); +err: + return ret; +} + +/** + * process_show_signature_db() - display the signature data list + * + * @data: pointer to the data for each entry + * Return: status code + */ +static efi_status_t process_show_signature_db(void *varname) +{ + char buf[50]; + efi_status_t ret; + efi_uintn_t db_size; + void *db, *new_db = NULL; + struct efimenu *efi_menu; + struct list_head *pos, *n; + struct eficonfig_entry *entry; + struct eficonfig_sig_data *selected; + + db = efi_get_var(varname, efi_auth_var_get_guid(varname), &db_size); + if (!db) { + eficonfig_print_msg("There is no entry in the signature database."); + return EFI_NOT_FOUND; + } + + efi_menu = calloc(1, sizeof(struct efimenu)); + if (!efi_menu) { + free(db); + return EFI_OUT_OF_RESOURCES; + } + + ret = prepare_signature_db_list(efi_menu, varname, db, db_size, + eficonfig_process_sigdata_delete, &selected); + if (ret != EFI_SUCCESS) + goto out; + + snprintf(buf, sizeof(buf), " ** Show/Delete Signature Database (%ls) **", + (u16 *)varname); + ret = eficonfig_process_common(efi_menu, buf); + if (ret == EFI_SUCCESS) { + u32 attr; + int delete; + + printf(ANSI_CURSOR_HIDE + "\n\n Are you sure you want to delete this item?\n\n" + " Press ENTER to delete, ESC/CTRL+C to quit"); + delete = eficonfig_console_wait_enter(); + if (!delete) + goto out; + + delete_selected_signature_data(db, &db_size, selected); + + ret = create_time_based_payload(db, &new_db, &db_size); + if (ret != EFI_SUCCESS) { + eficonfig_print_msg("ERROR! Failed to create payload with timestamp."); + goto out; + } + + attr = EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS; + ret = efi_set_variable_int((u16 *)varname, efi_auth_var_get_guid((u16 *)varname), + attr, db_size, new_db, false); + if (ret != EFI_SUCCESS) { + eficonfig_print_msg("ERROR! Failed to delete signature database"); + goto out; + } + } +out: + list_for_each_safe(pos, n, &efi_menu->list) { + entry = list_entry(pos, struct eficonfig_entry, list); + free(entry->data); + } + eficonfig_destroy(efi_menu); + free(new_db); + free(db); + + return ret; +} + +/** + * eficonfig_process_set_secure_boot_key() - display the key configuration menu + * + * @data: pointer to the data for each entry + * Return: status code + */ +static efi_status_t eficonfig_process_show_signature_db(void *data) +{ + efi_status_t ret; + + while (1) { + ret = process_show_signature_db(data); + if (ret != EFI_SUCCESS && ret != EFI_NOT_READY) + break; + } + + /* to stay the parent menu */ + ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret; + + return ret; +} + static struct eficonfig_item key_config_menu_items[] = { {"Enroll New Key", eficonfig_process_enroll_key}, + {"Show/Delete Signature Database", eficonfig_process_show_signature_db}, {"Quit", eficonfig_process_quit}, }; From patchwork Mon Oct 24 04:48:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 617838 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2483488pvb; Sun, 23 Oct 2022 21:49:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7gOwqBH65dTgVFXPsrDeLXQXFOIq/ST5pYcLe57n+OjtR3DUo8laG/Nx2A0GyqrfJ0CckT X-Received: by 2002:a17:907:72c7:b0:791:9ba2:4978 with SMTP id du7-20020a17090772c700b007919ba24978mr24893759ejc.217.1666586968531; Sun, 23 Oct 2022 21:49:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666586968; cv=none; d=google.com; s=arc-20160816; b=VU4LlEJ4ympcOzF0ILfjECHBTWHIw8+xOfr04v6nrf7g5e9W+QcnYG0ywFEFd1oMUK UioAq49bbnD3gizyilMcw5+WgOzKHwdT2UbSWsS3DZLHjccH6s/QdhnkQtM3JOJabQ0t vgWfQejKIdxLDEb0F3+3yxVfgC99I37Vhu97lDESXbMNIdxTudd/wHvpsP+tZvYae/cp Q+tMs2acvS6x3cPkptUCR8zWDR75r4VGCJNzOFu3G5nSNY1Kx8BCxyqwcC4fcTkruicq 8bDDaUy6cr1jVg5v+Iophw0aSSl3CWYFPLLQvP7H9RyEHdRdQazgP0tPrveG6qHFb14W mBQg== 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=a53pVwsVEfddCIlariPO7cWlCs1ay3bu01Fc9GMDt9g=; b=MZXhurVIHpE9HyX1tNESGZ6/w3kk2QgQuT0BkS0a/pm7ZxEgtuU6/FcWBM0QHyx6UD edJUba+BrLVpgSbcp/eNJ1/zssnFDkWVcawLw5qZuvCpui5NkM9r9yvaYZc8dv4vKlmo mnNbJ0d++DinXZqyC40Nq2acTiPJlVyAFPQbJ6DujeGFOvVhkejc5LOj4zBPM337O27H 9lxfIN1ij2aZBK18jBFm1i/FV+b61x6gLwqk1gQyXKRh2wI3QqnuiHMYN/8dZW40OMJt fmWMqmegEnePowT3d/fOIn4nKMA97x46fMYxVoeVAzCtAq6QaX0dFxGvvFLBGvwuqc5b RS+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aZSbvLD4; 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 jg16-20020a170907971000b0077d1db6241dsi26015138ejc.762.2022.10.23.21.49.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:49:28 -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=aZSbvLD4; 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 6B85084F58; Mon, 24 Oct 2022 06:48:17 +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="aZSbvLD4"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 44AD784225; Mon, 24 Oct 2022 06:48:07 +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-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (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 B92E484F4B for ; Mon, 24 Oct 2022 06:47:56 +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-pf1-x429.google.com with SMTP id d10so8070665pfh.6 for ; Sun, 23 Oct 2022 21:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=a53pVwsVEfddCIlariPO7cWlCs1ay3bu01Fc9GMDt9g=; b=aZSbvLD4Ese948fQBppFkJboO3AYysZKP2xS0lX6tea3/gKumnwfVyEOZ/Efjbi4Af chEcb6edockQ0ROTlxHM8mmZMksjvW3gXkMshZgjdDvXZU69+Zm7VKFK9jgr+EFYnF6D RJb/oioD4A5IlOThzdybgTIKGAUl4nBDHiZ5S2jVPBxqhbe64j0SbRf0Q376A0JHQ//R qNK5R5uanttEke0mNBODpjs2VnX7lqv5r5BvZcs8huwo6MT/wofMh37Fjs/iwKPY6tro Jq8SncEiGIWc5iL3bGydZepVGEklwqMXQ9trh/0CbZ6K0gSS9/2zOdSUcLBX+fGWLXi2 0lqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=a53pVwsVEfddCIlariPO7cWlCs1ay3bu01Fc9GMDt9g=; b=IoEgYOtXvZ6WyxNmLNFtUTxeAMvTa4mdHWCpjfl4M6Fz28MHF9fPM6wiDcoXZx8nQ4 rMAG9qL0NX9mZYveJautfrCKKH3OSiD4s4TM40JCyU93QwcLPgHCE9jsfraRelyuXXcN C0P0kCtmmt5vUFqAJs0LvQEcCbim9eMNvQhC15loRI4jPd5M02xNYhXaRhFRy9PKSsOl nZ+Jvgi5yxgDg4nOz7IJI5C/L6CuSD7J/yldB5r+3JOdjK4QYuM9i4T94F4FZv3DbtKh FjunuUiJ1MRA6RDXNTqgAjtwV4MBUSAyl4xzy2N6PWpf6S+5Aaqr18ieBNZW8pG6+NL2 Ah0w== X-Gm-Message-State: ACrzQf2YaPkJnyGH2CRZe7rftO35iqQHOqStizV6LtiQV6em29UwRrfr rNnSRv/V7Vr7uvsKsKU6iiuvI/OZyP/SNg== X-Received: by 2002:a05:6a00:22c3:b0:56b:f793:5ad1 with SMTP id f3-20020a056a0022c300b0056bf7935ad1mr368983pfj.58.1666586874392; Sun, 23 Oct 2022 21:47:54 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id i72-20020a62874b000000b0056b932f3280sm3213979pfe.103.2022.10.23.21.47.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 23 Oct 2022 21:47:53 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Masahisa Kojima Subject: [PATCH v4 7/7] test/py: eficonfig: use direct menu entry access mode Date: Mon, 24 Oct 2022 13:48:04 +0900 Message-Id: <20221024044804.3351-8-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221024044804.3351-1-masahisa.kojima@linaro.org> References: <20221024044804.3351-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.6 at phobos.denx.de X-Virus-Status: Clean To select the menu entry, use direct access mode instead of UP/DOWN key operation. Signed-off-by: Masahisa Kojima --- Newly added in v4 .../py/tests/test_eficonfig/test_eficonfig.py | 177 +++++++----------- 1 file changed, 70 insertions(+), 107 deletions(-) diff --git a/test/py/tests/test_eficonfig/test_eficonfig.py b/test/py/tests/test_eficonfig/test_eficonfig.py index 102bfd7541..dc08a35216 100644 --- a/test/py/tests/test_eficonfig/test_eficonfig.py +++ b/test/py/tests/test_eficonfig/test_eficonfig.py @@ -11,7 +11,7 @@ import time def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): def send_user_input_and_wait(user_str, expect_str): - time.sleep(0.1) # TODO: does not work correctly without sleep + time.sleep(0.3) # TODO: does not work correctly without sleep u_boot_console.run_command(cmd=user_str, wait_for_prompt=False, wait_for_echo=True, send_nl=False) u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False, @@ -20,20 +20,13 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): for i in expect_str: u_boot_console.p.expect([i]) - def press_up_down_enter_and_wait(up_count, down_count, enter, expect_str): - # press UP key - for i in range(up_count): - u_boot_console.run_command(cmd='\x1b\x5b\x41', wait_for_prompt=False, + def select_entry_and_wait(name, expect_str): + u_boot_console.run_command(cmd='&', wait_for_prompt=False, wait_for_echo=False, send_nl=False) - # press DOWN key - for i in range(down_count): - u_boot_console.run_command(cmd='\x1b\x5b\x42', wait_for_prompt=False, - wait_for_echo=False, send_nl=False) - # press ENTER if requested - if enter: - u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False, + u_boot_console.run_command(cmd=name, wait_for_prompt=False, + wait_for_echo=True, send_nl=False) + u_boot_console.run_command(cmd='\x0d', wait_for_prompt=False, wait_for_echo=False, send_nl=False) - # wait expected output if expect_str is not None: for i in expect_str: u_boot_console.p.expect([i]) @@ -76,11 +69,12 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): for i in ('UEFI Maintenance Menu', 'Add Boot Option', 'Edit Boot Option', 'Change Boot Order', 'Delete Boot Option', 'Quit'): u_boot_console.p.expect([i]) - # Select "Add Boot Option" - press_enter_key(False) + + select_entry_and_wait('Add Boot', None) for i in ('Add Boot Option', 'Description:', 'File', 'Initrd File', 'Optional Data', 'Save', 'Quit'): u_boot_console.p.expect([i]) + press_escape_key(False) check_current_is_maintenance_menu() # return to U-Boot console @@ -95,55 +89,43 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): u_boot_console.run_command('eficonfig', wait_for_prompt=False) - # Change the Boot Order - press_up_down_enter_and_wait(0, 2, True, 'Quit') - for i in ('host 0:1', 'Save', 'Quit'): - u_boot_console.p.expect([i]) + select_entry_and_wait('Change Boot', 'Quit') # disable auto generated boot option for succeeding test + select_entry_and_wait('host 0:1', None) u_boot_console.run_command(cmd=' ', wait_for_prompt=False, wait_for_echo=False, send_nl=False) - # Save the BootOrder - press_up_down_enter_and_wait(0, 1, True, None) + select_entry_and_wait('Save', None) check_current_is_maintenance_menu() # # Test Case 3: Add first Boot Option and load it # - # Select 'Add Boot Option' - press_up_down_enter_and_wait(0, 0, True, 'Quit') - - # Press the enter key to select 'Description:' entry, then enter Description - press_up_down_enter_and_wait(0, 0, True, 'enter description:') - # Send Description user input, press ENTER key to complete + # Set Description + select_entry_and_wait('Add Boot', 'Quit') + select_entry_and_wait('Description', 'enter description:') send_user_input_and_wait('test 1', 'Quit') # Set EFI image(initrddump.efi) - press_up_down_enter_and_wait(0, 1, True, 'Quit') - press_up_down_enter_and_wait(0, 0, True, 'host 0:1') - # Select 'host 0:1' - press_up_down_enter_and_wait(0, 0, True, 'Quit') - # Press down key to select "initrddump.efi" entry followed by the enter key - press_up_down_enter_and_wait(0, 2, True, 'Quit') + select_entry_and_wait('File:', 'Quit') + select_entry_and_wait('Select File', 'Quit') + select_entry_and_wait('host 0:1', 'Quit') + select_entry_and_wait('initrddump.efi', 'Quit') # Set Initrd file(initrd-1.img) - press_up_down_enter_and_wait(0, 2, True, 'Quit') - press_up_down_enter_and_wait(0, 0, True, 'host 0:1') - # Select 'host 0:1' - press_up_down_enter_and_wait(0, 0, True, 'Quit') - # Press down key to select "initrd-1.img" entry followed by the enter key - press_up_down_enter_and_wait(0, 0, True, 'Quit') + select_entry_and_wait('Initrd File:', 'Quit') + select_entry_and_wait('Select File', 'Quit') + select_entry_and_wait('host 0:1', 'Quit') + select_entry_and_wait('initrd-1.img', 'Quit') # Set optional_data - press_up_down_enter_and_wait(0, 3, True, 'Optional Data:') - # Send Description user input, press ENTER key to complete + select_entry_and_wait('Optional Data:', 'Optional Data:') send_user_input_and_wait('nocolor', None) for i in ('Description: test 1', 'File: host 0:1/initrddump.efi', 'Initrd File: host 0:1/initrd-1.img', 'Optional Data: nocolor', 'Save', 'Quit'): u_boot_console.p.expect([i]) - # Save the Boot Option - press_up_down_enter_and_wait(0, 4, True, None) + select_entry_and_wait('Save', None) check_current_is_maintenance_menu() # Check the newly added Boot Option is handled correctly @@ -159,51 +141,42 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): # u_boot_console.run_command('eficonfig', wait_for_prompt=False) - # Select 'Add Boot Option' - press_up_down_enter_and_wait(0, 0, True, 'Quit') - - # Press the enter key to select 'Description:' entry, then enter Description - press_up_down_enter_and_wait(0, 0, True, 'enter description:') - # Send Description user input, press ENTER key to complete + # Set Description + select_entry_and_wait('Add Boot', 'Quit') + select_entry_and_wait('Description', 'enter description:') send_user_input_and_wait('test 2', 'Quit') # Set EFI image(initrddump.efi) - press_up_down_enter_and_wait(0, 1, True, 'Quit') - press_up_down_enter_and_wait(0, 0, True, 'host 0:1') - # Select 'host 0:1' - press_up_down_enter_and_wait(0, 0, True, 'Quit') - # Press down key to select "initrddump.efi" entry followed by the enter key - press_up_down_enter_and_wait(0, 2, True, 'Quit') + select_entry_and_wait('File:', 'Quit') + select_entry_and_wait('Select File', 'Quit') + select_entry_and_wait('host 0:1', 'Quit') + select_entry_and_wait('initrddump.efi', 'Quit') # Set Initrd file(initrd-2.img) - press_up_down_enter_and_wait(0, 2, True, 'Quit') - press_up_down_enter_and_wait(0, 0, True, 'host 0:1') - # Select 'host 0:1' - press_up_down_enter_and_wait(0, 0, True, 'Quit') - # Press down key to select "initrd-2.img" entry followed by the enter key - press_up_down_enter_and_wait(0, 1, True, 'Quit') + select_entry_and_wait('Initrd File:', 'Quit') + select_entry_and_wait('Select File', 'Quit') + select_entry_and_wait('host 0:1', 'Quit') + select_entry_and_wait('initrd-2.img', 'Quit') # Set optional_data - press_up_down_enter_and_wait(0, 3, True, 'Optional Data:') - # Send Description user input, press ENTER key to complete + select_entry_and_wait('Optional Data:', 'Optional Data:') send_user_input_and_wait('nocolor', None) for i in ('Description: test 2', 'File: host 0:1/initrddump.efi', 'Initrd File: host 0:1/initrd-2.img', 'Optional Data: nocolor', 'Save', 'Quit'): u_boot_console.p.expect([i]) - # Save the Boot Option - press_up_down_enter_and_wait(0, 4, True, 'Quit') + select_entry_and_wait('Save', None) + check_current_is_maintenance_menu() - # Change the Boot Order - press_up_down_enter_and_wait(0, 2, True, 'Quit') - press_up_down_enter_and_wait(0, 1, False, 'Quit') - # move 'test 1' to the second entry + select_entry_and_wait('Change Boot', 'Quit') + # move 'test 2' to the first entry + select_entry_and_wait('test 2', 'Quit') u_boot_console.run_command(cmd='+', wait_for_prompt=False, wait_for_echo=False, send_nl=False) for i in ('test 2', 'test 1', 'host 0:1', 'Save', 'Quit'): u_boot_console.p.expect([i]) - # Save the BootOrder - press_up_down_enter_and_wait(0, 3, True, None) + + select_entry_and_wait('Save', None) check_current_is_maintenance_menu() # Check the newly added Boot Option is handled correctly @@ -219,18 +192,18 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): # u_boot_console.run_command('eficonfig', wait_for_prompt=False) - # Change the Boot Order - press_up_down_enter_and_wait(0, 2, True, None) + select_entry_and_wait('Change Boot', 'Quit') # Check the curren BootOrder for i in ('test 2', 'test 1', 'host 0:1', 'Save', 'Quit'): u_boot_console.p.expect([i]) # move 'test 2' to the second entry + select_entry_and_wait('test 2', 'Quit') u_boot_console.run_command(cmd='-', wait_for_prompt=False, wait_for_echo=False, send_nl=False) for i in ('test 1', 'test 2', 'host 0:1', 'Save', 'Quit'): u_boot_console.p.expect([i]) - # Save the BootOrder - press_up_down_enter_and_wait(0, 2, True, None) + + select_entry_and_wait('Save', 'Quit') check_current_is_maintenance_menu() # Return to U-Boot console @@ -245,14 +218,13 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): # u_boot_console.run_command('eficonfig', wait_for_prompt=False) - # Select 'Delete Boot Option' - press_up_down_enter_and_wait(0, 3, True, None) + select_entry_and_wait('Delete Boot', 'Quit') # Check the current BootOrder for i in ('test 1', 'test 2', 'Quit'): u_boot_console.p.expect([i]) # Delete 'test 2' - press_up_down_enter_and_wait(0, 1, True, None) + select_entry_and_wait('test 2', 'Quit') for i in ('test 1', 'Quit'): u_boot_console.p.expect([i]) press_escape_key(False) @@ -264,47 +236,40 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): # Test Case 7: Edit Boot Option # u_boot_console.run_command('eficonfig', wait_for_prompt=False) - # Select 'Edit Boot Option' - press_up_down_enter_and_wait(0, 1, True, None) + + select_entry_and_wait('Edit Boot', 'Quit') # Check the curren BootOrder for i in ('test 1', 'Quit'): u_boot_console.p.expect([i]) - press_up_down_enter_and_wait(0, 0, True, None) + select_entry_and_wait('test 1', 'Quit') for i in ('Description: test 1', 'File: host 0:1/initrddump.efi', 'Initrd File: host 0:1/initrd-1.img', 'Optional Data: nocolor', 'Save', 'Quit'): u_boot_console.p.expect([i]) - # Press the enter key to select 'Description:' entry, then enter Description - press_up_down_enter_and_wait(0, 0, True, 'enter description:') - # Send Description user input, press ENTER key to complete + # Set Description + select_entry_and_wait('Description', 'enter description:') send_user_input_and_wait('test 3', 'Quit') # Set EFI image(initrddump.efi) - press_up_down_enter_and_wait(0, 1, True, 'Quit') - press_up_down_enter_and_wait(0, 0, True, 'host 0:1') - # Select 'host 0:1' - press_up_down_enter_and_wait(0, 0, True, 'Quit') - # Press down key to select "initrddump.efi" entry followed by the enter key - press_up_down_enter_and_wait(0, 2, True, 'Quit') + select_entry_and_wait('File:', 'Quit') + select_entry_and_wait('Select File', 'Quit') + select_entry_and_wait('host 0:1', 'Quit') + select_entry_and_wait('initrddump.efi', 'Quit') # Set Initrd file(initrd-2.img) - press_up_down_enter_and_wait(0, 2, True, 'Quit') - press_up_down_enter_and_wait(0, 0, True, 'host 0:1') - # Select 'host 0:1' - press_up_down_enter_and_wait(0, 0, True, 'Quit') - # Press down key to select "initrd-1.img" entry followed by the enter key - press_up_down_enter_and_wait(0, 1, True, 'Quit') + select_entry_and_wait('Initrd File:', 'Quit') + select_entry_and_wait('Select File', 'Quit') + select_entry_and_wait('host 0:1', 'Quit') + select_entry_and_wait('initrd-2.img', 'Quit') # Set optional_data - press_up_down_enter_and_wait(0, 3, True, 'Optional Data:') - # Send Description user input, press ENTER key to complete + select_entry_and_wait('Optional Data:', 'Optional Data:') send_user_input_and_wait('', None) for i in ('Description: test 3', 'File: host 0:1/initrddump.efi', 'Initrd File: host 0:1/initrd-2.img', 'Optional Data:', 'Save', 'Quit'): u_boot_console.p.expect([i]) - # Save the Boot Option - press_up_down_enter_and_wait(0, 4, True, 'Quit') + select_entry_and_wait('Save', None) press_escape_key(False) check_current_is_maintenance_menu() @@ -321,14 +286,13 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): # u_boot_console.run_command('eficonfig', wait_for_prompt=False) - # Select 'Delete Boot Option' - press_up_down_enter_and_wait(0, 3, True, None) + select_entry_and_wait('Delete Boot', 'Quit') # Check the curren BootOrder for i in ('test 3', 'Quit'): u_boot_console.p.expect([i]) # Delete 'test 3' - press_up_down_enter_and_wait(0, 0, True, 'Quit') + select_entry_and_wait('test 3', 'Quit') press_escape_key(False) check_current_is_maintenance_menu() # Return to U-Boot console @@ -342,12 +306,11 @@ def test_efi_eficonfig(u_boot_console, efi_eficonfig_data): # u_boot_console.run_command('eficonfig', wait_for_prompt=False) - # Select 'Add Boot Option' - press_up_down_enter_and_wait(0, 0, True, 'Quit') + select_entry_and_wait('Add Boot', 'Quit') # Set EFI image - press_up_down_enter_and_wait(0, 1, True, 'Quit') - press_up_down_enter_and_wait(0, 0, True, 'No block device found!') + select_entry_and_wait('File:', 'Quit') + select_entry_and_wait('Select File', 'No block device found!') press_escape_key(False) press_escape_key(False) check_current_is_maintenance_menu()