Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEDB5C433F5 for ; Thu, 30 Sep 2021 16:24:06 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4905661507 for ; Thu, 30 Sep 2021 16:24:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4905661507 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=fris.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 11277831B0; Thu, 30 Sep 2021 18:23:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=fris.de 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=fris.de header.i=@fris.de header.b="gjrWfVrW"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9DC2C80F9D; Thu, 30 Sep 2021 18:22:30 +0200 (CEST) Received: from mail.fris.de (mail.fris.de [IPv6:2a01:4f8:c2c:390b::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0427182B9F for ; Thu, 30 Sep 2021 18:22:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=fris.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=frieder@fris.de Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id C3F04BFBEE; Thu, 30 Sep 2021 18:22:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fris.de; s=dkim; t=1633018938; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding; bh=FQ6XBj1pIZ3+NNGSnK/+F1DAI+aTiFFGX8ZD+4ezBz8=; b=gjrWfVrWUjg5EiS/+tLXfBoWczoiXioelvB0wZLYPcqaFvk6WRTqa8eXxvczYtk9WviGcM iaI+h+QyLTJECqSFxnjJYh3UaB4/JMFyHfIC7dfHb9SjKNZFtbE+LL3px6fcXSbPhq7KZW at0I9KQpW/KJGvA6uLO+ozMiAuBx9iD270ITNoIfawtOIXsrfIJU3cz4MmGDTHV5A+Om9y JO3TxSZTglbuOf9CofQuAgDCc+6vHmG3RP4c/tSr3V07Tn3RQg+/v32Or4V+BnIQ6Bf96x CKcElyRLgkqHyTSW8m4wJ1EqmgdyXPDNrZIqruKJjyocdWJpnlYXC1pl/XCkvg== From: Frieder Schrempf To: Lukasz Majewski , u-boot@lists.denx.de Cc: Heiko Thiery , Michael Walle , Frieder Schrempf , AKASHI Takahiro , Aswath Govindraju , Jaehoon Chung , Marek Szyprowski , Oleksandr Suvorov , Patrice Chotard , Patrick Delaunay Subject: [PATCH 1/3] dfu: use pointer to pass length to dfu_write() Date: Thu, 30 Sep 2021 18:22:06 +0200 Message-Id: <20210930162208.2749155-1-frieder@fris.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Last-TLS-Session-Version: TLSv1.3 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.103.2 at phobos.denx.de X-Virus-Status: Clean From: Frieder Schrempf This doesn't include any functional changes, but allows us to use the size parameter to report the actual written bytes back to the caller. This is useful in cases of unaligned writes to serial flash where the first write covers only a part of the buffer (until the next sector boundary) and the remaining bytes need to be written in a further call to dfu_write(). While at it, we also adjust the data type of the 'write' and 'left' variable in dfu_write_from_mem_addr() to match the values passed. Signed-off-by: Frieder Schrempf --- drivers/dfu/dfu.c | 23 ++++++++++++----------- include/dfu.h | 2 +- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c index ff1859d946..5b2659ee7d 100644 --- a/drivers/dfu/dfu.c +++ b/drivers/dfu/dfu.c @@ -334,12 +334,12 @@ int dfu_flush(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) return ret; } -int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) +int dfu_write(struct dfu_entity *dfu, void *buf, int *size, int blk_seq_num) { int ret; debug("%s: name: %s buf: 0x%p size: 0x%x p_num: 0x%x offset: 0x%llx bufoffset: 0x%lx\n", - __func__, dfu->name, buf, size, blk_seq_num, dfu->offset, + __func__, dfu->name, buf, *size, blk_seq_num, dfu->offset, (unsigned long)(dfu->i_buf - dfu->i_buf_start)); ret = dfu_transaction_initiate(dfu, false); @@ -371,7 +371,7 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) dfu->i_blk_seq_num = (dfu->i_blk_seq_num + 1) & 0xffff; /* flush buffer if overflow */ - if ((dfu->i_buf + size) > dfu->i_buf_end) { + if ((dfu->i_buf + *size) > dfu->i_buf_end) { ret = dfu_write_buffer_drain(dfu); if (ret) { dfu_transaction_cleanup(dfu); @@ -381,19 +381,19 @@ int dfu_write(struct dfu_entity *dfu, void *buf, int size, int blk_seq_num) } /* we should be in buffer now (if not then size too large) */ - if ((dfu->i_buf + size) > dfu->i_buf_end) { + if ((dfu->i_buf + *size) > dfu->i_buf_end) { pr_err("Buffer overflow! (0x%p + 0x%x > 0x%p)\n", dfu->i_buf, - size, dfu->i_buf_end); + *size, dfu->i_buf_end); dfu_transaction_cleanup(dfu); dfu_error_callback(dfu, "Buffer overflow"); return -1; } - memcpy(dfu->i_buf, buf, size); - dfu->i_buf += size; + memcpy(dfu->i_buf, buf, *size); + dfu->i_buf += *size; /* if end or if buffer full flush */ - if (size == 0 || (dfu->i_buf + size) > dfu->i_buf_end) { + if (*size == 0 || (dfu->i_buf + *size) > dfu->i_buf_end) { ret = dfu_write_buffer_drain(dfu); if (ret) { dfu_transaction_cleanup(dfu); @@ -704,7 +704,8 @@ int dfu_get_alt(char *name) int dfu_write_from_mem_addr(struct dfu_entity *dfu, void *buf, int size) { - unsigned long dfu_buf_size, write, left = size; + unsigned int write, left = size; + unsigned long dfu_buf_size; int i, ret = 0; void *dp = buf; @@ -720,9 +721,9 @@ int dfu_write_from_mem_addr(struct dfu_entity *dfu, void *buf, int size) for (i = 0; left > 0; i++) { write = min(dfu_buf_size, left); - debug("%s: dp: 0x%p left: %lu write: %lu\n", __func__, + debug("%s: dp: 0x%p left: %lu write: %u\n", __func__, dp, left, write); - ret = dfu_write(dfu, dp, write, i); + ret = dfu_write(dfu, dp, &write, i); if (ret) { pr_err("DFU write failed\n"); return ret; diff --git a/include/dfu.h b/include/dfu.h index f6868982df..2df55e507e 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -335,7 +335,7 @@ int dfu_read(struct dfu_entity *de, void *buf, int size, int blk_seq_num); * @blk_seq_num: block sequence number * Return: 0 for success, -1 for error */ -int dfu_write(struct dfu_entity *de, void *buf, int size, int blk_seq_num); +int dfu_write(struct dfu_entity *de, void *buf, int *size, int blk_seq_num); /** * dfu_flush() - flush to dfu entity -- 2.33.0