* Copyright (c) 1992 Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* %sccs.include.redist.c%
"@(#) Copyright (c) 1992 Regents of the University of California.\n\
static char sccsid
[] = "@(#)mkboot.c 7.6 (Berkeley) %G%";
#include <sys/disklabel.h>
#include <pmax/stand/dec_boot.h>
struct Dec_DiskBoot decBootInfo
;
char *bootfname
, *xxboot
, *bootxx
;
* This program takes a boot program and splits it into xxboot and bootxx
* files for the disklabel program. The disklabel program should be used to
* label and install the boot program onto a new disk.
* mkboot bootprog xxboot bootxx
ifd
= open(bootfname
, 0, 0);
ofd1
= creat(xxboot
, 0666);
ofd2
= creat(bootxx
, 0666);
* Check for exec header and skip to code segment.
if (!GetHeader(ifd
, &loadAddr
, &execAddr
, &length
)) {
fprintf(stderr
, "Need impure text format (OMAGIC) file\n");
* Write the boot information block.
decBootInfo
.magic
= DEC_BOOT_MAGIC
;
decBootInfo
.loadAddr
= loadAddr
;
decBootInfo
.execAddr
= execAddr
;
decBootInfo
.map
[0].numBlocks
= nsectors
=
(length
+ DEV_BSIZE
- 1) >> DEV_BSHIFT
;
decBootInfo
.map
[0].startBlock
= 1;
decBootInfo
.map
[1].numBlocks
= 0;
if (write(ofd1
, (char *)&decBootInfo
, sizeof(decBootInfo
)) !=
sizeof(decBootInfo
) || close(ofd1
) != 0)
printf("load %x, start %x, len %d, nsectors %d\n", loadAddr
, execAddr
,
* Write the boot code to the bootxx file.
for (i
= 0; i
< nsectors
&& length
> 0; i
++) {
if (length
< DEV_BSIZE
) {
if (read(ifd
, block
, n
) != n
) {
if (write(ofd2
, block
, DEV_BSIZE
) != DEV_BSIZE
) {
printf("Warning: didn't reach end of boot program!\n");
printf("Usage: mkboot bootprog xxboot bootxx\n");
printf("\t\"bootprog\" is a -N format file\n");
printf("\t\"xxboot\" is the file name for the first boot block\n");
printf("\t\"bootxx\" is the file name for the remaining boot blocks.\n");
*----------------------------------------------------------------------
* Check if the header is an a.out file.
* Return true if all went ok.
* bootFID is left ready to read the text & data sections.
* length is set to the size of the text + data sections.
*----------------------------------------------------------------------
GetHeader(bootFID
, loadAddr
, execAddr
, length
)
int bootFID
; /* Handle on the boot program */
long *loadAddr
; /* Address to start loading boot program. */
long *execAddr
; /* Address to start executing boot program. */
long *length
; /* Length of the boot program. */
if (lseek(bootFID
, 0, 0) < 0) {
bytesRead
= read(bootFID
, (char *)&aout
, sizeof(aout
));
if (bytesRead
!= sizeof(aout
) || aout
.a_magic
!= OMAGIC
)
*loadAddr
= aout
.a_entry
;
*execAddr
= aout
.a_entry
;
*length
= aout
.a_text
+ aout
.a_data
;
if (lseek(bootFID
, N_TXTOFF(aout
), 0) < 0) {
printf("Input file is a.out format\n");