www.pudn.com > S3c2410bsp.zip > bootConfig.c


/* bootConfig.c - system configuration module for boot ROMs */

/* Copyright 2004-2005  */


#include "vxWorks.h"
#include "bootEcoffLib.h"
#include "bootElfLib.h"
#include "bootLib.h"
#include "bootLoadLib.h"
#include "bsdSockLib.h"
#include "cacheLib.h"
#include "cbioLib.h"
#include "ctype.h"
#include "dosFsLib.h"
#include "dpartCbio.h"
#include "errno.h"
#include "errnoLib.h"
#include "fcntl.h"
#include "fioLib.h"
#include "ftpLib.h"
#include "hostLib.h"
#include "icmpLib.h"
#include "ifLib.h"
#include "if_sl.h"
#include "inetLib.h"
#include "intLib.h"
#include "ioLib.h"
#include "iosLib.h"
#include "loadAoutLib.h"
#include "loadCoffLib.h"
#include "loadLib.h"
#include "logLib.h"
#include "memLib.h"
#include "msgQLib.h"
#include "netLib.h"
#include "pipeDrv.h"
#include "proxyLib.h"
#include "qLib.h"
#include "qPriBMapLib.h"
#include "rebootLib.h"
#include "remLib.h"
#include "rngLib.h"
#include "routeLib.h"
#include "semLib.h"
#include "sockLib.h"
#include "stdio.h"
#include "string.h"
#include "sysLib.h"
#include "sysSymTbl.h"
#include "taskHookLib.h"
#include "taskLib.h"
#include "tftpLib.h"
#include "tickLib.h"
#include "trcLib.h"
#include "unistd.h"
#include "usrFdiskPartLib.h"
#include "version.h"
#include "wdLib.h"
#include "net/if.h"
#include "net/mbuf.h"
#include "netinet/if_ether.h"
#include "drv/netif/smNetLib.h"
#include "ipProto.h"
#include "private/excLibP.h"
#include "private/kernelLibP.h"
#include "private/workQLibP.h"
#include "config.h"
#include "scsiLib.h"
#include "..\bsps3c2410x\s3c2410xSio.h"


struct ipparamsinfo
{ char ipadrinfo[50];
	char netmaskinfo[50];
	char gatewayinfo[50];
	ULONG netmaskshowinfo;
	UCHAR macshowinfo[6];
	int dhcpflag;
  int bootpflag;
};
struct ipparamsinfo IP_PARAMS;

#ifdef INCLUDE_BOOTP
#include "bootpLib.h"
#endif 

#ifdef	INCLUDE_PPP
#include "pppLib.h"
#endif	
#ifdef INCLUDE_DHCPC
#include "dhcpcLib.h"
#include "dhcpcBootLib.h"
#include "dhcp/dhcpc.h"
#include "dhcp/dhcpcCommonLib.h"
#endif

#if (defined(INCLUDE_SECOND_SMNET)   || \
     defined(INCLUDE_SM_NET_ADDRGET) || \
     defined(INCLUDE_SM_SEQ_ADDR))
# ifndef   INCLUDE_SM_NET
#  define  INCLUDE_SM_NET
# endif 
#endif 

#if (defined(INCLUDE_SECOND_SMNET) && !defined(INCLUDE_SM_NET_ADDRGET))
#  define INCLUDE_SM_NET_ADDRGET
#endif 

#ifdef  INCLUDE_SM_NET
# ifndef   INCLUDE_BSD
#  define  INCLUDE_BSD
# endif /* INCLUDE_BSD */
# ifndef   INCLUDE_SM_COMMON
#  define  INCLUDE_SM_COMMON
# endif /* INCLUDE_SM_COMMON */
#endif /* INCLUDE_SM_NET */


/* defines */

#define STREQ(A, B) (strcmp(A, B) == 0 ? 1 : 0)
#define TIMEOUT		7	


#define MAX_LINE        160	

#define BOOT_CMD_MAX_LINE        BOOT_LINE_SIZE

#define RSHD		514	
#define DEC		FALSE	
#define HEX		TRUE
#define OPT		TRUE
#define MAX_ADR_SIZE 	6 
#define DOS_ID_OFFSET                   3
#define FIRST_PARTITION_SECTOR_OFFSET   (0x1be + 8)
#define VXDOS                           "VXDOS"
#define VXEXT                           "VXEXT"


#ifndef    NUM_PARTITIONS_DISK_BOOT
#   define NUM_PARTITIONS_DISK_BOOT    1 
#endif  

#ifndef    PARTITION_DISK_BOOT
#   define PARTITION_DISK_BOOT         1 
#endif  /* PARTITION_DISK_BOOT */


void		usrInit ();
IMPORT void 	sysInitAlt ();
extern int      random ();

extern unsigned char SST39VF160_ChipProg(unsigned long ulRomAddr,unsigned long ulRamAddr,unsigned long ulRomSize);
extern STATUS sysRomGet (char *string,    int   strLen,     int   offset        );
#if	(CPU_FAMILY==MIPS)
IMPORT void 	sysGpInit ();
#endif	

#ifdef  INCLUDE_NETWORK
#ifdef ETHERNET_ADR_SET
void		mEnet (char *);
void 		sysEnetAddrGet ();
void 		sysEnetAddrSet ();
#endif  
#endif  

#ifdef INCLUDE_END
LOCAL void* findCookie(int unitNo, char* devName);
#endif /* INCLUDE_END */

void compressedEntry 
    (
    int startType
    )
    {

#if (CPU_FAMILY==MIPS)
    WRS_ASM (".extern _gp; la $gp,_gp");
#endif

#if	(CPU_FAMILY==I960)
    sysInitAlt (startType);		
#else
    usrInit (startType);		
#endif
    }

#ifdef INCLUDE_END
#include "end.h"
#include "muxLib.h"
#include "muxTkLib.h"
#include "configNet.h"
#include "m2Lib.h"

IMPORT int 	ipAttach ();
IMPORT END_TBL_ENTRY endDevTbl[];

typedef struct cookie_tbl
    {
    int unitNo;
    char devName[END_NAME_MAX];
    void* pCookie;
    }COOKIE_TBL;

COOKIE_TBL cookieTbl[32];


#ifndef MUX_MAX_BINDS
#define MUX_MAX_BINDS 8
#endif

void*   pCookie;
M2_INTERFACETBL endM2Tbl;
#endif 	/* INCLUDE_END */

#ifndef IP_MAX_UNITS 
#define IP_MAX_UNITS 1
#endif

IP_DRV_CTRL ipDrvCtrl [IP_MAX_UNITS];
int ipMaxUnits = IP_MAX_UNITS;


#undef	INCLUDE_SHOW_ROUTINES		
#undef	INCLUDE_SM_NET_SHOW

#include "usrKernel.c"			



IMPORT char	edata [];		
IMPORT char	end [];			

#define FREE_MEM_START_ADRS FREE_RAM_ADRS

#ifdef  INCLUDE_INITIAL_MEM_ALLOCATION
#define MEM_POOL_START_ADRS \
	    (ROUND_UP(FREE_MEM_START_ADRS, (INITIAL_MEM_ALIGNMENT)) + \
	    (INITIAL_MEM_SIZE))
#else   
#define MEM_POOL_START_ADRS FREE_MEM_START_ADRS
#endif  



#ifdef  INCLUDE_TSFS_BOOT		

#if ((WDB_COMM_TYPE == WDB_COMM_SERIAL) && \
	(CONSOLE_TTY == NONE || CONSOLE_TTY == WDB_TTY_CHANNEL))
#define INCLUDE_TSFS_BOOT_VIO_CONSOLE	
#endif

#define INCLUDE_WDB			
#define INCLUDE_WDB_TSFS		

#undef  INCLUDE_WDB_BANNER		
#undef 	INCLUDE_WDB_TTY_TEST		
#undef  INCLUDE_WDB_START_NOTIFY	
#undef  INCLUDE_WDB_USER_EVENT		
#undef  INCLUDE_WDB_CTXT		
#undef  INCLUDE_WDB_FUNC_CALL		
#undef  INCLUDE_WDB_GOPHER		
#undef  INCLUDE_WDB_EXIT_NOTIFY		
#undef  INCLUDE_WDB_REG			
#undef  INCLUDE_WDB_EVENTPOINTS		
#undef  INCLUDE_WDB_MEM			
#undef  INCLUDE_WDB_BP			
#include "wdb/wdbEvtLib.h"
#include "usrWdb.c"    			

#else	
#undef INCLUDE_WDB
#endif  /* INCLUDE_TSFS_BOOT */

#ifdef  INCLUDE_NETWORK

/* forward declarations */
LOCAL STATUS usrNetProtoInit (void);

IMPORT int	lnEbsaattach ();
IMPORT int	oliattach ();
IMPORT int	dcattach ();
IMPORT int	eglattach ();
IMPORT int	eiattach ();
IMPORT int	feiattach ();
IMPORT int	exattach ();
IMPORT int	enpattach ();
IMPORT int	ieattach ();
IMPORT int	ilacattach ();
IMPORT int	lnattach ();
IMPORT int	lnsgiattach ();
IMPORT int	nicattach ();
IMPORT int	nicEvbattach ();
IMPORT int	medattach ();
IMPORT int      elcattach ();
IMPORT int      ultraattach ();
IMPORT int      eexattach ();
IMPORT int      eltattach ();
IMPORT int      eneattach ();
IMPORT int      esmcattach ();
IMPORT int	quattach ();
IMPORT int	loattach ();
IMPORT int	snattach ();
IMPORT int	fnattach ();
IMPORT STATUS	slipInit ();
IMPORT int	ifreset ();
IMPORT void	if_dettach ();
IMPORT u_long	in_netof ();
IMPORT struct ifnet *	ifunit ();
IMPORT int	pcmciaattach ();
IMPORT int	netLibInitialized;

#ifdef  NETIF_USR_DECL
    NETIF_USR_DECL 		/* additional declarations, from BSP */
#endif

#ifdef	INCLUDE_IF_USR
IMPORT int IF_USR_ATTACH ();
#endif	/* INCLUDE_IF_USR */

LOCAL NETIF netIf [] =
    {
#ifdef  NETIF_USR_ENTRIES
    NETIF_USR_ENTRIES		/* additional entries, from BSP */
#endif

#ifdef	INCLUDE_IF_USR
        { IF_USR_NAME, IF_USR_ATTACH, IF_USR_ARG1, IF_USR_ARG2, IF_USR_ARG3,
          IF_USR_ARG4, IF_USR_ARG5, IF_USR_ARG6, IF_USR_ARG7, IF_USR_ARG8 },
#endif	/* INCLUDE_IF_USR */
#ifdef  INCLUDE_LNEBSA
	{ "lnEbsa", lnEbsaattach, (char*)IO_ADRS_LNEBSA, INT_VEC_LNEBSA,
	  INT_LVL_LNEBSA, LNEBSA_POOL_ADRS, LNEBSA_POOL_SIZE,
	  LNEBSA_DATA_WIDTH, LNEBSA_MODE, LNEBSA_DMA_CHAN },
#endif  /* INCLUDE_LNEBSA */
#ifdef  INCLUDE_OLI
	{ "oli", oliattach, (char*)IO_ADRS_NISA_BASE,
	  IO_ADRS_NISA_PCMCIA, IO_ADRS_NISA_PCMEM,
	  INT_VEC_PCMCIA_A, INT_LVL_PCMCIA_A,
	  INT_VEC_PCMCIA_B, INT_LVL_PCMCIA_B },
#endif
#ifdef	INCLUDE_DC
	{ "dc", dcattach, (char*)IO_ADRS_DC, INT_VEC_DC, INT_LVL_DC,
	  DC_POOL_ADRS, DC_POOL_SIZE, DC_DATA_WIDTH, DC_RAM_PCI_ADRS,
	  DC_MODE },
#endif	/* INCLUDE_DC */
#ifdef	INCLUDE_EGL
	{ "egl", eglattach, (char*)IO_ADRS_EGL, INT_VEC_EGL, INT_LVL_EGL },
#endif	/* INCLUDE_EGL */
#ifdef	INCLUDE_EI
        { "ei", eiattach, (char*)INT_VEC_EI, EI_SYSBUS, EI_POOL_ADRS, 0, 0},
#endif	/* INCLUDE_EI */
#ifdef	INCLUDE_FEI
        { "fei", feiattach, (char*)FEI_POOL_ADRS, 0, 0, 0, 0},
#endif	/* INCLUDE_FEI */
#ifdef  INCLUDE_EX
        { "ex", exattach, (char*)IO_ADRS_EX, INT_VEC_EX, INT_LVL_EX,
	  IO_AM_EX_MASTER, IO_AM_EX },
#endif	/* INCLUDE_EX */
#ifdef  INCLUDE_ENP
        { "enp", enpattach, (char*)IO_ADRS_ENP, INT_VEC_ENP, INT_LVL_ENP,
	  IO_AM_ENP },
#endif	/* INCLUDE_ENP */
#ifdef  INCLUDE_IE
        { "ie", ieattach, (char*)IO_ADRS_IE, INT_VEC_IE, INT_LVL_IE },
#endif	/* INCLUDE_IE */
#ifdef	INCLUDE_ILAC
	{ "ilac", ilacattach, (char*)IO_ADRS_ILAC, INT_VEC_ILAC},
#endif	/* INCLUDE_ILAC */
#ifdef  INCLUDE_LN
        { "ln", lnattach, (char*)IO_ADRS_LN, INT_VEC_LN, INT_LVL_LN,
          LN_POOL_ADRS, LN_POOL_SIZE, LN_DATA_WIDTH, LN_PADDING,
	  LN_RING_BUF_SIZE },
#endif	/* INCLUDE_LN */
#ifdef  INCLUDE_LNSGI
        { "lnsgi", lnsgiattach, (char*)IO_ADRS_LNSGI, INT_VEC_LNSGI,
          INT_LVL_LNSGI, LNSGI_POOL_ADRS, LNSGI_POOL_SIZE, LNSGI_DATA_WIDTH,
          LNSGI_PADDING, LNSGI_RING_BUF_SIZE },
#endif  /* INCLUDE_LNSGI */
#ifdef  INCLUDE_NIC
        { "nic", nicattach, (char*)IO_ADRS_NIC, INT_VEC_NIC, INT_LVL_NIC },
#endif	/* INCLUDE_NIC */
#ifdef  INCLUDE_NIC_EVB
        { "nicEvb", nicEvbattach, (char*)IO_ADRS_NIC,INT_VEC_NIC,INT_LVL_NIC },
#endif	/* INCLUDE_NIC_EVB */
#ifdef  INCLUDE_MED
        { "med", medattach, (char*)IO_ADRS_DBETH, INT_VEC_DBETH, INT_LVL_DBETH},
#endif	/* INCLUDE_MED */
#ifdef  INCLUDE_ELC
	{ "elc", elcattach, (char*)IO_ADRS_ELC, INT_VEC_ELC, INT_LVL_ELC,
	  MEM_ADRS_ELC, MEM_SIZE_ELC, CONFIG_ELC},
#endif  /* INCLUDE_ELC */
#ifdef  INCLUDE_ULTRA
	{ "ultra", ultraattach, (char*)IO_ADRS_ULTRA, INT_VEC_ULTRA,
	  INT_LVL_ULTRA, MEM_ADRS_ULTRA, MEM_SIZE_ULTRA, CONFIG_ULTRA},
#endif  /* INCLUDE_ULTRA */
#ifdef  INCLUDE_EEX
	{ "eex", eexattach, (char*)IO_ADRS_EEX, INT_VEC_EEX, INT_LVL_EEX,
	  NTFDS_EEX, CONFIG_EEX},
#endif  /* INCLUDE_EEX */
#ifdef  INCLUDE_ELT
	{ "elt", eltattach, (char*)IO_ADRS_ELT, INT_VEC_ELT, INT_LVL_ELT,
	  NRF_ELT, CONFIG_ELT},
#endif  /* INCLUDE_ELT */
#ifdef  INCLUDE_ENE
	{ "ene", eneattach, (char*)IO_ADRS_ENE, INT_VEC_ENE, INT_LVL_ENE},
#endif  /* INCLUDE_ELT */
#ifdef  INCLUDE_ESMC
	{ "esmc", esmcattach, (char*)IO_ADRS_ESMC, INT_VEC_ESMC, INT_LVL_ESMC,
	  CONFIG_ESMC, RX_MODE_ESMC},
#endif  /* INCLUDE_ESMC */
#ifdef  INCLUDE_QU
	{ "qu", quattach, (char*)IO_ADRS_QU_EN, INT_VEC_QU_EN, QU_EN_SCC,
          QU_EN_TX_BD, QU_EN_RX_BD, QU_EN_TX_OFF, QU_EN_RX_OFF, QU_EN_MEM},
#endif  /* INCLUDE_QU */
#ifdef  INCLUDE_SN
        { "sn", snattach, (char*)IO_ADRS_SN, INT_VEC_SN },
#endif	/* INCLUDE_SN */
#ifdef  INCLUDE_FN
        { "fn", fnattach },
#endif  /* INCLUDE_FN */

#ifdef  INCLUDE_SM_NET
        { "sm", smNetAttach2, 0, 0, 0, 0, 0, 0, 0, 0 },
#endif  /* INCLUDE_SM_NET */

#ifdef	INCLUDE_PCMCIA
	{ "pcmcia", pcmciaattach, 0, 0, 0, 0, 0, 0 },
#endif	/* INCLUDE_PCMCIA */

#ifdef  INCLUDE_PPP
	{"ppp", 0, 0, 0, 0, 0},
#endif  /* INCLUDE_PPP */
#ifdef  INCLUDE_SLIP
	{ "sl", 0, 0, 0, 0, 0 },
#endif	/* INCLUDE_SLIP */
	{ "lo", loattach, 0, 0, 0, 0 },
        { 0, 0, 0, 0, 0, 0 },
    };

