[U-Boot] [PATCH 4/4] Add parameter to md5sum to save the md5 sum

Joe Hershberger joe.hershberger at ni.com
Fri Aug 17 23:00:48 CEST 2012


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 at ni.com>
---
 common/cmd_md5sum.c | 41 +++++++++++++++++++++++++++++++++++++----
 1 file 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
-- 
1.7.11.5



More information about the U-Boot mailing list