[U-Boot] [PATCH] crc32: Correct endianness of crc32 result

Allen Martin
2013-04-05T23:32:59Z

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