changeset 261:7f14d7c789a7

fc-tmsh ffs2: most commands implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 05 Feb 2014 05:48:47 +0000
parents c146f38d2b5f
children 577291a2ad76
files rvinterf/include/ffs.h rvinterf/tmsh/ffs2.c
diffstat 2 files changed, 298 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/include/ffs.h	Wed Feb 05 05:48:47 2014 +0000
@@ -0,0 +1,103 @@
+/*
+ * A few generic FFS API definitions which apply to both TMFFS1 and TMFFS2
+ */
+
+enum FFS_OPEN {
+    FFS_O_EMPTY  = 0x00,  // Okay?
+    FFS_O_CREATE = 0x01,
+    FFS_O_APPEND = 0x02,
+    FFS_O_EXCL   = 0x04,
+    FFS_O_TRUNC  = 0x08,
+    FFS_O_RDONLY = 0x10,
+    FFS_O_WRONLY = 0x20,
+    FFS_O_RDWR   = FFS_O_RDONLY | FFS_O_WRONLY
+};
+
+enum FFS_SEEK {
+    FFS_SEEK_SET = 0,
+    FFS_SEEK_CUR = 1,
+    FFS_SEEK_END = 2
+};
+
+enum FFS_QUERY {              // data size, description
+    Q_BYTES_FREE        =  1, // 4, number of free bytes in FFS
+    Q_BYTES_USED        =  2, // 4, number of used bytes in FFS
+    Q_BYTES_LOST        =  3, // 4, number of lost bytes in FFS
+    Q_BYTES_MAX         =  4, // 4, number of max available bytes in FFS
+    Q_BYTES_FREE_RAW    =  5, // 4, number of free raw bytes in FFS (used internal)
+
+    Q_FD_BUF_SIZE       = 10, // 4, size of buffer used by stream functions
+
+    Q_TM_BUFADDR        = 11, // 4, testmode buffer addr
+    Q_TM_BUFSIZE        = 12, // 4, testmode ffs buffer size
+    Q_DEV_BASE          = 13, // 4, FFS device base address
+    Q_CHUNK_SIZE_MAX    = 14, // 4, max size of chunks made by non stream fkt.
+
+    // FFS versions
+    Q_FFS_API_VERSION   = 16, // 2, FFS API Version
+    Q_FFS_DRV_VERSION   = 17, // 2, FFS Driver Version
+    Q_FFS_REVISION      = 18, // 2, FFS Revision (from PRCS)
+    Q_FFS_FORMAT_READ   = 19, // 2, FFS version as read from ffs
+    Q_FFS_LASTERROR     = 20, // 2, FFS last error (from init)
+    Q_FFS_FORMAT_WRITE  = 21, // 2, FFS version as written to ffs on format
+    Q_FFS_TM_VERSION    = 22, // 2, FFS Testmode version
+
+    // File system queries
+    Q_FILENAME_MAX      = 24, // 2, max filename length
+    Q_PATH_DEPTH_MAX    = 25, // 2, max path/directory nesting depth
+    Q_FD_MAX            = 26, // 2, max numbers of simultaneous open files
+
+    Q_OBJECTS_FREE      = 32, // 2, number of objects that can be created
+    Q_INODES_USED       = 33, // 2, number of inodes used
+    Q_INODES_LOST       = 34, // 2, number of inodes lost
+    Q_OBJECTS_USED      = 33, // 2, DEPRECATED: old name for Q_INODES_USED
+    Q_OBJECTS_LOST      = 34, // 2, DEPRECATED: old name for Q_INODES_LOST
+    Q_OBJECTS_MAX       = 35, // 2, max number of valid objects allowed
+    Q_INODES_MAX        = 36, // 2, physical total max number of inodes
+    Q_INODES_HIGH       = 37, // 2, watermark for when inodes will be reclaimed
+    Q_LOST_HIGH         = 38, // 2, watermark for when data block will be reclaimed
+
+    // Device queries
+    Q_DEV_MANUFACTURER  = 48, // 2, flash manufacturer ID
+    Q_DEV_DEVICE        = 49, // 2, flash device ID
+    Q_DEV_BLOCKS        = 50, // 2, number of FFS blocks in device
+    Q_DEV_ATOMSIZE      = 51, // 2, atomsize used by FFS for this device
+    Q_DEV_DRIVER        = 52, // 2, flash device driver
+
+    // All queries below here are for debug purpose only, are unsupported
+    // and can change at any time without notice!
+
+    // Miscellaneous/Internal
+    Q_BLOCKS_FREE_MIN   = 64, // 2, Number of spare blocks (0 or 1)
+
+    Q_BLOCKS_FREE       = 70, // 2, number of free blocks
+
+    // Debug queries
+    Q_FS_FLAGS          = 80,
+    Q_FS_INODES         = 81,
+    Q_FS_ROOT           = 82,
+
+    Q_OBJECTS_TOTAL     = 90, // 2, Accumulated number of valid objects
+    Q_TOTAL_OBJECTS     = 90, // 2, DEPRECATED: old name for Q_OBJECTS_TOTAL
+
+    Q_STATS_FIRST             = 100,
+    Q_STATS_DRECLAIMS         = 100,
+    Q_STATS_IRECLAIMS         = 101,
+    Q_STATS_BRECLAIMS         = 102,
+    Q_STATS_DATA_RECLAIMED    = 103,
+    Q_STATS_INODES_RECLAIMED  = 104,
+    Q_STATS_DATA_ALLOCATED    = 105,
+
+    Q_REQUEST_ID_LAST         = 110,
+
+    Q_DEBUG_FIRST             = 120,
+    Q_DEBUG_0                 = 120,
+    Q_DEBUG_1                 = 121,
+    Q_DEBUG_2                 = 122,
+    Q_DEBUG_3                 = 123,
+    Q_DEBUG_LAST              = 127,
+
+    // individual lines of the bstat array can be returned by the following
+    // id plus the bstat index of the line wanted.
+    Q_BSTAT                   = -128
+};
--- a/rvinterf/tmsh/ffs2.c	Wed Feb 05 04:02:13 2014 +0000
+++ b/rvinterf/tmsh/ffs2.c	Wed Feb 05 05:48:47 2014 +0000
@@ -11,6 +11,7 @@
 #include "limits.h"
 #include "localtypes.h"
 #include "etm.h"
