diff --git a/boards/arm/qemu/qemu-armv7a/configs/full/defconfig b/boards/arm/qemu/qemu-armv7a/configs/full/defconfig index 1b5dc69a8f0..dd26aa94ca1 100644 --- a/boards/arm/qemu/qemu-armv7a/configs/full/defconfig +++ b/boards/arm/qemu/qemu-armv7a/configs/full/defconfig @@ -29,6 +29,8 @@ CONFIG_CXX_LOCALIZATION=y CONFIG_CXX_WCHAR=y CONFIG_DEBUG_ASSERTIONS=y CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FS=y +CONFIG_DEBUG_FS_ERROR=y CONFIG_DEBUG_FULLOPT=y CONFIG_DEBUG_SCHED=y CONFIG_DEBUG_SCHED_ERROR=y @@ -56,6 +58,7 @@ CONFIG_FLASH_SIZE=50331648 CONFIG_FLASH_START=0x00600000 CONFIG_FLASH_VSTART=0x00600000 CONFIG_FS_LARGEFILE=y +CONFIG_FS_LITTLEFS=y CONFIG_FS_LOCK_BUCKET_SIZE=8 CONFIG_FS_PROCFS=y CONFIG_FS_ROMFS=y @@ -88,6 +91,8 @@ CONFIG_LV_USE_LOG=y CONFIG_LV_USE_NUTTX=y CONFIG_LV_USE_NUTTX_TOUCHSCREEN=y CONFIG_LV_USE_QRCODE=y +CONFIG_MTD=y +CONFIG_MTD_CFI=y CONFIG_NET=y CONFIG_NETDEV_HPWORK_THREAD=y CONFIG_NETDEV_IFINDEX=y @@ -133,6 +138,7 @@ CONFIG_SYSTEM_NXCODEC=y CONFIG_SYSTEM_VI=y CONFIG_SYSTEM_YMODEM=y CONFIG_SYSTEM_ZMODEM=y +CONFIG_TESTING_FSTEST=y CONFIG_TESTING_GETPRIME=y CONFIG_TESTING_OSTEST=y CONFIG_TIMER_FD=y diff --git a/boards/arm/qemu/qemu-armv7a/src/qemu_bringup.c b/boards/arm/qemu/qemu-armv7a/src/qemu_bringup.c index 2e1f43e5e82..463f846de7f 100644 --- a/boards/arm/qemu/qemu-armv7a/src/qemu_bringup.c +++ b/boards/arm/qemu/qemu-armv7a/src/qemu_bringup.c @@ -84,6 +84,14 @@ static void register_devices_from_fdt(void) } #endif +#ifdef CONFIG_MTD_CFI + ret = fdt_cfi_register(fdt); + if (ret < 0) + { + syslog(LOG_ERR, "fdt_cfi_register failed, ret=%d\n", ret); + } +#endif + UNUSED(ret); } @@ -130,6 +138,16 @@ int qemu_bringup(void) register_devices_from_fdt(); #endif +#if defined(CONFIG_FS_LITTLEFS) && defined(CONFIG_MTD_CFI) + /* Mount the procfs file system */ + + ret = nx_mount("/dev/cfi-flash1", "/data", "littlefs", 0, "autoformat"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: Failed to mount littlefs at /data: %d\n", ret); + } +#endif + UNUSED(ret); return OK; } diff --git a/drivers/devicetree/CMakeLists.txt b/drivers/devicetree/CMakeLists.txt index 98ce039cb7e..2f9c9391af4 100644 --- a/drivers/devicetree/CMakeLists.txt +++ b/drivers/devicetree/CMakeLists.txt @@ -30,6 +30,10 @@ if(CONFIG_DEVICE_TREE) list(APPEND SRCS fdt_virtio_mmio.c) endif() + if(CONFIG_MTD_CFI) + list(APPEND SRCS fdt_cfi.c) + endif() + target_include_directories(drivers PRIVATE ${NUTTX_DIR}/libs/libc/fdt/dtc/libfdt) target_sources(drivers PRIVATE ${SRCS}) diff --git a/drivers/devicetree/Make.defs b/drivers/devicetree/Make.defs index 23b5e6e4033..b67aadd581f 100644 --- a/drivers/devicetree/Make.defs +++ b/drivers/devicetree/Make.defs @@ -32,6 +32,10 @@ ifeq ($(CONFIG_DRIVERS_VIRTIO_MMIO),y) CSRCS += fdt_virtio_mmio.c endif +ifeq ($(CONFIG_MTD_CFI),y) + CSRCS += fdt_cfi.c +endif + CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)libs$(DELIM)libc$(DELIM)fdt$(DELIM)dtc$(DELIM)libfdt DEPPATH += --dep-path devicetree diff --git a/drivers/devicetree/fdt_cfi.c b/drivers/devicetree/fdt_cfi.c new file mode 100644 index 00000000000..e544ef18c0c --- /dev/null +++ b/drivers/devicetree/fdt_cfi.c @@ -0,0 +1,101 @@ +/**************************************************************************** + * drivers/devicetree/fdt_cfi.c + * + * 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 + +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: fdt_cfi_register + * + * Description: + * This function is used to register an fci flash from the device tree + * + * Input Parameters: + * fdt - Device tree handle + * + * Returned Value: + * Return 0 if success, nageative if failed + * + ****************************************************************************/ + +int fdt_cfi_register(FAR const void *fdt) +{ + int ret = 0; + int offset = -1; + + while ((offset = fdt_node_offset_by_compatible(fdt, offset, "cfi-flash")) + >= 0) + { + uintptr_t address_cell = fdt_get_parent_address_cells(fdt, offset); + uintptr_t size_cell = fdt_get_parent_size_cells(fdt, offset); + uint32_t bankwidth = fdt_get_bankwidth(fdt, offset); + uint32_t reg_cnt = fdt_get_reg_count(fdt, offset); + size_t num; + size_t i; + + /* get number of "address & size" cell pairs */ + + num = reg_cnt / (4 * (address_cell + size_cell)); + for (i = 0; i < num; i++) + { + uintptr_t flash_base = fdt_get_reg_base_by_index(fdt, offset, i); + uintptr_t flash_end = fdt_get_reg_size_by_index(fdt, offset, i) + + flash_base; + + if ((CONFIG_FLASH_START > flash_end || + CONFIG_FLASH_START + CONFIG_FLASH_SIZE < flash_base)) + { + ret = register_cfi_driver(flash_base, flash_end, + bankwidth, i); + if (ret < 0) + { + break; + } + } + else + { + ferr("cfi flash%d has beed used to store text:" + "[%x,%x], flash:[%x,%x]\n", i, flash_base, flash_end, + CONFIG_FLASH_START, CONFIG_FLASH_START + + CONFIG_FLASH_SIZE); + } + } + } + + return ret; +} diff --git a/include/nuttx/fdt.h b/include/nuttx/fdt.h index 23b939bc45e..af2fda728db 100644 --- a/include/nuttx/fdt.h +++ b/include/nuttx/fdt.h @@ -491,4 +491,21 @@ int fdt_pci_ecam_register(FAR const void *fdt); int fdt_virtio_mmio_devices_register(FAR const void *fdt, int irqbase); #endif +/**************************************************************************** + * Name: fdt_cfi_register + * + * Description: + * This function is used to register an fci flash from the device tree + * + * Input Parameters: + * fdt - Device tree handle + * + * Returned Value: + * Return 0 if success, nageative if failed + * + ****************************************************************************/ + +#ifdef CONFIG_MTD_CFI +int fdt_cfi_register(FAR const void *fdt); +#endif #endif /* __INCLUDE_NUTTX_FDT_H */