mkboot.c revision 1.1.4.2 1 1.1.4.2 rmind /* $NetBSD: mkboot.c,v 1.1.4.2 2014/05/18 17:45:11 rmind Exp $ */
2 1.1.4.2 rmind
3 1.1.4.2 rmind /* $OpenBSD: mkboot.c,v 1.9 2001/05/17 00:57:55 pvalchev Exp $ */
4 1.1.4.2 rmind
5 1.1.4.2 rmind /*
6 1.1.4.2 rmind * Copyright (c) 1990, 1993
7 1.1.4.2 rmind * The Regents of the University of California. All rights reserved.
8 1.1.4.2 rmind *
9 1.1.4.2 rmind * Redistribution and use in source and binary forms, with or without
10 1.1.4.2 rmind * modification, are permitted provided that the following conditions
11 1.1.4.2 rmind * are met:
12 1.1.4.2 rmind * 1. Redistributions of source code must retain the above copyright
13 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer.
14 1.1.4.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.4.2 rmind * notice, this list of conditions and the following disclaimer in the
16 1.1.4.2 rmind * documentation and/or other materials provided with the distribution.
17 1.1.4.2 rmind * 3. Neither the name of the University nor the names of its contributors
18 1.1.4.2 rmind * may be used to endorse or promote products derived from this software
19 1.1.4.2 rmind * without specific prior written permission.
20 1.1.4.2 rmind *
21 1.1.4.2 rmind * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1.4.2 rmind * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1.4.2 rmind * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1.4.2 rmind * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1.4.2 rmind * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1.4.2 rmind * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1.4.2 rmind * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1.4.2 rmind * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1.4.2 rmind * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1.4.2 rmind * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1.4.2 rmind * SUCH DAMAGE.
32 1.1.4.2 rmind *
33 1.1.4.2 rmind * @(#)mkboot.c 8.1 (Berkeley) 7/15/93
34 1.1.4.2 rmind */
35 1.1.4.2 rmind
36 1.1.4.2 rmind #if 0
37 1.1.4.2 rmind #ifndef lint
38 1.1.4.2 rmind static char copyright[] =
39 1.1.4.2 rmind "@(#) Copyright (c) 1990, 1993\n\
40 1.1.4.2 rmind The Regents of the University of California. All rights reserved.\n";
41 1.1.4.2 rmind #endif /* not lint */
42 1.1.4.2 rmind
43 1.1.4.2 rmind #ifndef lint
44 1.1.4.2 rmind static char rcsid[] = "$OpenBSD: mkboot.c,v 1.9 2001/05/17 00:57:55 pvalchev Exp $";
45 1.1.4.2 rmind #endif /* not lint */
46 1.1.4.2 rmind #endif
47 1.1.4.2 rmind
48 1.1.4.2 rmind #if HAVE_NBTOOL_CONFIG_H
49 1.1.4.2 rmind #include "nbtool_config.h"
50 1.1.4.2 rmind #include "../../sys/sys/bootblock.h"
51 1.1.4.2 rmind #else
52 1.1.4.2 rmind #include <sys/bootblock.h>
53 1.1.4.2 rmind #endif
54 1.1.4.2 rmind
55 1.1.4.2 rmind #include <sys/param.h>
56 1.1.4.2 rmind #include <sys/file.h>
57 1.1.4.2 rmind #include <sys/stat.h>
58 1.1.4.2 rmind #include <string.h>
59 1.1.4.2 rmind #include <stdlib.h>
60 1.1.4.2 rmind #include <unistd.h>
61 1.1.4.2 rmind #include <time.h>
62 1.1.4.2 rmind #include <err.h>
63 1.1.4.2 rmind
64 1.1.4.2 rmind /* BFD ELF headers */
65 1.1.4.2 rmind #include <elf/common.h>
66 1.1.4.2 rmind #include <elf/external.h>
67 1.1.4.2 rmind
68 1.1.4.2 rmind #define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
69 1.1.4.2 rmind (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
70 1.1.4.2 rmind (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
71 1.1.4.2 rmind (ehdr).e_ident[EI_MAG3] == ELFMAG3)
72 1.1.4.2 rmind
73 1.1.4.2 rmind /*
74 1.1.4.2 rmind * Macros to get values from multi-byte ELF header fields. These assume
75 1.1.4.2 rmind * a big-endian image.
76 1.1.4.2 rmind */
77 1.1.4.2 rmind #define ELFGET16(x) (((x)[0] << 8) | (x)[1])
78 1.1.4.2 rmind
79 1.1.4.2 rmind #define ELFGET32(x) (((x)[0] << 24) | ((x)[1] << 16) | \
80 1.1.4.2 rmind ((x)[2] << 8) | (x)[3])
81 1.1.4.2 rmind
82 1.1.4.2 rmind /*
83 1.1.4.2 rmind * Header prepended to each a.out file.
84 1.1.4.2 rmind */
85 1.1.4.2 rmind struct exec {
86 1.1.4.2 rmind u_long a_midmag; /* htonl(flags<<26 | mid<<16 | magic) */
87 1.1.4.2 rmind u_long a_text; /* text segment size */
88 1.1.4.2 rmind u_long a_data; /* initialized data size */
89 1.1.4.2 rmind u_long a_bss; /* uninitialized data size */
90 1.1.4.2 rmind u_long a_syms; /* symbol table size */
91 1.1.4.2 rmind u_long a_entry; /* entry point */
92 1.1.4.2 rmind u_long a_trsize; /* text relocation size */
93 1.1.4.2 rmind u_long a_drsize; /* data relocation size */
94 1.1.4.2 rmind };
95 1.1.4.2 rmind
96 1.1.4.2 rmind /* a_magic */
97 1.1.4.2 rmind #define OMAGIC 0407 /* old impure format */
98 1.1.4.2 rmind #define NMAGIC 0410 /* read-only text */
99 1.1.4.2 rmind #define ZMAGIC 0413 /* demand load format */
100 1.1.4.2 rmind #define QMAGIC 0314 /* "compact" demand load format; deprecated */
101 1.1.4.2 rmind
102 1.1.4.2 rmind #define N_GETMAGIC(ex) \
103 1.1.4.2 rmind ((((ex).a_midmag)&0xffff0000) ? \
104 1.1.4.2 rmind (ntohl((uint32_t)((ex).a_midmag))&0xffff) : ((ex).a_midmag))
105 1.1.4.2 rmind
106 1.1.4.2 rmind #include <stdio.h>
107 1.1.4.2 rmind #include <ctype.h>
108 1.1.4.2 rmind
109 1.1.4.2 rmind int putfile(char *, int);
110 1.1.4.2 rmind void __dead usage(void);
111 1.1.4.2 rmind void bcddate(char *, char *);
112 1.1.4.2 rmind char *lifname(char *);
113 1.1.4.2 rmind int cksum(int, int *, int);
114 1.1.4.2 rmind
115 1.1.4.2 rmind char *to_file;
116 1.1.4.2 rmind int loadpoint, verbose;
117 1.1.4.2 rmind u_long entry;
118 1.1.4.2 rmind
119 1.1.4.2 rmind /*
120 1.1.4.2 rmind * Old Format:
121 1.1.4.2 rmind * sector 0: LIF volume header (40 bytes)
122 1.1.4.2 rmind * sector 1: <unused>
123 1.1.4.2 rmind * sector 2: LIF directory (8 x 32 == 256 bytes)
124 1.1.4.2 rmind * sector 3-: LIF file 0, LIF file 1, etc.
125 1.1.4.2 rmind * where sectors are 256 bytes.
126 1.1.4.2 rmind *
127 1.1.4.2 rmind * New Format:
128 1.1.4.2 rmind * sector 0: LIF volume header (40 bytes)
129 1.1.4.2 rmind * sector 1: <unused>
130 1.1.4.2 rmind * sector 2: LIF directory (8 x 32 == 256 bytes)
131 1.1.4.2 rmind * sector 3: <unused>
132 1.1.4.2 rmind * sector 4-31: disklabel (~300 bytes right now)
133 1.1.4.2 rmind * sector 32-: LIF file 0, LIF file 1, etc.
134 1.1.4.2 rmind */
135 1.1.4.2 rmind int
136 1.1.4.2 rmind main(int argc, char **argv)
137 1.1.4.2 rmind {
138 1.1.4.2 rmind int to, n, pos, c;
139 1.1.4.2 rmind char buf[HPPA_LIF_FILESTART];
140 1.1.4.2 rmind struct hppa_lifvol *lifv = (struct hppa_lifvol *)buf;
141 1.1.4.2 rmind struct hppa_lifdir *lifd = (struct hppa_lifdir *)(buf + HPPA_LIF_DIRSTART);
142 1.1.4.2 rmind
143 1.1.4.2 rmind while ((c = getopt(argc, argv, "vl:")) != -1) {
144 1.1.4.2 rmind switch (c) {
145 1.1.4.2 rmind case 'v':
146 1.1.4.2 rmind verbose++;
147 1.1.4.2 rmind break;
148 1.1.4.2 rmind case 'l':
149 1.1.4.2 rmind sscanf(optarg, "0x%x", &loadpoint);
150 1.1.4.2 rmind break;
151 1.1.4.2 rmind default:
152 1.1.4.2 rmind usage();
153 1.1.4.2 rmind }
154 1.1.4.2 rmind }
155 1.1.4.2 rmind if (argc - optind < 2)
156 1.1.4.2 rmind usage();
157 1.1.4.2 rmind else if (argc - optind > 8)
158 1.1.4.2 rmind errx(1, "too many boot programs (max 8 supported)");
159 1.1.4.2 rmind
160 1.1.4.2 rmind to_file = argv[--argc];
161 1.1.4.2 rmind if ((to = open(to_file, O_RDWR | O_TRUNC | O_CREAT, 0644)) < 0)
162 1.1.4.2 rmind err(1, "%s: open", to_file);
163 1.1.4.2 rmind
164 1.1.4.2 rmind memset(buf, 0, sizeof(buf));
165 1.1.4.2 rmind
166 1.1.4.2 rmind /* record volume info */
167 1.1.4.2 rmind lifv->vol_id = htobe16(HPPA_LIF_VOL_ID);
168 1.1.4.2 rmind strncpy(lifv->vol_label, "MKBOOT", 6);
169 1.1.4.2 rmind lifv->vol_addr = htobe32(hppa_btolifs(HPPA_LIF_DIRSTART));
170 1.1.4.2 rmind lifv->vol_oct = htobe16(HPPA_LIF_VOL_OCT);
171 1.1.4.2 rmind lifv->vol_dirsize = htobe32(hppa_btolifs(HPPA_LIF_DIRSIZE));
172 1.1.4.2 rmind lifv->vol_version = htobe16(1);
173 1.1.4.2 rmind lifv->vol_number = htobe32(1);
174 1.1.4.2 rmind lifv->vol_lastvol = htobe32(1);
175 1.1.4.2 rmind lifv->vol_length = HPPA_LIF_FILESTART; /* ... so far. */
176 1.1.4.2 rmind bcddate(to_file, lifv->vol_toc);
177 1.1.4.2 rmind lifv->ipl_addr = htobe32(HPPA_LIF_FILESTART);
178 1.1.4.2 rmind
179 1.1.4.2 rmind argv += optind;
180 1.1.4.2 rmind argc -= optind;
181 1.1.4.2 rmind optind = 0;
182 1.1.4.2 rmind for (pos = HPPA_LIF_FILESTART; optind < argc; optind++) {
183 1.1.4.2 rmind
184 1.1.4.2 rmind /* output bootfile */
185 1.1.4.2 rmind if (lseek(to, pos, SEEK_SET) < 0)
186 1.1.4.2 rmind err(1, "%s: lseek", to_file);
187 1.1.4.2 rmind lifd[optind].dir_addr = htobe32(hppa_btolifs(pos));
188 1.1.4.2 rmind n = hppa_btolifs(putfile(argv[optind], to));
189 1.1.4.2 rmind if (lifv->ipl_entry == 0) {
190 1.1.4.2 rmind lifv->ipl_entry = htobe32(loadpoint + entry);
191 1.1.4.2 rmind lifv->ipl_size = htobe32(hppa_lifstob(n));
192 1.1.4.2 rmind lifd[optind].dir_type = htobe16(HPPA_LIF_DIR_ISL);
193 1.1.4.2 rmind lifd[optind].dir_implement = 0;
194 1.1.4.2 rmind } else {
195 1.1.4.2 rmind lifd[optind].dir_type = htobe16(HPPA_LIF_DIR_TYPE);
196 1.1.4.2 rmind lifd[optind].dir_implement = htobe32(loadpoint + entry);
197 1.1.4.2 rmind }
198 1.1.4.2 rmind
199 1.1.4.2 rmind memcpy(lifd[optind].dir_name, lifname(argv[optind]),
200 1.1.4.2 rmind sizeof(lifd[optind].dir_name));
201 1.1.4.2 rmind lifd[optind].dir_length = htobe32(n);
202 1.1.4.2 rmind bcddate(argv[optind], lifd[optind].dir_toc);
203 1.1.4.2 rmind lifd[optind].dir_flag = htobe16(HPPA_LIF_DIR_FLAG);
204 1.1.4.2 rmind
205 1.1.4.2 rmind lifv->vol_length += n;
206 1.1.4.2 rmind pos += hppa_lifstob(n);
207 1.1.4.2 rmind }
208 1.1.4.2 rmind
209 1.1.4.2 rmind /* terminate the directory */
210 1.1.4.2 rmind lifd[optind].dir_type = htobe16(0xffff);
211 1.1.4.2 rmind
212 1.1.4.2 rmind /* byte-swap the length now that we're done computing it */
213 1.1.4.2 rmind lifv->vol_length = htobe32(lifv->vol_length);
214 1.1.4.2 rmind
215 1.1.4.2 rmind /* output volume/directory header info */
216 1.1.4.2 rmind if (lseek(to, HPPA_LIF_VOLSTART, SEEK_SET) < 0)
217 1.1.4.2 rmind err(1, "%s: lseek", to_file);
218 1.1.4.2 rmind if (write(to, buf, sizeof(buf)) != sizeof(buf))
219 1.1.4.2 rmind err(1, "%s: write LIF volume", to_file);
220 1.1.4.2 rmind lseek(to, 0, SEEK_END);
221 1.1.4.2 rmind
222 1.1.4.2 rmind if (close(to) < 0)
223 1.1.4.2 rmind err(1, "%s", to_file);
224 1.1.4.2 rmind
225 1.1.4.2 rmind return(0);
226 1.1.4.2 rmind }
227 1.1.4.2 rmind
228 1.1.4.2 rmind int
229 1.1.4.2 rmind putfile(char *from_file, int to)
230 1.1.4.2 rmind {
231 1.1.4.2 rmind struct exec ex;
232 1.1.4.2 rmind char buf[2048];
233 1.1.4.2 rmind int n, total;
234 1.1.4.2 rmind int from, check_sum = 0;
235 1.1.4.2 rmind struct hppa_lifload load;
236 1.1.4.2 rmind Elf32_External_Ehdr elf_header;
237 1.1.4.2 rmind Elf32_External_Phdr *elf_segments;
238 1.1.4.2 rmind int i, header_count, memory_needed, elf_load_image_segment;
239 1.1.4.2 rmind
240 1.1.4.2 rmind if ((from = open(from_file, O_RDONLY)) < 0)
241 1.1.4.2 rmind err(1, "%s", from_file);
242 1.1.4.2 rmind
243 1.1.4.2 rmind n = read(from, &ex, sizeof(ex));
244 1.1.4.2 rmind if (n != sizeof(ex))
245 1.1.4.2 rmind err(1, "%s: reading file header", from_file);
246 1.1.4.2 rmind
247 1.1.4.2 rmind entry = ex.a_entry;
248 1.1.4.2 rmind if (N_GETMAGIC(ex) == OMAGIC || N_GETMAGIC(ex) == NMAGIC)
249 1.1.4.2 rmind entry += sizeof(ex);
250 1.1.4.2 rmind else if (IS_ELF(*(Elf32_External_Ehdr *)&ex)) {
251 1.1.4.2 rmind
252 1.1.4.2 rmind if (lseek(from, 0, SEEK_SET) < 0)
253 1.1.4.2 rmind err(1, "lseek");
254 1.1.4.2 rmind n = read(from, &elf_header, sizeof (elf_header));
255 1.1.4.2 rmind if (n != sizeof (elf_header))
256 1.1.4.2 rmind err(1, "%s: reading ELF header", from_file);
257 1.1.4.2 rmind header_count = ELFGET16(elf_header.e_phnum);
258 1.1.4.2 rmind memory_needed = header_count * sizeof (Elf32_External_Phdr);
259 1.1.4.2 rmind elf_segments = malloc(memory_needed);
260 1.1.4.2 rmind if (elf_segments == NULL)
261 1.1.4.2 rmind err(1, "malloc");
262 1.1.4.2 rmind if (lseek(from, ELFGET32(elf_header.e_phoff), SEEK_SET) < 0)
263 1.1.4.2 rmind err(1, "lseek");
264 1.1.4.2 rmind n = read(from, elf_segments, memory_needed);
265 1.1.4.2 rmind if (n != memory_needed)
266 1.1.4.2 rmind err(1, "%s: reading ELF segments", from_file);
267 1.1.4.2 rmind elf_load_image_segment = -1;
268 1.1.4.2 rmind for (i = 0; i < header_count; i++) {
269 1.1.4.2 rmind if (ELFGET32(elf_segments[i].p_filesz) &&
270 1.1.4.2 rmind ELFGET32(elf_segments[i].p_flags) & PF_X) {
271 1.1.4.2 rmind if (elf_load_image_segment != -1)
272 1.1.4.2 rmind errx(1, "%s: more than one ELF program "
273 1.1.4.2 rmind "segment", from_file);
274 1.1.4.2 rmind elf_load_image_segment = i;
275 1.1.4.2 rmind }
276 1.1.4.2 rmind }
277 1.1.4.2 rmind if (elf_load_image_segment == -1)
278 1.1.4.2 rmind errx(1, "%s: no suitable ELF program segment",
279 1.1.4.2 rmind from_file);
280 1.1.4.2 rmind entry = ELFGET32(elf_header.e_entry) +
281 1.1.4.2 rmind ELFGET32(elf_segments[elf_load_image_segment].p_offset) -
282 1.1.4.2 rmind ELFGET32(elf_segments[elf_load_image_segment].p_vaddr);
283 1.1.4.2 rmind } else if (*(uint8_t *)&ex == 0x1f && ((uint8_t *)&ex)[1] == 0x8b) {
284 1.1.4.2 rmind entry = 0;
285 1.1.4.2 rmind } else
286 1.1.4.2 rmind errx(1, "%s: bad magic number", from_file);
287 1.1.4.2 rmind
288 1.1.4.2 rmind entry += sizeof(load);
289 1.1.4.2 rmind lseek(to, sizeof(load), SEEK_CUR);
290 1.1.4.2 rmind
291 1.1.4.2 rmind total = 0;
292 1.1.4.2 rmind n = sizeof(buf) - sizeof(load);
293 1.1.4.2 rmind /* copy the whole file */
294 1.1.4.2 rmind for (lseek(from, 0, SEEK_SET); ; n = sizeof(buf)) {
295 1.1.4.2 rmind memset(buf, 0, sizeof(buf));
296 1.1.4.2 rmind if ((n = read(from, buf, n)) < 0)
297 1.1.4.2 rmind err(1, "%s", from_file);
298 1.1.4.2 rmind else if (n == 0)
299 1.1.4.2 rmind break;
300 1.1.4.2 rmind
301 1.1.4.2 rmind if (write(to, buf, n) != n)
302 1.1.4.2 rmind err(1, "%s", to_file);
303 1.1.4.2 rmind
304 1.1.4.2 rmind total += n;
305 1.1.4.2 rmind check_sum = cksum(check_sum, (int *)buf, n);
306 1.1.4.2 rmind }
307 1.1.4.2 rmind
308 1.1.4.2 rmind /* load header */
309 1.1.4.2 rmind load.address = htobe32(loadpoint + sizeof(load));
310 1.1.4.2 rmind load.count = htobe32(4 + total);
311 1.1.4.2 rmind check_sum = cksum(check_sum, (int *)&load, sizeof(load));
312 1.1.4.2 rmind
313 1.1.4.2 rmind if (verbose)
314 1.1.4.2 rmind warnx("wrote %d bytes of file \'%s\'", total, from_file);
315 1.1.4.2 rmind
316 1.1.4.2 rmind total += sizeof(load);
317 1.1.4.2 rmind /* insert the header */
318 1.1.4.2 rmind lseek(to, -total, SEEK_CUR);
319 1.1.4.2 rmind if (write(to, &load, sizeof(load)) != sizeof(load))
320 1.1.4.2 rmind err(1, "%s", to_file);
321 1.1.4.2 rmind lseek(to, total - sizeof(load), SEEK_CUR);
322 1.1.4.2 rmind
323 1.1.4.2 rmind memset(buf, 0, sizeof(buf));
324 1.1.4.2 rmind /* pad to int */
325 1.1.4.2 rmind n = sizeof(int) - total % sizeof(int);
326 1.1.4.2 rmind if (total % sizeof(int)) {
327 1.1.4.2 rmind if (write(to, buf, n) != n)
328 1.1.4.2 rmind err(1, "%s", to_file);
329 1.1.4.2 rmind else
330 1.1.4.2 rmind total += n;
331 1.1.4.2 rmind }
332 1.1.4.2 rmind
333 1.1.4.2 rmind /* pad to the blocksize */
334 1.1.4.2 rmind n = sizeof(buf) - total % sizeof(buf);
335 1.1.4.2 rmind
336 1.1.4.2 rmind if (n < sizeof(int)) {
337 1.1.4.2 rmind n += sizeof(buf);
338 1.1.4.2 rmind total += sizeof(buf);
339 1.1.4.2 rmind } else
340 1.1.4.2 rmind total += n;
341 1.1.4.2 rmind
342 1.1.4.2 rmind /* TODO should pad here to the 65k boundary for tape boot */
343 1.1.4.2 rmind
344 1.1.4.2 rmind if (verbose)
345 1.1.4.2 rmind warnx("checksum is 0x%08x", -check_sum);
346 1.1.4.2 rmind
347 1.1.4.2 rmind check_sum = htobe32(-check_sum);
348 1.1.4.2 rmind if (write(to, &check_sum, sizeof(int)) != sizeof(int))
349 1.1.4.2 rmind err(1, "%s", to_file);
350 1.1.4.2 rmind
351 1.1.4.2 rmind n -= sizeof(int);
352 1.1.4.2 rmind
353 1.1.4.2 rmind if (write(to, buf, n) != n)
354 1.1.4.2 rmind err(1, "%s", to_file);
355 1.1.4.2 rmind
356 1.1.4.2 rmind if (close(from) < 0)
357 1.1.4.2 rmind err(1, "%s", from_file);
358 1.1.4.2 rmind
359 1.1.4.2 rmind return total;
360 1.1.4.2 rmind }
361 1.1.4.2 rmind
362 1.1.4.2 rmind int
363 1.1.4.2 rmind cksum(int ck, int *p, int size)
364 1.1.4.2 rmind {
365 1.1.4.2 rmind /* we assume size is int-aligned */
366 1.1.4.2 rmind for (size = (size + sizeof(int) - 1) / sizeof(int); size--; p++ )
367 1.1.4.2 rmind ck += be32toh(*p);
368 1.1.4.2 rmind
369 1.1.4.2 rmind return ck;
370 1.1.4.2 rmind }
371 1.1.4.2 rmind
372 1.1.4.2 rmind void __dead
373 1.1.4.2 rmind usage(void)
374 1.1.4.2 rmind {
375 1.1.4.2 rmind fprintf(stderr,
376 1.1.4.2 rmind "usage: %s [-v] [-l loadpoint] prog1 {progN} outfile\n",
377 1.1.4.2 rmind getprogname());
378 1.1.4.2 rmind exit(1);
379 1.1.4.2 rmind }
380 1.1.4.2 rmind
381 1.1.4.2 rmind char *
382 1.1.4.2 rmind lifname(char *str)
383 1.1.4.2 rmind {
384 1.1.4.2 rmind static char lname[10] = "XXXXXXXXXX";
385 1.1.4.2 rmind char *cp;
386 1.1.4.2 rmind int i;
387 1.1.4.2 rmind
388 1.1.4.2 rmind cp = strrchr(str, '/');
389 1.1.4.2 rmind if (cp != NULL) {
390 1.1.4.2 rmind str = cp + 1;
391 1.1.4.2 rmind }
392 1.1.4.2 rmind for (i = 0; i < 9; i++) {
393 1.1.4.2 rmind if (islower(*str))
394 1.1.4.2 rmind lname[i] = toupper(*str);
395 1.1.4.2 rmind else if (isalnum(*str) || *str == '_')
396 1.1.4.2 rmind lname[i] = *str;
397 1.1.4.2 rmind else
398 1.1.4.2 rmind break;
399 1.1.4.2 rmind str++;
400 1.1.4.2 rmind }
401 1.1.4.2 rmind for ( ; i < 10; i++)
402 1.1.4.2 rmind lname[i] = ' ';
403 1.1.4.2 rmind return(lname);
404 1.1.4.2 rmind }
405 1.1.4.2 rmind
406 1.1.4.2 rmind
407 1.1.4.2 rmind void
408 1.1.4.2 rmind bcddate(char *file, char *toc)
409 1.1.4.2 rmind {
410 1.1.4.2 rmind struct stat statb;
411 1.1.4.2 rmind struct tm *tm;
412 1.1.4.2 rmind
413 1.1.4.2 rmind stat(file, &statb);
414 1.1.4.2 rmind tm = localtime(&statb.st_ctime);
415 1.1.4.2 rmind tm->tm_year %= 100;
416 1.1.4.2 rmind *toc = (tm->tm_year / 10) << 4;
417 1.1.4.2 rmind *toc++ |= tm->tm_year % 10;
418 1.1.4.2 rmind *toc = ((tm->tm_mon+1) / 10) << 4;
419 1.1.4.2 rmind *toc++ |= (tm->tm_mon+1) % 10;
420 1.1.4.2 rmind *toc = (tm->tm_mday / 10) << 4;
421 1.1.4.2 rmind *toc++ |= tm->tm_mday % 10;
422 1.1.4.2 rmind *toc = (tm->tm_hour / 10) << 4;
423 1.1.4.2 rmind *toc++ |= tm->tm_hour % 10;
424 1.1.4.2 rmind *toc = (tm->tm_min / 10) << 4;
425 1.1.4.2 rmind *toc++ |= tm->tm_min % 10;
426 1.1.4.2 rmind *toc = (tm->tm_sec / 10) << 4;
427 1.1.4.2 rmind *toc |= tm->tm_sec % 10;
428 1.1.4.2 rmind }
429