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