summaryrefslogtreecommitdiff
path: root/common/cmd_md5sum.c
diff options
context:
space:
mode:
authorJoe Hershberger <joe.hershberger@ni.com>2012-08-17 11:00:48 +0000
committerTom Rini <trini@ti.com>2012-10-03 16:01:22 -0700
commitecd72950044f9bcc68ff0ef5b3dbda79dff31fd3 (patch)
tree0fab235116bfd81f29934e9e5bdd31b4dfa8b459 /common/cmd_md5sum.c
parent5ab177bede8c7efc76798a79e4a3b36ed38a7401 (diff)
downloadu-boot-imx-ecd72950044f9bcc68ff0ef5b3dbda79dff31fd3.zip
u-boot-imx-ecd72950044f9bcc68ff0ef5b3dbda79dff31fd3.tar.gz
u-boot-imx-ecd72950044f9bcc68ff0ef5b3dbda79dff31fd3.tar.bz2
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>
Diffstat (limited to 'common/cmd_md5sum.c')
-rw-r--r--common/cmd_md5sum.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/common/cmd_md5sum.c b/common/cmd_md5sum.c
index fbe0aba..3f81fdf 100644
--- a/common/cmd_md5sum.c
+++ b/common/cmd_md5sum.c
@@ -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