From patchwork Thu Aug 21 15:35:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 99 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=1755790554; bh=p0wMcBTU/0HK+OzLjDj39b26rB/VJkDxeNoji9R4KkM=; 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=NKuUU91qAJEs+wukvKet4pVvqtSguOQO6gfuGNHIk7ucyU/3WyuGMUIXWwfpRKNRu ablZdujBVnMkTeoAdO0wwOoh/yhEoAvFMpOe11LGcb5WpKTmq8TWNtkpBIbJMH8XSI tm9ZFaac1aOv1YQiiXV2idwfbId8kJRrjKaawlAfJ7BLiIbEBhkb6lTHXfH8tsu50E 8zQWDMhTqcJTmAols6H5AcjVQaD0+Kq8AxhvMdK5ESKHCu4Wcpjkfl/dy/AlN83YAb 57wVrp2oXoJOKh/3Kt3XqtxMjqMiUnhL6bu3/62faBXHx1kZyhnnkiJj33EOzMGn/R 0eBExkSstF0EA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 26BD767522 for ; Thu, 21 Aug 2025 09:35:54 -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 qDbVZMRsGLV0 for ; Thu, 21 Aug 2025 09:35:54 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790553; bh=p0wMcBTU/0HK+OzLjDj39b26rB/VJkDxeNoji9R4KkM=; 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=HViFaiIpQj8rC63IlzVRCtra1NcznuO0av9epdFArO/t2HYY3d1HNkKkni0nYjGgs 6rZhbXeyiUwr9DwyGeJ7iofaL98OxfgQ8DBONon96AjK1/Y3fTEKI4yIUxAULZr5NC xJldptRZNExVgUmAUwpIKuhBFdX8tdUkMB77rrBtQr6tBVqgP9xbzAzGA3Sk1VfaQx MY6xJFWbUCDCaPLjji6dqSx743ii42hn2i5MNpfOvEkeLBIbOse9e8wtJD/xv3VpOJ FCt1JVkD6VO+broajoFHuBLoBnBzU4rEn6+SZ+4OOj6AO9NlRDyINCM8FPYMwvrS30 47yoD7qc85x6w== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 72EFE67533 for ; Thu, 21 Aug 2025 09:35:53 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790545; bh=5llBomW/kDMQ/XeeEQDwSPWljsUWu/OWXd42POlg8+c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HZC9VdTkiiluudTEZ8JSomoZsr56+avKoEj+z+GsIIQ6FoYZ3b+p9jOoW7tcKJh9J Dx/FxJmmrdV1XI5iseDU5YBNwfUofjMTCLCPcgoFvgq8+0Y7qT2jrTZt86m1tNsDLQ gQLXZWHEwlB6y4h5E3ro75JgmQvBYu6/zK/BhXJjgI7qWiZk5zHg/cdxD8RrfMujtw kKGMoE8U4CwP0wKQ0Gg+dK8ZVp1fLlOcHWbnXPiuR2eGSNrFzssSx4fKyJ+250PyxB f8VSZBOd4McS2c3a14p4zB44b2zazL9Cy34DKovCkcbCuUvyGGytZoXjTfIefw6468 5gvgwhCxhaCmA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 44C4C5FC00; Thu, 21 Aug 2025 09:35:45 -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 7ReoB1Ybj51I; Thu, 21 Aug 2025 09:35:45 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790544; bh=5NDDlZ8EfAwtmFz02GKavyWaccZ4CEyHdLOk2zhPrR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lI//BfBfuWC5qyMH3lfrmAkYA91RV2BNtug86O4/Vw3aLqASgqZSZyyPr0vO9yv+c sWiC3wc2iOQnm/6ZfDaeB1Xrmo0zip+QJMM2ZzjT4RZLsbG30GPGWI/n6bnorMXmfI AUzlBimICPYT+zJuD0AGC7thZyYRfXlRs04gZud9QAVh2GOIL9RkcxLyovHmAqJkzg l2Wx+sXYGzI1Af0Hzcd5gaJ2H5Oe38C6EIA7kzH22rE8PR08ajQqL5Kng8rbM85CyX JExPY0vMBiLLyZ4Q8a/T2yxQF19h6DoQGIt7pC2o9ymCZs0RCMyQ0t4OvOc1veAwP4 Lm5AAmo5yk9Cw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 02F245FC74; Thu, 21 Aug 2025 09:35:43 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 21 Aug 2025 09:35:18 -0600 Message-ID: <20250821153528.141740-2-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: Y25GR2JCSLW5SLR2IH6XXQG4UWHE3PFE X-Message-ID-Hash: Y25GR2JCSLW5SLR2IH6XXQG4UWHE3PFE 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 1/7] efi: Move guid used for variables to common files 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 Move efi_guid_image_security_database to a common file so that it can be used by the app. Signed-off-by: Simon Glass --- include/efi.h | 2 ++ include/efi_loader.h | 1 - lib/efi/device_path.c | 3 +++ lib/efi_loader/efi_var_common.c | 3 --- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/efi.h b/include/efi.h index 5e15a87ed3b..3558c03db23 100644 --- a/include/efi.h +++ b/include/efi.h @@ -157,6 +157,8 @@ extern const efi_guid_t efi_guid_fdt; /* GUID of the EFI_DRIVER_BINDING_PROTOCOL */ extern const efi_guid_t efi_guid_driver_binding_protocol; extern const efi_guid_t efi_guid_component_name2; +/* GUIDs for authentication - most of these are still in efi_loader.h */ +extern const efi_guid_t efi_guid_image_security_database; /* Generic EFI table header */ struct efi_table_hdr { diff --git a/include/efi_loader.h b/include/efi_loader.h index a475ebb5413..52314c33533 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -353,7 +353,6 @@ extern const efi_guid_t efi_guid_hii_config_access_protocol; extern const efi_guid_t efi_guid_hii_database_protocol; extern const efi_guid_t efi_guid_hii_string_protocol; /* GUIDs for authentication */ -extern const efi_guid_t efi_guid_image_security_database; extern const efi_guid_t efi_guid_sha256; extern const efi_guid_t efi_guid_cert_x509; extern const efi_guid_t efi_guid_cert_x509_sha256; diff --git a/lib/efi/device_path.c b/lib/efi/device_path.c index 449b9d4239b..1dc28f81146 100644 --- a/lib/efi/device_path.c +++ b/lib/efi/device_path.c @@ -39,6 +39,9 @@ const efi_guid_t efi_guid_driver_binding_protocol = EFI_DRIVER_BINDING_PROTOCOL_GUID; const efi_guid_t efi_guid_component_name2 = EFI_COMPONENT_NAME2_PROTOCOL_GUID; +const efi_guid_t efi_guid_image_security_database = + EFI_IMAGE_SECURITY_DATABASE_GUID; + /* template EFI_DP_END node: */ const struct efi_device_path EFI_DP_END = { .type = DEVICE_PATH_TYPE_END, diff --git a/lib/efi_loader/efi_var_common.c b/lib/efi_loader/efi_var_common.c index 4b34a58b4cf..f2fbf67f5ed 100644 --- a/lib/efi_loader/efi_var_common.c +++ b/lib/efi_loader/efi_var_common.c @@ -25,9 +25,6 @@ struct efi_auth_var_name_type { const enum efi_auth_var_type type; }; -const efi_guid_t efi_guid_image_security_database = - EFI_IMAGE_SECURITY_DATABASE_GUID; - static const struct efi_auth_var_name_type name_type[] = { {u"PK", &efi_global_variable_guid, EFI_AUTH_VAR_PK}, {u"KEK", &efi_global_variable_guid, EFI_AUTH_VAR_KEK}, From patchwork Thu Aug 21 15:35:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 100 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=1755790556; bh=knVQ9QZVeKV9nXfankQiZ7nRvw8mi9OyZzWbO0KVSzQ=; 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=rHikh6kKUMGQQrWNVeJjRdlkCOcHjdmnCfOpWEGCY7CHxhyhQ8/fh8e+IBxjwpOtV 8OhX2+xQMYKZ3JXedWZmPhk+irPIB6zb869kVFaNBDMm9Qg7X24lYbUOBIyp9O71Jf 0bJa332AP64Jlucb6P3JKps8F6TPXcSmJ7MAJgRz9O2UDA3Yd7q061x7sdPdOFvh6y 6tD+qT1l1LrxWQeDeEU3qgTlnCf7rQHUUaBhjzdP4yk9zUaHJdjF08qs7id1WJdFDt qgmo7KE5mXB12Rp+DR526UHyEn9ZM7g4XFcHYl5AjO4mrDYAA7Xkp3QFE46BiC2ElQ zgXWD8nIYsCcA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 64018676F0 for ; Thu, 21 Aug 2025 09:35:56 -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 t3HuXy1FH0sK for ; Thu, 21 Aug 2025 09:35:56 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790554; bh=knVQ9QZVeKV9nXfankQiZ7nRvw8mi9OyZzWbO0KVSzQ=; 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=GvrBxF5kq7qRcqbUdlfbhnYKTldPOn8whDTWX7JJLlVfn1Brj4incOaaij9CLUdd6 2vsOCgick633ymbdWxEUEfFkTNLI50dm3MpX9PYTTdO8I+rFULKncZcNUke5r13I8h WEntPGisAxZvXCrm+k5z09QdzNJWSvH/ucfNekP+BMGJ9pW4vdcPl2mmSavSSrrj2j bJRD7bdIGG42CoBiOMEk1pvGFfhjIWfaCzqMt8tjGQ2uZnFjIsZxv3XTpQ0ElGuFzv 1WrOTmhqI5KfS5gcgxZ7OQASM12K70MvlHz0g3IyAz6A15DiRmaIJ7E8m0HBaqw52J Vk+rhsOUvIVZA== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6253B676E2 for ; Thu, 21 Aug 2025 09:35:54 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790546; bh=xkf99EFgk1ygX6dkPLK0t5G8Z3FEdCxZph9qD1Gw9v4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bhHcGQEczxC/tuwjNMWjovyM8cshMl5D4O8MpAxc0ze6BmbdisN+M6tSfVq4zh/2B WE3/xH6AS+57Ed7sJFI62ptCbh5ZjHuHWTDeQvtV+hJbCAVi4sSlr6GNeeCM2grcX4 LyoSCX2z13vUeKXBqRBeGg3viqf+CftreakTE9K8rYmpntylg1rRrGrXtHIhHNExmT FSW6KTJpSXpDfTudOKfG5p2EtmamhodPXNKSxsle+yC33U+oqQHxytuL8QyZ+7kmkH 7PGgbmbjQGfysv9+hfgXbNH7Vqdd3EkD0KboGThutF63RO3dqWJc8t+dXanePhciCE C024X02ylhUDA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7A5D5675A4; Thu, 21 Aug 2025 09:35:46 -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 KAmlFY5AVNNs; Thu, 21 Aug 2025 09:35:46 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790545; bh=npOxgSr50SDArlDOzTfrWuBNYCf2X1Pa32t8ET1ExKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EIoXBRDBwrwI6fO2ym4N1K9DdsctrUrpWonsWPP1DUvdlGmwyoQflAwvrj0zkJdBO HqZLozyxsnlRoqIPhxqXrTl2+3zCgdCiY4QjqWDyoThuJqAbHHa6Sz0/CcBMODhzVD PZnWKzZG7v6iW+qxn2iz0s1d7x4BHNQ8ou5VhzE88BxuEw90pKoNbeoQNgbNHy4439 6e8LexJQl99lJu7Vq2muxYEN9TPEvzYIZyNL6zqEdBae//3Q96t+61+BRf9sTxnZ1w kYPEUGpZsME7/zyRP6wL19EFAdANvBOjnm6NfBvUDScoILXFbp2AVtgFyPaxixxDCK oRp1OYJ3JfXnw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 77A855FC74; Thu, 21 Aug 2025 09:35:45 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 21 Aug 2025 09:35:19 -0600 Message-ID: <20250821153528.141740-3-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: N3DLQFFYYATOJ6DSWKO6IRMS6BVQSBF7 X-Message-ID-Hash: N3DLQFFYYATOJ6DSWKO6IRMS6BVQSBF7 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 2/7] efi: Enable access to efi variables from the app 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 Enable the 'setenv -e' feature. Signed-off-by: Simon Glass --- cmd/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index fe9fb11ff95..882a4ee02e3 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -676,6 +676,7 @@ config CMD_ENV_FLAGS config CMD_NVEDIT_EFI bool "env [set|print] -e - set/print UEFI variables" depends on EFI_LOADER || EFI_APP + default y if EFI_APP imply HEXDUMP help UEFI variables are encoded as some form of U-Boot variables. From patchwork Thu Aug 21 15:35:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 101 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=1755790556; bh=brH3IbvGNWCHZ3DKaa99kuG7geUUW3j7j6IOP1LrW44=; 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=FH/q+ShAI5V34z2rt8fTtxUg5uKoHseLdhKO77STcdY0E4VUtQGpoPQhmzTBSfKMq KESalHw65BdyI19OI7XDYtDvRaoS4DQJ5GS+T1CzA+9PPuQKUq93D8SyohyPe7zgWb xuPKpH9JtDnsCPDoJXxF/6a2l6tu09LJ4lG8cMHah91IYPikPG3QhD7yG+caxgP+sZ 5spOFIgngI+45ZReLp6zclh0EyHmSEehgS/aynLEKzitzaEeMf833v7ADI5dSip7+A M8DzWr7RhweGW2L/1OFv6nruBV9ak6JqTmR0ii4/awWv2F0ZikR7UrMwSlMXnyPtJf N0PyJlNfnVNew== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id ADCED676F2 for ; Thu, 21 Aug 2025 09:35:56 -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 MDJZon-3VYg3 for ; Thu, 21 Aug 2025 09:35:56 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790554; bh=brH3IbvGNWCHZ3DKaa99kuG7geUUW3j7j6IOP1LrW44=; 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=RqaFSx+vxpaLKnso1uHzo6DJicxDeN2ULXl4vETjHTFrxJDCp6PNAsV6LXxikxLcw +L7G0VWlg9f3vOFXiMWp40POzSpfUY/ZDrnYXXWDssGuTHB0aJfkb8II9AN351WhRA 281qWMzPDqiUyiorNxspJdgba4ELm5S84Xtm9zk1sbE0iirdfp1kK9IW6yPnrl1Nrl xhvcAQXiMgL43PafmXjxNxz3SA2ZxeutkahO4rshH0vTVm2GenBJtZok5cUUq0Gwpp LM+xXsh1pW5QbBq1PEAFDroSZxxMh6XMBHEe4D6NvNAYL/296Wq01vVuemqxRzlTyq +qCTWvZQM/zUw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id D0D9A67533 for ; Thu, 21 Aug 2025 09:35:54 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790551; bh=jsBX4GP2/Em+jwZP2fRnFXqPfDh4O1udpkT5Mawg6eI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VGIKrXvHG9DRPK4nuQN9O95Pb81o08XEjYXejHebTXusvZkB88QFb9fXuZ1uOwSOQ XBjh7tl3x+sfU3BwEfIRRNfD52bUUWW4kX8d29JJyAHv2puGniObv00MF8Or4IgiBp s6AZWyyey6+3Chd4K4X24VbWyWRfqs+qvsXWaVcaomnuQ2ksLvf8l9SgPQtSuV22nb xis1cuqnSYLkWj3Z+KZcDQiuNRP345MxSu6J3UAwrNpg8nHDpjwSPYvpyvegwfDdFz F5/pE0tepjsWx+GW4ht7KcimzP8+ewZWAUhhAzugtS6Z2uR2mJc3tPnTrJQobtt1GK D5KHDAvA0qX5g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id DFB8F5FC74; Thu, 21 Aug 2025 09:35:51 -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 c_HRK88rvytP; Thu, 21 Aug 2025 09:35:51 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790547; bh=sjZTPvP369wGBPVWaYKji/kK+5JUCDmEr55sLCDx+qc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GvJCL1RsgahkdzwQpkyb8IrO7GFyv40uS2lwnG4822cyo144t9r8wfHATgjUFGs/F Xpnn8FNW31/LSwW41RnYOt2qzQbjLiAp5zqPBFkKQtsyHGPVSNSzWBdl64xKd59XVj U0+ktrMk2b/WgAuaTfIuwUu2PvB4sTl/kCfB9Y6iiFeDo9vUAlG+Y+nig75MPnJQlD UDGmyzJGulK+JjgAK5OWOqE5SrVCm4ezxxI5S9bQ78HuWGv1M17WUvQ5dMqACeAcPY qLBLGRk5CFiHA3p6sin2ft1zfWQhg5eIiMOrO2XogN3K7BlpIu17oWkgaBxubxmbLm 4TmVk4Ar8lOfA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id BB9B15FC00; Thu, 21 Aug 2025 09:35:46 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 21 Aug 2025 09:35:20 -0600 Message-ID: <20250821153528.141740-4-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: UKLHQ2ORSKEYHKTV7RJDVNFRUXMC5WPN X-Message-ID-Hash: UKLHQ2ORSKEYHKTV7RJDVNFRUXMC5WPN 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 , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 3/7] efi: Change env print -e to show only names by default 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 Change the default behavior of 'printenv -e' to show only EFI variable names. The previous verbose output is now available with the -v flag. This makes the command more user-friendly for quick variable listing. Update documentation to reflect the new behavior and provide examples of all three output modes: default (names only), -n (details without hex dump), and -v (full verbose output). It might be nicer to use -d to enable the dump, rather than have it on by default. Co-developed-by: Claude Signed-off-by: Simon Glass --- cmd/nvedit.c | 5 +- cmd/nvedit_efi.c | 65 +++++++++++-------- doc/usage/cmd/env.rst | 7 +- doc/usage/cmd/printenv.rst | 20 ++++-- .../py/tests/test_efi_secboot/test_authvar.py | 46 ++++++------- 5 files changed, 84 insertions(+), 59 deletions(-) diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 1f259801293..8dbe8a03fd5 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -1174,7 +1174,7 @@ U_BOOT_LONGHELP(env, #endif "env print [-a | name ...] - print environment\n" #if defined(CONFIG_CMD_NVEDIT_EFI) - "env print -e [-guid guid] [-n] [name ...] - print UEFI environment\n" + "env print -e [-guid guid] [-n] [-v] [name ...] print UEFI environment\n" #endif #if defined(CONFIG_CMD_RUN) "env run var [...] - run commands in an environment variable\n" @@ -1221,10 +1221,11 @@ U_BOOT_CMD_COMPLETE( "print environment variables", "[-a]\n - print [all] values of all environment variables\n" #if defined(CONFIG_CMD_NVEDIT_EFI) - "printenv -e [-guid guid][-n] [name ...]\n" + "printenv -e [-guid guid][-n] [-v] [name ...]\n" " - print UEFI variable 'name' or all the variables\n" " \"-guid\": GUID xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n" " \"-n\": suppress dumping variable's value\n" + " \"-v\": show GUID, flags, size; also dump (without -n)\n" #endif "printenv name ...\n" " - print value of environment variable 'name'", diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index 32b7d049074..12c98a5d5c4 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -43,11 +43,13 @@ static const struct { * * @name: Name of the variable * @guid: Vendor GUID - * @verbose: if true, dump data + * @verbose: if true, show detailed information + * @nodump: if true, don't show hexadecimal dump * * Show information encoded in one UEFI variable */ -static void efi_dump_single_var(u16 *name, const efi_guid_t *guid, bool verbose) +static void efi_dump_single_var(u16 *name, const efi_guid_t *guid, + bool verbose, bool nodump) { u32 attributes; u8 *data; @@ -75,23 +77,27 @@ static void efi_dump_single_var(u16 *name, const efi_guid_t *guid, bool verbose) if (ret != EFI_SUCCESS) goto out; - rtc_to_tm(time, &tm); - printf("%ls:\n %pUl (%pUs)\n", name, guid, guid); - if (attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) - printf(" %04d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year, - tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); - printf(" "); - for (count = 0, i = 0; i < ARRAY_SIZE(efi_var_attrs); i++) - if (attributes & efi_var_attrs[i].mask) { - if (count) - putc('|'); - count++; - puts(efi_var_attrs[i].text); - } - printf(", DataSize = 0x%zx\n", size); - if (verbose) - print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1, - data, size, true); + if (verbose) { + rtc_to_tm(time, &tm); + printf("%ls:\n %pUl (%pUs)\n", name, guid, guid); + if (attributes & EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) + printf(" %04d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year, + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); + printf(" "); + for (count = 0, i = 0; i < ARRAY_SIZE(efi_var_attrs); i++) + if (attributes & efi_var_attrs[i].mask) { + if (count) + putc('|'); + count++; + puts(efi_var_attrs[i].text); + } + printf(", DataSize = 0x%zx\n", size); + if (!nodump) + print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1, + data, size, true); + } else { + printf("%ls\n", name); + } out: free(data); @@ -130,13 +136,15 @@ out: * * @argc: Number of arguments (variables) * @argv: Argument (variable name) array - * @verbose: if true, dump data + * @guid_p: GUID to filter by, or NULL for all + * @verbose: if true, show detailed information + * @nodump: if true, don't show hexadecimal dump * Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE * * Show information encoded in all the UEFI variables */ static int efi_dump_var_all(int argc, char *const argv[], - const efi_guid_t *guid_p, bool verbose) + const efi_guid_t *guid_p, bool verbose, bool nodump) { u16 *var_name16, *p; efi_uintn_t buf_size, size; @@ -176,7 +184,7 @@ static int efi_dump_var_all(int argc, char *const argv[], continue; if (!argc || match_name(argc, argv, var_name16)) { match = true; - efi_dump_single_var(var_name16, &guid, verbose); + efi_dump_single_var(var_name16, &guid, verbose, nodump); } } free(var_name16); @@ -199,16 +207,18 @@ static int efi_dump_var_all(int argc, char *const argv[], * Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE * * This function is for "env print -e" or "printenv -e" command: - * => env print -e [-n] [-guid | -all] [var [...]] + * => env print -e [-v] [-guid | -all] [var [...]] * If one or more variable names are specified, show information * named UEFI variables, otherwise show all the UEFI variables. + * By default, only variable names are shown. Use -v for verbose output. */ int do_env_print_efi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { const efi_guid_t *guid_p = NULL; efi_guid_t guid; - bool verbose = true; + bool verbose = false; + bool nodump = false; efi_status_t ret; /* Initialize EFI drivers */ @@ -230,14 +240,17 @@ int do_env_print_efi(struct cmd_tbl *cmdtp, int flag, int argc, return CMD_RET_USAGE; guid_p = (const efi_guid_t *)guid.b; } else if (!strcmp(argv[0], "-n")) { - verbose = false; + verbose = true; + nodump = true; + } else if (!strcmp(argv[0], "-v")) { + verbose = true; } else { return CMD_RET_USAGE; } } /* enumerate and show all UEFI variables */ - return efi_dump_var_all(argc, argv, guid_p, verbose); + return efi_dump_var_all(argc, argv, guid_p, verbose, nodump); } /** diff --git a/doc/usage/cmd/env.rst b/doc/usage/cmd/env.rst index b65d85b6681..a1d90c6fca3 100644 --- a/doc/usage/cmd/env.rst +++ b/doc/usage/cmd/env.rst @@ -25,7 +25,7 @@ Synopsis env info [-d] [-p] [-q] env load env print [-a | name ...] - env print -e [-guid guid] [-n] [name ...] + env print -e [-guid guid] [-n] [-v] [name ...] env run var [...] env save env select [target] @@ -232,7 +232,10 @@ in UEFI variables. print only the UEFI variables matching this GUID (any by default) with guid format = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx". \-n - suppress dumping variable's value for UEFI. + don't show hexadecimal dump of value for UEFI variables. + \-v + show verbose output for UEFI variables including GUID, attributes, data + size and hexadecimal dump of value. Run ~~~ diff --git a/doc/usage/cmd/printenv.rst b/doc/usage/cmd/printenv.rst index dfdb3624934..cecfcf8bcda 100644 --- a/doc/usage/cmd/printenv.rst +++ b/doc/usage/cmd/printenv.rst @@ -12,7 +12,7 @@ Synopsis :: printenv [-a] [name ...] - printenv -e [-guid guid][-n] [name] + printenv -e [-guid guid][-n][-v] [name] Description ----------- @@ -32,6 +32,10 @@ The printenv command is used to print environment or UEFI variables. \-n don't show hexadecimal dump of value +\-v + show verbose output including GUID, attributes, data size and hexadecimal + dump of value (if not -n) + name Variable name. If no name is provided, all variables are printed. Multiple environment variable names may be specified. @@ -64,20 +68,24 @@ environment variables: Environment size: 653/8188 bytes => -The next example shows the effect of the *-n* flag when displaying an UEFI -variable and how to specify a vendor GUID: +The next example shows the different output modes when displaying UEFI +variables and how to specify a vendor GUID. By default, only the variable +name is shown. The *-v* flag shows full verbose output, while *-n* shows +details but omits the hexadecimal dump: :: - => printenv -e -guid 8be4df61-93ca-11d2-aa0d-00e098032b8c PlatformLangCodes + => printenv -e PlatformLangCodes + PlatformLangCodes + => printenv -e -v -n PlatformLangCodes PlatformLangCodes: 8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID) BS|RT|RO, DataSize = 0x6 - 00000000: 65 6e 2d 55 53 00 en-US. - => printenv -e -n PlatformLangCodes + => printenv -e -v -guid 8be4df61-93ca-11d2-aa0d-00e098032b8c PlatformLangCodes PlatformLangCodes: 8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID) BS|RT|RO, DataSize = 0x6 + 00000000: 65 6e 2d 55 53 00 en-US. => Configuration diff --git a/test/py/tests/test_efi_secboot/test_authvar.py b/test/py/tests/test_efi_secboot/test_authvar.py index 7b45f8fb814..3750f302dba 100644 --- a/test/py/tests/test_efi_secboot/test_authvar.py +++ b/test/py/tests/test_efi_secboot/test_authvar.py @@ -27,11 +27,11 @@ class TestEfiAuthVar(object): # Test Case 1a, Initial secure state output = ubman.run_command_list([ 'host bind 0 %s' % disk_img, - 'printenv -e SecureBoot']) + 'printenv -e -v SecureBoot']) assert '00000000: 00' in ''.join(output) output = ubman.run_command( - 'printenv -e SetupMode') + 'printenv -e -v SetupMode') assert '00000000: 01' in output with ubman.log.section('Test Case 1b'): @@ -46,14 +46,14 @@ class TestEfiAuthVar(object): output = ubman.run_command_list([ 'fatload host 0:1 4000000 PK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', - 'printenv -e -n PK']) + 'printenv -e -v PK']) assert 'PK:' in ''.join(output) output = ubman.run_command( - 'printenv -e SecureBoot') + 'printenv -e -v SecureBoot') assert '00000000: 01' in output output = ubman.run_command( - 'printenv -e SetupMode') + 'printenv -e -v SetupMode') assert '00000000: 00' in output with ubman.log.section('Test Case 1d'): @@ -78,11 +78,11 @@ class TestEfiAuthVar(object): output = ubman.run_command_list([ 'fatload host 0:1 4000000 KEK.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', - 'printenv -e -n KEK']) + 'printenv -e -v KEK']) assert 'KEK:' in ''.join(output) output = ubman.run_command( - 'printenv -e SecureBoot') + 'printenv -e -v SecureBoot') assert '00000000: 01' in output with ubman.log.section('Test Case 1f'): @@ -95,12 +95,12 @@ class TestEfiAuthVar(object): output = ubman.run_command_list([ 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) + 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) output = ubman.run_command( - 'printenv -e SecureBoot') + 'printenv -e -v SecureBoot') assert '00000000: 01' in output with ubman.log.section('Test Case 1g'): @@ -113,12 +113,12 @@ class TestEfiAuthVar(object): output = ubman.run_command_list([ 'fatload host 0:1 4000000 dbx.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize dbx', - 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f dbx']) + 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f dbx']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'dbx:' in ''.join(output) output = ubman.run_command( - 'printenv -e SecureBoot') + 'printenv -e -v SecureBoot') assert '00000000: 01' in output def test_efi_var_auth2(self, ubman, efi_boot_env): @@ -137,7 +137,7 @@ class TestEfiAuthVar(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) + 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) @@ -158,7 +158,7 @@ class TestEfiAuthVar(object): output = ubman.run_command_list([ 'fatload host 0:1 4000000 db1.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) + 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) @@ -178,7 +178,7 @@ class TestEfiAuthVar(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) + 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) @@ -199,7 +199,7 @@ class TestEfiAuthVar(object): output = ubman.run_command_list([ 'fatload host 0:1 4000000 db2.auth', 'setenv -e -nv -bs -rt -at -a -i 4000000:$filesize db', - 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) + 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) @@ -219,13 +219,13 @@ class TestEfiAuthVar(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) + 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'db:' in ''.join(output) output = ubman.run_command_list([ 'setenv -e -nv -bs -rt db', - 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) + 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' in ''.join(output) assert 'db:' in ''.join(output) @@ -233,7 +233,7 @@ class TestEfiAuthVar(object): # Test Case 4b, update without correct signature/data output = ubman.run_command_list([ 'setenv -e -nv -bs -rt -at db', - 'printenv -e -n -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) + 'printenv -e -v -guid d719b2cb-3d3a-4596-a3bc-dad00e67656f db']) assert 'Failed to set EFI variable' in ''.join(output) assert 'db:' in ''.join(output) @@ -253,14 +253,14 @@ class TestEfiAuthVar(object): 'setenv -e -nv -bs -rt -at -i 4000000:$filesize KEK', 'fatload host 0:1 4000000 db.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize db', - 'printenv -e -n PK']) + 'printenv -e -v PK']) assert 'Failed to set EFI variable' not in ''.join(output) assert 'PK:' in ''.join(output) output = ubman.run_command_list([ 'fatload host 0:1 4000000 PK_null.esl', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', - 'printenv -e -n PK']) + 'printenv -e -v PK']) assert 'Failed to set EFI variable' in ''.join(output) assert 'PK:' in ''.join(output) @@ -269,13 +269,13 @@ class TestEfiAuthVar(object): output = ubman.run_command_list([ 'fatload host 0:1 4000000 PK_null.auth', 'setenv -e -nv -bs -rt -at -i 4000000:$filesize PK', - 'printenv -e -n PK']) + 'printenv -e -v PK']) assert 'Failed to set EFI variable' not in ''.join(output) assert '\"PK\" not defined' in ''.join(output) output = ubman.run_command( - 'printenv -e SecureBoot') + 'printenv -e -v SecureBoot') assert '00000000: 00' in output output = ubman.run_command( - 'printenv -e SetupMode') + 'printenv -e -v SetupMode') assert '00000000: 01' in output From patchwork Thu Aug 21 15:35:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 102 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=1755790556; bh=bXCKVnnqyv0Q7jZxV+20uy1MWdJEJODIgzptNRNz2uo=; 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=RbxfJpTA3b7km6TmPP3yhaHjsu6u0XWF5FYd76f/qObk0MDUqE+Ys8xnxuODid5g8 axPpqMew85gyvNPqHxx9ufUpOHzXMQj/9SVTzdDPtBVfNFqB8esaIL18ksJcTSpJcG v2XOAJn9UrOn/j3cuqGhCUWDo2aWxfLwQW+Tg+BuPvhqG5k02WiDS3anoQc8vEMPHI N/K35JRk8gUHVPmWBFdfr3WDM11Lvdxqjttbp8LRt2UwAwUBTpKycQuETd5Sigh/Qz 51KatW0K0XgC3HcIJgLQ0HtantuabN6xxsy58yKZO5U74cy6VizD/J37Y+SzSN86Av atB1H1KAycZIw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id EC6A3676EF for ; Thu, 21 Aug 2025 09:35:56 -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 cW3ZJ7f588wM for ; Thu, 21 Aug 2025 09:35:56 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790556; bh=bXCKVnnqyv0Q7jZxV+20uy1MWdJEJODIgzptNRNz2uo=; 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=RbxfJpTA3b7km6TmPP3yhaHjsu6u0XWF5FYd76f/qObk0MDUqE+Ys8xnxuODid5g8 axPpqMew85gyvNPqHxx9ufUpOHzXMQj/9SVTzdDPtBVfNFqB8esaIL18ksJcTSpJcG v2XOAJn9UrOn/j3cuqGhCUWDo2aWxfLwQW+Tg+BuPvhqG5k02WiDS3anoQc8vEMPHI N/K35JRk8gUHVPmWBFdfr3WDM11Lvdxqjttbp8LRt2UwAwUBTpKycQuETd5Sigh/Qz 51KatW0K0XgC3HcIJgLQ0HtantuabN6xxsy58yKZO5U74cy6VizD/J37Y+SzSN86Av atB1H1KAycZIw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 4289D676DF for ; Thu, 21 Aug 2025 09:35:56 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790554; bh=46kTiSMqTosgVSS3CuLIrzDCz4Q6T2q9CZlMfVLNES4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c2+xANv6PeEwRaMn4eHCb1AiuwTm6XGdB+0lA5E2cT9leAzj0TJSxoLvl5PhUz+iR +zAjkNUMmB1bw1kUOkX7lITde7C5+1s/t0mVHjyw6FVIABkb0ZTICGjp8gl6ybmr4E mrjF871AHo+a0Z4aZAH2Fw6+8SSPHAn2Ffh3d8P6OhR+4yZcWeIeuHKAOj9FyiKaKk MDT1BE51/41ZW77186CaZKmFD6KL3L6eh7EyDls2LNLKlAfNbitaGq0WiNPIiyJ8qT cFvzpU2KuudRz47Lp5nZddQl19hmuDPlOiqCCp8sic85ttXVg74r4uBy9LBqfneowe sVPxwiOk+K7Og== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 287AB676E9; Thu, 21 Aug 2025 09:35:54 -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 LdXFc9tTWh2E; Thu, 21 Aug 2025 09:35:54 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790552; bh=PvJ+Lex+NhKNGbv+HciK9SIe4DzyJqSIvysykmkcGvA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ABeJuXFzeYbWWpaR2BZIbzzOJTFCaenHJxs/daov7Toz4wZ0UUyhFu1KzSHU10uX8 JMcb7frFpAtmN8KdnECGRBVBy7pp95+VtxT5keEsUoDcZWgfNTACNZ5QpE/B/jpM+E 2158PiepB/l+MpDDGt5dssa/S5A2zGuCE6vAlsaxiq7N42V2gUmiL2kdyv5NCzCRlf KDmg8s3afhzqmJaGtBS3CxjMFL7kftx9eAf03Ry5YF/PBRtkgNMgBOh9CGVdmlWDX7 noXma81KM0Xiwu9h+MchdfVLEZlDmgnL7iODrAS+1AzTrG2x/EvMSG2gyzyjoUMDsQ Fdu8Nu+pdHp0w== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 3416C676DB; Thu, 21 Aug 2025 09:35:52 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 21 Aug 2025 09:35:21 -0600 Message-ID: <20250821153528.141740-5-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: OZL263WTJW3CYBDC4ENEZVOUS3D4YGLU X-Message-ID-Hash: OZL263WTJW3CYBDC4ENEZVOUS3D4YGLU 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 4/7] efi: Rename var_name64 to name in efi_dump_var_all() 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 This variable name is quite long. There is only one 'name' (the variable name) and it has to be u16 as it is an EFI variable. So rename it to 'name'. Signed-off-by: Simon Glass --- cmd/nvedit_efi.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index 12c98a5d5c4..0e4abf49fc0 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -146,48 +146,47 @@ out: static int efi_dump_var_all(int argc, char *const argv[], const efi_guid_t *guid_p, bool verbose, bool nodump) { - u16 *var_name16, *p; efi_uintn_t buf_size, size; efi_guid_t guid; efi_status_t ret; bool match = false; + u16 *name, *p; buf_size = 128; - var_name16 = malloc(buf_size); - if (!var_name16) + name = malloc(buf_size); + if (!name) return CMD_RET_FAILURE; - var_name16[0] = 0; + name[0] = 0; for (;;) { size = buf_size; - ret = efi_get_next_variable_name_int(&size, var_name16, - &guid); + ret = efi_get_next_variable_name_int(&size, name, &guid); if (ret == EFI_NOT_FOUND) break; if (ret == EFI_BUFFER_TOO_SMALL) { buf_size = size; - p = realloc(var_name16, buf_size); + p = realloc(name, buf_size); if (!p) { - free(var_name16); + free(name); return CMD_RET_FAILURE; } - var_name16 = p; - ret = efi_get_next_variable_name_int(&size, var_name16, + name = p; + ret = efi_get_next_variable_name_int(&size, name, &guid); } if (ret != EFI_SUCCESS) { - free(var_name16); + free(name); return CMD_RET_FAILURE; } if (guid_p && guidcmp(guid_p, &guid)) continue; - if (!argc || match_name(argc, argv, var_name16)) { + if (!argc || match_name(argc, argv, name)) { match = true; - efi_dump_single_var(var_name16, &guid, verbose, nodump); + efi_dump_single_var(name, &guid, verbose, nodump); } } - free(var_name16); + free(name); if (!match && argc == 1) { printf("Error: \"%s\" not defined\n", argv[0]); From patchwork Thu Aug 21 15:35:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 103 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=1755790562; bh=LsQWGXMcosE1MuznhDYOxf6WOYj4HJW51iF/h9tj3ro=; 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=LDBUTJ3trfoBojp8hpkZDBHtBQ5MZ5/b1PPbngUwd489VbUGaSD6UjLHcSbtINVpN 9KE7JH3HZlO/EZ/bQ/k5Dy3tVd0l09dSlpgsiiWHK1PJhKIPdtzOP5E+Yye2O6GuJ/ RMbYSac78dkVAmOiZrZuZPHnDAZP6N6JqvA5PObV24fs6tVj288ly/VwO67TG+VTDD MU30/5riUA5eElWdcMQWZ0pbGlDbxSSEKT4X0fJuaHtLx8k9ISnSj8iD3lNEedjtq4 1EUUaILP+CSGY9UwdgBitssFb3RIQsAXDAkldrIZKtR/xopxe8FcLywG8cfnAb56BT bNHXfVUvj9Z9g== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 77622676DD for ; Thu, 21 Aug 2025 09:36:02 -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 UQBWw1ybq-_X 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=1755790562; bh=LsQWGXMcosE1MuznhDYOxf6WOYj4HJW51iF/h9tj3ro=; 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=LDBUTJ3trfoBojp8hpkZDBHtBQ5MZ5/b1PPbngUwd489VbUGaSD6UjLHcSbtINVpN 9KE7JH3HZlO/EZ/bQ/k5Dy3tVd0l09dSlpgsiiWHK1PJhKIPdtzOP5E+Yye2O6GuJ/ RMbYSac78dkVAmOiZrZuZPHnDAZP6N6JqvA5PObV24fs6tVj288ly/VwO67TG+VTDD MU30/5riUA5eElWdcMQWZ0pbGlDbxSSEKT4X0fJuaHtLx8k9ISnSj8iD3lNEedjtq4 1EUUaILP+CSGY9UwdgBitssFb3RIQsAXDAkldrIZKtR/xopxe8FcLywG8cfnAb56BT bNHXfVUvj9Z9g== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 62A955FC74 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=1755790559; bh=9QUOWqx9c9LAN/vTAsdcyY6H3dzaOhZ69ok+Ilm71e4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IvwrFTIk2Q/ND2tz7t2nzbgd7mGGmy/5CusQ7eTtgCDQBxMJMJcbuNO8E/KBeTZMG eoCMSBtdKAaH+mo/9Zk5GuAV1xxtXGTKznzIGJ0HOKQHWFaYwZ9H3kd7Jp6+xI5xxh E+1qYnRJqx3gjVvFf3pXZzhAdL7ITNf4Hi3ID3igBtJ95w2uHnPGCogbL5AOwVyMHI AZ8wqCbJi+fmQ/p3jZ98yCXDeq8jtYEcaYS8wkBTBQhCFAZlN6jzcRmMKPqp5/HeV0 QMPCFvH5tUb2ne5LmmBYx2QHTLUZO+9NcREiqg082LnjeguWModw8i/vkw8ggCMP2a 9Ska0SA4vPsQQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 457775FC74; Thu, 21 Aug 2025 09:35:59 -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 JiSW_CuUOFU1; Thu, 21 Aug 2025 09:35:59 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790553; bh=dOqAl8rBnKGGCUzItMCfMXBqi9FSQnB+Wk55ISz4Wuw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=INS1+WyVAkBIpJi1KPjiSEth/qVvvLqIsYgA1HRhn14Yjxn80nOzaszxELqZo//5I y0sq+RGPTqIGo2LvzNT9bVdVVsI+Obgp6XYNL2Rj8poxB5gnJyTdoQoasR2nWKXNro xfGVNVi0xWkmxL8rHdWiqPZclGEn79NyZYUrKYFPUz/XLl3EFzQ1xHJLjNIVYmYCNH q17SAvjtt/vxnWucU3+HR43kRjz84tiEqusljZYV6RZbHPvKkdNkgUnie7FXbXUAl8 6vqtagM/blXUslGvGAuXDiigY1Q5bAkbrPmfszIGiciFOdXfD5asn8sEN0wD2EcwiA F3PbV6ajxSDLg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id A8370676DD; Thu, 21 Aug 2025 09:35:53 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 21 Aug 2025 09:35:22 -0600 Message-ID: <20250821153528.141740-6-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: BAKSWAWD3RGTHXVUIKX4TNNBAZMKD2UH X-Message-ID-Hash: BAKSWAWD3RGTHXVUIKX4TNNBAZMKD2UH 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 5/7] efi: Refactor error handling in efi_dump_var_all() 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 freeing the variable in several places, put it at the end. Assume failure by default, returning success only if all steps passed. Signed-off-by: Simon Glass --- cmd/nvedit_efi.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index 0e4abf49fc0..f2bba42850d 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -150,6 +150,7 @@ static int efi_dump_var_all(int argc, char *const argv[], efi_guid_t guid; efi_status_t ret; bool match = false; + bool ok = false; u16 *name, *p; buf_size = 128; @@ -166,18 +167,14 @@ static int efi_dump_var_all(int argc, char *const argv[], if (ret == EFI_BUFFER_TOO_SMALL) { buf_size = size; p = realloc(name, buf_size); - if (!p) { - free(name); - return CMD_RET_FAILURE; - } + if (!p) + goto fail; name = p; ret = efi_get_next_variable_name_int(&size, name, &guid); } - if (ret != EFI_SUCCESS) { - free(name); - return CMD_RET_FAILURE; - } + if (ret != EFI_SUCCESS) + goto fail; if (guid_p && guidcmp(guid_p, &guid)) continue; @@ -186,14 +183,18 @@ static int efi_dump_var_all(int argc, char *const argv[], efi_dump_single_var(name, &guid, verbose, nodump); } } - free(name); if (!match && argc == 1) { printf("Error: \"%s\" not defined\n", argv[0]); - return CMD_RET_FAILURE; + goto done; } - return CMD_RET_SUCCESS; + ok = true; +fail: +done: + free(name); + + return ok ? 0 : CMD_RET_FAILURE; } /** 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; } From patchwork Thu Aug 21 15:35:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 105 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=1755790568; bh=DWU4L4ZJivh11VfEh0+sJBR1Hnj4ATE8c895zPnjcjk=; 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=ftNDam/j8JtUnXbm2EG/lO5nydqsxJeGgFEyg87o6ECSl+vz6DDDZ5Vl4wXQsWlOI cy1WdQxfCXn0CN96PUYGKrBtRRXESU8Y3laiZJDZ3Uvf02j4mM8LbG4QyN1PjIB18V UZ6NQ6U1572g7TLvq75V9Juzq9tLRem48+wZh071CQMKmXgPe8OVmEJ281IEjhUwm3 nQ8YJOtftG4mtaA6bYdxKFWqkeXnRrpF0SHgtcfhUAIEA6WofcLrFBzy84Zk5/z/c1 DUgKXSYjNyVvXf8gnuI1aNR6yhJUgfQLgWOkf37hwbJCaQveO5Je9BOtcVs2Sj2iv6 2C2DAxsHmVBbQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7767867533 for ; Thu, 21 Aug 2025 09:36:08 -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 lJQZMRuzBamE for ; Thu, 21 Aug 2025 09:36:08 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790568; bh=DWU4L4ZJivh11VfEh0+sJBR1Hnj4ATE8c895zPnjcjk=; 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=ftNDam/j8JtUnXbm2EG/lO5nydqsxJeGgFEyg87o6ECSl+vz6DDDZ5Vl4wXQsWlOI cy1WdQxfCXn0CN96PUYGKrBtRRXESU8Y3laiZJDZ3Uvf02j4mM8LbG4QyN1PjIB18V UZ6NQ6U1572g7TLvq75V9Juzq9tLRem48+wZh071CQMKmXgPe8OVmEJ281IEjhUwm3 nQ8YJOtftG4mtaA6bYdxKFWqkeXnRrpF0SHgtcfhUAIEA6WofcLrFBzy84Zk5/z/c1 DUgKXSYjNyVvXf8gnuI1aNR6yhJUgfQLgWOkf37hwbJCaQveO5Je9BOtcVs2Sj2iv6 2C2DAxsHmVBbQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 65434676C4 for ; Thu, 21 Aug 2025 09:36:08 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790567; bh=pLSfVpIawQuFanVmzMr1aGhZRcVIkGJryUPSYgFGbaM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n1fOFoZvfsAQF6lq+Gr8irXxZDSokRzudObCOzLbWSoDw6DN8LgF3QBBEvxqX9sUl z4st1h4XxBwwEW/h/dElSMQi+VQTUcrDxLDWzUMHdBRfWGojQcLTqimDsz1tgYE4NQ PHEF2xc33Qag1KFT3JrcaLqT8R+6iQRqwMxpZb0fF77sbEebgaeJ1O6aKAdq94cYnj ihFV4ixAFT7VpOHQp5h7lYad9uDeQ5vJBr40l1Ew0bKQsCz3TnlJ1woi/qvacy6BeK f/FJnGsIAgT98E6dmZCAw5NLIITiC8IFL9ya3XwzEhJYxNjWbDejUerhihrEmfhFDc VvTeGgcx770wQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 201C05FC74; Thu, 21 Aug 2025 09:36:07 -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 uWBLg6z3Kk5m; Thu, 21 Aug 2025 09:36:07 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755790560; bh=IUo4mOV2VkDevsd5ymCEaHc7ywhZcgRL0VVW6ZWx0/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JC5Ki5dA38uCRLY4hDrn7Ffdn3yzbvz2PfowchGxn5RZ0x8bFkHLkD1w3TrDqrTpa V8mKznj/suJDjKSSMEGGlzN6c6/oOaY8Dy7n/CA9vO+knxzirKgsw7nqHTblsuU100 6Zo3qe4DvKh1BV+CJSVHtu3Awc8ZGMCIjD5++D8hvzA+Gg6aq4aKvY3PHEG3JJieDS 0cQ1DKvsiuqVF8WZdlDn3PWsGyT/sx6EHNc6Ss4s0QLvmzrya25rKDo+WU2yQBrO3H feC+CUjsawZp4hArmWX2Ilf9QT4DFt1PQVrb6IIWKiT7N6b1Pldyj8oW/PZn2+rjV0 FP8VgqCu+vqzw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 59E0B5FC00; Thu, 21 Aug 2025 09:36:00 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Thu, 21 Aug 2025 09:35:24 -0600 Message-ID: <20250821153528.141740-8-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: LZL3ODZIAOVG4Z5JU7AUJ65XFTIPTOOP X-Message-ID-Hash: LZL3ODZIAOVG4Z5JU7AUJ65XFTIPTOOP 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 , Claude X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 7/7] cmd: Add -s flag to printenv -e for sorted output 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 Add support for sorting EFI variables by name when using printenv -e. The -s flag sorts variables alphabetically before display, useful when dealing with large numbers of variables. Co-developed-by: Claude Signed-off-by: Simon Glass --- cmd/nvedit.c | 5 +-- cmd/nvedit_efi.c | 31 +++++++++++++++-- doc/usage/cmd/env.rst | 4 ++- doc/usage/cmd/printenv.rst | 68 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 99 insertions(+), 9 deletions(-) diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 8dbe8a03fd5..f67c268da84 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -1174,7 +1174,7 @@ U_BOOT_LONGHELP(env, #endif "env print [-a | name ...] - print environment\n" #if defined(CONFIG_CMD_NVEDIT_EFI) - "env print -e [-guid guid] [-n] [-v] [name ...] print UEFI environment\n" + "env print -e [-guid guid] [-n] [-s] [-v] [name ...] print UEFI environment\n" #endif #if defined(CONFIG_CMD_RUN) "env run var [...] - run commands in an environment variable\n" @@ -1221,10 +1221,11 @@ U_BOOT_CMD_COMPLETE( "print environment variables", "[-a]\n - print [all] values of all environment variables\n" #if defined(CONFIG_CMD_NVEDIT_EFI) - "printenv -e [-guid guid][-n] [-v] [name ...]\n" + "printenv -e [-guid guid][-n] [-s] [-v] [name ...]\n" " - print UEFI variable 'name' or all the variables\n" " \"-guid\": GUID xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n" " \"-n\": suppress dumping variable's value\n" + " \"-s\": sort variables by name\n" " \"-v\": show GUID, flags, size; also dump (without -n)\n" #endif "printenv name ...\n" diff --git a/cmd/nvedit_efi.c b/cmd/nvedit_efi.c index ce3ab9f785a..5616e73bcfd 100644 --- a/cmd/nvedit_efi.c +++ b/cmd/nvedit_efi.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -142,6 +143,21 @@ out: return result; } +/** + * var_info_cmp() - compare two var_info structures by name + * + * @a: First var_info structure + * @b: Second var_info structure + * Return: comparison result for qsort + */ +static int var_info_cmp(const void *a, const void *b) +{ + const struct var_info *va = a; + const struct var_info *vb = b; + + return u16_strcmp(va->name, vb->name); +} + /** * efi_dump_var_all() - show information about all the UEFI variables * @@ -150,12 +166,14 @@ out: * @guid_p: GUID to filter by, or NULL for all * @verbose: if true, show detailed information * @nodump: if true, don't show hexadecimal dump + * @sort: if true, sort variables by name before printing * Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE * * Show information encoded in all the UEFI variables */ static int efi_dump_var_all(int argc, char *const argv[], - const efi_guid_t *guid_p, bool verbose, bool nodump) + const efi_guid_t *guid_p, bool verbose, bool nodump, + bool sort) { efi_uintn_t buf_size, size; struct var_info *var; @@ -209,6 +227,9 @@ static int efi_dump_var_all(int argc, char *const argv[], goto done; } + if (sort && vars.count > 1) + qsort(vars.data, vars.count, sizeof(struct var_info), var_info_cmp); + alist_for_each(var, &vars) efi_dump_single_var(var->name, &var->guid, verbose, nodump); @@ -233,10 +254,11 @@ done: * Return: CMD_RET_SUCCESS on success, or CMD_RET_RET_FAILURE * * This function is for "env print -e" or "printenv -e" command: - * => env print -e [-v] [-guid | -all] [var [...]] + * => env print -e [-v] [-s] [-guid | -all] [var [...]] * If one or more variable names are specified, show information * named UEFI variables, otherwise show all the UEFI variables. * By default, only variable names are shown. Use -v for verbose output. + * Use -s to sort variables by name. */ int do_env_print_efi(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -245,6 +267,7 @@ int do_env_print_efi(struct cmd_tbl *cmdtp, int flag, int argc, efi_guid_t guid; bool verbose = false; bool nodump = false; + bool sort = false; efi_status_t ret; /* Initialize EFI drivers */ @@ -270,13 +293,15 @@ int do_env_print_efi(struct cmd_tbl *cmdtp, int flag, int argc, nodump = true; } else if (!strcmp(argv[0], "-v")) { verbose = true; + } else if (!strcmp(argv[0], "-s")) { + sort = true; } else { return CMD_RET_USAGE; } } /* enumerate and show all UEFI variables */ - return efi_dump_var_all(argc, argv, guid_p, verbose, nodump); + return efi_dump_var_all(argc, argv, guid_p, verbose, nodump, sort); } /** diff --git a/doc/usage/cmd/env.rst b/doc/usage/cmd/env.rst index a1d90c6fca3..c96dd038f02 100644 --- a/doc/usage/cmd/env.rst +++ b/doc/usage/cmd/env.rst @@ -25,7 +25,7 @@ Synopsis env info [-d] [-p] [-q] env load env print [-a | name ...] - env print -e [-guid guid] [-n] [-v] [name ...] + env print -e [-guid guid] [-n] [-s] [-v] [name ...] env run var [...] env save env select [target] @@ -233,6 +233,8 @@ in UEFI variables. with guid format = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx". \-n don't show hexadecimal dump of value for UEFI variables. + \-s + sort UEFI variables by name before displaying. \-v show verbose output for UEFI variables including GUID, attributes, data size and hexadecimal dump of value. diff --git a/doc/usage/cmd/printenv.rst b/doc/usage/cmd/printenv.rst index cecfcf8bcda..5ba3a6e63f7 100644 --- a/doc/usage/cmd/printenv.rst +++ b/doc/usage/cmd/printenv.rst @@ -12,7 +12,7 @@ Synopsis :: printenv [-a] [name ...] - printenv -e [-guid guid][-n][-v] [name] + printenv -e [-guid guid][-n][-s][-v] [name] Description ----------- @@ -32,6 +32,9 @@ The printenv command is used to print environment or UEFI variables. \-n don't show hexadecimal dump of value +\-s + sort variables by name before displaying + \-v show verbose output including GUID, attributes, data size and hexadecimal dump of value (if not -n) @@ -71,7 +74,8 @@ environment variables: The next example shows the different output modes when displaying UEFI variables and how to specify a vendor GUID. By default, only the variable name is shown. The *-v* flag shows full verbose output, while *-n* shows -details but omits the hexadecimal dump: +details but omits the hexadecimal dump. The *-s* flag sorts variables by +name: :: @@ -86,7 +90,65 @@ details but omits the hexadecimal dump: 8be4df61-93ca-11d2-aa0d-00e098032b8c (EFI_GLOBAL_VARIABLE_GUID) BS|RT|RO, DataSize = 0x6 00000000: 65 6e 2d 55 53 00 en-US. - => + => print -e -s + 525400123456 + 525400123456 + Attempt 1 + Attempt 2 + Attempt 3 + Attempt 4 + Attempt 5 + Attempt 6 + Attempt 7 + Attempt 8 + Boot0000 + Boot0001 + Boot0002 + Boot0003 + BootCurrent + BootOptionSupport + BootOrder + ClientId + ConIn + ConInDev + ConOut + ConOutDev + ErrOut + ErrOutDev + HDDP + InitialAttemptOrder + Key0000 + Key0001 + Lang + LangCodes + MTC + MemoryTypeInformation + OsIndicationsSupported + PlatformLang + PlatformLangCodes + PlatformRecovery0000 + SbatLevel + Timeout + VarErrorFlag + cat + cd.. + cd\ + copy + debuglasterror + del + dir + lasterror + md + mem + mount + move + nonesting + path + profiles + ren + uefishellsupport + uefishellversion + uefiversion Configuration -------------