Skip to content

Commit 2b29b1b

Browse files
DvdGiessendpgeorge
authored andcommitted
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 <[email protected]>
1 parent 9287a1e commit 2b29b1b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

extmod/extmod.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ endif
206206

207207
ifeq ($(MICROPY_VFS_LFS2),1)
208208
CFLAGS_EXTMOD += -DMICROPY_VFS_LFS2=1
209-
CFLAGS_THIRDPARTY += -DLFS2_NO_MALLOC -DLFS2_NO_DEBUG -DLFS2_NO_WARN -DLFS2_NO_ERROR -DLFS2_NO_ASSERT
209+
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
210210
SRC_THIRDPARTY_C += $(addprefix $(LITTLEFS_DIR)/,\
211211
lfs2.c \
212212
lfs2_util.c \
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef LFS2_DEFINES_H
2+
#define LFS2_DEFINES_H
3+
4+
#include "py/mpconfig.h"
5+
6+
#if MICROPY_PY_DEFLATE
7+
// We reuse the CRC32 implementation from uzlib to save a few bytes
8+
#include "lib/uzlib/uzlib.h"
9+
#define LFS2_CRC(crc, buffer, size) uzlib_crc32(buffer, size, crc)
10+
#endif
11+
12+
#endif

lib/littlefs/lfs2_util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ static inline uint32_t lfs2_tobe32(uint32_t a) {
231231

232232
// Calculate CRC-32 with polynomial = 0x04c11db7
233233
#ifdef LFS2_CRC
234-
uint32_t lfs2_crc(uint32_t crc, const void *buffer, size_t size) {
235-
return LFS2_CRC(crc, buffer, size)
234+
static inline uint32_t lfs2_crc(uint32_t crc, const void *buffer, size_t size) {
235+
return LFS2_CRC(crc, buffer, size);
236236
}
237237
#else
238238
uint32_t lfs2_crc(uint32_t crc, const void *buffer, size_t size);

0 commit comments

Comments
 (0)