Skip to contentSkip to conversation

cmd: md5sum: use hash_command

PATCH In review Igor Opaniuk 2 participants 2 messages Mar 2, 2024 – Mar 7, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 cmd: md5sum: use hash_command

Drop old implementation and use hash_command() instead, as how it's currently done for crc32 and sha1sum cmds.

Test:
=> md5sum 0x60000000 0x200
md5 for 60000000 ... 600001ff ==> e6bbbe95f5b41996f4a9b9af7bbd4050

---

Changes in v2:
- Addressed build issues on some platforms

 cmd/Kconfig   |   1 +
 cmd/md5sum.c  | 150 ++++----------------------------------------------
 common/hash.c |   8 ++-
 3 files changed, 16 insertions(+), 143 deletions(-)
cmd/Kconfig +1 -0
index a86b5705174..622e96ad756 100644
@@ -825,6 +825,7 @@ config LOOPW
 config CMD_MD5SUM
 	bool "md5sum"
 	select MD5
+	select HASH
 	help
 	  Compute MD5 checksum.
 
cmd/md5sum.c +10 -140

180 lines not on this page · raw message

common/hash.c +5 -3
index e837c56d443..3d6b84de473 100644
@@ -321,7 +321,8 @@ static struct hash_algo hash_algo[] = {
 /* Try to minimize code size for boards that don't want much hashing */
 #if CONFIG_IS_ENABLED(SHA256) || IS_ENABLED(CONFIG_CMD_SHA1SUM) || \
 	CONFIG_IS_ENABLED(CRC32_VERIFY) || IS_ENABLED(CONFIG_CMD_HASH) || \
-	CONFIG_IS_ENABLED(SHA384) || CONFIG_IS_ENABLED(SHA512)
+	CONFIG_IS_ENABLED(SHA384) || CONFIG_IS_ENABLED(SHA512) || \
+	IS_ENABLED(CONFIG_CMD_MD5SUM)
 #define multi_hash()	1
 #else
 #define multi_hash()	0
@@ -404,7 +405,8 @@ int hash_block(const char *algo_name, const void *data, unsigned int len,
 }
 
 #if !defined(CONFIG_SPL_BUILD) && (defined(CONFIG_CMD_HASH) || \
-	defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32))
+	defined(CONFIG_CMD_SHA1SUM) || defined(CONFIG_CMD_CRC32)) || \
+	defined(CONFIG_CMD_MD5SUM)
 /**
  * store_result: Store the resulting sum to an address or variable
  *
@@ -565,7 +567,7 @@ int hash_command(const char *algo_name, int flags, struct cmd_tbl *cmdtp,
 
 		/* Try to avoid code bloat when verify is not needed */
 #if defined(CONFIG_CRC32_VERIFY) || defined(CONFIG_SHA1SUM_VERIFY) || \
-	defined(CONFIG_HASH_VERIFY)
+	defined(CONFIG_MD5SUM_VERIFY) || defined(CONFIG_HASH_VERIFY)
 		if (flags & HASH_FLAG_VERIFY) {
 #else
 		if (0) {
Signature · 1 line
2.34.1
#1 lore raw
Quoted 8 lines · Igor Opaniuk

Drop old implementation and use hash_command() instead, as how it's currently done for crc32 and sha1sum cmds.

Test:
=> md5sum 0x60000000 0x200
md5 for 60000000 ... 600001ff ==> e6bbbe95f5b41996f4a9b9af7bbd4050

So, I think this patch shows there's a bit more cleanup to do around crc32/crc16. Some platforms show:
aarch64: (for 1/1 boards) all +1042.0 data +168.0 rodata +38.0 text +836.0
hikey960 : all +1042 data +168 rodata +38 text +836
u-boot: add: 10/0, grow: 1/-1 bytes: 988/-272 (716)
function old new delta
hash_command 200 472 +272
hash_algo - 168 +168
hash_lookup_algo - 116 +116
crc32_wd_buf - 60 +60
crc16_ccitt_wd_buf - 60 +60
hash_finish_crc32 - 56 +56
hash_finish_crc16_ccitt - 56 +56
hash_update_crc32 - 52 +52
hash_update_crc16_ccitt - 52 +52
hash_init_crc32 - 48 +48
hash_init_crc16_ccitt - 48 +48
do_md5sum 320 48 -272

And prior to this patch this platform had enabled CONFIG_HASH already. That said, applied to u-boot/next, thanks!

Signature · 1 line
Tom