From patchwork Wed Nov 9 03:37:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 622918 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp19282pvb; Tue, 8 Nov 2022 19:36:21 -0800 (PST) X-Google-Smtp-Source: AMsMyM5LOcEBW05JGb33czLM8V1yqc7bzP5D5KBnMuQ87k6CbpGK7CcC2WcKcBF35P1a5oQSn9g7 X-Received: by 2002:a05:6402:13d6:b0:461:b1b9:bed0 with SMTP id a22-20020a05640213d600b00461b1b9bed0mr1079812edx.122.1667964981631; Tue, 08 Nov 2022 19:36:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667964981; cv=none; d=google.com; s=arc-20160816; b=R2SxaTYhW5bIBfMf3Fte66TgPdS7jMgp7Gb696Ak0okDgSh5AEZrFK/TWUHCMNdyhH fIdCzm8yz/RCTHe8vAhzPQRvqV64lWSOX9uNQEznaTGARKRL1koQwRyPuAJh57cz3FBN 5HttvYpYKilblyXfdM753MSWHcyCJgRILRJLjjt6v+/dc8Ie36sozhilUAYs5Kl77Iw1 mwDjK+r28c+hjAC/NuWaSYmM3XkFMoUsRWyGX9ZVMVW8CYTPigrWXBORyC5uLqGp7UM2 HP76kYvZPVbsvxOr8M4j8ZQWNlzdS5WHCxEmBVifKrT6owhCNYzHuu9nkjocDQWzxW6g CSgA== 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=pE903HxakBHXj9pxiGvbOZxjnU/ZFKD7OO3eVtHpiy0=; b=BBpX8wn6s6rLluaI5MNztmEYdkRv1ol+dHlq3LtxZ7REn5pltYj9Y4aYJbuNn9nfd2 83EEeL7690YGaY0brZ7X8+LzpMgGAn+HKnwiS4kJjkCP77wjIJQd2ijnV/kFtkXtvQQ5 NciYBDwaMHfm/DwzgZrN3m5lOXE4HGkrZe50oCTRc34PNwGQ/ZevL8QwkY+HmguAnpOX ihy/Rvb+rDEjGuOqHUkWXxl6E8R9B8ed8dZETDdSBKJyiFLHq8/fgZ9rpDCIsWjh/E3i Cialqb4xjTm0+aCIjUSj2Xk+154wOcESqObz5xqFF62kw9+p+a2uu4JvsJsFQ9g/CFFQ j1Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ls/dwJrZ"; 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 hd13-20020a170907968d00b007ae61d89b3esi13918265ejc.356.2022.11.08.19.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 19:36:21 -0800 (PST) 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="ls/dwJrZ"; 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 620F885045; Wed, 9 Nov 2022 04:36:18 +0100 (CET) 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="ls/dwJrZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 07F5B84FF9; Wed, 9 Nov 2022 04:35:57 +0100 (CET) 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-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) (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 C9CA384EF6 for ; Wed, 9 Nov 2022 04:35:52 +0100 (CET) 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-x62a.google.com with SMTP id c2so15909877plz.11 for ; Tue, 08 Nov 2022 19:35:52 -0800 (PST) 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=pE903HxakBHXj9pxiGvbOZxjnU/ZFKD7OO3eVtHpiy0=; b=ls/dwJrZCaKIPaICEp9Y3YqCmz+0ILuGm2uXiwmUaFVKD1Cgi6+r4G+EFFgODAIasP 7FZrKZgZK6Uvylj9dFDvojBfQ+OpIEbU5reBTbjEuJZ2Jwv6dbtgOck6R4u/B3Mkr464 cECcTIP0a71QqQpIUr6kDIk6v9ezrySSpPHbV+y+AG3NqMXjGcQKSfiSoqOUwIeD7shL WknPFUnP3cqQs3/NNJSnVvULMHzPJeDnZgDagM0d/yIYzZ+qp6jgrfk9FDyoqKK9YzCX 6AUoNBL4u3PFx/nFk3byBiiIfpiXc/TBk7KfwAW5b6c222xPWyYoq3emPPoZsjgir9Eb GaIg== 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=pE903HxakBHXj9pxiGvbOZxjnU/ZFKD7OO3eVtHpiy0=; b=yhfyLKzlu3TFFnAoDiGU0dU3L52TOPv4sQjUFA/if5kaWQ07dR+0/cq/3J4wsNlb5J LWd7cnGqeJQhRdtSTJu4B0QZLHhhgJM/pBDaUBez3U72+U8c5KZzWMPYA/jAA+ChQKZ+ uKHUzsCsVfP8mrEa/Wd6cVafIlSe9DzuU4+y8rFVUF583y9XRndTCAA2oUN7fNJnLkHJ u5AMdC9Jkuid3VTvTP+g5z45JZC/ZbkaHcs9S/9gnTXE3oAxL3ZSBP5DYETuvz6lWEKx vcZ+8MY9tFIvNO0VHiTWw6btinOqKJpzyZ+r8cPkhHqwsOtgFLwyrbw2Y/G/S8qpwmbZ y7vQ== X-Gm-Message-State: ACrzQf2faJgEQdvaeZnwBd4/yz0Tm0HJs9jDSG6nv+vBz7xpvD37pGJ5 Kh7nuiwrs+BfUM7xHDJPvv0Nnw== X-Received: by 2002:a17:902:e548:b0:186:f0d5:1ac2 with SMTP id n8-20020a170902e54800b00186f0d51ac2mr42400026plf.144.1667964951096; Tue, 08 Nov 2022 19:35:51 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id e17-20020a17090301d100b00177f25f8ab3sm7838370plh.89.2022.11.08.19.35.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 19:35:50 -0800 (PST) From: Masahisa Kojima To: kojima.masahisa@socionext.com, u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Etienne Carriere , Masahisa Kojima Subject: [PATCH v7 1/5] eficonfig: refactor file selection handling Date: Wed, 9 Nov 2022 12:37:24 +0900 Message-Id: <20221109033728.5623-2-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221109033728.5623-1-masahisa.kojima@linaro.org> References: <20221109033728.5623-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() adds an additional menu to clear the selected file. eficonfig_display_select_file_option() is not always necessary for the file selection process, so it must be outside of eficonfig_select_file_handler(). This commit also renames the following functions to avoid confusion. eficonfig_select_file_handler() -> eficonfig_process_select_file() eficonfig_select_file() -> eficonfig_show_file_selection() eficonfig_display_select_file_option() -> eficonfig_process_show_file_option() Finally, test_eficonfig.py need to be updated to get aligned with the above modification. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- Changes in v7: - rename functio name to avoid confusion - remove unused function - update commit message newly created in v2 cmd/eficonfig.c | 37 ++++++------------- include/efi_config.h | 2 +- .../py/tests/test_eficonfig/test_eficonfig.py | 1 + 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 2595dd9563..571e2b9ac0 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -756,14 +756,14 @@ out: } /** - * eficonfig_select_file() - construct the file selection menu + * eficonfig_show_file_selection() - construct the file selection menu * * @file_info: pointer to the file selection structure * @root: pointer to the file handle * Return: status code */ -static efi_status_t eficonfig_select_file(struct eficonfig_select_file_info *file_info, - struct efi_file_handle *root) +static efi_status_t eficonfig_show_file_selection(struct eficonfig_select_file_info *file_info, + struct efi_file_handle *root) { u32 count = 0, i; efi_uintn_t len; @@ -938,17 +938,6 @@ static efi_status_t eficonfig_boot_edit_save(void *data) return EFI_SUCCESS; } -/** - * eficonfig_process_select_file() - callback function for "Select File" entry - * - * @data: pointer to the data - * Return: status code - */ -efi_status_t eficonfig_process_select_file(void *data) -{ - return EFI_SUCCESS; -} - /** * eficonfig_process_clear_file_selection() - callback function for "Clear" entry * @@ -973,19 +962,19 @@ static struct eficonfig_item select_file_menu_items[] = { {"Quit", eficonfig_process_quit}, }; - /** - * eficonfig_display_select_file_option() - display select file option + * eficonfig_process_show_file_option() - display select file option * * @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_process_show_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) @@ -1001,12 +990,12 @@ efi_status_t eficonfig_display_select_file_option(struct eficonfig_select_file_i } /** - * eficonfig_select_file_handler() - handle user file selection + * eficonfig_process_select_file() - handle user file selection * * @data: pointer to the data * Return: status code */ -efi_status_t eficonfig_select_file_handler(void *data) +efi_status_t eficonfig_process_select_file(void *data) { size_t len; efi_status_t ret; @@ -1016,10 +1005,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; @@ -1046,7 +1031,7 @@ efi_status_t eficonfig_select_file_handler(void *data) if (ret != EFI_SUCCESS) goto out; - ret = eficonfig_select_file(tmp, root); + ret = eficonfig_show_file_selection(tmp, root); if (ret == EFI_ABORTED) continue; if (ret != EFI_SUCCESS) @@ -1284,7 +1269,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_process_show_file_option, file_info); out: free(devname); free(file_name); diff --git a/include/efi_config.h b/include/efi_config.h index 098cac2115..cc6aa51393 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -89,7 +89,7 @@ void eficonfig_print_msg(char *msg); void eficonfig_destroy(struct efimenu *efi_menu); efi_status_t eficonfig_process_quit(void *data); efi_status_t eficonfig_process_common(struct efimenu *efi_menu, char *menu_header); -efi_status_t eficonfig_select_file_handler(void *data); +efi_status_t eficonfig_process_select_file(void *data); efi_status_t eficonfig_get_unused_bootoption(u16 *buf, efi_uintn_t buf_size, u32 *index); efi_status_t eficonfig_append_bootorder(u16 index); 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 Wed Nov 9 03:37:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 622919 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp19325pvb; Tue, 8 Nov 2022 19:36:32 -0800 (PST) X-Google-Smtp-Source: AMsMyM5TFXaaFcTVX//0+7fapg+xw7PR8kQIx6MePEZVThifm8DzFE4a3i7Zd7QDmFEmCCtt9b6N X-Received: by 2002:a17:907:7608:b0:7ae:fdd:d0b6 with SMTP id jx8-20020a170907760800b007ae0fddd0b6mr30818293ejc.215.1667964991852; Tue, 08 Nov 2022 19:36:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667964991; cv=none; d=google.com; s=arc-20160816; b=n5nhMZXBkydp/wFx2WPIKEsQ87WY1HJE54kRwiUjVQWWMieU1YpbZreffE4XlQCw/U aJ3rRn6YMcemLXqk8XHBH+SjgNPg/O7+WLswRhz14mW96rTZtPhr/iwNA0jIM7uoyQ37 k6VVtOIhk4FA1g1OeooB3+zdSF2ejO42mH87rAGmL/p1cJll5u3ZjNKzjLwLJlgC9l0E Of8/0+s+r/dikD0byIZSVq7ecaaQQN96JHobiVMP1DnHoj07KFff4PqKMMWUipqea8jH /VtVAz+q/z0r7SqOrdY3r8oYh+dbMZ79UdiZDzTwa6B4IRilnWK45+UnmTW54xyHr5Y0 LzdA== 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=lcDWYqaxAunQ8gnmVLYDOECsUAhMh3Mg2BwuApAvT4Y=; b=M1A6v5HeXVCt2x9XAxL+j1VUkfG+nejBS/bzcnD5uMDNZIuyGW8lgVIIkSCbgxPH0V 6OrJHpHBcOq0YGZE6Ct814JIK1M7zODcCzENp098Tl6FWTFL4fYvlMI69Ryjn3T8B6yv l6rnNpWcDQUvFMB/NUHL37TlBGCThla9PxsiuqMYJPoWmdNGF4cS6tWZ85NZRUfQXQbS +AODSuhvz6Dlb105EPn2SsRcb6rm89I/9AmB8RXGpV7TYalBkhJXkEx2NJXMfQ5gmQjb lVUS4s+kUZfUaUO0Sh8/8fccTTNXeXZ6tEN9IGtqfe22UXwqHYR3JTR8cnPzWttIyF0Z Eoxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qE3vUtuE; 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 hc31-20020a170907169f00b007316843d58bsi16621258ejc.925.2022.11.08.19.36.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 19:36:31 -0800 (PST) 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=qE3vUtuE; 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 4931E85020; Wed, 9 Nov 2022 04:36:23 +0100 (CET) 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="qE3vUtuE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4F7C284FF4; Wed, 9 Nov 2022 04:36:11 +0100 (CET) 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-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (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 281B584FF4 for ; Wed, 9 Nov 2022 04:35:56 +0100 (CET) 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-x42e.google.com with SMTP id v28so15528221pfi.12 for ; Tue, 08 Nov 2022 19:35:56 -0800 (PST) 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=lcDWYqaxAunQ8gnmVLYDOECsUAhMh3Mg2BwuApAvT4Y=; b=qE3vUtuEQbNZmcGEWDMli17Hd6IZg0p9+5Ujb+bnvljFeHzgkuLpeKMGFYpBspVGx9 7ygS/KxPGtEXpYHaVrlzzRqGLcH3NhoBY2iy9AtlqTnR6svJWHhqwVowh37nx3ysPhDj iFFhWd9V7z99V/8tVlhjoMJtAEDUz9D3TrjsDWr9ccbB+hOPKJyNno8z+bUwINuj0XcW 6h+edHnwoKvILNkpiiIfGmzavVAbUJtIH7dgcK0OkN/z8l6g3vSgUpFbVzQuXxz9OgkM BOaBnUcDQZ/5fu6TaRuH5g3NVOg5mVOCBtWj4LMbWjmPQGc2GKzZ/izMdSjrZG3OU6ZS H+Sw== 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=lcDWYqaxAunQ8gnmVLYDOECsUAhMh3Mg2BwuApAvT4Y=; b=IVCVwR5aVkPcifBGPPU9vyBj1B5QV4FWXPEnYHN50zdFrHT1A+9Cz6p9fq5n/Vknh/ zgc+EcEN9v+rWy1DpL16PwkiJdqPBYh3DRDzpCBuHY1olZyUjOubPHaU+Z+lvMaPd8qz gSt642w6pdHCn5vtbH6tBACv46ch2ZKOJd/aWMch+0MJZvO8TleV+wwW5BtURjSH0+4c ta2qQ5qCUjGUMWgnAxbIDj41yuuep/RncaHVCygk70JaWFu/oJTPk/Lz7lfI/89hzRBK 9UR7mQcpgXEJFYXiQQmlmWIwcV7UnLin95UNiQaCs4WBUsae6BbrR60sQls4sOWRZvGJ 5fJw== X-Gm-Message-State: ANoB5pkVa+nz9soqh+B4t7LzSr707hspu4nYYEdfe9I8d1BQviV88vf2 OX+4NF1jyr3YH+yRFo1/vyqXYw== X-Received: by 2002:a05:6a00:acd:b0:56e:d365:df9d with SMTP id c13-20020a056a000acd00b0056ed365df9dmr19758748pfl.18.1667964954430; Tue, 08 Nov 2022 19:35:54 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id e17-20020a17090301d100b00177f25f8ab3sm7838370plh.89.2022.11.08.19.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 19:35:53 -0800 (PST) From: Masahisa Kojima To: kojima.masahisa@socionext.com, u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Etienne Carriere , Masahisa Kojima Subject: [PATCH v7 2/5] eficonfig: expose append entry function Date: Wed, 9 Nov 2022 12:37:25 +0900 Message-Id: <20221109033728.5623-3-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221109033728.5623-1-masahisa.kojima@linaro.org> References: <20221109033728.5623-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 Following commits are adding support for UEFI variable management via the eficonfig menu. Those functions needs to use append_entry() and append_quit_entry() to construct the menu, so move them out of their static declarations. Signed-off-by: Masahisa Kojima Reviewed-by: Ilias Apalodimas --- Changes in v7: - update commit message 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 571e2b9ac0..b392de7954 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_show_file_selection(struct eficonfig_select_file_i 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; @@ -1206,7 +1208,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); } /** @@ -1665,7 +1667,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); @@ -1724,7 +1726,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 cc6aa51393..064f2efe3f 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 Wed Nov 9 03:37:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 622920 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp19400pvb; Tue, 8 Nov 2022 19:36:52 -0800 (PST) X-Google-Smtp-Source: AMsMyM5yMpHhopHfIPdPFAphm27j4kYthhMsuIw0RNyuu9qWeD4P5jdyoqkyCSMVD3zHp3czX2fo X-Received: by 2002:a17:906:eb09:b0:7ad:d271:e5aa with SMTP id mb9-20020a170906eb0900b007add271e5aamr48546310ejb.182.1667965012173; Tue, 08 Nov 2022 19:36:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667965012; cv=none; d=google.com; s=arc-20160816; b=ULMDAYAlSN1Ce2hXcTt4R4RBtk+3luan4bHzfV3JkQ164TX1g1QQjki05q+77lIaUM YpIKlL5gzOnlQaTmjwGcrx11UYzCI80LlhCdNlBBCs9GLzJOK7Ih7sXhGpgy46ws53QM TH2TIEDOrx00vCAE9/sJHc6MFY/tyfSEOjdcE9jt8Yg1uZeHS1dKNJpfUy40gmorGgR0 Wm6vvNBLc4hmdm5xrRf0Lw6+Dvxv8no/HPwdI7Wm08YGv4L66aH7YDGz7EsJC9HzOnGf aiDBFU9u87FErdfGJgebdF+QhJucovD3qxb08nMBqGgvEqSaielDGhnOdz6wuAJSVa5b E2gA== 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=YwAb8AaFbBhqOO3XSiJyVxtV3Nq/z0yyybFmFoj8ajk=; b=ESehslooEbxce1N52pgsD+d+iZUVU0OLS5KYHIpoZcFhqXJcP4k0hDd56hWv8zkAS8 lkzL20RX/pryIU2y8N9xPb6y+dwdFm5OlGEFV6gwbpI6pcSW2It9kQNMZgDN0PaA+l2o 5NWfpDPeQonU40SR+ZJMJMxUH3tpjzXcRWMyXW+VP3RwLURvuHYnw5C7PcCS/+ArxnwE GKfpaSQZZqWSuR0z5sgdngS/XLcYx/DFsEzAdSsNRBwlswJYcdHxT8yql/404rJbAzrV WEzt43kxJSVKN7MJux80BxmTs7HXruRAWPLiQwKRYPQxfNZFGxgPCJj/NG9KU5GiJCuY FepQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rtXmJFdp; 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 qk36-20020a1709077fa400b007adca6532e3si14446820ejc.229.2022.11.08.19.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 19:36:52 -0800 (PST) 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=rtXmJFdp; 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 EE9DB8504A; Wed, 9 Nov 2022 04:36:37 +0100 (CET) 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="rtXmJFdp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 25CBA84ED3; Wed, 9 Nov 2022 04:36:21 +0100 (CET) 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-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) (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 2710185001 for ; Wed, 9 Nov 2022 04:36:00 +0100 (CET) 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-x62f.google.com with SMTP id d20so14863793plr.10 for ; Tue, 08 Nov 2022 19:35:59 -0800 (PST) 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=YwAb8AaFbBhqOO3XSiJyVxtV3Nq/z0yyybFmFoj8ajk=; b=rtXmJFdpC8w084Oyn22CuVE6UTWPzOaSMh7BO4ztVO5dinkdVC7OF6COL9hxscCwsv sl+EhokPphNpaRJAu1vy/uRwPsmwnCWjnbCsQ9Ful8McjtkqbLAPO+ibLlP5J8OIEmxS ZN0mzgOzOLx11a7yeBzKjTRZ/A22SMGJWKqOkzbAflK4UWMrYRin2LehEE0nTC6og+aL ABe2U2Yr56+R+LKseS4aIGscV1fsyGESNZwqzMPYUHIZ5d+TG/tKZCIGCb9YOVeaiLd3 rT0Za+JW9iruAH1UkcxCnuxMpqJEet0zN/9NiqjktlZG1cyjSg0U+Gy+vwauOG+SeWK3 W6ZQ== 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=YwAb8AaFbBhqOO3XSiJyVxtV3Nq/z0yyybFmFoj8ajk=; b=rM8GutOGIWNWfz5hOsd2ZgHRCjxlj3s5zxMbJyX1jAb2EG1Cz2/CNyh+ob5b2XBKJ1 Nb/Pm+SfDh38jD66mXrT6zo8Z8QfJFqJ/OykloxSON1z8/DuHdbvzxF9qeC5K57bv/v0 mx7iW3Mnv/4p1Tx22BY+43VR5sdd+QacCO/niNfK+I3ZmQnE/XeFZSdKXoUjD5yJCS52 skI0RxTrLY23O1IawKLLZE3VaO584lOhOlMzVBuzjROnrZ8/mv5SL49lFl6A1k2sNtD+ 5QFOqoEjDgwQ6Z8HYcKHGJCm5wXjTVTx1EIbxsIiBtb63BdROKQHtKPxr1/Hpe5jSXuz gfgw== X-Gm-Message-State: ACrzQf314ULbMsIGjNxjTurhplbk4dlQ03NkAWtXm14qZoCaWeT7SJEN Z4XMAVu392zNFdxGKNDVSCrNFg== X-Received: by 2002:a17:902:7283:b0:188:612b:1d31 with SMTP id d3-20020a170902728300b00188612b1d31mr28599540pll.81.1667964957785; Tue, 08 Nov 2022 19:35:57 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id e17-20020a17090301d100b00177f25f8ab3sm7838370plh.89.2022.11.08.19.35.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 19:35:57 -0800 (PST) From: Masahisa Kojima To: kojima.masahisa@socionext.com, u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Etienne Carriere , Masahisa Kojima Subject: [PATCH v7 3/5] eficonfig: refactor change boot order implementation Date: Wed, 9 Nov 2022 12:37:26 +0900 Message-Id: <20221109033728.5623-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221109033728.5623-1-masahisa.kojima@linaro.org> References: <20221109033728.5623-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 All the eficonfig menus other than "Change Boot Order" use 'eficonfig_entry' structure for each menu entry. This commit refactors change boot order implementation to use 'eficonfig_entry' structure same as other menus to have consistent menu handling. This commit also simplifies the data->active handling when KEY_SPACE is pressed, and sizeof() parameter. Signed-off-by: Masahisa Kojima Acked-by: Ilias Apalodimas --- Changes in v7: - simplify the data->active handling - update sizeof() parameter - update commit message Changes in v5: - remove direct access mode newly created in v4 cmd/eficonfig.c | 129 +++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 62 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index b392de7954..12babb76c2 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -93,20 +93,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; }; /** @@ -1802,7 +1796,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" @@ -1818,7 +1812,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); @@ -1827,13 +1821,13 @@ 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); + printf("%s", entry->title); if (reverse) puts(ANSI_COLOR_RESET); @@ -1850,9 +1844,8 @@ 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; while (1) { bootmenu_loop(NULL, &key, &esc); @@ -1861,11 +1854,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); @@ -1879,11 +1872,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); @@ -1909,9 +1902,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; return EFI_NOT_READY; } } @@ -1937,12 +1932,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); @@ -1950,31 +1946,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(*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; } /** @@ -1989,8 +1992,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++) { @@ -2017,27 +2020,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; } /** @@ -2053,7 +2054,7 @@ 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)); @@ -2084,9 +2085,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); @@ -2105,15 +2113,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 Wed Nov 9 03:37:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 622921 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp19505pvb; Tue, 8 Nov 2022 19:37:11 -0800 (PST) X-Google-Smtp-Source: AMsMyM6yptCXiLNtL4YmWIc1kHgLXBw5Q/rmSq7RfwyCTQmve0ABQk1WlF+WtdDE7tFBz60xAS3C X-Received: by 2002:a05:6402:5244:b0:461:d97e:5271 with SMTP id t4-20020a056402524400b00461d97e5271mr59995468edd.227.1667965031130; Tue, 08 Nov 2022 19:37:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667965031; cv=none; d=google.com; s=arc-20160816; b=aOOBeVr/xs4fzF8DF88vvMxMt4crMcZld1i7DiBM0tUdrnXQ5Z58M/5ezVmU1xGfeY C/rKpTEKf3PblrLsayavv0NKFzByHrslLEyfGMrSuUtzq8jgQwOEAu1OkFkst4XUgRed 3YP9LZGw8/i9b0bNO7rlbNONke9Z6aJe6LKwF2sfW8LA9Qo3R4jlSpTHAY/NBiRXzKjK eX8uS8pZjHfw1oN8SuKCVM4Z1Zne/cQfxxsauNVG0Nx76UjFQiwYSzafstMH1c4snKFA tbOZjFO5o0kHPKBEqq/tBcQkjKASOtxb98UvHcToD1tWIJTcmUf0wWcem3G5ecdiYWtz 7e9g== 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=i7UY77EGMZQ13NS7fZmn7pf9fjlwDFzZa7bkvarCZyo=; b=dU9ofj46QZUkpszJVRUmImmenMTNBS73/Ku4tgyhnTjMlLj4FeZ26NChLHu1SzJ5qU OaBrQ9IUqXBVxlM69MU8wV3F1SlQTt46u649921b+c+taEIRLtwjJH53Gzmh9qAumzWz j5d6ufvZnpb3iYMkYbchMqEt5L92mLOKKK+MPDI+5s/TMk7cxPzsL6Mb0waH55G1l5l/ nxk5feMv0UwjCxL2FaCIPifJru6BBh7WkTwayD53ICoqwpL2VTV6R/cJFawjtyHeN4Xg Ad+UQ9c/R/CGPCHZ1WvRcdfLmSHOmqCpdF9gzHVdkN9bMiuxCpI2CKYDArVArbNNtcG1 Irvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="oA/w6pGQ"; 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 vj23-20020a170907131700b0078316f0b5f8si8618934ejb.88.2022.11.08.19.37.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 19:37:11 -0800 (PST) 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="oA/w6pGQ"; 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 6CD6B8502B; Wed, 9 Nov 2022 04:36:41 +0100 (CET) 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="oA/w6pGQ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 53FE484FF9; Wed, 9 Nov 2022 04:36:25 +0100 (CET) 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-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) (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 8972E85006 for ; Wed, 9 Nov 2022 04:36:09 +0100 (CET) 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-x102a.google.com with SMTP id m6-20020a17090a5a4600b00212f8dffec9so749451pji.0 for ; Tue, 08 Nov 2022 19:36:09 -0800 (PST) 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=i7UY77EGMZQ13NS7fZmn7pf9fjlwDFzZa7bkvarCZyo=; b=oA/w6pGQkazqbHmhiwMwdtPbmHVjo/DmoaTpJFULm3BLOpJKutWDlCdK7PUSkyE+4j yziXJWvORhjCHi0SjbYg/V7VBqn09pBe11k2ARt2FzxuXZ6PQh50xqCqTZ06To6OdCHz dF79hyP+0RE8Oa6OaCg12WzzLGgXbmKjwmvQWnVmxPFjg4Mp7bHmq0Gc5NaH3HboGNy1 qFECUxNLpKoUBrEPYx5tWrSqAH8VKqjXXWeBO4RMcxE5f+irOvlt0/eHsjrKqY3rOoc9 4QLgW979KPjyjU/VKhl/nBnwrHPe5CEAlQGzCZ2AlKchfznck/vsJs8GQx0X4rcKZWJS CS1Q== 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=i7UY77EGMZQ13NS7fZmn7pf9fjlwDFzZa7bkvarCZyo=; b=bZw0/ondcpY0LtCegSNBCdKo2XKdNMR5+M4nw2bxVA5XdwlJlF4wXRagA0h08/bG6j a39uniliBW1HyBkucJxsl0JS2nGf4Tto2bGgbILxo699PHya+y/a+vTzIplbg7pL1x+6 q5kCmMJBPrh2lFkN+iS/6wev6Ptg1pjjwxYMWFSI1Liqc18GmutnANd5QP0yJkXoi3G1 ZLwkOHGTKvoqT70Oaa7epq0OlN4qDg6sbgBJrWDGY1gu3uPL92MvwUGo5z2aREEISexN njhodNI96vgntRy+rVlz3yt+LhRWf6/PpNTthtm/Sgkfnsb+LG0Ak7lHuKIhL52u+T+y YTAA== X-Gm-Message-State: ACrzQf3JWD060SoxLW0u7URZFWyM42XyxUfHNrgeH+i5iKwsyIy/NS+5 sY/htFgZvFrBpyoAvd2/nt1lwQ== X-Received: by 2002:a17:90a:2a8b:b0:213:9ae5:b9ab with SMTP id j11-20020a17090a2a8b00b002139ae5b9abmr61276702pjd.110.1667964962780; Tue, 08 Nov 2022 19:36:02 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id e17-20020a17090301d100b00177f25f8ab3sm7838370plh.89.2022.11.08.19.36.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 19:36:02 -0800 (PST) From: Masahisa Kojima To: kojima.masahisa@socionext.com, u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Etienne Carriere , Masahisa Kojima , Roger Knecht , Ovidiu Panait , Ashok Reddy Soma Subject: [PATCH v7 4/5] eficonfig: add UEFI Secure Boot Key enrollment interface Date: Wed, 9 Nov 2022 12:37:27 +0900 Message-Id: <20221109033728.5623-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221109033728.5623-1-masahisa.kojima@linaro.org> References: <20221109033728.5623-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 PK, KEK, db and dbx by selecting file. Only the signed EFI Signature List(s) with an authenticated header, typically '.auth' file, is accepted. To clear the PK, KEK, db and dbx, user needs to enroll the null key signed by PK or KEK. Signed-off-by: Masahisa Kojima --- Changes in v7: - only accept .auth file. - remove creating time based authenticated variable - update commit message - use efi_file_size() Changes in v6: - use efi_secure_boot_enabled() - replace with WIN_CERT_REVISION_2_0 from pe.h - call efi_build_signature_store() to check the valid EFI Signature List - update comment 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 | 242 ++++++++++++++++++++++++++++++++++++++++++ include/efi_config.h | 5 + 4 files changed, 255 insertions(+) create mode 100644 cmd/eficonfig_sbkey.c diff --git a/cmd/Makefile b/cmd/Makefile index 2444d116c0..0b6a96c1d9 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 12babb76c2..d79194794b 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -2435,6 +2435,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..1e9eb3f51e --- /dev/null +++ b/cmd/eficonfig_sbkey.c @@ -0,0 +1,242 @@ +// 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}, */ +}; + +/** + * 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; +} + +/** + * 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; + 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_process_select_file(&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; + + ret = efi_file_size(f, &size); + if (ret != EFI_SUCCESS) + goto out; + + buf = calloc(1, size); + if (!buf) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + if (size == 0) { + eficonfig_print_msg("ERROR! File is empty."); + 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 (!file_have_auth_header(buf, size)) { + eficonfig_print_msg("ERROR! Invalid file format. Only .auth variables is allowed."); + ret = EFI_INVALID_PARAMETER; + goto out; + } + + 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); + + /* return to 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; + } + + /* return to 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) **", + (efi_secure_boot_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; + } + + /* return to 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 064f2efe3f..7a02fc68ac 100644 --- a/include/efi_config.h +++ b/include/efi_config.h @@ -99,5 +99,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 Wed Nov 9 03:37:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 622922 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp19567pvb; Tue, 8 Nov 2022 19:37:25 -0800 (PST) X-Google-Smtp-Source: AMsMyM6HYSVyt40X8I/ZDc/RQ9tQXiYSdB46V5QTi+pjl9GA1aVRUM+Qn1zNvnD+kQs7gBwdMABx X-Received: by 2002:a05:6402:2681:b0:461:cbda:fe4b with SMTP id w1-20020a056402268100b00461cbdafe4bmr59022084edd.124.1667965045158; Tue, 08 Nov 2022 19:37:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667965045; cv=none; d=google.com; s=arc-20160816; b=qgpgTlYSGPhXaE4M0t2UcTV3LD1s9B3E/CaAY4MEeICav1I2P2SSfE6rXvfbcicU1N C95hEnzmN3QXJc5XgIjfjJzB0XBwFs44Y5sD3Sm0YCcigpauRYrLH5O5SBfnyRNSQeAA 6Z4+1r4XpLR4Lq5JKsknMTTl9C6NyRbcZwF/OTVirQFW5kPBtVRYuceHYjN+/2uB150m 4wxahAsFpCIfpa1il51bdGets2thZeceZ9SS/u2rkVMeWZc/RyDThoKNxVUMm4MHK46I IXkhfEE1YdwKb5nq4FoJ9gVwbVidVZA0Iwc5L7HxOYHdFMq26AmDoea8//Brx+4BGCjl KSvg== 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=veMMcW1Py5ijeRz3UPrw2Zlue+2Apr2+wmKRGb/Stjw=; b=wibqLv6jCUIouYz/lX7A3d6XxlZL2PQwJQNHGWaVZuIa3OmVehLVqAwetEugUtdYFX B+WyNl5KkvYMrldPFpyChCWGkpOo6NTHImi8EFNU7N9yple8xi3NKfsQHmp/VRwl4/2X jXmgBS/PIVDkXOs5CUVe9/lN/uVuFX8UxRV+0I1eUGFKId2u2zY+PJ3OFu+tyP9QXkwv VxvYF02axdO4JuwIka8fza8zGrZzc2ZXIXhGTYXV/0/VZRvyvwyW8vUO9bAmbWn8iBWc hg5Qzs41V3LxOCeFGrmpACvpjG3s03Hts7T4TZFk4HGvYDLgx4QxvEN314Fxfd+J0Hmo oACg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=A38VMuie; 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 o7-20020a17090608c700b00791a67e4c00si11671940eje.835.2022.11.08.19.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 19:37:25 -0800 (PST) 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=A38VMuie; 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 4C4C58505B; Wed, 9 Nov 2022 04:36:45 +0100 (CET) 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="A38VMuie"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8044180431; Wed, 9 Nov 2022 04:36:29 +0100 (CET) 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-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) (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 3C2C08503E for ; Wed, 9 Nov 2022 04:36:17 +0100 (CET) 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-x102e.google.com with SMTP id q1-20020a17090a750100b002139ec1e999so724175pjk.1 for ; Tue, 08 Nov 2022 19:36:17 -0800 (PST) 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=veMMcW1Py5ijeRz3UPrw2Zlue+2Apr2+wmKRGb/Stjw=; b=A38VMuieFEG8OGg52Qgce966C5peiyaESMl8wVlcQiIZZ+BvCn3jwojmlAvxKTc1kD duOklkh9Wdho6usvRxDR11mgOp2FRmvUl/vJ1ZN6mAbJp0BiFTXorQpHuocSCjfITGK9 klmazc1Zy5q4S+gq9TxBXnl+YpQPmso9dS1NR4OS0QwFA/Ukp8JmmF0F+kjZ7dUQ1mnL 8DPxeA8r785dSCJUMaaqC4zuLUI3QkhO8DgaEctgM0ty0Phjlb6fetS1BICmYmihD7+B ZsCwgcxvNa+sCgNLWYlmBtdPoIsJbwvEWxxD8nl/KOcRohLvMKOtxo33migxcpWS32S9 u1ug== 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=veMMcW1Py5ijeRz3UPrw2Zlue+2Apr2+wmKRGb/Stjw=; b=18VSITwHhZ4GvYtw2NlgmN0c9E0Sj3riZGP/QEDGd5Jnq5+mcVFmuv6mzyKip6Amng qH4cQczSMWMCtA5SExI7rPelLH12/B0Zmps5y38JWXVnzwdQwJ2tkdHJ+l5r/gQsX0RO Vx905cV4sIrMw7Rg+ReFhTNGq4FfMXitk0oQONS4UdDL3rcqrz6vJXCr7vmsLaZwRHTW Pj+wpOj+y07DaM23p//XbJQ2moATaY++T777bo4/LBIrAoeLrYJ25jJYm4evsag+BJXH lScYzeIveLcmlIM0euflRc6Zx56lFbF2Wz6KL0W+RdXVzgGgJ8U4+qhD+KIOniFRT+Jx Agww== X-Gm-Message-State: ACrzQf0pyOblst39E0ufMOVnLi6iLOPaKS57uIMlcdsqattnbvoex5Wu CPUFDPypVEnPIi9U5+19ZgAzug== X-Received: by 2002:a17:902:f552:b0:186:cdb2:b864 with SMTP id h18-20020a170902f55200b00186cdb2b864mr58533052plf.24.1667964966181; Tue, 08 Nov 2022 19:36:06 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id e17-20020a17090301d100b00177f25f8ab3sm7838370plh.89.2022.11.08.19.36.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 19:36:05 -0800 (PST) From: Masahisa Kojima To: kojima.masahisa@socionext.com, u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Etienne Carriere , Masahisa Kojima Subject: [PATCH v7 5/5] eficonfig: add "Show Signature Database" menu entry Date: Wed, 9 Nov 2022 12:37:28 +0900 Message-Id: <20221109033728.5623-6-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221109033728.5623-1-masahisa.kojima@linaro.org> References: <20221109033728.5623-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 the signature list content. Signed-off-by: Masahisa Kojima --- Changes in v7: - remove delete signature list feature user can clear the signature database with signed null key - rename function name to avoid confusion - update commit message Changes in v6: - update comment Changes in v2: - integrate show and delete signature database menu - add confirmation message before delete - add function comment cmd/eficonfig_sbkey.c | 236 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 236 insertions(+) diff --git a/cmd/eficonfig_sbkey.c b/cmd/eficonfig_sbkey.c index 1e9eb3f51e..9fd1dc3fcc 100644 --- a/cmd/eficonfig_sbkey.c +++ b/cmd/eficonfig_sbkey.c @@ -17,6 +17,13 @@ #include #include +struct eficonfig_sig_data { + struct efi_signature_list *esl; + struct efi_signature_data *esd; + struct list_head list; + u16 *varname; +}; + enum efi_sbkey_signature_type { SIG_TYPE_X509 = 0, SIG_TYPE_HASH, @@ -155,8 +162,237 @@ out: return ret; } +/** + * eficonfig_process_show_siglist() - show signature list content + * + * @data: pointer to the data for each entry + * Return: status code + */ +static efi_status_t eficonfig_process_show_siglist(void *data) +{ + u32 i; + struct eficonfig_sig_data *sg = data; + + puts(ANSI_CURSOR_HIDE); + puts(ANSI_CLEAR_CONSOLE); + printf(ANSI_CURSOR_POSITION, 1, 1); + + printf("\n ** Show 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."); + return EFI_INVALID_PARAMETER; + } + } + } + + while (tstc()) + getchar(); + + printf("\n\n Press any key to continue"); + getchar(); + + return EFI_SUCCESS; +} + +/** + * prepare_signature_list_menu() - create the signature list 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 + * Return: status code + */ +static efi_status_t prepare_signature_list_menu(struct efimenu *efi_menu, void *varname, + void *db, efi_uintn_t db_size, + eficonfig_entry_func func) +{ + 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->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; +} + +/** + * enumerate_and_show_signature_database() - enumerate and show the signature database + * + * @data: pointer to the data for each entry + * Return: status code + */ +static efi_status_t enumerate_and_show_signature_database(void *varname) +{ + void *db; + char buf[50]; + efi_status_t ret; + efi_uintn_t db_size; + struct efimenu *efi_menu; + struct list_head *pos, *n; + struct eficonfig_entry *entry; + + 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_list_menu(efi_menu, varname, db, db_size, + eficonfig_process_show_siglist); + if (ret != EFI_SUCCESS) + goto out; + + snprintf(buf, sizeof(buf), " ** Show Signature Database (%ls) **", (u16 *)varname); + ret = eficonfig_process_common(efi_menu, buf); +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(db); + + return ret; +} + +/** + * eficonfig_process_show_signature_database() - process show signature database + * + * @data: pointer to the data for each entry + * Return: status code + */ +static efi_status_t eficonfig_process_show_signature_database(void *data) +{ + efi_status_t ret; + + while (1) { + ret = enumerate_and_show_signature_database(data); + if (ret != EFI_SUCCESS && ret != EFI_NOT_READY) + break; + } + + /* return to 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 Signature Database", eficonfig_process_show_signature_database}, {"Quit", eficonfig_process_quit}, };