[PATCH 2/3] dfu: dfu_fs: Simplify find_sector()
Frieder Schrempf
frieder at fris.de
Thu Sep 30 18:22:07 CEST 2021
From: Frieder Schrempf <frieder.schrempf at kontron.de>
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 <frieder.schrempf at kontron.de>
---
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
More information about the U-Boot
mailing list