Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/lwext4: add lightweight implementation of the ext2/3/4 filesystem #18682

Merged
merged 4 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ ifneq (,$(filter fatfs_vfs,$(USEMODULE)))
USEMODULE += vfs
endif

ifneq (,$(filter lwext%_vfs,$(USEMODULE)))
USEPKG += lwext4
USEMODULE += vfs
endif

ifneq (,$(filter nimble_%,$(USEMODULE)))
USEPKG += nimble
endif
Expand Down
2 changes: 1 addition & 1 deletion boards/native/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif

# default to using littlefs2 on the virtual flash if no other fs was selected
ifneq (,$(filter vfs_default,$(USEMODULE)))
ifeq (,$(filter spiffs littlefs fatfs_vfs,$(USEMODULE)))
ifeq (,$(filter lwext%_vfs spiffs littlefs fatfs_vfs,$(USEMODULE)))
USEMODULE += littlefs2
endif
USEMODULE += mtd
Expand Down
8 changes: 6 additions & 2 deletions boards/native/board_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mtd_native_dev_t mtd0_dev = {
mtd_dev_t *mtd0 = &mtd0_dev.base;
#endif

#ifdef MODULE_VFS
#ifdef MODULE_VFS_DEFAULT
#include "vfs_default.h"

/*
Expand All @@ -62,8 +62,12 @@ VFS_AUTO_MOUNT(spiffs, VFS_MTD(mtd0_dev), VFS_DEFAULT_NVM(0), 0);
#elif defined(MODULE_FATFS_VFS)
VFS_AUTO_MOUNT(fatfs, VFS_MTD(mtd0_dev), VFS_DEFAULT_NVM(0), 0);

/* ext2/3/4 support */
#elif defined(MODULE_LWEXT4)
VFS_AUTO_MOUNT(lwext4, VFS_MTD(mtd0_dev), VFS_DEFAULT_NVM(0), 0);

#endif
#endif /* MODULE_VFS */
#endif /* MODULE_VFS_DEFAULT */

/**
* Nothing to initialize at the moment.
Expand Down
8 changes: 6 additions & 2 deletions boards/native/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,26 @@ void _native_LED_RED_TOGGLE(void);
* @{
*/
#ifndef MTD_PAGE_SIZE
#ifdef MODULE_FATFS
#if defined(MODULE_FATFS) || defined(MODULE_LWEXT4)
#define MTD_PAGE_SIZE (512)
#else
#define MTD_PAGE_SIZE (256)
#endif
#endif
#ifndef MTD_SECTOR_SIZE
#ifdef MODULE_FATFS
#if defined(MODULE_FATFS) || defined(MODULE_LWEXT4)
#define MTD_SECTOR_SIZE (512)
#else
#define MTD_SECTOR_SIZE (4096)
#endif
#endif
#ifndef MTD_SECTOR_NUM
#if defined(MODULE_FATFS) || defined(MODULE_LWEXT4)
#define MTD_SECTOR_NUM (32768)
#else
#define MTD_SECTOR_NUM (2048)
#endif
#endif
/** Advertised write size. While the file system backend supports single byte
* granularity, this can be increased to mimic other media. */
#ifndef MTD_WRITE_SIZE
Expand Down
5 changes: 4 additions & 1 deletion boards/same54-xpro/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ endif
# default to using littlefs2 on the external flash and fatfs on SD card
ifneq (,$(filter vfs_default,$(USEMODULE)))
USEPKG += littlefs2
USEMODULE += fatfs_vfs
# if ext2/3/4 is used, don't use FAT
ifeq (,$(filter lwext%_vfs,$(USEMODULE)))
USEMODULE += fatfs_vfs
endif
USEMODULE += mtd
endif
6 changes: 6 additions & 0 deletions boards/same54-xpro/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ static mtd_sam0_sdhc_t sdhc_dev = {
mtd_dev_t *mtd2 = (mtd_dev_t *)&sdhc_dev;

#ifdef MODULE_VFS_DEFAULT
/* default to FAT */
#if defined(MODULE_FATFS_VFS)
VFS_AUTO_MOUNT(fatfs, VFS_MTD(sdhc_dev), VFS_DEFAULT_SD(0), 1);
/* but also support ext2/3/4 */
#elif defined(MODULE_LWEXT4)
VFS_AUTO_MOUNT(lwext4, VFS_MTD(sdhc_dev), VFS_DEFAULT_SD(0), 1);
#endif
#endif /* MODULE_VFS_DEFAULT */
#endif /* MODULE_SAM0_SDHC */
5 changes: 5 additions & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ PSEUDOMODULES += log
PSEUDOMODULES += log_printfnoformat
PSEUDOMODULES += log_color
PSEUDOMODULES += lora
PSEUDOMODULES += lwext4_no_gpl
PSEUDOMODULES += lwext2_vfs
PSEUDOMODULES += lwext3_vfs
PSEUDOMODULES += lwext4_vfs
PSEUDOMODULES += lwext4_vfs_format
## @defgroup pseudomodule_libc_gettimeofday libc_gettimeofday
## @brief Includes implementation of gettimeofday()
##
Expand Down
13 changes: 13 additions & 0 deletions pkg/lwext4/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PKG_NAME=lwext4
PKG_URL=https://github.com/gkostka/lwext4.git
PKG_VERSION=58bcf89a121b72d4fb66334f1693d3b30e4cb9c5
PKG_LICENSE=GPLv2

CFLAGS += -Wno-cast-align
CFLAGS += -Wno-error=format
CFLAGS += -Wno-unused-parameter -Wno-unused-variable

include $(RIOTBASE)/pkg/pkg.mk

all:
$(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/src -f $(RIOTBASE)/Makefile.base MODULE=$(PKG_NAME)
5 changes: 5 additions & 0 deletions pkg/lwext4/Makefile.dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
USEMODULE += lwext_fs

ifneq (,$(filter vfs_auto_format,$(USEMODULE)))
DEFAULT_MODULE += lwext4_vfs_format
endif
23 changes: 23 additions & 0 deletions pkg/lwext4/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
INCLUDES += -I$(PKGDIRBASE)/lwext4/include

DIRS += $(RIOTPKG)/lwext4/fs

CFLAGS += -DCONFIG_USE_DEFAULT_CFG=1
CFLAGS += -DCONFIG_HAVE_OWN_OFLAGS=0

# select ext2/3/4 feature level based on module name
ifneq (,$(filter lwext4_vfs,$(USEMODULE)))
CFLAGS += -DCONFIG_EXT_FEATURE_SET_LVL=F_SET_EXT4
endif
ifneq (,$(filter lwext3_vfs,$(USEMODULE)))
CFLAGS += -DCONFIG_EXT_FEATURE_SET_LVL=F_SET_EXT3
endif
ifneq (,$(filter lwext2_vfs,$(USEMODULE)))
CFLAGS += -DCONFIG_EXT_FEATURE_SET_LVL=F_SET_EXT2
endif

# Disable GPL-only features
ifneq (,$(filter lwext4_no_gpl,$(USEMODULE)))
CFLAGS += -DCONFIG_EXTENTS_ENABLE=0
CFLAGS += -DCONFIG_XATTR_ENABLE=0
endif
19 changes: 19 additions & 0 deletions pkg/lwext4/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @defgroup pkg_lwext4 lightweight ext2/3/4 implementation
* @ingroup pkg
* @ingroup sys_fs
* @brief Provides a lightweight implementation of the ext2/3/4
* filesystem with optional journaling transactions & recovery
*
* Lwext4 is an excellent choice for SD/MMC card, USB flash drive
* or any other wear leveled memory types. However it is not good
* for raw flash devices.
*
* Some of the source files are licensed under GPLv2.
* It makes whole lwext4 GPLv2 licensed. To use library as a BSD3,
* GPLv2 licensed source files must be disabled.
* To do so, enable the `lwext4_no_gpl` module.
* This will disable support for extends and extended attributes.
*
* @see https://github.com/gkostka/lwext4
*/
3 changes: 3 additions & 0 deletions pkg/lwext4/fs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
MODULE := lwext_fs

include $(RIOTBASE)/Makefile.base
Loading