Skip to contentSkip to conversation

backport crc32 library to 2.4

PATCH New Duncan Sands 1 participant 1 message Mar 26, 2003

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backport crc32 library to 2.4

Just the 2.5 crc32 routines, not the driver changes. The lib/Makefile changes are probably crap: I don't know anything about Makefile syntax, so just slashed and hacked until it seemed to work.

Duncan.

Documentation/Configure.help +7 -0
diff -Nru a/Documentation/Configure.help b/Documentation/Configure.help
@@ -26462,6 +26462,13 @@
 
   If unsure, say N.
 
+CRC32 functions
+CONFIG_CRC32
+  This option is provided for the case where no in-kernel-tree
+  modules require CRC32 functions, but a module built outside the
+  kernel tree does. Such modules that use library CRC32 functions
+  require M here.
+
 #
 # A couple of things I keep forgetting:
 #   capitalize: AppleTalk, Ethernet, DOS, DMA, FAT, FTP, Internet,
Makefile +2 -0
diff -Nru a/Makefile b/Makefile
@@ -216,6 +216,8 @@
 	drivers/scsi/aic7xxx/aicasm/aicdb.h \
 	drivers/scsi/aic7xxx/aicasm/y.tab.h \
 	drivers/scsi/53c700_d.h \
+	lib/crc32table.h \
+	lib/gen_crc32table \
 	net/khttpd/make_times_h \
 	net/khttpd/times.h \
 	submenu*
include/linux/crc32.h +17 -39

66 lines not on this page · raw message

lib/Config.in +13 -0
diff -Nru a/lib/Config.in b/lib/Config.in
@@ -35,4 +35,17 @@
   fi
 fi
 
+#
+# Do we need CRC32 support?
+#
+if [ ]; then
+   define_tristate CONFIG_CRC32 y
+else
+  if [ ]; then
+     define_tristate CONFIG_CRC32 m
+  else
+     tristate 'CRC32 functions' CONFIG_CRC32
+  fi
+fi
+
 endmenu
lib/Makefile +11 -1
diff -Nru a/lib/Makefile b/lib/Makefile
@@ -8,7 +8,7 @@
 
 L_TARGET := lib.a
 
-export-objs := cmdline.o dec_and_lock.o rwsem-spinlock.o rwsem.o rbtree.o
+export-objs := cmdline.o crc32.o dec_and_lock.o rwsem-spinlock.o rwsem.o rbtree.o
 
 obj-y := errno.o ctype.o string.o vsprintf.o brlock.o cmdline.o \
 	 bust_spinlocks.o rbtree.o dump_stack.o
@@ -20,6 +20,8 @@
   obj-y += dec_and_lock.o
 endif
 
+obj-$(CONFIG_CRC32)	+= crc32.o
+
 subdir-$(CONFIG_ZLIB_INFLATE) += zlib_inflate
 subdir-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate
 
@@ -27,3 +29,11 @@
 obj-y += $(join $(subdir-y),$(subdir-y:%=/%.o))
 
 include $(TOPDIR)/Rules.make
+
+crc32.o: crc32table.h
+
+crc32table.h: gen_crc32table
+	./$< > $@
+
+gen_crc32table:
+	$(HOSTCC) $(HOSTCFLAGS) -o $@ $(@:=.c)
lib/crc32.c new file +528 -0

528 lines not on this page · raw message

lib/crc32defs.h new file +32 -0
diff -Nru a/lib/crc32defs.h b/lib/crc32defs.h
@@ -0,0 +1,32 @@
+/*
+ * There are multiple 16-bit CRC polynomials in common use, but this is
+ * *the* standard CRC-32 polynomial, first popularized by Ethernet.
+ * x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0
+ */
+#define CRCPOLY_LE 0xedb88320
+#define CRCPOLY_BE 0x04c11db7
+
+/* How many bits at a time to use.  Requires a table of 4<<CRC_xx_BITS bytes. */
+/* For less performance-sensitive, use 4 */
+#ifndef CRC_LE_BITS 
+# define CRC_LE_BITS 8
+#endif
+#ifndef CRC_BE_BITS
+# define CRC_BE_BITS 8
+#endif
+
+/*
+ * Little-endian CRC computation.  Used with serial bit streams sent
+ * lsbit-first.  Be sure to use cpu_to_le32() to append the computed CRC.
+ */
+#if CRC_LE_BITS > 8 || CRC_LE_BITS < 1 || CRC_LE_BITS & CRC_LE_BITS-1
+# error CRC_LE_BITS must be a power of 2 between 1 and 8
+#endif
+
+/*
+ * Big-endian CRC computation.  Used with serial bit streams sent
+ * msbit-first.  Be sure to use cpu_to_be32() to append the computed CRC.
+ */
+#if CRC_BE_BITS > 8 || CRC_BE_BITS < 1 || CRC_BE_BITS & CRC_BE_BITS-1
+# error CRC_BE_BITS must be a power of 2 between 1 and 8
+#endif
lib/gen_crc32table.c new file +82 -0

82 lines not on this page · raw message