Home | History | Annotate | Line # | Download | only in arch
i386.c revision 1.22
      1  1.22    dsl /* $NetBSD: i386.c,v 1.22 2006/02/18 10:08:07 dsl Exp $ */
      2   1.1    dsl 
      3   1.1    dsl /*-
      4   1.1    dsl  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5   1.1    dsl  * All rights reserved.
      6   1.1    dsl  *
      7   1.1    dsl  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1    dsl  * by David Laight.
      9   1.1    dsl  *
     10   1.1    dsl  * Redistribution and use in source and binary forms, with or without
     11   1.1    dsl  * modification, are permitted provided that the following conditions
     12   1.1    dsl  * are met:
     13   1.1    dsl  * 1. Redistributions of source code must retain the above copyright
     14   1.1    dsl  *    notice, this list of conditions and the following disclaimer.
     15   1.1    dsl  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1    dsl  *    notice, this list of conditions and the following disclaimer in the
     17   1.1    dsl  *    documentation and/or other materials provided with the distribution.
     18   1.1    dsl  * 3. All advertising materials mentioning features or use of this software
     19   1.1    dsl  *    must display the following acknowledgement:
     20   1.1    dsl  *        This product includes software developed by the NetBSD
     21   1.1    dsl  *        Foundation, Inc. and its contributors.
     22   1.1    dsl  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.1    dsl  *    contributors may be used to endorse or promote products derived
     24   1.1    dsl  *    from this software without specific prior written permission.
     25   1.1    dsl  *
     26   1.1    dsl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.1    dsl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.1    dsl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.1    dsl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.1    dsl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.1    dsl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.1    dsl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.1    dsl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.1    dsl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.1    dsl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.1    dsl  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1    dsl  */
     38   1.1    dsl 
     39  1.12  lukem #if HAVE_NBTOOL_CONFIG_H
     40  1.12  lukem #include "nbtool_config.h"
     41  1.12  lukem #endif
     42  1.12  lukem 
     43   1.1    dsl #include <sys/cdefs.h>
     44  1.12  lukem #if !defined(__lint)
     45  1.22    dsl __RCSID("$NetBSD: i386.c,v 1.22 2006/02/18 10:08:07 dsl Exp $");
     46  1.13  lukem #endif /* !__lint */
     47   1.1    dsl 
     48   1.1    dsl #include <sys/param.h>
     49   1.1    dsl 
     50   1.1    dsl #include <assert.h>
     51   1.1    dsl #include <err.h>
     52   1.5  bjh21 #include <md5.h>
     53   1.1    dsl #include <stddef.h>
     54   1.1    dsl #include <stdio.h>
     55   1.1    dsl #include <stdlib.h>
     56   1.1    dsl #include <string.h>
     57   1.1    dsl #include <unistd.h>
     58   1.1    dsl 
     59   1.1    dsl #include "installboot.h"
     60   1.1    dsl 
     61  1.19    dsl #define nelem(x) (sizeof (x)/sizeof *(x))
     62  1.19    dsl 
     63  1.19    dsl static const char *const console_names[] = {
     64  1.19    dsl 	"pc", "com0", "com1", "com2", "com3",
     65  1.19    dsl 	"com0kbd", "com1kbd", "com2kbd", "com3kbd",
     66  1.19    dsl 	NULL };
     67  1.19    dsl 
     68  1.22    dsl static int i386_setboot(ib_params *);
     69  1.22    dsl static int i386_editboot(ib_params *);
     70  1.22    dsl 
     71  1.22    dsl struct ib_mach ib_mach_i386 =
     72  1.22    dsl 	{ "i386", i386_setboot, no_clearboot, i386_editboot,
     73  1.22    dsl 		IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR |
     74  1.22    dsl 		IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT };
     75  1.22    dsl 
     76  1.22    dsl struct ib_mach ib_mach_amd64 =
     77  1.22    dsl 	{ "amd64", i386_setboot, no_clearboot, i386_editboot,
     78  1.22    dsl 		IB_RESETVIDEO | IB_CONSOLE | IB_CONSPEED | IB_CONSADDR |
     79  1.22    dsl 		IB_KEYMAP | IB_PASSWORD | IB_TIMEOUT };
     80  1.22    dsl 
     81  1.19    dsl static void
     82  1.19    dsl show_i386_boot_params(struct x86_boot_params  *bpp)
     83  1.19    dsl {
     84  1.19    dsl 	uint32_t i;
     85  1.19    dsl 
     86  1.19    dsl 	printf("Boot options:        ");
     87  1.19    dsl 	printf("timeout %d, ", le32toh(bpp->bp_timeout));
     88  1.19    dsl 	printf("flags %x, ", le32toh(bpp->bp_flags));
     89  1.19    dsl 	printf("speed %d, ", le32toh(bpp->bp_conspeed));
     90  1.19    dsl 	printf("ioaddr %x, ", le32toh(bpp->bp_consaddr));
     91  1.19    dsl 	i = le32toh(bpp->bp_consdev);
     92  1.19    dsl 	if (i < nelem(console_names) - 1)
     93  1.19    dsl 		printf("console %s\n", console_names[i]);
     94  1.19    dsl 	else
     95  1.19    dsl 		printf("console %d\n", i);
     96  1.19    dsl 	if (bpp->bp_keymap[0])
     97  1.19    dsl 		printf("                     keymap %s\n", bpp->bp_keymap);
     98  1.19    dsl }
     99  1.19    dsl 
    100  1.19    dsl static int
    101  1.19    dsl update_i386_boot_params(ib_params *params, struct x86_boot_params  *bpp)
    102  1.19    dsl {
    103  1.19    dsl 	struct x86_boot_params bp;
    104  1.19    dsl 	int bplen;
    105  1.19    dsl 	int i;
    106  1.19    dsl 
    107  1.19    dsl 	bplen = le32toh(bpp->bp_length);
    108  1.19    dsl 	if (bplen > sizeof bp)
    109  1.19    dsl 		/* Ignore pad space in bootxx */
    110  1.19    dsl 		bplen = sizeof bp;
    111  1.19    dsl 
    112  1.19    dsl 	/* Take (and update) local copy so we handle size mismatches */
    113  1.19    dsl 	memset(&bp, 0, sizeof bp);
    114  1.19    dsl 	memcpy(&bp, bpp, bplen);
    115  1.19    dsl 
    116  1.19    dsl 	if (params->flags & IB_TIMEOUT)
    117  1.19    dsl 		bp.bp_timeout = htole32(params->timeout);
    118  1.19    dsl 	if (params->flags & IB_RESETVIDEO)
    119  1.19    dsl 		bp.bp_flags ^= htole32(X86_BP_FLAGS_RESET_VIDEO);
    120  1.19    dsl 	if (params->flags & IB_CONSPEED)
    121  1.19    dsl 		bp.bp_conspeed = htole32(params->conspeed);
    122  1.19    dsl 	if (params->flags & IB_CONSADDR)
    123  1.19    dsl 		bp.bp_consaddr = htole32(params->consaddr);
    124  1.19    dsl 	if (params->flags & IB_CONSOLE) {
    125  1.19    dsl 		for (i = 0; ; i++) {
    126  1.19    dsl 			if (console_names[i] == NULL) {
    127  1.19    dsl 				warnx("invalid console name, valid names are:");
    128  1.19    dsl 				fprintf(stderr, "\t%s", console_names[0]);
    129  1.19    dsl 				for (i = 1; console_names[i] != NULL; i++)
    130  1.19    dsl 					fprintf(stderr, ", %s", console_names[i]);
    131  1.19    dsl 				fprintf(stderr, "\n");
    132  1.19    dsl 				return 1;
    133  1.19    dsl 			}
    134  1.19    dsl 			if (strcmp(console_names[i], params->console) == 0)
    135  1.19    dsl 				break;
    136  1.19    dsl 		}
    137  1.19    dsl 		bp.bp_consdev = htole32(i);
    138  1.19    dsl 	}
    139  1.19    dsl 	if (params->flags & IB_PASSWORD) {
    140  1.19    dsl 		if (params->password[0]) {
    141  1.19    dsl 			MD5_CTX md5ctx;
    142  1.19    dsl 			MD5Init(&md5ctx);
    143  1.19    dsl 			MD5Update(&md5ctx, params->password,
    144  1.19    dsl 			    strlen(params->password));
    145  1.19    dsl 			MD5Final(bp.bp_password, &md5ctx);
    146  1.19    dsl 			bp.bp_flags |= htole32(X86_BP_FLAGS_PASSWORD);
    147  1.19    dsl 		} else {
    148  1.19    dsl 			memset(&bp.bp_password, 0, sizeof bp.bp_password);
    149  1.19    dsl 			bp.bp_flags &= ~htole32(X86_BP_FLAGS_PASSWORD);
    150  1.19    dsl 		}
    151  1.19    dsl 	}
    152  1.19    dsl 	if (params->flags & IB_KEYMAP)
    153  1.19    dsl 		strlcpy(bp.bp_keymap, params->keymap, sizeof bp.bp_keymap);
    154  1.19    dsl 
    155  1.19    dsl 	if (params->flags & (IB_NOWRITE | IB_VERBOSE))
    156  1.19    dsl 		show_i386_boot_params(&bp);
    157  1.19    dsl 
    158  1.19    dsl 	/* Check we aren't trying to set anything we can't save */
    159  1.19    dsl 	if (bplen < sizeof bp && memcmp((char *)&bp + bplen,
    160  1.19    dsl 					(char *)&bp + bplen + 1,
    161  1.19    dsl 					sizeof bp - bplen - 1) != 0) {
    162  1.19    dsl 		warnx("Patch area in stage1 bootstrap is too small");
    163  1.19    dsl 		return 1;
    164  1.19    dsl 	}
    165  1.19    dsl 	memcpy(bpp, &bp, bplen);
    166  1.19    dsl 	return 0;
    167  1.19    dsl }
    168  1.19    dsl 
    169  1.22    dsl static int
    170   1.1    dsl i386_setboot(ib_params *params)
    171   1.1    dsl {
    172  1.11  lukem 	int		retval, i, bpbsize;
    173  1.11  lukem 	uint8_t		*bootstrapbuf;
    174  1.18   yamt 	u_int		bootstrapsize;
    175   1.1    dsl 	ssize_t		rv;
    176   1.1    dsl 	uint32_t	magic;
    177  1.19    dsl 	struct x86_boot_params	*bpp;
    178   1.9  lukem 	struct mbr_sector	mbr;
    179   1.1    dsl 
    180   1.1    dsl 	assert(params != NULL);
    181   1.1    dsl 	assert(params->fsfd != -1);
    182   1.1    dsl 	assert(params->filesystem != NULL);
    183   1.1    dsl 	assert(params->s1fd != -1);
    184   1.1    dsl 	assert(params->stage1 != NULL);
    185   1.1    dsl 
    186   1.1    dsl 	retval = 0;
    187   1.1    dsl 	bootstrapbuf = NULL;
    188   1.1    dsl 
    189   1.2    dsl 	/*
    190   1.2    dsl 	 * There is only 8k of space in a UFSv1 partition (and ustarfs)
    191   1.2    dsl 	 * so ensure we don't splat over anything important.
    192   1.2    dsl 	 */
    193   1.2    dsl 	if (params->s1stat.st_size > 8192) {
    194   1.2    dsl 		warnx("stage1 bootstrap `%s' is larger than 8192 bytes",
    195   1.2    dsl 			params->stage1);
    196   1.9  lukem 		goto done;
    197   1.9  lukem 	}
    198   1.9  lukem 
    199   1.9  lukem 	/*
    200   1.9  lukem 	 * Read in the existing MBR.
    201   1.9  lukem 	 */
    202   1.9  lukem 	rv = pread(params->fsfd, &mbr, sizeof(mbr), MBR_BBSECTOR);
    203   1.9  lukem 	if (rv == -1) {
    204   1.9  lukem 		warn("Reading `%s'", params->filesystem);
    205   1.9  lukem 		goto done;
    206   1.9  lukem 	} else if (rv != sizeof(mbr)) {
    207   1.9  lukem 		warnx("Reading `%s': short read", params->filesystem);
    208   1.9  lukem 		goto done;
    209   1.1    dsl 	}
    210  1.10  lukem 	if (mbr.mbr_magic != le16toh(MBR_MAGIC)) {
    211   1.9  lukem 		if (params->flags & IB_VERBOSE) {
    212   1.9  lukem 			printf(
    213   1.9  lukem 		    "Ignoring MBR with invalid magic in sector 0 of `%s'\n",
    214   1.9  lukem 			    params->filesystem);
    215   1.9  lukem 		}
    216   1.9  lukem 		memset(&mbr, 0, sizeof(mbr));
    217   1.9  lukem 	}
    218   1.9  lukem 
    219   1.1    dsl 	/*
    220   1.1    dsl 	 * Allocate a buffer, with space to round up the input file
    221   1.1    dsl 	 * to the next block size boundary, and with space for the boot
    222   1.1    dsl 	 * block.
    223   1.1    dsl 	 */
    224   1.1    dsl 	bootstrapsize = roundup(params->s1stat.st_size, 512);
    225   1.1    dsl 
    226   1.1    dsl 	bootstrapbuf = malloc(bootstrapsize);
    227   1.1    dsl 	if (bootstrapbuf == NULL) {
    228   1.1    dsl 		warn("Allocating %u bytes",  bootstrapsize);
    229   1.1    dsl 		goto done;
    230   1.1    dsl 	}
    231   1.1    dsl 	memset(bootstrapbuf, 0, bootstrapsize);
    232   1.1    dsl 
    233   1.9  lukem 	/*
    234   1.9  lukem 	 * Read the file into the buffer.
    235   1.9  lukem 	 */
    236   1.1    dsl 	rv = pread(params->s1fd, bootstrapbuf, params->s1stat.st_size, 0);
    237   1.1    dsl 	if (rv == -1) {
    238   1.1    dsl 		warn("Reading `%s'", params->stage1);
    239   1.9  lukem 		goto done;
    240   1.1    dsl 	} else if (rv != params->s1stat.st_size) {
    241   1.1    dsl 		warnx("Reading `%s': short read", params->stage1);
    242   1.9  lukem 		goto done;
    243   1.1    dsl 	}
    244   1.1    dsl 
    245   1.1    dsl 	magic = *(uint32_t *)(bootstrapbuf + 512 * 2 + 4);
    246   1.7    dsl 	if (magic != htole32(X86_BOOT_MAGIC_1)) {
    247  1.20    dsl 		warnx("Invalid magic in stage1 bootstrap %x != %x",
    248   1.7    dsl 			magic, htole32(X86_BOOT_MAGIC_1));
    249   1.2    dsl 		goto done;
    250   1.2    dsl 	}
    251   1.2    dsl 
    252   1.9  lukem 	/*
    253  1.11  lukem 	 * Determine size of BIOS Parameter Block (BPB) to copy from
    254  1.11  lukem 	 * original MBR to the temporary buffer by examining the first
    255  1.11  lukem 	 * few instruction in the new bootblock.  Supported values:
    256  1.11  lukem 	 *	eb 3c 90	jmp ENDOF(mbr_bpbFAT16)+1, nop
    257  1.11  lukem 	 *	eb 58 90	jmp ENDOF(mbr_bpbFAT32)+1, nop
    258  1.11  lukem 	 *      (anything else)	; don't preserve
    259  1.11  lukem 	 */
    260  1.11  lukem 	bpbsize = 0;
    261  1.11  lukem 	if (bootstrapbuf[0] == 0xeb && bootstrapbuf[2] == 0x90 &&
    262  1.11  lukem 	    (bootstrapbuf[1] == 0x3c || bootstrapbuf[1] == 0x58))
    263  1.11  lukem 		bpbsize = bootstrapbuf[1] + 2 - MBR_BPB_OFFSET;
    264  1.11  lukem 
    265  1.11  lukem 	/*
    266  1.15  lukem 	 * Ensure bootxx hasn't got any code or data (i.e, non-zero bytes) in
    267  1.11  lukem 	 * the partition table.
    268   1.9  lukem 	 */
    269   1.9  lukem 	for (i = 0; i < sizeof(mbr.mbr_parts); i++) {
    270   1.9  lukem 		if (*(uint8_t *)(bootstrapbuf + MBR_PART_OFFSET + i) != 0) {
    271   1.9  lukem 			warnx(
    272   1.9  lukem 		    "Partition table has non-zero byte at offset %d in `%s'",
    273   1.9  lukem 			    MBR_PART_OFFSET + i, params->stage1);
    274   1.9  lukem 			goto done;
    275   1.9  lukem 		}
    276   1.9  lukem 	}
    277   1.9  lukem 
    278   1.9  lukem 	/*
    279   1.9  lukem 	 * Copy the BPB and the partition table from the original MBR to the
    280   1.9  lukem 	 * temporary buffer so that they're written back to the fs.
    281   1.9  lukem 	 */
    282  1.11  lukem 	if (bpbsize != 0) {
    283  1.11  lukem 		if (params->flags & IB_VERBOSE)
    284  1.11  lukem 			printf("Preserving %d (%#x) bytes of the BPB\n",
    285  1.11  lukem 			    bpbsize, bpbsize);
    286  1.11  lukem 		memcpy(bootstrapbuf + MBR_BPB_OFFSET, &mbr.mbr_bpb, bpbsize);
    287  1.11  lukem 	}
    288   1.9  lukem 	memcpy(bootstrapbuf + MBR_PART_OFFSET, &mbr.mbr_parts,
    289   1.9  lukem 	    sizeof(mbr.mbr_parts));
    290   1.9  lukem 
    291   1.9  lukem 	/*
    292  1.15  lukem 	 * Fill in any user-specified options into the
    293  1.17    dsl 	 *      struct x86_boot_params
    294  1.15  lukem 	 * that's 8 bytes in from the start of the third sector.
    295  1.15  lukem 	 * See sys/arch/i386/stand/bootxx/bootxx.S for more information.
    296   1.9  lukem 	 */
    297  1.17    dsl 	bpp = (void *)(bootstrapbuf + 512 * 2 + 8);
    298  1.19    dsl 	if (update_i386_boot_params(params, bpp))
    299  1.17    dsl 		goto done;
    300   1.1    dsl 
    301   1.1    dsl 	if (params->flags & IB_NOWRITE) {
    302   1.1    dsl 		retval = 1;
    303   1.1    dsl 		goto done;
    304   1.1    dsl 	}
    305   1.1    dsl 
    306   1.9  lukem 	/*
    307   1.9  lukem 	 * Write MBR code to sector zero.
    308   1.9  lukem 	 */
    309   1.1    dsl 	rv = pwrite(params->fsfd, bootstrapbuf, 512, 0);
    310   1.1    dsl 	if (rv == -1) {
    311   1.1    dsl 		warn("Writing `%s'", params->filesystem);
    312   1.1    dsl 		goto done;
    313   1.1    dsl 	} else if (rv != 512) {
    314   1.1    dsl 		warnx("Writing `%s': short write", params->filesystem);
    315   1.1    dsl 		goto done;
    316   1.1    dsl 	}
    317   1.1    dsl 
    318   1.9  lukem 	/*
    319   1.9  lukem 	 * Skip disklabel in sector 1 and write bootxx to sectors 2..N.
    320   1.9  lukem 	 */
    321   1.1    dsl 	rv = pwrite(params->fsfd, bootstrapbuf + 512 * 2,
    322   1.1    dsl 		    bootstrapsize - 512 * 2, 512 * 2);
    323   1.1    dsl 	if (rv == -1) {
    324   1.1    dsl 		warn("Writing `%s'", params->filesystem);
    325   1.1    dsl 		goto done;
    326   1.1    dsl 	} else if (rv != bootstrapsize - 512 * 2) {
    327   1.1    dsl 		warnx("Writing `%s': short write", params->filesystem);
    328   1.1    dsl 		goto done;
    329   1.1    dsl 	}
    330   1.1    dsl 
    331   1.1    dsl 	retval = 1;
    332   1.1    dsl 
    333   1.1    dsl  done:
    334   1.1    dsl 	if (bootstrapbuf)
    335   1.1    dsl 		free(bootstrapbuf);
    336   1.1    dsl 	return retval;
    337   1.1    dsl }
    338  1.19    dsl 
    339  1.22    dsl static int
    340  1.19    dsl i386_editboot(ib_params *params)
    341  1.19    dsl {
    342  1.19    dsl 	int		retval;
    343  1.19    dsl 	uint8_t		buf[512];
    344  1.19    dsl 	ssize_t		rv;
    345  1.19    dsl 	uint32_t	magic;
    346  1.19    dsl 	uint32_t	offset;
    347  1.19    dsl 	struct x86_boot_params	*bpp;
    348  1.19    dsl 
    349  1.19    dsl 	assert(params != NULL);
    350  1.19    dsl 	assert(params->fsfd != -1);
    351  1.19    dsl 	assert(params->filesystem != NULL);
    352  1.19    dsl 
    353  1.19    dsl 	retval = 0;
    354  1.19    dsl 
    355  1.19    dsl 	/*
    356  1.19    dsl 	 * Read in the existing bootstrap.
    357  1.21    dsl 	 * Look in any of the first 4 sectors.
    358  1.19    dsl 	 */
    359  1.19    dsl 
    360  1.19    dsl 	bpp = NULL;
    361  1.19    dsl 	for (offset = 0; offset < 4 * 512; offset += 512) {
    362  1.19    dsl 		rv = pread(params->fsfd, &buf, sizeof buf, offset);
    363  1.19    dsl 		if (rv == -1) {
    364  1.19    dsl 			warn("Reading `%s'", params->filesystem);
    365  1.19    dsl 			goto done;
    366  1.19    dsl 		} else if (rv != sizeof buf) {
    367  1.19    dsl 			warnx("Reading `%s': short read", params->filesystem);
    368  1.19    dsl 			goto done;
    369  1.19    dsl 		}
    370  1.19    dsl 
    371  1.21    dsl 		/* Magic number is 4 bytes in (to allow for a jmps) */
    372  1.21    dsl 		/* Also allow any of the magic numbers. */
    373  1.21    dsl 		magic = le32toh(*(uint32_t *)(buf + 4)) | 0xf;
    374  1.21    dsl 		if (magic != (X86_BOOT_MAGIC_1 | 0xf))
    375  1.19    dsl 			continue;
    376  1.21    dsl 
    377  1.21    dsl 		/* The parameters are just after the magic number */
    378  1.19    dsl 		bpp = (void *)(buf + 8);
    379  1.19    dsl 		break;
    380  1.19    dsl 	}
    381  1.19    dsl 	if (bpp == NULL) {
    382  1.21    dsl 		warnx("Invalid magic in existing bootstrap");
    383  1.19    dsl 		goto done;
    384  1.19    dsl 	}
    385  1.19    dsl 
    386  1.19    dsl 	/*
    387  1.19    dsl 	 * Fill in any user-specified options into the
    388  1.19    dsl 	 *      struct x86_boot_params
    389  1.19    dsl 	 * that's 8 bytes in from the start of the third sector.
    390  1.19    dsl 	 * See sys/arch/i386/stand/bootxx/bootxx.S for more information.
    391  1.19    dsl 	 */
    392  1.19    dsl 	if (update_i386_boot_params(params, bpp))
    393  1.19    dsl 		goto done;
    394  1.19    dsl 
    395  1.19    dsl 	if (params->flags & IB_NOWRITE) {
    396  1.19    dsl 		retval = 1;
    397  1.19    dsl 		goto done;
    398  1.19    dsl 	}
    399  1.19    dsl 
    400  1.19    dsl 	/*
    401  1.19    dsl 	 * Write boot code back
    402  1.19    dsl 	 */
    403  1.19    dsl 	rv = pwrite(params->fsfd, buf, sizeof buf, offset);
    404  1.19    dsl 	if (rv == -1) {
    405  1.19    dsl 		warn("Writing `%s'", params->filesystem);
    406  1.19    dsl 		goto done;
    407  1.19    dsl 	} else if (rv != sizeof buf) {
    408  1.19    dsl 		warnx("Writing `%s': short write", params->filesystem);
    409  1.19    dsl 		goto done;
    410  1.19    dsl 	}
    411  1.19    dsl 
    412  1.19    dsl 	retval = 1;
    413  1.19    dsl 
    414  1.19    dsl  done:
    415  1.19    dsl 	return retval;
    416  1.19    dsl }
    417