* Copyright (c) 1988 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* 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
"@(#) Copyright (c) 1988 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)enpload.c 5.4 (Berkeley) 1/14/91";
* CMC Ethernet ``Microcode'' Loader.
#include <tahoe/if/if_enpreg.h>
int enp
= -1, fd
, first
= 1, nostart
= 0;
enp
= open(dev
= argv
[0], O_RDWR
);
fprintf(stderr
, "enpload: ");
for (; argc
> 0; argc
--, argv
++) {
if (strcmp(argv
[0], "-s") == 0 || strcmp(argv
[0], "-S") == 0) {
* Reset device before first file is loaded.
if (ioctl(enp
, ENPIORESET
) < 0) {
fprintf(stderr
, "enpload: %s: ", dev
);
perror("ioctl (ENPIORESET)");
if ((fd
= open(argv
[0], O_RDONLY
)) < 0) {
fprintf(stderr
, "enpload: "), perror(argv
[0]);
enpload(enp
, fd
, argv
[0]);
if (enp
!= -1 && !nostart
&& ioctl(enp
, ENPIOGO
) < 0) {
fprintf(stderr
, "enpload: ");
perror("ioctl (ENPIOGO)");
#define RELO 0x03FFFF /* relocation offset */
#define ENPMSTART 0x0 /* start of memory */
#define BSIZE 512 /* buffer size */
enpload(enp
, fd
, filename
)
if (read(fd
, &hdr
, sizeof (hdr
)) != sizeof (hdr
)) {
fprintf(stderr
, "enpload: %s: Read short (header).\n",
fprintf(stderr
, "enpload: %s: Bad magic number.\n", filename
);
size
= hdr
.a_text
+ hdr
.a_data
;
lstart
= (ENPMSTART
+ (hdr
.a_entry
& RELO
)) - 0x1000;
printf("%s: Loading %s...", dev
, filename
);
(void) lseek(enp
, lstart
+ size
, L_SET
);
while (hdr
.a_bss
>= BSIZE
) {
if (write(enp
, zbuf
, BSIZE
) != BSIZE
) {
fprintf(stderr
, "enpload: Bss write error.\n");
if (hdr
.a_bss
> 0 && write(enp
, zbuf
, hdr
.a_bss
) != hdr
.a_bss
) {
fprintf(stderr
, "enpload: Bss write error.\n");
(void) lseek(enp
, lstart
, L_SET
);
cnt
= read(fd
, buff
, BSIZE
);
if (write(enp
, buff
, cnt
) != cnt
) {
fprintf(stderr
, "enpload: Write error.\n");
cnt
= read(fd
, buff
, size
);
if (write(enp
, buff
, cnt
) != cnt
) {
fprintf(stderr
, "enpload: Write error.\n");