Move to calling the abstraction which allows for hardware acceleration. We also remove unneeded defines and only include objects if required.
Signed-off-by: Ben Whitten <ben.whit...@lairdtech.com> --- common/hash.c | 4 ++++ common/image-fit.c | 27 +++++++++------------------ include/image.h | 42 ++++++++++++++++++++++-------------------- lib/Makefile | 5 ++++- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/common/hash.c b/common/hash.c index d2f4b3f..ceee124 100644 --- a/common/hash.c +++ b/common/hash.c @@ -85,6 +85,7 @@ static int hash_finish_sha256(struct hash_algo *algo, void *ctx, void } #endif +#if defined(CONFIG_CRC32) static int hash_init_crc32(struct hash_algo *algo, void **ctxp) { uint32_t *ctx = malloc(sizeof(uint32_t)); @@ -110,6 +111,7 @@ static int hash_finish_crc32(struct hash_algo *algo, void *ctx, void *dest_buf, free(ctx); return 0; } +#endif /* * These are the hash algorithms we support. If we have hardware acceleration @@ -159,6 +161,7 @@ static struct hash_algo hash_algo[] = { #endif }, #endif +#ifdef CONFIG_CRC32 { .name = "crc32", .digest_size = 4, @@ -168,6 +171,7 @@ static struct hash_algo hash_algo[] = { .hash_update = hash_update_crc32, .hash_finish = hash_finish_crc32, }, +#endif #ifdef CONFIG_MD5 { .name = "md5", diff --git a/common/image-fit.c b/common/image-fit.c index 8c15ed1..7d8c961 100644 --- a/common/image-fit.c +++ b/common/image-fit.c @@ -1082,26 +1082,17 @@ int fit_set_timestamp(void *fit, int noffset, time_t timestamp) int calculate_hash(const void *data, int data_len, const char *algo, uint8_t *value, int *value_len) { - if (IMAGE_ENABLE_CRC32 && strcmp(algo, "crc32") == 0) { - *((uint32_t *)value) = crc32_wd(0, data, data_len, - CHUNKSZ_CRC32); - *((uint32_t *)value) = cpu_to_uimage(*((uint32_t *)value)); - *value_len = 4; - } else if (IMAGE_ENABLE_SHA1 && strcmp(algo, "sha1") == 0) { - sha1_csum_wd((unsigned char *)data, data_len, - (unsigned char *)value, CHUNKSZ_SHA1); - *value_len = 20; - } else if (IMAGE_ENABLE_SHA256 && strcmp(algo, "sha256") == 0) { - sha256_csum_wd((unsigned char *)data, data_len, - (unsigned char *)value, CHUNKSZ_SHA256); - *value_len = SHA256_SUM_LEN; - } else if (IMAGE_ENABLE_MD5 && strcmp(algo, "md5") == 0) { - md5_wd((unsigned char *)data, data_len, value, CHUNKSZ_MD5); - *value_len = 16; - } else { + struct hash_algo *hash_algo; + int ret; + + ret = hash_lookup_algo(algo, &hash_algo); + if (ret) { debug("Unsupported hash alogrithm\n"); - return -1; } + hash_algo->hash_func_ws((unsigned char *)data, data_len, + (unsigned char *)value, hash_algo->chunk_size); + *value_len = hash_algo->digest_size; + return 0; } diff --git a/include/image.h b/include/image.h index a5a5807..16bc097 100644 --- a/include/image.h +++ b/include/image.h @@ -32,6 +32,7 @@ struct fdt_region; #define CONFIG_FIT_ENABLE_SHA256_SUPPORT #define CONFIG_SHA1 #define CONFIG_SHA256 +#define CONFIG_CRC32 #define CONFIG_MD5 #define IMAGE_ENABLE_IGNORE 0 @@ -58,38 +59,39 @@ struct fdt_region; #include <fdt_support.h> # ifdef CONFIG_SPL_BUILD # ifdef CONFIG_SPL_CRC32_SUPPORT -# define IMAGE_ENABLE_CRC32 1 +# define CONFIG_CRC32 +# else +# undef CONFIG_CRC32 # endif # ifdef CONFIG_SPL_MD5_SUPPORT -# define IMAGE_ENABLE_MD5 1 +# define CONFIG_MD5 +# else +# undef CONFIG_MD5 # endif # ifdef CONFIG_SPL_SHA1_SUPPORT -# define IMAGE_ENABLE_SHA1 1 +# define CONFIG_SHA1 +# else +# undef CONFIG_SHA1 # endif # else +# ifndef CONFIG_CRC32 # define CONFIG_CRC32 /* FIT images need CRC32 support */ -# define IMAGE_ENABLE_CRC32 1 -# define IMAGE_ENABLE_MD5 1 -# define IMAGE_ENABLE_SHA1 1 +# endif +# ifndef CONFIG_MD5 +# define CONFIG_MD5 +# endif +# ifndef CONFIG_SHA1 +# define CONFIG_SHA1 +# endif # endif -#ifndef IMAGE_ENABLE_CRC32 -#define IMAGE_ENABLE_CRC32 0 -#endif - -#ifndef IMAGE_ENABLE_MD5 -#define IMAGE_ENABLE_MD5 0 -#endif - -#ifndef IMAGE_ENABLE_SHA1 -#define IMAGE_ENABLE_SHA1 0 -#endif - #if defined(CONFIG_FIT_ENABLE_SHA256_SUPPORT) || \ defined(CONFIG_SPL_SHA256_SUPPORT) -#define IMAGE_ENABLE_SHA256 1 +#ifndef CONFIG_SHA256 +#define CONFIG_SHA256 +#endif #else -#define IMAGE_ENABLE_SHA256 0 +#undef CONFIG_SHA256 #endif #endif /* IMAGE_ENABLE_FIT */ diff --git a/lib/Makefile b/lib/Makefile index 5c4aa73..5b40444 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -24,6 +24,7 @@ obj-$(CONFIG_USB_TTY) += circbuf.o obj-y += crc7.o obj-y += crc8.o obj-y += crc16.o +obj-$(CONFIG_CRC32) += crc32.o obj-$(CONFIG_ERRNO_STR) += errno_str.o obj-$(CONFIG_FIT) += fdtdec_common.o obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o @@ -61,6 +62,8 @@ obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += fdtdec_common.o obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += fdtdec.o endif + + ifdef CONFIG_SPL_BUILD obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16.o obj-$(CONFIG_SPL_NET_SUPPORT) += net_utils.o @@ -71,7 +74,7 @@ obj-y += errno.o obj-y += display_options.o CFLAGS_display_options.o := $(if $(BUILD_TAG),-DBUILD_TAG='"$(BUILD_TAG)"') obj-$(CONFIG_BCH) += bch.o -obj-y += crc32.o +obj-$(CONFIG_$(SPL_TPL_)CRC32_SUPPORT) += crc32.o obj-$(CONFIG_CRC32C) += crc32c.o obj-y += ctype.o obj-y += div64.o -- 2.7.4 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de https://lists.denx.de/listinfo/u-boot