[U-Boot] Add md5sum and sha1 commands...

From: Robin Getz rgetz@blackfin.uclinux.org
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 rgetz@analog.com
README | 4 ++ common/cmd_mem.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+)
---
diff --git a/README b/README index 9071472..cf3867d 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 cdf8c79..ac2492c 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -34,6 +34,14 @@ #endif #include <watchdog.h>
+#ifdef CONFIG_CMD_MD5SUM +#include <u-boot/md5.h> +#endif + +#ifdef CONFIG_CMD_SHA1 +#include <sha1.h> +#endif + #ifdef CMD_MEM_DEBUG #define PRINTF(fmt,args...) printf (fmt ,##args) #else @@ -1141,6 +1149,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_sha1(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 +1324,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_SHA1 +U_BOOT_CMD( + sha1, 3, 1, do_sha1, + "compute SHA1 message digest", + "address count" +); +#endif /* CONFIG_CMD_SHA1 */ + #ifdef CONFIG_CMD_UNZIP U_BOOT_CMD( unzip, 4, 1, do_unzip,

On Saturday 25 July 2009 16:07:49 Robin Getz wrote:
--- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -34,6 +34,14 @@ #endif #include <watchdog.h>
+#ifdef CONFIG_CMD_MD5SUM +#include <u-boot/md5.h> +#endif
+#ifdef CONFIG_CMD_SHA1 +#include <sha1.h> +#endif
i dont think there would be a problem just including these all the time. would make it easier to notice problems down the line if people moved files and compile tested with boards that didnt enable these commands for example.
- for (i = 0; i < 16 ; i++)
no space before that semicolon
- for (i = 0; i < 20 ; i++)
same here
+#ifdef CONFIG_CMD_MD5SUM +U_BOOT_CMD(
- md5sum, 3, 1, do_md5sum,
- "compute MD5 message digest",
- "address count"
+); +#endif
+#ifdef CONFIG_CMD_SHA1 +U_BOOT_CMD(
- sha1, 3, 1, do_sha1,
- "compute SHA1 message digest",
- "address count"
+); +#endif /* CONFIG_CMD_SHA1 */
there's no need for these to be at the bottom of the file. move the U_BOOT_CMD() into the releated #ifdef block.
also, they should both have a "sum" suffix or neither. i'd lean towards the former ... -mike

On Sat 25 Jul 2009 22:49, Mike Frysinger pondered:
On Saturday 25 July 2009 16:07:49 Robin Getz wrote:
--- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -34,6 +34,14 @@ #endif #include <watchdog.h>
+#ifdef CONFIG_CMD_MD5SUM +#include <u-boot/md5.h> +#endif
+#ifdef CONFIG_CMD_SHA1 +#include <sha1.h> +#endif
i dont think there would be a problem just including these all the time. would make it easier to notice problems down the line if people moved files and compile tested with boards that didnt enable these commands for example.
I'm OK with either way.
- for (i = 0; i < 16 ; i++)
no space before that semicolon
- for (i = 0; i < 20 ; i++)
same here
Oops.
+#ifdef CONFIG_CMD_MD5SUM +U_BOOT_CMD(
- md5sum, 3, 1, do_md5sum,
- "compute MD5 message digest",
- "address count"
+); +#endif
+#ifdef CONFIG_CMD_SHA1 +U_BOOT_CMD(
- sha1, 3, 1, do_sha1,
- "compute SHA1 message digest",
- "address count"
+); +#endif /* CONFIG_CMD_SHA1 */
there's no need for these to be at the bottom of the file. move the U_BOOT_CMD() into the releated #ifdef block.
I'm just doing the same as all the other things in the same file (which doesn't mean it is correct). What is the preferred style?
also, they should both have a "sum" suffix or neither. i'd lean towards the former ...
Will do. Since the standard Linux console commands are sha1sum & md5sum I'll make U-Boot do like-wise.
I'll send a new version, when Wolfgang lets me know what the ifdef preference is...
-Robin

