U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Behun <marek.behun@nic.cz>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/9] lib: Add CRC32-C
Date: Sun, 3 Sep 2017 21:25:17 +0200	[thread overview]
Message-ID: <20170903212517.71fd8410@nic.cz> (raw)
In-Reply-To: <30fb71b1-2e00-7169-f39d-f84bd516f7ca@denx.de>

Hi Łukasz,

the Castagnoli CRC32 algorithm just uses different polynomial. Perhaps
I should generalize the original CRC32.

Marek

On Sun, 3 Sep 2017 17:47:28 +0200
Łukasz Majewski <lukma@denx.de> wrote:

> Hi Marek,
> 
> > This is needed for BTRFS.
> > 
> > Signed-off-by: Marek Behun <marek.behun@nic.cz>
> > 
> >   create mode 100644 lib/crc32c.c  
> 
> Excuse me my ignorance, but in u-boot we already have:
> ./lib/crc32.c
> 
> is the crc32c algorithm a different one from venerable crc32?
> 
> 
> > 
> > diff --git a/include/u-boot/crc.h b/include/u-boot/crc.h
> > index 6764d58bab..6d08f5df98 100644
> > --- a/include/u-boot/crc.h
> > +++ b/include/u-boot/crc.h
> > @@ -28,4 +28,8 @@ uint32_t crc32_no_comp (uint32_t, const unsigned
> > char *, uint); void crc32_wd_buf(const unsigned char *input, uint
> > ilen, unsigned char *output, uint chunk_sz);
> >   
> > +/* lib/crc32c.c */
> > +void crc32c_init(uint32_t *, uint32_t);
> > +uint32_t crc32c_cal(uint32_t, const char *, int, uint32_t *);
> > +
> >   #endif /* _UBOOT_CRC_H */
> > diff --git a/lib/Kconfig b/lib/Kconfig
> > index fe337acaeb..29e55dbe1d 100644
> > --- a/lib/Kconfig
> > +++ b/lib/Kconfig
> > @@ -146,6 +146,9 @@ config SHA_PROG_HW_ACCEL
> >   config MD5
> >   	bool
> >   
> > +config CRC32C
> > +	bool
> > +
> >   endmenu
> >   
> >   menu "Compression Support"
> > diff --git a/lib/Makefile b/lib/Makefile
> > index 2eef1eb80e..a58ce0f815 100644
> > --- a/lib/Makefile
> > +++ b/lib/Makefile
> > @@ -67,6 +67,7 @@ obj-y += display_options.o
> >   CFLAGS_display_options.o := $(if
> > $(BUILD_TAG),-DBUILD_TAG='"$(BUILD_TAG)"') obj-$(CONFIG_BCH) +=
> > bch.o obj-y += crc32.o
> > +obj-$(CONFIG_CRC32C) += crc32c.o
> >   obj-y += ctype.o
> >   obj-y += div64.o
> >   obj-y += hang.o
> > diff --git a/lib/crc32c.c b/lib/crc32c.c
> > new file mode 100644
> > index 0000000000..322c08ff5d
> > --- /dev/null
> > +++ b/lib/crc32c.c
> > @@ -0,0 +1,38 @@
> > +/*
> > + * Copied from Linux kernel crypto/crc32c.c
> > + * Copyright (c) 2004 Cisco Systems, Inc.
> > + * Copyright (c) 2008 Herbert Xu <herbert@gondor.apana.org.au>
> > + *
> > + * This program is free software; you can redistribute it and/or
> > modify it
> > + * under the terms of the GNU General Public License as published
> > by the Free
> > + * Software Foundation; either version 2 of the License, or (at
> > your option)
> > + * any later version.
> > + * SPDX-License-Identifier:	GPL-2.0+
> > + */
> > +
> > +#include <common.h>
> > +#include <compiler.h>
> > +
> > +uint32_t crc32c_cal(uint32_t crc, const char *data, int length,
> > +		    uint32_t *crc32c_table)
> > +{
> > +	while (length--)
> > +		crc = crc32c_table[(u8)(crc ^ *data++)] ^ (crc >>
> > 8); +
> > +	return crc;
> > +}
> > +
> > +void crc32c_init(uint32_t *crc32c_table, uint32_t pol)
> > +{
> > +	int i, j;
> > +	uint32_t v;
> > +	const uint32_t poly = pol; /* Bit-reflected CRC32C
> > polynomial */ +
> > +	for (i = 0; i < 256; i++) {
> > +		v = i;
> > +		for (j = 0; j < 8; j++)
> > +			v = (v >> 1) ^ ((v & 1) ? poly : 0);
> > +
> > +		crc32c_table[i] = v;
> > +	}
> > +}
> >   
> 
> 

  reply	other threads:[~2017-09-03 19:25 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-03 15:00 [U-Boot] [PATCH 0/9] Add single-device read-only BTRFS support Marek Behún
2017-09-03 15:00 ` [U-Boot] [PATCH 1/9] lib: Add CRC32-C Marek Behún
2017-09-03 15:47   ` Łukasz Majewski
2017-09-03 19:25     ` Marek Behun [this message]
2017-10-03 12:51   ` [U-Boot] [U-Boot,1/9] " Tom Rini
2017-09-03 15:00 ` [U-Boot] [PATCH 2/9] fs: Create a common fs_devread for ext4/reiserfs/zfs Marek Behún
2017-10-03 12:51   ` [U-Boot] [U-Boot, " Tom Rini
2017-09-03 15:00 ` [U-Boot] [PATCH 3/9] include: Add a variadic macro to call a callback for all arguments Marek Behún
2017-10-03 12:51   ` [U-Boot] [U-Boot, " Tom Rini
2017-09-03 15:00 ` [U-Boot] [PATCH 4/9] fs: btrfs: Add btrfs_tree.h and ctree.h from Linux (and modified) Marek Behún
2017-10-03 12:51   ` [U-Boot] [U-Boot, " Tom Rini
2017-09-03 15:00 ` [U-Boot] [PATCH 5/9] fs: btrfs: Add disk-to-cpu and cpu-to-disk conversion functions Marek Behún
2017-10-03 12:51   ` [U-Boot] [U-Boot, " Tom Rini
2017-09-03 15:00 ` [U-Boot] [PATCH 6/9] fs: btrfs: Add single-device read-only BTRFS implementation Marek Behún
2017-10-03 12:52   ` [U-Boot] [U-Boot, " Tom Rini
2017-09-03 15:00 ` [U-Boot] [PATCH 7/9] fs: btrfs: Add U-Boot fs handlers Marek Behún
2017-10-03 12:52   ` [U-Boot] [U-Boot,7/9] " Tom Rini
2017-09-03 15:00 ` [U-Boot] [PATCH 8/9] cmd: Add the 'btrsubvol' command to list BTRFS subvolumes Marek Behún
2017-10-03 12:52   ` [U-Boot] [U-Boot, " Tom Rini
2017-09-03 15:00 ` [U-Boot] [PATCH 9/9] mvebu: turris_omnia: Add CONFIG_CMD_BTRFS to defconfig Marek Behún
2017-10-03 12:52   ` [U-Boot] [U-Boot, " Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170903212517.71fd8410@nic.cz \
    --to=marek.behun@nic.cz \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox