[U-Boot] [PATCH v2 2/3] fit: allow fit to call hardware accelerated hash

Tom Rini trini at konsulko.com
Thu Jun 28 18:14:01 UTC 2018


On Thu, Jun 28, 2018 at 03:46:27PM +0000, Ben Whitten wrote:
> Hi Tom,
> 
> > Subject: Re: [U-Boot] [PATCH v2 2/3] fit: allow fit to call hardware accelerated
> > hash
> > 
> > On Wed, Jun 06, 2018 at 05:03:57PM +0100, Ben Whitten wrote:
> > 
> > > 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.whitten at lairdtech.com>
> > [snip]
> > > 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);
> > 
> > This is unfortunately not code equivalent.  There's a little bit missing
> > to switch this over to using SPL_CRC32_SUPPORT as well.  A good test
> > would be to make sure that a sunxi platform still builds after this (it
> > doesn't currently with the series) and use buildman -Ssdel to compare
> > before/after sizes and make sure it's a tiny change in size related to
> > the code switch and not a huge change due to droppped (or added!)
> > support.  Thanks!
> 
> I see that I should be including the crc32.o file regardless in non SPL builds,
> now the sunxi board build passes locally.
> I tested a fit image with all hashes enabled and they all passed so atleast the
> calling of the functions seems to work. Did you spot another inequivalence?
> I am un-familiar with the buildman tool, but I shall give it a go as you suggest.

If the size tests above are pretty-close (as in, you can see it's just a
size change due to code change and not due to now including/excluding an
algorithm), I think we're there.  Thanks again!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180628/13e0f55f/attachment.sig>


More information about the U-Boot mailing list