From patchwork Fri Dec 2 04:59:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 630194 Delivered-To: patch@linaro.org Received: by 2002:a17:906:9c8c:b0:7c0:a5ce:226a with SMTP id fj12csp903590ejc; Thu, 1 Dec 2022 21:01:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf68Cc57+PGDyURzDuPeoOHiqTNCZE1QujUnkHAAPL9ohkQyiyh5XtfcsoB1bMhyoAXsVMpy X-Received: by 2002:a5e:9515:0:b0:6df:e6e8:39fd with SMTP id r21-20020a5e9515000000b006dfe6e839fdmr1152235ioj.24.1669957261108; Thu, 01 Dec 2022 21:01:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669957261; cv=none; d=google.com; s=arc-20160816; b=YKBW/RyO4MkxtGp35Bs9t9yAE4HfsD9jvqmKJfCc7DFrE92AXTZDg6qUoe/B7g8Jks s/oIWQx4d11nO58KckaWLBtazQ9rtLmDG3hFhdo5gdTM1Abie0WwUfXB7ZfvdQs1yTI1 l0v+XsseIORqQnucEyEN56RNLQAaoCgR6Cdurh5ccx0TkmZ0T/I0WaqqPFkC7ZOc/1aE vO1TbLzf3Xng7TJJQty6Tvi9CdVDsAt0bHaA5GeLko7+FHJW0qbo4ZLTLxeiDM/z5iiK 43sDTizRoDFtTYMr2gE4epNZLmjVvu+o1w+w6trY5jJg2AYgweRo4D0YYX2DIhh57UQn FODw== 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=JwVaoFqkTKjsdH9BGs/xnhh8pUYAScZ75/3kFTxkHEM=; b=LN9fAMVjcyK3LEWcl+g/oydR85vhfHLh38onlnm+zjlPt4fQZO5oPOlOJ4s4dfX+qj MojjK81SOAqxeO0ti37LsO8/+bYqIMI/9Zgjl4fINSAmzJ0a84Q7a0q2YAULkad3kfpi cKLLXFcoN5t1c0kmkb4BTMLnvT7V72BXmzMPZ/nGtbgfFcFWsvdxc6KJdO10hXBjNdSz 4i+e8zuBkXDCqIfE+JYN0PbJjcCG2Nj0keE8YUlSHHigzLz/UQDd/+gOFBzbahy+zKMm +5Z5xz9yCaRYx/4IIrwwoZ8qlojGx+iqb6Onj5LIXk2Bw9/4iTbpm3K8vAoSNX1/QgL6 rCig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DwKrpzZX; 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 j14-20020a056e02220e00b003031ed0a479si4881979ilf.175.2022.12.01.21.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 21:01:01 -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=DwKrpzZX; 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 091258544A; Fri, 2 Dec 2022 06:00:38 +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="DwKrpzZX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2B90D85460; Fri, 2 Dec 2022 06:00:31 +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-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) (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 1F41985445 for ; Fri, 2 Dec 2022 06:00: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-pg1-x530.google.com with SMTP id s196so3500302pgs.3 for ; Thu, 01 Dec 2022 21:00:00 -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=JwVaoFqkTKjsdH9BGs/xnhh8pUYAScZ75/3kFTxkHEM=; b=DwKrpzZXwvBU1KxdnUr1Q34CDnN9jlJe1cuz6/SMFhE5w/yhsCQ4jVNAY507f/ZB4J Ov5sK0d3rbpngrdjFmQer/WNb/ttxwilFCNWGlmFpCo/u3ugZoIN481lKgRKl0vydA1o 7tvfy6H6gcvaFeF6KK7JewXPn5qFTGQovBF7GW+jAoVs29Lx5BRoKLdBHJjJGLQDy6c8 TFDP8/L0pBBCy+G6MeXbUQp97mp9339nPwKH1sI3WybjSYZ0grHcWgK2+EZqsEu2WQFY DpMoKhXOyN2VRSfCWKl6Qk53106/yq8V8jlJJzmoYkgRxJm69Pb1KFU24V7/IXwQy65v DwDA== 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=JwVaoFqkTKjsdH9BGs/xnhh8pUYAScZ75/3kFTxkHEM=; b=HN8HVSwRHdMmFOMZDAOUFyOCpiRogiJJR/9iwnhl+SseCFTIQ0RnRXgL1MtUstb2WS 4fbTTUtULPuRGbeP/5xFHp3Y/J/WJ9KjLqcDDaOzxDzXmlcL2gZ3PnUPjf4Qs1J7ZS2B lxZJPsQWeO8oi55Urj7tCFTqcQey7DztzXXfWjh1iBoi6alyCWWY7zTOVQRAlfsmH9lM Edhta1o18Rme7kWT9mY3ivRpnpeo2V8a1XoPXMop6Cgfa80KAKaCOS9nJXNa3K8GOUh5 HuKJt5gocWq1gHDXAKAXbMVdwiomGzNHWLY+/ZBRq0TTVHdx00q5jNsHnd3ywjWOsjFT +A2w== X-Gm-Message-State: ANoB5pn+su+UDRb03FYTrbFeiOdXLAveQCsEi1ubZzRLtk9f1zbz0Yhv 6PO9JDeYiipoAeQKDYrzFXnAKDhjS18OluCy X-Received: by 2002:a05:6a00:1941:b0:56b:a80f:38d4 with SMTP id s1-20020a056a00194100b0056ba80f38d4mr51263025pfk.12.1669957197608; Thu, 01 Dec 2022 20:59:57 -0800 (PST) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id z27-20020aa7949b000000b00575fbe1cf31sm3234456pfk.67.2022.12.01.20.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 20:59:56 -0800 (PST) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Jerome Forissier , Masahisa Kojima Subject: [PATCH v3 4/5] eficonfig: use efi_get_next_variable_name_int() Date: Fri, 2 Dec 2022 13:59:36 +0900 Message-Id: <20221202045937.7846-5-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221202045937.7846-1-masahisa.kojima@linaro.org> References: <20221202045937.7846-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 command reads all possible UEFI load options from 0x0000 to 0xFFFF to construct the menu. This takes too much time in some environment. This commit uses efi_get_next_variable_name_int() to read all existing UEFI load options to significantlly reduce the count of efi_get_var() call. Signed-off-by: Masahisa Kojima --- No update since v2 v1->v2: - totaly change the implemention, remove new Kconfig introduced in v1. - use efi_get_next_variable_name_int() to read the all existing UEFI variables, then enumerate the "Boot####" variables - this commit does not provide the common function to enumerate all "Boot####" variables. I think common function does not simplify the implementation, because caller of efi_get_next_variable_name_int() needs to remember original buffer size, new buffer size and buffer address and it is a bit complicated when we consider to create common function. cmd/eficonfig.c | 141 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 117 insertions(+), 24 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 88d507d04c..394ae67cce 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -1683,7 +1683,8 @@ static efi_status_t eficonfig_show_boot_selection(unsigned int *selected) u32 i; u16 *bootorder; efi_status_t ret; - efi_uintn_t num, size; + u16 *var_name16 = NULL, *p; + efi_uintn_t num, size, buf_size; struct efimenu *efi_menu; struct list_head *pos, *n; struct eficonfig_entry *entry; @@ -1707,14 +1708,43 @@ static efi_status_t eficonfig_show_boot_selection(unsigned int *selected) } /* list the remaining load option not included in the BootOrder */ - for (i = 0; i <= 0xFFFF; i++) { - /* If the index is included in the BootOrder, skip it */ - if (search_bootorder(bootorder, num, i, NULL)) - continue; + buf_size = 128; + var_name16 = malloc(buf_size); + if (!var_name16) + return EFI_OUT_OF_RESOURCES; - ret = eficonfig_add_boot_selection_entry(efi_menu, i, selected); - if (ret != EFI_SUCCESS) - goto out; + var_name16[0] = 0; + for (;;) { + int index; + efi_guid_t guid; + + size = buf_size; + ret = efi_get_next_variable_name_int(&size, var_name16, &guid); + if (ret == EFI_NOT_FOUND) + break; + if (ret == EFI_BUFFER_TOO_SMALL) { + buf_size = size; + p = realloc(var_name16, buf_size); + if (!p) { + free(var_name16); + return EFI_OUT_OF_RESOURCES; + } + var_name16 = p; + ret = efi_get_next_variable_name_int(&size, var_name16, &guid); + } + if (ret != EFI_SUCCESS) { + free(var_name16); + return ret; + } + if (efi_varname_is_load_option(var_name16, &index)) { + /* If the index is included in the BootOrder, skip it */ + if (search_bootorder(bootorder, num, index, NULL)) + continue; + + ret = eficonfig_add_boot_selection_entry(efi_menu, index, selected); + if (ret != EFI_SUCCESS) + goto out; + } if (efi_menu->count >= EFICONFIG_ENTRY_NUM_MAX - 1) break; @@ -1732,6 +1762,8 @@ out: } eficonfig_destroy(efi_menu); + free(var_name16); + return ret; } @@ -1994,6 +2026,8 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi u32 i; char *title; efi_status_t ret; + u16 *var_name16 = NULL, *p; + efi_uintn_t size, buf_size; /* list the load option in the order of BootOrder variable */ for (i = 0; i < num; i++) { @@ -2006,17 +2040,45 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi } /* list the remaining load option not included in the BootOrder */ - for (i = 0; i < 0xFFFF; i++) { + buf_size = 128; + var_name16 = malloc(buf_size); + if (!var_name16) + return EFI_OUT_OF_RESOURCES; + + var_name16[0] = 0; + for (;;) { + int index; + efi_guid_t guid; + if (efi_menu->count >= EFICONFIG_ENTRY_NUM_MAX - 2) break; - /* If the index is included in the BootOrder, skip it */ - if (search_bootorder(bootorder, num, i, NULL)) - continue; - - ret = eficonfig_add_change_boot_order_entry(efi_menu, i, false); + size = buf_size; + ret = efi_get_next_variable_name_int(&size, var_name16, &guid); + if (ret == EFI_NOT_FOUND) + break; + if (ret == EFI_BUFFER_TOO_SMALL) { + buf_size = size; + p = realloc(var_name16, buf_size); + if (!p) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + var_name16 = p; + ret = efi_get_next_variable_name_int(&size, var_name16, &guid); + } if (ret != EFI_SUCCESS) goto out; + + if (efi_varname_is_load_option(var_name16, &index)) { + /* If the index is included in the BootOrder, skip it */ + if (search_bootorder(bootorder, num, index, NULL)) + continue; + + ret = eficonfig_add_change_boot_order_entry(efi_menu, index, false); + if (ret != EFI_SUCCESS) + goto out; + } } /* add "Save" and "Quit" entries */ @@ -2035,9 +2097,9 @@ static efi_status_t eficonfig_create_change_boot_order_entry(struct efimenu *efi goto out; efi_menu->active = 0; - - return EFI_SUCCESS; out: + free(var_name16); + return ret; } @@ -2270,17 +2332,48 @@ out: efi_status_t eficonfig_delete_invalid_boot_option(struct eficonfig_media_boot_option *opt, efi_status_t count) { - u32 i, j; + u32 i; efi_uintn_t size; void *load_option; struct efi_load_option lo; + u16 *var_name16 = NULL, *p; u16 varname[] = u"Boot####"; efi_status_t ret = EFI_SUCCESS; + efi_uintn_t varname_size, buf_size; - for (i = 0; i <= 0xFFFF; i++) { + buf_size = 128; + var_name16 = malloc(buf_size); + if (!var_name16) + return EFI_OUT_OF_RESOURCES; + + var_name16[0] = 0; + for (;;) { + int index; + efi_guid_t guid; efi_uintn_t tmp; - efi_create_indexed_name(varname, sizeof(varname), "Boot", i); + varname_size = buf_size; + ret = efi_get_next_variable_name_int(&varname_size, var_name16, &guid); + if (ret == EFI_NOT_FOUND) + break; + if (ret == EFI_BUFFER_TOO_SMALL) { + buf_size = varname_size; + p = realloc(var_name16, buf_size); + if (!p) { + free(var_name16); + return EFI_OUT_OF_RESOURCES; + } + var_name16 = p; + ret = efi_get_next_variable_name_int(&varname_size, var_name16, &guid); + } + if (ret != EFI_SUCCESS) { + free(var_name16); + return ret; + } + if (!efi_varname_is_load_option(var_name16, &index)) + continue; + + efi_create_indexed_name(varname, sizeof(varname), "Boot", index); load_option = efi_get_var(varname, &efi_global_variable_guid, &size); if (!load_option) continue; @@ -2292,15 +2385,15 @@ efi_status_t eficonfig_delete_invalid_boot_option(struct eficonfig_media_boot_op if (size >= sizeof(efi_guid_bootmenu_auto_generated)) { if (guidcmp(lo.optional_data, &efi_guid_bootmenu_auto_generated) == 0) { - for (j = 0; j < count; j++) { - if (opt[j].size == tmp && - memcmp(opt[j].lo, load_option, tmp) == 0) { - opt[j].exist = true; + for (i = 0; i < count; i++) { + if (opt[i].size == tmp && + memcmp(opt[i].lo, load_option, tmp) == 0) { + opt[i].exist = true; break; } } - if (j == count) { + if (i == count) { ret = delete_boot_option(i); if (ret != EFI_SUCCESS) { free(load_option);