summaryrefslogtreecommitdiffstats
path: root/package
diff options
context:
space:
mode:
authorblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>2007-12-24 23:06:11 +0000
committerblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>2007-12-24 23:06:11 +0000
commit2417836a4607b40767f4a3247bdcbefe424f3ece (patch)
tree43945ec2c079a441ab765a8b3801b170d9811ee6 /package
parentc91626b9ab84ef031b3f2315b713cf476ae2c1c8 (diff)
add ifx adsl tools
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@9900 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package')
-rw-r--r--package/ifxmips_adsl/Makefile45
-rw-r--r--package/ifxmips_adsl/src/Makefile10
-rw-r--r--package/ifxmips_adsl/src/cmvread.c216
-rw-r--r--package/ifxmips_adsl/src/cmvwrite.c221
-rw-r--r--package/ifxmips_adsl/src/danube_autoboot_daemon.c1011
-rw-r--r--package/ifxmips_adsl/src/danube_mei_debug.c84
-rw-r--r--package/ifxmips_adsl/src/danube_show_firmware_date.c75
-rw-r--r--package/ifxmips_adsl/src/model_config.sh14
-rw-r--r--package/ifxmips_adsl/src/sysconfig.sh90
-rw-r--r--package/ifxmips_adsl/src/translate.c848
10 files changed, 2614 insertions, 0 deletions
diff --git a/package/ifxmips_adsl/Makefile b/package/ifxmips_adsl/Makefile
new file mode 100644
index 000000000..7445b9ec6
--- /dev/null
+++ b/package/ifxmips_adsl/Makefile
@@ -0,0 +1,45 @@
+#
+# Copyright (C) 2007 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+# $Id$
+
+include $(TOPDIR)/rules.mk
+include $(INCLUDE_DIR)/kernel.mk
+
+PKG_NAME:=ifxmips_adsl
+PKG_RELEASE:=1
+PKG_VERSION:=1.0
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/ifxmips_adsl
+ SECTION:=net
+ CATEGORY:=Network
+ DEPENDS:=@TARGET_ifxmips
+ TITLE:=ifxmips adsl firmware loader
+endef
+
+define Package/ifxmips_adsl/description
+ ifxmips adsl firmware loader
+endef
+
+define Build/Prepare
+ mkdir -p $(PKG_BUILD_DIR)
+ $(CP) ./src/* $(PKG_BUILD_DIR)/
+endef
+
+define Build/Compile
+ $(MAKE) -C $(PKG_BUILD_DIR) \
+ $(TARGET_CONFIGURE_OPTS) \
+ CFLAGS="$(TARGET_CFLAGS) -I$(LINUX_DIR)/include/"
+endef
+
+define Package/ifxmips_adsl/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_BUILD_DIR)/{translate,danube_autoboot_daemon,danube_mei_debug,danube_show_firmware_date,cmvread,cmvwrite} $(1)/usr/bin/
+endef
+
+$(eval $(call BuildPackage,ifxmips_adsl))
diff --git a/package/ifxmips_adsl/src/Makefile b/package/ifxmips_adsl/src/Makefile
new file mode 100644
index 000000000..2f69a425c
--- /dev/null
+++ b/package/ifxmips_adsl/src/Makefile
@@ -0,0 +1,10 @@
+CFLAGS?=
+
+TARGET = translate danube_autoboot_daemon danube_mei_debug danube_show_firmware_date cmvread cmvwrite
+
+all: $(TARGET)
+
+.PHONY: clean
+clean:
+ -rm -f $(DEPS) $(OBJS) $(TARGET)
+
diff --git a/package/ifxmips_adsl/src/cmvread.c b/package/ifxmips_adsl/src/cmvread.c
new file mode 100644
index 000000000..7e5eecd0f
--- /dev/null
+++ b/package/ifxmips_adsl/src/cmvread.c
@@ -0,0 +1,216 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+//-----------------------------------------------------------------------
+//Description:
+// read the CMV register under Linux for Amazon
+//-----------------------------------------------------------------------
+//Author: Joe.Lin@infineon.com
+//Created: 31-December-2004
+//-----------------------------------------------------------------------
+/* History
+ * Last changed on:
+ * 000002:tc.chen 2005/06/10 add get_adsl_rate and ifx_makeCMV api
+ * Last changed by:
+ *
+*/
+
+#define _IFXMIPS_ADSL_APP
+//#define DEBUG
+#define u32 unsigned int
+#define u16 unsigned short
+#define u8 unsigned char
+#define IFXMIPS_MEI_DEV "/dev/ifxmips/mei"
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+#include <asm/ifxmips/ifxmips_mei_app_ioctl.h>
+#include <asm/ifxmips/ifxmips_mei_app.h>
+#include <asm/ifxmips/ifxmips_mei_ioctl.h>
+#include <asm/ifxmips/ifxmips_mei.h>
+
+#ifdef IFX_MULTILIB_UTIL
+#define main cmvread_main
+#define display_version cmvread_display_version
+#endif
+
+/*============================definitions======================*/
+#define OPTN 5
+#define CNFG 8
+#define CNTL 1
+#define STAT 2
+#define RATE 6
+#define PLAM 7
+#define INFO 3
+#define TEST 4
+
+typedef unsigned short UINT16;
+typedef unsigned long UINT32;
+
+
+
+/*=============================================================*/
+
+
+/*=============================global variables================*/
+int c=0;
+int input_flag=0;
+int digit_optind=0;
+FILE* script_file;
+void (*func)()=NULL;
+int fd;
+
+UINT16 var16[8];
+UINT32 var32[8];
+UINT16 Message[16];
+
+/*=============================================================*/
+
+int ifx_makeCMV(unsigned char opcode, unsigned char group, unsigned short address, unsigned short index, int size, unsigned short * data, unsigned short *Message, int msg_len)
+{
+ if (msg_len < 16*2)
+ return -1;
+ memset(Message, 0, 16*2);
+ Message[0]= (opcode<<4) + (size&0xf);
+ if(opcode == H2D_DEBUG_WRITE_DM)
+ Message[1]= (group&0x7f);
+ else
+ Message[1]= (((index==0)?0:1)<<7) + (group&0x7f);
+ Message[2]= address;
+ Message[3]= index;
+ if((opcode == H2D_CMV_WRITE)||(opcode == H2D_DEBUG_WRITE_DM))
+ memcpy(Message+4, data, size*2);
+
+ return 0;
+}
+
+void display_version()
+{
+ printf("adsl cmv reader version1.0\nby Joe Lin \nJoe.Lin@infineon.com\n");
+ return;
+}
+
+
+void cmvreader_help()
+{
+ printf("Usage:cmvread [options] [group name][address][index][size] ...\n");
+ printf("options:\n");
+ printf(" -h --help Display help information\n");
+ printf(" -v --version Display version information\n");
+ printf("group name: --group name of CMV to read\n");
+ printf(" OPTN --Read CMV Group 5 \n");
+ printf(" CNFG --Read CMV Group 8 \n");
+ printf(" CNTL --Read CMV Group 1 \n");
+ printf(" STAT --Read CMV Group 2 \n");
+ printf(" RATE --Read CMV Group 6 \n");
+ printf(" PLAM --Read CMV Group 7 \n");
+ printf(" INFO --Read CMV Group 3 \n");
+ printf(" TEST --REad CMV Group 4 \n");
+ printf("address --address value of CMV to read\n");
+ printf("index --index value of CMV to read\n");
+ printf("size --number of words(16bits) to read \n");
+
+
+
+ return;
+}
+
+int main (int argc, char** argv) {
+
+ UINT16 Message[16]; //000002:tc.chen
+ char *endptr;
+ int group=0,address,index,size;
+
+ if (argc < 2)
+ {
+ cmvreader_help();
+ return;
+ }
+
+ if (strstr(argv[1], "-h") != NULL){
+ cmvreader_help();
+ return;
+ }
+
+ if (strstr(argv[1], "-v") != NULL){
+ display_version();
+ return;
+ }
+
+ fd=open(IFXMIPS_MEI_DEV, O_RDWR);
+ if(fd<0){
+ printf("\n\n autoboot open device fail\n");
+ return -1;
+ }
+
+ if((strcmp(argv[1],"optn")==0)||(strcmp(argv[1],"OPTN")==0))
+ group=OPTN;
+ else if((strcmp(argv[1],"cnfg")==0)||(strcmp(argv[1],"CNFG")==0))
+ group=CNFG;
+ else if((strcmp(argv[1],"cntl")==0)||(strcmp(argv[1],"CNTL")==0))
+ group=CNTL;
+ else if((strcmp(argv[1],"stat")==0)||(strcmp(argv[1],"STAT")==0))
+ group=STAT;
+ else if((strcmp(argv[1],"rate")==0)||(strcmp(argv[1],"RATE")==0))
+ group=RATE;
+ else if((strcmp(argv[1],"plam")==0)||(strcmp(argv[1],"PLAM")==0))
+ group=PLAM;
+ else if((strcmp(argv[1],"info")==0)||(strcmp(argv[1],"INFO")==0))
+ group=INFO;
+ else if((strcmp(argv[1],"test")==0)||(strcmp(argv[1],"TEST")==0))
+ group=TEST;
+ else
+ {
+ printf("wrong group type!\nplease slect group:OPTN CNFG CNTL STAT RATE PLAM INFO TEST \n");
+ close(fd);
+ exit(0);
+ }
+
+ address = strtoul(argv[2], &endptr, 0);
+ index = strtoul(argv[3], &endptr, 0);
+ size = strtoul(argv[4], &endptr, 0);
+ //makeCMV(H2D_CMV_READ, group, address, index, size, NULL);
+ ifx_makeCMV(H2D_CMV_READ, group, address, index, size, NULL,Message,sizeof(Message));
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("cr read %d %d %d fail",group,address,index);
+ close(fd);
+ exit(0);
+ }
+
+ int i;
+ for (i=0;i<size;i++) printf ("0x%X\n",Message[i+4]);
+
+
+// return Message[4];
+
+
+
+
+ close(fd);
+ return 0;
+}
+
+
+
diff --git a/package/ifxmips_adsl/src/cmvwrite.c b/package/ifxmips_adsl/src/cmvwrite.c
new file mode 100644
index 000000000..4d68cc6b1
--- /dev/null
+++ b/package/ifxmips_adsl/src/cmvwrite.c
@@ -0,0 +1,221 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+//-----------------------------------------------------------------------
+//Description:
+// read the CMV register under Linux for Amazon
+//-----------------------------------------------------------------------
+//Author: Joe.Lin@infineon.com
+//Created: 31-December-2004
+//-----------------------------------------------------------------------
+/* History
+ * Last changed on:
+ * 507051:linmars 2005/07/5 fix makeCMV problem
+ * Last changed by:
+ *
+*/
+
+#define _IFXMIPS_ADSL_APP
+//#define DEBUG
+#define u32 unsigned int
+#define u16 unsigned short
+#define u8 unsigned char
+#define IFXMIPS_MEI_DEV "/dev/ifxmips/mei"
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+#include <asm/ifxmips/ifxmips_mei_app_ioctl.h>
+#include <asm/ifxmips/ifxmips_mei_app.h>
+#include <asm/ifxmips/ifxmips_mei_ioctl.h>
+#include <asm/ifxmips/ifxmips_mei.h>
+
+#ifdef IFX_MULTILIB_UTIL
+#define main cmvwrite_main
+#define display_version cmvwrite_display_version
+#endif
+
+/*============================definitions======================*/
+#define OPTN 5
+#define CNFG 8
+#define CNTL 1
+#define STAT 2
+#define RATE 6
+#define PLAM 7
+#define INFO 3
+#define TEST 4
+
+typedef unsigned short UINT16;
+typedef unsigned long UINT32;
+
+/*=============================================================*/
+
+
+/*=============================global variables================*/
+#ifdef IFX_MULTILIB_UTIL
+extern int c;
+extern int input_flag;
+extern int digit_optind;
+extern FILE* script_file;
+extern void (*func)();
+extern int fd;
+
+UINT16 var16[8];
+UINT32 var32[8];
+UINT16 Message[16];
+#else
+int c=0;
+int input_flag=0;
+int digit_optind=0;
+FILE* script_file;
+void (*func)()=NULL;
+int fd;
+
+UINT16 var16[8];
+UINT32 var32[8];
+UINT16 Message[16];
+#endif
+/*=============================================================*/
+/*165001:henryhsu 2005/9/7 Modify some error in cmvwrite utility*/
+int ifx_makeCMV(unsigned char opcode, unsigned char group, unsigned short address, unsigned short index, int size, unsigned short * data, unsigned short *Message, int msg_len)
+{
+ if (msg_len < 16*2)
+ return -1;
+ memset(Message, 0, 16*2);
+ Message[0]= (opcode<<4) + (size&0xf);
+ if(opcode == H2D_DEBUG_WRITE_DM)
+ Message[1]= (group&0x7f);
+ else
+ Message[1]= (((index==0)?0:1)<<7) + (group&0x7f);
+ Message[2]= address;
+ Message[3]= index;
+ if((opcode == H2D_CMV_WRITE)||(opcode == H2D_DEBUG_WRITE_DM))
+ memcpy(Message+4, data, size*2);
+
+ return 0;
+}
+
+
+void display_version()
+{
+ printf("adsl cmv write version1.0\nby Joe Lin \nJoe.Lin@infineon.com\n");
+ return;
+}
+
+//165001:henryhsu 2005/9/7 No need to check this any more
+//#ifndef IFX_MULTILIB_UTIL
+
+//void cmvreader_help()
+void cmvwrite_help()
+{
+ printf("Usage:cmvwrite [options] [group name][address][index][data] ...\n");
+ printf("options:\n");
+ printf(" -h --help Display help information\n");
+ printf(" -v --version Display version information\n");
+ printf("group name: --group name of CMV to read\n");
+ printf(" OPTN -- CMV Group 5 \n");
+ printf(" CNFG -- CMV Group 8 \n");
+ printf(" CNTL -- CMV Group 1 \n");
+ printf(" STAT -- CMV Group 2 \n");
+ printf(" RATE -- CMV Group 6 \n");
+ printf(" PLAM -- CMV Group 7 \n");
+ printf(" INFO -- CMV Group 3 \n");
+ printf(" TEST -- CMV Group 4 \n");
+ printf("address --address value of CMV to write\n");
+ printf("index --index value of CMV to write\n");
+ printf("data --data to write in Hex.\n");
+
+ return;
+}
+
+int main (int argc, char** argv) {
+
+ char *endptr;
+ unsigned short value;
+ if (argc < 2)
+ {
+ cmvwrite_help();
+ return;
+ }
+
+ if (strstr(argv[1], "-h") != NULL){
+ cmvwrite_help();
+ return;
+ }
+
+ if (strstr(argv[1], "-v") != NULL){
+ display_version();
+ return;
+ }
+
+
+ fd=open(IFXMIPS_MEI_DEV, O_RDWR);
+ if(fd<0){
+ printf("\n\n autoboot open device fail\n");
+ return -1;
+ }
+
+
+
+ int group=0,address,index,size;
+ if((strcmp(argv[1],"optn")==0)||(strcmp(argv[1],"OPTN")==0))
+ group=OPTN;
+ else if((strcmp(argv[1],"cnfg")==0)||(strcmp(argv[1],"CNFG")==0))
+ group=CNFG;
+ else if((strcmp(argv[1],"cntl")==0)||(strcmp(argv[1],"CNTL")==0))
+ group=CNTL;
+ else if((strcmp(argv[1],"stat")==0)||(strcmp(argv[1],"STAT")==0))
+ group=STAT;
+ else if((strcmp(argv[1],"rate")==0)||(strcmp(argv[1],"RATE")==0))
+ group=RATE;
+ else if((strcmp(argv[1],"plam")==0)||(strcmp(argv[1],"PLAM")==0))
+ group=PLAM;
+ else if((strcmp(argv[1],"info")==0)||(strcmp(argv[1],"INFO")==0))
+ group=INFO;
+ else if((strcmp(argv[1],"test")==0)||(strcmp(argv[1],"TEST")==0))
+ group=TEST;
+ else
+ {
+ printf("wrong group type!\nplease slect group:OPTN CNFG CNTL STAT RATE PLAM INFO TEST \n");
+ close(fd);
+ exit(0);
+ }
+
+ address = strtoul(argv[2], &endptr, 10);
+ index = strtoul(argv[3], &endptr, 10);
+
+ value = strtoul(argv[4],NULL,0);
+ ifx_makeCMV(H2D_CMV_WRITE, group, address, index, 1, &value, Message, sizeof(Message));
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("cr read %d %d %d fail",group,address,index);
+ close(fd);
+ exit(0);
+ }
+
+ printf ("write %s %d %d 0x%X\n",argv[1],address,index,value);
+
+ close(fd);
+ return 0;
+}
+
diff --git a/package/ifxmips_adsl/src/danube_autoboot_daemon.c b/package/ifxmips_adsl/src/danube_autoboot_daemon.c
new file mode 100644
index 000000000..9563b5bbc
--- /dev/null
+++ b/package/ifxmips_adsl/src/danube_autoboot_daemon.c
@@ -0,0 +1,1011 @@
+/****************************************************************************
+
+ Copyright (c) 2005
+ Infineon Technologies AG
+ St. Martin Strasse 53; 81669 Munich, Germany
+
+ Any use of this Software is subject to the conclusion of a respective
+ License Agreement. Without such a License Agreement no rights to the
+ Software are granted.
+
+*****************************************************************************/
+/**
+History:
+1.02:
+09/08/2006 Removed DEMO_ONLY define
+1.03:
+31/08/2006 Add IOCTL AUTOBOOT_ENABLE_SET
+1.04:
+14/09/2006 Add min snr margin check for in Annex B DMT mode
+1.05:
+18/09/2006 Add G.lite support
+1.06: 611101:tc.chen
+10/11/2006 change quiet mode and showtime lock implement mechanism (old: using cmv, new: using ioctl to kernel mode, and the mei driver keep the value) per the mail from Oliver Salomon on 08/11/2006
+1.07:
+13/11/2006 TC Chen: Fix minimal snr issue for ADSL Annex B.
+1.08:
+08/12/2006 TC Chen: Fix loop diagnostic warning issue
+1.09:
+27/12/2006 TC Chen: Fix the issue that "The autoboot daemon will call "./translate" which is a problem when started through scripts."
+1.10"
+1/09/2007 Bing Tao: Fix AnnexJ issue
+*/
+
+#define _IFXMIPS_ADSL_APP
+//#define IFXMIPS_PORT_RTEMS 1
+#define __LINUX__
+
+#if defined(IFXMIPS_PORT_RTEMS)
+#include "ifxmips_mei_rtems.h"
+#define KERNEL_SPACE_APPLICATION 1
+#endif
+
+#define u32 unsigned int
+
+#define VERSION_MAJOR 1
+#define VERSION_MINOR 10
+
+#if defined(__LINUX__)
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <asm/ifxmips/ifxmips_mei_app.h>
+#include <asm/ifxmips/ifxmips_mei_app_ioctl.h>
+#include <asm/ifxmips/ifxmips_mei_ioctl.h>
+#include <sys/types.h>
+#include <string.h>
+#include <time.h>
+
+#define IFXMIPS_MEI_DEV "/dev/ifxmips/mei"
+#endif
+
+#if defined(KERNEL_SPACE_APPLICATION)
+#include "ifxmips_adsl_fw.h"
+#endif
+
+#define IFXMIPS_GPIO_DEVICE "/dev/ifxmips_port"
+#undef DEMO_ONLY //todo: remove for normal release
+
+#define SEGMENT_SIZE (64*1024)
+
+#define MODE_ALL 0
+#define MODE_992_1A 1
+#define MODE_992_1B 2
+#define MODE_992_3A 3
+#define MODE_992_3B 4
+#define MODE_992_5A 5
+#define MODE_992_5B 6
+
+#define MODE_992_3I 7
+#define MODE_992_3J 8
+#define MODE_992_3M 9
+#define MODE_992_5I 10
+#define MODE_992_5J 11
+#define MODE_992_5M 12
+#define MODE_M_ALL 13
+#define MODE_B_ALL 14
+#define MODE_M_B_ALL 15
+
+
+#if defined(KERNEL_SPACE_APPLICATION)
+extern int mei_ioctl(int ino, int * fil, unsigned int command, unsigned long lon);
+#define ioctl(fd,cmd,arg) mei_ioctl(1,0,cmd,(unsigned long)arg)
+extern void makeCMV(u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data,u16 *CMVMSG);
+#endif
+
+static u16 Message[16]__attribute__ ((aligned(4)));
+
+#if !defined(KERNEL_SPACE_APPLICATION)
+void makeCMV(u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data, u16 *CMVMSG);
+void makeCMV(u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data, u16 *CMVMSG)
+{
+ memset(CMVMSG, 0, 16*2);
+ CMVMSG[0]= (opcode<<4) + (size&0xf);
+ if(opcode == H2D_DEBUG_WRITE_DM)
+ CMVMSG[1]= (group&0x7f);
+ else
+ CMVMSG[1]= (((index==0)?0:1)<<7) + (group&0x7f);
+ CMVMSG[2]= address;
+ CMVMSG[3]= index;
+ if((opcode == H2D_CMV_WRITE)||(opcode == H2D_DEBUG_WRITE_DM))
+ memcpy(CMVMSG+4, data, size*2);
+ return;
+}
+#endif
+
+void print_usage(char *program_name)
+{
+ printf("Usage: %s ADSL_Firmware ADSL_MODE \n",program_name);
+ printf("\tADSL_Firmeare: Specify the ADSL firmware file to use.\n");
+ printf("\tADSL_MODE:Specify the ADSL mode to use for training.\n");
+ printf("\t\tSupported Mode: all,1a,3a,5a,1b,3b,5b,3i,3j,3m,5i,5j,5m,m_all,b_all,mb_all\n");
+
+}
+
+#if defined(KERNEL_SPACE_APPLICATION)
+
+int Download_Firmware(char *filename, int fd_mei)
+{
+ extern ssize_t mei_write(char * filp, const char * buf, size_t size, loff_t * loff);
+ extern unsigned long cgi_pFileData_modemfw_bin[];
+ unsigned long offset=0;
+
+ mei_write(0,(char *)cgi_pFileData_modemfw_bin,sizeof(cgi_pFileData_modemfw_bin),&offset);
+ return 0;
+}
+#else
+int Download_Firmware(char *filename, int fd_mei)
+{
+ int fd_image=0;
+ char *buf=NULL;
+ int size=0,read_size = SEGMENT_SIZE;
+ struct stat file_stat;
+
+ fd_image=open(filename, O_RDONLY);
+ if (fd_image<=0)
+ {
+ printf("\n open %s fail.\n",filename);
+ return -1;
+ }
+ if(lstat(filename, &file_stat)<0){
+ printf("\n lstat error");
+ return -1;
+ }
+ size=file_stat.st_size;
+ buf=malloc(read_size);
+ if(buf==NULL){
+ printf("\n malloc failed in MEI main()");
+ return -1;
+ }
+
+ lseek(fd_image, 0, SEEK_SET);
+ lseek(fd_mei, 0, SEEK_SET);
+ while(size>0)
+ {
+ static flag=1;
+ if (size>SEGMENT_SIZE)
+ read_size=SEGMENT_SIZE;
+ else
+ read_size=size;
+ if(read(fd_image, buf, read_size)<=0){
+ printf("\n amazon_mei_image not present");
+ return -1;
+ }
+ if(write(fd_mei, buf, read_size)!=read_size){
+ printf("\n write to mei driver fail");
+ free(buf);
+ return -1;
+ }
+ size-=read_size;
+ }
+ free(buf);
+ close(fd_image);
+}
+#endif
+
+// 609141:tc.chen :read min margin from CO for Annex B in DMT mode
+int read_min_snr_margin(int fd, s16 *rt_ne_ds_min_margin)
+{
+ makeCMV(H2D_CMV_READ,STAT, 1, 0, 1, NULL, Message);
+ if (ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)!=0)
+ return -1;
+ if (Message[4] == 0x8) //992.1 AnnexB
+ {
+ u16 min_margin;
+ makeCMV(H2D_CMV_READ,INFO, 33, 1, 1, NULL, Message);
+ if (ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)!=0)
+ {
+ return -1;
+ }
+ // INFO 33 is 6 bits sign value
+ min_margin = (Message[4] & 0x3f);
+ if (min_margin > 31)
+ {
+ *rt_ne_ds_min_margin = min_margin - 64;
+ }else
+ {
+ *rt_ne_ds_min_margin = min_margin ;
+ }
+ }else
+ {
+ *rt_ne_ds_min_margin = 0;
+ }
+ return 0;
+}
+// 609141:tc.chen end
+
+#if !defined(KERNEL_SPACE_APPLICATION)
+int main(int argc, char **argv)
+#else
+int ifxmips_autoboot_main (int argc, char **argv)
+#endif
+{
+ int fd;
+ int i,j;
+ char systemstr[50];
+ u16 all_data = 0;
+ u16 zero = 0x0;
+ u16 one=0x1;
+ u16 mw = 0x10;
+ u16 link = 0x2;
+ u16 temp=0;
+ u16 rt_macrostate;
+ meireg meiregister;
+ int reboot_flag, rt_ne_los_flag;
+ u16 rt_ne_failure_flags=0;
+ s16 rt_ne_ds_margin=0;
+ s16 rt_ne_ds_min_margin=0; //609141:tc.chen:
+ u16 rt_buildcode_lsw=0, rt_buildcode_msw=0;
+ u32 rt_buildcode = 0;
+ int FarEndResponseReceived;
+ time_t start_time;
+ int timeout_limit;
+ int tmpShowTimeLockEnabled = 0;
+ u16 nFECS_L_count=0;
+ u16 nES_L_count=0;
+ u16 nSES_L_count=0;
+ u16 nLOSS_L_count=0;
+ u16 first_power_on=1;
+ int mode = -1;
+ int pre_loop_diagnostics_mode=0;
+ int loop_diagnostics_mode=0;
+
+ if ((argc < 2) || (argc > 5) )
+ { printf("\n Wrong Argument\n");
+ print_usage(argv[0]);
+ return -1;
+ }
+
+//KD
+// translate is called with "./translate -ef", but if the autoboot daemon
+// is started during system boot, the current directory is "/", which
+// makes the "system" call fail.
+// Thus we make the program's directory the working directory.
+ {
+ char *argv0, *prog_dir;
+ int argv0_size;
+ /* The dirname system call might change its argument,
+ thus we need a local copy */
+ argv0_size = strlen(argv[0]) + 1;
+ argv0 = malloc(argv0_size);
+ if (argv0 == 0) {
+ printf("\n Insufficient memory\n");
+ return -1;
+ }
+ /* make sure there is no buffer overflow and
+ the string is null-terminated */
+ strncpy(argv0, argv[0], argv0_size);
+ argv0[argv0_size-1] = '\0';
+
+ prog_dir = dirname(argv0);
+ chdir(prog_dir);
+ free(argv0);
+ argv0 = 0;
+ }
+
+ //display version info or download firmware
+ if(argc==2)
+ {
+ if ((strncmp(argv[1], "ver", 3)==0) || (strncmp(argv[1], "VER", 3)==0)){
+ printf("\n ifxmips_autoboot_daemon version: %d.%02d.00\n",VERSION_MAJOR,VERSION_MINOR);
+ }else
+ {
+#if !defined(KERNEL_SPACE_APPLICATION)
+ fd=open(IFXMIPS_MEI_DEV, O_RDWR);
+ if(fd<0){
+ printf("autoboot open %s fail\n",IFXMIPS_MEI_DEV);
+ return -1;
+ }
+#endif
+ // Notify mei driver that it is controlled by autoboot daemon
+ i = 1;
+ if (ioctl(fd, AUTOBOOT_ENABLE_SET, &i)<0){
+ printf("\n\n mei ioctl AUTOBOOT_ENABLE_SET fail.\n");
+ }
+
+ Download_Firmware(argv[1],fd);
+ if (ioctl(fd, IFXMIPS_MEI_START,NULL)<0){
+ printf("\n\n mei start fail.\n");
+#if !defined(KERNEL_SPACE_APPLICATION)
+ close(fd);
+#endif
+ return -1;
+ }
+#if !defined(KERNEL_SPACE_APPLICATION)
+ close(fd);
+#endif
+ }
+ return 0;
+ }
+
+ if (strncmp(argv[2], "all", 3) == 0)
+ mode = MODE_ALL;
+ else if ((strncmp(argv[2], "1a", 2) == 0) || (strncmp(argv[2], "1A", 2) == 0))
+ mode = MODE_992_1A;
+ else if ((strncmp(argv[2], "1b", 2) == 0) || (strncmp(argv[2], "1B", 2) == 0))
+ mode = MODE_992_1B;
+ else if ((strncmp(argv[2], "3a", 2) == 0) || (strncmp(argv[2], "3A", 2) == 0))
+ mode = MODE_992_3A;
+ else if ((strncmp(argv[2], "3b", 2) == 0) || (strncmp(argv[2], "3B", 2) == 0))
+ mode = MODE_992_3B;
+ else if ((strncmp(argv[2], "5a", 2) == 0) || (strncmp(argv[2], "5A", 2) == 0))
+ mode = MODE_992_5A;
+ else if ((strncmp(argv[2], "5b", 2) == 0) || (strncmp(argv[2], "5B", 2) == 0))
+ mode = MODE_992_5B;
+
+ else if ((strncmp(argv[2], "3i",2) == 0) || (strncmp(argv[2], "3I",2) == 0))
+ mode = MODE_992_3I;
+ else if ((strncmp(argv[2], "3j",2) == 0) || (strncmp(argv[2], "3J",2) == 0))
+ mode = MODE_992_3J;
+ else if ((strncmp(argv[2], "3m",2) == 0) || (strncmp(argv[2], "3M",2) == 0))
+ mode = MODE_992_3M;
+ else if ((strncmp(argv[2], "5i",2) == 0) || (strncmp(argv[2], "5I",2) == 0))
+ mode = MODE_992_5I;
+ else if ((strncmp(argv[2], "5j",2) == 0) || (strncmp(argv[2], "5J",2) == 0))
+ mode = MODE_992_5J;
+ else if ((strncmp(argv[2], "5m",2) == 0) || (strncmp(argv[2], "5M",2) == 0))
+ mode = MODE_992_5M;
+ else if (strncmp(argv[2], "m_all",5) == 0)
+ mode = MODE_M_ALL;
+ else if (strncmp(argv[2], "b_all",5) == 0)
+ mode = MODE_B_ALL;
+ else if (strncmp(argv[2], "mb_all",6) == 0)
+ mode = MODE_M_B_ALL;
+
+ if (mode == -1)
+ { printf("\n Wrong Argument\n");
+ print_usage(argv[0]);
+ return -1;
+ }
+
+#if !defined(KERNEL_SPACE_APPLICATION)
+ fd=open(IFXMIPS_MEI_DEV, O_RDWR);
+ if(fd<0){
+ printf("autoboot open %s fail\n",IFXMIPS_MEI_DEV);
+ return -1;
+ }
+#endif
+fw_download:
+ i = 1;
+ if (ioctl(fd, AUTOBOOT_ENABLE_SET, &i)<0){
+ printf("\n\n mei ioctl AUTOBOOT_ENABLE_SET fail.\n");
+ }
+ Download_Firmware(argv[1],fd);
+
+ if (ioctl(fd, IFXMIPS_MEI_START,NULL)<0){
+ printf("\n\n mei start fail.\n");
+ ioctl(fd, IFXMIPS_MEI_REBOOT,NULL);
+ goto fw_download;
+ }
+
+ // test Annex A or B
+ makeCMV(H2D_CMV_READ, INFO, 54,1, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read INFO 54 1 fail");
+ return -1;
+ }
+
+ if(((Message[4]>>8)&0x3f)==0x1){//Annex A
+ all_data = 0x9105;
+ if ((mode == MODE_992_1B) || (mode == MODE_992_3B) || (mode == MODE_992_5B))
+ { printf("\n\nWrong Argument, Annex A is running!\n\n");
+ return -1;
+ }
+ }
+ else if(((Message[4]>>8)&0x3f)==0x2){// Annex B
+ all_data=0x4208;
+ if ( (mode == MODE_992_1A) || (mode == MODE_992_3A) || (mode == MODE_992_5A)\
+// changed by xu bingtao 09/01/2007
+/*
+ || (mode == MODE_992_3I) || (mode == MODE_992_3J) ||(mode == MODE_992_3M)\
+ || (mode == MODE_992_5I) || (mode == MODE_992_5J) || (mode == MODE_992_5M))
+*/
+ || (mode == MODE_992_3I) ||(mode == MODE_992_3M)\
+ || (mode == MODE_992_5I) || (mode == MODE_992_5M))
+// changed by xu bingtao 09/01/2007
+ { printf("\n\nWrong Argument, Annex B is running!\n\n");
+ return -1;
+ }
+ }
+ else{
+ printf("\n\n Firmware Neither Annex A nor B\n\n");
+ return -1;
+ }
+
+ /* add by tc chen */
+ system("echo \"0\" > /tmp/adsl_status");
+
+ makeCMV(H2D_CMV_READ, INFO, 55, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read INFO 55 0 fail");
+ return -1;
+ }
+
+ rt_buildcode_lsw = Message[4];
+
+ makeCMV(H2D_CMV_READ, INFO, 55, 1, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read INFO 55 1 fail");
+ return -1;
+ }
+ rt_buildcode_msw = Message[4];
+
+ rt_buildcode = rt_buildcode_lsw + (rt_buildcode_msw << 16);
+ printf("date: %d, month: %d, hour: %d, minute: %d\n",
+ (rt_buildcode >> 0) & 0xFF,
+ (rt_buildcode >> 8) & 0xFF,
+ (rt_buildcode >> 16) & 0xFF,
+ (rt_buildcode >> 25) & 0xFF
+ );
+
+ while(1){
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &zero, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ if (mode == MODE_992_1A)
+ { makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x4;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_992_3A)
+ { makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x100;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_992_5A)
+ { makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x8100;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_992_1B)
+ { makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x8;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_992_3B)
+ { makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x200;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_992_5B)
+ { makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x4200;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }
+
+ else if (mode == MODE_992_3I)
+ { makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x400;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_992_3J)
+ { makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x800;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_992_3M)
+ { makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x2000;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_992_5I)
+ { makeCMV(H2D_CMV_READ, OPTN, 7, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 7 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x1;
+ makeCMV(H2D_CMV_WRITE, OPTN, 7, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 7 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_992_5J)
+ { makeCMV(H2D_CMV_READ, OPTN, 7, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 7 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x2;
+ makeCMV(H2D_CMV_WRITE, OPTN, 7, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 7 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_992_5M)
+ { makeCMV(H2D_CMV_READ, OPTN, 7, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 7 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x4;
+ makeCMV(H2D_CMV_WRITE, OPTN, 7, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 7 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_M_ALL){
+ makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x2000;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+
+ makeCMV(H2D_CMV_READ, OPTN, 7, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 7 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x4;
+ makeCMV(H2D_CMV_WRITE, OPTN, 7, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 7 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_B_ALL){
+ makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x4208;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }else if (mode == MODE_M_B_ALL){
+ makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=0x6208;
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }
+ else if (mode == MODE_ALL)
+ { makeCMV(H2D_CMV_READ, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp|=all_data;
+ temp|= 2; //609181:tc.chen support G.lite
+
+ makeCMV(H2D_CMV_WRITE, OPTN, 0, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 0 0 fail");
+ goto rt_reboot;
+ }
+ }
+
+ if(ioctl(fd, GET_ADSL_LOOP_DIAGNOSTICS_MODE, &j)<0){
+ printf("\n\n ioctl GET_ADSL_LOOP_DIAGNOSTICS_MODE fail");
+ goto rt_reboot;
+ }
+ if (j == 1) // LOOP DIAGNOSTICS enabled
+ {
+ makeCMV(H2D_CMV_READ, OPTN, 9, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read OPTN 9 0 fail");
+ goto rt_reboot;
+ }
+ temp = Message[4];
+ temp |= 1<<2;
+ //temp = 1<<2;
+ makeCMV(H2D_CMV_WRITE, OPTN, 9, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 9 0 fail");
+ goto rt_reboot;
+ }
+ }
+
+ /************ remove in future ***********/
+
+ if(argc==4){ //execute script file
+ strncpy(systemstr, "./translate -ef ",16);
+ strcpy(systemstr+16, argv[3]);
+ system(systemstr);
+ }
+
+#ifdef DEMO_ONLY
+ if (mode == MODE_992_1A)
+ temp=0x303;
+ else
+ temp=0x300;
+ makeCMV(H2D_CMV_WRITE, OPTN, 1, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 1 0 fail");
+ return -1;
+ }
+ temp=0x8f78;
+ makeCMV(H2D_CMV_WRITE, OPTN, 2, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n write OPTN 2 0 fail");
+ return -1;
+ }
+#endif
+
+ makeCMV(H2D_CMV_WRITE, CNTL, 0, 0, 1, &link, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n set CNTL 0 0 fail");
+ goto rt_reboot;
+ }
+
+ FarEndResponseReceived=0;
+ time(&start_time);
+ timeout_limit=60;
+
+ while(1){
+ int tmpQuietModeEnabled;
+ tmpQuietModeEnabled = 0;
+ if(ioctl(fd, QUIET_MODE_GET, &tmpQuietModeEnabled)<0){
+ printf("\n\n ioctl QUIET_MODE_GET fail");
+ goto rt_reboot;
+ }
+#if 0 // 611101:tc.chen : change to use ioctl QUIET_MODE_GET
+ makeCMV(H2D_CMV_READ, INFO, 94, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n INFO 94 0 read fail");
+ goto rt_reboot;
+ }
+ if( Message[4] == 0x0 )
+ tmpQuietModeEnabled = 1;
+#endif
+ // check if loop diagnostic mode is changed
+ if(ioctl(fd, GET_ADSL_LOOP_DIAGNOSTICS_MODE, &loop_diagnostics_mode)<0)
+ {
+ printf("\n\n ioctl GET_ADSL_LOOP_DIAGNOSTICS_MODE fail");
+ goto rt_reboot;
+ }
+ if (loop_diagnostics_mode != pre_loop_diagnostics_mode)
+ {
+ pre_loop_diagnostics_mode = loop_diagnostics_mode;
+ goto rt_reboot;
+ }
+
+ makeCMV(H2D_CMV_READ, STAT, 0, 0, 1, &rt_macrostate, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n STAT read fail");
+ goto rt_reboot;
+ }
+
+ if(Message[4]==2)
+ {
+ if( tmpQuietModeEnabled == 0 )
+ break;
+ }
+
+ if((FarEndResponseReceived==0) && ((Message[4]==5) || (Message[4]==6))){
+ FarEndResponseReceived=1;
+ timeout_limit=60;
+ time(&start_time);
+ }
+
+ if(Message[4]==9){
+ timeout_limit=120;
+ if(FarEndResponseReceived==0){
+ FarEndResponseReceived=1;
+ time(&start_time);
+ }
+ }
+
+ if(Message[4]==3){
+ if( tmpQuietModeEnabled == 0 ){
+ sleep(5);
+ break;
+ }
+ }
+
+ if(Message[4]==7){
+ break;
+ }
+
+ if(time((time_t *)0)-start_time > timeout_limit){
+ if( tmpQuietModeEnabled == 0 )
+ break;
+ }
+ usleep(100000);
+ }
+
+ if (Message[4] != 7)
+ {
+ if (Message[4] == 3) // Done with loop diagnostics
+ {
+ ioctl(fd,LOOP_DIAGNOSTIC_MODE_COMPLETE,NULL);
+ while(1)
+ {
+ if(ioctl(fd, GET_ADSL_LOOP_DIAGNOSTICS_MODE, &loop_diagnostics_mode)<0)
+ {
+ printf("\n\n ioctl GET_ADSL_LOOP_DIAGNOSTICS_MODE fail");
+ goto rt_reboot;
+ }
+ if (loop_diagnostics_mode == 0)
+ {
+ pre_loop_diagnostics_mode = loop_diagnostics_mode;
+ goto rt_reboot;
+ }
+ sleep(1);
+ }
+ }else
+ {
+ printf("\n\n Keep trying to reboot!");
+ goto rt_reboot;
+ }
+ }
+
+ j=0;
+ reboot_flag=0;
+ while(reboot_flag==0){
+ if(ioctl(fd, GET_ADSL_LOOP_DIAGNOSTICS_MODE, &loop_diagnostics_mode)<0)
+ {
+ printf("\n\n ioctl GET_ADSL_LOOP_DIAGNOSTICS_MODE fail");
+ goto rt_reboot;
+ }
+ if (loop_diagnostics_mode != pre_loop_diagnostics_mode)
+ {
+ pre_loop_diagnostics_mode = loop_diagnostics_mode;
+ goto rt_reboot;
+ }
+
+ makeCMV(H2D_CMV_READ, PLAM, 0, 0, 1, &rt_ne_failure_flags, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n PLAM 0 0 read fail");
+ goto rt_reboot;
+ }
+
+ rt_ne_failure_flags = Message[4];
+ rt_ne_los_flag=rt_ne_failure_flags & 0x1;
+
+#ifndef DEMO_ONLY
+ // MIB count start
+ ioctl(fd, IFXMIPS_MIB_LO_ATUC, (u32*)rt_ne_failure_flags);
+ makeCMV(H2D_CMV_READ, PLAM, 1, 0, 1, &temp, Message);
+
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n PLAM 1 0 read fail");
+ goto rt_reboot;
+ }
+
+ ioctl(fd, IFXMIPS_MIB_LO_ATUR, (u32*)Message[4]);
+ //MIB count end
+#endif
+
+ rt_ne_ds_margin = 0;
+ makeCMV(H2D_CMV_READ, PLAM, 46, 0, 1, &rt_ne_ds_margin, Message);
+
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n PLAM 46 0 read fail");
+ goto rt_reboot;
+ }
+
+ rt_ne_ds_margin = (s16)Message[4];
+
+ if(ioctl(fd, SHOWTIME_LOCK_GET, &tmpShowTimeLockEnabled)<0){
+ printf("\n\n ioctl SHOWTIME_LOCK_GET fail!");
+ goto rt_reboot;
+ }
+#if 0 //611101:tc.chen change to ioctl SHOWTIME_LOCK
+ makeCMV(H2D_CMV_READ, TEST, 29, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n TEST 29 0 read fail");
+ goto rt_reboot;
+ }
+ if( Message[4] == 0xffff )
+ tmpShowTimeLockEnabled = 1;
+#endif
+ /* rt_ne_ds_margin is SNR *2 */
+ if((rt_ne_los_flag!=0)|| ( rt_ne_ds_margin<(rt_ne_ds_min_margin * 2))){
+ if(tmpShowTimeLockEnabled == 1) {
+// changed by xu bingtao 09/01/2007
+/*
+ printf("NE_LOS or NE_DS_MARGIN detected but no rebooting because of the showtime lock\n");
+*/
+ printf("NE_LOS or NE_DS_MARGIN detected but no rebooting because of the showtime lock\n");
+ printf(" Minimum Margin: %d/2 dB - Expected Margin: %d dB - LOS : %d\n",rt_ne_ds_margin, rt_ne_ds_min_margin, rt_ne_los_flag);
+// changed by xu bingtao 09/01/2007
+ }
+ else
+ reboot_flag=1;
+ }
+
+ usleep(1500000);
+
+ if(j<3){//wait for several seconds before setting showtime
+ makeCMV(H2D_CMV_READ, STAT, 4, 0, 1, &temp, Message);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n STAT 4 0 read fail");
+ goto rt_reboot;
+ }
+ if((Message[4]&0x2)==0x2){
+ printf("\n\n setting showtime to driver\n\n");
+ system("/etc/rc.d/adsl_up &"); //000001:tc.chen
+ system("echo \"7\" > /tmp/adsl_status");
+ printf("ADSL SHOWTIME!!\n");
+ sleep(1);
+//joelin 04/16/2005
+#ifndef DEMO_ONLY
+ if (!first_power_on){
+
+ makeCMV(H2D_CMV_WRITE,PLAM, 6, 0, 1, &nFECS_L_count, Message);
+ ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message);
+
+ makeCMV(H2D_CMV_WRITE,PLAM, 7, 0, 1, &nES_L_count, Message);
+ ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message);
+
+
+ makeCMV(H2D_CMV_WRITE,PLAM, 8, 0, 1, &nSES_L_count, Message);
+ ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message);
+
+
+ makeCMV(H2D_CMV_WRITE,PLAM, 9, 0, 1, &nLOSS_L_count, Message);
+ ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message);
+ }
+#endif
+ ioctl(fd, IFXMIPS_MEI_SHOWTIME,NULL); //set showtime=1 in driver
+ // 609141:tc.chen :read min margin from CO for Annex B in DMT mode
+ // read adsl link mode
+ read_min_snr_margin(fd, &rt_ne_ds_min_margin);
+ j=1000;
+ }
+ j++;
+ if(j==3){//timeout, set showtimei
+ printf("\n\n timeout, setting showtime to driver\n\n");
+ //system("echo \"7\" > /tmp/adsl_status");
+ printf("ADSL SHOWTIME!!\n");
+ sleep(1);
+ ioctl(fd, IFXMIPS_MEI_SHOWTIME,NULL); //set showtime=1 in driver
+ // 609141:tc.chen :read min margin from CO for Annex B in DMT mode
+ // read adsl link mode
+ read_min_snr_margin( fd, &rt_ne_ds_min_margin);
+ }
+ }
+ }
+rt_reboot:
+
+#ifndef DEMO_ONLY
+ makeCMV(H2D_CMV_READ,PLAM, 6, 0, 1, &temp, Message);
+ ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message);
+ nFECS_L_count=nFECS_L_count+Message[4];
+
+ makeCMV(H2D_CMV_READ,PLAM, 7, 0, 1, &temp, Message);
+ ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message);
+ nES_L_count=nES_L_count+Message[4];
+
+ makeCMV(H2D_CMV_READ,PLAM, 8, 0, 1, &temp, Message);
+ ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message);
+ nSES_L_count=nSES_L_count+Message[4];
+
+ makeCMV(H2D_CMV_READ,PLAM, 9, 0, 1, &temp, Message);
+ ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message);
+ nLOSS_L_count=nLOSS_L_count+Message[4];
+#endif
+
+ /* add by tc chen */
+ system("echo \"0\" > /tmp/adsl_status");
+ printf("\n Rebooting ARC\n");
+reboot_adsl:
+ ioctl(fd, IFXMIPS_MEI_REBOOT,NULL);
+ Download_Firmware(argv[1],fd);
+ if (ioctl(fd, IFXMIPS_MEI_START,NULL)<0){
+ printf("\n\n mei start fail.\n");
+ goto reboot_adsl;
+ }
+ }
+
+#if !defined(KERNEL_SPACE_APPLICATION)
+ close(fd);
+#endif
+ return 0;
+}
diff --git a/package/ifxmips_adsl/src/danube_mei_debug.c b/package/ifxmips_adsl/src/danube_mei_debug.c
new file mode 100644
index 000000000..e3247f66a
--- /dev/null
+++ b/package/ifxmips_adsl/src/danube_mei_debug.c
@@ -0,0 +1,84 @@
+#define _IFXMIPS_ADSL_APP
+#define u32 unsigned int
+#define IFXMIPS_MEI_DEV "/dev/ifxmips/mei"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <asm/ifxmips/ifxmips_mei_app.h>
+#include <asm/ifxmips/ifxmips_mei_ioctl.h>
+#include <asm/ifxmips/ifxmips_mei_app_ioctl.h>
+
+#define SEGMENT_SIZE (64*1024)
+#if 0
+#define u8 unsigned char
+#define u16 unsigned short
+#endif
+
+int main(int argc, char **argv)
+{
+ int fd_image, fd_mei;
+ char *buf;
+ struct stat state;
+ int i,j;
+ char * filename;
+ int size,read_size=SEGMENT_SIZE;
+ u16 temp=0;
+ u16 Message[16]__attribute__ ((aligned(4)));
+ meidebug dbg_data;
+ int rw_flag =0;
+
+ if(argc<4){
+ printf("\nWrong Arguments! Usage: %s r/w address size/value\n",argv[0]);
+ return -1;
+ }
+
+ fd_mei=open(IFXMIPS_MEI_DEV, O_RDWR);
+ if(fd_mei<0)
+ printf("\n open device fail");
+
+ dbg_data.iAddress = strtoul(argv[2],NULL,0);
+ printf("Address = %08X\n",dbg_data.iAddress);
+ if(argv[1][0]=='w')
+ {
+ dbg_data.buffer[0]=strtoul(argv[3],NULL,0);
+
+ dbg_data.iCount = 1;
+ rw_flag = 1;
+ }else
+ {
+ dbg_data.iCount =strtoul(argv[3],NULL,0);
+ }
+ if (rw_flag==1)
+ {
+ if(ioctl(fd_mei, IFXMIPS_MEI_WRITEDEBUG,&dbg_data)!=MEI_SUCCESS){
+ printf("\n IFXMIPS_MEI_WRITEDEBUG() failed");
+ close(fd_mei);
+ return -1;
+ }
+ printf("Writing %08X with data %X!\n",dbg_data.iAddress,dbg_data.buffer[0]);
+ }else
+ {
+ if(ioctl(fd_mei, IFXMIPS_MEI_READDEBUG,&dbg_data)!=MEI_SUCCESS){
+ printf("\n IFXMIPS_MEI_READDEBUG() failed");
+ close(fd_mei);
+ return -1;
+ }
+ printf("Read %08X .\nResult:",dbg_data.iAddress);
+ for (i=0;i<dbg_data.iCount;i++)
+ {
+ printf("%08X ",dbg_data.buffer[i]);
+ if(i%4==3)
+ printf("\n");
+ }
+ printf("\n");
+ }
+ close(fd_mei);
+}
diff --git a/package/ifxmips_adsl/src/danube_show_firmware_date.c b/package/ifxmips_adsl/src/danube_show_firmware_date.c
new file mode 100644
index 000000000..94abc32ae
--- /dev/null
+++ b/package/ifxmips_adsl/src/danube_show_firmware_date.c
@@ -0,0 +1,75 @@
+#define _IFXMIPS_ADSL_APP
+#define u32 unsigned int
+#define IFXMIPS_MEI_DEV "/dev/ifxmips/mei"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <asm/ifxmips/ifxmips_mei_app_ioctl.h>
+#include <asm/ifxmips/ifxmips_mei_app.h>
+#include <asm/ifxmips/ifxmips_mei_ioctl.h>
+
+u16 Message[16]__attribute__ ((aligned(4)));
+
+void makeCMV(u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data);
+void makeCMV(u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data)
+{
+ memset(Message, 0, 16*2);
+ Message[0]= (opcode<<4) + (size&0xf);
+ if(opcode == H2D_DEBUG_WRITE_DM)
+ Message[1]= (group&0x7f);
+ else
+ Message[1]= (((index==0)?0:1)<<7) + (group&0x7f);
+ Message[2]= address;
+ Message[3]= index;
+ if((opcode == H2D_CMV_WRITE)||(opcode == H2D_DEBUG_WRITE_DM))
+ memcpy(Message+4, data, size*2);
+ return;
+}
+
+
+int main(int argc, char **argv)
+{
+ int fd;
+ u16 temp=0;
+ u16 rt_buildcode_lsw=0, rt_buildcode_msw=0;
+ u32 rt_buildcode = 0;
+
+ fd=open(IFXMIPS_MEI_DEV, O_RDWR);
+ if(fd<0){
+ printf("\n\n autoboot open device fail");
+ return -1;
+ }
+
+
+ makeCMV(H2D_CMV_READ, INFO, 55, 0, 1, &temp);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read INFO 55 0 fail");
+ return -1;
+ }
+ rt_buildcode_lsw = Message[4];
+
+ makeCMV(H2D_CMV_READ, INFO, 55, 1, 1, &temp);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("\n\n read INFO 55 1 fail");
+ return -1;
+ }
+ rt_buildcode_msw = Message[4];
+
+ rt_buildcode = rt_buildcode_lsw + (rt_buildcode_msw << 16);
+ printf("date: %d, month: %d, hour: %d, minute: %d\n",
+ (rt_buildcode >> 0) & 0xFF,
+ (rt_buildcode >> 8) & 0xFF,
+ (rt_buildcode >> 16) & 0xFF,
+ (rt_buildcode >> 25) & 0xFF
+ );
+ return 0;
+}
diff --git a/package/ifxmips_adsl/src/model_config.sh b/package/ifxmips_adsl/src/model_config.sh
new file mode 100644
index 000000000..b7dada369
--- /dev/null
+++ b/package/ifxmips_adsl/src/model_config.sh
@@ -0,0 +1,14 @@
+#
+# Automatically generated by make menuconfig: don't edit
+#
+# CONFIG_AMZ is not set
+CONFIG_DNB=y
+IFX_CONFIG_CPU="IFXMIPS"
+IFX_CONFIG_FUTURE_SET="V33WT_SM"
+IFX_CONFIG_MEMORY_SIZE=32
+IFX_CONFIG_FLASH_SIZE=4
+IFX_UBOOT_RAM_TEXT_BASE=0xa0400000
+IFX_HEAD_FLASH_TEXT_BASE=0xb0000000
+IFX_IN_PAD_LEN=25000
+
+#### End of Configuration ####
diff --git a/package/ifxmips_adsl/src/sysconfig.sh b/package/ifxmips_adsl/src/sysconfig.sh
new file mode 100644
index 000000000..34707b332
--- /dev/null
+++ b/package/ifxmips_adsl/src/sysconfig.sh
@@ -0,0 +1,90 @@
+#
+# Automatically generated by make menuconfig: don't edit
+#
+
+#
+# General Setup
+#
+CONFIG_TC_3_3_6=y
+TOOLCHAIN_DIR="/opt/uclibc-toolchain/ifx-lxdb-1-2"
+BUILD_DIR="/mnt/the-noob/build"
+BUILD_VOB="n"
+# COPY_TFTP is not set
+TOPDIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0/"
+KERNEL_SOURCE_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/kernel/opensource/linux-2.4.31/"
+BUILD_ROOTFS_DIR="/mnt/the-noob/build/root_filesystem/"
+UBOOT_SOURCE_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/u-boot/"
+USER_SOURCE_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/"
+USER_IFXSOURCE_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/ifx/"
+USER_OPENSOURCE_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/opensource/"
+IFX_APIS_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/ifx/IFXAPIs/"
+KERNEL_IFX_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/kernel/ifx/"
+BUILD_TOOLS_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//tools/build_tools/"
+KERNEL_CONFIG="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/kernel/opensource/linux-2.4.31//.config"
+TOOLS_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0/tools/build_tools"
+VER_FILE="/mnt/CD1_BSP/software/ReleasePackage/3.3.0/tools/build_tools/versions"
+IFX_HOSTCC="gcc"
+BUILD="i686-pc-linux-gnu"
+HOSTUTILS_PATH="/opt/uclibc-toolchain/ifx-lxdb-1-2/hostutils/bin"
+FAKE_ENV="/mnt/the-noob/build/fakeroot.env"
+DEV_FILE="/mnt/CD1_BSP/software/ReleasePackage/3.3.0/tools/build_tools/device_table.txt"
+
+#
+# Platform Configuration
+#
+# CONFIG_AMZ is not set
+# CONFIG_AMZ_SE is not set
+CONFIG_DNB=y
+CONFIG_G0432V33_BSP=y
+PLATFORM_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0/platforms/Danube"
+MODEL="G0432V33_BSP"
+CONFIG_MIPS=y
+CONFIG_UIMAGE_LZMA=y
+CONFIG_FS_OTHER=y
+PLATFORM_NAME="Danube"
+BSP_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0/platforms/Danube/source/kernel/ifx"
+CONFIG_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//config"
+IFXAPI_SRC_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/ifx/IFXAPIs//src"
+IFXAPI_INC_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/ifx/IFXAPIs//include"
+CONFIG_MGMT_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/ifx//ConfigManagementProcess"
+IFX_HTTPD_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/ifx//ifx_httpd"
+IFX_UTIL_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/ifx//utilities"
+IFX_NFEXT_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/ifx//nfext"
+IFX_ROOTFS_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/rootfs.bsp/"
+ROOTFS_SOURCE_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/rootfs.bsp/flashdisk"
+IFX_CFLAGS="-Os -mips32 -mtune=4kc -I/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/ifx//IFXAPIs/include"
+IFX_LDFLAGS="-L/mnt/the-noob/build/root_filesystem//lib -Wl,-rpath-link,/mnt/the-noob/build/root_filesystem//lib"
+VOIP_SRC_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/ifx/gateway-sip"
+TR69_SRC_DIR="/mnt/CD1_BSP/software/ReleasePackage/3.3.0//source/user/ifx/tr69"
+CONFIG_ENDIAN="mips"
+COMPILER_PREFIX="mips-linux-"
+TOOLCHAIN_PATH="/opt/uclibc-toolchain/ifx-lxdb-1-2/gcc-3.3.6/toolchain-mips/bin"
+COMPILER_PREFIX="mips-linux-"
+LIBPATH="/opt/uclibc-toolchain/ifx-lxdb-1-2/gcc-3.3.6/toolchain-mips/lib"
+CCACHE_PATH="/opt/uclibc-toolchain/ifx-lxdb-1-2/gcc-3.3.6/toolchain-mips/bin-ccache"
+IFX_CC="mips-linux-gcc"
+IFX_AR="mips-linux-ar"
+IFX_AS="mips-linux-as"
+IFX_LD="mips-linux-ld"
+IFX_NM="mips-linux-nm"
+IFX_STRIP="mips-linux-strip"
+IFX_RANLIB="mips-linux-ranlib"
+IFX_CXX="mips-linux-g++"
+IFX_CPP="mips-linux-cpp"
+IFX_OBJCOPY="mips-linux-objcopy"
+IFX_OBJDUMP="mips-linux-objdump"
+TARGET="mips-linux"
+HOST="mips-linux"
+
+#
+# Library Configuration
+#
+# CONFIG_LIB_FEATURE is not set
+RECONFIG=y
+# NEW_DEFAULTS is not set
+# NEW_MODEL is not set
+
+#### End of Configuration ####
+
+. /mnt/CD1_BSP/software/ReleasePackage/3.3.0/tools/build_tools/.gen_funcs
+. /mnt/CD1_BSP/software/ReleasePackage/3.3.0/tools/build_tools/.board_funcs
diff --git a/package/ifxmips_adsl/src/translate.c b/package/ifxmips_adsl/src/translate.c
new file mode 100644
index 000000000..164f4396c
--- /dev/null
+++ b/package/ifxmips_adsl/src/translate.c
@@ -0,0 +1,848 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+//-----------------------------------------------------------------------
+//Description:
+// winhost script translation tool under Linux for Danube
+//-----------------------------------------------------------------------
+//Author: Qi-Ming.Wu@infineon.com
+//Created: 29-October-2004
+//-----------------------------------------------------------------------
+/* History
+ * Last changed on:
+ * Last changed by:
+ *
+*/
+
+#define _IFXMIPS_ADSL_APP
+//#define DEBUG
+#define u32 unsigned int
+#define u16 unsigned short
+#define u8 unsigned char
+#define IFXMIPS_MEI_DEV "/dev/ifxmips/mei"
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <time.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/mman.h>
+
+#include <asm/ifxmips/ifxmips.h>
+#include <asm/ifxmips/ifxmips_mei_app_ioctl.h>
+#include <asm/ifxmips/ifxmips_mei_app.h>
+#include <asm/ifxmips/ifxmips_mei_ioctl.h>
+#include <asm/ifxmips/ifxmips_mei.h>
+
+
+/*============================definitions======================*/
+#define OPTN 5
+#define CNFG 8
+#define CNTL 1
+#define STAT 2
+#define RATE 6
+#define PLAM 7
+#define INFO 3
+#define TEST 4
+
+typedef unsigned short UINT16;
+typedef unsigned long UINT32;
+
+
+
+/*=============================================================*/
+
+
+/*=============================global variables================*/
+int c=0;
+int input_flag=0;
+int digit_optind=0;
+FILE* script_file;
+void (*func)()=NULL;
+int fd;
+
+UINT16 var16[8];
+UINT32 var32[8];
+UINT16 Message[16];
+
+/*=============================================================*/
+
+
+
+
+void display_version()
+{
+ printf("translate version1.0\nby Wu Qi Ming\nQi-Ming.Wu@infineon.com\n");
+ return;
+}
+
+
+void translate_help()
+{
+ printf("Usage:translate [options] [parameter] ...\n");
+ printf("options:\n");
+ printf("-h --help Display help information\n");
+ printf("-v --version Display version information\n");
+ printf("-f --file Specify the script file\n");
+ printf("-e --execute Execute the specified script file\n");
+ //printf("-c --check Check the script file\n");
+ return;
+}
+
+/*
+print the content in buf excluding the command "echo" itself.
+*/
+
+void echo(char* buf)
+{
+ int i;
+ char msg[128];
+ for(i=0;i<128;i++)
+ {
+ if((buf[i]!=0)&&(buf[i]!=32))
+ {
+ sscanf(buf+i,"%s",&msg);
+ if(strcmp(msg,"echo")==0)
+ i+=4;
+ else break;
+ }
+
+ }
+ for(i;i<128;i++)
+ {
+ if(buf[i]!=0&&(buf[i]!=10))
+ {
+ printf("%c",buf[i]);
+ }
+ }
+
+
+ printf("\n");
+ return;
+
+}
+
+static void makeCMV(u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data)
+{
+
+ memset(Message, 0, 16*2);
+ Message[0]= (opcode<<4) + (size&0xf);
+ if(opcode == H2D_DEBUG_WRITE_DM)
+ Message[1]= (group&0x7f);
+ else
+ Message[1]= (((index==0)?0:1)<<7) + (group&0x7f);
+ Message[2]= address;
+ Message[3]= index;
+ if((opcode == H2D_CMV_WRITE)||(opcode == H2D_DEBUG_WRITE_DM))
+ memcpy(Message+4, data, size*2);
+
+ return;
+}
+
+
+
+UINT16 CMV_read(char* str_group,int address,int index)
+{
+ int group=0;
+ if(strcmp(str_group,"optn")==0)
+ group=OPTN;
+ else if(strcmp(str_group,"cnfg")==0)
+ group=CNFG;
+ else if(strcmp(str_group,"cntl")==0)
+ group=CNTL;
+ else if(strcmp(str_group,"stat")==0)
+ group=STAT;
+ else if(strcmp(str_group,"rate")==0)
+ group=RATE;
+ else if(strcmp(str_group,"plam")==0)
+ group=PLAM;
+ else if(strcmp(str_group,"info")==0)
+ group=INFO;
+ else if(strcmp(str_group,"test")==0)
+ group=TEST;
+ else
+ {
+ printf("wrong group type!\ncheck script file please!\n");
+ exit(0);
+ }
+
+#ifndef DEBUG
+ makeCMV(H2D_CMV_READ, group, address, index, 1, NULL);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("cr read %d %d %d fail",group,address,index);
+ exit(0);
+ }
+#endif
+
+ return Message[4];
+
+
+}
+
+
+int CMV_write(char* str_group,int address,int index,UINT16 value)
+{
+ int group=0;
+ if(strcmp(str_group,"optn")==0)
+ group=OPTN;
+ else if(strcmp(str_group,"cnfg")==0)
+ group=CNFG;
+ else if(strcmp(str_group,"cntl")==0)
+ group=CNTL;
+ else if(strcmp(str_group,"stat")==0)
+ group=STAT;
+ else if(strcmp(str_group,"rate")==0)
+ group=RATE;
+ else if(strcmp(str_group,"plam")==0)
+ group=PLAM;
+ else if(strcmp(str_group,"info")==0)
+ group=INFO;
+ else if(strcmp(str_group,"test")==0)
+ group=TEST;
+ else
+ {
+ printf("wrong group type!\ncheck script file please!\n");
+ exit(0);
+ }
+
+#ifndef DEBUG
+ makeCMV(H2D_CMV_WRITE, group, address, index, 1, &value);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("cw %d %d %d fail",group,address,index);
+ return -1;
+ }
+#endif
+
+ return 0;
+
+
+}
+
+void execute_script()
+{
+ char buf[128];
+ char str_command[20]={0};
+ char str_group[20]={0};
+ char str_value[128]={0};
+ char op1[40],op2[40];
+ int address,index;
+ int n=0;
+ UINT16 value=0;
+ if(!script_file) return;
+
+ while(fgets(buf,128,script_file))/*scan one line into buffer, 128 bytes at most*/
+ {
+ if(sscanf(buf,"%s",&str_command)==0) continue;
+ /*if the line is empty, then go on to the next*/
+ if(strcmp(str_command,"cr")==0)/*cr command*/
+ {
+ sscanf(buf,"%s %s %d %d %s",&str_command,\
+ &str_group,\
+ &address,\
+ &index,\
+ &str_value);
+ if(strncmp(str_value,"$",1)!=0)
+ {
+ printf("error:cr parameter type mismatch!\n");
+ break;
+ }
+ n=strtoul(str_value+1,NULL,0);
+ var16[n]=CMV_read(str_group,address,index);
+ printf("read %s %d %d, value=%04x\n",str_group, address, index,var16[n]);
+ }
+ else if(strcmp(str_command,"cw")==0)/*cw command*/
+ {
+ sscanf(buf,"%s %s %d %d %s",&str_command,\
+ &str_group,\
+ &address,\
+ &index,\
+ &str_value);
+ n=strtoul(str_value+1,NULL,0);
+ if(strncmp(str_value,"$",1)==0)
+ {
+ value=var16[n];
+ }
+ else if(strncmp(str_value,"#",1)==0)
+ {
+ value=strtoul(str_value+1,NULL,0);
+ }
+ else
+ {
+ value=strtoul(str_value,NULL,0);
+ }
+ if(CMV_write(str_group,address,index,value)<0)
+ {
+ break;
+ }
+ }
+
+ else if(strcmp(str_command,"mw")==0)/*mr command*/
+ {
+
+ sscanf(buf,"%s %s %s",&str_command,\
+ &op1,\
+ &str_value);
+
+ n=strtoul(str_value+1,NULL,0);
+ address=strtoul(op1,NULL,0);
+ if(strncmp(str_value,"$",1)==0)
+ {
+ value=var16[n];
+ }
+ else if(strncmp(str_value,"#",1)==0)
+ {
+ value=strtoul(str_value+1,NULL,0);
+ }
+ else
+ {
+ value=strtoul(str_value,NULL,0);
+
+ }
+
+ makeCMV(H2D_DEBUG_WRITE_DM, 0x0, address>>16, (address)&(0xffff), 1, &value);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("mw %08x fail",address);
+ break;
+
+ }
+
+ }
+
+ else if(strcmp(str_command,"mr")==0)/*mr command*/
+ {
+
+ sscanf(buf,"%s %s %s",&str_command,\
+ &op1,\
+ &str_value);
+ address=strtoul(op1,NULL,0);
+ n=strtoul(str_value+1,NULL,0);
+ if(strncmp(str_value,"$",1)!=0)
+ {
+ printf("error:mr parameter type mismatch!\n");
+ break;
+ }
+ makeCMV(H2D_DEBUG_READ_DM, 0x0, address>>16, (address)&(0xffff), 1, NULL);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
+ printf("mw %08x fail",address);
+ break;
+ }
+ value=Message[4];
+ var16[n]=value;
+ }
+
+
+
+ else if(strcmp(str_command,"meiw")==0)/*meiw command*/
+ {
+ meireg regrdwr;
+ sscanf(buf,"%s %s %s",&str_command,\
+ &op1,\
+ &op2);
+ regrdwr.iAddress=strtoul(op1,NULL,0)+IFXMIPS_MEI_BASE_ADDR;
+
+
+ if(strncmp(op2,"#",1)==0) regrdwr.iData=strtoul(op1+1,NULL,0);
+ else if(strncmp(op2,"$",1)==0) regrdwr.iData=var16[strtoul(op2+1,NULL,0)];
+ else if(strncmp(op2,"@",1)==0) regrdwr.iData=var32[strtoul(op2+1,NULL,0)];
+ else regrdwr.iData=strtoul(op1,NULL,0);
+ //printf("address=%08x\n", regrdwr.iAddress);
+ if(ioctl(fd, IFXMIPS_MEI_CMV_WRITE, &regrdwr)<0){
+ printf("meiw fail\n");
+ break;;
+ }
+
+ }
+
+ else if(strcmp(str_command,"meir")==0)/*meir command*/
+ {
+ meireg regrdwr;
+ sscanf(buf,"%s %s %s",&str_command,\
+ &op1,\
+ &op2);
+ regrdwr.iAddress=strtoul(op1,NULL,0)+IFXMIPS_MEI_BASE_ADDR;
+ if(ioctl(fd, IFXMIPS_MEI_CMV_READ, &regrdwr)<0){
+ printf("meir fail\n");
+ break;
+ }
+ if(strncmp(op2,"$",1)==0) var16[strtoul(op2+1,NULL,0)]=regrdwr.iData;
+ else if(strncmp(op2,"@",1)==0) var32[strtoul(op2+1,NULL,0)]=regrdwr.iData;
+ else
+ {
+ printf("meir grammar error!\n");
+ break;
+ }
+
+ }
+
+
+ else if(strcmp(str_command,"lst")==0)/*lst command*/
+ {
+
+ sscanf(buf,"%s %s",&str_command,\
+ &str_value);
+
+ if(strncmp(str_value,"$",1)==0)
+ {
+ n=strtoul(str_value+1,NULL,0);
+ printf("$%d=0x%04x\n",n,var16[n]);
+
+ }
+ else if(strncmp(str_value,"@",1)==0)
+ {
+ n=strtoul(str_value+1,NULL,0);
+ printf("$%d=0x%08x\n",n,var32[n]);
+
+ }
+ else
+ {
+ printf("lst grammar error!\n");
+ break;
+ }
+ }
+
+ else if(strcmp(str_command,"echo")==0)/*echo command*/
+ {
+ echo(buf);
+ }
+ else if(strcmp(str_command,"mov")==0)/*mov command*/
+ {
+ sscanf(buf,"%s %s %s",&str_command,\
+ &op1,\
+ &op2);
+ if(strncmp(op1,"$",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]=strtoul(op2+1,NULL,0);
+ }
+ else
+ {
+ var16[strtoul(op1+1,NULL,0)]=strtoul(op2,NULL,0);
+
+ }
+ }
+ else if(strncmp(op1,"@",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]=strtoul(op2+1,NULL,0);
+ }
+ }
+ else
+ {
+ printf("grammar error!\n");
+ break;
+ }
+
+
+ }
+
+
+ else if(strcmp(str_command,"or")==0)/*or command*/
+ {
+ sscanf(buf,"%s %s %s",&str_command,\
+ &op1,\
+ &op2);
+ if(strncmp(op1,"$",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]|=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]|= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]|=strtoul(op2+1,NULL,0);
+ }
+ }
+ else if(strncmp(op1,"@",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]|=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]|= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]|=strtoul(op2+1,NULL,0);
+ }
+ }
+ else
+ {
+ printf("grammar error!\n");
+ break;
+ }
+ }
+
+ else if(strcmp(str_command,"and")==0)/*and command*/
+ {
+ sscanf(buf,"%s %s %s",&str_command,\
+ &op1,\
+ &op2);
+ if(strncmp(op1,"$",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]&=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]&= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]&=strtoul(op2+1,NULL,0);
+ }
+ }
+ else if(strncmp(op1,"@",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]&=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]&= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]&=strtoul(op2+1,NULL,0);
+ }
+ }
+ else
+ {
+ printf("grammar error!\n");
+ break;
+ }
+ }
+ else if(strcmp(str_command,"not")==0)/*not command*/
+ {
+ sscanf(buf,"%s %s",&str_command,\
+ &op1);
+ if(strncmp(op1,"$",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]=~var16[strtoul(op1+1,NULL,0)];
+ }
+ else if(strncmp(op1,"@",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]=~var32[strtoul(op1+1,NULL,0)];
+ }
+ else
+ {
+ printf("grammar error!\n");
+ break;
+ }
+ }
+ else if(strcmp(str_command,"shl")==0)/*shl command*/
+ {
+ sscanf(buf,"%s %s %s",&str_command,\
+ &op1,\
+ &op2);
+ if(strncmp(op1,"$",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]<<=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]<<= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]<<=strtoul(op2+1,NULL,0);
+ }
+ }
+ else if(strncmp(op1,"@",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]<<=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]<<= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]<<=strtoul(op2+1,NULL,0);
+ }
+ }
+ else
+ {
+ printf("grammar error!\n");
+ break;
+ }
+ }
+
+ else if(strcmp(str_command,"shr")==0)/*shr command*/
+ {
+ sscanf(buf,"%s %s %s",&str_command,\
+ &op1,\
+ &op2);
+ if(strncmp(op1,"$",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]>>=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]>>= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]>>=strtoul(op2+1,NULL,0);
+ }
+ }
+ else if(strncmp(op1,"@",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]>>=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]>>= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]>>=strtoul(op2+1,NULL,0);
+ }
+ }
+ else
+ {
+ printf("grammar error!\n");
+ break;
+ }
+ }
+
+ else if(strcmp(str_command,"add")==0)/*add command*/
+ {
+ sscanf(buf,"%s %s %s",&str_command,\
+ &op1,\
+ &op2);
+ if(strncmp(op1,"$",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]+=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]+= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]+=strtoul(op2+1,NULL,0);
+ }
+ }
+ else if(strncmp(op1,"@",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]+=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]+= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]+=strtoul(op2+1,NULL,0);
+ }
+ }
+ else
+ {
+ printf("grammar error!\n");
+ break;
+ }
+ }
+ else if(strcmp(str_command,"sub")==0)/*sub command*/
+ {
+ sscanf(buf,"%s %s %s",&str_command,\
+ &op1,\
+ &op2);
+ if(strncmp(op1,"$",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]-=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]-= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var16[strtoul(op1+1,NULL,0)]-=strtoul(op2+1,NULL,0);
+ }
+ }
+ else if(strncmp(op1,"@",1)==0)
+ {
+ if(strncmp(op2,"$",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]-=var16[strtoul(op2+1,NULL,0)];
+ }
+ else if(strncmp(op2,"@",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]-= var32[strtoul(op2+1,NULL,0)];
+
+ }
+ else if(strncmp(op2,"#",1)==0)
+ {
+ var32[strtoul(op1+1,NULL,0)]-=strtoul(op2+1,NULL,0);
+ }
+ }
+ else
+ {
+ printf("grammar error!\n");
+ break;
+ }
+ }
+
+ memset(str_command,0,20);
+ memset(buf,0,128);
+ }
+ return;
+}
+
+int main (int argc, char** argv) {
+
+#ifndef DEBUG
+ fd=open(IFXMIPS_MEI_DEV, O_RDWR);
+ if(fd<0){
+ printf("\n\n autoboot open device fail\n");
+ return -1;
+ }
+#endif
+ while(1) {
+ int option_index=0;
+ static struct option long_options[] ={
+ {"help",0,0,0},
+ {"version",0,0,0},
+ {"file",1,0,0},
+ {"execute",0,0,0}
+ };
+
+ c = getopt_long(argc,argv, "hvf:e",
+ long_options, &option_index);
+
+ //printf("c=%d option_index=%d\n",c,option_index);
+ if(c==-1)
+ {
+ if(input_flag==0)
+ {
+ printf("translate:please specify parameters\n");
+ func=&translate_help;
+ }
+ if(func)
+ (*func)();
+ else
+ {
+ERROR: translate_help();
+ }
+ break;
+ }
+ input_flag=1;
+ switch (c) {
+ case 0:
+ if(option_index==0)
+ {
+ func=&translate_help;
+ break;
+ }
+ if(option_index==1)
+ {
+ func=&display_version;
+ break;
+ }
+ if(option_index==2)
+ {
+ goto FILE;
+ break;
+ }
+ if(option_index==3)
+ {
+ goto EXECUTE;
+ break;
+ }
+ case 'h':
+ func=&translate_help;
+ break;
+ case 'v':
+ func=&display_version;
+ break;
+ case 'f':
+FILE: if(!optarg) goto ERROR;
+ script_file=fopen((char*)optarg,"r");
+ if(!script_file) perror("fopen");
+ break;
+ case 'e':
+EXECUTE: func=&execute_script;
+ break;
+ }
+
+
+ }
+ if(script_file) fclose(script_file);
+#ifndef DEBUG
+ close(fd);
+#endif
+}
+
+
+