Home | History | Annotate | Line # | Download | only in zaurus
md.c revision 1.10
      1 /*	$NetBSD: md.c,v 1.10 2020/10/14 08:49:04 martin Exp $	*/
      2 
      3 /*
      4  * Copyright 1997 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 -- zaurus machine specific routines */
     36 
     37 #include <sys/param.h>
     38 #include <sys/sysctl.h>
     39 
     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
     49 md_init(void)
     50 {
     51 }
     52 
     53 void
     54 md_init_set_status(int flags)
     55 {
     56 	static const int mib[2] = {CTL_KERN, KERN_VERSION};
     57 	size_t len;
     58 	char *version;
     59 
     60 	/* check INSTALL kernel name to select an appropriate kernel set */
     61 	/* XXX: hw.cpu_model has a processor name on arm ports */
     62 	sysctl(mib, 2, NULL, &len, NULL, 0);
     63 	version = malloc(len);
     64 	if (version == NULL)
     65 		return;
     66 	sysctl(mib, 2, version, &len, NULL, 0);
     67 	if (strstr(version, "C700") != NULL)
     68 		set_kernel_set(SET_KERNEL_C700);
     69 	free(version);
     70 }
     71 
     72 bool
     73 md_get_info(struct install_partition_desc *install)
     74 {
     75 	int res;
     76 
     77 	if (pm->no_mbr || pm->no_part)
     78 		return true;
     79 
     80 again:
     81 	if (pm->parts == NULL) {
     82 
     83 		const struct disk_partitioning_scheme *ps =
     84 		    select_part_scheme(pm, NULL, true, NULL);
     85 
     86 		if (!ps)
     87 			return false;
     88 
     89 		struct disk_partitions *parts =
     90 		   (*ps->create_new_for_disk)(pm->diskdev,
     91 		   0, pm->dlsize, true, NULL);
     92 		if (!parts)
     93 			return false;
     94 
     95 		pm->parts = parts;
     96 		if (ps->size_limit > 0 && pm->dlsize > ps->size_limit)
     97 			pm->dlsize = ps->size_limit;
     98 	}
     99 
    100 	res = set_bios_geom_with_mbr_guess(pm->parts);
    101 	if (res == 0)
    102 		return false;
    103 	else if (res == 1)
    104 		return true;
    105 
    106 	pm->parts->pscheme->destroy_part_scheme(pm->parts);
    107 	pm->parts = NULL;
    108 	goto again;
    109 }
    110 
    111 int
    112 md_make_bsd_partitions(struct install_partition_desc *install)
    113 {
    114 	return make_bsd_partitions(install);
    115 }
    116 
    117 /*
    118  * any additional partition validation
    119  */
    120 bool
    121 md_check_partitions(struct install_partition_desc *install)
    122 {
    123 	return true;
    124 }
    125 
    126 /*
    127  * hook called before writing new disklabel.
    128  */
    129 bool
    130 md_pre_disklabel(struct install_partition_desc *install,
    131     struct disk_partitions *parts)
    132 {
    133 
    134 	if (parts->parent == NULL)
    135 		return true;	/* no outer partitions */
    136 
    137 	parts = parts->parent;
    138 
    139 	msg_display_subst(MSG_dofdisk, 3, parts->disk,
    140 	    msg_string(parts->pscheme->name),
    141 	    msg_string(parts->pscheme->short_name));
    142 
    143 	/* write edited "MBR" onto disk. */
    144 	if (!parts->pscheme->write_to_disk(parts)) {
    145 		msg_display(MSG_wmbrfail);
    146 		process_menu(MENU_ok, NULL);
    147 		return false;
    148 	}
    149 	return true;
    150 }
    151 
    152 /*
    153  * hook called after writing disklabel to new target disk.
    154  */
    155 bool
    156 md_post_disklabel(struct install_partition_desc *install,
    157     struct disk_partitions *parts)
    158 {
    159 	return true;
    160 }
    161 
    162 /*
    163  * hook called after upgrade() or install() has finished setting
    164  * up the target disk but immediately before the user is given the
    165  * ``disks are now set up'' message.
    166  */
    167 int
    168 md_post_newfs(struct install_partition_desc *install)
    169 {
    170 	struct mbr_sector pbr;
    171 	char adevname[STRSIZE];
    172 	ssize_t sz;
    173 	int fd = -1;
    174 
    175 	snprintf(adevname, sizeof(adevname), "/dev/r%sa", pm->diskdev);
    176 	fd = open(adevname, O_RDWR);
    177 	if (fd < 0)
    178 		goto out;
    179 
    180 	/* Read partition boot record */
    181 	sz = pread(fd, &pbr, sizeof(pbr), 0);
    182 	if (sz != sizeof(pbr))
    183 		goto out;
    184 
    185 	/* Check magic number */
    186 	if (pbr.mbr_magic != le16toh(MBR_MAGIC))
    187 		goto out;
    188 
    189 #ifdef NETBSD_MAJOR
    190 #define	OSNAME	"NetBSD" NETBSD_MAJOR
    191 #else
    192 #define	OSNAME	"NetBSD60"
    193 #endif
    194 	/* Update oemname */
    195 	memcpy(&pbr.mbr_oemname, OSNAME, sizeof(OSNAME) - 1);
    196 
    197 	/* Clear BPB */
    198 	memset(&pbr.mbr_bpb, 0, sizeof(pbr.mbr_bpb));
    199 
    200 	/* write-backed new patition boot record */
    201 	(void)pwrite(fd, &pbr, sizeof(pbr), 0);
    202 
    203 out:
    204 	if (fd >= 0)
    205 		close(fd);
    206 	return 0;
    207 }
    208 
    209 int
    210 md_post_extract(struct install_partition_desc *install)
    211 {
    212 	return 0;
    213 }
    214 
    215 void
    216 md_cleanup_install(struct install_partition_desc *install)
    217 {
    218 #ifndef DEBUG
    219 	enable_rc_conf();
    220 #endif
    221 }
    222 
    223 int
    224 md_pre_update(struct install_partition_desc *install)
    225 {
    226 	return 1;
    227 }
    228 
    229 /* Upgrade support */
    230 int
    231 md_update(struct install_partition_desc *install)
    232 {
    233 	md_post_newfs(install);
    234 	return 1;
    235 }
    236 
    237 int
    238 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
    239 {
    240 	return 2;
    241 }
    242 
    243 bool
    244 md_parts_use_wholedisk(struct disk_partitions *parts)
    245 {
    246 
    247 	return parts_use_wholedisk(parts, 0, NULL);
    248 }
    249 
    250 
    251 int
    252 md_pre_mount(struct install_partition_desc *install, size_t ndx)
    253 {
    254 	return 0;
    255 }
    256 
    257 bool
    258 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
    259 {
    260 	return false;	/* no change, no need to write back */
    261 }
    262 
    263 #ifdef HAVE_GPT
    264 bool
    265 md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
    266     bool root_is_new, part_id efi_id, bool efi_is_new)
    267 {
    268 	/* no GPT boot support, nothing needs to be done here */
    269 	return true;
    270 }
    271 #endif
    272 
    273