From patchwork Fri Apr 26 14:13:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1928203 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=lbfhZFz7; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VQvq21vVYz1yZx for ; Sat, 27 Apr 2024 00:14:06 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5BCA1885BC; Fri, 26 Apr 2024 16:13:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com 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=canonical.com header.i=@canonical.com header.b="lbfhZFz7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EB8BF885B4; Fri, 26 Apr 2024 16:13:51 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 58047885A3 for ; Fri, 26 Apr 2024 16:13:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id CAAFB3FE5F for ; Fri, 26 Apr 2024 14:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1714140827; bh=RYQWPn5AeJUd8lxUKHzYcdEuDE0zU69ZgxrUmc6ri9Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lbfhZFz7yDIt0bd5V0ri/T8/T43HgFtNktVJBHsLfJWLNs8/WvMWpx2UKygFuJihp mRNfkVu5R8ukbeS50cvMOtqMemg4WehdkftgAaf41X5elJiAiMHqUmyyB//zglIElc AZDjLvdXDy+5ooP3WBnnsHXG5N1brjl55xNKjqKt5K6BOPGQySJ4fGTYxpHQRJvP+d 8Upfez+XRF/cUQXYKiiuVQ0zcbOJiZQbRsaWKyYL9isph2iYmSv1m2j4gjGYN7n1O7 J7WvwXdcFbdNqTHV/UDHw6KvKudIkDBYxHbnw9R12WrOklnbU3678aKUCl0vL516sO 22qCZa/bMvSyw== Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-34a49f5a6baso1867451f8f.3 for ; Fri, 26 Apr 2024 07:13:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714140827; x=1714745627; h=content-transfer-encoding:mime-version: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=RYQWPn5AeJUd8lxUKHzYcdEuDE0zU69ZgxrUmc6ri9Q=; b=bj46XxUfa3FXgmf/cgQtJ8DNRUEDgxCV0YY9UrwvJWlywLZWk45X5RD42A52KnNuZV i444+NMKLbqL0CO0TOxU/sDM8NPha5UILpGiNFX1XVXp9Y0T/iLKB+DW0itJRFC664WP Qe/82q1BaiUIUJ0oCBd1bSgGAbdoeLO3X2IDYOrLKJX4IKxieXmCXNhsxN5NI7GiiCpw TQxDRHRvC3Wk+JfsHZ/Ow3yQ/FOQrxFxmtlEs4jl4NxjdiroQYupO1jeFSBlEO/tWirT tneoE4ZxLIcFNNSSaC1K5PFx0b+wI9UcST+gs7uLtJwdaN2AOI5BEYcAhSUXGRe1ixa5 Bwjg== X-Forwarded-Encrypted: i=1; AJvYcCW8EzTN6DIbwYeH2tlVuKy5NiJ44asjKU7gyzdcuwNd/UjIR80MKabVyfObzLb3IDccwDGNanmblzxJKaj0SbDISht81g== X-Gm-Message-State: AOJu0Yx95kg6dvVrf0gqyCHZGW5RB1QJn5/hqUl4M/E2sBRuOw+FL/cW JkLFdbIaLDicOGOZQOVIWk0QePn1cUYGR/55u4TXUhbgffYmccAR6M83qpdtIbqR04133qFidGD IUBFW+hYiFPtu7+pZE4poO68ttdOHv04UiRAteD2fEmuzHIhDTITn42HFQLZX8RDZHfg= X-Received: by 2002:a05:6000:174e:b0:34b:4d4e:c67a with SMTP id m14-20020a056000174e00b0034b4d4ec67amr2213812wrf.66.1714140827010; Fri, 26 Apr 2024 07:13:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyiPjDlX1B9Ap5MHDLkWInQLOBv2D0DbN3Z8MdMWyErCFWxLnV40lAeSrCVkz0a8hJxzqJKg== X-Received: by 2002:a05:6000:174e:b0:34b:4d4e:c67a with SMTP id m14-20020a056000174e00b0034b4d4ec67amr2213795wrf.66.1714140826700; Fri, 26 Apr 2024 07:13:46 -0700 (PDT) Received: from workstation5.fritz.box (ip-062-143-245-032.um16.pools.vodafone-ip.de. [62.143.245.32]) by smtp.gmail.com with ESMTPSA id s20-20020adfa294000000b003455e5d2569sm1460593wra.0.2024.04.26.07.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 07:13:46 -0700 (PDT) From: Heinrich Schuchardt To: Ilias Apalodimas Cc: Simon Glass , Tom Rini , Shantur Rathore , Bin Meng , AKASHI Takahiro , Masahisa Kojima , Raymond Mao , Mark Kettenis , Joao Marcos Costa , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [RFC 01/14] efi_loader: pass GUID by address to efi_dp_from_lo Date: Fri, 26 Apr 2024 16:13:08 +0200 Message-ID: <20240426141321.232236-2-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426141321.232236-1-heinrich.schuchardt@canonical.com> References: <20240426141321.232236-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean We should not pass GUIDs by value as this requires copying. Signed-off-by: Heinrich Schuchardt Reviewed-by: Ilias Apalodimas --- include/efi_loader.h | 2 +- lib/efi_loader/efi_helper.c | 4 ++-- lib/efi_loader/efi_load_initrd.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 69442f4e58d..9600941aa32 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -743,7 +743,7 @@ efi_status_t EFIAPI efi_register_protocol_notify(const efi_guid_t *protocol, efi_status_t efi_file_size(struct efi_file_handle *fh, efi_uintn_t *size); /* get a device path from a Boot#### option */ -struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid); +struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t *guid); /* get len, string (used in u-boot crypto from a guid */ const char *guid_to_sha_str(const efi_guid_t *guid); diff --git a/lib/efi_loader/efi_helper.c b/lib/efi_loader/efi_helper.c index 6918fd5e48a..c5d13c0f19c 100644 --- a/lib/efi_loader/efi_helper.c +++ b/lib/efi_loader/efi_helper.c @@ -72,7 +72,7 @@ out: * * Return: device path or NULL. Caller must free the returned value */ -struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid) +struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t *guid) { struct efi_load_option lo; void *var_value; @@ -92,7 +92,7 @@ struct efi_device_path *efi_get_dp_from_boot(const efi_guid_t guid) if (ret != EFI_SUCCESS) goto err; - return efi_dp_from_lo(&lo, &guid); + return efi_dp_from_lo(&lo, guid); err: free(var_value); diff --git a/lib/efi_loader/efi_load_initrd.c b/lib/efi_loader/efi_load_initrd.c index 67d1f75d525..d91135436c4 100644 --- a/lib/efi_loader/efi_load_initrd.c +++ b/lib/efi_loader/efi_load_initrd.c @@ -63,7 +63,7 @@ static efi_status_t get_initrd_fp(struct efi_device_path **initrd_fp) * We can then use this specific return value and not install the * protocol, while allowing the boot to continue */ - dp = efi_get_dp_from_boot(efi_lf2_initrd_guid); + dp = efi_get_dp_from_boot(&efi_lf2_initrd_guid); if (!dp) return EFI_INVALID_PARAMETER; From patchwork Fri Apr 26 14:13:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1928205 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=ALHL9ypj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VQvqR2JDSz1yZx for ; Sat, 27 Apr 2024 00:14:26 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1FC0C8863E; Fri, 26 Apr 2024 16:13:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com 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=canonical.com header.i=@canonical.com header.b="ALHL9ypj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 63CEC885BE; Fri, 26 Apr 2024 16:13:53 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 746EB8857C for ; Fri, 26 Apr 2024 16:13:51 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id D27443F8DF for ; Fri, 26 Apr 2024 14:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1714140828; bh=kHme1oKORNvND9fAuaPL5yDjhH0XVg0WgDGvImvhoac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ALHL9ypjFS4Av+Ey4AV8byIYJ3mbR+lRDH5WUomfhqMDFaWwK5olyqfXXzUxn4bYM Ki7aLNZPUGodVnXBqO8bOhQzTLDkULqy24fJ3auUcHAQrWUViJDwu9670L1tWW0DZO AljjMGB7kj/x4iQaOKuAqTORj4YZsCdUG58N8rfz0gkMCsfyxC+AvUUcEaiaDgzBrc uz1Z0VmrFHK/wvlQIyxzx9ApEwfkQgbe+KWnMt7eLOMgtzIRRvjQJpYgZw7s0zRBBm upSJdCuwacgvqrC1qKu1CTeHgsYyfWjAT7QeC7yZxb4u0JqPHRqzEi7Jllz8Za4q0u 1ziywTb/yo0QQ== Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-343f8b51910so1290043f8f.3 for ; Fri, 26 Apr 2024 07:13:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714140828; x=1714745628; h=content-transfer-encoding:mime-version: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=kHme1oKORNvND9fAuaPL5yDjhH0XVg0WgDGvImvhoac=; b=vzX3sCRVs0nzqMCTzJSMafusFxxlYtzHdN9EBqD9Rcv4iOWNqaDb7O5hhGKr1R1geh kBoLgvCmvY+YvoGaDqMBYAeQBWga7/evZ3Xr9oKlfMTJN1ft5Zo47Xe+poP0e+J5V9k9 7NHNLXmpDe1joiQbsxC3qiddMykui8Jq4dFTuiIXqPtXJ+zqoBWoKhMbvwct5BndbRD+ JwEh5lZ+pkLHldLEI5/LghnwLkQ2dtXhUtpEu1flKpF3XfvFAJVsQ2wZ97NzJvI0icv4 Nw3StHXO87HeVRQCtwJ20TN6dVZxA/E4qjJjW33sUcllHqr1kqxJCOVjcIpfd73K9bmu 0HaA== X-Forwarded-Encrypted: i=1; AJvYcCVAis+itJFrXenMut18GtcVD9DgLIVJAMP16jlk5hBSfudtr12bJ/nEPdbreN5BRXJXA3p0dCX0md7jx6WTGdA5M1QDOg== X-Gm-Message-State: AOJu0YxPDPD39oDTzCNoaE1c1VXSimYJDu0ZC6GytTdNn+gWSCLcV4Ui tA4fTd8qWf04Afsr3/C6LeuOLdzI6wnW+/BALtMbPKyEfzRK7k0mOXWBeLZro5ot3ZNxw9CccSj iFoExMbPUjmmZldMJMaOU6ISJfImqAkGHLCh2myHgJuO3WuZdHf2xakQqX805J0bnegY= X-Received: by 2002:a5d:614c:0:b0:343:7a0c:62ff with SMTP id y12-20020a5d614c000000b003437a0c62ffmr1701864wrt.61.1714140828493; Fri, 26 Apr 2024 07:13:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtgm/VMfvBKlv2uq2FlDhT4qzwJpfBkl7u4HVF5uUoZYMC5DfQ6E8lZVuDMz3VDAQDPGWbfw== X-Received: by 2002:a5d:614c:0:b0:343:7a0c:62ff with SMTP id y12-20020a5d614c000000b003437a0c62ffmr1701850wrt.61.1714140828142; Fri, 26 Apr 2024 07:13:48 -0700 (PDT) Received: from workstation5.fritz.box (ip-062-143-245-032.um16.pools.vodafone-ip.de. [62.143.245.32]) by smtp.gmail.com with ESMTPSA id s20-20020adfa294000000b003455e5d2569sm1460593wra.0.2024.04.26.07.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 07:13:47 -0700 (PDT) From: Heinrich Schuchardt To: Ilias Apalodimas Cc: Simon Glass , Tom Rini , Shantur Rathore , Bin Meng , AKASHI Takahiro , Masahisa Kojima , Raymond Mao , Mark Kettenis , Joao Marcos Costa , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [RFC 02/14] efi_loader: library function efi_dp_merge Date: Fri, 26 Apr 2024 16:13:09 +0200 Message-ID: <20240426141321.232236-3-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426141321.232236-1-heinrich.schuchardt@canonical.com> References: <20240426141321.232236-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean Provide a function to append a device_path to a list of device paths that is separated by final end nodes. Signed-off-by: Heinrich Schuchardt --- include/efi_loader.h | 3 +++ lib/efi_loader/efi_device_path.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/efi_loader.h b/include/efi_loader.h index 9600941aa32..a7d7b8324f1 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -944,6 +944,9 @@ struct efi_load_option { struct efi_device_path *efi_dp_from_lo(struct efi_load_option *lo, const efi_guid_t *guid); +struct efi_device_path *efi_dp_merge(const struct efi_device_path *dp1, + efi_uintn_t *size, + const struct efi_device_path *dp2); struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, const struct efi_device_path *dp2, bool split_end_node); diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 46aa59b9e40..16cbe41d32f 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -270,6 +270,37 @@ struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp) return ndp; } +/** + * efi_dp_merge() - Concatenate two device paths separated by final end node + * + * @dp1: first device path + * @size: pointer to length of @dp1, total size on return + * @dp2: second device path + * + * Return: concatenated device path or NULL + */ +struct efi_device_path *efi_dp_merge(const struct efi_device_path *dp1, + efi_uintn_t *size, + const struct efi_device_path *dp2) +{ + efi_uintn_t len, len1, len2; + struct efi_device_path *dp; + u8 *p; + + len1 = *size; + len2 = efi_dp_size(dp2) + sizeof(END); + len = len1 + len2; + dp = efi_alloc(len); + if (!dp) + return NULL; + memcpy(dp, dp1, len1); + p = (u8 *)dp + len1; + memcpy(p, dp2, len2); + *size = len; + + return dp; +} + /** * efi_dp_concat() - Concatenate two device paths and add and terminate them * with an end node. From patchwork Fri Apr 26 14:13:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1928204 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=RQQD71CT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VQvqF50Nmz1yZx for ; Sat, 27 Apr 2024 00:14:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B5568885CA; Fri, 26 Apr 2024 16:13:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com 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=canonical.com header.i=@canonical.com header.b="RQQD71CT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AEFEC885BE; Fri, 26 Apr 2024 16:13:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9B485885AE for ; Fri, 26 Apr 2024 16:13:50 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 06BFB3FE58 for ; Fri, 26 Apr 2024 14:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1714140830; bh=ycaUs8QeNyJ3M70xtoVidqljHwEoS3kMAM3I6zihxFs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RQQD71CTFGDM/k6kEVe0KcEnZxktFcIJuDDylnxUiZteAPCRgGT84s1H6kw77Pj7R HZ8uclseBMFJ9ZeA+K0rRxiEDOprYfup87ihGzljSNs78P4My32Pu7UmOzTCTKitPU /8DZVo6fVoOfy8+BCQHmiXdyDwkAHp1T9tVzPaE66fkydiNrHIvD5OZZdKE6EJevSs 24wJ00ObXBzEicgNTydf2t/kf/JapAwLo0mraq3bq/9GozB0xvokq3yDroOW6tQEKc HfzLQ+Ch/inXpeNKpmckF+Cs+pmXtgNP4v1yoZcGM8g/nbP5Dh/WtpL+aaVm614uca UarTD+P8eFQ4g== Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-41a074e2d69so9627775e9.3 for ; Fri, 26 Apr 2024 07:13:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714140829; x=1714745629; h=content-transfer-encoding:mime-version: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=ycaUs8QeNyJ3M70xtoVidqljHwEoS3kMAM3I6zihxFs=; b=YIY6BqJaVh6qLbrY8cJF8PxjNOYZHl4gb31iNasoUCsGElnbIaJKuiM0/2SJehsBTr nOOwsCH+8lJtpqsUXvjXcUJmzU+p32hQvwg7svn95jy/mLKvJJAkNeiH6G30Ro5TK/kn cRwU3L3aIokYmLp/U5ZxXw6vAO905BoTGiwFG37CQkP3QPugQ77W8lfPlpzZCxdFpy+S Tyiizn5CtMrcX2qyYMABeQslQzt98PKG7r+VpkXUf+Y5WsR58QzVYgCn/Th5URSoqAL4 OXNgTHqGnq46g2baNlBcsxmdEUQdZE07uazmsMh2P05pBCn/UqO6+VW6wCfq1RFjWLn4 DF4Q== X-Forwarded-Encrypted: i=1; AJvYcCWDfrp8keloahgHZcoRQqBDKPSxVF8oQGhJFeoY9twpD9iGt3VGGAYYPHI8JRLVQl7QLCBa0/amcqyabds/EUDTdIF7ZA== X-Gm-Message-State: AOJu0YyiCBLL/Grbkfo8vzoLKnfPEtL6vrb2RcImY4r2tynh2IwawqDF rx6q9eR8EEaF32IRnl2Nd2DI3tS+zw10Ec/crrD7G6MZc4MJlk2z5fcehxRC9PSb0pq50j1IW1y BOFBaH7bKof/L22gqZHBHyJt+1Wl+KMLrhfhbjXzmlA+ULdgeTjjZksPTeSKefhKhqJE= X-Received: by 2002:a5d:60d0:0:b0:343:8373:1591 with SMTP id x16-20020a5d60d0000000b0034383731591mr1868907wrt.64.1714140829488; Fri, 26 Apr 2024 07:13:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFVvZrDT18HCuL85nAoQMA43X0km9Pimx1Q1JGn2566t2EFi+ronvgY6iZr0k2wEvZ8auDa7w== X-Received: by 2002:a5d:60d0:0:b0:343:8373:1591 with SMTP id x16-20020a5d60d0000000b0034383731591mr1868888wrt.64.1714140829135; Fri, 26 Apr 2024 07:13:49 -0700 (PDT) Received: from workstation5.fritz.box (ip-062-143-245-032.um16.pools.vodafone-ip.de. [62.143.245.32]) by smtp.gmail.com with ESMTPSA id s20-20020adfa294000000b003455e5d2569sm1460593wra.0.2024.04.26.07.13.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 07:13:48 -0700 (PDT) From: Heinrich Schuchardt To: Ilias Apalodimas Cc: Simon Glass , Tom Rini , Shantur Rathore , Bin Meng , AKASHI Takahiro , Masahisa Kojima , Raymond Mao , Mark Kettenis , Joao Marcos Costa , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [RFC 03/14] efi_loader: simplify efi_dp_concat() Date: Fri, 26 Apr 2024 16:13:10 +0200 Message-ID: <20240426141321.232236-4-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426141321.232236-1-heinrich.schuchardt@canonical.com> References: <20240426141321.232236-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean As we now have efi_dp_merge() we can use this function to replace efi_dp_concat(,,true) and remove the last parameter from efi_dp_concat() otherwise. Signed-off-by: Heinrich Schuchardt --- cmd/eficonfig.c | 22 +++++++++--------- cmd/efidebug.c | 17 +++++++++----- include/efi_loader.h | 3 +-- lib/efi_loader/efi_bootbin.c | 2 +- lib/efi_loader/efi_bootmgr.c | 2 +- lib/efi_loader/efi_boottime.c | 2 +- lib/efi_loader/efi_device_path.c | 26 ++++------------------ lib/efi_loader/efi_device_path_utilities.c | 2 +- 8 files changed, 31 insertions(+), 45 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 0ba92c60e03..1c57e66040b 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -531,7 +531,7 @@ struct efi_device_path *eficonfig_create_device_path(struct efi_device_path *dp_ dp = efi_dp_shorten(dp_volume); if (!dp) dp = dp_volume; - dp = efi_dp_concat(dp, &fp->dp, false); + dp = efi_dp_concat(dp, &fp->dp); free(buf); return dp; @@ -1485,7 +1485,7 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo goto out; } initrd_dp = efi_dp_concat((const struct efi_device_path *)&id_dp, - dp, false); + dp); efi_free_pool(dp); } @@ -1494,17 +1494,17 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo ret = EFI_OUT_OF_RESOURCES; goto out; } - final_dp_size = efi_dp_size(dp) + sizeof(END); + + final_dp = dp; + final_dp_size = efi_dp_size(final_dp) + sizeof(END); + if (initrd_dp) { - final_dp = efi_dp_concat(dp, initrd_dp, true); - final_dp_size += efi_dp_size(initrd_dp) + sizeof(END); - } else { - final_dp = efi_dp_dup(dp); + final_dp = efi_dp_merge(final_dp, &final_dp_size, initrd_dp); + if (!final_dp) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } } - efi_free_pool(dp); - - if (!final_dp) - goto out; if (utf16_utf8_strlen(bo->optional_data)) { len = utf16_utf8_strlen(bo->optional_data) + 1; diff --git a/cmd/efidebug.c b/cmd/efidebug.c index a587860e2a5..93ba16efc7d 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -697,7 +697,7 @@ struct efi_device_path *create_initrd_dp(const char *dev, const char *part, short_fp = tmp_fp; initrd_dp = efi_dp_concat((const struct efi_device_path *)&id_dp, - short_fp, false); + short_fp); out: efi_free_pool(tmp_dp); @@ -917,11 +917,16 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag, goto out; } - final_fp = efi_dp_concat(file_path, initrd_dp, true); - if (!final_fp) { - printf("Cannot create final device path\n"); - r = CMD_RET_FAILURE; - goto out; + final_fp = file_path; + fp_size = efi_dp_size(final_fp) + sizeof(END); + + if (initrd_dp) { + final_fp = efi_dp_merge(final_fp, &fp_size, initrd_dp); + if (!final_fp) { + printf("Cannot create final device path\n"); + r = CMD_RET_FAILURE; + goto out; + } } lo.file_path = final_fp; diff --git a/include/efi_loader.h b/include/efi_loader.h index a7d7b8324f1..0ac04990b8e 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -948,8 +948,7 @@ struct efi_device_path *efi_dp_merge(const struct efi_device_path *dp1, efi_uintn_t *size, const struct efi_device_path *dp2); struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, - const struct efi_device_path *dp2, - bool split_end_node); + const struct efi_device_path *dp2); struct efi_device_path *search_gpt_dp_node(struct efi_device_path *device_path); efi_status_t efi_deserialize_load_option(struct efi_load_option *lo, u8 *data, efi_uintn_t *size); diff --git a/lib/efi_loader/efi_bootbin.c b/lib/efi_loader/efi_bootbin.c index b7910f78fb6..745b941b6ca 100644 --- a/lib/efi_loader/efi_bootbin.c +++ b/lib/efi_loader/efi_bootbin.c @@ -150,7 +150,7 @@ efi_status_t efi_run_image(void *source_buffer, efi_uintn_t source_size) msg_path = file_path; } else { file_path = efi_dp_concat(bootefi_device_path, - bootefi_image_path, false); + bootefi_image_path); msg_path = bootefi_image_path; log_debug("Loaded from disk\n"); } diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 4ac519228a6..db394df6bf4 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -130,7 +130,7 @@ static efi_status_t try_load_from_file_path(efi_handle_t *fs_handles, if (!dp) continue; - dp = efi_dp_concat(dp, fp, false); + dp = efi_dp_concat(dp, fp); if (!dp) continue; diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index 1951291747c..33f03c0cb0f 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1816,7 +1816,7 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path, if (device_path) { info->device_handle = efi_dp_find_obj(device_path, NULL, NULL); - dp = efi_dp_concat(device_path, file_path, false); + dp = efi_dp_concat(device_path, file_path); if (!dp) { ret = EFI_OUT_OF_RESOURCES; goto failure; diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 16cbe41d32f..75fe95c9c1e 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -307,21 +307,15 @@ struct efi_device_path *efi_dp_merge(const struct efi_device_path *dp1, * * @dp1: First device path * @dp2: Second device path - * @split_end_node: If true the two device paths will be concatenated and - * separated by an end node (DEVICE_PATH_SUB_TYPE_END). - * If false the second device path will be concatenated to the - * first one as-is. * * Return: * concatenated device path or NULL. Caller must free the returned value */ struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, - const struct efi_device_path *dp2, - bool split_end_node) + const struct efi_device_path *dp2) { struct efi_device_path *ret; - size_t end_size; if (!dp1 && !dp2) { /* return an end node */ @@ -333,29 +327,17 @@ efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, } else { /* both dp1 and dp2 are non-null */ unsigned sz1 = efi_dp_size(dp1); - unsigned sz2 = efi_dp_size(dp2); + /* the end node of the second device path has to be retained */ + unsigned int sz2 = efi_dp_size(dp2) + sizeof(END); void *p; - if (split_end_node) - end_size = 2 * sizeof(END); - else - end_size = sizeof(END); - p = efi_alloc(sz1 + sz2 + end_size); + p = efi_alloc(sz1 + sz2); if (!p) return NULL; ret = p; memcpy(p, dp1, sz1); p += sz1; - - if (split_end_node) { - memcpy(p, &END, sizeof(END)); - p += sizeof(END); - } - - /* the end node of the second device path has to be retained */ memcpy(p, dp2, sz2); - p += sz2; - memcpy(p, &END, sizeof(END)); } return ret; diff --git a/lib/efi_loader/efi_device_path_utilities.c b/lib/efi_loader/efi_device_path_utilities.c index c95dbfa9b5f..5f06602dba6 100644 --- a/lib/efi_loader/efi_device_path_utilities.c +++ b/lib/efi_loader/efi_device_path_utilities.c @@ -76,7 +76,7 @@ static struct efi_device_path * EFIAPI append_device_path( const struct efi_device_path *src2) { EFI_ENTRY("%pD, %pD", src1, src2); - return EFI_EXIT(efi_dp_concat(src1, src2, false)); + return EFI_EXIT(efi_dp_concat(src1, src2)); } /* From patchwork Fri Apr 26 14:13:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1928206 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=hfaEOeZd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VQvqd3MDBz1yZx for ; Sat, 27 Apr 2024 00:14:37 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6D34388667; Fri, 26 Apr 2024 16:13:56 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com 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=canonical.com header.i=@canonical.com header.b="hfaEOeZd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8F94D8860F; Fri, 26 Apr 2024 16:13:55 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9C089885C1 for ; Fri, 26 Apr 2024 16:13:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id E9A163FE60 for ; Fri, 26 Apr 2024 14:13:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1714140831; bh=aSURsQK7vhNefALFMTx/kvOabbE3mUsH8XfwRCIhoY4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hfaEOeZdKrwuuD3DvFuLPsyXzqjojZvPxWXoSw3Xrc3NEqKgM9EqjYSA8P+JuOduN jzjrFe+bv8TXeGcE0Wy/cwCr61GeM3DBctoRRYymDMFdd1DKeeIOhHTSRvtbgPVIVC 0INER+INLp7GFqQ8pPXwYhD19Ejdn1sb+dX28vDLi9u5IJ5XWbRAGdfoDcpkNTOTqk NZN65RMtWqF0JZZu2Q4iDunFajqozFk7+ecatl+ARxZWkNDGT9CID0nQJozPhKKGOC +v25h4z+IP7sH/MIYFTzpUx3dDeN5VJl2SmbebraQ+01dU8mFMYMYGJbWUCQz3gmxW yfi2Yy1kMebjA== Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-34b08e09bc4so1132480f8f.1 for ; Fri, 26 Apr 2024 07:13:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714140830; x=1714745630; h=content-transfer-encoding:mime-version: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=aSURsQK7vhNefALFMTx/kvOabbE3mUsH8XfwRCIhoY4=; b=vAIv20uxic3SNMqxaEZDFzzX7LFrrCASwnOhP1jB6LwG1Ft8SMKGtVK49RAqj8szOM HRbGPCa8UEjtxy6WaEifzISpA1BoNZOdVM7SgBTv5JJFVBh8bJ6uOpbWGhh8TV1hDHSQ owQ5sVctoBoU7+XqqyTCBX+Gp7vm22lbGIqtaYnTGtdLhACZuit0q110K0jQgM83x/ZU uhk33rxiOlJmBsUglWx3nWl/aZuAxs+QxsXCMcWUF32fA/XZek/Zp5YFwOnvQaLdu2g9 ni1V3LKv2C1b6k8cZLX5fz5+FIMLQfs4XK1tMHkHIyY+Ue5fxPlJg2OLj8TdkSs0XHp7 7YRg== X-Forwarded-Encrypted: i=1; AJvYcCVn+04i44BWtZHLJWA8XvGGyTqWrbiuAbcbbOwmBcL+i5dUWOl38rjNtSOxbcTNvCU/IYynWvZ8YlQdx4b84MJsTHP/gg== X-Gm-Message-State: AOJu0YzyEwLQTVAI6mx+caRFWQl0ibqj9puQ5scQOiRVGScxlysLtC18 DMrrtqXRSER5X6ys3s2Ihh/W67wB8jsI1mDvVRhkVcgBl8keLJlcQejp6cHSZS5/GESNbXrgvBk TdW1b/pF/Sqkl5ORsiaZkOxP1F4DTxLYmnUcOLw4+CTgnqw8YJsNlO0CbLGEvisKpICM= X-Received: by 2002:adf:f4c8:0:b0:349:ca9b:545a with SMTP id h8-20020adff4c8000000b00349ca9b545amr2362035wrp.29.1714140830411; Fri, 26 Apr 2024 07:13:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFEuOSE1SY1kO9Lf0DzPPiI5nLQVhS9o6Dscz7b90aK6edeQwK/gUE5fgNJdY+BdXKfDPdjDw== X-Received: by 2002:adf:f4c8:0:b0:349:ca9b:545a with SMTP id h8-20020adff4c8000000b00349ca9b545amr2362014wrp.29.1714140830039; Fri, 26 Apr 2024 07:13:50 -0700 (PDT) Received: from workstation5.fritz.box (ip-062-143-245-032.um16.pools.vodafone-ip.de. [62.143.245.32]) by smtp.gmail.com with ESMTPSA id s20-20020adfa294000000b003455e5d2569sm1460593wra.0.2024.04.26.07.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 07:13:49 -0700 (PDT) From: Heinrich Schuchardt To: Ilias Apalodimas Cc: Simon Glass , Tom Rini , Shantur Rathore , Bin Meng , AKASHI Takahiro , Masahisa Kojima , Raymond Mao , Mark Kettenis , Joao Marcos Costa , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [RFC 04/14] cmd: eficonfig: add support for setting fdt Date: Fri, 26 Apr 2024 16:13:11 +0200 Message-ID: <20240426141321.232236-5-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426141321.232236-1-heinrich.schuchardt@canonical.com> References: <20240426141321.232236-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean We already support creating a load option where the device-path field contains the concatenation of the binary device-path and optionally the device path of the initrd which we expose via the EFI_LOAD_FILE2_PROTOCOL. Allow to append another device-path pointing to the device-tree identified by the device-tree GUID. Signed-off-by: Heinrich Schuchardt Tested-by: E Shattow --- cmd/eficonfig.c | 68 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/cmd/eficonfig.c b/cmd/eficonfig.c index 1c57e66040b..d314051ee58 100644 --- a/cmd/eficonfig.c +++ b/cmd/eficonfig.c @@ -62,6 +62,7 @@ struct eficonfig_filepath_info { struct eficonfig_boot_option { struct eficonfig_select_file_info file_info; struct eficonfig_select_file_info initrd_info; + struct eficonfig_select_file_info fdt_info; unsigned int boot_index; u16 *description; u16 *optional_data; @@ -1308,6 +1309,10 @@ static efi_status_t eficonfig_show_boot_option(struct eficonfig_boot_option *bo, if (ret != EFI_SUCCESS) goto out; + ret = prepare_file_selection_entry(efi_menu, "Fdt File: ", &bo->fdt_info); + if (ret != EFI_SUCCESS) + goto out; + ret = create_boot_option_entry(efi_menu, "Optional Data: ", bo->optional_data, eficonfig_boot_add_optional_data, bo); if (ret != EFI_SUCCESS) @@ -1394,21 +1399,39 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo struct efi_device_path *final_dp = NULL; struct efi_device_path *device_dp = NULL; struct efi_device_path *initrd_dp = NULL; + struct efi_device_path *fdt_dp = NULL; struct efi_device_path *initrd_device_dp = NULL; + struct efi_device_path *fdt_device_dp = NULL; - const struct efi_initrd_dp id_dp = { + const struct efi_initrd_dp initrd_prefix = { .vendor = { { DEVICE_PATH_TYPE_MEDIA_DEVICE, DEVICE_PATH_SUB_TYPE_VENDOR_PATH, - sizeof(id_dp.vendor), + sizeof(initrd_prefix.vendor), }, EFI_INITRD_MEDIA_GUID, }, .end = { DEVICE_PATH_TYPE_END, DEVICE_PATH_SUB_TYPE_END, - sizeof(id_dp.end), + sizeof(initrd_prefix.end), + } + }; + + const struct efi_initrd_dp fdt_prefix = { + .vendor = { + { + DEVICE_PATH_TYPE_MEDIA_DEVICE, + DEVICE_PATH_SUB_TYPE_VENDOR_PATH, + sizeof(fdt_prefix.vendor), + }, + EFI_FDT_GUID, + }, + .end = { + DEVICE_PATH_TYPE_END, + DEVICE_PATH_SUB_TYPE_END, + sizeof(initrd_prefix.end), } }; @@ -1424,6 +1447,12 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo goto out; } + bo->fdt_info.current_path = calloc(1, EFICONFIG_FILE_PATH_BUF_SIZE); + if (!bo->fdt_info.current_path) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + bo->description = calloc(1, EFICONFIG_DESCRIPTION_MAX * sizeof(u16)); if (!bo->description) { ret = EFI_OUT_OF_RESOURCES; @@ -1456,13 +1485,20 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo if (lo.file_path) fill_file_info(lo.file_path, &bo->file_info, device_dp); - /* Initrd file path(optional) is placed at second instance. */ + /* Initrd file path (optional) is placed at second instance. */ initrd_dp = efi_dp_from_lo(&lo, &efi_lf2_initrd_guid); if (initrd_dp) { fill_file_info(initrd_dp, &bo->initrd_info, initrd_device_dp); efi_free_pool(initrd_dp); } + /* Fdt file path (optional) is placed as third instance. */ + fdt_dp = efi_dp_from_lo(&lo, &efi_guid_fdt); + if (fdt_dp) { + fill_file_info(fdt_dp, &bo->fdt_info, fdt_device_dp); + efi_free_pool(fdt_dp); + } + if (size > 0) memcpy(bo->optional_data, lo.optional_data, size); } @@ -1484,11 +1520,23 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo ret = EFI_OUT_OF_RESOURCES; goto out; } - initrd_dp = efi_dp_concat((const struct efi_device_path *)&id_dp, + initrd_dp = efi_dp_concat((const struct efi_device_path *)&initrd_prefix, dp); efi_free_pool(dp); } + if (bo->fdt_info.dp_volume) { + dp = eficonfig_create_device_path(bo->fdt_info.dp_volume, + bo->fdt_info.current_path); + if (!dp) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + fdt_dp = efi_dp_concat((const struct efi_device_path *)&fdt_prefix, + dp); + efi_free_pool(dp); + } + dp = eficonfig_create_device_path(bo->file_info.dp_volume, bo->file_info.current_path); if (!dp) { ret = EFI_OUT_OF_RESOURCES; @@ -1505,6 +1553,13 @@ static efi_status_t eficonfig_edit_boot_option(u16 *varname, struct eficonfig_bo goto out; } } + if (fdt_dp) { + final_dp = efi_dp_merge(final_dp, &final_dp_size, fdt_dp); + if (!final_dp) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + } if (utf16_utf8_strlen(bo->optional_data)) { len = utf16_utf8_strlen(bo->optional_data) + 1; @@ -1522,9 +1577,12 @@ out: free(bo->description); free(bo->file_info.current_path); free(bo->initrd_info.current_path); + free(bo->fdt_info.current_path); efi_free_pool(device_dp); efi_free_pool(initrd_device_dp); efi_free_pool(initrd_dp); + efi_free_pool(fdt_device_dp); + efi_free_pool(fdt_dp); efi_free_pool(final_dp); return ret; From patchwork Fri Apr 26 14:13:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heinrich Schuchardt X-Patchwork-Id: 1928208 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=WJbHLRLt; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VQvr22CDRz1yZx for ; Sat, 27 Apr 2024 00:14:58 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3038C886B1; Fri, 26 Apr 2024 16:13:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com 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=canonical.com header.i=@canonical.com header.b="WJbHLRLt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9DCF188693; Fri, 26 Apr 2024 16:13:57 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 smtp-relay-internal-0.canonical.com (smtp-relay-internal-0.canonical.com [185.125.188.122]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6BD52885FA for ; Fri, 26 Apr 2024 16:13:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=canonical.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=heinrich.schuchardt@canonical.com Received: from mail-lj1-f199.google.com (mail-lj1-f199.google.com [209.85.208.199]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id A5130424AD for ; Fri, 26 Apr 2024 14:13:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1714140832; bh=GbALgmVHL+0wQnCP5jjAKRdXoH+xnZ0i1B9JJwMmhjM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WJbHLRLtaNN01ghQ16wki03tyO017VpFFvPamqLZxAJB3SwMSuBMB53OITOwQRjiZ 3OAL7vao9lWxYxSfroL2gtDh4jNG+08+IpAi1XHlXmhJA+jRH0fY849LPPYWQ1iVew uCYVKSPBB5fJaJ4ptLSEKTBFNUsOt884uI6ytFj7eQtp9JkSigUHdqtH7ART1T+X7Q iXg9PSbqFi7LKFqZVI9cFarBnntEuxjNeJwm8XQRr4Ifd6aKZjbzUhQ/J4A1LBeCz8 AxBg/IP1rAEipJdwQmDMSCcm5TPITIPUx7Q0+cQRdPadecIoxdYz3HPBA/XQvyWMX/ cQunbKGgE/COw== Received: by mail-lj1-f199.google.com with SMTP id 38308e7fff4ca-2db6acacdacso19710051fa.0 for ; Fri, 26 Apr 2024 07:13:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714140831; x=1714745631; h=content-transfer-encoding:mime-version: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=GbALgmVHL+0wQnCP5jjAKRdXoH+xnZ0i1B9JJwMmhjM=; b=tuHHZ/ZXnp/1mi9vBeQaXGW39PO8V6qBZqXZRUj3J4R9Fdg2XiW9tf3h12334T6/Fw eBQEwDzWrOb0/2XFe7htXyrhiyk11C3soEuzyX+pr4x53CE1aZT4vwHTofnOzhXUorFQ Z7by93w3B/NuB63ILtaWsFcbWCqLx5BW7MXVp8+9iCKfHNMN+TMQN2F+a3BH16rAQxOa dZ2Z9m7APDen9h3B1BafZJg3vFS3HR1T9qktG+nsPUZMd4hrPXFuod6R2M3SUOK23ixe xCtjc+N2q/eCngDpGMKyHSFQzV8+WCiyT18CHVJ3eZByC4pl0KYob8Dk0b2WbDGrdP+P 88mg== X-Forwarded-Encrypted: i=1; AJvYcCWIcFqdPvTaok37HgO0VfEtKhTSlBzqzV19BoHwpUOZQyE0a9AZgifuaGjG01DwTPm4Eg3McbG+aIww+rlhYtTLG+UOxQ== X-Gm-Message-State: AOJu0YzQCpI5k+DyCB6oB3EKhoqPRTX3fBxcMSG2VKoTr8tcuXW+X52e qNE0ksOtX+j/529rK5jNo8IjrzCpaGYvxtpMADoKzz/SsKXb92cMDdyqSesddcond/c2dvXwptP sfqgY8DqzT90c3kyWgFgREwwrP7/IcSuR68K8jeZmEg/JGa1no3riMRv/iFszEEqNcX4= X-Received: by 2002:a2e:8ed7:0:b0:2da:b1fc:7b8f with SMTP id e23-20020a2e8ed7000000b002dab1fc7b8fmr2310828ljl.9.1714140831443; Fri, 26 Apr 2024 07:13:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGs/5xPN1JGwxxLRVpvyrID0KM9YezFkMYQ4RZD6ceMqkouAvPqA4DmRcnk/M+eInxkU2e2Kw== X-Received: by 2002:a2e:8ed7:0:b0:2da:b1fc:7b8f with SMTP id e23-20020a2e8ed7000000b002dab1fc7b8fmr2310804ljl.9.1714140830973; Fri, 26 Apr 2024 07:13:50 -0700 (PDT) Received: from workstation5.fritz.box (ip-062-143-245-032.um16.pools.vodafone-ip.de. [62.143.245.32]) by smtp.gmail.com with ESMTPSA id s20-20020adfa294000000b003455e5d2569sm1460593wra.0.2024.04.26.07.13.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 07:13:50 -0700 (PDT) From: Heinrich Schuchardt To: Ilias Apalodimas Cc: Simon Glass , Tom Rini , Shantur Rathore , Bin Meng , AKASHI Takahiro , Masahisa Kojima , Raymond Mao , Mark Kettenis , Joao Marcos Costa , u-boot@lists.denx.de, Heinrich Schuchardt Subject: [RFC 05/14] cmd: efidebug: add support for setting fdt Date: Fri, 26 Apr 2024 16:13:12 +0200 Message-ID: <20240426141321.232236-6-heinrich.schuchardt@canonical.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240426141321.232236-1-heinrich.schuchardt@canonical.com> References: <20240426141321.232236-1-heinrich.schuchardt@canonical.com> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean We already support creating a load option where the device-path field contains the concatenation of the binary device-path and optionally the device path of the initrd which we expose via the EFI_LOAD_FILE2_PROTOCOL. Allow to append another device-path pointing to the device-tree identified by the device-tree GUID. Signed-off-by: Heinrich Schuchardt --- cmd/efidebug.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 93ba16efc7d..32c64711b6c 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -660,16 +660,33 @@ static int do_efi_show_tables(struct cmd_tbl *cmdtp, int flag, * @part: disk partition * @file: filename * @shortform: create short form device path + * @fdt: create path for device-tree * Return: pointer to the device path or ERR_PTR */ static struct efi_device_path *create_initrd_dp(const char *dev, const char *part, - const char *file, int shortform) + const char *file, bool shortform, + bool fdt) { struct efi_device_path *tmp_dp = NULL, *tmp_fp = NULL, *short_fp = NULL; struct efi_device_path *initrd_dp = NULL; efi_status_t ret; + const struct efi_initrd_dp fdt_dp = { + .vendor = { + { + DEVICE_PATH_TYPE_MEDIA_DEVICE, + DEVICE_PATH_SUB_TYPE_VENDOR_PATH, + sizeof(fdt_dp.vendor), + }, + EFI_FDT_GUID, + }, + .end = { + DEVICE_PATH_TYPE_END, + DEVICE_PATH_SUB_TYPE_END, + sizeof(fdt_dp.end), + } + }; const struct efi_initrd_dp id_dp = { .vendor = { { @@ -696,7 +713,8 @@ struct efi_device_path *create_initrd_dp(const char *dev, const char *part, if (!short_fp) short_fp = tmp_fp; - initrd_dp = efi_dp_concat((const struct efi_device_path *)&id_dp, + initrd_dp = efi_dp_concat((const struct efi_device_path *) + (fdt ? &fdt_dp : &id_dp), short_fp); out: @@ -796,6 +814,7 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag, struct efi_device_path *fp_free = NULL; struct efi_device_path *final_fp = NULL; struct efi_device_path *initrd_dp = NULL; + struct efi_device_path *fdt_dp = NULL; struct efi_load_option lo; void *data = NULL; efi_uintn_t size; @@ -860,6 +879,27 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag, argc -= 5; argv += 5; break; + case 'd': + shortform = 1; + fallthrough; + case 'D': + if (argc < 3 || fdt_dp) { + r = CMD_RET_USAGE; + goto out; + } + + fdt_dp = create_initrd_dp(argv[1], argv[2], argv[3], + shortform, true); + if (!fdt_dp) { + printf("Cannot add a device-tree\n"); + r = CMD_RET_FAILURE; + goto out; + } + argc -= 3; + argv += 3; + fp_size += efi_dp_size(fdt_dp) + + sizeof(struct efi_device_path); + break; case 'i': shortform = 1; /* fallthrough */ @@ -870,7 +910,7 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag, } initrd_dp = create_initrd_dp(argv[1], argv[2], argv[3], - shortform); + shortform, false); if (!initrd_dp) { printf("Cannot add an initrd\n"); r = CMD_RET_FAILURE; @@ -929,6 +969,15 @@ static int do_efi_boot_add(struct cmd_tbl *cmdtp, int flag, } } + if (fdt_dp) { + final_fp = efi_dp_merge(final_fp, &fp_size, fdt_dp); + if (!final_fp) { + printf("Cannot create final device path\n"); + r = CMD_RET_FAILURE; + goto out; + } + } + lo.file_path = final_fp; lo.file_path_length = fp_size; @@ -952,6 +1001,7 @@ out: free(data); efi_free_pool(final_fp); efi_free_pool(initrd_dp); + efi_free_pool(fdt_dp); efi_free_pool(fp_free); free(lo.label); @@ -1014,7 +1064,8 @@ static int do_efi_boot_rm(struct cmd_tbl *cmdtp, int flag, */ static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size) { - struct efi_device_path *initrd_path = NULL; + struct efi_device_path *fdt_path; + struct efi_device_path *initrd_path; struct efi_load_option lo; efi_status_t ret; @@ -1043,6 +1094,12 @@ static void show_efi_boot_opt_data(u16 *varname16, void *data, size_t *size) efi_free_pool(initrd_path); } + fdt_path = efi_dp_from_lo(&lo, &efi_guid_fdt); + if (fdt_path) { + printf(" device-tree path: %pD\n", fdt_path); + efi_free_pool(fdt_path); + } + printf(" data:\n"); print_hex_dump(" ", DUMP_PREFIX_OFFSET, 16, 1, lo.optional_data, *size, true); @@ -1570,8 +1627,9 @@ U_BOOT_LONGHELP(efidebug, "\n" "efidebug boot add - set UEFI BootXXXX variable\n" " -b|-B