changeset 17:24b88c119465

loadtools: hw parameter file reading implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 03 May 2013 22:55:28 +0000
parents 4c78fc688127
children fa3e9a5665bd
files loadtools/Makefile loadtools/defpath.c loadtools/hwparam.c loadtools/romload.c loadtools/sertool.c
diffstat 5 files changed, 190 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/Makefile	Fri May 03 07:27:53 2013 +0000
+++ b/loadtools/Makefile	Fri May 03 22:55:28 2013 +0000
@@ -2,8 +2,8 @@
 CFLAGS=	-O2
 PROGS=	fc-sertool
 
-SERTOOL_OBJS=	hexdecode.o romload.o sercomm.o sertool.o srecreader.o \
-		ttypassthru.o
+SERTOOL_OBJS=	defpath.o hexdecode.o hwparam.o romload.o sercomm.o sertool.o \
+		srecreader.o ttypassthru.o
 
 all:	${PROGS}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadtools/defpath.c	Fri May 03 22:55:28 2013 +0000
@@ -0,0 +1,7 @@
+/*
+ * By default the loadagent.srec target utility and some hardware parameter
+ * files are sought in an installation directory, to make the more common
+ * command line operations more manageable.
+ */
+
+char default_helpers_dir[] = "/usr/local/share/freecalypso";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadtools/hwparam.c	Fri May 03 22:55:28 2013 +0000
@@ -0,0 +1,159 @@
+/*
+ * This module contains the code that reads the hardware parameter files
+ * specified with -h or -H, and sets variables for later use by other code.
+ */
+
+#include <sys/param.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <strings.h>
+#include <stdlib.h>
+
+extern char default_helpers_dir[];
+
+char hw_init_script[128];
+
+static void
+handle_init_script(arg, filename_for_errs, lineno_for_errs)
+	char *arg;
+	char *filename_for_errs;
+	int lineno_for_errs;
+{
+	char *cp;
+
+	while (isspace(*arg))
+		arg++;
+	if (!*arg) {
+		fprintf(stderr,
+		"%s line %d: init-script setting requires an argument\n",
+			filename_for_errs, lineno_for_errs);
+		exit(1);
+	}
+	for (cp = arg; *cp && !isspace(*cp); cp++)
+		;
+	*cp = '\0';
+	if (cp - arg > sizeof(hw_init_script) - 1) {
+		fprintf(stderr,
+	"%s line %d: init-script argument is too long (buffer overflow)\n",
+			filename_for_errs, lineno_for_errs);
+		exit(1);
+	}
+	strcpy(hw_init_script, arg);
+}
+
+static void
+handle_pll_config(arg, filename_for_errs, lineno_for_errs)
+	char *arg;
+	char *filename_for_errs;
+	int lineno_for_errs;
+{
+	int mult, div;
+
+	while (isspace(*arg))
+		arg++;
+	if (!isdigit(*arg)) {
+inv:		fprintf(stderr, "%s line %d: pll-config argument must be M/N\n",
+			filename_for_errs, lineno_for_errs);
+		exit(1);
+	}
+	mult = atoi(arg);
+	arg++;
+	if (isdigit(*arg))
+		arg++;
+	if (*arg++ != '/')
+		goto inv;
+	if (!isdigit(*arg))
+		goto inv;
+	div = atoi(arg);
+	arg++;
+	if (*arg && !isspace(*arg))
+		goto inv;
+	if (mult < 0 || mult > 31 || div < 1 || div > 4) {
+		fprintf(stderr,
+			"%s line %d: pll-config argument is out of range\n",
+			filename_for_errs, lineno_for_errs);
+		exit(1);
+	}
+	set_romload_pll_conf((mult << 2) | (div - 1));
+}
+
+static void
+handle_rhea_cntl(arg, filename_for_errs, lineno_for_errs)
+	char *arg;
+	char *filename_for_errs;
+	int lineno_for_errs;
+{
+	int byte;
+
+	while (isspace(*arg))
+		arg++;
+	if (arg[0] == '0' && (arg[1] == 'x' || arg[1] == 'X'))
+		arg += 2;
+	byte = decode_hex_byte(arg);
+	if (byte < 0 || arg[2] && !isspace(arg[2])) {
+		fprintf(stderr,
+		"%s line %d: rhea-cntl argument must be a hex byte value\n",
+			filename_for_errs, lineno_for_errs);
+		exit(1);
+	}
+	set_romload_rhea_cntl(byte);
+}
+
+static struct cmdtab {
+	char *name;
+	void (*func)();
+} cmdtab[] = {
+	{"init-script", handle_init_script},
+	{"pll-config", handle_pll_config},
+	{"rhea-cntl", handle_rhea_cntl},
+	{0, 0}
+};
+
+void
+read_hwparam_file_fullpath(filename)
+	char *filename;
+{
+	FILE *f;
+	char linebuf[512];
+	int lineno;
+	char *cp, *np;
+	struct cmdtab *tp;
+
+	f = fopen(filename, "r");
+	if (!f) {
+		perror(filename);
+		exit(1);
+	}
+	for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) {
+		for (cp = linebuf; isspace(*cp); cp++)
+			;
+		if (!*cp || *cp == '#')
+			continue;
+		for (np = cp; *cp && !isspace(*cp); cp++)
+			;
+		if (*cp)
+			*cp++ = '\0';
+		for (tp = cmdtab; tp->name; tp++)
+			if (!strcmp(tp->name, np))
+				break;
+		if (tp->func)
+			tp->func(cp, filename, lineno);
+		else {
+			fprintf(stderr,
+				"%s line %d: setting \"%s\" not understood\n",
+				filename, lineno, np);
+			exit(1);
+		}
+	}
+	fclose(f);
+}
+
+void
+read_hwparam_file_shortname(confname)
+	char *confname;
+{
+	char pathname[MAXPATHLEN];
+
+	sprintf(pathname, "%s/%s.config", default_helpers_dir, confname);
+	read_hwparam_file_fullpath(pathname);
+}
--- a/loadtools/romload.c	Fri May 03 07:27:53 2013 +0000
+++ b/loadtools/romload.c	Fri May 03 22:55:28 2013 +0000
@@ -67,6 +67,20 @@
 	beacon_interval = i;
 }
 
+/*
+ * The following functions alter some of the parameters sent to the
+ * boot ROM in the <p command.
+ */
+set_romload_pll_conf(byte)
+{
+	param_cmd[3] = byte;
+}
+
+set_romload_rhea_cntl(byte)
+{
+	param_cmd[6] = byte;
+}
+
 static int
 expect_response(timeout)
 {
--- a/loadtools/sertool.c	Fri May 03 07:27:53 2013 +0000
+++ b/loadtools/sertool.c	Fri May 03 22:55:28 2013 +0000
@@ -22,15 +22,21 @@
 	extern int optind;
 	int c;
 
-	while ((c = getopt(argc, argv, "i:")) != EOF)
+	while ((c = getopt(argc, argv, "h:H:i:")) != EOF)
 		switch (c) {
+		case 'h':
+			read_hwparam_file_shortname(optarg);
+			continue;
+		case 'H':
+			read_hwparam_file_fullpath(optarg);
+			continue;
 		case 'i':
 			set_beacon_interval(optarg);
 			continue;
 		case '?':
 		default:
 usage:			fprintf(stderr,
-	"usage: fc-sertool [-i beacon-interval] ttyport iramimage.srec\n");
+			"usage: fc-sertool [options] ttyport iramimage.srec\n");
 			exit(1);
 		}
 	if (argc - optind != 2)