From patchwork Wed Jul 22 06:05:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 246958 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp254583ilg; Tue, 21 Jul 2020 23:08:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXO6HTItpAL9SWZ706X3Lt+TdwmgMiu0zXrwvcNg6MrERkTaM/nWWib+iucLK4A3dFp/8W X-Received: by 2002:a17:906:1b45:: with SMTP id p5mr28323469ejg.51.1595398111746; Tue, 21 Jul 2020 23:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595398111; cv=none; d=google.com; s=arc-20160816; b=cTp0Hk+6ty5ukmHYw/yWSs6Du9Rku2/IzibVPBlAdCaozcTtKgz59yM6mCNT6TVsS3 GiliW/ngz7OjUNSJzYCOahP7VX/J2WLANCYM0BW+4vughrA8EKCxzw14RUxUvqWP+3nx KD2wG/G/YH/4PzmZ+QPhg8AogZfiFDirduABF2BfpYSXCnrKyDYgfgQKniAWtLblBG9S wCJOmyqensdvrXU8yqSAyYWfJWNWuA/AwzguzYzEvk0qmeR7eWxvC1sRigAkd6Kazqq4 15BiibwXCyW/I95H86YMoymt8lpqsAZHJ61nrBw/Qbcf9uACIpWo2R5jdpbbf9JVjMni Iy9w== 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=57/1ebt39P1NW0BLV3wVPGNCHF586iwQzxt3Lki1wcw=; b=0sqY4W1I8j5CtSxtM8ce3YQmPt2Xwpk3zrgEBgBuZFC3WSeID7Pkm76289Ge8JUeiN VfHSrAfjjGI5z4BzRGKHq7FrRejPrblf36DuxETIcXJiUlC/LtiripU53qcpFNY5W8EP 47UE1h8nIF6kdwrcQAwG/yRMpPEvS0xQ+vkTgIMG+2nHZaxuaJZC7SldIyc7tEbdp1Q4 JXmaVIa2NWFVq6C5dzfBGL6uqlnhbpJGN9TWpO53jangM0aCcQZI95e4T5ds2s2q/z4k 2UFLxoXbXffPFE7M7YFy25lEt0yjlM1vWvKPjyMverMEfyCfiYVZemU0/5naQ+CekPXX c5GQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CwvAg4vP; 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 bf28si14520056edb.312.2020.07.21.23.08.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 23:08:31 -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=CwvAg4vP; 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 5FE3D8216F; Wed, 22 Jul 2020 08:07:11 +0200 (CEST) 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="CwvAg4vP"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2A991820C6; Wed, 22 Jul 2020 08:06:52 +0200 (CEST) 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-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (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 ADA0981F14 for ; Wed, 22 Jul 2020 08:06:48 +0200 (CEST) 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-x442.google.com with SMTP id j20so618322pfe.5 for ; Tue, 21 Jul 2020 23:06:48 -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=57/1ebt39P1NW0BLV3wVPGNCHF586iwQzxt3Lki1wcw=; b=CwvAg4vPgQpYd26Ity+AdAdg+9UMFHVZzFjTvH0asqmF/GLAaPoiGAV5O6V1UYH2F5 enfAEpC/+Hgx4WNxu2IMhqTIMPO9Sp8P4ehydB2l86T9dAOL6TUbERA1WynMJoJ2GTTF xb36uzs4zVFQ8iRkIqKOIhLJTvwxtZTado+6YaAXOFydyACxYPb34tyLSP2TNadFTmiM FC9PbiExiTzm4cUV25LNta1+vcocDMj4TPIeBqyBI7Hx/MNNRjlp9HFXa5okpcHABHlC zaEh69qAhQiyLJ6ZixnRF7DIHXcBjzAESwB4NZW+rPTpZZ7wIAY4kuuyoSrNF5Va/6Nm jHYA== 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=57/1ebt39P1NW0BLV3wVPGNCHF586iwQzxt3Lki1wcw=; b=Z+2UNqOMC998uFEX++7nVSGfCgGN2nrcqiiKtb7hk+GfdPlvu2jVbIJAcRZqzfklp3 dJCQ/NRyJaiIAvkyWWa87yLFJUEMJPQMs0oaqYwt5LE4qg/sh2Owo/KzaBT/YTiv+UER AgEwMdkHgxFP54+xYxtfkKudt6nTOyvZvyt2L+cA9UApCca0fI6KtTcub5psljDFGnle yqbbG0rAg1KA+j1o1NegxbceP61Rh71LrNuvafW1uIuZh000F8bw1YNwEibbDqY1i4/2 eK25yIIqT/ARTIGVGPgZXCr2oIat7u6GMEAEoM9XkfEG2rUtcCUtc9WGpyVJ7jkAjjqT hfRg== X-Gm-Message-State: AOAM532nlo8UKhR2czTI9F/uCvBG6ZyfKZ9t4HJJ3u3x63IoTNRWhsPr mW0RqNBKRrYYHnse6MdPRIAdfhTgZ0Ho6g== X-Received: by 2002:aa7:842c:: with SMTP id q12mr28490353pfn.209.1595398007195; Tue, 21 Jul 2020 23:06:47 -0700 (PDT) Received: from localhost.localdomain (p6e424d9a.tkyea130.ap.so-net.ne.jp. [110.66.77.154]) by smtp.gmail.com with ESMTPSA id p10sm19578759pgn.6.2020.07.21.23.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 23:06:46 -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: [PATCH v4 11/16] dfu: add dfu_write_by_alt() Date: Wed, 22 Jul 2020 15:05:34 +0900 Message-Id: <20200722060539.15168-12-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200722060539.15168-1-takahiro.akashi@linaro.org> References: <20200722060539.15168-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.27.0 diff --git a/drivers/dfu/dfu_alt.c b/drivers/dfu/dfu_alt.c index f6b87c51ed30..7c6ca3489354 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 4e6814a45b5e..6beafd03288c 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);