From patchwork Wed Aug 20 11:23: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: 64 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=1755689061; bh=eiDgq/Go2O2H4VF574q2Nc5WX1EzG+84/W9NoWicG8k=; 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=PHTDe4AbZ35hQxpWDgusbQl1dvVnOhhd37TCuG6newGdMPihnJgz2V6ZiXSa7tNXT 7M3E5cIMHD7P2QIC44LXxQCN8ae7PlOHK4NraberwleU5eWl8UmWLCaTfUImFgNlCX 0EZ7M4zAq2okdBKXaPdPlIlHvCn9U4KK9kJu/HrHW9HdDNEsqqZVQC0t1gTydHKwOS AXHgMLBPAXAuxxTlUKcaoTWdXTrU3MMDU0KCbgTzyr2GAXExGE3RVt3ZXKm9D82Jvv ExxtCghKvIYTgu3ks0nLXQ8MDAZgWE5xU4tEamWbel4DxvncLhGgmhTKlpnixgz6sL etckgL1auqNdA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 6071667681 for ; Wed, 20 Aug 2025 05:24:21 -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 eFROaR_ww_D0 for ; Wed, 20 Aug 2025 05:24:21 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755689057; bh=eiDgq/Go2O2H4VF574q2Nc5WX1EzG+84/W9NoWicG8k=; 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=GHYt+wCN59V12u6wVi/4+eDGNTeFrQoxnXAKA/agMY6bpf4cq4FE6NUx9cUdOnNaS tlijGlJdJhR0+M9Pg+sBGLskPJGTHbHW3UCsFPx8olTNHp/cLYqnoyaJIfeFTz5OBr Xv3yK7WA/ZX8EdToEUCxZHB/7XVsQsRQ4AWpG0+84a5AdwKj0zRx+UKp08tjWYAG0C uokkb54ePlJ8VJY150Dx0tHVlTNfSuLMeWhsB8UF3Afsas+TCz0cAX+qAI1ZMEFMS6 +FXhnep+wJcn7GYNjZ8zdov/9InAhN0E4g4VrcAXxHCwEXn7IsUxYG/MPwR2+OPhAF RF35cTAWbb1nQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AB9AE67685 for ; Wed, 20 Aug 2025 05:24:17 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755689054; bh=U6LxrGBguOKhvOngbDpFNFEyA6tkzz77PzVbV2SCO1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hU7rQexgAeohN7/ik0oG/oE6mECm9Sh/KO1USpjcgcL0zjcSQi7+kYQMK3AeuLXx8 vsA+Eob8agnVJ8D/tfV/ndw4U/vhQHOTRJ8tXtXW4p/UTen7cor2OjcXfQzQO8/ecY Y0jQfwYWAdaooRfW6tqs2tcBZWyl7/dT+zl1gBLNSQe3kEekhZEkEg/PhVwHg0lH9e 3C8MIpj8mVq4TsNKmIh69S4ctrITJlNNTPJ8RnugieFwXP9bQV3aCrJH/57OmrWz7r 0vZk4gaLd8EavV5lDxcQaQXnxqmB61jnfQu2jRtvnf1IOH34bA93Hyp0Gme/Te7fAf YmusexFo3dX9w== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 54B566766B; Wed, 20 Aug 2025 05:24:14 -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 VAMPfcv1xZXy; Wed, 20 Aug 2025 05:24:14 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755689051; bh=r2S1wS33XRCdSfKn8e/EGs2DLXZSNSzhdTSkgHzysr4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mfw4b+/xJjZcWPz9om+OVS/p23ho0eN9eo8krQYwH5+OCjgjrCySbGRApECMbj9gN Pk/VmtPLF0IadCpaRebtpbV0+VXPUi1pEnspJXCHqQTnxyqRFhw3YuQOkq7+qOAD4A gnDLgM3bS6xqMHcoMz/5cIj/XDDYnAZGzCr5T+gR1/O7KVJZEHVzdu2wMHYSx0BAyK obL4JzWYAn3fumJ3/QZudugET7T5Zfgp2xc0p9bCt2i5uVrqFID0aJgqKrCqpp/fxW cSERQE+1wtrixykOHCWN401+f6kT0WkKS1wzG6IuXCKJnBZjff6C5ThbvjAs6JCBv+ Qt4WTPu78HlVA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 645DA6768D; Wed, 20 Aug 2025 05:24:11 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 20 Aug 2025 05:23:20 -0600 Message-ID: <20250820112340.147082-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250820112340.147082-1-sjg@u-boot.org> References: <20250820112340.147082-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: AVJ7OY4VAB3C3GD26IJ5FEWBOXOBFEBE X-Message-ID-Hash: AVJ7OY4VAB3C3GD26IJ5FEWBOXOBFEBE 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 v2 08/18] efi: Move a few helper functions into the common efi/ dir 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 Checking if a variable is a load option is useful for the app, so move efi_varname_is_load_option() and u16_tohex() into a new helper.c file. Signed-off-by: Simon Glass --- (no changes since v1) lib/efi/Makefile | 1 + lib/efi/helper.c | 42 +++++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_helper.c | 33 ----------------------------- 3 files changed, 43 insertions(+), 33 deletions(-) create mode 100644 lib/efi/helper.c diff --git a/lib/efi/Makefile b/lib/efi/Makefile index 213c9910b39..a31caf1fce9 100644 --- a/lib/efi/Makefile +++ b/lib/efi/Makefile @@ -5,5 +5,6 @@ obj-y += basename.o obj-y += device_path.o +obj-y += helper.o obj-y += memory.o obj-y += run.o diff --git a/lib/efi/helper.c b/lib/efi/helper.c new file mode 100644 index 00000000000..34cf3f49f95 --- /dev/null +++ b/lib/efi/helper.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020, Linaro Limited + */ + +#define LOG_CATEGORY LOGC_EFI + +#include +#include + +static int u16_tohex(u16 c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + if (c >= 'A' && c <= 'F') + return c - 'A' + 10; + + /* not hexadecimal */ + return -1; +} + +bool efi_varname_is_load_option(u16 *var_name16, int *index) +{ + int id, i, digit; + + if (memcmp(var_name16, u"Boot", 8)) + return false; + + for (id = 0, i = 0; i < 4; i++) { + digit = u16_tohex(var_name16[4 + i]); + if (digit < 0) + break; + id = (id << 4) + digit; + } + if (i == 4 && !var_name16[8]) { + if (index) + *index = id; + return true; + } + + return false; +} diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 82e0fd7b069..56ea7d1c7d9 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -241,39 +241,6 @@ int efi_unlink_dev(efi_handle_t handle) return 0; } -static int u16_tohex(u16 c) -{ - if (c >= '0' && c <= '9') - return c - '0'; - if (c >= 'A' && c <= 'F') - return c - 'A' + 10; - - /* not hexadecimal */ - return -1; -} - -bool efi_varname_is_load_option(u16 *var_name16, int *index) -{ - int id, i, digit; - - if (memcmp(var_name16, u"Boot", 8)) - return false; - - for (id = 0, i = 0; i < 4; i++) { - digit = u16_tohex(var_name16[4 + i]); - if (digit < 0) - break; - id = (id << 4) + digit; - } - if (i == 4 && !var_name16[8]) { - if (index) - *index = id; - return true; - } - - return false; -} - /** * efi_next_variable_name() - get next variable name *