Home | History | Annotate | Line # | Download | only in zaurus
md.c revision 1.3
      1 /*	$NetBSD: md.c,v 1.3 2019/06/12 06:20:23 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 	return set_bios_geom_with_mbr_guess(pm->parts);
     76 }
     77 
     78 bool
     79 md_make_bsd_partitions(struct install_partition_desc *install)
     80 {
     81 	return make_bsd_partitions(install);
     82 }
     83 
     84 /*
     85  * any additional partition validation
     86  */
     87 bool
     88 md_check_partitions(struct install_partition_desc *install)
     89 {
     90 	return true;
     91 }
     92 
     93 /*
     94  * hook called before writing new disklabel.
     95  */
     96 bool
     97 md_pre_disklabel(struct install_partition_desc *install,
     98     struct disk_partitions *parts)
     99 {
    100 
    101 	if (parts->parent == NULL)
    102 		return true;	/* no outer partitions */
    103 
    104 	parts = parts->parent;
    105 
    106 	msg_display_subst(MSG_dofdisk, 3, parts->disk,
    107 	    msg_string(parts->pscheme->name),
    108 	    msg_string(parts->pscheme->short_name));
    109 
    110 	/* write edited "MBR" onto disk. */
    111 	if (!parts->pscheme->write_to_disk(parts)) {
    112 		msg_display(MSG_wmbrfail);
    113 		process_menu(MENU_ok, NULL);
    114 		return false;
    115 	}
    116 	return true;
    117 }
    118 
    119 /*
    120  * hook called after writing disklabel to new target disk.
    121  */
    122 bool
    123 md_post_disklabel(struct install_partition_desc *install,
    124     struct disk_partitions *parts)
    125 {
    126 	return true;
    127 }
    128 
    129 /*
    130  * hook called after upgrade() or install() has finished setting
    131  * up the target disk but immediately before the user is given the
    132  * ``disks are now set up'' message.
    133  */
    134 int
    135 md_post_newfs(struct install_partition_desc *install)
    136 {
    137 	struct mbr_sector pbr;
    138 	char adevname[STRSIZE];
    139 	ssize_t sz;
    140 	int fd = -1;
    141 
    142 	snprintf(adevname, sizeof(adevname), "/dev/r%sa", pm->diskdev);
    143 	fd = open(adevname, O_RDWR);
    144 	if (fd < 0)
    145 		goto out;
    146 
    147 	/* Read partition boot record */
    148 	sz = pread(fd, &pbr, sizeof(pbr), 0);
    149 	if (sz != sizeof(pbr))
    150 		goto out;
    151 
    152 	/* Check magic number */
    153 	if (pbr.mbr_magic != le16toh(MBR_MAGIC))
    154 		goto out;
    155 
    156 #ifdef NETBSD_MAJOR
    157 #define	OSNAME	"NetBSD" NETBSD_MAJOR
    158 #else
    159 #define	OSNAME	"NetBSD60"
    160 #endif
    161 	/* Update oemname */
    162 	memcpy(&pbr.mbr_oemname, OSNAME, sizeof(OSNAME) - 1);
    163 
    164 	/* Clear BPB */
    165 	memset(&pbr.mbr_bpb, 0, sizeof(pbr.mbr_bpb));
    166 
    167 	/* write-backed new patition boot record */
    168 	(void)pwrite(fd, &pbr, sizeof(pbr), 0);
    169 
    170 out:
    171 	if (fd >= 0)
    172 		close(fd);
    173 	return 0;
    174 }
    175 
    176 int
    177 md_post_extract(struct install_partition_desc *install)
    178 {
    179 	return 0;
    180 }
    181 
    182 void
    183 md_cleanup_install(struct install_partition_desc *install)
    184 {
    185 #ifndef DEBUG
    186 	enable_rc_conf();
    187 #endif
    188 }
    189 
    190 int
    191 md_pre_update(struct install_partition_desc *install)
    192 {
    193 	return 1;
    194 }
    195 
    196 /* Upgrade support */
    197 int
    198 md_update(struct install_partition_desc *install)
    199 {
    200 	md_post_newfs(install);
    201 	return 1;
    202 }
    203 
    204 int
    205 md_check_mbr(struct disk_partitions *parts, mbr_info_t *mbri, bool quiet)
    206 {
    207 	return 2;
    208 }
    209 
    210 bool
    211 md_parts_use_wholedisk(struct disk_partitions *parts)
    212 {
    213 
    214 	return parts_use_wholedisk(parts, 0, NULL);
    215 }
    216 
    217 
    218 int
    219 md_pre_mount(struct install_partition_desc *install)
    220 {
    221 	return 0;
    222 }
    223 
    224 bool
    225 md_mbr_update_check(struct disk_partitions *parts, mbr_info_t *mbri)
    226 {
    227 	return false;	/* no change, no need to write back */
    228 }
    229 
    230 #ifdef HAVE_GPT
    231 bool
    232 md_gpt_post_write(struct disk_partitions *parts, part_id root_id,
    233     bool root_is_new, part_id efi_id, bool efi_is_new)
    234 {
    235 	/* no GPT boot support, nothing needs to be done here */
    236 	return true;
    237 }
    238 #endif
    239 
    240