Changeset 2f90960 in freewrt
- Timestamp:
- Feb 27, 2007, 8:58:45 AM (19 years ago)
- Branches:
- freewrt_1_0, freewrt_2_0
- Children:
- 1334083d
- Parents:
- 560055d
- Location:
- package/mtd
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
package/mtd/Makefile
r560055d r2f90960 9 9 PKG_NAME:= mtd 10 10 PKG_VERSION:= 1.0 11 PKG_RELEASE:= 511 PKG_RELEASE:= 6 12 12 13 13 WRKSRC= ${WRKDIR}/$(PKG_NAME) -
package/mtd/mtd.c
r560055d r2f90960 2 2 * mtd - simple memory technology device manipulation tool 3 3 * 4 * Copyright (c) 2006 Thorsten Glaser <tg@freewrt.org>4 * Copyright (c) 2006, 2007 Thorsten Glaser <tg@freewrt.org> 5 5 * Copyright (C) 2005 Waldemar Brodkorb <wbx@freewrt.org>, 6 6 * Felix Fietkau <nbd@openwrt.org> … … 33 33 #include <limits.h> 34 34 #include <unistd.h> 35 #include <stdbool.h> 35 36 #include <stdlib.h> 36 37 #include <stdio.h> … … 63 64 }; 64 65 66 int image_check_bcom(int, const char *); 67 int image_check(int, const char *); 68 int mtd_check(char *); 69 int mtd_unlock(const char *); 70 int mtd_open(const char *, int); 71 int mtd_erase(const char *); 72 int mtd_write(int, const char *, int, bool); 73 void usage(void) __attribute__((noreturn)); 74 65 75 char buf[BUFSIZE]; 66 76 int buflen; … … 75 85 buflen = read(imagefd, buf, 32); 76 86 if (buflen < 32) { 77 fprintf(stdout, "Could not get image header, file too small (% ld bytes)\n", buflen);87 fprintf(stdout, "Could not get image header, file too small (%d bytes)\n", buflen); 78 88 return 0; 79 89 } … … 128 138 image_check(int imagefd, const char *mtd) 129 139 { 130 int fd, systype; 131 size_t count; 140 int systype; 132 141 char *c; 133 142 FILE *f; … … 152 161 } 153 162 154 int mtd_check(char *mtd) 163 int 164 mtd_check(char *mtd) 155 165 { 156 166 struct mtd_info_user mtdInfo; … … 263 273 264 274 int 265 mtd_write(int imagefd, const char *mtd, int quiet )266 { 267 int fd, i,result;275 mtd_write(int imagefd, const char *mtd, int quiet, bool do_erase) 276 { 277 int fd, result; 268 278 size_t r, w, e; 269 279 struct mtd_info_user mtdInfo; 270 280 struct erase_info_user mtdEraseInfo; 271 int ret = 0;272 281 273 282 fd = mtd_open(mtd, O_RDWR | O_SYNC); … … 297 306 298 307 /* need to erase the next block before writing data to it */ 299 while ( w > e) {308 while (do_erase && w > e) { 300 309 mtdEraseInfo.start = e; 301 310 mtdEraseInfo.length = mtdInfo.erasesize; … … 314 323 fprintf(stderr, "\b\b\b[w]"); 315 324 316 if ((result = write(fd, buf, r)) < r) {325 if ((result = write(fd, buf, r)) < (ssize_t)r) { 317 326 if (result < 0) { 318 327 fprintf(stderr, "Error writing image.\n"); … … 333 342 } 334 343 335 void usage(void) 344 void 345 usage(void) 336 346 { 337 347 fprintf(stderr, "Usage: mtd [<options> ...] <command> [<arguments> ...] <device>\n\n" 338 348 "The device is in the format of mtdX (eg: mtd4) or its label.\n" 339 "mtd recogni zes these commands:\n"349 "mtd recognises these commands:\n" 340 350 " unlock unlock the device\n" 341 351 " erase erase all data on device\n" … … 352 362 } 353 363 354 int main (int argc, char **argv) 355 { 356 int ch, i, boot, unlock, imagefd, force, quiet, unlocked; 357 char *erase[MAX_ARGS], *device, *imagefile; 364 int 365 main(int argc, char **argv) 366 { 367 int ch, i, boot, imagefd = -1, force, quiet, unlocked; 368 char *erase[MAX_ARGS], *device, *imagefile = NULL; 358 369 enum { 359 370 CMD_ERASE, … … 449 460 mtd_erase(erase[i]); 450 461 if (strcmp(erase[i], device) == 0) 462 /* this means that <device> is unlocked and erased */ 451 463 unlocked = 1; 452 464 i++; … … 463 475 break; 464 476 case CMD_ERASE: 477 if (unlocked) { 478 fprintf(stderr, "Already erased: %s\n", device); 479 break; 480 } 465 481 if (quiet < 2) 466 482 fprintf(stderr, "Erasing %s ...\n", device); … … 470 486 if (quiet < 2) 471 487 fprintf(stderr, "Writing from %s to %s ... ", imagefile, device); 472 mtd_write(imagefd, device, quiet );488 mtd_write(imagefd, device, quiet, (unlocked == 0)); 473 489 if (quiet < 2) 474 490 fprintf(stderr, "\n"); … … 479 495 480 496 if (boot) { 497 if (quiet < 2) 498 fprintf(stderr, "\nRebooting ... "); 481 499 fflush(stdout); 500 fflush(stderr); 482 501 syscall(SYS_reboot,LINUX_REBOOT_MAGIC1,LINUX_REBOOT_MAGIC2,LINUX_REBOOT_CMD_RESTART,NULL); 483 502 }
Note:
See TracChangeset
for help on using the changeset viewer.
