From bd7ebbf17b3b8c28fcf8c797a6e29bc78e220157 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 13 Jan 2019 14:24:00 +0800 Subject: [PATCH 1/3] [DFS][romfs] fix the mkrom issue when file/dir size zero --- components/dfs/filesystems/romfs/dfs_romfs.h | 8 ++++---- .../dfs/filesystems/romfs => tools}/mkromfs.py | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) rename {components/dfs/filesystems/romfs => tools}/mkromfs.py (93%) diff --git a/components/dfs/filesystems/romfs/dfs_romfs.h b/components/dfs/filesystems/romfs/dfs_romfs.h index 74b256c8a6..05d2906449 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.h +++ b/components/dfs/filesystems/romfs/dfs_romfs.h @@ -17,11 +17,11 @@ struct romfs_dirent { - rt_uint32_t type; /* dirent type */ + 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 */ + const char *name; /* dirent name */ + const rt_uint8_t *data; /* file date ptr */ + rt_size_t size; /* file size */ }; int dfs_romfs_init(void); diff --git a/components/dfs/filesystems/romfs/mkromfs.py b/tools/mkromfs.py similarity index 93% rename from components/dfs/filesystems/romfs/mkromfs.py rename to tools/mkromfs.py index f3c12876d2..5371106987 100644 --- a/components/dfs/filesystems/romfs/mkromfs.py +++ b/tools/mkromfs.py @@ -40,6 +40,10 @@ class File(object): head = 'static const rt_uint8_t %s[] = {\n' % \ (prefix + self.c_name) tail = '\n};' + + if self.entry_size == 0: + return '' + return head + ','.join(('0x%02x' % ord(i) for i in self._data)) + tail @property @@ -118,23 +122,31 @@ class Folder(object): It is recursive.''' # make the current dirent # static is good. Only root dirent is global visible. + if self.entry_size == 0: + return '' + dhead = 'static const struct romfs_dirent %s[] = {\n' % (prefix + self.c_name) dtail = '\n};' body_fmt = ' {{{type}, "{name}", (rt_uint8_t *){data}, sizeof({data})/sizeof({data}[0])}}' + body_fmt0= ' {{{type}, "{name}", RT_NULL, 0}}' # prefix of children cpf = prefix+self.c_name body_li = [] payload_li = [] for c in self._children: + entry_size = c.entry_size if isinstance(c, File): tp = 'ROMFS_DIRENT_FILE' elif isinstance(c, Folder): tp = 'ROMFS_DIRENT_DIR' else: assert False, 'Unkown instance:%s' % str(c) - body_li.append(body_fmt.format(type=tp, - name=c.name, - data=cpf+c.c_name)) + if entry_size == 0: + body_li.append(body_fmt0.format(type=tp, name = c.name)) + else: + body_li.append(body_fmt.format(type=tp, + name=c.name, + data=cpf+c.c_name)) payload_li.append(c.c_data(prefix=cpf)) # All the data we need is defined in payload so we should append the From 9af2d2935136ef46e9bc455777165934d9df96b3 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 13 Jan 2019 14:31:55 +0800 Subject: [PATCH 2/3] [DFS][romfs] code cleanup --- components/dfs/filesystems/romfs/dfs_romfs.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/dfs/filesystems/romfs/dfs_romfs.h b/components/dfs/filesystems/romfs/dfs_romfs.h index 05d2906449..2004e55bc6 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.h +++ b/components/dfs/filesystems/romfs/dfs_romfs.h @@ -1,10 +1,11 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2019, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes + * 2019/01/13 Bernard code cleanup */ #ifndef __DFS_ROMFS_H__ @@ -17,11 +18,11 @@ struct romfs_dirent { - rt_uint32_t type; /* dirent type */ + 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 */ + const char *name; /* dirent name */ + const rt_uint8_t *data; /* file date ptr */ + rt_size_t size; /* file size */ }; int dfs_romfs_init(void); From b998c4ed8dbf12e0744b7ffee95cb9c1ebcbc108 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 13 Jan 2019 14:33:24 +0800 Subject: [PATCH 3/3] [DFS][romfs] code cleanup --- components/dfs/filesystems/romfs/dfs_romfs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/dfs/filesystems/romfs/dfs_romfs.h b/components/dfs/filesystems/romfs/dfs_romfs.h index 2004e55bc6..efb6d44caf 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.h +++ b/components/dfs/filesystems/romfs/dfs_romfs.h @@ -18,7 +18,7 @@ struct romfs_dirent { - rt_uint32_t type; /* dirent type */ + rt_uint32_t type; /* dirent type */ const char *name; /* dirent name */ const rt_uint8_t *data; /* file date ptr */