Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Behún | 2938754 | 2017-09-03 17:00:28 +0200 | [diff] [blame] | 2 | /* |
| 3 | * BTRFS filesystem implementation for U-Boot |
| 4 | * |
| 5 | * 2017 Marek Behun, CZ.NIC, marek.behun@nic.cz |
Marek Behún | 2938754 | 2017-09-03 17:00:28 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include "btrfs.h" |
| 9 | #include <u-boot/crc.h> |
Alberto Sánchez Molero | d1f4333 | 2018-01-20 09:17:57 +0200 | [diff] [blame] | 10 | #include <asm/unaligned.h> |
Marek Behún | 2938754 | 2017-09-03 17:00:28 +0200 | [diff] [blame] | 11 | |
| 12 | static u32 btrfs_crc32c_table[256]; |
| 13 | |
| 14 | void btrfs_hash_init(void) |
| 15 | { |
| 16 | static int inited = 0; |
| 17 | |
| 18 | if (!inited) { |
| 19 | crc32c_init(btrfs_crc32c_table, 0x82F63B78); |
| 20 | inited = 1; |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | u32 btrfs_crc32c(u32 crc, const void *data, size_t length) |
| 25 | { |
| 26 | return crc32c_cal(crc, (const char *) data, length, |
| 27 | btrfs_crc32c_table); |
| 28 | } |
| 29 | |
| 30 | u32 btrfs_csum_data(char *data, u32 seed, size_t len) |
| 31 | { |
| 32 | return btrfs_crc32c(seed, data, len); |
| 33 | } |
| 34 | |
| 35 | void btrfs_csum_final(u32 crc, void *result) |
| 36 | { |
Alberto Sánchez Molero | d1f4333 | 2018-01-20 09:17:57 +0200 | [diff] [blame] | 37 | put_unaligned(cpu_to_le32(~crc), (u32 *)result); |
Marek Behún | 2938754 | 2017-09-03 17:00:28 +0200 | [diff] [blame] | 38 | } |