xref: /netbsd-src/usr.sbin/installboot/arch/ews4800mips.c (revision e5c09b191b3a14e8b4648a699077b773caf1ed9b)
1 
2 #if HAVE_NBTOOL_CONFIG_H
3 #include "nbtool_config.h"
4 #endif
5 
6 #include <sys/cdefs.h>
7 #if !defined(__lint)
8 __RCSID("$NetBSD: ews4800mips.c,v 1.3 2019/05/07 04:35:31 thorpej Exp $");
9 #endif	/* !__lint */
10 
11 #include <sys/param.h>
12 #include <unistd.h>
13 #include <err.h>
14 #include <stdio.h>
15 #include "installboot.h"
16 
17 static int ews4800mips_setboot(ib_params *);
18 
19 struct ib_mach ib_mach_ews4800mips = {
20 	.name		=	"ews4800mips",
21 	.setboot	=	ews4800mips_setboot,
22 	.clearboot	=	no_clearboot,
23 	.editboot	=	no_editboot,
24 };
25 
26 struct bbinfo_params ews4800mips_bbparams = {
27 	EWS4800MIPS_BBINFO_MAGIC,
28 	EWS4800MIPS_BOOT_BLOCK_OFFSET,
29 	EWS4800MIPS_BOOT_BLOCK_BLOCKSIZE,
30 	EWS4800MIPS_BOOT_BLOCK_MAX_SIZE,
31 	0,
32 	BBINFO_BIG_ENDIAN,
33 };
34 
35 static int
ews4800mips_setboot(ib_params * params)36 ews4800mips_setboot(ib_params *params)
37 {
38 	u_int8_t buf[EWS4800MIPS_BOOT_BLOCK_MAX_SIZE];
39 	int rv;
40 
41 	rv = pread(params->s1fd, buf, sizeof buf, 0);
42 	if (rv == -1) {
43 		warn("Reading `%s'", params->stage1);
44 		return 0;
45 	} else if (rv != sizeof buf) {
46 		warnx("Reading `%s' : short read", params->stage1);
47 		return 0;
48 	}
49 
50 	if (params->flags & IB_NOWRITE)
51 		return 1;
52 
53 	if (params->flags & IB_VERBOSE)
54 		printf("Writing boot block\n");
55 
56 	rv = pwrite(params->fsfd, buf, sizeof buf, 0);
57 	if (rv == -1) {
58 		warn("Writing `%s'", params->filesystem);
59 		return 0;
60 	} else if (rv != sizeof buf) {
61 		warnx("Writing `%s': short write", params->filesystem);
62 		return 0;
63 	}
64 
65 	return 1;
66 }
67