#endif  /* INCLUDE_NETWORK */


SYMTAB_ID	sysSymTbl;
int		consoleFd;		
char		consoleName [20];	
int		sysStartType;		

BOOL		scsiInitialized      = FALSE;
int		bootCmdTaskPriority  = 1;
int		bootCmdTaskOptions   = VX_SUPERVISOR_MODE;
int		bootCmdTaskStackSize = BOOT_CMD_STACK_SIZE;


#define TRAP_VALUE_1	0x12348765
#define TRAP_VALUE_2	0x5a5ac3c3
LOCAL volatile UINT32	trapValue1	= TRAP_VALUE_1;
LOCAL volatile UINT32	trapValue2	= TRAP_VALUE_2;

#ifdef  INCLUDE_NETWORK


#ifdef INCLUDE_TCP
TCP_CFG_PARAMS tcpCfgParams =  
    {
    TCP_FLAGS_DFLT,            
    TCP_SND_SIZE_DFLT,          
    TCP_RCV_SIZE_DFLT,          
    TCP_CON_TIMEO_DFLT,        
    TCP_REXMT_THLD_DFLT,        
    TCP_MSS_DFLT,               
    TCP_RND_TRIP_DFLT,          
    TCP_IDLE_TIMEO_DFLT,       
    TCP_MAX_PROBE_DFLT,         
    };
#endif 

#ifdef INCLUDE_UDP
UDP_CFG_PARAMS udpCfgParams =   
    {
    UDP_FLAGS_DFLT,
    UDP_SND_SIZE_DFLT,          
    UDP_RCV_SIZE_DFLT           
    };
#endif 

#ifdef INCLUDE_ICMP
ICMP_CFG_PARAMS icmpCfgParams = 
    {
    ICMP_FLAGS_DFLT             
    };
#endif 

IP_CFG_PARAMS ipCfgParams =    
    {
    IP_FLAGS_DFLT,             
    IP_TTL_DFLT,               
    IP_QLEN_DFLT,             
    IP_FRAG_TTL_DFLT           
    };

M_CL_CONFIG mClBlkConfig =
    {
    NUM_NET_MBLKS_MIN, 	NUM_CL_BLKS_MIN,	NULL, 		0
    };

CL_DESC clDescTbl [] =
    {
    {64,            NUM_64_MIN,		NULL,           0},
    {128,           NUM_128_MIN,        NULL,           0},
    {256,           NUM_256_MIN,        NULL,           0},
    {512,           NUM_512_MIN,        NULL,           0},
    {1024,          NUM_1024_MIN,       NULL,           0},
    };
int clDescTblNumEnt = (NELEMENTS(clDescTbl));

M_CL_CONFIG sysMclBlkConfig = 
    {
    NUM_SYS_MBLKS_MIN, 	NUM_SYS_CL_BLKS_MIN,	NULL, 		0
    };

CL_DESC sysClDescTbl [] = 		
    {
    {64,		NUM_SYS_64_MIN,		NULL,		0},
    {128,		NUM_SYS_128_MIN,	NULL,		0},
    {256,		NUM_SYS_256_MIN,	NULL,		0},
    {512,		NUM_SYS_512_MIN,	NULL,		0},
    }; 
int sysClDescTblNumEnt = (NELEMENTS(sysClDescTbl));

#ifdef  INCLUDE_PPP

#ifndef PPP_OPTIONS_FLAGS
#define PPP_OPTIONS_FLAGS ((PPP_OPT_NO_ALL << PPP_S_NO_ALL)  | \
    (PPP_OPT_PASSIVE_MODE << PPP_S_PASSIVE_MODE)             | \
    (PPP_OPT_SILENT_MODE << PPP_S_SILENT_MODE)               | \
    (PPP_OPT_DEFAULTROUTE << PPP_S_DEFAULTROUTE)             | \
    (PPP_OPT_PROXYARP << PPP_S_PROXYARP)                     | \
    (PPP_OPT_IPCP_ACCEPT_LOCAL << PPP_S_IPCP_ACCEPT_LOCAL)   | \
    (PPP_OPT_IPCP_ACCEPT_REMOTE << PPP_S_IPCP_ACCEPT_REMOTE) | \
    (PPP_OPT_NO_IP << PPP_S_NO_IP)                           | \
    (PPP_OPT_NO_ACC << PPP_S_NO_ACC)                         | \
    (PPP_OPT_NO_PC << PPP_S_NO_PC)                           | \
    (PPP_OPT_NO_VJ << PPP_S_NO_VJ)                           | \
    (PPP_OPT_NO_VJCCOMP << PPP_S_NO_VJCCOMP)                 | \
    (PPP_OPT_NO_ASYNCMAP << PPP_S_NO_ASYNCMAP)               | \
    (PPP_OPT_NO_MN << PPP_S_NO_MN)                           | \
    (PPP_OPT_NO_MRU << PPP_S_NO_MRU)                         | \
    (PPP_OPT_NO_PAP << PPP_S_NO_PAP)                         | \
    (PPP_OPT_NO_CHAP << PPP_S_NO_CHAP)                       | \
    (PPP_OPT_REQUIRE_PAP << PPP_S_REQUIRE_PAP)               | \
    (PPP_OPT_REQUIRE_CHAP << PPP_S_REQUIRE_CHAP)             | \
    (PPP_OPT_LOGIN << PPP_S_LOGIN)                           | \
    (PPP_OPT_DEBUG << PPP_S_DEBUG)                           | \
    (PPP_OPT_DRIVER_DEBUG << PPP_S_DRIVER_DEBUG))
#endif  /* PPP_OPTIONS_FLAGS */
 
PPP_OPTIONS pppOptions =
    {
    PPP_OPTIONS_FLAGS,		
    PPP_STR_ASYNCMAP,		
    PPP_STR_ESCAPE_CHARS,	
    PPP_STR_VJ_MAX_SLOTS,	
    PPP_STR_NETMASK,		
    PPP_STR_MRU,		
    PPP_STR_MTU,		
    PPP_STR_LCP_ECHO_FAILURE,	
    PPP_STR_LCP_ECHO_INTERVAL,
    PPP_STR_LCP_RESTART,	
    PPP_STR_LCP_MAX_TERMINATE,	
    PPP_STR_LCP_MAX_CONFIGURE,	
    PPP_STR_LCP_MAX_FAILURE,	
    PPP_STR_IPCP_RESTART,	
    PPP_STR_IPCP_MAX_TERMINATE,
    PPP_STR_IPCP_MAX_CONFIGURE,	
    PPP_STR_IPCP_MAX_FAILURE,	
    PPP_STR_LOCAL_AUTH_NAME,	
    PPP_STR_REMOTE_AUTH_NAME,	
    PPP_STR_PAP_FILE,		
    PPP_STR_PAP_USER_NAME,	
    PPP_STR_PAP_PASSWD,		
    PPP_STR_PAP_RESTART,	
    PPP_STR_PAP_MAX_AUTHREQ,	
    PPP_STR_CHAP_FILE,		
    PPP_STR_CHAP_RESTART,	
    PPP_STR_CHAP_INTERVAL,	
    PPP_STR_CHAP_MAX_CHALLENGE	
    };
 
#endif  /* INCLUDE_PPP */

#endif  /* INCLUDE_NETWORK */


#ifdef __STDC__

void 		usrRoot (char *pMemPoolStart, unsigned memPoolSize);
void 		usrClock (void);
void		usrKernelInit (void);
LOCAL void	bootCmdLoop (void);
LOCAL char	autoboot (int timeout);
LOCAL void	printBootLogo (void);
LOCAL void	bootHelp (void);
LOCAL STATUS	bootLoad (char *bootString, FUNCPTR *pEntry);
LOCAL void	go (FUNCPTR entry);
LOCAL void	m (char *adrs);
LOCAL void	d (char *adrs, int nwords);
LOCAL void	bootExcHandler (int tid);
LOCAL void	skipSpace (char **strptr);
LOCAL void	printExcMsg (char *string);
LOCAL STATUS	getArg (char **ppString, int *pValue, BOOL defaultHex,
			BOOL optional);
LOCAL void	usrBootLineInit (int startType);
LOCAL STATUS	usrBootLineCrack (char *bootString, BOOT_PARAMS *pParams);

#ifdef  INCLUDE_NETWORK
LOCAL STATUS	netLoad (char *hostName, char *fileName, char *usr, 
			 char *passwd, FUNCPTR *pEntry);
LOCAL void	netifAdrsPrint (char *ifname);
LOCAL STATUS	checkInetAddrField (char *pInetAddr, BOOL subnetMaskOK);
LOCAL STATUS	usrNetIfAttach (char *devName, int unitNum, char *inetAdrs);
LOCAL STATUS	usrNetIfConfig (char *devName, int unitNum, char *inetAdrs, 
                                char *inetName, int netmask);
LOCAL STATUS	usrBpInit (char *devName, int unitNum, u_long startAddr);
LOCAL STATUS	usrSlipInit (char *pBootDev, int unitNum, char *localAddr, 
			     char *peerAddr);
LOCAL STATUS    usrPPPInit (char *pBootDev, int unitNum, char *localAddr, 
                            char *peerAddr);
#ifdef INCLUDE_BOOTP
LOCAL STATUS	bootpGet (char *pNetDev, char *pBootDevAddr, char *pBootFile,
			  char *pHostAddr, int *pMask);
#endif

#ifdef INCLUDE_DHCPC
LOCAL STATUS 	dhcpGet (char *pNetDev, char *pBootDevAddr, char *pBootFile,
                         char *pHostAddr, int  *pMask,char *pGateway,
                         DHCP_LEASE_DATA *pDhcpLease);
#endif

#endif  /* INCLUDE_NETWORK */

#ifdef	INCLUDE_SCSI_BOOT
LOCAL STATUS	scsiLoad (int bootDevId, int bootDevLUN, char *fileName,
		          FUNCPTR *pEntry);
#endif	/* INCLUDE_SCSI_BOOT */

#ifdef  INCLUDE_FD
LOCAL STATUS    fdLoad (int drive, int type, char *fileName, FUNCPTR *pEntry);
#endif  /* INCLUDE_FD */

#ifdef  INCLUDE_IDE
LOCAL STATUS    ideLoad (int drive, int type, char *fileName, FUNCPTR *pEntry);
#endif  /* INCLUDE_IDE */

#ifdef	INCLUDE_ATA
LOCAL STATUS	ataLoad (int ctrl, int drive, char *fileName, FUNCPTR *pEntry);
#endif	/* INCLUDE_ATA */

#ifdef	INCLUDE_PCMCIA
LOCAL STATUS	pcmciaLoad (int sock, char *fileName, FUNCPTR *pEntry);
#endif	/* INCLUDE_PCMCIA */

#ifdef	INCLUDE_TFFS
LOCAL STATUS    tffsLoad (int drive, int removable, char *fileName, 
			  FUNCPTR *pEntry);
#endif	/* INCLUDE_TFFS */

#ifdef	INCLUDE_TSFS_BOOT
LOCAL STATUS	tsfsLoad (char * fileName, FUNCPTR * pEntry);
LOCAL void	wdbRebootEventGet (void * pNode, WDB_EVT_DATA *	pEvtData);
#endif	/* INCLUDE_TSFS_BOOT */

#else

void		usrRoot ();
void		usrClock ();
void		usrKernelInit ();
LOCAL void	bootCmdLoop ();
LOCAL char	autoboot ();
LOCAL void	printBootLogo ();
LOCAL void	bootHelp ();
LOCAL STATUS	bootLoad ();
LOCAL void	go ();
LOCAL void	m ();
LOCAL void	d ();
LOCAL void	bootExcHandler ();
LOCAL void	skipSpace ();
LOCAL void	printExcMsg ();
LOCAL STATUS	getArg ();
LOCAL void	usrBootLineInit ();
LOCAL STATUS	usrBootLineCrack ();

#ifdef  INCLUDE_NETWORK
LOCAL STATUS	netLoad ();
LOCAL void	netifAdrsPrint ();
LOCAL STATUS	checkInetAddrField ();
LOCAL STATUS	usrNetIfAttach ();
LOCAL STATUS	usrNetIfConfig ();
LOCAL STATUS	usrBpInit ();
LOCAL STATUS	usrSlipInit ();
LOCAL STATUS	usrPPPInit ();
#ifdef INCLUDE_BOOTP
LOCAL STATUS	bootpGet ();
#endif
#endif  /* INCLUDE_NETWORK */

#ifdef	INCLUDE_SCSI_BOOT
LOCAL STATUS	scsiLoad();
#endif	/* INCLUDE_SCSI_BOOT */

#ifdef  INCLUDE_FD
LOCAL STATUS    fdLoad ();
#endif  /* INCLUDE_FD */

#ifdef  INCLUDE_IDE
LOCAL STATUS    ideLoad ();
#endif  /* INCLUDE_IDE */

#ifdef	INCLUDE_ATA
LOCAL STATUS	ataLoad ();
#endif	/* INCLUDE_ATA */

#ifdef	INCLUDE_PCMCIA
LOCAL STATUS	pcmciaLoad ();
#endif	/* INCLUDE_PCMCIA */

#ifdef	INCLUDE_TFFS
LOCAL STATUS    tffsLoad ();
#endif	/* INCLUDE_TFFS */

#ifdef	INCLUDE_TSFS_BOOT
LOCAL STATUS	tsfsLoad ();
LOCAL void	wdbRebootEventGet ();
#endif	/* INCLUDE_TSFS_BOOT */

#endif	/* __STDC__ */


void usrInit 
    (
    int startType
    )
    {
    


    while (trapValue1 != TRAP_VALUE_1 || trapValue2 != TRAP_VALUE_2)
	{
	}
    
#if (CPU_FAMILY == SPARC)
    excWindowInit ();				
#endif

#if	(CPU_FAMILY == MIPS)
    sysGpInit ();				
#endif

#ifdef INCLUDE_SYS_HW_INIT_0
   

    SYS_HW_INIT_0 ();
#endif 




#ifdef	INCLUDE_CACHE_SUPPORT
#if (!defined(USER_D_CACHE_ENABLE) && !defined(USER_D_CACHE_MODE))
#define USER_D_CACHE_MODE CACHE_DISABLED
#endif
#if (!defined(USER_I_CACHE_ENABLE) && !defined(USER_I_CACHE_MODE))
#define USER_I_CACHE_MODE CACHE_DISABLED
#endif	

    cacheLibInit (USER_I_CACHE_MODE, USER_D_CACHE_MODE);
#endif	

	
	

#if (CPU == SPARClite)
    cacheLib.textUpdateRtn = NULL;		
#endif


    bzero (edata, end - edata);		

    sysStartType = startType;	

    intVecBaseSet ((FUNCPTR *) VEC_BASE_ADRS);	

#if (CPU_FAMILY == AM29XXX)
    excSpillFillInit ();                      
#endif

    excVecInit ();		
	
    sysHwInit ();	

    usrKernelInit ();				
 	

#if	(CPU==SPARC) || (CPU_FAMILY==I80X86)	
#undef USER_I_CACHE_ENABLE	
#endif	

#ifdef	INCLUDE_CACHE_SUPPORT
#ifdef 	USER_I_CACHE_ENABLE
    cacheEnable (INSTRUCTION_CACHE);		
#endif	
#endif	



    kernelInit ((FUNCPTR) usrRoot, ROOT_STACK_SIZE,
		(char *) MEM_POOL_START_ADRS,
		sysMemTop (), ISR_STACK_SIZE, INT_LOCK_LEVEL);
    }

