From 3c210e29cd9ae1b70fe89fd1d58574af4b079855 Mon Sep 17 00:00:00 2001 From: Joe Hershberger Date: Fri, 17 Aug 2012 11:00:46 +0000 Subject: [PATCH] Add parameter to sha1sum to save the SHA1 sum Add a parameter that allows you to store the SHA1 sum to either a memory location or a variable. Signed-off-by: Joe Hershberger --- common/cmd_sha1sum.c | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/common/cmd_sha1sum.c b/common/cmd_sha1sum.c index fbb99eaad1..8db5456c95 100644 --- a/common/cmd_sha1sum.c +++ b/common/cmd_sha1sum.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 < 20; i++) + *ptr++ = sum[i]; + } else { + char str_output[41]; + char *str_ptr = str_output; + + for (i = 0; i < 20; i++) { + sprintf(str_ptr, "%02x", sum[i]); + str_ptr += 2; + } + str_ptr = '\0'; + setenv(dest, str_output); + } +} + #ifdef CONFIG_SHA1SUM_VERIFY static int parse_verify_sum(char *verify_str, u8 *vsum) { @@ -94,6 +120,9 @@ int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) for (i = 0; i < 20; 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_sha1sum(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_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) U_BOOT_CMD( sha1sum, 5, 1, do_sha1sum, "compute SHA1 message digest", - "address count\n" - " - compute SHA1 message digest\n" + "address count [[*]sum]\n" + " - compute SHA1 message digest [save to sum]\n" "sha1sum -v address count [*]sum\n" " - verify sha1sum of memory area" ); #else U_BOOT_CMD( - sha1sum, 3, 1, do_sha1sum, + sha1sum, 4, 1, do_sha1sum, "compute SHA1 message digest", - "address count" + "address count [[*]sum]\n" + " - compute SHA1 message digest [save to sum]" ); #endif -- 2.25.1