From patchwork Fri Nov 13 04:15:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 324270 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp899853ils; Thu, 12 Nov 2020 20:18:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYVhD7p9UlycNahrV31zbANoVxQH5VRPbbwwfh66KNzuO0/osatpURO/HhFbCr+JTC9c8J X-Received: by 2002:a50:9518:: with SMTP id u24mr637951eda.124.1605241138853; Thu, 12 Nov 2020 20:18:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605241138; cv=none; d=google.com; s=arc-20160816; b=eU1ftoT517Ht+6F/YCFwV7Krp7Id1P5hJAFdOMa/NTPICrDEL+hEil+B0CT9+XuOVH Z2XCJKplxx+pUKQycECNQQqScq+STFHqFkdsbHkmiutSFpLYvR9cFwaPYkkPqMJrIyVg 0Ql89IrQt/bMj9K/sHec1ezXRycyKGzLYPtQnQbUrM0UdDvCIEL7IbsBvhi03At5g27R YHIUCJIq4QL29rlewTyZR1fN4YU7D5sbVXeKHhcJTJ1rlnIopE0t6ICs4XRq8ifTvw5+ e6uZl1A7C9gmHLrkSxVMO+5KqNXlSM8YhyGfV8n7cykvBa6LAWPqd8kGlcZ8VltlpdVj kkhQ== 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=GOxjoIFrbPU/USWH83c4NCXOSoHA/g+AcKYd/lZMzps=; b=r4CbNfAA2C6BVYXXZ1cxoE4uvU0cF9h/0+SfLlDbQbpAEv7F5n25XdjAqWp1Wn2gki FCw4u4sys+PPLMm4apeUBPxF7msCrB1HUgnv2+DBzfqgP2x0cHj5Tm8yGd09CovqVge5 9QZ7g7SxqhrgNQwsfTl8uL+sgYlKKNlFkG2e1z9DMF3eBbFAD8fv4ITPNTpMTJh8VQ1Z 0VkGxPLWLuXzLm4Iu2oDnHfLIiFGsyZUDwAQcIGj/YYMOi13ljYsiYbo4w3JdlFNt41J +Gddt1tQU1pjSl08lJfeidLXgiAcnpEmh7ZL4x2rw1xARhRDfJW5tBGob1x6qXnT2LAd JuJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VsQ8osVG; 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 h13si5778401edn.268.2020.11.12.20.18.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 20:18:58 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VsQ8osVG; 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 58136825A3; Fri, 13 Nov 2020 05:17:34 +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="VsQ8osVG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1B78282594; Fri, 13 Nov 2020 05:16:30 +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=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,SPF_HELO_NONE,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.2 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (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 75B858000F for ; Fri, 13 Nov 2020 05:16:10 +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-x433.google.com with SMTP id q10so6563082pfn.0 for ; Thu, 12 Nov 2020 20:16:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GOxjoIFrbPU/USWH83c4NCXOSoHA/g+AcKYd/lZMzps=; b=VsQ8osVG57+re5XiOG8QHEWbyB9fR36WkVENZIAB3/2EJWLTotg4HEq1Y9xosrdnFW NdLUTF0FYtAfimQbG71pgwUS5wUVAt+NrqZOXy6mF45bIIwk6NkPOC78Sig8XrfZc6tR gUAHX+UxtXgc5SdM/+ne5BNlCpYv2YGy70IOa+yBMRQzRwQZ1/vlAYIxKuJ5sTsOV3Pq 0IgYzTJMD/2r8h3xU7QAfjxpJB0XJjbQEMEpVxG3GjzaOkkCBZ52cRoARn5nT6BYTgdA Yvuo5mBF807OTqsdvmnAu0W0SPDuHmlv1jHG8fSrTE42gMCaw2t+AdchUAwY446kQcx2 sNTg== 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=GOxjoIFrbPU/USWH83c4NCXOSoHA/g+AcKYd/lZMzps=; b=in7RFQq/rlMe/a7z2dF/oEZLZ393T+7YDc6B8XUVyaCOnvO0hNeD5yc3vyFzdaOCZt 7lUZnNF+3P0ZJaYFeYxSrh4fU3tvWGBC8rTvXHj+vU+VnYu1y6tmBOI0KLcpT6Rjwo7p ZvUPexJD3cs/qURwolX3oVuGkkWQB69r0/BQLTrgmCcMPXAFJgEMYb7i4at4uK8t4Dw6 STrOfZFSlIXDJVYy5o8q6PLX0MNboUQa4pZb4piyS6wcuFVes+FatSQ1pCe7vZXnYCFT v0AbHAo6sLkvh2GBkKNm/BP4BIfwgBDw4kVHoOKvBlMmnSZpfDH6xY/LFIPHyQnMZRk/ Zxew== X-Gm-Message-State: AOAM530lKQGQSWbw0xnarOowp/PpR5ZQzE14WYucN4RprtRtTnyvFXCg xrLWaIuhN6Wyug31P4mCSBnpoA== X-Received: by 2002:a63:450a:: with SMTP id s10mr542289pga.275.1605240968800; Thu, 12 Nov 2020 20:16:08 -0800 (PST) Received: from localhost.localdomain (p784a5642.tkyea130.ap.so-net.ne.jp. [120.74.86.66]) by smtp.gmail.com with ESMTPSA id s10sm4588340pjn.35.2020.11.12.20.16.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Nov 2020 20:16:08 -0800 (PST) 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 v8 12/18] dfu: add dfu_write_by_alt() Date: Fri, 13 Nov 2020 13:15:05 +0900 Message-Id: <20201113041511.48207-13-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201113041511.48207-1-takahiro.akashi@linaro.org> References: <20201113041511.48207-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 eaf4bfc0d5ed..a767adee4107 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_WRITE_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_WRITE_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);