Add parameter to md5sum to save the md5 sum

Add a parameter that allows you to store the md5 sum to either a
memory location or a variable.

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
This commit is contained in:
Joe Hershberger 2012-08-17 11:00:48 +00:00 committed by Tom Rini
parent 5ab177bede
commit ecd7295004
1 changed files with 37 additions and 4 deletions

View File

@ -28,6 +28,32 @@
#include <command.h>
#include <u-boot/md5.h>
/*
* Store the resulting sum to an address or variable
*/
static void store_result(const u8 *sum, const char *dest)
{
unsigned int i;
if (*dest == '*') {
u8 *ptr;
ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16);
for (i = 0; i < 16; i++)
*ptr++ = sum[i];
} else {
char str_output[33];
char *str_ptr = str_output;
for (i = 0; i < 16; i++) {
sprintf(str_ptr, "%02x", sum[i]);
str_ptr += 2;
}
str_ptr = '\0';
setenv(dest, str_output);
}
}
#ifdef CONFIG_MD5SUM_VERIFY
static int parse_verify_sum(char *verify_str, u8 *vsum)
{
@ -94,6 +120,9 @@ int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
for (i = 0; i < 16; i++)
printf("%02x", output[i]);
printf("\n");
if (ac > 2)
store_result(output, *av);
} else {
char *verify_str = *av++;
@ -136,6 +165,9 @@ static int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
printf("%02x", output[i]);
printf("\n");
if (argc > 3)
store_result(output, argv[3]);
return 0;
}
#endif
@ -144,15 +176,16 @@ static int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
U_BOOT_CMD(
md5sum, 5, 1, do_md5sum,
"compute MD5 message digest",
"address count\n"
" - compute MD5 message digest\n"
"address count [[*]sum]\n"
" - compute MD5 message digest [save to sum]\n"
"md5sum -v address count [*]sum\n"
" - verify md5sum of memory area"
);
#else
U_BOOT_CMD(
md5sum, 3, 1, do_md5sum,
md5sum, 4, 1, do_md5sum,
"compute MD5 message digest",
"address count"
"address count [[*]sum]\n"
" - compute MD5 message digest [save to sum]"
);
#endif