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 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <common.h> |
| 27 | #include <command.h> |
| 28 | #include <hash.h> |
Simon Glass | e22a6fc | 2013-02-24 17:33:32 +0000 | [diff] [blame^] | 29 | #include <linux/ctype.h> |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 30 | |
| 31 | static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 32 | { |
Simon Glass | e22a6fc | 2013-02-24 17:33:32 +0000 | [diff] [blame^] | 33 | char *s; |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 34 | #ifdef CONFIG_HASH_VERIFY |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 35 | int flags = HASH_FLAG_ENV; |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 36 | |
Simon Glass | 20bc72a | 2013-02-24 17:33:11 +0000 | [diff] [blame] | 37 | if (argc < 4) |
| 38 | return CMD_RET_USAGE; |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 39 | if (!strcmp(argv[1], "-v")) { |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 40 | flags |= HASH_FLAG_VERIFY; |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 41 | argc--; |
| 42 | argv++; |
| 43 | } |
Simon Glass | 20bc72a | 2013-02-24 17:33:11 +0000 | [diff] [blame] | 44 | #else |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 45 | const int flags = HASH_FLAG_ENV; |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 46 | #endif |
| 47 | /* Move forward to 'algorithm' parameter */ |
| 48 | argc--; |
| 49 | argv++; |
Simon Glass | e22a6fc | 2013-02-24 17:33:32 +0000 | [diff] [blame^] | 50 | for (s = *argv; *s; s++) |
| 51 | *s = tolower(*s); |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 52 | return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1); |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | #ifdef CONFIG_HASH_VERIFY |
| 56 | U_BOOT_CMD( |
| 57 | hash, 6, 1, do_hash, |
| 58 | "compute hash message digest", |
| 59 | "algorithm address count [[*]sum_dest]\n" |
| 60 | " - compute message digest [save to env var / *address]\n" |
| 61 | "hash -v algorithm address count [*]sum\n" |
| 62 | " - verify hash of memory area with env var / *address" |
| 63 | ); |
| 64 | #else |
| 65 | U_BOOT_CMD( |
| 66 | hash, 5, 1, do_hash, |
| 67 | "compute message digest", |
| 68 | "algorithm address count [[*]sum_dest]\n" |
| 69 | " - compute message digest [save to env var / *address]" |
| 70 | ); |
| 71 | #endif |