Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / usr.sbin / installboot / arch / ews4800mips.c
blob1ee77644fcf6461328ec31dbd9b5a47682aa4b7b
2 #if HAVE_NBTOOL_CONFIG_H
3 #include "nbtool_config.h"
4 #endif
6 #include <sys/cdefs.h>
7 #if !defined(__lint)
8 __RCSID("$NetBSD: ews4800mips.c,v 1.1 2005/12/29 15:32:20 tsutsui Exp $");
9 #endif /* !__lint */
11 #include <sys/param.h>
12 #include <unistd.h>
13 #include <err.h>
14 #include <stdio.h>
15 #include "installboot.h"
17 static int ews4800mips_setboot(ib_params *);
19 struct ib_mach ib_mach_ews4800mips =
20 { "ews4800mips", ews4800mips_setboot, no_clearboot, no_editboot, 0};
22 struct bbinfo_params ews4800mips_bbparams = {
23 EWS4800MIPS_BBINFO_MAGIC,
24 EWS4800MIPS_BOOT_BLOCK_OFFSET,
25 EWS4800MIPS_BOOT_BLOCK_BLOCKSIZE,
26 EWS4800MIPS_BOOT_BLOCK_MAX_SIZE,
28 BBINFO_BIG_ENDIAN,
31 static int
32 ews4800mips_setboot(ib_params *params)
34 u_int8_t buf[EWS4800MIPS_BOOT_BLOCK_MAX_SIZE];
35 int rv;
37 rv = pread(params->s1fd, buf, sizeof buf, 0);
38 if (rv == -1) {
39 warn("Reading `%s'", params->stage1);
40 return 0;
41 } else if (rv != sizeof buf) {
42 warnx("Reading `%s' : short read", params->stage1);
43 return 0;
46 if (params->flags & IB_NOWRITE)
47 return 1;
49 if (params->flags & IB_VERBOSE)
50 printf("Writing boot block\n");
52 rv = pwrite(params->fsfd, buf, sizeof buf, 0);
53 if (rv == -1) {
54 warn("Writing `%s'", params->filesystem);
55 return 0;
56 } else if (rv != sizeof buf) {
57 warnx("Writing `%s': short write", params->filesystem);
58 return 0;
61 return 1;