X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fcmd_md5sum.c;h=3ac8cc41b1a450edc7f5e489b3a6e9e4c2d14a38;hb=24289208354c143967968755cff5c825a12e3f90;hp=fbe0aba84159bc14702087b9034e6624677689f1;hpb=5ab177bede8c7efc76798a79e4a3b36ed38a7401;p=u-boot diff --git a/common/cmd_md5sum.c b/common/cmd_md5sum.c index fbe0aba841..3ac8cc41b1 100644 --- a/common/cmd_md5sum.c +++ b/common/cmd_md5sum.c @@ -5,29 +5,38 @@ * (C) Copyright 2000 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, - * MA 02111-1307 USA + * SPDX-License-Identifier: GPL-2.0+ */ #include #include #include +/* + * Store the resulting sum to an address or variable + */ +static void store_result(const u8 *sum, const char *dest) +{ + unsigned int i; + + if (*dest == '*') { + u8 *ptr; + + ptr = (u8 *)simple_strtoul(dest + 1, NULL, 16); + for (i = 0; i < 16; i++) + *ptr++ = sum[i]; + } else { + char str_output[33]; + char *str_ptr = str_output; + + for (i = 0; i < 16; i++) { + sprintf(str_ptr, "%02x", sum[i]); + str_ptr += 2; + } + setenv(dest, str_output); + } +} + #ifdef CONFIG_MD5SUM_VERIFY static int parse_verify_sum(char *verify_str, u8 *vsum) { @@ -94,6 +103,9 @@ int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) for (i = 0; i < 16; i++) printf("%02x", output[i]); printf("\n"); + + if (ac > 2) + store_result(output, *av); } else { char *verify_str = *av++; @@ -136,6 +148,9 @@ static int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) printf("%02x", output[i]); printf("\n"); + if (argc > 3) + store_result(output, argv[3]); + return 0; } #endif @@ -144,15 +159,16 @@ static int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) U_BOOT_CMD( md5sum, 5, 1, do_md5sum, "compute MD5 message digest", - "address count\n" - " - compute MD5 message digest\n" + "address count [[*]sum]\n" + " - compute MD5 message digest [save to sum]\n" "md5sum -v address count [*]sum\n" " - verify md5sum of memory area" ); #else U_BOOT_CMD( - md5sum, 3, 1, do_md5sum, + md5sum, 4, 1, do_md5sum, "compute MD5 message digest", - "address count" + "address count [[*]sum]\n" + " - compute MD5 message digest [save to sum]" ); #endif