Home | History | Annotate | Line # | Download | only in arch
news.c revision 1.1
      1 /*	$NetBSD: news.c,v 1.1 2002/05/20 16:05:27 lukem Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Luke Mewburn and Izumi Tsutsui.
      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. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 #if defined(__RCSID) && !defined(__lint)
     41 __RCSID("$NetBSD: news.c,v 1.1 2002/05/20 16:05:27 lukem Exp $");
     42 #endif	/* !__lint */
     43 
     44 #if HAVE_CONFIG_H
     45 #include "config.h"
     46 #endif
     47 
     48 #include <sys/param.h>
     49 
     50 #include <assert.h>
     51 #include <err.h>
     52 #include <stddef.h>
     53 #include <stdio.h>
     54 #include <stdlib.h>
     55 #include <string.h>
     56 #include <unistd.h>
     57 
     58 #include "installboot.h"
     59 
     60 static int	news_clearboot(ib_params *, struct bbinfo_params *, uint8_t *);
     61 static int	news_setboot(ib_params *, struct bbinfo_params *, uint8_t *);
     62 
     63 
     64 /*
     65  * news68k specific support
     66  */
     67 
     68 static struct bbinfo_params news68k_bbparams = {
     69 	NEWS68K_BBINFO_MAGIC,
     70 	0,				/* write all 8K (including disklabel) */
     71 	NEWS_BOOT_BLOCK_BLOCKSIZE,
     72 	NEWS_BOOT_BLOCK_MAX_SIZE,
     73 	NEWS_BOOT_BLOCK_OFFSET,		/* but load bootxx here */
     74 	BBINFO_BIG_ENDIAN,
     75 };
     76 
     77 int
     78 news68k_clearboot(ib_params *params)
     79 {
     80 
     81 	assert(params != NULL);
     82 
     83 	if (params->flags & IB_STAGE1START) {
     84 		warnx("`-b bno' is not supported for %s",
     85 		    params->machine->name);
     86 		return (0);
     87 	}
     88 	return (shared_bbinfo_clearboot(params, &news68k_bbparams,
     89 	    news_clearboot));
     90 }
     91 
     92 int
     93 news68k_setboot(ib_params *params)
     94 {
     95 
     96 	assert(params != NULL);
     97 
     98 	if (params->flags & IB_STAGE1START) {
     99 		warnx("`-b bno' is not supported for %s",
    100 		    params->machine->name);
    101 		return (0);
    102 	}
    103 	return (shared_bbinfo_setboot(params, &news68k_bbparams, news_setboot));
    104 }
    105 
    106 
    107 /*
    108  * newsmips specific support
    109  */
    110 
    111 static struct bbinfo_params newsmips_bbparams = {
    112 	NEWSMIPS_BBINFO_MAGIC,
    113 	0,				/* write all 8K (including disklabel) */
    114 	NEWS_BOOT_BLOCK_BLOCKSIZE,
    115 	NEWS_BOOT_BLOCK_MAX_SIZE,
    116 	NEWS_BOOT_BLOCK_OFFSET,		/* but load bootxx here */
    117 	BBINFO_BIG_ENDIAN,
    118 };
    119 
    120 int
    121 newsmips_clearboot(ib_params *params)
    122 {
    123 
    124 	assert(params != NULL);
    125 
    126 	if (params->flags & IB_STAGE1START) {
    127 		warnx("`-b bno' is not supported for %s",
    128 		    params->machine->name);
    129 		return (0);
    130 	}
    131 	return (shared_bbinfo_clearboot(params, &newsmips_bbparams,
    132 	    news_clearboot));
    133 }
    134 
    135 int
    136 newsmips_setboot(ib_params *params)
    137 {
    138 
    139 	assert(params != NULL);
    140 
    141 	if (params->flags & IB_STAGE1START) {
    142 		warnx("`-b bno' is not supported for %s",
    143 		    params->machine->name);
    144 		return (0);
    145 	}
    146 	return (shared_bbinfo_setboot(params, &newsmips_bbparams,
    147 	    news_setboot));
    148 }
    149 
    150 
    151 /*
    152  * news common code
    153  */
    154 
    155 static int
    156 news_clearboot(ib_params *params, struct bbinfo_params *bbparams, uint8_t *bb)
    157 {
    158 
    159 	assert(params != NULL);
    160 	assert(bbparams != NULL);
    161 	assert(bb != NULL);
    162 
    163 		/* Clear out first sector to disklabel */
    164 	memset(bb, 0, NEWS_BOOT_BLOCK_LABELOFFSET);
    165 	return (1);
    166 }
    167 
    168 static int
    169 news_setboot(ib_params *params, struct bbinfo_params *bbparams, uint8_t *bb)
    170 {
    171 	uint8_t	boot00[NEWS_BOOT_BLOCK_OFFSET];
    172 	ssize_t	rv;
    173 
    174 	assert(params != NULL);
    175 	assert(params->fsfd != -1);
    176 	assert(bbparams != NULL);
    177 	assert(bb != NULL);
    178 
    179 		/* Read label sector to overwrite jump instruction */
    180 	memset(boot00, 0, sizeof(boot00));
    181 	rv = pread(params->fsfd, boot00, sizeof(boot00), 0);
    182 	if (rv == -1) {
    183 		warn("Reading label sector from `%s'", params->filesystem);
    184 		return (0);
    185 	}
    186 		/* Copy disklabel */
    187 	memcpy(bb + NEWS_BOOT_BLOCK_LABELOFFSET,
    188 	    boot00 + NEWS_BOOT_BLOCK_LABELOFFSET,
    189 	    sizeof(boot00) - NEWS_BOOT_BLOCK_LABELOFFSET);
    190 
    191 	return (1);
    192 }
    193