From patchwork Sun Sep 3 15:00:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 809314 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=nic.cz header.i=@nic.cz header.b="Y9JYoESL"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3xlbsy6N5Wz9t2y for ; Mon, 4 Sep 2017 01:06:46 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A3ABCC21E21; Sun, 3 Sep 2017 15:03:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 7E701C21EFC; Sun, 3 Sep 2017 15:01:40 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 38F63C21C4F; Sun, 3 Sep 2017 15:01:34 +0000 (UTC) Received: from mail.nic.cz (mail.nic.cz [217.31.204.67]) by lists.denx.de (Postfix) with ESMTPS id 51616C21D70 for ; Sun, 3 Sep 2017 15:01:33 +0000 (UTC) Received: from dellmb.labs.office.nic.cz (unknown [IPv6:2001:1488:fffe:6:8982:ed8c:62b1:c0c8]) by mail.nic.cz (Postfix) with ESMTP id E88846222D; Sun, 3 Sep 2017 17:01:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1504450893; bh=+wqr3W4b3ZwRLXIbbL1VNiqCpDZG3hJCdk4uCLqo+NQ=; h=From:To:Date; b=Y9JYoESLfHp6ZRajc73iUaSwaAHCdHPA8Cnurkd3WX/L9UinbsqCcPKl5DM2FPlFf 8Eo7Mv9h9b9rL479lpszyoGopj2ngIAywGjK1XTamXF5cEg7HQ+mpR3MbP8VCi44J2 EevmPLjU5u2yJwerMqc/9+UzHFBvZsNa1av+54Ls= From: =?utf-8?q?Marek_Beh=C3=BAn?= To: u-boot@lists.denx.de Date: Sun, 3 Sep 2017 17:00:23 +0200 Message-Id: <20170903150031.18179-2-marek.behun@nic.cz> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20170903150031.18179-1-marek.behun@nic.cz> References: <20170903150031.18179-1-marek.behun@nic.cz> X-Virus-Scanned: clamav-milter 0.99.2 at mail X-Virus-Status: Clean Cc: Tomas Hlavacek , Stefan Roese , =?utf-8?q?Andreas_F=C3=A4rber?= Subject: [U-Boot] [PATCH 1/9] lib: Add CRC32-C X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This is needed for BTRFS. Signed-off-by: Marek Behun create mode 100644 lib/crc32c.c 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 + * + * 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 +#include + +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; + } +}