Use err(3). Remove progname.

This commit is contained in:
Philippe Charnier 1997-10-20 12:51:34 +00:00
parent 1c95916129
commit 0fc00685c3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=30600
4 changed files with 106 additions and 185 deletions

View File

@ -44,7 +44,7 @@
.Op Fl B Ar boot-banner
.Op Fl b Ar unit-number
.Sh DESCRIPTION
.Nm stlload
.Nm Stlload
is used to download the firmware code to Stallion Technologies intelligent
multiport serial boards.
A firmware download is only required for those boards that use the Stallion
@ -62,11 +62,11 @@ driver control device,
This device implements a file type device that can read and write into the
boards shared memory region.
It also implements a number of special
.Pa ioctls
.Em ioctls
that reset and restart the board.
.Pp
The options are:
.Bl -tag -width xxxxx
.Bl -tag -width indent
.It Fl v
Verbose output generation.
Trace is generated at each phase of the download and startup process.
@ -79,11 +79,13 @@ Reset the board only.
Does not proceed to download firmware to the board.
.It Fl i Ar image-file
Specify the firmware image file to download.
The default firmware image is /usr/libdata/stallion/cdk.sys.
The default firmware image is
.Pa /usr/libdata/stallion/cdk.sys .
.It Fl c Ar control-device
Specify the board control device through which to download the firmware
and start up the board.
The default is /dev/staliomem0.
The default is
.Pa /dev/staliomem0 .
.It Fl r Ar rx-buf-size
Specify the size of the boards shared memory Receive Data buffer.
By default the buffer is dynamically sized to use the maximum
@ -102,7 +104,7 @@ Specify the unit (board) number to be downloaded. The default is to
download board 0.
.El
.Pp
.Nm stlload
.Nm Stlload
would typically be run from
.Pa /etc/rc.serial .
.Sh FILES
@ -118,4 +120,5 @@ driver board control device
.Xr stli 4 ,
.Xr stlstats 8
.Sh HISTORY
This program was originally developed by Greg Ungerer (gerg@stallion.com).
This program was originally developed by
.An Greg Ungerer Aq gerg@stallion.com .

View File

