xref: /netbsd-src/usr.sbin/sysinst/arch/zaurus/md.c (revision 4b2364d962896663e7fd2dabc7dac582c3631f68)
1 /*	$NetBSD: md.c,v 1.2 2014/08/03 16:09:41 martin Exp $	*/
2 
3 /*
4  * Copyright 1997 Piermont Information Systems Inc.
5  * All rights reserved.
6  *
7  * Based on code written by Philip A. Nelson for Piermont Information
8  * Systems Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
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.
18  * 3. The name of Piermont Information Systems Inc. may not be used to endorse
19  *    or promote products derived from this software without specific prior
20  *    written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
23  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
26  * 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
32  * THE POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /* md.c -- zaurus machine specific routines */
36 
37 #include <sys/param.h>
38 #include <sys/sysctl.h>
39 
40 #include <stdio.h>
41 #include <util.h>
42 
43 #include "defs.h"
44 #include "md.h"
45 #include "msg_defs.h"
46 #include "menu_defs.h"
47 
48 void
49 md_init(void)
50 {
51 }
52 
53 void
54 md_init_set_status(int flags)
55 {
56 	static const int mib[2] = {CTL_KERN, KERN_VERSION};
57 	size_t len;
58 	char *version;
59 
60 	/* check INSTALL kernel name to select an appropriate kernel set */
61 	/* XXX: hw.cpu_model has a processor name on arm ports */
62 	sysctl(mib, 2, NULL, &len, NULL, 0);
63 	version = malloc(len);
64 	if (version == NULL)
65 		return;
66 	sysctl(mib, 2, version, &len, NULL, 0);
67 	if (strstr(version, "C700") != NULL)
68 		set_kernel_set(SET_KERNEL_C700);
69 	free(version);
70 }
71 
72 int
73 md_get_info(void)
74 {
75 	return set_bios_geom_with_mbr_guess();
76 }
77 
78 int
79 md_make_bsd_partitions(void)
80 {
81 	return make_bsd_partitions();
82 }
83 
84 /*
85  * any additional partition validation
86  */
87 int
88 md_check_partitions(void)
89 {
90 	return 1;
91 }
92 
93 /*
94  * hook called before writing new disklabel.
95  */
96 int
97 md_pre_disklabel(void)
98 {
99 
100 	msg_display(MSG_dofdisk);
101 
102 	/* write edited MBR onto disk. */
103 	if (write_mbr(pm->diskdev, &mbr, 1) != 0) {
104 		msg_display(MSG_wmbrfail);
105 		process_menu(MENU_ok, NULL);
106 		return 1;
107 	}
108 	return 0;
109 }
110 
111 /*
112  * hook called after writing disklabel to new target disk.
113  */
114 int
115 md_post_disklabel(void)
116 {
117 	return 0;
118 }
119 
120 /*
121  * hook called after upgrade() or install() has finished setting
122  * up the target disk but immediately before the user is given the
123  * ``disks are now set up'' message.
124  */
125 int
126 md_post_newfs(void)
127 {
128 	struct mbr_sector pbr;
129 	char adevname[STRSIZE];
130 	ssize_t sz;
131 	int fd = -1;
132 
133 	snprintf(adevname, sizeof(adevname), "/dev/r%sa", pm->diskdev);
134 	fd = open(adevname, O_RDWR);
135 	if (fd < 0)
136 		goto out;
137 
138 	/* Read partition boot record */
139 	sz = pread(fd, &pbr, sizeof(pbr), 0);
140 	if (sz != sizeof(pbr))
141 		goto out;
142 
143 	/* Check magic number */
144 	if (pbr.mbr_magic != le16toh(MBR_MAGIC))
145 		goto out;
146 
147 #define	OSNAME	"NetBSD60"
148 	/* Update oemname */
149 	memcpy(&pbr.mbr_oemname, OSNAME, sizeof(OSNAME) - 1);
150 
151 	/* Clear BPB */
152 	memset(&pbr.mbr_bpb, 0, sizeof(pbr.mbr_bpb));
153 
154 	/* write-backed new patition boot record */
155 	(void)pwrite(fd, &pbr, sizeof(pbr), 0);
156 
157 out:
158 	if (fd >= 0)
159 		close(fd);
160 	return 0;
161 }
162 
163 int
164 md_post_extract(void)
165 {
166 	return 0;
167 }
168 
169 void
170 md_cleanup_install(void)
171 {
172 #ifndef DEBUG
173 	enable_rc_conf();
174 #endif
175 }
176 
177 int
178 md_pre_update(void)
179 {
180 	return 1;
181 }
182 
183 /* Upgrade support */
184 int
185 md_update(void)
186 {
187 	md_post_newfs();
188 	return 1;
189 }
190 
191 int
192 md_check_mbr(mbr_info_t *mbri)
193 {
194 
195 	(void)mbri;
196 	return 2;
197 }
198 
199 int
200 md_mbr_use_wholedisk(mbr_info_t *mbri)
201 {
202 
203 	return mbr_use_wholedisk(mbri);
204 }
205 
206 
207 int
208 md_pre_mount()
209 {
210 	return 0;
211 }
212