blob: ded3f9e1831413c0dbc33e77826841052b30953e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Mike Frysingerc3d2a172011-04-02 21:40:19 -04002/*
Joe Hershberger5ab177b2012-08-17 11:00:47 +00003 * (C) Copyright 2011
4 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
5 *
Mike Frysingerc3d2a172011-04-02 21:40:19 -04006 * (C) Copyright 2000
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Mike Frysingerc3d2a172011-04-02 21:40:19 -04008 */
9
Mike Frysingerc3d2a172011-04-02 21:40:19 -040010#include <command.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060011#include <env.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060012#include <image.h>
Igor Opaniuk6ec3f922024-03-02 16:05:48 +010013#include <hash.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050014#include <mapmem.h>
Mike Frysingerc3d2a172011-04-02 21:40:19 -040015#include <u-boot/md5.h>
Suriyan Ramasami79444952014-11-17 14:39:34 -080016#include <asm/io.h>
Mike Frysingerc3d2a172011-04-02 21:40:19 -040017
Igor Opaniuk6ec3f922024-03-02 16:05:48 +010018static int do_md5sum(struct cmd_tbl *cmdtp, int flag, int argc,
19 char *const argv[])
Joe Hershbergerecd72952012-08-17 11:00:48 +000020{
Igor Opaniuk6ec3f922024-03-02 16:05:48 +010021 int flags = HASH_FLAG_ENV;
Joe Hershberger5ab177b2012-08-17 11:00:47 +000022 int ac;
Igor Opaniuk6ec3f922024-03-02 16:05:48 +010023 char *const *av;
Joe Hershberger5ab177b2012-08-17 11:00:47 +000024
25 if (argc < 3)
26 return CMD_RET_USAGE;
27
28 av = argv + 1;
29 ac = argc - 1;
Igor Opaniuk6ec3f922024-03-02 16:05:48 +010030 if (IS_ENABLED(CONFIG_MD5SUM_VERIFY) && strcmp(*av, "-v") == 0) {
31 flags |= HASH_FLAG_VERIFY;
Joe Hershberger5ab177b2012-08-17 11:00:47 +000032 av++;
33 ac--;
Joe Hershberger5ab177b2012-08-17 11:00:47 +000034 }
35
Igor Opaniuk6ec3f922024-03-02 16:05:48 +010036 return hash_command("md5", flags, cmdtp, flag, ac, av);
Joe Hershberger5ab177b2012-08-17 11:00:47 +000037}
Mike Frysingerc3d2a172011-04-02 21:40:19 -040038
Igor Opaniuk6ec3f922024-03-02 16:05:48 +010039#if IS_ENABLED(CONFIG_MD5SUM_VERIFY)
Joe Hershberger5ab177b2012-08-17 11:00:47 +000040U_BOOT_CMD(
41 md5sum, 5, 1, do_md5sum,
42 "compute MD5 message digest",
Joe Hershbergerecd72952012-08-17 11:00:48 +000043 "address count [[*]sum]\n"
44 " - compute MD5 message digest [save to sum]\n"
Joe Hershberger5ab177b2012-08-17 11:00:47 +000045 "md5sum -v address count [*]sum\n"
46 " - verify md5sum of memory area"
47);
48#else
Mike Frysingerc3d2a172011-04-02 21:40:19 -040049U_BOOT_CMD(
Joe Hershbergerecd72952012-08-17 11:00:48 +000050 md5sum, 4, 1, do_md5sum,
Mike Frysingerc3d2a172011-04-02 21:40:19 -040051 "compute MD5 message digest",
Joe Hershbergerecd72952012-08-17 11:00:48 +000052 "address count [[*]sum]\n"
53 " - compute MD5 message digest [save to sum]"
Mike Frysingerc3d2a172011-04-02 21:40:19 -040054);
Igor Opaniuk6ec3f922024-03-02 16:05:48 +010055#endif /* IS_ENABLED(CONFIG_MD5SUM_VERIFY) */