lib/littlefs: Reuse existing CRC32 function to save space.

Getting this to work required fixing a small issue in `lfs2_util.h`, which
has been submitted upstream.

Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
This commit is contained in:
Daniël van de Giessen 2025-04-16 18:26:37 +02:00 committed by Damien George
parent 9287a1e6ea
commit 2b29b1b8f9
3 changed files with 15 additions and 3 deletions

View file

@ -206,7 +206,7 @@ endif
ifeq ($(MICROPY_VFS_LFS2),1)
CFLAGS_EXTMOD += -DMICROPY_VFS_LFS2=1
CFLAGS_THIRDPARTY += -DLFS2_NO_MALLOC -DLFS2_NO_DEBUG -DLFS2_NO_WARN -DLFS2_NO_ERROR -DLFS2_NO_ASSERT
CFLAGS_THIRDPARTY += -DLFS2_NO_MALLOC -DLFS2_NO_DEBUG -DLFS2_NO_WARN -DLFS2_NO_ERROR -DLFS2_NO_ASSERT -DLFS2_DEFINES=extmod/littlefs-include/lfs2_defines.h
SRC_THIRDPARTY_C += $(addprefix $(LITTLEFS_DIR)/,\
lfs2.c \
lfs2_util.c \

View file

@ -0,0 +1,12 @@
#ifndef LFS2_DEFINES_H
#define LFS2_DEFINES_H
#include "py/mpconfig.h"
#if MICROPY_PY_DEFLATE
// We reuse the CRC32 implementation from uzlib to save a few bytes
#include "lib/uzlib/uzlib.h"
#define LFS2_CRC(crc, buffer, size) uzlib_crc32(buffer, size, crc)
#endif
#endif

View file

@ -231,8 +231,8 @@ static inline uint32_t lfs2_tobe32(uint32_t a) {
// Calculate CRC-32 with polynomial = 0x04c11db7
#ifdef LFS2_CRC
uint32_t lfs2_crc(uint32_t crc, const void *buffer, size_t size) {
return LFS2_CRC(crc, buffer, size)
static inline uint32_t lfs2_crc(uint32_t crc, const void *buffer, size_t size) {
return LFS2_CRC(crc, buffer, size);
}
#else
uint32_t lfs2_crc(uint32_t crc, const void *buffer, size_t size);