Commit 3ef46a998a2f2c52e227246ac0438ca048ddfd09

Authored by Nikolay Dimitrov
Committed by Tom Rini
1 parent d210718d9a

Fix hash verification

Fix issue in parse_verify_sum() which swaps handling of env-var and *address.
Move hash_command() argc check earlier.
Cosmetic change on do_hash() variable declaration.
Improved help message for "hash" command.

Signed-off-by: Nikolay Dimitrov <picmaster@mail.bg>
Reviewed-by: Simon Glass <sjg@chromium.org>

Showing 2 changed files with 15 additions and 19 deletions Side-by-side Diff

... ... @@ -18,9 +18,9 @@
18 18 static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
19 19 {
20 20 char *s;
21   -#ifdef CONFIG_HASH_VERIFY
22 21 int flags = HASH_FLAG_ENV;
23 22  
  23 +#ifdef CONFIG_HASH_VERIFY
24 24 if (argc < 4)
25 25 return CMD_RET_USAGE;
26 26 if (!strcmp(argv[1], "-v")) {
... ... @@ -28,8 +28,6 @@
28 28 argc--;
29 29 argv++;
30 30 }
31   -#else
32   - const int flags = HASH_FLAG_ENV;
33 31 #endif
34 32 /* Move forward to 'algorithm' parameter */
35 33 argc--;
36 34  
37 35  
38 36  
39 37  
... ... @@ -40,20 +38,20 @@
40 38 }
41 39  
42 40 #ifdef CONFIG_HASH_VERIFY
43   -U_BOOT_CMD(
44   - hash, 6, 1, do_hash,
45   - "compute hash message digest",
46   - "algorithm address count [[*]sum_dest]\n"
47   - " - compute message digest [save to env var / *address]\n"
48   - "hash -v algorithm address count [*]sum\n"
49   - " - verify hash of memory area with env var / *address"
50   -);
  41 +#define HARGS 6
51 42 #else
  43 +#define HARGS 5
  44 +#endif
  45 +
52 46 U_BOOT_CMD(
53   - hash, 5, 1, do_hash,
54   - "compute message digest",
55   - "algorithm address count [[*]sum_dest]\n"
  47 + hash, HARGS, 1, do_hash,
  48 + "compute hash message digest",
  49 + "algorithm address count [[*]hash_dest]\n"
56 50 " - compute message digest [save to env var / *address]"
57   -);
  51 +#ifdef CONFIG_HASH_VERIFY
  52 + "\nhash -v algorithm address count [*]hash\n"
  53 + " - verify message digest of memory area to immediate value, \n"
  54 + " env var or *address"
58 55 #endif
  56 +);
... ... @@ -256,7 +256,7 @@
256 256 env_var = 1;
257 257 }
258 258  
259   - if (env_var) {
  259 + if (!env_var) {
260 260 ulong addr;
261 261 void *buf;
262 262  
... ... @@ -347,7 +347,7 @@
347 347 {
348 348 ulong addr, len;
349 349  
350   - if (argc < 2)
  350 + if ((argc < 2) || ((flags & HASH_FLAG_VERIFY) && (argc < 3)))
351 351 return CMD_RET_USAGE;
352 352  
353 353 addr = simple_strtoul(*argv++, NULL, 16);
... ... @@ -380,8 +380,6 @@
380 380 #else
381 381 if (0) {
382 382 #endif
383   - if (!argc)
384   - return CMD_RET_USAGE;
385 383 if (parse_verify_sum(algo, *argv, vsum,
386 384 flags & HASH_FLAG_ENV)) {
387 385 printf("ERROR: %s does not contain a valid "