/*******************************************************************************

* NOMANUAL
*/

void usrRoot
    (
    char *      pMemPoolStart,         
    unsigned    memPoolSize             
    )

    {
    char tyName [20];
    int ix;
	


#ifdef INCLUDE_END
    int count;
    END_TBL_ENTRY* pDevTbl;
#endif /* INCLUDE_END */


    memInit (pMemPoolStart, memPoolSize);

    sysClkConnect ((FUNCPTR) usrClock, 0);
    sysClkRateSet (SYS_CLK_RATE); 	  
    sysClkEnable ();			 
   


#ifdef INCLUDE_SELECT
    selectInit (NUM_FILES);
#endif  



    iosInit (NUM_DRIVERS, NUM_FILES, "/null");
    consoleFd = NONE;
	

#ifdef  INCLUDE_TYCODRV_5_2
#ifdef  INCLUDE_TTY_DEV
    if (NUM_TTY > 0)
        {
        tyCoDrv ();                            

        for (ix = 0; ix < NUM_TTY; ix++)       
            {
            sprintf (tyName, "%s%d", "/tyCo/", ix);

            (void) tyCoDevCreate (tyName, ix, 512, 512);

            if (ix == CONSOLE_TTY)
                strcpy (consoleName, tyName);   
            }

        consoleFd = open (consoleName, O_RDWR, 0);


        (void) ioctl (consoleFd, FIOBAUDRATE, CONSOLE_BAUD_RATE);
        (void) ioctl (consoleFd, FIOSETOPTIONS,
			OPT_ECHO | OPT_CRMOD | OPT_TANDEM | OPT_7_BIT);
        }
#endif  

#else   
#ifdef  INCLUDE_TTY_DEV
    if (NUM_TTY > 0)
        {
        ttyDrv();                              

        for (ix = 0; ix < NUM_TTY; ix++)        
            {
#if (defined(INCLUDE_WDB) && (WDB_COMM_TYPE == WDB_COMM_SERIAL))
	    if (ix == WDB_TTY_CHANNEL)          
	    	continue;
#endif
            sprintf (tyName, "%s%d", "/tyCo/", ix);
            (void) ttyDevCreate (tyName, sysSerialChanGet(ix), 512, 512);

            if (ix == CONSOLE_TTY)             
                {
                strcpy (consoleName, tyName);
                consoleFd = open (consoleName, O_RDWR, 0);
                (void) ioctl (consoleFd, FIOBAUDRATE, CONSOLE_BAUD_RATE);
                (void) ioctl (consoleFd, FIOSETOPTIONS,
			OPT_ECHO | OPT_CRMOD | OPT_TANDEM | OPT_7_BIT);
                }
            }
        }
#endif  /* INCLUDE_TTY_DEV */

#ifdef INCLUDE_PC_CONSOLE
    pcConDrv ();
    for (ix = 0; ix < N_VIRTUAL_CONSOLES; ix++)
        {
        sprintf (tyName, "%s%d", "/pcConsole/", ix);
        (void) pcConDevCreate (tyName,ix, 512, 512);
        if (ix == PC_CONSOLE)          
            {
            strcpy (consoleName, tyName);
            consoleFd = open (consoleName, O_RDWR, 0);
            (void) ioctl (consoleFd, FIOBAUDRATE, CONSOLE_BAUD_RATE);
            (void) ioctl (consoleFd, FIOSETOPTIONS,
			OPT_ECHO | OPT_CRMOD | OPT_TANDEM | OPT_7_BIT);
            }
        }
#endif  /* INCLUDE_PC_CONSOLE */

#endif  /* !INCLUDE_TYCODRV_5_2 */	

#ifdef INCLUDE_WDB
    wdbConfig();		
    vxBootFile[0] = NULL;	
	

#if defined(INCLUDE_TSFS_BOOT) && defined(INCLUDE_TSFS_BOOT_VIO_CONSOLE)
    consoleFd = open ("/vio/0", O_RDWR, 0);	
	
#endif
#endif	


    ioGlobalStdSet (STD_IN,  consoleFd);
    ioGlobalStdSet (STD_OUT, consoleFd);
    ioGlobalStdSet (STD_ERR, consoleFd);


	

    pipeDrv ();					

#if     defined(INCLUDE_EXC_HANDLING) && defined(INCLUDE_EXC_TASK)
#ifdef  INCLUDE_EXC_SHOW
    excShowInit ();			
#endif
    excInit ();				
#endif  

    excHookAdd ((FUNCPTR) bootExcHandler);	
    logInit (consoleFd, 5);			

#ifdef	INCLUDE_DOSFS
    hashLibInit ();				
#endif


#if	defined(INCLUDE_AOUT)
    bootAoutInit ();				
#else	
#if	defined(INCLUDE_ECOFF)
    bootEcoffInit ();				
#else	/* coff */
#if	defined(INCLUDE_COFF)
    bootCoffInit ();			
#else   /* coff */
#if	defined(INCLUDE_ELF)
    bootElfInit ();				
#endif
#endif 					
#endif
#endif

#ifdef  INCLUDE_PCMCIA                                       
                                                             
    pcmciaInit ();                     

#endif 

	


#ifdef INCLUDE_END
    muxMaxBinds = MUX_MAX_BINDS;
    if (muxLibInit() == ERROR)
	return;                              
    for (count = 0, pDevTbl = endDevTbl; pDevTbl->endLoadFunc != END_TBL_END;
         pDevTbl++, count++)
        {
        cookieTbl[count].pCookie = muxDevLoad (pDevTbl->unit, pDevTbl->endLoadFunc,
                                       pDevTbl->endLoadString,
                                       pDevTbl->endLoan, pDevTbl->pBSP);
        if (cookieTbl[count].pCookie == NULL)
            {
            printf ("muxLoad failed!\n");
            }
        
        cookieTbl[count].unitNo=pDevTbl->unit;
	bzero((void *)cookieTbl[count].devName,END_NAME_MAX);
	pDevTbl->endLoadFunc((char*)cookieTbl[count].devName, NULL);

        }
#endif 
	
    
    taskSpawn ("tBoot", bootCmdTaskPriority, bootCmdTaskOptions,
		bootCmdTaskStackSize, (FUNCPTR) bootCmdLoop,
		0,0,0,0,0,0,0,0,0,0);	

	while(1){	 	
		taskDelay (sysClkRateGet()/4);	
		rPDATD= 0x4fff;	
		taskDelay (sysClkRateGet()/4);	
		rPDATD= 0x1fff;			
	}
	
    }
/*******************************************************************************

* NOMANUAL
*/

void usrClock (void)

    {
    tickAnnounce ();	
    }

#include "tffs/tffsDrv.h"	
STATUS 	ftpdInit (FUNCPTR, int stackSize); 
int     netInit(char *   bootString);	     

/*******************************************************************************
*
*/

LOCAL void bootCmdLoop (void)

    {
    BOOT_PARAMS params;
    char line [BOOT_CMD_MAX_LINE];
    char *pLine;
    int nwords;
    int nbytes;
    int value;
    int adr;
    int adr2;
    FUNCPTR entry;
    char key = 0;
	int fd;
	int i=0;
	
STATUS return_value;

    (void) ioctl (STD_IN, FIOFLUSH, 0 /*XXX*/);

    if (sysStartType & BOOT_CLEAR)
	printBootLogo ();	

    usrBootLineInit (sysStartType);		
    bootStringToStruct (BOOT_LINE_ADRS, ¶ms);
    bcopyBytes ((char *) (0x7e000), &(IP_PARAMS),sizeof(IP_PARAMS));    
 	    if(IP_PARAMS.dhcpflag==1)
 	         params.flags = 0x40;
 	    else 
 	    {
 	    	if(IP_PARAMS.bootpflag==1)
 	    	    params.flags = 0x40;
 	    	else
 	    	   params.flags = 0;
 	    }
         sysFlags = params.flags;

#ifdef INCLUDE_TFFS
	if (tffsDrv () != OK)    	
	dosFsInit (NUM_DOSFS_FILES);        
    if (usrTffsConfig (0, 0, "/tffs0/vxworks") == ERROR)
	{
	}
#endif	
#ifdef INCLUDE_NETWORK
	if( netInit(BOOT_LINE_ADRS) == ERROR )	
	{

	}
#endif
#ifdef INCLUDE_FTP_SERVER
	if( ftpdInit(0,0) == ERROR)	
	{

	}
#endif




    printExcMsg (sysExcMsg);
    *sysExcMsg = EOS;		

    bootStringToStruct (BOOT_LINE_ADRS, ¶ms);
    sysFlags = params.flags;

#if defined(INCLUDE_TSFS_BOOT) && defined(INCLUDE_TSFS_BOOT_VIO_CONSOLE)


    while (!wdbTargetIsConnected())
    	taskDelay (sysClkRateGet());

    sysStartType |= BOOT_NO_AUTOBOOT;
#endif

    if (!(sysStartType & BOOT_NO_AUTOBOOT) &&
	!(sysFlags & SYSFLG_NO_AUTOBOOT))
	{
	int timeout = TIMEOUT;

	if ((sysStartType & BOOT_QUICK_AUTOBOOT) ||
	    (sysFlags & SYSFLG_QUICK_AUTOBOOT))
	    {
	    timeout = 1;
	    }

	key = autoboot (timeout);	
	}
	


    (void) ioctl (consoleFd, FIOSETOPTIONS, OPT_TERMINAL);


    printf ("\n");

    FOREVER
	{
	if (key == '@')
	    {
	    line [0] = key;
	    line [1] = EOS;
	    key = 0;
	    }
	else
	    {
	    printf ("[VxWorks Boot]: ");
	    fioRdString (STD_IN, line, sizeof (line));
	    }

	adr = adr2 = 0;
	nwords = 0;

	/* take blanks off end of line */

	pLine = line + strlen (line) - 1;		/* point at last char */
	while ((pLine >= line) && (*pLine == ' '))
	    {
	    *pLine = EOS;
	    pLine--;
	    }

	pLine = line;
	skipSpace (&pLine);

	switch (*(pLine++))
	    {
	    case EOS:		
		break;

	    case 'z':			    	
			if( tffsDevFormat(0,0) != OK )	    		
				printErr ("tffsDevFormat tffs 0 fail!\n");
			break;
		
	    case 'd':		
		if ((getArg (&pLine, &adr, HEX, OPT) == OK) &&
		    (getArg (&pLine, &nwords, DEC, OPT) == OK))
		    d ((char *) adr, nwords);
		break;

	    case 'e':		
		printExcMsg (sysExcMsg + 1);
		break;

	    case 'f':		/* fill */
		if ((getArg (&pLine, &adr, HEX, !OPT) == OK) &&
		    (getArg (&pLine, &nbytes, DEC, !OPT) == OK) &&
		    (getArg (&pLine, &value, DEC, !OPT) == OK))
		    {
		    bfillBytes ((char *) adr, nbytes, value);
		    }

		break;

	    case 't':		/* transpose(?) (running out of letters!) */
		if ((getArg (&pLine, &adr, HEX, !OPT) == OK) &&
		    (getArg (&pLine, &adr2, HEX, !OPT) == OK) &&
		    (getArg (&pLine, &nbytes, HEX, !OPT) == OK))
		    {
		    bcopy ((char *) adr, (char *) adr2, nbytes);
		    }
		break;

	    case 'm':		/* modify */
		if (getArg (&pLine, &adr, HEX, !OPT) == OK)
		    m ((char *) adr);
		break;

#ifdef	TARGET_HK_V2F
	    case 's':		/* system controller */
		{
		extern ULONG sysBCLSet ();

		if (getArg (&pLine, &value, DEC, !OPT) == OK)
		    {
		    if (value != 0)
			{
			(void) sysBCLSet ((ULONG)HK_BCL_SYS_CONTROLLER,
					  (ULONG)HK_BCL_SYS_CONTROLLER);
			printf ("System controller on.\n");
			}
		    else
			{
			(void) sysBCLSet ((ULONG)HK_BCL_SYS_CONTROLLER,
					  (ULONG)0);
			printf ("System controller off.\n");
			}
		    }
		break;
		}
#endif	/* TARGET_HK_V2F */

#if defined(TARGET_FRC_30) || defined(TARGET_FRC_31) || defined(TARGET_FRC_33)
	    case 's':		/* system controller */
		if (getArg (&pLine, &value, DEC, !OPT) == OK)
		    {
		    if (value != 0)
			{
			*FGA_CTL1 |= FGA_CTL1_SCON;
			printf ("System controller on.\n");
			}
		    else
			{
			*FGA_CTL1 &= ~FGA_CTL1_SCON;
			printf ("System controller off.\n");
			}
		    }
		break;
#endif	/* TARGET_FRC_30 || TARGET_FRC_31 || TARGET_FRC_33 */

	    case 'p':		
		bootParamsShow (BOOT_LINE_ADRS);
		break;

	    case 'c':		
		bootParamsPrompt (BOOT_LINE_ADRS);
                if (strlen(BOOT_LINE_ADRS) <= BOOT_LINE_SIZE)
                    {
                  if((SST39VF160_ChipProg(0x3F800,(LOCAL_MEM_LOCAL_ADRS+BOOT_LINE_OFFSET),ROM_PARA_LEN))== 0) 
                        printf("\nNOTE: Bootline not saved to NVRAM\n");
                    }
                else
				{

				}
                
		bootStringToStruct (BOOT_LINE_ADRS, ¶ms);
		for (i = 0; i < 50; ++i)
        		(IP_PARAMS).ipadrinfo[i]=params.ead[i];
        	sprintf(IP_PARAMS.gatewayinfo, "%s", params.gad);
		
		if(params.flags == 0x40)
      		IP_PARAMS.dhcpflag = 1;
		if(params.flags == 0x0)
      		IP_PARAMS.dhcpflag = 2;
SST39VF160_ChipProg(0x3F000,&(IP_PARAMS),sizeof(IP_PARAMS));
                break;

	    case 'g':		
		if (getArg (&pLine, (int *) &entry, HEX, !OPT) == OK)
		    go (entry);
		break;

#ifdef  INCLUDE_NETWORK
	    case 'n':
		netifAdrsPrint (pLine);
		break;

#ifdef ETHERNET_ADR_SET
	    case 'N':
		mEnet (pLine);
		break;
#endif  /* ETHERNET_ADR_SET */
#endif  /* INCLUDE_NETWORK */

	    case '?':			/* help */
            case 'h':			/* help */
		bootHelp ();
		break;


            case '@':			
	    case '$':			
		if (tffsLoad (0, 0, "/tffs0/vxworks", &entry) == OK)
		    {
		    go (entry);
		    }
		else
		    {
		    taskDelay (sysClkRateGet ());	
		    reboot (BOOT_NO_AUTOBOOT);		
		    }
		break;	    

            case 'v':                   

                printBootLogo ();
                break;

	    default:
		printf ("Unrecognized command. Type '?' for help.\n");
		break;

            } /* switch */
        } /* FOREVER */
    }
/******************************************************************************
*
* autoboot - do automatic boot sequence
*
* RETURNS: Doesn't return if successful (starts execution of booted system).
*/

