9
0
Fork 0

Add M25Px as paging source

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@2937 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2010-09-11 01:58:26 +00:00
parent e3bc212c54
commit 2794f1b7f8
11 changed files with 235 additions and 22 deletions

View File

@ -12,7 +12,7 @@
<h1><big><font color="#3c34ec"> <h1><big><font color="#3c34ec">
<i>NuttX RTOS Porting Guide</i> <i>NuttX RTOS Porting Guide</i>
</font></big></h1> </font></big></h1>
<p>Last Updated: September 8, 2010</p> <p>Last Updated: September 10, 2010</p>
</td> </td>
</tr> </tr>
</table> </table>
@ -2593,6 +2593,21 @@ build
This should be defined to be zero for the typical device that has only a single slot (See <code>CONFIG_MMCSD_NSLOTS</code>). This should be defined to be zero for the typical device that has only a single slot (See <code>CONFIG_MMCSD_NSLOTS</code>).
If defined, <code>CONFIG_PAGING_SDSLOT</code> will instruct certain board-specific logic to initialize the media in this SD slot. If defined, <code>CONFIG_PAGING_SDSLOT</code> will instruct certain board-specific logic to initialize the media in this SD slot.
</li> </li>
<li>
<code>CONFIG_PAGING_M25PX</code>:
Use the m25px.c FLASH driver.
If this is selected, then the MTD interface to the MP25x device will be used to support paging.
</li>
<li>
<code>CONFIG_PAGING_M25PX_BINOFFSET</code>:
If CONFIG_PAGING_M25PX is defined then CONFIG_PAGING_M25PX_BINOFFSET will be used to specify the offset in bytes into the FLASH device where the NuttX binary image is located.
Default: 0
</li>
<li>
<code>CONFIG_PAGING_M25PX_SPIPORT</code>:
If CONFIG_PAGING_M25PX is defined and the device has multiple SPI busses (ports), then this configuration should be set to indicate which SPI port the M25Px device is connected.
Default: 0
</li>
</ul> </ul>
<p> <p>
The following can be used to disable categories of APIs supported The following can be used to disable categories of APIs supported

View File

@ -420,6 +420,17 @@ defconfig -- This is a configuration file similar to the Linux
only a single slot (See CONFIG_MMCSD_NSLOTS). If defined, only a single slot (See CONFIG_MMCSD_NSLOTS). If defined,
CONFIG_PAGING_SDSLOT will instruct certain board-specific logic to CONFIG_PAGING_SDSLOT will instruct certain board-specific logic to
initialize the media in this SD slot. initialize the media in this SD slot.
CONFIG_PAGING_M25PX - Use the m25px.c FLASH driver. If this is selected,
then the MTD interface to the MP25x device will be used to support
paging.
CONFIG_PAGING_M25PX_BINOFFSET - If CONFIG_PAGING_M25PX is defined then
CONFIG_PAGING_M25PX_BINOFFSET will be used to specify the offset
in bytes into the FLASH device where the NuttX binary image is located.
Default: 0
CONFIG_PAGING_M25PX_SPIPORT - If CONFIG_PAGING_M25PX is defined and
the device has multiple SPI busses (ports), then this configuration
should be set to indicate which SPI port the M25Px device is connected.
Default: 0
The following can be used to disable categories of APIs supported The following can be used to disable categories of APIs supported
by the OS. If the compiler supports weak functions, then it by the OS. If the compiler supports weak functions, then it

View File