@ -32,18 +32,21 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: stlload.c,v 1.5 1997/02/22 16:13:45 peter Exp $
*/
/*****************************************************************************/
#include <stdio.h>
#include <errno.h>
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <err.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
@ -56,7 +59,6 @@ char *defdevice = "/dev/staliomem%d";
char *image = BOOTDIR "/cdk.sys";
char *oldimage = BOOTDIR "/2681.sys";
char *progname;
char *memdevice;
char devstr[128];
int brdnr = 0;
@ -92,26 +94,18 @@ cdkonbsig_t onbsig;
/*
* Declare internal function prototypes here.
*/
void usage(void);
static void usage(void);
int ecpfindports(cdkecpsig_t *sigp);
int onbfindports(cdkonbsig_t *sigp);
int download(void);
/*****************************************************************************/
void usage()
static void usage()
{
fprintf(stderr, "Usage: %s [OPTION]\n\n", progname);
fprintf(stderr, " -h print this information\n");
fprintf(stderr, " -v print full diagnostic trace\n");
fprintf(stderr, " -V show version information and exit\n");
fprintf(stderr, " -i specify image file to use\n");
fprintf(stderr, " -b download board number\n");
fprintf(stderr, " -d specify memory device to use\n");
fprintf(stderr, " -B enable slave boot banner\n");
fprintf(stderr, " -R reset board only\n");
fprintf(stderr, " -t set size of TX slave buffer\n");
fprintf(stderr, " -r set size of RX slave buffer\n");
fprintf(stderr, "%s\n%s\n",
"usage: stlload [-vhVR] [-i image-file] [-c control-device] [-r rx-buf-size]",
" [-t tx-buf-size] [-B boot-banner] [-b unit-number]");
exit(0);
}
@ -185,14 +179,12 @@ int download()
unsigned char alivemarker;
time_t strttime;
int memfd, ifd;
int nrdevs, sigok, n, rc;
int nrdevs, sigok, n;
if (verbose)
printf("Opening shared memory device %s\n", memdevice);
if ((memfd = open(memdevice, O_RDWR)) < 0) {
fprintf(stderr,
"%s: failed to open memory device %s, errno=%d\n",
progname, memdevice, errno);
warn("failed to open memory device %s", memdevice);
return(-1);
}
@ -205,16 +197,14 @@ int download()
if (verbose)
printf("Stoping any current slave\n");
if (ioctl(memfd, STL_BSTOP, 0) < 0) {
fprintf(stderr, "%s: ioctl(STL_BSTOP) failed, errno=%d\n",
progname, errno);
warn("ioctl(STL_BSTOP)");
return(-1);
}
if (verbose)
printf("Reseting the board\n");
if (ioctl(memfd, STL_BRESET, 0) < 0) {
fprintf(stderr, "%s: ioctl(STL_BRESET) failed, errno=%d\n",
progname, errno);
warn("ioctl(STL_BRESET)");
return(-1);
}
if (reset)
@ -227,8 +217,7 @@ int download()
if (verbose)
printf("Interrupting board to activate shared memory\n");
if (ioctl(memfd, STL_BINTR, 0) < 0) {
fprintf(stderr, "%s: ioctl(STL_BINTR) failed, errno=%d\n",
progname, errno);
warn("ioctl(STL_BINTR)");
return(-1);
}
/*sleep(1);*/
@ -236,8 +225,7 @@ int download()
if (verbose)
printf("Opening slave image file %s\n", image);
if ((ifd = open(image, O_RDONLY)) < 0) {
fprintf(stderr, "%s: failed to open image file %s, errno=%d\n",
progname, image, errno);
warn("failed to open image file %s", image);
return(-1);
}
@ -251,14 +239,11 @@ int download()
printf("Reading ROM signature from board\n");
if (lseek(memfd, CDK_SIGADDR, SEEK_SET) != CDK_SIGADDR) {
fprintf(stderr,
"%s: lseek(%x) failed on memory file, errno=%d\n",
progname, CDK_FEATADDR, errno);
warn("lseek(%x) failed on memory file", CDK_FEATADDR);
return(-1);
}
if (read(memfd, &ecpsig, sizeof(cdkecpsig_t)) < 0) {
fprintf(stderr, "%s: read of ROM signature failed, errno=%d\n",
progname, errno);
warn("read of ROM signature failed");
return(-1);
}
if (ecpsig.magic == ECP_MAGIC) {
@ -269,14 +254,11 @@ int download()
}
if (lseek(memfd, CDK_SIGADDR, SEEK_SET) != CDK_SIGADDR) {
fprintf(stderr,
"%s: lseek(%x) failed on memory file, errno=%d\n",
progname, CDK_FEATADDR, errno);
warn("lseek(%x) failed on memory file", CDK_FEATADDR);
return(-1);
}
if (read(memfd, &onbsig, sizeof(cdkonbsig_t)) < 0) {
fprintf(stderr, "%s: read of ROM signature failed, errno=%d\n",
progname, errno);
warn("read of ROM signature failed");
return(-1);
}
if ((onbsig.magic0 == ONB_MAGIC0) && (onbsig.magic1 == ONB_MAGIC1) &&
@ -289,7 +271,7 @@ int download()
}
if (! sigok) {
fprintf(stderr, "%s: unknown signature from board\n", progname);
warnx("unknown signature from board");
return(-1);
}
@ -305,33 +287,24 @@ int download()
if (verbose)
printf("Copying vector table into shared memory\n");
if ((n = read(ifd, buf, CDK_SIGADDR)) < 0) {
fprintf(stderr, "%s: read of image file failed, errno=%d\n",
progname, errno);
warn("read of image file failed");
return(-1);
}
if (lseek(memfd, 0, SEEK_SET) != 0) {
fprintf(stderr,
"%s: lseek(%x) failed on memory file, errno=%d\n",
progname, CDK_FEATADDR, errno);
warn("lseek(%x) failed on memory file", CDK_FEATADDR);
return(-1);
}
if (write(memfd, buf, n) < 0) {
fprintf(stderr,
"%s: write to memory device failed, errno=%d\n",
progname, errno);
warn("write to memory device failed");
return(-1);
}
if (lseek(ifd, 0x1000, SEEK_SET) != 0x1000) {
fprintf(stderr,
"%s: lseek(%x) failed on image file, errno=%d\n",
progname, CDK_FEATADDR, errno);
warn("lseek(%x) failed on image file", CDK_FEATADDR);
return(-1);
}
if (lseek(memfd, 0x1000, SEEK_SET) != 0x1000) {
fprintf(stderr,
"%s: lseek(%x) failed on memory device, errno=%d\n",
progname, CDK_FEATADDR, errno);
warn("lseek(%x) failed on memory device", CDK_FEATADDR);
return(-1);
}
@ -340,15 +313,11 @@ int download()
*/
do {
if ((n = read(ifd, buf, BUFSIZE)) < 0) {
fprintf(stderr,
"%s: read of image file failed, errno=%d\n",
progname, errno);
warn("read of image file failed");
return(-1);
}
if (write(memfd, buf, n) < 0) {
fprintf(stderr,
"%s: write to memory device failed, errno=%d\n",
progname, errno);
warn("write to memory device failed");
return(-1);
}
} while (n == BUFSIZE);
@ -365,15 +334,11 @@ int download()
if (verbose)
printf("Loading features into shared memory\n");
if (lseek(memfd, CDK_FEATADDR, SEEK_SET) != CDK_FEATADDR) {
fprintf(stderr,
"%s: lseek(%x) failed on memory device, errno=%d\n",
progname, CDK_FEATADDR, errno);
warn("lseek(%x) failed on memory device", CDK_FEATADDR);
return(-1);
}
if (write(memfd, &feature, sizeof(cdkfeature_t)) < 0) {
fprintf(stderr,
"%s: write to memory device failed, errno=%d\n",
progname, errno);
warn("write to memory device failed");
return(-1);
}
@ -385,16 +350,12 @@ int download()
if (verbose)
printf("Setting alive marker to 0\n");
if (lseek(memfd, CDK_RDYADDR, SEEK_SET) != CDK_RDYADDR) {
fprintf(stderr,
"%s: lseek(%x) failed on memory device, errno=%d\n",
progname, CDK_RDYADDR, errno);
warn("lseek(%x) failed on memory device", CDK_RDYADDR);
return(-1);
}
alivemarker = 0;
if (write(memfd, &alivemarker, 1) < 0) {
fprintf(stderr,
"%s: write to memory device failed, errno=%d\n",
progname, errno);
warn("write to memory device failed");
return(-1);
}
@ -405,8 +366,7 @@ int download()
if (verbose)
printf("Interrupting board to start slave image\n");
if (ioctl(memfd, STL_BINTR, 0) < 0) {
fprintf(stderr, "%s: ioctl(STL_BINTR) failed, errno=%d\n",
progname, errno);
warn("ioctl(STL_BINTR) failed");
return(-1);
}
@ -416,15 +376,11 @@ int download()
strttime, TIMEOUT);
while (time((time_t *) NULL) < (strttime + TIMEOUT)) {
if (lseek(memfd, CDK_RDYADDR, SEEK_SET) != CDK_RDYADDR) {
fprintf(stderr,
"%s: lseek(%x) failed on memory device, "
"errno=%d\n", progname, CDK_RDYADDR, errno);
warn("lseek(%x) failed on memory device", CDK_RDYADDR);
return(-1);
}
if (read(memfd, &alivemarker, 1) < 0){
fprintf(stderr,
"%s: read of image file failed, errno=%d\n",
progname, errno);
warn("read of image file failed");
return(-1);
}
if (alivemarker == CDK_ALIVEMARKER)
@ -432,20 +388,17 @@ int download()
}
if (alivemarker != CDK_ALIVEMARKER) {
fprintf(stderr, "%s: slave image failed to start\n", progname);
warnx("slave image failed to start");
return(-1);
}
if (lseek(memfd, CDK_RDYADDR, SEEK_SET) != CDK_RDYADDR) {
fprintf(stderr,
"%s: lseek(%x) failed on memory device, errno=%d\n",
progname, CDK_RDYADDR, errno);
warn("lseek(%x) failed on memory device", CDK_RDYADDR);
return(-1);
}
alivemarker = 0;
if (write(memfd, &alivemarker, 1) < 0) {
fprintf(stderr, "%s: write to memory device failed, errno=%d\n",
progname, errno);
warn("write to memory device failed");
return(-1);
}
@ -460,8 +413,7 @@ int download()
if (verbose)
printf("Driver initializing host shared memory interface\n");
if (ioctl(memfd, STL_BSTART, 0) < 0) {
fprintf(stderr, "%s: ioctl(STL_BSTART) failed, errno=%d\n",
progname, errno);
warn("ioctl(STL_BSTART) failed");
return(-1);
}
@ -477,12 +429,11 @@ void main(int argc, char *argv[])
int optind, c;
optind = 0;
progname = argv[0];
while ((c = getopt(argc, argv, "hvVRB:i:b:d:t:r:")) != -1) {
switch (c) {
case 'V':
printf("%s version %s\n", progname, version);
printf("stlload version %s\n", version);
exit(0);
break;
case 'B':
@ -520,12 +471,8 @@ void main(int argc, char *argv[])
}
if (memdevice == (char *) NULL) {
if ((brdnr < 0) || (brdnr >= 8)) {
fprintf(stderr,
"%s: invalid board number %d specified\n",
progname, brdnr);
exit(1);
}
if ((brdnr < 0) || (brdnr >= 8))
errx(1, "invalid board number %d specified", brdnr);
sprintf(devstr, defdevice, brdnr);
memdevice = &devstr[0];
if (verbose)
@ -538,22 +485,13 @@ void main(int argc, char *argv[])
/*
* Check that the shared memory device exits and is a character device.
*/
if (stat(memdevice, &statinfo) < 0) {
fprintf(stderr, "%s: memory device %s does not exist\n",
progname, memdevice);
exit(1);
}
if ((statinfo.st_mode & S_IFMT) != S_IFCHR) {
fprintf(stderr, "%s: memory device %s is not a char device\n",
progname, memdevice);
exit(1);
}
if (stat(memdevice, &statinfo) < 0)
errx(1, "memory device %s does not exist", memdevice);
if ((statinfo.st_mode & S_IFMT) != S_IFCHR)
errx(1, "memory device %s is not a char device", memdevice);
if (stat(image, &statinfo) < 0) {
fprintf(stderr, "%s: image file %s does not exist\n",
progname, image);
exit(1);
}
if (stat(image, &statinfo) < 0)
errx(1, "image file %s does not exist", image);
/*
* All argument checking is now done. So lets get this show on the road.

View File

@ -42,11 +42,11 @@
.Op Fl p Ar port-number
.Op Fl d Ar port-device
.Sh DESCRIPTION
.Nm stlstats
.Nm Stlstats
is used to display statistical information about the ports on Stallion
Technologies multiport serial boards.
.Pp
.Nm stlstats
.Nm Stlstats
normally runs as a full screen menu driven application.
A help line is displayed at the bottom of each screen with the valid
input keys for this screen.
@ -91,7 +91,7 @@ modem signal transitions and
current RS-232 signal states.
.Pp
The options are:
.Bl -tag -width xxxxxxx
.Bl -tag -width indent
.It Fl h
Output usage information.
.It Fl V
@ -100,21 +100,24 @@ Output version information.
Output only the board type information.
This output is useful for scripts or other programs that need to know
a little bit about the board (for example an automated download script).
.Nm stlstats
.Nm Stlstats
will not enter full screen interactive mode.
.It Fl c Ar control-device
Specify the board control device through which to gather port statistics.
The default is /dev/staliomem0.
The default is
.Pa /dev/staliomem0 .
.It Fl b Ar board-number
Specify the board number to display first.
The default is to display board 0.
.It Fl p Ar port-number
Specify the port number to display first.
.Nm stlstats
.Nm Stlstats
will go straight into the port display screen (bypassing board display)
when this option is used.
.It Fl d Ar port-device
Specify the port special device file (the /dev/ttyXXX file) to
Specify the port special device file (the
.Pa /dev/ttyXXX
file) to
display first.
The board screen is bypassed and the port statistics screen is shown
immediately on start up.
@ -128,4 +131,5 @@ driver control device used for statistics collection
.Xr stli 4 ,
.Xr stlload 8
.Sh HISTORY
This program was originally developed by Greg Ungerer (gerg@stallion.com).
This program was originally developed by
.An Greg Ungerer Aq gerg@stallion.com .

View File

@ -32,19 +32,23 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: stlstats.c,v 1.4 1997/02/22 16:13:50 peter Exp $
*/
/*****************************************************************************/
#include <stdio.h>
#include <errno.h>
#ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <err.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <ncurses.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
@ -56,7 +60,6 @@
char *version = "1.0.0";
char *defdevice = "/dev/staliomem0";
char *progname;
char *ctrldevice;
int ctrlfd;
int displaybrdnr = 0;
@ -77,7 +80,7 @@ char *line = "
/*
* Declare internal function prototypes here.
*/
void usage(void);
static void usage(void);
void useportdevice(char *devname);
void localexit(int nr);
void menuport();
@ -91,15 +94,11 @@ void clearallstats();
/*****************************************************************************/
void usage()
static void usage()
{
fprintf(stderr, "Usage: %s [-hVbpdc]\n\n", progname);
fprintf(stderr, " -h print this information\n");
fprintf(stderr, " -V show version information and exit\n");
fprintf(stderr, " -b display board\n");
fprintf(stderr, " -p display panel\n");
fprintf(stderr, " -d display port device stats\n");
fprintf(stderr, " -c specify control device to use\n");
fprintf(stderr, "%s\n%s\n",
"usage: stlstats [-hVi] [-c control-device] [-b board-number]",
" [-p port-number] [-d port-device]");
exit(0);
}
@ -109,28 +108,19 @@ void useportdevice(char *devname)
{
struct stat statinfo;
int portnr, portcnt;
int i, fd;
int i;
if (stat(devname, &statinfo) < 0) {
fprintf(stderr, "%s: port device %s does not exist\n",
progname, devname);
exit(1);
}
if ((statinfo.st_mode & S_IFMT) != S_IFCHR) {
fprintf(stderr, "%s: port device %s is not a char device\n",
progname, devname);
exit(1);
}
if (stat(devname, &statinfo) < 0)
errx(1, "port device %s does not exist", devname);
if ((statinfo.st_mode & S_IFMT) != S_IFCHR)
errx(1, "port device %s is not a char device", devname);
displaybrdnr = (statinfo.st_rdev & 0x00700000) >> 20;
portnr = (statinfo.st_rdev & 0x1f) |
((statinfo.st_rdev & 0x00010000) >> 11);
getbrdstats();
if (brdstats.ioaddr == 0) {
fprintf(stderr, "%s: device %s does not exist\n", progname,
devname);
exit(1);
}
if (brdstats.ioaddr == 0)
errx(1, "device %s does not exist", devname);
for (portcnt = 0, i = 0; (i < brdstats.nrpanels); i++) {
if ((portnr >= portcnt) &&
@ -138,11 +128,8 @@ void useportdevice(char *devname)
break;
portcnt += brdstats.panels[i].nrports;
}
if (i >= brdstats.nrpanels) {
fprintf(stderr, "%s: device %s does not exist\n", progname,
devname);
exit(1);
}
if (i >= brdstats.nrpanels)
errx(1, "device %s does not exist", devname);
displaypanelnr = i;
displayportnr = portnr - portcnt;
if (displayportnr >= 16)
@ -213,8 +200,7 @@ void getallstats()
stats[i].panel = displaypanelnr;
stats[i].port = i;
if (ioctl(ctrlfd, COM_GETPORTSTATS, &stats[i]) < 0) {
fprintf(stderr, "\n\r\nERROR: ioctl(COM_GETPORTSTATS) "
"failed, errno=%d\n\r\n", errno);
warn("ioctl(COM_GETPORTSTATS) failed");
localexit(1);
}
}
@ -518,14 +504,13 @@ void main(int argc, char *argv[])
char *portdev;
optind = 0;
progname = argv[0];
ctrldevice = defdevice;
useport = 0;
while ((c = getopt(argc, argv, "hvVb:p:d:c:")) != -1) {
switch (c) {
case 'V':
printf("%s version %s\n", progname, version);
printf("stlstats version %s\n", version);
exit(0);
break;
case 'h':
@ -554,21 +539,12 @@ void main(int argc, char *argv[])
/*
* Check that the control device exits and is a character device.
*/
if (stat(ctrldevice, &statinfo) < 0) {
fprintf(stderr, "%s: control device %s does not exist\n",
progname, ctrldevice);
exit(1);
}
if ((statinfo.st_mode & S_IFMT) != S_IFCHR) {
fprintf(stderr, "%s: control device %s is not a char device\n",
progname, ctrldevice);
exit(1);
}
if ((ctrlfd = open(ctrldevice, O_RDWR)) < 0) {
fprintf(stderr, "%s: open of %s failed, errno=%d\n", progname,
ctrldevice, errno);
exit(1);
}
if (stat(ctrldevice, &statinfo) < 0)
errx(1, "control device %s does not exist", ctrldevice);
if ((statinfo.st_mode & S_IFMT) != S_IFCHR)
errx(1, "control device %s is not a char device", ctrldevice);
if ((ctrlfd = open(ctrldevice, O_RDWR)) < 0)
errx(1, "open of %s failed", ctrldevice);
/*
* Validate the panel number supplied by user. We do this now since we