cmd: sf: Handle unaligned 'update' start offset
authorMarek Vasut <marex@denx.de>
Wed, 28 Sep 2022 16:45:04 +0000 (18:45 +0200)
committerJagan Teki <jagan@edgeble.ai>
Tue, 25 Oct 2022 04:47:33 +0000 (10:17 +0530)
commit622b5d356136f9172db7fe7ba240cd9e45097a19
treea3ec1cec885e4c84d27efb7e2ec9cb33b5087704
parente28d3ead7258ce1deb87003d0064b16ec50abc81
cmd: sf: Handle unaligned 'update' start offset

Currently the 'sf update' command fails in case the 'start' offset is
not aligned to SPI NOR erase block size. Add the missing alignment
calculation. In case the start offset is in the middle of erase block,
round start address down to the nearest aligned one, compare only the
updated data between what is in the SPI NOR and what is being written,
copy new data at offset of the compare buffer, and write back the entire
erase block.

This is useful e.g. on i.MX6Q where the u-boot-with-spl.imx is at
offset 0x400 in the SPI NOR, while the SPI NOR may have erase block
size e.g. 0x1000 bytes.

Signed-off-by: Marek Vasut <marex@denx.de>
Reviewed-by: Jagan Teki <jagan@amarulasolutions.com>
cmd/sf.c