#include "libbb.h"
#include <mtd/mtd-user.h>
+/* If 1, simulates "flashing" by writing to existing regular file */
#define MTD_DEBUG 0
#define OPT_v (1 << 0)
if (total)
percent = (unsigned) (percent / total);
printf("\r%s: %"OFF_FMT"u/%"OFF_FMT"u (%u%%) ",
- (mode == 0) ? "Erasing block" : ((mode == 1) ? "Writing kb" : "Verifying kb"),
+ (mode == -1) ? "Erasing block" : ((mode == 0) ? "Writing kb" : "Verifying kb"),
count, total, (unsigned)percent);
fflush_all();
}
#endif
e.start = 0;
for (i = 1; i <= erase_count; i++) {
- progress(0, i, erase_count);
- errno = 0;
+ progress(-1, i, erase_count);
#if !MTD_DEBUG
if (ioctl(fd_d, MEMERASE, &e) < 0) {
bb_perror_msg_and_die("erase error at 0x%llx on %s",
/* doing this outer loop gives significantly smaller code
* than doing two separate loops for writing and verifying */
- for (i = 1; i <= 2; i++) {
+ for (i = 0; i <= 1; i++) {
uoff_t done;
unsigned count;
done = 0;
count = BUFSIZE;
while (1) {
- uoff_t rem = statb.st_size - done;
+ uoff_t rem;
+
+ progress(i, done / 1024, (uoff_t)statb.st_size / 1024);
+ rem = statb.st_size - done;
if (rem == 0)
break;
if (rem < BUFSIZE)
count = rem;
- progress(i, done / 1024, (uoff_t)statb.st_size / 1024);
xread(fd_f, buf, count);
- if (i == 1) {
+ if (i == 0) {
int ret;
+ if (count < BUFSIZE)
+ memset((char*)buf + count, 0, BUFSIZE - count);
errno = 0;
- ret = full_write(fd_d, buf, count);
- if (ret != count) {
+ ret = full_write(fd_d, buf, BUFSIZE);
+ if (ret != BUFSIZE) {
bb_perror_msg_and_die("write error at 0x%"OFF_FMT"x on %s, "
"write returned %d",
done, devicename, ret);
}
- } else { /* i == 2 */
+ } else { /* i == 1 */
xread(fd_d, buf2, count);
- if (memcmp(buf, buf2, count)) {
+ if (memcmp(buf, buf2, count) != 0) {
bb_error_msg_and_die("verification mismatch at 0x%"OFF_FMT"x", done);
}
}