From mboxrd@z Thu Jan 1 00:00:00 1970 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 9F0F0C433EF for ; Thu, 30 Sep 2021 16:23:55 +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 038EF61139 for ; Thu, 30 Sep 2021 16:23:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 038EF61139 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 22BEE831AE; Thu, 30 Sep 2021 18:23:23 +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="GyxR+tsZ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6FDC581545; Thu, 30 Sep 2021 18:22:29 +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 80E2582982 for ; Thu, 30 Sep 2021 18:22:21 +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 B71F7BFC87; Thu, 30 Sep 2021 18:22:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fris.de; s=dkim; t=1633018941; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=w/Yyy5g0P1eGgZj4dBC8fxYOrLBo7NWvcNJoo63Yh/8=; b=GyxR+tsZjXIynpqzrINPNdqQyS4znIFKN2uPEa7ioayAVlaB/OMK67u/+gABErwkL0/TjH DVlpfB4HOQI+sr5UMHEMKDLsXLNqO0Ef3iXT2glhSXQbnPpj0bXhjalt7nqhvLijjZUpQl GRNdXaAO2NHVL4eeoXDu66GYw/I2Fz2qT90tPJAd7nYSDk+I5MgH6glJXgZFzMCj29n/vy GUq0AiOPxjUb2jfRruF2D7W0sAdw75Pbo+GYuIGSSHkQ7kXvEQb5xbuWLnGhErKJXcnIkO 0ftFFe12urzZ+NYvQlX22tg9ZGoXxrg8uw0ee015t1lI2Ihgon2f3qRJ3RGFzA== From: Frieder Schrempf To: Lukasz Majewski , u-boot@lists.denx.de Cc: Heiko Thiery , Michael Walle , Frieder Schrempf , Heinrich Schuchardt , Simon Glass Subject: [PATCH 2/3] dfu: dfu_fs: Simplify find_sector() Date: Thu, 30 Sep 2021 18:22:07 +0200 Message-Id: <20210930162208.2749155-2-frieder@fris.de> In-Reply-To: <20210930162208.2749155-1-frieder@fris.de> References: <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 simplifies the existing code a bit and prepares for the following patch that implements unaligned writes. Signed-off-by: Frieder Schrempf --- drivers/dfu/dfu_sf.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c index 7e64ab772f..c7ed674092 100644 --- a/drivers/dfu/dfu_sf.c +++ b/drivers/dfu/dfu_sf.c @@ -28,25 +28,24 @@ static int dfu_read_medium_sf(struct dfu_entity *dfu, u64 offset, void *buf, *len, buf); } -static u64 find_sector(struct dfu_entity *dfu, u64 start, u64 offset) +static u64 find_sector(struct dfu_entity *dfu, u64 offset) { - return (lldiv((start + offset), dfu->data.sf.dev->sector_size)) * + return (lldiv(offset, dfu->data.sf.dev->sector_size)) * dfu->data.sf.dev->sector_size; } static int dfu_write_medium_sf(struct dfu_entity *dfu, u64 offset, void *buf, long *len) { + u64 start = dfu->data.sf.start + offset; int ret; - ret = spi_flash_erase(dfu->data.sf.dev, - find_sector(dfu, dfu->data.sf.start, offset), + ret = spi_flash_erase(dfu->data.sf.dev, find_sector(dfu, start), dfu->data.sf.dev->sector_size); if (ret) return ret; - ret = spi_flash_write(dfu->data.sf.dev, dfu->data.sf.start + offset, - *len, buf); + ret = spi_flash_write(dfu->data.sf.dev, start, *len, buf); if (ret) return ret; @@ -61,7 +60,7 @@ static int dfu_flush_medium_sf(struct dfu_entity *dfu) return 0; /* in case of ubi partition, erase rest of the partition */ - off = find_sector(dfu, dfu->data.sf.start, dfu->offset); + off = find_sector(dfu, dfu->data.sf.start + dfu->offset); /* last write ended with unaligned length jump to next */ if (off != dfu->data.sf.start + dfu->offset) off += dfu->data.sf.dev->sector_size; -- 2.33.0