mkbootimage makes bootable BeOS DR8 filesystem(a.k.a. obfs) image.
This commit is contained in:
parent
d6205b71c6
commit
5b75eca570
|
@ -0,0 +1,6 @@
|
|||
# $NetBSD: Makefile,v 1.1 1999/06/28 00:35:22 sakamoto Exp $
|
||||
|
||||
PROG= mkbootimage
|
||||
MKMAN= no
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -0,0 +1,172 @@
|
|||
/* $NetBSD: bootimage.h,v 1.1 1999/06/28 00:35:23 sakamoto Exp $ */
|
||||
|
||||
#define HEADER_SIZE 0x6400
|
||||
#define BLOCK_SIZE 0x100
|
||||
#define FILE_SIZE_OFFSET 0x00004494
|
||||
#define FILE_SIZE_ALIGN_OFFSET 0x00004498
|
||||
#define FILE_BLOCK_MAP_START 0x00000200
|
||||
#define FILE_BLOCK_MAP_END 0x00000368
|
||||
|
||||
u_char image_data0[] = {
|
||||
0x00, 0x03, 0x00, 0x00, 0xde, 0xad, 0xbe, 0xef, /* mtime */
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x0b, 0x40, /* avail size */
|
||||
0x00, 0x00, 0x02, 0x00, 0xff, 0xff, 0xff, 0xff,
|
||||
0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x0b, 0x40, /* used block */
|
||||
0x01, 0x00, 0x00, 0x00, 0x66, 0x64, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x41, 0xc0,
|
||||
0xbe, 0x00, 0xbe, 0x01, 0xbe, 0x02, 0xbe, 0x03,
|
||||
0x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be, 0xa6, 0xbe, 0xa7,
|
||||
0xbe, 0xa8, 0xbe, 0xa9, 0xbe, 0xaa, 0xbe, 0xab,
|
||||
0xbe, 0xac, 0xbe, 0xad, 0xbe, 0xae, 0xbe, 0xaf,
|
||||
0xbe, 0xb0, 0xbe, 0xb1, 0xbe, 0xb2, 0xbe, 0xb3,
|
||||
0xbe, 0xb4, 0xbe, 0xb5, 0xbe, 0xb6, 0xbe, 0xb7,
|
||||
0xbe, 0xb8, 0xbe, 0xb9, 0xbe, 0xba, 0xbe, 0xbb,
|
||||
0xbe, 0xbc, 0xbe, 0xbd, 0xbe, 0xbe, 0xbe, 0xbf,
|
||||
0xbe, 0xc0, 0xbe, 0xc1, 0xbe, 0xc2, 0xbe, 0xc3,
|
||||
0xbe, 0xc4, 0xbe, 0xc5, 0xbe, 0xc6, 0xbe, 0xc7,
|
||||
0xbe, 0xc8, 0xbe, 0xc9, 0xbe, 0xca, 0xbe, 0xcb,
|
||||
0xbe, 0xcc, 0xbe, 0xcd, 0xbe, 0xce, 0xbe, 0xcf,
|
||||
0xbe, 0xd0, 0xbe, 0xd1, 0xbe, 0xd2, 0xbe, 0xd3,
|
||||
};
|
||||
|
||||
u_char image_data1[] = {
|
||||
0x54, 0x72, 0x61, 0x73, 0x68, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
u_char image_data2[] = {
|
||||
0x00, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0xff, 0xde, 0xad, 0xbe, 0xef, /* mtime */
|
||||
0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00, /* mtime */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x41, 0xff,
|
||||
};
|
||||
|
||||
u_char image_data3[] = {
|
||||
0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00,
|
||||
};
|
||||
|
||||
u_char image_data4[] = {
|
||||
0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00,
|
||||
0xff, 0xff, 0xff, 0xff, 0xde, 0xad, 0xbe, 0xef, /* mtime */
|
||||
0xde, 0xad, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00, /* mtime */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x41, 0xff,
|
||||
};
|
||||
|
||||
u_char image_data5[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
|
||||
};
|
||||
|
||||
u_char image_data6[] = {
|
||||
0x00, 0x72, 0x61, 0x73, 0x68, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
u_char image_data7[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0xff,
|
||||
};
|
||||
|
||||
u_char image_data8[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
|
||||
};
|
||||
|
||||
u_char image_data9[] = {
|
||||
0x6b, 0x65, 0x72, 0x6e, 0x65, 0x6c, 0x00, 0x00,
|
||||
};
|
||||
|
||||
u_char image_data10[] = {
|
||||
0x80, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x65,
|
||||
0x00, 0x00, 0x00, 0x00, 0xde, 0xad, 0xbe, 0xef, /* mtime */
|
||||
0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, /* mtime/filesize */
|
||||
0xde, 0xea, 0xbe, 0xef, 0x00, 0x00, 0x00, 0x00, /* filesize(aligned) */
|
||||
0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x81, 0xb6,
|
||||
};
|
||||
|
||||
u_char image_data11[] = {
|
||||
0x00, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x00, 0x00,
|
||||
};
|
||||
|
||||
u_char image_data12[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0xff,
|
||||
};
|
||||
|
||||
struct image_block {
|
||||
long offset;
|
||||
u_char *data;
|
||||
int size;
|
||||
};
|
||||
|
||||
#define IMG(x) __CONCAT(image_data,x)
|
||||
#define IMG_DATA_SIZE(x) IMG(x), (sizeof (IMG(x)) / sizeof (IMG(x)[0]))
|
||||
|
||||
struct image_block image_block[] = {
|
||||
{ 0x00000000, IMG_DATA_SIZE(0) },
|
||||
{ 0x00000440, IMG_DATA_SIZE(1) },
|
||||
{ 0x00000480, IMG_DATA_SIZE(2) },
|
||||
{ 0x000004c0, IMG_DATA_SIZE(3) },
|
||||
{ 0x00000500, IMG_DATA_SIZE(4) },
|
||||
{ 0x00002400, IMG_DATA_SIZE(5) },
|
||||
{ 0x00002440, IMG_DATA_SIZE(6) },
|
||||
{ 0x000024a0, IMG_DATA_SIZE(7) },
|
||||
{ 0x00004400, IMG_DATA_SIZE(8) },
|
||||
{ 0x00004440, IMG_DATA_SIZE(9) },
|
||||
{ 0x00004480, IMG_DATA_SIZE(10) },
|
||||
{ 0x000044c0, IMG_DATA_SIZE(11) },
|
||||
{ 0x00004520, IMG_DATA_SIZE(12) },
|
||||
{ -1 }
|
||||
};
|
||||
|
||||
long mtime_offset[] = {
|
||||
0x00000004,
|
||||
0x0000048c,
|
||||
0x00000490,
|
||||
0x0000050c,
|
||||
0x00000510,
|
||||
0x0000448c,
|
||||
0x00004490,
|
||||
-1
|
||||
};
|
|
@ -0,0 +1,180 @@
|
|||
/* $NetBSD: mkbootimage.c,v 1.1 1999/06/28 00:35:23 sakamoto Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 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 Christopher G. Demetriou
|
||||
* for the NetBSD Project.
|
||||
* 4. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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 SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/param.h> /* XXX for roundup */
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <machine/endian.h>
|
||||
#include <machine/bswap.h>
|
||||
#include "bootimage.h"
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
#define BO(x) bswap32(x)
|
||||
#else
|
||||
#define BO(x)
|
||||
#endif
|
||||
|
||||
static void usage(void);
|
||||
|
||||
extern char *__progname;
|
||||
|
||||
static void
|
||||
usage()
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s [-n] [-v] inputfile [outputfile]\n", __progname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
const char *infile, *outfile;
|
||||
char *outbuf;
|
||||
struct image_block *p;
|
||||
struct stat insb;
|
||||
struct timeval tp;
|
||||
struct timezone tzp;
|
||||
size_t outbufsize;
|
||||
ssize_t rv;
|
||||
int c, verbose, nowrite, infd, outfd;
|
||||
long *offset;
|
||||
|
||||
verbose = nowrite = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "nv")) != -1) {
|
||||
switch (c) {
|
||||
case 'n':
|
||||
/* Do not actually write the boot file */
|
||||
nowrite = 1;
|
||||
break;
|
||||
case 'v':
|
||||
/* Chat */
|
||||
verbose = 1;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
if (argc != 1 && argc != 2)
|
||||
usage();
|
||||
|
||||
infile = argv[0];
|
||||
outfile = argv[1]; /* NULL if argc == 1 */
|
||||
|
||||
if (verbose) {
|
||||
fprintf(stderr, "input file: %s\n", infile);
|
||||
fprintf(stderr, "output file: %s\n",
|
||||
outfile != NULL ? outfile : "<stdout>");
|
||||
}
|
||||
|
||||
/* Open the input file and check it out */
|
||||
if ((infd = open(infile, O_RDONLY)) == -1)
|
||||
err(EXIT_FAILURE, "open %s", infile);
|
||||
if (fstat(infd, &insb) == -1)
|
||||
err(EXIT_FAILURE, "fstat %s", infile);
|
||||
if (!S_ISREG(insb.st_mode))
|
||||
errx(EXIT_FAILURE, "%s must be a regular file", infile);
|
||||
|
||||
/*
|
||||
* Allocate a buffer, with space to round up the input file
|
||||
* to the next block size boundary, and with space for the boot
|
||||
* block.
|
||||
*/
|
||||
outbufsize = roundup(insb.st_size, BLOCK_SIZE);
|
||||
outbufsize += HEADER_SIZE;
|
||||
outbufsize = roundup(outbufsize, 512);
|
||||
|
||||
outbuf = malloc(outbufsize);
|
||||
if (outbuf == NULL)
|
||||
err(EXIT_FAILURE, "allocating output buffer");
|
||||
memset(outbuf, 0, outbufsize);
|
||||
|
||||
/* copy the boot image info the buffer */
|
||||
for (p = image_block; p->offset != -1; p++)
|
||||
memcpy(outbuf + p->offset, p->data, p->size);
|
||||
|
||||
/* fill used block bitmap */
|
||||
memset(outbuf + FILE_BLOCK_MAP_START, 0xff,
|
||||
FILE_BLOCK_MAP_END - FILE_BLOCK_MAP_START);
|
||||
|
||||
/* fix the file size in the header */
|
||||
*(long *)(outbuf + FILE_SIZE_OFFSET) =
|
||||
(long)BO(insb.st_size);
|
||||
*(long *)(outbuf + FILE_SIZE_ALIGN_OFFSET) =
|
||||
(long)BO(roundup(insb.st_size, BLOCK_SIZE));
|
||||
|
||||
/* set mtime */
|
||||
gettimeofday(&tp, &tzp);
|
||||
for (offset = mtime_offset; *offset != -1; offset++)
|
||||
*(long *)(outbuf + *offset) = (long)BO(tp.tv_sec);
|
||||
|
||||
/* read the file into the buffer, leaving room for the boot block */
|
||||
rv = read(infd, outbuf + HEADER_SIZE, insb.st_size);
|
||||
if (rv == -1)
|
||||
err(EXIT_FAILURE, "read %s", infile);
|
||||
else if (rv != insb.st_size)
|
||||
errx(EXIT_FAILURE, "read %s: short read", infile);
|
||||
(void)close(infd);
|
||||
|
||||
if (nowrite)
|
||||
exit(EXIT_SUCCESS);
|
||||
|
||||
/* set up the output file descriptor */
|
||||
if (outfile == NULL) {
|
||||
outfd = STDOUT_FILENO;
|
||||
outfile = "<stdout>";
|
||||
} else if ((outfd = open(outfile, O_WRONLY|O_CREAT, 0666)) == -1)
|
||||
err(EXIT_FAILURE, "open %s", outfile);
|
||||
|
||||
/* write the data */
|
||||
rv = write(outfd, outbuf, outbufsize);
|
||||
if (rv == -1)
|
||||
err(EXIT_FAILURE, "write %s", outfile);
|
||||
else if (rv != outbufsize)
|
||||
errx(EXIT_FAILURE, "write %s: short write", outfile);
|
||||
(void)close(outfd);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
Loading…
Reference in New Issue