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);