1 /* $NetBSD: amiga.c,v 1.5 2006/02/18 10:08:07 dsl Exp $ */
4 * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Luke Mewburn of Wasabi Systems.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
35 #if HAVE_NBTOOL_CONFIG_H
36 #include "nbtool_config.h"
39 #include <sys/cdefs.h>
40 #if defined(__RCSID) && !defined(__lint)
41 __RCSID("$NetBSD: amiga.c,v 1.5 2006/02/18 10:08:07 dsl Exp $");
44 #include <sys/param.h>
55 #include "installboot.h"
57 /* XXX Must be kept in sync with bbstart.s! */
58 #define CMDLN_LOC 0x10
59 #define CMDLN_LEN 0x20
63 u_int32_t
chksum(u_int32_t
*, int);
65 static int amiga_setboot(ib_params
*);
67 struct ib_mach ib_mach_amiga
=
68 { "amiga", amiga_setboot
, no_clearboot
, no_editboot
,
69 IB_STAGE1START
| IB_STAGE2START
| IB_COMMAND
};
72 amiga_setboot(ib_params
*params
)
78 u_int32_t sum2
, sum16
;
80 struct stat bootstrapsb
;
82 u_int32_t block
[128*16];
85 if (fstat(params
->s1fd
, &bootstrapsb
) == -1) {
86 warn("Examining `%s'", params
->stage1
);
89 if (!S_ISREG(bootstrapsb
.st_mode
)) {
90 warnx("`%s' must be a regular file", params
->stage1
);
94 rv
= pread(params
->s1fd
, &block
, sizeof(block
), 0);
96 warn("Reading `%s'", params
->stage1
);
98 } else if (rv
!= sizeof(block
)) {
99 warnx("Reading `%s': short read", params
->stage1
);
103 /* XXX the choices should not be hardcoded */
105 sum2
= chksum(block
, 1024/4);
106 sum16
= chksum(block
, 8192/4);
108 if (sum16
== 0xffffffff) {
110 } else if (sum2
== 0xffffffff) {
113 errx(1, "%s: wrong checksum", params
->stage1
);
118 warnx("eek - both sums are the same");
121 if (params
->flags
& IB_COMMAND
) {
122 dline
= (char *)&(block
[CMDLN_LOC
/4]);
123 /* XXX keep the default default line in sync with bbstart.s */
124 if (strcmp(dline
, "netbsd -ASn2") != 0) {
125 errx(1, "Old bootblock version? Can't change command line.");
127 (void)strncpy(dline
, params
->command
, CMDLN_LEN
-1);
130 block
[1] = 0xffffffff - chksum(block
, sumlen
);
133 if (params
->flags
& IB_NOWRITE
) {
138 if (params
->flags
& IB_VERBOSE
)
139 printf("Writing boot block\n");
140 rv
= pwrite(params
->fsfd
, &block
, sizeof(block
), 0);
142 warn("Writing `%s'", params
->filesystem
);
144 } else if (rv
!= sizeof(block
)) {
145 warnx("Writing `%s': short write", params
->filesystem
);
160 u_int32_t sum
, lastsum
;
165 for (i
=0; i
<size
; i
++) {
167 sum
+= htobe32(block
[i
]);