public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] crc32: Correct endianness of crc32 result
@ 2013-04-05 23:11 Simon Glass
  2013-04-05 23:32 ` Allen Martin
  2013-04-06  7:04 ` Wolfgang Denk
  0 siblings, 2 replies; 19+ messages in thread
From: Simon Glass @ 2013-04-05 23:11 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2013-04-18 19:18 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-05 23:11 [U-Boot] [PATCH] crc32: Correct endianness of crc32 result Simon Glass
2013-04-05 23:32 ` Allen Martin
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox