diff ffstools/tiffs-rd/main.c @ 225:c04aa85559ed

TIFFS in vitro reader started
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 13 Jan 2014 09:05:01 +0000
parents
children 24ed817dd25d
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ffstools/tiffs-rd/main.c	Mon Jan 13 09:05:01 2014 +0000
@@ -0,0 +1,121 @@
+/*
+ * This C module contains the main() function for the tiffs utility,
+ * dispatching control to different operation commands.
+ */
+
+#include <sys/types.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "types.h"
+
+u8 tiffs_header[6] = {'F', 'f', 's', '#', 0x10, 0x02};
+u8 blank_flash_line[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
+			   0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
+
+char *imgfile;
+u32 eraseblk_size;
+int total_blocks;
+u32 total_ffs_size;
+int index_blk_num = -1, root_node_no;
+int offset_blocks;
+int verbose;
+
+parse_org_arg(arg)
+	char *arg;
+{
+	char *cp;
+
+	cp = index(arg, 'x');
+	if (!cp || !isdigit(cp[1]) || !isdigit(arg[0])) {
+		fprintf(stderr,
+		"error: TIFFS organization argument \"%s\" is invalid\n", arg);
+		exit(1);
+	}
+	*cp++ = '\0';
+	if (!strcmp(arg, "16"))
+		eraseblk_size = 0x4000;
+	else if (!strcmp(arg, "32"))
+		eraseblk_size = 0x8000;
+	else if (!strcmp(arg, "64"))
+		eraseblk_size = 0x10000;
+	else if (!strcmp(arg, "128"))
+		eraseblk_size = 0x20000;
+	else if (!strcmp(arg, "256"))
+		eraseblk_size = 0x40000;
+	else {
+		fprintf(stderr,
+			"error: \"%s\" is not a recognized flash sector size\n",
+			arg);
+		exit(1);
+	}
+	total_blocks = atoi(cp);
+	if (total_blocks < 1 || total_blocks > 128) {
+		fprintf(stderr,
+		"error: \"%s\" is not a reasonable number of FFS sectors\n",
+			cp);
+		exit(1);
+	}
+	total_ffs_size = eraseblk_size * total_blocks;
+}
+
+static struct cmdtab {
+	char *cmd;
+	int (*func)();
+} cmdtab[] = {
+	{"cat", NULL},
+	{"fsck", NULL},
+	{"ls", NULL},
+	{"xtr", NULL},
+	{NULL, NULL}
+};
+
+main(argc, argv)
+	char **argv;
+{
+	extern int optind;
+	extern char *optarg;
+	int c;
+	char *cmd;
+	struct cmdtab *tp;
+
+	while ((c = getopt(argc, argv, "+a:o:r:v")) != EOF)
+		switch (c) {
+		case 'a':
+			index_blk_num = atoi(optarg);
+			continue;
+		case 'o':
+			offset_blocks = atoi(optarg);
+			continue;
+		case 'r':
+			root_node_no = atoi(optarg);
+			continue;
+		case 'v':
+			verbose++;
+			continue;
+		default:
+usage:			fprintf(stderr,
+			"usage: %s [global-options] <imgfile> <org> <op> ...\n",
+				argv[0]);
+			exit(1);
+		}
+	if (argc - optind < 3)
+		goto usage;
+	imgfile = argv[optind];
+	parse_org_arg(argv[optind+1]);
+	cmd = argv[optind+2];
+
+	for (tp = cmdtab; tp->cmd; tp++)
+		if (!strcmp(tp->cmd, cmd))
+			break;
+	if (!tp->func) {
+		fprintf(stderr,
+			"%s: operation \"%s\" is unknown or unimplemented\n",
+			argv[0], cmd);
+		exit(1);
+	}
+	optind += 2;
+	return tp->func(argc - optind, argv + optind);
+}