LOCAL char autoboot 
    (
    int timeout		/* timeout time in seconds */
    )
    {
    ULONG	autoBootTime;
    int		timeLeft;
    UINT	timeMarker;
    int		bytesRead = 0;
    FUNCPTR	entry;
    char	key;

    if (timeout > 0)
	{
	printf ("\nPress any key to stop auto-boot...\n");

	/* Loop looking for a char, or timeout after specified seconds */

	autoBootTime = tickGet () + sysClkRateGet () * timeout;
	timeMarker = tickGet () + sysClkRateGet ();
	timeLeft = timeout;

	printf ("%2d\r", timeLeft);

	 while ((tickGet () < autoBootTime) && (bytesRead == 0))
	    {
	    (void) ioctl (consoleFd, FIONREAD, (int) &bytesRead);
	    if (tickGet () == timeMarker)
		{
		timeMarker = tickGet () + sysClkRateGet ();
		printf ("%2d\r", --timeLeft);		
		}
	    }
	}

	

    if (bytesRead == 0)    
	{

	(void) ioctl (consoleFd, FIOSETOPTIONS, OPT_TERMINAL);

	if (tffsLoad (0, 0, "/tffs0/vxworks", &entry) == OK)	    
		go (entry);				
	else		    
		{	    
		printf ("Can't load boot file from TFFS!!\n");	    
		printErr ("\nError loading file: errno = 0x%x.\n", errno);	    
		taskDelay (sysClkRateGet ());	/* pause a second */	    
		}
		
	}
    else
	{
	read (consoleFd, &key, 1);
	return (key & 0x7f);		
	}

    return (ERROR);			
    }
    
    
  
    
    
/******************************************************************************
*
* printBootLogo - print initial boot banner page
*/

LOCAL void printBootLogo (void)

    {
    printf ("\n\n\n\n\n\n\n\n\n\n\n");
    printf ("%20s%s", "","Strong S3C2410X Gold Board Boot");	/* : modified */
    printf ("\n\n\nCopyright 2004-2005  ChenXi@bupt-bcnl.com");		/* : added */
    printf ("\nCopyright 1984-2002  Wind River Systems, Inc.\n\n\n");	/* : modified */
    printf ("CPU: %s\n", sysModel ());
    printf ("Version: %s\n", vxWorksVersion);
    printf ("BSP version: " BSP_VERSION BSP_REV "\n");
    printf ("Creation date: %s\n\n", creationDate);
    }

/*******************************************************************************
*
* bootHelp - print brief help list
*/

LOCAL void bootHelp (void)

    {
    static char *helpMsg[] =
	{
	"#",                      "- network boot (load and go)",	
	"z",                      "- format tffs 0",                
	"?",                      "- print this list",
	"@",                      "- tffs boot (load and go)",	    
	"r",                      "- tffs backup image boot (when the newest image is broken)",  
	"p",                      "- print boot params",
	"c",                      "- change boot params",
	"&",                      "- get vxworks image by tftp"
	"l",                      "- load boot file",
	"g adrs",                 "- go to adrs",
	"d adrs[,n]",             "- display memory",
	"m adrs",                 "- modify memory",
	"f adrs, nbytes, value",  "- fill memory",
	"t adrs, adrs, nbytes",   "- copy memory",
	"e",                      "- print fatal exception",
        "v",                      "- print boot logo with version",
#ifdef INCLUDE_NETWORK
	"n netif",	  	  "- print network interface device address",
#if defined(ETHERNET_ADR_SET)
	"N",			  "- set ethernet address",
#endif  /* ETHERNET_ADR_SET */
#endif  /* INCLUDE_NETWORK */
#if defined(TARGET_HK_V2F) || defined(TARGET_FRC_30) || \
    defined(TARGET_FRC_31) || defined(TARGET_FRC_33)
	"s [0/1]",                "- system controller 0 = off, 1 = on",
#endif	/* TARGET_HK_V2F/FRC_30/FRC_31/FRC_33 */
	"$dev(0,procnum)host:/file h=# e=# b=# g=# u=usr [pw=passwd] f=#", "",
	"                          tn=targetname s=script o=other", "",

#ifdef	INCLUDE_SCSI_BOOT
	"boot device: scsi=id,lun              file name: /sd0/vxWorks","",
#endif	/*INCLUDE_SCSI_BOOT*/

#ifdef	INCLUDE_FD
	"boot device: fd=drive,fdType          file name: /fd0/vxWorks","",
#endif	/* INCLUDE_FD */

#ifdef	INCLUDE_IDE
	"boot device: ide=drive,configType     file name: /ide0/vxWorks","",
#endif	/* INCLUDE_IDE */

#ifdef	INCLUDE_ATA
	"boot device: ata=ctrl,drive           file name: /ata0/vxWorks","",
#endif	/* INCLUDE_ATA */

#ifdef	INCLUDE_PCMCIA
	"boot device: pcmcia=sock              file name: /pcmcia0/vxWorks","",
#endif	/* INCLUDE_PCMCIA */

#ifdef	INCLUDE_TFFS
	"boot device: tffs=drive,removable     file name: /tffs0/vxWorks","",
#endif	/* INCLUDE_TFFS */

#ifdef INCLUDE_TSFS_BOOT
	"boot device: tsfs                     file name: /tgtsvr/vxWorks","",
#endif /*INCLUDE_TSFS_BOOT */

	"Boot flags:",		  "",
#if defined(TARGET_HK_V2F) || defined(TARGET_FRC_30) || \
    defined(TARGET_FRC_31) || defined(TARGET_FRC_33)
	"  0x01  - don't be system controller",	"",
#endif	/* TARGET_HK_V2F/FRC_30/FRC_31/FRC_33 */
	"  0x02  - load local system symbols",		"",
	"  0x04  - don't autoboot",			"",
	"  0x08  - quick autoboot (no countdown)",	"",
#ifdef  INCLUDE_NETWORK
	"  0x20  - disable login security",		"",
#ifdef  INCLUDE_DHCPC
	"  0x40  - use dhcp to get boot parameters",	"",
#else
#ifdef INCLUDE_BOOTP
	"  0x40  - use bootp to get boot parameters",	"",
#else
	"  0x40  - autoconfigure: NOT AVAILABLE (no method installed)",	"",
#endif /* INCLUDE_BOOTP */
#endif /* INCLUDE_DHCPC */

	"  0x80  - use tftp to get boot image",		"",
	"  0x100 - use proxy arp",			"",
#endif  /* INCLUDE_NETWORK */
	NULL
	};

    FAST char **pMsg;
#ifdef  INCLUDE_NETWORK
    FAST NETIF *pNif;
#endif  /* INCLUDE_NETWORK */

#ifdef INCLUDE_END
    int count;
    char       muxDevName[8];
    END_TBL_ENTRY* pDevTbl;
#endif /* INCLUDE_END */

    printf ("\n");

    for (pMsg = helpMsg; *pMsg != NULL; pMsg += 2)
	printf (" %-21s %s\n", *pMsg, *(pMsg + 1));

#ifdef  INCLUDE_NETWORK

    printf ("\navailable boot devices:");

#ifdef INCLUDE_END
    printf ("Enhanced Network Devices\n");
    for (count = 0, pDevTbl = endDevTbl; pDevTbl->endLoadFunc != END_TBL_END;
         pDevTbl++, count++)
        {
        if (!pDevTbl->processed)
            {
            muxDevName [0] = EOS;
            pDevTbl->endLoadFunc (muxDevName, NULL);
            printf (" %s%d", muxDevName, pDevTbl->unit);
            }
        }
#endif /* INCLUDE_END */
    
    for (pNif = netIf; pNif->ifName != 0; pNif++)
	{
	if (strncmp (pNif->ifName, "lo", 2) != 0)
	    printf (" %s", pNif->ifName);
	}


#endif  /* INCLUDE_NETWORK */

#ifdef	INCLUDE_SCSI_BOOT
    printf (" scsi");
#endif	/*INCLUDE_SCSI_BOOT*/

#ifdef  INCLUDE_FD
    printf (" fd");
#endif  /* INCLUDE_FD */

#ifdef  INCLUDE_IDE
    printf (" ide");
#endif  /* INCLUDE_IDE */

#ifdef  INCLUDE_ATA
    printf (" ata");
#endif  /* INCLUDE_ATA */

#ifdef  INCLUDE_TFFS
    printf (" tffs");
#endif  /* INCLUDE_TFFS */

#ifdef  INCLUDE_TSFS_BOOT
    printf (" tsfs");
#endif  /* INCLUDE_TSFS_BOOT */

    printf ("\n");
    }

/*******************************************************************************
*
* bootLoad - load a module into memory
*
* RETURNS: OK or ERROR
*/

LOCAL STATUS bootLoad 
    (
    char *   bootString,
    FUNCPTR *pEntry
    )
    {
    
    BOOT_PARAMS		params;
#ifdef  INCLUDE_SCSI_BOOT
#ifdef  INCLUDE_SCSI2
     SCSI_OPTIONS	options;
     UINT		which;
     int		devBusId;
#endif  /* INCLUDE_SCSI2 */
#endif  /* INCLUDE_SCSI_BOOT */
#ifdef  INCLUDE_NETWORK
    IMPORT int          netTaskPriority;
    int                 oldTaskPriority;
#endif  /* INCLUDE_NETWORK */


#ifndef  INCLUDE_NETWORK

    printf ("\nError loading file: networking code not present.\n");
    return (ERROR);
    }

#else  /* INCLUDE_NETWORK */



    return (OK);
    }

#ifdef INCLUDE_END
/*******************************************************************************
*
* findCookie - traverses the cookieTbl to return the right cookie
*
* Given the unit number and the device name this function traverses the cookieTbl
* to return the right cookie. This is a local file.
*
* RETURNS: cookie or NULL
*
*/

LOCAL void* findCookie
    (
    int unitNo,
    char* devName
    )
    {
    int count;
    for(count=0;count<32;count++)
	{
	if((cookieTbl[count].unitNo==unitNo) && 
	    (STREQ(cookieTbl[count].devName,devName)))
        return(cookieTbl[count].pCookie);
	}
    return (NULL);
    }
#endif    /* INCLUDE_END */

/*******************************************************************************
*
* RETURNS: OK or ERROR
*/

LOCAL STATUS netLoad 
    (
    char *hostName,
    char *fileName,
    char *usr,
    char *passwd,
    FUNCPTR *pEntry
    )
    {
    int fd;
    int errFd;		/* for receiving standard error messages from Unix */
    char command [BOOT_FILE_LEN + BOOT_HOST_LEN];
    BOOL bootFtp = (passwd[0] != EOS);
    BOOL bootRsh = FALSE;

    printf ("Loading... ");      

    return (OK);

    }

#endif  /* INCLUDE_NETWORK */

#if     (defined (INCLUDE_SCSI_BOOT) || defined (INCLUDE_FD) || \
	 defined (INCLUDE_IDE) || defined (INCLUDE_ATA) || \
	 defined (INCLUDE_TFFS))

#define	SPIN_UP_TIMEOUT	45	/* max # of seconds to wait for spinup */

/******************************************************************************
*
* devSplit - split the device name from a full path name
*
* This routine returns the device name from a valid UNIX-style path name
* by copying until two slashes ("/") are detected.  The device name is
* copied into .
*
* RETURNS: N/A
*
* NOMANUAL
*/

void devSplit 
    (
    FAST char *fullFileName,	/* full file name being parsed */
    FAST char *devName		/* result device name */
    )
    {
    FAST int nChars = 0;

    if (fullFileName != NULL)
	{
	char *p0 = fullFileName;
	char *p1 = devName;

	while ((nChars < 2) && (*p0 != EOS))
	    {
	    if (*p0 == '/')
		nChars++;

	    *p1++ = *p0++;
	    }
	*p1 = EOS;
	}
    else
	{
	(void) strcpy (devName, "");
	}
    }

#endif  /* (defined (INCLUDE_SCSI_BOOT) || (INCLUDE_FD) || (INCLUDE_IDE)) */

#ifdef  INCLUDE_SCSI_BOOT

/******************************************************************************
*
* scsiLoad - load a vxWorks image from a local SCSI disk
*
* RETURNS: OK, or ERROR if file can not be loaded.
*/

LOCAL STATUS scsiLoad 
    (
    int     bootDevId,
    int     bootDevLUN,
    char    *fileName,
    FUNCPTR *pEntry
    )
    {
    int fd;
    SCSI_PHYS_DEV *pScsiPhysBootDev;
    BLK_DEV       *pScsiBlkBootDev;
    char bootDir  [BOOT_FILE_LEN];
    int           ix;
#ifdef INCLUDE_SCSI2
    SCSI_OPTIONS  options;
    UINT          which;
#endif /* INCLUDE_SCSI2 */
    CBIO_DEV_ID pCbio;


    if (!scsiInitialized)		/* skip if this is a retry */
	{
	if (sysScsiInit () == ERROR)
	    {
	    printErr ("Could not initialize SCSI.\n");
	    return (ERROR);
	    }
	scsiInitialized = TRUE;
	}

    taskDelay (sysClkRateGet ());	/* delay 1 second after reset */

    if ((bootDevId  < SCSI_MIN_BUS_ID) ||
	(bootDevId  > SCSI_MAX_BUS_ID) ||
	(bootDevLUN < SCSI_MIN_LUN)    ||
	(bootDevLUN > SCSI_MAX_LUN))
	{
	printErr ("SCSI device parameters < busId = %d, lun = %d > ",
		  bootDevId, bootDevLUN);
	printErr ("are out of range (0-7).\n");
	printErr ("Check boot device format:\n");
	printErr ("    scsi=,  e.g.  scsi=2,0\n");
	return (ERROR);
	}

#ifdef INCLUDE_SCSI2
    /* Set all devices to asynchronous data transfer */

    which = SCSI_SET_OPT_XFER_PARAMS;
    options.maxOffset = 0;
    options.minPeriod = SCSI_SYNC_XFER_MIN_PERIOD;
    scsiTargetOptionsSet (pSysScsiCtrl, bootDevId, &options, which);
#endif /* INCLUDE_SCSI2 */

    /* create device handle for TEST UNIT READY commands */

    if ((pScsiPhysBootDev = scsiPhysDevCreate (pSysScsiCtrl, bootDevId,
					       bootDevLUN, 128, 0, 0,
					       0xffff, 512))
	== NULL)
	{
	printErr ("scsiPhysDevCreate failed.\n");
	return (ERROR);
	}

    /* issue a couple fo TEST UNIT READY commands to clear reset execption */

    scsiTestUnitRdy (pScsiPhysBootDev);
    scsiTestUnitRdy (pScsiPhysBootDev);

    /* issue a TEST UNIT READY every second for SPIN_UP_TIMEOUT seconds,
     * or until device returns OK status.
     */

    if (scsiTestUnitRdy (pScsiPhysBootDev) != OK)
        {
        printf ("Waiting for disk to spin up...");

        for (ix = 0; ix < SPIN_UP_TIMEOUT; ix++)
            {
            if (scsiTestUnitRdy (pScsiPhysBootDev) == OK)
                {
                printf (" done.\n");
                break;
		}
            else
		{
                if (ix != (SPIN_UP_TIMEOUT - 1))
                    printf (".");
                else
                    {
                    printf (" timed out.\n");
                    return (ERROR);
		    }
                taskDelay (sysClkRateGet ());
		}
	    }
	}

    /* delete temporary device handle */

    scsiPhysDevDelete (pScsiPhysBootDev);

    printf ("Attaching to scsi device... ");

    /* recreate a device handle, with polling for actual device parameters */

    taskDelay (sysClkRateGet ());

    if ((pScsiPhysBootDev = scsiPhysDevCreate (pSysScsiCtrl, bootDevId,
                                               bootDevLUN, 0, -1, 0, 0, 0))
         == NULL)
	{
        printErr ("scsiPhysDevCreate failed.\n");
        return (ERROR);
        }

    /*-------------------------------------------------------------------------
     *
     * Configuration of an OMTI3500
     *
     *-----------------------------------------------------------------------*/

    if ((strncmp (pScsiPhysBootDev->devVendorID, "SMS", 3) == 0) &&
	(strncmp (pScsiPhysBootDev->devProductID, "OMTI3500", 8) == 0))
	{
	char modeData [4];	/* array for floppy MODE SELECT data */

	/* zero modeData array, then set byte 1 to "medium code" (0x1b).
	 * NOTE: MODE SELECT data is highly device-specific.  If your device
	 * requires configuration via MODE SELECT, please consult the device's
	 * Programmer's Reference for the relevant data format.
	 */

	bzero (modeData, sizeof (modeData));
	modeData [1] = 0x1b;

	/* issue a MODE SELECT cmd to correctly configure floppy controller */

	scsiModeSelect (pScsiPhysBootDev, 1, 0, modeData, sizeof (modeData));

	/* delete and re-create the SCSI_PHYS_DEV so that INQUIRY will return
	 * the new device parameters, i.e., correct number of blocks
	 */

	scsiPhysDevDelete (pScsiPhysBootDev);

	/* recreate a device handle, polling for actual device parameters */

	if ((pScsiPhysBootDev = scsiPhysDevCreate (pSysScsiCtrl, bootDevId,
						   bootDevLUN, 0, -1, 0, 0, 0))
	    == NULL)
	    {
	    printErr ("scsiPhysDevCreate failed.\n");
	    return (ERROR);
	    }
	}
    /*-------------------------------------------------------------------------
     *
     * END of OMTI3500 configuration
     *
     *-----------------------------------------------------------------------*/

    /* create a block device spanning entire disk (non-distructive!) */

    if ((pScsiBlkBootDev = scsiBlkDevCreate (pScsiPhysBootDev, 0, 0)) == NULL)
	{
        printErr ("scsiLoad: scsiBlkDevCreate failed.\n");
        return (ERROR);
	}

    dosFsInit (NUM_DOSFS_FILES);        /* initialize DOS-FS */

    /* split off boot device from boot file */

    devSplit (fileName, bootDir);

    /* now support booting from partitions on SCSI devices */

    pCbio = dpartDevCreate((CBIO_DEV_ID) pScsiBlkBootDev,
                           NUM_PARTITIONS_DISK_BOOT,
                           usrFdiskPartRead);

    if (NULL == pCbio)
        {
        printErr ("scsiLoad: dpartDevCreate returned NULL.\n");
        return (ERROR);
	}

    /* initialize the boot block device as a dosFs device named  */

    if (ERROR == dosFsDevCreate(bootDir,
                                dpartPartGet(pCbio,PARTITION_DISK_BOOT),
                                20, NONE))
        {
        printErr ("scsiLoad: dosFsDevCreate returned ERROR.\n");
        return (ERROR);
	}
	
    printErr ("done.\n");

    /* load the boot file */

    printErr ("Loading %s...", fileName);

    fd = open (fileName, O_RDONLY, 0);

    if (fd == ERROR)
	{
        printErr ("\nCannot open \"%s\".\n", fileName);
        return (ERROR);
	}

    if (bootLoadModule (fd, pEntry) != OK)
        goto readErr;

    close (fd);
    return (OK);

readErr:

    close (fd);
    return (ERROR);
    }

