mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-08 10:39:08 +00:00
Roll crc32 into hash infrastructure
Add the CRC32 algorithm to the list of available hashes, and make the crc32 command use hash_command(). Add a new crc32_wd_buf() to make this possible, which puts its result in a buffer rather than returning it as a 32-bit value. Note: For some boards the hash command is not enabled, neither are sha1, sha256 or the verify option. In this case the full hash implementation adds about 500 bytes of overhead. So as a special case, we use #ifdef to select very simple bahaviour in that case. The justification for this is that it is currently a very common case (virtually all boards enable crc32 but only some enable more advanced features). Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
d5b76673a5
commit
d20a40de9d
5 changed files with 115 additions and 114 deletions
|
@ -32,6 +32,7 @@
|
|||
#ifdef CONFIG_HAS_DATAFLASH
|
||||
#include <dataflash.h>
|
||||
#endif
|
||||
#include <hash.h>
|
||||
#include <watchdog.h>
|
||||
#include <asm/io.h>
|
||||
#include <linux/compiler.h>
|
||||
|
@ -1098,89 +1099,27 @@ mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
|
|||
|
||||
#ifdef CONFIG_CMD_CRC32
|
||||
|
||||
#ifndef CONFIG_CRC32_VERIFY
|
||||
|
||||
static int do_mem_crc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||
{
|
||||
ulong addr, length;
|
||||
ulong crc;
|
||||
ulong *ptr;
|
||||
int flags = 0;
|
||||
int ac;
|
||||
char * const *av;
|
||||
|
||||
if (argc < 3)
|
||||
return CMD_RET_USAGE;
|
||||
|
||||
addr = simple_strtoul (argv[1], NULL, 16);
|
||||
addr += base_address;
|
||||
|
||||
length = simple_strtoul (argv[2], NULL, 16);
|
||||
|
||||
crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
|
||||
|
||||
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 * const argv[])
|
||||
{
|
||||
ulong addr, length;
|
||||
ulong crc;
|
||||
ulong *ptr;
|
||||
ulong vcrc;
|
||||
int verify;
|
||||
int ac;
|
||||
char * const *av;
|
||||
|
||||
if (argc < 3) {
|
||||
usage:
|
||||
return CMD_RET_USAGE;
|
||||
}
|
||||
|
||||
av = argv + 1;
|
||||
ac = argc - 1;
|
||||
#ifdef CONFIG_HASH_VERIFY
|
||||
if (strcmp(*av, "-v") == 0) {
|
||||
verify = 1;
|
||||
flags |= HASH_FLAG_VERIFY;
|
||||
av++;
|
||||
ac--;
|
||||
if (ac < 3)
|
||||
goto usage;
|
||||
} else
|
||||
verify = 0;
|
||||
|
||||
addr = simple_strtoul(*av++, NULL, 16);
|
||||
addr += base_address;
|
||||
length = simple_strtoul(*av++, NULL, 16);
|
||||
|
||||
crc = crc32_wd (0, (const uchar *) addr, length, CHUNKSZ_CRC32);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
return hash_command("crc32", flags, cmdtp, flag, ac, av);
|
||||
}
|
||||
#endif /* CONFIG_CRC32_VERIFY */
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue