changeset 84:ccc5161848c7

loadtools: support building for GTA0x AP
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 20 Aug 2013 04:51:15 +0000
parents ebe258a85813
children 6f8d3771aa6c
files loadtools/Makefile loadtools/clmain.c loadtools/gta-ap-build.sed loadtools/gtapower.c loadtools/ltmain.c loadtools/romload.c loadtools/sertool.c
diffstat 7 files changed, 86 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/loadtools/Makefile	Mon Aug 19 05:16:34 2013 +0000
+++ b/loadtools/Makefile	Tue Aug 20 04:51:15 2013 +0000
@@ -5,29 +5,30 @@
 SCRIPTS=scripts/pirelli.config scripts/pirelli.init
 INSTBIN=/usr/local/bin
 INSTSCR=/usr/local/share/freecalypso
+EXTRA_OBJ=
 
 IRAM_OBJS=	defpath.o hexdecode.o hwparam.o hwparamstubs.o romload.o \
-		sercomm.o sertool.o srecreader.o ttypassthru.o
+		sercomm.o sertool.o srecreader.o ttypassthru.o ${EXTRA_OBJ}
 
 LOADTOOL_OBJS=	crc32tab.o defpath.o flerase.o flprogbin.o flutil.o hexdecode.o\
 		hwparam.o labaud.o ltdispatch.o ltdump.o ltexit.o ltflash.o \
 		ltmain.o ltmisc.o ltpassthru.o ltscript.o romload.o sercomm.o \
-		srecreader.o tpinterf.o tpinterf2.o tpinterf3.o
+		srecreader.o tpinterf.o tpinterf2.o tpinterf3.o ${EXTRA_OBJ}
 
 XRAM_OBJS=	chainload.o clmain.o defpath.o hexdecode.o hwparam.o \
 		hwparamstubs.o initscript.o labaud.o romload.o sercomm.o \
-		srecreader.o tpinterf.o ttypassthru.o
+		srecreader.o tpinterf.o ttypassthru.o ${EXTRA_OBJ}
 
 all:	${PROGS}
 
 fc-iram:	${IRAM_OBJS}
-	${CC} -o $@ ${IRAM_OBJS}
+	${CC} ${CFLAGS} -o $@ ${IRAM_OBJS}
 
 fc-loadtool:	${LOADTOOL_OBJS}
-	${CC} -o $@ ${LOADTOOL_OBJS}
+	${CC} ${CFLAGS} -o $@ ${LOADTOOL_OBJS}
 
 fc-xram:	${XRAM_OBJS}
-	${CC} -o $@ ${XRAM_OBJS}
+	${CC} ${CFLAGS} -o $@ ${XRAM_OBJS}
 
 # The loadagent.srec image needs to be installed in the "system" directory
 # where fc-loadtool and fc-xram will find it.  However, we have a dilemma:
--- a/loadtools/clmain.c	Mon Aug 19 05:16:34 2013 +0000
+++ b/loadtools/clmain.c	Tue Aug 20 04:51:15 2013 +0000
@@ -19,6 +19,7 @@
 extern char hw_init_script[];
 extern struct baudrate baud_rate_table[];
 extern struct baudrate *current_baud_rate;
+extern int gta_modem_poweron;
 
 extern struct baudrate *find_baudrate_by_name();
 
@@ -33,7 +34,7 @@
 	int c;
 	struct baudrate *br;
 
