From patchwork Wed Mar 17 19:54:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 403218 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp777402jai; Wed, 17 Mar 2021 12:55:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRAWV0jJXpfhMaZ6QY7KGCRbIBwmHCLRTNd6kjJAyoD3eDx6PCSCJJ/5VWNQBuEpzQWtQ4 X-Received: by 2002:a17:906:2504:: with SMTP id i4mr37906486ejb.115.1616010926919; Wed, 17 Mar 2021 12:55:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616010926; cv=none; d=google.com; s=arc-20160816; b=l0kHooxuvMGWRg5//Sy/1Dua8RCe195cAI/iM/ReqIivpmGI4VOLPe6uH9xetX7Icx rOAYKkP9q+VR06897+I8pAdxFZWtL2uq1DSTFSAgWrgjV9zbQYLnvV1N3DgRzmCIFL6j 4fnvhFFgk6BF3e0Gsp1sPu6KXXEhYZgOIL9LCDdCu/O9yHbVGPw+8gscyDpUVuwkjx8C kDkDuraNKIly8byJ5ufEL9zoGw+lOMNkwkgesO+9Wu0/5akz+zczktxNf5+S/5IdiEAu SuLrAQmoWwy8xL8aklHBkF6lZMP4k9fiuZ0PPh4B6GrDiplzT/sZHxJQYEViXfapcTJp x+xg== 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=PvZ6Jt8wgAXlsiDa/9CswidFx8bAWTuh0kBKbg5M6Q8=; b=F6xWzCu8Q8Aoq7S8SscDdWfcpdBuDF3CkKf/uSnOtv5CHvyUltuyfOv6LfcwupAOaq zkTXkTClixc+43EYD5LH07LUAjGNZNH0HOGFPbBMw24QrAhboVch3jEzgu6mH0m8zOvr 8JukknIsj7tYZd85LeV/YQdZOzbRq1Ir9CpbQyDcWBDcZgrDugQvnTLupPKqNOT0OFMb B6f3vUBkXBxAOATll0IZ/yBHnwblfs/VylNML9gGeTjlkQK5id2yIaR8ABwjfKPRn/xf W8iLG+iYj1J6FWQnRozSUEE55J/VH4tZyxCBCYFJjbPK3z1ErKwV6XqDOL2rhAtZRF1g ojEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZSj4GZDA; 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 q2si14966641ejx.352.2021.03.17.12.55.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 12:55:26 -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=ZSj4GZDA; 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 740738232D; Wed, 17 Mar 2021 20:55:19 +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="ZSj4GZDA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 61F5E8232D; Wed, 17 Mar 2021 20:55:16 +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-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) (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 0F9BA80040 for ; Wed, 17 Mar 2021 20:55:13 +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-x42b.google.com with SMTP id x13so3086134wrs.9 for ; Wed, 17 Mar 2021 12:55:13 -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=PvZ6Jt8wgAXlsiDa/9CswidFx8bAWTuh0kBKbg5M6Q8=; b=ZSj4GZDArCh3aKjGZXsjAd1LjbeAY7M08s0cohvD3gkuCkSbNxVU2I2Vy6C2nezhQ1 4bFAhKgFuLSat5c/WaC2lD2WNIJ/5F4eIUfAll6Ct0wMnkmEXEp6lq7hvGgJxEmNcN94 gE6qX2BBchc+ljVXGdryxrU1dKmztms5KcTmRv4OZ9s3mMbZLGLBx/AkGL4OlMef2l/x fVgHchvz9xrtdTHflCETyZO2XWMU3HdOSH3DKXsPH6Gcjy4bd6B1Angps8TfC29C/msh qwhTwsg1hMEu0a8MRDJ9rO/DrKkOi+gwO9qw70cKfxW/3KC05/xC8IQX0X8YIM0CvNks uBDQ== 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=PvZ6Jt8wgAXlsiDa/9CswidFx8bAWTuh0kBKbg5M6Q8=; b=q/l2OFX67Ff+Lre0v5bNRvX2sxNZGU65i6hooxAsmxs31NTCN8nAHsmpjY963Ts0gS T6EpBmID5kPRDE6kt0M7/8ZP8lRXsJH33vj0XJ6Yfs0Q/SMXcF+2OrrE+jq1mFCiTwTY 3Cw0th6MASBbfUd/v5CN1Jh3eGtRo+/hQUb/xyT1fwRiXkgDSrS8bKwnluqkPOWMegyn v0tPyqD0nZaQ6As27ndn2lV+EzRsHY92gRvAtfbjQypxCYTh5cjAX/27KlTgb3E1tdwM doatlPOFPhYE4YYvbzqODGW9lOHjd31ZKvlQUMeRz6T/jDCI/mnP3cgVaDWFnUZeD63F FGCA== X-Gm-Message-State: AOAM533LwFWoC+LkFmyRiGtrouJp9R6p0QwwUWAvLA8v5L7qfTS7bKsy pXv/XdSh87US0AcwjGbGzOSRd862sCCtPG6t X-Received: by 2002:adf:fb42:: with SMTP id c2mr6096128wrs.83.1616010912650; Wed, 17 Mar 2021 12:55:12 -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 z82sm3343853wmg.19.2021.03.17.12.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Mar 2021 12:55:12 -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 1/5 v4] efi_loader: Add device path related functions for initrd via Boot#### Date: Wed, 17 Mar 2021 21:54:58 +0200 Message-Id: <20210317195505.337105-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.31.0 In-Reply-To: <20210317195505.337105-1-ilias.apalodimas@linaro.org> References: <20210317195505.337105-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.31.0 Reviewed-by: Heinrich Schuchardt diff --git a/include/efi_loader.h b/include/efi_loader.h index 68daa1a4a9dc..5d534e69bb59 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -744,6 +744,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; +}