@ -2,7 +2,7 @@
* configs/ea3131/include/board.h * configs/ea3131/include/board.h
* include/arch/board/board.h * include/arch/board/board.h
* *
* Copyright (C) 2009 Gregory Nutt. All rights reserved. * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -117,7 +117,7 @@ CONFIG_LPC313X_BUILDROOT=y
# Individual subsystems can be enabled: # Individual subsystems can be enabled:
# #
CONFIG_LPC313X_MCI=n CONFIG_LPC313X_MCI=n
CONFIG_LPC313X_SPI=n CONFIG_LPC313X_SPI=y
CONFIG_LPC313X_UART=y CONFIG_LPC313X_UART=y
# #
@ -424,6 +424,17 @@ CONFIG_SIG_SIGWORK=4
# only a single slot (See CONFIG_MMCSD_NSLOTS). If defined, # only a single slot (See CONFIG_MMCSD_NSLOTS). If defined,
# CONFIG_PAGING_SDSLOT will instruct certain board-specific logic to # CONFIG_PAGING_SDSLOT will instruct certain board-specific logic to
# initialize the media in this SD slot. # initialize the media in this SD slot.
# CONFIG_PAGING_M25PX - Use the m25px.c FLASH driver. If this is selected,
# then the MTD interface to the MP25x device will be used to support
# paging.
# CONFIG_PAGING_M25PX_BINOFFSET - If CONFIG_PAGING_M25PX is defined then
# CONFIG_PAGING_M25PX_BINOFFSET will be used to specify the offset
# in bytes into the FLASH device where the NuttX binary image is located.
# Default: 0
# CONFIG_PAGING_M25PX_SPIPORT - If CONFIG_PAGING_M25PX is defined and
# the device has multiple SPI busses (ports), then this configuration
# should be set to indicate which SPI port the M25Px device is connected.
# Default: 0
# #
CONFIG_PAGING=y CONFIG_PAGING=y
CONFIG_PAGING_PAGESIZE=1024 CONFIG_PAGING_PAGESIZE=1024
@ -445,6 +456,9 @@ CONFIG_PAGING_BLOCKINGFILL=y
CONFIG_PAGING_MOUNTPT="/mnt/pgsrc" CONFIG_PAGING_MOUNTPT="/mnt/pgsrc"
CONFIG_PAGING_MINOR=0 CONFIG_PAGING_MINOR=0
CONFIG_PAGING_SDSLOT=0 CONFIG_PAGING_SDSLOT=0
CONFIG_PAGING_M25PX=y
CONFIG_PAGING_M25PX_BINOFFSET=0
CONFIG_PAGING_M25PX_SPIPORT=0
# #
# The following can be used to disable categories of # The following can be used to disable categories of

View File

@ -40,7 +40,19 @@ CFLAGS += -I$(TOPDIR)/sched
ASRCS = ASRCS =
AOBJS = $(ASRCS:.S=$(OBJEXT)) AOBJS = $(ASRCS:.S=$(OBJEXT))
CSRCS = up_boot.c up_buttons.c up_clkinit.c up_leds.c up_mem.c up_spi.c CSRCS = up_boot.c up_clkinit.c
ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += up_buttons.c
endif
ifeq ($(CONFIG_LPC313X_EXTSDRAM),y)
CSRCS += up_mem.c
endif
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += up_leds.c
endif
ifeq ($(CONFIG_LPC313X_SPI),y)
CSRCS += up_spi.c
endif
ifeq ($(CONFIG_EXAMPLES_NSH_ARCHINIT),y) ifeq ($(CONFIG_EXAMPLES_NSH_ARCHINIT),y)
CSRCS += up_nsh.c CSRCS += up_nsh.c
endif endif

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* configs/ea3131/src/up_leds.c * configs/ea3131/src/up_leds.c
* *
* Copyright (C) 2009 Gregory Nutt. All rights reserved. * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -2,7 +2,7 @@
* configs/ea3131/src/up_clkinit.c * configs/ea3131/src/up_clkinit.c
* arch/arm/src/board/up_clkinit.c * arch/arm/src/board/up_clkinit.c
* *
* Copyright (C) 2009 Gregory Nutt. All rights reserved. * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* References: * References:

View File