On Saturday 25 July 2009 23:25:00 Robin Getz wrote:
On Sat 25 Jul 2009 22:49, Mike Frysinger pondered:
On Saturday 25 July 2009 16:07:49 Robin Getz wrote:
+#ifdef CONFIG_CMD_MD5SUM +U_BOOT_CMD(
- md5sum, 3, 1, do_md5sum,
- "compute MD5 message digest",
- "address count"
+); +#endif
+#ifdef CONFIG_CMD_SHA1 +U_BOOT_CMD(
- sha1, 3, 1, do_sha1,
- "compute SHA1 message digest",
- "address count"
+); +#endif /* CONFIG_CMD_SHA1 */
there's no need for these to be at the bottom of the file. move the U_BOOT_CMD() into the releated #ifdef block.
I'm just doing the same as all the other things in the same file (which doesn't mean it is correct). What is the preferred style?
ive been merging them to reduce #ifdef noise -mike

Dear Robin Getz,
In message 200907252325.00174.rgetz@blackfin.uclinux.org you wrote:
I'm just doing the same as all the other things in the same file (which doesn't mean it is correct). What is the preferred style?
also, they should both have a "sum" suffix or neither. i'd lean towards the former ...
Will do. Since the standard Linux console commands are sha1sum & md5sum I'll make U-Boot do like-wise.
I'll send a new version, when Wolfgang lets me know what the ifdef preference is...
I'm not aware of an "official" preferred style. When adding to existing code, I recommend to copy what you find there.
Best regards,
Wolfgang Denk

From: Robin Getz rgetz@blackfin.uclinux.org
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 rgetz@analog.com
README | 4 ++ common/cmd_mem.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
---
diff --git a/README b/README index 9071472..cf3867d 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 cdf8c79..9850800 100644 --- a/common/cmd_mem.c +++ b/common/cmd_mem.c @@ -34,6 +34,9 @@ #endif #include <watchdog.h>
+#include <u-boot/md5.h> +#include <sha1.h> + #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,

On Mon 27 Jul 2009 00:07, Robin Getz pondered:
From: Robin Getz rgetz@blackfin.uclinux.org
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 rgetz@blackfin.uclinux.org
README | 4 ++ common/cmd_mem.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
Wolfgang - was there anything wrong with this? or did you want me to send again?

Dear Robin Getz,
In message 200908111357.25007.rgetz@blackfin.uclinux.org you wrote:
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 rgetz@blackfin.uclinux.org
README | 4 ++ common/cmd_mem.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
Wolfgang - was there anything wrong with this? or did you want me to send again?
No, there is nothing wrog with it. Looks good to me. But it is new stuff, and the "next" branch is currently not so high on my priority list. Is this urgent to you?
Best regards,
Wolfgang Denk

On Tue 11 Aug 2009 15:21, Wolfgang Denk pondered:
Dear Robin Getz,
In message 200908111357.25007.rgetz@blackfin.uclinux.org you wrote:
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 rgetz@blackfin.uclinux.org
README | 4 ++ common/cmd_mem.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+)
Wolfgang - was there anything wrong with this? or did you want me to send again?
No, there is nothing wrog with it. Looks good to me. But it is new stuff, and the "next" branch is currently not so high on my priority list. Is this urgent to you?
No - I was just going to update, and if I dropped it by accident (still learning git) - I wanted to make sure it was in your inbox...
:)

On Tuesday 11 August 2009 15:36:26 Robin Getz wrote:
On Tue 11 Aug 2009 15:21, Wolfgang Denk pondered:
Robin Getz wrote:
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 rgetz@blackfin.uclinux.org
README | 4 ++ common/cmd_mem.c | 68
Wolfgang - was there anything wrong with this? or did you want me to send again?
No, there is nothing wrog with it. Looks good to me. But it is new stuff, and the "next" branch is currently not so high on my priority list. Is this urgent to you?
No - I was just going to update, and if I dropped it by accident (still learning git) - I wanted to make sure it was in your inbox...
i stash patches in a dedicated branch or use git-format-patch and keep the result in ../patches/ so that i can `git-am` them if need be without ever losing them -mike

Dear Robin Getz,
In message 200907251607.49314.rgetz@blackfin.uclinux.org you wrote:
From: Robin Getz rgetz@blackfin.uclinux.org
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 rgetz@analog.com
README | 4 ++ common/cmd_mem.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+)
Applied to "next" branch.
Note that the statisctics lines are not part of the commit message, so they should go _below_ the '---' line.
Best regards,
Wolfgang Denk
participants (3)
-
Mike Frysinger
-
Robin Getz
-
Wolfgang Denk