* [PATCH] commands/crc32: add compare 2 files crc
@ 2010-09-22 10:36 Jean-Christophe PLAGNIOL-VILLARD
2010-09-22 12:36 ` Sascha Hauer
0 siblings, 1 reply; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-22 10:36 UTC (permalink / raw)
To: barebox
add -F options to compare to file crc
it's usefull to compare what you flash in a partition
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
commands/crc.c | 103 ++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 66 insertions(+), 37 deletions(-)
diff --git a/commands/crc.c b/commands/crc.c
index 4842cdc..a2b8e78 100644
--- a/commands/crc.c
+++ b/commands/crc.c
@@ -30,20 +30,76 @@
#include <malloc.h>
#include <linux/ctype.h>
+static int file_crc(char* filename, ulong start, ulong size, ulong *crc,
+ ulong *total)
+{
+ int fd, now;
+ int ret = 0;
+ char *buf;
+
+ *total = 0;
+ *crc = 0;
+
+ fd = open(filename, O_RDONLY);
+ if (fd < 0) {
+ printf("open %s: %s\n", filename, errno_str());
+ return fd;
+ }
+
+ if (start > 0) {
+ ret = lseek(fd, start, SEEK_SET);
+ if (ret == -1) {
+ perror("lseek");
+ goto out;
+ }
+ }
+
+ buf = xmalloc(4096);
+
+ while (size) {
+ now = min((ulong)4096, size);
+ now = read(fd, buf, now);
+ if (now < 0) {
+ ret = now;
+ perror("read");
+ goto out_free;
+ }
+ if (!now)
+ break;
+ *crc = crc32(*crc, buf, now);
+ size -= now;
+ *total += now;
+ }
+
+ printf ("CRC32 for %s 0x%08lx ... 0x%08lx ==> 0x%08lx",
+ filename, start, start + *total - 1, *crc);
+
+out_free:
+ free(buf);
+out:
+ close(fd);
+
+ return ret;
+}
+
static int do_crc(struct command *cmdtp, int argc, char *argv[])
{
ulong start = 0, size = ~0, total = 0;
ulong crc = 0, vcrc = 0;
char *filename = "/dev/mem";
- char *buf;
- int fd, opt, err = 0, filegiven = 0, verify = 0, now;
+ char *vfilename = NULL;
+ int opt, err = 0, filegiven = 0, verify = 0;
- while((opt = getopt(argc, argv, "f:v:")) > 0) {
+ while((opt = getopt(argc, argv, "f:F:v:")) > 0) {
switch(opt) {
case 'f':
filename = optarg;
filegiven = 1;
break;
+ case 'F':
+ verify = 1;
+ vfilename = optarg;
+ break;
case 'v':
verify = 1;
vcrc = simple_strtoul(optarg, NULL, 0);
@@ -61,39 +117,16 @@ static int do_crc(struct command *cmdtp, int argc, char *argv[])
}
}
- fd = open(filename, O_RDONLY);
- if (fd < 0) {
- printf("open %s: %s\n", filename, errno_str());
+ if (file_crc(filename, start, size, &crc, &total) < 0)
return 1;
- }
- if (start > 0) {
- if (lseek(fd, start, SEEK_SET) == -1) {
- perror("lseek");
- err = 1;
- goto out;
- }
- }
-
- buf = xmalloc(4096);
-
- while (size) {
- now = min((ulong)4096, size);
- now = read(fd, buf, now);
- if (now < 0) {
- perror("read");
- goto out_free;
- }
- if (!now)
- break;
- crc = crc32(crc, buf, now);
- size -= now;
- total += now;
+ if (vfilename) {
+ size = total;
+ puts("\n");
+ if (file_crc(vfilename, start, size, &vcrc, &total) < 0)
+ return 1;
}
- printf ("CRC32 for %s 0x%08lx ... 0x%08lx ==> 0x%08lx",
- filename, start, start + total - 1, crc);
-
if (verify && crc != vcrc) {
printf(" != 0x%08x ** ERROR **", vcrc);
err = 1;
@@ -101,11 +134,6 @@ static int do_crc(struct command *cmdtp, int argc, char *argv[])
printf("\n");
-out_free:
- free(buf);
-out:
- close(fd);
-
return err;
}
@@ -114,6 +142,7 @@ static const __maybe_unused char cmd_crc_help[] =
"Calculate a crc32 checksum of a memory area\n"
"Options:\n"
" -f <file> Use file instead of memory\n"
+" -F <file> Use file to compare\n"
" -v <crc> Verfify\n";
BAREBOX_CMD_START(crc32)
--
1.7.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] commands/crc32: add compare 2 files crc
2010-09-22 10:36 [PATCH] commands/crc32: add compare 2 files crc Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-22 12:36 ` Sascha Hauer
2010-09-22 13:12 ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-22 15:25 ` Peter Korsgaard
0 siblings, 2 replies; 9+ messages in thread
From: Sascha Hauer @ 2010-09-22 12:36 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Wed, Sep 22, 2010 at 12:36:25PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> add -F options to compare to file crc
>
> it's usefull to compare what you flash in a partition
Why don't you use memcmp?
memcmp -s uImage -d /dev/nand0.kernel.bb 0 0
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] commands/crc32: add compare 2 files crc
2010-09-22 12:36 ` Sascha Hauer
@ 2010-09-22 13:12 ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-22 15:25 ` Peter Korsgaard
1 sibling, 0 replies; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-22 13:12 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 14:36 Wed 22 Sep , Sascha Hauer wrote:
> On Wed, Sep 22, 2010 at 12:36:25PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > add -F options to compare to file crc
> >
> > it's usefull to compare what you flash in a partition
>
> Why don't you use memcmp?
why not crc as I want to check the crc of the file on the host too
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] commands/crc32: add compare 2 files crc
2010-09-22 12:36 ` Sascha Hauer
2010-09-22 13:12 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-22 15:25 ` Peter Korsgaard
2010-09-22 16:08 ` Sascha Hauer
1 sibling, 1 reply; 9+ messages in thread
From: Peter Korsgaard @ 2010-09-22 15:25 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
>>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
Sascha> On Wed, Sep 22, 2010 at 12:36:25PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
>> add -F options to compare to file crc
>>
>> it's usefull to compare what you flash in a partition
Sascha> Why don't you use memcmp?
Sascha> memcmp -s uImage -d /dev/nand0.kernel.bb 0 0
It's sometimes interesting to be able to compare a checksum with a file
on the host (E.G. output of cksum/md5sum/sha1sum/..)
--
Bye, Peter Korsgaard
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] commands/crc32: add compare 2 files crc
2010-09-22 15:25 ` Peter Korsgaard
@ 2010-09-22 16:08 ` Sascha Hauer
2010-09-22 16:12 ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-22 19:09 ` Peter Korsgaard
0 siblings, 2 replies; 9+ messages in thread
From: Sascha Hauer @ 2010-09-22 16:08 UTC (permalink / raw)
To: Peter Korsgaard; +Cc: barebox
On Wed, Sep 22, 2010 at 05:25:49PM +0200, Peter Korsgaard wrote:
> >>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
>
> Sascha> On Wed, Sep 22, 2010 at 12:36:25PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> >> add -F options to compare to file crc
> >>
> >> it's usefull to compare what you flash in a partition
>
> Sascha> Why don't you use memcmp?
>
> Sascha> memcmp -s uImage -d /dev/nand0.kernel.bb 0 0
>
> It's sometimes interesting to be able to compare a checksum with a file
> on the host (E.G. output of cksum/md5sum/sha1sum/..)
crc32 can output the crc checksum of a file using the -f option. What
Jean-Christophe added is an option to calculate the checksum of two
files (one given with -f and the other with -F). I just fail to see why
this must be done in a single step instead of using a crc32 followed by
a memcmp.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] commands/crc32: add compare 2 files crc
2010-09-22 16:08 ` Sascha Hauer
@ 2010-09-22 16:12 ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-22 16:54 ` Sascha Hauer
2010-09-22 19:09 ` Peter Korsgaard
1 sibling, 1 reply; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-22 16:12 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 18:08 Wed 22 Sep , Sascha Hauer wrote:
> On Wed, Sep 22, 2010 at 05:25:49PM +0200, Peter Korsgaard wrote:
> > >>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
> >
> > Sascha> On Wed, Sep 22, 2010 at 12:36:25PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > >> add -F options to compare to file crc
> > >>
> > >> it's usefull to compare what you flash in a partition
> >
> > Sascha> Why don't you use memcmp?
> >
> > Sascha> memcmp -s uImage -d /dev/nand0.kernel.bb 0 0
> >
> > It's sometimes interesting to be able to compare a checksum with a file
> > on the host (E.G. output of cksum/md5sum/sha1sum/..)
>
> crc32 can output the crc checksum of a file using the -f option. What
> Jean-Christophe added is an option to calculate the checksum of two
> files (one given with -f and the other with -F). I just fail to see why
> this must be done in a single step instead of using a crc32 followed by
> a memcmp.
it's faster btw
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] commands/crc32: add compare 2 files crc
2010-09-22 16:12 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-22 16:54 ` Sascha Hauer
2010-09-23 11:25 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 1 reply; 9+ messages in thread
From: Sascha Hauer @ 2010-09-22 16:54 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Wed, Sep 22, 2010 at 06:12:18PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 18:08 Wed 22 Sep , Sascha Hauer wrote:
> > On Wed, Sep 22, 2010 at 05:25:49PM +0200, Peter Korsgaard wrote:
> > > >>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
> > >
> > > Sascha> On Wed, Sep 22, 2010 at 12:36:25PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > >> add -F options to compare to file crc
> > > >>
> > > >> it's usefull to compare what you flash in a partition
> > >
> > > Sascha> Why don't you use memcmp?
> > >
> > > Sascha> memcmp -s uImage -d /dev/nand0.kernel.bb 0 0
> > >
> > > It's sometimes interesting to be able to compare a checksum with a file
> > > on the host (E.G. output of cksum/md5sum/sha1sum/..)
> >
> > crc32 can output the crc checksum of a file using the -f option. What
> > Jean-Christophe added is an option to calculate the checksum of two
> > files (one given with -f and the other with -F). I just fail to see why
> > this must be done in a single step instead of using a crc32 followed by
> > a memcmp.
> it's faster btw
Yes, that's the remaining argument, so this should be the selling point
for this patch?
btw, does the patch handle the case when the partition is bigger than
the image file?
I would also write the image file directly to the flash instead of
transfering it to RAM and then copy it to flash. That should be even
faster.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] commands/crc32: add compare 2 files crc
2010-09-22 16:54 ` Sascha Hauer
@ 2010-09-23 11:25 ` Jean-Christophe PLAGNIOL-VILLARD
0 siblings, 0 replies; 9+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2010-09-23 11:25 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 18:54 Wed 22 Sep , Sascha Hauer wrote:
> On Wed, Sep 22, 2010 at 06:12:18PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 18:08 Wed 22 Sep , Sascha Hauer wrote:
> > > On Wed, Sep 22, 2010 at 05:25:49PM +0200, Peter Korsgaard wrote:
> > > > >>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
> > > >
> > > > Sascha> On Wed, Sep 22, 2010 at 12:36:25PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > > >> add -F options to compare to file crc
> > > > >>
> > > > >> it's usefull to compare what you flash in a partition
> > > >
> > > > Sascha> Why don't you use memcmp?
> > > >
> > > > Sascha> memcmp -s uImage -d /dev/nand0.kernel.bb 0 0
> > > >
> > > > It's sometimes interesting to be able to compare a checksum with a file
> > > > on the host (E.G. output of cksum/md5sum/sha1sum/..)
> > >
> > > crc32 can output the crc checksum of a file using the -f option. What
> > > Jean-Christophe added is an option to calculate the checksum of two
> > > files (one given with -f and the other with -F). I just fail to see why
> > > this must be done in a single step instead of using a crc32 followed by
> > > a memcmp.
> > it's faster btw
>
> Yes, that's the remaining argument, so this should be the selling point
> for this patch?
yes
>
> btw, does the patch handle the case when the partition is bigger than
> the image file?
yes
>
> I would also write the image file directly to the flash instead of
> transfering it to RAM and then copy it to flash. That should be even
> faster.
here we just do a crc32 but we could integrate it in the tftp & co to as check
in a second step
Best Regards,
J.
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] commands/crc32: add compare 2 files crc
2010-09-22 16:08 ` Sascha Hauer
2010-09-22 16:12 ` Jean-Christophe PLAGNIOL-VILLARD
@ 2010-09-22 19:09 ` Peter Korsgaard
1 sibling, 0 replies; 9+ messages in thread
From: Peter Korsgaard @ 2010-09-22 19:09 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
>>>>> "Sascha" == Sascha Hauer <s.hauer@pengutronix.de> writes:
>> It's sometimes interesting to be able to compare a checksum with a
>> file on the host (E.G. output of cksum/md5sum/sha1sum/..)
Sascha> crc32 can output the crc checksum of a file using the -f
Sascha> option. What Jean-Christophe added is an option to calculate
Sascha> the checksum of two files (one given with -f and the other with
Sascha> -F). I just fail to see why this must be done in a single step
Sascha> instead of using a crc32 followed by a memcmp.
Ahh, ok - Then I don't see any reason for it.
--
Bye, Peter Korsgaard
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-09-23 11:27 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-22 10:36 [PATCH] commands/crc32: add compare 2 files crc Jean-Christophe PLAGNIOL-VILLARD
2010-09-22 12:36 ` Sascha Hauer
2010-09-22 13:12 ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-22 15:25 ` Peter Korsgaard
2010-09-22 16:08 ` Sascha Hauer
2010-09-22 16:12 ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-22 16:54 ` Sascha Hauer
2010-09-23 11:25 ` Jean-Christophe PLAGNIOL-VILLARD
2010-09-22 19:09 ` Peter Korsgaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox