From 5a7d4885100f23fb33d624dd047c6ea49c959300 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Thu, 5 Jul 2007 18:02:16 +0200 Subject: [PATCH] svn_rev_676 --- commands/Kconfig | 7 ++- commands/Makefile | 1 + commands/crc.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 commands/crc.c diff --git a/commands/Kconfig b/commands/Kconfig index 61ee8c549..c09a14e41 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -125,7 +125,12 @@ config CMD_MEMINFO config CMD_MEMORY bool - prompt "md, mm, mw and several others" + prompt "md and mw" + +config CMD_CRC + bool + select CRC32 + prompt "crc" config CMD_MTEST bool diff --git a/commands/Makefile b/commands/Makefile index e4c38c12e..733deb1b3 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -27,3 +27,4 @@ obj-$(CONFIG_CMD_CAT) += cat.o obj-$(CONFIG_CMD_MOUNT) += mount.o obj-$(CONFIG_CMD_UMOUNT) += umount.o obj-$(CONFIG_CMD_REGINFO) += reginfo.o +obj-$(CONFIG_CMD_CRC) += crc.o diff --git a/commands/crc.c b/commands/crc.c new file mode 100644 index 000000000..d4e3590fc --- /dev/null +++ b/commands/crc.c @@ -0,0 +1,107 @@ +#include +#include + +#ifndef CONFIG_CRC32_VERIFY + +int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + ulong addr, length; + ulong crc; + ulong *ptr; + + if (argc < 3) { + printf ("Usage:\n%s\n", cmdtp->usage); + return 1; + } + + addr = simple_strtoul (argv[1], NULL, 16); + + length = simple_strtoul (argv[2], NULL, 16); + + crc = crc32 (0, (const uchar *) addr, length); + + printf ("CRC32 for %08lx ... %08lx ==> %08lx\n", + addr, addr + length - 1, crc); + + if (argc > 3) { + ptr = (ulong *) simple_strtoul (argv[3], NULL, 16); + *ptr = crc; + } + + return 0; +} + +#else /* CONFIG_CRC32_VERIFY */ + +int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + ulong addr, length; + ulong crc; + ulong *ptr; + ulong vcrc; + int verify; + int ac; + char **av; + + if (argc < 3) { + usage: + printf ("Usage:\n%s\n", cmdtp->usage); + return 1; + } + + av = argv + 1; + ac = argc - 1; + if (strcmp(*av, "-v") == 0) { + verify = 1; + av++; + ac--; + if (ac < 3) + goto usage; + } else + verify = 0; + + addr = simple_strtoul(*av++, NULL, 16); + length = simple_strtoul(*av++, NULL, 16); + + crc = crc32(0, (const uchar *) addr, length); + + if (!verify) { + printf ("CRC32 for %08lx ... %08lx ==> %08lx\n", + addr, addr + length - 1, crc); + if (ac > 2) { + ptr = (ulong *) simple_strtoul (*av++, NULL, 16); + *ptr = crc; + } + } else { + vcrc = simple_strtoul(*av++, NULL, 16); + if (vcrc != crc) { + printf ("CRC32 for %08lx ... %08lx ==> %08lx != %08lx ** ERROR **\n", + addr, addr + length - 1, crc, vcrc); + return 1; + } + } + + return 0; + +} +#endif /* CONFIG_CRC32_VERIFY */ + +#ifndef CONFIG_CRC32_VERIFY + +U_BOOT_CMD_START(crc32) + .maxargs = 4, + .cmd = do_mem_crc, + .usage = "checksum calculation", + U_BOOT_CMD_HELP("address count [addr]\n - compute CRC32 checksum [save at addr]\n") +U_BOOT_CMD_END + +#else /* CONFIG_CRC32_VERIFY */ + +U_BOOT_CMD( + crc32, 5, 0, do_mem_crc, + "crc32 - checksum calculation\n", + "address count [addr]\n - compute CRC32 checksum [save at addr]\n" + "-v address count crc\n - verify crc of memory area\n" +); + +#endif /* CONFIG_CRC32_VERIFY */