1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2011
4 * Joe Hershberger, National Instruments, joe.hershberger@ni.com
5 *
6 * (C) Copyright 2000
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 */
9
10#include <command.h>
11#include <env.h>
12#include <image.h>
13#include <hash.h>
14#include <mapmem.h>
15#include <u-boot/md5.h>
16#include <asm/io.h>
17
18static int do_md5sum(struct cmd_tbl *cmdtp, int flag, int argc,
19		     char *const argv[])
20{
21	int flags = HASH_FLAG_ENV;
22	int ac;
23	char *const *av;
24
25	if (argc < 3)
26		return CMD_RET_USAGE;
27
28	av = argv + 1;
29	ac = argc - 1;
30	if (IS_ENABLED(CONFIG_MD5SUM_VERIFY) && strcmp(*av, "-v") == 0) {
31		flags |= HASH_FLAG_VERIFY;
32		av++;
33		ac--;
34	}
35
36	return hash_command("md5", flags, cmdtp, flag, ac, av);
37}
38
39#if IS_ENABLED(CONFIG_MD5SUM_VERIFY)
40U_BOOT_CMD(
41	md5sum,	5,	1,	do_md5sum,
42	"compute MD5 message digest",
43	"address count [[*]sum]\n"
44		"    - compute MD5 message digest [save to sum]\n"
45	"md5sum -v address count [*]sum\n"
46		"    - verify md5sum of memory area"
47);
48#else
49U_BOOT_CMD(
50	md5sum,	4,	1,	do_md5sum,
51	"compute MD5 message digest",
52	"address count [[*]sum]\n"
53		"    - compute MD5 message digest [save to sum]"
54);
55#endif /* IS_ENABLED(CONFIG_MD5SUM_VERIFY) */
56