From a5418405d7209e3e2b8ec4839aaa2765b5b150f3 Mon Sep 17 00:00:00 2001 From: Alin Jerpelea Date: Thu, 13 Jun 2019 15:04:33 +0000 Subject: [PATCH] Merged in alinjerpelea/nuttx (pull request #897) configs: spresense: enable SPI Flash * arch: arm: cxd56xx: organize menu items Group all CXD56xx Options in one menu Signed-off-by: Alin Jerpelea * arch: arm: cxd56xx: add Storage Options menu Add Storage Options menu and Peripheral Support comment Signed-off-by: Alin Jerpelea * arch: arm: cxd56xx: add SPI Flash support add SPI Flash support for cxd56xx Signed-off-by: Alin Jerpelea * configs: spresense: enable SPI Flash Enable SPI Flash on spresense board Signed-off-by: Alin Jerpelea Approved-by: Gregory Nutt --- arch/arm/src/cxd56xx/Kconfig | 48 ++++- arch/arm/src/cxd56xx/Make.defs | 4 + arch/arm/src/cxd56xx/cxd56_sfc.c | 274 ++++++++++++++++++++++++ arch/arm/src/cxd56xx/cxd56_sfc.h | 66 ++++++ configs/spresense/Kconfig | 8 + configs/spresense/include/board.h | 1 + configs/spresense/include/cxd56_flash.h | 86 ++++++++ configs/spresense/src/Makefile | 4 + configs/spresense/src/cxd56_bringup.c | 8 + configs/spresense/src/cxd56_flash.c | 133 ++++++++++++ 10 files changed, 628 insertions(+), 4 deletions(-) create mode 100644 arch/arm/src/cxd56xx/cxd56_sfc.c create mode 100644 arch/arm/src/cxd56xx/cxd56_sfc.h create mode 100644 configs/spresense/include/cxd56_flash.h create mode 100644 configs/spresense/src/cxd56_flash.c diff --git a/arch/arm/src/cxd56xx/Kconfig b/arch/arm/src/cxd56xx/Kconfig index e63b13bf7c..d2fd2be001 100644 --- a/arch/arm/src/cxd56xx/Kconfig +++ b/arch/arm/src/cxd56xx/Kconfig @@ -3,7 +3,7 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -comment "CXD56xx Configuration Options" +comment "CXD56xx Options" config CXD56_ARCH_OPTS bool @@ -25,7 +25,6 @@ config CXD56_WLCSP bool "WLCSP 100 pin package" endchoice -endmenu comment "Basic Options" @@ -95,7 +94,9 @@ config CXD56_RTC_LATEINIT endif # CXD56_RTC -menu "CXD56xx Peripheral Support" +comment "Peripheral Support" + +menu "Peripheral Support" config CXD56_DMAC bool "DMAC" @@ -296,6 +297,45 @@ config CXD56_USBDEV default n ---help--- Enables USB +endmenu + +comment "Storage Options" + +menu "Storage Options" + +menuconfig CXD56_SFC + bool "SPI Flash" + default n if CXD56_SUBCORE + default y + select MTD + +if CXD56_SFC + +config CXD56_SFC_PAGE_SHIFT_SIZE + int "SPI Flash page shift size" + default 12 + range 8 12 + ---help--- + Specify page shift size to determine block size of SPI flash access. + Relationship between page shift size and block size is as follows. + page shift size : block size + 8 : 256 + 9 : 512 + 10 : 1024 + 11 : 2048 + 12 : 4096 + When file system is SMART file system, please set the value to SMART + Device sector size or less. + Following equation is satisfied. + MTD_SMART_SECTOR_SIZE >= (1 << CXD56_SFC_PAGE_SHIFT_SIZE) + +config CXD56_SFC_VERIFY_WRITE + bool "Enable write with verify" + default n + ---help--- + Enalbe SPI flash write function with verify. + +endif # CXD56_SFC menuconfig CXD56_SDIO bool "SDIO SD Card" @@ -337,5 +377,5 @@ config CXD56_SDIO_ENABLE_MULTIFUNCTION Support multi-function with SDIO interfaced peripheral other than SD Card. endif # SDIO Configuration - +endmenu endmenu diff --git a/arch/arm/src/cxd56xx/Make.defs b/arch/arm/src/cxd56xx/Make.defs index 27a6a51ce8..9afa5f6650 100644 --- a/arch/arm/src/cxd56xx/Make.defs +++ b/arch/arm/src/cxd56xx/Make.defs @@ -118,6 +118,10 @@ ifeq ($(CONFIG_CXD56_SDIO),y) CHIP_CSRCS += cxd56_sdhci.c endif +ifeq ($(CONFIG_CXD56_SFC),y) +CHIP_CSRCS += cxd56_sfc.c +endif + ifeq ($(CONFIG_CXD56_SPI),y) CHIP_CSRCS += cxd56_spi.c endif diff --git a/arch/arm/src/cxd56xx/cxd56_sfc.c b/arch/arm/src/cxd56xx/cxd56_sfc.c new file mode 100644 index 0000000000..91c7c6918a --- /dev/null +++ b/arch/arm/src/cxd56xx/cxd56_sfc.c @@ -0,0 +1,274 @@ +/**************************************************************************** + * arch/arm/src/cxd56xx/cxd56_sfc.c + * + * Copyright 2018 Sony Semiconductor Solutions Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Sony Semiconductor Solutions Corporation nor + * the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include + +/* Prototypes for Remote API */ + +int FM_RawWrite(uint32_t offset, const void *buf, uint32_t size); +int FM_RawVerifyWrite(uint32_t offset, const void *buf, uint32_t size); +int FM_RawRead(uint32_t offset, void *buf, uint32_t size); +int FM_RawEraseSector(uint32_t sector); + +#ifndef CONFIG_CXD56_SPIFLASHSIZE +# define CONFIG_CXD56_SPIFLASHSIZE (16 * 1024 * 1024) +#endif + +#define SECTOR_SHIFT 12 +#define SECTOR_SIZE (1 << SECTOR_SHIFT) + +#ifdef CONFIG_CXD56_SFC_PAGE_SHIFT_SIZE +# define PAGE_SHIFT CONFIG_CXD56_SFC_PAGE_SHIFT_SIZE +#else +# define PAGE_SHIFT 12 +#endif +#define PAGE_SIZE (1 << PAGE_SHIFT) + +/** + * Flash device information + */ +struct flash_controller_s +{ + struct mtd_dev_s mtd; /* MTD interface */ + uint32_t density; +}; + +static struct flash_controller_s g_sfc; + +/**************************************************************************** + * Name: cxd56_erase + ****************************************************************************/ +static int cxd56_erase(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks) +{ + int ret; + size_t i; + + finfo("erase: %08lx (%u blocks)\n", startblock << PAGE_SHIFT, nblocks); + + for (i = 0; i < nblocks; i++) + { + ret = FM_RawEraseSector(startblock + i); + if (ret < 0) + { + set_errno(-ret); + return ERROR; + } + } + return OK; +} + +static ssize_t cxd56_bread(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR uint8_t *buffer) +{ + int ret; + + finfo("bread: %08lx (%u blocks)\n", startblock << PAGE_SHIFT, nblocks); + + ret = FM_RawRead(startblock << PAGE_SHIFT, buffer, nblocks << PAGE_SHIFT); + if (ret < 0) + { + set_errno(-ret); + return ERROR; + } + + return nblocks; +} + +static ssize_t cxd56_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, + size_t nblocks, FAR const uint8_t *buffer) +{ + int ret; + + finfo("bwrite: %08lx (%u blocks)\n", startblock << PAGE_SHIFT, nblocks); + +#ifdef CONFIG_CXD56_SFC_VERIFY_WRITE + ret = FM_RawVerifyWrite(startblock << PAGE_SHIFT, buffer, + nblocks << PAGE_SHIFT); +#else + ret = FM_RawWrite(startblock << PAGE_SHIFT, buffer, + nblocks << PAGE_SHIFT); +#endif + if (ret < 0) + { + set_errno(-ret); + return ERROR; + } + + return nblocks; +} + +static ssize_t cxd56_read(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR uint8_t *buffer) +{ + int ret; + + finfo("read: %08lx (%u bytes)\n", offset, nbytes); + + ret = FM_RawRead(offset, buffer, nbytes); + if (ret < 0) + { + set_errno(-ret); + return ERROR; + } + + return nbytes; +} + +#ifdef CONFIG_MTD_BYTE_WRITE +static ssize_t cxd56_write(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR const uint8_t *buffer) +{ + int ret; + + finfo("write: %08lx (%u bytes)\n", offset, nbytes); + +#ifdef CONFIG_CXD56_SFC_VERIFY_WRITE + ret = FM_RawVerifyWrite(offset, buffer, nbytes); +#else + ret = FM_RawWrite(offset, buffer, nbytes); +#endif + if (ret < 0) + { + set_errno(-ret); + return ERROR; + } + + return nbytes; +} +#endif + +static int cxd56_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) +{ + struct flash_controller_s *priv = (struct flash_controller_s *)dev; + int ret = OK; + + switch (cmd) + { + case MTDIOC_GEOMETRY: + { + FAR struct mtd_geometry_s *geo = + (FAR struct mtd_geometry_s *)((uintptr_t)arg); + finfo("cmd: GEOM\n"); + if (geo) + { + /* Populate the geometry structure with information need to know + * the capacity and how to access the device. + * + * NOTE: that the device is treated as though it where just an + * array of fixed size blocks. That is most likely not true, + * but the client will expect the device logic to do whatever is + * necessary to make it appear so. + */ + + geo->blocksize = PAGE_SIZE; + geo->erasesize = SECTOR_SIZE; + geo->neraseblocks = priv->density >> SECTOR_SHIFT; + ret = OK; + + finfo("blocksize: %d erasesize: %d neraseblocks: %d\n", + geo->blocksize, geo->erasesize, geo->neraseblocks); + } + } + break; + + case MTDIOC_BULKERASE: + { + /* Erase the entire device */ + + uint32_t sec = 0; + uint32_t last = priv->density >> SECTOR_SHIFT; + + finfo("cmd: ERASE\n"); + + while (sec < last) + { + FM_RawEraseSector(sec); + sec++; + } + } + break; + + case MTDIOC_XIPBASE: + default: + ret = -ENOTTY; /* Bad command */ + break; + } + + return ret; +} + +FAR struct mtd_dev_s *cxd56_sfc_initialize(void) +{ + struct flash_controller_s *priv = &g_sfc; + + priv->mtd.erase = cxd56_erase; + priv->mtd.bread = cxd56_bread; + priv->mtd.bwrite = cxd56_bwrite; + priv->mtd.read = cxd56_read; +#ifdef CONFIG_MTD_BYTE_WRITE + priv->mtd.write = cxd56_write; +#endif + priv->mtd.ioctl = cxd56_ioctl; + + /* TODO: Flash reserved area should be configurable dynamically. */ + + priv->density = CONFIG_CXD56_SPIFLASHSIZE; + +#ifdef CONFIG_SFC_SECTOR512 + + /* Allocate a buffer for the erase block cache */ + + priv->cache = (FAR uint8_t *)kmm_malloc(SPIFI_BLKSIZE); + if (!priv->cache) + { + /* Allocation failed! */ + + /* Discard all of that work we just did and return NULL */ + + ferr("ERROR: Allocation failed\n"); + return NULL; + } +#endif + + return &priv->mtd; +} diff --git a/arch/arm/src/cxd56xx/cxd56_sfc.h b/arch/arm/src/cxd56xx/cxd56_sfc.h new file mode 100644 index 0000000000..1a4ceb05f1 --- /dev/null +++ b/arch/arm/src/cxd56xx/cxd56_sfc.h @@ -0,0 +1,66 @@ +/**************************************************************************** + * arch/arm/src/cxd56xx/cxd56_sfc.h + * + * Copyright 2018 Sony Semiconductor Solutions Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Sony Semiconductor Solutions Corporation nor + * the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM_SRC_CXD56XX_CXD56_SFC_H +#define __ARCH_ARM_SRC_CXD56XX_CXD56_SFC_H + +/**************************************************************************** + * include files + ****************************************************************************/ + +#include +#include + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +FAR struct mtd_dev_s *cxd56_sfc_initialize(void); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __ASSEMBLY__ */ + +#endif diff --git a/configs/spresense/Kconfig b/configs/spresense/Kconfig index 1cf22ff3b3..7af7de405f 100644 --- a/configs/spresense/Kconfig +++ b/configs/spresense/Kconfig @@ -5,6 +5,14 @@ if ARCH_BOARD_SPRESENSE +config CXD56_SPIFLASHSIZE + hex + default 0x400000 + depends on CXD56_SFC + ---help--- + Specify the SPI flash total available size for the application. + This value is generally set half of SPI flash device capacity. + config SDCARD_TXS02612 bool "SD Card TXS02612 port expander with voltage level translation" default y diff --git a/configs/spresense/include/board.h b/configs/spresense/include/board.h index a4c260f9d8..f9147906ac 100644 --- a/configs/spresense/include/board.h +++ b/configs/spresense/include/board.h @@ -47,6 +47,7 @@ #include "cxd56_clock.h" #include "cxd56_power.h" +#include "cxd56_flash.h" #include "cxd56_sdcard.h" /**************************************************************************** diff --git a/configs/spresense/include/cxd56_flash.h b/configs/spresense/include/cxd56_flash.h new file mode 100644 index 0000000000..dc3da7bfae --- /dev/null +++ b/configs/spresense/include/cxd56_flash.h @@ -0,0 +1,86 @@ +/**************************************************************************** + * configs/spresense/include/cxd56_flash.h + * + * Copyright 2018 Sony Semiconductor Solutions Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Sony Semiconductor Solutions Corporation nor + * the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __BOARD_COMMON_INCLUDE_CXD56_FLASH_H +#define __BOARD_COMMON_INCLUDE_CXD56_FLASH_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: board_flash_initialize + * + * Description: + * Initialize the SPI-Flash device and mount the file system. + * + ****************************************************************************/ + +#ifdef CONFIG_CXD56_SFC +int board_flash_initialize(void); +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __BOARD_COMMON_INCLUDE_CXD56_FLASH_H */ diff --git a/configs/spresense/src/Makefile b/configs/spresense/src/Makefile index 225b1c18ca..359d5158cd 100644 --- a/configs/spresense/src/Makefile +++ b/configs/spresense/src/Makefile @@ -60,6 +60,10 @@ ifeq ($(CONFIG_ARCH_LEDS),y) CSRCS += cxd56_leds.c endif +ifeq ($(CONFIG_CXD56_SFC),y) +CSRCS += cxd56_flash.c +endif + ifeq ($(CONFIG_CXD56_SDIO),y) CSRCS += cxd56_sdcard.c endif diff --git a/configs/spresense/src/cxd56_bringup.c b/configs/spresense/src/cxd56_bringup.c index eb5e19408b..4862e9d3a0 100644 --- a/configs/spresense/src/cxd56_bringup.c +++ b/configs/spresense/src/cxd56_bringup.c @@ -208,6 +208,14 @@ int cxd56_bringup(void) } #endif +#ifdef CONFIG_CXD56_SFC + ret = board_flash_initialize(); + if (ret < 0) + { + _err("ERROR: Failed to initialze SPI-Flash. %d\n", errno); + } +#endif + /* In order to prevent Hi-Z from being input to the SD Card controller, * Initialize SDIO pins to GPIO low output with internal pull-down. */ diff --git a/configs/spresense/src/cxd56_flash.c b/configs/spresense/src/cxd56_flash.c new file mode 100644 index 0000000000..1a5d30adfe --- /dev/null +++ b/configs/spresense/src/cxd56_flash.c @@ -0,0 +1,133 @@ +/**************************************************************************** + * configs/spresense/src/cxd56_flash.c + * + * Copyright 2018 Sony Semiconductor Solutions Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Sony Semiconductor Solutions Corporation nor + * the names of its contributors may be used to endorse or promote + * products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_FS_NXFFS +# include +#endif + +#include "cxd56_sfc.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef CONFIG_SFC_DEVNO +# define CONFIG_SFC_DEVNO 0 +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_flash_initialize + * + * Description: + * Initialize the SPI-Flash device and mount the file system. + * + ****************************************************************************/ + +int board_flash_initialize(void) +{ + int ret; + FAR struct mtd_dev_s *mtd; + + mtd = cxd56_sfc_initialize(); + if (!mtd) + { + ferr("ERROR: Failed to initialize SFC. %d\n ", ret); + return -ENODEV; + } + + /* use the FTL layer to wrap the MTD driver as a block driver */ + + ret = ftl_initialize(CONFIG_SFC_DEVNO, mtd); + if (ret < 0) + { + ferr("ERROR: Initializing the FTL layer: %d\n", ret); + return ret; + } + +#if defined(CONFIG_FS_SMARTFS) + /* Initialize to provide SMARTFS on the MTD interface */ + + ret = smart_initialize(CONFIG_SFC_DEVNO, mtd, NULL); + if (ret < 0) + { + ferr("ERROR: SmartFS initialization failed: %d\n", ret); + return ret; + } + + ret = mount("/dev/smart0d1", "/mnt/spif", "smartfs", 0, NULL); + if (ret < 0) + { + ferr("ERROR: Failed to mount the SmartFS volume: %d\n", errno); + return ret; + } + +#elif defined(CONFIG_FS_NXFFS) + /* Initialize to provide NXFFS on the MTD interface */ + + ret = nxffs_initialize(mtd); + if (ret < 0) + { + ferr("ERROR: NXFFS initialization failed: %d\n", ret); + return ret; + } + + ret = mount(NULL, "/mnt/spif", "nxffs", 0, NULL); + if (ret < 0) + { + ferr("ERROR: Failed to mount the NXFFS volume: %d\n", errno); + return ret; + } +#endif + + return OK; +}