From fa8d5cd53d0681ac2247e76f16ae367a3bf39566 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Thu, 12 Dec 2024 14:48:55 +0900 Subject: [PATCH] littlefs: Use LFS_DEFINES if available --- fs/littlefs/CMakeLists.txt | 22 +++++++++-------- fs/littlefs/Kconfig | 12 +++++++++ fs/littlefs/Make.defs | 5 ++++ fs/littlefs/lfs_nuttx_defines.h | 43 +++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 fs/littlefs/lfs_nuttx_defines.h diff --git a/fs/littlefs/CMakeLists.txt b/fs/littlefs/CMakeLists.txt index 236dde4673..d6f5e67e30 100644 --- a/fs/littlefs/CMakeLists.txt +++ b/fs/littlefs/CMakeLists.txt @@ -51,16 +51,18 @@ if(CONFIG_FS_LITTLEFS) target_compile_definitions( fs - PRIVATE -DLFS_TRACE=finfo - -DLFS_DEBUG=finfo - -DLFS_WARN=fwarn - -DLFS_ERROR=ferr - -DLFS_ASSERT=DEBUGASSERT - -DLFS_CONFIG=${CMAKE_CURRENT_LIST_DIR}/lfs_vfs.h - -DLFS_NAME_MAX=${CONFIG_FS_LITTLEFS_NAME_MAX} - -DLFS_FILE_MAX=${CONFIG_FS_LITTLEFS_FILE_MAX} - -DLFS_ATTR_MAX=${CONFIG_FS_LITTLEFS_ATTR_MAX} - $<$:-DLFS_MULTIVERSION>) + PRIVATE + $<$>:-DLFS_TRACE=finfo> + $<$>:-DLFS_DEBUG=finfo> + $<$>:-DLFS_WARN=fwarn> + $<$>:-DLFS_ERROR=ferr> + $<$>:-DLFS_ASSERT=DEBUGASSERT> + $<$>:-DLFS_CONFIG=${CMAKE_CURRENT_LIST_DIR}/lfs_vfs.h> + $<$:-DLFS_DEFINES=${CMAKE_CURRENT_LIST_DIR}/lfs_nuttx_defines.h> + -DLFS_NAME_MAX=${CONFIG_FS_LITTLEFS_NAME_MAX} + -DLFS_FILE_MAX=${CONFIG_FS_LITTLEFS_FILE_MAX} + -DLFS_ATTR_MAX=${CONFIG_FS_LITTLEFS_ATTR_MAX} + $<$:-DLFS_MULTIVERSION>) # Note: the littlefs upstream doesn't seems to care -Wshadow cf. # https://github.com/littlefs-project/littlefs/pull/873 diff --git a/fs/littlefs/Kconfig b/fs/littlefs/Kconfig index adefd7fbfa..86b841c519 100644 --- a/fs/littlefs/Kconfig +++ b/fs/littlefs/Kconfig @@ -129,6 +129,18 @@ config FS_LITTLEFS_LOCAL_PATCHES patches for LITTLEFS. This is NOT expected to be tweaked directly by users. +config FS_LITTLEFS_HAS_LFS_DEFINES + bool "Use LFS_DEFINES (available for littlefs >=2.10.0)" + depends on !FS_LITTLEFS_LOCAL_PATCHES + default y + ---help--- + Set this y if you are using littlefs versions which supports + LFS_DEFINES. (that is, 2.10.0 and later) + Otherwise, set this n. + + See the littlefs 2.10.0 release notes about what LFS_DEFINES is. + https://github.com/littlefs-project/littlefs/releases/tag/v2.10.0 + config FS_LITTLEFS_ATTR_UPDATE bool "LITTLEFS update attributes" depends on FS_LITTLEFS_ATTR_MAX > 0 diff --git a/fs/littlefs/Make.defs b/fs/littlefs/Make.defs index 57109d5755..daa8320fdf 100644 --- a/fs/littlefs/Make.defs +++ b/fs/littlefs/Make.defs @@ -41,12 +41,17 @@ VPATH += :littlefs/littlefs # cf. https://github.com/littlefs-project/littlefs/pull/873 CFLAGS += -Wno-shadow +ifeq ($(CONFIG_FS_LITTLEFS_HAS_LFS_DEFINES),y) +CFLAGS += -DLFS_DEFINES=../lfs_nuttx_defines.h +else CFLAGS += -DLFS_TRACE=finfo CFLAGS += -DLFS_DEBUG=finfo CFLAGS += -DLFS_WARN=fwarn CFLAGS += -DLFS_ERROR=ferr CFLAGS += -DLFS_ASSERT=DEBUGASSERT CFLAGS += -DLFS_CONFIG=../lfs_vfs.h +endif + CFLAGS += -DLFS_NAME_MAX=$(CONFIG_FS_LITTLEFS_NAME_MAX) CFLAGS += -DLFS_FILE_MAX=$(CONFIG_FS_LITTLEFS_FILE_MAX) CFLAGS += -DLFS_ATTR_MAX=$(CONFIG_FS_LITTLEFS_ATTR_MAX) diff --git a/fs/littlefs/lfs_nuttx_defines.h b/fs/littlefs/lfs_nuttx_defines.h new file mode 100644 index 0000000000..68ad280de5 --- /dev/null +++ b/fs/littlefs/lfs_nuttx_defines.h @@ -0,0 +1,43 @@ +/**************************************************************************** + * fs/littlefs/lfs_nuttx_defines.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include "fs_heap.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define LFS_TRACE finfo +#define LFS_DEBUG finfo +#define LFS_WARN fwarn +#define LFS_ERROR ferr + +#define LFS_ASSERT DEBUGASSERT + +#define LFS_MALLOC(sz) fs_heap_malloc(sz) +#define LFS_FREE(p) fs_heap_free(p)