xref: /netbsd-src/usr.sbin/sysinst/arch/zaurus/md.c (revision 4204f81037ec1430b81b70ee975f04b277901e24)
1*4204f810Smartin /*	$NetBSD: md.c,v 1.12 2022/01/29 16:01:21 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 -- zaurus machine specific routines */
3650dbef1aSdholland 
3750dbef1aSdholland #include <sys/param.h>
3850dbef1aSdholland #include <sys/sysctl.h>
3950dbef1aSdholland 
4050dbef1aSdholland #include <stdio.h>
4150dbef1aSdholland #include <util.h>
4250dbef1aSdholland 
4350dbef1aSdholland #include "defs.h"
4450dbef1aSdholland #include "md.h"
4550dbef1aSdholland #include "msg_defs.h"
4650dbef1aSdholland #include "menu_defs.h"
4750dbef1aSdholland 
4850dbef1aSdholland void
md_init(void)4950dbef1aSdholland md_init(void)
5050dbef1aSdholland {
5150dbef1aSdholland }
5250dbef1aSdholland 
5350dbef1aSdholland void
md_init_set_status(int flags)5450dbef1aSdholland md_init_set_status(int flags)
5550dbef1aSdholland {
5650dbef1aSdholland 	static const int mib[2] = {CTL_KERN, KERN_VERSION};
5750dbef1aSdholland 	size_t len;
5850dbef1aSdholland 	char *version;
5950dbef1aSdholland 
6050dbef1aSdholland 	/* check INSTALL kernel name to select an appropriate kernel set */
6150dbef1aSdholland 	/* XXX: hw.cpu_model has a processor name on arm ports */
6250dbef1aSdholland 	sysctl(mib, 2, NULL, &len, NULL, 0);
6350dbef1aSdholland 	version = malloc(len);
6450dbef1aSdholland 	if (version == NULL)
6550dbef1aSdholland 		return;
6650dbef1aSdholland 	sysctl(mib, 2, version, &len, NULL, 0);
6750dbef1aSdholland 	if (strstr(version, "C700") != NULL)
6850dbef1aSdholland 		set_kernel_set(SET_KERNEL_C700);
6950dbef1aSdholland 	free(version);
7050dbef1aSdholland }
7150dbef1aSdholland 
724103857bSmartin bool
md_get_info(struct install_partition_desc * install)734103857bSmartin md_get_info(struct install_partition_desc *install)
7450dbef1aSdholland {
75957b5cd6Smartin 	int res;
76e11b8d25Smartin 
77e11b8d25Smartin 	if (pm->no_mbr || pm->no_part)
78e11b8d25Smartin 		return true;
79e11b8d25Smartin 
800d9613faSmartin again:
81e11b8d25Smartin 	if (pm->parts == NULL) {
82e11b8d25Smartin 
83e11b8d25Smartin 		const struct disk_partitioning_scheme *ps =
84e11b8d25Smartin 		    select_part_scheme(pm, NULL, true, NULL);
85e11b8d25Smartin 
86e11b8d25Smartin 		if (!ps)
876fec6798Smartin 			return false;
88e11b8d25Smartin 
89e11b8d25Smartin 		struct disk_partitions *parts =
90e11b8d25Smartin 		   (*ps->create_new_for_disk)(pm->diskdev,
9186906049Smartin 		   0, pm->dlsize, true, NULL);
92e11b8d25Smartin 		if (!parts)
93e11b8d25Smartin 			return false;
94e11b8d25Smartin 
95e11b8d25Smartin 		pm->parts = parts;
96e11b8d25Smartin 		if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
97e11b8d25Smartin 			pm->dlsize = ps->size_limit;
98e11b8d25Smartin 	}
99e11b8d25Smartin 
100957b5cd6Smartin 	res = set_bios_geom_with_mbr_guess(pm->parts);
101957b5cd6Smartin 	if (res == 0)
102957b5cd6Smartin 		return false;
103957b5cd6Smartin 	else if (res == 1)
104957b5cd6Smartin 		return true;
105957b5cd6Smartin 
106957b5cd6Smartin 	pm->parts->pscheme->destroy_part_scheme(pm->parts);
107957b5cd6Smartin 	pm->parts = NULL;
108957b5cd6Smartin 	goto again;
10950dbef1aSdholland }
11050dbef1aSdholland 
111957b5cd6Smartin int
md_make_bsd_partitions(struct install_partition_desc * install)1124103857bSmartin md_make_bsd_partitions(struct install_partition_desc *install)
11350dbef1aSdholland {
1144103857bSmartin 	return make_bsd_partitions(install);
11550dbef1aSdholland }
11650dbef1aSdholland 
11750dbef1aSdholland /*
11850dbef1aSdholland  * any additional partition validation
11950dbef1aSdholland  */
1204103857bSmartin bool
md_check_partitions(struct install_partition_desc * install)1214103857bSmartin md_check_partitions(struct install_partition_desc *install)
12250dbef1aSdholland {
1234103857bSmartin 	return true;
12450dbef1aSdholland }
12550dbef1aSdholland 
12650dbef1aSdholland /*
12750dbef1aSdholland  * hook called before writing new disklabel.
12850dbef1aSdholland  */
1294103857bSmartin bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1304103857bSmartin md_pre_disklabel(struct install_partition_desc *install,
1314103857bSmartin     struct disk_partitions *parts)
13250dbef1aSdholland {
13350dbef1aSdholland 
1344103857bSmartin 	if (parts->parent == NULL)
1354103857bSmartin 		return true;	/* no outer partitions */
13650dbef1aSdholland 
1374103857bSmartin 	parts = parts->parent;
1384103857bSmartin 
1394103857bSmartin 	msg_display_subst(MSG_dofdisk, 3, parts->disk,
1404103857bSmartin 	    msg_string(parts->pscheme->name),
1414103857bSmartin 	    msg_string(parts->pscheme->short_name));
1424103857bSmartin 
1434103857bSmartin 	/* write edited "MBR" onto disk. */
1444103857bSmartin 	if (!parts->pscheme->write_to_disk(parts)) {
14550dbef1aSdholland 		msg_display(MSG_wmbrfail);
14650dbef1aSdholland 		process_menu(MENU_ok, NULL);
1474103857bSmartin 		return false;
14850dbef1aSdholland 	}
1494103857bSmartin 	return true;
15050dbef1aSdholland }
15150dbef1aSdholland 
15250dbef1aSdholland /*
15350dbef1aSdholland  * hook called after writing disklabel to new target disk.
15450dbef1aSdholland  */
1554103857bSmartin bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)1564103857bSmartin md_post_disklabel(struct install_partition_desc *install,
1574103857bSmartin     struct disk_partitions *parts)
15850dbef1aSdholland {
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 	struct mbr_sector pbr;
17150dbef1aSdholland 	char adevname[STRSIZE];
17250dbef1aSdholland 	ssize_t sz;
17350dbef1aSdholland 	int fd = -1;
17450dbef1aSdholland 
1754b2364d9Smartin 	snprintf(adevname, sizeof(adevname), "/dev/r%sa", pm->diskdev);
17650dbef1aSdholland 	fd = open(adevname, O_RDWR);
17750dbef1aSdholland 	if (fd < 0)
17850dbef1aSdholland 		goto out;
17950dbef1aSdholland 
18050dbef1aSdholland 	/* Read partition boot record */
18150dbef1aSdholland 	sz = pread(fd, &pbr, sizeof(pbr), 0);
18250dbef1aSdholland 	if (sz != sizeof(pbr))
18350dbef1aSdholland 		goto out;
18450dbef1aSdholland 
18550dbef1aSdholland 	/* Check magic number */
18650dbef1aSdholland 	if (pbr.mbr_magic != le16toh(MBR_MAGIC))
18750dbef1aSdholland 		goto out;
18850dbef1aSdholland 
1894103857bSmartin #ifdef NETBSD_MAJOR
1904103857bSmartin #define	OSNAME	"NetBSD" NETBSD_MAJOR
1914103857bSmartin #else
19250dbef1aSdholland #define	OSNAME	"NetBSD60"
1934103857bSmartin #endif
19450dbef1aSdholland 	/* Update oemname */
19550dbef1aSdholland 	memcpy(&pbr.mbr_oemname, OSNAME, sizeof(OSNAME) - 1);
19650dbef1aSdholland 
19750dbef1aSdholland 	/* Clear BPB */
19850dbef1aSdholland 	memset(&pbr.mbr_bpb, 0, sizeof(pbr.mbr_bpb));
19950dbef1aSdholland 
20032a556f9Sandvar 	/* write-backed new partition boot record */
20150dbef1aSdholland 	(void)pwrite(fd, &pbr, sizeof(pbr), 0);
20250dbef1aSdholland 
20350dbef1aSdholland out:
20450dbef1aSdholland 	if (fd >= 0)
20550dbef1aSdholland 		close(fd);
20650dbef1aSdholland 	return 0;
20750dbef1aSdholland }
20850dbef1aSdholland 
20950dbef1aSdholland int
md_post_extract(struct install_partition_desc * install,bool upgrade)210*4204f810Smartin md_post_extract(struct install_partition_desc *install, bool upgrade)
21150dbef1aSdholland {
21250dbef1aSdholland 	return 0;
21350dbef1aSdholland }
21450dbef1aSdholland 
21550dbef1aSdholland void
md_cleanup_install(struct install_partition_desc * install)2164103857bSmartin md_cleanup_install(struct install_partition_desc *install)
21750dbef1aSdholland {
21850dbef1aSdholland #ifndef DEBUG
21950dbef1aSdholland 	enable_rc_conf();
22050dbef1aSdholland #endif
22150dbef1aSdholland }
22250dbef1aSdholland 
22350dbef1aSdholland int
md_pre_update(struct install_partition_desc * install)2244103857bSmartin md_pre_update(struct install_partition_desc *install)
22550dbef1aSdholland {
22650dbef1aSdholland 	return 1;
22750dbef1aSdholland }
22850dbef1aSdholland 
22950dbef1aSdholland /* Upgrade support */
23050dbef1aSdholland int
md_update(struct install_partition_desc * install)2314103857bSmartin md_update(struct install_partition_desc *install)
23250dbef1aSdholland {
2334103857bSmartin 	md_post_newfs(install);
23450dbef1aSdholland 	return 1;
23550dbef1aSdholland }
23650dbef1aSdholland 
23750dbef1aSdholland int
md_check_mbr(struct disk_partitions * parts,mbr_info_t * mbri,bool quiet)2384103857bSmartin md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
23950dbef1aSdholland {
24050dbef1aSdholland 	return 2;
24150dbef1aSdholland }
24250dbef1aSdholland 
2434103857bSmartin bool
md_parts_use_wholedisk(struct disk_partitions * parts)2444103857bSmartin md_parts_use_wholedisk(struct disk_partitions *parts)
24550dbef1aSdholland {
24650dbef1aSdholland 
2474103857bSmartin 	return parts_use_wholedisk(parts, 0, NULL);
24850dbef1aSdholland }
24950dbef1aSdholland 
25050dbef1aSdholland 
25150dbef1aSdholland int
md_pre_mount(struct install_partition_desc * install,size_t ndx)2524f30cbf3Smartin md_pre_mount(struct install_partition_desc *install, size_t ndx)
25350dbef1aSdholland {
25450dbef1aSdholland 	return 0;
25550dbef1aSdholland }
2564103857bSmartin 
2574103857bSmartin bool
md_mbr_update_check(struct disk_partitions * parts,mbr_info_t * mbri)2584103857bSmartin md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
2594103857bSmartin {
2604103857bSmartin 	return false;	/* no change, no need to write back */
2614103857bSmartin }
2624103857bSmartin 
2634103857bSmartin #ifdef HAVE_GPT
2644103857bSmartin 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)2654103857bSmartin md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
2664103857bSmartin     bool root_is_new, part_id efi_id, bool efi_is_new)
2674103857bSmartin {
2684103857bSmartin 	/* no GPT boot support, nothing needs to be done here */
2694103857bSmartin 	return true;
2704103857bSmartin }
2714103857bSmartin #endif
2724103857bSmartin 
273