return spi_flash_read(dfu->data.sf.dev, offset, *len, buf);
}
+static u64 find_sector(struct dfu_entity *dfu, u64 start, u64 offset)
+{
+ return (lldiv((start + 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)
{
int ret;
- ret = spi_flash_erase(dfu->data.sf.dev, offset,
+ ret = spi_flash_erase(dfu->data.sf.dev,
+ find_sector(dfu, dfu->data.sf.start, offset),
dfu->data.sf.dev->sector_size);
if (ret)
return ret;
- ret = spi_flash_write(dfu->data.sf.dev, offset, *len, buf);
+ ret = spi_flash_write(dfu->data.sf.dev, dfu->data.sf.start + offset,
+ *len, buf);
if (ret)
return ret;
int dfu_fill_entity_sf(struct dfu_entity *dfu, char *devstr, char *s)
{
char *st;
+ char *devstr_bkup = strdup(devstr);
- dfu->data.sf.dev = parse_dev(devstr);
+ dfu->data.sf.dev = parse_dev(devstr_bkup);
+ free(devstr_bkup);
if (!dfu->data.sf.dev)
return -ENODEV;