Commit ecd72950044f9bcc68ff0ef5b3dbda79dff31fd3

Authored by Joe Hershberger
Committed by Tom Rini
1 parent 5ab177bede

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>

Showing 1 changed file with 37 additions and 4 deletions Side-by-side Diff

... ... @@ -28,6 +28,32 @@
28 28 #include <command.h>
29 29 #include <u-boot/md5.h>
30 30  
  31 +/*
  32 + * Store the resulting sum to an address or variable
  33 + */
  34 +static void store_result(const u8 *sum, const char *dest)
  35 +{
  36 + unsigned int i;
  37 +
  38 + if (*dest == '*') {
  39 + u8 *ptr;
  40 +
  41 + ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16);
  42 + for (i = 0; i < 16; i++)
  43 + *ptr++ = sum[i];
  44 + } else {
  45 + char str_output[33];
  46 + char *str_ptr = str_output;
  47 +
  48 + for (i = 0; i < 16; i++) {
  49 + sprintf(str_ptr, "%02x", sum[i]);
  50 + str_ptr += 2;
  51 + }
  52 + str_ptr = '\0';
  53 + setenv(dest, str_output);
  54 + }
  55 +}
  56 +
31 57 #ifdef CONFIG_MD5SUM_VERIFY
32 58 static int parse_verify_sum(char *verify_str, u8 *vsum)
33 59 {
... ... @@ -94,6 +120,9 @@
94 120 for (i = 0; i < 16; i++)
95 121 printf("%02x", output[i]);
96 122 printf("\n");
  123 +
  124 + if (ac > 2)
  125 + store_result(output, *av);
97 126 } else {
98 127 char *verify_str = *av++;
99 128  
... ... @@ -136,6 +165,9 @@
136 165 printf("%02x", output[i]);
137 166 printf("\n");
138 167  
  168 + if (argc > 3)
  169 + store_result(output, argv[3]);
  170 +
139 171 return 0;
140 172 }
141 173 #endif
142 174  
143 175  
... ... @@ -144,16 +176,17 @@
144 176 U_BOOT_CMD(
145 177 md5sum, 5, 1, do_md5sum,
146 178 "compute MD5 message digest",
147   - "address count\n"
148   - " - compute MD5 message digest\n"
  179 + "address count [[*]sum]\n"
  180 + " - compute MD5 message digest [save to sum]\n"
149 181 "md5sum -v address count [*]sum\n"
150 182 " - verify md5sum of memory area"
151 183 );
152 184 #else
153 185 U_BOOT_CMD(
154   - md5sum, 3, 1, do_md5sum,
  186 + md5sum, 4, 1, do_md5sum,
155 187 "compute MD5 message digest",
156   - "address count"
  188 + "address count [[*]sum]\n"
  189 + " - compute MD5 message digest [save to sum]"
157 190 );
158 191 #endif