From patchwork Wed Aug 20 00:40: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: 46 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=1755650483; bh=YMV8j+n+4E0aZt5bHEi6i94hW1famMi2hHCq/XZBTMg=; 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=g/mylgg0Y8P/WxVCk5fSYmO3OpMajLA13NoDlD+LZr9qzpFKR2TRMLuYnShX7r4O7 i+ASAdztL8TtxFkuHjuCpcVRmJiMnyDadrioEZ5YBrzZZXoevYf0KfXxMRq1L9BAKG 2+Fj1PH3+5VnOOie5mW/qj8lByCMkd5ZcA8VSf9VRinpqRlifPGdhMx4VV1806IRjy I2xT7M3u/9LOvF+qx9WCKnCfICmBc1dww6qpkSk62J19M4uqlmYYMHhgkVwTGO/hMB pkT5SUBknkQqkt0CSAcmOUGJ+22w5EJGLLYBrb9e2fLqEQPVAEu3JXyJdKKgyxTTiy UnneeRoAO/JSQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id C4C7567659 for ; Tue, 19 Aug 2025 18:41:23 -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 x59tr0DW78OA for ; Tue, 19 Aug 2025 18:41:23 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755650482; bh=YMV8j+n+4E0aZt5bHEi6i94hW1famMi2hHCq/XZBTMg=; 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=DRQRo5qzszmmQ5L3fWDiVDcI/LioEOloth11/Q/A3WvVCrhUo3k4pQ7rF9j0ujQYP 4s2ecrUZz/94gqN2kIig59wQBk6kxcAIfoskAnw+ZZ6aGjbvD/8ggXflY3B884iJEE yRkh5Y+Q4y5LXmAToWNApR04mBTPUnqKiVpHq0mY3qU54EES2SNr3Bi/MKs45jrBEP Hw/+6JFfS3Npr+uJpRWI6ibvBVpDHChxMujnsZPuAH+QOuPE4MeJCuar4qIdVTW9oU v8cnw5LKDlFEHHih6mI/z/iQUeqHrY49LteluoctLNnEbZ/vLUf4wH684bdJ3hguoI rAmWq1eFQdwIw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id B9DD467660 for ; Tue, 19 Aug 2025 18:41:22 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755650479; bh=QOoeHXyKSzdZntULICKDQtphcnot/aY3f7RwNRn6AJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qQVmmW1GFVTG6UwigzVTq9RT9rKRy48dt0D+b108GbyaBMuTHG+x/FMvOp2jeCIfz HMCHlR1lyvheQwtYdd4bLo9bmspM4aj4XJ1qwMj4oJlWXuQAFW5WU0bvJLYVmaOt3A VbYoVZsJRXxtUI/VrCmcw73aJYSzRie00CmJLcLmjjX5dXYD0mORJChtLqgly0UUwM SBpUOIA/Q3WxGGvEp6xEl9Xzlx66FKBZdU0z8NwqVxzd6uJ7n3Z/MT3LBopFpk0xZx +oYAiFO3S0L83SvzVWLvEKsKmv++ECUOsrnxkAf8s/3nxd0kYM7m9iIb/GEF8uAYP7 Ase28LinWiBVA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 025506765D; Tue, 19 Aug 2025 18:41:19 -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 d_PY8Pzd2CMs; Tue, 19 Aug 2025 18:41:18 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1755650478; bh=f+jRJaW/lujFvdA+4MrE2EZGV8r6BTbje20isVhcoHs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mZIX+DKnBCtJfZ/h+CVCi9CrNROvhZ9XANOqXBEOJO3/UKm7NO/0A7aW7WR+TbBHe 4QiFCDP2PEaW5B8aR7Q/JxuJPvv5zeC0TiDulilkRDEgRnJPEbyqSmkVorjEsk2Mbu leKEH6vySBsVAkb3DWALQDEEYqsXSlGcXo97i6ckl9BS25clJLip4DYKxsPYOUgv6s S1TxNBH4xpZuyWGX8KqsB/ipfK9c8+Z8zQsciyL+0O3qbFCYatJ+Uog0fwdghOFJJk ei330+swuUNxRY4B9rqPecWCBBDLHg5sv1sq2C2t6Ot/x5TsOUYMqtrU0kb5iBOzZr KLfdUkweNHC7g== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 17DFD67650; Tue, 19 Aug 2025 18:41:18 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Tue, 19 Aug 2025 18:40:22 -0600 Message-ID: <20250820004039.3920254-9-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250820004039.3920254-1-sjg@u-boot.org> References: <20250820004039.3920254-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: MMJVJTVEMNQX2QOYQHLWJEA3PDYA7LLE X-Message-ID-Hash: MMJVJTVEMNQX2QOYQHLWJEA3PDYA7LLE 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 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 --- 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 *