From patchwork Sun Mar 14 19:05:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 400112 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2861903jai; Sun, 14 Mar 2021 12:06:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyU8a4KhzuiLmiU24yBdiy2qzR2Rmhuw9vCKtHo73ZEUVavLw7OWm5WgtKA1ehw1mXxUoLu X-Received: by 2002:a05:6402:b2a:: with SMTP id bo10mr6198291edb.144.1615748777870; Sun, 14 Mar 2021 12:06:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615748777; cv=none; d=google.com; s=arc-20160816; b=r0BIbi218v515RvG141Gg7pe6YTrvmb3F++zWAAWGWuQX7pjCEJBaKxWnjHkF6z7Vl RwNe+dxHTLq3GVBqPFW74AHGMZRkn3H7qLrjK2p4vduKt2D5BxhlhRQK+6PEmtFrjSsc YDhR8VPnCSQuLiH1al7pIMdBwzUpZqoHLC+bxK+HDsfpI75Pl+XQxqeKAkpG13hL3Y7y LjFX7+t/5bmTz0pxmqQNel6nRzxAYQCagXlmNyfh9P66JyeFAxwhB5mw8e3L512vrkqC 5izsQdUu+mc605o57Mex2rgFPeefbsNB3cosjmh5qRf8UXMNfAWb1wr5kHIDBGdnnsNa V8QQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uG4maLm+fRSlIZABVE5eBCkYjrC1YtWc1i+8/L5o+j8=; b=t9lzki3HE3yiBVNq7/fBZt7aN0KENTgHjuEmWTVmyHXoOSL1P+ZsUlKG7E20JquOCZ jcJNXIZq9q4+xNUvNDhcO6Abjz4Gv+Ok8uWYTdMjo8WKAkfKrbQodT5wm+dBaag1ocik x6W8HWlXHujVrSK6MKq6pFuXCj6HO0AXKiVZB4fmr4EGAbfdmRK5c6Zg/YjCKJXxAe1A 47xYlkgoXeqe+FlEKgxE2nmPWxAdJ3RbM4IZ9Xqq58+mJGBoUImMmDqt/NA2vO04IGow 1icZuCAj5CbiDzCCQWT9fal1Ra60lsSVGxD7KE2acMDPx22Hv8gTCPLWnSJK0MVf2qDg cfOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Au5XU5yN; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id cw1si9909615edb.412.2021.03.14.12.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:06:17 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Au5XU5yN; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1B47382970; Sun, 14 Mar 2021 20:06:01 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org 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=linaro.org header.i=@linaro.org header.b="Au5XU5yN"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4968E82944; Sun, 14 Mar 2021 20:05:57 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3D7C88285A for ; Sun, 14 Mar 2021 20:05:54 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x432.google.com with SMTP id b9so4616374wrt.8 for ; Sun, 14 Mar 2021 12:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uG4maLm+fRSlIZABVE5eBCkYjrC1YtWc1i+8/L5o+j8=; b=Au5XU5yNx3/8+PXaZbCdzgM09+npt300TS29/+PhpD5XUqkmuv4YQ5c9FRQX3ZHBTJ LeGtlxFpA9Ix9pLaLNQPEsI7r/TkwLaRR0JKnGgeNB6tCkYn+sr0ZJOybFBYF2ApTTGd 2ABw5UyYvCVXLh4risT0vyr3tJ6RI1gH/5QGMVciV26/okUyjAwPsxiIM8nYKGgstuRK 6V1csO92os0r49vNZEPafZ/G0zWnJ7J0FShV3eRDm8mVxFbbAfeJ/02YHDOi29sATmMg newzT4J+18Iy0QVoSpeN/Nq2SA2t/+jhVQl0cuCJRUyIwxMVeSgw0ZH9zDFkOKKUelvm unxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uG4maLm+fRSlIZABVE5eBCkYjrC1YtWc1i+8/L5o+j8=; b=S6hn+f1qQv0rN5vWmBvTzDj9no6KU7e29B4qImPL2ydMDBDely8EAtOioq8nnd1ZHR qFhdA7IEvPTitmtF6NpFp+68gXPZ9InqYHiAQLT0+PxsQ8IslpAxBEBuwM5CW+p8GI3C opuCIMCYquXrUJmqkx1Cr9HPY/txJKWHzmknfghDd5QoaDugZTffz1OcD5c1r51t+fx+ NLqnFPygkT0UtW2dV2ZOmhfNic9RiMsBi+Csx/j1RUwqQKHeBDX0nmZS/Pu7H3ATnlz3 9m0qcbjevIXwtZsuPBG8cita1QyWvjvwuqObVt3a0+y1NMIDyR06+UylVc6L5rxrAdUZ R0WQ== X-Gm-Message-State: AOAM530XBtkGZ1O1v5B5h/D1NhTacp16ZK94Iv41tbDO2W5WYqm9nZet l7oS81/ALR8IsdS9Sfc2mTHICA== X-Received: by 2002:a5d:63d2:: with SMTP id c18mr23782071wrw.277.1615748753802; Sun, 14 Mar 2021 12:05:53 -0700 (PDT) Received: from localhost.localdomain (ppp-94-64-113-158.home.otenet.gr. [94.64.113.158]) by smtp.gmail.com with ESMTPSA id 3sm18718029wry.72.2021.03.14.12.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Mar 2021 12:05:53 -0700 (PDT) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: takahiro.akashi@linaro.org, Ilias Apalodimas , Alexander Graf , Sughosh Ganu , u-boot@lists.denx.de Subject: [PATCH 2/6 v3] efi_loader: Add device path related functions for initrd via Boot#### Date: Sun, 14 Mar 2021 21:05:34 +0200 Message-Id: <20210314190541.129687-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210314190541.129687-1-ilias.apalodimas@linaro.org> References: <20210314190541.129687-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.102.4 at phobos.denx.de X-Virus-Status: Clean On the following patches we allow for an initrd path to be stored in Boot#### variables. Specifically we encode in the FIlePathList[] of the EFI_LOAD_OPTIONS for each Boot#### variable. The FilePathList[] array looks like this: kernel - 0xff - VenMedia(initrd GUID) - initrd1 - 0x01 initrd2 - 0xff So let's add the relevant functions to concatenate and retrieve a device path based on a Vendor GUID. Signed-off-by: Ilias Apalodimas --- include/efi_loader.h | 4 ++ lib/efi_loader/efi_device_path.c | 106 +++++++++++++++++++++++++++++-- 2 files changed, 105 insertions(+), 5 deletions(-) -- 2.30.2 diff --git a/include/efi_loader.h b/include/efi_loader.h index f470bbd636f4..eb11a8c7d4b1 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -738,6 +738,10 @@ struct efi_load_option { const u8 *optional_data; }; +struct efi_device_path *efi_dp_from_lo(struct efi_load_option *lo, + efi_uintn_t *size, efi_guid_t guid); +struct efi_device_path *efi_dp_concat(const struct efi_device_path *dp1, + const struct efi_device_path *dp2); efi_status_t efi_deserialize_load_option(struct efi_load_option *lo, u8 *data, efi_uintn_t *size); unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data); diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index c9315dd45857..1491251e224b 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -282,11 +282,30 @@ struct efi_device_path *efi_dp_dup(const struct efi_device_path *dp) return ndp; } -struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1, - const struct efi_device_path *dp2) +/** efi_dp_append_or_concatenate() - Append or concatenate two device paths. + * Concatenated device path will be separated + * by a sub-type 0xff end node + * + * @dp1: First device path + * @dp2: Second device path + * @concat: If true the two device paths will be concatenated and separated + * by an end of entrire device path sub-type 0xff end node. + * If true the second device path will be appended to the first and + * terminated by an end node + * + * Return: concatenated device path or NULL. Caller must free the returned + * value + */ +static struct +efi_device_path *efi_dp_append_or_concatenate(const struct efi_device_path *dp1, + const struct efi_device_path *dp2, + bool concat) { struct efi_device_path *ret; + size_t end_size = sizeof(END); + if (concat) + end_size = 2 * sizeof(END); if (!dp1 && !dp2) { /* return an end node */ ret = efi_dp_dup(&END); @@ -298,18 +317,56 @@ struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1, /* both dp1 and dp2 are non-null */ unsigned sz1 = efi_dp_size(dp1); unsigned sz2 = efi_dp_size(dp2); - void *p = dp_alloc(sz1 + sz2 + sizeof(END)); + void *p = dp_alloc(sz1 + sz2 + end_size); if (!p) return NULL; + ret = p; memcpy(p, dp1, sz1); + p += sz1; + + if (concat) { + memcpy(p, &END, sizeof(END)); + p += sizeof(END); + } + /* the end node of the second device path has to be retained */ - memcpy(p + sz1, dp2, sz2 + sizeof(END)); - ret = p; + memcpy(p, dp2, sz2); + p += sz2; + memcpy(p, &END, sizeof(END)); } return ret; } +/** efi_dp_append() - Append a device to an existing device path. + * + * @dp1: First device path + * @dp2: Second device path + * + * Return: concatenated device path or NULL. Caller must free the returned + * value + */ +struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1, + const struct efi_device_path *dp2) +{ + return efi_dp_append_or_concatenate(dp1, dp2, false); +} + +/** efi_dp_concat() - Concatenate 2 device paths. The final device path will + * contain two device paths separated by and end node (0xff). + * + * @dp1: First device path + * @dp2: Second device path + * + * 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) +{ + return efi_dp_append_or_concatenate(dp1, dp2, true); +} + struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp, const struct efi_device_path *node) { @@ -1160,3 +1217,42 @@ ssize_t efi_dp_check_length(const struct efi_device_path *dp, dp = (const struct efi_device_path *)((const u8 *)dp + len); } } + +/** + * efi_dp_from_lo() - Get the instance of a VenMedia node in a + * multi-instance device path that matches + * a specific GUID. This kind of device paths + * is found in Boot#### options describing an + * initrd location + * + * @load_option: EFI_LOAD_OPTION containing a valid device path + * @size: size of the discovered device path + * @guid: guid to search for + * + * Return: device path including the VenMedia node or NULL. + * Caller must free the returned value + */ +struct +efi_device_path *efi_dp_from_lo(struct efi_load_option *lo, + efi_uintn_t *size, efi_guid_t guid) +{ + struct efi_device_path *fp = lo->file_path; + struct efi_device_path_vendor *vendor; + int lo_len = lo->file_path_length; + + for (; lo_len >= sizeof(struct efi_device_path); + lo_len -= fp->length, fp = (void *)fp + fp->length) { + if (lo_len < 0 || efi_dp_check_length(fp, lo_len) < 0) + break; + if (fp->type != DEVICE_PATH_TYPE_MEDIA_DEVICE || + fp->sub_type != DEVICE_PATH_SUB_TYPE_VENDOR_PATH) + continue; + + vendor = (struct efi_device_path_vendor *)fp; + if (!guidcmp(&vendor->guid, &guid)) + return efi_dp_dup(fp); + } + log_debug("VenMedia(%pUl) not found in %ls\n", &guid, lo->label); + + return NULL; +}