bootConfig.c
资源名称:bcm4702.rar [点击查看]
上传用户:yuanda199
上传日期:2022-06-26
资源大小:412k
文件大小:169k
源码类别:
VxWorks
开发平台:
C/C++
- {
- printf ("nError loading file: errno = 0x%x.n", errno);
- return (ERROR);
- }
- 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 */
- #ifdef BROADCOM_BSP
- /*****************************************************************************
- * netLoadInit - Attach the network to the point where ftpXfer will work.
- */
- LOCAL BOOL netLoadInited = FALSE;
- LOCAL STATUS netLoadInit(char *bootString)
- {
- BOOT_PARAMS params;
- char nad [20]; /* host's network internet addr */
- int netmask = 0; /* temporary storage */
- int result; /* classification of address string */
- unsigned long leaseLen; /* lease length field (optional) */
- #ifdef INCLUDE_DHCPC
- DHCP_LEASE_DATA dhcpLease;
- #endif /* INCLUDE_DHCPC */
- char buf [30]; /* string of netmask and timestamps */
- char netDev [BOOT_DEV_LEN + 1];
- char bootDev [BOOT_DEV_LEN];
- BOOL backplaneBoot;
- char * pBootAddr;
- #ifdef INCLUDE_END
- char muxDevName[8];
- #endif /* INCLUDE_END */
- if (netLoadInited)
- return OK;
- netLoadInited = TRUE;
- /* interpret boot command */
- if (usrBootLineCrack (BOOT_LINE_ADRS, ¶ms) != OK)
- return (ERROR);
- /* set our processor number: may establish vme access, etc. */
- sysFlags = params.flags;
- sysProcNumSet (params.procNum);
- /* start the network */
- /* initialize the generic socket library */
- if (sockLibInit (NUM_FILES) == ERROR)
- return (ERROR);
- #if defined(INCLUDE_STREAMS) || defined(INCLUDE_STREAMS_ALL)
- if (usrStrmInit() == ERROR) /* init Streams subsystem */
- return (ERROR);
- #endif
- #if defined(INCLUDE_BSD) || defined(INCLUDE_BSD_SOCKET)
- /* add the BSD socket library interface */
- 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 */
- /* install default socket library interface */
- #ifndef DEFAULT_STREAMS_SOCKET
- if (sockLibAdd ((FUNCPTR) bsdSockLibInit, AF_INET, AF_INET) == ERROR)
- return (ERROR);
- #endif /* DEFAULT_STREAMS_SOCKET */
- hostTblInit (); /* initialize host table */
- usrNetProtoInit (); /* initialize various protocols */
- netLibInit ();
- #ifdef INCLUDE_PPP
- #ifdef INCLUDE_PPP_CRYPT
- cryptRtnInit (&pppCryptRtn); /* install crypt() routine */
- #endif /* INCLUDE_PPP_CRYPT */
- #endif /* INCLUDE_PPP */
- /* attach and configure boot interface */
- if (strncmp (params.bootDev, "ppp", 3) == 0)
- {
- /* booting via ppp */
- 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 bpn");
- 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 != ~0)
- {
- /* Handle a finite address assignment. */
- if (sysFlags & SYSFLG_AUTOCONFIG)
- *pBootAddr = EOS; /* Remove for later replacement. */
- else
- {
- /*
- * Technically, this address is invalid since it contains
- * a finite interval that requires DHCP for verification
- * and the automatic configuration flag is not set.
- * However, this situation can only occur if caused
- * deliberately by the user. So, just ignore the timing
- * information and assign the address permanently.
- */
- result = 0; /* Prevents restoration of time values. */
- }
- }
- }
- #ifdef INCLUDE_DHCPC
- /* Set the DHCP lease information, if needed. */
- if (sysFlags & SYSFLG_AUTOCONFIG)
- {
- /* Save the requested lease length if entered by the user. */
- if (result == 1)
- dhcpLease.lease_duration = leaseLen;
- else
- {
- /*
- * The lease length is either not present or left over from
- * an earlier lease. Use the default value.
- */
- dhcpLease.lease_duration = DHCPC_DEFAULT_LEASE;
- }
- dhcpLease.lease_origin = 0;
- }
- #endif /* INCLUDE_DHCPC */
- netmask = 0;
- bootNetmaskExtract (pBootAddr, &netmask);
- (void) sprintf (netDev, "%s%d", bootDev, params.unitNum);
- #ifdef INCLUDE_END
- pCookie=findCookie(params.unitNum, bootDev);
- if (muxDevStart (pCookie) != OK)
- {
- printf("Failed to start device %sn", bootDev);
- return (ERROR);
- }
- /* Find the END_OBJ associated with it. */
- pEnd = endFindByName (bootDev, params.unitNum);
- #if 0
- if (muxIoctl (pEnd, EIOCGMIB2, (char *)&endM2Tbl)
- == ERROR)
- return (ERROR);
- #endif
- /* Add our default address resolution functions. */
- 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);
- #else
- if (usrNetIfAttach (bootDev, params.unitNum, pBootAddr) != OK)
- return (ERROR);
- #endif /* INCLUDE_END */
- if ( (sysFlags & SYSFLG_AUTOCONFIG) || (sysFlags & SYSFLG_PROXY) ||
- (netmask == 0))
- {
- struct ifnet * pIf;
- /* Initialize the boot device */
- if ( (pIf = ifunit (netDev)) == NULL)
- {
- printf ("invalid device "%s"n", netDev);
- return (ERROR); /* device not attached */
- }
- 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: %sn", params.bad);
- if (params.bad [0] == EOS)
- {
- printf ("no backplane address specifiedn");
- return (ERROR);
- }
- if ((sysFlags & SYSFLG_AUTOCONFIG) && !(sysFlags & SYSFLG_PROXY))
- {
- #ifdef INCLUDE_DHCPC
- printf ("DHCP over backplane only with proxy arpn");
- #else
- printf ("BOOTP over backplane only with proxy arpn");
- #endif
- return (ERROR);
- }
- if (sysFlags & SYSFLG_PROXY)
- {
- #ifdef INCLUDE_PROXY_CLIENT
- printf ("registering proxy client: %s", params.bad);
- if (proxyReg (netDev, params.bad) == ERROR)
- {
- printf ("client registered failed %xn", errno);
- return (ERROR);
- }
- printf ("done.n");
- #else /* INCLUDE_PROXY_CLIENT */
- printf ("proxy client referenced but not included.n");
- return (ERROR);
- #endif /* INCLUDE_PROXY_CLIENT */
- }
- }
- #endif /* INCLUDE_SM_NET */
- /* Get boot parameters over the network if requested. */
- if (sysFlags & SYSFLG_AUTOCONFIG)
- {
- if (bootpGet (netDev, pBootAddr, params.bootFile, params.had,
- &netmask) == ERROR)
- return (ERROR);
- #ifdef INCLUDE_DHCPC
- if (dhcpGet (netDev, pBootAddr, params.bootFile, params.had,
- &netmask, &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)
- {
- (void) icmpMaskGet (netDev, pBootAddr, backplaneBoot ?
- NULL : params.had, &netmask);
- if (netmask != 0)
- {
- sprintf (bootDev, "%s%d", bootDev, params.unitNum);
- ifMaskSet (bootDev, netmask);
- printf ("Subnet Mask: 0x%xn", netmask);
- }
- }
- /* get gateway address */
- #ifdef INCLUDE_SM_NET
- if (backplaneBoot && (params.gad [0] == EOS) &&
- !(sysFlags & SYSFLG_PROXY))
- {
- struct in_addr host; /* Internet Address */
- struct in_addr backpl; /* Internet Address */
- host.s_addr = inet_addr (params.had);
- backpl.s_addr = inet_addr (params.bad);
- if ( in_netof(host) != in_netof(backpl) )
- {
- /* We can get the gateway address (assumed to be master) */
- if ((strncmp (bootDev, "sm", 2) == 0) &&
- (smNetInetGet (netDev, params.gad, 0) == OK))
- printf ("Gateway inet address: %sn", params.gad);
- }
- }
- #endif /* INCLUDE_SM_NET */
- if (netmask != 0) /* reconstruct address with mask */
- {
- sprintf (buf, ":%x", netmask);
- strcat (pBootAddr, buf);
- }
- /*
- * If a value was specified for the requested lease length and the
- * address information was not replaced by automatic configuration,
- * restore that value for use by later reboots.
- */
- if (!(sysFlags & SYSFLG_AUTOCONFIG) && result == 1)
- {
- /*
- * The value is ignored if <result> is 2, since that is only
- * possible at this point for permanent DHCP assignments,
- * which need no special processing by later reboots.
- */
- if (netmask == 0) /* Create empty netmask field. */
- sprintf (buf, "::%lx", leaseLen);
- else /* Append requested lease length to netmask. */
- sprintf(buf, ":%lx", leaseLen);
- strcat (pBootAddr, buf);
- }
- #ifdef INCLUDE_DHCPC
- /*
- * If the target IP address was assigned by a DHCP server, append
- * the lease times. The presence of those fields in the address string
- * will cause the runtime image to renew the corresponding lease.
- */
- if (sysFlags & SYSFLG_AUTOCONFIG)
- {
- /* Add lease origin and lease duration if needed. */
- if (dhcpcBindType == DHCP_NATIVE)
- {
- if (netmask == 0) /* Create empty netmask field. */
- sprintf (buf, "::%lx:%lx", dhcpLease.lease_duration,
- dhcpLease.lease_origin);
- else /* Append lease timestamps to netmask. */
- 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 a gateway was specified, extract the network part of the host's
- * address and add a route to this network
- */
- if (params.gad[0] != EOS)
- {
- inet_netof_string (params.had, nad);
- #ifdef BROADCOM_BSP
- /* Make the gateway the default route */
- routeAdd ("0.0.0.0", params.gad);
- #else
- routeAdd (nad, params.gad);
- #endif
- }
- /* associate hostName with the specified host address */
- hostAdd (params.hostName, params.had);
- #ifdef BROADCOM_BSP
- {
- extern void sysBindFix(void);
- sysBindFix(); /* See sysLib.c */
- }
- #endif
- /* load specified file */
- return OK;
- }
- #define FLASH_BUF_SIZE (512 * 1024)
- LOCAL STATUS netFlash(char *bootString)
- {
- BOOT_PARAMS params;
- int fd = -1;
- int errFd = -1;
- FILE *fp = 0;
- char command [100];
- BOOL bootFtp;
- BOOL bootRsh = FALSE;
- char *hostName;
- char *fileName;
- char *usr;
- char *passwd;
- char *flashBuf = 0;
- char tmpc = 0;
- int entry, i;
- int sRecords;
- /* Re-probe in case jumper moved */
- if (flashDrvLibInit() == ERROR) {
- return(ERROR);
- }
- if ((flashBuf = malloc(FLASH_BUF_SIZE)) == 0) {
- printf("nNot enough memoryn");
- goto fail;
- }
- /* copy bootString to low mem address, if specified */
- if ((bootString != NULL) && (*bootString != EOS))
- strcpy (BOOT_LINE_ADRS, bootString);
- /* interpret boot command */
- if (usrBootLineCrack (BOOT_LINE_ADRS, ¶ms) != OK)
- goto fail;
- hostName = params.had;
- fileName = params.bootFile;
- usr = params.usr;
- passwd = params.passwd;
- bootFtp = (passwd[0] != EOS);
- if (strlen(fileName) < 4) {
- bad_fname:
- printf("Illegal file %s, must end in .img or .hexn", fileName);
- goto fail;
- }
- if (! strcmp(fileName + strlen(fileName) - 4, ".img"))
- sRecords = 0;
- else if (! strcmp(fileName + strlen(fileName) - 4, ".hex"))
- sRecords = 1;
- else
- goto bad_fname; /* Above */
- if (netLoadInit(bootString) != OK) {
- printf("nError configuring networkn");
- goto fail;
- }
- printf ("Loading... ");
- #ifdef INCLUDE_TFTP_CLIENT
- if (sysFlags & SYSFLG_TFTP) /* use tftp to get image */
- {
- if (tftpXfer (hostName, 0, fileName, "get", "binary", &fd,
- &errFd) == ERROR)
- goto fail;
- }
- else
- #endif
- {
- if (bootFtp)
- {
- if (ftpXfer2 (hostName, usr, passwd, "", "RETR %s", "", fileName,
- &errFd, &fd) == ERROR)
- goto fail;
- }
- else
- {
- bootRsh = TRUE;
- sprintf (command, "cat %s", fileName);
- fd = rcmd (hostName, RSHD, usr, usr, command, &errFd);
- if (fd == ERROR)
- goto fail;
- }
- }
- if ((fp = fdopen(fd, "r")) == 0) {
- printf("nCould not open fdn");
- goto readErr;
- }
- if (sRecords) {
- if ((i = srecLoad(fp, flashBuf, FLASH_BUF_SIZE, &entry)) < 0) {
- printf("nError reading file: %sn", srecErrmsg(i));
- goto readErr;
- }
- } else if ((i = fread(flashBuf, 1, 512 * 1024, fp)) != 512 * 1024) {
- printf("nFailed reading 512 kB from binary file %sn",
- fileName);
- goto readErr;
- }
- printf("%dn", i);
- #ifdef MBZ
- for(i = 0; i < FLASH_BUF_SIZE; i += 4) {
- tmpc = flashBuf[i];
- flashBuf[i] = flashBuf[i + 3];
- flashBuf[i + 3] = tmpc;
- tmpc = flashBuf[i + 1];
- flashBuf[i + 1] = flashBuf[i + 2];
- flashBuf[i + 2] = tmpc;
- }
- #endif
- if (bootRsh == FALSE)
- {
- /* Empty the Data Socket before close. PC FTP server hangs otherwise */
- while ((read (fd, command, sizeof (command))) > 0);
- /* Close the data connection -- fixes timeout hang with wu-ftp */
- close(fd);
- if (bootFtp)
- {
- if (ftpReplyGet(errFd, TRUE) != FTP_COMPLETE)
- printErr("No FTP completion replyn");
- (void) ftpCommand (errFd, "QUIT",0,0,0,0,0,0);
- }
- }
- fclose (fp); /* closes fd */
- close (errFd);
- printf("%dnErasing boot area ...", i);
- for (i = FLASH_BOOT_START_SECTOR;
- i < FLASH_BOOT_START_SECTOR + FLASH_BOOT_SIZE_SECTORS;
- i++) {
- if (flashEraseBank(i,1) != OK) {
- printf("nflashBoot: failed erasing -- PROM DESTROYEDn");
- return ERROR;
- }
- printf(".");
- }
- printf("donenWriting boot data ...");
- if (flashBlkWrite(FLASH_BOOT_START_SECTOR, flashBuf, 0, 512*1024) != OK) {
- printf("nflashBoot: failed writing -- PROM DESTROYEDn");
- return ERROR;
- }
- printf("donen");
- free(flashBuf);
- return (OK);
- readErr:
- /* check standard error on Unix */
- if (bootRsh == FALSE)
- {
- /* Empty the Data Socket before close. PC FTP server hangs otherwise */
- while ((read (fd, command, sizeof (command))) > 0);
- /* Close the data connection -- fixes timeout hang with wu-ftp */
- close(fd);
- if (bootFtp)
- {
- (void) ftpReplyGet (errFd, FALSE); /* error message on std. err */
- (void) ftpCommand (errFd, "QUIT",0,0,0,0,0,0);
- }
- }
- else
- {
- char buf [100];
- int errBytesRecv = fioRead (errFd, buf, sizeof (buf));
- if (errBytesRecv > 0)
- {
- /* print error message on standard error fd */
- buf [errBytesRecv] = EOS;
- printf ("n%s:%s: %sn", hostName, fileName, buf);
- }
- }
- fail:
- if (fp)
- fclose(fp); /* closes fd */
- else if (fd >= 0)
- close (fd);
- if (errFd >= 0)
- close (errFd);
- if (flashBuf)
- free(flashBuf);
- return (ERROR);
- }
- #endif /* BROADCOM_BSP */
- /*******************************************************************************
- *
- * netLoad - downLoad a file from a remote machine via the network.
- *
- * The remote shell daemon on the machine 'host' is used to download
- * the given file to the specified previously opened network file descriptor.
- * The remote userId should have been set previously by a call to iam().
- * If the file does not exist, the error message from the Unix 'host'
- * is printed to the VxWorks standard error fd and ERROR is returned.
- *
- * 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 [100];
- BOOL bootFtp = (passwd[0] != EOS);
- BOOL bootRsh = FALSE;
- printf ("Loading... ");
- #ifdef INCLUDE_TFTP_CLIENT
- if (sysFlags & SYSFLG_TFTP) /* use tftp to get image */
- {
- if (tftpXfer (hostName, 0, fileName, "get", "binary", &fd,
- &errFd) == ERROR)
- return (ERROR);
- }
- else
- #endif
- {
- if (bootFtp)
- {
- #ifdef BROADCOM_BSP
- #if 0
- printf("ftpXfer2: %s %s %s %sn",hostName, fileName, usr, passwd);
- #endif
- if (ftpXfer2 (hostName, usr, passwd, "", "RETR %s", "", fileName,
- &errFd, &fd) == ERROR)
- #else
- if (ftpXfer (hostName, usr, passwd, "", "RETR %s", "", fileName,
- &errFd, &fd) == ERROR)
- #endif
- return (ERROR);
- }
- else
- {
- bootRsh = TRUE;
- sprintf (command, "cat %s", fileName);
- fd = rcmd (hostName, RSHD, usr, usr, command, &errFd);
- if (fd == ERROR)
- return (ERROR);
- }
- }
- #ifdef BROADCOM_BSP
- /* Support loading deflated files. */
- #if 0
- {
- int compSize, r;
- char compBuf;
- while ((r = read(fd, /* Read loop required to support network */
- &compBuf,
- 1 )) > 0)
- {
- if (compBuf == 'n') sysSerialPutc('r');
- sysSerialPutc(compBuf);
- }
- }
- #endif
- if (DEFLATED_FILE(fileName)) {
- if (bootLoadModuleInflate(fd, pEntry) != OK)
- goto readErr;
- } else {
- if (bootLoadModule (fd, pEntry) != OK)
- goto readErr;
- }
- #else
- if (bootLoadModule (fd, pEntry) != OK)
- goto readErr;
- #endif
- #ifdef INCLUDE_TFTP_CLIENT
- /*
- * Successful TFTP transfers don't need any cleanup. The tftpXfer()
- * routine closes all file descriptors once the data has been
- * retrieved from the remote host.
- */
- if (sysFlags & SYSFLG_TFTP) /* used tftp to get image - just exit */
- return (OK);
- #endif
- if (bootRsh == FALSE)
- {
- /* Empty the Data Socket before close. PC FTP server hangs otherwise */
- while ((read (fd, command, sizeof (command))) > 0);
- if (bootFtp)
- (void) ftpCommand (errFd, "QUIT",0,0,0,0,0,0);
- }
- close (fd);
- close (errFd);
- return (OK);
- readErr:
- /* check standard error on Unix */
- if (bootRsh == FALSE)
- {
- /* Empty the Data Socket before close. PC FTP server hangs otherwise */
- while ((read (fd, command, sizeof (command))) > 0);
- if (bootFtp)
- {
- (void) ftpReplyGet (errFd, FALSE); /* error message on std. err */
- (void) ftpCommand (errFd, "QUIT",0,0,0,0,0,0);
- }
- }
- else
- {
- char buf [100];
- int errBytesRecv = fioRead (errFd, buf, sizeof (buf));
- if (errBytesRecv > 0)
- {
- /* print error message on standard error fd */
- buf [errBytesRecv] = EOS;
- printf ("n%s:%s: %sn", hostName, fileName, buf);
- }
- }
- close (fd);
- close (errFd);
- return (ERROR);
- }
- #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 <devName>.
- *
- * 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 */
- 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=<busId>,<lun> e.g. scsi=2,0n");
- 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
- *
- *-----------------------------------------------------------------------*/
- /*-------------------------------------------------------------------------
- *
- * START OF CODE WHICH ASSUMES A DOS-FS PARTITION BEGINNING AT BLOCK 0
- *
- *-----------------------------------------------------------------------*/
- /* create a block device spanning entire disk (non-distructive!) */
- if ((pScsiBlkBootDev = scsiBlkDevCreate (pScsiPhysBootDev, 0, 0)) == NULL)
- {
- printErr ("scsiBlkDevCreate failed.n");
- return (ERROR);
- }
- dosFsInit (NUM_DOSFS_FILES); /* initialize DOS-FS */
- /* split off boot device from boot file */
- devSplit (fileName, bootDir);
- /* initialize the boot block device as a dosFs device named <bootDir> */
- if (dosFsDevInit (bootDir, pScsiBlkBootDev, NULL) == NULL)
- {
- printErr ("dosFsDevInit failed.n");
- return (ERROR);
- }
- /*-------------------------------------------------------------------------
- *
- * END OF CODE WHICH ASSUMES A DOS-FS PARTITION BEGINNING AT BLOCK 0
- *
- *------------------------------------------------------------------------*/
- 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:
- printErr ("nerror loading file: status = 0x%x.n", errnoGet ());
- close (fd);
- return (ERROR);
- }
- #endif /* INCLUDE_SCSI_BOOT */
- #ifdef INCLUDE_FD
- #include "../../src/config/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:
- printErr ("nerror loading file: status = 0x%x.n", errnoGet ());
- close (fd);
- return (ERROR);
- }
- #endif /* INCLUDE_FD */
- #ifdef INCLUDE_IDE
- #define IDE_MEM_DOSFS 0x200000
- #include "../../src/config/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:
- printErr ("nerror loading file: status = 0x%x.n", errno);
- close (fd);
- return (ERROR);
- }
- #endif /* INCLUDE_IDE */
- #ifdef INCLUDE_ATA
- #define ATA_MEM_DOSFS 0x200000
- #include "../../src/config/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;
- 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 */
- if (usrAtaConfig (ctrl, drive, fileName) == 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:
- printErr ("nerror loading file: status = 0x%x.n", errno);
- close (fd);
- return (ERROR);
- }
- #endif /* INCLUDE_ATA */
- #ifdef INCLUDE_PCMCIA
- #define PCMCIA_MEM_DOSFS 0x200000
- #include "../../src/config/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:
- printErr ("nerror loading file: status = 0x%x.n", errno);
- close (fd);
- return (ERROR);
- }
- #endif /* INCLUDE_PCMCIA */
- #ifdef INCLUDE_TFFS
- #ifndef BROADCOM_BSP
- #define TFFS_MEM_DOSFS 0x200000
- #include "../../src/config/usrTffs.c"
- #endif
- /******************************************************************************
- *
- * 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, /* TFFS drive number (0 - (noOfDrives-1)) */
- int removable, /* 0 - nonremovable flash media */
- char * fileName, /* file name to download */
- FUNCPTR * pEntry
- )
- {
- int fd;
- #ifndef BROADCOM_BSP
- if (tffsDrv () != OK)
- {
- printErr ("Could not initialize.n");
- return (ERROR);
- }
- #endif
- printf ("Attaching to TFFS... ");
- dosFsInit (NUM_DOSFS_FILES); /* initialize DOS-FS */
- #ifdef BROADCOM_BSP
- tffsBCM47xxInit(0);
- #else
- if (usrTffsConfig (drive, removable, fileName) == ERROR)
- {
- printErr ("usrTffsConfig failed.n");
- return (ERROR);
- }
- #endif
- 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);
- }
- #ifdef BROADCOM_BSP
- if (DEFLATED_FILE(fileName)) {
- if (bootLoadModuleInflate(fd, pEntry) != OK) {
- /* Error message already printed */
- close(fd);
- return ERROR;
- }
- } else {
- printErr("Loading %s ... ", fileName);
- if (bootLoadModule(fd, pEntry) != OK)
- goto tffsLoadErr;
- }
- #else
- if (bootLoadModule (fd, pEntry) != OK)
- goto tffsLoadErr;
- #endif
- close (fd);
- return (OK);
- tffsLoadErr:
- printErr ("nerror loading file: status = 0x%x.n", errnoGet ());
- close (fd);
- return (ERROR);
- }
- #endif /* INCLUDE_TFFS */
- #ifdef INCLUDE_TSFS_BOOT
- /******************************************************************************
- *
- * tsfsLoad - load a vxWorks image from a Target Server File System (TSFS).
- *
- * 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 [strlen (fileName) + 8];
- /* add a leading slash if the filename is a relatif path */
- 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...");
- /* wait for Target Server connection */
- while (!wdbTargetIsConnected())
- taskDelay (sysClkRateGet());
- printf (" Done.n");
- #endif /* INCLUDE_TSFS_BOOT_VIO_CONSOLE */
- /* open the core file via tsfs */
- printErr ("nLoading %s...n", corefile);
- if ((fd = open (corefile, O_RDONLY, 0)) == ERROR)
- {
- printErr ("nCannot open "%s".n", corefile);
- return (ERROR);
- }
- /* load the the core file */
- if (bootLoadModule (fd, pEntry) != OK)
- goto tsfsLoadErr;
- close (fd);
- #if (WDB_COMM_TYPE != WDB_COMM_SERIAL)
- /* Notify the host of the target reboot */
- wdbEventNodeInit (&rebootEventNode, wdbRebootEventGet, NULL, NULL);
- wdbEventPost (&rebootEventNode);
- /* let some time to WDB to post the event */
- taskDelay (sysClkRateGet() / 10);
- #endif /* WDB_COMM_TYPE != WDB_COMM_SERIAL */
- return (OK);
- tsfsLoadErr:
- printErr ("nerror loading file: status = 0x%x.n", errnoGet ());
- 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 specifiedn");
- return;
- }
- while (*ifname == ' ')
- ifname++; /* skip leading blanks */
- if (*ifname == EOS)
- {
- printf ("Interface not specifiedn");
- return;
- }
- /* Search for unit number of network device. */
- i = 0;
- while (!isdigit((int)ifname[i]) && !isspace((int)ifname[i]) && ifname[i] != EOS)
- i++;
- if (ifname[i] == EOS) /* No unit number given - use 0. */
- value = 0;
- buf = &ifname[i];
- if (bootScanNum (&buf, &value, FALSE) != OK) /* No unit number - use 0. */
- value = 0;
- ifname[i] = EOS;
- sprintf (devName, "%s%d", ifname, value);
- if (strncmp (devName, "bp", 2) == 0)
- {
- /* address for backplane is just processor number */
- printf ("Address for device "%s" == 00:00:00:00:00:%02xn",
- devName, sysProcNumGet ());
- return;
- }
- /* start the network */
- hostTblInit (); /* initialize host table */
- netLibInit ();
- 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:%02xn",
- 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...nn", (int) entry);
- taskDelay (sysClkRateGet ()); /* give the network a moment to close */
- #ifdef INCLUDE_NETWORK
- ifreset (); /* reset network to avoid interrupts */
- #ifdef INCLUDE_END
- /* Stop all ENDs to restore to known state for interrupts and DMA */
- (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 (); /* no clock interrupts are necessary */
- #endif /* (CPU_FAMILY == I80X86) */
- (entry) (); /* go to entry point - never to return */
- }
- /*******************************************************************************
- *
- * m - modify memory
- *
- * This routine prompts the user for modifications to memory, starting at the
- * specified address. It prints each address, and the current contents of
- * that address, in turn. The user can respond in one of several ways:
- *
- * RETURN - No change to that address, but continue
- * prompting at next address.
- * <number> - Set the contents to <number>.
- * . (dot) - No change to that address, and quit.
- * <EOF> - No change to that address, and quit.
- *
- * 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 */
- }
- printf ("%02x", *adrs & 0x000000ff);
- 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
- *
- * This routine gets the next numerical argument from the command line.
- * If the argument is not optional, then an error is reported if no argument
- * is found. <ppString> will be updated to point to the new position in the
- * 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 parametern");
- return (ERROR);
- }
- else
- return (OK);
- }
- /* scan arg */
- if (bootScanNum (ppString, pValue, defaultHex) != OK)
- {
- printf ("invalid parametern");
- return (ERROR);
- }
- skipSpace (ppString);
- /* if we encountered ',' delimiter, step over it */
- if (**ppString == ',')
- {
- ++*ppString;
- return (OK);
- }
- /* if end of line, scan is ok */
- if (**ppString == EOS)
- return (OK);
- /* we got stopped by something else */
- printf ("invalid parametern");
- return (ERROR);
- }
- /* The following routines are common to bootConfig and usrConfig and will
- * eventually be merged
- */
- /******************************************************************************
- *
- * usrBootLineInit - initialize system boot line
- *
- * Initializes system boot line as per specified start type.
- * If this is a COLD boot, i.e., with CLEAR option to clear memory,
- * then the boot line is initialized from non-volatile RAM, if any,
- * otherwise from the compiled in default boot line.
- */
- LOCAL void usrBootLineInit
- (
- int startType
- )
- {
- if (startType & BOOT_CLEAR)
- {
- /* this is a cold boot so get the default boot line */
- if ((sysNvRamGet (BOOT_LINE_ADRS,
- BOOT_LINE_SIZE,
- bootActiveStringNVOFF()) == ERROR) ||
- (*BOOT_LINE_ADRS == EOS))
- {
- /* either no non-volatile RAM or empty boot line */
- strcpy (BOOT_LINE_ADRS, DEFAULT_BOOT_LINE);
- }
- }
- }
- /******************************************************************************
- *
- * usrBootLineCrack - interpret and verify boot line
- *
- * This routine interprets the specified boot line and checks the validity
- * of certain parameters. If there are errors, a diagnostic message is
- * printed.
- *
- * 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;
- /*
- * The bzero() call corrects SPR 6326. The calls to bootNetmaskExtract()
- * and inet_addr() did not delimit the input string with a ' '. When
- * inet_addr attempted to print the invalid address, the system would
- * crash or hang.
- */
- 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);
- }
- /******************************************************************************
- *
- * usrNetIfAttach - attach a network interface
- *
- * This routine attaches the specified network interface.
- *
- * - interface is attached
- * - interface name is constructed as "<devName><unitNum>"
- *
- * 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) = ' ';
- }
- #endif /* INCLUDE_PCMCIA */
- /* find interface in table */
- sprintf(buf, "%s%d", devName, unitNum);
- for (pNif = netIf; pNif->ifName != 0; pNif++)
- {
- if (strcmp (buf, pNif->ifName) == 0)
- break;
- }
- /*
- * For backward compatibility, the device name only is acceptable for
- * unit numbers of 0.
- */
- 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)
- /* SGI VIP10 boards are supposed to come with the ethernet address
- * in SGI formated non volatile ram. We can not be sure where this
- * is so we default the upper 4 bytes of the address to SGI standard
- * and use the bottom two bytes of the internet address for the rest.
- */
- if (strcmp (devName, "lnsgi") == 0)
- {
- IMPORT char lnsgiEnetAddr []; /* ethernet addr for lance */
- 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 commandn");
- else
- printf ("failed: errno = %#x.n", errno);
- return (ERROR);
- }
- printf ("done.n");
- return (OK);
- }
- /******************************************************************************
- *
- * usrNetIfConfig - configure a network interface
- * - subnetmask is extracted from inetAdrs and, if present,
- * set for interface
- * - inet address is set for interface
- * - if present, inet name for interface is added to host table
- */
- LOCAL STATUS usrNetIfConfig
- (
- char * devName, /* device name */
- int unitNum, /* unit number */
- char * inetAdrs, /* inet address */
- char * inetName, /* host name */
- int netmask /* subnet mask */
- )
- {
- char ifname [20];
- #ifdef INCLUDE_PCMCIA
- if (strncmp (devName, "pcmcia", 6) == 0)
- devName = "pcmcia";
- #endif /* INCLUDE_PCMCIA */
- /* check for empty inet address */
- if (inetAdrs[0] == EOS)
- {
- printf ("No inet address specified for interface %s.n", devName);
- return (ERROR);
- }
- /* build interface name */
- sprintf (ifname, "%s%d", devName, unitNum);
- /* set subnet mask, if any specified */
- if (netmask != 0)
- ifMaskSet (ifname, netmask);
- /* set inet address */
- if (ifAddrSet (ifname, inetAdrs) != OK)
- {
- printf ("Error setting inet address of %s to %s, errno = %#xn",
- ifname, inetAdrs, errno);
- return (ERROR);
- }
- /* add host name to host table */
- if ((inetName != NULL) && (*inetName != EOS))
- hostAdd (inetName, inetAdrs);
- return (OK);
- }
- /******************************************************************************
- *
- * usrBpInit - initialize backplane driver
- *
- * usrBpInit initializes the backplane driver shared memory region
- * and sets up the backplane parameters to attach.
- *
- * RETURNS: OK if successful otherwise ERROR
- */
- LOCAL STATUS usrBpInit
- (
- char * devName, /* device name */
- int unitNum, /* unit number */
- u_long startAddr /* inet address */
- )
- {
- #ifdef INCLUDE_SM_NET
- char * bpAnchor; /* anchor address */
- FAST NETIF * pNif; /* netif struct */
- STATUS status; /* status */
- int procNum; /* proc num */
- char buf [BOOT_DEV_LEN]; /* network device */
- /*
- * Pick off optional "=<anchorAdrs>" from backplane
- * device. Also truncates devName to just "bp" or "sm"
- */
- 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 we are master, initialize backplane net */
- 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, 0, 0, startAddr);
- if (status == ERROR)
- {
- printf ("Error: backplane device %s not initializedn", 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;
- }
- /*
- * For backward compatibility, the device name only is acceptable for
- * unit numbers of 0.
- */
- 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);
- /* configure backplane parameters (most set in NETIF struct) */
- pNif->arg1 = bpAnchor; /* anchor address */
- pNif->arg3 = SM_INT_NONE;
- pNif->arg4 = 0;
- pNif->arg5 = 0;
- pNif->arg6 = 0;
- return (OK);
- #else /* INCLUDE_SM_NET */
- printf ("nError: backplane driver referenced but not included.n");
- return (ERROR);
- #endif /* INCLUDE_SM_NET */
- }
- /*******************************************************************************
- *
- * usrSlipInit - initialize the slip device
- *
- * RETURNS: OK if successful, otherwise ERROR.
- */
- LOCAL STATUS usrSlipInit
- (
- char *pBootDev, /* boot device */
- int unitNum, /* unit number */
- char *localAddr, /* local address */
- char *peerAddr /* peer address */
- )
- {
- #ifdef INCLUDE_SLIP
- char slTyDev [20]; /* slip device */
- int netmask; /* netmask */
- #ifndef SLIP_BAUDRATE
- #define SLIP_BAUDRATE 0 /* uses previously selected baudrate */
- #endif
- #ifdef CSLIP_ENABLE
- #undef CSLIP_ENABLE
- #define CSLIP_ENABLE TRUE /* force CSLIP header compression */
- #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] == '=')
- {
- /* get the tty device used for SLIP interface e.g. "sl=/tyCo/1" */
- strcpy (slTyDev, &pBootDev [3]);
- pBootDev [2] = ' ';
- }
- 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%xn", 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++ = ' ';
- pppBaudRate = atoi (pBaudStr);
- }
- if (pBootDev [3] == '=')
- {
- /* get the tty device used for PPP interface e.g. "ppp=/tyCo/1" */
- strcpy (pppTyDev, &pBootDev [4]);
- pBootDev [3] = ' ';
- }
- else
- {
- /* construct the default PPP tty device */
- 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%xn", 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 */
- }
- #if defined(INCLUDE_STREAMS) || defined(INCLUDE_STREAMS_ALL)
- /*******************************************************************************
- *
- * usrStrmInit - Streams subsystem initialization
- *
- * This routine is called at system startup time to create the Streams task
- * and install relevant Streams services.
- *
- * RETURNS: OK, or ERROR if the Streams initialization fails.
- */
- LOCAL STATUS usrStrmInit (void)
- {
- int strmMemSize = STREAMS_MEM_PART_SIZE;
- if ((strmMemSize == NULL) || (strmMemSize > STREAMS_MEM_MAX))
- strmMemSize = STREAMS_MEM_MAX;
- if (strmInit (strmMemSize,
- STREAMS_MEM_PART_ADDR,
- STREAMS_MSGSZ_MAX,
- STREAMS_CTLSZ_MAX,
- STREAMS_PUSH_MAX) == ERROR)
- {
- printf ("Streams initialization failuren");
- return (ERROR);
- }
- #if defined(INCLUDE_STREAMS_SOCKET) || defined(INCLUDE_STREAMS_ALL)
- strmSockInit (); /* initialize sockmod module */
- if (sockLibAdd ((FUNCPTR) strmSockLibInit, AF_INET_STREAMS, AF_INET) ==
- ERROR)
- return (ERROR);
- #ifdef DEFAULT_STREAMS_SOCKET
- if (sockLibAdd ((FUNCPTR) strmSockLibInit, AF_INET, AF_INET) == ERROR)
- return (ERROR);
- #endif /* DEFAULT_STREAMS_SOCKET */
- #endif /* INCLUDE_STREAMS_SOCKET */
- #if defined(INCLUDE_STREAMS_TLI) || defined(INCLUDE_STREAMS_ALL)
- tliInit (); /* initialize timod and tirdwr modules */
- #endif /* INCLUDE_STREAMS_TLI */
- #if defined(INCLUDE_STREAMS_AUTOPUSH) || defined(INCLUDE_STREAMS_ALL)
- autopushInit (); /* Include Autopush facility */
- #endif /* INCLUDE_STREAMS_AUTOPUSH */
- #if defined(INCLUDE_STREAMS_DLPI) || defined(INCLUDE_STREAMS_ALL)
- dlpiInit (); /* initialize the /dev/dlb devices */
- #endif /* INCLUDE_STREAMS_DLPI */
- #if defined(INCLUDE_STREAMS_STRACE) || defined(INCLUDE_STREAMS_ALL)
- strmStraceInit (STREAMS_STRACE_OUTPUT_DIR); /* init strace utility */
- #endif /* INCLUDE_STREAMS_STRACE */
- #if defined(INCLUDE_STREAMS_STRERR) || defined(INCLUDE_STREAMS_ALL)
- strmStrerrInit (STREAMS_STRERR_OUTPUT_DIR); /* init strerr utility */
- #endif /* INCLUDE_STREAMS_STRERR */
- #ifdef INCLUDE_STREAMS_DEBUG
- strmDebugInit (); /* initialize the Streams debug facility */
- #endif /* INCLUDE_STREAMS_DEBUG */
- /* call user-provided protocol initialization hook routine */
- if ((strmProtoInitRtn != NULL) && ((*strmProtoInitRtn) () == ERROR))
- return (ERROR);
- return (OK); /* Streams initialization complete */
- }
- #endif /* INCLUDE_STREAMS */
- /******************************************************************************
- *
- * bootpGet - get boot parameters via BOOTP.
- *
- * This routine retrieves a boot file name, host and target IP addresses, and
- * subnet mask from a BOOTP server, using the bootstrap protocol defined in
- * RFC 1542. The IP address and subnet mask values will only be stored in the
- * boot parameters if not already specified. In order to use BOOTP, the boot
- * device indicated by <pNetDev> must be capable of sending broadcast messages.
- * Currently, only Ethernet devices and the shared-memory network drivers are
- * supported. To use the shared-memory drivers, the target IP address must
- * already be specified.
- * .IP
- * The routine is called when the SYSFLG_AUTOCONFIG boot flag is set and the
- * BOOTP client is included in the boot program. If the DHCP client is also
- * included, that protocol is used instead.
- *
- * RETURNS: OK if successful, or ERROR otherwise.
- *
- * ERRNO: N/A
- *
- * SEE ALSO: bootpLib, RFC 1542, RFC 951
- */
- LOCAL STATUS bootpGet
- (
- char *pNetDev, /* boot device */
- char *pBootDevAddr, /* device address */
- char *pBootFile, /* file name */
- char *pHostAddr, /* host address */
- int *pMask /* mask */
- )
- {
- #ifndef INCLUDE_DHCPC
- #ifdef INCLUDE_BOOTP
- struct bootpParams bootParams; /* parameter descriptor */
- struct in_addr clntAddr; /* client address */
- struct in_addr hostAddr; /* server address */
- int subnetMask; /* subnet mask */
- 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));
- /* Need inet address to boot over the backplane */
- 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);
- }
- /* Set pointers to retrieve needed boot parameters. */
- bootParams.clientAddr = &clntAddr; /* pBootDevAddr */
- bootParams.bootHostAddr = &hostAddr; /* pHostAddr */
- bootParams.bootfile = pBootFile;
- bootParams.netmask = (struct in_addr *)&subnetMask;
- printf ("Getting boot parameters via network interface %s", pNetDev);
- if (bootpParamsGet (pNetDev, 0, 0, &bootParams) == ERROR)
- return (ERROR);
- inet_ntoa_b (*bootParams.bootHostAddr, bootServer);
- printf ("nBootp Server:%sn", bootServer);
- if (pBootFile [0] == EOS)
- return (ERROR); /* no bootfile */
- printf (" Boot file: %sn", pBootFile);
- /* copies to params.had */
- if (pHostAddr [0] == EOS) /* fill in host address */
- {
- strncpy (pHostAddr, bootServer, INET_ADDR_LEN);
- printf (" Boot host: %sn", pHostAddr);
- }
- /*
- * copies to pBootDevAddr (params.ead or params.bad) if not using bp or sm
- * drivers and address is not already present.
- */
- if (pBootDevAddr [0] == EOS) /* fill in inet address */
- {
- inet_ntoa_b (*bootParams.clientAddr, pBootDevAddr);
- printf (" Boot device Addr (%s): %sn", pNetDev, pBootDevAddr);
- }
- /* copies to netmask */
- if ((*pMask == 0) && (subnetMask != 0))
- {
- *pMask = ntohl (subnetMask);
- printf (" Subnet mask: 0x%xn", *pMask);
- }
- return (OK);
- #else
- printf ("automatic address assignment requested but not included.n");
- return (ERROR);
- #endif
- #else
- return (OK); /* DHCP client used instead. */
- #endif
- }
- #ifdef INCLUDE_DHCPC
- /******************************************************************************
- *
- * dhcpGet - get boot parameters with DHCP
- *
- * This routine retrieves a boot file name, host and target IP addresses, and
- * subnet mask from a DHCP or BOOTP server, using the lease negotation process
- * defined in RFC 1541. The IP address and subnet mask values will only be
- * stored in the boot parameters if not already specified. The DHCP client will
- * select the longest offered lease which exceeds the DHCPC_MIN_LEASE value.
- * Any DHCP lease will be given preference over BOOTP replies. Unless a
- * specific lease duration is provided in the target IP address entry, the
- * client requests the lease length defined by DHCPC_DEFAULT_LEASE. The client
- * will collect additional DHCP offers until the interval specified by
- * DHCPC_OFFER_TIMEOUT expires.
- * .IP
- * The <pNetDev> argument indicates the network device which will be used to
- * send and receive DHCP messages. The DHCP client only supports devices
- * attached to the IP protocol with the MUX/END interface. The MTU size of the
- * network interface must be large enough to receive an IP datagram of 576
- * bytes and the device also must be capable of sending broadcast messages.
- * Finally, the target IP address must already be specified to use the
- * shared-memory driver.
- * .IP
- * This routine executes when the SYSFLG_AUTOCONFIG boot flag is set and the
- * DHCP client is included in the boot program, whether or not the BOOTP client
- * is also available.
- *
- * NOTE
- * The boot file to be loaded must also contain the DHCP client library in
- * order to continue using the assigned target IP address. In addition, the
- * DHCP server included with Windows NT does not supply boot file names. If
- * that server is used to supply the boot parameters, the boot file name must
- * be entered manually.
- *
- * RETURNS: OK if successful, or ERROR otherwise.
- *
- * ERRNO: N/A
- *
- * SEE ALSO: dhcpcBootLib, RFC 1541
- */
- LOCAL STATUS dhcpGet
- (
- char * pNetDev, /* boot device */
- char * pBootDevAddr, /* device IP address */
- char * pBootFile, /* boot file name */
- char * pHostAddr, /* host IP address */
- int * pMask, /* target subnet mask */
- DHCP_LEASE_DATA * pDhcpLease /* lease times and addresses */
- )
- {
- STATUS result;
- struct ifnet * pIf; /* pointer to network interface data */
- char serverAddr [INET_ADDR_LEN]; /* DHCP server address */
- char bootFile [BOOT_FILE_LEN]; /* name of boot file */
- int subnetMask; /* subnet mask */
- void * pCookie;
- struct dhcp_param bootParams;
- bzero (serverAddr, INET_ADDR_LEN);
- bzero ( (char *)&bootParams, sizeof (struct dhcp_param));
- /*
- * Using pBootFile directly only works if all the DHCP servers supply a
- * bootfile. The Windows NT server does not, so we can't do this.
- */
- /* bootParams.file = pBootFile; - Desired assignment to save memory. */
- bootParams.file = bootFile;
- bootParams.subnet_mask = (struct in_addr *)&subnetMask;
- /* Need target IP address to boot over the backplane */
- 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);
- }
- /* Set requested lease length to value from bootline. */
- dhcpcOptionAdd (pCookie, _DHCP_LEASE_TIME_TAG, sizeof (int),
- (UCHAR *)&pDhcpLease->lease_duration);
- if (pBootDevAddr[0] == EOS)
- {
- /* Attempt to retrieve address information from a DHCP server. */
- result = dhcpcBootBind ();
- if (result != OK)
- return (ERROR);
- }
- else
- {
- /*
- * Externally configured address. Get any additional parameters.
- * Ignore any failure (since the network device can be configured)
- * as long as a boot file is available.
- */
- result = dhcpcBootInformGet (pBootDevAddr);
- if (result != OK)
- {
- if (pBootFile[0] == EOS)
- return (ERROR);
- else
- return (OK);
- }
- }
- result = dhcpcBootParamsGet (&bootParams);
- if (result == ERROR)
- return (ERROR);
- /* Fill in configuration parameters for storage in bootline. */
- if (pBootDevAddr[0] == EOS)
- {
- /*
- * If the DHCP process established a lease (which includes an IP
- * address assignment), get the assigned address and timestamp
- * values. This information is not available if an address is
- * assigned externally. (A DHCP inform message is sent in that case).
- */
- 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:%sn", serverAddr);
- if (pBootFile [0] == EOS && bootFile[0] == EOS)
- return (ERROR); /* no bootfile */
- if (bootFile[0] != EOS) /* Save new bootfile */
- {
- bcopy (bootFile, pBootFile, BOOT_FILE_LEN);
- printf (" Boot file: %sn", pBootFile);
- }
- if (pHostAddr [0] == EOS) /* fill in host address */
- {
- inet_ntoa_b (bootParams.siaddr, pHostAddr);
- printf (" Boot host: %sn", pHostAddr);
- }
- /*
- * Fill in the target's IP address, if needed. The status
- * variable indicates the source of the IP address as follows:
- * DHCP_NATIVE - assigned by a DHCP server
- * DHCP_BOOTP - issued by a BOOTP server
- * DHCP_MANUAL - entered in boot parameters
- */
- if (pBootDevAddr [0] == EOS) /* fill in inet address */
- {
- /*
- * Use the IP address from the DHCP protocol.
- * The status variable has already been set.
- */
- inet_ntoa_b (bootParams.yiaddr, pBootDevAddr);
- printf (" Boot device Addr (%s): %sn", pNetDev, pBootDevAddr);
- }
- if ( (*pMask == 0) && (subnetMask != 0))
- {
- *pMask = ntohl (subnetMask);
- printf (" Subnet mask: 0x%xn", *pMask);
- }
- 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:%02xn", 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:%02xn", 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- %02xn", 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 ("%02xn", byte[0]);
- #else /* _BYTE_ORDER == _LITTLE_ENDIAN */
- for (ix = 5; ix > 0; ix--)
- printf ("%02x:", byte[ix]);
- printf ("%02xn", byte[0]);
- #endif /* _BYTE_ODER == _BIG_ENDIAN */
- }
- #endif /* ETHERNET_ADR_SET */
- /*******************************************************************************
- *
- * usrNetProtoInit - configure the various protocols
- *
- * This routine configures various protocols of the network system.
- * This function should be called before netLibInit() at the initialization
- * time.
- *
- * RETURNS: OK, or ERROR if the protocol initialization fails
- *
- * NOMANUAL
- */
- LOCAL STATUS usrNetProtoInit (void)
- {
- ipLibInit (&ipCfgParams); /* has to included by default */
- rawIpLibInit (); /* has to included by default */
- rawLibInit ();
- #ifdef INCLUDE_UDP
- udpLibInit (&udpCfgParams); /* udp protocol initialization */
- #endif
- #ifdef INCLUDE_TCP
- tcpLibInit (&tcpCfgParams); /* tcp protocol initialization */
- #endif
- #ifdef INCLUDE_ICMP
- icmpLibInit (&icmpCfgParams); /* icmp protocol initialization */
- #endif
- #ifdef INCLUDE_IGMP
- igmpLibInit (); /* igmp protocol initialization */
- #endif
- #ifdef INCLUDE_OSPF
- ospfLibInit ();
- #endif
- return (OK);
- }
- #endif /* INCLUDE_NETWORK */