blob: ded3f9e1831413c0dbc33e77826841052b30953e [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 Hershbergercd39f642012-08-17 11:00:47 +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
Mike Frysingera2274902011-04-02 21:40:19 -040010#include <command.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060012#include <image.h>
Igor Opaniuk489a5782024-03-02 16:05:48 +010013#include <hash.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050014#include <mapmem.h>
Mike Frysingera2274902011-04-02 21:40:19 -040015#include <u-boot/md5.h>
Suriyan Ramasami95bfacb2014-11-17 14:39:34 -080016#include <asm/io.h>
Mike Frysingera2274902011-04-02 21:40:19 -040017
Igor Opaniuk489a5782024-03-02 16:05:48 +010018static int do_md5sum(struct cmd_tbl *cmdtp, int flag, int argc,
19 char *const argv[])
Joe Hershbergercd39f642012-08-17 11:00:47 +000020{
Igor Opaniuk489a5782024-03-02 16:05:48 +010021 int flags = HASH_FLAG_ENV;
Joe Hershbergercd39f642012-08-17 11:00:47 +000022 int ac;
Igor Opaniuk489a5782024-03-02 16:05:48 +010023 char *const *av;
Joe Hershbergercd39f642012-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 Opaniuk489a5782024-03-02 16:05:48 +010030 if (IS_ENABLED(CONFIG_MD5SUM_VERIFY) && strcmp(*av, "-v") == 0) {
31 flags |= HASH_FLAG_VERIFY;
Joe Hershbergercd39f642012-08-17 11:00:47 +000032 av++;
33 ac--;
Joe Hershbergercd39f642012-08-17 11:00:47 +000034 }
35
Igor Opaniuk489a5782024-03-02 16:05:48 +010036 return hash_command("md5", flags, cmdtp, flag, ac, av);
Mike Frysingera2274902011-04-02 21:40:19 -040037}
38
Igor Opaniuk489a5782024-03-02 16:05:48 +010039#if IS_ENABLED(CONFIG_MD5SUM_VERIFY)
Joe Hershbergercd39f642012-08-17 11:00:47 +000040U_BOOT_CMD(
41 md5sum, 5, 1, do_md5sum,
42 "compute MD5 message digest",
Joe Hershberger47685cf2012-08-17 11:00:48 +000043 "address count [[*]sum]\n"
44 " - compute MD5 message digest [save to sum]\n"
Joe Hershbergercd39f642012-08-17 11:00:47 +000045 "md5sum -v address count [*]sum\n"
46 " - verify md5sum of memory area"
47);
48#else
Mike Frysingera2274902011-04-02 21:40:19 -040049U_BOOT_CMD(
Joe Hershberger47685cf2012-08-17 11:00:48 +000050 md5sum, 4, 1, do_md5sum,
Mike Frysingera2274902011-04-02 21:40:19 -040051 "compute MD5 message digest",
Joe Hershberger47685cf2012-08-17 11:00:48 +000052 "address count [[*]sum]\n"
53 " - compute MD5 message digest [save to sum]"
Mike Frysingera2274902011-04-02 21:40:19 -040054);
Igor Opaniuk489a5782024-03-02 16:05:48 +010055#endif /* IS_ENABLED(CONFIG_MD5SUM_VERIFY) */