1 /* $NetBSD: inckern.c,v 1.1 2005/12/29 15:20:09 tsutsui Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
35 enum { TMPBUF_SIZE
= 0x2000 };
38 main(int argc
, char *argv
[])
40 unsigned char buf
[TMPBUF_SIZE
];
42 int err
, i
, n
, total
, nulldata
;
49 while ((i
= getopt(argc
, argv
, "d:i:o:")) != -1) {
51 case 'd': /* Generate dummy file */
52 if ((optarg
== 0) || (ifd
!= stdin
))
54 total
= strtoul(optarg
, 0, 0);
57 case 'i': /* Specify input file */
58 if ((optarg
== 0) || (total
!= 0) ||
59 (ifd
= fopen(optarg
, "r")) == 0)
62 case 'o': /* Specify output file */
63 if ((optarg
== 0) || (ofd
= fopen(optarg
, "w")) == 0)
69 fprintf(ofd
, "#include <lib/libsa/stand.h>\n");
70 fprintf(ofd
, "#include <lib/libkern/libkern.h>\n");
71 fprintf(ofd
, "#include \"local.h\"\n");
72 fprintf(ofd
, "uint8_t kernel_binary[");
74 fprintf(ofd
, "%d];\n", total
);
75 fprintf(ofd
, "int kernel_binary_size = %d;\n", total
);
77 fprintf(ofd
, "] = {\n\t");
78 while ((n
= fread(buf
, 1, TMPBUF_SIZE
, ifd
)) > 0) {
79 for (i
= 0; i
< n
; i
++) {
80 fprintf(ofd
, "0x%02x, ", buf
[i
]);
81 if (((i
+ 1) & 0x7) == 0)
86 fprintf(ofd
, "\n};\nint kernel_binary_size = %d;\n", total
);