summaryrefslogtreecommitdiffstats
path: root/patches/features/all/lib-crcitut-bit-reversed.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/features/all/lib-crcitut-bit-reversed.patch')
-rw-r--r--patches/features/all/lib-crcitut-bit-reversed.patch79
1 files changed, 79 insertions, 0 deletions
diff --git a/patches/features/all/lib-crcitut-bit-reversed.patch b/patches/features/all/lib-crcitut-bit-reversed.patch
new file mode 100644
index 0000000..358c0d8
--- /dev/null
+++ b/patches/features/all/lib-crcitut-bit-reversed.patch
@@ -0,0 +1,79 @@
+From c450dd0d27ff5cd7b83084e381e0cc808db2554e Mon Sep 17 00:00:00 2001
+From: Darren Salt <linux@youmustbejoking.demon.co.uk>
+Date: Sat, 11 Apr 2009 15:40:04 +0100
+Subject: [PATCH] crc-itu-t: add bit-reversed calculation
+
+Signed-off-by: Darren Salt <linux@youmustbejoking.demon.co.uk>
+---
+ include/linux/crc-itu-t.h | 10 ++++++++++
+ lib/crc-itu-t.c | 18 ++++++++++++++++++
+ 2 files changed, 28 insertions(+), 0 deletions(-)
+
+diff --git a/include/linux/crc-itu-t.h b/include/linux/crc-itu-t.h
+index 84920f3..7b2b7ba 100644
+--- a/include/linux/crc-itu-t.h
++++ b/include/linux/crc-itu-t.h
+@@ -6,6 +6,9 @@
+ * Poly 0x0x1021 (x^16 + x^12 + x^15 + 1)
+ * Init 0
+ *
++ * The bit-reversed buffer variants may be non-standard, but some firmware
++ * loaders require them.
++ *
+ * This source code is licensed under the GNU General Public License,
+ * Version 2. See the file COPYING for more details.
+ */
+@@ -14,15 +17,22 @@
+ #define CRC_ITU_T_H
+
+ #include <linux/types.h>
++#include <linux/bitrev.h>
+
+ extern u16 const crc_itu_t_table[256];
+
+ extern u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len);
++extern u16 crc_itu_t_bitreversed(u16 crc, const u8 *buffer, size_t len);
+
+ static inline u16 crc_itu_t_byte(u16 crc, const u8 data)
+ {
+ return (crc << 8) ^ crc_itu_t_table[((crc >> 8) ^ data) & 0xff];
+ }
+
++static inline u16 crc_itu_t_bitreversed_byte(u16 crc, const u8 data)
++{
++ return (crc << 8) ^ crc_itu_t_table[((crc >> 8) ^ bitrev8(data)) & 0xff];
++}
++
+ #endif /* CRC_ITU_T_H */
+
+diff --git a/lib/crc-itu-t.c b/lib/crc-itu-t.c
+index a63472b..886981e 100644
+--- a/lib/crc-itu-t.c
++++ b/lib/crc-itu-t.c
+@@ -64,6 +64,23 @@ u16 crc_itu_t(u16 crc, const u8 *buffer, size_t len)
+ }
+ EXPORT_SYMBOL(crc_itu_t);
+
++/**
++ * crc_itu_t_bitreversed - Compute the CRC-ITU-T for a bit-reversed data buffer
++ *
++ * @crc: previous CRC value
++ * @buffer: data pointer
++ * @len: number of bytes in the buffer
++ *
++ * Returns the updated CRC value
++ */
++u16 crc_itu_t_bitreversed(u16 crc, const u8 *buffer, size_t len)
++{
++ while (len--)
++ crc = crc_itu_t_bitreversed_byte(crc, *buffer++);
++ return crc;
++}
++EXPORT_SYMBOL(crc_itu_t_bitreversed);
++
+ MODULE_DESCRIPTION("CRC ITU-T V.41 calculations");
+ MODULE_LICENSE("GPL");
+
+--
+1.5.6.5
+