summaryrefslogtreecommitdiff
path: root/fs
diff options
context:
space:
mode:
authorRamesh Thomas <ramesh.thomas@intel.com>2016-07-25 16:20:54 -0700
committerRamesh Thomas <ramesh.thomas@intel.com>2016-08-01 16:46:38 -0700
commitcc74572c5be92e5fdc30aac4208f94067ad7d99c (patch)
treef750708393a0965dd1f1e0ba62f70307f53a3bfd /fs
parent573b7420d46342e4ed263681760a616685ff96cc (diff)
fs: Adds diskio interface
Adds the diskio interface for the FAT file system. This revision uses RAM to emulate disk storage. Origin: Original Jira: ZEP-285 Change-Id: I7a30c8761d5ed9b564f1d1e08482c5ef199d7372 Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/Kconfig67
-rw-r--r--fs/Makefile1
-rw-r--r--fs/fat_ram_diskio.c71
3 files changed, 139 insertions, 0 deletions
diff --git a/fs/Kconfig b/fs/Kconfig
new file mode 100644
index 000000000..b958a930c
--- /dev/null
+++ b/fs/Kconfig
@@ -0,0 +1,67 @@
+#
+# Copyright (c) 2016 Intel Corporation
+#
+# Licensed 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.
+#
+
+menu "File System"
+
+config FILE_SYSTEM
+ bool "File system support"
+ default n
+ help
+ Enables support for file system.
+
+config FILE_SYSTEM_FAT
+ bool "FAT file system support"
+ default y
+ depends on FILE_SYSTEM
+ help
+ Enables FAT file system support.
+
+choice
+ prompt "Select file system storage device"
+ depends on FILE_SYSTEM_FAT
+ default FS_FAT_RAM_DISK
+ help
+ The storage device where the file system
+ resides
+
+config FS_FAT_RAM_DISK
+ bool
+ prompt "RAM Disk"
+ help
+ RAM buffer used to emulate storage disk.
+ This option can used to test the file
+ system.
+
+endchoice
+
+if FS_FAT_RAM_DISK
+
+config FS_VOLUME_SIZE
+ hex
+ default 0x18000
+ help
+ This is the file system volume size in bytes.
+
+config FS_BLOCK_SIZE
+ hex
+ default 0x1000
+ help
+ This is typically the minimum block size that
+ is erased at one time in flash storage.
+
+endif # FS_RAM_DISK
+
+endmenu
diff --git a/fs/Makefile b/fs/Makefile
new file mode 100644
index 000000000..4e618c7c0
--- /dev/null
+++ b/fs/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_FS_FAT_RAM_DISK) += fat_ram_diskio.o
diff --git a/fs/fat_ram_diskio.c b/fs/fat_ram_diskio.c
new file mode 100644
index 000000000..565e30378
--- /dev/null
+++ b/fs/fat_ram_diskio.c
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 2016 Intel Corporation.
+ *
+ * Licensed 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.
+ */
+
+#include <string.h>
+#include <stdint.h>
+#include <misc/__assert.h>
+#include <diskio.h>
+#include <ff.h>
+
+static uint8_t file_buff[CONFIG_FS_VOLUME_SIZE];
+
+static void *lba_to_address(uint32_t lba)
+{
+ __ASSERT(((lba * _MIN_SS) < CONFIG_FS_VOLUME_SIZE), "FS bound error");
+ return &file_buff[(lba * _MIN_SS)];
+}
+
+DSTATUS fat_disk_status(void)
+{
+ return RES_OK;
+}
+
+DSTATUS fat_disk_initialize(void)
+{
+ return RES_OK;
+}
+
+DRESULT fat_disk_read(void *buff, uint32_t sector, uint32_t count)
+{
+ memcpy(buff, lba_to_address(sector), count * _MIN_SS);
+
+ return RES_OK;
+}
+
+DRESULT fat_disk_write(void *buff, uint32_t sector, uint32_t count)
+{
+ memcpy(lba_to_address(sector), buff, count * _MIN_SS);
+
+ return RES_OK;
+}
+
+DRESULT fat_disk_ioctl(uint8_t cmd, void *buff)
+{
+ switch (cmd) {
+ case CTRL_SYNC:
+ return RES_OK;
+ case GET_SECTOR_COUNT:
+ *(uint32_t *) buff = CONFIG_FS_VOLUME_SIZE / _MIN_SS;
+ return RES_OK;
+ case GET_BLOCK_SIZE:
+ *(uint32_t *) buff = CONFIG_FS_BLOCK_SIZE / _MIN_SS;
+ return RES_OK;
+ case CTRL_TRIM:
+ break;
+ }
+
+ return RES_PARERR;
+}