BSD 4_3_Tahoe release
[unix-history] / usr / src / new / np100 / npload.c
CommitLineData
ed0d8cc8 1/*
4f51e749
KS
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.
ed0d8cc8
KS
5 *
6 */
7#ifndef lint
8char copyright[] =
4f51e749 9"@(#) Copyright (c) 1986 MICOM-Interlan, Inc., Boxborough Mass.\n\
ed0d8cc8
KS
10 All rights reserved.\n";
11#endif not lint
12
13#ifndef lint
95f51977 14static char sccsid[] = "@(#)npload.c 6.2 (Berkeley) 2/20/86";
ed0d8cc8
KS
15#endif not lint
16
17#include <stdio.h>
18#include <fcntl.h>
19#include "npcmd.h"
20#include <sys/ioctl.h>
21
22extern int errno;
23
24main(argc,argv)
25int argc;
26char **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}