qemu/armv7a: register cfi flash

search the device tree and register cfi flash

test flowchart:
mount -t littlefs -o autoformat /dev/cfi-flash1 /data
fstest -m /data

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2025-02-05 13:25:08 +08:00 committed by archer
parent ef24233501
commit 34bde7b80a
6 changed files with 150 additions and 0 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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 <errno.h>
#include <debug.h>
#include <nuttx/config.h>
#include <nuttx/fdt.h>
#include <nuttx/mtd/mtd.h>
#include <libfdt.h>
/****************************************************************************
* 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;
}

View file

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