Skip to content

Commit

Permalink
libflash/file: greatly increase perf of file_erase()
Browse files Browse the repository at this point in the history
Do 4096 byte chunks not 8 byte chunks. A ffspart invocation constructing
a 64MB PNOR goes from a couple of seconds to ~0.1seconds with this
patch.

Signed-off-by: Stewart Smith <[email protected]>
Reviewed-by: Samuel Mendoza-Jonas <[email protected]>
Signed-off-by: Stewart Smith <[email protected]>
  • Loading branch information
stewartsmith committed Dec 12, 2018
1 parent eb02262 commit 1534ab1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions libflash/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,17 @@ static int file_write(struct blocklevel_device *bl, uint64_t dst, const void *sr
*/
static int file_erase(struct blocklevel_device *bl, uint64_t dst, uint64_t len)
{
unsigned long long int d = ULLONG_MAX;
char buf[4096];
int i = 0;
int rc;

memset(buf, ~0, sizeof(buf));

while (len - i > 0) {
rc = file_write(bl, dst + i, &d, len - i > sizeof(d) ? sizeof(d) : len - i);
rc = file_write(bl, dst + i, buf, len - i > sizeof(buf) ? sizeof(buf) : len - i);
if (rc)
return rc;
i += len - i > sizeof(d) ? sizeof(d) : len - i;
i += (len - i > sizeof(buf)) ? sizeof(buf) : len - i;
}

return 0;
Expand Down

0 comments on commit 1534ab1

Please sign in to comment.