From 02c9aa1d41f73fdcf8383a36cc0cbbfaf952855d Mon Sep 17 00:00:00 2001 From: Robin Getz Date: Mon, 27 Jul 2009 00:07:59 -0400 Subject: [PATCH] Add md5sum and sha1 commands... Now that we have sha1 and md5 in lib_generic, allow people to use them on the command line, for checking downloaded files. Signed-off-by: Robin Getz --- README | 4 +++ common/cmd_mem.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/README b/README index 90714727cd..cf3867dcf3 100644 --- a/README +++ b/README @@ -629,6 +629,8 @@ The following options need to be configured: CONFIG_CMD_KGDB * kgdb CONFIG_CMD_LOADB loadb CONFIG_CMD_LOADS loads + CONFIG_CMD_MD5SUM print md5 message digest + (requires CONFIG_CMD_MEMORY and CONFIG_MD5) CONFIG_CMD_MEMORY md, mm, nm, mw, cp, cmp, crc, base, loop, loopw, mtest CONFIG_CMD_MISC Misc functions like sleep etc @@ -652,6 +654,8 @@ The following options need to be configured: (requires CONFIG_CMD_I2C) CONFIG_CMD_SETGETDCR Support for DCR Register access (4xx only) + CONFIG_CMD_SHA1 print sha1 memory digest + (requires CONFIG_CMD_MEMORY) CONFIG_CMD_SOURCE "source" command Support CONFIG_CMD_SPI * SPI serial bus support CONFIG_CMD_USB * USB support diff --git a/common/cmd_mem.c b/common/cmd_mem.c index cdf8c798dd..98508003b0 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -34,6 +34,9 @@ #endif #include +#include +#include + #ifdef CMD_MEM_DEBUG #define PRINTF(fmt,args...) printf (fmt ,##args) #else @@ -1141,6 +1144,55 @@ int do_mem_crc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } #endif /* CONFIG_CRC32_VERIFY */ +#ifdef CONFIG_CMD_MD5SUM +int do_md5sum(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + unsigned long addr, len; + unsigned int i; + u8 output[16]; + + if (argc < 3) { + cmd_usage(cmdtp); + return 1; + } + + addr = simple_strtoul(argv[1], NULL, 16); + len = simple_strtoul(argv[2], NULL, 16); + + md5((unsigned char *) addr, len, output); + printf("md5 for %08lx ... %08lx ==> ", addr, addr + len - 1); + for (i = 0; i < 16; i++) + printf("%02x", output[i]); + printf("\n"); + + return 0; +} +#endif + +#ifdef CONFIG_CMD_SHA1 +int do_sha1sum(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) +{ + unsigned long addr, len; + unsigned int i; + u8 output[20]; + + if (argc < 3) { + cmd_usage(cmdtp); + return 1; + } + + addr = simple_strtoul(argv[1], NULL, 16); + len = simple_strtoul(argv[2], NULL, 16); + + sha1_csum((unsigned char *) addr, len, output); + printf("SHA1 for %08lx ... %08lx ==> ", addr, addr + len - 1); + for (i = 0; i < 20; i++) + printf("%02x", output[i]); + printf("\n"); + + return 0; +} +#endif #ifdef CONFIG_CMD_UNZIP int gunzip (void *, int, unsigned char *, unsigned long *); @@ -1267,6 +1319,22 @@ U_BOOT_CMD( ); #endif /* CONFIG_MX_CYCLIC */ +#ifdef CONFIG_CMD_MD5SUM +U_BOOT_CMD( + md5sum, 3, 1, do_md5sum, + "compute MD5 message digest", + "address count" +); +#endif + +#ifdef CONFIG_CMD_SHA1SUM +U_BOOT_CMD( + sha1sum, 3, 1, do_sha1sum, + "compute SHA1 message digest", + "address count" +); +#endif /* CONFIG_CMD_SHA1 */ + #ifdef CONFIG_CMD_UNZIP U_BOOT_CMD( unzip, 4, 1, do_unzip, -- 2.39.5