From: Joe Hershberger Date: Fri, 17 Aug 2012 11:00:48 +0000 (+0000) Subject: Add parameter to md5sum to save the md5 sum X-Git-Tag: v2012.10-rc3~23 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ecd729500;p=u-boot 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 --- diff --git a/common/cmd_md5sum.c b/common/cmd_md5sum.c index fbe0aba841..3f81fdf6ef 100644 --- a/common/cmd_md5sum.c +++ b/common/cmd_md5sum.c @@ -28,6 +28,32 @@ #include #include +/* + * 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