--- embedtools/src/imgupd.c 2014/02/06 14:22:43 1.6.2.6 +++ embedtools/src/imgupd.c 2017/01/22 20:40:10 1.7.4.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: imgupd.c,v 1.6.2.6 2014/02/06 14:22:43 misho Exp $ + * $Id: imgupd.c,v 1.7.4.1 2017/01/22 20:40:10 misho Exp $ * ************************************************************************* The ELWIX and AITNET software is distributed under the following @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004 - 2014 +Copyright 2004 - 2017 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -61,7 +61,6 @@ Usage() " Syntax: imgupd [options] [image_file]\n\n" "\t-v\t\tVerbose ...\n" "\t-R\t\tReboot system after complete\n" - "\t-p\t\tPipe suitable transfer on little chunks\n" "\t-i\t\tStart fill storage from begin\n" "\t-g\t\tGet image from Storage\n" "\t-t\t\tTruncate Storage file name\n" @@ -130,8 +129,8 @@ EmptyStore(int img, int flg) if (wlen == -1) ESYSERR(0); else - EERROR(EIO, "Error at chunk %d init %d bytes, " - "should be %u\n", i, wlen, bufSize); + EERROR(EIO, "Error at chunk %d init %zd bytes, " + "should be %d\n", i, wlen, bufSize); return -1; } else VERB(1) printf("+Written chunk #%d\n", i); @@ -161,7 +160,7 @@ FillStore(int img, int iflg, int fd, int fflg) } else if (!rlen) break; else - VERB(1) printf("+Readed %d bytes for chunk #%d\n", rlen, j); + VERB(1) printf("+Readed %zd bytes for chunk #%d\n", rlen, j); } wlen = write(img, buf, bufSize); @@ -169,10 +168,10 @@ FillStore(int img, int iflg, int fd, int fflg) ESYSERR(0); return -1; } else if (wlen && wlen != bufSize) { - EERROR(EIO, "Error at chunk %d written %d bytes, " + EERROR(EIO, "Error at chunk %d written %zd bytes, " "should be %u\n", i, wlen, bufSize); } else - VERB(1) printf("+Written %d bytes at chunk #%d\n", wlen, i); + VERB(1) printf("+Written %zd bytes at chunk #%d\n", wlen, i); } return 0; @@ -184,7 +183,7 @@ main(int argc, char **argv) char ch, m = 0, R = 0; int fd, img, tr = 0; - while ((ch = getopt(argc, argv, "hvRipgts:f:")) != -1) + while ((ch = getopt(argc, argv, "hvRigts:f:")) != -1) switch (ch) { case 'f': strlcpy(imgName, optarg, sizeof imgName); @@ -199,9 +198,6 @@ main(int argc, char **argv) case 't': tr = O_TRUNC; break; - case 'p': - bufSize = IMGBUF_SIZE2; - break; case 'g': m = 1; case 'i': @@ -240,7 +236,8 @@ main(int argc, char **argv) close(fd); EERROR(ENOSPC, "Error:: file size %llu is " "greater from storage size %llu\n", - iSize, imgSize); + (unsigned long long) iSize, + (unsigned long long) imgSize); return 2; } else lseek(fd, 0, SEEK_SET); @@ -273,7 +270,7 @@ main(int argc, char **argv) } VERB(1) printf("imgSize=%llu imgName=%s imgFile=%s\n", - imgSize, imgName, argc ? imgFile : ""); + (unsigned long long) imgSize, imgName, argc ? imgFile : ""); if (!m) { /* open storage device */ @@ -306,7 +303,8 @@ main(int argc, char **argv) close(img); EERROR(ENOSPC, "Error:: storage size %llu is " "greater from file size %llu\n", - iSize, imgSize); + (unsigned long long) iSize, + (unsigned long long) imgSize); return 3; } else lseek(img, 0, SEEK_SET); @@ -335,12 +333,13 @@ main(int argc, char **argv) } } else { /* GET */ iSize ^= iSize; - if (EmptyStore(fd, fileFlg) == -1) { - if (fd > 2) - close(fd); - close(img); - return 3; - } + if (!(fileFlg & FD_PIPE)) + if (EmptyStore(fd, fileFlg) == -1) { + if (fd > 2) + close(fd); + close(img); + return 3; + } if (FillStore(fd, fileFlg, img, nameFlg) == -1) { if (fd > 2) close(fd);