blob: 3c50fc27ce875e289a74754ff6496c434cfb1b8d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mike Frysingera2274902011-04-02 21:40:19 -04002/*
Joe Hershbergerd4483122012-08-17 11:00:45 +00003 * (C) Copyright 2011
4 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
5 *
Mike Frysingera2274902011-04-02 21:40:19 -04006 * (C) Copyright 2000
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Mike Frysingera2274902011-04-02 21:40:19 -04008 */
9
10#include <common.h>
11#include <command.h>
Simon Glassff436e02012-12-05 14:46:37 +000012#include <hash.h>
Jeroen Hofsteebfe88fe2014-06-12 22:27:12 +020013#include <u-boot/sha1.h>
Mike Frysingera2274902011-04-02 21:40:19 -040014
Joe Hershbergerd4483122012-08-17 11:00:45 +000015int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
16{
Simon Glass80e345a2013-02-24 17:33:26 +000017 int flags = HASH_FLAG_ENV;
Joe Hershbergerd4483122012-08-17 11:00:45 +000018 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 Glassff436e02012-12-05 14:46:37 +000026#ifdef CONFIG_SHA1SUM_VERIFY
Joe Hershbergerd4483122012-08-17 11:00:45 +000027 if (strcmp(*av, "-v") == 0) {
Simon Glass80e345a2013-02-24 17:33:26 +000028 flags |= HASH_FLAG_VERIFY;
Joe Hershbergerd4483122012-08-17 11:00:45 +000029 av++;
30 ac--;
Joe Hershbergerd4483122012-08-17 11:00:45 +000031 }
Simon Glassff436e02012-12-05 14:46:37 +000032#endif
Joe Hershberger95e11082012-08-17 11:00:46 +000033
Simon Glass80e345a2013-02-24 17:33:26 +000034 return hash_command("sha1", flags, cmdtp, flag, ac, av);
Mike Frysingera2274902011-04-02 21:40:19 -040035}
36
Joe Hershbergerd4483122012-08-17 11:00:45 +000037#ifdef CONFIG_SHA1SUM_VERIFY
38U_BOOT_CMD(
39 sha1sum, 5, 1, do_sha1sum,
40 "compute SHA1 message digest",
Joe Hershberger95e11082012-08-17 11:00:46 +000041 "address count [[*]sum]\n"
42 " - compute SHA1 message digest [save to sum]\n"
Joe Hershbergerd4483122012-08-17 11:00:45 +000043 "sha1sum -v address count [*]sum\n"
44 " - verify sha1sum of memory area"
45);
46#else
Mike Frysingera2274902011-04-02 21:40:19 -040047U_BOOT_CMD(
Joe Hershberger95e11082012-08-17 11:00:46 +000048 sha1sum, 4, 1, do_sha1sum,
Mike Frysingera2274902011-04-02 21:40:19 -040049 "compute SHA1 message digest",
Joe Hershberger95e11082012-08-17 11:00:46 +000050 "address count [[*]sum]\n"
51 " - compute SHA1 message digest [save to sum]"
Mike Frysingera2274902011-04-02 21:40:19 -040052);
Joe Hershbergerd4483122012-08-17 11:00:45 +000053#endif