+#include "ffs.h"
 #include "tmffs2.h"
 
 void
@@ -34,7 +35,7 @@
 
 	slen = strlen(argv[1]);
 	if (slen >= TMFFS_STRING_SIZE) {
-		printf("error: argument exceeds string length limit\n");
+		printf("error: pathname arg exceeds string length limit\n");
 		return;
 	}
 	dp = cmdpkt + 1;
@@ -71,6 +72,27 @@
 }
 
 void
+cmd_ffs2_mkdir(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int slen;
+
+	slen = strlen(argv[1]);
+	if (slen >= TMFFS_STRING_SIZE) {
+		printf("error: pathname arg exceeds string length limit\n");
+		return;
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_MKDIR;
+	*dp++ = slen + 1;
+	strcpy(dp, argv[1]);
+	dp += slen + 1;
+	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
+}
+
+void
 cmd_ffs2_open(argc, argv)
 	char **argv;
 {
@@ -79,7 +101,7 @@
 
 	slen = strlen(argv[1]);
 	if (slen >= TMFFS_STRING_SIZE) {
-		printf("error: argument exceeds string length limit\n");
+		printf("error: pathname arg exceeds string length limit\n");
 		return;
 	}
 	dp = cmdpkt + 1;
@@ -93,6 +115,27 @@
 }
 
 void
+cmd_ffs2_opendir(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int slen;
+
+	slen = strlen(argv[1]);
+	if (slen >= TMFFS_STRING_SIZE) {
+		printf("error: pathname arg exceeds string length limit\n");
+		return;
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_OPENDIR;
+	*dp++ = slen + 1;
+	strcpy(dp, argv[1]);
+	dp += slen + 1;
+	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
+}
+
+void
 cmd_ffs2_preformat()
 {
 	u_char cmdpkt[6];
@@ -106,6 +149,74 @@
 }
 
 void
+cmd_ffs2_query(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[5];
+
+	cmdpkt[1] = ETM_FFS2;
+	cmdpkt[2] = TMFFS_QUERY;
+	cmdpkt[3] = strtoul(argv[1], 0, 0);
+	send_etm_cmd(cmdpkt, 3);
+}
+
+void
+cmd_ffs2_readfd(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[6];
+
+	cmdpkt[1] = ETM_FFS2;
+	cmdpkt[2] = TMFFS_READ;
+	cmdpkt[3] = strtoul(argv[1], 0, 0);
+	cmdpkt[4] = strtoul(argv[2], 0, 0);
+	send_etm_cmd(cmdpkt, 4);
+}
+
+void
+cmd_ffs2_readfile(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int slen;
+
+	slen = strlen(argv[1]);
+	if (slen >= TMFFS_STRING_SIZE) {
+		printf("error: pathname arg exceeds string length limit\n");
+		return;
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_FILE_READ;
+	*dp++ = slen + 1;
+	strcpy(dp, argv[1]);
+	dp += slen + 1;
+	*dp++ = strtoul(argv[2], 0, 0);
+	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
+}
+
+void
+cmd_ffs2_stat(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int slen;
+
+	slen = strlen(argv[1]);
+	if (slen >= TMFFS_STRING_SIZE) {
+		printf("error: pathname arg exceeds string length limit\n");
+		return;
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_STAT;
+	*dp++ = slen + 1;
+	strcpy(dp, argv[1]);
+	dp += slen + 1;
+	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
+}
+
+void
 cmd_ffs2_version()
 {
 	u_char cmdpkt[4];
@@ -115,6 +226,79 @@
 	send_etm_cmd(cmdpkt, 2);
 }
 
+void
+cmd_ffs2_wrfile(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int slen, slen2;
+
+	slen = strlen(argv[1]);
+	if (slen >= TMFFS_STRING_SIZE) {
+		printf("error: pathname arg exceeds string length limit\n");
+		return;
+	}
+	slen2 = strlen(argv[2]);
+	if (slen2 > 64) {
+		printf("error: write test data argument is too long\n");
+		return;
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_FILE_WRITE;
+	*dp++ = slen + 1;
+	strcpy(dp, argv[1]);
+	dp += slen + 1;
+	*dp++ = slen2;		/* no NUL-termination on test data */
+	strcpy(dp, argv[2]);
+	dp += slen2;
+	*dp++ = FFS_O_CREATE | FFS_O_TRUNC;
+	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
+}
+
+void
+cmd_ffs2_writefd(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int slen2;
+
+	slen2 = strlen(argv[2]);
+	if (slen2 > 64) {
+		printf("error: write test data argument is too long\n");
+		return;
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_WRITE;
+	*dp++ = strtoul(argv[1], 0, 0);
+	*dp++ = slen2;		/* no NUL-termination on test data */
+	strcpy(dp, argv[2]);
+	dp += slen2;
+	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
+}
+
+void
+cmd_ffs2_xlstat(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int slen;
+
+	slen = strlen(argv[1]);
+	if (slen >= TMFFS_STRING_SIZE) {
+		printf("error: pathname arg exceeds string length limit\n");
+		return;
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_XLSTAT;
+	*dp++ = slen + 1;
+	strcpy(dp, argv[1]);
+	dp += slen + 1;
+	send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
+}
+
 static struct cmdtab {
 	char *cmd;
 	int minargs;
@@ -124,9 +308,18 @@
 	{"close", 1, 1, cmd_ffs2_close},
 	{"delete", 1, 1, cmd_ffs2_delete},
 	{"format", 1, 1, cmd_ffs2_format},
+	{"mkdir", 1, 1, cmd_ffs2_mkdir},
 	{"open", 2, 2, cmd_ffs2_open},
+	{"opendir", 1, 1, cmd_ffs2_opendir},
 	{"preformat", 0, 0, cmd_ffs2_preformat},
+	{"query", 1, 1, cmd_ffs2_query},
+	{"readfd", 2, 2, cmd_ffs2_readfd},
+	{"readfile", 2, 2, cmd_ffs2_readfile},
+	{"stat", 1, 1, cmd_ffs2_stat},
 	{"version", 0, 0, cmd_ffs2_version},
+	{"wrfile", 2, 2, cmd_ffs2_wrfile},
+	{"writefd", 2, 2, cmd_ffs2_writefd},
+	{"xlstat", 1, 1, cmd_ffs2_xlstat},
 	{0, 0, 0, 0}
 };