From patchwork Thu Aug 21 15:35:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 104 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790564; bh=1j3dVO3JDo0ZPfFhYr+vcg8GUjHuOIrSreodznaMYXY=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=lfmCYLP4jhahWRdQ9cJ5Bzkj4hMmMDMDp/Lr/VESXf9v0xJvvz0gecrqj946tTZjf a8Ba/+Q6+caAgtLHS0iJnrp6yvh63pEygLoH2wbGgw3O3MQBjqn0Gh8EKZKuXI0pSo WNrhRN7hFPsAPjw26eci2LqyFjcgtjnPD8ax5cPFZZVUEtmF4XoYde/U7yHJNwxOeM S45z1NwVCWQzGdglldkcybco6iZC8Ra3SwuakMsWvmzWUrIxyJrAg8/qyblnzlqKFg H8On7yO0a8/v+f0zIyU6+nQAG/ODLrpreZLdnhl9ppxE0mdZTas2cwl5VMcJ2bO2RT Fjw13Rkg1a5Yw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DA8EA676D7 for ; Thu, 21 Aug 2025 09:36:04 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id tBKF6W_vib6I for ; Thu, 21 Aug 2025 09:36:04 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790562; bh=1j3dVO3JDo0ZPfFhYr+vcg8GUjHuOIrSreodznaMYXY=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=CZa6qczkKZPJ4VGFn3GDMWpgFBWEcXxuLp7EW3VU18kRGRjnvK55y1EJrgMl8G64q RYLeDD5xpFO+W6iKaQxGY/sw+FWwqSNiflMU0oVZe22McU7bmuu7opwVvUb3OAzJ3F y4Wfb+WCDZUW5qk4xt1pcXTViI83yQGJbcj3pc3KjF4BG1CJQQuKVIAwLM/Y446+ZB FYPyTCuPt8Bg74G/hkhxZg6xHoMi/XRi/3PvDQRFUyoLjRA7mdO5uRhjS1Uu44AOz+ GrA4lmVqub+h6n1tRoGU0UNbLaiHl4e8806DCdHYJP78tV0UwMqaL10M4vcUFX8fg9 EDYGm1SM13unw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E2369676E2 for ; Thu, 21 Aug 2025 09:36:02 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790560; bh=9qquCu5ZCqbHlYUiS9BemBvowoGx2uRr7u7zSfAI/Ww=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hty7jKExdjsOk2ywtyVPiVWzGYdW0ROYlPgEDYjFm6mi2+sqC11YzCHxjYndvdsDV nPfM7SXbnKtvikgFCy29YDlbJABg8aq6RsHJmpe3/IMGLmFiLPg6S6wGdO0ejzhXcH PKAEfxw2j0cTPUx/gFviZA6pE7xolTf+14oOgDPXptK1soprEAH0Fe/wEm39iEQ1oQ jv4AVV8MKJOgEDUBmdxToIdCtyTwo3/chDad7CmPMkPl7aF8B1hofvkSAMwIwWvDRU uL24m/mpPP7v4VQYcMh5P2OTbag/j8gOwT9ik0FecE0yAga12eJjivvIIqxVljiggq hYn5FqdW0K/hQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1B33E676D7; Thu, 21 Aug 2025 09:36:00 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id b-HvW0lmWcoI; Thu, 21 Aug 2025 09:36:00 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790558; bh=zLbOzCCc6Gn6QkVoX1+EDL9RhvraHh2fd0e0q/d6WUE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tqijUUIZys8bYnEhnlZ4Oo3hcRWBBOZSw4aVXaFun+KttX68aVagfINdVWsQfFGat 8h7iok70dUw28+HwO7D90UFHLYNMzr2+O7yEHG195oX03w2Re3lGSIXXdYompsGgH4 vVpHFLP0zt+CV/OT8P/XI+zzGYYFupZiUHibTikeRnjT3Hqz1Zb9TN+hTyRoA3A3Nu sfR6n3a6Mg6KYwAhLzVAekf/RGMMa/Tnn3R8BHPPyO/hCayKeFnOOu5gi37KCjS4NI F3aJ+QXD4l+jcjiaZAayPD2VIOcTbRfUpHYygQwNtLC8WGndQKVUPfCyXnlWtzVe8U nbshaTylH/kGA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 4664A5FC00; Thu, 21 Aug 2025 09:35:58 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 21 Aug 2025 09:35:23 -0600 Message-ID: <20250821153528.141740-7-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250821153528.141740-1-sjg@u-boot.org> References: <20250821153528.141740-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: GO3VP7QFNSD7J7N3OKPPGFDKCJO2YUGX X-Message-ID-Hash: GO3VP7QFNSD7J7N3OKPPGFDKCJO2YUGX X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt , Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 6/7] efi: nvedit: Place variables in an alist before printing them List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass Rather than printing as we go, add variables to an alist so they can be printed when all variables are present. Signed-off-by: Simon Glass --- cmd/nvedit_efi.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index f2bba42850d..ce3ab9f785a 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -38,6 +38,17 @@ static const struct { {EFI_VARIABLE_READ_ONLY, "RO"}, }; +/** + * struct var_info - stores information about a single variable + * + * @name: Variable name (allocated) + * @guid: Variable guid + */ +struct var_info { + u16 *name; + efi_guid_t guid; +}; + /** * efi_dump_single_var() - show information about a UEFI variable * @@ -147,9 +158,10 @@ static int efi_dump_var_all(int argc, char *const argv[], const efi_guid_t *guid_p, bool verbose, bool nodump) { efi_uintn_t buf_size, size; + struct var_info *var; + struct alist vars; efi_guid_t guid; efi_status_t ret; - bool match = false; bool ok = false; u16 *name, *p; @@ -159,6 +171,7 @@ static int efi_dump_var_all(int argc, char *const argv[], return CMD_RET_FAILURE; name[0] = 0; + alist_init_struct(&vars, struct var_info); for (;;) { size = buf_size; ret = efi_get_next_variable_name_int(&size, name, &guid); @@ -179,20 +192,33 @@ static int efi_dump_var_all(int argc, char *const argv[], if (guid_p && guidcmp(guid_p, &guid)) continue; if (!argc || match_name(argc, argv, name)) { - match = true; - efi_dump_single_var(name, &guid, verbose, nodump); + struct var_info new_var; + + new_var.name = (u16 *)memdup(name, size); + if (!new_var.name) + goto fail; + new_var.guid = guid; + + if (!alist_add(&vars, new_var)) + goto fail; } } - if (!match && argc == 1) { + if (!vars.count && argc == 1) { printf("Error: \"%s\" not defined\n", argv[0]); goto done; } + alist_for_each(var, &vars) + efi_dump_single_var(var->name, &var->guid, verbose, nodump); + ok = true; fail: done: free(name); + alist_for_each(var, &vars) + free(var->name); + alist_uninit(&vars); return ok ? 0 : CMD_RET_FAILURE; }