* Copyright (c) 1992 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
* @(#)mkboottape.c 7.5 (Berkeley) %G%
#include <pmax/stand/dec_boot.h>
void err
__P((const char *, ...));
struct Dec_DiskBoot decBootInfo
;
* This program takes a kernel and the name of the special device file that
* has the mini-root file system stored on it and creates a boot tape.
* The -b option makes a bootfile that can load the kernel and mini-root
* over the network using the 'boot 6/tftp/filename -m' PROM command.
* usage: mkboottape [-b] tapedev vmunix minirootdev size
while ((i
= getopt(argc
, argv
, "b")) != EOF
)
ofd
= open(argv
[0], O_CREAT
|O_TRUNC
|O_WRONLY
, DEFFILEMODE
);
ofd
= open(argv
[0], O_RDWR
, 0);
deverr
: err("%s: %s", argv
[0], strerror(errno
));
if ((ifd
= open(argv
[1], O_RDONLY
, 0)) < 0)
bootferr
: err("%s: %s", argv
[1], strerror(errno
));
if ((rfd
= open(argv
[2], O_RDONLY
, 0)) < 0)
rooterr
: err("%s: %s", argv
[2], strerror(errno
));
rootsize
= atoi(argv
[3]);
* Check for exec header and skip to code segment.
if (read(ifd
, &aout
, sizeof(aout
)) != sizeof(aout
) ||
aout
.ex_fhdr
.magic
!= COFF_MAGIC
|| aout
.a_magic
!= OMAGIC
)
err("need impure text format (OMAGIC) file");
loadAddr
= aout
.ex_aout
.codeStart
;
length
= aout
.a_text
+ aout
.a_data
;
textoff
= N_TXTOFF(aout
);
(void)printf("Input file is COFF format\n");
(void)printf("load %x, start %x, len %d\n", loadAddr
, execAddr
, length
);
* Compute size of boot program rounded to page size + mini-root size.
nsectors
= (((length
+ aout
.a_bss
+ NBPG
- 1) & ~(NBPG
- 1)) >>
* Write modified ECOFF header.
aout
.ex_fhdr
.numSections
= 1;
aout
.ex_fhdr
.numSyms
= 0;
aout
.a_text
= nsectors
<< DEV_BSHIFT
;
aout
.ex_aout
.heapStart
= aout
.ex_aout
.bssStart
=
aout
.ex_aout
.codeStart
+ aout
.a_text
;
if (write(ofd
, (char *)&aout
, sizeof(aout
)) != sizeof(aout
))
strncpy(shdr
.name
, ".text", sizeof(shdr
.name
));
shdr
.physAddr
= shdr
.virtAddr
= loadAddr
;
shdr
.sectionPtr
= n
= (sizeof(aout
) + sizeof(shdr
) + 15) & ~15;
if (write(ofd
, (char *)&shdr
, sizeof(shdr
)) != sizeof(shdr
))
n
-= sizeof(aout
) + sizeof(shdr
);
if (write(ofd
, block
, n
) != n
)
* Write the boot information block.
decBootInfo
.magic
= DEC_BOOT_MAGIC
;
decBootInfo
.loadAddr
= loadAddr
;
decBootInfo
.execAddr
= execAddr
;
decBootInfo
.map
[0].numBlocks
= nsectors
;
decBootInfo
.map
[0].startBlock
= 1;
decBootInfo
.map
[1].numBlocks
= 0;
if (write(ofd
, (char *)&decBootInfo
, sizeof(decBootInfo
)) !=
/* seek to start of text */
if (lseek(ifd
, textoff
, SEEK_SET
) < 0)
* Write the remaining code to the correct place on the tape.
for (i
= length
; i
> 0; i
-= n
) {
if (read(ifd
, block
, n
) != n
)
if (write(ofd
, block
, DEV_BSIZE
) != DEV_BSIZE
)
* Pad the boot file with zeros to the start of the mini-root.
i
= ((nsectors
- rootsize
) << DEV_BSHIFT
) -
((length
+ DEV_BSIZE
- 1) & ~(DEV_BSIZE
- 1));
if (write(ofd
, block
, n
) != n
)
* Write the mini-root to tape.
for (i
= rootsize
; i
> 0; i
--) {
if (read(rfd
, block
, DEV_BSIZE
) != DEV_BSIZE
)
if (write(ofd
, block
, DEV_BSIZE
) != DEV_BSIZE
)
(void)printf("mkboottape: wrote %d sectors\n", nsectors
);
"usage: mkboottape [-b] tapedev vmunix minirootdev size\n");
err(const char *fmt
, ...)
(void)fprintf(stderr
, "mkboottape: ");
(void)vfprintf(stderr
, fmt
, ap
);
(void)fprintf(stderr
, "\n");