xref: /netbsd-src/usr.sbin/sysinst/arch/playstation2/md.c (revision 4204f81037ec1430b81b70ee975f04b277901e24)
1*4204f810Smartin /*	$NetBSD: md.c,v 1.10 2022/01/29 16:01:20 martin Exp $ */
250dbef1aSdholland 
350dbef1aSdholland /*
450dbef1aSdholland  * Copyright 1997 Piermont Information Systems Inc.
550dbef1aSdholland  * All rights reserved.
650dbef1aSdholland  *
750dbef1aSdholland  * Based on code written by Philip A. Nelson for Piermont Information
850dbef1aSdholland  * Systems Inc.
950dbef1aSdholland  *
1050dbef1aSdholland  * Redistribution and use in source and binary forms, with or without
1150dbef1aSdholland  * modification, are permitted provided that the following conditions
1250dbef1aSdholland  * are met:
1350dbef1aSdholland  * 1. Redistributions of source code must retain the above copyright
1450dbef1aSdholland  *    notice, this list of conditions and the following disclaimer.
1550dbef1aSdholland  * 2. Redistributions in binary form must reproduce the above copyright
1650dbef1aSdholland  *    notice, this list of conditions and the following disclaimer in the
1750dbef1aSdholland  *    documentation and/or other materials provided with the distribution.
1850dbef1aSdholland  * 3. All advertising materials mentioning features or use of this software
1950dbef1aSdholland  *    must display the following acknowledgement:
2050dbef1aSdholland  *      This product includes software developed for the NetBSD Project by
2150dbef1aSdholland  *      Piermont Information Systems Inc.
2250dbef1aSdholland  * 4. The name of Piermont Information Systems Inc. may not be used to endorse
2350dbef1aSdholland  *    or promote products derived from this software without specific prior
2450dbef1aSdholland  *    written permission.
2550dbef1aSdholland  *
2650dbef1aSdholland  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
2750dbef1aSdholland  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2850dbef1aSdholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2950dbef1aSdholland  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
3050dbef1aSdholland  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3150dbef1aSdholland  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3250dbef1aSdholland  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3350dbef1aSdholland  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3450dbef1aSdholland  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3550dbef1aSdholland  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3650dbef1aSdholland  * THE POSSIBILITY OF SUCH DAMAGE.
3750dbef1aSdholland  */
3850dbef1aSdholland 
3950dbef1aSdholland /* md.c -- playstation2 machine specific routines */
4050dbef1aSdholland 
4150dbef1aSdholland #include <stdio.h>
4250dbef1aSdholland #include <util.h>
4350dbef1aSdholland #include <sys/param.h>
4450dbef1aSdholland #include <sys/sysctl.h>
4550dbef1aSdholland 
4650dbef1aSdholland #include "defs.h"
4750dbef1aSdholland #include "md.h"
4850dbef1aSdholland #include "msg_defs.h"
4950dbef1aSdholland #include "menu_defs.h"
5050dbef1aSdholland 
5150dbef1aSdholland void
md_init(void)5250dbef1aSdholland md_init(void)
5350dbef1aSdholland {
5450dbef1aSdholland }
5550dbef1aSdholland 
5650dbef1aSdholland void
md_init_set_status(int minimal)5750dbef1aSdholland md_init_set_status(int minimal)
5850dbef1aSdholland {
5950dbef1aSdholland 	(void)minimal;
6050dbef1aSdholland }
6150dbef1aSdholland 
624103857bSmartin bool
md_get_info(struct install_partition_desc * install)634103857bSmartin md_get_info(struct install_partition_desc *install)
6450dbef1aSdholland {
65957b5cd6Smartin 	int cyl, head, sec, res;
6650dbef1aSdholland 
674103857bSmartin 	if (pm->no_mbr || pm->no_part)
684103857bSmartin 		return true;
694103857bSmartin 
70957b5cd6Smartin again:
714103857bSmartin 	if (pm->parts == NULL) {
724103857bSmartin 
734103857bSmartin 		const struct disk_partitioning_scheme *ps =
744103857bSmartin 		    select_part_scheme(pm, NULL, true, NULL);
754103857bSmartin 
764103857bSmartin 		if (!ps)
776fec6798Smartin 			return false;
784103857bSmartin 
794103857bSmartin 		struct disk_partitions *parts =
804103857bSmartin 		   (*ps->create_new_for_disk)(pm->diskdev,
8186906049Smartin 		   0, pm->dlsize, true, NULL);
824103857bSmartin 		if (!parts)
834103857bSmartin 			return false;
844103857bSmartin 
854103857bSmartin 		pm->parts = parts;
864103857bSmartin 		if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
874103857bSmartin 			pm->dlsize = ps->size_limit;
884103857bSmartin 	}
8950dbef1aSdholland 
9024ecf24eSchristos 	msg_fmt_display(MSG_nobiosgeom, "%d%d%d",
9124ecf24eSchristos 	    pm->dlcyl, pm->dlhead, pm->dlsec);
9250dbef1aSdholland 
934103857bSmartin 	if (guess_biosgeom_from_parts(pm->parts, &cyl, &head, &sec) >= 0
944103857bSmartin 	    && pm->parts->pscheme->change_disk_geom != NULL)
954103857bSmartin 		pm->parts->pscheme->change_disk_geom(pm->parts,
964103857bSmartin 		    cyl, head, sec);
974103857bSmartin 	else
9886906049Smartin 		set_default_sizemult(pm->diskdev, MEG, pm->sectorsize);
9950dbef1aSdholland 
1004103857bSmartin 	/*
1014103857bSmartin 	 * If the selected scheme does not need two-stage partitioning
1024103857bSmartin 	 * (like GPT), do not bother to edit the outer partitions.
1034103857bSmartin 	 */
1044103857bSmartin 	if (pm->parts->pscheme->secondary_partitions == NULL ||
1054103857bSmartin 	    pm->parts->pscheme->secondary_scheme == NULL)
1064103857bSmartin 		return true;
10750dbef1aSdholland 
1084103857bSmartin 	if (pm->no_mbr || pm->no_part)
1094103857bSmartin 		return true;
1104103857bSmartin 
111957b5cd6Smartin 	res = edit_outer_parts(pm->parts);
112957b5cd6Smartin 	if (res == 0)
113957b5cd6Smartin 		return false;
114957b5cd6Smartin 	else if (res == 1)
115957b5cd6Smartin 		return true;
116957b5cd6Smartin 
117957b5cd6Smartin 	pm->parts->pscheme->destroy_part_scheme(pm->parts);
118957b5cd6Smartin 	pm->parts = NULL;
119957b5cd6Smartin 	goto again;
12050dbef1aSdholland }
12150dbef1aSdholland 
12250dbef1aSdholland /*
12350dbef1aSdholland  * md back-end code for menu-driven BSD disklabel editor.
12450dbef1aSdholland  */
125957b5cd6Smartin int
md_make_bsd_partitions(struct install_partition_desc * install)1264103857bSmartin md_make_bsd_partitions(struct install_partition_desc *install)
12750dbef1aSdholland {
1284103857bSmartin 	return make_bsd_partitions(install);
12950dbef1aSdholland }
13050dbef1aSdholland 
13150dbef1aSdholland /*
13250dbef1aSdholland  * any additional partition validation
13350dbef1aSdholland  */
1344103857bSmartin bool
md_check_partitions(struct install_partition_desc * install)1354103857bSmartin md_check_partitions(struct install_partition_desc *install)
13650dbef1aSdholland {
13750dbef1aSdholland 	return 1;
13850dbef1aSdholland }
13950dbef1aSdholland 
14050dbef1aSdholland /*
14150dbef1aSdholland  * hook called before writing new disklabel.
14250dbef1aSdholland  */
1434103857bSmartin bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1444103857bSmartin md_pre_disklabel(struct install_partition_desc *install,
1454103857bSmartin     struct disk_partitions *parts)
14650dbef1aSdholland {
14750dbef1aSdholland 
1484103857bSmartin 	if (parts->parent == NULL)
1494103857bSmartin 		return true;	/* no outer partitions */
1504103857bSmartin 
1514103857bSmartin 	parts = parts->parent;
1524103857bSmartin 
1534103857bSmartin 	msg_display_subst(MSG_dofdisk, 3, parts->disk,
1544103857bSmartin 	    msg_string(parts->pscheme->name),
1554103857bSmartin 	    msg_string(parts->pscheme->short_name));
1564103857bSmartin 
1574103857bSmartin 	/* write edited "MBR" onto disk. */
1584103857bSmartin 	if (!parts->pscheme->write_to_disk(parts)) {
15950dbef1aSdholland 		msg_display(MSG_wmbrfail);
16050dbef1aSdholland 		process_menu(MENU_ok, NULL);
1614103857bSmartin 		return false;
16250dbef1aSdholland 	}
1634103857bSmartin 	return true;
16450dbef1aSdholland }
16550dbef1aSdholland 
16650dbef1aSdholland /*
16750dbef1aSdholland  * hook called after writing disklabel to new target disk.
16850dbef1aSdholland  */
1694103857bSmartin bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1704103857bSmartin md_post_disklabel(struct install_partition_desc *install,
1714103857bSmartin     struct disk_partitions *parts)
17250dbef1aSdholland {
1734103857bSmartin 	return true;
17450dbef1aSdholland }
17550dbef1aSdholland 
17650dbef1aSdholland /*
17750dbef1aSdholland  * hook called after upgrade() or install() has finished setting
17850dbef1aSdholland  * up the target disk but immediately before the user is given the
17950dbef1aSdholland  * ``disks are now set up'' message.
18050dbef1aSdholland  */
18150dbef1aSdholland int
md_post_newfs(struct install_partition_desc * install)1824103857bSmartin md_post_newfs(struct install_partition_desc *install)
18350dbef1aSdholland {
18450dbef1aSdholland 	return 0;
18550dbef1aSdholland }
18650dbef1aSdholland 
18750dbef1aSdholland int
md_post_extract(struct install_partition_desc * install,bool upgrade)188*4204f810Smartin md_post_extract(struct install_partition_desc *install, bool upgrade)
18950dbef1aSdholland {
19050dbef1aSdholland 	return 0;
19150dbef1aSdholland }
19250dbef1aSdholland 
19350dbef1aSdholland void
md_cleanup_install(struct install_partition_desc * install)1944103857bSmartin md_cleanup_install(struct install_partition_desc *install)
19550dbef1aSdholland {
19650dbef1aSdholland #ifndef DEBUG
19750dbef1aSdholland 	enable_rc_conf();
19850dbef1aSdholland #endif
19950dbef1aSdholland }
20050dbef1aSdholland 
20150dbef1aSdholland int
md_pre_update(struct install_partition_desc * install)2024103857bSmartin md_pre_update(struct install_partition_desc *install)
20350dbef1aSdholland {
20450dbef1aSdholland 	return 1;
20550dbef1aSdholland }
20650dbef1aSdholland 
20750dbef1aSdholland /* Upgrade support */
20850dbef1aSdholland int
md_update(struct install_partition_desc * install)2094103857bSmartin md_update(struct install_partition_desc *install)
21050dbef1aSdholland {
2114103857bSmartin 	md_post_newfs(install);
21250dbef1aSdholland 	return 1;
21350dbef1aSdholland }
21450dbef1aSdholland 
21550dbef1aSdholland int
md_check_mbr(struct disk_partitions * parts,mbr_info_t * mbri,bool quiet)2164103857bSmartin md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
21750dbef1aSdholland {
21850dbef1aSdholland 	return 2;
21950dbef1aSdholland }
22050dbef1aSdholland 
2214103857bSmartin bool
md_parts_use_wholedisk(struct disk_partitions * parts)2224103857bSmartin md_parts_use_wholedisk(struct disk_partitions *parts)
22350dbef1aSdholland {
2244103857bSmartin 	return parts_use_wholedisk(parts, 0, NULL);
22550dbef1aSdholland }
2264b2364d9Smartin 
2274b2364d9Smartin int
md_pre_mount(struct install_partition_desc * install,size_t ndx)2284f30cbf3Smartin md_pre_mount(struct install_partition_desc *install, size_t ndx)
2294b2364d9Smartin {
2304b2364d9Smartin 	return 0;
2314b2364d9Smartin }
2324b2364d9Smartin 
2334103857bSmartin bool
md_mbr_update_check(struct disk_partitions * parts,mbr_info_t * mbri)2344103857bSmartin md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
2354103857bSmartin {
2364103857bSmartin 	return false;	/* no change, no need to write back */
2374103857bSmartin }
2384103857bSmartin 
2394103857bSmartin #ifdef HAVE_GPT
2404103857bSmartin 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)2414103857bSmartin md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
2424103857bSmartin     bool root_is_new, part_id efi_id, bool efi_is_new)
2434103857bSmartin {
2444103857bSmartin 	/* no GPT boot support, nothing needs to be done here */
2454103857bSmartin 	return true;
2464103857bSmartin }
2474103857bSmartin #endif
2484103857bSmartin 
249