xref: /netbsd-src/usr.sbin/sysinst/arch/hpcmips/md.c (revision 4204f81037ec1430b81b70ee975f04b277901e24)
1*4204f810Smartin /*	$NetBSD: md.c,v 1.10 2022/01/29 16:01:18 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. The name of Piermont Information Systems Inc. may not be used to endorse
1950dbef1aSdholland  *    or promote products derived from this software without specific prior
2050dbef1aSdholland  *    written permission.
2150dbef1aSdholland  *
2250dbef1aSdholland  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
2350dbef1aSdholland  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2450dbef1aSdholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2550dbef1aSdholland  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
2650dbef1aSdholland  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2750dbef1aSdholland  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2850dbef1aSdholland  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2950dbef1aSdholland  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3050dbef1aSdholland  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3150dbef1aSdholland  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3250dbef1aSdholland  * THE POSSIBILITY OF SUCH DAMAGE.
3350dbef1aSdholland  */
3450dbef1aSdholland 
3550dbef1aSdholland /* md.c -- hpcmips machine specific routines */
3650dbef1aSdholland 
3750dbef1aSdholland #include <stdio.h>
3850dbef1aSdholland #include <util.h>
3950dbef1aSdholland #include <sys/param.h>
4050dbef1aSdholland #include <machine/cpu.h>
4150dbef1aSdholland #include <sys/sysctl.h>
4250dbef1aSdholland 
4350dbef1aSdholland #include "defs.h"
4450dbef1aSdholland #include "md.h"
4550dbef1aSdholland #include "msg_defs.h"
4650dbef1aSdholland #include "menu_defs.h"
4750dbef1aSdholland #include "endian.h"
4850dbef1aSdholland #include "mbr.h"
4950dbef1aSdholland 
5050dbef1aSdholland void
md_init(void)5150dbef1aSdholland md_init(void)
5250dbef1aSdholland {
5350dbef1aSdholland }
5450dbef1aSdholland 
5550dbef1aSdholland void
md_init_set_status(int flags)5650dbef1aSdholland md_init_set_status(int flags)
5750dbef1aSdholland {
5850dbef1aSdholland 	(void)flags;
5950dbef1aSdholland }
6050dbef1aSdholland 
614103857bSmartin bool
md_get_info(struct install_partition_desc * install)624103857bSmartin md_get_info(struct install_partition_desc *install)
6350dbef1aSdholland {
64957b5cd6Smartin 	int res;
65e11b8d25Smartin 
66e11b8d25Smartin 	if (pm->no_mbr || pm->no_part)
67e11b8d25Smartin 		return true;
68e11b8d25Smartin 
69957b5cd6Smartin again:
70e11b8d25Smartin 	if (pm->parts == NULL) {
71e11b8d25Smartin 
72e11b8d25Smartin 		const struct disk_partitioning_scheme *ps =
73e11b8d25Smartin 		    select_part_scheme(pm, NULL, true, NULL);
74e11b8d25Smartin 
75e11b8d25Smartin 		if (!ps)
766fec6798Smartin 			return false;
77e11b8d25Smartin 
78e11b8d25Smartin 		struct disk_partitions *parts =
79e11b8d25Smartin 		   (*ps->create_new_for_disk)(pm->diskdev,
8086906049Smartin 		   0, pm->dlsize, true, NULL);
81e11b8d25Smartin 		if (!parts)
82e11b8d25Smartin 			return false;
83e11b8d25Smartin 
84e11b8d25Smartin 		pm->parts = parts;
85e11b8d25Smartin 		if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
86e11b8d25Smartin 			pm->dlsize = ps->size_limit;
87e11b8d25Smartin 	}
88e11b8d25Smartin 
89957b5cd6Smartin 	res = set_bios_geom_with_mbr_guess(pm->parts);
90957b5cd6Smartin 	if (res == 0)
91957b5cd6Smartin 		return false;
92957b5cd6Smartin 	else if (res == 1)
93957b5cd6Smartin 		return true;
94957b5cd6Smartin 
95957b5cd6Smartin 	pm->parts->pscheme->destroy_part_scheme(pm->parts);
96957b5cd6Smartin 	pm->parts = NULL;
97957b5cd6Smartin 	goto again;
9850dbef1aSdholland }
9950dbef1aSdholland 
10050dbef1aSdholland /*
10150dbef1aSdholland  * md back-end code for menu-driven BSD disklabel editor.
10250dbef1aSdholland  */
103957b5cd6Smartin int
md_make_bsd_partitions(struct install_partition_desc * install)1044103857bSmartin md_make_bsd_partitions(struct install_partition_desc *install)
10550dbef1aSdholland {
1064103857bSmartin 	return make_bsd_partitions(install);
10750dbef1aSdholland }
10850dbef1aSdholland 
10950dbef1aSdholland /*
11050dbef1aSdholland  * any additional partition validation
11150dbef1aSdholland  */
1124103857bSmartin bool
md_check_partitions(struct install_partition_desc * install)1134103857bSmartin md_check_partitions(struct install_partition_desc *install)
11450dbef1aSdholland {
1154103857bSmartin 	return true;
11650dbef1aSdholland }
11750dbef1aSdholland 
11850dbef1aSdholland /*
11950dbef1aSdholland  * hook called before writing new disklabel.
12050dbef1aSdholland  */
1214103857bSmartin bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1224103857bSmartin md_pre_disklabel(struct install_partition_desc *install,
1234103857bSmartin     struct disk_partitions *parts)
12450dbef1aSdholland {
12550dbef1aSdholland 
1264103857bSmartin 	if (parts->parent == NULL)
1274103857bSmartin 		return true;	/* no outer partitions */
1284103857bSmartin 
1294103857bSmartin 	parts = parts->parent;
1304103857bSmartin 
1314103857bSmartin 	msg_display_subst(MSG_dofdisk, 3, parts->disk,
1324103857bSmartin 	    msg_string(parts->pscheme->name),
1334103857bSmartin 	    msg_string(parts->pscheme->short_name));
1344103857bSmartin 
1354103857bSmartin 	/* write edited "MBR" onto disk. */
1364103857bSmartin 	if (!parts->pscheme->write_to_disk(parts)) {
13750dbef1aSdholland 		msg_display(MSG_wmbrfail);
13850dbef1aSdholland 		process_menu(MENU_ok, NULL);
1394103857bSmartin 		return false;
14050dbef1aSdholland 	}
1414103857bSmartin 	return true;
14250dbef1aSdholland }
14350dbef1aSdholland 
14450dbef1aSdholland /*
14550dbef1aSdholland  * hook called after writing disklabel to new target disk.
14650dbef1aSdholland  */
1474103857bSmartin bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1484103857bSmartin md_post_disklabel(struct install_partition_desc *install,
1494103857bSmartin     struct disk_partitions *parts)
15050dbef1aSdholland {
1514103857bSmartin #if 0	/* XXX - when did bad144 get removed and this code not? */
15250dbef1aSdholland 	/* Sector forwarding / badblocks ... */
1534b2364d9Smartin 	if (*pm->doessf) {
15450dbef1aSdholland 		msg_display(MSG_dobad144);
15550dbef1aSdholland 		return run_program(RUN_DISPLAY, "/usr/sbin/bad144 %s 0",
1564103857bSmartin 		    pm->diskdev) == 0;
15750dbef1aSdholland 	}
1584103857bSmartin #endif
1594103857bSmartin 	return true;
16050dbef1aSdholland }
16150dbef1aSdholland 
16250dbef1aSdholland /*
16350dbef1aSdholland  * hook called after upgrade() or install() has finished setting
16450dbef1aSdholland  * up the target disk but immediately before the user is given the
16550dbef1aSdholland  * ``disks are now set up'' message.
16650dbef1aSdholland  */
16750dbef1aSdholland int
md_post_newfs(struct install_partition_desc * install)1684103857bSmartin md_post_newfs(struct install_partition_desc *install)
16950dbef1aSdholland {
17050dbef1aSdholland 	return 0;
17150dbef1aSdholland }
17250dbef1aSdholland 
17350dbef1aSdholland void
md_cleanup_install(struct install_partition_desc * install)1744103857bSmartin md_cleanup_install(struct install_partition_desc *install)
17550dbef1aSdholland {
17650dbef1aSdholland #ifndef DEBUG
17750dbef1aSdholland 	enable_rc_conf();
17850dbef1aSdholland #endif
17950dbef1aSdholland }
18050dbef1aSdholland 
18150dbef1aSdholland int
md_pre_update(struct install_partition_desc * install)1824103857bSmartin md_pre_update(struct install_partition_desc *install)
18350dbef1aSdholland {
18450dbef1aSdholland 	return 1;
18550dbef1aSdholland }
18650dbef1aSdholland 
18750dbef1aSdholland /* Upgrade support */
18850dbef1aSdholland int
md_update(struct install_partition_desc * install)1894103857bSmartin md_update(struct install_partition_desc *install)
19050dbef1aSdholland {
1914103857bSmartin 	md_post_newfs(install);
19250dbef1aSdholland 	return 1;
19350dbef1aSdholland }
19450dbef1aSdholland 
19550dbef1aSdholland int
md_post_extract(struct install_partition_desc * install,bool upgrade)196*4204f810Smartin md_post_extract(struct install_partition_desc *install, bool upgrade)
19750dbef1aSdholland {
19850dbef1aSdholland 	return 0;
19950dbef1aSdholland }
20050dbef1aSdholland 
20150dbef1aSdholland int
md_check_mbr(struct disk_partitions * parts,mbr_info_t * mbri,bool quiet)2024103857bSmartin md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
20350dbef1aSdholland {
20450dbef1aSdholland 	return 2;
20550dbef1aSdholland }
20650dbef1aSdholland 
2074103857bSmartin bool
md_parts_use_wholedisk(struct disk_partitions * parts)2084103857bSmartin md_parts_use_wholedisk(struct disk_partitions *parts)
20950dbef1aSdholland {
2104103857bSmartin 	return parts_use_wholedisk(parts, 0, NULL);
21150dbef1aSdholland }
21250dbef1aSdholland 
21350dbef1aSdholland int
md_pre_mount(struct install_partition_desc * install,size_t ndx)2144f30cbf3Smartin md_pre_mount(struct install_partition_desc *install, size_t ndx)
21550dbef1aSdholland {
21650dbef1aSdholland 	return 0;
21750dbef1aSdholland }
2184103857bSmartin 
2194103857bSmartin /* returns false if no write-back of parts is required */
2204103857bSmartin bool
md_mbr_update_check(struct disk_partitions * parts,mbr_info_t * mbri)2214103857bSmartin md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
2224103857bSmartin {
2234103857bSmartin 	return false;
2244103857bSmartin }
2254103857bSmartin 
2264103857bSmartin #ifdef HAVE_GPT
2274103857bSmartin /*
2284103857bSmartin  * New GPT partitions have been written, update bootloader or remember
2294103857bSmartin  * data untill needed in md_post_newfs
2304103857bSmartin  */
2314103857bSmartin 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)2324103857bSmartin md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
2334103857bSmartin     bool root_is_new, part_id efi_id, bool efi_is_new)
2344103857bSmartin {
2354103857bSmartin 	return true;
2364103857bSmartin }
2374103857bSmartin #endif
2384103857bSmartin 
239