xref: /netbsd-src/usr.sbin/sysinst/arch/evbppc/md.c (revision 8d626ee2f883c1469274039c561b1f5e36459127)
1 /*	$NetBSD: md.c,v 1.11 2024/01/20 21:36:00 jmcneill Exp $ */
2 
3 /*
4  * Copyright 1997,2002 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 -- evbppc machine specific routines */
36 
37 #include <sys/param.h>
38 #include <sys/sysctl.h>
39 #include <sys/utsname.h>
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
md_init(void)49 md_init(void)
50 {
51 }
52 
53 void
md_init_set_status(int flags)54 md_init_set_status(int flags)
55 {
56 	struct utsname instsys;
57 
58 	(void)flags;
59 
60 	/*
61 	 * Get the name of the install kernel we are running under and
62 	 * enable the installation of the corresponding kernel.
63 	 */
64 	uname(&instsys);
65 	if (strstr(instsys.version, "(INSTALL_WII")) {
66 		set_kernel_set(EVBPPC_SET_KERNEL_WII);
67 		set_noextract_set(EVBPPC_SET_KERNEL_WII);
68 	}
69 }
70 
71 bool
md_get_info(struct install_partition_desc * install)72 md_get_info(struct install_partition_desc *install)
73 {
74 	int res;
75 
76 	if (pm->no_mbr || pm->no_part)
77 		return true;
78 
79 again:
80 	if (pm->parts == NULL) {
81 
82 		const struct disk_partitioning_scheme *ps =
83 		    select_part_scheme(pm, NULL, true, NULL);
84 
85 		if (!ps)
86 			return false;
87 
88 		struct disk_partitions *parts =
89 		   (*ps->create_new_for_disk)(pm->diskdev,
90 		   0, pm->dlsize, true, NULL);
91 		if (!parts)
92 			return false;
93 
94 		pm->parts = parts;
95 		if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
96 			pm->dlsize = ps->size_limit;
97 	}
98 
99 	res = set_bios_geom_with_mbr_guess(pm->parts);
100 	if (res == 0)
101 		return false;
102 	else if (res == 1)
103 		return true;
104 
105 	pm->parts->pscheme->destroy_part_scheme(pm->parts);
106 	pm->parts = NULL;
107 	goto again;
108 }
109 
110 /*
111  * md back-end code for menu-driven BSD disklabel editor.
112  */
113 int
md_make_bsd_partitions(struct install_partition_desc * install)114 md_make_bsd_partitions(struct install_partition_desc *install)
115 {
116 	return make_bsd_partitions(install);
117 }
118 
119 /*
120  * any additional partition validation
121  */
122 bool
md_check_partitions(struct install_partition_desc * install)123 md_check_partitions(struct install_partition_desc *install)
124 {
125 	return true;
126 }
127 
128 /*
129  * hook called before writing new disklabel.
130  */
131 bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)132 md_pre_disklabel(struct install_partition_desc *install,
133     struct disk_partitions *parts)
134 {
135 
136 	if (parts->parent == NULL)
137 		return true;	/* no outer partitions */
138 
139 	parts = parts->parent;
140 
141 	msg_display_subst(MSG_dofdisk, 3, parts->disk,
142 	    msg_string(parts->pscheme->name),
143 	    msg_string(parts->pscheme->short_name));
144 
145 	/* write edited "MBR" onto disk. */
146 	if (!parts->pscheme->write_to_disk(parts)) {
147 		msg_display(MSG_wmbrfail);
148 		process_menu(MENU_ok, NULL);
149 		return false;
150 	}
151 	return true;
152 }
153 
154 /*
155  * hook called after writing disklabel to new target disk.
156  */
157 bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)158 md_post_disklabel(struct install_partition_desc *install,
159     struct disk_partitions *parts)
160 {
161 	return true;
162 }
163 
164 /*
165  * hook called after upgrade() or install() has finished setting
166  * up the target disk but immediately before the user is given the
167  * ``disks are now set up'' message.
168  */
169 int
md_post_newfs(struct install_partition_desc * install)170 md_post_newfs(struct install_partition_desc *install)
171 {
172 	/* Walnut doesn't do bootblocks */
173 	return 0;
174 }
175 
176 int
md_post_extract(struct install_partition_desc * install,bool upgrade)177 md_post_extract(struct install_partition_desc *install, bool upgrade)
178 {
179 	return 0;
180 }
181 
182 void
md_cleanup_install(struct install_partition_desc * install)183 md_cleanup_install(struct install_partition_desc *install)
184 {
185 #ifndef DEBUG
186 	enable_rc_conf();
187 #endif
188 }
189 
190 int
md_pre_update(struct install_partition_desc * install)191 md_pre_update(struct install_partition_desc *install)
192 {
193 	return 1;
194 }
195 
196 /* Upgrade support */
197 int
md_update(struct install_partition_desc * install)198 md_update(struct install_partition_desc *install)
199 {
200 	md_post_newfs(install);
201 	return 1;
202 }
203 
204 int
md_check_mbr(struct disk_partitions * parts,mbr_info_t * mbri,bool quiet)205 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
206 {
207 	return 2;
208 }
209 
210 bool
md_parts_use_wholedisk(struct disk_partitions * parts)211 md_parts_use_wholedisk(struct disk_partitions *parts)
212 {
213 	return parts_use_wholedisk(parts, 0, NULL);
214 }
215 
216 int
md_pre_mount(struct install_partition_desc * install,size_t ndx)217 md_pre_mount(struct install_partition_desc *install, size_t ndx)
218 {
219 	return 0;
220 }
221 
222 bool
md_mbr_update_check(struct disk_partitions * parts,mbr_info_t * mbri)223 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
224 {
225 	return false;	/* no change, no need to write back */
226 }
227 
228 #ifdef HAVE_GPT
229 bool
md_gpt_post_write(struct disk_partitions * parts,part_id root_id,bool root_is_new,part_id efi_id,bool efi_is_new)230 md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
231     bool root_is_new, part_id efi_id, bool efi_is_new)
232 {
233 	/* no GPT boot support, nothing needs to be done here */
234 	return true;
235 }
236 #endif
237