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