Skip to contentSkip to conversation

hash: Compile-off SHA SW lib in case SHA HW lib is present

PATCH New Sumit Garg 2 participants 3 messages Aug 14, 2017 – Aug 15, 2017

lore
Share & tools
lore

Sumit Garg

author
#0 lore raw

PATCH 1/1 hash: Compile-off SHA SW lib in case SHA HW lib is present

Commit 089df18bfe9d ("lib: move hash CONFIG options to Kconfig") moved CONFIG_SHA1, CONFIG_SHA256, CONFIG_SHA_HW_ACCEL, and CONFIG_SHA_PROG_HW_ACCEL config options to Kconfig. So in case of SPL, CONFIG_SPL_HASH_SUPPORT enables CONFIG_SHA1 and CONFIG_SHA256 which enables SHA SW library by default. But in case of platforms with SHA HW library support, SHA SW library becomes redundant and increases size of SPL by approx 18K. So to take care of this SHA SW library is compiled-off in case SHA HW acceleration is present.

---
 common/hash.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
common/hash.c +4 -1
index 771d8fa..3f75c77 100644
@@ -30,6 +30,7 @@
 #include <u-boot/sha256.h>
 #include <u-boot/md5.h>
 
+#ifndef CONFIG_SHA_HW_ACCEL
 #ifdef CONFIG_SHA1
 static int hash_init_sha1(struct hash_algo *algo, void **ctxp)
 {
@@ -85,6 +86,7 @@ static int hash_finish_sha256(struct hash_algo *algo, void *ctx, void
 	return 0;
 }
 #endif
+#endif
 
 static int hash_init_crc32(struct hash_algo *algo, void **ctxp)
 {
@@ -144,7 +146,7 @@ static struct hash_algo hash_algo[] = {
 		hw_sha_finish,
 #endif
 	},
-#endif
+#else
 #ifdef CONFIG_SHA1
 	{
 		"sha1",
@@ -167,6 +169,7 @@ static struct hash_algo hash_algo[] = {
 		hash_finish_sha256,
 	},
 #endif
+#endif
 	{
 		"crc32",
 		4,
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 hash: Compile-off SHA SW lib in case SHA HW lib is present

Quoted 9 lines · Sumit Garg

Commit 089df18bfe9d ("lib: move hash CONFIG options to Kconfig") moved CONFIG_SHA1, CONFIG_SHA256, CONFIG_SHA_HW_ACCEL, and CONFIG_SHA_PROG_HW_ACCEL config options to Kconfig. So in case of SPL, CONFIG_SPL_HASH_SUPPORT enables CONFIG_SHA1 and CONFIG_SHA256 which enables SHA SW library by default. But in case of platforms with SHA HW library support, SHA SW library becomes redundant and increases size of SPL by approx 18K. So to take care of this SHA SW library is compiled-off in case SHA HW acceleration is present.

Quoted 4 lines
---
 common/hash.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Good find. Looking at the code I think this can be done a bit differently to clean up the code as well, which was the first thing I was wondering about when looking this over. I'll have a v2 of this hopefully later today (testing in travis now). Thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170814/8b410ec3/attachment.sig>
author
#2 lore raw

PATCH 1/1 hash: Compile-off SHA SW lib in case SHA HW lib is present

Quoted 27 lines

-----Original Message-----
From: Tom Rini [mailto:trini at konsulko.com]
Sent: Monday, August 14, 2017 8:04 PM
To: Sumit Garg <[email protected]>
Cc: u-boot at lists.denx.de; York Sun <[email protected]>; Ruchika Gupta <[email protected]>; Prabhakar Kushwaha <[email protected]>; sjg at chromium.org
Subject: Re: [PATCH] hash: Compile-off SHA SW lib in case SHA HW lib is present

Quoted 4 lines · Sumit Garg

Commit 089df18bfe9d ("lib: move hash CONFIG options to Kconfig") moved CONFIG_SHA1, CONFIG_SHA256, CONFIG_SHA_HW_ACCEL, and CONFIG_SHA_PROG_HW_ACCEL config options to Kconfig. So in case of SPL, CONFIG_SPL_HASH_SUPPORT enables CONFIG_SHA1 and CONFIG_SHA256

which

Quoted 9 lines

enables SHA SW library by default. But in case of platforms with SHA HW library support, SHA SW library becomes redundant and increases size of SPL by approx 18K. So to take care of this SHA SW library is compiled-off in case SHA HW acceleration is present.

---
 common/hash.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 7 lines

Good find. Looking at the code I think this can be done a bit differently to clean up the code as well, which was the first thing I was wondering about when looking this over. I'll have a v2 of this hopefully later today (testing in travis now). Thanks!

--
Tom

Thanks Tom for your comments.

Sumit