From patchwork Fri Mar 5 22:22: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: 1448274 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=rpXsR7Fn; dkim-atps=neutral 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dsj1g53dzz9sPf for ; Sat, 6 Mar 2021 09:23:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CEBA4826F3; Fri, 5 Mar 2021 23:23: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="rpXsR7Fn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 09F9182748; Fri, 5 Mar 2021 23:23:18 +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-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (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 3058782016 for ; Fri, 5 Mar 2021 23:23:09 +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-wm1-x332.google.com with SMTP id j4-20020a05600c4104b029010c62bc1e20so160476wmi.3 for ; Fri, 05 Mar 2021 14:23:09 -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=dlRU6TIZxKlFX0m10EUF4T3JCjghXQQ1dR3PMOpdLhY=; b=rpXsR7FnFjoR5F7Yv+L5creiLSZrJC/YPFcD8e4+UkOM1W8Id3E9EO76/BNv07juy8 2DfTDBHw0G5yS93iUmdufLetHPm3I6igi/q6X/O/pfRs6BIiYSSC1wNnC2WlGGNkPDnP BlMs0CpTTbLKojabtJ/mDUGgz62sA5NHZoI+AKlkyBC27EaqfD32pFMlF+M6peCf73cA I6+suXzoe+1h6TYNOJ0Lg+n7rcuQ+bp0nF6Xxptfk1vhd7sSTrNabcoEMh8/OjZSQWM+ b/OofaaUdUK2YreY1NJPr6MJz2d6YweavTTPqOSB6T+Fv+C7DGf9afO8aKY83M+w/CpX S1kg== 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=dlRU6TIZxKlFX0m10EUF4T3JCjghXQQ1dR3PMOpdLhY=; b=JiywIGGf05U8TSHJGoJpWNdtLELv1rkN2TamTK/xBHESxDOj+ULzvKJU8q58oBMBuH tHZkcS///tlM8OTKjZWx3MEkw4AxuxUkvl/q2xrOJODYGaePb1yOEmO8o1iQ5HPXeVsS mNPrAjrzvbXC7hfpmSWLHTSFa56vZ58xXsRjSiZpizURBW4fSi8wXLhmPbaLyKfK8n00 BF4ltLxyMAkfrRMTsF0+RZ74iVUIViDdX18lpB+faBDQwq+zPmdLwqKHYr5iwsP+WOpF bHXiO6E1I+Lc09OY/pRf5al0ZnaCkvXPbNvVd2TqqJfbSEr6uJS+gKc3AgHfksM3u3Fm 06yg== X-Gm-Message-State: AOAM530W/qNXrYm5tTVwJ0XQggh3Cx72zv0By3EUBBxgVhOy6I9O7aJY EJqJSBcimYVTtSOexWL2v03BHA== X-Google-Smtp-Source: ABdhPJzT1Yb+gBQJgKBaiGlCp4XwWyUnYPCtBTptfHDv0jTpm/YOt0rAdgx4lNcUdpQxLW3FwXVOjQ== X-Received: by 2002:a7b:c050:: with SMTP id u16mr10844773wmc.90.1614982988749; Fri, 05 Mar 2021 14:23:08 -0800 (PST) Received: from apalos.home ([2a02:587:4647:e6c6:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id s11sm6493296wme.22.2021.03.05.14.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:08 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de, takahiro.akashi@linaro.org Cc: 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, 6 Mar 2021 00:22:58 +0200 Message-Id: <20210305222303.2866284-2-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210305222303.2866284-1-ilias.apalodimas@linaro.org> References: <20210305222303.2866284-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) - 0x01 - 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 | 72 ++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) 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..cf1321828e87 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -310,6 +310,41 @@ struct efi_device_path *efi_dp_append(const struct efi_device_path *dp1, return ret; } +/** 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 + * @size: 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) +{ + struct efi_device_path *ret; + efi_uintn_t sz1, sz2; + void *p; + + if (!dp1 || !dp2) + return NULL; + sz1 = efi_dp_size(dp1); + sz2 = efi_dp_size(dp2); + p = dp_alloc(sz1 + sz2 + (2 * sizeof(END))); + /* both dp1 and dp2 are non-null */ + if (!p) + return NULL; + ret = p; + memcpy(p, dp1, sz1); + p += sz1; + memcpy(p, &END, sizeof(END)); + p += sizeof(END); + memcpy(p, dp2, sz2); + p += sz2; + memcpy(p, &END, sizeof(END)); + + return ret; +} + struct efi_device_path *efi_dp_append_node(const struct efi_device_path *dp, const struct efi_device_path *node) { @@ -1160,3 +1195,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 Vendor Device Path + * in a multi-instance device path that matches + * a specific GUID + * + * @load_option: device paths to search + * @size: size of the discovered device path + * @guid: guid to search for + * + * Return: device path 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; + + while (lo_len) { + if (fp->type != DEVICE_PATH_TYPE_MEDIA_DEVICE || + fp->sub_type != DEVICE_PATH_SUB_TYPE_VENDOR_PATH) { + lo_len -= fp->length; + fp = (void *)fp + fp->length; + continue; + } + + vendor = (struct efi_device_path_vendor *)fp; + if (!guidcmp(&vendor->guid, &guid)) + return efi_dp_dup(fp); + lo_len -= fp->length; + fp = (void *)fp + fp->length; + } + + return NULL; +}