md.c revision 1.3 1 /* $NetBSD: md.c,v 1.3 2019/06/12 06:20:22 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 -- sandpoint machine specific routines */
36
37 #include <sys/param.h>
38 #include <sys/sysctl.h>
39 #include <sys/utsname.h>
40
41 #include <stdio.h>
42 #include <string.h>
43 #include <util.h>
44
45 #include "defs.h"
46 #include "md.h"
47 #include "msg_defs.h"
48 #include "menu_defs.h"
49
50 static char *prodname;
51
52 void
53 md_init(void)
54 {
55 }
56
57 void
58 md_init_set_status(int flags)
59 {
60 static const char mib_name[] = "machdep.prodfamily";
61 static char unknown[] = "unknown";
62 size_t len;
63
64 (void)flags;
65
66 /*
67 * Determine the product family of the board we are running on and
68 * enable the installation of the corresponding GENERIC kernel.
69 *
70 * Note: In md.h the two kernels are disabled. If they are
71 * enabled there the logic here needs to be switched.
72 */
73 if (sysctlbyname(mib_name, NULL, &len, NULL, 0) != 0) {
74 prodname = unknown;
75 return;
76 }
77 prodname = malloc(len);
78 sysctlbyname(mib_name, prodname, &len, NULL, 0);
79
80 if (strcmp(prodname, "kurobox")==0 || strcmp(prodname, "kurot4")==0)
81 /*
82 * Running on a KuroBox family product, so enable KUROBOX
83 */
84 set_kernel_set(SET_KERNEL_2);
85 else
86 /*
87 * Otherwise enable GENERIC
88 */
89 set_kernel_set(SET_KERNEL_1);
90 }
91
92 bool
93 md_get_info(struct install_partition_desc *install)
94 {
95 return set_bios_geom_with_mbr_guess(pm->parts);
96 }
97
98 /*
99 * md back-end code for menu-driven BSD disklabel editor.
100 */
101 bool
102 md_make_bsd_partitions(struct install_partition_desc *install)
103 {
104 return make_bsd_partitions(install);
105 }
106
107 /*
108 * any additional partition validation
109 */
110 bool
111 md_check_partitions(struct install_partition_desc *install)
112 {
113 return true;
114 }
115
116 /*
117 * hook called before writing new disklabel.
118 */
119 bool
120 md_pre_disklabel(struct install_partition_desc *install,
121 struct disk_partitions *parts)
122 {
123
124 if (parts->parent == NULL)
125 return true; /* no outer partitions */
126
127 parts = parts->parent;
128
129 msg_display_subst(MSG_dofdisk, 3, parts->disk,
130 msg_string(parts->pscheme->name),
131 msg_string(parts->pscheme->short_name));
132
133 /* write edited "MBR" onto disk. */
134 if (!parts->pscheme->write_to_disk(parts)) {
135 msg_display(MSG_wmbrfail);
136 process_menu(MENU_ok, NULL);
137 return false;
138 }
139 return true;
140 }
141
142 /*
143 * hook called after writing disklabel to new target disk.
144 */
145 bool
146 md_post_disklabel(struct install_partition_desc *install,
147 struct disk_partitions *parts)
148 {
149 return true;
150 }
151
152 /*
153 * hook called after upgrade() or install() has finished setting
154 * up the target disk but immediately before the user is given the
155 * ``disks are now set up'' message.
156 */
157 int
158 md_post_newfs(struct install_partition_desc *install)
159 {
160 /* no boot blocks, we are using altboot */
161 return 0;
162 }
163
164 int
165 md_post_extract(struct install_partition_desc *install)
166 {
167 return 0;
168 }
169
170 void
171 md_cleanup_install(struct install_partition_desc *install)
172 {
173 #ifndef DEBUG
174 int new_speed;
175
176 enable_rc_conf();
177
178 /*
179 * Set the console speed in /etc/ttys depending on the board.
180 * The default speed is 115200, which is patched when needed.
181 */
182 if (strcmp(prodname, "kurobox")==0 || strcmp(prodname, "kurot4")==0)
183 new_speed = 57600; /* KuroBox */
184
185 else if (strcmp(prodname, "dlink") == 0 || /* D-Link DSM-G600 */
186 strcmp(prodname, "nhnas") == 0) /* NH23x, All6250 */
187 new_speed = 9600;
188
189 else
190 new_speed = 0;
191
192 if (new_speed != 0) {
193 run_program(RUN_CHROOT, "sed -an -e 's/115200/%d/;H;$!d;g;w"
194 "/etc/ttys' /etc/ttys", new_speed);
195 }
196 #endif
197 }
198
199 int
200 md_pre_update(struct install_partition_desc *install)
201 {
202 return 1;
203 }
204
205 /* Upgrade support */
206 int
207 md_update(struct install_partition_desc *install)
208 {
209 md_post_newfs(install);
210 return 1;
211 }
212
213 int
214 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
215 {
216 return 2;
217 }
218
219 bool
220 md_parts_use_wholedisk(struct disk_partitions *parts)
221 {
222 return parts_use_wholedisk(parts, 0, NULL);
223 }
224
225 int
226 md_pre_mount(struct install_partition_desc *install)
227 {
228 return 0;
229 }
230
231 bool
232 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
233 {
234 return false; /* no change, no need to write back */
235 }
236
237 #ifdef HAVE_GPT
238 bool
239 md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
240 bool root_is_new, part_id efi_id, bool efi_is_new)
241 {
242 /* no GPT boot support, nothing needs to be done here */
243 return true;
244 }
245 #endif
246
247