littlefs: Use LFS_DEFINES if available

This commit is contained in:
YAMAMOTO Takashi 2024-12-12 14:48:55 +09:00 committed by Xiang Xiao
parent 9e8e7ace09
commit fa8d5cd53d
4 changed files with 72 additions and 10 deletions

View file

@ -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}
$<$<BOOL:${CONFIG_FS_LITTLEFS_MULTI_VERSION}>:-DLFS_MULTIVERSION>)
PRIVATE
$<$<NOT:$<BOOL:${CONFIG_FS_LITTLEFS_HAS_LFS_DEFINES}>>:-DLFS_TRACE=finfo>
$<$<NOT:$<BOOL:${CONFIG_FS_LITTLEFS_HAS_LFS_DEFINES}>>:-DLFS_DEBUG=finfo>
$<$<NOT:$<BOOL:${CONFIG_FS_LITTLEFS_HAS_LFS_DEFINES}>>:-DLFS_WARN=fwarn>
$<$<NOT:$<BOOL:${CONFIG_FS_LITTLEFS_HAS_LFS_DEFINES}>>:-DLFS_ERROR=ferr>
$<$<NOT:$<BOOL:${CONFIG_FS_LITTLEFS_HAS_LFS_DEFINES}>>:-DLFS_ASSERT=DEBUGASSERT>
$<$<NOT:$<BOOL:${CONFIG_FS_LITTLEFS_HAS_LFS_DEFINES}>>:-DLFS_CONFIG=${CMAKE_CURRENT_LIST_DIR}/lfs_vfs.h>
$<$<BOOL:${CONFIG_FS_LITTLEFS_HAS_LFS_DEFINES}>:-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}
$<$<BOOL:${CONFIG_FS_LITTLEFS_MULTI_VERSION}>:-DLFS_MULTIVERSION>)
# Note: the littlefs upstream doesn't seems to care -Wshadow cf.
# https://github.com/littlefs-project/littlefs/pull/873

View file

@ -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

View file

@ -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)

View file

@ -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 <debug.h>
#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)