changeset 180:25b54c5ad6c2

calextract tool written, works
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 12 Jul 2014 00:05:22 +0000
parents d0e8cdb82117
children bf4286245c74
files .hgignore miscprog/Makefile miscprog/calextract.c
diffstat 3 files changed, 201 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Fri Jul 11 00:59:50 2014 +0000
+++ b/.hgignore	Sat Jul 12 00:05:22 2014 +0000
@@ -18,6 +18,7 @@
 ^leo-obj/tool/tiobjd$
 
 ^miscprog/atsc$
+^miscprog/calextract$
 ^miscprog/factdiff$
 ^miscprog/imeibrute$
 ^miscprog/mokosrec2bin$
--- a/miscprog/Makefile	Fri Jul 11 00:59:50 2014 +0000
+++ b/miscprog/Makefile	Sat Jul 12 00:05:22 2014 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-STD=	atsc factdiff mokosrec2bin rfcap-grep
+STD=	atsc calextract factdiff mokosrec2bin rfcap-grep
 CRYPTO=	imeibrute pirimei
 PROGS=	${STD} ${CRYPTO}
 
@@ -13,6 +13,7 @@
 	${CC} ${CFLAGS} -o $@ $@.c -lcrypto
 
 atsc:		atsc.c
+calextract:	calextract.c
 factdiff:	factdiff.c
 imeibrute:	imeibrute.c
 mokosrec2bin:	mokosrec2bin.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/miscprog/calextract.c	Sat Jul 12 00:05:22 2014 +0000
@@ -0,0 +1,198 @@
+/*
+ * GSM firmwares constructed per TI's canon contain several hard-coded
+ * T_RF_BAND structures, one per band, emitted literally in the .const
+ * section as they are constant initialized data, i.e.,
+ * const T_RF_BAND rf_XXX = { blah }.  This utility extracts one of these
+ * structures from a binary file (hex offset must be given) and parses it
+ * into a C form suitable for placement in l1_rf12.c in the FreeCalypso
+ * gsm-fw source.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+char *binfilename;
+FILE *binf;
+u_long start_offset;
+
+getbyte()
+{
+	int c;
+
+	c = getc(binf);
+	if (c < 0) {
+		fprintf(stderr, "error or EOF reading from %s\n", binfilename);
+		exit(1);
+	}
+	return(c);
+}
+
+get_u16()
+{
+	int lo, hi;
+
+	lo = getbyte();
+	hi = getbyte();
+	return((hi << 8) | lo);
+}
+
+get_s16()
+{
+	int i;
+
+	i = get_u16();
+	if (i >= 32768)
+		i -= 65536;
+	return(i);
+}
+
+do_rx_cal_params()
+{
+	int i;
+
+	puts("    { /* T_RX_CAL_PARAMS */");
+	for (i = 0; i < 4; i++)
+		printf("%10d,\n", get_u16());
+	puts("    },");
+}
+
+do_rx_agc_bands()
+{
+	int i, u, s;
+
+	puts("    { /* T_RF_AGC_BANDs */");
+	for (i = 0; i < 10; i++) {
+		u = get_u16();
+		s = get_s16();
+		printf("      {%5d,%6d},\n", u, s);
+	}
+	puts("    },");
+}
+
+do_rx_temp_comp()
+{
+	int i, s1, s2;
+
+	puts("    { /* Rx temperature compensation */");
+	for (i = 0; i < 11; i++) {
+		s1 = get_s16();
+		s2 = get_s16();
+		printf("      {%6d,%6d},\n", s1, s2);
+	}
+	puts("    },");
+}
+
+do_rx()
+{
+	puts("  { /* Rx structure */");
+	do_rx_cal_params();
+	do_rx_agc_bands();
+	do_rx_temp_comp();
+	puts("  },");
+}
+
+do_tx_levels()
+{
+	int i, u, b1, b2;
+
+	puts("    { /* levels */");
+	for (i = 0; i < 32; i++) {
+		u = get_u16();
+		b1 = getbyte();
+		b2 = getbyte();
+		printf("      {%5d,%3d,%3d}, /* %d */\n", u, b1, b2, i);
+	}
+	puts("    },");
+}
+
+do_tx_calchan()
+{
+	int i, j, u, s;
+
+	puts("    { /* channel calibration tables */");
+	for (i = 0; i < 4; i++) {
+		printf("      { /* calibration table %d */\n", i);
+		for (j = 0; j < 8; j++) {
+			u = get_u16();
+			s = get_s16();
+			printf("\t{%5d,%6d},\n", u, s);
+		}
+		puts("      },");
+	}
+	puts("    },");
+}
+
+do_ramp_16bytes()
+{
+	int i, b;
+
+	putchar('\t');
+	putchar('{');
+	for (i = 0; i < 16; i++) {
+		b = getbyte();
+		printf("%3d%c", b, i == 15 ? '}' : ',');
+	}
+	putchar(',');
+	putchar('\n');
+}
+
+do_tx_ramps()
+{
+	int i;
+
+	puts("    { /* ramps */");
+	for (i = 0; i < 16; i++) {
+		printf("      { /* profile %d */\n", i);
+		puts("\t/* ramp-up */");
+		do_ramp_16bytes();
+		puts("\t/* ramp-down */");
+		do_ramp_16bytes();
+		puts("      },");
+	}
+	puts("    },");
+}
+
+do_tx_temp_comp()
+{
+	int i, j, s[4];
+
+	puts("    { /* Tx temperature compensation */");
+	for (i = 0; i < 5; i++) {
+		for (j = 0; j < 4; j++)
+			s[j] = get_s16();
+		printf("      {%6d,%6d,%6d,%6d},\n", s[0], s[1], s[2], s[3]);
+	}
+	puts("    },");
+}
+
+do_tx()
+{
+	puts("  { /* Tx structure */");
+	do_tx_levels();
+	do_tx_calchan();
+	do_tx_ramps();
+	do_tx_temp_comp();
+	puts("  },");
+}
+
+main(argc, argv)
+	char **argv;
+{
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s binfile hex-offset\n", argv[0]);
+		exit(1);
+	}
+	binfilename = argv[1];
+	start_offset = strtoul(argv[2], 0, 16);
+	binf = fopen(binfilename, "r");
+	if (!binf) {
+		perror(binfilename);
+		exit(1);
+	}
+	fseek(binf, start_offset, SEEK_SET);
+	puts("const T_RF_BAND rf_XXX = {");
+	do_rx();
+	do_tx();
+	printf("  %d\n}\n", getbyte());
+	exit(0);
+}