Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The Chromium OS Authors. |
| 3 | * |
| 4 | * (C) Copyright 2011 |
| 5 | * Joe Hershberger, National Instruments, joe.hershberger@ni.com |
| 6 | * |
| 7 | * (C) Copyright 2000 |
| 8 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 9 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <command.h> |
| 15 | #include <hash.h> |
Simon Glass | e22a6fc | 2013-02-24 17:33:32 +0000 | [diff] [blame] | 16 | #include <linux/ctype.h> |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 17 | |
| 18 | static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 19 | { |
Simon Glass | e22a6fc | 2013-02-24 17:33:32 +0000 | [diff] [blame] | 20 | char *s; |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 21 | int flags = HASH_FLAG_ENV; |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 22 | |
Nikolay Dimitrov | 810b84d | 2014-12-12 20:01:23 +0200 | [diff] [blame] | 23 | #ifdef CONFIG_HASH_VERIFY |
Simon Glass | 20bc72a | 2013-02-24 17:33:11 +0000 | [diff] [blame] | 24 | if (argc < 4) |
| 25 | return CMD_RET_USAGE; |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 26 | if (!strcmp(argv[1], "-v")) { |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 27 | flags |= HASH_FLAG_VERIFY; |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 28 | argc--; |
| 29 | argv++; |
| 30 | } |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 31 | #endif |
| 32 | /* Move forward to 'algorithm' parameter */ |
| 33 | argc--; |
| 34 | argv++; |
Simon Glass | e22a6fc | 2013-02-24 17:33:32 +0000 | [diff] [blame] | 35 | for (s = *argv; *s; s++) |
| 36 | *s = tolower(*s); |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 37 | return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1); |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | #ifdef CONFIG_HASH_VERIFY |
Nikolay Dimitrov | 810b84d | 2014-12-12 20:01:23 +0200 | [diff] [blame] | 41 | #define HARGS 6 |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 42 | #else |
Nikolay Dimitrov | 810b84d | 2014-12-12 20:01:23 +0200 | [diff] [blame] | 43 | #define HARGS 5 |
| 44 | #endif |
| 45 | |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 46 | U_BOOT_CMD( |
Nikolay Dimitrov | 810b84d | 2014-12-12 20:01:23 +0200 | [diff] [blame] | 47 | hash, HARGS, 1, do_hash, |
| 48 | "compute hash message digest", |
| 49 | "algorithm address count [[*]hash_dest]\n" |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 50 | " - compute message digest [save to env var / *address]" |
Nikolay Dimitrov | 810b84d | 2014-12-12 20:01:23 +0200 | [diff] [blame] | 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" |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 55 | #endif |
Nikolay Dimitrov | 810b84d | 2014-12-12 20:01:23 +0200 | [diff] [blame] | 56 | ); |