Author: titmuss
Date: Thu Feb 14 04:22:18 2008
New Revision: 1956
URL: http://svn.slimdevices.com?rev=1956&root=Jive&view=rev
Log:
[EMAIL PROTECTED] (orig r1949): titmuss | 2008-02-14 12:14:35 +0000
Bug: 7114
Description:
Allow nandwrite to accept data from stdin (thanks Felix!).
Modified:
trunk/ (props changed)
trunk/squeezeboxJive/src/system/mtd-utils/nandwrite.c
Propchange: trunk/
------------------------------------------------------------------------------
--- svk:merge (original)
+++ svk:merge Thu Feb 14 04:22:18 2008
@@ -1,3 +1,3 @@
-bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/7.0:1948
+bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/7.0:1949
bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/SN:1083
bbe22326-0783-4b3a-ac2b-7ab96b24c8d9:/branches/scrolling:1378
Modified: trunk/squeezeboxJive/src/system/mtd-utils/nandwrite.c
URL:
http://svn.slimdevices.com/trunk/squeezeboxJive/src/system/mtd-utils/nandwrite.c?rev=1956&root=Jive&r1=1955&r2=1956&view=diff
==============================================================================
--- trunk/squeezeboxJive/src/system/mtd-utils/nandwrite.c (original)
+++ trunk/squeezeboxJive/src/system/mtd-utils/nandwrite.c Thu Feb 14 04:22:18
2008
@@ -74,7 +74,7 @@
void display_help (void)
{
- printf("Usage: nandwrite [OPTION] MTD_DEVICE INPUTFILE\n"
+ printf("Usage: nandwrite [OPTION] [MTD_DEVICE INPUTFILE|-]\n"
"Writes to the specified MTD device.\n"
"\n"
" -a, --autoplace Use auto oob layout\n"
@@ -214,6 +214,7 @@
int ret, readlen;
int oobinfochanged = 0;
struct nand_oobinfo old_oobinfo;
+ int read_from_stdin = 0;
process_options(argc, argv);
@@ -330,15 +331,29 @@
oob.length = meminfo.oobsize;
oob.ptr = noecc ? oobreadbuf : oobbuf;
- /* Open the input file */
- if ((ifd = open(img, O_RDONLY)) == -1) {
- perror("open input file");
- goto restoreoob;
- }
-
- // get image length
- imglen = lseek(ifd, 0, SEEK_END);
- lseek (ifd, 0, SEEK_SET);
+ // Check if we read from stdin
+ if (strcmp(img, "-") == 0) {
+ // FIXME OOB data and stdin
+ if( writeoob) {
+ fprintf(stderr, "Can't use oob data when stdin is
used.\n");
+ exit(-1);
+ }
+
+ ifd = STDIN_FILENO;
+ read_from_stdin = 1;
+ imglen = pagelen; // used as flag in stdin case
+ }
+ else {
+ /* Open the input file */
+ if ((ifd = open(img, O_RDONLY)) == -1) {
+ perror("open input file");
+ goto restoreoob;
+ }
+
+ // get image length
+ imglen = lseek(ifd, 0, SEEK_END);
+ lseek (ifd, 0, SEEK_SET);
+ }
pagelen = meminfo.writesize + ((writeoob == 1) ? meminfo.oobsize : 0);
@@ -357,6 +372,7 @@
}
/* Get data from input and write to the device */
+ /* imglen is used as flag in stdin case */
while (imglen && (mtdoffset < meminfo.size)) {
// new eraseblock , check for bad block(s)
// Stay in the loop to be sure if the mtdoffset changes because
@@ -394,18 +410,51 @@
}
readlen = meminfo.writesize;
- if (pad && (imglen < readlen))
- {
- readlen = imglen;
- memset(writebuf + readlen, 0xff, meminfo.writesize -
readlen);
- }
-
- /* Read Page Data from input file */
- if ((cnt = read(ifd, writebuf, readlen)) != readlen) {
- if (cnt == 0) // EOF
- break;
- perror ("File I/O error on input file");
- goto closeall;
+
+ if( !read_from_stdin) {
+ if (pad && (imglen < readlen))
+ {
+ readlen = imglen;
+ memset(writebuf + readlen, 0xff,
meminfo.writesize - readlen);
+ }
+
+ /* Read Page Data from input file */
+ if ((cnt = read(ifd, writebuf, readlen)) != readlen) {
+ if (cnt == 0) // EOF
+ break;
+ perror ("File I/O error on input file");
+ goto closeall;
+ }
+ } else {
+ /* Read Page Data from stdin */
+ int tinycnt = 0;
+ while(tinycnt < readlen) {
+ cnt = read(ifd, writebuf + tinycnt, readlen -
tinycnt);
+ if (cnt == 0) { // EOF
+ break;
+ }
+ else if (cnt < 0) {
+ perror ("File I/O error on stdin");
+ goto closeall;
+ }
+ tinycnt += cnt;
+ }
+
+ /* No padding needed - we are done */
+ if (tinycnt == 0) {
+ imglen = 0;
+ break;
+ }
+
+ /* No more bytes - we are done after writing the
remaining bytes */
+ if (cnt == 0) {
+ imglen = 0;
+ }
+
+ /* Padding */
+ if (pad && (tinycnt < readlen)) {
+ memset( writebuf + tinycnt, 0xff,
meminfo.writesize - tinycnt);
+ }
}
if (writeoob) {
@@ -455,7 +504,10 @@
perror ("pwrite");
goto closeall;
}
- imglen -= readlen;
+
+ if (!read_from_stdin) {
+ imglen -= readlen;
+ }
mtdoffset += meminfo.writesize;
}
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins