2 * crc.c - Calculate a crc32 checksum of a memory area
4 * Copyright (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include <linux/ctype.h>
33 static int do_crc (cmd_tbl_t
*cmdtp
, int argc
, char *argv
[])
35 ulong start
= 0, size
= ~0, total
= 0;
36 ulong crc
= 0, vcrc
= 0;
37 char *filename
= "/dev/mem";
39 int fd
, opt
, err
= 0, filegiven
= 0, verify
= 0, now
;
41 while((opt
= getopt(argc
, argv
, "f:v:")) > 0) {
49 vcrc
= simple_strtoul(optarg
, NULL
, 0);
54 if (!filegiven
&& optind
== argc
)
55 return COMMAND_ERROR_USAGE
;
58 if (parse_area_spec(argv
[optind
], &start
, &size
)) {
59 printf("could not parse area description: %s\n", argv
[optind
]);
64 fd
= open(filename
, O_RDONLY
);
66 printf("open %s: %s\n", filename
, errno_str());
70 if (lseek(fd
, start
, SEEK_SET
) == -1) {
79 now
= min((ulong
)4096, size
);
80 now
= read(fd
, buf
, now
);
87 crc
= crc32(crc
, buf
, now
);
92 printf ("CRC32 for %s 0x%08lx ... 0x%08lx ==> 0x%08lx",
93 filename
, start
, start
+ total
- 1, crc
);
95 if (verify
&& crc
!= vcrc
) {
96 printf(" != 0x%08x ** ERROR **", vcrc
);
110 static const __maybe_unused
char cmd_crc_help
[] =
111 "Usage: crc32 [OPTION] [AREA]\n"
112 "Calculate a crc32 checksum of a memory area\n"
114 " -f <file> Use file instead of memory\n"
115 " -v <crc> Verfify\n";
117 U_BOOT_CMD_START(crc32
)
119 .usage
= "crc32 checksum calculation",
120 U_BOOT_CMD_HELP(cmd_crc_help
)