changeset 890:452a4aea3fc5

gsm-fw: implemented reading of Pirelli's factory calibration records
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 29 Jun 2015 21:45:23 +0000
parents 1b1683cda154
children f3fba126778a
files gsm-fw/L1/cust0/Makefile gsm-fw/L1/cust0/l1_cust.c gsm-fw/L1/cust0/pirelli.c gsm-fw/cfgmagic/target.pirelli
diffstat 4 files changed, 100 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/gsm-fw/L1/cust0/Makefile	Sun Jun 28 16:52:06 2015 +0000
+++ b/gsm-fw/L1/cust0/Makefile	Mon Jun 29 21:45:23 2015 +0000
@@ -4,9 +4,15 @@
 CFLAGS=	-O2 -fno-builtin -mthumb-interwork
 LD=	arm-elf-ld
 
+sinclude ../../include/config.mk
+
 IOBJS=	ind_os.o l1_cust_iram.o
 XOBJS=	l1_cust_xip.o l1_rf12.o
 
+ifeq (${CONFIG_TARGET_PIRELLI},1)
+XOBJS+=	pirelli.o
+endif
+
 all:	iramcode.o xipcode.o
 
 l1_cust_iram.o:	l1_cust.c
--- a/gsm-fw/L1/cust0/l1_cust.c	Sun Jun 28 16:52:06 2015 +0000
+++ b/gsm-fw/L1/cust0/l1_cust.c	Mon Jun 29 21:45:23 2015 +0000
@@ -469,6 +469,13 @@
     NULL,                          0,                   0 // terminator
 };
 
+#if CONFIG_TARGET_PIRELLI
+extern int pirelli_cal_fread(const char *name, void *userbuf, T_FFS_SIZE size);
+#define	cal_fread	pirelli_cal_fread
+#else
+#define	cal_fread	ffs_file_read
+#endif
+
 void config_ffs_read(char type)
 {
   config_rf_read(type);
@@ -488,7 +495,7 @@
     while (file->name != NULL)
     {
         if (type == '*' || type == file->name[0]) {
-            ffs_fread(&file->name[1], file->addr, file->size);
+            cal_fread(&file->name[1], file->addr, file->size);
         }
         file++;
     }
@@ -547,7 +554,7 @@
 #endif /*if (L1_FF_MULTIBAND == 0)*/
 
             if (read == 1)
-              ffs_fread(name, p, f1->size);
+              cal_fread(name, p, f1->size);
             else //write == 0
             {
               ffs_fwrite(name, p, f1->size);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsm-fw/L1/cust0/pirelli.c	Mon Jun 29 21:45:23 2015 +0000
@@ -0,0 +1,84 @@
+/*
+ * This module is a FreeCalypso addition.  Here we implement
+ * retrieval of Pirelli's factory calibration and IMEI records
+ * from their factory data block.
+ */
+
+#include <string.h>
+#include "config.h"
+#include "sys_types.h"
+#include "../../services/ffs/ffs.h"
+#include "../../services/ffs/core.h"	/* for ffs_begin() and ffs_end() */
+
+#define	FACTORY_BLOCK_BASE_ADDR	0x027F0000
+
+static effs_t
+pirelli_chksum(uint8 *addr, T_FFS_SIZE size)
+{
+	uint8 accum = 0;
+
+	for (; size; size--)
+		accum += *addr++;
+	if (accum == *addr)
+		return EFFS_OK;
+	else
+		return EFFS_CORRUPTED;
+}
+
+pirelli_read_factory_record(uint32 offset, void *userbuf, T_FFS_SIZE size,
+			    int has_chksum)
+{
+	effs_t rc;
+	uint8 *flash_record = (uint8 *) FACTORY_BLOCK_BASE_ADDR + offset;
+
+	rc = ffs_begin();
+	if (rc != EFFS_OK)
+		return(rc);
+	if (has_chksum)
+		rc = pirelli_chksum(flash_record, size);
+	if (rc == EFFS_OK)
+		bcopy(flash_record, userbuf, size);
+	return ffs_end(rc);
+}
+
+static const struct calmap {
+	uint32	offset;
+	char	*ti_equiv;
+} pirelli_cal_map[] = {
+	{0x06E5, "/sys/adccal"},
+	{0x072B, "/gsm/rf/tx/ramps.900"},
+	{0x092C, "/gsm/rf/tx/levels.900"},
+	{0x09AD, "/gsm/rf/tx/calchan.900"},
+	{0x0A2E, "/gsm/rf/tx/ramps.1800"},
+	{0x0C2F, "/gsm/rf/tx/levels.1800"},
+	{0x0CB0, "/gsm/rf/tx/calchan.1800"},
+	{0x0D31, "/gsm/rf/tx/ramps.1900"},
+	{0x0F32, "/gsm/rf/tx/levels.1900"},
+	{0x0FB3, "/gsm/rf/tx/calchan.1900"},
+	{0x10AF, "/gsm/rf/rx/calchan.900"},
+	{0x10D8, "/gsm/rf/rx/agcparams.900"},
+	{0x10E1, "/gsm/rf/rx/calchan.1800"},
+	{0x110A, "/gsm/rf/rx/agcparams.1800"},
+	{0x1113, "/gsm/rf/rx/calchan.1900"},
+	{0x113C, "/gsm/rf/rx/agcparams.1900"},
+	{0, 0}
+};
+
+pirelli_cal_fread(const char *name, void *userbuf, T_FFS_SIZE size)
+{
+	int rc;
+	const struct calmap *map;
+
+	/* try FFS first, so FreeCalypso user can override factory prog */
+	rc = ffs_file_read(name, userbuf, size);
+	if (rc >= 0)
+		return EFFS_OK;
+	/* does the sought file correspond to a Pirelli factory data record? */
+	for (map = pirelli_cal_map; map->ti_equiv; map++)
+		if (!strcmp(map->ti_equiv, name))
+			break;
+	if (!map->offset)	/* not found */
+		return rc;	/* return error code from FFS */
+	/* found it */
+	return pirelli_read_factory_record(map->offset, userbuf, size, 1);
+}
--- a/gsm-fw/cfgmagic/target.pirelli	Sun Jun 28 16:52:06 2015 +0000
+++ b/gsm-fw/cfgmagic/target.pirelli	Mon Jun 29 21:45:23 2015 +0000
@@ -1,5 +1,6 @@
 CONFIG_TARGET_PIRELLI=1
 export_to_c	CONFIG_TARGET_PIRELLI
+export_to_mk	CONFIG_TARGET_PIRELLI
 
 CONFIG_IRAM_SIZE=0x80000
 CONFIG_XRAM_SIZE=0x800000