Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2012 The Chromium OS Authors. |
| 4 | * |
| 5 | * (C) Copyright 2011 |
| 6 | * Joe Hershberger, National Instruments, joe.hershberger@ni.com |
| 7 | * |
| 8 | * (C) Copyright 2000 |
| 9 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 12 | #include <command.h> |
| 13 | #include <hash.h> |
Simon Glass | e22a6fc | 2013-02-24 17:33:32 +0000 | [diff] [blame] | 14 | #include <linux/ctype.h> |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 15 | |
Igor Opaniuk | 1eb0c62 | 2024-02-07 01:01:32 +0100 | [diff] [blame] | 16 | #if IS_ENABLED(CONFIG_HASH_VERIFY) |
| 17 | #define HARGS 6 |
| 18 | #else |
| 19 | #define HARGS 5 |
| 20 | #endif |
| 21 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 22 | static int do_hash(struct cmd_tbl *cmdtp, int flag, int argc, |
| 23 | char *const argv[]) |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 24 | { |
Simon Glass | e22a6fc | 2013-02-24 17:33:32 +0000 | [diff] [blame] | 25 | char *s; |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 26 | int flags = HASH_FLAG_ENV; |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 27 | |
Igor Opaniuk | 1eb0c62 | 2024-02-07 01:01:32 +0100 | [diff] [blame] | 28 | if (argc < (HARGS - 1)) |
Simon Glass | 20bc72a | 2013-02-24 17:33:11 +0000 | [diff] [blame] | 29 | return CMD_RET_USAGE; |
Igor Opaniuk | 1eb0c62 | 2024-02-07 01:01:32 +0100 | [diff] [blame] | 30 | |
| 31 | #if IS_ENABLED(CONFIG_HASH_VERIFY) |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 32 | if (!strcmp(argv[1], "-v")) { |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 33 | flags |= HASH_FLAG_VERIFY; |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 34 | argc--; |
| 35 | argv++; |
| 36 | } |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 37 | #endif |
| 38 | /* Move forward to 'algorithm' parameter */ |
| 39 | argc--; |
| 40 | argv++; |
Simon Glass | e22a6fc | 2013-02-24 17:33:32 +0000 | [diff] [blame] | 41 | for (s = *argv; *s; s++) |
| 42 | *s = tolower(*s); |
Simon Glass | 80e345a | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 43 | return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1); |
Simon Glass | 058bb8d | 2012-12-05 14:46:38 +0000 | [diff] [blame] | 44 | } |
| 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]" |
Igor Opaniuk | 1eb0c62 | 2024-02-07 01:01:32 +0100 | [diff] [blame] | 51 | #if IS_ENABLED(CONFIG_HASH_VERIFY) |
Nikolay Dimitrov | 810b84d | 2014-12-12 20:01:23 +0200 | [diff] [blame] | 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 | ); |