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>
This commit is contained in:
parent
573b7420d4
commit
cc74572c5b
8 changed files with 248 additions and 2 deletions
|
@ -32,6 +32,8 @@ source "misc/Kconfig"
|
||||||
|
|
||||||
source "lib/Kconfig"
|
source "lib/Kconfig"
|
||||||
|
|
||||||
|
source "fs/Kconfig"
|
||||||
|
|
||||||
source "ext/Kconfig"
|
source "ext/Kconfig"
|
||||||
|
|
||||||
source "usb/Kconfig"
|
source "usb/Kconfig"
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -518,7 +518,7 @@ scripts: scripts_basic include/config/auto.conf include/config/tristate.conf
|
||||||
|
|
||||||
# arch/ must be last here so that .gnu.linkonce magic for interrupts/exceptions
|
# arch/ must be last here so that .gnu.linkonce magic for interrupts/exceptions
|
||||||
# works as expected
|
# works as expected
|
||||||
core-y := lib/ kernel/ misc/ net/ boards/ ext/ usb/ arch/
|
core-y := lib/ kernel/ misc/ net/ boards/ ext/ usb/ fs/ arch/
|
||||||
drivers-y := drivers/
|
drivers-y := drivers/
|
||||||
|
|
||||||
ifneq ($(strip $(MAKEFILE_APP_DIR)),)
|
ifneq ($(strip $(MAKEFILE_APP_DIR)),)
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
obj-$(CONFIG_FAT_FILESYSTEM_ELM) += ff.o
|
obj-$(CONFIG_FAT_FILESYSTEM_ELM) += ff.o
|
||||||
obj-$(CONFIG_FAT_FILESYSTEM_ELM) += diskio.o
|
obj-$(CONFIG_FAT_FILESYSTEM_ELM) += zfs_diskio.o
|
||||||
|
|
75
ext/fs/fat/zfs_diskio.c
Normal file
75
ext/fs/fat/zfs_diskio.c
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Low level disk I/O module skeleton for FatFs (C)ChaN, 2016 */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* If a working storage control module is available, it should be */
|
||||||
|
/* attached to the FatFs via a glue function rather than modifying it. */
|
||||||
|
/* This is an example of glue functions to attach various exsisting */
|
||||||
|
/* storage control modules to the FatFs module with a defined API. */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/*----------------------------------------------------------------------------/
|
||||||
|
/ FatFs - Generic FAT file system module R0.12a /
|
||||||
|
/-----------------------------------------------------------------------------/
|
||||||
|
/
|
||||||
|
/ Copyright (C) 2016, ChaN, all right reserved.
|
||||||
|
/
|
||||||
|
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||||
|
/ source and binary forms, with or without modification, are permitted provided
|
||||||
|
/ that the following condition is met:
|
||||||
|
|
||||||
|
/ 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
/ this condition and the following disclaimer.
|
||||||
|
/
|
||||||
|
/ This software is provided by the copyright holder and contributors "AS IS"
|
||||||
|
/ and any warranties related to this software are DISCLAIMED.
|
||||||
|
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
||||||
|
/ by use of this software.
|
||||||
|
/----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include <diskio.h> /* FatFs lower layer API */
|
||||||
|
#include <fs/fat_diskio.h>
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Get Drive Status */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
DSTATUS disk_status(uint8_t pdrv)
|
||||||
|
{
|
||||||
|
return fat_disk_status();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Inidialize a Drive */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
DSTATUS disk_initialize(uint8_t pdrv)
|
||||||
|
{
|
||||||
|
return fat_disk_initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Read Sector(s) */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
DRESULT disk_read(uint8_t pdrv, uint8_t *buff, unsigned long sector,
|
||||||
|
uint32_t count)
|
||||||
|
{
|
||||||
|
return fat_disk_read(buff, sector, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Write Sector(s) */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
DRESULT disk_write(uint8_t pdrv,
|
||||||
|
const uint8_t *buff, unsigned long sector, uint32_t count)
|
||||||
|
{
|
||||||
|
return fat_disk_write(buff, sector, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
/* Miscellaneous Functions */
|
||||||
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
DRESULT disk_ioctl(uint8_t pdrv, uint8_t cmd, void *buff)
|
||||||
|
{
|
||||||
|
return fat_disk_ioctl(cmd, buff);
|
||||||
|
}
|
67
fs/Kconfig
Normal file
67
fs/Kconfig
Normal file
|
@ -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
|
1
fs/Makefile
Normal file
1
fs/Makefile
Normal file
|
@ -0,0 +1 @@
|
||||||
|
obj-$(CONFIG_FS_FAT_RAM_DISK) += fat_ram_diskio.o
|
71
fs/fat_ram_diskio.c
Normal file
71
fs/fat_ram_diskio.c
Normal file
|
@ -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;
|
||||||
|
}
|
30
include/fs/fat_diskio.h
Normal file
30
include/fs/fat_diskio.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _FAT_DISKIO_H_
|
||||||
|
#define _FAT_DISKIO_H_
|
||||||
|
|
||||||
|
#include <diskio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
DSTATUS fat_disk_status(void);
|
||||||
|
DSTATUS fat_disk_initialize(void);
|
||||||
|
DRESULT fat_disk_read(uint8_t *buff, unsigned long sector, uint32_t count);
|
||||||
|
DRESULT fat_disk_write(const uint8_t *buff, unsigned long sector,
|
||||||
|
uint32_t count);
|
||||||
|
DRESULT fat_disk_ioctl(uint8_t cmd, void *buff);
|
||||||
|
|
||||||
|
#endif /* _FAT_DISKIO_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue