From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lukasz Majewski Date: Wed, 23 Sep 2015 10:09:19 +0200 Subject: [U-Boot] [PATCH] dfu: dfu_sf: Take the start address into account In-Reply-To: <1442980239-3931-1-git-send-email-festevam@gmail.com> References: <1442980239-3931-1-git-send-email-festevam@gmail.com> Message-ID: <20150923100919.30e977ff@amdc2363> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Fabio, > From: Fabio Estevam > > 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: Fabio Estevam > --- > drivers/dfu/dfu_sf.c | 12 ++++++++++-- > 1 file changed, 10 insertions(+), 2 deletions(-) > > diff --git a/drivers/dfu/dfu_sf.c b/drivers/dfu/dfu_sf.c > index 448d95d..844da1f 100644 > --- a/drivers/dfu/dfu_sf.c > +++ b/drivers/dfu/dfu_sf.c > @@ -23,17 +23,25 @@ static int dfu_read_medium_sf(struct dfu_entity > *dfu, u64 offset, void *buf, return spi_flash_read(dfu->data.sf.dev, > offset, *len, buf); } > > +static u64 find_sector(struct dfu_entity *dfu, u64 start, u64 offset) > +{ > + return ((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; > Acked-by: Lukasz Majewski Applied to u-boot-dfu. Thanks for your patch. -- Best regards, Lukasz Majewski Samsung R&D Institute Poland (SRPOL) | Linux Platform Group