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 | 5ab177b | 2012-08-17 11:00:47 +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 | |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 10 | #include <command.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 11 | #include <env.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 12 | #include <image.h> |
Igor Opaniuk | 6ec3f92 | 2024-03-02 16:05:48 +0100 | [diff] [blame] | 13 | #include <hash.h> |
Joe Hershberger | 0eb25b6 | 2015-03-22 17:08:59 -0500 | [diff] [blame] | 14 | #include <mapmem.h> |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 15 | #include <u-boot/md5.h> |
Suriyan Ramasami | 7944495 | 2014-11-17 14:39:34 -0800 | [diff] [blame] | 16 | #include <asm/io.h> |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 17 | |
Igor Opaniuk | 6ec3f92 | 2024-03-02 16:05:48 +0100 | [diff] [blame] | 18 | static int do_md5sum(struct cmd_tbl *cmdtp, int flag, int argc, |
| 19 | char *const argv[]) |
Joe Hershberger | ecd7295 | 2012-08-17 11:00:48 +0000 | [diff] [blame] | 20 | { |
Igor Opaniuk | 6ec3f92 | 2024-03-02 16:05:48 +0100 | [diff] [blame] | 21 | int flags = HASH_FLAG_ENV; |
Joe Hershberger | 5ab177b | 2012-08-17 11:00:47 +0000 | [diff] [blame] | 22 | int ac; |
Igor Opaniuk | 6ec3f92 | 2024-03-02 16:05:48 +0100 | [diff] [blame] | 23 | char *const *av; |
Joe Hershberger | 5ab177b | 2012-08-17 11:00:47 +0000 | [diff] [blame] | 24 | |
| 25 | if (argc < 3) |
| 26 | return CMD_RET_USAGE; |
| 27 | |
| 28 | av = argv + 1; |
| 29 | ac = argc - 1; |
Igor Opaniuk | 6ec3f92 | 2024-03-02 16:05:48 +0100 | [diff] [blame] | 30 | if (IS_ENABLED(CONFIG_MD5SUM_VERIFY) && strcmp(*av, "-v") == 0) { |
| 31 | flags |= HASH_FLAG_VERIFY; |
Joe Hershberger | 5ab177b | 2012-08-17 11:00:47 +0000 | [diff] [blame] | 32 | av++; |
| 33 | ac--; |
Joe Hershberger | 5ab177b | 2012-08-17 11:00:47 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Igor Opaniuk | 6ec3f92 | 2024-03-02 16:05:48 +0100 | [diff] [blame] | 36 | return hash_command("md5", flags, cmdtp, flag, ac, av); |
Joe Hershberger | 5ab177b | 2012-08-17 11:00:47 +0000 | [diff] [blame] | 37 | } |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 38 | |
Igor Opaniuk | 6ec3f92 | 2024-03-02 16:05:48 +0100 | [diff] [blame] | 39 | #if IS_ENABLED(CONFIG_MD5SUM_VERIFY) |
Joe Hershberger | 5ab177b | 2012-08-17 11:00:47 +0000 | [diff] [blame] | 40 | U_BOOT_CMD( |
| 41 | md5sum, 5, 1, do_md5sum, |
| 42 | "compute MD5 message digest", |
Joe Hershberger | ecd7295 | 2012-08-17 11:00:48 +0000 | [diff] [blame] | 43 | "address count [[*]sum]\n" |
| 44 | " - compute MD5 message digest [save to sum]\n" |
Joe Hershberger | 5ab177b | 2012-08-17 11:00:47 +0000 | [diff] [blame] | 45 | "md5sum -v address count [*]sum\n" |
| 46 | " - verify md5sum of memory area" |
| 47 | ); |
| 48 | #else |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 49 | U_BOOT_CMD( |
Joe Hershberger | ecd7295 | 2012-08-17 11:00:48 +0000 | [diff] [blame] | 50 | md5sum, 4, 1, do_md5sum, |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 51 | "compute MD5 message digest", |
Joe Hershberger | ecd7295 | 2012-08-17 11:00:48 +0000 | [diff] [blame] | 52 | "address count [[*]sum]\n" |
| 53 | " - compute MD5 message digest [save to sum]" |
Mike Frysinger | c3d2a17 | 2011-04-02 21:40:19 -0400 | [diff] [blame] | 54 | ); |
Igor Opaniuk | 6ec3f92 | 2024-03-02 16:05:48 +0100 | [diff] [blame] | 55 | #endif /* IS_ENABLED(CONFIG_MD5SUM_VERIFY) */ |