1
0
mirror of https://github.com/corundum/corundum.git synced 2025-01-16 08:12:53 +08:00

Minor cleanup

This commit is contained in:
Alex Forencich 2022-03-03 22:48:24 -08:00
parent 3d5395a7ca
commit d325d0df3e

View File

@ -133,7 +133,7 @@ static void usage(char *name)
int flash_read_progress(struct flash_device *fdev, size_t addr, size_t len, void *dest) int flash_read_progress(struct flash_device *fdev, size_t addr, size_t len, void *dest)
{ {
int ret; int ret = 0;
size_t remain = len; size_t remain = len;
size_t seg; size_t seg;
int step = 0x10000; int step = 0x10000;
@ -163,13 +163,15 @@ int flash_read_progress(struct flash_device *fdev, size_t addr, size_t len, void
seg = remain; seg = remain;
} }
printf("Read address 0x%08lx, length 0x%08lx (%ld%%)\r", addr, seg, ((100*(len-remain))/len)); printf("Read address 0x%08lx, length 0x%08lx (%ld%%)\r", addr, seg, (100*(len-remain))/len);
fflush(stdout); fflush(stdout);
ret = flash_read(fdev, addr, seg, dest); ret = flash_read(fdev, addr, seg, dest);
if (ret) if (ret) {
return ret; fprintf(stderr, "\nRead failed\n");
goto err;
}
addr += seg; addr += seg;
remain -= seg; remain -= seg;
@ -178,12 +180,13 @@ int flash_read_progress(struct flash_device *fdev, size_t addr, size_t len, void
printf("\n"); printf("\n");
return 0; err:
return ret;
} }
int flash_write_progress(struct flash_device *fdev, size_t addr, size_t len, const void *src) int flash_write_progress(struct flash_device *fdev, size_t addr, size_t len, const void *src)
{ {
int ret; int ret = 0;
size_t remain = len; size_t remain = len;
size_t seg; size_t seg;
int step = 0x10000; int step = 0x10000;
@ -215,13 +218,15 @@ int flash_write_progress(struct flash_device *fdev, size_t addr, size_t len, con
seg = remain; seg = remain;
} }
printf("Write address 0x%08lx, length 0x%08lx (%ld%%)\r", addr, seg, ((100*(len-remain))/len)); printf("Write address 0x%08lx, length 0x%08lx (%ld%%)\r", addr, seg, (100*(len-remain))/len);
fflush(stdout); fflush(stdout);
ret = flash_write(fdev, addr, seg, src); ret = flash_write(fdev, addr, seg, src);
if (ret) if (ret) {
return ret; fprintf(stderr, "\nWrite failed\n");
goto err;
}
addr += seg; addr += seg;
remain -= seg; remain -= seg;
@ -230,7 +235,8 @@ int flash_write_progress(struct flash_device *fdev, size_t addr, size_t len, con
printf("\n"); printf("\n");
return 0; err:
return ret;
} }
int flash_erase_progress(struct flash_device *fdev, size_t addr, size_t len) int flash_erase_progress(struct flash_device *fdev, size_t addr, size_t len)