From patchwork Thu Oct 29 00:25:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319304 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp14803ilc; Wed, 28 Oct 2020 17:26:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEgsN+2tNayDgS2oAyHbPDHvmQo5Zqc1rHYyUMJmJmRXthJx1fDszEjR9G/XxsOD7BxQfB X-Received: by 2002:aa7:dc52:: with SMTP id g18mr1482086edu.369.1603931162287; Wed, 28 Oct 2020 17:26:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931162; cv=none; d=google.com; s=arc-20160816; b=wWTPvE0YB1Nd1D1BCUGiLVaNQYlRKgPJJtCeR9vsopp3mKFid4gPVBvJdZ1KreI8gm CjBR/fEBV8b/KjORDhkj8V20kEISM2E4BBdLnIuHn+7lR22utNNZcnnxrIAqp79wbLCf wnsesfUl7OFhXnlRxHWkN7KriiebN1cX+9kXjFa47g7JmE057tMVUvpiEC2exIZOCiMW Jyho0oVaULBqVIOymfSf1f2O7q+uzLrzHTNcb07WPdOlgNbgDc89Hg8RE/jm3oyoRjod Kj2PkAgIBRxeaeg6kpriiBNwPIBs6h6VlzNn7fd1urp5gODC5HUtGkUOieF7Hk1D2k/7 lsyQ== 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=Zi7aKf5qP1b8ddwIytuFsCexeq9zKmRYaMwNeAo9Vpk=; b=js6RHqTi3SdWiMh93k4cfuhDM2l20mL86MDBOg8H+mFGrtzS33TBNX8RdF5q0WtMqc fpr6/8ZwG9qYFEkzCpGL2lwNmgI3UeYdQ+J4cAuR6c7kJxCbkPYoE6N+oW/6f8USPx72 CwL883WrrC61O6MznwVXQ34i8w0m3rEFVRtwEW3wLKaQhENVbu67hvQIAzOXjN0zMn44 cL5h2Fq6vFoR1yXqKdX4r9Pw83Jigyvnv5ydYK0OSgvMQ/LhqgC+MMd7GWS31kd4oAb5 YEWHEKXZHGLD1X+xmpaSOVCcFvBl/QXaeq03wYAmXC5z0K3bLWuQoEKxbHv4KIKtJpFs GE8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r2ByijRp; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ck9si614039ejb.445.2020.10.28.17.26.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:02 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r2ByijRp; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 74AE18246A; Thu, 29 Oct 2020 01:26: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="r2ByijRp"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E22C9824A4; Thu, 29 Oct 2020 01:25:59 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) (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 C491682430 for ; Thu, 29 Oct 2020 01:25:56 +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=takahiro.akashi@linaro.org Received: by mail-pg1-x542.google.com with SMTP id r186so923225pgr.0 for ; Wed, 28 Oct 2020 17:25:56 -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=Zi7aKf5qP1b8ddwIytuFsCexeq9zKmRYaMwNeAo9Vpk=; b=r2ByijRp9FGPJgnZKd6ATGIqzf/UEYehaNwWSwcdnF7zrCUBkoFOyW8Vt1/dsL83Xr p4FJJGP+wgd8+bgfss0EjGfzfH5Nosh3EPo78J5BBiUSToYoByKL129TLg/Qc2cfoAQh 0M30hDDAzfYhJHHUeDBZi5PQynbTQTnONDCZ+iVPJrfwCk/qwH28FmRdGxjKbqaXhMHe Blhi5V+Hznzfh+y06RsilgxqwpWpOVvt2ufakm9nHIwrUvxizGm7h3dYcZG08/pI8hyq Fggo4R2e2by6LfiMKOM///0ScI/ftw7pNtIkU8IdI97TyNOh90PsyQTqqiJyy159jivj 0hvg== 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=Zi7aKf5qP1b8ddwIytuFsCexeq9zKmRYaMwNeAo9Vpk=; b=hvIdybaBffJko7HCP15Txndh9hxrL1iHZbED6ALh4H34V1B2nB2WWL8FLOWdgGd1iV yod4Nz2SGlikyMWMPWQiimrv+urviaZcglmDnc4PjfIL8VvSB6D10FP7f01GK4Ehc/2C SRQwlvoA5dIwZj+ceu9USKWzaw2Zr/phquW+2Wjw9fZs+ycV64jWBlHDPaDorx1ouxsO vNaG1+vNzHbSo5IP0B0nyoa11+yA98YdzFlTg62di4i1+YWE3K5GVBi4le0hCwu4df5u mh1QyWQnHWq2tQy+tYOxYLq8KUk/S0wqxa6wL8aGTbRnbOjK+XaSGenmWUfxEWdBGp3X Nngg== X-Gm-Message-State: AOAM532N3awI4jmlPBzaCaeXnIdxcpLUsEVzFrU8N4XUQbr9Xq7zKWsy pAPC+7VW5ykudUHNKe6Gr/qRBQ== X-Received: by 2002:a63:4e5e:: with SMTP id o30mr1765390pgl.251.1603931155243; Wed, 28 Oct 2020 17:25:55 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.25.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:25:54 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 01/17] dfu: rename dfu_tftp_write() to dfu_write_by_name() Date: Thu, 29 Oct 2020 09:25:12 +0900 Message-Id: <20201029002528.34408-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean This function is essentially independent from tftp, and will also be utilised in implementing UEFI capsule update in a later commit. So just give it a more generic name. In addition, a new configuration option, CONFIG_DFU_ALT, was introduced so that the file will be compiled with different options, particularly one added in a later commit. Signed-off-by: AKASHI Takahiro --- common/update.c | 5 +++-- drivers/dfu/Kconfig | 5 +++++ drivers/dfu/Makefile | 2 +- drivers/dfu/{dfu_tftp.c => dfu_alt.c} | 17 ++++++++++++-- include/dfu.h | 32 +++++++++++++-------------- 5 files changed, 40 insertions(+), 21 deletions(-) rename drivers/dfu/{dfu_tftp.c => dfu_alt.c} (67%) -- 2.28.0 diff --git a/common/update.c b/common/update.c index 36b6b7523d50..39946776d74f 100644 --- a/common/update.c +++ b/common/update.c @@ -324,8 +324,9 @@ got_update_file: } } else if (fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE)) { - ret = dfu_tftp_write(fit_image_name, update_addr, - update_size, interface, devstring); + ret = dfu_write_by_name(fit_image_name, update_addr, + update_size, interface, + devstring); if (ret) return ret; } diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig index 0eec00ba734d..78f901ff348a 100644 --- a/drivers/dfu/Kconfig +++ b/drivers/dfu/Kconfig @@ -14,8 +14,13 @@ config DFU_OVER_TFTP depends on NET if DFU +config DFU_ALT + bool + default n + config DFU_TFTP bool "DFU via TFTP" + select DFU_ALT select DFU_OVER_TFTP help This option allows performing update of DFU-managed medium with data diff --git a/drivers/dfu/Makefile b/drivers/dfu/Makefile index 0d7925c083ef..cc7de1d3ed9b 100644 --- a/drivers/dfu/Makefile +++ b/drivers/dfu/Makefile @@ -9,5 +9,5 @@ obj-$(CONFIG_$(SPL_)DFU_MTD) += dfu_mtd.o obj-$(CONFIG_$(SPL_)DFU_NAND) += dfu_nand.o obj-$(CONFIG_$(SPL_)DFU_RAM) += dfu_ram.o obj-$(CONFIG_$(SPL_)DFU_SF) += dfu_sf.o -obj-$(CONFIG_$(SPL_)DFU_TFTP) += dfu_tftp.o +obj-$(CONFIG_$(SPL_)DFU_ALT) += dfu_alt.o obj-$(CONFIG_$(SPL_)DFU_VIRT) += dfu_virt.o diff --git a/drivers/dfu/dfu_tftp.c b/drivers/dfu/dfu_alt.c similarity index 67% rename from drivers/dfu/dfu_tftp.c rename to drivers/dfu/dfu_alt.c index ffae4bb54f80..5b1b13d7170d 100644 --- a/drivers/dfu/dfu_tftp.c +++ b/drivers/dfu/dfu_alt.c @@ -10,8 +10,21 @@ #include #include -int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len, - char *interface, char *devstring) +/** + * dfu_write_by_name() - write data to DFU medium + * @dfu_entity_name: Name of DFU entity to write + * @addr: Address of data buffer to write + * @len: Number of bytes + * @interface: Destination DFU medium (e.g. "mmc") + * @devstring: Instance number of destination DFU medium (e.g. "1") + * + * This function is storing data received on DFU supported medium which + * is specified by @dfu_entity_name. + * + * Return: 0 - on success, error code - otherwise + */ +int dfu_write_by_name(char *dfu_entity_name, unsigned int addr, + unsigned int len, char *interface, char *devstring) { char *s, *sb; int alt_setting_num, ret; diff --git a/include/dfu.h b/include/dfu.h index 84abdc79acd1..cecfbd76597b 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -494,27 +494,27 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, #endif /** - * dfu_tftp_write() - write TFTP data to DFU medium + * dfu_write_by_name() - write data to DFU medium + * @dfu_entity_name: Name of DFU entity to write + * @addr: Address of data buffer to write + * @len: Number of bytes + * @interface: Destination DFU medium (e.g. "mmc") + * @devstring: Instance number of destination DFU medium (e.g. "1") * - * This function is storing data received via TFTP on DFU supported medium. + * This function is storing data received on DFU supported medium which + * is specified by @dfu_entity_name. * - * @dfu_entity_name: name of DFU entity to write - * @addr: address of data buffer to write - * @len: number of bytes - * @interface: destination DFU medium (e.g. "mmc") - * @devstring: instance number of destination DFU medium (e.g. "1") - * - * Return: 0 on success, otherwise error code + * Return: 0 - on success, error code - otherwise */ -#if CONFIG_IS_ENABLED(DFU_TFTP) -int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, unsigned int len, - char *interface, char *devstring); +#if CONFIG_IS_ENABLED(DFU_ALT) +int dfu_write_by_name(char *dfu_entity_name, unsigned int addr, + unsigned int len, char *interface, char *devstring); #else -static inline int dfu_tftp_write(char *dfu_entity_name, unsigned int addr, - unsigned int len, char *interface, - char *devstring) +static inline int dfu_write_by_name(char *dfu_entity_name, unsigned int addr, + unsigned int len, char *interface, + char *devstring) { - puts("TFTP write support for DFU not available!\n"); + puts("write support for DFU not available!\n"); return -ENOSYS; } #endif From patchwork Thu Oct 29 00:25:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319305 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp14906ilc; Wed, 28 Oct 2020 17:26:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYi1IxoF869eGqJkQUnhg9ValagQQo3i2egrIwsXYpTdI7Bh3XaQ0tbjQMRPnuJvgLueJ5 X-Received: by 2002:a05:6402:22e3:: with SMTP id dn3mr1434290edb.205.1603931172658; Wed, 28 Oct 2020 17:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931172; cv=none; d=google.com; s=arc-20160816; b=l8Ranz4TPt/n0j2fzQt9cexYPOJ1OsIKg+Bb9IzQsBPUDt4iji1crg1Ln/M48YDsfx pp50y1xIfsT/vZemRLfwYg/MZRhLmJXeg+l1zrOo3jMqRkYIV8n+SG2Z3H82GEx2zOMw TvTWWNCD+1hADze4M7LJLzxNZSsAak1uGb+/toDWordXGppuvxT1y45mrcLvYoEbTmeF b4GHCBQXqmbFSvDZ32XhJ0s6JSzwu7LYTtEomv0dEsG+fs2MvcGkHJdVWfsdigW72cAl QA9panK5ZSkpNVUtYHnczwM6ektKOLs/zqCSmvhJPBQEkdCzpm0htHe52A4YbXfCmhRX gbeg== 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=gqY/srhD03OZnQsaQHroe9Z7PgmuG4jHelGJ5Q907Fk=; b=BcxAbXoambY8LWj6/CivqkPwUqUPfn+FRffnQIkokX9vrvupH8Hqog9XXkPyWTfeN+ dvBmkUl0uYTSAA8zqQMHyJlUR0hvYb5venwuJSefehJmdfBxF3fX2mAsU73ZqmAEr1El Xoogfy6BeMKnS1uv8F8Lb7O0MKiT2M9z0EV8gx6gnxIe2etzfVYoFOICgqwKTJcUzuD3 P25UaHe+i+jG38Xqw7O88GLXx1X6f++cvgDrKW7mjU5pUvVb5q6H6IS+wg2n1lwBBYyz swSKDKN7An8bnozS0d/8T26PKhN6inJw/MWPpr6vYGVsw8OAID9TjaAL22PLYSOrCGwu FOng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="XlZoGoO/"; 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 y16si883483edm.444.2020.10.28.17.26.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:12 -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="XlZoGoO/"; 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 D15BA824C5; Thu, 29 Oct 2020 01:26:06 +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="XlZoGoO/"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F3BE382434; Thu, 29 Oct 2020 01:26:02 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (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 8A9AC82434 for ; Thu, 29 Oct 2020 01:25:59 +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=takahiro.akashi@linaro.org Received: by mail-pf1-x441.google.com with SMTP id o129so880075pfb.1 for ; Wed, 28 Oct 2020 17:25:59 -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=gqY/srhD03OZnQsaQHroe9Z7PgmuG4jHelGJ5Q907Fk=; b=XlZoGoO/9+9TLJ+I5cBJ27w4nQDmn7640Fm2t8ixWfpjEpj+bwKm5k9OqxUNjoZ9F7 mMEzlnXHOZFuC2cIciVfg14O8rodwF6vSXfPvAcEyMku4cwOx7SYY18zE3jPb4RayCpr skj/rI4JS1Ll46XoU3XtZ5APB3xRadZ4OPqkoiQPTbm21Mo9n0WMpmXtKVSZt6P9Z7Qd aCA3hZfofoSPkfRFOSvZ8RXY7UVC8HzNq3dQWGV16FpoWXqdFqe4LiVG0roT3lNaYCnV aXKCVEkLbpJn1/br7iNp2Jpv6VVIbzbsGijgmY3IK+s+0AmzYkp5EynDVhcHru6vK8WA Byaw== 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=gqY/srhD03OZnQsaQHroe9Z7PgmuG4jHelGJ5Q907Fk=; b=qmt9LwX1v+wszWRHPInWDOhXDZDHSTyfY3KW+bmbLYE/fwp1XFI67UKwGKIq3LLF+n muhFQXWtj1SsCdDh+bhfoAliw4DvcGob7MB9ojNrlCZbjS71KdxIOAFGEiYUINQu2Irg iuMpBBles8WNPfHPyVFOF1J/KhlZ62WY6LeOor0p4M7aO8U1+NNvQ2MzDL540+5QQYDW ow1Fa9XIMbWt/GvTu1yzx9tMtw2NWVSnSkQD3tOQmzgrTNOrYlOPAEpVPo5AxtV49iob SnUpHQm2bUBJFpgtRsh29TWyP0JMUZK1oWYRYf54RSrPNF1mLX6fxPtbjzt6EpqlM/uD WJzA== X-Gm-Message-State: AOAM530bFsSzZawyATyn3xaKz7ER+tEqm8vFAUXBAIVhDC1XH5HsPS5X IbJyEHqppaYnayP3/5XUPGnS/Q== X-Received: by 2002:a65:50c5:: with SMTP id s5mr1646994pgp.399.1603931158153; Wed, 28 Oct 2020 17:25:58 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.25.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:25:57 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 02/17] dfu: modify an argument type for an address Date: Thu, 29 Oct 2020 09:25:13 +0900 Message-Id: <20201029002528.34408-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean The range of an addressable pointer can go beyond 'integer'. So change the argument type to a void pointer. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- common/update.c | 3 ++- drivers/dfu/dfu_alt.c | 6 +++--- include/dfu.h | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) -- 2.28.0 diff --git a/common/update.c b/common/update.c index 39946776d74f..8dd6ee8b7ddb 100644 --- a/common/update.c +++ b/common/update.c @@ -324,7 +324,8 @@ got_update_file: } } else if (fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE)) { - ret = dfu_write_by_name(fit_image_name, update_addr, + ret = dfu_write_by_name(fit_image_name, + (void *)update_addr, update_size, interface, devstring); if (ret) diff --git a/drivers/dfu/dfu_alt.c b/drivers/dfu/dfu_alt.c index 5b1b13d7170d..7528806cd163 100644 --- a/drivers/dfu/dfu_alt.c +++ b/drivers/dfu/dfu_alt.c @@ -23,14 +23,14 @@ * * Return: 0 - on success, error code - otherwise */ -int dfu_write_by_name(char *dfu_entity_name, unsigned int addr, +int dfu_write_by_name(char *dfu_entity_name, void *addr, unsigned int len, char *interface, char *devstring) { char *s, *sb; int alt_setting_num, ret; struct dfu_entity *dfu; - debug("%s: name: %s addr: 0x%x len: %d device: %s:%s\n", __func__, + debug("%s: name: %s addr: 0x%p len: %d device: %s:%s\n", __func__, dfu_entity_name, addr, len, interface, devstring); ret = dfu_init_env_entities(interface, devstring); @@ -69,7 +69,7 @@ int dfu_write_by_name(char *dfu_entity_name, unsigned int addr, goto done; } - ret = dfu_write_from_mem_addr(dfu, (void *)(uintptr_t)addr, len); + ret = dfu_write_from_mem_addr(dfu, (void *)addr, len); done: dfu_free_entities(); diff --git a/include/dfu.h b/include/dfu.h index cecfbd76597b..2299a83a3d94 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -507,10 +507,10 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, * Return: 0 - on success, error code - otherwise */ #if CONFIG_IS_ENABLED(DFU_ALT) -int dfu_write_by_name(char *dfu_entity_name, unsigned int addr, +int dfu_write_by_name(char *dfu_entity_name, void *addr, unsigned int len, char *interface, char *devstring); #else -static inline int dfu_write_by_name(char *dfu_entity_name, unsigned int addr, +static inline int dfu_write_by_name(char *dfu_entity_name, void *addr, unsigned int len, char *interface, char *devstring) { From patchwork Thu Oct 29 00:25:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319306 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15012ilc; Wed, 28 Oct 2020 17:26:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+2ZvmjiAORXmjIL6T7/hES1F5rRQWSaNfHdAZyq6TT/K9livKw96x8hLMHb1OQWn8kV0x X-Received: by 2002:a50:fe05:: with SMTP id f5mr1569173edt.366.1603931184432; Wed, 28 Oct 2020 17:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931184; cv=none; d=google.com; s=arc-20160816; b=zSza0T5BmVDE6ebCmzftAE/WL4z8I8UnDbAR8/0aSqFbIUvqf2X4rEj8cZojXlwuPJ lahF+E+CuQIGZqc43GkkAbJIfzKUAookCZYfx7DrkktgGkU15Lx2sFOD47hwsoxo9z/Y WtlzQYvLTz/cKtAMSb4hX8lUwm1nv5SVZ/Ws2e0sqWp1GdzJDJf8CV5LbktOCcXozcq8 tmTBKw2vSUotUEpB7BeztQSEe0iS+BQ8lROjEesqIY5qBadO3R08BLhSe8gLsRidaLyY M/nZIk5HJyFkWSUNWZj8q4x9fKDSjj2uj0aJAYR78Q4m9/5PK4hLOaFJclqbvGoCHJRl qmdw== 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=FcJgQrljui/HJx683kIxTRBuXZBU0d8QT3uyfp4p+FI=; b=moVotXSB9r/AdEjRJfhbs0Z1lZrP7mv4/fgQ6JiwBtUrLVsCX4ueifc/bdzgjOjgei 6MjmmgxIo7jHonE4xFiu/Rk7Y21ZEQhf5gnSHmeiN5GkmCLjOdjMPD2m+dvGCGHzydqs AsCOKBhXpwUHatvmCwDL3qHmP+hh37wHz3Hpw6bAjl7O2wLmzeRPLOl2ic6J33xkBaGy w2+gWznauV0Km6g3jq0YPR1jNYk2akFfIWNMFTLnRtVXoyq2jjlcIrpppaNoV1Nwr8TP pSNrP9EJ+FHcEEkWddGz6d+gTXYCz5nUtycYeFUWBxxBr+y6RXPoXvlWxNrHY/T2DJFg xWyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WMWyIFkq; 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 nt19si660175ejb.490.2020.10.28.17.26.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:24 -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=WMWyIFkq; 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 DC63B824E1; Thu, 29 Oct 2020 01:26:08 +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="WMWyIFkq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 394E3824C5; Thu, 29 Oct 2020 01:26:06 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (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 966EA8248E for ; Thu, 29 Oct 2020 01:26:02 +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=takahiro.akashi@linaro.org Received: by mail-pf1-x444.google.com with SMTP id 13so868823pfy.4 for ; Wed, 28 Oct 2020 17:26:02 -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=FcJgQrljui/HJx683kIxTRBuXZBU0d8QT3uyfp4p+FI=; b=WMWyIFkqTkPo+8+Y1DoFn19TE2v1h2JEAAX/pYWVHJy1OxCUTlKM7vr3Xon2DdK4TW lKpUr4JTpJW7KYSFO8KuMCI77zh4SvaPTu+NuZUcP5CN58NHIB6VTETH4PGO/v87bNJV QtxU8vqI0tRaWVZgniFHMG5pmRVHfSmaVsya/dl8lMfbBwdnqjmGGnfeo+CMOXdLxJWh BQ3e/jHqhfE7wLFwyDaWKvRC9HHfF/ahTCLh194QthAmRv40ftVOk46TnuOC4O3rlIeF 35bIPQNowkFmntEeGWyc+TEEf/LoHTm4+j3NLpX0ppYxfq9WVYIwdR+aIJ3oinkOOnjT WmvA== 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=FcJgQrljui/HJx683kIxTRBuXZBU0d8QT3uyfp4p+FI=; b=DdoQUC1as90ZxjCjiAemdVDQ4LIilUgU5ao6wpEAIAKcbWxEjoToX8k9wyyW8edZaI Arjmrvl5UpuvgNwhxbRHEKOLVyFcD9guvOxTUF43yeWRlVusLJbXHMnAZdKMU+NPf+Hd htNbLQjsHsBQFXdFPiPS+qWtQstjYYZiWTHSLRqJ7Mk7BYJ4XAdvLTLgqtOKQ9KK5oPH gReUH4VWeRpc+i9kqcytkmvc2r8KwffarBN9EQw8vNPomi1yefBcJScErVKhonJcmgBS /JEHMIT3ABujotvoYsfZ1sGpLiEQxsFS24vkxnqoXo167xZfJ9l2Ji1us+QsrTWpbLbT fxqg== X-Gm-Message-State: AOAM532xk97WPn1ClQ+ljMdZs17Qm8HKG7AZStuu08IrdAeWTWlhPjxn +El3DcxH0l4lxVcrIzkWyP2hWw== X-Received: by 2002:aa7:9a86:0:b029:163:bfc2:2d7e with SMTP id w6-20020aa79a860000b0290163bfc22d7emr1421490pfi.61.1603931161069; Wed, 28 Oct 2020 17:26:01 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:00 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 03/17] common: update: add a generic interface for FIT image Date: Thu, 29 Oct 2020 09:25:14 +0900 Message-Id: <20201029002528.34408-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean The main purpose of this patch is to separate a generic interface for updating firmware using DFU drivers from "auto-update" via tftp. This function will also be used in implementing UEFI capsule update in a later commit. Signed-off-by: AKASHI Takahiro --- common/Kconfig | 15 ++++++++++ common/Makefile | 3 +- common/update.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ drivers/dfu/Kconfig | 1 + include/image.h | 12 ++++++++ 5 files changed, 100 insertions(+), 2 deletions(-) -- 2.28.0 diff --git a/common/Kconfig b/common/Kconfig index 318d372a481b..787d203d0aea 100644 --- a/common/Kconfig +++ b/common/Kconfig @@ -599,9 +599,15 @@ endmenu menu "Update support" +config UPDATE_COMMON + bool + default n + select DFU_ALT + config UPDATE_TFTP bool "Auto-update using fitImage via TFTP" depends on FIT + select UPDATE_COMMON help This option allows performing update of NOR with data in fitImage sent via TFTP boot. @@ -616,6 +622,15 @@ config UPDATE_TFTP_MSEC_MAX default 100 depends on UPDATE_TFTP +config UPDATE_FIT + bool "Firmware update using fitImage" + depends on FIT + depends on DFU + select UPDATE_COMMON + help + This option allows performing update of DFU-capable storage with + data in fitImage. + config ANDROID_AB bool "Android A/B updates" default n diff --git a/common/Makefile b/common/Makefile index 2e7a090588d9..bcf352d01652 100644 --- a/common/Makefile +++ b/common/Makefile @@ -53,8 +53,7 @@ obj-$(CONFIG_LCD_ROTATION) += lcd_console_rotation.o obj-$(CONFIG_LCD_DT_SIMPLEFB) += lcd_simplefb.o obj-$(CONFIG_LYNXKDI) += lynxkdi.o obj-$(CONFIG_MENU) += menu.o -obj-$(CONFIG_UPDATE_TFTP) += update.o -obj-$(CONFIG_DFU_TFTP) += update.o +obj-$(CONFIG_UPDATE_COMMON) += update.o obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o obj-$(CONFIG_CMDLINE) += cli_readline.o cli_simple.o diff --git a/common/update.c b/common/update.c index 8dd6ee8b7ddb..808be0880dfd 100644 --- a/common/update.c +++ b/common/update.c @@ -29,6 +29,7 @@ #include #include +#ifdef CONFIG_DFU_TFTP /* env variable holding the location of the update file */ #define UPDATE_FILE_ENV "updatefile" @@ -98,6 +99,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr) return rv; } +#endif /* CONFIG_DFU_TFTP */ #ifdef CONFIG_MTD_NOR_FLASH static int update_flash_protect(int prot, ulong addr_first, ulong addr_last) @@ -231,6 +233,7 @@ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, return 0; } +#ifdef CONFIG_DFU_TFTP int update_tftp(ulong addr, char *interface, char *devstring) { char *filename, *env_addr, *fit_image_name; @@ -337,3 +340,71 @@ next_node: return ret; } +#endif /* CONFIG_DFU_UPDATE */ + +#ifdef CONFIG_UPDATE_FIT +/** + * fit_update - update storage with FIT image + * @fit: Pointer to FIT image + * + * Update firmware on storage using FIT image as input. + * The storage area to be update will be identified by the name + * in FIT and matching it to "dfu_alt_info" variable. + * + * Return: 0 - on success, non-zero - otherwise + */ +int fit_update(const void *fit) +{ + char *fit_image_name; + ulong update_addr, update_fladdr, update_size; + int images_noffset, ndepth, noffset; + int ret = 0; + + if (!fit) + return -EINVAL; + + if (!fit_check_format((void *)fit)) { + printf("Bad FIT format of the update file, aborting auto-update\n"); + return -EINVAL; + } + + /* process updates */ + images_noffset = fdt_path_offset(fit, FIT_IMAGES_PATH); + + ndepth = 0; + noffset = fdt_next_node(fit, images_noffset, &ndepth); + while (noffset >= 0 && ndepth > 0) { + if (ndepth != 1) + goto next_node; + + fit_image_name = (char *)fit_get_name(fit, noffset, NULL); + printf("Processing update '%s' :", fit_image_name); + + if (!fit_image_verify(fit, noffset)) { + printf("Error: invalid update hash, aborting\n"); + ret = 1; + goto next_node; + } + + printf("\n"); + if (update_fit_getparams(fit, noffset, &update_addr, + &update_fladdr, &update_size)) { + printf("Error: can't get update parameters, aborting\n"); + ret = 1; + goto next_node; + } + + if (fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE)) { + ret = dfu_write_by_name(fit_image_name, + (void *)update_addr, + update_size, NULL, NULL); + if (ret) + return ret; + } +next_node: + noffset = fdt_next_node(fit, noffset, &ndepth); + } + + return ret; +} +#endif /* CONFIG_UPDATE_FIT */ diff --git a/drivers/dfu/Kconfig b/drivers/dfu/Kconfig index 78f901ff348a..ce0c42c7df9c 100644 --- a/drivers/dfu/Kconfig +++ b/drivers/dfu/Kconfig @@ -22,6 +22,7 @@ config DFU_TFTP bool "DFU via TFTP" select DFU_ALT select DFU_OVER_TFTP + select UPDATE_COMMON help This option allows performing update of DFU-managed medium with data sent via TFTP boot. diff --git a/include/image.h b/include/image.h index 4094ee588a57..00bc03bebece 100644 --- a/include/image.h +++ b/include/image.h @@ -1602,4 +1602,16 @@ struct fit_loadable_tbl { .handler = _handler, \ } +/** + * fit_update - update storage with FIT image + * @fit: Pointer to FIT image + * + * Update firmware on storage using FIT image as input. + * The storage area to be update will be identified by the name + * in FIT and matching it to "dfu_alt_info" variable. + * + * Return: 0 on success, non-zero otherwise + */ +int fit_update(const void *fit); + #endif /* __IMAGE_H__ */ From patchwork Thu Oct 29 00:25:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319307 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15107ilc; Wed, 28 Oct 2020 17:26:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrI4PB/VYw5W5q7tT4nyzdhqDTjvXxEReYuVp+VgvER80N6juERa5AgUEOhVqxp2AG/UZX X-Received: by 2002:a05:6402:782:: with SMTP id d2mr1498629edy.131.1603931195810; Wed, 28 Oct 2020 17:26:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931195; cv=none; d=google.com; s=arc-20160816; b=OQOilyIWSR4AQ9iTt4ma2M8rdQnijPteDXqvm2P7aG35yizqxQ7jJ2BqwXm8PAICYQ xH6mxWlv6iHHPMT9N4QxeSi35Ln3bGXNicOUMespS5VIgM7GHrmKgSfwd3avmZJ/ztvU xwtOa5B39TM15s4BGs4BKPDzkVZ5xAeP+f4d2hVs/9GRn2glySK4wnhXzvrbCSEFdsL9 +CO63ImvrLbrbxRjqJ7RQciurckMPyj52ufNiSmzxRIaKYE4v5WuGjccMo5fv2TltSc1 PVCuy+kkaIGYhOT4fGSeFpxSv7PB4UvvWVcLdic5WCBTNciey2KjlOaIxyOtznVPxdFZ 4htA== 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=0AfYMcPf+ZnAOcOuxNgaIkD5zAmRUz9pGnONGECo7aA=; b=VDYStte1eEW/Wfbfv4aTfiuhJejEFdICrBsLibRh2gAlpn3STIj6XmZ8yWhD/HD3QY g8xaXZSBgt/YyTVk+sUul31DUqp8MYhEMrP964nUzAlx3voingiFJEEeMg5d542Q1IVY vilp2bWLD7jb62FIamvnUBexpCo3dElt87Z0wOx4TVGtpDlamZTv01DgdM5+WGeFNtze wSvr3K3bvZcmrQMWlwLy46j0oMBqsSh03ChE7sIJDiZMjCJTqc/J6atED0xmRv4YNIJN +rdmqcKe16pVj72vRfiIxMwPD5u0mXEQU+9uK5SF7EojdqM4RvuKcDJ/wHthq55hWE1z au/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bs24wBBb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id y17si669650ejb.417.2020.10.28.17.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:35 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bs24wBBb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 8305F824EC; Thu, 29 Oct 2020 01:26:17 +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="bs24wBBb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2D61C824DE; Thu, 29 Oct 2020 01:26:09 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (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 6FC41824AE for ; Thu, 29 Oct 2020 01:26:05 +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=takahiro.akashi@linaro.org Received: by mail-pf1-x441.google.com with SMTP id y14so840259pfp.13 for ; Wed, 28 Oct 2020 17:26:05 -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=0AfYMcPf+ZnAOcOuxNgaIkD5zAmRUz9pGnONGECo7aA=; b=bs24wBBbauAtiyosmoaMn3dwI0ZlM+hOEZNXyRddRxhpd8XxKVOOJKdozH89VTrJ96 rZ0jbY/3L74N2NtgdQZpHnTnPggFmsqNR0GE2qdI3gVm9dxitKiGOkpaM4e+cD1DBDK0 bkcyu+bOoqDQPgmOjJ2mgRjyjAYyAT0h1tLVKcP8GwMBC+SpLUi7gHb8APXgOdYUEcpX uReBY+AzL5yOdpjT3sXxcjgBDGwUYyxp5CYVqFXi8B6uX85SyYPkjNjih9trVGQj+MCr kWM2jRfweVP7ebJftFEdH5/+izvDX4AAlU4PAvND3yIIIGyG0J3YjN96ai8b2psaDAK4 hxHw== 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=0AfYMcPf+ZnAOcOuxNgaIkD5zAmRUz9pGnONGECo7aA=; b=l1eIulMShOhEpS1GVjLbwwcUR6h/i1+CH32m5qhdjhN+eXO8heD3l1CgpwEVWOr5S+ cPMA66ZH7oqVS8HeYTQkl7iRjtlMim8nGJ3fcykfgU0rWU3MNGlqO07NdgRNgTU39aX3 5nzN+IHB9diHQ7cs8pc46VdrtWbcaJQtcRydDstYnnYJkRTDYgKHf+8RGSFEi9qeEvwA fEnFZHB95OFUXplpePVSnecvFba1oYOAYYE3zWmn2loFJ/2EhJ07ghj6+Cy6UmDkWThT 1eU3C8tzo++eR7bKkUHOH7gPmz0YycfngmNnQBDU10Uwq8E6N5JO8adyCf3qzlPn7ZqO 5onQ== X-Gm-Message-State: AOAM532i2NLvCYVCfP3hdSGwjhVRwSz85s5MM43fSZ3gycHpBxX6/zJR VBEcgiZQAkI+UhWQVU70SbTugyYufJ6oWQ== X-Received: by 2002:a63:541a:: with SMTP id i26mr1703887pgb.117.1603931164064; Wed, 28 Oct 2020 17:26:04 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:03 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 04/17] dfu: export dfu_list Date: Thu, 29 Oct 2020 09:25:15 +0900 Message-Id: <20201029002528.34408-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean This variable will be utilized to enumerate all dfu entities for UEFI capsule firmware update in a later commit. Signed-off-by: AKASHI Takahiro --- drivers/dfu/dfu.c | 2 +- include/dfu.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) -- 2.28.0 diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index a298c2c43999..501a60b34400 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -18,7 +18,7 @@ #include #include -static LIST_HEAD(dfu_list); +LIST_HEAD(dfu_list); static int dfu_alt_num; static int alt_num_cnt; static struct hash_algo *dfu_hash_algo; diff --git a/include/dfu.h b/include/dfu.h index 2299a83a3d94..015d1bf895d0 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -158,6 +158,9 @@ struct dfu_entity { unsigned int inited:1; }; +struct list_head; +extern struct list_head dfu_list; + #ifdef CONFIG_SET_DFU_ALT_INFO /** * set_dfu_alt_info() - set dfu_alt_info environment variable From patchwork Thu Oct 29 00:25:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319308 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15197ilc; Wed, 28 Oct 2020 17:26:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylMENaITX1mJ2oVlcrs2MdTcf4Xy9m+9Nxjl8ePzF0+M4mVYHFMi/mRuTPlLwjnvBBLJt4 X-Received: by 2002:a17:906:a05a:: with SMTP id bg26mr557566ejb.379.1603931207546; Wed, 28 Oct 2020 17:26:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931207; cv=none; d=google.com; s=arc-20160816; b=T+8YXgiffOaKJqdfVa0XzUal047ZXybVQ/os218vq1igZgV9qTeWtP4nj38MWd2EUc pZD2wtkEaG5PiLzziWHyTEDHWQ/nmS25JSiqGRs5fXtXn09cEq+F3yCEgX57YaXktoXi S4h/ditdKyEzqw3jZaP/fy31Kq0buYgL7SvTkZPktXEQEnMn5tx2n67oGm2EU8smdC/Z jAQfKZew9rpKu967VSqlK+9psTIJAzolXbVHDI26gQwKBzniB7V1AXMFQyWFQiiFhCjF aQXwUynFCgyDc4a5s49/yc5mfes6PUh4dDLapnZGcV6NfchPTdfEEcANRgmKWwOPLgPu yTlA== 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=n5F2thosGyZvZniKXgGd9Rsns7gjUVAKncs8BSfblsY=; b=mky/7GJh6SOApGaHWBCTP01mNhOGlXr1lIsFgSJwiBaea4gkhvQETx4lreFUmuxTRz OuGUaBDNW/7EVPpXTUZ1eDxCCfmGPV3WjrwPx7U+f9x155jfP8NBqLuKQgXJOTU6REzL Xpg/Bz2zPkKAorbhZVO6izB8adNlgCLrFhDMgOwhpNhroW1f5xylmQ4GMn1PvwLU4jVn rUoK1IGvpyYdGbrdnMxS8mK/YP0YBwLRka1KGf0iYklD5/eeAEF3IRx2Yz0yuW72lK6B yYQL0riCpb/ux11owm4majYNddkFSY52uUXpeR9qntIDZmVZg1xbDmZF7N+np42OA6nh dMqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b5SrYbPq; 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 bo6si637609ejb.367.2020.10.28.17.26.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:47 -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=b5SrYbPq; 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 70B6E824FC; Thu, 29 Oct 2020 01:26: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="b5SrYbPq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B0AE9824DE; Thu, 29 Oct 2020 01:26:11 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (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 A82AE824A8 for ; Thu, 29 Oct 2020 01:26:08 +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=takahiro.akashi@linaro.org Received: by mail-pg1-x543.google.com with SMTP id s22so890436pga.9 for ; Wed, 28 Oct 2020 17:26:08 -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=n5F2thosGyZvZniKXgGd9Rsns7gjUVAKncs8BSfblsY=; b=b5SrYbPqC5M9jU7DXL4pftCcuiEdHq55bqMEXH+6n4XtANGaF6jXnZw+Gyx/xPFIsz 9zaNSqYoLkmocYZnZQyE7YEMpP+HC4Mc60yxphuJ08V/YpkyLvVXn/4UD5t/zaNCWqsx aomP7v5EOmYr6WLsZlSnE8xdAp3eixBwSH3/jnTrN8VEpW1+V4/2CPrkKOiAm0ZQvDUW 18tV8RJn8PI8sjI2/TZAclcm2OXGmUlWEcj2ebIlQWXXFpANTJHg6MxhdLm10B/vnYIV 8wfcTo2dyaURUDxy6CtFtuHZo7OY0Qc0k/h+g60JMSdA1dyyi95rLoKX/2tqSVpjWtAY IOBw== 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=n5F2thosGyZvZniKXgGd9Rsns7gjUVAKncs8BSfblsY=; b=VcjqRuhuBoaBtk/P9yMMjcRiRjiqXWG5KN5TEHUgcSGZmA1BRTcs5EtpY2cDO9nCn+ hEfBwdZlVodhHBd89CuIjD1vjSfzOQ2qUhTWx4UNzlBJDNCMTgpm48i/3oaLrX9GgMkq AwBQWpIF0Kfv+MatxGGfGWd7l48TfbaG9x4oUEW+khsRZJbRfsXl1Wlt825flb2oOeJW aKDVhzy+sjuh+WgIevM6nfaD5cj2FXZr46uXXxJkjg2/Hh5Qnt5fL9pMFESxBNI2sSUh f4r0g4khwvSWn5oL/4tl+tpW+eXUpsbnEjqMjhKfPmAVJ3TE5pdLdZWn79W5OoVx0W8G K+Ew== X-Gm-Message-State: AOAM5338fVcRM8jnymHqJRZLXEYvTlxYMKk+hNmxlPlp2Ju/jWhKbZzM XU0oUtjZQLS6M0NNRdUJjVjamw== X-Received: by 2002:a17:90a:db55:: with SMTP id u21mr1376914pjx.235.1603931167234; Wed, 28 Oct 2020 17:26:07 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:06 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 05/17] efi_loader: add option to initialise EFI subsystem early Date: Thu, 29 Oct 2020 09:25:16 +0900 Message-Id: <20201029002528.34408-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean If this option, CONFIG_EFI_SETUP_EARLY, is enabled, the initialisation of UEFI subsystem will be done as part of U-Boot initialisation. Please note that this option won't be enabled explicitly by users, instead, should be enabled implicitly by other configuration options. Specifically, this feature will be utilised in implementing capsule-on-disk feature. Signed-off-by: AKASHI Takahiro --- common/board_r.c | 6 ++++++ lib/efi_loader/Kconfig | 4 ++++ 2 files changed, 10 insertions(+) -- 2.28.0 diff --git a/common/board_r.c b/common/board_r.c index b9217b2e27f0..2212d981e5ea 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -73,6 +73,9 @@ #if defined(CONFIG_GPIO_HOG) #include #endif +#ifdef CONFIG_EFI_SETUP_EARLY +#include +#endif DECLARE_GLOBAL_DATA_PTR; @@ -889,6 +892,9 @@ static init_fnc_t init_sequence_r[] = { #endif #if defined(CONFIG_PRAM) initr_mem, +#endif +#ifdef CONFIG_EFI_SETUP_EARLY + (init_fnc_t)efi_init_obj_list, #endif run_main_loop, }; diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index ab42f3ba75b1..075481428cdf 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -27,6 +27,10 @@ config EFI_LOADER if EFI_LOADER +config EFI_SETUP_EARLY + bool + default n + choice prompt "Store for non-volatile UEFI variables" default EFI_VARIABLE_FILE_STORE From patchwork Thu Oct 29 00:25:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319309 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15329ilc; Wed, 28 Oct 2020 17:27:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQv5U0b/3Efty6DuHjfyOnJf2gxGjLLXRPekdY1YDTseHOv9v9isjybZI99sfaUG+rsxW+ X-Received: by 2002:a17:906:e83:: with SMTP id p3mr364021ejf.243.1603931222032; Wed, 28 Oct 2020 17:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931222; cv=none; d=google.com; s=arc-20160816; b=Tq0VHl7/XzmTw/kZwoW9iiup5qwCAZl3lHKzcyfIKiZ7YzX1lYwO3z6zXpmhowU6wd 4D0d9nrdBEu8eQtX0pyGgXLvxMyfhldWUlUL7asCw2D3S9WpdiE4HwTAlE9TC5lep+rE pfV8hKdT7lnbBcx3RCZWJpihvVMHDftYjdzKNe913jQd4AyRaa33vcsOOd24B8ATMbMk OMdtESqa7zKRbF0Xuvag0uoLnD/RJZyWSnIJKn/mxcxk6vkkTwINennr2dXDrFMISNyh X+WvDZYvOu8ym2/JRMSyHxVlMSVqO7gvqXOPpClU2gbHedlJOEjuU15kJPQsxyWbg2P+ SvtQ== 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=GSl8/l9AOaOO/jgvjLXv/fxiBZTskrBqb2jbCbYfjeQ=; b=nxZK42LHMJ6WpkTiO187Xt6SEIs4iWGiI8ieah5a5VUv+wdgnWshtOQPDTrUFU1GmB 9m5L4l2P+jcOil1817kyUOxlNO7KERmv2fxTbzd7Txp6hpBSmeT6IC9BcDmpj5lAvphv hogRLo49AGgVsWxZLm+oy1MI1Cli/fJPlOWP9EvAbg5Ak/Qmg87IMQ7cYi00Vo4O50Vy NvbLZdQp9LcUyIpk23OSOZo+rIVdL66jGXqxqcs12nllf0mWya76TN3b5OPnBBGzENUi FBCi2baDvdHOc/3VvNEjeTgnApdk85CZDwNN68Bc1VzUNj/MZ1oZDxAC2yUh9MnPfwMt vtpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DjC5ZcuW; 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 e3si647618eja.411.2020.10.28.17.27.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:27:02 -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=DjC5ZcuW; 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 8A047824DA; Thu, 29 Oct 2020 01:26:25 +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="DjC5ZcuW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 164EA824E8; Thu, 29 Oct 2020 01:26:17 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (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 CC458824A8 for ; Thu, 29 Oct 2020 01:26:11 +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=takahiro.akashi@linaro.org Received: by mail-pl1-x641.google.com with SMTP id b19so473514pld.0 for ; Wed, 28 Oct 2020 17:26:11 -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=GSl8/l9AOaOO/jgvjLXv/fxiBZTskrBqb2jbCbYfjeQ=; b=DjC5ZcuWDPgcToE3beTiCjN7c/l9awS1dMzo17qyWlwsyzdo2MRzsFziFHrlWlkbVH +FwE9Sz+h8cOADJD8Dd7d8thmyOa8MteZX4c9bL/0dmanv2707T8piAEouMqOkFJgvCb EJrFkI+Z/2FELqguMkhR5ATgSMLT+n/Tl6lHH8PXEozbZwJl6AGHA28rAN1IvB+6HihV 4QJChYgXe9kD5E6+gu8QrGaCLv2JAcOULGU5D1Zqgw0AMCAbyUEFm7XZBJQRfLEn/oPS cfhiV9h16ZOvjJiHQFhBFvMGjke1ryH4aoPW/AciXOlKllYy6P4mapSipsnuR3q5BKzR UGxA== 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=GSl8/l9AOaOO/jgvjLXv/fxiBZTskrBqb2jbCbYfjeQ=; b=IhbYj7Uk43mrKJnv3kGkXoGWePjXCzG27sDE0g2EiqC7pBM7frNKweZTjQDxF2ROKO OH9CQn26QqZDvPHT4kJDVy0Y/H5ViM+hW8yRUbkaPyLXmdMAbnWmWSDsmBHxVrHf315P wMzt6Xb/SPGmq3GilMZL8arTaROXht5iEIoYkQ6iwGFtXWNia1iNnmUObxj3Kkw5Y3w8 k3gkh5xQ9wU0NGn9Ptw4gq93D2FDhSf+qXzc5f/cV8KpECSXWCsP5epKC9niSZEXNDtb 0U6Q9PlxVsdoGHcWeV9yXtmldRIgzW29LjQAXoU+IpfW/nGVFeVPrjmI2iqxT+dFOe8Y BiLg== X-Gm-Message-State: AOAM533qSMRj3gzZItDA09wu2dbkTy/4bsaOQUvJhpxa23M5Tg7208bs Fo/3RYWhhzeOk8XSDrecsIUSdexXSOmFdQ== X-Received: by 2002:a17:902:7004:b029:d6:489b:6657 with SMTP id y4-20020a1709027004b02900d6489b6657mr1438208plk.20.1603931170216; Wed, 28 Oct 2020 17:26:10 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:09 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 06/17] efi_loader: add efi_create_indexed_name() Date: Thu, 29 Oct 2020 09:25:17 +0900 Message-Id: <20201029002528.34408-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean This function will be used from several places in UEFI subsystem to generate some specific form of utf-16 variable name. For example, L"Capsule0001" Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 3 +++ lib/efi_loader/efi_setup.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) -- 2.28.0 diff --git a/include/efi_loader.h b/include/efi_loader.h index 7eea5566fdc9..6865a4847d53 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -804,6 +804,9 @@ bool efi_image_parse(void *efi, size_t len, struct efi_image_regions **regp, /* runtime implementation of memcpy() */ void efi_memcpy_runtime(void *dest, const void *src, size_t n); +/* commonly used helper function */ +u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index); + #else /* CONFIG_IS_ENABLED(EFI_LOADER) */ /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */ diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 45226c5c1a53..6346eda771d0 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -235,3 +236,32 @@ out: efi_obj_list_initialized = ret; return ret; } + +/** + * efi_create_indexed_name - create a string name with an index + * @buffer: Buffer + * @name: Name string + * @index: Index + * + * Create a utf-16 string with @name, appending @index. + * For example, L"Capsule0001" + * This function is expected to be called only from several places + * in EFI subsystem. A caller should ensure that the buffer have + * enough space for a resulting string, including L"\0". + * No strict check against the length will be done here. + * + * Return: A pointer to the next position after the created string + * in @buffer, or NULL otherwise + */ +u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index) +{ + u16 *p; + char index_buf[5]; + + u16_strcpy(buffer, name); + p = buffer + utf16_strnlen(name, SIZE_MAX); + sprintf(index_buf, "%04X", index); + utf8_utf16_strcpy(&p, index_buf); + + return p; +} From patchwork Thu Oct 29 00:25:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319310 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15412ilc; Wed, 28 Oct 2020 17:27:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7x0WWBekaq2tj81GvZVNrg4WbeiN0fFzrm68dvZ+oNyHbQgkPFTuMjp3FH1vQEcN8LXag X-Received: by 2002:a17:906:1614:: with SMTP id m20mr1619824ejd.258.1603931234058; Wed, 28 Oct 2020 17:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931234; cv=none; d=google.com; s=arc-20160816; b=DJVlZSx1Aw3IaZq+bFErXO+gZ4N5dan5i0XmOmlGhTgcjeEekVltsIPIHX9TeWAxE0 EXmOMWB1XygIWfBNz9ooxEU9llWQRq7prZkPnLwBImqELKNGZ8wVyxMYpkknWACZ8pLC 23Q0uOBPeyXHGLfaXrf04EWY2ihvJlIwhui0oRMAQ2RG3gixM7bmys7unGwYIrKPY3cZ GNJSk21sCUbTt1e2fCq3Ng/pX4Dv7+vnIEpun6k4wrBSPYMTP1sxgKc3kIo6VVUrbQno pOFYM9bPUvtMyBgy1UfwFWc20/Z2s/OqsX68RofXUvGQ+mu38gAcZ6L+41B3PYLIE6Vf hw6Q== 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=knf0brLjC9JIcYXe/vOGa5O91hreLu9DM7d+AV9Agn0=; b=SWq/wsrMjkq3no8soqvxdVCUkjsXQS0sKDkGkh4F+ylYD1lU+VLfXb58LRoO5sYqeO 3CxWOEnZ/3f4EEWjQrSpgsMZs2LGXe6U37K3TJz5eyxCMKpvJAf/rF4TMOrV6iay+teC byEJ5Mepy42XtelOEaPNLWPhodwW2zf69L0wfyOIGJNokm/9EMnaCJQGEz333fy/FMIG H1Prn7/orRdZsw/xvz/8k1okWGBTry0VfXIv41p7fW8xof7A7N+ryCcTuHMgIN9KZlWX 5uv7r4S2Es6fgsoHQj3ohYJjCX05uTtZpjIHiRUbPTqD0b4dkwVM1o1X9zPtwwpF7yyw MPTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XChjtyKE; 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 ne6si751586ejb.416.2020.10.28.17.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:27:14 -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=XChjtyKE; 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 F1E2482509; Thu, 29 Oct 2020 01:26:26 +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="XChjtyKE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 75E1A824FD; Thu, 29 Oct 2020 01:26:21 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) (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 8A8B7824E5 for ; Thu, 29 Oct 2020 01:26:16 +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=takahiro.akashi@linaro.org Received: by mail-pg1-x542.google.com with SMTP id 15so881192pgd.12 for ; Wed, 28 Oct 2020 17:26:16 -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=knf0brLjC9JIcYXe/vOGa5O91hreLu9DM7d+AV9Agn0=; b=XChjtyKEvBaTakEFjIZovw2cy/oq5RDu7qx4CEBNdvyDEnxXhYNvB5eZ24WZCue4jQ goSUsV0U+3msbt3G5BDSa8umQV6sF+LYbgav7EgtD2g4kV8LHsL7ksWGpirXtnrDzra2 +GGFz90Twfkd2/UO7LNkpO0TEDNAb1VsQvkCpJeNo4A6HDONSZ406EiMMSB6OySjVDaT 8OBy2+wXxX4G28rWASmSgwciTb/4Ka6yq6zMjs74CEiTS4s/YxIZA6vG8kDrvLH2VeSJ iD+fyGi7eDRckUjcwg+EhZytfHtaCFeBv8Bo3+MTvTihCgJx/x6JcL4cifRrYybWqek6 Q7Mg== 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=knf0brLjC9JIcYXe/vOGa5O91hreLu9DM7d+AV9Agn0=; b=nCkMVmUiJTUHRYuN1ypeFp6aw+b5MIbN5mUIkQl5RUbvqj2ssEMbbavOE4QAXRQcQb OAwsKm671vEgp+zlRoY/AHpo7Gel4topKgRJDb+QzUcuNKDHCW7+Q7vOm5c2MptGyrvI 0M20Sg98IIUlgENpGXiE6+YGzUMh+Nbj58Q54JJGp9vaeqn9a2xxmo+Z9w49J5Fwp8GF K8YIXvTf0YDHLWi9/lLT61hLVC+xnUf5I9K2EFynLt8GpmuVNWYqOPiAOKSQij3NrnpO hHZ9J7vKg23Lg+LCl61dxtEJzpOWsF2QAgzupTTBLBrCbMZf+hteQAilmz+HVM+UajUM DZ4A== X-Gm-Message-State: AOAM533RHOC5wkJJdBZKDd8j9u7dg1pJCV6ejj/74Pg2/ATl2n9E+2We YVKteOw4zq3fWKP1Ys2NtVZhjGvp5AvjGQ== X-Received: by 2002:a17:90a:a107:: with SMTP id s7mr1447887pjp.208.1603931173292; Wed, 28 Oct 2020 17:26:13 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:12 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 07/17] efi_loader: define UpdateCapsule api Date: Thu, 29 Oct 2020 09:25:18 +0900 Message-Id: <20201029002528.34408-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean In this commit, skeleton functions for capsule-related API's are added under CONFIG_EFI_UPDATE_CAPSULE configuration. Detailed implementation for a specific capsule type will be added in the succeeding patches. Signed-off-by: AKASHI Takahiro --- include/efi_api.h | 12 +++ include/efi_loader.h | 13 +++ lib/efi_loader/Kconfig | 11 +++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_capsule.c | 165 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_runtime.c | 104 ++++++++++++---------- lib/efi_loader/efi_setup.c | 64 +++++++++++--- 7 files changed, 316 insertions(+), 54 deletions(-) create mode 100644 lib/efi_loader/efi_capsule.c -- 2.28.0 diff --git a/include/efi_api.h b/include/efi_api.h index 5744f6aed86d..c128a0a66ce8 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -217,6 +217,10 @@ enum efi_reset_type { #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000 #define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 +#define EFI_CAPSULE_REPORT_GUID \ + EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \ + 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3) + struct efi_capsule_header { efi_guid_t capsule_guid; u32 header_size; @@ -224,6 +228,14 @@ struct efi_capsule_header { u32 capsule_image_size; } __packed; +struct efi_capsule_result_variable_header { + u32 variable_total_size; + u32 reserved; + efi_guid_t capsule_guid; + struct efi_time capsule_processed; + efi_status_t capsule_status; +} __packed; + #define EFI_RT_SUPPORTED_GET_TIME 0x0001 #define EFI_RT_SUPPORTED_SET_TIME 0x0002 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004 diff --git a/include/efi_loader.h b/include/efi_loader.h index 6865a4847d53..ffe772866675 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -207,6 +207,8 @@ extern const efi_guid_t efi_guid_cert_type_pkcs7; /* GUID of RNG protocol */ extern const efi_guid_t efi_guid_rng_protocol; +/* GUID of capsule update result */ +extern const efi_guid_t efi_guid_capsule_report; extern unsigned int __efi_runtime_start, __efi_runtime_stop; extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop; @@ -807,6 +809,17 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t n); /* commonly used helper function */ u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index); +/* Capsule update */ +efi_status_t EFIAPI efi_update_capsule( + struct efi_capsule_header **capsule_header_array, + efi_uintn_t capsule_count, + u64 scatter_gather_list); +efi_status_t EFIAPI efi_query_capsule_caps( + struct efi_capsule_header **capsule_header_array, + efi_uintn_t capsule_count, + u64 *maximum_capsule_size, + u32 *reset_type); + #else /* CONFIG_IS_ENABLED(EFI_LOADER) */ /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */ diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 075481428cdf..3ca396df3646 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -93,6 +93,17 @@ config EFI_SET_TIME Provide the SetTime() runtime service at boottime. This service can be used by an EFI application to adjust the real time clock. +config EFI_HAVE_CAPSULE_SUPPORT + bool + +config EFI_RUNTIME_UPDATE_CAPSULE + bool "UpdateCapsule() runtime service" + default n + select EFI_HAVE_CAPSULE_SUPPORT + help + Select this option if you want to use UpdateCapsule and + QueryCapsuleCapabilities API's. + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 9bad1d159b03..c7d231f0e57d 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -23,6 +23,7 @@ endif obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o obj-y += efi_bootmgr.o obj-y += efi_boottime.o +obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o obj-y += efi_console.o obj-y += efi_device_path.o obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c new file mode 100644 index 000000000000..02a8435cd3d1 --- /dev/null +++ b/lib/efi_loader/efi_capsule.c @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * EFI Capsule + * + * Copyright (c) 2018 Linaro Limited + * Author: AKASHI Takahiro + */ + +#include +#include +#include +#include +#include +#include + +const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID; + +/** + * get_last_capsule - get the last capsule index + * + * Retrieve the index of the capsule invoked last time from "CapsuleLast" + * variable. + * + * Return: + * * > 0 - the last capsule index invoked + * * 0xffff - on error, or no capsule invoked yet + */ +static __maybe_unused unsigned int get_last_capsule(void) +{ + u16 value16[11]; /* "CapsuleXXXX": non-null-terminated */ + char value[11], *p; + efi_uintn_t size; + unsigned long index = 0xffff; + efi_status_t ret; + + size = sizeof(value16); + ret = efi_get_variable_int(L"CapsuleLast", &efi_guid_capsule_report, + NULL, &size, value16, NULL); + if (ret != EFI_SUCCESS || u16_strncmp(value16, L"Capsule", 7)) + goto err; + + p = value; + utf16_utf8_strcpy(&p, value16); + strict_strtoul(&value[7], 16, &index); +err: + return index; +} + +/** + * set_capsule_result - set a result variable + * @capsule: Capsule + * @return_status: Return status + * + * Create and set a result variable, "CapsuleXXXX", for the capsule, + * @capsule. + */ +static __maybe_unused +void set_capsule_result(int index, struct efi_capsule_header *capsule, + efi_status_t return_status) +{ + u16 variable_name16[12]; + struct efi_capsule_result_variable_header result; + struct efi_time time; + efi_status_t ret; + + efi_create_indexed_name(variable_name16, L"Capsule", index); + + result.variable_total_size = sizeof(result); + result.capsule_guid = capsule->capsule_guid; + ret = EFI_CALL((*efi_runtime_services.get_time)(&time, NULL)); + if (ret == EFI_SUCCESS) + memcpy(&result.capsule_processed, &time, sizeof(time)); + else + memset(&result.capsule_processed, 0, sizeof(time)); + result.capsule_status = return_status; + ret = efi_set_variable(variable_name16, &efi_guid_capsule_report, + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + sizeof(result), &result); + if (ret) + printf("EFI: creating %ls failed\n", variable_name16); +} + +/** + * efi_update_capsule() - process information from operating system + * @capsule_header_array: Array of virtual address pointers + * @capsule_count: Number of pointers in capsule_header_array + * @scatter_gather_list: Array of physical address pointers + * + * This function implements the UpdateCapsule() runtime service. + * + * See the Unified Extensible Firmware Interface (UEFI) specification for + * details. + * + * Return: status code + */ +efi_status_t EFIAPI efi_update_capsule( + struct efi_capsule_header **capsule_header_array, + efi_uintn_t capsule_count, + u64 scatter_gather_list) +{ + struct efi_capsule_header *capsule; + unsigned int i; + efi_status_t ret; + + EFI_ENTRY("%p, %lu, %llu\n", capsule_header_array, capsule_count, + scatter_gather_list); + + if (!capsule_count) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + ret = EFI_UNSUPPORTED; + for (i = 0, capsule = *capsule_header_array; i < capsule_count; + i++, capsule = *(++capsule_header_array)) { + } +out: + return EFI_EXIT(ret); +} + +/** + * efi_query_capsule_caps() - check if capsule is supported + * @capsule_header_array: Array of virtual pointers + * @capsule_count: Number of pointers in capsule_header_array + * @maximum_capsule_size: Maximum capsule size + * @reset_type: Type of reset needed for capsule update + * + * This function implements the QueryCapsuleCapabilities() runtime service. + * + * See the Unified Extensible Firmware Interface (UEFI) specification for + * details. + * + * Return: status code + */ +efi_status_t EFIAPI efi_query_capsule_caps( + struct efi_capsule_header **capsule_header_array, + efi_uintn_t capsule_count, + u64 *maximum_capsule_size, + u32 *reset_type) +{ + struct efi_capsule_header *capsule __attribute__((unused)); + unsigned int i; + efi_status_t ret; + + EFI_ENTRY("%p, %lu, %p, %p\n", capsule_header_array, capsule_count, + maximum_capsule_size, reset_type); + + if (!maximum_capsule_size) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + *maximum_capsule_size = U64_MAX; + *reset_type = EFI_RESET_COLD; + + ret = EFI_SUCCESS; + for (i = 0, capsule = *capsule_header_array; i < capsule_count; + i++, capsule = *(++capsule_header_array)) { + /* TODO */ + } +out: + return EFI_EXIT(ret); +} diff --git a/lib/efi_loader/efi_runtime.c b/lib/efi_loader/efi_runtime.c index 1fa1595e402f..0b171c1ff7bf 100644 --- a/lib/efi_loader/efi_runtime.c +++ b/lib/efi_loader/efi_runtime.c @@ -133,6 +133,10 @@ efi_status_t efi_init_runtime_supported(void) #ifdef CONFIG_EFI_HAVE_RUNTIME_RESET rt_table->runtime_services_supported |= EFI_RT_SUPPORTED_RESET_SYSTEM; #endif + if (IS_ENABLED(CONFIG_EFI_RUNTIME_UPDATE_CAPSULE)) + rt_table->runtime_services_supported |= + (EFI_RT_SUPPORTED_UPDATE_CAPSULE | + EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES); ret = efi_install_configuration_table(&efi_rt_properties_table_guid, rt_table); @@ -448,6 +452,50 @@ efi_status_t __weak __efi_runtime EFIAPI efi_set_time(struct efi_time *time) return EFI_UNSUPPORTED; } +/** + * efi_update_capsule_unsupported() - process information from operating system + * + * This function implements the UpdateCapsule() runtime service. + * + * See the Unified Extensible Firmware Interface (UEFI) specification for + * details. + * + * @capsule_header_array: pointer to array of virtual pointers + * @capsule_count: number of pointers in capsule_header_array + * @scatter_gather_list: pointer to array of physical pointers + * Returns: status code + */ +efi_status_t __efi_runtime EFIAPI efi_update_capsule_unsupported( + struct efi_capsule_header **capsule_header_array, + efi_uintn_t capsule_count, + u64 scatter_gather_list) +{ + return EFI_UNSUPPORTED; +} + +/** + * efi_query_capsule_caps_unsupported() - check if capsule is supported + * + * This function implements the QueryCapsuleCapabilities() runtime service. + * + * See the Unified Extensible Firmware Interface (UEFI) specification for + * details. + * + * @capsule_header_array: pointer to array of virtual pointers + * @capsule_count: number of pointers in capsule_header_array + * @maximum_capsule_size: maximum capsule size + * @reset_type: type of reset needed for capsule update + * Returns: status code + */ +efi_status_t __efi_runtime EFIAPI efi_query_capsule_caps_unsupported( + struct efi_capsule_header **capsule_header_array, + efi_uintn_t capsule_count, + u64 *maximum_capsule_size, + u32 *reset_type) +{ + return EFI_UNSUPPORTED; +} + /** * efi_is_runtime_service_pointer() - check if pointer points to runtime table * @@ -471,6 +519,13 @@ void efi_runtime_detach(void) efi_runtime_services.reset_system = efi_reset_system; efi_runtime_services.get_time = efi_get_time; efi_runtime_services.set_time = efi_set_time; + if (IS_ENABLED(CONFIG_EFI_RUNTIME_UPDATE_CAPSULE)) { + /* won't support at runtime */ + efi_runtime_services.update_capsule = + efi_update_capsule_unsupported; + efi_runtime_services.query_capsule_caps = + efi_query_capsule_caps_unsupported; + } /* Update CRC32 */ efi_update_table_header_crc32(&efi_runtime_services.hdr); @@ -879,50 +934,6 @@ static efi_status_t __efi_runtime EFIAPI efi_unimplemented(void) return EFI_UNSUPPORTED; } -/** - * efi_update_capsule() - process information from operating system - * - * This function implements the UpdateCapsule() runtime service. - * - * See the Unified Extensible Firmware Interface (UEFI) specification for - * details. - * - * @capsule_header_array: pointer to array of virtual pointers - * @capsule_count: number of pointers in capsule_header_array - * @scatter_gather_list: pointer to arry of physical pointers - * Returns: status code - */ -efi_status_t __efi_runtime EFIAPI efi_update_capsule( - struct efi_capsule_header **capsule_header_array, - efi_uintn_t capsule_count, - u64 scatter_gather_list) -{ - return EFI_UNSUPPORTED; -} - -/** - * efi_query_capsule_caps() - check if capsule is supported - * - * This function implements the QueryCapsuleCapabilities() runtime service. - * - * See the Unified Extensible Firmware Interface (UEFI) specification for - * details. - * - * @capsule_header_array: pointer to array of virtual pointers - * @capsule_count: number of pointers in capsule_header_array - * @maximum_capsule_size: maximum capsule size - * @reset_type: type of reset needed for capsule update - * Returns: status code - */ -efi_status_t __efi_runtime EFIAPI efi_query_capsule_caps( - struct efi_capsule_header **capsule_header_array, - efi_uintn_t capsule_count, - u64 *maximum_capsule_size, - u32 *reset_type) -{ - return EFI_UNSUPPORTED; -} - struct efi_runtime_services __efi_runtime_data efi_runtime_services = { .hdr = { .signature = EFI_RUNTIME_SERVICES_SIGNATURE, @@ -940,7 +951,12 @@ struct efi_runtime_services __efi_runtime_data efi_runtime_services = { .set_variable = efi_set_variable, .get_next_high_mono_count = (void *)&efi_unimplemented, .reset_system = &efi_reset_system_boottime, +#ifdef CONFIG_EFI_RUNTIME_UPDATE_CAPSULE .update_capsule = efi_update_capsule, .query_capsule_caps = efi_query_capsule_caps, +#else + .update_capsule = efi_update_capsule_unsupported, + .query_capsule_caps = efi_query_capsule_caps_unsupported, +#endif .query_variable_info = efi_query_variable_info, }; diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 6346eda771d0..3a1c8ea00446 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -101,9 +101,9 @@ static efi_status_t efi_init_secure_boot(void) ret = efi_set_variable_int(L"SignatureSupport", &efi_global_variable_guid, + EFI_VARIABLE_READ_ONLY | EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS | - EFI_VARIABLE_READ_ONLY, + EFI_VARIABLE_RUNTIME_ACCESS, sizeof(signature_types), &signature_types, false); if (ret != EFI_SUCCESS) @@ -118,6 +118,53 @@ static efi_status_t efi_init_secure_boot(void) } #endif /* CONFIG_EFI_SECURE_BOOT */ +/** + * efi_init_capsule - initialize capsule update state + * + * Return: status code + */ +static efi_status_t efi_init_capsule(void) +{ + efi_status_t ret = EFI_SUCCESS; + + if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_UPDATE)) { + ret = efi_set_variable_int(L"CapsuleMax", + &efi_guid_capsule_report, + EFI_VARIABLE_READ_ONLY | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + 22, L"CapsuleFFFF", false); + if (ret != EFI_SUCCESS) + printf("EFI: cannot initialize CapsuleMax variable\n"); + } + + return ret; +} + +/** + * efi_init_os_indications() - indicate supported features for OS requests + * + * Set the OsIndicationsSupported variable. + * + * Return: status code + */ +static efi_status_t efi_init_os_indications(void) +{ + u64 os_indications_supported = 0; + + if (IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT)) + os_indications_supported |= + EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED; + + return efi_set_variable_int(L"OsIndicationsSupported", + &efi_global_variable_guid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS | + EFI_VARIABLE_READ_ONLY, + sizeof(os_indications_supported), + &os_indications_supported, false); +} + /** * efi_init_obj_list() - Initialize and populate EFI object list * @@ -125,7 +172,6 @@ static efi_status_t efi_init_secure_boot(void) */ efi_status_t efi_init_obj_list(void) { - u64 os_indications_supported = 0; /* None */ efi_status_t ret = EFI_SUCCESS; /* Initialize once only */ @@ -168,13 +214,7 @@ efi_status_t efi_init_obj_list(void) goto out; /* Indicate supported features */ - ret = efi_set_variable_int(L"OsIndicationsSupported", - &efi_global_variable_guid, - EFI_VARIABLE_BOOTSERVICE_ACCESS | - EFI_VARIABLE_RUNTIME_ACCESS | - EFI_VARIABLE_READ_ONLY, - sizeof(os_indications_supported), - &os_indications_supported, false); + ret = efi_init_os_indications(); if (ret != EFI_SUCCESS) goto out; @@ -227,6 +267,10 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + ret = efi_init_capsule(); + if (ret != EFI_SUCCESS) + goto out; + /* Initialize EFI runtime services */ ret = efi_reset_system_init(); if (ret != EFI_SUCCESS) From patchwork Thu Oct 29 00:25:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319311 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15511ilc; Wed, 28 Oct 2020 17:27:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzkcRXNo9slW3a0RHuvFHYzcqzhzJGvTychuNo39FAAPveDOYmGjiUmPK46HfIG8S75WXJH X-Received: by 2002:a05:6402:1bd9:: with SMTP id ch25mr1425238edb.365.1603931246812; Wed, 28 Oct 2020 17:27:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931246; cv=none; d=google.com; s=arc-20160816; b=yvq/0dM74H0zE7P9Z2XnxEBABt904dBY2IkyrJCwJTD4TTd0/W6tvabcNsRPRxPPQb TCUIBBuLAHfUnAtEbknPMCZbU0W3ai2CHqQkcKD2myVw9OAXLqPolKgRgkcnUn/+1OvM SUc9oQVkLSu6PPK9BOFagk52APxS87n0Na0VxDmcDX3kz28Au7ZXu2lNOWOPCLa4ukyG bsHameF2qgmDlJzoC0liqzsMjJOEoK2rMKb4gXVrk1hRUy0tRHoBC+2N6Rltvjv2r73i WJJPF1gFl2Syc3CFdoipSvrfEzuYVAAMW6uz+pmkKkh8FSbUPKM/o7ux2a4KLUxClFFf OvhQ== 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=40FS4iJUykq9mSU9PYdkb6oUQKrbFWaj8vs1Q5mwZyE=; b=HPevfva5Prv+/WD73zv0WAIuNKPdCsZnHb0t6lw7eLqW3iXAjS1fATJ1TldGfuUbmO JzLlWfwQDpQ56bf674AvJcY5FFvgDK4IZrMIq1aGPqZ1raEtxQ2EKXrd7yaNRoiXOF3G 7QiXT42L4ni7pNQMtiVa11ojLEk9Hw5YmzVTvtAzWIxumU9zDdKraKWCnWYDiFTe5E3Y AsbcvRoudGgLALSKq4DlzT7p/uMEj9Don5/4T6Pi63AnZofYWzHajADhbwFibaojhF1O Gizdut70XIDftH8+x7nMH4FZ8ePFL5jnjRdTypHCOVoItzHoshj7xKSxtFUDHMzulRyD njpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nc5XPAyI; 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 v5si863606edx.121.2020.10.28.17.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:27: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=Nc5XPAyI; 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 7C3AF82513; Thu, 29 Oct 2020 01:26:28 +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="Nc5XPAyI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 594DF824DA; Thu, 29 Oct 2020 01:26:23 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (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 276DE824F4 for ; Thu, 29 Oct 2020 01:26:18 +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=takahiro.akashi@linaro.org Received: by mail-pf1-x443.google.com with SMTP id e15so861924pfh.6 for ; Wed, 28 Oct 2020 17:26:18 -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=40FS4iJUykq9mSU9PYdkb6oUQKrbFWaj8vs1Q5mwZyE=; b=Nc5XPAyIen02wg0kTyDHhfaMQrLKYr/8p4vRH8bRU/CmG2TTf0T1Yv/HRPIkv736Rk nKyKQrn0odpJ33a2R9qBoE7ewoPj2wOFweoZAVe3W8i8i1Xy+1iReSM6CZRMcUGJy0c+ ttFz8mA+shE0vj7cLRM9Vgz3MbcJoDNo1l4pcFEawPk5ilYvvcZzCFQX3nUl1aJl8wy/ sMjC04D7M/8sb+cC1S+4Szly/exd6N+hryh0jpatkFvod5W5rtAxNOWN6KO0WRgcB8Nc IeZXYbQnA4JBh14mkZXTbIwkxBcX29iPruiKrmeghzM/CrKml4qKVHh8ApNinxAD1H73 EP1w== 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=40FS4iJUykq9mSU9PYdkb6oUQKrbFWaj8vs1Q5mwZyE=; b=HDxFRn5SOs4fAgmYMJXhM9R0siimdepjoIF/F8tvb1CjDZckRn7XANspFzdstTpv1S SlcZcTALklCxFpCM97WE5DEa7MHxfacnVZIPjmrZ/1390YKm+J3Eg6IYBiNFEps/bvHZ BKgZcRJqjzCzKBFX+x7wbezsPrfdAHfDmWqeYl60v7145RlCmc4VVatMhEgokn5QYXw1 mVP7IsxKft+oj7JvoIyUJVjK/T3XKm6M3ECFAdbPja0DlEHMPOgYKq7SJEKnfy26v4e7 aM4qmrE7lVPKc+c3A2J5AE7ARPFEC9R5Tq/tV6o048wL3fFU8c//0gCOcEdDLXOr5rjN IlUg== X-Gm-Message-State: AOAM531oiSzBJQuhpPkP9aWpNVkZkVHVdYQ/ejEPr35paiEV4ZUu0veI AE/L99UxsEMCKx8B/nU0BvIiGA== X-Received: by 2002:a65:5b48:: with SMTP id y8mr1677801pgr.67.1603931176588; Wed, 28 Oct 2020 17:26:16 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:15 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 08/17] efi_loader: capsule: add capsule_on_disk support Date: Thu, 29 Oct 2020 09:25:19 +0900 Message-Id: <20201029002528.34408-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean Capsule data can be loaded into the system either via UpdateCapsule runtime service or files on a file system (of boot device). The latter case is called "capsules on disk", and actual updates will take place at the next boot time. In this commit, we will support capsule on disk mechanism. Please note that U-Boot itself has no notion of "boot device" and all the capsule files to be executed will be detected only if they are located in a specific directory, \EFI\UpdateCapsule, on a device that is identified as a boot device by "BootXXXX" variables. Signed-off-by: AKASHI Takahiro --- common/main.c | 4 + include/efi_loader.h | 9 + lib/efi_loader/Kconfig | 22 ++ lib/efi_loader/efi_capsule.c | 498 +++++++++++++++++++++++++++++++++++ lib/efi_loader/efi_setup.c | 8 + 5 files changed, 541 insertions(+) -- 2.28.0 diff --git a/common/main.c b/common/main.c index 4b3cd302c3e2..ae5bcdb32f8b 100644 --- a/common/main.c +++ b/common/main.c @@ -16,6 +16,7 @@ #include #include #include +#include static void run_preboot_environment_command(void) { @@ -53,6 +54,9 @@ void main_loop(void) if (IS_ENABLED(CONFIG_UPDATE_TFTP)) update_tftp(0UL, NULL, NULL); + if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) + efi_launch_capsules(); + s = bootdelay_process(); if (cli_process_fdt(&s)) cli_secure_boot_cmd(s); diff --git a/include/efi_loader.h b/include/efi_loader.h index ffe772866675..572cfadd491a 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -820,6 +820,11 @@ efi_status_t EFIAPI efi_query_capsule_caps( u64 *maximum_capsule_size, u32 *reset_type); +#define EFI_CAPSULE_DIR L"\\EFI\\UpdateCapsule\\" + +/* Hook at initialization */ +efi_status_t efi_launch_capsules(void); + #else /* CONFIG_IS_ENABLED(EFI_LOADER) */ /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */ @@ -836,6 +841,10 @@ static inline void efi_set_bootdev(const char *dev, const char *devnr, const char *path) { } static inline void efi_net_set_dhcp_ack(void *pkt, int len) { } static inline void efi_print_image_infos(void *pc) { } +static inline efi_status_t efi_launch_capsules(void) +{ + return EFI_SUCCESS; +} #endif /* CONFIG_IS_ENABLED(EFI_LOADER) */ diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 3ca396df3646..a2a015225a10 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -104,6 +104,28 @@ config EFI_RUNTIME_UPDATE_CAPSULE Select this option if you want to use UpdateCapsule and QueryCapsuleCapabilities API's. +config EFI_CAPSULE_ON_DISK + bool "Enable capsule-on-disk support" + select EFI_HAVE_CAPSULE_SUPPORT + default n + help + Select this option if you want to use capsule-on-disk feature, + that is, capsules can be fetched and executed from files + under a specific directory on UEFI system partition instead of + via UpdateCapsule API. + +config EFI_CAPSULE_ON_DISK_EARLY + bool "Initiate capsule-on-disk at U-Boot boottime" + depends on EFI_CAPSULE_ON_DISK + default y + select EFI_SETUP_EARLY + help + Normally, without this option enabled, capsules will be + executed only at the first time of invoking one of efi command. + If this option is enabled, capsules will be enforced to be + executed as part of U-Boot initialisation so that they will + surely take place whatever is set to distro_bootcmd. + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 02a8435cd3d1..2259bfbf3d19 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -11,10 +11,16 @@ #include #include #include +#include #include const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID; +#ifdef CONFIG_EFI_CAPSULE_ON_DISK +/* for file system access */ +static struct efi_file_handle *bootdev_root; +#endif + /** * get_last_capsule - get the last capsule index * @@ -163,3 +169,495 @@ efi_status_t EFIAPI efi_query_capsule_caps( out: return EFI_EXIT(ret); } + +#ifdef CONFIG_EFI_CAPSULE_ON_DISK +/** + * get_dp_device - retrieve a device path from boot variable + * @boot_var: Boot variable name + * @device_dp Device path + * + * Retrieve a device patch from boot variable, @boot_var. + * + * Return: status code + */ +static efi_status_t get_dp_device(u16 *boot_var, + struct efi_device_path **device_dp) +{ + void *buf = NULL; + efi_uintn_t size; + struct efi_load_option lo; + struct efi_device_path *file_dp; + efi_status_t ret; + + size = 0; + ret = efi_get_variable_int(boot_var, &efi_global_variable_guid, + NULL, &size, NULL, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) { + buf = malloc(size); + if (!buf) + return EFI_OUT_OF_RESOURCES; + ret = efi_get_variable_int(boot_var, &efi_global_variable_guid, + NULL, &size, buf, NULL); + } + if (ret != EFI_SUCCESS) + return ret; + + efi_deserialize_load_option(&lo, buf, &size); + + if (lo.attributes & LOAD_OPTION_ACTIVE) { + efi_dp_split_file_path(lo.file_path, device_dp, &file_dp); + efi_free_pool(file_dp); + + ret = EFI_SUCCESS; + } else { + ret = EFI_NOT_FOUND; + } + + free(buf); + + return ret; +} + +/** + * device_is_present_and_system_part - check if a device exists + * @dp Device path + * + * Check if a device pointed to by the device path, @dp, exists and is + * located in UEFI system partition. + * + * Return: true - yes, false - no + */ +static bool device_is_present_and_system_part(struct efi_device_path *dp) +{ + efi_handle_t handle; + + handle = efi_dp_find_obj(dp, NULL); + if (!handle) + return false; + + return efi_disk_is_system_part(handle); +} + +/** + * find_boot_device - identify the boot device + * + * Identify the boot device from boot-related variables as UEFI + * specification describes and put its handle into bootdev_root. + * + * Return: status code + */ +static efi_status_t find_boot_device(void) +{ + char boot_var[9]; + u16 boot_var16[9], *p, bootnext, *boot_order = NULL; + efi_uintn_t size; + int i, num; + struct efi_simple_file_system_protocol *volume; + struct efi_device_path *boot_dev = NULL; + efi_status_t ret; + + /* find active boot device in BootNext */ + bootnext = 0; + size = sizeof(bootnext); + ret = efi_get_variable_int(L"BootNext", + (efi_guid_t *)&efi_global_variable_guid, + NULL, &size, &bootnext, NULL); + if (ret == EFI_SUCCESS || ret == EFI_BUFFER_TOO_SMALL) { + /* BootNext does exist here */ + if (ret == EFI_BUFFER_TOO_SMALL || size != sizeof(u16)) { + printf("BootNext must be 16-bit integer\n"); + goto skip; + } + sprintf((char *)boot_var, "Boot%04X", bootnext); + p = boot_var16; + utf8_utf16_strcpy(&p, boot_var); + + ret = get_dp_device(boot_var16, &boot_dev); + if (ret == EFI_SUCCESS) { + if (device_is_present_and_system_part(boot_dev)) { + goto out; + } else { + efi_free_pool(boot_dev); + boot_dev = NULL; + } + } + } + +skip: + /* find active boot device in BootOrder */ + size = 0; + ret = efi_get_variable_int(L"BootOrder", &efi_global_variable_guid, + NULL, &size, NULL, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) { + boot_order = malloc(size); + if (!boot_order) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + ret = efi_get_variable_int(L"BootOrder", + &efi_global_variable_guid, + NULL, &size, boot_order, NULL); + } + if (ret != EFI_SUCCESS) + goto out; + + /* check in higher order */ + num = size / sizeof(u16); + for (i = 0; i < num; i++) { + sprintf((char *)boot_var, "Boot%04X", boot_order[i]); + p = boot_var16; + utf8_utf16_strcpy(&p, boot_var); + ret = get_dp_device(boot_var16, &boot_dev); + if (ret != EFI_SUCCESS) + continue; + + if (device_is_present_and_system_part(boot_dev)) + break; + + efi_free_pool(boot_dev); + boot_dev = NULL; + } +out: + if (boot_dev) { + u16 *path_str; + + path_str = efi_dp_str(boot_dev); + EFI_PRINT("EFI Capsule: bootdev is %ls\n", path_str); + efi_free_pool(path_str); + + volume = efi_fs_from_path(boot_dev); + if (!volume) + ret = EFI_DEVICE_ERROR; + else + ret = EFI_CALL(volume->open_volume(volume, + &bootdev_root)); + efi_free_pool(boot_dev); + } else { + ret = EFI_NOT_FOUND; + } + free(boot_order); + + return ret; +} + +/** + * efi_capsule_scan_dir - traverse a capsule directory in boot device + * @files: Array of file names + * @num: Number of elements in @files + * + * Traverse a capsule directory in boot device. + * Called by initialization code, and returns an array of capsule file + * names in @files. + * + * Return: status code + */ +static efi_status_t efi_capsule_scan_dir(u16 ***files, unsigned int *num) +{ + struct efi_file_handle *dirh; + struct efi_file_info *dirent; + efi_uintn_t dirent_size, tmp_size; + unsigned int count; + u16 **tmp_files; + efi_status_t ret; + + ret = find_boot_device(); + if (ret == EFI_NOT_FOUND) { + EFI_PRINT("EFI Capsule: bootdev is not set\n"); + *num = 0; + return EFI_SUCCESS; + } else if (ret != EFI_SUCCESS) { + return EFI_DEVICE_ERROR; + } + + /* count capsule files */ + ret = EFI_CALL((*bootdev_root->open)(bootdev_root, &dirh, + EFI_CAPSULE_DIR, + EFI_FILE_MODE_READ, 0)); + if (ret != EFI_SUCCESS) { + *num = 0; + return EFI_SUCCESS; + } + + dirent_size = 256; + dirent = malloc(dirent_size); + if (!dirent) + return EFI_OUT_OF_RESOURCES; + + count = 0; + while (1) { + tmp_size = dirent_size; + ret = EFI_CALL((*dirh->read)(dirh, &tmp_size, dirent)); + if (ret == EFI_BUFFER_TOO_SMALL) { + dirent = realloc(dirent, tmp_size); + if (!dirent) { + ret = EFI_OUT_OF_RESOURCES; + goto err; + } + dirent_size = tmp_size; + ret = EFI_CALL((*dirh->read)(dirh, &tmp_size, dirent)); + } + if (ret != EFI_SUCCESS) + goto err; + if (!tmp_size) + break; + + if (!(dirent->attribute & EFI_FILE_DIRECTORY) && + u16_strcmp(dirent->file_name, L".") && + u16_strcmp(dirent->file_name, L"..")) + count++; + } + + ret = EFI_CALL((*dirh->setpos)(dirh, 0)); + if (ret != EFI_SUCCESS) + goto err; + + /* make a list */ + tmp_files = malloc(count * sizeof(*files)); + if (!tmp_files) { + ret = EFI_OUT_OF_RESOURCES; + goto err; + } + + count = 0; + while (1) { + tmp_size = dirent_size; + ret = EFI_CALL((*dirh->read)(dirh, &tmp_size, dirent)); + if (ret != EFI_SUCCESS) + goto err; + if (!tmp_size) + break; + + if (!(dirent->attribute & EFI_FILE_DIRECTORY) && + u16_strcmp(dirent->file_name, L".") && + u16_strcmp(dirent->file_name, L"..")) + tmp_files[count++] = u16_strdup(dirent->file_name); + } + /* ignore an error */ + EFI_CALL((*dirh->close)(dirh)); + + /* in ascii order */ + /* FIXME: u16 version of strcasecmp */ + qsort(tmp_files, count, sizeof(*tmp_files), + (int (*)(const void *, const void *))strcasecmp); + *files = tmp_files; + *num = count; + ret = EFI_SUCCESS; +err: + free(dirent); + + return ret; +} + +/** + * efi_capsule_read_file - read in a capsule file + * @filename: File name + * @capsule: Pointer to buffer for capsule + * + * Read a capsule file and put its content in @capsule. + * + * Return: status code + */ +static efi_status_t efi_capsule_read_file(const u16 *filename, + struct efi_capsule_header **capsule) +{ + struct efi_file_handle *dirh, *fh; + struct efi_file_info *file_info = NULL; + struct efi_capsule_header *buf = NULL; + efi_uintn_t size; + efi_status_t ret; + + ret = EFI_CALL((*bootdev_root->open)(bootdev_root, &dirh, + EFI_CAPSULE_DIR, + EFI_FILE_MODE_READ, 0)); + if (ret != EFI_SUCCESS) + return ret; + ret = EFI_CALL((*dirh->open)(dirh, &fh, (u16 *)filename, + EFI_FILE_MODE_READ, 0)); + /* ignore an error */ + EFI_CALL((*dirh->close)(dirh)); + if (ret != EFI_SUCCESS) + return ret; + + /* file size */ + size = 0; + ret = EFI_CALL((*fh->getinfo)(fh, &efi_file_info_guid, + &size, file_info)); + if (ret == EFI_BUFFER_TOO_SMALL) { + file_info = malloc(size); + if (!file_info) { + ret = EFI_OUT_OF_RESOURCES; + goto err; + } + ret = EFI_CALL((*fh->getinfo)(fh, &efi_file_info_guid, + &size, file_info)); + } + if (ret != EFI_SUCCESS) + goto err; + size = file_info->file_size; + free(file_info); + buf = malloc(size); + if (!buf) { + ret = EFI_OUT_OF_RESOURCES; + goto err; + } + + /* fetch data */ + ret = EFI_CALL((*fh->read)(fh, &size, buf)); + if (ret == EFI_SUCCESS) { + if (size >= buf->capsule_image_size) { + *capsule = buf; + } else { + free(buf); + ret = EFI_INVALID_PARAMETER; + } + } else { + free(buf); + } +err: + EFI_CALL((*fh->close)(fh)); + + return ret; +} + +/** + * efi_capsule_delete_file - delete a capsule file + * @filename: File name + * + * Delete a capsule file from capsule directory. + * + * Return: status code + */ +static efi_status_t efi_capsule_delete_file(const u16 *filename) +{ + struct efi_file_handle *dirh, *fh; + efi_status_t ret; + + ret = EFI_CALL((*bootdev_root->open)(bootdev_root, &dirh, + EFI_CAPSULE_DIR, + EFI_FILE_MODE_READ, 0)); + if (ret != EFI_SUCCESS) + return ret; + ret = EFI_CALL((*dirh->open)(dirh, &fh, (u16 *)filename, + EFI_FILE_MODE_READ, 0)); + /* ignore an error */ + EFI_CALL((*dirh->close)(dirh)); + + ret = EFI_CALL((*fh->delete)(fh)); + + return ret; +} + +/** + * efi_capsule_scan_done - reset a scan help function + * + * Reset a scan help function + */ +static void efi_capsule_scan_done(void) +{ + EFI_CALL((*bootdev_root->close)(bootdev_root)); + bootdev_root = NULL; +} + +/** + * arch_efi_load_capsule_drivers - initialize capsule drivers + * + * Architecture or board specific initialization routine + * + * Return: status code + */ +efi_status_t __weak arch_efi_load_capsule_drivers(void) +{ + return EFI_SUCCESS; +} + +/** + * efi_launch_capsule - launch capsules + * + * Launch all the capsules in system at boot time. + * Called by efi init code + * + * Return: status codde + */ +efi_status_t efi_launch_capsules(void) +{ + u64 os_indications; + efi_uintn_t size; + struct efi_capsule_header *capsule = NULL; + u16 **files; + unsigned int nfiles, index, i; + u16 variable_name16[12]; + efi_status_t ret; + + size = sizeof(os_indications); + ret = efi_get_variable_int(L"OsIndications", &efi_global_variable_guid, + NULL, &size, &os_indications, NULL); + if (ret != EFI_SUCCESS || + !(os_indications + & EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED)) + return EFI_SUCCESS; + + index = get_last_capsule(); + + /* Load capsule drivers */ + ret = arch_efi_load_capsule_drivers(); + if (ret != EFI_SUCCESS) + return ret; + + /* + * Find capsules on disk. + * All the capsules are collected at the beginning because + * capsule files will be removed instantly. + */ + nfiles = 0; + files = NULL; + ret = efi_capsule_scan_dir(&files, &nfiles); + if (ret != EFI_SUCCESS) + return ret; + if (!nfiles) + return EFI_SUCCESS; + + /* Launch capsules */ + for (i = 0, ++index; i < nfiles; i++, index++) { + EFI_PRINT("capsule from %ls ...\n", files[i]); + if (index > 0xffff) + index = 0; + ret = efi_capsule_read_file(files[i], &capsule); + if (ret == EFI_SUCCESS) { + ret = EFI_CALL(efi_update_capsule(&capsule, 1, 0)); + if (ret != EFI_SUCCESS) + printf("EFI Capsule update failed at %ls\n", + files[i]); + + free(capsule); + } else { + printf("EFI: reading capsule failed: %ls\n", + files[i]); + } + /* create CapsuleXXXX */ + set_capsule_result(index, capsule, ret); + + /* delete a capsule either in case of success or failure */ + ret = efi_capsule_delete_file(files[i]); + if (ret != EFI_SUCCESS) + printf("EFI: deleting a capsule file failed: %ls\n", + files[i]); + } + efi_capsule_scan_done(); + + for (i = 0; i < nfiles; i++) + free(files[i]); + free(files); + + /* CapsuleLast */ + efi_create_indexed_name(variable_name16, L"Capsule", index - 1); + efi_set_variable_int(L"CapsuleLast", &efi_guid_capsule_report, + EFI_VARIABLE_READ_ONLY | + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + 22, variable_name16, false); + + return ret; +} +#endif /* CONFIG_EFI_CAPSULE_ON_DISK */ diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 3a1c8ea00446..99146671c899 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -156,6 +156,10 @@ static efi_status_t efi_init_os_indications(void) os_indications_supported |= EFI_OS_INDICATIONS_CAPSULE_RESULT_VAR_SUPPORTED; + if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK)) + os_indications_supported |= + EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED; + return efi_set_variable_int(L"OsIndicationsSupported", &efi_global_variable_guid, EFI_VARIABLE_BOOTSERVICE_ACCESS | @@ -276,6 +280,10 @@ efi_status_t efi_init_obj_list(void) if (ret != EFI_SUCCESS) goto out; + /* Execute capsules after reboot */ + if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK) && + !IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) + ret = efi_launch_capsules(); out: efi_obj_list_initialized = ret; return ret; From patchwork Thu Oct 29 00:25:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319312 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15606ilc; Wed, 28 Oct 2020 17:27:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXt33Bif8ihVgttJ5Ns9b1+hAT6rKJgrvZZXvsgr9ns7+OCpgLdRGb3iGOVI0mA4KlplVg X-Received: by 2002:a17:906:b1c9:: with SMTP id bv9mr1612311ejb.495.1603931259007; Wed, 28 Oct 2020 17:27:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931259; cv=none; d=google.com; s=arc-20160816; b=AGLuEBtwmVzFSjtqXURQUi0gpd+X3fMBo2JhkkaGOhSM6XfT6JirsZ+8up3g4ySY5j BcYC+Y0v1NdCLRZvJzYhW1M+cwwhnnNbdU5B9MkY4A49tYXzET5nFkzZ3x4yhYpXRxZE qEOvrthbNE6rDPTUjQAidItJFPVwssN64MLwp5zPlYnd4G8iTt+01vVpqXde18iqm0bf lnKXH0m+DlsA57qL28Vcmoqa4yD7H2IlsFZRrVqC9MI4gy97djYOLOw2YF0UX30igDmV c8/4zCzcLgPWd1c3YL8FMKHvW78e2nXX9cZYnN3c+lA8QStMlVxOnL/TSlybfTjBrq3j ExNw== 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=pfzS9a249CGCsTB62oWKa+nEqo4kbxAX5xW5fvW6X+k=; b=B0oku3sEtKAOBPmewilrMltZW1ApDl0bM2XJE+X6g23ItZEyuG90SvOiZb89tzzHGp xylNAprEqKbWlGXXy8XdUwVko5ddLTx8gC6vp4bOSHuCmtGjqUN7Z42JZNiOc63l9CWm 80RC3KC5BjWz3bCTgFW86raBJ7bpyWNPq7uLh1cd8T7HJNbhOP75JUbfGCgwIB8W8sMs +9P0XN/07C1xIN3PoapgvNNz1ovi7uu1fwIaFJQ4/1YLs391uuHr5lYgZxBAwl8UYzVN wYLm+aXgZ899GlQl4Dk7uJW0snaVklPZYk/S7gLNSEXOntGgP2kTtr+V/1fITQUUjm4P xOWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dEikyGdV; 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 k2si823734edx.333.2020.10.28.17.27.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:27:38 -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=dEikyGdV; 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 A2CC382518; Thu, 29 Oct 2020 01:26:30 +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="dEikyGdV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2F7CD824DA; Thu, 29 Oct 2020 01:26:24 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (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 F2D59824A8 for ; Thu, 29 Oct 2020 01:26:20 +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=takahiro.akashi@linaro.org Received: by mail-pg1-x544.google.com with SMTP id s22so890763pga.9 for ; Wed, 28 Oct 2020 17:26:20 -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=pfzS9a249CGCsTB62oWKa+nEqo4kbxAX5xW5fvW6X+k=; b=dEikyGdVVC1Ft8TiL/AweAIReTd2k7QlRywhkwhFU5psePSzkPkS0LC8Pwfz51wHCX wksmQgK3AOpI/2t/iaKlkKbx6aQGqJLTMhbv/trwhJ0zOM9ZC2B9ixG3EJVcaKClYQa+ vUa6amX5t9+HkBs6T5rV7nL7szKzYey2XmPug/J0JxqMKIdIAKZfyHlXOix5mgKblcH0 54ywOvJb+i1Gb5bKQlT6uJNClxFCc2VlZYBBGsU0S+EDj4+NwtX9gvzZiyGKB5V7yKOJ ZTz8EvEJHKQWLlInB6a8L/Pttu5ZdqAEDMIp1v9iPD7ca07TVwXSl9ThUYSd/9MAHx8H xL9w== 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=pfzS9a249CGCsTB62oWKa+nEqo4kbxAX5xW5fvW6X+k=; b=LBLvjZ0HOk5qmg9+gQt6r3xYyQqfJq66RE5kVFq1+U0nsuSvRQX9lrS+DFgTxllQKa iAQZ1F4gqwAbxH+L9I6Aw5Avnay1ZI1arcjwjEFnwlBU4m6ED1/uR9XChUKwwkK+MlJx ahAQ8Zk4YHxyLClC784EwefnmGghjr8PRWms5yiG0NeIpQnrVW9nFScwI/Jf8HhvHytD 3aIuf2JCUOEaMAE/Yy2DI/HUqAYLr1HJKfNMX7kA5N8rszEQOnqLg02Z+M1U2BU/j7Ys 4DDcH+OenAosAZdMvyzxqJR+BiAvy+ESU6qzx6OMYA1vvgu97UmslUtCs2NSD4605+dJ 2RLA== X-Gm-Message-State: AOAM532vEYR5lfMmLdOfn0lRlkX2374bkCnIlawlWTb9mTi613yhZ6Ex GOJbzNp+F8P3KbHqFfuc+u19m8FBPfDu6A== X-Received: by 2002:a65:4cc1:: with SMTP id n1mr1668788pgt.404.1603931179553; Wed, 28 Oct 2020 17:26:19 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:19 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 09/17] efi_loader: capsule: add memory range capsule definitions Date: Thu, 29 Oct 2020 09:25:20 +0900 Message-Id: <20201029002528.34408-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean Memory range capsule gives us a way to notify that some memory regions should be left untouched across the next reset. See UEFI specification, section 8.5.3. Since how we should handle this kind of capsule is totally up to the system, no implementation will be added in this commit. Signed-off-by: AKASHI Takahiro --- include/efi_api.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) -- 2.28.0 diff --git a/include/efi_api.h b/include/efi_api.h index c128a0a66ce8..7a2a087c60ed 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -221,6 +221,10 @@ enum efi_reset_type { EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \ 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3) +#define EFI_MEMORY_RANGE_CAPSULE_GUID \ + EFI_GUID(0xde9f0ec, 0x88b6, 0x428f, 0x97, 0x7a, \ + 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72) + struct efi_capsule_header { efi_guid_t capsule_guid; u32 header_size; @@ -236,6 +240,19 @@ struct efi_capsule_result_variable_header { efi_status_t capsule_status; } __packed; +struct efi_memory_range { + efi_physical_addr_t address; + u64 length; +}; + +struct efi_memory_range_capsule { + struct efi_capsule_header *header; + /* EFI_MEMORY_TYPE: 0x80000000-0xFFFFFFFF */ + enum efi_mem_type os_requested_memory_type; + u64 number_of_memory_ranges; + struct efi_memory_range memory_ranges[]; +} __packed; + #define EFI_RT_SUPPORTED_GET_TIME 0x0001 #define EFI_RT_SUPPORTED_SET_TIME 0x0002 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004 From patchwork Thu Oct 29 00:25:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319313 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15685ilc; Wed, 28 Oct 2020 17:27:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhlMwQM0F+4lM1VqePVDYA/J8OMUDGqZYoPcUJ5jzzRKUTsYwGjXjHD/n6CIxV7elYww5Q X-Received: by 2002:a05:6402:1457:: with SMTP id d23mr1442762edx.311.1603931270452; Wed, 28 Oct 2020 17:27:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931270; cv=none; d=google.com; s=arc-20160816; b=ZBAQ+229IwbCj/So8+WnkG9L+KiWZ1+FSOM5lc8j2mNGrwncS3UZlFjyIfk23piMsK avTDxV7larSBb0FuLLnXvffn74krkiHEP+cRfAQM0jpch7JTSRVNHX8J4Yo0IaeGUhbc QAZoaagXhG50h5L5lxTpxpEegnhIVmsiU7svT7w2qM8jQYECwPrxAX5TmyCPuu6fyHtB NbktldpAhGkqE3nAZxXBuNst3u0XtqRO9MoeZG00dS2AnSpAgSPKDqokLEYOw+22UbJP 4jgqA2NLVNHMTt5Ouu7bxA/KHBwSYii5PCu5lXx738bwG9GMZGI2rgAx7tBBy+RG4PGa wMpA== 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=ILurSkZM2uPogdlrQz+rMa1BuhOIedI0dlMDytHQ96s=; b=XbFMWTSrosu5IC69FHEmN1jk2Bby19R0FSV98sAGusQpPJqSbrTpHI4c4w27B8sdWB cywUHxgcjBPCIHnSl8E/zmPKemplOea5toVWVxcJFENFVwubJn0+1roJPG0zNsTZLYld YV9KiVccVotsTwizVlFaxElRPkhUvCZpjikOGh6ZJ6XoZIi0+iXEAdE0xHBZVBVU38s2 1zq0mDm7Wga+NNZ0PaMH/vLwd8YlENBrOqqfXIlmmNwUkrHlmr6KOws5Mz5Au2dfmKwZ V1zuuAcsus3nrDElX4RkcazDLe1tiYnOViTZOoEX6cA0p3UmYMB6S8jchI1/rLRW0aUg pRZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bpqxr4WB; 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 p12si839166edm.318.2020.10.28.17.27.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:27:50 -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=bpqxr4WB; 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 C99668250C; Thu, 29 Oct 2020 01:26:38 +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="bpqxr4WB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D55118250F; Thu, 29 Oct 2020 01:26:27 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (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 3E0DB8246A for ; Thu, 29 Oct 2020 01:26:24 +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=takahiro.akashi@linaro.org Received: by mail-pg1-x529.google.com with SMTP id h6so906791pgk.4 for ; Wed, 28 Oct 2020 17:26:24 -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=ILurSkZM2uPogdlrQz+rMa1BuhOIedI0dlMDytHQ96s=; b=bpqxr4WBQKUsfAs2aQWfqe3Hs6gOgAyjwcE0E/H6pc/TyBwTG0MSPeW4zTwj5ThT+R j8QM78MvifTOJHZXrKQZ6zUMA4p7jRvD8sx6PG705A19PMTO92eG+ZFe1n7zayNi9CbP Jrhg/HnWPXdTwlbVsRHpH9CaGtl+krriTPNF0QgwaBErC7aRf67KsWjJEfrc4OKXw27f 8+zIGdK3lCSad9rbI/TxRJsJFrdeHkZbHFRVVoYFrAEKutLnTgOgCmcCdxWo5Yb0Kz0/ EawLSlOLDiVjQGiMSZ07iSo41v5iTdxhlCofzFOUqadu0D/2f06tB1Foq5Wo00g27yfg fbLA== 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=ILurSkZM2uPogdlrQz+rMa1BuhOIedI0dlMDytHQ96s=; b=ep5wJhVrQ1h6Q0gGe4BwjTRRkphkoQRaTvzeGWUNqqGlF22ry5HY1qelBAqieiSHSZ LU53dDf9zVCHyzN50Srqn914M8tBlBG1GzMHQcxL2xlaGAQ+jmNV1Kv6TlgAjOj5roUa FbnC78FJ3we5fYAWHvck4+Pirj2/NT4NEko7bPDEpy/Z+gwWG1pGBWtD/4O4Eq2B0Kgc B3mDUn5pJb3DRUy58c/sBfdS+sp1RhY/QXJQh140PFwsVekAdcZJRzZ+CjGi+/YMKL4H GOIPT7ua0X0JllRELD4hrz5jGLdrJaFvE9KLkJZEv+HDD9l/OFiXKCRf7Icb40pmp7mL CDTg== X-Gm-Message-State: AOAM532WAtq3iMgvcDwcwDPsNMV1PR9rfA/rfBDv2gioU5UCSvlHPu0V eZSy8DPE/32KdiodNek3QP3e1w== X-Received: by 2002:a17:90a:4a95:: with SMTP id f21mr1294164pjh.223.1603931182744; Wed, 28 Oct 2020 17:26:22 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:22 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 10/17] efi_loader: capsule: support firmware update Date: Thu, 29 Oct 2020 09:25:21 +0900 Message-Id: <20201029002528.34408-11-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean A capsule tagged with the guid, EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID, is handled as a firmware update object. What efi_update_capsule() basically does is to load any firmware management protocol (or fmp) drivers contained in a capsule, find out an appropriate fmp driver and then invoke its set_image() interface against each binary in a capsule. In this commit, however, loading drivers is not supported. The result of applying a capsule is set to be stored in "CapsuleXXXX" variable, but its implementation is deferred to a fmp driver. Signed-off-by: AKASHI Takahiro --- include/efi_api.h | 129 +++++++++++++++++++ include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 8 ++ lib/efi_loader/efi_capsule.c | 238 ++++++++++++++++++++++++++++++++++- lib/efi_loader/efi_setup.c | 4 + 5 files changed, 380 insertions(+), 1 deletion(-) -- 2.28.0 diff --git a/include/efi_api.h b/include/efi_api.h index 7a2a087c60ed..966bc6e590bf 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -217,6 +217,9 @@ enum efi_reset_type { #define CAPSULE_FLAGS_POPULATE_SYSTEM_TABLE 0x00020000 #define CAPSULE_FLAGS_INITIATE_RESET 0x00040000 +#define CAPSULE_SUPPORT_AUTHENTICATION 0x0000000000000001 +#define CAPSULE_SUPPORT_DEPENDENCY 0x0000000000000002 + #define EFI_CAPSULE_REPORT_GUID \ EFI_GUID(0x39b68c46, 0xf7fb, 0x441b, 0xb6, 0xec, \ 0x16, 0xb0, 0xf6, 0x98, 0x21, 0xf3) @@ -225,6 +228,10 @@ enum efi_reset_type { EFI_GUID(0xde9f0ec, 0x88b6, 0x428f, 0x97, 0x7a, \ 0x25, 0x8f, 0x1d, 0xe, 0x5e, 0x72) +#define EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID \ + EFI_GUID(0x6dcbd5ed, 0xe82d, 0x4c44, 0xbd, 0xa1, \ + 0x71, 0x94, 0x19, 0x9a, 0xd9, 0x2a) + struct efi_capsule_header { efi_guid_t capsule_guid; u32 header_size; @@ -253,6 +260,33 @@ struct efi_memory_range_capsule { struct efi_memory_range memory_ranges[]; } __packed; +struct efi_firmware_management_capsule_header { + u32 version; + u16 embedded_driver_count; + u16 payload_item_count; + u64 item_offset_list[]; +} __packed; + +struct efi_firmware_management_capsule_image_header { + u32 version; + efi_guid_t update_image_type_id; + u8 update_image_index; + u8 reserved[3]; + u32 update_image_size; + u32 update_vendor_code_size; + u64 update_hardware_instance; + u64 image_capsule_support; +} __packed; + +struct efi_capsule_result_variable_fmp { + u16 version; + u8 payload_index; + u8 update_image_index; + efi_guid_t update_image_type_id; + // u16 capsule_file_name[]; + // u16 capsule_target[]; +} __packed; + #define EFI_RT_SUPPORTED_GET_TIME 0x0001 #define EFI_RT_SUPPORTED_SET_TIME 0x0002 #define EFI_RT_SUPPORTED_GET_WAKEUP_TIME 0x0004 @@ -1808,4 +1842,99 @@ struct efi_signature_list { /* struct efi_signature_data signatures[...][signature_size]; */ } __attribute__((__packed__)); +/* + * Firmware management protocol + */ +#define EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID \ + EFI_GUID(0x86c77a67, 0x0b97, 0x4633, 0xa1, 0x87, \ + 0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7) + +#define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE 0x0000000000000001 +#define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002 +#define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004 +#define IMAGE_ATTRIBUTE_IN_USE 0x0000000000000008 +#define IMAGE_ATTRIBUTE_UEFI_IMAGE 0x0000000000000010 +#define IMAGE_ATTRIBUTE_DEPENDENCY 0x0000000000000020 + +#define IMAGE_COMPATIBILITY_CHECK_SUPPORTED 0x0000000000000001 + +#define IMAGE_UPDATABLE_VALID 0x0000000000000001 +#define IMAGE_UPDATABLE_INVALID 0x0000000000000002 +#define IMAGE_UPDATABLE_INVALID_TYPE 0x0000000000000004 +#define IMAGE_UPDATABLE_INVALID_OLLD 0x0000000000000008 +#define IMAGE_UPDATABLE_VALID_WITH_VENDOR_CODE 0x0000000000000010 + +#define PACKAGE_ATTRIBUTE_VERSION_UPDATABLE 0x0000000000000001 +#define PACKAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002 +#define PACKAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004 + +#define EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION 4 + +typedef struct efi_firmware_image_dependencies { + u8 dependencies[0]; +} efi_firmware_image_dep_t; + +struct efi_firmware_image_descriptor { + u8 image_index; + efi_guid_t image_type_id; + u64 image_id; + u16 *image_id_name; + u32 version; + u16 *version_name; + efi_uintn_t size; + u64 attributes_supported; + u64 attributes_setting; + u64 compatibilities; + u32 lowest_supported_image_version; + u32 last_attempt_version; + u32 last_attempt_status; + u64 hardware_instance; + efi_firmware_image_dep_t *dependencies; +}; + +struct efi_firmware_management_protocol { + efi_status_t (EFIAPI *get_image_info)( + struct efi_firmware_management_protocol *this, + efi_uintn_t *image_info_size, + struct efi_firmware_image_descriptor *image_info, + u32 *descriptor_version, + u8 *descriptor_count, + efi_uintn_t *descriptor_size, + u32 *package_version, + u16 **package_version_name); + efi_status_t (EFIAPI *get_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + void *image, + efi_uintn_t *image_size); + efi_status_t (EFIAPI *set_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + const void *image, + efi_uintn_t image_size, + const void *vendor_code, + efi_status_t (*progress)(efi_uintn_t completion), + u16 **abort_reason); + efi_status_t (EFIAPI *check_image)( + struct efi_firmware_management_protocol *this, + u8 image_index, + const void *image, + efi_uintn_t *image_size, + u32 *image_updatable); + efi_status_t (EFIAPI *get_package_info)( + struct efi_firmware_management_protocol *this, + u32 *package_version, + u16 **package_version_name, + u32 *package_version_name_maxlen, + u64 *attributes_supported, + u64 *attributes_setting); + efi_status_t (EFIAPI *set_package_info)( + struct efi_firmware_management_protocol *this, + const void *image, + efi_uintn_t *image_size, + const void *vendor_code, + u32 package_version, + const u16 *package_version_name); +}; + #endif diff --git a/include/efi_loader.h b/include/efi_loader.h index 572cfadd491a..b3b575f10c6a 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -209,6 +209,8 @@ extern const efi_guid_t efi_guid_cert_type_pkcs7; extern const efi_guid_t efi_guid_rng_protocol; /* GUID of capsule update result */ extern const efi_guid_t efi_guid_capsule_report; +/* GUID of firmware management protocol */ +extern const efi_guid_t efi_guid_firmware_management_protocol; extern unsigned int __efi_runtime_start, __efi_runtime_stop; extern unsigned int __efi_runtime_rel_start, __efi_runtime_rel_stop; diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index a2a015225a10..6ae18a422071 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -126,6 +126,14 @@ config EFI_CAPSULE_ON_DISK_EARLY executed as part of U-Boot initialisation so that they will surely take place whatever is set to distro_bootcmd. +config EFI_CAPSULE_FIRMWARE_MANAGEMENT + bool "Capsule: Firmware Management Protocol" + depends on EFI_HAVE_CAPSULE_SUPPORT + default y + help + Select this option if you want to enable capsule-based + firmware update using Firmware Management Protocol. + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 2259bfbf3d19..2015929e3708 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -15,6 +15,10 @@ #include const efi_guid_t efi_guid_capsule_report = EFI_CAPSULE_REPORT_GUID; +static const efi_guid_t efi_guid_firmware_management_capsule_id = + EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID; +const efi_guid_t efi_guid_firmware_management_protocol = + EFI_FIRMWARE_MANAGEMENT_PROTOCOL_GUID; #ifdef CONFIG_EFI_CAPSULE_ON_DISK /* for file system access */ @@ -88,6 +92,218 @@ void set_capsule_result(int index, struct efi_capsule_header *capsule, printf("EFI: creating %ls failed\n", variable_name16); } +#ifdef CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT +/** + * efi_fmp_find - search for Firmware Management Protocol drivers + * @image_type: Image type guid + * @instance: Instance number + * @handles: Handles of FMP drivers + * @no_handles: Number of handles + * + * Search for Firmware Management Protocol drivers, matching the image + * type, @image_type and the machine instance, @instance, from the list, + * @handles. + * + * Return: + * * Protocol instance - on success + * * NULL - on failure + */ +static struct efi_firmware_management_protocol * +efi_fmp_find(efi_guid_t *image_type, u64 instance, efi_handle_t *handles, + efi_uintn_t no_handles) +{ + efi_handle_t *handle; + struct efi_firmware_management_protocol *fmp; + struct efi_firmware_image_descriptor *image_info, *desc; + efi_uintn_t info_size, descriptor_size; + u32 descriptor_version; + u8 descriptor_count; + u32 package_version; + u16 *package_version_name; + bool found = false; + int i, j; + efi_status_t ret; + + for (i = 0, handle = handles; i < no_handles; i++, handle++) { + ret = EFI_CALL(efi_handle_protocol( + *handle, + &efi_guid_firmware_management_protocol, + (void **)&fmp)); + if (ret != EFI_SUCCESS) + continue; + + /* get device's image info */ + info_size = 0; + image_info = NULL; + descriptor_version = 0; + descriptor_count = 0; + descriptor_size = 0; + package_version = 0; + package_version_name = NULL; + ret = EFI_CALL(fmp->get_image_info(fmp, &info_size, + image_info, + &descriptor_version, + &descriptor_count, + &descriptor_size, + &package_version, + &package_version_name)); + if (ret != EFI_BUFFER_TOO_SMALL) + goto skip; + + image_info = malloc(info_size); + if (!image_info) + goto skip; + + ret = EFI_CALL(fmp->get_image_info(fmp, &info_size, + image_info, + &descriptor_version, + &descriptor_count, + &descriptor_size, + &package_version, + &package_version_name)); + if (ret != EFI_SUCCESS) + goto skip; + + /* matching */ + for (j = 0, desc = image_info; j < descriptor_count; + j++, desc = (void *)desc + descriptor_size) { + EFI_PRINT("+++ desc[%d] index: %d, name: %ls\n", + j, desc->image_index, desc->image_id_name); + if (!guidcmp(&desc->image_type_id, image_type) && + (!instance || + !desc->hardware_instance || + (descriptor_version >= 3 && + desc->hardware_instance == instance))) + found = true; + } + +skip: + efi_free_pool(package_version_name); + free(image_info); + EFI_CALL(efi_close_protocol( + (efi_handle_t)fmp, + &efi_guid_firmware_management_protocol, + NULL, NULL)); + if (found) + return fmp; + } + + return NULL; +} + +/** + * efi_capsule_update_firmware - update firmware from capsule + * @capsule_data: Capsule + * + * Update firmware, using a capsule, @capsule_data. Loading any FMP + * drivers embedded in a capsule is not supported. + * + * Return: status code + */ +static efi_status_t efi_capsule_update_firmware( + struct efi_capsule_header *capsule_data) +{ + struct efi_firmware_management_capsule_header *capsule; + struct efi_firmware_management_capsule_image_header *image; + size_t capsule_size; + void *image_binary, *vendor_code; + efi_handle_t *handles; + efi_uintn_t no_handles; + int item; + struct efi_firmware_management_protocol *fmp; + u16 *abort_reason; + efi_status_t ret = EFI_SUCCESS; + + /* sanity check */ + if (capsule_data->header_size < sizeof(*capsule) || + capsule_data->header_size >= capsule_data->capsule_image_size) + return EFI_INVALID_PARAMETER; + + capsule = (void *)capsule_data + capsule_data->header_size; + capsule_size = capsule_data->capsule_image_size + - capsule_data->header_size; + + if (capsule->version != 0x00000001) + return EFI_INVALID_PARAMETER; + + /* Drivers */ + /* TODO: support loading drivers */ + + handles = NULL; + ret = EFI_CALL(efi_locate_handle_buffer( + BY_PROTOCOL, + &efi_guid_firmware_management_protocol, + NULL, &no_handles, (efi_handle_t **)&handles)); + if (ret != EFI_SUCCESS) + return EFI_UNSUPPORTED; + + /* Payload */ + for (item = capsule->embedded_driver_count; + item < capsule->embedded_driver_count + + capsule->payload_item_count; item++) { + /* sanity check */ + if ((capsule->item_offset_list[item] + sizeof(*image) + >= capsule_size)) { + printf("EFI: A capsule has not enough size of data\n"); + ret = EFI_INVALID_PARAMETER; + goto out; + } + + image = (void *)capsule + capsule->item_offset_list[item]; + + if (image->version != 0x00000001 && + image->version != 0x00000002 && + image->version != 0x00000003) { + ret = EFI_INVALID_PARAMETER; + goto out; + } + + /* find a device for update firmware */ + /* TODO: should we pass index as well, or nothing but type? */ + fmp = efi_fmp_find(&image->update_image_type_id, + image->version == 0x1 ? 0 : + image->update_hardware_instance, + handles, no_handles); + if (!fmp) { + printf("EFI Capsule: driver not found for firmware type: %pUl, hardware instance: %lld\n", + &image->update_image_type_id, + image->version == 0x1 ? 0 : + image->update_hardware_instance); + ret = EFI_UNSUPPORTED; + goto out; + } + + /* do it */ + image_binary = (void *)image + sizeof(*image); + vendor_code = image_binary + image->update_image_size; + + abort_reason = NULL; + ret = EFI_CALL(fmp->set_image(fmp, image->update_image_index, + image_binary, + image->update_image_size, + vendor_code, NULL, + &abort_reason)); + if (ret != EFI_SUCCESS) { + printf("EFI Capsule: firmware update failed: %ls\n", + abort_reason); + efi_free_pool(abort_reason); + goto out; + } + } + +out: + efi_free_pool(handles); + + return ret; +} +#else +static efi_status_t efi_capsule_update_firmware( + struct efi_capsule_header *capsule_data) +{ + return EFI_UNSUPPORTED; +} +#endif /* CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT */ + /** * efi_update_capsule() - process information from operating system * @capsule_header_array: Array of virtual address pointers @@ -118,9 +334,29 @@ efi_status_t EFIAPI efi_update_capsule( goto out; } - ret = EFI_UNSUPPORTED; + ret = EFI_SUCCESS; for (i = 0, capsule = *capsule_header_array; i < capsule_count; i++, capsule = *(++capsule_header_array)) { + /* sanity check */ + if (capsule->header_size < sizeof(*capsule) || + capsule->capsule_image_size < sizeof(*capsule)) { + printf("EFI: A capsule has not enough size of data\n"); + continue; + } + + EFI_PRINT("Capsule[%d] (guid:%pUl)\n", + i, &capsule->capsule_guid); + if (!guidcmp(&capsule->capsule_guid, + &efi_guid_firmware_management_capsule_id)) { + ret = efi_capsule_update_firmware(capsule); + } else { + printf("EFI: not support capsule type: %pUl\n", + &capsule->capsule_guid); + ret = EFI_UNSUPPORTED; + } + + if (ret != EFI_SUCCESS) + goto out; } out: return EFI_EXIT(ret); diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index 99146671c899..b4303864bde6 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -160,6 +160,10 @@ static efi_status_t efi_init_os_indications(void) os_indications_supported |= EFI_OS_INDICATIONS_FILE_CAPSULE_DELIVERY_SUPPORTED; + if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT)) + os_indications_supported |= + EFI_OS_INDICATIONS_FMP_CAPSULE_SUPPORTED; + return efi_set_variable_int(L"OsIndicationsSupported", &efi_global_variable_guid, EFI_VARIABLE_BOOTSERVICE_ACCESS | From patchwork Thu Oct 29 00:25:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319314 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15774ilc; Wed, 28 Oct 2020 17:28:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRhZwDc3Wxp7b9p4RPcpzjfIVTE7VU9p8pM4eKV1rm2O6ffsB8YVEiDXhKezGOIt55OZec X-Received: by 2002:a17:906:81c5:: with SMTP id e5mr1630502ejx.10.1603931282524; Wed, 28 Oct 2020 17:28:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931282; cv=none; d=google.com; s=arc-20160816; b=Cl3mdUaM9F8v9he8rp9BRfr8xVOWLtC4glixpmrLiY7Br00X7WqJEAGDTyQUWDyf7o EayBJqHhlMm4ishMDNOM1N3EOr66C7C6FWRGRE//7+9DLgu7BN9WhqtXnJ3T2Cs/VNMo InEnCqs1xtGrv1ljmI5jHCaKB1aWr4o6w1Yn2xFVdegkxHbbPBsqa0JIAeLoTw/hor8S CJjBKuiRIvH4s5ynovNbnGI/575lmyYfeqaeMlbroHER49nd67tDOZ3vsiounRW4CA+6 3LwuH36dKbVceoKgfKWxf0O2Mucxqqn+AWBwCXY75M02t8ZiBTAOb9TMl0+qUznOtlsF fClQ== 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=3jx9p+TCVO+KsZFfgZFH6u4KPC59n5+7xCrCRSyTgh8=; b=IhzGNv8Se9XA3GL3pbfhXPLqRHP0yKHNDjosLn0plQJbK04e3Dy6pmuQR3b1QBU9X+ fgeKflWlFU3Ryl7UX1yeisfUnNPN9ubFsyDn7HyNKt2pT6rOcOA6W4+XjYruWKuG9f/O uvdahtvfA2s/lKXuhSZI3SNUbhz+OyzeGVeZSSgRw8ju0sEM0DQfL2Jpf0iWfprpp7Tl c7aHR6hlXb3b1tzU9oHNS1teFxH5iNR4vgmjrN5Z974LnmpeEx5jV3baFAwjFAyOJ36V PlYwezKLvVKYb0y1YHliDuMNOg24x6cEI02W+SBwfLc881MnvVcggd56MHazgnttzIRu w8uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HI8YVYTd; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id i19si671145ejh.153.2020.10.28.17.28.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:28:02 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HI8YVYTd; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 46F7182528; Thu, 29 Oct 2020 01:26:40 +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="HI8YVYTd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 04A00824FD; Thu, 29 Oct 2020 01:26:31 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) (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 69F228250C for ; Thu, 29 Oct 2020 01:26:27 +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=takahiro.akashi@linaro.org Received: by mail-pg1-x544.google.com with SMTP id s22so890946pga.9 for ; Wed, 28 Oct 2020 17:26:27 -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=3jx9p+TCVO+KsZFfgZFH6u4KPC59n5+7xCrCRSyTgh8=; b=HI8YVYTd0L8DoRUjeh6/fy6w5bqqUPQVS2VFA0n0zofjDA1lzbef/NMSlBRnmILpQO EQVkzCm1osvS0Xu63TLGaKryyGob2jYaoM02yEMPRBUpKhkS+P9dsfuS7pjOk3pH98rx ifLT0092320cbEMxtTG8V1ultKXcOXeHcB1Lk2rVkWmC724qYlcWAXNv/g2vPPck93f4 wo3ATxF2+1TsnLMJupGsSq5Ec1pQYQ3wNN7CfcroVBtEctvFSYUfxknffYtycbfL/rtE JTZMmLJWuEa7qnkux3cU/qowGpfDZirVLKt2vVeqXIeo/gIfBSPbouk5B+MUvzuojmzf /3jg== 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=3jx9p+TCVO+KsZFfgZFH6u4KPC59n5+7xCrCRSyTgh8=; b=PUQL7v6C0qRh3AG2pKbn9JV6AREUER/+3rPmWCKyxdYfoNX8L4rA0T0SYXg0HbD4Fh qJ+zo64LABfTDqFB0oScV3SBeH2s+wO27Wbl02L869c2nyOxQaTWsRHmj/sCgNOdICWQ 3wvayuqk3S5cW317F8nLHEUUD9Vl6QtBS+2ZdrwMtomGrA3nHLNIxnl6BhXcKREjqkef eql2mYwbF6oitdTQ0QloHf4+OthjLU+8pZ/tFyP8hdhWgts3gr5j0aJS4Jdr4/62tQLj YIwiiJVJq/Qrx00rzvKREH8e3HrE8GSbO9rQQqpVSzXWSXoFxgFqbPatQ7gaE1DoWyCB q0pw== X-Gm-Message-State: AOAM530RiwLEPU7QuiJ+Z16wuMeilIDYqOt1+SwyYHj6JvWwq6PyS57/ +qxz1J76TR3fN6myBYrVl+Zx1Q== X-Received: by 2002:a05:6a00:2282:b029:156:1a7b:3cf9 with SMTP id f2-20020a056a002282b02901561a7b3cf9mr1687601pfe.5.1603931185929; Wed, 28 Oct 2020 17:26:25 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:25 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 11/17] efi_loader: add firmware management protocol for FIT image Date: Thu, 29 Oct 2020 09:25:22 +0900 Message-Id: <20201029002528.34408-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean In this commit, a very simple firmware management protocol driver is implemented. It will take a common FIT image firmware in a capsule file and apply the data using dfu backend storage drivers via update_fit() interface. So "dfu_alt_info" variable should be properly set to specify a device and location to be updated. Please read README.dfu. Fit image is a common file format for firmware update on U-Boot, and this protocol works neatly just as a wrapper for one. Signed-off-by: AKASHI Takahiro --- include/efi_api.h | 4 + include/efi_loader.h | 2 + lib/efi_loader/Kconfig | 11 ++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_capsule.c | 12 +- lib/efi_loader/efi_firmware.c | 291 ++++++++++++++++++++++++++++++++++ 6 files changed, 320 insertions(+), 1 deletion(-) create mode 100644 lib/efi_loader/efi_firmware.c -- 2.28.0 diff --git a/include/efi_api.h b/include/efi_api.h index 966bc6e590bf..071d0ba866c7 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -1849,6 +1849,10 @@ struct efi_signature_list { EFI_GUID(0x86c77a67, 0x0b97, 0x4633, 0xa1, 0x87, \ 0x49, 0x10, 0x4d, 0x06, 0x85, 0xc7) +#define EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID \ + EFI_GUID(0xae13ff2d, 0x9ad4, 0x4e25, 0x9a, 0xc8, \ + 0x6d, 0x80, 0xb3, 0xb2, 0x21, 0x47) + #define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE 0x0000000000000001 #define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002 #define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004 diff --git a/include/efi_loader.h b/include/efi_loader.h index b3b575f10c6a..de6d353de3b1 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -811,6 +811,8 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t n); /* commonly used helper function */ u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index); +extern const struct efi_firmware_management_protocol efi_fmp_fit; + /* Capsule update */ efi_status_t EFIAPI efi_update_capsule( struct efi_capsule_header **capsule_header_array, diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 6ae18a422071..94c1ad2af097 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -134,6 +134,17 @@ config EFI_CAPSULE_FIRMWARE_MANAGEMENT Select this option if you want to enable capsule-based firmware update using Firmware Management Protocol. +config EFI_CAPSULE_FIRMWARE_FIT + bool "FMP driver for FIT image" + depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT + depends on FIT + select UPDATE_FIT + select DFU + default n + help + Select this option if you want to enable firmware management protocol + driver for FIT image + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index c7d231f0e57d..23b1828b0fe0 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o obj-y += efi_bootmgr.o obj-y += efi_boottime.o obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o +obj-$(CONFIG_EFI_CAPSULE_FIRMWARE_FIT) += efi_firmware.o obj-y += efi_console.o obj-y += efi_device_path.o obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index 2015929e3708..a44f81daaee9 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -804,7 +804,17 @@ static void efi_capsule_scan_done(void) */ efi_status_t __weak arch_efi_load_capsule_drivers(void) { - return EFI_SUCCESS; + __maybe_unused efi_handle_t handle; + efi_status_t ret = EFI_SUCCESS; + + if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_FIT)) { + handle = NULL; + ret = EFI_CALL(efi_install_multiple_protocol_interfaces( + &handle, &efi_guid_firmware_management_protocol, + &efi_fmp_fit, NULL)); + } + + return ret; } /** diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c new file mode 100644 index 000000000000..4c395f4eb5d9 --- /dev/null +++ b/lib/efi_loader/efi_firmware.c @@ -0,0 +1,291 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * EFI Firmware management protocol + * + * Copyright (c) 2020 Linaro Limited + * Author: AKASHI Takahiro + */ + +#include +#include +#include +#include +#include +#include + +/* + * This FIRMWARE_MANAGEMENT_PROTOCOL driver provides a firmware update + * method with existing FIT image format, and handles + * - multiple regions of firmware via DFU + * but doesn't support + * - versioning of firmware image + * - package information + */ +const efi_guid_t efi_firmware_image_type_uboot_fit = + EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID; + +/** + * efi_get_dfu_info - return information about the current firmware image + * @this: Protocol instance + * @image_info_size: Size of @image_info + * @image_info: Image information + * @descriptor_version: Pointer to version number + * @descriptor_count: Pointer to number of descriptors + * @descriptor_size: Pointer to descriptor size + * package_version: Package version + * package_version_name: Package version's name + * image_type: Image type GUID + * + * Return information bout the current firmware image in @image_info. + * @image_info will consist of a number of descriptors. + * Each descriptor will be created based on "dfu_alt_info" variable. + * + * Return status code + */ +static efi_status_t efi_get_dfu_info( + efi_uintn_t *image_info_size, + struct efi_firmware_image_descriptor *image_info, + u32 *descriptor_version, + u8 *descriptor_count, + efi_uintn_t *descriptor_size, + u32 *package_version, + u16 **package_version_name, + const efi_guid_t *image_type) +{ + struct dfu_entity *dfu; + size_t names_len, total_size; + int dfu_num, i; + u16 *name, *next; + + dfu_init_env_entities(NULL, NULL); + + names_len = 0; + dfu_num = 0; + list_for_each_entry(dfu, &dfu_list, list) { + names_len += (utf8_utf16_strlen(dfu->name) + 1) * 2; + dfu_num++; + } + if (!dfu_num) { + EFI_PRINT("Probably dfu_alt_info not defined\n"); + *image_info_size = 0; + dfu_free_entities(); + + return EFI_SUCCESS; + } + + total_size = sizeof(*image_info) * dfu_num + names_len; + /* + * we will assume that sizeof(*image_info) * dfu_name + * is, at least, a multiple of 2. So the start address for + * image_id_name would be aligned with 2 bytes. + */ + if (*image_info_size < total_size) { + *image_info_size = total_size; + dfu_free_entities(); + + return EFI_BUFFER_TOO_SMALL; + } + *image_info_size = total_size; + + *descriptor_version = EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION; + *descriptor_count = dfu_num; + *descriptor_size = sizeof(*image_info); + *package_version = 0xffffffff; /* not supported */ + *package_version_name = NULL; /* not supported */ + + /* DFU alt number should correspond to image_index */ + i = 0; + /* Name area starts just after descriptors */ + name = (u16 *)((u8 *)image_info + sizeof(*image_info) * dfu_num); + next = name; + list_for_each_entry(dfu, &dfu_list, list) { + image_info[i].image_index = dfu->alt + 1; + image_info[i].image_type_id = *image_type; + image_info[i].image_id = dfu->alt; + + /* copy the DFU entity name */ + utf8_utf16_strcpy(&next, dfu->name); + image_info[i].image_id_name = name; + name = ++next; + + image_info[i].version = 0; /* not supported */ + image_info[i].version_name = NULL; /* not supported */ + image_info[i].size = 0; + image_info[i].attributes_supported = + IMAGE_ATTRIBUTE_IMAGE_UPDATABLE; + image_info[i].attributes_setting = + IMAGE_ATTRIBUTE_IMAGE_UPDATABLE; + image_info[i].lowest_supported_image_version = 0; + image_info[i].last_attempt_version = 0; + image_info[i].last_attempt_status = LAST_ATTEMPT_STATUS_SUCCESS; + image_info[i].hardware_instance = 1; + image_info[i].dependencies = NULL; + + i++; + } + + dfu_free_entities(); + + return EFI_SUCCESS; +} + +/** + * efi_firmware_fit_get_image_info - return information about the current + * firmware image + * @this: Protocol instance + * @image_info_size: Size of @image_info + * @image_info: Image information + * @descriptor_version: Pointer to version number + * @descriptor_count: Pointer to number of descriptors + * @descriptor_size: Pointer to descriptor size + * package_version: Package version + * package_version_name: Package version's name + * + * Return information bout the current firmware image in @image_info. + * @image_info will consist of a number of descriptors. + * Each descriptor will be created based on "dfu_alt_info" variable. + * + * Return status code + */ +static +efi_status_t EFIAPI efi_firmware_fit_get_image_info( + struct efi_firmware_management_protocol *this, + efi_uintn_t *image_info_size, + struct efi_firmware_image_descriptor *image_info, + u32 *descriptor_version, + u8 *descriptor_count, + efi_uintn_t *descriptor_size, + u32 *package_version, + u16 **package_version_name) +{ + efi_status_t ret; + + EFI_ENTRY("%p %p %p %p %p %p %p %p\n", this, + image_info_size, image_info, + descriptor_version, descriptor_count, descriptor_size, + package_version, package_version_name); + + if (!image_info_size) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + if (*image_info_size && + (!image_info || !descriptor_version || !descriptor_count || + !descriptor_size || !package_version || !package_version_name)) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + ret = efi_get_dfu_info(image_info_size, image_info, + descriptor_version, descriptor_count, + descriptor_size, + package_version, package_version_name, + &efi_firmware_image_type_uboot_fit); + + return EFI_EXIT(ret); +} + +/* Place holder; not supported */ +static +efi_status_t EFIAPI efi_firmware_get_image_unsupported( + struct efi_firmware_management_protocol *this, + u8 image_index, + void *image, + efi_uintn_t *image_size) +{ + EFI_ENTRY("%p %d %p %p\n", this, image_index, image, image_size); + + return EFI_EXIT(EFI_UNSUPPORTED); +} + +/** + * efi_firmware_fit_set_image - update the firmware image + * @this: Protocol instance + * @image_index: Image index number + * @image: New image + * @image_size: Size of new image + * @vendor_code: Vendor-specific update policy + * @progress: Function to report the progress of update + * @abort_reason: Pointer to string of abort reason + * + * Update the firmware to new image, using dfu. The new image should + * have FIT image format commonly used in U-Boot. + * @vendor_code, @progress and @abort_reason are not supported. + * + * Return: status code + */ +static +efi_status_t EFIAPI efi_firmware_fit_set_image( + struct efi_firmware_management_protocol *this, + u8 image_index, + const void *image, + efi_uintn_t image_size, + const void *vendor_code, + efi_status_t (*progress)(efi_uintn_t completion), + u16 **abort_reason) +{ + EFI_ENTRY("%p %d %p %ld %p %p %p\n", this, image_index, image, + image_size, vendor_code, progress, abort_reason); + + if (!image || image_index != 1) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + if (fit_update(image)) + return EFI_EXIT(EFI_DEVICE_ERROR); + + return EFI_EXIT(EFI_SUCCESS); +} + +/* Place holder; not supported */ +static +efi_status_t EFIAPI efi_firmware_check_image_unsupported( + struct efi_firmware_management_protocol *this, + u8 image_index, + const void *image, + efi_uintn_t *image_size, + u32 *image_updatable) +{ + EFI_ENTRY("%p %d %p %p %p\n", this, image_index, image, image_size, + image_updatable); + + return EFI_EXIT(EFI_UNSUPPORTED); +} + +/* Place holder; not supported */ +static +efi_status_t EFIAPI efi_firmware_get_package_info_unsupported( + struct efi_firmware_management_protocol *this, + u32 *package_version, + u16 **package_version_name, + u32 *package_version_name_maxlen, + u64 *attributes_supported, + u64 *attributes_setting) +{ + EFI_ENTRY("%p %p %p %p %p %p\n", this, package_version, + package_version_name, package_version_name_maxlen, + attributes_supported, attributes_setting); + + return EFI_EXIT(EFI_UNSUPPORTED); +} + +/* Place holder; not supported */ +static +efi_status_t EFIAPI efi_firmware_set_package_info_unsupported( + struct efi_firmware_management_protocol *this, + const void *image, + efi_uintn_t *image_size, + const void *vendor_code, + u32 package_version, + const u16 *package_version_name) +{ + EFI_ENTRY("%p %p %p %p %x %p\n", this, image, image_size, vendor_code, + package_version, package_version_name); + + return EFI_EXIT(EFI_UNSUPPORTED); +} + +const struct efi_firmware_management_protocol efi_fmp_fit = { + .get_image_info = efi_firmware_fit_get_image_info, + .get_image = efi_firmware_get_image_unsupported, + .set_image = efi_firmware_fit_set_image, + .check_image = efi_firmware_check_image_unsupported, + .get_package_info = efi_firmware_get_package_info_unsupported, + .set_package_info = efi_firmware_set_package_info_unsupported, +}; From patchwork Thu Oct 29 00:25:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319315 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15887ilc; Wed, 28 Oct 2020 17:28:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbrkP7TlnU63pWr1c10pYlkzRgaYsXaKCsa9MuSLAEdwNrZrgewBMWAERwY3B4X4D0YnAb X-Received: by 2002:a05:6402:2d7:: with SMTP id b23mr1475204edx.196.1603931294308; Wed, 28 Oct 2020 17:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931294; cv=none; d=google.com; s=arc-20160816; b=aW4NKbxyo2yA0GXF4PABfPbu0DeUjyCoAQv7T1z3AcGif0/6PXVEY3ULaRa+PldphE 4//vBP7GTOyS/I5ckfQpQ3vj1mGyBOHcWhH7s7ntgmNASjNjPNpvDzmD/mCs95GA/qI4 ZtkthEtmF05LtcFtL5D4rYL5Cab+yhvZ3OuQRk8NXJuT2EIQ4v4X+WYrJl/xc04bjo8s INDJ4HSEYB77pcsn30nEAqURFV//aA2LUKBuEN36w2pkOkMrIgr/3BuYCXDI9FYdopSi R7Mus6oSz5hUPznZ3emi+2AwTzJTuhyJiADG6l7fOeJHu4SGTMuFGgyO/t1pXhxjsgV+ XA+w== 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=WiqeZfpZSu5UfUsqbzXxfvRpNlDhX0frfl2n+yjmzt8=; b=y1MIyJMI7nW5mG/x1dOboSxsXFY0ZSImvq7IMk51D/LevwM/y4nESjC0EgVIkfFqWs dMrUeHSEjyNJArENmLdQbvdXh/X+YfoMKh/blzFRh6PbO/GjQ6attzCttT4e1D0l+UzY dKf3vItTvH5l5WlFJ+ypgCPlR+ZR8HqM1AWQyqF3sKKZYeAEpmwdTkDiXhCp9KQbi8ao pP431cw2f9DAT8JDvr6NfSeeQJKoCHclMlFc63b/vT5nDBB/vsnWdkrsJAaUIGrJE1Di nNt23/X/lKEaflpxl6vhXs+2uFuxDUfjEsU/GdCXwo0q/UpJHtmWTuSAZLnKp7aKucz4 VioQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CcOP+g8l; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id yd22si951647ejb.101.2020.10.28.17.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:28:14 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CcOP+g8l; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 70F4782529; Thu, 29 Oct 2020 01:26:42 +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="CcOP+g8l"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6E0DE8250C; Thu, 29 Oct 2020 01:26:33 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) (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 6453E82508 for ; Thu, 29 Oct 2020 01:26:30 +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=takahiro.akashi@linaro.org Received: by mail-pg1-x52d.google.com with SMTP id f38so912839pgm.2 for ; Wed, 28 Oct 2020 17:26:30 -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=WiqeZfpZSu5UfUsqbzXxfvRpNlDhX0frfl2n+yjmzt8=; b=CcOP+g8lKLeLx07/yiUPW/f4aMBt3xlSLZVk1VzQ6yrFSXfqK+s/CMypxFN+1va556 G4I8wdLuz+Upg5sEdZbLWq8gTRiKQvgc7g+WX2IY1zkr2FzO6eZaLDInV5ivrcOaW7f3 B4UFy8LoPisGzna4qTcGuVF0MpROL9NeC+QzUMBCOkDxXwfkoMHQ66DXSrwggeGNNMpt XgJQgeEb+c6YUOCRFivCCElnIGF2GqrvkI7oGPcVvdECHkibdjfxhD+sXqUiODIF7Sbb tYW6Wgx6T8x4oEPQemYVJ+iV6HDDHMp6DeJ9poAqXWDVxf1DS8mP2rSn9y635zJ0w0Fu o6Cw== 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=WiqeZfpZSu5UfUsqbzXxfvRpNlDhX0frfl2n+yjmzt8=; b=q9f/dpfRSrRZpw/98+SNhpwvDX+Gli1ONFAP35SlJuFcG1zvnfFKakcCaLtLOW6Yi6 UGwSJi6r7HgMxWOgfpcGDwN9Bd1kpu4yaJJarwCketGXAXII3WJY0RKoLY0vzPFeDA5X jF9puzHLuiUDzdkAVWWu1bl65/36lf/0hJ4OPTYnm/kBBghnE2Bxbj794XsXKQ0/ziG4 NGtnXiQ3KlT+/2To+UMSsV9bsQy61ApQAGMBrPLKiom6jp/nEZvddlt2Bu76JXIK31cS GGtS+/BXTjGmjWAEXTgr2lPC+xyGJ3ZPpvt1wWPf395P99dhVRCEKwojlPkzbW4MzfvU KHpA== X-Gm-Message-State: AOAM5310XLzjzsWE6nHe1xB42eU8wAKZLkmROS2vlSwQ70FhMygCv5gM zN7Wad+YO/7CyNQ6clkgbWHhRA== X-Received: by 2002:aa7:9dd1:0:b029:15d:d9c2:f8b0 with SMTP id g17-20020aa79dd10000b029015dd9c2f8b0mr1452922pfq.47.1603931188946; Wed, 28 Oct 2020 17:26:28 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:28 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 12/17] dfu: add dfu_write_by_alt() Date: Thu, 29 Oct 2020 09:25:23 +0900 Message-Id: <20201029002528.34408-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean This function is a variant of dfu_write_by_name() and takes a DFU alt setting number for dfu configuration. It will be utilised to implement UEFI capsule management protocol for raw image in a later commit. Signed-off-by: AKASHI Takahiro --- drivers/dfu/dfu_alt.c | 47 +++++++++++++++++++++++++++++++++++++++++++ include/dfu.h | 26 +++++++++++++++++++++++- 2 files changed, 72 insertions(+), 1 deletion(-) -- 2.28.0 diff --git a/drivers/dfu/dfu_alt.c b/drivers/dfu/dfu_alt.c index 7528806cd163..d5827812070c 100644 --- a/drivers/dfu/dfu_alt.c +++ b/drivers/dfu/dfu_alt.c @@ -76,3 +76,50 @@ done: return ret; } + +/** + * dfu_write_by_alt() - write data to DFU medium + * @dfu_alt_num: DFU alt setting number + * @addr: Address of data buffer to write + * @len: Number of bytes + * @interface: Destination DFU medium (e.g. "mmc") + * @devstring: Instance number of destination DFU medium (e.g. "1") + * + * This function is storing data received on DFU supported medium which + * is specified by @dfu_alt_name. + * + * Return: 0 - on success, error code - otherwise + */ +int dfu_write_by_alt(int dfu_alt_num, void *addr, unsigned int len, + char *interface, char *devstring) +{ + struct dfu_entity *dfu; + int ret; + + debug("%s: alt: %d addr: 0x%p len: %d device: %s:%s\n", __func__, + dfu_alt_num, addr, len, interface, devstring); + + ret = dfu_init_env_entities(interface, devstring); + if (ret) + goto done; + + if (dfu_alt_num < 0) { + pr_err("Invalid alt number: %d", dfu_alt_num); + ret = -ENODEV; + goto done; + } + + dfu = dfu_get_entity(dfu_alt_num); + if (!dfu) { + pr_err("DFU entity for alt: %d not found!", dfu_alt_num); + ret = -ENODEV; + goto done; + } + + ret = dfu_write_from_mem_addr(dfu, (void *)(uintptr_t)addr, len); + +done: + dfu_free_entities(); + + return ret; +} diff --git a/include/dfu.h b/include/dfu.h index 015d1bf895d0..6c5b4aaa5963 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -496,6 +496,7 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, } #endif +#if CONFIG_IS_ENABLED(DFU_ALT) /** * dfu_write_by_name() - write data to DFU medium * @dfu_entity_name: Name of DFU entity to write @@ -509,9 +510,24 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, * * Return: 0 - on success, error code - otherwise */ -#if CONFIG_IS_ENABLED(DFU_ALT) int dfu_write_by_name(char *dfu_entity_name, void *addr, unsigned int len, char *interface, char *devstring); + +/** + * dfu_write_by_alt() - write data to DFU medium + * @dfu_alt_num: DFU alt setting number + * @addr: Address of data buffer to write + * @len: Number of bytes + * @interface: Destination DFU medium (e.g. "mmc") + * @devstring: Instance number of destination DFU medium (e.g. "1") + * + * This function is storing data received on DFU supported medium which + * is specified by @dfu_alt_name. + * + * Return: 0 - on success, error code - otherwise + */ +int dfu_write_by_alt(int dfu_alt_num, void *addr, unsigned int len, + char *interface, char *devstring); #else static inline int dfu_write_by_name(char *dfu_entity_name, void *addr, unsigned int len, char *interface, @@ -520,6 +536,14 @@ static inline int dfu_write_by_name(char *dfu_entity_name, void *addr, puts("write support for DFU not available!\n"); return -ENOSYS; } + +static inline int dfu_write_by_alt(int dfu_alt_num, void *addr, + unsigned int len, char *interface, + char *devstring) +{ + puts("write support for DFU not available!\n"); + return -ENOSYS; +} #endif int dfu_add(struct usb_configuration *c); From patchwork Thu Oct 29 00:25:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319316 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp15956ilc; Wed, 28 Oct 2020 17:28:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzV70rqOPtEfK/nbnQkdHao6l8W7/+3iCWSd5y2GyFC/stWuGvU/ZhekzCmt7i5zu1vfxkL X-Received: by 2002:a17:906:d1c3:: with SMTP id bs3mr1574690ejb.246.1603931304531; Wed, 28 Oct 2020 17:28:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931304; cv=none; d=google.com; s=arc-20160816; b=bQtbruhTKMf4dHEaCrqcddd6sOqhrUoFZn465flpfbx0lqpfdcbavlWPWYWei5oe2F TTx3LuEFqIAETxqyHbOUF7Ye1Ubvet/Sn4x2aJhTgfywvAcYVu2xdllI5r9KWcdVG1fb UVyEf5HRS12NBOv7Ibrg5pI9AAbGVy2lQjFHhVwTL/dF0djOuxZ+iEhUuUaRFR4UcA57 zYI5DuhTTC+vbDY4zRp+C6vDVGzlGMqLzj2iz8z25VnnockLwubWZDDfMDw4HsE7QBOb mJCNyKUe+QnkCEKEktYk67gVC4PSg9gNjsKvhVeO2kE1L7qTYKJHE0vI2HVrBnWq+Kgy NiWg== 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=ycJLDJSgluesOuFiFpNjIvc1ES6aEwt0Sy4ukMwnts4=; b=JoCzFBD51XAgvkVH4iPgjkAZdT3FzyV89IxR382XoX2/jLMMk5aV8xYI3PfhKC6G7K rbEcUY7mF/8s/L1TmCBGOU4WnzJrdLOBxjJ8fTBScyZ0cwVMRuw8XttMqbzIB5jE9WA8 njk9Fwh9Lcg5E9fiAdzurDiZU9qW5xwU3IGgZdU6+tnA6sHhxhCUrBGpaxCl8rOAC1cL qd1u6KyqmDKrcTS3pZIA+37dak9VMr643LF3tBtPtikKJItvISM1OzP7Ucse03VOyiaZ OUiXq+CeR6E3RMPGT/EEw8n2wVxzDtZ0dAaM5ERHcbCylS1k6JTu+0dUcijDkEjRjo9h SQAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TQuXnXuF; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id h34si793606edd.72.2020.10.28.17.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:28:24 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TQuXnXuF; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 8876A82522; Thu, 29 Oct 2020 01:26:43 +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="TQuXnXuF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1E5F08250C; Thu, 29 Oct 2020 01:26:37 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (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 8415A8002F for ; Thu, 29 Oct 2020 01:26:33 +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=takahiro.akashi@linaro.org Received: by mail-pf1-x443.google.com with SMTP id o129so881100pfb.1 for ; Wed, 28 Oct 2020 17:26:33 -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=ycJLDJSgluesOuFiFpNjIvc1ES6aEwt0Sy4ukMwnts4=; b=TQuXnXuF8j7dp/bKdYXY+BUmIx34n4eZdnS90HVtS5LBrH2BxfwuJdjDa4Wqsnhk2r bxVKlHgerapEcDc9lgoEiTDD7DWC0g1OaLHQ2ysW/zv/627YxixzHO+1J1dxuFQoej57 w+EoaWasGHaHIsO9acOwwK9JNPor3zrAWWw2cncCH2MxHGsZ7wE6jGTPXjTpZWuTXjfb Uw/uf9Rnucs9BzTwvR1g0oTUzWUONq24yFSZUwsTL558nCFHtaCljAWJ8rkNC6Avdbmn VaKksFPwnuVwpkS1LBQrf2YEV5Mk/OBXTwLVlepuhwepIM8Sf/V2hwA6ZmDXQMxj4pqJ WCHQ== 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=ycJLDJSgluesOuFiFpNjIvc1ES6aEwt0Sy4ukMwnts4=; b=n8qw+GxgZxXEvf+UPIJ+fXWV8Fo9Ww23g60qavI0gerT0eHWDy8ePlOuqYoB6hxjTo 0wZMbdJadJKQiHojp25poXrFWLPkqEvab6h/MiiApHSvWhGMrSLkN+JBYJd+VH72MnhP ZsxmpIZgiLR1TzQ19vgQLzgxM4WqTmWoFRQEsbNSxSEma/LpLrFou0IcwOiC7T3SsKwR t+Va4oFlHxCjFbutr4uBA/Z/wZcQBM2lT59lGyvVceDDoE2bRNnYIHHRXwIjLvaR2NI+ 4JfdUAQPrOQ5VQpwKiQhvPgS6yVc71HV2W08oDY8dKXetPJXef8bzjUXzgP+ZatTLM9l C4EA== X-Gm-Message-State: AOAM532tyRwZNxEzih36TuXAI1BO0VtJKGzQTWTZYA7uo4BaSWoTnmZ6 kbWqFnAcnQKzfjDuiv5HjiK8B35GFLrLYQ== X-Received: by 2002:a63:be43:: with SMTP id g3mr1721788pgo.266.1603931192082; Wed, 28 Oct 2020 17:26:32 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:31 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 13/17] efi_loader: add firmware management protocol for raw image Date: Thu, 29 Oct 2020 09:25:24 +0900 Message-Id: <20201029002528.34408-14-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean In this commit, a very simple firmware management protocol driver is implemented. It will take a binary image in a capsule file and apply the data using dfu backend storage drivers via dfu_write_by_alt() interface. So "dfu_alt_info" variable should be properly set to specify a device and location to be updated. Please read README.dfu. Signed-off-by: AKASHI Takahiro --- include/efi_api.h | 4 + include/efi_loader.h | 1 + lib/efi_loader/Kconfig | 16 +++ lib/efi_loader/Makefile | 2 +- lib/efi_loader/efi_capsule.c | 8 ++ lib/efi_loader/efi_firmware.c | 226 +++++++++++++++++++++++++--------- 6 files changed, 199 insertions(+), 58 deletions(-) -- 2.28.0 diff --git a/include/efi_api.h b/include/efi_api.h index 071d0ba866c7..c7038f863ab2 100644 --- a/include/efi_api.h +++ b/include/efi_api.h @@ -1853,6 +1853,10 @@ struct efi_signature_list { EFI_GUID(0xae13ff2d, 0x9ad4, 0x4e25, 0x9a, 0xc8, \ 0x6d, 0x80, 0xb3, 0xb2, 0x21, 0x47) +#define EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID \ + EFI_GUID(0xe2bb9c06, 0x70e9, 0x4b14, 0x97, 0xa3, \ + 0x5a, 0x79, 0x13, 0x17, 0x6e, 0x3f) + #define IMAGE_ATTRIBUTE_IMAGE_UPDATABLE 0x0000000000000001 #define IMAGE_ATTRIBUTE_RESET_REQUIRED 0x0000000000000002 #define IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED 0x0000000000000004 diff --git a/include/efi_loader.h b/include/efi_loader.h index de6d353de3b1..0f85873a72f8 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -812,6 +812,7 @@ void efi_memcpy_runtime(void *dest, const void *src, size_t n); u16 *efi_create_indexed_name(u16 *buffer, const u16 *name, unsigned int index); extern const struct efi_firmware_management_protocol efi_fmp_fit; +extern const struct efi_firmware_management_protocol efi_fmp_raw; /* Capsule update */ efi_status_t EFIAPI efi_update_capsule( diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index 94c1ad2af097..f94a9637b23a 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -126,6 +126,10 @@ config EFI_CAPSULE_ON_DISK_EARLY executed as part of U-Boot initialisation so that they will surely take place whatever is set to distro_bootcmd. +config EFI_CAPSULE_FIRMWARE + bool + default n + config EFI_CAPSULE_FIRMWARE_MANAGEMENT bool "Capsule: Firmware Management Protocol" depends on EFI_HAVE_CAPSULE_SUPPORT @@ -140,11 +144,23 @@ config EFI_CAPSULE_FIRMWARE_FIT depends on FIT select UPDATE_FIT select DFU + select EFI_CAPSULE_FIRMWARE default n help Select this option if you want to enable firmware management protocol driver for FIT image +config EFI_CAPSULE_FIRMWARE_RAW + bool "FMP driver for raw image" + depends on EFI_CAPSULE_FIRMWARE_MANAGEMENT + select DFU + select DFU_ALT + select EFI_CAPSULE_FIRMWARE + default n + help + Select this option if you want to enable firmware management protocol + driver for raw image + config EFI_DEVICE_PATH_TO_TEXT bool "Device path to text protocol" default y diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index 23b1828b0fe0..a7631d92a3b0 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -24,7 +24,7 @@ obj-$(CONFIG_CMD_BOOTEFI_HELLO) += helloworld_efi.o obj-y += efi_bootmgr.o obj-y += efi_boottime.o obj-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += efi_capsule.o -obj-$(CONFIG_EFI_CAPSULE_FIRMWARE_FIT) += efi_firmware.o +obj-$(CONFIG_EFI_CAPSULE_FIRMWARE) += efi_firmware.o obj-y += efi_console.o obj-y += efi_device_path.o obj-$(CONFIG_EFI_DEVICE_PATH_TO_TEXT) += efi_device_path_to_text.o diff --git a/lib/efi_loader/efi_capsule.c b/lib/efi_loader/efi_capsule.c index a44f81daaee9..af40b4a1599e 100644 --- a/lib/efi_loader/efi_capsule.c +++ b/lib/efi_loader/efi_capsule.c @@ -814,6 +814,14 @@ efi_status_t __weak arch_efi_load_capsule_drivers(void) &efi_fmp_fit, NULL)); } + if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_RAW)) { + handle = NULL; + ret = EFI_CALL(efi_install_multiple_protocol_interfaces( + &efi_root, + &efi_guid_firmware_management_protocol, + &efi_fmp_raw, NULL)); + } + return ret; } diff --git a/lib/efi_loader/efi_firmware.c b/lib/efi_loader/efi_firmware.c index 4c395f4eb5d9..7e5607738319 100644 --- a/lib/efi_loader/efi_firmware.c +++ b/lib/efi_loader/efi_firmware.c @@ -13,16 +13,66 @@ #include #include -/* - * This FIRMWARE_MANAGEMENT_PROTOCOL driver provides a firmware update - * method with existing FIT image format, and handles - * - multiple regions of firmware via DFU - * but doesn't support - * - versioning of firmware image - * - package information - */ -const efi_guid_t efi_firmware_image_type_uboot_fit = - EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID; +/* Place holder; not supported */ +static +efi_status_t EFIAPI efi_firmware_get_image_unsupported( + struct efi_firmware_management_protocol *this, + u8 image_index, + void *image, + efi_uintn_t *image_size) +{ + EFI_ENTRY("%p %d %p %p\n", this, image_index, image, image_size); + + return EFI_EXIT(EFI_UNSUPPORTED); +} + +/* Place holder; not supported */ +static +efi_status_t EFIAPI efi_firmware_check_image_unsupported( + struct efi_firmware_management_protocol *this, + u8 image_index, + const void *image, + efi_uintn_t *image_size, + u32 *image_updatable) +{ + EFI_ENTRY("%p %d %p %p %p\n", this, image_index, image, image_size, + image_updatable); + + return EFI_EXIT(EFI_UNSUPPORTED); +} + +/* Place holder; not supported */ +static +efi_status_t EFIAPI efi_firmware_get_package_info_unsupported( + struct efi_firmware_management_protocol *this, + u32 *package_version, + u16 **package_version_name, + u32 *package_version_name_maxlen, + u64 *attributes_supported, + u64 *attributes_setting) +{ + EFI_ENTRY("%p %p %p %p %p %p\n", this, package_version, + package_version_name, package_version_name_maxlen, + attributes_supported, attributes_setting); + + return EFI_EXIT(EFI_UNSUPPORTED); +} + +/* Place holder; not supported */ +static +efi_status_t EFIAPI efi_firmware_set_package_info_unsupported( + struct efi_firmware_management_protocol *this, + const void *image, + efi_uintn_t *image_size, + const void *vendor_code, + u32 package_version, + const u16 *package_version_name) +{ + EFI_ENTRY("%p %p %p %p %x %p\n", this, image, image_size, vendor_code, + package_version, package_version_name); + + return EFI_EXIT(EFI_UNSUPPORTED); +} /** * efi_get_dfu_info - return information about the current firmware image @@ -129,6 +179,18 @@ static efi_status_t efi_get_dfu_info( return EFI_SUCCESS; } +#ifdef CONFIG_EFI_CAPSULE_FIRMWARE_FIT +/* + * This FIRMWARE_MANAGEMENT_PROTOCOL driver provides a firmware update + * method with existing FIT image format, and handles + * - multiple regions of firmware via DFU + * but doesn't support + * - versioning of firmware image + * - package information + */ +const efi_guid_t efi_firmware_image_type_uboot_fit = + EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID; + /** * efi_firmware_fit_get_image_info - return information about the current * firmware image @@ -182,19 +244,6 @@ efi_status_t EFIAPI efi_firmware_fit_get_image_info( return EFI_EXIT(ret); } -/* Place holder; not supported */ -static -efi_status_t EFIAPI efi_firmware_get_image_unsupported( - struct efi_firmware_management_protocol *this, - u8 image_index, - void *image, - efi_uintn_t *image_size) -{ - EFI_ENTRY("%p %d %p %p\n", this, image_index, image, image_size); - - return EFI_EXIT(EFI_UNSUPPORTED); -} - /** * efi_firmware_fit_set_image - update the firmware image * @this: Protocol instance @@ -233,59 +282,122 @@ efi_status_t EFIAPI efi_firmware_fit_set_image( return EFI_EXIT(EFI_SUCCESS); } -/* Place holder; not supported */ -static -efi_status_t EFIAPI efi_firmware_check_image_unsupported( - struct efi_firmware_management_protocol *this, - u8 image_index, - const void *image, - efi_uintn_t *image_size, - u32 *image_updatable) -{ - EFI_ENTRY("%p %d %p %p %p\n", this, image_index, image, image_size, - image_updatable); +const struct efi_firmware_management_protocol efi_fmp_fit = { + .get_image_info = efi_firmware_fit_get_image_info, + .get_image = efi_firmware_get_image_unsupported, + .set_image = efi_firmware_fit_set_image, + .check_image = efi_firmware_check_image_unsupported, + .get_package_info = efi_firmware_get_package_info_unsupported, + .set_package_info = efi_firmware_set_package_info_unsupported, +}; +#endif /* CONFIG_EFI_CAPSULE_FIRMWARE_FIT */ - return EFI_EXIT(EFI_UNSUPPORTED); -} +#ifdef CONFIG_EFI_CAPSULE_FIRMWARE_RAW +/* + * This FIRMWARE_MANAGEMENT_PROTOCOL driver provides a firmware update + * method with raw data. + */ +const efi_guid_t efi_firmware_image_type_uboot_raw = + EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID; -/* Place holder; not supported */ +/** + * efi_firmware_raw_get_image_info - return information about the current + firmware image + * @this: Protocol instance + * @image_info_size: Size of @image_info + * @image_info: Image information + * @descriptor_version: Pointer to version number + * @descriptor_count: Pointer to number of descriptors + * @descriptor_size: Pointer to descriptor size + * package_version: Package version + * package_version_name: Package version's name + * + * Return information bout the current firmware image in @image_info. + * @image_info will consist of a number of descriptors. + * Each descriptor will be created based on "dfu_alt_info" variable. + * + * Return status code + */ static -efi_status_t EFIAPI efi_firmware_get_package_info_unsupported( +efi_status_t EFIAPI efi_firmware_raw_get_image_info( struct efi_firmware_management_protocol *this, + efi_uintn_t *image_info_size, + struct efi_firmware_image_descriptor *image_info, + u32 *descriptor_version, + u8 *descriptor_count, + efi_uintn_t *descriptor_size, u32 *package_version, - u16 **package_version_name, - u32 *package_version_name_maxlen, - u64 *attributes_supported, - u64 *attributes_setting) + u16 **package_version_name) { - EFI_ENTRY("%p %p %p %p %p %p\n", this, package_version, - package_version_name, package_version_name_maxlen, - attributes_supported, attributes_setting); + efi_status_t ret = EFI_SUCCESS; - return EFI_EXIT(EFI_UNSUPPORTED); + EFI_ENTRY("%p %p %p %p %p %p %p %p\n", this, + image_info_size, image_info, + descriptor_version, descriptor_count, descriptor_size, + package_version, package_version_name); + + if (!image_info_size) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + if (*image_info_size && + (!image_info || !descriptor_version || !descriptor_count || + !descriptor_size || !package_version || !package_version_name)) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + ret = efi_get_dfu_info(image_info_size, image_info, + descriptor_version, descriptor_count, + descriptor_size, + package_version, package_version_name, + &efi_firmware_image_type_uboot_raw); + + return EFI_EXIT(ret); } -/* Place holder; not supported */ +/** + * efi_firmware_raw_set_image - update the firmware image + * @this: Protocol instance + * @image_index: Image index number + * @image: New image + * @image_size: Size of new image + * @vendor_code: Vendor-specific update policy + * @progress: Function to report the progress of update + * @abort_reason: Pointer to string of abort reason + * + * Update the firmware to new image, using dfu. The new image should + * be a single raw image. + * @vendor_code, @progress and @abort_reason are not supported. + * + * Return: status code + */ static -efi_status_t EFIAPI efi_firmware_set_package_info_unsupported( +efi_status_t EFIAPI efi_firmware_raw_set_image( struct efi_firmware_management_protocol *this, + u8 image_index, const void *image, - efi_uintn_t *image_size, + efi_uintn_t image_size, const void *vendor_code, - u32 package_version, - const u16 *package_version_name) + efi_status_t (*progress)(efi_uintn_t completion), + u16 **abort_reason) { - EFI_ENTRY("%p %p %p %p %x %p\n", this, image, image_size, vendor_code, - package_version, package_version_name); + EFI_ENTRY("%p %d %p %ld %p %p %p\n", this, image_index, image, + image_size, vendor_code, progress, abort_reason); - return EFI_EXIT(EFI_UNSUPPORTED); + if (!image) + return EFI_EXIT(EFI_INVALID_PARAMETER); + + if (dfu_write_by_alt(image_index - 1, (void *)image, image_size, + NULL, NULL)) + return EFI_EXIT(EFI_DEVICE_ERROR); + + return EFI_EXIT(EFI_SUCCESS); } -const struct efi_firmware_management_protocol efi_fmp_fit = { - .get_image_info = efi_firmware_fit_get_image_info, +const struct efi_firmware_management_protocol efi_fmp_raw = { + .get_image_info = efi_firmware_raw_get_image_info, .get_image = efi_firmware_get_image_unsupported, - .set_image = efi_firmware_fit_set_image, + .set_image = efi_firmware_raw_set_image, .check_image = efi_firmware_check_image_unsupported, .get_package_info = efi_firmware_get_package_info_unsupported, .set_package_info = efi_firmware_set_package_info_unsupported, }; +#endif /* CONFIG_EFI_CAPSULE_FIRMWARE_RAW */ From patchwork Thu Oct 29 00:25:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319317 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp16085ilc; Wed, 28 Oct 2020 17:28:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx47i4qVkv7hALBSltqrRwRifuoUrsO9swePg/bhVEKyJiehFQlw9yFl4/W6f4I1CWOJ8qv X-Received: by 2002:aa7:df0c:: with SMTP id c12mr1556424edy.234.1603931324237; Wed, 28 Oct 2020 17:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931324; cv=none; d=google.com; s=arc-20160816; b=dad4/zcXJchiYnBejfJiCuCnsFn0Y7me2GHKsK/AyscSlAecCreK9Gns4Qh4JCWv9y qj5cJAVwyuEFhqodYnLvPg9gbO1d21nVw0SuVliSSLCxtwgydVxt4iJ00XB3qryYuWPi tEK/YkQ5XG61EvC1QuHnEU6Jg11mBw+TqYD6iFmecP+jvz9EtuRWvkgzKaW0/NmmZdu2 4gyIAFUvik1UGyefqS+UXaltHRlIAR+2gtDfdGmoPRRys1bOlkUP/qTMmVsttHeMvy4n poVG6ehlDyQWc/RJmh8PQFIBJrd1K6j7SgbGvr5lOdlFJ8ADgoaL9ACi+6BKeypbX6kn QifQ== 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=yqrxDc6ObQsRN+ZFvwOxoruSMgmdQxuJIuaGjJP56Ic=; b=WzTLzZdQHGIEoy5xOatRwezldiLaeqdZTE1Bb4RDA1sGxuEWQUyCgK0Us5LRyCvR8A E9ECzpL51LUyUxsKOXDX5M/SzdB8O0phHWHsYl6NuFmGeOo7JIuMmbO+uXON3Kq2jkyE dyjlifKadhaRpmJyIHxnA+kO5KMmPJU/I8vDqG9c1pXvSYAxL1BnKsYOfE/hoUUGFnT0 ocqM1+DlUNWlOMrRuH9LsXg2azIFR33/HvxdQZ+u7GXqkjRK/6XHGz6fNY5sYtU2UMD0 i78R3tMIZatF0YCEvQry4ufLSc468cFRSzRu+xtBe5H2eaSNp98ZhBAlYJaWo09cheXW z9/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UnfYiOe7; 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 c1si848432edq.563.2020.10.28.17.28.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:28:44 -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=UnfYiOe7; 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 828A28247D; Thu, 29 Oct 2020 01:26: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=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="UnfYiOe7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 26FD682526; Thu, 29 Oct 2020 01:26:40 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) (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 8B484824E1 for ; Thu, 29 Oct 2020 01:26:36 +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=takahiro.akashi@linaro.org Received: by mail-pl1-x633.google.com with SMTP id t6so444822plq.11 for ; Wed, 28 Oct 2020 17:26:36 -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=yqrxDc6ObQsRN+ZFvwOxoruSMgmdQxuJIuaGjJP56Ic=; b=UnfYiOe7V3laTuDEtsx7J+USrbgDJvKn2ciyp4ZgSiep/0oPcrYeLDzsr+CigoqVWr X4AJyYrcwGx5aTopodgF1W5y22g3njz0dE/HtHXxcviX0VsL9pI7+oKOW0WwNDGYVXbE 3Ixd+1H1NYSD2KfsM8K/9rPSQiCXvm/4kf2oFMehS0Fz+/Rrkb5z6T1U5EWudddGTd52 YyFMw3VCjBfJFsjh2KQlC42yAYB6QFj440opfBo0VbsCYB08HJJEao1r9OwazMNUpU3S SzJj7QeWizO8TmDYdGgcmWcFRH05SKLhEzO8qXCXXN8b6P7SRD4AbYtquEP9HImBBbky vveQ== 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=yqrxDc6ObQsRN+ZFvwOxoruSMgmdQxuJIuaGjJP56Ic=; b=KEx7FC/0D0JKSpUrJEvEcxIm74yY6j7/tJpnNT5LKwiqKzCz4hOCuHsYI1PtlFLnQF 2ZVdOffEUUq68QoqDdbatnaSFoDx7FuaNIFysftj9lsGWS8C4WIZSzMyG7EWN5DJixzW cT4CSfWbvrJDEM7zjbXJJ0EO9Fco96sz9UCYjLFdzFKVQXwAMiIh+6Gs/bbJ/oCJ/yw9 GgQ2L+cEa4nKVAZHjTfZe6HfnbdYc+KDmR91eLxoLCX7JjXSyPIeHgz4yMCwirpPvgTb mtA6jvDEMSh8n/mGc5eTadLnVj/9fGZ5593bmlQ2nTAuVYg9mwinqUxK5Gp+zriTJyun uKIQ== X-Gm-Message-State: AOAM531vL4HWeTuZFpFWazEKTnD3V16pmveoB/FAb85gMqW31QZw/2zu kbatEMWSPG6lmQ1IqW4vsINOsbBCySzZrw== X-Received: by 2002:a17:902:7c86:b029:d5:f680:f756 with SMTP id y6-20020a1709027c86b02900d5f680f756mr1743231pll.39.1603931195090; Wed, 28 Oct 2020 17:26:35 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:34 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 14/17] cmd: add "efidebug capsule" command Date: Thu, 29 Oct 2020 09:25:25 +0900 Message-Id: <20201029002528.34408-15-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean "efidebug capsule" is more or less a debugging utility. efidebug capsule update: invoke UpdateCapsule against data on memory efidebug capsule show: show a capsule header efidebug capsule result: dump a capsule result variable Signed-off-by: AKASHI Takahiro --- cmd/efidebug.c | 235 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) -- 2.28.0 diff --git a/cmd/efidebug.c b/cmd/efidebug.c index 5288b9920b4d..7d327c82681f 100644 --- a/cmd/efidebug.c +++ b/cmd/efidebug.c @@ -19,6 +19,228 @@ #include #define BS systab.boottime +#define RT systab.runtime + +#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT +/** + * do_efi_capsule_update() - process a capsule update + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "capsule update" sub-command. + * process a capsule update. + * + * efidebug capsule update [-v] + */ +static int do_efi_capsule_update(struct cmd_tbl *cmdtp, int flag, + int argc, char * const argv[]) +{ + struct efi_capsule_header *capsule; + int verbose = 0; + char *endp; + efi_status_t ret; + + if (argc != 2 && argc != 3) + return CMD_RET_USAGE; + + if (argc == 3) { + if (strcmp(argv[1], "-v")) + return CMD_RET_USAGE; + + verbose = 1; + argc--; + argv++; + } + + capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16); + if (endp == argv[1]) { + printf("Invalid address: %s", argv[1]); + return CMD_RET_FAILURE; + } + + if (verbose) { + printf("Capsule guid: %pUl\n", &capsule->capsule_guid); + printf("Capsule flags: 0x%x\n", capsule->flags); + printf("Capsule header size: 0x%x\n", capsule->header_size); + printf("Capsule image size: 0x%x\n", + capsule->capsule_image_size); + } + + ret = EFI_CALL(RT->update_capsule(&capsule, 1, (u64)NULL)); + if (ret) { + printf("Cannot handle a capsule at %p", capsule); + return CMD_RET_FAILURE; + } + + return CMD_RET_SUCCESS; +} + +/** + * do_efi_capsule_show() - show capsule information + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "capsule show" sub-command. + * show capsule information. + * + * efidebug capsule show + */ +static int do_efi_capsule_show(struct cmd_tbl *cmdtp, int flag, + int argc, char * const argv[]) +{ + struct efi_capsule_header *capsule; + char *endp; + + if (argc != 2) + return CMD_RET_USAGE; + + capsule = (typeof(capsule))simple_strtoul(argv[1], &endp, 16); + if (endp == argv[1]) { + printf("Invalid address: %s", argv[1]); + return CMD_RET_FAILURE; + } + + printf("Capsule guid: %pUl\n", &capsule->capsule_guid); + printf("Capsule flags: 0x%x\n", capsule->flags); + printf("Capsule header size: 0x%x\n", capsule->header_size); + printf("Capsule image size: 0x%x\n", + capsule->capsule_image_size); + + return CMD_RET_SUCCESS; +} + +/** + * do_efi_capsule_res() - show a capsule update result + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "capsule result" sub-command. + * show a capsule update result. + * If result number is not specified, CapsuleLast will be shown. + * + * efidebug capsule result [] + */ +static int do_efi_capsule_res(struct cmd_tbl *cmdtp, int flag, + int argc, char * const argv[]) +{ + int capsule_id; + char *endp; + char var_name[12]; + u16 var_name16[12], *p; + efi_guid_t guid; + struct efi_capsule_result_variable_header *result = NULL; + efi_uintn_t size; + efi_status_t ret; + + if (argc != 1 && argc != 2) + return CMD_RET_USAGE; + + guid = efi_guid_capsule_report; + if (argc == 1) { + size = sizeof(var_name16); + ret = EFI_CALL(RT->get_variable(L"CapsuleLast", &guid, NULL, + &size, var_name16)); + if (ret != EFI_SUCCESS) { + if (ret == EFI_NOT_FOUND) + printf("CapsuleLast doesn't exist\n"); + else + printf("Failed to get CapsuleLast\n"); + + return CMD_RET_FAILURE; + } + printf("CapsuleLast is %ls\n", var_name16); + } else { + argc--; + argv++; + + capsule_id = simple_strtoul(argv[0], &endp, 16); + if (capsule_id < 0 || capsule_id > 0xffff) + return CMD_RET_USAGE; + + sprintf(var_name, "Capsule%04X", capsule_id); + p = var_name16; + utf8_utf16_strncpy(&p, var_name, 9); + } + + size = 0; + ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, NULL)); + if (ret == EFI_BUFFER_TOO_SMALL) { + result = malloc(size); + ret = EFI_CALL(RT->get_variable(var_name16, &guid, NULL, &size, + result)); + if (ret != EFI_SUCCESS) { + free(result); + printf("Failed to get %ls\n", var_name16); + + return CMD_RET_FAILURE; + } + } + + printf("Result total size: 0x%x\n", result->variable_total_size); + printf("Capsule guid: %pUl\n", &result->capsule_guid); + printf("Time processed: %04d-%02d-%02d %02d:%02d:%02d\n", + result->capsule_processed.year, result->capsule_processed.month, + result->capsule_processed.day, result->capsule_processed.hour, + result->capsule_processed.minute, + result->capsule_processed.second); + printf("Capsule status: 0x%lx\n", result->capsule_status); + + free(result); + + return CMD_RET_SUCCESS; +} + +static struct cmd_tbl cmd_efidebug_capsule_sub[] = { + U_BOOT_CMD_MKENT(update, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_update, + "", ""), + U_BOOT_CMD_MKENT(show, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_show, + "", ""), + U_BOOT_CMD_MKENT(result, CONFIG_SYS_MAXARGS, 1, do_efi_capsule_res, + "", ""), +}; + +/** + * do_efi_capsule() - manage UEFI capsules + * + * @cmdtp: Command table + * @flag: Command flag + * @argc: Number of arguments + * @argv: Argument array + * Return: CMD_RET_SUCCESS on success, + * CMD_RET_USAGE or CMD_RET_RET_FAILURE on failure + * + * Implement efidebug "capsule" sub-command. + */ +static int do_efi_capsule(struct cmd_tbl *cmdtp, int flag, + int argc, char * const argv[]) +{ + struct cmd_tbl *cp; + + if (argc < 2) + return CMD_RET_USAGE; + + argc--; argv++; + + cp = find_cmd_tbl(argv[0], cmd_efidebug_capsule_sub, + ARRAY_SIZE(cmd_efidebug_capsule_sub)); + if (!cp) + return CMD_RET_USAGE; + + return cp->cmd(cmdtp, flag, argc, argv); +} +#endif /* CONFIG_EFI_HAVE_CAPSULE_SUPPORT */ /** * efi_get_device_handle_info() - get information of UEFI device @@ -1237,6 +1459,10 @@ static int do_efi_query_info(struct cmd_tbl *cmdtp, int flag, static struct cmd_tbl cmd_efidebug_sub[] = { U_BOOT_CMD_MKENT(boot, CONFIG_SYS_MAXARGS, 1, do_efi_boot_opt, "", ""), +#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT + U_BOOT_CMD_MKENT(capsule, CONFIG_SYS_MAXARGS, 1, do_efi_capsule, + "", ""), +#endif U_BOOT_CMD_MKENT(devices, CONFIG_SYS_MAXARGS, 1, do_efi_show_devices, "", ""), U_BOOT_CMD_MKENT(drivers, CONFIG_SYS_MAXARGS, 1, do_efi_show_drivers, @@ -1311,6 +1537,15 @@ static char efidebug_help_text[] = "efidebug boot order [ [ [ [...]]]]\n" " - set/show UEFI boot order\n" "\n" +#ifdef CONFIG_EFI_HAVE_CAPSULE_SUPPORT + "efidebug capsule update [-v] \n" + " - process a capsule\n" + "efidebug capsule show \n" + " - show capsule information\n" + "efidebug capsule result []\n" + " - show a capsule update result\n" + "\n" +#endif "efidebug devices\n" " - show UEFI devices\n" "efidebug drivers\n" From patchwork Thu Oct 29 00:25:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319318 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp16158ilc; Wed, 28 Oct 2020 17:28:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+EnUec4fACpZ+cPezAzy/QyWpWWY7yfPL8V6J0rAEJznLb5qwOEcdXcpiu9KhgzJEZIzM X-Received: by 2002:aa7:c68b:: with SMTP id n11mr1464440edq.340.1603931335102; Wed, 28 Oct 2020 17:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931335; cv=none; d=google.com; s=arc-20160816; b=YSTgHzj8eRO6+bHGpjgZfOfQQMBwBBJuP0XE0wb9KT0v3Njfbk8X7VuN5Qpfe7Ab5+ IqaJSzlVPKID/kjiWDliAuFMPygKT6V0TGeJEtQ8FakI62Z0MEC2Ij20TWo3eo8ByF+P O7sm/LgFk48/GQ0D8jqPua4zTyOheRQYesRnvvxuWgB2gpafZJn2ZDS/GYaWZqgXdgvj Db7oWTV16R0jloPHntgOo4wjwFIB0dvJtQTZsMvDw+aRFy3GGCRJfvh1FLatlNR8GVag jp/HULMe9k4rrkvNasLgmCHEgpItVNImkYr2dAb2PRC+7HqAaT/Sg/0/KZJdTKhDcrAb 84jw== 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=Z+/O5+FTtGlaZoI0+NvnfBAMCvpzihjClRuaSmYgNho=; b=b0LqCFjS2o9MwdoyOr6tR+qH30sU9OVol3uS2xPot2UIyeaU0iNTKfAvYJvJzwNxQp HGuvxJzfTKWMA38iKbkCKLPP6jJB6SpsGwm/+m++pZj2XrmyMcQ739X2F7/Xb14UrSid V06fgzwgahpzpm3CoBcQLykqTwM/QoFcw3hD9ujIGyWlCZVJhG2yNgQpYs90t4iFiKDr sZlD3rM2y8PduS9nEfr+VV1hfZdZJk4nPwnVEjYqDsPHvTJcZYwWqPT+GhaeQtbHK/Nz JfbaDMvdMENhAr2mL0s4YAN3Ig8c5IZEuD8FPGQI6AKv6w7SYmBnclIG1B6o6taMU9Kw 5yBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m+1kbbTe; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id t4si736226edr.514.2020.10.28.17.28.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:28:55 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m+1kbbTe; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 31A1E824EC; Thu, 29 Oct 2020 01:26:56 +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="m+1kbbTe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 54A0082521; Thu, 29 Oct 2020 01:26:43 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (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 7E2D182522 for ; Thu, 29 Oct 2020 01:26:39 +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=takahiro.akashi@linaro.org Received: by mail-pl1-x62c.google.com with SMTP id j5so458826plk.7 for ; Wed, 28 Oct 2020 17:26:39 -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=Z+/O5+FTtGlaZoI0+NvnfBAMCvpzihjClRuaSmYgNho=; b=m+1kbbTeD+hG6VYvZ9A936d3L7ZDzFIyztOpGPsXBGBEGejPcLcwkfag1mNYWqHShI eS/i06OlMefpLjUPypqRvJ+togWtkhtVNwyIYiDG9oGdk7IjOXPd3BUbF4NfnntGcFm0 jkz4nnwpUG0WSKe++d1tiih9Uj7e08j6wzzp5IItoozA/3KAThzm2PNTPgRDkCJ6NM5A +97zCykFlaAJGDcsTjZmGw2TmC/7cZyNcQc7ZofMd0d5ng4aodQRYzO3Shs2iN9sXYZI 1qA4qpouxZJskR43oMdgkTlPZX4GTcK/Xj9/mrFmur5xD8hRsU/QuAMltohF/0WnofY9 1W+A== 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=Z+/O5+FTtGlaZoI0+NvnfBAMCvpzihjClRuaSmYgNho=; b=UNx878Vdk1TpiaNRYeBMd8sP0Be8wJbM+A8AQcj19KyrADSyYhoTobr++otvP5a/XJ gYh5LAWWGqXYD6W6IQOxGvzgkENBs2uhZqld5zft5QWG1UMEMD0RgM1NInkZx3+1f0sm T4GmpNG0VT0huaVEwXdW4XaHC2MMV7l6m/vFM/0VgN96msggts7FFBw6Gn2HZQDLawl0 rf6OqZwIO2TT146Sjgkr3SZy8sDG3MxlaNu+8aesEYc0qiODiyEvlI8bXU3lnzpzxnMq ga/dcdldFlcn/ZdofUnKwfnBrH/tu9/N4WwcBwnIj2830Vhp4QSqo8UGOjsMVZ/xDqoQ wX3Q== X-Gm-Message-State: AOAM532/EZ01Sc/PUigzFWZNzhv9MG2qqPIe8wMTLzvS79e2cbcSGTcf /whmWMOCREtwXs+wuoTioffS+Q== X-Received: by 2002:a17:902:369:b029:d6:1d46:21dc with SMTP id 96-20020a1709020369b02900d61d4621dcmr1521206pld.56.1603931198018; Wed, 28 Oct 2020 17:26:38 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:37 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 15/17] tools: add mkeficapsule command for UEFI capsule update Date: Thu, 29 Oct 2020 09:25:26 +0900 Message-Id: <20201029002528.34408-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean This is a utility mainly for test purpose. mkeficapsule -f: create a test capsule file for FIT image firmware Having said that, you will be able to customize the code to fit your specific requirements for your platform. Signed-off-by: AKASHI Takahiro --- tools/Makefile | 2 + tools/mkeficapsule.c | 238 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+) create mode 100644 tools/mkeficapsule.c -- 2.28.0 diff --git a/tools/Makefile b/tools/Makefile index 51123fd92983..66d9376803e3 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -218,6 +218,8 @@ hostprogs-$(CONFIG_MIPS) += mips-relocs hostprogs-$(CONFIG_ASN1_COMPILER) += asn1_compiler HOSTCFLAGS_asn1_compiler.o = -idirafter $(srctree)/include +hostprogs-$(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) += mkeficapsule + # We build some files with extra pedantic flags to try to minimize things # that won't build on some weird host compiler -- though there are lots of # exceptions for files that aren't complaint. diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c new file mode 100644 index 000000000000..db95426457cc --- /dev/null +++ b/tools/mkeficapsule.c @@ -0,0 +1,238 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2018 Linaro Limited + * Author: AKASHI Takahiro + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef __u8 u8; +typedef __u16 u16; +typedef __u32 u32; +typedef __u64 u64; +typedef __s16 s16; +typedef __s32 s32; + +#define aligned_u64 __aligned_u64 + +#ifndef __packed +#define __packed __attribute__((packed)) +#endif + +#include +#include + +static const char *tool_name = "mkeficapsule"; + +efi_guid_t efi_guid_fm_capsule = EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID; +efi_guid_t efi_guid_image_type_uboot_fit = + EFI_FIRMWARE_IMAGE_TYPE_UBOOT_FIT_GUID; +efi_guid_t efi_guid_image_type_uboot_raw = + EFI_FIRMWARE_IMAGE_TYPE_UBOOT_RAW_GUID; + +static struct option options[] = { + {"fit", required_argument, NULL, 'f'}, + {"raw", required_argument, NULL, 'r'}, + {"index", required_argument, NULL, 'i'}, + {"instance", required_argument, NULL, 'I'}, + {"version", required_argument, NULL, 'v'}, + {"help", no_argument, NULL, 'h'}, + {NULL, 0, NULL, 0}, +}; + +static void print_usage(void) +{ + printf("Usage: %s [options] \n" + "Options:\n" + "\t--fit new FIT image file\n" + "\t--raw new raw image file\n" + "\t--index update image index\n" + "\t--instance update hardware instance\n" + "\t--version firmware version\n" + "\t--help print a help message\n", + tool_name); +} + +static int create_fwbin(char *path, char *bin, efi_guid_t *guid, + unsigned long version, unsigned long index, + unsigned long instance) +{ + struct efi_capsule_header header; + struct efi_firmware_management_capsule_header capsule; + struct efi_firmware_management_capsule_image_header image; + FILE *f, *g; + struct stat bin_stat; + u8 *data; + size_t size; + +#ifdef DEBUG + printf("For output: %s\n", path); + printf("\tbin: %s\n\ttype: %pUl\n" bin, guid); + printf("\tversion: %ld\n\tindex: %ld\n\tinstance: %ld\n", + version, index, instance); +#endif + + g = fopen(bin, "r"); + if (!g) { + printf("cannot open %s\n", bin); + return -1; + } + if (stat(bin, &bin_stat) < 0) { + printf("cannot determine the size of %s\n", bin); + goto err_1; + } + data = malloc(bin_stat.st_size); + if (!data) { + printf("cannot allocate memory: %lx\n", bin_stat.st_size); + goto err_1; + } + f = fopen(path, "w"); + if (!f) { + printf("cannot open %s\n", path); + goto err_2; + } + header.capsule_guid = efi_guid_fm_capsule; + header.header_size = sizeof(header); + header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET; /* TODO */ + header.capsule_image_size = sizeof(header) + + sizeof(capsule) + sizeof(u64) + + sizeof(image) + + bin_stat.st_size; + + size = fwrite(&header, 1, sizeof(header), f); + if (size < sizeof(header)) { + printf("write failed (%lx)\n", size); + goto err_3; + } + + capsule.version = 0x00000001; + capsule.embedded_driver_count = 0; + capsule.payload_item_count = 1; + capsule.item_offset_list[0] = sizeof(capsule) + sizeof(u64); + size = fwrite(&capsule, 1, sizeof(capsule) + sizeof(u64), f); + if (size < (sizeof(capsule) + sizeof(u64))) { + printf("write failed (%lx)\n", size); + goto err_3; + } + + image.version = version; + memcpy(&image.update_image_type_id, guid, sizeof(*guid)); + image.update_image_index = index; + image.update_image_size = bin_stat.st_size; + image.update_vendor_code_size = 0; /* none */ + image.update_hardware_instance = instance; + image.image_capsule_support = 0; + + size = fwrite(&image, 1, sizeof(image), f); + if (size < sizeof(image)) { + printf("write failed (%lx)\n", size); + goto err_3; + } + size = fread(data, 1, bin_stat.st_size, g); + if (size < bin_stat.st_size) { + printf("read failed (%lx)\n", size); + goto err_3; + } + size = fwrite(data, 1, bin_stat.st_size, f); + if (size < bin_stat.st_size) { + printf("write failed (%lx)\n", size); + goto err_3; + } + + fclose(f); + fclose(g); + free(data); + + return 0; + +err_3: + fclose(f); +err_2: + free(data); +err_1: + fclose(g); + + return -1; +} + +/* + * Usage: + * $ mkeficapsule -f + */ +int main(int argc, char **argv) +{ + char *file; + efi_guid_t *guid; + unsigned long index, instance, version; + int c, idx; + + file = NULL; + guid = NULL; + index = 0; + instance = 0; + version = 0; + for (;;) { + c = getopt_long(argc, argv, "f:r:i:I:v:h", options, &idx); + if (c == -1) + break; + + switch (c) { + case 'f': + if (file) { + printf("Image already specified\n"); + return -1; + } + file = optarg; + guid = &efi_guid_image_type_uboot_fit; + break; + case 'r': + if (file) { + printf("Image already specified\n"); + return -1; + } + file = optarg; + guid = &efi_guid_image_type_uboot_raw; + break; + case 'i': + index = strtoul(optarg, NULL, 0); + break; + case 'I': + instance = strtoul(optarg, NULL, 0); + break; + case 'v': + version = strtoul(optarg, NULL, 0); + break; + case 'h': + print_usage(); + return 0; + } + } + + /* need a output file */ + if (argc != optind + 1) { + print_usage(); + return -1; + } + + /* need a fit image file or raw image file */ + if (!file) { + print_usage(); + return -1; + } + + if (create_fwbin(argv[optind], file, guid, version, index, instance) + < 0) { + printf("Creating firmware capsule failed\n"); + return -1; + } + + return 0; +} From patchwork Thu Oct 29 00:25:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319319 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp16238ilc; Wed, 28 Oct 2020 17:29:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoR09dmEI+YiBBqmTJVIKdNzq4RPlA+RELYLrBeNL1XNNfKlejHgRwVbHjEuDLse/ezLTN X-Received: by 2002:a17:906:6d04:: with SMTP id m4mr1760482ejr.68.1603931344436; Wed, 28 Oct 2020 17:29:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931344; cv=none; d=google.com; s=arc-20160816; b=xfwVmFEYLw67VvXzkzkYAKcdYHGJrfCMJfboqFtkeGGzETcJYtsycmTRT2PSN9yRy/ HePwCQ8nPOXNf+l5RYn7Gk+Ru7XbUtKstQKobC0YbBpLg36cwIr69lAvcmvi2zNPi6x4 cJ1D0cgm3YL38ok2lT5Bo2vZzdaU5f6fl6aZYT7ZDL01nQPNbs6/l+UXYallEeuNO5St I/Wt4m9DUtn7SKGkzF1mwEVuokZMd6VKnwSChWNrUbplLjoE2MlxWct1Y6Xlf65XI1/E 9ZI+KqKTjo3Ak9aAZxEQ5KR5NO04H9zbDWoFfYaTXHp8fOC50LXi+CfIEIajTUCp24zs W5vQ== 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=GrUY44MWtP94MIIWPjtp35v3JdOgqmo3bkTAwU/kFBk=; b=g3f6/bn4HTLxpn6/qmQDDg0+ehB997iJfbW6hPqElgnJk8O7brRPfzVkgsael9KICc aErHGNXdvt3VOY0NbYE7Ttjg59k1fIYmXUOwNmcUKS6baBWk40obNG1woc8oYLG1hbAa /nvbfdXP1Wyk0mWLNheUE8BH22hIhYchrW9gvEcyZs9hdkYSpNbxGVYbyMZkXsQs2tPa M33A4IvJ/LbXtmhly3r4PQCjyL/o5euH5SEncl2m9x6SPpmFJCB69dpZHMfX6RHYY+Qq kG0KSBBAgYKMwrShJ34oszk66DpMSRVx7t/oKwNaESdIxIPhVcdbPHEG6lyE11xcIeFP n/4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AQI5tMtV; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id b5si620589eju.428.2020.10.28.17.29.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:29:04 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AQI5tMtV; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 71A9282540; Thu, 29 Oct 2020 01:26:57 +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="AQI5tMtV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9959A82539; Thu, 29 Oct 2020 01:26:46 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (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 C523D82535 for ; Thu, 29 Oct 2020 01:26:42 +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=takahiro.akashi@linaro.org Received: by mail-pg1-x535.google.com with SMTP id o7so903648pgv.6 for ; Wed, 28 Oct 2020 17:26:42 -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=GrUY44MWtP94MIIWPjtp35v3JdOgqmo3bkTAwU/kFBk=; b=AQI5tMtVUz2b6AV04rmtRKlT7G1OOvpamgIoIR1yVi+jruuNW2nxpZ3pW0m5KdpF+B ZFW2utEkqaJU/ApCOMkwhdEKzjOTa7qZVU61/99iweaTnAcIKtgNPBA0WsnzK8V3ZrIF Tgg3eXUaTtwR3GkaobwaLJQ0i9Xbci2pFjzKhIUlqkdGuHHox5iXLpaAP9YIebyvTdzm WX7An72eT0ox7jPVj9VHc3HdQoum+SnlxTok1d/dw6Vq4Wl5TJDAXsD8MTjMrMlIN2hM M6vFpnCrhF0UjrN1mmKsumLZzzdn9R0it7AtEnMrfuZvObuyHxjLQgTY70Q10+TvKyrT 5JEA== 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=GrUY44MWtP94MIIWPjtp35v3JdOgqmo3bkTAwU/kFBk=; b=E968XtUVV445ySEi6UWYFhqaS601l75UaPKTCRLy+RlhEHgZ6MjSAbZNlGVU+Oybqp Q49o7g9vKn2Vq6GYkHA2O83aXZ7JDJDHRkszNSmDhcCqbNe8ZEbYFfTUyGsUgiR+wcRs JwUrD+oNAWQ6RuU5+dOUYA9yS22h8vku07OU1Kdm17ouneoV4iHoIPsjzkW2t5nGf6Yi ernxlsBxuNqoE47BGSyhIqkWB4x+DyUUuuREUfp0a9l7uPox3N/eDhksOK5uy1eqp74Y il7u8Cf4VuEK61l2CSAGrfT4Lo09HrVQCmuK0xHETwQaMM0iTnirBRyIGtyPS1qu2DTq Sk+A== X-Gm-Message-State: AOAM530Ho+TQyCzYra9vhC4xJxgLEpdJwrbY2Ju0ozz107MvWd03vNrf /VZnP7h1xmFxcEMeAeFRBo1RSg== X-Received: by 2002:aa7:990b:0:b029:155:d228:8cad with SMTP id z11-20020aa7990b0000b0290155d2288cadmr1468522pff.29.1603931201241; Wed, 28 Oct 2020 17:26:41 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:40 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 16/17] test/py: efi_capsule: test for FIT image capsule Date: Thu, 29 Oct 2020 09:25:27 +0900 Message-Id: <20201029002528.34408-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean The test can run on sandbox build and it attempts to execute a firmware update via a capsule-on-disk, using a FIT image capsule, CONFIG_EFI_CAPSULE_FIT. To run this test successfully, you need configure U-Boot specifically; See test_capsule_firmware.py for requirements, and hence it won't run on Travis CI, at least, for now. Signed-off-by: AKASHI Takahiro --- test/py/tests/test_efi_capsule/conftest.py | 69 +++++++ test/py/tests/test_efi_capsule/defs.py | 12 ++ .../test_efi_capsule/test_capsule_firmware.py | 178 ++++++++++++++++++ .../tests/test_efi_capsule/uboot_bin_env.its | 36 ++++ tools/mkeficapsule.c | 3 +- 5 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 test/py/tests/test_efi_capsule/conftest.py create mode 100644 test/py/tests/test_efi_capsule/defs.py create mode 100644 test/py/tests/test_efi_capsule/test_capsule_firmware.py create mode 100644 test/py/tests/test_efi_capsule/uboot_bin_env.its -- 2.28.0 diff --git a/test/py/tests/test_efi_capsule/conftest.py b/test/py/tests/test_efi_capsule/conftest.py new file mode 100644 index 000000000000..4e7c36f04ba5 --- /dev/null +++ b/test/py/tests/test_efi_capsule/conftest.py @@ -0,0 +1,69 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2020, Linaro Limited +# Author: AKASHI Takahiro + +import os +import os.path +import re +from subprocess import call, check_call, check_output, CalledProcessError +import pytest +from defs import * + +# +# Fixture for UEFI secure boot test +# + + +@pytest.fixture(scope='session') +def efi_capsule_data(request, u_boot_config): + """Set up a file system to be used in UEFI capsule test. + + Args: + request: Pytest request object. + u_boot_config: U-boot configuration. + + Return: + A path to disk image to be used for testing + """ + mnt_point = u_boot_config.persistent_data_dir + '/test_efi_capsule' + data_dir = mnt_point + CAPSULE_DATA_DIR + install_dir = mnt_point + CAPSULE_INSTALL_DIR + image_path = u_boot_config.persistent_data_dir + '/test_efi_capsule.img' + + try: + # Create a target device + check_call('dd if=/dev/zero of=./spi.bin bs=1MiB count=16', shell=True) + + check_call('rm -rf %s' % mnt_point, shell=True) + check_call('mkdir -p %s' % data_dir, shell=True) + check_call('mkdir -p %s' % install_dir, shell=True) + + # Create capsule files + # two regions: one for u-boot.bin and the other for u-boot.env + check_call('cd %s; echo -n u-boot:Old > u-boot.bin.old; echo -n u-boot:New > u-boot.bin.new; echo -n u-boot-env:Old -> u-boot.env.old; echo -n u-boot-env:New > u-boot.env.new' % data_dir, + shell=True) + check_call('sed -e \"s?BINFILE1?u-boot.bin.new?\" -e \"s?BINFILE2?u-boot.env.new?\" %s/test/py/tests/test_efi_capsule/uboot_bin_env.its > %s/uboot_bin_env.its' % + (u_boot_config.source_dir, data_dir), + shell=True) + check_call('cd %s; %s/tools/mkimage -f uboot_bin_env.its uboot_bin_env.itb' % + (data_dir, u_boot_config.build_dir), + shell=True) + check_call('cd %s; %s/tools/mkeficapsule --fit uboot_bin_env.itb --version 1 --index 1 Test01' % + (data_dir, u_boot_config.build_dir), + shell=True) + + # Create a disk image with EFI system partition + check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' % + (mnt_point, image_path), shell=True) + check_call('sgdisk %s -A 1:set:0 -t 1:C12A7328-F81F-11D2-BA4B-00A0C93EC93B' % + image_path, shell=True) + + except CalledProcessError as exception: + pytest.skip('Setup failed: %s' % exception.cmd) + return + else: + yield image_path + finally: + call('rm -rf %s' % mnt_point, shell=True) + call('rm -f %s' % image_path, shell=True) + call('rm -f ./spi.bin', shell=True) diff --git a/test/py/tests/test_efi_capsule/defs.py b/test/py/tests/test_efi_capsule/defs.py new file mode 100644 index 000000000000..2c5b0ee49beb --- /dev/null +++ b/test/py/tests/test_efi_capsule/defs.py @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0+ + +# Size in MiB +EFI_BOOTDEV_IMAGE_SIZE = 16 +EFI_BOOTDEV_PART_SIZE = 8 + +# Owner guid +GUID = '11111111-2222-3333-4444-123456789abc' + +# Directories +CAPSULE_DATA_DIR = '/EFI/CapsuleTestData' +CAPSULE_INSTALL_DIR = '/EFI/UpdateCapsule' diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware.py b/test/py/tests/test_efi_capsule/test_capsule_firmware.py new file mode 100644 index 000000000000..ab7c2a7d6bea --- /dev/null +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware.py @@ -0,0 +1,178 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Copyright (c) 2020, Linaro Limited +# Author: AKASHI Takahiro +# +# U-Boot UEFI: Firmware Update Test + +""" +This test verifies capsule-on-disk firmware update +""" + +from subprocess import check_call, check_output, CalledProcessError +import pytest +from defs import * + + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('efi_capsule_firmware_fit') +@pytest.mark.buildconfigspec('efi_capsule_on_disk') +@pytest.mark.buildconfigspec('dfu') +@pytest.mark.buildconfigspec('dfu_sf') +@pytest.mark.buildconfigspec('cmd_efidebug') +@pytest.mark.buildconfigspec('cmd_fat') +@pytest.mark.buildconfigspec('cmd_memory') +@pytest.mark.buildconfigspec('cmd_nvedit_efi') +@pytest.mark.buildconfigspec('cmd_sf') +@pytest.mark.slow +class TestEfiCapsuleFirmwareFit(object): + def test_efi_capsule_fw1( + self, u_boot_config, u_boot_console, efi_capsule_data): + """ + Test Case 1 - Update U-Boot and U-Boot environment on SPI Flash + but with OsIndications unset + No update should happen + 0x100000-0x150000: U-Boot binary (but dummy) + 0x150000-0x200000: U-Boot environment (but dummy) + """ + disk_img = efi_capsule_data + with u_boot_console.log.section('Test Case 1-a, before reboot'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'efidebug boot add 1 TEST host 0:1 /helloworld.efi ""', + 'efidebug boot order 1', + 'env set -e OsIndications', + 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"', + 'env save']) + + # initialize contents + output = u_boot_console.run_command_list([ + 'sf probe 0:0', + 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR, + 'sf write 4000000 100000 10', + 'sf read 5000000 100000 10', + 'md.b 5000000 10']) + assert 'Old' in ''.join(output) + output = u_boot_console.run_command_list([ + 'sf probe 0:0', + 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR, + 'sf write 4000000 150000 10', + 'sf read 5000000 150000 10', + 'md.b 5000000 10']) + assert 'Old' in ''.join(output) + + # place a capsule file + output = u_boot_console.run_command_list([ + 'fatload host 0:1 4000000 %s/Test01' % CAPSULE_DATA_DIR, + 'fatwrite host 0:1 4000000 %s/Test01 $filesize' % CAPSULE_INSTALL_DIR, + 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR]) + assert 'Test01' in ''.join(output) + + # reboot + u_boot_console.restart_uboot() + + capsule_early = u_boot_config.buildconfig.get( + 'config_efi_capsule_on_disk_early') + with u_boot_console.log.section('Test Case 1-b, after reboot'): + if not capsule_early: + # make sure that dfu_alt_info exists even persistent variables + # are not available. + output = u_boot_console.run_command_list([ + 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"', + 'host bind 0 %s' % disk_img, + 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR]) + assert 'Test01' in ''.join(output) + + # need to run uefi command to initiate capsule handling + output = u_boot_console.run_command( + 'env print -e -all Capsule0000') + + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR]) + assert 'Test01' in ''.join(output) + + output = u_boot_console.run_command_list([ + 'sf probe 0:0', + 'sf read 4000000 100000 10', + 'md.b 4000000 10']) + assert 'u-boot:Old' in ''.join(output) + + output = u_boot_console.run_command_list([ + 'sf read 4000000 150000 10', + 'md.b 4000000 10']) + assert 'u-boot-env:Old' in ''.join(output) + + def test_efi_capsule_fw2( + self, u_boot_config, u_boot_console, efi_capsule_data): + """ + Test Case 2 - Update U-Boot and U-Boot environment on SPI Flash + 0x100000-0x150000: U-Boot binary (but dummy) + 0x150000-0x200000: U-Boot environment (but dummy) + """ + disk_img = efi_capsule_data + with u_boot_console.log.section('Test Case 2-a, before reboot'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'efidebug boot add 1 TEST host 0:1 /helloworld.efi ""', + 'efidebug boot order 1', + 'env set -e -nv -bs -rt OsIndications =0x0000000000000004', + 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"', + 'env save']) + + # initialize contents + output = u_boot_console.run_command_list([ + 'sf probe 0:0', + 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR, + 'sf write 4000000 100000 10', + 'sf read 5000000 100000 10', + 'md.b 5000000 10']) + assert 'Old' in ''.join(output) + output = u_boot_console.run_command_list([ + 'sf probe 0:0', + 'fatload host 0:1 4000000 %s/u-boot.env.old' % CAPSULE_DATA_DIR, + 'sf write 4000000 150000 10', + 'sf read 5000000 150000 10', + 'md.b 5000000 10']) + assert 'Old' in ''.join(output) + + # place a capsule file + output = u_boot_console.run_command_list([ + 'fatload host 0:1 4000000 %s/Test01' % CAPSULE_DATA_DIR, + 'fatwrite host 0:1 4000000 %s/Test01 $filesize' % CAPSULE_INSTALL_DIR, + 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR]) + assert 'Test01' in ''.join(output) + + # reboot + u_boot_console.restart_uboot() + + capsule_early = u_boot_config.buildconfig.get( + 'config_efi_capsule_on_disk_early') + with u_boot_console.log.section('Test Case 2-b, after reboot'): + if not capsule_early: + # make sure that dfu_alt_info exists even persistent variables + # are not available. + output = u_boot_console.run_command_list([ + 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"', + 'host bind 0 %s' % disk_img, + 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR]) + assert 'Test01' in ''.join(output) + + # need to run uefi command to initiate capsule handling + output = u_boot_console.run_command( + 'env print -e -all Capsule0000') + + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR]) + assert 'Test01' not in ''.join(output) + + output = u_boot_console.run_command_list([ + 'sf probe 0:0', + 'sf read 4000000 100000 10', + 'md.b 4000000 10']) + assert 'u-boot:New' in ''.join(output) + + output = u_boot_console.run_command_list([ + 'sf read 4000000 150000 10', + 'md.b 4000000 10']) + assert 'u-boot-env:New' in ''.join(output) diff --git a/test/py/tests/test_efi_capsule/uboot_bin_env.its b/test/py/tests/test_efi_capsule/uboot_bin_env.its new file mode 100644 index 000000000000..31e2f8049f9a --- /dev/null +++ b/test/py/tests/test_efi_capsule/uboot_bin_env.its @@ -0,0 +1,36 @@ +/* + * Automatic software update for U-Boot + * Make sure the flashing addresses ('load' prop) is correct for your board! + */ + +/dts-v1/; + +/ { + description = "Automatic U-Boot environment update"; + #address-cells = <2>; + + images { + u-boot-bin@100000 { + description = "U-Boot binary on SPI Flash"; + data = /incbin/("BINFILE1"); + compression = "none"; + type = "firmware"; + arch = "sandbox"; + load = <0>; + hash-1 { + algo = "sha1"; + }; + }; + u-boot-env@150000 { + description = "U-Boot environment on SPI Flash"; + data = /incbin/("BINFILE2"); + compression = "none"; + type = "firmware"; + arch = "sandbox"; + load = <0>; + hash-1 { + algo = "sha1"; + }; + }; + }; +}; diff --git a/tools/mkeficapsule.c b/tools/mkeficapsule.c index db95426457cc..45e27d74a5e9 100644 --- a/tools/mkeficapsule.c +++ b/tools/mkeficapsule.c @@ -101,7 +101,8 @@ static int create_fwbin(char *path, char *bin, efi_guid_t *guid, } header.capsule_guid = efi_guid_fm_capsule; header.header_size = sizeof(header); - header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET; /* TODO */ + /* TODO: The current implementation ignores flags */ + header.flags = CAPSULE_FLAGS_PERSIST_ACROSS_RESET; header.capsule_image_size = sizeof(header) + sizeof(capsule) + sizeof(u64) + sizeof(image) From patchwork Thu Oct 29 00:25:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 319320 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp16331ilc; Wed, 28 Oct 2020 17:29:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjDPy8mASk+jPvmpAvgSqVFRJr8rHFglJoF4tv1LMD+cW27ZebXiXwlX7PjyC+waKotP0K X-Received: by 2002:a50:ef0a:: with SMTP id m10mr1549784eds.116.1603931354913; Wed, 28 Oct 2020 17:29:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603931354; cv=none; d=google.com; s=arc-20160816; b=DMCeNccHimHtXbSPxXUcEve2QdQs9DFoZ6cobeVwi5hm+zn4jtFAJZFqaqYA79oGna 2M06m2TaEWvdyxPpo9YdnSq+g+ZrsGqYoiLBG8fhFX1ACwNGXhNWOP6ENd1iN80pB2iY +8Nb5LENRokPha0axw6aTXFCoZj4sZswIg7Em2FgQyt69BtKB5Hwu/RfVtdDdq1t4sXD p0vjmS+T/1iimzKFGX/uYaCRRv2YyPBmthgbwwYOZ27ufJifH0NATzjvmaXB9ODZuqW9 QGbym4jNWgpkxySLIq3SVfHkMnApPnYrMoQfhWpyP4Gdf0NgIxlJA5RgACHhqmS5C0Hr njAA== 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=vOZL7HMoUBm2QgX/veSjMfzSO/qPFQVDFF4KFNeP7Lw=; b=IDmQTys8sdVEHlqxweEVBVg/nsq8EsCJUw97eY3qBWU6BDpZl7j3pvMPX5hZU/zToW xC6mA1R4v2G3LEnWeciwLK817wHTWt1G2hOIZGHoPLcLIqe7lGSnOJhxdNH2dDPv6Rat hyokqGEbKp5CjRpj+0w/SBOoRZbF+vJoqxk1JmT1TFUGKaeE33QGLkuI2bhtUEDZDdbY FRnJ1dT07S7G4nCv8e2H+Ut/BvD+i2isrUmcuJrdak+nrdDZTyTYaOY1qa7I7UNNM9+l B6xN750zXdjlzZKaGnlj1RC2HSdWU1k7dIPGDkPkcXl2Y1OyfxQ+/oTuWsiTTT2RnwMV oBYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p1CrF+Q9; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id b20si650872ejz.383.2020.10.28.17.29.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:29:14 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p1CrF+Q9; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 A593382545; Thu, 29 Oct 2020 01:26:58 +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="p1CrF+Q9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EB4588253E; Thu, 29 Oct 2020 01:26:48 +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,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) (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 AE2D2823F3 for ; Thu, 29 Oct 2020 01:26:45 +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=takahiro.akashi@linaro.org Received: by mail-pg1-x52f.google.com with SMTP id o3so882410pgr.11 for ; Wed, 28 Oct 2020 17:26:45 -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=vOZL7HMoUBm2QgX/veSjMfzSO/qPFQVDFF4KFNeP7Lw=; b=p1CrF+Q94m61bO/1wyRjsGU9S3xphezOQXjmKOUlUrTnWBSbmx0DLd6iEMx9UIhmMG zP0k8h5syjxpOmKWHVOewYkR+yQQ2rRiP2qrPOclLD3j66+VOqcNBYBmW4NVLgnY10ej 1/fOBSZAIjZ5hiOov/RQTR4jW8g7n32HXzBbgnIX5mrClmorfh1Wk8vD2JSqxMhTKnq3 5/s5ysX0auIg7uTc4n+nuF5pnv5NUvcgKegVqq4vTJF6FZiFncFcNLRnzYwd7RyBdjxa jG+xt9vjcT9pUcgrUn7E3mRgs0rthUQri5XXo+dsUfxtnYsputWgU6IC+E0T+IPggN9A 0PqQ== 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=vOZL7HMoUBm2QgX/veSjMfzSO/qPFQVDFF4KFNeP7Lw=; b=H+YdxI29itT8b01z08/CSv7Y2u8iEypY0+zUi8mte3t4S6dYWrTMiEIj/wazsnwOyL QcWjXkxD92RO1qH8kku3SVj1dgJwEOa3GqAMza09G5+rS43E9ztYor2W88Ol8GjqatyC 7t087zMhoqI0NZD0gJUKvPpz6NCST865MGeTgy/6IdQEcM6LBsAmG4c+zw6UPL7Q+R3X SfSsJLokuQqmcjlgGoO2TkBl14YTqZ68a3rYLETRNEwvLxc107T4JKPfAhfxCvUzLekt +n7Vf2bq3ZeZ2MXDwZmeIPNcp31hwFKIIAJyQb55RI01VVVHXS88Z2aIo+RdKWkZsCQJ EBpg== X-Gm-Message-State: AOAM530x/HJMwYtrR7l2DtBQf0JWbqjKpUBYSxFfW2ddi0Sis7T0c0y0 s684H8Miro03P4zfxJQvCKt6jQ== X-Received: by 2002:a17:90a:f184:: with SMTP id bv4mr1395431pjb.1.1603931204270; Wed, 28 Oct 2020 17:26:44 -0700 (PDT) Received: from localhost.localdomain (p784a66b9.tkyea130.ap.so-net.ne.jp. [120.74.102.185]) by smtp.gmail.com with ESMTPSA id s22sm731502pfu.119.2020.10.28.17.26.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 17:26:43 -0700 (PDT) From: AKASHI Takahiro To: lukma@denx.de, trini@konsulko.com, xypron.glpk@gmx.de, agraf@csgraf.de Cc: sughosh.ganu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RESEND PATCH v6 17/17] test/py: efi_capsule: test for raw image capsule Date: Thu, 29 Oct 2020 09:25:28 +0900 Message-Id: <20201029002528.34408-18-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201029002528.34408-1-takahiro.akashi@linaro.org> References: <20201029002528.34408-1-takahiro.akashi@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.3 at phobos.denx.de X-Virus-Status: Clean The test can run on sandbox build and it attempts to execute a firmware update via a capsule-on-disk, using a raw image capsule, CONFIG_EFI_CAPSULE_RAW. To run this test successfully, you need configure U-Boot specifically; See test_capsule_firmware.py for requirements, and hence it won't run on Travis CI, at least, for now. Signed-off-by: AKASHI Takahiro --- test/py/tests/test_efi_capsule/conftest.py | 3 + .../test_efi_capsule/test_capsule_firmware.py | 63 +++++++++++++++++++ 2 files changed, 66 insertions(+) -- 2.28.0 diff --git a/test/py/tests/test_efi_capsule/conftest.py b/test/py/tests/test_efi_capsule/conftest.py index 4e7c36f04ba5..4544a24d5351 100644 --- a/test/py/tests/test_efi_capsule/conftest.py +++ b/test/py/tests/test_efi_capsule/conftest.py @@ -51,6 +51,9 @@ def efi_capsule_data(request, u_boot_config): check_call('cd %s; %s/tools/mkeficapsule --fit uboot_bin_env.itb --version 1 --index 1 Test01' % (data_dir, u_boot_config.build_dir), shell=True) + check_call('cd %s; %s/tools/mkeficapsule --raw u-boot.bin.new --version 1 --index 1 Test02' % + (data_dir, u_boot_config.build_dir), + shell=True) # Create a disk image with EFI system partition check_call('virt-make-fs --partition=gpt --size=+1M --type=vfat %s %s' % diff --git a/test/py/tests/test_efi_capsule/test_capsule_firmware.py b/test/py/tests/test_efi_capsule/test_capsule_firmware.py index ab7c2a7d6bea..c9b180ac65e8 100644 --- a/test/py/tests/test_efi_capsule/test_capsule_firmware.py +++ b/test/py/tests/test_efi_capsule/test_capsule_firmware.py @@ -15,6 +15,7 @@ from defs import * @pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('efi_capsule_firmware_fit') +@pytest.mark.buildconfigspec('efi_capsule_firmware_raw') @pytest.mark.buildconfigspec('efi_capsule_on_disk') @pytest.mark.buildconfigspec('dfu') @pytest.mark.buildconfigspec('dfu_sf') @@ -176,3 +177,65 @@ class TestEfiCapsuleFirmwareFit(object): 'sf read 4000000 150000 10', 'md.b 4000000 10']) assert 'u-boot-env:New' in ''.join(output) + + def test_efi_capsule_fw3( + self, u_boot_config, u_boot_console, efi_capsule_data): + """ + Test Case 3 - Update U-Boot on SPI Flash, raw image format + 0x100000-0x150000: U-Boot binary (but dummy) + """ + disk_img = efi_capsule_data + with u_boot_console.log.section('Test Case 3-a, before reboot'): + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'efidebug boot add 1 TEST host 0:1 /helloworld.efi ""', + 'efidebug boot order 1', + 'env set -e -nv -bs -rt OsIndications =0x0000000000000004', + 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"', + 'env save']) + + # initialize content + output = u_boot_console.run_command_list([ + 'sf probe 0:0', + 'fatload host 0:1 4000000 %s/u-boot.bin.old' % CAPSULE_DATA_DIR, + 'sf write 4000000 100000 10', + 'sf read 5000000 100000 10', + 'md.b 5000000 10']) + assert 'Old' in ''.join(output) + + # place a capsule file + output = u_boot_console.run_command_list([ + 'fatload host 0:1 4000000 %s/Test02' % CAPSULE_DATA_DIR, + 'fatwrite host 0:1 4000000 %s/Test02 $filesize' % CAPSULE_INSTALL_DIR, + 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR]) + assert 'Test02' in ''.join(output) + + # reboot + u_boot_console.restart_uboot() + + capsule_early = u_boot_config.buildconfig.get( + 'config_efi_capsule_on_disk_early') + with u_boot_console.log.section('Test Case 3-b, after reboot'): + if not capsule_early: + # make sure that dfu_alt_info exists even persistent variables + # are not available. + output = u_boot_console.run_command_list([ + 'env set dfu_alt_info "sf 0:0=u-boot-bin raw 0x100000 0x50000;u-boot-env raw 0x150000 0x200000"', + 'host bind 0 %s' % disk_img, + 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR]) + assert 'Test02' in ''.join(output) + + # need to run uefi command to initiate capsule handling + output = u_boot_console.run_command( + 'env print -e -all Capsule0000') + + output = u_boot_console.run_command_list([ + 'host bind 0 %s' % disk_img, + 'fatls host 0:1 %s' % CAPSULE_INSTALL_DIR]) + assert 'Test02' not in ''.join(output) + + output = u_boot_console.run_command_list([ + 'sf probe 0:0', + 'sf read 4000000 100000 10', + 'md.b 4000000 10']) + assert 'u-boot:New' in ''.join(output)