#endif	/* INCLUDE_SCSI_BOOT */

#ifdef	INCLUDE_FD

#include "usrFd.c"

/******************************************************************************
*
* fdLoad - load a vxWorks image from a local floppy disk
*
* RETURNS: OK, or ERROR if file can not be loaded.
*/

LOCAL STATUS fdLoad 
    (
    int     drive,
    int     type,
    char    *fileName,
    FUNCPTR *pEntry
    )
    {
    int fd;

    if (fdDrv (FD_INT_VEC, FD_INT_LVL) != OK)
	{
	printErr ("Could not initialize.\n");
	return (ERROR);
	}

    printf ("Attaching to floppy disk device... ");

    dosFsInit (NUM_DOSFS_FILES);        /* initialize DOS-FS */

    if (usrFdConfig (drive, type, fileName) == ERROR)
	{
        printErr ("usrFdConfig failed.\n");
        return (ERROR);
	}

    printErr ("done.\n");

    /* load the boot file */

    printErr ("Loading %s...", fileName);

    if ((fd = open (fileName, O_RDONLY, 0)) == ERROR)
	{
        printErr ("\nCannot open \"%s\".\n", fileName);
        return (ERROR);
	}

    if (bootLoadModule (fd, pEntry) != OK)
        goto fdLoadErr;

    close (fd);
    return (OK);

fdLoadErr:

    close (fd);
    return (ERROR);
    }

#endif	/* INCLUDE_FD */

#ifdef	INCLUDE_IDE

#define	IDE_MEM_DOSFS	0x200000
#include "usrIde.c"

/******************************************************************************
*
* ideLoad - load a vxWorks image from a local IDE disk
*
* RETURNS: OK, or ERROR if file can not be loaded.
*/

LOCAL STATUS ideLoad 
    (
    int     drive,
    int     type,
    char    *fileName,
    FUNCPTR *pEntry
    )
    {
    int fd;

    if (ideDrv (IDE_INT_VEC, IDE_INT_LVL, type) == ERROR)
	{
	printErr ("Could not initialize.\n");
	return (ERROR);
	}

    printf ("Attaching to IDE disk device... ");

    dosFsInit (NUM_DOSFS_FILES);        /* initialize DOS-FS */

    if (usrIdeConfig (drive, fileName) == ERROR)
	{
        printErr ("usrIdeConfig failed.\n");
        return (ERROR);
	}

    printErr ("done.\n");

    /* load the boot file */

    printErr ("Loading %s...", fileName);

    if ((fd = open (fileName, O_RDONLY, 0)) == ERROR)
	{
        printErr ("\nCannot open \"%s\".\n", fileName);
        return (ERROR);
	}

    if (bootLoadModule (fd, pEntry) != OK)
        goto ideLoadErr;

    close (fd);
    return (OK);

ideLoadErr:

    close (fd);
    return (ERROR);
    }

#endif	/* INCLUDE_IDE */

#ifdef	INCLUDE_ATA

#define	ATA_MEM_DOSFS	0x200000
#include "usrAta.c"

/******************************************************************************
*
* ataLoad - load a vxWorks image from a local ATA disk
*
* RETURNS: OK, or ERROR if file can not be loaded.
*/

LOCAL STATUS ataLoad 
    (
    int     ctrl,
    int     drive,
    char    *fileName,
    FUNCPTR *pEntry
    )
    {
    IMPORT ATA_RESOURCE ataResources[];
    ATA_RESOURCE *pAtaResource	= &ataResources[ctrl];
    int fd;
    char tmp[BOOT_FILE_LEN];

    if (ataDrv (ctrl, pAtaResource->drives, pAtaResource->intVector,
		pAtaResource->intLevel, pAtaResource->configType,
		pAtaResource->semTimeout, pAtaResource->wdgTimeout) == ERROR)
	{
	printErr ("Could not initialize.\n");
	return (ERROR);
	}

    printf ("Attaching to ATA disk device... ");

    dosFsInit (NUM_DOSFS_FILES);        /* initialize DOS-FS */

    devSplit (fileName, tmp);

    if (usrAtaConfig (ctrl, drive, tmp) == ERROR)
	{
        printErr ("usrAtaConfig failed.\n");
        return (ERROR);
	}

    printErr ("done.\n");

    /* load the boot file */

    printErr ("Loading %s...", fileName);

    if ((fd = open (fileName, O_RDONLY, 0)) == ERROR)
	{
        printErr ("\nCannot open \"%s\".\n", fileName);
        return (ERROR);
	}

    if (bootLoadModule (fd, pEntry) != OK)
        goto ataLoadErr;

    close (fd);
    return (OK);

ataLoadErr:

    close (fd);
    return (ERROR);
    }

#endif	/* INCLUDE_ATA */

#ifdef	INCLUDE_PCMCIA

#define	PCMCIA_MEM_DOSFS	0x200000
#include "usrPcmcia.c"

/******************************************************************************
*
* pcmciaLoad - load a vxWorks image from a PCMCIA disk device
*
* RETURNS: OK, or ERROR if file can not be loaded.
*/

LOCAL STATUS pcmciaLoad 
    (
    int     sock,
    char    *fileName,
    FUNCPTR *pEntry
    )
    {
    int fd;

    printf ("Attaching to PCMCIA block device... ");

    dosFsInit (NUM_DOSFS_FILES);        /* initialize DOS-FS */

    if (usrPcmciaConfig (sock, fileName) != OK)
        return (ERROR);

    printErr ("done.\n");

    /* load the boot file */

    printErr ("Loading %s...", fileName);

    if ((fd = open (fileName, O_RDONLY, 0)) == ERROR)
	{
        printErr ("\nCannot open \"%s\".\n", fileName);
        return (ERROR);
	}

    if (bootLoadModule (fd, pEntry) != OK)
        goto pcmciaLoadErr;

    close (fd);
    return (OK);

pcmciaLoadErr:

    close (fd);
    return (ERROR);
    }

#endif	/* INCLUDE_PCMCIA */

#ifdef	INCLUDE_TFFS

#define	TFFS_MEM_DOSFS	0x200000
#include "usrTffs.c"
#include "sysTffs.c"      /* the BSP stub file, in the BSP directory */ 

/******************************************************************************
*
* tffsLoad - load a vxWorks image from a TFFS Flash disk
*
* RETURNS: OK, or ERROR if file can not be loaded.
*
* NOMANUAL
*/

LOCAL STATUS tffsLoad 
    (
    int     drive,		
    int     removable,		
    char    * fileName,		
    FUNCPTR * pEntry
    )
    {
    int fd;

    printErr ("Loading %s...", fileName);

    if ((fd = open (fileName, O_RDONLY, 0)) == ERROR)
	{
        printErr ("\nCannot open \"%s\".\n", fileName);
        return (ERROR);
	}

    if (bootLoadModule (fd, pEntry) != OK)
        goto tffsLoadErr;

    close (fd);
    return (OK);

tffsLoadErr:

    close (fd);
    return (ERROR);
    }

#endif	/* INCLUDE_TFFS */

#ifdef INCLUDE_TSFS_BOOT
/******************************************************************************
*
* RETURNS: OK, or ERROR if file can not be loaded.
*
* NOMANUAL
*/

LOCAL STATUS tsfsLoad 
    (
    char    * fileName,		/* file name to download */
    FUNCPTR * pEntry
    )
    {
    int fd;
    WDB_EVT_NODE rebootEventNode;
    char corefile [100];


    if (fileName[0] != '/' && fileName[0] != '\\')
	sprintf (corefile, "/tgtsvr/%s", fileName);
    else
	sprintf (corefile, "/tgtsvr%s", fileName);

    printf ("Booting using TSFS...\nMake sure that your");
    printf (" Target Server is started with -R[oot] option.\n");

#ifndef INCLUDE_TSFS_BOOT_VIO_CONSOLE
    printf ("Waiting for Target Server connection...");


    while (!wdbTargetIsConnected())
    	taskDelay (sysClkRateGet());

    printf (" Done.\n");
#endif	/* INCLUDE_TSFS_BOOT_VIO_CONSOLE */


    printErr ("\nLoading %s...\n", corefile);

    if ((fd = open (corefile, O_RDONLY, 0)) == ERROR)
	{
        printErr ("\nCannot open \"%s\".\n", corefile);
        return (ERROR);
	}


    if (bootLoadModule (fd, pEntry) != OK)
        goto tsfsLoadErr;

    close (fd);

#if (WDB_COMM_TYPE != WDB_COMM_SERIAL)


    wdbEventNodeInit (&rebootEventNode, wdbRebootEventGet, NULL, NULL);
    wdbEventPost (&rebootEventNode);


    taskDelay (sysClkRateGet() / 10);
#endif	/* WDB_COMM_TYPE != WDB_COMM_SERIAL */

    return (OK);

tsfsLoadErr:

    close (fd);
    return (ERROR);
    }

/******************************************************************************
*
* wdbRebootEventGet - dummy eventGet routine to force the Target Server restart
*
* suspend the WDB task, so the Target Server will get a RPC_SYSTEMERROR
* will trying to get an event, so it will restart and try to re-attach to
* the target.
*/

LOCAL void wdbRebootEventGet
    (
    void *		pNode,
    WDB_EVT_DATA *	pEvtData
    )
    {
    taskSuspend (0);
    }

#endif	/* INCLUDE_TSFS_BOOT */

#ifdef  INCLUDE_NETWORK

/******************************************************************************
*
* netifAdrsPrint - print MAC address of a network interface
*/

LOCAL void netifAdrsPrint 
    (
    char *ifname		/* interface name */
    )
    {
    IMPORT struct ifnet *ifunit ();
    struct ifnet *ifp;
    char *buf;
    char  devName [10];
    int i, value;

    if (ifname == NULL || *ifname == EOS)
	{
	printf ("Interface not specified\n");
	return;
	}

    while (*ifname == ' ')
	ifname++;       /* skip leading blanks */

    if (*ifname == EOS)
	{
	printf ("Interface not specified\n");
	return;
	}

    i = 0;
    while (!isdigit((int)ifname[i]) && !isspace((int)ifname[i]) && ifname[i] != EOS)
       i++;

    if (ifname[i] == EOS)         
       value = 0;
 
    buf = &ifname[i];
    if (bootScanNum (&buf, &value, FALSE) != OK)  
       value = 0;

    ifname[i] = EOS;
    sprintf (devName, "%s%d", ifname, value);

    if (strncmp (devName, "bp", 2) == 0)
	{

	printf ("Address for device \"%s\" == 00:00:00:00:00:%02x\n",
		devName,  sysProcNumGet ());
	return;
	}


    hostTblInit ();		/* initialize host table */
    if (netLibInit () != OK)
        printf ("netLibInit() error returned\n");

    if ((ifp = ifunit (devName)) == NULL)
	{
	if ((usrNetIfAttach (ifname, value, "0") != OK) ||
	    (usrNetIfConfig (ifname, value, "0", (char *) NULL, 0) != OK))
	    {
	    printf ("Cannot initialize interface named \"%s\"\n", devName);
	    return;
	    }

	if ((ifp = ifunit (devName)) == NULL)
	    {
	    printf ("Device named \"%s\" doesn't exist.\n", devName);
	    return;
	    }
	}

    if (!(ifp->if_flags & IFF_POINTOPOINT) &&
	!(ifp->if_flags & IFF_LOOPBACK))
	{
        printf ("Address for device \"%s\" == %02x:%02x:%02x:%02x:%02x:%02x\n",
		devName,
		((struct arpcom *)ifp)->ac_enaddr [0],
		((struct arpcom *)ifp)->ac_enaddr [1],
		((struct arpcom *)ifp)->ac_enaddr [2],
		((struct arpcom *)ifp)->ac_enaddr [3],
		((struct arpcom *)ifp)->ac_enaddr [4],
		((struct arpcom *)ifp)->ac_enaddr [5]);
	}

    if_dettach (ifunit (devName));	/* dettach interface for fresh start */
    }

#endif  /* INCLUDE_NETWORK */

/*******************************************************************************
*
* go - start at specified address
*/

LOCAL void go 
    (
    FUNCPTR entry
    )
    {
    printf ("Starting at 0x%x...\n\n", (int) entry);

    taskDelay (sysClkRateGet ());	/* give the network a moment to close */

#ifdef  INCLUDE_NETWORK
    if (netLibInitialized == TRUE)
        ifreset ();			/* reset network to avoid interrupts */
#ifdef INCLUDE_END
   

    (void) muxDevStopAll (0);      
#endif  /* INCLUDE_END */
#endif  /* INCLUDE_NETWORK */

#if	(CPU_FAMILY == PPC)
    cacheTextUpdate ((void *) (LOCAL_MEM_LOCAL_ADRS),	/* cache coherency */
		     (size_t) (sysMemTop() - LOCAL_MEM_LOCAL_ADRS));
#else
#ifdef	INCLUDE_CACHE_SUPPORT
    cacheClear (DATA_CACHE, NULL, ENTIRE_CACHE);	/* push cache to mem */
#endif	/* INCLUDE_CACHE_SUPPORT */
#endif	/* (CPU_FAMILY == PPC) */

#if	(CPU_FAMILY == I80X86)
    sysClkDisable ();			/* disable the system clock interrupt */
    sysIntLock ();			/* lock the used/owned interrupts */
#   if defined (SYMMETRIC_IO_MODE) || defined (VIRTUAL_WIRE_MODE)
    {
    extern void loApicEnable ();
    loApicEnable (FALSE);		/* disable the LOAPIC */
    }
#       if defined (SYMMETRIC_IO_MODE)
    {
    extern BOOL	sysBp;			/* TRUE for BP, FALSE for AP */
    extern void ioApicEnable ();
    if (sysBp)
        ioApicEnable (FALSE);		/* disable the IO APIC */
    }
#       endif /* (SYMMETRIC_IO_MODE) */
#   endif /* (SYMMETRIC_IO_MODE) || (VIRTUAL_WIRE_MODE) */
#endif	/* (CPU_FAMILY == I80X86) */


    intLock(); 

    (entry) ();		
    }

