crc16: Remove duplicate implementations
Subsystems (5)
PATCH 2/5 crc16: Rename fs/ubifs/crc16.h to include/linux/crc16.h
In reply to Pali RohárFile fs/ubifs/crc16.h is standard linux's crc16.h include file. So move it from fs/ubifs to include/linux where are also other linux include files.
---
fs/ubifs/crc16.c | 2 +-
fs/ubifs/lpt.c | 2 +-
fs/ubifs/lpt_commit.c | 2 +-
{fs/ubifs => include/linux}/crc16.h | 0
4 files changed, 3 insertions(+), 3 deletions(-)
rename {fs/ubifs => include/linux}/crc16.h (100%)fs/ubifs/crc16.c +1 -1
@@ -6,7 +6,7 @@*/ #include <linux/types.h> -#include "crc16.h" +#include <linux/crc16.h> /** CRC table for the CRC-16. The poly is 0x8005 (x^16 + x^15 + x^2 + 1) */ u16 const crc16_table[256 ] = {
fs/ubifs/lpt.c +1 -1
@@ -42,7 +42,7 @@#include <linux/compat.h> #include <linux/err.h> #include <ubi_uboot.h> -#include "crc16.h" +#include <linux/crc16.h> #endif /**
fs/ubifs/lpt_commit.c +1 -1
@@ -23,7 +23,7 @@#include <linux/bitops.h> #include <linux/compat.h> #include <linux/err.h> -#include "crc16.h" +#include <linux/crc16.h> #endif #include "ubifs.h"
include/linux/crc16.h renamed from fs/ubifs/crc16.h +0 -0
Signature · 1 line
2.20.1
PATCH 1/5 crc16-ccitt: Rename file with CRC-16-CCITT implementation to crc16-ccitt.c
In reply to Pali RohárU-Boot CRC-16 implementation uses polynomial x^16 + x^12 + x^5 + 1 which is not standard CRC-16 algorithm, but it is known as CRC-16-CCITT. Rename file crc16.c to crc16-ccitt.c to reduce confusion.
---
include/u-boot/crc.h | 2 +-
lib/Makefile | 8 ++++----
lib/{crc16.c => crc16-ccitt.c} | 2 +-
tools/Makefile | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)
rename lib/{crc16.c => crc16-ccitt.c} (99%)include/u-boot/crc.h +1 -1
@@ -25,7 +25,7 @@*/ unsigned int crc8 (unsigned int crc_start,const unsigned char *vptr,int len); -/* lib/crc16.c - 16 bit CRC with polynomial x^16+x^12+x^5+1 (CRC-CCITT) */ +/* lib/crc16-ccitt.c - 16 bit CRC with polynomial x^16+x^12+x^5+1 (CRC-CCITT) */ uint16_t crc16_ccitt (uint16_t crc_start,const unsigned char *s,int len);/** * crc16_ccitt_wd_buf - Perform CRC16-CCIT on an input buffer and return the
lib/Makefile +4 -4
@@ -37,7 +37,7 @@ obj-$(CONFIG_CIRCBUF) += circbuf.o endif obj-y += crc8.o -obj-y += crc16.o +obj-y += crc16-ccitt.o obj-$(CONFIG_ERRNO_STR) += errno_str.o obj-$(CONFIG_FIT) += fdtdec_common.o obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o
@@ -90,9 +90,9 @@ obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += libfdt/ obj-$(CONFIG_$(SPL_TPL_)OF_REAL) += fdtdec_common.o fdtdec.o ifdef CONFIG_SPL_BUILD -obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16.o -obj-$(CONFIG_$(SPL_TPL_)HASH) += crc16.o -obj-$(CONFIG_MMC_SPI_CRC_ON) += crc16.o +obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16-ccitt.o +obj-$(CONFIG_$(SPL_TPL_)HASH) += crc16-ccitt.o +obj-$(CONFIG_MMC_SPI_CRC_ON) += crc16-ccitt.o obj-y += net_utils.o endif obj-$(CONFIG_ADDR_MAP) += addr_map.o
lib/crc16-ccitt.c renamed from lib/crc16.c +1 -1
@@ -2,7 +2,7 @@/* *========================================================================== * -* crc16.c +* crc16-ccitt.c * * 16 bit CRC with polynomial x^16+x^12+x^5+1 *
tools/Makefile +1 -1
@@ -131,7 +131,7 @@ dumpimage-mkimage-objs := aisimage.o \ $(ROCKCHIP_OBS) \ socfpgaimage.o \ sunxi_egon.o \ - lib/crc16.o \ + lib/crc16-ccitt.o \ lib/hash-checksum.o \ lib/sha1.o \ lib/sha256.o \
Signature · 1 line
2.20.1
cover crc16: Remove duplicate implementations
This patch series removes duplicate implementations of CRC-16 with polynomial x^16 + x^15 + x^2 + 1. One implementation is enough.
Atsha 5/5 patch depends on another atsha patch:
https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
Pali Rohár (5):
crc16-ccitt: Rename file with CRC-16-CCITT implementation to
crc16-ccitt.c
crc16: Rename fs/ubifs/crc16.h to include/linux/crc16.h
crc16: Move standard CRC-16 implementation from ubifs to lib
fs: ext4: Use CRC-16 implementation from linux/crc16.h
misc: atsha204a: Remove duplicate CRC-16 implementation
drivers/misc/Kconfig | 1 +
drivers/misc/atsha204a-i2c.c | 122 +--------------------------
fs/ext4/Makefile | 2 +-
fs/ext4/crc16.c | 62 --------------
fs/ext4/crc16.h | 16 ----
fs/ext4/ext4_common.c | 8 +-
fs/ext4/ext4_common.h | 2 +-
fs/ubifs/Makefile | 2 +-
fs/ubifs/crc16.c | 60 --------------
fs/ubifs/lpt.c | 2 +-
fs/ubifs/lpt_commit.c | 2 +-
{fs/ubifs => include/linux}/crc16.h | 0
include/u-boot/crc.h | 5 +-
lib/Makefile | 7 +-
lib/crc16-ccitt.c | 84 +++++++++++++++++++
lib/crc16.c | 124 +++++++++++-----------------
tools/Makefile | 2 +-
17 files changed, 156 insertions(+), 345 deletions(-)
delete mode 100644 fs/ext4/crc16.c
delete mode 100644 fs/ext4/crc16.h
delete mode 100644 fs/ubifs/crc16.c
rename {fs/ubifs => include/linux}/crc16.h (100%)
create mode 100644 lib/crc16-ccitt.cSignature · 1 line
2.20.1
PATCH 3/5 crc16: Move standard CRC-16 implementation from ubifs to lib
This implementation provides standard CRC-16 algorithm with polynomial x^16 + x^15 + x^2 + 1.
---
fs/ubifs/Makefile | 2 +-
include/u-boot/crc.h | 3 +++
lib/Makefile | 1 +
{fs/ubifs => lib}/crc16.c | 0
4 files changed, 5 insertions(+), 1 deletion(-)
rename {fs/ubifs => lib}/crc16.c (100%)fs/ubifs/Makefile +1 -1
@@ -9,5 +9,5 @@ obj-y := ubifs.o io.o super.o sb.o master.o lpt.o obj-y += lpt_commit.o scan.o lprops.o -obj-y += tnc.o tnc_misc.o debug.o crc16.o budget.o +obj-y += tnc.o tnc_misc.o debug.o budget.o obj-y += log.o orphan.o recovery.o replay.o gc.o
include/u-boot/crc.h +3 -0
@@ -25,6 +25,9 @@*/ unsigned int crc8 (unsigned int crc_start,const unsigned char *vptr,int len); +/* lib/crc16.c - 16 bit CRC with polynomial x^16 + x^15 + x^2 + 1 */ +uint16_t crc16 (uint16_t crc,const unsigned char *buffer,size_t len); +/* lib/crc16-ccitt.c - 16 bit CRC with polynomial x^16+x^12+x^5+1 (CRC-CCITT) */ uint16_t crc16_ccitt (uint16_t crc_start,const unsigned char *s,int len);/**
lib/Makefile +1 -0
@@ -37,6 +37,7 @@ obj-$(CONFIG_CIRCBUF) += circbuf.o endif obj-y += crc8.o +obj-y += crc16.o obj-y += crc16-ccitt.o obj-$(CONFIG_ERRNO_STR) += errno_str.o obj-$(CONFIG_FIT) += fdtdec_common.o
lib/crc16.c renamed from fs/ubifs/crc16.c +0 -0
Signature · 1 line
2.20.1
PATCH 5/5 misc: atsha204a: Remove duplicate CRC-16 implementation
In reply to Pali RohárATSHA204A uses bit-reversed checksum of standard CRC-16 with polynomial x^16 + x^15 + x^2 + 1.
This ATSHA204A specific checksum can be calculated just by using common U-Boot functions bitrev16() and crc16().
So replace custom driver CRC-16 implementation by common U-Boot functions.
--- drivers/misc/Kconfig | 1 + drivers/misc/atsha204a-i2c.c | 122 +---------------------------------- 2 files changed, 4 insertions(+), 119 deletions(-)
drivers/misc/Kconfig +1 -0
@@ -40,6 +40,7 @@ config ALTERA_SYSID config ATSHA204A bool "Support for Atmel ATSHA204A module" + select BITREVERSE depends on MISC help Enable support for I2C connected Atmel's ATSHA204A
drivers/misc/atsha204a-i2c.c +3 -119
135 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 4/5 fs: ext4: Use CRC-16 implementation from linux/crc16.h
In reply to Pali RohárImplementation in linux/crc16.h provides standard CRC-16 algorithm with polynomial x^16 + x^15 + x^2 + 1. Use it and remove duplicate ext4 CRC-16 specific code.
--- fs/ext4/Makefile | 2 +- fs/ext4/crc16.c | 62 ------------------------------------------- fs/ext4/crc16.h | 16 ----------- fs/ext4/ext4_common.c | 8 +++--- fs/ext4/ext4_common.h | 2 +- 5 files changed, 6 insertions(+), 84 deletions(-) delete mode 100644 fs/ext4/crc16.c delete mode 100644 fs/ext4/crc16.h
fs/ext4/Makefile +1 -1
@@ -8,4 +8,4 @@ # obj-y := ext4fs.o ext4_common.o dev.o -obj-$(CONFIG_EXT4_WRITE) += ext4_write.o ext4_journal.o crc16.o +obj-$(CONFIG_EXT4_WRITE) += ext4_write.o ext4_journal.o
fs/ext4/crc16.c deleted +0 -62
62 lines not on this page · raw message
fs/ext4/crc16.h deleted +0 -16
@@ -1,16 +0,0 @@ -/* -* crc16.h - CRC-16 routine -* Implements the standard CRC-16: -* Width 16 -* Poly 0x8005 (x16 + x15 + x2 + 1) -* Init 0 -* -* Copyright (c) 2005 Ben Gardner <[email protected]> -* This source code is licensed under the GNU General Public License, -* Version 2. See the file COPYING for more details. -*/ -#ifndef __CRC16_H -#define __CRC16_H -extern unsigned int ext2fs_crc16 (unsigned int crc, -const void *buffer,unsigned int len); -#endif
fs/ext4/ext4_common.c +4 -4
@@ -427,14 +427,14 @@ uint16_t ext4fs_checksum_update(uint32_t i)if (le32_to_cpu (fs->sb->feature_ro_compat) &EXT4_FEATURE_RO_COMPAT_GDT_CSUM ) {int offset = offsetof(struct ext2_block_group , bg_checksum); - crc =ext2fs_crc16 (~0 , fs->sb->unique_id, + crc =crc16 (~0 , (__u8 *)fs->sb->unique_id,sizeof (fs->sb->unique_id)); - crc =ext2fs_crc16 (crc, &le32_i,sizeof (le32_i)); - crc =ext2fs_crc16 (crc, desc, offset); + crc =crc16 (crc, (__u8 *)&le32_i,sizeof (le32_i)); + crc =crc16 (crc, (__u8 *)desc, offset); offset +=sizeof (desc->bg_checksum);/* skip checksum */ assert (offset ==sizeof (*desc));if (offset < fs->gdsize) { - crc =ext2fs_crc16 (crc, (__u8 *)desc + offset, + crc =crc16 (crc, (__u8 *)desc + offset, fs->gdsize - offset); } }
fs/ext4/ext4_common.h +1 -1
@@ -27,7 +27,7 @@#include <linux/errno.h> #if defined(CONFIG_EXT4_WRITE )#include "ext4_journal.h" -#include "crc16.h" +#include <linux/crc16.h> #endif #define YES 1
Signature · 1 line
2.20.1
Re: [PATCH 1/5] crc16-ccitt: Rename file with CRC-16-CCITT implementation to crc16-ccitt.c
In reply to Pali RohárQuoted 5 lines · Pali Rohár
U-Boot CRC-16 implementation uses polynomial x^16 + x^12 + x^5 + 1 which is not standard CRC-16 algorithm, but it is known as CRC-16-CCITT. Rename file
crc16.ctocrc16-ccitt.cto reduce confusion.Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 68 lines
--- include/u-boot/crc.h | 2 +- lib/Makefile | 8 ++++---- lib/{crc16.c => crc16-ccitt.c} | 2 +- tools/Makefile | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-)rename
lib/{crc16.c=>crc16-ccitt.c} (99%)include/u-boot/crc.h +1
-1@@ -25,7 +25,7 @@*/ unsigned int crc8 (unsigned int crc_start,const unsigned char *vptr,int len); -/* lib/crc16.c - 16 bit CRC with polynomial x^16+x^12+x^5+1 (CRC-CCITT) */ +/* lib/crc16-ccitt.c - 16 bit CRC with polynomial x^16+x^12+x^5+1 (CRC-CCITT) */ uint16_t crc16_ccitt (uint16_t crc_start,const unsigned char *s,int len);/** * crc16_ccitt_wd_buf - Perform CRC16-CCIT on an input buffer and return the lib/Makefile +4
-4@@ -37,7 +37,7 @@ obj-$(CONFIG_CIRCBUF) += circbuf.o endif obj-y += crc8.o -obj-y += crc16.o +obj-y += crc16-ccitt.o obj-$(CONFIG_ERRNO_STR) += errno_str.o obj-$(CONFIG_FIT) += fdtdec_common.o obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o@@ -90,9 +90,9 @@ obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += libfdt/ obj-$(CONFIG_$(SPL_TPL_)OF_REAL) += fdtdec_common.o fdtdec.o ifdef CONFIG_SPL_BUILD -obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16.o -obj-$(CONFIG_$(SPL_TPL_)HASH) += crc16.o -obj-$(CONFIG_MMC_SPI_CRC_ON) += crc16.o +obj-$(CONFIG_SPL_YMODEM_SUPPORT) += crc16-ccitt.o +obj-$(CONFIG_$(SPL_TPL_)HASH) += crc16-ccitt.o +obj-$(CONFIG_MMC_SPI_CRC_ON) += crc16-ccitt.o obj-y += net_utils.o endif obj-$(CONFIG_ADDR_MAP) += addr_map.olib/crc16-ccitt.c renamed from lib/crc16.c +1
-1@@ -2,7 +2,7 @@/* *========================================================================== * -* crc16.c +* crc16-ccitt.c * * 16 bit CRC with polynomial x^16+x^12+x^5+1 * tools/Makefile +0
-0
tools/Makefile dumpimage-mkimage-objs := aisimage.o \ · line 137
Quoted 8 lines
tools/Makefile +1
-1@@ -131,7 +131,7 @@ dumpimage-mkimage-objs := aisimage.o \ $(ROCKCHIP_OBS) \ socfpgaimage.o \ sunxi_egon.o \ - lib/crc16.o \ + lib/crc16-ccitt.o \ lib/hash-checksum.o \ lib/sha1.o \ lib/sha256.o \
Viele Grüße,
Stefan Roese
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Re: [PATCH 2/5] crc16: Rename fs/ubifs/crc16.h to include/linux/crc16.h
In reply to Pali RohárQuoted 4 lines · Pali Rohár
File
fs/ubifs/crc16.his standard linux'scrc16.hinclude file. So move it from fs/ubifs toinclude/linuxwhere are also other linux include files.Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
include/linux/crc16.h
Quoted 51 lines
--- fs/ubifs/crc16.c | 2 +- fs/ubifs/lpt.c | 2 +- fs/ubifs/lpt_commit.c | 2 +- {fs/ubifs => include/linux}/crc16.h | 0 4 files changed, 3 insertions(+), 3 deletions(-)rename {fs/ubifs =>
include/linux}/crc16.h(100%)fs/ubifs/crc16.c +1
-1@@ -6,7 +6,7 @@*/ #include <linux/types.h> -#include "crc16.h" +#include <linux/crc16.h> /** CRC table for the CRC-16. The poly is 0x8005 (x^16 + x^15 + x^2 + 1) */ u16 const crc16_table[256 ] = {fs/ubifs/lpt.c +1
-1@@ -42,7 +42,7 @@#include <linux/compat.h> #include <linux/err.h> #include <ubi_uboot.h> -#include "crc16.h" +#include <linux/crc16.h> #endif /** fs/ubifs/lpt_commit.c +1
-1@@ -23,7 +23,7 @@#include <linux/bitops.h> #include <linux/compat.h> #include <linux/err.h> -#include "crc16.h" +#include <linux/crc16.h> #endif #include "ubifs.h" include/linux/crc16.h renamed from fs/ubifs/crc16.h +0
-0
Viele Grüße,
Stefan Roese
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Re: [PATCH 3/5] crc16: Move standard CRC-16 implementation from ubifs to lib
In reply to Pali RohárQuoted 4 lines · Pali Rohár
This implementation provides standard CRC-16 algorithm with polynomial x^16 + x^15 + x^2 + 1.
Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
lib/crc16.c
Quoted 49 lines
--- fs/ubifs/Makefile | 2 +- include/u-boot/crc.h | 3 +++ lib/Makefile | 1 + {fs/ubifs => lib}/crc16.c | 0 4 files changed, 5 insertions(+), 1 deletion(-)rename {fs/ubifs =>
lib}/crc16.c(100%)fs/ubifs/Makefile +1
-1@@ -9,5 +9,5 @@ obj-y := ubifs.o io.o super.o sb.o master.o lpt.o obj-y += lpt_commit.o scan.o lprops.o -obj-y += tnc.o tnc_misc.o debug.o crc16.o budget.o +obj-y += tnc.o tnc_misc.o debug.o budget.o obj-y += log.o orphan.o recovery.o replay.o gc.oinclude/u-boot/crc.h +3
-0@@ -25,6 +25,9 @@*/ unsigned int crc8 (unsigned int crc_start,const unsigned char *vptr,int len); +/* lib/crc16.c - 16 bit CRC with polynomial x^16 + x^15 + x^2 + 1 */ +uint16_t crc16 (uint16_t crc,const unsigned char *buffer,size_t len); +/* lib/crc16-ccitt.c - 16 bit CRC with polynomial x^16+x^12+x^5+1 (CRC-CCITT) */ uint16_t crc16_ccitt (uint16_t crc_start,const unsigned char *s,int len);/** lib/Makefile +1
-0@@ -37,6 +37,7 @@ obj-$(CONFIG_CIRCBUF) += circbuf.o endif obj-y += crc8.o +obj-y += crc16.o obj-y += crc16-ccitt.o obj-$(CONFIG_ERRNO_STR) += errno_str.o obj-$(CONFIG_FIT) += fdtdec_common.olib/crc16.c renamed from fs/ubifs/crc16.c +0
-0
Viele Grüße,
Stefan Roese
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Re: [PATCH 4/5] fs: ext4: Use CRC-16 implementation from linux/crc16.h
In reply to Pali RohárQuoted 5 lines · Pali Rohár
Implementation in
linux/crc16.hprovides standard CRC-16 algorithm with polynomial x^16 + x^15 + x^2 + 1. Use it and remove duplicate ext4 CRC-16 specific code.Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 138 lines
--- fs/ext4/Makefile | 2 +- fs/ext4/crc16.c | 62 ------------------------------------------- fs/ext4/crc16.h | 16 ----------- fs/ext4/ext4_common.c | 8 +++--- fs/ext4/ext4_common.h | 2 +- 5 files changed, 6 insertions(+), 84 deletions(-)delete mode 100644
fs/ext4/crc16.c
delete mode 100644fs/ext4/crc16.hfs/ext4/Makefile +1
-1@@ -8,4 +8,4 @@ # obj-y := ext4fs.o ext4_common.o dev.o -obj-$(CONFIG_EXT4_WRITE) += ext4_write.o ext4_journal.o crc16.o +obj-$(CONFIG_EXT4_WRITE) += ext4_write.o ext4_journal.ofs/ext4/crc16.c deleted +0
-62@@ -1,62 +0,0 @@ -/* -* crc16.c -* -* This source code is licensed under the GNU General Public License, -* Version 2. See the file COPYING for more details. -*/ - -#include <common.h> -#include <asm/byteorder.h> -#include <linux/stat.h> -#include "crc16.h" - -/** CRC table for the CRC-16. The poly is 0x8005 (x16 + x15 + x2 + 1) */ -static __u16 const crc16_table[256 ] = { -0x0000 ,0xC0C1 ,0xC181 ,0x0140 ,0xC301 ,0x03C0 ,0x0280 ,0xC241 , -0xC601 ,0x06C0 ,0x0780 ,0xC741 ,0x0500 ,0xC5C1 ,0xC481 ,0x0440 , -0xCC01 ,0x0CC0 ,0x0D80 ,0xCD41 ,0x0F00 ,0xCFC1 ,0xCE81 ,0x0E40 , -0x0A00 ,0xCAC1 ,0xCB81 ,0x0B40 ,0xC901 ,0x09C0 ,0x0880 ,0xC841 , -0xD801 ,0x18C0 ,0x1980 ,0xD941 ,0x1B00 ,0xDBC1 ,0xDA81 ,0x1A40 , -0x1E00 ,0xDEC1 ,0xDF81 ,0x1F40 ,0xDD01 ,0x1DC0 ,0x1C80 ,0xDC41 , -0x1400 ,0xD4C1 ,0xD581 ,0x1540 ,0xD701 ,0x17C0 ,0x1680 ,0xD641 , -0xD201 ,0x12C0 ,0x1380 ,0xD341 ,0x1100 ,0xD1C1 ,0xD081 ,0x1040 , -0xF001 ,0x30C0 ,0x3180 ,0xF141 ,0x3300 ,0xF3C1 ,0xF281 ,0x3240 , -0x3600 ,0xF6C1 ,0xF781 ,0x3740 ,0xF501 ,0x35C0 ,0x3480 ,0xF441 , -0x3C00 ,0xFCC1 ,0xFD81 ,0x3D40 ,0xFF01 ,0x3FC0 ,0x3E80 ,0xFE41 , -0xFA01 ,0x3AC0 ,0x3B80 ,0xFB41 ,0x3900 ,0xF9C1 ,0xF881 ,0x3840 , -0x2800 ,0xE8C1 ,0xE981 ,0x2940 ,0xEB01 ,0x2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8F81 ,0x4F40 ,0x8D01 ,0x4DC0 ,0x4C80 ,0x8C41 , -0x4400 ,0x84C1 ,0x8581 ,0x4540 ,0x8701 ,0x47C0 ,0x4680 ,0x8641 , -0x8201 ,0x42C0 ,0x4380 ,0x8341 ,0x4100 ,0x81C1 ,0x8081 ,0x4040 -}; - -/** -* Compute the CRC-16 for the data buffer -*/ - -unsigned int ext2fs_crc16 (unsigned int crc, -const void *buffer,unsigned int len) -{ -const unsigned char *cp = buffer; - -while (len--) - crc = (((crc >>8 ) &0xffU ) ^ - crc16_table[(crc ^ *cp++) &0xffU ]) &0x0000ffffU ; -return crc; -}fs/ext4/crc16.h deleted +0
-16@@ -1,16 +0,0 @@ -/* -* crc16.h - CRC-16 routine -* Implements the standard CRC-16: -* Width 16 -* Poly 0x8005 (x16 + x15 + x2 + 1) -* Init 0 -* -* Copyright (c) 2005 Ben Gardner <[email protected]> -* This source code is licensed under the GNU General Public License, -* Version 2. See the file COPYING for more details. -*/ -#ifndef __CRC16_H -#define __CRC16_H -extern unsigned int ext2fs_crc16 (unsigned int crc, -const void *buffer,unsigned int len); -#endif fs/ext4/ext4_common.c +4
-4@@ -427,14 +427,14 @@ uint16_t ext4fs_checksum_update(uint32_t i)if (le32_to_cpu (fs->sb->feature_ro_compat) &EXT4_FEATURE_RO_COMPAT_GDT_CSUM ) {int offset = offsetof(struct ext2_block_group , bg_checksum); - crc =ext2fs_crc16 (~0 , fs->sb->unique_id, + crc =crc16 (~0 , (__u8 *)fs->sb->unique_id,sizeof (fs->sb->unique_id)); - crc =ext2fs_crc16 (crc, &le32_i,sizeof (le32_i)); - crc =ext2fs_crc16 (crc, desc, offset); + crc =crc16 (crc, (__u8 *)&le32_i,sizeof (le32_i)); + crc =crc16 (crc, (__u8 *)desc, offset); offset +=sizeof (desc->bg_checksum);/* skip checksum */ assert (offset ==sizeof (*desc));if (offset < fs->gdsize) { - crc =ext2fs_crc16 (crc, (__u8 *)desc + offset, + crc =crc16 (crc, (__u8 *)desc + offset, fs->gdsize - offset); } }fs/ext4/ext4_common.h +0
-0
fs/ext4/ext4_common.h line 33
Quoted 8 lines
fs/ext4/ext4_common.h +1
-1@@ -27,7 +27,7 @@#include <linux/errno.h> #if defined(CONFIG_EXT4_WRITE )#include "ext4_journal.h" -#include "crc16.h" +#include <linux/crc16.h> #endif #define YES 1
Viele Grüße,
Stefan Roese
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Re: [PATCH 5/5] misc: atsha204a: Remove duplicate CRC-16 implementation
In reply to Pali RohárQuoted 9 lines · Pali Rohár
ATSHA204A uses bit-reversed checksum of standard CRC-16 with polynomial x^16 + x^15 + x^2 + 1.
This ATSHA204A specific checksum can be calculated just by using common U-Boot functions
bitrev16()andcrc16().So replace custom driver CRC-16 implementation by common U-Boot functions.
Signed-off-by Pali Rohár <[email protected]>
Thanks,
Stefan
Quoted 148 lines
--- drivers/misc/Kconfig | 1 + drivers/misc/atsha204a-i2c.c | 122 +---------------------------------- 2 files changed, 4 insertions(+), 119 deletions(-)drivers/misc/Kconfig +1
-0@@ -40,6 +40,7 @@ config ALTERA_SYSID config ATSHA204A bool "Support for Atmel ATSHA204A module" + select BITREVERSE depends on MISC help Enable support for I2C connected Atmel's ATSHA204Adrivers/misc/atsha204a-i2c.c +2
-113@@ -18,6 +18,7 @@#include <log.h> #include <asm/global_data.h> #include <linux/delay.h> +#include <linux/bitrev.h> #include <u-boot/crc.h> #define ATSHA204A_TWLO 60@@ -27,126 +28,9 @@DECLARE_GLOBAL_DATA_PTR ; -/* -* The ATSHA204A uses an (to me) unknown CRC-16 algorithm. -* The Reveng CRC-16 catalogue does not contain it. -* -* Because in Atmel's documentation only a primitive implementation -* can be found, I have implemented this one with lookup table. -*/ - -/* -* This is the code that computes the table below: -* -* int i, j; -* for (i = 0; i < 256; ++i) {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,0x69 ,0xe9 , -0x19 ,0x99 ,0x59 ,0xd9 ,0x39 ,0xb9 ,0x79 ,0xf9 , -0x05 ,0x85 ,0x45 ,0xc5 ,0x25 ,0xa5 ,0x65 ,0xe5 , -0x15 ,0x95 ,0x55 ,0xd5 ,0x35 ,0xb5 ,0x75 ,0xf5 , -0x0d ,0x8d ,0x4d ,0xcd ,0x2d ,0xad ,0x6d ,0xed , -0x1d ,0x9d ,0x5d ,0xdd ,0x3d ,0xbd ,0x7d ,0xfd , -0x03 ,0x83 ,0x43 ,0xc3 ,0x23 ,0xa3 ,0x63 ,0xe3 , -0x13 ,0x93 ,0x53 ,0xd3 ,0x33 ,0xb3 ,0x73 ,0xf3 , -0x0b ,0x8b ,0x4b ,0xcb ,0x2b ,0xab ,0x6b ,0xeb , -0x1b ,0x9b ,0x5b ,0xdb ,0x3b ,0xbb ,0x7b ,0xfb , -0x07 ,0x87 ,0x47 ,0xc7 ,0x27 ,0xa7 ,0x67 ,0xe7 , -0x17 ,0x97 ,0x57 ,0xd7 ,0x37 ,0xb7 ,0x77 ,0xf7 , -0x0f ,0x8f ,0x4f ,0xcf ,0x2f ,0xaf ,0x6f ,0xef , -0x1f ,0x9f ,0x5f ,0xdf ,0x3f ,0xbf ,0x7f ,0xff , -}; - -/* -* This is the code that computes the table below: -* -* int i, j; -* for (i = 0; i < 256; ++i) { -* u16 c = i << 8; -* for (j = 0; j < 8; ++j) { -* int b = c >> 15; -* c <<= 1; -* if (b) -* c ^= 0x8005; -* } -* crc16_table[i] = c; -* } -*/ -static u16 const crc16_table[256 ] = { -0x0000 ,0x8005 ,0x800f ,0x000a ,0x801b ,0x001e ,0x0014 ,0x8011 , -0x8033 ,0x0036 ,0x003c ,0x8039 ,0x0028 ,0x802d ,0x8027 ,0x0022 , -0x8063 ,0x0066 ,0x006c ,0x8069 ,0x0078 ,0x807d ,0x8077 ,0x0072 , -0x0050 ,0x8055 ,0x805f ,0x005a ,0x804b ,0x004e ,0x0044 ,0x8041 , -0x80c3 ,0x00c6 ,0x00cc ,0x80c9 ,0x00d8 ,0x80dd ,0x80d7 ,0x00d2 , -0x00f0 ,0x80f5 ,0x80ff ,0x00fa ,0x80eb ,0x00ee ,0x00e4 ,0x80e1 , -0x00a0 ,0x80a5 ,0x80af ,0x00aa ,0x80bb ,0x00be ,0x00b4 ,0x80b1 , -0x8093 ,0x0096 ,0x009c ,0x8099 ,0x0088 ,0x808d ,0x8087 ,0x0082 , -0x8183 ,0x0186 ,0x018c ,0x8189 ,0x0198 ,0x819d ,0x8197 ,0x0192 , -0x01b0 ,0x81b5 ,0x81bf ,0x01ba ,0x81ab ,0x01ae ,0x01a4 ,0x81a1 , -0x01e0 ,0x81e5 ,0x81ef ,0x01ea ,0x81fb ,0x01fe ,0x01f4 ,0x81f1 , -0x81d3 ,0x01d6 ,0x01dc ,0x81d9 ,0x01c8 ,0x81cd ,0x81c7 ,0x01c2 , -0x0140 ,0x8145 ,0x814f ,0x014a ,0x815b ,0x015e ,0x0154 ,0x8151 , -0x8173 ,0x0176 ,0x017c ,0x8179 ,0x0168 ,0x816d ,0x8167 ,0x0162 , -0x8123 ,0x0126 ,0x012c ,0x8129 ,0x0138 ,0x813d ,0x8137 ,0x0132 , -0x0110 ,0x8115 ,0x811f ,0x011a ,0x810b ,0x010e ,0x0104 ,0x8101 , -0x8303 ,0x0306 ,0x030c ,0x8309 ,0x0318 ,0x831d ,0x8317 ,0x0312 , -0x0330 ,0x8335 ,0x833f ,0x033a ,0x832b ,0x032e ,0x0324 ,0x8321 , -0x0360 ,0x8365 ,0x836f ,0x036a ,0x837b ,0x037e ,0x0374 ,0x8371 , -0x8353 ,0x0356 ,0x035c ,0x8359 ,0x0348 ,0x834d ,0x8347 ,0x0342 , -0x03c0 ,0x83c5 ,0x83cf ,0x03ca ,0x83db ,0x03de ,0x03d4 ,0x83d1 , -0x83f3 ,0x03f6 ,0x03fc ,0x83f9 ,0x03e8 ,0x83ed ,0x83e7 ,0x03e2 , -0x83a3 ,0x03a6 ,0x03ac ,0x83a9 ,0x03b8 ,0x83bd ,0x83b7 ,0x03b2 , -0x0390 ,0x8395 ,0x839f ,0x039a ,0x838b ,0x038e ,0x0384 ,0x8381 , -0x0280 ,0x8285 ,0x828f ,0x028a ,0x829b ,0x029e ,0x0294 ,0x8291 , -0x82b3 ,0x02b6 ,0x02bc ,0x82b9 ,0x02a8 ,0x82ad ,0x82a7 ,0x02a2 , -0x82e3 ,0x02e6 ,0x02ec ,0x82e9 ,0x02f8 ,0x82fd ,0x82f7 ,0x02f2 , -0x02d0 ,0x82d5 ,0x82df ,0x02da ,0x82cb ,0x02ce ,0x02c4 ,0x82c1 , -0x8243 ,0x0246 ,0x024c ,0x8249 ,0x0258 ,0x825d ,0x8257 ,0x0252 , -0x0270 ,0x8275 ,0x827f ,0x027a ,0x826b ,0x026e ,0x0264 ,0x8261 , -0x0220 ,0x8225 ,0x822f ,0x022a ,0x823b ,0x023e ,0x0234 ,0x8231 , -0x8213 ,0x0216 ,0x021c ,0x8219 ,0x0208 ,0x820d ,0x8207 ,0x0202 , -}; - -static inline u16 crc16_byte (u16 crc,const u8 data) +static inline u16 atsha204a_crc16 (const u8 *buffer,size_t len) { -u16 t = crc16_table[((crc >>8 ) ^ bitreverse_table[data]) &0xff ]; -return ((crc <<8 ) ^ t); -} - -static u16 atsha204a_crc16 (const u8 *buffer,size_t len) -{
drivers/misc/atsha204a-i2c.c line 36
Quoted 10 lines
drivers/misc/atsha204a-i2c.c +1
-6-u16 crc =0 ; - -while (len--) - crc =crc16_byte (crc, *buffer++); - -return crc; +return bitrev16 (crc16 (0 , buffer, len)); }static int atsha204a_send (struct udevice *dev,const u8 *buf,u8 len)
Viele Grüße,
Stefan Roese
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Re: [PATCH 1/5] crc16-ccitt: Rename file with CRC-16-CCITT implementation to crc16-ccitt.c
In reply to Pali RohárQuoted 6 lines · Pali Rohár
U-Boot CRC-16 implementation uses polynomial x^16 + x^12 + x^5 + 1 which is not standard CRC-16 algorithm, but it is known as CRC-16-CCITT. Rename file
crc16.ctocrc16-ccitt.cto reduce confusion.Signed-off-by Pali Rohár <[email protected]>Reviewed-by Stefan Roese <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom
Re: [PATCH 2/5] crc16: Rename fs/ubifs/crc16.h to include/linux/crc16.h
In reply to Pali RohárQuoted 5 lines · Pali Rohár
File
fs/ubifs/crc16.his standard linux'scrc16.hinclude file. So move it from fs/ubifs toinclude/linuxwhere are also other linux include files.Signed-off-by Pali Rohár <[email protected]>Reviewed-by Stefan Roese <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom
Re: [PATCH 3/5] crc16: Move standard CRC-16 implementation from ubifs to lib
In reply to Pali RohárQuoted 5 lines · Pali Rohár
This implementation provides standard CRC-16 algorithm with polynomial x^16 + x^15 + x^2 + 1.
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Stefan Roese <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom
Re: [PATCH 4/5] fs: ext4: Use CRC-16 implementation from linux/crc16.h
In reply to Pali RohárQuoted 6 lines · Pali Rohár
Implementation in
linux/crc16.hprovides standard CRC-16 algorithm with polynomial x^16 + x^15 + x^2 + 1. Use it and remove duplicate ext4 CRC-16 specific code.Signed-off-by Pali Rohár <[email protected]>Reviewed-by Stefan Roese <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom
Re: [PATCH 5/5] misc: atsha204a: Remove duplicate CRC-16 implementation
In reply to Pali RohárQuoted 10 lines · Pali Rohár
ATSHA204A uses bit-reversed checksum of standard CRC-16 with polynomial x^16 + x^15 + x^2 + 1.
This ATSHA204A specific checksum can be calculated just by using common U-Boot functions
bitrev16()andcrc16().So replace custom driver CRC-16 implementation by common U-Boot functions.
Signed-off-by Pali Rohár <[email protected]>Reviewed-by Stefan Roese <[email protected]>
Applied to u-boot/master, thanks!
Signature · 1 line
Tom