* [PATCH] [MTD-UTILS] nandwrite: read from stdin support
@ 2008-09-02 9:04 Tommi Airikka
2008-09-02 10:54 ` Artem Bityutskiy
2008-09-02 16:21 ` Grant Erickson
0 siblings, 2 replies; 3+ messages in thread
From: Tommi Airikka @ 2008-09-02 9:04 UTC (permalink / raw)
To: linux-mtd
[-- Attachment #1: Type: text/plain, Size: 196 bytes --]
Here is a patch that adds read from stdin support for nandwrite.
I have tried it with 'cat filename.jffs2 | nandwrite -i filesize -p
/dev/mtdX -'
and it did work.
Regards,
Tommi Airikka
[-- Attachment #2: 0001-nandwrite-support-reading-from-stdin.patch --]
[-- Type: application/octet-stream, Size: 3287 bytes --]
From 107facb87fc8967968aa441f2c13de78684d6d28 Mon Sep 17 00:00:00 2001
From: Tommi Airikka <tommi.airikka@ericsson.com>
Date: Fri, 8 Aug 2008 09:44:00 +0200
Subject: [PATCH] nandwrite: support reading from stdin
Adds -i/--file-size switch.
If inputfile is '-', stdin will be read.
If used, -i/--file-size must be specified.
Signed-off-by: Tommi Airikka <tommi.airikka@ericsson.com>
---
nandwrite.c | 36 ++++++++++++++++++++++++++++++------
1 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/nandwrite.c b/nandwrite.c
index a5462ae..354eabd 100644
--- a/nandwrite.c
+++ b/nandwrite.c
@@ -86,6 +86,7 @@ void display_help (void)
" -p, --pad pad to page size\n"
" -b, --blockalign=1|2|4 set multiple of eraseblocks to align to\n"
" -q, --quiet don't display progress messages\n"
+ " -i bytes, --file-size=bytes has to be used when reading file from standard in\n"
" --help display this help and exit\n"
" --version output version information and exit\n");
exit(0);
@@ -118,6 +119,8 @@ int forcelegacy = 0;
int noecc = 0;
int pad = 0;
int blockalign = 1; /*default to using 16K block size */
+int filesize = 0;
+int from_stdin = 0;
void process_options (int argc, char *argv[])
{
@@ -125,7 +128,7 @@ void process_options (int argc, char *argv[])
for (;;) {
int option_index = 0;
- static const char *short_options = "ab:fjmnopqs:y";
+ static const char *short_options = "ab:fjmnopqs:yi:";
static const struct option long_options[] = {
{"help", no_argument, 0, 0},
{"version", no_argument, 0, 0},
@@ -140,6 +143,7 @@ void process_options (int argc, char *argv[])
{"quiet", no_argument, 0, 'q'},
{"start", required_argument, 0, 's'},
{"yaffs", no_argument, 0, 'y'},
+ {"file-size", required_argument, 0, 'i'},
{0, 0, 0, 0},
};
@@ -193,6 +197,9 @@ void process_options (int argc, char *argv[])
case 'b':
blockalign = atoi (optarg);
break;
+ case 'i':
+ filesize = atoi (optarg);
+ break;
case '?':
error = 1;
break;
@@ -204,6 +211,9 @@ void process_options (int argc, char *argv[])
mtd_device = argv[optind++];
img = argv[optind];
+
+ if(strcmp(img, "-") == 0)
+ from_stdin = 1;
}
/*
@@ -228,6 +238,12 @@ int main(int argc, char **argv)
exit(1);
}
+ /* Check if filesize is valid if reading from standard in */
+ if (from_stdin && filesize <= 0) {
+ fprintf(stderr, "File size has to be specified when reading from standard in.\n");
+ exit(1);
+ }
+
/* Open the device */
if ((fd = open(mtd_device, O_RDWR)) == -1) {
perror("open flash");
@@ -335,14 +351,22 @@ int main(int argc, char **argv)
oob.ptr = noecc ? oobreadbuf : oobbuf;
/* Open the input file */
- if ((ifd = open(img, O_RDONLY)) == -1) {
- perror("open input file");
- goto restoreoob;
+ if (!from_stdin) {
+ if ((ifd = open(img, O_RDONLY)) == -1) {
+ perror("open input file");
+ goto restoreoob;
+ }
}
+ else
+ ifd = STDIN_FILENO;
// get image length
- imglen = lseek(ifd, 0, SEEK_END);
- lseek (ifd, 0, SEEK_SET);
+ if (!from_stdin) {
+ imglen = lseek(ifd, 0, SEEK_END);
+ lseek (ifd, 0, SEEK_SET);
+ }
+ else
+ imglen = filesize;
pagelen = meminfo.writesize + ((writeoob == 1) ? meminfo.oobsize : 0);
--
1.5.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] [MTD-UTILS] nandwrite: read from stdin support
2008-09-02 9:04 [PATCH] [MTD-UTILS] nandwrite: read from stdin support Tommi Airikka
@ 2008-09-02 10:54 ` Artem Bityutskiy
2008-09-02 16:21 ` Grant Erickson
1 sibling, 0 replies; 3+ messages in thread
From: Artem Bityutskiy @ 2008-09-02 10:54 UTC (permalink / raw)
To: Tommi Airikka; +Cc: linux-mtd
On Tue, 2008-09-02 at 11:04 +0200, Tommi Airikka wrote:
> Here is a patch that adds read from stdin support for nandwrite.
> I have tried it with 'cat filename.jffs2 | nandwrite -i filesize -p
> /dev/mtdX -'
> and it did work.
Looks OK for me, but I would rather call stdin "Standard input", not
"Standard in", as you call it in the help output and in the comments.
Also, it would be better to send the patch in-line, not as an
attachment.
--
Best regards,
Artem Bityutskiy (Битюцкий Артём)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [MTD-UTILS] nandwrite: read from stdin support
2008-09-02 9:04 [PATCH] [MTD-UTILS] nandwrite: read from stdin support Tommi Airikka
2008-09-02 10:54 ` Artem Bityutskiy
@ 2008-09-02 16:21 ` Grant Erickson
1 sibling, 0 replies; 3+ messages in thread
From: Grant Erickson @ 2008-09-02 16:21 UTC (permalink / raw)
To: Tommi Airikka; +Cc: linux-mtd
On 9/2/08 2:04 AM, Tommi Airikka wrote:
> Here is a patch that adds read from stdin support for nandwrite.
> I have tried it with 'cat filename.jffs2 | nandwrite -i filesize -p
> /dev/mtdX -' and it did work.
Tommi:
Thank you for this patch. Your timing is perfect since I had written about
precisely this feature a little over a week ago:
http://lists.infradead.org/pipermail/linux-mtd/2008-August/022556.html
If I can get my nanddump deblocking patch completed, the following should
work as a use case:
flash_eraseall -q <device-out>
nanddump -o -b -s <offset> -l <size> <device-in> | nandwrite -q -p -s
<offset> <device-out>
Regards,
Grant
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-09-02 16:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-02 9:04 [PATCH] [MTD-UTILS] nandwrite: read from stdin support Tommi Airikka
2008-09-02 10:54 ` Artem Bityutskiy
2008-09-02 16:21 ` Grant Erickson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox