X-Git-Url: https://git.rohieb.name/openwrt.git/blobdiff_plain/9e3ab7a0fb2efc08fa3e4c242ba8cbdd3904e23f..a1d1cc5f82fbb4e48ddfffd5c912d0de6fbbd111:/openwrt/package/mtd/mtd.c?ds=sidebyside diff --git a/openwrt/package/mtd/mtd.c b/openwrt/package/mtd/mtd.c index bdc2f10f7..23e99160a 100644 --- a/openwrt/package/mtd/mtd.c +++ b/openwrt/package/mtd/mtd.c @@ -96,7 +96,7 @@ image_check_bcom(int imagefd, const char *mtd) } /* check if image fits to mtd device */ - fd = mtd_open(mtd, O_RDWR); + fd = mtd_open(mtd, O_RDWR | O_SYNC); if(fd < 0) { fprintf(stderr, "Could not open mtd device: %s\n", mtd); exit(1); @@ -113,6 +113,7 @@ image_check_bcom(int imagefd, const char *mtd) return 0; } + close(fd); return 1; } @@ -148,7 +149,7 @@ int mtd_check(char *mtd) struct mtd_info_user mtdInfo; int fd; - fd = mtd_open(mtd, O_RDWR); + fd = mtd_open(mtd, O_RDWR | O_SYNC); if(fd < 0) { fprintf(stderr, "Could not open mtd device: %s\n", mtd); return 0; @@ -171,7 +172,7 @@ mtd_unlock(const char *mtd) struct mtd_info_user mtdInfo; struct erase_info_user mtdLockInfo; - fd = mtd_open(mtd, O_RDWR); + fd = mtd_open(mtd, O_RDWR | O_SYNC); if(fd < 0) { fprintf(stderr, "Could not open mtd device: %s\n", mtd); exit(1); @@ -222,7 +223,7 @@ mtd_erase(const char *mtd) struct mtd_info_user mtdInfo; struct erase_info_user mtdEraseInfo; - fd = mtd_open(mtd, O_RDWR); + fd = mtd_open(mtd, O_RDWR | O_SYNC); if(fd < 0) { fprintf(stderr, "Could not open mtd device: %s\n", mtd); exit(1); @@ -260,8 +261,9 @@ mtd_write(int imagefd, const char *mtd, int quiet) size_t r, w, e; struct mtd_info_user mtdInfo; struct erase_info_user mtdEraseInfo; + int ret = 0; - fd = mtd_open(mtd, O_RDWR); + fd = mtd_open(mtd, O_RDWR | O_SYNC); if(fd < 0) { fprintf(stderr, "Could not open mtd device: %s\n", mtd); exit(1); @@ -318,7 +320,8 @@ mtd_write(int imagefd, const char *mtd, int quiet) } if (!quiet) fprintf(stderr, "\b\b\b\b"); - + + close(fd); return 0; } @@ -331,7 +334,8 @@ void usage(void) " erase erase all data on device\n" " write |- write (use - for stdin) to device\n" "Following options are available:\n" - " -q quiet mode\n" + " -q quiet mode (once: no [w] on writing,\n" + " twice: no status messages)\n" " -r reboot after successful command\n" " -f force write without trx checks\n" " -e erase before executing the command\n\n" @@ -365,7 +369,7 @@ int main (int argc, char **argv) boot = 1; break; case 'q': - quiet = 1; + quiet++; break; case 'e': i = 0; @@ -409,7 +413,7 @@ int main (int argc, char **argv) /* check trx file before erasing or writing anything */ if (!image_check(imagefd, device)) { - if (!quiet && force) + if ((quiet < 2) || !force) fprintf(stderr, "TRX check failed!\n"); if (!force) exit(1); @@ -428,10 +432,10 @@ int main (int argc, char **argv) i = 0; unlocked = 0; while (erase[i] != NULL) { - if (!quiet) + if (quiet < 2) fprintf(stderr, "Unlocking %s ...\n", erase[i]); mtd_unlock(erase[i]); - if (!quiet) + if (quiet < 2) fprintf(stderr, "Erasing %s ...\n", erase[i]); mtd_erase(erase[i]); if (strcmp(erase[i], device) == 0) @@ -440,7 +444,7 @@ int main (int argc, char **argv) } if (!unlocked) { - if (!quiet) + if (quiet < 2) fprintf(stderr, "Unlocking %s ...\n", device); mtd_unlock(device); } @@ -449,17 +453,21 @@ int main (int argc, char **argv) case CMD_UNLOCK: break; case CMD_ERASE: + if (quiet < 2) + fprintf(stderr, "Erasing %s ...\n", device); mtd_erase(device); break; case CMD_WRITE: - if (!quiet) + if (quiet < 2) fprintf(stderr, "Writing from %s to %s ... ", imagefile, device); mtd_write(imagefd, device, quiet); - if (!quiet) + if (quiet < 2) fprintf(stderr, "\n"); break; } + sync(); + if (boot) kill(1, 15); // send SIGTERM to init for reboot