summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-05-12 16:21:19 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2007-05-12 16:21:19 +0000
commit473e28a6eebe47b386e625fd33b1c13b60f8e108 (patch)
treee713f6ec7e54668042ad6ab0f339c87ae16a1fe5
parentda889ad22acc0c476b1485b3fd6959825d30240d (diff)
downloadnuttx-473e28a6eebe47b386e625fd33b1c13b60f8e108.tar.gz
nuttx-473e28a6eebe47b386e625fd33b1c13b60f8e108.tar.bz2
nuttx-473e28a6eebe47b386e625fd33b1c13b60f8e108.zip
simulated block device now contains a VFAT formated disk image
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@212 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/arch/sim/src/Makefile9
-rw-r--r--nuttx/arch/sim/src/up_blockdevice.c15
-rw-r--r--nuttx/arch/sim/src/up_deviceimage.c365
-rw-r--r--nuttx/arch/sim/src/up_internal.h21
4 files changed, 400 insertions, 10 deletions
diff --git a/nuttx/arch/sim/src/Makefile b/nuttx/arch/sim/src/Makefile
index 2694c7a8b..35ea8668a 100644
--- a/nuttx/arch/sim/src/Makefile
+++ b/nuttx/arch/sim/src/Makefile
@@ -45,7 +45,11 @@ CSRCS = up_initialize.c up_idle.c up_interruptcontext.c \
up_releasestack.c up_unblocktask.c up_blocktask.c \
up_releasepending.c up_reprioritizertr.c \
up_exit.c up_schedulesigaction.c up_allocateheap.c \
- up_devconsole.c up_blockdevice.c
+ up_devconsole.c
+ifeq ($(CONFIG_FS_FAT),y)
+CSRCS += up_blockdevice.c up_deviceimage.c
+endif
+
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
@@ -53,6 +57,9 @@ OBJS = $(AOBJS) $(COBJS)
LDFLAGS = $(ARCHSCRIPT)
EXTRA_LIBS = -lc
+ifeq ($(CONFIG_FS_FAT),y)
+EXTRA_LIBS += -lz
+endif
LINKOBJS = up_head$(OBJEXT)
LINKLIBS =
diff --git a/nuttx/arch/sim/src/up_blockdevice.c b/nuttx/arch/sim/src/up_blockdevice.c
index 1d4216e01..bf573b323 100644
--- a/nuttx/arch/sim/src/up_blockdevice.c
+++ b/nuttx/arch/sim/src/up_blockdevice.c
@@ -39,7 +39,6 @@
#include <nuttx/config.h>
#include <sys/types.h>
-#include <stdlib.h>
#include <string.h>
#include <nuttx/fs.h>
#include <errno.h>
@@ -50,8 +49,8 @@
* Private Definitions
****************************************************************************/
-#define NSECTORS 128
-#define SECTOR_SIZE 512
+#define NSECTORS 2048
+#define LOGICAL_SECTOR_SIZE 512
/****************************************************************************
* Private Types
@@ -95,12 +94,12 @@ static const struct block_operations g_bops =
static int up_open(FAR struct file *filp)
{
- filp->f_priv = (void*)malloc(NSECTORS*SECTOR_SIZE);
+ filp->f_priv = (void*)up_deviceimage();
return 0;
}
/****************************************************************************
- * Name: up_close
+ * Name: up_closel
*
* Description: close the block device
*
@@ -131,7 +130,7 @@ static ssize_t up_read(FAR struct file *filp, char *buffer,
start_sector < NSECTORS &&
start_sector + nsectors < NSECTORS)
{
- memcpy(buffer, &src[start_sector*SECTOR_SIZE], nsectors*SECTOR_SIZE);
+ memcpy(buffer, &src[start_sector*LOGICAL_SECTOR_SIZE], nsectors*LOGICAL_SECTOR_SIZE);
return OK;
}
else
@@ -155,7 +154,7 @@ static ssize_t up_write(FAR struct file *filp, const char *buffer,
start_sector < NSECTORS &&
start_sector + nsectors < NSECTORS)
{
- memcpy(&dest[start_sector*SECTOR_SIZE], buffer, nsectors*SECTOR_SIZE);
+ memcpy(&dest[start_sector*LOGICAL_SECTOR_SIZE], buffer, nsectors*LOGICAL_SECTOR_SIZE);
return OK;
}
else
@@ -177,7 +176,7 @@ static size_t up_geometry(FAR struct file *filp, struct geometry *geometry)
{
geometry->geo_available = (filp->f_priv != NULL);
geometry->geo_nsectors = NSECTORS;
- geometry->geo_sectorsize = SECTOR_SIZE;
+ geometry->geo_sectorsize = LOGICAL_SECTOR_SIZE;
return OK;
}
return -EINVAL;
diff --git a/nuttx/arch/sim/src/up_deviceimage.c b/nuttx/arch/sim/src/up_deviceimage.c
new file mode 100644
index 000000000..46c42792f
--- /dev/null
+++ b/nuttx/arch/sim/src/up_deviceimage.c
@@ -0,0 +1,365 @@
+/****************************************************************************
+ * up_deviceimage.c
+ *
+ * Copyright (C) 2007 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * 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 Gregory Nutt 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
+ ****************************************************************************/
+
+#ifdef VFAT_STANDALONE
+# include <stdio.h>
+# include <stdlib.h>
+# include <zlib.h>
+#else
+# include <nuttx/config.h>
+# include <sys/types.h>
+# include <stdlib.h>
+# include <debug.h>
+# include <zlib.h>
+# include "up_internal.h"
+#endif
+
+/****************************************************************************
+ * Private Definitions
+ ****************************************************************************/
+
+#ifdef VFAT_STANDALONE
+# define dbg(format, arg...) printf(format, ##arg)
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This array holds a compressed VFAT file system created with:
+ *
+ * /sbin/mkdosfs -C -F 32 -I -n "NuttXTestVol" -s 4 -S 512
+ * -v nuttx-test.vfat 1024
+ *
+ * Then manually massaged from gzip to zlib format
+ */
+
+static const unsigned char g_vfatdata[] =
+{
+ 0x08, 0x1d, 0xed, 0xdc, 0x31, 0x6b, 0x53, 0x51, 0x14, 0x07, 0xf0, 0xdb,
+ 0x52, 0xb4, 0x54, 0x5a, 0x9d, 0x04, 0x27, 0x0f, 0x6e, 0x2e, 0x19, 0x2a,
+ 0x74, 0x13, 0xcc, 0x60, 0x47, 0x91, 0x92, 0x96, 0x4e, 0xc2, 0x2b, 0x79,
+ 0xd5, 0x90, 0x98, 0x17, 0xde, 0x7b, 0x22, 0x01, 0x77, 0x47, 0xfd, 0x18,
+ 0x52, 0x32, 0xba, 0x09, 0xe2, 0x17, 0xc8, 0xb7, 0x70, 0xcb, 0xd2, 0xa5,
+ 0xd0, 0xc9, 0x98, 0x52, 0x05, 0x33, 0xb9, 0xa8, 0x4f, 0xe8, 0xef, 0xc7,
+ 0xbd, 0x9c, 0x0b, 0x67, 0xf9, 0x2f, 0x97, 0x7b, 0xa6, 0x3b, 0x3b, 0x7c,
+ 0xff, 0xb2, 0xdf, 0x2d, 0xaa, 0xe3, 0x2a, 0xa5, 0xd5, 0xb5, 0x48, 0xab,
+ 0x29, 0xa5, 0xf5, 0xf3, 0x94, 0x22, 0x3d, 0x4a, 0x3f, 0xad, 0xfd, 0xa8,
+ 0x17, 0xbd, 0x95, 0x74, 0x2d, 0x2d, 0xbb, 0xff, 0xee, 0xc3, 0xe3, 0xdd,
+ 0x27, 0xaf, 0xea, 0xfa, 0xb0, 0x93, 0x57, 0xf5, 0x41, 0xb1, 0xdb, 0xee,
+ 0x3c, 0xd8, 0x8e, 0x88, 0xad, 0xbb, 0x9f, 0x5f, 0xbf, 0x99, 0xdc, 0xfb,
+ 0x52, 0xdf, 0x38, 0xf8, 0xb8, 0xf5, 0xe9, 0x7a, 0x9a, 0xde, 0x7a, 0x36,
+ 0x3b, 0xdd, 0xfe, 0x3a, 0xbd, 0x3d, 0xbd, 0x33, 0xfb, 0xd6, 0x79, 0xd1,
+ 0xab, 0x62, 0xb1, 0x86, 0x45, 0x1d, 0x59, 0x1c, 0x15, 0x45, 0x9d, 0x1d,
+ 0x0d, 0xf2, 0xe8, 0xf6, 0xaa, 0x7e, 0x2b, 0xe2, 0xe9, 0x20, 0xcf, 0xaa,
+ 0x3c, 0x7a, 0xc3, 0x2a, 0x2f, 0x97, 0xfa, 0xc7, 0x83, 0x62, 0x34, 0x1a,
+ 0x47, 0x36, 0xec, 0x6e, 0x6e, 0x8c, 0xca, 0xbc, 0xaa, 0x16, 0xc7, 0x71,
+ 0xf4, 0xf3, 0x71, 0xd4, 0x45, 0xd4, 0xe5, 0xa2, 0xf3, 0x3c, 0xeb, 0x0d,
+ 0xa3, 0xd5, 0x6a, 0xc5, 0xe6, 0x46, 0xe2, 0x77, 0xf6, 0x4f, 0xf6, 0xf6,
+ 0xb2, 0x76, 0xd3, 0x29, 0xf8, 0xbb, 0xca, 0xb2, 0x9d, 0x9d, 0xad, 0x5c,
+ 0xde, 0xdf, 0x65, 0xfb, 0x27, 0x0d, 0xc4, 0x01, 0x00, 0x1a, 0x36, 0x33,
+ 0xff, 0x5f, 0x61, 0xe6, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0xdd, 0xf9, 0x7c, 0x7e, 0x73, 0xbe,
+ 0xd8, 0x17, 0xb5, 0xe9, 0x2c, 0x00, 0xc0, 0xbf, 0xe1, 0xfd, 0x07, 0x80,
+ 0xab, 0xe7, 0x97, 0x8f, 0x3b, 0xd6, 0x53, 0x7a, 0xfb, 0x70, 0xb2, 0x33,
+ 0xd9, 0xb9, 0xac, 0x4d, 0x27, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x33, 0xbe, 0x03
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_deviceimage
+ *
+ * Description: Return an allocated buffer representing an in-memory VFAT
+ * file system.
+ *
+ ****************************************************************************/
+
+char *up_deviceimage(void)
+{
+ char *pbuffer;
+ int bufsize = 1024*1024;
+ int offset = 0;
+ z_stream strm;
+ int ret;
+
+ /* Ininitilize inflate state */
+
+ strm.zalloc = Z_NULL;
+ strm.zfree = Z_NULL;
+ strm.opaque = Z_NULL;
+ strm.avail_in = 0;
+ strm.next_in = Z_NULL;
+ ret = inflateInit(&strm);
+ if (ret != Z_OK)
+ {
+ dbg("inflateInit FAILED: ret=%d msg=\"%s\"\n", ret, strm.msg ? strm.msg : "No message" );
+ return NULL;
+ }
+
+ /* Allocate a buffer to hold the decompressed buffer. We may have
+ * to reallocate this a few times to get the size right.
+ */
+ pbuffer = (char*)malloc(bufsize);
+
+ /* Set up the input buffer */
+
+ strm.avail_in = sizeof(g_vfatdata);
+ strm.next_in = (Bytef*)g_vfatdata;
+
+ /* Run inflate() on input until output buffer not full */
+
+ do {
+ /* Set up to catch the next output chunk in the output buffer */
+
+ strm.avail_out = bufsize - offset;
+ strm.next_out = (Bytef*)&pbuffer[offset];
+
+ /* inflate */
+
+ ret = inflate(&strm, Z_NO_FLUSH);
+
+ /* Handle inflate() error return values */
+
+ switch (ret)
+ {
+ case Z_NEED_DICT:
+ case Z_DATA_ERROR:
+ case Z_MEM_ERROR:
+ case Z_STREAM_ERROR:
+ dbg("inflate FAILED: ret=%d msg=\"%s\"\n", ret, strm.msg ? strm.msg : "No message" );
+ (void)inflateEnd(&strm);
+ free(pbuffer);
+ return NULL;
+ }
+
+ /* If avail_out is zero, then inflate() returned only
+ * because it is out of buffer space. In this case, we
+ * will have to reallocate the buffer and try again.
+ */
+
+ if (strm.avail_out == 0)
+ {
+ int newbufsize = bufsize + 128*1024;
+ char *newbuffer = realloc(pbuffer, newbufsize);
+ if (!newbuffer)
+ {
+ free(pbuffer);
+ return NULL;
+ }
+ else
+ {
+ pbuffer = newbuffer;
+ offset = bufsize;
+ bufsize = newbufsize;
+ }
+ }
+ else
+ {
+ /* There are unused bytes in the buffer, reallocate to
+ * correct size.
+ */
+
+ int newbufsize = bufsize - strm.avail_out;
+ char *newbuffer = realloc(pbuffer, newbufsize);
+ if (!newbuffer)
+ {
+ free(pbuffer);
+ return NULL;
+ }
+ else
+ {
+ pbuffer = newbuffer;
+ bufsize = newbufsize;
+ }
+ }
+ } while (strm.avail_out == 0 && ret != Z_STREAM_END);
+
+ (void)inflateEnd(&strm);
+ return pbuffer;
+}
+
+/****************************************************************************
+ * Name: main
+ *
+ * Description: Used to test decompression logic
+ *
+ * gcc -g -Wall -DVFAT_STANDALONE -lz -o vfat-test up_deviceimage.c
+ *
+ ****************************************************************************/
+
+#ifdef VFAT_STANDALONE
+int main(int argc, char **argv, char **envp)
+{
+ char *deviceimage;
+ int cmf;
+ int fdict;
+ int flg;
+ int check;
+
+ cmf = g_vfatdata[0];
+ printf("CMF=%02x: CM=%d CINFO=%d\n", cmf, cmf &0x0f, cmf >> 4);
+
+ flg = g_vfatdata[1];
+ fdict = (flg >> 5) & 1;
+
+ printf("FLG=%02x: FCHECK=%d FDICT=%d FLEVEL=%d\n", flg, flg &0x1f, fdict, flg >> 6);
+
+ /* The FCHECK value must be such that CMF and FLG, when viewed as
+ * a 16-bit unsigned integer stored in MSB order (CMF*256 + FLG),
+ * is a multiple of 31.
+ */
+
+ check = cmf*256 + flg;
+ if (check % 31 != 0)
+ {
+ printf("Fails check: %04x is not a multiple of 31\n", check);
+ }
+
+ deviceimage = up_deviceimage();
+ if (deviceimage)
+ {
+ printf("Inflate SUCCEEDED\n");
+ free(deviceimage);
+ return 0;
+ }
+ else
+ {
+ printf("Inflate FAILED\n");
+ return 1;
+ }
+}
+#endif
diff --git a/nuttx/arch/sim/src/up_internal.h b/nuttx/arch/sim/src/up_internal.h
index 5de1d7687..d7e6588cb 100644
--- a/nuttx/arch/sim/src/up_internal.h
+++ b/nuttx/arch/sim/src/up_internal.h
@@ -65,6 +65,20 @@
#define SIM_HEAP_SIZE (4*1024*1024)
+/* These definitions characterize the compressed filesystem image */
+
+#define BLOCK_COUNT 1024
+#define SECTOR_OF_BACKUPT 6
+#define NUMBER_OF_FATS 2
+#define FAT_SIZE 32
+#define NUM_HIDDEN_SECTORS 0
+#define VOLUME_NAME "NuttXTestVol"
+#define USE_WHOLE_DEVICE 1
+#define ROOT_DIR_ENTRIES 512
+#define RESERVED_SECTORS 32
+#define SECTORS_PER_CLUSTER 4
+#define LOGICAL_SECTOR_SIZE 512
+
/**************************************************************************
* Public Types
**************************************************************************/
@@ -78,15 +92,20 @@
**************************************************************************/
#ifndef __ASSEMBLY__
+
/* up_setjmp.S ************************************************************/
extern int up_setjmp(int *jb);
extern void up_longjmp(int *jb, int val) __attribute__ ((noreturn));
-/* up_devconsole **********************************************************/
+/* up_devconsole.c ********************************************************/
extern void up_devconsole(void);
extern void up_registerblockdevice(void);
+/* up_deviceimage.c *******************************************************/
+
+extern char *up_deviceimage(void);
+
#endif /* __ASSEMBLY__ */
#endif /* __ARCH_UP_INTERNAL_H */