/*******************************************************************************
*
* m - modify memory
*
*
* All numbers entered and displayed are in hexadecimal.
* Memory is treated as 16-bit words.
*/

LOCAL void m 
    (
    char *adrs		/* address to change */
    )
    {
    char line [MAX_LINE + 1];	/* leave room for EOS */
    char *pLine;		/* ptr to current position in line */
    int value;			/* value found in line */
    char excess;

    /* round down to word boundary */

    for (adrs = (char *) ((int) adrs & 0xfffffffe);	/* start on even addr */
         ;						/* FOREVER */
	 adrs = (char *) (((short *) adrs) + 1))	/* bump as short ptr */
	{
	/* prompt for substitution */

	printf ("%06x:  %04x-", (int) adrs, (*(short *)adrs) & 0x0000ffff);

	/* get substitution value:
	 *   skip empty lines (CR only);
	 *   quit on end of file or invalid input;
	 *   otherwise put specified value at address */

	if (fioRdString (STD_IN, line, MAX_LINE) == EOF)
	    break;

	line [MAX_LINE] = EOS;	/* make sure input line has EOS */

	/* skip leading spaces*/

	for (pLine = line; isspace ((UINT) * pLine); ++pLine)
	    ;

	if (*pLine == EOS)			/* skip field if just CR */
	    continue;

	if (sscanf (pLine, "%x%1s", &value, &excess) != 1)
	    break;				/* quit if not number */

	* (short *) adrs = value;		/* assign new value */
	}

    printf ("\n");
    }
/*******************************************************************************
*
* d - display memory
*
* Display contents of memory, starting at adrs.  Memory is displayed in
* words.  The number of words displayed defaults to 64.  If
* nwords is non-zero, that number of words is printed, rounded up to
* the nearest number of full lines.  That number then becomes the default.
*/

LOCAL void d 
    (
    FAST char *adrs,	/* address to display */
    int	       nwords	/* number of words to print. */
    )			/* If 0, print 64 or last specified. */
    {
    static char *last_adrs;
    static int dNbytes = 128;
    char ascii [17];
    FAST int nbytes;
    FAST int byte;

    ascii [16] = EOS;			/* put an EOS on the string */

    nbytes = 2 * nwords;

    if (nbytes == 0)
	nbytes = dNbytes;	/* no count specified: use current byte count */
    else
	dNbytes = nbytes;	/* change current byte count */

    if (adrs == 0)
	adrs = last_adrs;	/* no address specified: use last address */

    adrs = (char *) ((int) adrs & ~1);	/* round adrs down to word boundary */


    /* print leading spaces on first line */

    bfill ((char *) ascii, 16, '.');

    printf ("%06x:  ", (int) adrs & ~0xf);

    for (byte = 0; byte < ((int) adrs & 0xf); byte++)
	{
	printf ("  ");
	if (byte & 1)
	    printf (" ");	/* space between words */
	if (byte == 7)
	    printf (" ");	/* extra space between words 3 and 4 */

	ascii [byte] = ' ';
	}


    /* print out all the words */

    while (nbytes-- > 0)
	{
	if (byte == 16)
	    {
	    /* end of line:
	     *   print out ascii format values and address of next line */

	    printf ("  *%16s*\n%06x:  ", ascii, (int) adrs);

	    bfill ((char *) ascii, 16, '.');	/* clear out ascii buffer */
	    byte = 0;				/* reset word count */
	    }


#if  _BYTE_ORDER == _BIG_ENDIAN
    printf ("%02x", *adrs & 0x000000ff);
#else  /* _BYTE_ORDER == _LITTLE_ENDIAN  */
    /* swap odd and even bytes */
    if ( (long)adrs & 1)
        {
        printf ("%02x", *((char *)((long)adrs & 0xfffffffe)) & 0x000000ff);
        }
    else
        {
        printf ("%02x", *((char *)((long)adrs + 1)) & 0x000000ff);
        }
#endif /* _BYTE_ORDER == _BIG_ENDIAN  */

	if (byte & 1)
	    printf (" ");	/* space between words */
	if (byte == 7)
	    printf (" ");	/* extra space between words 3 and 4 */

	if (* adrs == ' ' ||
			(isascii ((UINT) * adrs) && isprint ((UINT) * adrs)))
	    ascii [byte] = (UINT) * adrs;

	adrs++;
	byte++;
	}


    /* print remainder of last line */

    for (; byte < 16; byte++)
	{
	printf ("  ");
	if (byte & 1)
	    printf (" ");	/* space between words */
	if (byte == 7)
	    printf (" ");	/* extra space between words 3 and 4 */

	ascii [byte] = ' ';
	}

    printf ("  *%16s*\n", ascii);	/* print out ascii format values */

    last_adrs = adrs;
    }
/*******************************************************************************
*
* bootExcHandler - bootrom exception handling routine
*/

LOCAL void bootExcHandler 
    (
    int tid		/* task ID */
    )
    {
    REG_SET regSet;       /* task's registers */

    /* get registers of task to be traced */

    if (taskRegsGet (tid, ®Set) != ERROR)
        {
        trcStack (®Set, (FUNCPTR) NULL, tid);
        taskRegsShow (tid);
        }
    else
        printf ("bootExcHandler: exception caught but no valid task.\n");

    taskDelay (sysClkRateGet ());       /* pause a second */

    reboot (BOOT_NO_AUTOBOOT);
    }
/*******************************************************************************
*
* skipSpace - advance pointer past white space
*
* Increments the string pointer passed as a parameter to the next
* non-white-space character in the string.
*/

LOCAL void skipSpace 
    (
    FAST char **strptr	/* pointer to pointer to string */
    )
    {
    while (isspace ((UINT) ** strptr))
	++ * strptr;
    }
/*******************************************************************************
*
* printExcMsg - print exception message
*
* Avoid printing possible control characters in exception message area.
*/

LOCAL void printExcMsg 
    (
    char *string
    )
    {
    printf ("\n");

    while (isascii ((UINT) * string) && (isprint ((UINT) * string) ||
						isspace ((UINT) * string)))
	printf ("%c", * string++);

    printf ("\n");
    }

/******************************************************************************
*
* getArg - get argument from command line
*
*
* RETURNS: OK or ERROR
*/

LOCAL STATUS getArg 
    (
    FAST char **ppString,	/* ptr to ptr to current position in line */
    int *	pValue,		/* ptr where to return value */
    BOOL	defaultHex,	/* TRUE = arg is hex (even w/o 0x) */
    BOOL	optional	/* TRUE = ok if end of line */
    )
    {
    skipSpace (ppString);


    /* if nothing left, complain if arg is not optional */

    if (**ppString == EOS)
	{
	if (!optional)
	    {
	    printf ("missing parameter\n");
	    return (ERROR);
	    }
	else
	    return (OK);
	}


    /* scan arg */

    if (bootScanNum (ppString, pValue, defaultHex) != OK)
	{
	printf ("invalid parameter\n");
	return (ERROR);
	}

    skipSpace (ppString);


    if (**ppString == ',')
	{
	++*ppString;
	return (OK);
	}


    if (**ppString == EOS)
	return (OK);


    printf ("invalid parameter\n");
    return (ERROR);
    }


/* The following routines are common to bootConfig and usrConfig and will
 * eventually be merged
 */


LOCAL void usrBootLineInit 
    (
    int startType
    )
    {
    if (startType & BOOT_CLEAR)
	{
	    if ((sysRomGet (BOOT_LINE_ADRS, ROM_PARA_LEN, ROM_PARA_OFFSET) == ERROR) ||
	    (*BOOT_LINE_ADRS == EOS) || (*BOOT_LINE_ADRS == (char) -1))
	    {
	    strcpy (BOOT_LINE_ADRS, DEFAULT_BOOT_LINE);
	    }
	}
    }
/******************************************************************************
*
* usrBootLineCrack - interpret and verify boot line
*
* RETURNS: OK or ERROR
*/

LOCAL STATUS usrBootLineCrack 
    (
    char *	 bootString,
    BOOT_PARAMS *pParams
    )
    {
    FAST char *	pS;

    pS = bootStringToStruct (bootString, pParams);

    if (*pS != EOS)
	{
	bootParamsErrorPrint (bootString, pS);
	return (ERROR);
	}

#ifdef  INCLUDE_NETWORK
    /* check inet addresses */

    if ((checkInetAddrField (pParams->ead, TRUE) != OK) ||
	(checkInetAddrField (pParams->bad, TRUE) != OK) ||
	(checkInetAddrField (pParams->had, FALSE) != OK) ||
	(checkInetAddrField (pParams->gad, FALSE) != OK))
	{
	return (ERROR);
	}
#endif  /* INCLUDE_NETWORK */

    return (OK);
    }

#ifdef  INCLUDE_NETWORK

/******************************************************************************
*
* checkInetAddrField - check for valid inet address in boot field
*/

LOCAL STATUS checkInetAddrField 
    (
    char *pInetAddr,
    BOOL subnetMaskOK
    )
    {
    char inetAddr [30];
    int netmask;


    bzero (inetAddr, sizeof(inetAddr));

    if (*pInetAddr == EOS)
	return (OK);

    strncpy (inetAddr, pInetAddr, sizeof (inetAddr) - 1);

    if (subnetMaskOK)
	{
	if (bootNetmaskExtract (inetAddr, &netmask) < 0)
	    {
	    printf ("Error: invalid netmask in boot field \"%s\".\n", inetAddr);
	    return (ERROR);
	    }
	}

    if (inet_addr (inetAddr) == (ULONG) ERROR)
	{
	printf ("Error: invalid inet address in boot field \"%s\".\n",inetAddr);
	return (ERROR);
	}

    return (OK);
    }

/******************************************************************************
*
* RETURNS: OK or ERROR
*/

LOCAL STATUS usrNetIfAttach 
    (
    char *devName,
    int  unitNum,
    char *inetAdrs
    )
    {
    FAST NETIF *	pNif;
    STATUS 		status;
    char                buf [BOOT_DEV_LEN];     /* network device */

#ifdef  INCLUDE_PCMCIA
    int sock;

    if (strncmp (devName, "pcmcia", 6) == 0)
	{
	if (strlen (devName) == 6)
	    return (ERROR);
	else
	    sscanf (devName, "%*6s%*c%d", &sock);
	*(devName + 6) = EOS;
	}
#endif  /* INCLUDE_PCMCIA */

    sprintf(buf, "%s%d", devName, unitNum);

    for (pNif = netIf; pNif->ifName != 0; pNif++)
	{
	if (strcmp (buf, pNif->ifName) == 0)
	    break;
	}

    if (pNif->ifName == 0 && unitNum == 0)
        {
        for (pNif = netIf; pNif->ifName != 0; pNif++)
            {
            if (strcmp (devName, pNif->ifName) == 0)
                break;
            }
        }

    if (pNif->ifName == 0)
	{
	printf ("Network interface %s unknown.\n", devName);
	return (ERROR);
	}

    if (pNif->attachRtn == NULL)
        {
	printf ("Network interface %s has no attach routine.\n", devName);
	return (OK);
	}

    printf ("Attaching network interface %s... ", buf);

#ifdef	INCLUDE_PCMCIA
    if (strncmp (devName, "pcmcia", 6) == 0)
	pNif->arg1 = (char *)sock;
#endif	/* INCLUDE_PCMCIA */

#if defined (TARGET_VIP10)
        if (strcmp (devName, "lnsgi") == 0)
            {
            IMPORT char lnsgiEnetAddr [];     

            u_long inet = inet_addr (inetAdrs);
            lnsgiEnetAddr [4] = (inet >> 8) & 0xff;
            lnsgiEnetAddr [5] = inet & 0xff;
            }
#endif  /* TARGET_VIP10 */

    status = pNif->attachRtn (unitNum, pNif->arg1, pNif->arg2, pNif->arg3,
			      pNif->arg4, pNif->arg5, pNif->arg6, pNif->arg7, 
                              pNif->arg8);
    if (status != OK)
	{
        if (errno == S_iosLib_CONTROLLER_NOT_PRESENT)
            printf ("failed.\nError: S_iosLib_CONTROLLER_NOT_PRESENT.\n");
        else if (errno == S_iosLib_INVALID_ETHERNET_ADDRESS)
	    printf ("failed: S_iosLib_INVALID_ETHERNET_ADDRESS, use N command\n");
	else
	    printf ("failed: errno = %#x.\n", errno);
	return (ERROR);
	}

    printf ("done.\n");

    return (OK);
    }

/******************************************************************************
*
*/

LOCAL STATUS usrNetIfConfig 
    (
    char *	devName,		
    int         unitNum,                
    char *	inetAdrs,		
    char *	inetName,		
    int 	netmask			
    )
    {
    char 	ifname [20];

#ifdef	INCLUDE_PCMCIA
    if (strncmp (devName, "pcmcia", 6) == 0)
	devName = "pcmcia";
#endif	/* INCLUDE_PCMCIA */


    if (inetAdrs[0] == EOS)
	{
	printf ("No inet address specified for interface %s.\n", devName);
	return (ERROR);
	}


    sprintf (ifname, "%s%d", devName, unitNum);

    if (netmask != 0)
	ifMaskSet (ifname, netmask);

    if (ifAddrSet (ifname, inetAdrs) != OK)
        {
        printf ("Error setting inet address of %s to %s, errno = %#x\n",
                ifname, inetAdrs, errno);
        return (ERROR);
        }

    if ((inetName != NULL) && (*inetName != EOS))
	hostAdd (inetName, inetAdrs);

    return (OK);
    }

/******************************************************************************
*
* RETURNS: OK if successful otherwise ERROR
*/

LOCAL STATUS usrBpInit 
    (
    char *	devName,	
    int         unitNum,      
    u_long	startAddr	
    )
    {
#ifdef	INCLUDE_SM_NET
    char *		bpAnchor;	
    FAST NETIF *	pNif;		
    STATUS 		status;		
    int			procNum;	
    char                buf [BOOT_DEV_LEN];     

    if ((strncmp (devName, "bp=", 3) == 0) ||
        (strncmp (devName, "sm=", 3) == 0))
	{
	if (bootBpAnchorExtract (devName, &bpAnchor) < 0)
	    {
	    printf ("Invalid anchor address specified: \"%s\"\n", devName);
	    return (ERROR);
	    }
	}
    else
	bpAnchor = SM_ANCHOR_ADRS;		/* default anchor */

    procNum = sysProcNumGet ();


    if (procNum == 0)
	{
	printf ("Initializing backplane net with anchor at %#x... ",
		(int) bpAnchor);

	status = smNetInit ((SM_ANCHOR *) bpAnchor, (char *) SM_MEM_ADRS,
                            (int)SM_MEM_SIZE, SM_TAS_TYPE, SM_CPUS_MAX,
                            SM_PKTS_SIZE, startAddr);

	if (status == ERROR)
  	    {
	    printf ("Error: backplane device %s not initialized\n", devName);
	    return (ERROR);
	    }

	printf ("done.\n");
	}

    /* Locate NETIF structure for backplane */
    sprintf(buf, "%s%d", devName, unitNum);

    for (pNif = netIf; pNif->ifName != 0; pNif++)
   	{
	if (strcmp (buf, pNif->ifName) == 0)
	    break;
	}

    if (pNif->ifName == 0 && unitNum == 0)
        {
        for (pNif = netIf; pNif->ifName != 0; pNif++)
            {
            if (strcmp (devName, pNif->ifName) == 0)
                break;
            }
        }

    if (pNif->ifName == 0)
	return (ERROR);

    printf ("Backplane anchor at %#x... ", (int) bpAnchor);


    pNif->arg1 = bpAnchor;		
    pNif->arg2 = SM_MAX_PKTS;
    pNif->arg3 = SM_INT_TYPE;
    pNif->arg4 = SM_INT_ARG1;
    pNif->arg5 = SM_INT_ARG2;
    pNif->arg6 = SM_INT_ARG3;
    pNif->arg7 = SM_MASTER;
    pNif->arg8 = SM_MAX_WAIT;

    return (OK);
#else	/* INCLUDE_SM_NET */

    printf ("\nError: backplane driver referenced but not included.\n");
    return (ERROR);
#endif	/* INCLUDE_SM_NET */
    }


