Commit 2727f3bf authored by Fabio Estevam's avatar Fabio Estevam Committed by Tom Rini

dfu: dfu_sf: Take the start address into account

The dfu_alt_info_spl variable allows passing a starting point
for the binary to be flashed in the SPI NOR.

For example, if we have 'dfu_alt_info_spl=spl raw 0x400', this means
that we want to flash the binary starting at address 0x400.

In order to do so we need to erase the entire sector and write to
the the subsequent SPI NOR sectors taking such start address
into account for the address calculations.

Tested by succesfully writing SPL binary into 0x400 offset and
the u-boot.img at offset 64 kiB of a SPL NOR.
Signed-off-by: default avatarFabio Estevam <>
Acked-by: default avatarLukasz Majewski <>
[trini: Use lldiv for the math]
Signed-off-by: default avatarTom Rini <>
parent f4c92582
......@@ -23,17 +23,25 @@ static int dfu_read_medium_sf(struct dfu_entity *dfu, u64 offset, void *buf,
return spi_flash_read(dfu->, offset, *len, buf);
static u64 find_sector(struct dfu_entity *dfu, u64 start, u64 offset)
return (lldiv((start + offset), dfu->>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->, offset,
ret = spi_flash_erase(dfu->,
find_sector(dfu, dfu->data.sf.start, offset),
if (ret)
return ret;
ret = spi_flash_write(dfu->, offset, *len, buf);
ret = spi_flash_write(dfu->, dfu->data.sf.start + offset,
*len, buf);
if (ret)
return ret;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment