Embedded GPLv2 license in dfs

This commit is contained in:
yiyue.fang 2013-06-26 22:30:40 +08:00
parent cb517cecc9
commit 773990abdb
27 changed files with 1759 additions and 1353 deletions

View File

@ -1,7 +1,26 @@
/*
* RT-Thread Console Device File
* File : console.c
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#include <rtthread.h>
struct console_device

View File

@ -1,3 +1,26 @@
/*
* File : devfs.c
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#include <rtthread.h>
#include <dfs.h>
#include <dfs_fs.h>
@ -6,276 +29,276 @@
struct device_dirent
{
rt_device_t *devices;
rt_uint16_t read_index;
rt_uint16_t device_count;
rt_device_t *devices;
rt_uint16_t read_index;
rt_uint16_t device_count;
};
int dfs_device_fs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data)
{
return DFS_STATUS_OK;
return DFS_STATUS_OK;
}
int dfs_device_fs_ioctl(struct dfs_fd *file, int cmd, void *args)
{
rt_err_t result;
rt_device_t dev_id;
rt_err_t result;
rt_device_t dev_id;
RT_ASSERT(file != RT_NULL);
RT_ASSERT(file != RT_NULL);
/* get device handler */
dev_id = (rt_device_t)file->data;
RT_ASSERT(dev_id != RT_NULL);
/* get device handler */
dev_id = (rt_device_t)file->data;
RT_ASSERT(dev_id != RT_NULL);
/* close device handler */
result = rt_device_control(dev_id, cmd, args);
if (result == RT_EOK)
return DFS_STATUS_OK;
/* close device handler */
result = rt_device_control(dev_id, cmd, args);
if (result == RT_EOK)
return DFS_STATUS_OK;
return -DFS_STATUS_EIO;
return -DFS_STATUS_EIO;
}
int dfs_device_fs_read(struct dfs_fd *file, void *buf, rt_size_t count)
{
int result;
rt_device_t dev_id;
int result;
rt_device_t dev_id;
RT_ASSERT(file != RT_NULL);
RT_ASSERT(file != RT_NULL);
/* get device handler */
dev_id = (rt_device_t)file->data;
RT_ASSERT(dev_id != RT_NULL);
/* get device handler */
dev_id = (rt_device_t)file->data;
RT_ASSERT(dev_id != RT_NULL);
/* read device data */
result = rt_device_read(dev_id, file->pos, buf, count);
file->pos += result;
/* read device data */
result = rt_device_read(dev_id, file->pos, buf, count);
file->pos += result;
return result;
return result;
}
int dfs_device_fs_write(struct dfs_fd *file, const void *buf, rt_size_t count)
{
int result;
rt_device_t dev_id;
int result;
rt_device_t dev_id;
RT_ASSERT(file != RT_NULL);
RT_ASSERT(file != RT_NULL);
/* get device handler */
dev_id = (rt_device_t)file->data;
RT_ASSERT(dev_id != RT_NULL);
/* get device handler */
dev_id = (rt_device_t)file->data;
RT_ASSERT(dev_id != RT_NULL);
/* read device data */
result = rt_device_write(dev_id, file->pos, buf, count);
file->pos += result;
/* read device data */
result = rt_device_write(dev_id, file->pos, buf, count);
file->pos += result;
return result;
return result;
}
int dfs_device_fs_close(struct dfs_fd *file)
{
rt_err_t result;
rt_device_t dev_id;
rt_err_t result;
rt_device_t dev_id;
RT_ASSERT(file != RT_NULL);
RT_ASSERT(file != RT_NULL);
if (file->type == FT_DIRECTORY)
{
struct device_dirent *root_dirent;
if (file->type == FT_DIRECTORY)
{
struct device_dirent *root_dirent;
root_dirent = (struct device_dirent *)file->data;
RT_ASSERT(root_dirent != RT_NULL);
/* release dirent */
rt_free(root_dirent);
return DFS_STATUS_OK;
}
root_dirent = (struct device_dirent *)file->data;
RT_ASSERT(root_dirent != RT_NULL);
/* release dirent */
rt_free(root_dirent);
return DFS_STATUS_OK;
}
/* get device handler */
dev_id = (rt_device_t)file->data;
RT_ASSERT(dev_id != RT_NULL);
/* get device handler */
dev_id = (rt_device_t)file->data;
RT_ASSERT(dev_id != RT_NULL);
/* close device handler */
result = rt_device_close(dev_id);
if (result == RT_EOK)
{
file->data = RT_NULL;
/* close device handler */
result = rt_device_close(dev_id);
if (result == RT_EOK)
{
file->data = RT_NULL;
return DFS_STATUS_OK;
}
return DFS_STATUS_OK;
}
return -DFS_STATUS_EIO;
return -DFS_STATUS_EIO;
}
int dfs_device_fs_open(struct dfs_fd *file)
{
rt_device_t device;
rt_device_t device;
if (file->flags & DFS_O_CREAT)
return -DFS_STATUS_EINVAL;
if (file->flags & DFS_O_CREAT)
return -DFS_STATUS_EINVAL;
/* open root directory */
if ((file->path[0] == '/') && (file->path[1] == '\0') &&
(file->flags & DFS_O_DIRECTORY))
{
struct rt_object *object;
struct rt_list_node *node;
struct rt_object_information *information;
struct device_dirent *root_dirent;
rt_uint32_t count = 0;
extern struct rt_object_information rt_object_container[];
/* open root directory */
if ((file->path[0] == '/') && (file->path[1] == '\0') &&
(file->flags & DFS_O_DIRECTORY))
{
struct rt_object *object;
struct rt_list_node *node;
struct rt_object_information *information;
struct device_dirent *root_dirent;
rt_uint32_t count = 0;
extern struct rt_object_information rt_object_container[];
/* lock scheduler */
rt_enter_critical();
/* lock scheduler */
rt_enter_critical();
/* traverse device object */
information = &rt_object_container[RT_Object_Class_Device];
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
{
count ++;
}
/* traverse device object */
information = &rt_object_container[RT_Object_Class_Device];
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
{
count ++;
}
root_dirent = (struct device_dirent *)rt_malloc(sizeof(struct device_dirent) +
count * sizeof(rt_device_t));
if (root_dirent != RT_NULL)
{
root_dirent->devices = (rt_device_t *)(root_dirent + 1);
root_dirent->read_index = 0;
root_dirent->device_count = count;
count = 0;
/* get all device node */
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
{
object = rt_list_entry(node, struct rt_object, list);
root_dirent->devices[count] = (rt_device_t)object;
count ++;
}
}
rt_exit_critical();
root_dirent = (struct device_dirent *)rt_malloc(sizeof(struct device_dirent) +
count * sizeof(rt_device_t));
if (root_dirent != RT_NULL)
{
root_dirent->devices = (rt_device_t *)(root_dirent + 1);
root_dirent->read_index = 0;
root_dirent->device_count = count;
count = 0;
/* get all device node */
for (node = information->object_list.next; node != &(information->object_list); node = node->next)
{
object = rt_list_entry(node, struct rt_object, list);
root_dirent->devices[count] = (rt_device_t)object;
count ++;
}
}
rt_exit_critical();
/* set data */
file->data = root_dirent;
return DFS_STATUS_OK;
}
/* set data */
file->data = root_dirent;
return DFS_STATUS_OK;
}
device = rt_device_find(&file->path[1]);
if (device == RT_NULL)
return -DFS_STATUS_ENODEV;
device = rt_device_find(&file->path[1]);
if (device == RT_NULL)
return -DFS_STATUS_ENODEV;
file->data = device;
return DFS_STATUS_OK;
file->data = device;
return DFS_STATUS_OK;
}
int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st)
{
/* stat root directory */
if ((path[0] == '/') && (path[1] == '\0'))
{
st->st_dev = 0;
/* stat root directory */
if ((path[0] == '/') && (path[1] == '\0'))
{
st->st_dev = 0;
st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH |
DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH;
st->st_mode &= ~DFS_S_IFREG;
st->st_mode |= DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH;
st->st_mode = DFS_S_IFREG | DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH |
DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH;
st->st_mode &= ~DFS_S_IFREG;
st->st_mode |= DFS_S_IFDIR | DFS_S_IXUSR | DFS_S_IXGRP | DFS_S_IXOTH;
st->st_size = 0;
st->st_mtime = 0;
st->st_blksize = 512;
return DFS_STATUS_OK;
}
else
{
rt_device_t dev_id;
st->st_size = 0;
st->st_mtime = 0;
st->st_blksize = 512;
return DFS_STATUS_OK;
}
else
{
rt_device_t dev_id;
dev_id = rt_device_find(&path[1]);
if (dev_id != RT_NULL)
{
st->st_dev = 0;
dev_id = rt_device_find(&path[1]);
if (dev_id != RT_NULL)
{
st->st_dev = 0;
st->st_mode = DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH |
DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH;
st->st_mode = DFS_S_IRUSR | DFS_S_IRGRP | DFS_S_IROTH |
DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH;
if (dev_id->type == RT_Device_Class_Char)
st->st_mode |= DFS_S_IFCHR;
else if (dev_id->type == RT_Device_Class_Block)
st->st_mode |= DFS_S_IFBLK;
else
st->st_mode |= DFS_S_IFREG;
if (dev_id->type == RT_Device_Class_Char)
st->st_mode |= DFS_S_IFCHR;
else if (dev_id->type == RT_Device_Class_Block)
st->st_mode |= DFS_S_IFBLK;
else
st->st_mode |= DFS_S_IFREG;
st->st_size = 0;
st->st_mtime = 0;
st->st_blksize = 512;
return DFS_STATUS_OK;
}
}
st->st_size = 0;
st->st_mtime = 0;
st->st_blksize = 512;
return DFS_STATUS_OK;
}
}
return -DFS_STATUS_ENOENT;
return -DFS_STATUS_ENOENT;
}
int dfs_device_fs_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count)
{
rt_uint32_t index;
rt_object_t object;
struct dirent *d;
struct device_dirent *root_dirent;
rt_uint32_t index;
rt_object_t object;
struct dirent *d;
struct device_dirent *root_dirent;
root_dirent = (struct device_dirent *)file->data;
RT_ASSERT(root_dirent != RT_NULL);
root_dirent = (struct device_dirent *)file->data;
RT_ASSERT(root_dirent != RT_NULL);
/* make integer count */
count = (count / sizeof(struct dirent));
if (count == 0)
return -DFS_STATUS_EINVAL;
/* make integer count */
count = (count / sizeof(struct dirent));
if (count == 0)
return -DFS_STATUS_EINVAL;
for (index = 0; index < count && index + root_dirent->read_index < root_dirent->device_count;
index ++)
{
object = (rt_object_t)root_dirent->devices[root_dirent->read_index + index];
for (index = 0; index < count && index + root_dirent->read_index < root_dirent->device_count;
index ++)
{
object = (rt_object_t)root_dirent->devices[root_dirent->read_index + index];
d = dirp + index;
d->d_type = DFS_DT_REG;
d->d_namlen = RT_NAME_MAX;
d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
rt_strncpy(d->d_name, object->name, RT_NAME_MAX);
}
d = dirp + index;
d->d_type = DFS_DT_REG;
d->d_namlen = RT_NAME_MAX;
d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
rt_strncpy(d->d_name, object->name, RT_NAME_MAX);
}
root_dirent->read_index += index;
root_dirent->read_index += index;
return index * sizeof(struct dirent);
return index * sizeof(struct dirent);
}
static const struct dfs_filesystem_operation _device_fs =
{
"devfs",
DFS_FS_FLAG_DEFAULT,
dfs_device_fs_mount,
RT_NULL,
RT_NULL,
RT_NULL,
"devfs",
DFS_FS_FLAG_DEFAULT,
dfs_device_fs_mount,
RT_NULL,
RT_NULL,
RT_NULL,
dfs_device_fs_open,
dfs_device_fs_close,
dfs_device_fs_ioctl,
dfs_device_fs_read,
dfs_device_fs_write,
RT_NULL,
RT_NULL,
dfs_device_fs_getdents,
RT_NULL,
dfs_device_fs_stat,
RT_NULL,
dfs_device_fs_open,
dfs_device_fs_close,
dfs_device_fs_ioctl,
dfs_device_fs_read,
dfs_device_fs_write,
RT_NULL,
RT_NULL,
dfs_device_fs_getdents,
RT_NULL,
dfs_device_fs_stat,
RT_NULL,
};
int devfs_init(void)
{
/* register rom file system */
dfs_register(&_device_fs);
/* register rom file system */
dfs_register(&_device_fs);
return 0;
return 0;
}
INIT_FS_EXPORT(devfs_init);

