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: 393593 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp811622jai; Fri, 5 Mar 2021 14:23:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWfl0VZA4C0SB3+cYBmMnd2x4iT2PMfB2r3Sxh++KZVU8cWAe7kWTdIa0ypP/56RN5YPj8 X-Received: by 2002:a17:906:9888:: with SMTP id zc8mr4570274ejb.310.1614983013447; Fri, 05 Mar 2021 14:23:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614983013; cv=none; d=google.com; s=arc-20160816; b=rLuuF9opWapBYT1c4g3MOKRQ6ZN1rZKZNt7xr411yX+0wZ9vg3cX6ZEu9NvxPU54hU 88W4qDXnGoAihyYBIe57ANJ0z8NJkp/BiyRcVlz2B7XNKYoWTq2HTiycVHJTNkI1tzTG /Vi5zyVP18kKk9hLocAzW2pQWKCiG2MkCa+zXHFpYbIUgV+QZNLxXWZZ3gmyBT7Qr+hh i86O3xT7xDF5/ej8QmWvFMBDCWySv9bxwxwLf7JYJ5Kr6wk++JwmdIzr76YNuNAMS/ql XMKNPj4V+/UHwwRP9jqusdOvSf6XFWyRacfGP9ph4CyUpMqcWAqwmMFxhbVhurtKo65+ uePA== 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=dlRU6TIZxKlFX0m10EUF4T3JCjghXQQ1dR3PMOpdLhY=; b=aw3WYJctAQl8/qnkvAzTHoXstNDSrvsf7jvxKtqpf5Q7taqeOsW8sUauAEAsnvcTDN B52H8KGY+H5brhb2Vr/w2EM3v4qqbuMviAZ4wDsf3M0/M+xyoV0xUw23oox10SnH4YhB 2+yyP07ZX5pCX8lk/eqFKpklO45hQwyop7B1bWSLBs3krD7vZfKsON1s/aj39avYJFZE u9LexLAihwjKFrkyPARaqf8UCnPQlsM4QWqXmHjefec+WcwREiAxfMXM51VO30zv4ntr 48RZr+QKvWTbDtoTAE5fjMS1Uc+AMWSyg+QPky1edvxSxXBlvkVZpltFe/0kcnmykkj5 IxPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rpXsR7Fn; 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 bt16si2156365edb.440.2021.03.05.14.23.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Mar 2021 14:23:33 -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=rpXsR7Fn; 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 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-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(+) -- 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..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; +}