From patchwork Sat Mar 13 21:47:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 399599 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp2272446jai; Sat, 13 Mar 2021 13:48:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwI5fVbWI9Nx3p3PCvX1ksozJf7jo57+5t3N6EKl4oCNC63fwGb7YmyFo8HulqCeRYnhn6L X-Received: by 2002:a17:906:2816:: with SMTP id r22mr15563934ejc.2.1615672096520; Sat, 13 Mar 2021 13:48:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615672096; cv=none; d=google.com; s=arc-20160816; b=snUqlvzi1D+3IrJuWza6VyNfVpjjtIf6mP0fl6bJF+0VevYOaROiMWx4KF/kY3LSK7 YC5dv9aV6Xvp75W1kmkRfeIsS/DJubUaVKAdohjrXqLqbrk16YcGmZKYagQcWZIE4JUM uPS6OX7nBb7q55wuENtZVYqRLALnjJfAgMDktKsUwWM8oAvWcZuan7FxeLych/AmYMrJ Ky3nYO0tKs+O3qEWFCkKsw7Y44vWYDnwMvK3sAchO5XGzXgXe81Uc8VEQB1rbSzxavIV YWV04+sNum/PLRqiTIdeXYSV0MUmxninYTKPaKaB12oqeRSfs12E/UL/KRhUCaZ3/u8i aq2g== 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=lluyp91O8LViBfEHeVl02veK/6XpIIo8Y3gEQdrAVF4=; b=KI+rCAEllmWklbg7Bv5B/wWSU4fpaySE9J/Fw+nzIowX0IRqoaJFkRS14MoZDLJ9qO grDxSJ/MS/hW2r3RQUBTFjIDlq5QiYxXVAn6aAxeLJbqQC6ErGuWUlf+7JmNDD2rblKh b08zjbZg6Sf+vluxDDb4T+LQUint5rky1d5LhN43JlPMhUPb5QZmmcuzKzgmYaPVaASI JC4uI93P6367eClvFXzqk50P9YjBNGIvIq7k4DVA0MK916ffRIpDtkQgBGs2XF9C6T4V 1UiCqZx5p7GvFfy9zRH24I8NlPBWIDGZ4Z1/2xI8XjXSsu1rLuigQ+Y51WnscYeWnSLq csXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dlbl+ve6; 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 t14si7454796ejr.191.2021.03.13.13.48.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 13:48:16 -0800 (PST) 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=dlbl+ve6; 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 261808284A; Sat, 13 Mar 2021 22:47:53 +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="dlbl+ve6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9A71082829; Sat, 13 Mar 2021 22:47:50 +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-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) (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 83F9482821 for ; Sat, 13 Mar 2021 22:47:47 +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-ej1-x632.google.com with SMTP id c10so59967516ejx.9 for ; Sat, 13 Mar 2021 13:47:47 -0800 (PST) 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=lluyp91O8LViBfEHeVl02veK/6XpIIo8Y3gEQdrAVF4=; b=dlbl+ve6IGbDGngE9KHgDLXcDVaBhpSFzN4MjkF4+NFDgM8GCTW9MrRqEIyOeRdfrL FQdGKJSiEEV7HWrSuTKtAUYBmDZYFG0Fsw8S0OocXM3UxiFws2v3BvB966kzCtUm4pLs UBV8f059+BCxHq6jxFmSstJGh2UxHu7uciHzalS2MHFPUzLJzLiJ+O6FflJORpS9c7GS S93kCUry2lGR3qzgiVxtujcfQZ5OWM4zu+bZR2NYClW2jQQZvqUxIZnLziTSoEaAjPPW rj9Gih0XpO6n8kf4m1hd6txbyICrGfg4P3lZHFG5QpwRIxDbSTI9ts8AOJEb4V6NlaAM 4eiQ== 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=lluyp91O8LViBfEHeVl02veK/6XpIIo8Y3gEQdrAVF4=; b=pnAGfGqjFtj+pXd7MyJOu4hVoKnErVOw+EQ30D9GMTb6+yY7Xs50eRXlBT0mN+ukDe w3S1QnJFW9dajB+A8e2v+XfGtL70ea7Rsic0XgBoGiFL9DaQ1GP8H6FYhwvuz1IfWzKK JCaJxh7PM1YEh60kokQXwTSjEuz3D4JO+GV66eBmyrLQdmIxZPptD14zjU5voiml+9cY UlJfnvHfpplQ48sbRRtzrIvoCUnz4h8uGSDyRxlB6X3XOXukwN8AmK2NCaIqq+jQNUJM MuQbT/tK/jtaKL3aIAx49EpG4r5fsWs8t4oXjhOVWsPWtPR3+iI23NTIepSNHzh4PVaW Cc1Q== X-Gm-Message-State: AOAM530P2VrALRECSfakaIJHza53Es9NoqbT6h94wTNFljIaGRNwynSX /B9KcKpHnpotvVYnxw9O3oCOVw== X-Received: by 2002:a17:906:a1c8:: with SMTP id bx8mr15394351ejb.381.1615672067094; Sat, 13 Mar 2021 13:47:47 -0800 (PST) Received: from apalos.home ([2a02:587:4647:e6c6:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id a9sm1571144eds.33.2021.03.13.13.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Mar 2021 13:47:46 -0800 (PST) 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] efi_loader: Add device path related functions for initrd via Boot#### Date: Sat, 13 Mar 2021 23:47:33 +0200 Message-Id: <20210313214738.3257922-3-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210313214738.3257922-1-ilias.apalodimas@linaro.org> References: <20210313214738.3257922-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 | 99 ++++++++++++++++++++++++++++++-- 2 files changed, 98 insertions(+), 5 deletions(-) -- 2.30.1 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..1f55c772dc83 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -282,11 +282,25 @@ 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() - Append or concatenate two device paths. + * Concatenated device path will be separated by a 0xff end + * node. + * + * @dp1: First device path + * @dp2: Second device path + * + * Return: concatenated device path or NULL. Caller must free the returned + * value + */ +static struct efi_device_path *_efi_dp_append(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 +312,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(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(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 +1212,40 @@ 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 (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; +}