]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
Add parameter to md5sum to save the md5 sum
authorJoe Hershberger <joe.hershberger@ni.com>
Fri, 17 Aug 2012 11:00:48 +0000 (11:00 +0000)
committerTom Rini <trini@ti.com>
Wed, 3 Oct 2012 23:01:22 +0000 (16:01 -0700)
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>
common/cmd_md5sum.c

index fbe0aba84159bc14702087b9034e6624677689f1..3f81fdf6ef25bd3631baa86359b0256c78cfe767 100644 (file)
 #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