--- embedtools/src/imgupd.c 2014/02/05 23:31:55 1.6 +++ embedtools/src/imgupd.c 2014/02/06 00:56:16 1.6.2.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ - * $Id: imgupd.c,v 1.6 2014/02/05 23:31:55 misho Exp $ + * $Id: imgupd.c,v 1.6.2.3 2014/02/06 00:56:16 misho Exp $ * ************************************************************************* The ELWIX and AITNET software is distributed under the following @@ -47,7 +47,7 @@ SUCH DAMAGE. char imgName[PATH_MAX], imgFile[PATH_MAX]; -off_t imgSize, iSize; +off_t imgSize, iSize, fromBegin; int Verbose, bufSize = IMGBUF_SIZE; extern char compiled[], compiledby[], compilehost[]; @@ -61,6 +61,7 @@ Usage() "\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" "\t-s \tStorage size (required for stdin)\n" @@ -77,12 +78,15 @@ EmptyStore(int img) VERB(1) printf("Erase store %s\n", imgName); - iSize = lseek(img, 0, SEEK_END); - if (iSize == -1) { - ESYSERR(0); - return -1; + if (!fromBegin) { + iSize = lseek(img, 0, SEEK_END); + if (iSize == -1) { + ESYSERR(0); + return -1; + } else + imgSize += E_ALIGN(iSize, bufSize); } else - imgSize += E_ALIGN(iSize, bufSize); + iSize ^= iSize; memset(buf, 0, sizeof buf); for (i = howmany(iSize, bufSize); i < howmany(imgSize, bufSize); i++) @@ -119,13 +123,13 @@ FillStore(int img, int fd) else VERB(1) printf("+Readed %d bytes for chunk #%d\n", rlen, j); - wlen = write(img, buf, rlen); + wlen = write(img, buf, bufSize); if (wlen == -1) { ESYSERR(0); return -1; - } else if (wlen && wlen != rlen) { - EERROR(EIO, "Readed %d bytes are not equal to written %d bytes\n", - rlen, wlen); + } else if (wlen && wlen != bufSize) { + EERROR(EIO, "Error at chunk %d written %d bytes, " + "should be %u\n", i, wlen, bufSize); } else VERB(1) printf("+Written %d bytes at chunk #%d\n", wlen, i); } @@ -139,7 +143,7 @@ main(int argc, char **argv) char ch, m = 0, R = 0; int fd, img, tr = 0; - while ((ch = getopt(argc, argv, "hvRpgts:f:")) != -1) + while ((ch = getopt(argc, argv, "hvRipgts:f:")) != -1) switch (ch) { case 'f': strlcpy(imgName, optarg, sizeof imgName); @@ -154,11 +158,13 @@ main(int argc, char **argv) case 't': tr = O_TRUNC; break; - case 'g': - m = 1; - break; case 'p': bufSize = IMGBUF_SIZE2; + break; + case 'g': + m = 1; + case 'i': + fromBegin = 1; break; case 'R': R = 1;