All of lore.kernel.org
 help / color / mirror / Atom feed
From: Allen Martin <amartin@nvidia.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] crc32: Correct endianness of crc32 result
Date: Fri, 5 Apr 2013 16:32:59 -0700	[thread overview]
Message-ID: <20130405233259.GA17449@badger> (raw)
In-Reply-To: <1365203470-9099-1-git-send-email-sjg@chromium.org>

On Fri, Apr 05, 2013 at 04:11:10PM -0700, Simon Glass wrote:
> When crc32 is handled by the hash library, it requires the data to be in
> big-endian format, since it reads it byte-wise. Thus at present the 'crc32'
> command reports incorrect data. For example, previously we might see:
> 
> Peach # crc32 40000000 100
> CRC32 for 40000000 ... 400000ff ==> 0d968558
> 
> but instead with the hash library we see:
> 
> Peach # crc32 40000000 100
> CRC32 for 40000000 ... 400000ff ==> 5885960d
> 
> Correct this.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> Reviewed-by: Vadim Bendebury <vbendeb@google.com>
> ---
>  lib/crc32.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/lib/crc32.c b/lib/crc32.c
> index 76205da..94720bf 100644
> --- a/lib/crc32.c
> +++ b/lib/crc32.c
> @@ -10,6 +10,7 @@
>  
>  #ifndef USE_HOSTCC
>  #include <common.h>
> +#include <asm/unaligned.h>
>  #endif
>  #include <compiler.h>
>  #include <u-boot/crc.h>
> @@ -256,5 +257,10 @@ void crc32_wd_buf(const unsigned char *input, unsigned int ilen,
>  	uint32_t crc;
>  
>  	crc = crc32_wd(0, input, ilen, chunk_sz);
> +#ifdef USE_HOSTCC
> +	crc = htobe32(crc);
>  	memcpy(output, &crc, sizeof(crc));
> +#else
> +	put_unaligned_be32(crc, output);
> +#endif
>  }
> -- 
> 1.8.1.3
> 

Tested on Tegra114 Dalmore, verified crc32 comes out as expected now.

Reviewed-by: Allen Martin <amartin@nvidia.com>
Tested-by: Allen Martin <amartin@nvidia.com>

-- 
nvpublic

  reply	other threads:[~2013-04-05 23:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-05 23:11 [U-Boot] [PATCH] crc32: Correct endianness of crc32 result Simon Glass
2013-04-05 23:32 ` Allen Martin [this message]
2013-04-06  7:04 ` Wolfgang Denk
2013-04-16 21:57   ` Simon Glass
2013-04-16 23:00     ` Tom Rini
2013-04-16 23:16       ` Simon Glass
2013-04-17  5:40     ` Wolfgang Denk
2013-04-17 18:28       ` Simon Glass
2013-04-17 19:23         ` Albert ARIBAUD
2013-04-17 20:59           ` Simon Glass
2013-04-18  6:20             ` Albert ARIBAUD
2013-04-18 10:36               ` Wolfgang Denk
2013-04-18 11:18                 ` Albert ARIBAUD
2013-04-18 14:39                   ` Wolfgang Denk
2013-04-18 16:39                     ` Albert ARIBAUD
2013-04-18 16:58                       ` Tom Rini
2013-04-18 18:43                         ` Albert ARIBAUD
2013-04-18 19:06                           ` Simon Glass
2013-04-18 19:18                             ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130405233259.GA17449@badger \
    --to=amartin@nvidia.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.