From: Simon Glass <simon.glass@canonical.com> Add ext4l_crc32c() which uses the Castagnoli polynomial (0x82F63B78) required for ext4 checksums. The table is initialised on first mount. Signed-off-by: Simon Glass <simon.glass@canonical.com> --- fs/ext4l/ext4_uboot.h | 2 ++ fs/ext4l/interface.c | 2 ++ fs/ext4l/support.c | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/fs/ext4l/ext4_uboot.h b/fs/ext4l/ext4_uboot.h index 96b1c06a05b..8b70bbcb75c 100644 --- a/fs/ext4l/ext4_uboot.h +++ b/fs/ext4l/ext4_uboot.h @@ -35,6 +35,7 @@ #include <linux/iomap.h> #include <linux/seq_file.h> #include <linux/rbtree.h> /* Real rbtree implementation */ +#include <u-boot/crc.h> /* For crc32() used by crc32_be */ /* * Override no_printk to avoid format warnings in disabled debug prints. @@ -2818,6 +2819,7 @@ struct wait_bit_entry { void free_buffer_head(struct buffer_head *bh); /* ext4l support functions (support.c) */ +void ext4l_crc32c_init(void); void bh_cache_clear(void); int ext4l_read_block(sector_t block, size_t size, void *buffer); diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c index e1458ea6bfe..141afc42c17 100644 --- a/fs/ext4l/interface.c +++ b/fs/ext4l/interface.c @@ -92,6 +92,8 @@ int ext4l_probe(struct blk_desc *fs_dev_desc, /* Set up block device for buffer I/O */ ext4l_set_blk_dev(fs_dev_desc, fs_partition); + ext4l_crc32c_init(); + /* Initialise journal subsystem if enabled */ if (IS_ENABLED(CONFIG_EXT4_JOURNAL)) { ret = jbd2_journal_init_global(); diff --git a/fs/ext4l/support.c b/fs/ext4l/support.c index 0765065a99f..2040ad5f480 100644 --- a/fs/ext4l/support.c +++ b/fs/ext4l/support.c @@ -12,12 +12,33 @@ #include <blk.h> #include <part.h> #include <malloc.h> +#include <u-boot/crc.h> #include <linux/errno.h> #include <linux/types.h> #include "ext4_uboot.h" #include "ext4.h" +/* + * CRC32C support - uses Castagnoli polynomial 0x82F63B78 + * Table is initialised on first mount + */ +static u32 ext4l_crc32c_table[256]; +static bool ext4l_crc32c_inited; + +void ext4l_crc32c_init(void) +{ + if (!ext4l_crc32c_inited) { + crc32c_init(ext4l_crc32c_table, 0x82F63B78); + ext4l_crc32c_inited = true; + } +} + +u32 ext4l_crc32c(u32 crc, const void *address, unsigned int length) +{ + return crc32c_cal(crc, address, length, ext4l_crc32c_table); +} + /* * Buffer cache implementation * -- 2.43.0