Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 2 | /* |
Joe Hershberger | e6e77d3 | 2012-08-17 11:00:45 +0000 | [diff] [blame] | 3 | * (C) Copyright 2011 |
| 4 | * Joe Hershberger, National Instruments, joe.hershberger@ni.com |
| 5 | * |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 6 | * (C) Copyright 2000 |
| 7 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <command.h> |
Simon Glass | e50b12c | 2012-12-05 14:46:37 +0000 | [diff] [blame] | 12 | #include <hash.h> |
Jeroen Hofstee | 2b9912e | 2014-06-12 22:27:12 +0200 | [diff] [blame] | 13 | #include <u-boot/sha1.h> |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 14 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 15 | int do_sha1sum(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Joe Hershberger | e6e77d3 | 2012-08-17 11:00:45 +0000 | [diff] [blame] | 16 | { |
Simon Glass | d5b7667 | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 17 | int flags = HASH_FLAG_ENV; |
Joe Hershberger | e6e77d3 | 2012-08-17 11:00:45 +0000 | [diff] [blame] | 18 | int ac; |
| 19 | char * const *av; |
| 20 | |
| 21 | if (argc < 3) |
| 22 | return CMD_RET_USAGE; |
| 23 | |
| 24 | av = argv + 1; |
| 25 | ac = argc - 1; |
Simon Glass | e50b12c | 2012-12-05 14:46:37 +0000 | [diff] [blame] | 26 | #ifdef CONFIG_SHA1SUM_VERIFY |
Joe Hershberger | e6e77d3 | 2012-08-17 11:00:45 +0000 | [diff] [blame] | 27 | if (strcmp(*av, "-v") == 0) { |
Simon Glass | d5b7667 | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 28 | flags |= HASH_FLAG_VERIFY; |
Joe Hershberger | e6e77d3 | 2012-08-17 11:00:45 +0000 | [diff] [blame] | 29 | av++; |
| 30 | ac--; |
Joe Hershberger | e6e77d3 | 2012-08-17 11:00:45 +0000 | [diff] [blame] | 31 | } |
Joe Hershberger | e6e77d3 | 2012-08-17 11:00:45 +0000 | [diff] [blame] | 32 | #endif |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 33 | |
Simon Glass | d5b7667 | 2013-02-24 17:33:26 +0000 | [diff] [blame] | 34 | return hash_command("sha1", flags, cmdtp, flag, ac, av); |
Simon Glass | e50b12c | 2012-12-05 14:46:37 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Joe Hershberger | e6e77d3 | 2012-08-17 11:00:45 +0000 | [diff] [blame] | 37 | #ifdef CONFIG_SHA1SUM_VERIFY |
| 38 | U_BOOT_CMD( |
| 39 | sha1sum, 5, 1, do_sha1sum, |
| 40 | "compute SHA1 message digest", |
Joe Hershberger | 3c210e2 | 2012-08-17 11:00:46 +0000 | [diff] [blame] | 41 | "address count [[*]sum]\n" |
| 42 | " - compute SHA1 message digest [save to sum]\n" |
Joe Hershberger | e6e77d3 | 2012-08-17 11:00:45 +0000 | [diff] [blame] | 43 | "sha1sum -v address count [*]sum\n" |
| 44 | " - verify sha1sum of memory area" |
| 45 | ); |
| 46 | #else |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 47 | U_BOOT_CMD( |
Joe Hershberger | 3c210e2 | 2012-08-17 11:00:46 +0000 | [diff] [blame] | 48 | sha1sum, 4, 1, do_sha1sum, |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 49 | "compute SHA1 message digest", |
Joe Hershberger | 3c210e2 | 2012-08-17 11:00:46 +0000 | [diff] [blame] | 50 | "address count [[*]sum]\n" |
| 51 | " - compute SHA1 message digest [save to sum]" |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 52 | ); |
Joe Hershberger | e6e77d3 | 2012-08-17 11:00:45 +0000 | [diff] [blame] | 53 | #endif |