From 086fe35951945b8a62dfe0b07ffb31a7f21fe321 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 14 Feb 2022 14:31:31 +0100 Subject: [PATCH 1/9] boards/msba2: configure FAT on SD card --- boards/msba2/Makefile.dep | 6 ++++++ boards/msba2/board_init.c | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/boards/msba2/Makefile.dep b/boards/msba2/Makefile.dep index 66367441c8..bfc4187d19 100644 --- a/boards/msba2/Makefile.dep +++ b/boards/msba2/Makefile.dep @@ -12,3 +12,9 @@ endif ifneq (,$(filter mtd,$(USEMODULE))) USEMODULE += mtd_mci endif + +# default to using FAT on the SD card +ifneq (,$(filter vfs_default,$(USEMODULE))) + USEMODULE += fatfs_vfs + USEMODULE += mtd +endif diff --git a/boards/msba2/board_init.c b/boards/msba2/board_init.c index 0b59e720d4..f7bc1e3f6e 100644 --- a/boards/msba2/board_init.c +++ b/boards/msba2/board_init.c @@ -27,11 +27,14 @@ #include "board.h" #include "cpu.h" #include "mtd.h" -#include "periph/init.h" -#include "stdio_base.h" #ifdef MODULE_MTD_MCI extern const mtd_desc_t mtd_mci_driver; static mtd_dev_t _mtd_mci = { .driver = &mtd_mci_driver }; mtd_dev_t *mtd0 = &_mtd_mci; #endif + +#ifdef MODULE_VFS_DEFAULT +#include "vfs_default.h" +VFS_AUTO_MOUNT(fatfs, { .dev = &_mtd_mci }, VFS_DEFAULT_SD(0), 0); +#endif From e57fd0888e672f86117d6c0466f8451f610388cb Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 14 Feb 2022 14:31:42 +0100 Subject: [PATCH 2/9] boards/mcb2388: configure FAT on SD card --- boards/mcb2388/Makefile.dep | 6 ++++++ boards/mcb2388/board_init.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/boards/mcb2388/Makefile.dep b/boards/mcb2388/Makefile.dep index 2cbfd39bed..376c2c6914 100644 --- a/boards/mcb2388/Makefile.dep +++ b/boards/mcb2388/Makefile.dep @@ -7,3 +7,9 @@ endif ifneq (,$(filter mtd,$(USEMODULE))) USEMODULE += mtd_mci endif + +# default to using FAT on the SD card +ifneq (,$(filter vfs_default,$(USEMODULE))) + USEMODULE += fatfs_vfs + USEMODULE += mtd +endif diff --git a/boards/mcb2388/board_init.c b/boards/mcb2388/board_init.c index 4e4a199022..351a732964 100644 --- a/boards/mcb2388/board_init.c +++ b/boards/mcb2388/board_init.c @@ -31,6 +31,11 @@ static mtd_dev_t _mtd_mci = { .driver = &mtd_mci_driver }; mtd_dev_t *mtd0 = &_mtd_mci; #endif +#ifdef MODULE_VFS_DEFAULT +#include "vfs_default.h" +VFS_AUTO_MOUNT(fatfs, { .dev = &_mtd_mci }, VFS_DEFAULT_SD(0), 0); +#endif + void led_init(void) { /* LEDs */ From a866a745b501d41164969783c248e4a33fd3a686 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 14 Feb 2022 14:33:51 +0100 Subject: [PATCH 3/9] boards/iotlab-m3: configure littlefs2 on external flash --- boards/iotlab-m3/Makefile.dep | 6 ++++++ boards/iotlab-m3/mtd.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/boards/iotlab-m3/Makefile.dep b/boards/iotlab-m3/Makefile.dep index 9323e8ae12..7a4d350b63 100644 --- a/boards/iotlab-m3/Makefile.dep +++ b/boards/iotlab-m3/Makefile.dep @@ -9,4 +9,10 @@ ifneq (,$(filter mtd,$(USEMODULE))) USEMODULE += mtd_spi_nor endif +# default to using littlefs2 on the external flash +ifneq (,$(filter vfs_default,$(USEMODULE))) + USEPKG += littlefs2 + USEMODULE += mtd +endif + USEMODULE += boards_common_iotlab diff --git a/boards/iotlab-m3/mtd.c b/boards/iotlab-m3/mtd.c index 23bf99753a..20e24df08b 100644 --- a/boards/iotlab-m3/mtd.c +++ b/boards/iotlab-m3/mtd.c @@ -52,4 +52,9 @@ static mtd_spi_nor_t mtd_nor_dev = { }; mtd_dev_t *mtd0 = (mtd_dev_t *)&mtd_nor_dev; + +#ifdef MODULE_VFS_DEFAULT +#include "vfs_default.h" +VFS_AUTO_MOUNT(littlefs2, VFS_MTD(mtd_nor_dev), VFS_DEFAULT_NVM(0), 0); +#endif #endif /* MODULE_MTD */ From 53756e24cb66a873b96afd8ea6e4606314e9c93d Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 14 Feb 2022 14:35:31 +0100 Subject: [PATCH 4/9] boards/weact-f4x1cx: configure littlefs2 on external flash --- boards/common/weact-f4x1cx/Makefile.dep | 6 ++++++ boards/common/weact-f4x1cx/board.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/boards/common/weact-f4x1cx/Makefile.dep b/boards/common/weact-f4x1cx/Makefile.dep index b20039bc5f..72486e8959 100644 --- a/boards/common/weact-f4x1cx/Makefile.dep +++ b/boards/common/weact-f4x1cx/Makefile.dep @@ -13,3 +13,9 @@ endif ifneq (,$(filter mtd,$(USEMODULE))) USEMODULE += mtd_spi_nor endif + +# default to using littlefs2 on the external flash +ifneq (,$(filter vfs_default,$(USEMODULE))) + USEPKG += littlefs2 + USEMODULE += mtd +endif diff --git a/boards/common/weact-f4x1cx/board.c b/boards/common/weact-f4x1cx/board.c index ade4f31cb8..806d808516 100644 --- a/boards/common/weact-f4x1cx/board.c +++ b/boards/common/weact-f4x1cx/board.c @@ -52,4 +52,9 @@ static mtd_spi_nor_t weact_nor_dev = { }; mtd_dev_t *mtd0 = (mtd_dev_t *)&weact_nor_dev; + +#ifdef MODULE_VFS_DEFAULT +#include "vfs_default.h" +VFS_AUTO_MOUNT(littlefs2, VFS_MTD(weact_nor_dev), VFS_DEFAULT_NVM(0), 0); +#endif #endif /* MODULE_MTD */ From 0bbcc4d9245fae76ef5fa534b28b7cd455ef9978 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 14 Feb 2022 14:37:33 +0100 Subject: [PATCH 5/9] boards/nrf52840dk: configure littlefs2 on external flash --- boards/nrf52840dk/Makefile.dep | 6 ++++++ boards/nrf52840dk/mtd.c | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/boards/nrf52840dk/Makefile.dep b/boards/nrf52840dk/Makefile.dep index 0eaff21511..a620e90be7 100644 --- a/boards/nrf52840dk/Makefile.dep +++ b/boards/nrf52840dk/Makefile.dep @@ -4,4 +4,10 @@ ifneq (,$(filter mtd,$(USEMODULE))) USEMODULE += mtd_spi_nor endif +# default to using littlefs2 on the external flash +ifneq (,$(filter vfs_default,$(USEMODULE))) + USEPKG += littlefs2 + USEMODULE += mtd +endif + include $(RIOTBOARD)/common/nrf52xxxdk/Makefile.dep diff --git a/boards/nrf52840dk/mtd.c b/boards/nrf52840dk/mtd.c index 449560f635..2f26ce9cb3 100644 --- a/boards/nrf52840dk/mtd.c +++ b/boards/nrf52840dk/mtd.c @@ -54,4 +54,8 @@ static mtd_spi_nor_t nrf52840dk_nor_dev = { mtd_dev_t *mtd0 = (mtd_dev_t *)&nrf52840dk_nor_dev; +#ifdef MODULE_VFS_DEFAULT +#include "vfs_default.h" +VFS_AUTO_MOUNT(littlefs2, VFS_MTD(nrf52840dk_nor_dev), VFS_DEFAULT_NVM(0), 0); +#endif #endif From 5b3c8380435d8fa3523f29bbe8dfd8df4c745c6b Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 14 Feb 2022 14:31:01 +0100 Subject: [PATCH 6/9] tests/vfs_default: add compile test for vfs_default --- tests/vfs_default/Makefile | 9 ++++++++ tests/vfs_default/Makefile.ci | 11 +++++++++ tests/vfs_default/main.c | 42 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 tests/vfs_default/Makefile create mode 100644 tests/vfs_default/Makefile.ci create mode 100644 tests/vfs_default/main.c diff --git a/tests/vfs_default/Makefile b/tests/vfs_default/Makefile new file mode 100644 index 0000000000..99cf7835a2 --- /dev/null +++ b/tests/vfs_default/Makefile @@ -0,0 +1,9 @@ +include ../Makefile.tests_common + +USEMODULE += vfs_default +USEMODULE += vfs_auto_format + +USEMODULE += shell +USEMODULE += shell_commands + +include $(RIOTBASE)/Makefile.include diff --git a/tests/vfs_default/Makefile.ci b/tests/vfs_default/Makefile.ci new file mode 100644 index 0000000000..28dd3afe00 --- /dev/null +++ b/tests/vfs_default/Makefile.ci @@ -0,0 +1,11 @@ +BOARD_INSUFFICIENT_MEMORY := \ + arduino-leonardo \ + arduino-nano \ + atmega328p-xplained-mini \ + arduino-duemilanove \ + arduino-uno \ + atmega328p \ + stm32f030f4-demo \ + samd10-xmini \ + nucleo-l011k4 \ + # diff --git a/tests/vfs_default/main.c b/tests/vfs_default/main.c new file mode 100644 index 0000000000..3cf3746e4b --- /dev/null +++ b/tests/vfs_default/main.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2022 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup tests + * @{ + * + * @file + * @brief Test application for vfs_default + * + * @author Benjamin Valentin + * @} + */ + +#include + +#include "shell.h" +#include "shell_commands.h" +#include "vfs_default.h" + +int main(void) +{ + vfs_DIR mount = {0}; + + /* list mounted file systems */ + puts("mount points:"); + while (vfs_iterate_mount_dirs(&mount)) { + printf("\t%s\n", mount.mp->mount_point); + } + printf("\ndata dir: %s\n", VFS_DEFAULT_DATA); + + /* start the shell */ + char line_buf[SHELL_DEFAULT_BUFSIZE]; + shell_run(NULL, line_buf, SHELL_DEFAULT_BUFSIZE); + + return 0; +} From 7ba58d4461ba15d3afd51f8c500f8ce90ac468e8 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 28 Mar 2022 17:46:15 +0200 Subject: [PATCH 7/9] sys/vfs: add vfs_default.h --- sys/include/vfs_default.h | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 sys/include/vfs_default.h diff --git a/sys/include/vfs_default.h b/sys/include/vfs_default.h new file mode 100644 index 0000000000..db6e0def1d --- /dev/null +++ b/sys/include/vfs_default.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2022 ML!PA Consulting GmbH + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup sys_vfs + * @brief VFS default mount points + * + * @{ + * @file + * @brief VFS layer default definitions & mount points + * + * @author Benjamin Valentin + */ + +#ifndef VFS_DEFAULT_H +#define VFS_DEFAULT_H + +#include "board.h" +#include "vfs.h" + +#if IS_USED(MODULE_FATFS_VFS) +#include "fs/fatfs.h" +#endif +#if IS_USED(MODULE_LITTLEFS) +#include "fs/littlefs_fs.h" +#endif +#if IS_USED(MODULE_LITTLEFS2) +#include "fs/littlefs2_fs.h" +#endif +#if IS_USED(MODULE_SPIFFS) +#include "fs/spiffs_fs.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Default mount point for removable storage + */ +#ifndef VFS_DEFAULT_SD +#define VFS_DEFAULT_SD(n) "/sd" # n +#endif + +/** + * @brief Default mount point for non-removable storage + */ +#ifndef VFS_DEFAULT_NVM +#define VFS_DEFAULT_NVM(n) "/nvm" # n +#endif + +/** + * @brief Default data directory + * This can be written to by applications + */ +#ifndef VFS_DEFAULT_DATA +#if IS_USED(MODULE_MTD_MCI) || IS_USED(MODULE_MTD_SDCARD) +#define VFS_DEFAULT_DATA VFS_DEFAULT_SD(0) +#else +#define VFS_DEFAULT_DATA VFS_DEFAULT_NVM(0) +#endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* VFS_DEFAULT_H */ + +/** @} */ From 2d352306ea4445a5e5d50d66c410238f95f08d51 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 28 Mar 2022 18:02:14 +0200 Subject: [PATCH 8/9] boards/same54-xpro: use default mount point --- boards/same54-xpro/board.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boards/same54-xpro/board.c b/boards/same54-xpro/board.c index 0b8597d004..77b009873e 100644 --- a/boards/same54-xpro/board.c +++ b/boards/same54-xpro/board.c @@ -63,8 +63,8 @@ static mtd_at24cxxx_t at24mac_dev = { mtd_dev_t *mtd1 = (mtd_dev_t *)&at24mac_dev; #ifdef MODULE_VFS_DEFAULT -#include "fs/littlefs2_fs.h" -VFS_AUTO_MOUNT(littlefs2, VFS_MTD(same54_nor_dev), "/nvm", 0); +#include "vfs_default.h" +VFS_AUTO_MOUNT(littlefs2, VFS_MTD(same54_nor_dev), VFS_DEFAULT_NVM(0), 0); #endif #endif /* MODULE_MTD */ From a652bea27ed43a433ba4c12ec1a155e82d9a6fb6 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Mon, 28 Mar 2022 18:03:43 +0200 Subject: [PATCH 9/9] boards/native: use default mount point --- boards/native/board_init.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/boards/native/board_init.c b/boards/native/board_init.c index 6f91c5c515..2449403ce2 100644 --- a/boards/native/board_init.c +++ b/boards/native/board_init.c @@ -35,7 +35,7 @@ mtd_dev_t *mtd0 = &mtd0_dev.base; #endif #ifdef MODULE_VFS -#include "vfs.h" +#include "vfs_default.h" /* * On `native` we define auto-mounts for every file system. @@ -47,27 +47,19 @@ mtd_dev_t *mtd0 = &mtd0_dev.base; /* littlefs support */ #if defined(MODULE_LITTLEFS) - -#include "fs/littlefs_fs.h" -VFS_AUTO_MOUNT(littlefs, VFS_MTD(mtd0_dev), "/nvm", 0); +VFS_AUTO_MOUNT(littlefs, VFS_MTD(mtd0_dev), VFS_DEFAULT_NVM(0), 0); /* littlefs2 support */ #elif defined(MODULE_LITTLEFS2) - -#include "fs/littlefs2_fs.h" -VFS_AUTO_MOUNT(littlefs2, VFS_MTD(mtd0_dev), "/nvm", 0); +VFS_AUTO_MOUNT(littlefs2, VFS_MTD(mtd0_dev), VFS_DEFAULT_NVM(0), 0); /* spiffs support */ #elif defined(MODULE_SPIFFS) - -#include "fs/spiffs_fs.h" -VFS_AUTO_MOUNT(spiffs, VFS_MTD(mtd0_dev), "/nvm", 0); +VFS_AUTO_MOUNT(spiffs, VFS_MTD(mtd0_dev), VFS_DEFAULT_NVM(0), 0); /* FAT support */ #elif defined(MODULE_FATFS_VFS) - -#include "fs/fatfs.h" -VFS_AUTO_MOUNT(fatfs, VFS_MTD(mtd0_dev), "/nvm", 0); +VFS_AUTO_MOUNT(fatfs, VFS_MTD(mtd0_dev), VFS_DEFAULT_NVM(0), 0); #endif #endif /* MODULE_VFS */