/*******************************************************************************
*
* RETURNS: OK if successful, otherwise ERROR.
*/

LOCAL STATUS usrSlipInit 
    (
    char *pBootDev,		
    int  unitNum,               
    char *localAddr,		
    char *peerAddr	
    )
    {
#ifdef INCLUDE_SLIP
    char 	slTyDev [20];		
    int		netmask;		

#ifndef SLIP_BAUDRATE
#define SLIP_BAUDRATE 0 
#endif

#ifdef	CSLIP_ENABLE
#undef	CSLIP_ENABLE
#define	CSLIP_ENABLE	TRUE	
#else	/* CSLIP_ENABLE */
#undef	CSLIP_ENABLE
#define	CSLIP_ENABLE	FALSE
#endif	/* CSLIP_ENABLE */

#ifdef	CSLIP_ALLOW
#undef	CSLIP_ALLOW
#define	CSLIP_ALLOW	TRUE	/* enable CSLIP compression on Rx */
#else	/* CSLIP_ALLOW */
#undef	CSLIP_ALLOW
#define	CSLIP_ALLOW	FALSE
#endif	/* CSLIP_ALLOW */

#ifndef SLIP_MTU
#define SLIP_MTU 576
#endif

    if (pBootDev [2] == '=')
	{

	strcpy (slTyDev, &pBootDev [3]);
	pBootDev [2] = EOS;
	}
    else
	{
	/* construct the default SLIP tty device */

	sprintf (slTyDev, "%s%d", "/tyCo/", SLIP_TTY);
	}

    printf ("Attaching network interface sl%d... ", unitNum);

    bootNetmaskExtract (localAddr, &netmask); /* remove and ignore mask */

    if (slipInit (unitNum, slTyDev, localAddr, peerAddr, SLIP_BAUDRATE,
	          CSLIP_ENABLE, CSLIP_ALLOW, SLIP_MTU) == ERROR)
	{
	printf ("\nslipInit failed 0x%x\n", errno);
	return (ERROR);
	}

    printf ("done.\n");
    return (OK);

#else /* INCLUDE_SLIP */
    printf ("\nError: slip not included.\n");
    return (ERROR);
#endif	/* INCLUDE_SLIP */
    }


/*******************************************************************************
*
* usrPPPInit - initialize a ppp channel
*
* RETURNS: OK if successful, otherwise ERROR.
*/

LOCAL STATUS usrPPPInit (pBootDev, unitNum, localAddr, peerAddr)
    char *      pBootDev;               /* boot device */
    int         unitNum;                /* unit number */
    char *      localAddr;              /* local address */
    char *      peerAddr;               /* peer address */
    {
#ifdef INCLUDE_PPP
    PPP_INFO    pppInfo;
    PPP_OPTIONS *pOptions = NULL;
    char        pppTyDev [20];          /* ppp device */
#ifdef PPP_BAUDRATE
    int		pppBaudRate = PPP_BAUDRATE;	/* ppp baud rate */
#else
    int		pppBaudRate = 0;		/* ppp baud rate */
#endif	/* PPP_BAUDRATE */
    char *	pBaudStr;		/* ppp boot string */
    int         netmask;                /* netmask */
    int		sysRate = sysClkRateGet();
    int		ix;

#ifdef  PPP_OPTIONS_STRUCT  
    pOptions = &pppOptions;
#endif  /* PPP_OPTIONS_STRUCT */
     
    if ((pBaudStr = strpbrk (pBootDev, ",")) != NULL)
        {
	*pBaudStr++ = EOS;
	pppBaudRate = atoi (pBaudStr);
	}

    if (pBootDev [3] == '=')
        {
        strcpy (pppTyDev, &pBootDev [4]);
        pBootDev [3] = EOS;
        }
    else 
        {
        sprintf (pppTyDev, "%s%d", "/tyCo/", PPP_TTY);
        }

    printf ("Attaching network interface ppp%d...\n", unitNum);

    bootNetmaskExtract (localAddr, &netmask); /* remove and ignore mask */

    if (pppInit (unitNum, pppTyDev, localAddr, peerAddr, pppBaudRate,
		 pOptions, PPP_OPTIONS_FILE) == ERROR)
        {
        printf ("\npppInit failed 0x%x\n", errno);
        return (ERROR);
        }

    /* wait for PPP link to be established */

    for (ix = 0; ix < PPP_CONNECT_DELAY; ix++)
	{
	taskDelay (sysRate);

        if ((pppInfoGet (unitNum, &pppInfo) == OK) &&
	    (pppInfo.ipcp_fsm.state == OPENED))
           break;
	}

    if (ix == PPP_CONNECT_DELAY) 
        {
        pppDelete (unitNum);                   /* kill the interface */ 
	printf ("ppp0: timeout: could not establish link with peer.\n");
	return (ERROR);
	}

    printf ("done.\n");
    return (OK);

#else /* INCLUDE_PPP */
    printf ("\nError: ppp not included.\n");
    return (ERROR);
#endif  /* INCLUDE_PPP */
    }

#ifdef INCLUDE_BOOTP
/******************************************************************************
*
*
* ERRNO: N/A
*
* 
*/

LOCAL STATUS bootpGet 
    (
    char *pNetDev,		
    char *pBootDevAddr,		
    char *pBootFile,		
    char *pHostAddr,		
    int  *pMask 		
    )
    {
#ifndef INCLUDE_DHCPC
    struct bootpParams 		bootParams;    
    struct in_addr 		clntAddr; 
    struct in_addr 		hostAddr; 	
    int 			subnetMask;	
    struct ifnet *              pIf;            

    char	bootServer [INET_ADDR_LEN];/* boot server */

    subnetMask 	      = 0;

    bzero ( (char *)&clntAddr, sizeof (struct in_addr));
    bzero ( (char *)&hostAddr, sizeof (struct in_addr));
    bzero (bootServer, INET_ADDR_LEN);
    bzero ((char *)&bootParams, sizeof (struct bootpParams));

    pIf = ifunit (pNetDev);
    if (pIf == NULL)
	return (ERROR);


    if ( (strncmp (pNetDev, "bp", 2) == 0) || 
            (strncmp (pNetDev, "sm", 2) == 0))
	{
	if (pBootDevAddr [0] == EOS)
	    return (ERROR);

        clntAddr.s_addr = inet_addr (pBootDevAddr);
        if (clntAddr.s_addr == (ULONG)ERROR)
            return (ERROR);
	}


    bootParams.netmask = (struct in_addr *)&subnetMask;

    printf ("Getting boot parameters via network interface %s", pNetDev);

    if (bootpLibInit (BOOTP_MAX_HDRSIZE) == ERROR)
        return (ERROR);

    if (bootpParamsGet (pIf, BOOTP_MAX_REQUESTS, &clntAddr, &hostAddr,
		        NULL, pBootFile, &bootParams) == ERROR)
	return (ERROR);

    inet_ntoa_b (hostAddr, bootServer);

    printf ("\nBootp Server:%s\n", bootServer);

    if (pBootFile [0] == EOS)
	return (ERROR);				

    printf ("    Boot file: %s\n", pBootFile);


    if (pHostAddr [0] == EOS)			
	{
	strncpy (pHostAddr, bootServer, INET_ADDR_LEN);
	printf ("    Boot host: %s\n", pHostAddr);
	}


    if (pBootDevAddr [0] == EOS)		/* fill in inet address */
	{
        inet_ntoa_b (clntAddr, pBootDevAddr);
	printf ("    Boot device Addr (%s): %s\n", pNetDev, pBootDevAddr);
	}


    if ((*pMask == 0) && (subnetMask != 0))
	{
        *pMask = ntohl (subnetMask);
	printf ("    Subnet mask: 0x%x\n", *pMask);
	}

    return (OK);
#else
    return (OK);          
#endif /* INCLUDE_DHCPC */
    }
#endif /* INCLUDE_BOOTP */

#ifdef INCLUDE_DHCPC
/******************************************************************************
*
* RETURNS: OK if successful, or ERROR otherwise.
*
* ERRNO: N/A
*
* SEE ALSO: dhcpcBootLib, RFC 1541
*/

LOCAL STATUS dhcpGet
    (
    char * 		pNetDev, 	
    char * 		pBootDevAddr, 	
    char * 		pBootFile, 	
    char * 		pHostAddr, 
    int * 		pMask, 		
    char *pGateway,
    DHCP_LEASE_DATA * 	pDhcpLease 	
    )
    {
    STATUS 		result;
    struct ifnet * 	pIf; 		
    char 		serverAddr [INET_ADDR_LEN];   
    char 		bootFile [BOOT_FILE_LEN]; 	
    int 		subnetMask; 			
    void *              pCookie;
    unsigned long	duration;
    char buf[30];

    struct dhcp_param  bootParams;
	
	struct in_addrs routerStruct; 
	struct in_addr routerAddress;


    bzero (serverAddr, INET_ADDR_LEN);
    bzero ( (char *)&bootParams, sizeof (struct dhcp_param));
 

    bootParams.file = bootFile;
    bootParams.subnet_mask = (struct in_addr *)&subnetMask;

	bzero ( (char *) &routerAddress, sizeof (struct in_addr));
	routerStruct.num = 1;
	routerStruct.addr = &routerAddress;
	bootParams.router = &routerStruct;

    if ( (strncmp (pNetDev, "bp", 2) == 0) || 
            (strncmp (pNetDev, "sm", 2) == 0))
        {
        if (pBootDevAddr [0] == EOS)
            return (ERROR);
        }

    pIf = ifunit (pNetDev);
    if (pIf == NULL)
        return (ERROR);

    printf ("Getting boot parameters via network interface %s.\n", pNetDev);

    /* Setup client to retrieve address information from a DHCP server. */

    pCookie = dhcpcBootInit (pIf, DHCPC_SPORT, DHCPC_CPORT, DHCPC_MAX_MSGSIZE,
		             DHCPC_OFFER_TIMEOUT, DHCPC_DEFAULT_LEASE,
                             DHCPC_MIN_LEASE );
    if (pCookie == NULL)
        {
        printf ("Error initializing DHCP client.\n");
        return (ERROR);
        }

#if (DHCPC_DISCOVER_RETRIES) 
    dhcpcDiscoverRetries = DHCPC_DISCOVER_RETRIES;
#endif

    duration = htonl(pDhcpLease->lease_duration); 
    dhcpcOptionAdd (pCookie, _DHCP_LEASE_TIME_TAG, sizeof (int),
                    (UCHAR *)&duration);
	
	dhcpcOptionSet (pCookie, _DHCP_ROUTER_TAG);
	
    if (pBootDevAddr[0] == EOS)
        {
 
        result = dhcpcBootBind ();
        if (result != OK)
            return (ERROR);
        }
    else
        {
 
        result = dhcpcBootInformGet (pBootDevAddr);
 
        if (result != OK)
            {
            if (pBootFile[0] == EOS)
                return (ERROR);
            else
                return (OK);
            }
        }

    result = dhcpcBootParamsGet (&bootParams);
    if (result == ERROR)
      return (ERROR);


    if (pBootDevAddr[0] == EOS)
        {
 
        bcopy ( (char *)&bootParams.yiaddr, (char *)&pDhcpLease->yiaddr,
               sizeof (struct in_addr));
        pDhcpLease->lease_duration = bootParams.lease_duration;
        pDhcpLease->lease_origin = bootParams.lease_origin;
        }

    inet_ntoa_b (bootParams.server_id, serverAddr);
    printf ("\nDHCP Server:%s\n", serverAddr);

    if (pBootFile [0] == EOS && bootFile[0] == EOS)
        return (ERROR);                        

    if (bootFile[0] != EOS)                     
        {
        bcopy (bootFile, pBootFile, BOOT_FILE_LEN);
        printf ("    Boot file: %s\n", pBootFile);
        }

    if (pHostAddr [0] == EOS)                 
        {
        inet_ntoa_b (bootParams.siaddr, pHostAddr);
        printf ("    Boot host: %s\n", pHostAddr);
        }

	if(pGateway [0] == EOS && routerAddress.s_addr != 0)
	{
		inet_ntoa_b (routerAddress, pGateway);
		printf ("Gateway: %s\n", pGateway);
		sprintf(IP_PARAMS.gatewayinfo, "%s", pGateway);
	}



    if (pBootDevAddr [0] == EOS)                /* fill in inet address */
        {

        inet_ntoa_b (bootParams.yiaddr, pBootDevAddr);
        printf ("    Boot device Addr (%s): %s\n", pNetDev, pBootDevAddr);
        sprintf(IP_PARAMS.ipadrinfo, "%s", pBootDevAddr);
        }

    if ( (*pMask == 0) && (subnetMask != 0))
        {
        *pMask = ntohl (subnetMask);
        printf ("    Subnet mask: 0x%x\n", *pMask);
        IP_PARAMS.netmaskshowinfo = *pMask;
        sprintf(buf,":%x",IP_PARAMS.netmaskshowinfo);
        strcat(IP_PARAMS.ipadrinfo,buf);
        }
    SST39VF160_ChipProg(0x3F000,&(IP_PARAMS),sizeof(IP_PARAMS));
    return (OK);
    }
#endif             /* INCLUDE_DHCPC */

#ifdef ETHERNET_ADR_SET
/*******************************************************************************
*
* mEnet - modify the last three bytes of the ethernet address
*
* RETURNS: void
*
* NOMANUAL
*/

void mEnet 
    (
    char * 	pNum   /* Boot line, including unit number. */
    )
    {
    uchar_t byte [MAX_ADR_SIZE];	/* array to hold new Enet addr */
    uchar_t curArr [MAX_ADR_SIZE];	/* array to hold current Enet addr */
    char line [MAX_LINE + 1];
    char *pLine;		/* ptr to current position in line */
    int value;			/* value found in line */
    char excess;
    char *buf;
    int unitNum;
    int ix;

    /* Search for unit number of network device. */

    buf = pNum;
    if (bootScanNum (&buf, &unitNum, FALSE) != OK)  /* Use 0 if no unit #. */
        unitNum = 0;

    sysEnetAddrGet (unitNum, curArr);
    printf ("Current Ethernet Address is: ");

#if _BYTE_ORDER == _BIG_ENDIAN
    printf ("%02x:%02x:%02x:%02x:%02x:%02x\n", curArr[5], 
	    curArr[4], curArr[3], curArr[2], 
	    curArr[1], curArr[0]);
    byte[5] = ((ENET_DEFAULT & 0x0000ff00) >> 8);
    byte[4] = ((ENET_DEFAULT & 0x00ff0000) >> 16);
    byte[3] = ((ENET_DEFAULT & 0xff000000) >> 24);
    byte[2] = curArr[2];
    byte[1] = curArr[1];
    byte[0] = curArr[0];
#else  /* _BYTE_ORDER == _LITTLE_ENDIAN  */
    printf ("%02x:%02x:%02x:%02x:%02x:%02x\n", curArr[0], 
	    curArr[1], curArr[2], curArr[3], 
	    curArr[4], curArr[5]);
    byte[5] = ((ENET_DEFAULT & 0x00ff0000) >> 16);
    byte[4] = ((ENET_DEFAULT & 0x0000ff00) >> 8);
    byte[3] = (ENET_DEFAULT & 0x000000ff);
    byte[2] = curArr[3];
    byte[1] = curArr[4];
    byte[0] = curArr[5];
#endif /* _BYTE_ORDER == _BIG_ENDIAN */

    printf ("Modify only the last 3 bytes (board unique portion) of Ethernet Address.\n");
    printf ("The first 3 bytes are fixed at manufacturer's default address block.\n");

    for (ix = 5; ix > 2; ix--)
        printf ("%02x- %02x\n", byte[ix], byte[ix]);


    /* start on fourth byte of enet addr */
    for (ix = 2; ix >= 0; ix --)	
	{
	/* prompt for substitution */

	printf ("%02x- ", byte[ix]);

	/* get substitution value:
	 *   skip empty lines (CR only);
	 *   quit on end of file or invalid input;
	 *   otherwise put specified value at address */

	if (fioRdString (STD_IN, line, MAX_LINE) == EOF)
	    break;

	line [MAX_ADR_SIZE] = EOS;	/* make sure input line has EOS */

	for (pLine = line; isspace ((int) *pLine); ++pLine)	/* skip leading spaces*/
	    ;

	if (*pLine == EOS)			/* skip field if just CR */
	    continue;

	if (sscanf (pLine, "%x%1s", &value, &excess) != 1)
	    break;				/* quit if not number */

	byte[ix]  = (uchar_t)value;		/* assign new value */
	}

    printf ("\n");

    sysEnetAddrSet (byte[5], byte[4], byte[3], byte[2], byte[1], byte[0]);

    printf ("New Ethernet Address is: ");
#if _BYTE_ORDER == _BIG_ENDIAN
    for (ix = 5; ix > 0; ix--)
        printf ("%02x:", byte[ix]);
    printf ("%02x\n", byte[0]);
#else  /* _BYTE_ORDER == _LITTLE_ENDIAN */
    for (ix = 5; ix > 0; ix--)
        printf ("%02x:", byte[ix]);
    printf ("%02x\n", byte[0]);
#endif /* _BYTE_ODER == _BIG_ENDIAN */
    }
