mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-07 00:59:00 +08:00
add romfs support.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@887 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
@@ -16,6 +16,12 @@ filesystems/elmfat/dfs_elm.c
|
||||
filesystems/elmfat/ff.c
|
||||
""")
|
||||
|
||||
# DFS-ROMFS options
|
||||
romfs = Split("""
|
||||
filesystems/romfs/dfs_romfs.c
|
||||
filesystems/romfs/romfs.c
|
||||
""")
|
||||
|
||||
# DFS-YAFFS2 options
|
||||
yaffs2_main = Split("""
|
||||
filesystems/yaffs2/direct/yaffscfg.c
|
||||
@@ -69,6 +75,10 @@ if 'RT_USING_DFS_NFS' in dir(rtconfig) and rtconfig.RT_USING_DFS_NFS:
|
||||
src_local = src_local + nfs
|
||||
path = path + [RTT_ROOT + '/components/dfs/filesystems/nfs']
|
||||
|
||||
if 'RT_USING_DFS_ROMFS' in dir(rtconfig) and rtconfig.RT_USING_DFS_ROMFS:
|
||||
src_local = src_local + romfs
|
||||
path = path + [RTT_ROOT + '/components/dfs/filesystems/romfs']
|
||||
|
||||
# group definitions
|
||||
group = {}
|
||||
group['name'] = 'Filesystem'
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
#ifndef __DFS_ROMFS_H__
|
||||
#define __DFS_ROMFS_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#define ROMFS_DIRENT_FILE 0x00
|
||||
#define ROMFS_DIRENT_DIR 0x01
|
||||
|
||||
struct romfs_dirent
|
||||
{
|
||||
rt_uint32_t type; /* dirent type */
|
||||
|
||||
const char *name; /* dirent name */
|
||||
const rt_uint8_t *data; /* file date ptr */
|
||||
rt_size_t size; /* file size */
|
||||
};
|
||||
|
||||
int dfs_romfs_init(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,90 @@
|
||||
import sys
|
||||
import os
|
||||
import string
|
||||
|
||||
basename = ''
|
||||
|
||||
def mkromfs_output(out):
|
||||
print '%s' % out,
|
||||
|
||||
def mkromfs_file(filename, arrayname):
|
||||
f = open(filename, "rb")
|
||||
arrayname = arrayname.replace('.', '_')
|
||||
mkromfs_output('const static unsigned char %s[] = {\n' % arrayname)
|
||||
|
||||
count = 0
|
||||
while True:
|
||||
byte = f.read(1)
|
||||
|
||||
if not byte:
|
||||
break
|
||||
|
||||
mkromfs_output('0x%02x,' % ord(byte))
|
||||
|
||||
count = count + 1
|
||||
if count == 16:
|
||||
count = 0
|
||||
mkromfs_output('\n')
|
||||
|
||||
mkromfs_output('};\n\n')
|
||||
f.close()
|
||||
|
||||
def mkromfs_dir(dirname, is_root = False):
|
||||
list = os.listdir(dirname)
|
||||
path = os.path.abspath(dirname)
|
||||
|
||||
# make for directory
|
||||
for item in list:
|
||||
fullpath = os.path.join(path, item)
|
||||
if os.path.isdir(fullpath):
|
||||
mkromfs_dir(fullpath)
|
||||
|
||||
# make for files
|
||||
for item in list:
|
||||
fullpath = os.path.join(path, item)
|
||||
if os.path.isfile(fullpath):
|
||||
subpath = fullpath[len(basename):]
|
||||
array = subpath.split('\\')
|
||||
arrayname = string.join(array, '_')
|
||||
mkromfs_file(fullpath, arrayname)
|
||||
|
||||
subpath = path[len(basename):]
|
||||
dir = subpath.split('\\')
|
||||
direntname = string.join(dir, '_')
|
||||
if is_root:
|
||||
mkromfs_output('const struct romfs_dirent romfs_root[] = {\n')
|
||||
else:
|
||||
mkromfs_output(('const static struct romfs_dirent %s[] = {\n' % direntname))
|
||||
|
||||
for item in list:
|
||||
fullpath = os.path.join(path, item)
|
||||
fn = fullpath[len(dirname):]
|
||||
if fn[0] == '\\':
|
||||
fn = fn[1:]
|
||||
fn = fn.replace('\\', '/')
|
||||
|
||||
subpath = fullpath[len(basename):]
|
||||
items = subpath.split('\\')
|
||||
item_name = string.join(items, '_')
|
||||
item_name = item_name.replace('.', '_')
|
||||
subpath = subpath.replace('\\', '/')
|
||||
if subpath[0] == '/':
|
||||
subpath = subpath[1:]
|
||||
|
||||
if os.path.isfile(fullpath):
|
||||
mkromfs_output(('\t{ROMFS_DIRENT_FILE, "%s", %s, sizeof(%s)},\n' % (fn, item_name, item_name)))
|
||||
else:
|
||||
mkromfs_output(('\t{ROMFS_DIRENT_DIR, "%s", %s, sizeof(%s)/sizeof(%s[0])},\n' % (fn, item_name, item_name, item_name)))
|
||||
|
||||
mkromfs_output('};\n\n')
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
basename = os.path.abspath(sys.argv[1])
|
||||
filename = os.path.abspath(sys.argv[2])
|
||||
except IndexError:
|
||||
print "Usage: %s <dirname> <filename>" % sys.argv[0]
|
||||
raise SystemExit
|
||||
|
||||
mkromfs_output("#include <dfs_romfs.h>\n\n")
|
||||
mkromfs_dir(basename, is_root = True)
|
||||
@@ -0,0 +1,18 @@
|
||||
#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 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 struct romfs_dirent romfs_root[] = {
|
||||
{ROMFS_DIRENT_DIR, "dummy", _dummy, sizeof(_dummy)/sizeof(_dummy[0])},
|
||||
{ROMFS_DIRENT_FILE, "dummy.txt", _dummy_txt, sizeof(_dummy_txt)},
|
||||
};
|
||||
Reference in New Issue
Block a user