View File

@ -1,3 +1,26 @@
/*
* File : devfs.h
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#ifndef __DEVICE_FS_H__
#define __DEVICE_FS_H__

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2008-2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

File diff suppressed because it is too large Load Diff

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,9 +1,21 @@
/*
* File : dfs_ramfs.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, Shanghai Real-Thread Technology Co., Ltd
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2013, RT-Thread Development Team
*
* All rights reserved.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
@ -17,11 +29,14 @@
#include <dfs_fs.h>
#include "dfs_ramfs.h"
int dfs_ramfs_mount(struct dfs_filesystem *fs, unsigned long rwflag, const void *data)
int dfs_ramfs_mount(struct dfs_filesystem *fs,
unsigned long rwflag,
const void *data)
{
struct dfs_ramfs* ramfs;
if (data == RT_NULL) return -DFS_STATUS_EIO;
if (data == RT_NULL)
return -DFS_STATUS_EIO;
ramfs = (struct dfs_ramfs*) data;
fs->data = ramfs;
@ -55,7 +70,9 @@ int dfs_ramfs_ioctl(struct dfs_fd *file, int cmd, void *args)
return -DFS_STATUS_EIO;
}
struct ramfs_dirent *dfs_ramfs_lookup(struct dfs_ramfs* ramfs, const char *path, rt_size_t *size)
struct ramfs_dirent *dfs_ramfs_lookup(struct dfs_ramfs *ramfs,
const char *path,
rt_size_t *size)
{
const char *subpath;
struct ramfs_dirent *dirent;
@ -65,16 +82,18 @@ struct ramfs_dirent *dfs_ramfs_lookup(struct dfs_ramfs* ramfs, const char *path,
if (! *subpath) /* is root directory */
{
*size = 0;
return &(ramfs->root);
}
for (dirent = rt_list_entry(ramfs->root.list.next, struct ramfs_dirent, list);
dirent != &(ramfs->root);
dirent = rt_list_entry(dirent->list.next, struct ramfs_dirent, list))
dirent != &(ramfs->root);
dirent = rt_list_entry(dirent->list.next, struct ramfs_dirent, list))
{
if (rt_strcmp(dirent->name, subpath) == 0)
{
*size = dirent->size;
return dirent;
}
}
@ -122,6 +141,7 @@ int dfs_ramfs_write(struct dfs_fd *fd, const void *buf, rt_size_t count)
if (ptr == RT_NULL)
{
rt_set_errno(-RT_ENOMEM);
return 0;
}
@ -145,6 +165,7 @@ int dfs_ramfs_lseek(struct dfs_fd *file, rt_off_t offset)
if (offset <= (rt_off_t)file->size)
{
file->pos = offset;
return file->pos;
}
@ -154,6 +175,7 @@ int dfs_ramfs_lseek(struct dfs_fd *file, rt_off_t offset)
int dfs_ramfs_close(struct dfs_fd *file)
{
file->data = RT_NULL;
return DFS_STATUS_OK;
}
@ -195,8 +217,7 @@ int dfs_ramfs_open(struct dfs_fd *file)
if (dirent == RT_NULL)
{
if (file->flags & DFS_O_CREAT ||
file->flags & DFS_O_WRONLY)
if (file->flags & DFS_O_CREAT || file->flags & DFS_O_WRONLY)
{
char *name_ptr;
@ -209,7 +230,8 @@ int dfs_ramfs_open(struct dfs_fd *file)
/* remove '/' separator */
name_ptr = file->path;
while (*name_ptr == '/' && *name_ptr) name_ptr ++;
while (*name_ptr == '/' && *name_ptr)
name_ptr ++;
strncpy(dirent->name, name_ptr, RAMFS_NAME_MAX);
rt_list_init(&(dirent->list));
@ -218,7 +240,8 @@ int dfs_ramfs_open(struct dfs_fd *file)
/* add to the root directory */
rt_list_insert_after(&(ramfs->root.list), &(dirent->list));
}
else return -DFS_STATUS_ENOENT;
else
return -DFS_STATUS_ENOENT;
}
/* Creates a new file. If the file is existing, it is truncated and overwritten. */
@ -282,8 +305,8 @@ int dfs_ramfs_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t cou
index = 0;
count = 0;
for (dirent = rt_list_entry(dirent->list.next, struct ramfs_dirent, list);
dirent != &(ramfs->root) && index < end;
dirent = rt_list_entry(dirent->list.next, struct ramfs_dirent, list))
dirent != &(ramfs->root) && index < end;
dirent = rt_list_entry(dirent->list.next, struct ramfs_dirent, list))
{
if (index >= (rt_size_t)file->pos)
{
@ -312,7 +335,8 @@ int dfs_ramfs_unlink(struct dfs_filesystem *fs, const char *path)
RT_ASSERT(ramfs != RT_NULL);
dirent = dfs_ramfs_lookup(ramfs, path, &size);
if (dirent == RT_NULL) return -DFS_STATUS_ENOENT;
if (dirent == RT_NULL)
return -DFS_STATUS_ENOENT;
rt_list_remove(&(dirent->list));
if (dirent->data != RT_NULL)
@ -322,7 +346,9 @@ int dfs_ramfs_unlink(struct dfs_filesystem *fs, const char *path)
return DFS_STATUS_OK;
}
int dfs_ramfs_rename(struct dfs_filesystem *fs, const char *oldpath, const char *newpath)
int dfs_ramfs_rename(struct dfs_filesystem *fs,
const char *oldpath,
const char *newpath)
{
struct ramfs_dirent *dirent;
struct dfs_ramfs *ramfs;
@ -332,10 +358,12 @@ int dfs_ramfs_rename(struct dfs_filesystem *fs, const char *oldpath, const char
RT_ASSERT(ramfs != RT_NULL);
dirent = dfs_ramfs_lookup(ramfs, newpath, &size);
if (dirent != RT_NULL) return -DFS_STATUS_EEXIST;
if (dirent != RT_NULL)
return -DFS_STATUS_EEXIST;
dirent = dfs_ramfs_lookup(ramfs, oldpath, &size);
if (dirent == RT_NULL) return -DFS_STATUS_ENOENT;
if (dirent == RT_NULL)
return -DFS_STATUS_ENOENT;
strncpy(dirent->name, newpath, RAMFS_NAME_MAX);
@ -368,10 +396,11 @@ int dfs_ramfs_init(void)
{
/* register ram file system */
dfs_register(&_ramfs);
return 0;
}
struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t* pool, rt_size_t size)
struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t *pool, rt_size_t size)
{
struct dfs_ramfs *ramfs;
rt_uint8_t *data_ptr;
@ -385,9 +414,10 @@ struct dfs_ramfs* dfs_ramfs_create(rt_uint8_t* pool, rt_size_t size)
size = RT_ALIGN_DOWN(size, RT_ALIGN_SIZE);
result = rt_memheap_init(&ramfs->memheap, "ramfs", data_ptr, size);
if (result != RT_EOK) return RT_NULL;
/* detach this memheap object from the system */
rt_object_detach((rt_object_t)&(ramfs->memheap));
if (result != RT_EOK)
return RT_NULL;
/* detach this memheap object from the system */
rt_object_detach((rt_object_t)&(ramfs->memheap));
/* initialize ramfs object */
ramfs->magic = RAMFS_MAGIC;

View File

@ -1,9 +1,21 @@
/*
* File : dfs_ramfs.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2011, Shanghai Real-Thread Technology Co., Ltd
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2013, RT-Thread Development Team
*
* All rights reserved.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -1,23 +1,51 @@
/*
* File : romfs.c
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#include <dfs_romfs.h>
const static unsigned char _dummy_dummy_txt[] = {
0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x61,0x20,0x66,0x69,0x6c,0x65,0x21,0x0d,
0x0a,
const static unsigned char _dummy_dummy_txt[] =
{
0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x61,0x20,0x66,0x69,0x6c,0x65,0x21,0x0d,0x0a,
};
const static struct romfs_dirent _dummy[] = {
{ROMFS_DIRENT_FILE, "dummy.txt", _dummy_dummy_txt, sizeof(_dummy_dummy_txt)},
const static struct romfs_dirent _dummy[] =
{
{ROMFS_DIRENT_FILE, "dummy.txt", _dummy_dummy_txt, sizeof(_dummy_dummy_txt)},
};
const static unsigned char _dummy_txt[] = {
0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x61,0x20,0x66,0x69,0x6c,0x65,0x21,0x0d,
0x0a,
const static unsigned char _dummy_txt[] =
{
0x74,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x61,0x20,0x66,0x69,0x6c,0x65,0x21,0x0d,0x0a,
};
const struct romfs_dirent _root_dirent[] = {
{ROMFS_DIRENT_DIR, "dummy", (rt_uint8_t*) _dummy, sizeof(_dummy)/sizeof(_dummy[0])},
{ROMFS_DIRENT_FILE, "dummy.txt", _dummy_txt, sizeof(_dummy_txt)},
const struct romfs_dirent _root_dirent[] =
{
{ROMFS_DIRENT_DIR, "dummy", (rt_uint8_t *)_dummy, sizeof(_dummy)/sizeof(_dummy[0])},
{ROMFS_DIRENT_FILE, "dummy.txt", _dummy_txt, sizeof(_dummy_txt)},
};
const struct romfs_dirent romfs_root = {ROMFS_DIRENT_DIR, "/", (rt_uint8_t*) _root_dirent, sizeof(_root_dirent)/sizeof(_root_dirent[0])};
const struct romfs_dirent romfs_root =
{
ROMFS_DIRENT_DIR, "/", (rt_uint8_t *)_root_dirent, sizeof(_root_dirent)/sizeof(_root_dirent[0])
};

View File

@ -1,6 +1,26 @@
/*
* A skeleton of file system in Device File System
* File : skeleton.c
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#include <rtthread.h>
#include <dfs.h>
#include <dfs_fs.h>
@ -9,74 +29,74 @@
int dfs_skt_mount(struct dfs_filesystem* fs, unsigned long rwflag, const void* data)
{
return DFS_STATUS_OK;
return DFS_STATUS_OK;
}
int dfs_skt_unmount(struct dfs_filesystem* fs)
{
return DFS_STATUS_OK;
return DFS_STATUS_OK;
}
int dfs_skt_ioctl(struct dfs_fd* file, int cmd, void* args)
int dfs_skt_ioctl(struct dfs_fd* file, int cmd, void* args)
{
return -DFS_STATUS_EIO;
return -DFS_STATUS_EIO;
}
int dfs_skt_read(struct dfs_fd* file, void *buf, rt_size_t count)
{
return count;
return count;
}
int dfs_skt_lseek(struct dfs_fd* file, rt_off_t offset)
{
return -DFS_STATUS_EIO;
return -DFS_STATUS_EIO;
}
int dfs_skt_close(struct dfs_fd* file)
{
return DFS_STATUS_OK;
return DFS_STATUS_OK;
}
int dfs_skt_open(struct dfs_fd* file)
{
return DFS_STATUS_OK;
return DFS_STATUS_OK;
}
int dfs_skt_stat(struct dfs_filesystem* fs, const char *path, struct stat *st)
{
return DFS_STATUS_OK;
return DFS_STATUS_OK;
}
int dfs_skt_getdents(struct dfs_fd* file, struct dirent* dirp, rt_uint32_t count)
{
return count * sizeof(struct dirent);
return count * sizeof(struct dirent);
}
static const struct dfs_filesystem_operation _skt_fs =
{
"skt",
DFS_FS_FLAG_DEFAULT,
dfs_skt_mount,
dfs_skt_unmount,
RT_NULL,
RT_NULL,
"skt",
DFS_FS_FLAG_DEFAULT,
dfs_skt_mount,
dfs_skt_unmount,
RT_NULL,
RT_NULL,
dfs_skt_open,
dfs_skt_close,
dfs_skt_ioctl,
dfs_skt_read,
RT_NULL,
RT_NULL,
dfs_skt_lseek,
dfs_skt_getdents,
RT_NULL,
dfs_skt_stat,
RT_NULL,
dfs_skt_open,
dfs_skt_close,
dfs_skt_ioctl,
dfs_skt_read,
RT_NULL,
RT_NULL,
dfs_skt_lseek,
dfs_skt_getdents,
RT_NULL,
dfs_skt_stat,
RT_NULL,
};
int dfs_skt_init(void)
{
/* register rom file system */
dfs_register(&_skt_fs);
return 0;
return 0;
}

View File

@ -1,3 +1,26 @@
/*
* File : skeleton.h
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
*/
#ifndef __SKELETON_H__
#define __SKELETON_H__

View File

@ -1,18 +1,29 @@
/*
* File : rtthread.h
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2006-2012, RT-Thread Development Team
* File : dfs_uffs.c
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2011-10-22 prife the first version
* 2012-03-28 prife use mtd device interface
* 2012-04-05 prife update uffs with official repo and use uffs_UnMount/Mount
*/
*/
#include <rtthread.h>
#include <dfs_fs.h>

View File

@ -1,8 +1,25 @@
/*
* dfs_uffs.h
* File : dfs_uffs.h
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* Created on: 2012-3-30
* Author: prife
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes
* 2012-03-30 prife the first version
*/
#ifndef DFS_UFFS_H_

View File

@ -8,338 +8,352 @@
static int nand_init_flash(uffs_Device *dev)
{
return UFFS_FLASH_NO_ERR;
return UFFS_FLASH_NO_ERR;
}
static int nand_release_flash(uffs_Device *dev)
{
return UFFS_FLASH_NO_ERR;
return UFFS_FLASH_NO_ERR;
}
static int nand_erase_block(uffs_Device *dev, unsigned block)
{
int res;
res = rt_mtd_nand_erase_block(RT_MTD_NAND_DEVICE(dev->_private), block);
return res == RT_EOK ? UFFS_FLASH_NO_ERR : UFFS_FLASH_IO_ERR;
int res;
res = rt_mtd_nand_erase_block(RT_MTD_NAND_DEVICE(dev->_private), block);
return res == RT_EOK ? UFFS_FLASH_NO_ERR : UFFS_FLASH_IO_ERR;
}
#if defined(RT_UFFS_USE_CHECK_MARK_FUNCITON)
static int nand_check_block(uffs_Device *dev, unsigned block)
{
int res;
res = rt_mtd_nand_check_block(RT_MTD_NAND_DEVICE(dev->_private), block);
return res == RT_EOK ? UFFS_FLASH_NO_ERR : UFFS_FLASH_BAD_BLK;
int res;
res = rt_mtd_nand_check_block(RT_MTD_NAND_DEVICE(dev->_private), block);
return res == RT_EOK ? UFFS_FLASH_NO_ERR : UFFS_FLASH_BAD_BLK;
}
static int nand_mark_badblock(uffs_Device *dev, unsigned block)
{
int res;
res = rt_mtd_nand_mark_badblock(RT_MTD_NAND_DEVICE(dev->_private), block);
return res == RT_EOK ? UFFS_FLASH_NO_ERR : UFFS_FLASH_IO_ERR;
int res;
res = rt_mtd_nand_mark_badblock(RT_MTD_NAND_DEVICE(dev->_private), block);
return res == RT_EOK ? UFFS_FLASH_NO_ERR : UFFS_FLASH_IO_ERR;
}
#endif
#if (RT_CONFIG_UFFS_ECC_MODE == UFFS_ECC_NONE) || (RT_CONFIG_UFFS_ECC_MODE == UFFS_ECC_SOFT)
static int nand_read_page(
uffs_Device *dev,
u32 block, u32 page,
u8 *data, int data_len,
u8 * ecc,
rt_uint8_t *spare, int spare_len)
static int nand_read_page(uffs_Device *dev,
u32 block,
u32 page,
u8 *data,
int data_len,
u8 *ecc,
rt_uint8_t *spare,
int spare_len)
{
int res;
int res;
page = block * dev->attr->pages_per_block + page;
if (data == NULL && spare == NULL)
{
page = block * dev->attr->pages_per_block + page;
if (data == NULL && spare == NULL)
{
#if defined(RT_UFFS_USE_CHECK_MARK_FUNCITON)
RT_ASSERT(0); //should not be here
RT_ASSERT(0); //should not be here
#else
/* check block status: bad or good */
rt_uint8_t spare[UFFS_MAX_SPARE_SIZE];
/* check block status: bad or good */
rt_uint8_t spare[UFFS_MAX_SPARE_SIZE];
rt_memset(spare, 0, UFFS_MAX_SPARE_SIZE);
rt_memset(spare, 0, UFFS_MAX_SPARE_SIZE);
rt_mtd_nand_read(RT_MTD_NAND_DEVICE(dev->_private),
page, RT_NULL, 0,
spare, dev->attr->spare_size);//dev->mem.spare_data_size
rt_mtd_nand_read(RT_MTD_NAND_DEVICE(dev->_private),
page, RT_NULL, 0,
spare, dev->attr->spare_size);//dev->mem.spare_data_size
res = spare[dev->attr->block_status_offs] == 0xFF ?
UFFS_FLASH_NO_ERR : UFFS_FLASH_BAD_BLK;
return res;
res = spare[dev->attr->block_status_offs] == 0xFF ?
UFFS_FLASH_NO_ERR : UFFS_FLASH_BAD_BLK;
return res;
#endif
}
}
rt_mtd_nand_read(RT_MTD_NAND_DEVICE(dev->_private),
page, data, data_len, spare, spare_len);
rt_mtd_nand_read(RT_MTD_NAND_DEVICE(dev->_private),
page, data, data_len, spare, spare_len);
return UFFS_FLASH_NO_ERR;
return UFFS_FLASH_NO_ERR;
}
static int nand_write_page(
uffs_Device *dev,
u32 block, u32 page,
const u8 *data, int data_len,
const u8 *spare, int spare_len)
static int nand_write_page(uffs_Device *dev,
u32 block,
u32 page,
const u8 *data,
int data_len,
const u8 *spare,
int spare_len)
{
int res;
int res;
RT_ASSERT(UFFS_MAX_SPARE_SIZE >= dev->attr->spare_size);
RT_ASSERT(UFFS_MAX_SPARE_SIZE >= dev->attr->spare_size);
page = block * dev->attr->pages_per_block + page;
page = block * dev->attr->pages_per_block + page;
if (data == NULL && spare == NULL)
{
if (data == NULL && spare == NULL)
{
#if defined(RT_UFFS_USE_CHECK_MARK_FUNCITON)
RT_ASSERT(0); //should not be here
RT_ASSERT(0); //should not be here
#else
/* mark bad block */
rt_uint8_t spare[UFFS_MAX_SPARE_SIZE];
/* mark bad block */
rt_uint8_t spare[UFFS_MAX_SPARE_SIZE];
rt_memset(spare, 0xFF, UFFS_MAX_SPARE_SIZE);
spare[dev->attr->block_status_offs] = 0x00;
rt_memset(spare, 0xFF, UFFS_MAX_SPARE_SIZE);
spare[dev->attr->block_status_offs] = 0x00;
res = rt_mtd_nand_write(RT_MTD_NAND_DEVICE(dev->_private),
page, RT_NULL, 0,
spare, dev->attr->spare_size);//dev->mem.spare_data_size
if (res != RT_EOK)
goto __error;
res = rt_mtd_nand_write(RT_MTD_NAND_DEVICE(dev->_private),
page, RT_NULL, 0,
spare, dev->attr->spare_size);//dev->mem.spare_data_size
if (res != RT_EOK)
goto __error;
#endif
}
}
res = rt_mtd_nand_write(RT_MTD_NAND_DEVICE(dev->_private),
page, data, data_len, spare, spare_len);
if (res != RT_EOK)
goto __error;
res = rt_mtd_nand_write(RT_MTD_NAND_DEVICE(dev->_private),
page, data, data_len, spare, spare_len);
if (res != RT_EOK)
goto __error;
return UFFS_FLASH_NO_ERR;
return UFFS_FLASH_NO_ERR;
__error:
return UFFS_FLASH_IO_ERR;
return UFFS_FLASH_IO_ERR;
}
const uffs_FlashOps nand_ops =
{
nand_init_flash, /* InitFlash() */
nand_release_flash, /* ReleaseFlash() */
nand_read_page, /* ReadPage() */
NULL, /* ReadPageWithLayout */
nand_write_page, /* WritePage() */
NULL, /* WirtePageWithLayout */
nand_init_flash, /* InitFlash() */
nand_release_flash, /* ReleaseFlash() */
nand_read_page, /* ReadPage() */
NULL, /* ReadPageWithLayout */
nand_write_page, /* WritePage() */
NULL, /* WirtePageWithLayout */
#if defined(RT_UFFS_USE_CHECK_MARK_FUNCITON)
nand_check_block,
nand_mark_badblock,
nand_check_block,
nand_mark_badblock,
#else
NULL, /* IsBadBlock(), let UFFS take care of it. */
NULL, /* MarkBadBlock(), let UFFS take care of it. */
NULL, /* IsBadBlock(), let UFFS take care of it. */
NULL, /* MarkBadBlock(), let UFFS take care of it. */
#endif
nand_erase_block, /* EraseBlock() */
nand_erase_block, /* EraseBlock() */
};
void uffs_setup_storage(
struct uffs_StorageAttrSt *attr,
struct rt_mtd_nand_device * nand)
void uffs_setup_storage(struct uffs_StorageAttrSt *attr,
struct rt_mtd_nand_device *nand)
{
rt_memset(attr, 0, sizeof(struct uffs_StorageAttrSt));
rt_memset(attr, 0, sizeof(struct uffs_StorageAttrSt));
// attr->total_blocks = nand->end_block - nand->start_block + 1;/* no use */
attr->page_data_size = nand->page_size; /* page data size */
attr->pages_per_block = nand->pages_per_block; /* pages per block */
attr->spare_size = nand->oob_size; /* page spare size */
attr->ecc_opt = RT_CONFIG_UFFS_ECC_MODE; /* ecc option */
attr->ecc_size = 0; /* ecc size is 0 , the uffs will calculate the ecc size*/
attr->block_status_offs = attr->ecc_size; /* indicate block bad or good, offset in spare */
attr->layout_opt = RT_CONFIG_UFFS_LAYOUT; /* let UFFS do the spare layout */
// attr->total_blocks = nand->end_block - nand->start_block + 1;/* no use */
attr->page_data_size = nand->page_size; /* page data size */
attr->pages_per_block = nand->pages_per_block; /* pages per block */
attr->spare_size = nand->oob_size; /* page spare size */
attr->ecc_opt = RT_CONFIG_UFFS_ECC_MODE; /* ecc option */
attr->ecc_size = 0; /* ecc size is 0 , the uffs will calculate the ecc size*/
attr->block_status_offs = attr->ecc_size; /* indicate block bad or good, offset in spare */
attr->layout_opt = RT_CONFIG_UFFS_LAYOUT; /* let UFFS do the spare layout */
}
#elif RT_CONFIG_UFFS_ECC_MODE == UFFS_ECC_HW_AUTO
static int WritePageWithLayout(
uffs_Device *dev, u32 block, u32 page,
const u8 *data, int data_len,
const u8 *ecc, //NULL
const uffs_TagStore *ts)
static int WritePageWithLayout(uffs_Device *dev,
u32 block,
u32 page,
const u8 *data,
int data_len,
const u8 *ecc, //NULL
const uffs_TagStore *ts)
{
int res;
int spare_len;
rt_uint8_t spare[UFFS_MAX_SPARE_SIZE];
int res;
int spare_len;
rt_uint8_t spare[UFFS_MAX_SPARE_SIZE];
RT_ASSERT(UFFS_MAX_SPARE_SIZE >= dev->attr->spare_size);
RT_ASSERT(UFFS_MAX_SPARE_SIZE >= dev->attr->spare_size);
page = block * dev->attr->pages_per_block + page;
spare_len = dev->mem.spare_data_size;
page = block * dev->attr->pages_per_block + page;
spare_len = dev->mem.spare_data_size;
if (data == NULL && ts == NULL)
{
if (data == NULL && ts == NULL)
{
#if defined(RT_UFFS_USE_CHECK_MARK_FUNCITON)
RT_ASSERT(0); //should not be here
RT_ASSERT(0); //should not be here
#else
/* mark bad block */
rt_memset(spare, 0xFF, UFFS_MAX_SPARE_SIZE);
spare[dev->attr->block_status_offs] = 0x00;
/* mark bad block */
rt_memset(spare, 0xFF, UFFS_MAX_SPARE_SIZE);
spare[dev->attr->block_status_offs] = 0x00;
res = rt_mtd_nand_write(RT_MTD_NAND_DEVICE(dev->_private),
page, RT_NULL, 0,
spare, dev->attr->spare_size);//dev->mem.spare_data_size
if (res != RT_EOK)
goto __error;
dev->st.io_write++;
return UFFS_FLASH_NO_ERR;
res = rt_mtd_nand_write(RT_MTD_NAND_DEVICE(dev->_private),
page, RT_NULL, 0,
spare, dev->attr->spare_size);//dev->mem.spare_data_size
if (res != RT_EOK)
goto __error;
dev->st.io_write++;
return UFFS_FLASH_NO_ERR;
#endif
}
}
if (data != NULL && data_len != 0)
{
RT_ASSERT(data_len == dev->attr->page_data_size);
if (data != NULL && data_len != 0)
{
RT_ASSERT(data_len == dev->attr->page_data_size);
dev->st.page_write_count++;
dev->st.io_write += data_len;
}
dev->st.page_write_count++;
dev->st.io_write += data_len;
}
if (ts != RT_NULL)
{
uffs_FlashMakeSpare(dev, ts, RT_NULL, (u8 *)spare);
dev->st.spare_write_count++;
dev->st.io_write += spare_len;
}
if (ts != RT_NULL)
{
uffs_FlashMakeSpare(dev, ts, RT_NULL, (u8 *)spare);
dev->st.spare_write_count++;
dev->st.io_write += spare_len;
}
res = rt_mtd_nand_write(RT_MTD_NAND_DEVICE(dev->_private),
page, data, data_len, spare, spare_len);
if (res != RT_EOK)
goto __error;
res = rt_mtd_nand_write(RT_MTD_NAND_DEVICE(dev->_private),
page, data, data_len, spare, spare_len);
if (res != RT_EOK)
goto __error;
return UFFS_FLASH_NO_ERR;
return UFFS_FLASH_NO_ERR;
__error:
return UFFS_FLASH_IO_ERR;
return UFFS_FLASH_IO_ERR;
}
static URET ReadPageWithLayout(
uffs_Device *dev, u32 block, u32 page,
u8* data, int data_len,
u8 *ecc, //NULL
uffs_TagStore *ts,
u8 *ecc_store) //NULL
static URET ReadPageWithLayout(uffs_Device *dev,
u32 block,
u32 page,
u8 *data,
int data_len,
u8 *ecc, //NULL
uffs_TagStore *ts,
u8 *ecc_store) //NULL
{
int res = UFFS_FLASH_NO_ERR;
int spare_len;
rt_uint8_t spare[UFFS_MAX_SPARE_SIZE];
int res = UFFS_FLASH_NO_ERR;
int spare_len;
rt_uint8_t spare[UFFS_MAX_SPARE_SIZE];
RT_ASSERT(UFFS_MAX_SPARE_SIZE >= dev->attr->spare_size);
RT_ASSERT(UFFS_MAX_SPARE_SIZE >= dev->attr->spare_size);
page = block * dev->attr->pages_per_block + page;
spare_len = dev->mem.spare_data_size;
page = block * dev->attr->pages_per_block + page;
spare_len = dev->mem.spare_data_size;
if (data == RT_NULL && ts == RT_NULL)
{
if (data == RT_NULL && ts == RT_NULL)
{
#if defined(RT_UFFS_USE_CHECK_MARK_FUNCITON)
RT_ASSERT(0); //should not be here
RT_ASSERT(0); //should not be here
#else
/* check block good or bad */
/* check block good or bad */
rt_mtd_nand_read(RT_MTD_NAND_DEVICE(dev->_private),
page, RT_NULL, 0,
spare, dev->attr->spare_size);//dev->mem.spare_data_size
rt_mtd_nand_read(RT_MTD_NAND_DEVICE(dev->_private),
page, RT_NULL, 0,
spare, dev->attr->spare_size);//dev->mem.spare_data_size
dev->st.io_read++;
dev->st.io_read++;
res = spare[dev->attr->block_status_offs] == 0xFF ?
UFFS_FLASH_NO_ERR : UFFS_FLASH_BAD_BLK;
return res;
res = spare[dev->attr->block_status_offs] == 0xFF ?
UFFS_FLASH_NO_ERR : UFFS_FLASH_BAD_BLK;
return res;
#endif
}
}
if (data != RT_NULL)
{
dev->st.io_read += data_len;
dev->st.page_read_count++;
}
if (data != RT_NULL)
{
dev->st.io_read += data_len;
dev->st.page_read_count++;
}
res = rt_mtd_nand_read(RT_MTD_NAND_DEVICE(dev->_private),
page, data, data_len, spare, spare_len);
if (res == 0)
res = UFFS_FLASH_NO_ERR;
else if (res == -1)
{
//TODO ecc correct, add code to use hardware do ecc correct
res = UFFS_FLASH_ECC_OK;
}
else
res = UFFS_FLASH_ECC_FAIL;
res = rt_mtd_nand_read(RT_MTD_NAND_DEVICE(dev->_private),
page, data, data_len, spare, spare_len);
if (res == 0)
res = UFFS_FLASH_NO_ERR;
else if (res == -1)
{
//TODO ecc correct, add code to use hardware do ecc correct
res = UFFS_FLASH_ECC_OK;
}
else
res = UFFS_FLASH_ECC_FAIL;
if (ts != RT_NULL)
{
// unload ts and ecc from spare, you can modify it if you like
uffs_FlashUnloadSpare(dev, (const u8 *)spare, ts, RT_NULL);
if (ts != RT_NULL)
{
// unload ts and ecc from spare, you can modify it if you like
uffs_FlashUnloadSpare(dev, (const u8 *)spare, ts, RT_NULL);
if ((spare[spare_len - 1] == 0xFF) && (res == UFFS_FLASH_NO_ERR))
res = UFFS_FLASH_NOT_SEALED;
if ((spare[spare_len - 1] == 0xFF) && (res == UFFS_FLASH_NO_ERR))
res = UFFS_FLASH_NOT_SEALED;
dev->st.io_read += spare_len;
dev->st.spare_read_count++;
}
dev->st.io_read += spare_len;
dev->st.spare_read_count++;
}
return res;
return res;
}
const uffs_FlashOps nand_ops =
{
nand_init_flash, /* InitFlash() */
nand_release_flash, /* ReleaseFlash() */
NULL, /* ReadPage() */
ReadPageWithLayout, /* ReadPageWithLayout */
NULL, /* WritePage() */
WritePageWithLayout,/* WirtePageWithLayout */
nand_init_flash, /* InitFlash() */
nand_release_flash, /* ReleaseFlash() */
NULL, /* ReadPage() */
ReadPageWithLayout, /* ReadPageWithLayout */
NULL, /* WritePage() */
WritePageWithLayout,/* WirtePageWithLayout */
#if defined(RT_UFFS_USE_CHECK_MARK_FUNCITON)
nand_check_block,
nand_mark_badblock,
nand_check_block,
nand_mark_badblock,
#else
NULL, /* IsBadBlock(), let UFFS take care of it. */
NULL, /* MarkBadBlock(), let UFFS take care of it. */
NULL, /* IsBadBlock(), let UFFS take care of it. */
NULL, /* MarkBadBlock(), let UFFS take care of it. */
#endif
nand_erase_block, /* EraseBlock() */
nand_erase_block, /* EraseBlock() */
};
static rt_uint8_t hw_flash_data_layout[UFFS_SPARE_LAYOUT_SIZE] =
{0x05, 0x08, 0xFF, 0x00};
{
0x05, 0x08, 0xFF, 0x00
};
static rt_uint8_t hw_flash_ecc_layout[UFFS_SPARE_LAYOUT_SIZE] =
{0x00, 0x04, 0xFF, 0x00};
void uffs_setup_storage(
struct uffs_StorageAttrSt *attr,
struct rt_mtd_nand_device * nand)
{
rt_memset(attr, 0, sizeof(struct uffs_StorageAttrSt));
0x00, 0x04, 0xFF, 0x00
};
// attr->total_blocks = nand->end_block - nand->start_block + 1;/* no use */
attr->page_data_size = nand->page_size; /* page data size */
attr->pages_per_block = nand->pages_per_block; /* pages per block */
attr->spare_size = nand->oob_size; /* page spare size */
attr->ecc_opt = RT_CONFIG_UFFS_ECC_MODE; /* ecc option */
attr->ecc_size = nand->oob_size-nand->oob_free; /* ecc size */
attr->block_status_offs = attr->ecc_size; /* indicate block bad or good, offset in spare */
attr->layout_opt = RT_CONFIG_UFFS_LAYOUT; /* let UFFS do the spare layout */
void uffs_setup_storage(struct uffs_StorageAttrSt *attr,
struct rt_mtd_nand_device *nand)
{
rt_memset(attr, 0, sizeof(struct uffs_StorageAttrSt));
/* calculate the ecc layout array */
hw_flash_data_layout[0] = attr->ecc_size + 1; /* ecc size + 1byte block status */
hw_flash_data_layout[1] = 0x08;
hw_flash_data_layout[2] = 0xFF;
hw_flash_data_layout[3] = 0x00;
// attr->total_blocks = nand->end_block - nand->start_block + 1;/* no use */
attr->page_data_size = nand->page_size; /* page data size */
attr->pages_per_block = nand->pages_per_block; /* pages per block */
attr->spare_size = nand->oob_size; /* page spare size */
attr->ecc_opt = RT_CONFIG_UFFS_ECC_MODE; /* ecc option */
attr->ecc_size = nand->oob_size-nand->oob_free; /* ecc size */
attr->block_status_offs = attr->ecc_size; /* indicate block bad or good, offset in spare */
attr->layout_opt = RT_CONFIG_UFFS_LAYOUT; /* let UFFS do the spare layout */
hw_flash_ecc_layout[0] = 0;
hw_flash_ecc_layout[1] = attr->ecc_size;
hw_flash_ecc_layout[2] = 0xFF;
hw_flash_ecc_layout[3] = 0x00;
/* calculate the ecc layout array */
hw_flash_data_layout[0] = attr->ecc_size + 1; /* ecc size + 1byte block status */
hw_flash_data_layout[1] = 0x08;
hw_flash_data_layout[2] = 0xFF;
hw_flash_data_layout[3] = 0x00;
/* initialize _uffs_data_layout and _uffs_ecc_layout */
rt_memcpy(attr->_uffs_data_layout, hw_flash_data_layout, UFFS_SPARE_LAYOUT_SIZE);
rt_memcpy(attr->_uffs_ecc_layout, hw_flash_ecc_layout, UFFS_SPARE_LAYOUT_SIZE);
hw_flash_ecc_layout[0] = 0;
hw_flash_ecc_layout[1] = attr->ecc_size;
hw_flash_ecc_layout[2] = 0xFF;
hw_flash_ecc_layout[3] = 0x00;
attr->data_layout = attr->_uffs_data_layout;
attr->ecc_layout = attr->_uffs_ecc_layout;
/* initialize _uffs_data_layout and _uffs_ecc_layout */
rt_memcpy(attr->_uffs_data_layout, hw_flash_data_layout, UFFS_SPARE_LAYOUT_SIZE);
rt_memcpy(attr->_uffs_ecc_layout, hw_flash_ecc_layout, UFFS_SPARE_LAYOUT_SIZE);
attr->data_layout = attr->_uffs_data_layout;
attr->ecc_layout = attr->_uffs_ecc_layout;
}
#endif

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2008-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2011, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes

View File

@ -3,9 +3,19 @@
* This file is part of Device File System in RT-Thread RTOS
* COPYRIGHT (C) 2004-2012, RT-Thread Development Team
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rt-thread.org/license/LICENSE.
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Change Logs:
* Date Author Notes