#endif  /* ETHERNET_ADR_SET */

/*******************************************************************************
*
* RETURNS: OK, or ERROR if the protocol initialization fails
*
* NOMANUAL
*/

LOCAL STATUS usrNetProtoInit (void)
    {
    ipLibInit (&ipCfgParams);		
    rawIpLibInit ();                  
    rawLibInit ();

#ifdef INCLUDE_UDP
    udpLibInit (&udpCfgParams);         
#endif

#ifdef INCLUDE_TCP
    tcpLibInit (&tcpCfgParams);        
#endif

#ifdef INCLUDE_ICMP
    icmpLibInit (&icmpCfgParams);       
#endif

#ifdef INCLUDE_IGMP
    igmpLibInit ();                    
#endif

    return (OK);
    }


#endif  /* INCLUDE_NETWORK */

int netInit(char *   bootString)
{
		
	BOOT_PARAMS		params;
#ifdef  INCLUDE_NETWORK
    char		nad [20];	
    int			netmask = 0;	
    int 		result; 	
    unsigned long 	leaseLen; 	

#ifdef INCLUDE_DHCPC
    DHCP_LEASE_DATA dhcpLease;
#endif  /* INCLUDE_DHCPC */
    char		buf [30];	
    char 		netDev [BOOT_DEV_LEN + 1];
    char 		bootDev [BOOT_DEV_LEN];
    BOOL		backplaneBoot = FALSE;
	char *		pBootAddr;
    BOOL 		attached = FALSE; /* driver is attached */
    char                icmpPeer [BOOT_ADDR_LEN];

    int i;
    
#ifdef INCLUDE_END
    char		muxDevName[8];
#endif /* INCLUDE_END */

	if (usrBootLineCrack (bootString, ¶ms) != OK)	
		return (ERROR);
		
  if((IP_PARAMS.ipadrinfo[0]!=0)||(IP_PARAMS.ipadrinfo[1]!=0)||(IP_PARAMS.ipadrinfo[2]!=0)||(IP_PARAMS.ipadrinfo[3]!=0)||(IP_PARAMS.ipadrinfo[4]!=0)||(IP_PARAMS.ipadrinfo[5]!=0)||
  	(IP_PARAMS.ipadrinfo[6]!=0)||(IP_PARAMS.ipadrinfo[7]!=0)||(IP_PARAMS.ipadrinfo[8]!=0)||(IP_PARAMS.ipadrinfo[9]!=0)||(IP_PARAMS.ipadrinfo[10]!=0)||(IP_PARAMS.ipadrinfo[11]!=0)||
  	(IP_PARAMS.ipadrinfo[12]!=0)||(IP_PARAMS.ipadrinfo[13]!=0)||(IP_PARAMS.ipadrinfo[14]!=0)||(IP_PARAMS.ipadrinfo[15]!=0)||(IP_PARAMS.ipadrinfo[16]!=0)||(IP_PARAMS.ipadrinfo[17]!=0)||
  	(IP_PARAMS.ipadrinfo[18]!=0)||(IP_PARAMS.ipadrinfo[19]!=0)||(IP_PARAMS.dhcpflag==1)||(IP_PARAMS.bootpflag==1))

		{
		 sprintf(params.ead, "%s", IP_PARAMS.ipadrinfo);
		 sprintf(params.gad, "%s", IP_PARAMS.gatewayinfo);
		 bootStructToString(BOOT_LINE_ADRS, ¶ms);
		}
		
		else
			{
					sprintf(IP_PARAMS.ipadrinfo, "%s", params.ead);
					sprintf(IP_PARAMS.gatewayinfo, "%s", params.gad);

					SST39VF160_ChipProg(0x3F000,&(IP_PARAMS),sizeof(IP_PARAMS));
			}

	if(IP_PARAMS.dhcpflag==1)	
	{
				
		      for (i = 0; i < 50; ++i)
        		params.ead[i]=0;
        	for (i = 0; i < 30; ++i)
        		params.gad[i]=0;
        	params.flags = 0x40;	
        	bootStructToString(BOOT_LINE_ADRS, ¶ms);
  	}

    if (sockLibInit (NUM_FILES) == ERROR)
        return (ERROR);


#if defined(INCLUDE_BSD) || defined(INCLUDE_BSD_SOCKET)

    if (sockLibAdd ((FUNCPTR) bsdSockLibInit, AF_INET_BSD, AF_INET) == ERROR)
        return (ERROR);
    if (sockLibAdd ((FUNCPTR) bsdSockLibInit, AF_ROUTE, AF_ROUTE) == ERROR)
        return (ERROR);
#endif  /* INCLUDE_BSD || INCLUDE_BSD_SOCKET */



#ifndef DEFAULT_STREAMS_SOCKET
    if (sockLibAdd ((FUNCPTR) bsdSockLibInit, AF_INET, AF_INET) == ERROR)
        return (ERROR);
#endif  /* DEFAULT_STREAMS_SOCKET */

 
    hostTblInit ();		
    usrNetProtoInit ();        
    if (netLibInit () != OK)
        return (ERROR);

#ifdef	INCLUDE_PPP
#ifdef	INCLUDE_PPP_CRYPT 
    cryptRtnInit (&pppCryptRtn);	
#endif	/* INCLUDE_PPP_CRYPT */
#endif	/* INCLUDE_PPP */



    if (strncmp (params.bootDev, "ppp", 3) == 0)
        {

        if (usrPPPInit (params.bootDev, params.unitNum, params.ead, 
                        ((params.gad[0] == EOS)? params.had : params.gad)) 
                        == ERROR)
            return (ERROR);
        }
    else if (strncmp (params.bootDev, "sl", 2) == 0)
        {
        if (usrSlipInit (params.bootDev, params.unitNum, params.ead, 
	                 ((params.gad[0] == EOS)? params.had : params.gad)) 
			 == ERROR)
	    return (ERROR);
        }
    else
	{
        strncpy (bootDev, params.bootDev, sizeof (bootDev));

	if ((strncmp (params.bootDev, "bp", 2) != 0) &&
            (strncmp (params.bootDev, "sm", 2) != 0))
	    {
	    pBootAddr = params.ead;
	    backplaneBoot = FALSE;
	    }
        else
	    {
	    if (sysProcNumGet () == 0)
		{
                printf (
                  "Error: processor number must be non-zero to boot from bp\n");
	        return (ERROR);
                }

	    if (usrBpInit (bootDev, params.unitNum, 0) == ERROR)
		return (ERROR);

	    pBootAddr = params.bad;
	    backplaneBoot = TRUE;
	    }

        /* Save requested lease length, if any. Ignore lease origin value. */

        result = bootLeaseExtract (pBootAddr, &leaseLen, NULL);
        if (result < 0)
            {
            printf ("Error reading target address information.\n");
            return (ERROR);
            }

        /* Handle any lease information attached to the address entry. */

        if (result == 2)
            {
            /* 
             * The current address contains both a duration value and a start
             * time, indicating that it was assigned by a DHCP server.
             */

            if (leaseLen != (ULONG)~0)
                {
                /* Handle a finite address assignment. */

                if (sysFlags & SYSFLG_AUTOCONFIG)
                    *pBootAddr = EOS;    /* Remove for later replacement. */
                else
                    {

                    result = 0;    
                    }
                }
            }


#ifdef INCLUDE_DHCPC

        if (sysFlags & SYSFLG_AUTOCONFIG)
            {

            if (result == 1)
                dhcpLease.lease_duration = leaseLen;
            else
                {

                dhcpLease.lease_duration = DHCPC_DEFAULT_LEASE;
                }
            dhcpLease.lease_origin = 0;
            }
#endif  /* INCLUDE_DHCPC */

        netmask = 0;
        bootNetmaskExtract (pBootAddr, &netmask);


#ifdef INCLUDE_END


        pCookie=findCookie(params.unitNum, bootDev);
	if (!attached && (pCookie != NULL))
	    {
            if (muxDevStart (pCookie) != OK)
                {
                printf("Failed to start device %s\n", bootDev);
                return (ERROR);
                }
	


	    muxAddrResFuncAdd (M2_ifType_ethernet_csmacd, 0x800, ipEtherResolvRtn);

	    if (ipAttach (params.unitNum, bootDev) != OK)
		{
		printf ("Failed to attach TCP/IP to device %s", muxDevName);
		return (ERROR);
		}

	    printf ("Attached TCP/IP interface to %s%d.\n", bootDev,
		     params.unitNum);

	    attached = TRUE;
	    }
#endif /*INCLUDE_END*/	

#ifdef INCLUDE_BSD


        if (!attached)
	    {
	    if (usrNetIfAttach (bootDev, params.unitNum, pBootAddr) == OK)
		{
		attached = TRUE;
		}
	    else
		return ERROR;
	    }
            
#endif /* INCLUDE_BSD */

	if (!attached)
	    return ERROR;	/* attachment failed */


        sprintf (netDev, "%s%d", bootDev, params.unitNum);

        if ( (sysFlags & SYSFLG_AUTOCONFIG) || (sysFlags & SYSFLG_PROXY) ||
            (netmask == 0))
            {
            struct ifnet *	pIf;
                
                
            if ( (pIf = ifunit (netDev)) == NULL) 
                {
                printf ("invalid device \"%s\"\n", netDev);
                return (ERROR);			
                }
                
            if (pIf->if_init != NULL)
                {
                if ( (*pIf->if_init) (pIf->if_unit) != 0)
                    {
                    printf ("initialization failed for device \"%s\"\n",netDev);
                    return (ERROR);
                    }
                }
            }

#ifdef INCLUDE_SM_NET
 	if (backplaneBoot)
	    {
	    if ((params.bad [0] == EOS) &&
	    	(strncmp (bootDev, "sm", 2) == 0) &&
		(smNetInetGet (netDev, params.bad, NONE) == OK))
	    	printf ("Backplane inet address: %s\n", params.bad);

	    if (params.bad [0] == EOS) 
	    	{
	    	printf ("no backplane address specified\n");
		return (ERROR);
		}

	    if ((sysFlags & SYSFLG_AUTOCONFIG) && !(sysFlags & SYSFLG_PROXY))
	        {
#ifdef INCLUDE_DHCPC
	        printf ("Warning! DHCP over backplane may need proxy arp\n");
#else
	        printf ("Warning! BOOTP over backplane may need proxy arp\n");
#endif
	        }
	    }
#endif /* INCLUDE_SM_NET */


	if (sysFlags & SYSFLG_PROXY)
	    {
#ifdef INCLUDE_PROXY_CLIENT
            printf ("registering proxy client: %s...", pBootAddr);

            if (proxyReg (netDev, pBootAddr) == ERROR)
                {
                printf ("failed: error %x\n", errno);
                return (ERROR);
                }
            printf ("done.\n");
#else /* INCLUDE_PROXY_CLIENT */
            printf ("proxy client requested but not included.\n");
            return (ERROR);
#endif /* INCLUDE_PROXY_CLIENT */
            }


        if (sysFlags & SYSFLG_AUTOCONFIG)
            {

#ifndef INCLUDE_BOOTP
#ifndef INCLUDE_DHCPC

            printf ("automatic address assignment requested but not included.\n");
            return (ERROR);
#endif /* INCLUDE_DHCPC */
#endif /* INCLUDE_BOOTP */

#ifdef INCLUDE_BOOTP
            if (bootpGet (netDev, pBootAddr, params.bootFile, params.had,
                          &netmask) == ERROR)
                return (ERROR);
#endif /* INCLUDE_BOOTP */

#ifdef INCLUDE_DHCPC
            if (dhcpGet (netDev, pBootAddr, params.bootFile, params.had,
                         &netmask, params.gad, &dhcpLease) == ERROR)
                return (ERROR);
#endif      /* INCLUDE_DHCPC */
            }

        /* configure the device */
		
        if (usrNetIfConfig (bootDev, params.unitNum, pBootAddr, 
                            (char *) NULL, netmask) != OK)
            return (ERROR);


        if (netmask == 0)
            {
	    if (params.gad [0] == EOS)
                strcpy (icmpPeer, params.had);
            else
	        strcpy (icmpPeer, params.gad);

            (void) icmpMaskGet (netDev, pBootAddr, backplaneBoot ?
                                NULL : icmpPeer, &netmask);

            if (netmask != 0)
                {
                sprintf (bootDev, "%s%d", bootDev, params.unitNum);
                ifMaskSet (bootDev, netmask);
		printf ("Obtained subnet mask 0x%x from %s.\n", netmask,
			icmpPeer);
                }
	    else
	        printf ("Warning: no netmask specified.\n");
            }


#ifdef INCLUDE_SM_NET
	if (backplaneBoot && (params.gad [0] == EOS) && 
	    !(sysFlags & SYSFLG_PROXY))
	    {
	        struct in_addr host;		
	        struct in_addr backpl;		

	        host.s_addr = inet_addr (params.had);
	        backpl.s_addr = inet_addr (params.bad);

	        if ( in_netof(host) != in_netof(backpl) )
	        {

	        if ((strncmp (bootDev, "sm", 2) == 0) && 
	            (smNetInetGet (netDev, params.gad, 0) == OK))
		    printf ("Gateway inet address: %s\n", params.gad);
		}
	    }
#endif /* INCLUDE_SM_NET */

        if (netmask != 0)		
            {
            sprintf (buf, ":%x", netmask);
            strcat  (pBootAddr, buf);
            }


        if (!(sysFlags & SYSFLG_AUTOCONFIG) && result == 1)
            {

            if (netmask == 0) 	
                sprintf (buf, "::%lx", leaseLen);
            else 		
                sprintf(buf, ":%lx", leaseLen);

            strcat (pBootAddr, buf);
            }

#ifdef INCLUDE_DHCPC

        if (sysFlags & SYSFLG_AUTOCONFIG)
            {

            if (dhcpcBindType == DHCP_NATIVE)
                {
                if (netmask == 0) 	
                    sprintf (buf, "::%lx:%lx", dhcpLease.lease_duration, 
                                               dhcpLease.lease_origin);
                else 		
                    sprintf(buf, ":%lx:%lx", dhcpLease.lease_duration, 
                                             dhcpLease.lease_origin);
                strcat (pBootAddr, buf);
                }
            }
#endif    /* INCLUDE_DHCPC */

        bootStructToString (BOOT_LINE_ADRS, ¶ms);
        }

    usrNetIfAttach ("lo", 0, "127.0.0.1");
    usrNetIfConfig ("lo", 0, "127.0.0.1", "localhost", 0);


    if (params.gad[0] != EOS)
        {
	if (routeAdd("0.0.0.0", params.gad)== ERROR)
	printf("Error adding gateway as default route.\n");

        }



    hostAdd (params.hostName, params.had);
	return OK;
#else
	return ERROR;
#endif  /* INCLUDE_NETWORK */    
}