xref: /netbsd/usr.sbin/sysinst/arch/zaurus/md.c (revision b8b586ec)
1*b8b586ecSmartin /*	$NetBSD: md.c,v 1.12 2022/01/29 16:01:21 martin Exp $	*/
226165e63Sdholland 
326165e63Sdholland /*
426165e63Sdholland  * Copyright 1997 Piermont Information Systems Inc.
526165e63Sdholland  * All rights reserved.
626165e63Sdholland  *
726165e63Sdholland  * Based on code written by Philip A. Nelson for Piermont Information
826165e63Sdholland  * Systems Inc.
926165e63Sdholland  *
1026165e63Sdholland  * Redistribution and use in source and binary forms, with or without
1126165e63Sdholland  * modification, are permitted provided that the following conditions
1226165e63Sdholland  * are met:
1326165e63Sdholland  * 1. Redistributions of source code must retain the above copyright
1426165e63Sdholland  *    notice, this list of conditions and the following disclaimer.
1526165e63Sdholland  * 2. Redistributions in binary form must reproduce the above copyright
1626165e63Sdholland  *    notice, this list of conditions and the following disclaimer in the
1726165e63Sdholland  *    documentation and/or other materials provided with the distribution.
1826165e63Sdholland  * 3. The name of Piermont Information Systems Inc. may not be used to endorse
1926165e63Sdholland  *    or promote products derived from this software without specific prior
2026165e63Sdholland  *    written permission.
2126165e63Sdholland  *
2226165e63Sdholland  * THIS SOFTWARE IS PROVIDED BY PIERMONT INFORMATION SYSTEMS INC. ``AS IS''
2326165e63Sdholland  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2426165e63Sdholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2526165e63Sdholland  * ARE DISCLAIMED. IN NO EVENT SHALL PIERMONT INFORMATION SYSTEMS INC. BE
2626165e63Sdholland  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2726165e63Sdholland  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2826165e63Sdholland  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2926165e63Sdholland  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3026165e63Sdholland  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3126165e63Sdholland  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
3226165e63Sdholland  * THE POSSIBILITY OF SUCH DAMAGE.
3326165e63Sdholland  */
3426165e63Sdholland 
3526165e63Sdholland /* md.c -- zaurus machine specific routines */
3626165e63Sdholland 
3726165e63Sdholland #include <sys/param.h>
3826165e63Sdholland #include <sys/sysctl.h>
3926165e63Sdholland 
4026165e63Sdholland #include <stdio.h>
4126165e63Sdholland #include <util.h>
4226165e63Sdholland 
4326165e63Sdholland #include "defs.h"
4426165e63Sdholland #include "md.h"
4526165e63Sdholland #include "msg_defs.h"
4626165e63Sdholland #include "menu_defs.h"
4726165e63Sdholland 
4826165e63Sdholland void
md_init(void)4926165e63Sdholland md_init(void)
5026165e63Sdholland {
5126165e63Sdholland }
5226165e63Sdholland 
5326165e63Sdholland void
md_init_set_status(int flags)5426165e63Sdholland md_init_set_status(int flags)
5526165e63Sdholland {
5626165e63Sdholland 	static const int mib[2] = {CTL_KERN, KERN_VERSION};
5726165e63Sdholland 	size_t len;
5826165e63Sdholland 	char *version;
5926165e63Sdholland 
6026165e63Sdholland 	/* check INSTALL kernel name to select an appropriate kernel set */
6126165e63Sdholland 	/* XXX: hw.cpu_model has a processor name on arm ports */
6226165e63Sdholland 	sysctl(mib, 2, NULL, &len, NULL, 0);
6326165e63Sdholland 	version = malloc(len);
6426165e63Sdholland 	if (version == NULL)
6526165e63Sdholland 		return;
6626165e63Sdholland 	sysctl(mib, 2, version, &len, NULL, 0);
6726165e63Sdholland 	if (strstr(version, "C700") != NULL)
6826165e63Sdholland 		set_kernel_set(SET_KERNEL_C700);
6926165e63Sdholland 	free(version);
7026165e63Sdholland }
7126165e63Sdholland 
72dcc57e24Smartin bool
md_get_info(struct install_partition_desc * install)73dcc57e24Smartin md_get_info(struct install_partition_desc *install)
7426165e63Sdholland {
7580bf2417Smartin 	int res;
76b07bdc27Smartin 
77b07bdc27Smartin 	if (pm->no_mbr || pm->no_part)
78b07bdc27Smartin 		return true;
79b07bdc27Smartin 
808b9f7d7cSmartin again:
81b07bdc27Smartin 	if (pm->parts == NULL) {
82b07bdc27Smartin 
83b07bdc27Smartin 		const struct disk_partitioning_scheme *ps =
84b07bdc27Smartin 		    select_part_scheme(pm, NULL, true, NULL);
85b07bdc27Smartin 
86b07bdc27Smartin 		if (!ps)
87c876c9c7Smartin 			return false;
88b07bdc27Smartin 
89b07bdc27Smartin 		struct disk_partitions *parts =
90b07bdc27Smartin 		   (*ps->create_new_for_disk)(pm->diskdev,
910ea03d33Smartin 		   0, pm->dlsize, true, NULL);
92b07bdc27Smartin 		if (!parts)
93b07bdc27Smartin 			return false;
94b07bdc27Smartin 
95b07bdc27Smartin 		pm->parts = parts;
96b07bdc27Smartin 		if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
97b07bdc27Smartin 			pm->dlsize = ps->size_limit;
98b07bdc27Smartin 	}
99b07bdc27Smartin 
10080bf2417Smartin 	res = set_bios_geom_with_mbr_guess(pm->parts);
10180bf2417Smartin 	if (res == 0)
10280bf2417Smartin 		return false;
10380bf2417Smartin 	else if (res == 1)
10480bf2417Smartin 		return true;
10580bf2417Smartin 
10680bf2417Smartin 	pm->parts->pscheme->destroy_part_scheme(pm->parts);
10780bf2417Smartin 	pm->parts = NULL;
10880bf2417Smartin 	goto again;
10926165e63Sdholland }
11026165e63Sdholland 
11180bf2417Smartin int
md_make_bsd_partitions(struct install_partition_desc * install)112dcc57e24Smartin md_make_bsd_partitions(struct install_partition_desc *install)
11326165e63Sdholland {
114dcc57e24Smartin 	return make_bsd_partitions(install);
11526165e63Sdholland }
11626165e63Sdholland 
11726165e63Sdholland /*
11826165e63Sdholland  * any additional partition validation
11926165e63Sdholland  */
120dcc57e24Smartin bool
md_check_partitions(struct install_partition_desc * install)121dcc57e24Smartin md_check_partitions(struct install_partition_desc *install)
12226165e63Sdholland {
123dcc57e24Smartin 	return true;
12426165e63Sdholland }
12526165e63Sdholland 
12626165e63Sdholland /*
12726165e63Sdholland  * hook called before writing new disklabel.
12826165e63Sdholland  */
129dcc57e24Smartin bool
md_pre_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)130dcc57e24Smartin md_pre_disklabel(struct install_partition_desc *install,
131dcc57e24Smartin     struct disk_partitions *parts)
13226165e63Sdholland {
13326165e63Sdholland 
134dcc57e24Smartin 	if (parts->parent == NULL)
135dcc57e24Smartin 		return true;	/* no outer partitions */
13626165e63Sdholland 
137dcc57e24Smartin 	parts = parts->parent;
138dcc57e24Smartin 
139dcc57e24Smartin 	msg_display_subst(MSG_dofdisk, 3, parts->disk,
140dcc57e24Smartin 	    msg_string(parts->pscheme->name),
141dcc57e24Smartin 	    msg_string(parts->pscheme->short_name));
142dcc57e24Smartin 
143dcc57e24Smartin 	/* write edited "MBR" onto disk. */
144dcc57e24Smartin 	if (!parts->pscheme->write_to_disk(parts)) {
14526165e63Sdholland 		msg_display(MSG_wmbrfail);
14626165e63Sdholland 		process_menu(MENU_ok, NULL);
147dcc57e24Smartin 		return false;
14826165e63Sdholland 	}
149dcc57e24Smartin 	return true;
15026165e63Sdholland }
15126165e63Sdholland 
15226165e63Sdholland /*
15326165e63Sdholland  * hook called after writing disklabel to new target disk.
15426165e63Sdholland  */
155dcc57e24Smartin bool
md_post_disklabel(struct install_partition_desc * install,struct disk_partitions * parts)156dcc57e24Smartin md_post_disklabel(struct install_partition_desc *install,
157dcc57e24Smartin     struct disk_partitions *parts)
15826165e63Sdholland {
159dcc57e24Smartin 	return true;
16026165e63Sdholland }
16126165e63Sdholland 
16226165e63Sdholland /*
16326165e63Sdholland  * hook called after upgrade() or install() has finished setting
16426165e63Sdholland  * up the target disk but immediately before the user is given the
16526165e63Sdholland  * ``disks are now set up'' message.
16626165e63Sdholland  */
16726165e63Sdholland int
md_post_newfs(struct install_partition_desc * install)168dcc57e24Smartin md_post_newfs(struct install_partition_desc *install)
16926165e63Sdholland {
17026165e63Sdholland 	struct mbr_sector pbr;
17126165e63Sdholland 	char adevname[STRSIZE];
17226165e63Sdholland 	ssize_t sz;
17326165e63Sdholland 	int fd = -1;
17426165e63Sdholland 
175da5a563bSmartin 	snprintf(adevname, sizeof(adevname), "/dev/r%sa", pm->diskdev);
17626165e63Sdholland 	fd = open(adevname, O_RDWR);
17726165e63Sdholland 	if (fd < 0)
17826165e63Sdholland 		goto out;
17926165e63Sdholland 
18026165e63Sdholland 	/* Read partition boot record */
18126165e63Sdholland 	sz = pread(fd, &pbr, sizeof(pbr), 0);
18226165e63Sdholland 	if (sz != sizeof(pbr))
18326165e63Sdholland 		goto out;
18426165e63Sdholland 
18526165e63Sdholland 	/* Check magic number */
18626165e63Sdholland 	if (pbr.mbr_magic != le16toh(MBR_MAGIC))
18726165e63Sdholland 		goto out;
18826165e63Sdholland 
189dcc57e24Smartin #ifdef NETBSD_MAJOR
190dcc57e24Smartin #define	OSNAME	"NetBSD" NETBSD_MAJOR
191dcc57e24Smartin #else
19226165e63Sdholland #define	OSNAME	"NetBSD60"
193dcc57e24Smartin #endif
19426165e63Sdholland 	/* Update oemname */
19526165e63Sdholland 	memcpy(&pbr.mbr_oemname, OSNAME, sizeof(OSNAME) - 1);
19626165e63Sdholland 
19726165e63Sdholland 	/* Clear BPB */
19826165e63Sdholland 	memset(&pbr.mbr_bpb, 0, sizeof(pbr.mbr_bpb));
19926165e63Sdholland 
20072f96fa8Sandvar 	/* write-backed new partition boot record */
20126165e63Sdholland 	(void)pwrite(fd, &pbr, sizeof(pbr), 0);
20226165e63Sdholland 
20326165e63Sdholland out:
20426165e63Sdholland 	if (fd >= 0)
20526165e63Sdholland 		close(fd);
20626165e63Sdholland 	return 0;
20726165e63Sdholland }
20826165e63Sdholland 
20926165e63Sdholland int
md_post_extract(struct install_partition_desc * install,bool upgrade)210*b8b586ecSmartin md_post_extract(struct install_partition_desc *install, bool upgrade)
21126165e63Sdholland {
21226165e63Sdholland 	return 0;
21326165e63Sdholland }
21426165e63Sdholland 
21526165e63Sdholland void
md_cleanup_install(struct install_partition_desc * install)216dcc57e24Smartin md_cleanup_install(struct install_partition_desc *install)
21726165e63Sdholland {
21826165e63Sdholland #ifndef DEBUG
21926165e63Sdholland 	enable_rc_conf();
22026165e63Sdholland #endif
22126165e63Sdholland }
22226165e63Sdholland 
22326165e63Sdholland int
md_pre_update(struct install_partition_desc * install)224dcc57e24Smartin md_pre_update(struct install_partition_desc *install)
22526165e63Sdholland {
22626165e63Sdholland 	return 1;
22726165e63Sdholland }
22826165e63Sdholland 
22926165e63Sdholland /* Upgrade support */
23026165e63Sdholland int
md_update(struct install_partition_desc * install)231dcc57e24Smartin md_update(struct install_partition_desc *install)
23226165e63Sdholland {
233dcc57e24Smartin 	md_post_newfs(install);
23426165e63Sdholland 	return 1;
23526165e63Sdholland }
23626165e63Sdholland 
23726165e63Sdholland int
md_check_mbr(struct disk_partitions * parts,mbr_info_t * mbri,bool quiet)238dcc57e24Smartin md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
23926165e63Sdholland {
24026165e63Sdholland 	return 2;
24126165e63Sdholland }
24226165e63Sdholland 
243dcc57e24Smartin bool
md_parts_use_wholedisk(struct disk_partitions * parts)244dcc57e24Smartin md_parts_use_wholedisk(struct disk_partitions *parts)
24526165e63Sdholland {
24626165e63Sdholland 
247dcc57e24Smartin 	return parts_use_wholedisk(parts, 0, NULL);
24826165e63Sdholland }
24926165e63Sdholland 
25026165e63Sdholland 
25126165e63Sdholland int
md_pre_mount(struct install_partition_desc * install,size_t ndx)252d5a9dfe9Smartin md_pre_mount(struct install_partition_desc *install, size_t ndx)
25326165e63Sdholland {
25426165e63Sdholland 	return 0;
25526165e63Sdholland }
256dcc57e24Smartin 
257dcc57e24Smartin bool
md_mbr_update_check(struct disk_partitions * parts,mbr_info_t * mbri)258dcc57e24Smartin md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
259dcc57e24Smartin {
260dcc57e24Smartin 	return false;	/* no change, no need to write back */
261dcc57e24Smartin }
262dcc57e24Smartin 
263dcc57e24Smartin #ifdef HAVE_GPT
264dcc57e24Smartin 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)265dcc57e24Smartin md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
266dcc57e24Smartin     bool root_is_new, part_id efi_id, bool efi_is_new)
267dcc57e24Smartin {
268dcc57e24Smartin 	/* no GPT boot support, nothing needs to be done here */
269dcc57e24Smartin 	return true;
270dcc57e24Smartin }
271dcc57e24Smartin #endif
272dcc57e24Smartin 
273