@ -62,6 +62,13 @@
# endif # endif
#endif #endif
#ifdef CONFIG_PAGING_M25PX
# include <sys/ioctl.h>
# include <nuttx/ioctl.h>
# include <nuttx/spi.h>
# include <nuttx/mtd.h>
#endif
/**************************************************************************** /****************************************************************************
* Definitions * Definitions
****************************************************************************/ ****************************************************************************/
@ -72,6 +79,7 @@
#ifdef CONFIG_ARCH_BOARD_EA3131 #ifdef CONFIG_ARCH_BOARD_EA3131
# define HAVE_SD 1 # define HAVE_SD 1
# define HAVE_SPINOR 1
# if defined(CONFIG_PAGING_SDSLOT) && CONFIG_PAGING_SDSLOT != 0 # if defined(CONFIG_PAGING_SDSLOT) && CONFIG_PAGING_SDSLOT != 0
# error "Only one SD slot" # error "Only one SD slot"
# undef CONFIG_PAGING_SDSLOT # undef CONFIG_PAGING_SDSLOT
@ -81,6 +89,14 @@
# error "Unrecognized LPC313X board" # error "Unrecognized LPC313X board"
# undef CONFIG_PAGING_SDSLOT # undef CONFIG_PAGING_SDSLOT
# undef HAVE_SD # undef HAVE_SD
# undef HAVE_SPINOR
#endif
/* Sanity check: We can only perform paging using a single source device */
#if defined(CONFIG_PAGING_BINPATH) && defined(CONFIG_PAGING_M25PX)
# error "Both CONFIG_PAGING_BINPATH and CONFIG_PAGING_M25PX are defined"
# undef CONFIG_PAGING_BINPATH
#endif #endif
/* Are we accessing the page source data through a file path? */ /* Are we accessing the page source data through a file path? */
@ -122,10 +138,37 @@
#endif /* CONFIG_PAGING_BINPATH */ #endif /* CONFIG_PAGING_BINPATH */
/* Are we accessing the page source data through the M25P* MTD device? */
#ifdef CONFIG_PAGING_M25PX
/* Verify that SPI support is enabld */
#ifndef CONFIG_LPC313X_SPI
# error "SPI support is not enabled"
#endif
/* Make sure that some value is defined for the offset into the FLASH
* of the NuttX binary image.
*/
# ifndef CONFIG_PAGING_M25PX_BINOFFSET
# define CONFIG_PAGING_M25PX_BINOFFSET 0
# endif
/* Make sure that some value is defined for the SPI port number */
# ifndef CONFIG_PAGING_M25PX_SPIPORT
# define CONFIG_PAGING_M25PX_SPIPORT 0
# endif
#endif
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
/* State structure needed to support paging from a file */
#ifdef CONFIG_PAGING_BINPATH #ifdef CONFIG_PAGING_BINPATH
struct pg_source_s struct pg_source_s
{ {
@ -134,11 +177,34 @@ struct pg_source_s
}; };
#endif #endif
/* State structured needd to support paging through the M25P* MTD interface. */
#ifdef CONFIG_PAGING_M25PX
struct pg_source_s
{
/* If interrupts or DMA are used, then we will have to defer initialization */
#if defined(CONFIG_LPC313x_SPI_INTERRUPTS) || defined(CONFIG_LPC313x_SPI_DMA)
bool initialized; /* TRUE: we are initialized */
#endif
/* This is the MP25P* device state structure */
FAR struct mtd_dev_s *mtd;
/* This the the device geometry */
#ifdef CONFIG_DEBUG
FAR struct mtd_geometry_s geo;
#endif
};
#endif
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_PAGING_BINPATH #if defined(CONFIG_PAGING_BINPATH) || defined(CONFIG_PAGING_M25PX)
static struct pg_source_s g_pgsrc; static struct pg_source_s g_pgsrc;
#endif #endif
@ -157,7 +223,7 @@ static struct pg_source_s g_pgsrc;
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_PAGING_BINPATH #if defined(CONFIG_PAGING_BINPATH)
static inline void lpc313x_initsrc(void) static inline void lpc313x_initsrc(void)
{ {
#ifdef CONFIG_PAGING_SDSLOT #ifdef CONFIG_PAGING_SDSLOT
@ -211,9 +277,56 @@ static inline void lpc313x_initsrc(void)
} }
} }
#else /* CONFIG_PAGING_BINPATH */ #elif defined(CONFIG_PAGING_M25PX)
static inline void lpc313x_initsrc(void)
{
#ifdef CONFIG_DEBUG
uint32_t capacity;
int ret;
#endif
/* Are we already initialized? */
#if defined(CONFIG_LPC313x_SPI_INTERRUPTS) || defined(CONFIG_LPC313x_SPI_DMA)
if (!g_pgsrc.initialized)
#endif
{
pgvdbg("Initializing\n");
/* First get an instance of the SPI device interface */
FAR struct spi_dev_s *spi = up_spiinitialize(CONFIG_PAGING_M25PX_SPIPORT);
DEBUGASSERT(spi != NULL);
/* Then bind the SPI interface to the M25Px MTD driver */
g_pgsrc.mtd = m25p_initialize(spi);
DEBUGASSERT(g_pgsrc.mtd != NULL);
/* Verify that we can use the device */
#ifdef CONFIG_DEBUG
/* Get the device geometry. (casting to uintptr_t first eliminates
* complaints on some architectures where the sizeof long is different
* from the size of a pointer).
*/
ret = MTD_IOCTL(g_pgsrc.mtd, MTDIOC_GEOMETRY, (unsigned long)&g_pgsrc.geo);
DEBUGASSERT(ret >= 0);
capacity = g_pgsrc.geo.erasesize*g_pgsrc.geo.neraseblocks;
pgllvdbg("capacity: %d\n", capacity);
DEBUGASSERT(capacity >= (CONFIG_PAGING_M25PX_BINOFFSET + PG_TEXT_VSIZE));
#endif
#if defined(CONFIG_LPC313x_SPI_INTERRUPTS) || defined(CONFIG_LPC313x_SPI_DMA)
g_pgsrc.initialized = true;
#endif
}
}
#else
# define lpc313x_initsrc() # define lpc313x_initsrc()
#endif /* CONFIG_PAGING_BINPATH */ #endif
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
@ -277,10 +390,13 @@ static inline void lpc313x_initsrc(void)
int up_fillpage(FAR _TCB *tcb, FAR void *vpage) int up_fillpage(FAR _TCB *tcb, FAR void *vpage)
{ {
#ifdef CONFIG_PAGING_BINPATH #if defined(CONFIG_PAGING_BINPATH)
ssize_t nbytes; ssize_t nbytes;
off_t offset; off_t offset;
off_t pos; off_t pos;
#elif defined(CONFIG_PAGING_M25PX)
ssize_t nbytes;
off_t offset;
#endif #endif
pgdbg("TCB: %p vpage: %p far: %08x\n", tcb, vpage, tcb->xcp.far); pgdbg("TCB: %p vpage: %p far: %08x\n", tcb, vpage, tcb->xcp.far);
@ -291,7 +407,7 @@ int up_fillpage(FAR _TCB *tcb, FAR void *vpage)
* time that up_fillpage() is called. Are we initialized? * time that up_fillpage() is called. Are we initialized?
*/ */
#ifdef CONFIG_PAGING_BINPATH #if defined(CONFIG_PAGING_BINPATH)
/* Perform initialization of the paging source device (if necessary and /* Perform initialization of the paging source device (if necessary and
* appropriate) * appropriate)
@ -303,7 +419,7 @@ int up_fillpage(FAR _TCB *tcb, FAR void *vpage)
* virtual address. File offset 0 corresponds to PG_LOCKED_VBASE. * virtual address. File offset 0 corresponds to PG_LOCKED_VBASE.
*/ */
offset = (off_t)vpage - PG_LOCKED_VBASE; offset = (off_t)tcb->xcp.far - PG_LOCKED_VBASE;
/* Seek to that position */ /* Seek to that position */
@ -316,15 +432,41 @@ int up_fillpage(FAR _TCB *tcb, FAR void *vpage)
DEBUGASSERT(nbytes == PAGESIZE); DEBUGASSERT(nbytes == PAGESIZE);
return OK; return OK;
#else /* CONFIG_PAGING_BINPATH */ #elif defined(CONFIG_PAGING_M25PX) /* !CONFIG_PAGING_BINPATH */
/* If CONFIG_PAGING_M25PX is defined, use the m25px.c FLASH driver. If this
* is selected, then the MTD interface to the MP25x device will be used to
* support paging.
*
* If the driver is configured to use interrupts or DMA, then it must be
* initialized in this context.
*/
#if defined(CONFIG_LPC313x_SPI_INTERRUPTS) || defined(CONFIG_LPC313x_SPI_DMA)
lpc313x_initsrc();
#endif
/* Create an offset into the binary image that corresponds to the
* virtual address. File offset 0 corresponds to PG_LOCKED_VBASE.
*/
offset = (off_t)tcb->xcp.far - PG_LOCKED_VBASE + CONFIG_PAGING_M25PX_BINOFFSET;
/* Read the page at the correct offset into the SPI FLASH device */
nbytes = MTD_READ(g_pgsrc.mtd, offset, PAGESIZE, (FAR uint8_t *)vpage);
DEBUGASSERT(nbytes == PAGESIZE);
return OK;
#else /* !CONFIG_PAGING_BINPATH && !CONFIG_PAGING_M25PX */
# warning "Not implemented" # warning "Not implemented"
return -ENOSYS; return -ENOSYS;
#endif /* CONFIG_PAGING_BINPATH */ #endif /* !CONFIG_PAGING_BINPATH && !CONFIG_PAGING_M25PX */
} }
#else #else /* CONFIG_PAGING_BLOCKINGFILL */
/* Version 2: Supports non-blocking, asynchronous fill operations */ /* Version 2: Supports non-blocking, asynchronous fill operations */
@ -333,8 +475,10 @@ int up_fillpage(FAR _TCB *tcb, FAR void *vpage, up_pgcallback_t pg_callback)
pgdbg("TCB: %p vpage: %d far: %08x\n", tcb, vpage, tcb->xcp.far); pgdbg("TCB: %p vpage: %d far: %08x\n", tcb, vpage, tcb->xcp.far);
DEBUGASSERT(tcb->xcp.far >= PG_PAGED_VBASE && tcb->xcp.far < PG_PAGED_VEND); DEBUGASSERT(tcb->xcp.far >= PG_PAGED_VBASE && tcb->xcp.far < PG_PAGED_VEND);
#ifdef CONFIG_PAGING_BINPATH #if defined(CONFIG_PAGING_BINPATH)
# error "File system-based paging must always be implemented with blocking calls" # error "File system-based paging must always be implemented with blocking calls"
#elif defined(CONFIG_PAGING_M25PX)
# error "SPI FLASH paging must always be implemented with blocking calls"
#else #else
# warning "Not implemented" # warning "Not implemented"
#endif #endif
@ -367,7 +511,8 @@ void weak_function lpc313x_pginitialize(void)
* that it is called. * that it is called.
*/ */
#ifdef CONFIG_PAGING_BINPATH #if defined(CONFIG_PAGING_BINPATH)
/* If BINPATH is defined, then it is the full path to a file on a mounted file /* If BINPATH is defined, then it is the full path to a file on a mounted file
* system. However, in this case, initialization will involve some higher level * system. However, in this case, initialization will involve some higher level
* file system operations. Since this function is called from a low level (before * file system operations. Since this function is called from a low level (before
@ -375,6 +520,22 @@ void weak_function lpc313x_pginitialize(void)
* operations yet. Therefore, initialization will be deferred until the first * operations yet. Therefore, initialization will be deferred until the first
* time that up_fillpage() is called. * time that up_fillpage() is called.
*/ */
#elif defined(CONFIG_PAGING_M25PX)
/* If CONFIG_PAGING_M25PX is defined, use the m25px.c FLASH driver. If this
* is selected, then the MTD interface to the MP25x device will be used to
* support paging.
*
* If the driver is not configured to use interrupts or DMA, then it is
* probably safe to initialize it in this context.
*/
#if !defined(CONFIG_LPC313x_SPI_INTERRUPTS) && !defined(CONFIG_LPC313x_SPI_DMA)
lpc313x_initsrc();
#endif
#endif #endif
} }

View File

@ -2,7 +2,7 @@
* configs/ea3131/src/up_leds.c * configs/ea3131/src/up_leds.c
* arch/arm/src/board/up_leds.c * arch/arm/src/board/up_leds.c
* *
* Copyright (C) 2009 Gregory Nutt. All rights reserved. * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View File

@ -2,7 +2,7 @@
* configs/ea3131/src/up_mem.c * configs/ea3131/src/up_mem.c
* arch/arm/src/board/up_mem.c * arch/arm/src/board/up_mem.c
* *
* Copyright (C) 2009 Gregory Nutt. All rights reserved. * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* References: * References:

View File

@ -2,7 +2,7 @@
* configs/ea3131/src/up_spi.c * configs/ea3131/src/up_spi.c
* arch/arm/src/board/up_spi.c * arch/arm/src/board/up_spi.c
* *
* Copyright (C) 2009 Gregory Nutt. All rights reserved. * Copyright (C) 2009-2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr> * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without