-	while ((c = getopt(argc, argv, "a:b:B:h:H:i:")) != EOF)
+	while ((c = getopt(argc, argv, "a:b:B:h:H:i:n")) != EOF)
 		switch (c) {
 		case 'a':
 			iramimage.filename = optarg;
@@ -56,6 +57,9 @@
 		case 'i':
 			set_beacon_interval(optarg);
 			continue;
+		case 'n':
+			gta_modem_poweron = 0;
+			continue;
 		case '?':
 		default:
 usage:			fprintf(stderr,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadtools/gta-ap-build.sed	Tue Aug 20 04:51:15 2013 +0000
@@ -0,0 +1,3 @@
+s,^CC=.*$,CC=	/opt/arm-2012.03/bin/arm-none-linux-gnueabi-gcc,
+s,^CFLAGS=.*$,CFLAGS=	-O2 -march=armv4t -mtune=arm920t -DGTA0x_AP_BUILD,
+s,^EXTRA_OBJ=.*,EXTRA_OBJ=gtapower.o,
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/loadtools/gtapower.c	Tue Aug 20 04:51:15 2013 +0000
@@ -0,0 +1,54 @@
+/*
+ * This module is included only when loadtools are being built to run on the
+ * GTA0x application processor (AP).  It provides automated modem power
+ * control, i.e., coordinates modem power control with loadtools operations
+ * for convenience.
+ */
+
+#include <sys/types.h>
+#include <sys/file.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+/*
+ * Check this pathname: it is correct for the kernel version I'm using
+ * on my test GTA02, but it differs for some other kernel versions.
+ */
+static char modem_powerctl_pathname[] =
+	"/sys/bus/platform/devices/gta02-pm-gsm.0/power_on";
+
+void
+set_gta_modem_power_ctrl(boolval)
+{
+	char strbuf[16];
+	int len, fd;
+
+	len = sprintf(strbuf, "%d\n", boolval);
+	fd = open(modem_powerctl_pathname, O_WRONLY);
+	if (fd < 0) {
+		perror(modem_powerctl_pathname);
+		exit(1);
+	}
+	write(fd, strbuf, len);
+	close(fd);
+}
+
+void
+fork_gta_modem_poweron()
+{
+	int i;
+
+	i = fork();
+	if (i < 0) {
+		perror("fork");
+		exit(1);
+	}
+	if (i)
+		return;
+	printf("Toggling %s\n", modem_powerctl_pathname);
+	set_gta_modem_power_ctrl(0);
+	usleep(350000);
+	set_gta_modem_power_ctrl(1);
+	exit(0);
+}
--- a/loadtools/ltmain.c	Mon Aug 19 05:16:34 2013 +0000
+++ b/loadtools/ltmain.c	Tue Aug 20 04:51:15 2013 +0000
@@ -14,6 +14,7 @@
 extern char default_loadagent_image[];
 extern char hw_init_script[];
 extern void (*default_exit)();
+extern int gta_modem_poweron;
 
 main(argc, argv)
 	char **argv;
@@ -23,7 +24,7 @@
 	int c;
 	char command[512];
 
-	while ((c = getopt(argc, argv, "a:b:h:H:i:")) != EOF)
+	while ((c = getopt(argc, argv, "a:b:h:H:i:n")) != EOF)
 		switch (c) {
 		case 'a':
 			iramimage.filename = optarg;
@@ -40,6 +41,9 @@
 		case 'i':
 			set_beacon_interval(optarg);
 			continue;
+		case 'n':
+			gta_modem_poweron = 0;
+			continue;
 		case '?':
 		default:
 usage:			fprintf(stderr,
--- a/loadtools/romload.c	Mon Aug 19 05:16:34 2013 +0000
+++ b/loadtools/romload.c	Tue Aug 20 04:51:15 2013 +0000
@@ -26,6 +26,9 @@
 struct srecreader iramimage;
 struct baudrate *romload_baud_rate = baud_rate_table;	/* 1st entry default */
 
+/* global var always defined, but does anything only for GTA0x_AP_BUILD */
+int gta_modem_poweron = 1;
+
 static int beacon_interval = 13;	/* in milliseconds */
 
 static u_char beacon_cmd[2] = {'<', 'i'};
@@ -144,6 +147,10 @@
 send_beacons()
 {
 	printf("Sending beacons to %s\n", target_ttydev);
+#ifdef GTA0x_AP_BUILD
+	if (gta_modem_poweron)
+		fork_gta_modem_poweron();
+#endif
 	do
 		write(target_fd, beacon_cmd, sizeof beacon_cmd);
 	while (expect_response(beacon_interval) != 'i');
--- a/loadtools/sertool.c	Mon Aug 19 05:16:34 2013 +0000
+++ b/loadtools/sertool.c	Tue Aug 20 04:51:15 2013 +0000
@@ -14,6 +14,7 @@
 
 extern char *target_ttydev;
 extern struct srecreader iramimage;
+extern int gta_modem_poweron;
 
 main(argc, argv)
 	char **argv;
@@ -22,7 +23,7 @@
 	extern int optind;
 	int c;
 
-	while ((c = getopt(argc, argv, "b:h:H:i:")) != EOF)
+	while ((c = getopt(argc, argv, "b:h:H:i:n")) != EOF)
 		switch (c) {
 		case 'b':
 			set_romload_baudrate(optarg);
@@ -36,6 +37,9 @@
 		case 'i':
 			set_beacon_interval(optarg);
 			continue;
+		case 'n':
+			gta_modem_poweron = 0;
+			continue;
 		case '?':
 		default:
 usage:			fprintf(stderr,