1: /*
   2:  * Copyright (c) 1986 MICOM-Interlan, Inc., Boxborough Mass.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  *
   6:  */
   7: #ifndef lint
   8: char copyright[] =
   9: "@(#) Copyright (c) 1986 MICOM-Interlan, Inc., Boxborough Mass.\n\
  10:  All rights reserved.\n";
  11: #endif not lint
  12: 
  13: #ifndef lint
  14: static char sccsid[] = "@(#)npload.c	6.2 (Berkeley) 2/20/86";
  15: #endif not lint
  16: 
  17: #include <stdio.h>
  18: #include <fcntl.h>
  19: #include "npcmd.h"
  20: #include <sys/ioctl.h>
  21: 
  22: extern int errno;
  23: 
  24: main(argc,argv)
  25: int argc;
  26: char **argv;
  27: {
  28: 
  29:     int ret;
  30:     int ed;
  31:     int fd;
  32:     int nbyte;
  33:     char    *fname;
  34:     char    ibuf[1024];
  35:     char    obuf[1024];
  36:     long    stadd = 0x400;
  37:     char    *devname = "/dev/np00";
  38: 
  39:     switch (argc) {
  40:     case 3:
  41:         /* Pathname for device to be loaded */
  42:         devname = argv[2];
  43:     case 2:
  44:         /* Name of the image file to be loaded */
  45:         fname = argv[1];
  46:         break;
  47:     default:
  48:         printf("usage: npload imagefile [device]\n");
  49:         exit(1);
  50:     }
  51:     /* Open the device to be loaded */
  52: 
  53:     if((ed = open(devname,O_RDWR)) == -1) {
  54:         char fullpath[50];
  55:         (void) sprintf(fullpath, "/dev/%s", devname);
  56:         if((ed = open(devname,O_RDWR)) == -1) {
  57:             fprintf(stderr,
  58:                 "%s unable to open device %s errno = %d\n",
  59:                 argv[0], devname, errno);
  60:             exit(2);
  61:         }
  62:     }
  63: 
  64:     /* Open the image file */
  65: 
  66:     if((fd = open(fname,O_RDONLY)) == -1) {
  67:         fprintf(stderr,"%s: unable to open file %s errno = %d\n",
  68:             argv[0],fname,errno);
  69:         exit(3);
  70:     }
  71: 
  72:     /* Reset the specified device */
  73: 
  74:     if(ioctl(ed,NPRESET | IOC_VOID,&stadd) == -1) {
  75:         fprintf(stderr,"unable to reset %s errno = %d\n",devname,errno);
  76:         exit(4);
  77:     }
  78: 
  79:     /* Seek to address 400 on the device */
  80: 
  81:     if(lseek(ed,(long)0x400,0) == -1) {
  82:         fprintf(stderr,"seek failed on %s errno = %d.\n",devname,errno);
  83:         exit(5);
  84:     }
  85: 
  86:     /* Seek to address 400 on the image file */
  87: 
  88:     if(lseek(fd,(long)0x400,0) == -1) {
  89:         fprintf(stderr,"seek failed on %s errno = %d.\n",fname,errno);
  90:         exit(6);
  91:     }
  92: 
  93:     /* Read from the image file and write to the device */
  94: 
  95:     while((nbyte = read(fd,ibuf,1024)) > 0) {
  96: 
  97:         if((ret = write(ed,ibuf,nbyte)) == -1) {
  98:             fprintf(stderr,"Bad write to %s errno = %d\n",
  99:                 argv[0],errno);
 100:             exit(7);
 101:         }
 102:     }
 103: 
 104:     /* Issue a begin execution command to the device */
 105: 
 106:     if(ioctl(ed,NPSTART | IOC_VOID,&stadd) == -1) {
 107:         fprintf(stderr,"Start error on %s errno = %d.\n",devname,errno);
 108:         exit(8);
 109:     }
 110: 
 111:     close(fd);
 112:     close(ed);
 113: 
 114:     exit(0);
 115: }

Defined functions

main defined in line 24; never used

Defined variables

copyright defined in line 8; never used
sccsid defined in line 14; never used
Last modified: 1986-02-20
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 945
Valid CSS Valid XHTML 1.0 Strict